Tool [Release]PySock - Adminpage tool

Stato
Discussione chiusa ad ulteriori risposte.

martysama0134

Utente Platinum
9 Gennaio 2009
3,446
80
1,703
1,107
Ultima modifica da un moderatore:
Intro:
Tale programmino (in python) sarebbe un'alternativa del mio stesso programmino in c++ postato qua.
Lo feci tempo fa tanto per fare e, tanto per non farlo ammuffire, eccolo qua.

Richiede avere python installato nel server. (può funzionare anche su windows)
Ci sono 3 modi per installare python:
1. Dal comando pkg_add:
Codice:
pkg_add -r python27
#oppure
pkg_add -r python
2. Dalla cartella di python27 nei ports di freebsd
Codice:
cd /usr/ports/lang/python27
#oppure
cd /usr/ports/lang/python
#poi
make install
3. Dai source del sito di python:
Codice:
fetch http://python.org/ftp/python/2.7.3/Python-2.7.3.tgz
tar -xz -f "Python-2.7.3.tgz"
cd Python-2.7.3
#crea la configurazione
./configure
#compila i sorgenti
./make
#installa
./make install
#non ricordo se poi qua copiava in automatico l'interprete su ./build/
#in /usr/local/bin/ oppure era da fare a mano

Screen:
1zgav6f.gif


Uso:
La maggior parte delle cose son state spiegate nel vecchio thread.
Particolari:
-Con questa versione potrete leggere il return da parte del server (in caso di USER_COUNT apparirà il numero dei player on)
-All'inizio dell'__init__ ci sono 2 variabili che indicano che host e che dati dell'adminpage usare di default
-Il file "pysock_cmd.txt" può essere impostato così:
Codice:
NOTICE Uno!
NOTICE Due!
NOTICE Ecc!
-Con il parametro -s/--set si impostano i dati d'accesso sul file "pysock_con.txt" e si richiamano con -g/--get

Varie prove:
Codice:
#invio comando+salvataggio dati su pysock_con.txt
./pysock -s "123.456.78.90:13000:SHOWMETHEMONEY" -c "NOTICE Yeah!;NOTICE Yeah!!!"
#una volta creato il file pysock_con.txt basta fare così:
./pysock -g -c "NOTICE Yeah!"
#per caricare roba da un file (nel mentre creiamolo):
echo NOTICE Yeah! >> pysock_cmd.txt
./pysock -g -f "pysock_cmd.txt"
#possiamo incrociare più roba:
./pysock -g -f "pysock_cmd.txt" -c "NOTICE Yeah!;EVENT xmas_boom 1;USER_COUNT;"
#completamente manuale:
./pysock -r "123.456.78.90:13000 SHOWMETHEMONEY Yeah!"
#miscuglio:
./pysock -r "123.456.78.90:13000 SHOWMETHEMONEY Yeah!" -g -f "pysock_cmd.txt" -c "NOTICE Yeah!"
#ripetuto:
./pysock -g -c "NOTICE Yeah!" -c "NOTICE Yeah!" -c "NOTICE Yeah!" -c "NOTICE Yeah!"

Download: html mode, txt mode, file mode
Oppure:
Codice:
#!/usr/local/bin/python2.7
import getopt	#getopt.getopt
import os		#os.path.exists
import socket	#socket.socket, socket.connect, socket.send, socket.recv, socket.close
import sys		#sys.exit
import time		#time.sleep

