mirror of
https://github.com/SystemRage/py-kms.git
synced 2024-11-29 03:34:16 +01:00
Made server timeout option effective
This commit is contained in:
parent
8d105710e6
commit
328dcedea2
@ -119,7 +119,8 @@ MsgMap = {0 : {'text' : "{yellow}\n\t\t\tClient generating RPC Bind Request...{
|
|||||||
-1 : {'text' : "{white}Server receiving{end}", 'where' : "clt"},
|
-1 : {'text' : "{white}Server receiving{end}", 'where' : "clt"},
|
||||||
-2 : {'text' : "{white}\n\n\t\t\t\t\t\t\t\tClient sending{end}", 'where' : "srv"},
|
-2 : {'text' : "{white}\n\n\t\t\t\t\t\t\t\tClient sending{end}", 'where' : "srv"},
|
||||||
-3 : {'text' : "{white}\t\t\t\t\t\t\t\tClient receiving{end}", 'where' : "srv"},
|
-3 : {'text' : "{white}\t\t\t\t\t\t\t\tClient receiving{end}", 'where' : "srv"},
|
||||||
-4 : {'text' : "{white}\n\nServer sending{end}", 'where' : "clt"}
|
-4 : {'text' : "{white}\n\nServer sending{end}", 'where' : "clt"},
|
||||||
|
30 : {'text' : "{red}{bold}\nServer connection timed out. Exiting...{end}", 'where' : "srv"}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -31,7 +31,15 @@ srv_version = 'py-kms_2019-05-15'
|
|||||||
srv_config = {}
|
srv_config = {}
|
||||||
|
|
||||||
##---------------------------------------------------------------------------------------------------------------------------------------------------------
|
##---------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
class KeyServer(socketserver.ThreadingMixIn, socketserver.TCPServer):
|
||||||
|
daemon_threads = True
|
||||||
|
allow_reuse_address = True
|
||||||
|
|
||||||
|
def handle_timeout(self):
|
||||||
|
ShellMessage.Process([30]).run()
|
||||||
|
loggersrv.error("Server connection timed out. Exiting...")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
class server_thread(threading.Thread):
|
class server_thread(threading.Thread):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
threading.Thread.__init__(self)
|
threading.Thread.__init__(self)
|
||||||
@ -50,9 +58,12 @@ class server_thread(threading.Thread):
|
|||||||
# Create and run threaded server.
|
# Create and run threaded server.
|
||||||
self.server = server_create()
|
self.server = server_create()
|
||||||
try:
|
try:
|
||||||
self.server.serve_forever()
|
while True:
|
||||||
|
self.server.handle_request()
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
sys.exit(0)
|
pass
|
||||||
|
finally:
|
||||||
|
self.server.server_close()
|
||||||
elif item == 'stop':
|
elif item == 'stop':
|
||||||
self.is_running = False
|
self.is_running = False
|
||||||
self.server = None
|
self.server = None
|
||||||
@ -80,7 +91,7 @@ for server OSes and Office >=5', 'def' : None, 'des' : "CurrentClientCount"},
|
|||||||
'def' : False, 'des' : "sqlite"},
|
'def' : False, 'des' : "sqlite"},
|
||||||
'hwid' : {'help' : 'Use this option to specify a HWID. The HWID must be an 16-character string of hex characters. \
|
'hwid' : {'help' : 'Use this option to specify a HWID. The HWID must be an 16-character string of hex characters. \
|
||||||
The default is \"364F463A8863D35F\" or type \"RANDOM\" to auto generate the HWID.', 'def' : "364F463A8863D35F", 'des' : "hwid"},
|
The default is \"364F463A8863D35F\" or type \"RANDOM\" to auto generate the HWID.', 'def' : "364F463A8863D35F", 'des' : "hwid"},
|
||||||
'time' : {'help' : 'Disconnect clients after time of inactivity (in seconds). The default is \"30\" seconds', 'def' : 30, 'des' : "timeout"},
|
'time' : {'help' : 'Max time (in seconds) for server to generate an answer. If \"None\" (default) serve forever.', 'def' : None, 'des' : "timeout"},
|
||||||
'llevel' : {'help' : 'Use this option to set a log level. The default is \"ERROR\".', 'def' : "ERROR", 'des' : "loglevel",
|
'llevel' : {'help' : 'Use this option to set a log level. The default is \"ERROR\".', 'def' : "ERROR", 'des' : "loglevel",
|
||||||
'choi' : ["CRITICAL", "ERROR", "WARNING", "INFO", "DEBUG", "MINI"]},
|
'choi' : ["CRITICAL", "ERROR", "WARNING", "INFO", "DEBUG", "MINI"]},
|
||||||
'lfile' : {'help' : 'Use this option to set or not an output log file. The default is \"pykms_logserver.log\" or type \"STDOUT\" to view log info on stdout.',
|
'lfile' : {'help' : 'Use this option to set or not an output log file. The default is \"pykms_logserver.log\" or type \"STDOUT\" to view log info on stdout.',
|
||||||
@ -185,13 +196,12 @@ def server_check():
|
|||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
def server_create():
|
def server_create():
|
||||||
socketserver.TCPServer.allow_reuse_address = True
|
server = KeyServer((srv_config['ip'], srv_config['port']), kmsServerHandler)
|
||||||
server = socketserver.TCPServer((srv_config['ip'], srv_config['port']), kmsServer)
|
|
||||||
server.timeout = srv_config['timeout']
|
server.timeout = srv_config['timeout']
|
||||||
loggersrv.info("TCP server listening at %s on port %d." % (srv_config['ip'], srv_config['port']))
|
loggersrv.info("TCP server listening at %s on port %d." % (srv_config['ip'], srv_config['port']))
|
||||||
loggersrv.info("HWID: %s" % deco(binascii.b2a_hex(srv_config['hwid']), 'utf-8').upper())
|
loggersrv.info("HWID: %s" % deco(binascii.b2a_hex(srv_config['hwid']), 'utf-8').upper())
|
||||||
return server
|
return server
|
||||||
|
|
||||||
def srv_main_without_gui():
|
def srv_main_without_gui():
|
||||||
# Parse options.
|
# Parse options.
|
||||||
server_options()
|
server_options()
|
||||||
@ -215,7 +225,7 @@ def srv_main_with_gui(width = 950, height = 660):
|
|||||||
root.mainloop()
|
root.mainloop()
|
||||||
|
|
||||||
|
|
||||||
class kmsServer(socketserver.BaseRequestHandler):
|
class kmsServerHandler(socketserver.BaseRequestHandler):
|
||||||
def setup(self):
|
def setup(self):
|
||||||
loggersrv.info("Connection accepted: %s:%d" % (self.client_address[0], self.client_address[1]))
|
loggersrv.info("Connection accepted: %s:%d" % (self.client_address[0], self.client_address[1]))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user