class PySockModule:
	def __init__(self):
		#con-data
		self.HOSTPORT=None
		self.ADMINPWD=None
		self.COMMAND=None
		#default-data
		self.dftHOSTPORT=("123.456.78.90",13000)
		self.dftADMINPWD="SHOWMETHEMONEY"
		self.dftCOMMAND=("NOTICE /!\\ ",)
		#cleanlist
		self.NOWAY=(0,"0","",None)
		#file
		self.PYSOCK_HLPFILE="pysock_hlp.txt"
		self.PYSOCK_CMDFILE="pysock_cmd.txt"
		self.PYSOCK_CONFILE="pysock_con.txt"
		#args
		self.PYSOCK_SHRTARG='c:df:ghr:s:'
		self.PYSOCK_LONGARG=('command=','default','file=','get','help','raw=','set=')
		
		#analyze argv
		try:
			self.optlist, self.args = getopt.getopt(sys.argv[1:],self.PYSOCK_SHRTARG,self.PYSOCK_LONGARG)
		except getopt.GetoptError, err:
			print str(err)
			sys.exit(2)
		#analyze optlist
		self.ArgAnalyze(self.optlist)
			
	def Docs():
		"""\
		Intro
		\tPySock is a simple program that uses socket connection
		\t\tto send a little query to a metin2 server (using adminpage)
		
		
		ArgvList:
		#(-c or --command) send command
		\t./pysock.py -c "<command>"
		#(-g or --get) get con-data from con-file (pysock_con.txt) and send a command
		\t./pysock.py -g -c "<command>"
		#(-f or --file) send command from file
		\t./pysock.py -f "<file>"
		\t\tExample:\t./pysock.py -f "mysock_cmd.txt"
		#(-h or --help) help
		\t./pysock.py -h
		#(-s or --set) set con-data to con-file (pysock_con.txt) and send a command
		\t./pysock.py -s "<host>:<port>:<pwd>"
		\t\tExample:\t./pysock.py -s "123.456.78.90:13000:SHOMETHEMONEY" -c "NOTICE 1;NOTICE 2;NOTICE 3"
		#(-r or --raw) raw mode
		\t./pysock.py -r "<host:port> <adminpwd> <command>"
		\t\tExample:\t./pysock.py -r "123.456.78.90:13000 SHOWMETHEMONEY NOTICE 1;NOTICE 2;USER_COUNT"
		
		CommandList:
		#block_chat %s %d
		\tBLOCK_CHAT <nick> <duration>
		\t\tExample:\tBLOCK_CHAT [GA]LoLLo 1h
		#block_exception
		\tBLOCK_EXCEPTION
		#check_client
		\tCHECK_CLIENT
		#close_passpod
		\tCLOSE_PASSPOD
		#dc %s
		\tDC <account>
		\t\tExample:\tDC tuoaccount
		#event %s %d
		\tEVENT <eventflag> <value>
		\t\tExample:\tEVENT xmas_tree 4
		#notice %s
		\tNOTICE <message>
		\t\tExample:\tNOTICE This is a test
		#is_passpod_up
		\tIS_PASSPOD_UP
		#is_server_up
		\tIS_SERVER_UP
		#priv_empire %d %d %d %d
		\tPRIV_EMPIRE <empire> <type> <value> <duration>
		\t\tempire\t0-3  0==all, 1==red, 2==yellow, 3==blue)
		\t\ttype\t1:item_drop, 2:gold_drop, 3:gold10_drop, 4:exp
		\t\tvalue\tpercent
		\t\tdur.\thour
		\t\tExample:\tPRIV_EMPIRE 0 4 200 72h
		#profile
		\tPROFILE
		#reload &%s
		\tRELOAD <&type>
		\t\ttype\tdefault:general, a:admin, c:cube, f:fish, p:player, q:quest, s:string
		#reload_crc
		\tRELOAD_CRC
		#shutdown
		\tSHUTDOWN
		#shutdown_only
		\tSHUTDOWN_ONLY
		#unknown
		\tUNKNOWN
		#user_count
		\tUSER_COUNT
		
		Created by martysama0134 - All rights reserved
		"""

	def SendPacket(self, HOSTPORT=None, ADMINPWD=None, COMMAND=None):
		if(HOSTPORT in self.NOWAY): HOSTPORT=self.dftHOSTPORT
		if(ADMINPWD in self.NOWAY): ADMINPWD=self.dftADMINPWD
		if(COMMAND in self.NOWAY): COMMAND=self.dftCOMMAND
		try:
			#connect
			con=socket.socket(socket.AF_INET, socket.SOCK_STREAM, socket.SOL_TCP)
			con.connect(HOSTPORT)
			#send
			CMDSEND="@%s\n@%s\n" % (ADMINPWD,"\n@".join(COMMAND))
			print CMDSEND
			con.send(CMDSEND)
			#receive
			print repr(con.recv(1024))#escape
			time.sleep(0.1)#required
			#close
			con.close()
			print "<Pysock> Socket inviato con successo"
		except socket.error:
			assert False, "<Pysock> Socket failed, con-data maybe wrong (%s, %s, %s)"%(HOSTPORT[0], HOSTPORT[1], ADMINPWD)

	def ArgAnalyze(self, optlist):
		for o, a in optlist:
			#help
			if o in ('-h', '--help'):
				try:
					help(self.Docs)
					#print self.Docs.__doc__
				except KeyboardInterrupt:
					pass
				sys.exit()
			#send command from arg
			elif o in ('-c', '--command'):
				#analyze string-arg
				try:
					self.COMMAND=a.split(";")
				except IndentationError, err:
					assert False, "<Pysock> Except %s" % (err,)
				self.SendPacket(self.HOSTPORT, self.ADMINPWD, self.COMMAND)
			#load default con-data
			elif o in ('-d', '--default'):
				self.HOSTPORT=self.dftHOSTPORT
				self.ADMINPWD=self.dftADMINPWD
				self.COMMAND=self.dftCOMMAND
			#load command from file
			elif o in ('-f', '--file'):
				#analyze string-arg
				if(os.path.exists(a)):
					#read file
					self.COMMAND=open(a,"r").read().split("\n")
					#send
					self.SendPacket(self.HOSTPORT, self.ADMINPWD, self.COMMAND)
				else:
					assert False, "<Pysock> File %s not found" % (a,)
			#load con-data from file
			elif o in ('-g', '--get'):
				#analyze string-arg
				if(os.path.exists(self.PYSOCK_CONFILE)):
					#read file
					self.CONREAD=open(self.PYSOCK_CONFILE,"r").read()
					#set con-data
					try:
						self.CONAN=self.CONREAD.split(":",2)
						#set con-data
						self.HOSTPORT=(self.CONAN[0],int(self.CONAN[1]))
						self.ADMINPWD=self.CONAN[2].replace("\n","").replace("\r","")
					except IndentationError, err:
						assert False, "<Pysock> Except %s" % (err,)
				else:
					assert False, "<Pysock> File %s not found" % (self.PYSOCK_CONFILE,)
			#create a manual string
			elif o in ('-r', '--raw'):
				#analyze string-arg
				try:
					a=a.split(" ",2)
				except IndentationError, err:
					assert False, "<Pysock> Except %s" % (err,)
				#set data
				myHOSTPORT=a[0].split(":",1)
				self.HOSTPORT=(myHOSTPORT[0],int(myHOSTPORT[1]))
				self.ADMINPWD=a[1]
				self.COMMAND=a[2].split(";")
				#send
				self.SendPacket(self.HOSTPORT, self.ADMINPWD, self.COMMAND)
			#save your data connection
			elif o in ('-s', '--set'):
				#analyze string-arg
				try:
					self.CONAN=a.split(":",2)
				except IndentationError, err:
					assert False, "<Pysock> Except %s" % (err,)
				#save hostport
				f1=open(self.PYSOCK_CONFILE,"w")
				f1.write(a)
				del f1
				#set con-data
				self.HOSTPORT=(self.CONAN[0],int(self.CONAN[1]))
				self.ADMINPWD=self.CONAN[2]
			#invalid args
			else:
				assert False, "<Pysock> Unhandled %s option" % (o,)

avvia=PySockModule
avvia()

Ricordo che questo tool serve unicamente per il vostro server! (gestire eventi, mettere rates, bloccare chat e tanto altro da riga di comando!)
Usarlo su server non propri è altamente inutile!
 
visto che hai fatto uno script basato sullo "SHOWMETHEMONEY" spiega anche come usarlo in sicurezza per i nabbi :D
 
visto che hai fatto uno script basato sullo "SHOWMETHEMONEY" spiega anche come usarlo in sicurezza per i nabbi :D
Umh, dovrebbe esser spiegato tutto sull'altro thread riguardante il mysock (uso+adminpage disable dif)
Poi, se qualcuno non capisse ancora qualcosa può sempre chieder aiuto qua (basta che non assilli)
 
Perchè quell'inutilissima funzione "pysock_help"....perchèèèèè martaaaaa???
Mi hai deluso v.v
 
Rosella, sistemata quella serie di print! °°

Aggiornato: (v2)
  • Ristrutturato il codice
  • Gestite quasi tutte le eccezioni
  • Ora con -s/--set si salveranno i dati su pysock_con.txt mentre con -g/--get si leggeranno da esso!
  • I dati di default si trovano sulle righe 15-17 nelle variabili che contengono "dft"

Per qualsiasi problema/info scrivete qua.
 
Ho aggiornato una riga della "documentazione".
Ricordo che il comando DC dell'adminpage non fa crashare un pg ma un account:
Codice:
#Questo comando può non funzionare su alcune porte (per via dei game non comunicanti)
DC tuoaccount
La porta da usare è quella dichiarata su CONFIG con PORT (le P2P_PORT fanno altro)
 
Hey LoLLo, how to kick someone from channel1?
Did you tested this?

I tried those cmd:
./pysock.py -s "IP:13000:pASSWORD" -c "DC account_name;"

(13000 - Standard Port from channel1)

Tried also
./pysock.py -s "IP:14000:pASSWORD" -c "DC account_name;"

(14000 - P2P port from channel1)

Other CMD's work very good, but I need to kick... :/
 
Stato
Discussione chiusa ad ulteriori risposte.