mirror of
https://github.com/SystemRage/py-kms.git
synced 2024-11-25 17:55:37 +01:00
Checked GUI options
disabled maximize button (gives visualization error) disabled widgets when client/server running
This commit is contained in:
parent
abd093d949
commit
cbfe1511a2
@ -10,6 +10,7 @@ import sys
|
|||||||
import uuid
|
import uuid
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
import threading
|
||||||
|
|
||||||
import pykms_RpcBind, pykms_RpcRequest
|
import pykms_RpcBind, pykms_RpcRequest
|
||||||
from pykms_Filetimes import dt_to_filetime
|
from pykms_Filetimes import dt_to_filetime
|
||||||
@ -28,6 +29,16 @@ clt_description = 'KMS Client Emulator written in Python'
|
|||||||
clt_version = 'py-kms_2019-05-15'
|
clt_version = 'py-kms_2019-05-15'
|
||||||
clt_config = {}
|
clt_config = {}
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
class client_thread(threading.Thread):
|
||||||
|
def __init__(self, name):
|
||||||
|
threading.Thread.__init__(self)
|
||||||
|
self.name = name
|
||||||
|
self.with_gui = False
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
clt_main(with_gui = self.with_gui)
|
||||||
|
|
||||||
#---------------------------------------------------------------------------------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
loggerclt = logging.getLogger('logclt')
|
loggerclt = logging.getLogger('logclt')
|
||||||
@ -69,13 +80,22 @@ def client_options():
|
|||||||
try:
|
try:
|
||||||
clt_config.update(vars(parser.parse_args()))
|
clt_config.update(vars(parser.parse_args()))
|
||||||
# Check logfile.
|
# Check logfile.
|
||||||
clt_config['logfile'] = check_logfile(clt_config['logfile'], clt_options['lfile']['def'])
|
clt_config['logfile'] = check_logfile(clt_config['logfile'], clt_options['lfile']['def'], where = "clt")
|
||||||
except KmsException as e:
|
except KmsException as e:
|
||||||
pretty_printer(put_text = "{reverse}{red}{bold}%s. Exiting...{end}" %str(e), to_exit = True)
|
pretty_printer(put_text = "{reverse}{red}{bold}%s. Exiting...{end}" %str(e), to_exit = True)
|
||||||
|
|
||||||
def client_check():
|
def client_check():
|
||||||
|
# Check logfile (only for GUI).
|
||||||
|
try:
|
||||||
|
from pykms_GuiBase import clientthread
|
||||||
|
if clientthread.with_gui:
|
||||||
|
clt_config['logfile'] = check_logfile(clt_config['logfile'], clt_options['lfile']['def'], where = "clt")
|
||||||
|
except ImportError:
|
||||||
|
pass
|
||||||
|
|
||||||
# Setup hidden or not messages.
|
# Setup hidden or not messages.
|
||||||
ShellMessage.view = ( False if any(i in ['STDOUT', 'FILESTDOUT'] for i in clt_config['logfile']) else True )
|
ShellMessage.view = ( False if any(i in ['STDOUT', 'FILESTDOUT'] for i in clt_config['logfile']) else True )
|
||||||
|
|
||||||
# Create log.
|
# Create log.
|
||||||
logger_create(loggerclt, clt_config, mode = 'a')
|
logger_create(loggerclt, clt_config, mode = 'a')
|
||||||
|
|
||||||
@ -84,12 +104,12 @@ def client_check():
|
|||||||
try:
|
try:
|
||||||
uuid.UUID(clt_config['cmid'])
|
uuid.UUID(clt_config['cmid'])
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pretty_printer(log_obj = loggerclt.error, to_exit = True,
|
pretty_printer(log_obj = loggerclt.error, to_exit = True, where = "clt",
|
||||||
put_text = "{reverse}{red}{bold}Bad CMID. Exiting...{end}")
|
put_text = "{reverse}{red}{bold}Bad CMID. Exiting...{end}")
|
||||||
# Check machineName.
|
# Check machineName.
|
||||||
if clt_config['machineName'] is not None:
|
if clt_config['machineName'] is not None:
|
||||||
if len(clt_config['machineName']) < 2 or len(clt_config['machineName']) > 63:
|
if len(clt_config['machineName']) < 2 or len(clt_config['machineName']) > 63:
|
||||||
pretty_printer(log_obj = loggerclt.error, to_exit = True,
|
pretty_printer(log_obj = loggerclt.error, to_exit = True, where = "clt",
|
||||||
put_text = "{reverse}{red}{bold}machineName must be between 2 and 63 characters in length. Exiting...{end}")
|
put_text = "{reverse}{red}{bold}machineName must be between 2 and 63 characters in length. Exiting...{end}")
|
||||||
|
|
||||||
clt_config['call_id'] = 1
|
clt_config['call_id'] = 1
|
||||||
@ -131,16 +151,16 @@ def client_create():
|
|||||||
pretty_printer(num_text = [-1, 1], where = "clt")
|
pretty_printer(num_text = [-1, 1], where = "clt")
|
||||||
s.send(RPC_Bind)
|
s.send(RPC_Bind)
|
||||||
except socket.error as e:
|
except socket.error as e:
|
||||||
pretty_printer(log_obj = loggerclt.error, to_exit = True,
|
pretty_printer(log_obj = loggerclt.error, to_exit = True, where = "clt",
|
||||||
put_text = "{reverse}{red}{bold}While sending: %s{end}" %str(e))
|
put_text = "{reverse}{red}{bold}While sending: %s{end}" %str(e))
|
||||||
try:
|
try:
|
||||||
bindResponse = s.recv(1024)
|
bindResponse = s.recv(1024)
|
||||||
if bindResponse == '' or not bindResponse:
|
if bindResponse == '' or not bindResponse:
|
||||||
pretty_printer(log_obj = loggerclt.warning, to_exit = True,
|
pretty_printer(log_obj = loggerclt.warning, to_exit = True, where = "clt",
|
||||||
put_text = "{reverse}{yellow}{bold}No data received.{end}")
|
put_text = "{reverse}{yellow}{bold}No data received.{end}")
|
||||||
pretty_printer(num_text = [-4, 7], where = "clt")
|
pretty_printer(num_text = [-4, 7], where = "clt")
|
||||||
except socket.error as e:
|
except socket.error as e:
|
||||||
pretty_printer(log_obj = loggerclt.error, to_exit = True,
|
pretty_printer(log_obj = loggerclt.error, to_exit = True, where = "clt",
|
||||||
put_text = "{reverse}{red}{bold}While receiving: %s{end}" %str(e))
|
put_text = "{reverse}{red}{bold}While receiving: %s{end}" %str(e))
|
||||||
|
|
||||||
packetType = MSRPCHeader(bindResponse)['type']
|
packetType = MSRPCHeader(bindResponse)['type']
|
||||||
@ -156,13 +176,13 @@ def client_create():
|
|||||||
pretty_printer(num_text = [-1, 12], where = "clt")
|
pretty_printer(num_text = [-1, 12], where = "clt")
|
||||||
s.send(RPC_Actv)
|
s.send(RPC_Actv)
|
||||||
except socket.error as e:
|
except socket.error as e:
|
||||||
pretty_printer(log_obj = loggerclt.error, to_exit = True,
|
pretty_printer(log_obj = loggerclt.error, to_exit = True, where = "clt",
|
||||||
put_text = "{reverse}{red}{bold}While sending: %s{end}" %str(e))
|
put_text = "{reverse}{red}{bold}While sending: %s{end}" %str(e))
|
||||||
try:
|
try:
|
||||||
response = s.recv(1024)
|
response = s.recv(1024)
|
||||||
pretty_printer(num_text = [-4, 20], where = "clt")
|
pretty_printer(num_text = [-4, 20], where = "clt")
|
||||||
except socket.error as e:
|
except socket.error as e:
|
||||||
pretty_printer(log_obj = loggerclt.error, to_exit = True,
|
pretty_printer(log_obj = loggerclt.error, to_exit = True, where = "clt",
|
||||||
put_text = "{reverse}{red}{bold}While receiving: %s{end}" %str(e))
|
put_text = "{reverse}{red}{bold}While receiving: %s{end}" %str(e))
|
||||||
|
|
||||||
loggerclt.debug("Response: \n%s\n" % justify(deco(binascii.b2a_hex(response), 'latin-1')))
|
loggerclt.debug("Response: \n%s\n" % justify(deco(binascii.b2a_hex(response), 'latin-1')))
|
||||||
@ -191,7 +211,7 @@ def client_create():
|
|||||||
loggerclt.info(justify(MSRPCBindNak(bindResponse).dump(print_to_stdout = False)))
|
loggerclt.info(justify(MSRPCBindNak(bindResponse).dump(print_to_stdout = False)))
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
else:
|
else:
|
||||||
pretty_printer(log_obj = loggerclt.warning, to_exit = True,
|
pretty_printer(log_obj = loggerclt.warning, to_exit = True, where = "clt",
|
||||||
put_text = "{reverse}{magenta}{bold}Something went wrong.{end}")
|
put_text = "{reverse}{magenta}{bold}Something went wrong.{end}")
|
||||||
|
|
||||||
def clt_main(with_gui = False):
|
def clt_main(with_gui = False):
|
||||||
|
@ -22,9 +22,8 @@ except ImportError:
|
|||||||
|
|
||||||
from pykms_Server import srv_options, srv_version, srv_config, srv_terminate, serverqueue, serverthread
|
from pykms_Server import srv_options, srv_version, srv_config, srv_terminate, serverqueue, serverthread
|
||||||
from pykms_GuiMisc import ToolTip, TextDoubleScroll, TextRedirect, custom_background
|
from pykms_GuiMisc import ToolTip, TextDoubleScroll, TextRedirect, custom_background
|
||||||
from pykms_Client import clt_options, clt_version, clt_config, clt_main
|
from pykms_Client import clt_options, clt_version, clt_config, client_thread
|
||||||
|
|
||||||
from pykms_Misc import check_logfile
|
|
||||||
gui_description = 'py-kms GUI'
|
gui_description = 'py-kms GUI'
|
||||||
gui_version = 'v1.0'
|
gui_version = 'v1.0'
|
||||||
|
|
||||||
@ -42,26 +41,14 @@ def get_ip_address():
|
|||||||
import socket
|
import socket
|
||||||
ip = socket.gethostbyname(socket.gethostname())
|
ip = socket.gethostbyname(socket.gethostname())
|
||||||
else:
|
else:
|
||||||
ip = ''
|
ip = 'Unknown'
|
||||||
print('Error: Couldn\'t get local ip')
|
|
||||||
return ip
|
return ip
|
||||||
|
|
||||||
def switch_dir(path):
|
|
||||||
if os.path.isdir(path):
|
|
||||||
os.chdir(path)
|
|
||||||
return True
|
|
||||||
|
|
||||||
if path == '':
|
|
||||||
os.chdir(os.getcwd())
|
|
||||||
return True
|
|
||||||
else:
|
|
||||||
return
|
|
||||||
|
|
||||||
def gui_redirect(str_to_print, where):
|
def gui_redirect(str_to_print, where):
|
||||||
global txsrv, txclt, txcol, rclt
|
global txsrv, txclt, txcol
|
||||||
|
|
||||||
try:
|
try:
|
||||||
TextRedirect.StdoutRedirect(txsrv, txclt, txcol, rclt, str_to_print, where)
|
TextRedirect.StdoutRedirect(txsrv, txclt, txcol, str_to_print, where)
|
||||||
except:
|
except:
|
||||||
print(str_to_print)
|
print(str_to_print)
|
||||||
|
|
||||||
@ -79,7 +66,8 @@ class KmsGui(tk.Tk):
|
|||||||
tk.Tk.__init__(self, *args, **kwargs)
|
tk.Tk.__init__(self, *args, **kwargs)
|
||||||
self.wraplength = 200
|
self.wraplength = 200
|
||||||
serverthread.with_gui = True
|
serverthread.with_gui = True
|
||||||
|
self.validation_int = self.register(self.validate_int)
|
||||||
|
|
||||||
## Define fonts and colors.
|
## Define fonts and colors.
|
||||||
self.btnwinfont = tkFont.Font(family = 'Times', size = 12, weight = 'bold')
|
self.btnwinfont = tkFont.Font(family = 'Times', size = 12, weight = 'bold')
|
||||||
self.othfont = tkFont.Font(family = 'Times', size = 9, weight = 'bold')
|
self.othfont = tkFont.Font(family = 'Times', size = 9, weight = 'bold')
|
||||||
@ -105,11 +93,10 @@ class KmsGui(tk.Tk):
|
|||||||
## Create client gui + other operations.
|
## Create client gui + other operations.
|
||||||
self.gui_complete()
|
self.gui_complete()
|
||||||
## Create globals for printing process (redirect stdout).
|
## Create globals for printing process (redirect stdout).
|
||||||
global txsrv, txclt, txcol, rclt
|
global txsrv, txclt, txcol
|
||||||
txsrv = self.textboxsrv.get()
|
txsrv = self.textboxsrv.get()
|
||||||
txclt = self.textboxclt.get()
|
txclt = self.textboxclt.get()
|
||||||
txcol = self.customcolors
|
txcol = self.customcolors
|
||||||
rclt = self.runbtnclt
|
|
||||||
## Redirect stderr.
|
## Redirect stderr.
|
||||||
sys.stderr = TextRedirect.StderrRedirect(txsrv, txclt, txcol)
|
sys.stderr = TextRedirect.StderrRedirect(txsrv, txclt, txcol)
|
||||||
|
|
||||||
@ -154,73 +141,86 @@ class KmsGui(tk.Tk):
|
|||||||
# Version.
|
# Version.
|
||||||
ver = tk.Label(self.optsrvwin, text = 'You are running server version: ' + srv_version, foreground = self.customcolors['red'],
|
ver = tk.Label(self.optsrvwin, text = 'You are running server version: ' + srv_version, foreground = self.customcolors['red'],
|
||||||
font = self.othfont)
|
font = self.othfont)
|
||||||
|
self.allopts_srv = []
|
||||||
# Ip Address.
|
# Ip Address.
|
||||||
ipaddlbl = tk.Label(self.optsrvwin, text = 'IP Address: ', font = self.optfont)
|
srvipaddlbl = tk.Label(self.optsrvwin, text = 'IP Address: ', font = self.optfont)
|
||||||
self.ipadd = tk.Entry(self.optsrvwin, width = 10, font = self.optfont)
|
self.srvipadd = tk.Entry(self.optsrvwin, width = 10, font = self.optfont)
|
||||||
self.ipadd.insert('end', srv_options['ip']['def'])
|
self.srvipadd.insert('end', srv_options['ip']['def'])
|
||||||
ToolTip(self.ipadd, text = srv_options['ip']['help'], wraplength = self.wraplength)
|
ToolTip(self.srvipadd, text = srv_options['ip']['help'], wraplength = self.wraplength)
|
||||||
myipadd = tk.Label(self.optsrvwin, text = 'Your IP address is: {}'.format(get_ip_address()), foreground = self.customcolors['red'],
|
myipadd = tk.Label(self.optsrvwin, text = 'Your IP address is: {}'.format(get_ip_address()), foreground = self.customcolors['red'],
|
||||||
font = self.othfont)
|
font = self.othfont)
|
||||||
|
self.allopts_srv.append(self.srvipadd)
|
||||||
# Port.
|
# Port.
|
||||||
portlbl = tk.Label(self.optsrvwin, text = 'Port: ', font = self.optfont)
|
srvportlbl = tk.Label(self.optsrvwin, text = 'Port: ', font = self.optfont)
|
||||||
self.port = tk.Entry(self.optsrvwin, width = 10, font = self.optfont)
|
self.srvport = tk.Entry(self.optsrvwin, width = 10, font = self.optfont, validate = "key", validatecommand = (self.validation_int, "%S"))
|
||||||
self.port.insert('end', str(srv_options['port']['def']))
|
self.srvport.insert('end', str(srv_options['port']['def']))
|
||||||
ToolTip(self.port, text = srv_options['port']['help'], wraplength = self.wraplength)
|
ToolTip(self.srvport, text = srv_options['port']['help'], wraplength = self.wraplength)
|
||||||
|
self.allopts_srv.append(self.srvport)
|
||||||
# EPID.
|
# EPID.
|
||||||
epidlbl = tk.Label(self.optsrvwin, text = 'EPID: ', font = self.optfont)
|
epidlbl = tk.Label(self.optsrvwin, text = 'EPID: ', font = self.optfont)
|
||||||
self.epid = tk.Entry(self.optsrvwin, width = 10, font = self.optfont)
|
self.epid = tk.Entry(self.optsrvwin, width = 10, font = self.optfont)
|
||||||
self.epid.insert('end', str(srv_options['epid']['def']))
|
self.epid.insert('end', str(srv_options['epid']['def']))
|
||||||
ToolTip(self.epid, text = srv_options['epid']['help'], wraplength = self.wraplength)
|
ToolTip(self.epid, text = srv_options['epid']['help'], wraplength = self.wraplength)
|
||||||
|
self.allopts_srv.append(self.epid)
|
||||||
# LCID.
|
# LCID.
|
||||||
lcidlbl = tk.Label(self.optsrvwin, text = 'LCID: ', font = self.optfont)
|
lcidlbl = tk.Label(self.optsrvwin, text = 'LCID: ', font = self.optfont)
|
||||||
self.lcid = tk.Entry(self.optsrvwin, width = 10, font = self.optfont)
|
self.lcid = tk.Entry(self.optsrvwin, width = 10, font = self.optfont, validate = "key", validatecommand = (self.validation_int, "%S"))
|
||||||
self.lcid.insert('end', str(srv_options['lcid']['def']))
|
self.lcid.insert('end', str(srv_options['lcid']['def']))
|
||||||
ToolTip(self.lcid, text = srv_options['lcid']['help'], wraplength = self.wraplength)
|
ToolTip(self.lcid, text = srv_options['lcid']['help'], wraplength = self.wraplength)
|
||||||
|
self.allopts_srv.append(self.lcid)
|
||||||
# HWID.
|
# HWID.
|
||||||
hwidlbl = tk.Label(self.optsrvwin, text = 'HWID: ', font = self.optfont)
|
hwidlbl = tk.Label(self.optsrvwin, text = 'HWID: ', font = self.optfont)
|
||||||
self.hwid = tk.Entry(self.optsrvwin, width = 10, font = self.optfont)
|
self.hwid = tk.Entry(self.optsrvwin, width = 10, font = self.optfont)
|
||||||
self.hwid.insert('end', srv_options['hwid']['def'])
|
self.hwid.insert('end', srv_options['hwid']['def'])
|
||||||
ToolTip(self.hwid, text = srv_options['hwid']['help'], wraplength = self.wraplength)
|
ToolTip(self.hwid, text = srv_options['hwid']['help'], wraplength = self.wraplength)
|
||||||
|
self.allopts_srv.append(self.hwid)
|
||||||
# Client Count
|
# Client Count
|
||||||
countlbl = tk.Label(self.optsrvwin, text = 'Client Count: ', font = self.optfont)
|
countlbl = tk.Label(self.optsrvwin, text = 'Client Count: ', font = self.optfont)
|
||||||
self.count = tk.Entry(self.optsrvwin, width = 10, font = self.optfont)
|
self.count = tk.Entry(self.optsrvwin, width = 10, font = self.optfont)
|
||||||
self.count.insert('end', str(srv_options['count']['def']))
|
self.count.insert('end', str(srv_options['count']['def']))
|
||||||
ToolTip(self.count, text = srv_options['count']['help'], wraplength = self.wraplength)
|
ToolTip(self.count, text = srv_options['count']['help'], wraplength = self.wraplength)
|
||||||
|
self.allopts_srv.append(self.count)
|
||||||
# Activation Interval.
|
# Activation Interval.
|
||||||
activlbl = tk.Label(self.optsrvwin, text = 'Activation Interval: ', font = self.optfont)
|
activlbl = tk.Label(self.optsrvwin, text = 'Activation Interval: ', font = self.optfont)
|
||||||
self.activ = tk.Entry(self.optsrvwin, width = 10, font = self.optfont)
|
self.activ = tk.Entry(self.optsrvwin, width = 10, font = self.optfont, validate = "key", validatecommand = (self.validation_int, "%S"))
|
||||||
self.activ.insert('end', str(srv_options['activation']['def']))
|
self.activ.insert('end', str(srv_options['activation']['def']))
|
||||||
ToolTip(self.activ, text = srv_options['activation']['help'], wraplength = self.wraplength)
|
ToolTip(self.activ, text = srv_options['activation']['help'], wraplength = self.wraplength)
|
||||||
|
self.allopts_srv.append(self.activ)
|
||||||
# Renewal Interval.
|
# Renewal Interval.
|
||||||
renewlbl = tk.Label(self.optsrvwin, text = 'Activation Interval: ', font = self.optfont)
|
renewlbl = tk.Label(self.optsrvwin, text = 'Activation Interval: ', font = self.optfont)
|
||||||
self.renew = tk.Entry(self.optsrvwin, width = 10, font = self.optfont)
|
self.renew = tk.Entry(self.optsrvwin, width = 10, font = self.optfont, validate = "key", validatecommand = (self.validation_int, "%S"))
|
||||||
self.renew.insert('end', str(srv_options['renewal']['def']))
|
self.renew.insert('end', str(srv_options['renewal']['def']))
|
||||||
ToolTip(self.renew, text = srv_options['renewal']['help'], wraplength = self.wraplength)
|
ToolTip(self.renew, text = srv_options['renewal']['help'], wraplength = self.wraplength)
|
||||||
|
self.allopts_srv.append(self.renew)
|
||||||
# Logfile.
|
# Logfile.
|
||||||
filelbl = tk.Label(self.optsrvwin, text = 'Logfile Path / Name: ', font = self.optfont)
|
srvfilelbl = tk.Label(self.optsrvwin, text = 'Logfile Path / Name: ', font = self.optfont)
|
||||||
self.file = tk.Entry(self.optsrvwin, width = 10, font = self.optfont)
|
self.srvfile = tk.Entry(self.optsrvwin, width = 10, font = self.optfont)
|
||||||
self.file.insert('end', srv_options['lfile']['def'])
|
self.srvfile.insert('end', srv_options['lfile']['def'])
|
||||||
self.file.xview_moveto(1)
|
self.srvfile.xview_moveto(1)
|
||||||
ToolTip(self.file, text = srv_options['lfile']['help'], wraplength = self.wraplength)
|
ToolTip(self.srvfile, text = srv_options['lfile']['help'], wraplength = self.wraplength)
|
||||||
filebtnwin = tk.Button(self.optsrvwin, text = 'Browse', command = lambda: self.browse(self.file, srv_options))
|
self.allopts_srv.append(self.srvfile)
|
||||||
|
filebtnwin = tk.Button(self.optsrvwin, text = 'Browse', command = lambda: self.browse(self.srvfile, srv_options))
|
||||||
|
self.allopts_srv.append(filebtnwin)
|
||||||
# Loglevel.
|
# Loglevel.
|
||||||
levellbl = tk.Label(self.optsrvwin, text = 'Loglevel: ', font = self.optfont)
|
srvlevellbl = tk.Label(self.optsrvwin, text = 'Loglevel: ', font = self.optfont)
|
||||||
self.level = ttk.Combobox(self.optsrvwin, values = tuple(srv_options['llevel']['choi']), width = 10)
|
self.srvlevel = ttk.Combobox(self.optsrvwin, values = tuple(srv_options['llevel']['choi']), width = 10)
|
||||||
self.level.set(srv_options['llevel']['def'])
|
self.srvlevel.set(srv_options['llevel']['def'])
|
||||||
ToolTip(self.level, text = srv_options['llevel']['help'], wraplength = self.wraplength)
|
ToolTip(self.srvlevel, text = srv_options['llevel']['help'], wraplength = self.wraplength)
|
||||||
|
self.allopts_srv.append(self.srvlevel)
|
||||||
# Sqlite database.
|
# Sqlite database.
|
||||||
self.chkval = tk.BooleanVar()
|
self.chkval = tk.BooleanVar()
|
||||||
self.chkval.set(srv_options['sql']['def'])
|
self.chkval.set(srv_options['sql']['def'])
|
||||||
chksql = tk.Checkbutton(self.optsrvwin, text = 'Create Sqlite\nDatabase', font = self.optfont, var = self.chkval)
|
chksql = tk.Checkbutton(self.optsrvwin, text = 'Create Sqlite\nDatabase', font = self.optfont, var = self.chkval)
|
||||||
ToolTip(chksql, text = srv_options['sql']['help'], wraplength = self.wraplength)
|
ToolTip(chksql, text = srv_options['sql']['help'], wraplength = self.wraplength)
|
||||||
|
self.allopts_srv.append(chksql)
|
||||||
|
|
||||||
## Layout widgets (optsrvwin)
|
## Layout widgets (optsrvwin)
|
||||||
ver.grid(row = 0, column = 0, columnspan = 3, padx = 5, pady = 5, sticky = 'ew')
|
ver.grid(row = 0, column = 0, columnspan = 3, padx = 5, pady = 5, sticky = 'ew')
|
||||||
ipaddlbl.grid(row = 1, column = 0, padx = 5, pady = 5, sticky = 'e')
|
srvipaddlbl.grid(row = 1, column = 0, padx = 5, pady = 5, sticky = 'e')
|
||||||
self.ipadd.grid(row = 1, column = 1, padx = 5, pady = 5, sticky = 'ew')
|
self.srvipadd.grid(row = 1, column = 1, padx = 5, pady = 5, sticky = 'ew')
|
||||||
myipadd.grid(row = 2, column = 1, columnspan = 2, padx = 5, pady = 5, sticky = 'ew')
|
myipadd.grid(row = 2, column = 1, columnspan = 2, padx = 5, pady = 5, sticky = 'ew')
|
||||||
portlbl.grid(row = 3, column = 0, padx = 5, pady = 5, sticky = 'e')
|
srvportlbl.grid(row = 3, column = 0, padx = 5, pady = 5, sticky = 'e')
|
||||||
self.port.grid(row = 3, column = 1, padx = 5, pady = 5, sticky = 'ew')
|
self.srvport.grid(row = 3, column = 1, padx = 5, pady = 5, sticky = 'ew')
|
||||||
epidlbl.grid(row = 4, column = 0, padx = 5, pady = 5, sticky = 'e')
|
epidlbl.grid(row = 4, column = 0, padx = 5, pady = 5, sticky = 'e')
|
||||||
self.epid.grid(row = 4, column = 1, padx = 5, pady = 5, sticky = 'ew')
|
self.epid.grid(row = 4, column = 1, padx = 5, pady = 5, sticky = 'ew')
|
||||||
lcidlbl.grid(row = 5, column = 0, padx = 5, pady = 5, sticky = 'e')
|
lcidlbl.grid(row = 5, column = 0, padx = 5, pady = 5, sticky = 'e')
|
||||||
@ -233,11 +233,11 @@ class KmsGui(tk.Tk):
|
|||||||
self.activ.grid(row = 8, column = 1, padx = 5, pady = 5, sticky = 'ew')
|
self.activ.grid(row = 8, column = 1, padx = 5, pady = 5, sticky = 'ew')
|
||||||
renewlbl.grid(row = 9, column = 0, padx = 5, pady = 5, sticky = 'e')
|
renewlbl.grid(row = 9, column = 0, padx = 5, pady = 5, sticky = 'e')
|
||||||
self.renew.grid(row = 9, column = 1, padx = 5, pady = 5, sticky = 'ew')
|
self.renew.grid(row = 9, column = 1, padx = 5, pady = 5, sticky = 'ew')
|
||||||
filelbl.grid(row = 10, column = 0, padx = 5, pady = 5, sticky = 'e')
|
srvfilelbl.grid(row = 10, column = 0, padx = 5, pady = 5, sticky = 'e')
|
||||||
self.file.grid(row = 10, column = 1, padx = 5, pady = 5, sticky = 'ew')
|
self.srvfile.grid(row = 10, column = 1, padx = 5, pady = 5, sticky = 'ew')
|
||||||
filebtnwin.grid(row = 10, column = 2, padx = 5, pady = 5, sticky = 'ew')
|
filebtnwin.grid(row = 10, column = 2, padx = 5, pady = 5, sticky = 'ew')
|
||||||
levellbl.grid(row = 11, column = 0, padx = 5, pady = 5, sticky = 'e')
|
srvlevellbl.grid(row = 11, column = 0, padx = 5, pady = 5, sticky = 'e')
|
||||||
self.level.grid(row = 11, column = 1, padx = 5, pady = 5, sticky = 'ew')
|
self.srvlevel.grid(row = 11, column = 1, padx = 5, pady = 5, sticky = 'ew')
|
||||||
chksql.grid(row = 12, column = 1, padx = 5, pady = 5, sticky = 'ew')
|
chksql.grid(row = 12, column = 1, padx = 5, pady = 5, sticky = 'ew')
|
||||||
|
|
||||||
## Create widgets and layout (msgsrvwin) -----------------------------------------------------------------------------------------------
|
## Create widgets and layout (msgsrvwin) -----------------------------------------------------------------------------------------------
|
||||||
@ -303,43 +303,52 @@ class KmsGui(tk.Tk):
|
|||||||
# Version.
|
# Version.
|
||||||
cltver = tk.Label(self.optcltwin, text = 'You are running client version: ' + clt_version, foreground = self.customcolors['red'],
|
cltver = tk.Label(self.optcltwin, text = 'You are running client version: ' + clt_version, foreground = self.customcolors['red'],
|
||||||
font = self.othfont)
|
font = self.othfont)
|
||||||
|
self.allopts_clt = []
|
||||||
# Ip Address.
|
# Ip Address.
|
||||||
cltipaddlbl = tk.Label(self.optcltwin, text = 'IP Address: ', font = self.optfont)
|
cltipaddlbl = tk.Label(self.optcltwin, text = 'IP Address: ', font = self.optfont)
|
||||||
self.cltipadd = tk.Entry(self.optcltwin, width = 10, font = self.optfont)
|
self.cltipadd = tk.Entry(self.optcltwin, width = 10, font = self.optfont)
|
||||||
self.cltipadd.insert('end', clt_options['ip']['def'])
|
self.cltipadd.insert('end', clt_options['ip']['def'])
|
||||||
ToolTip(self.cltipadd, text = clt_options['ip']['help'], wraplength = self.wraplength)
|
ToolTip(self.cltipadd, text = clt_options['ip']['help'], wraplength = self.wraplength)
|
||||||
|
self.allopts_clt.append(self.cltipadd)
|
||||||
# Port.
|
# Port.
|
||||||
cltportlbl = tk.Label(self.optcltwin, text = 'Port: ', font = self.optfont)
|
cltportlbl = tk.Label(self.optcltwin, text = 'Port: ', font = self.optfont)
|
||||||
self.cltport = tk.Entry(self.optcltwin, width = 10, font = self.optfont)
|
self.cltport = tk.Entry(self.optcltwin, width = 10, font = self.optfont, validate = "key", validatecommand = (self.validation_int, "%S"))
|
||||||
self.cltport.insert('end', str(clt_options['port']['def']))
|
self.cltport.insert('end', str(clt_options['port']['def']))
|
||||||
ToolTip(self.cltport, text = clt_options['port']['help'], wraplength = self.wraplength)
|
ToolTip(self.cltport, text = clt_options['port']['help'], wraplength = self.wraplength)
|
||||||
|
self.allopts_clt.append(self.cltport)
|
||||||
# Mode.
|
# Mode.
|
||||||
cltmodelbl = tk.Label(self.optcltwin, text = 'Mode: ', font = self.optfont)
|
cltmodelbl = tk.Label(self.optcltwin, text = 'Mode: ', font = self.optfont)
|
||||||
self.cltmode = ttk.Combobox(self.optcltwin, values = tuple(clt_options['mode']['choi']), width = 10)
|
self.cltmode = ttk.Combobox(self.optcltwin, values = tuple(clt_options['mode']['choi']), width = 10)
|
||||||
self.cltmode.set(clt_options['mode']['def'])
|
self.cltmode.set(clt_options['mode']['def'])
|
||||||
ToolTip(self.cltmode, text = clt_options['mode']['help'], wraplength = self.wraplength)
|
ToolTip(self.cltmode, text = clt_options['mode']['help'], wraplength = self.wraplength)
|
||||||
|
self.allopts_clt.append(self.cltmode)
|
||||||
# CMID.
|
# CMID.
|
||||||
cltcmidlbl = tk.Label(self.optcltwin, text = 'CMID: ', font = self.optfont)
|
cltcmidlbl = tk.Label(self.optcltwin, text = 'CMID: ', font = self.optfont)
|
||||||
self.cltcmid = tk.Entry(self.optcltwin, width = 10, font = self.optfont)
|
self.cltcmid = tk.Entry(self.optcltwin, width = 10, font = self.optfont)
|
||||||
self.cltcmid.insert('end', str(clt_options['cmid']['def']))
|
self.cltcmid.insert('end', str(clt_options['cmid']['def']))
|
||||||
ToolTip(self.cltcmid, text = clt_options['cmid']['help'], wraplength = self.wraplength)
|
ToolTip(self.cltcmid, text = clt_options['cmid']['help'], wraplength = self.wraplength)
|
||||||
|
self.allopts_clt.append(self.cltcmid)
|
||||||
# Machine Name.
|
# Machine Name.
|
||||||
cltnamelbl = tk.Label(self.optcltwin, text = 'Machine Name: ', font = self.optfont)
|
cltnamelbl = tk.Label(self.optcltwin, text = 'Machine Name: ', font = self.optfont)
|
||||||
self.cltname = tk.Entry(self.optcltwin, width = 10, font = self.optfont)
|
self.cltname = tk.Entry(self.optcltwin, width = 10, font = self.optfont)
|
||||||
self.cltname.insert('end', str(clt_options['name']['def']))
|
self.cltname.insert('end', str(clt_options['name']['def']))
|
||||||
ToolTip(self.cltname, text = clt_options['name']['help'], wraplength = self.wraplength)
|
ToolTip(self.cltname, text = clt_options['name']['help'], wraplength = self.wraplength)
|
||||||
|
self.allopts_clt.append(self.cltname)
|
||||||
# Logfile.
|
# Logfile.
|
||||||
cltfilelbl = tk.Label(self.optcltwin, text = 'Logfile Path / Name: ', font = self.optfont)
|
cltfilelbl = tk.Label(self.optcltwin, text = 'Logfile Path / Name: ', font = self.optfont)
|
||||||
self.cltfile = tk.Entry(self.optcltwin, width = 10, font = self.optfont)
|
self.cltfile = tk.Entry(self.optcltwin, width = 10, font = self.optfont)
|
||||||
self.cltfile.insert('end', clt_options['lfile']['def'])
|
self.cltfile.insert('end', clt_options['lfile']['def'])
|
||||||
self.cltfile.xview_moveto(1)
|
self.cltfile.xview_moveto(1)
|
||||||
ToolTip(self.cltfile, text = clt_options['lfile']['help'], wraplength = self.wraplength)
|
ToolTip(self.cltfile, text = clt_options['lfile']['help'], wraplength = self.wraplength)
|
||||||
|
self.allopts_clt.append(self.cltfile)
|
||||||
cltfilebtnwin = tk.Button(self.optcltwin, text = 'Browse', command = lambda: self.browse(self.cltfile, clt_options))
|
cltfilebtnwin = tk.Button(self.optcltwin, text = 'Browse', command = lambda: self.browse(self.cltfile, clt_options))
|
||||||
|
self.allopts_clt.append(cltfilebtnwin)
|
||||||
# Loglevel.
|
# Loglevel.
|
||||||
cltlevellbl = tk.Label(self.optcltwin, text = 'Loglevel: ', font = self.optfont)
|
cltlevellbl = tk.Label(self.optcltwin, text = 'Loglevel: ', font = self.optfont)
|
||||||
self.cltlevel = ttk.Combobox(self.optcltwin, values = tuple(clt_options['llevel']['choi']), width = 10)
|
self.cltlevel = ttk.Combobox(self.optcltwin, values = tuple(clt_options['llevel']['choi']), width = 10)
|
||||||
self.cltlevel.set(clt_options['llevel']['def'])
|
self.cltlevel.set(clt_options['llevel']['def'])
|
||||||
ToolTip(self.cltlevel, text = clt_options['llevel']['help'], wraplength = self.wraplength)
|
ToolTip(self.cltlevel, text = clt_options['llevel']['help'], wraplength = self.wraplength)
|
||||||
|
self.allopts_clt.append(self.cltlevel)
|
||||||
|
|
||||||
# Layout widgets (optcltwin)
|
# Layout widgets (optcltwin)
|
||||||
cltver.grid(row = 0, column = 0, columnspan = 3, padx = 5, pady = 5, sticky = 'ew')
|
cltver.grid(row = 0, column = 0, columnspan = 3, padx = 5, pady = 5, sticky = 'ew')
|
||||||
@ -364,12 +373,28 @@ class KmsGui(tk.Tk):
|
|||||||
relief = 'ridge', font = self.msgfont)
|
relief = 'ridge', font = self.msgfont)
|
||||||
self.textboxclt.put()
|
self.textboxclt.put()
|
||||||
|
|
||||||
def proper_none(self, value):
|
def prep_option(self, value):
|
||||||
value = None if value == 'None' else value
|
value = None if value == 'None' else value
|
||||||
try:
|
try:
|
||||||
return int(value)
|
return int(value)
|
||||||
except TypeError:
|
except (TypeError, ValueError):
|
||||||
|
# is NONE or is a STRING.
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
def prep_logfile(self, optionlog):
|
||||||
|
if optionlog.startswith('FILESTDOUT '):
|
||||||
|
split = optionlog.split('FILESTDOUT ')
|
||||||
|
split[0] = 'FILESTDOUT'
|
||||||
|
return split
|
||||||
|
elif optionlog.startswith('STDOUT '):
|
||||||
|
split = optionlog.split('STDOUT ')
|
||||||
|
split[0] = 'STDOUT'
|
||||||
|
return split
|
||||||
|
else:
|
||||||
|
return optionlog
|
||||||
|
|
||||||
|
def validate_int(self, value):
|
||||||
|
return value.isdigit()
|
||||||
|
|
||||||
def clt_on_show(self, force = False):
|
def clt_on_show(self, force = False):
|
||||||
if self.optcltwin.winfo_ismapped() or force:
|
if self.optcltwin.winfo_ismapped() or force:
|
||||||
@ -385,16 +410,17 @@ class KmsGui(tk.Tk):
|
|||||||
|
|
||||||
def srv_on_start(self):
|
def srv_on_start(self):
|
||||||
if self.runbtnsrv['text'] == 'START\nSERVER':
|
if self.runbtnsrv['text'] == 'START\nSERVER':
|
||||||
if self.srv_actions_start():
|
self.srv_actions_start()
|
||||||
self.on_clear([txsrv, txclt])
|
# wait for switch.
|
||||||
self.runbtnsrv.configure(text = 'STOP\nSERVER', background = self.customcolors['red'],
|
while not serverthread.is_running_server:
|
||||||
foreground = self.customcolors['white'])
|
pass
|
||||||
self.runbtnclt.configure(state = 'normal')
|
|
||||||
|
|
||||||
# run thread for interrupting.
|
self.on_clear([txsrv, txclt])
|
||||||
self.ejectthread = threading.Thread(target = self.srv_eject, name = "Thread-Ejt")
|
self.srv_toggle_all(on_start = True)
|
||||||
self.ejectthread.setDaemon(True)
|
# run thread for interrupting server when an error happens.
|
||||||
self.ejectthread.start()
|
self.srv_eject_thread = threading.Thread(target = self.srv_eject, name = "Thread-SrvEjt")
|
||||||
|
self.srv_eject_thread.setDaemon(True)
|
||||||
|
self.srv_eject_thread.start()
|
||||||
|
|
||||||
elif self.runbtnsrv['text'] == 'STOP\nSERVER':
|
elif self.runbtnsrv['text'] == 'STOP\nSERVER':
|
||||||
serverthread.terminate_eject()
|
serverthread.terminate_eject()
|
||||||
@ -405,49 +431,51 @@ class KmsGui(tk.Tk):
|
|||||||
self.srv_actions_stop()
|
self.srv_actions_stop()
|
||||||
|
|
||||||
def srv_actions_start(self):
|
def srv_actions_start(self):
|
||||||
ok = False
|
srv_config[srv_options['ip']['des']] = self.srvipadd.get()
|
||||||
if switch_dir(os.path.dirname(self.file.get())):
|
srv_config[srv_options['port']['des']] = self.prep_option(self.srvport.get())
|
||||||
if self.file.get().lower().endswith('.log'):
|
srv_config[srv_options['epid']['des']] = self.prep_option(self.epid.get())
|
||||||
# Load dict.
|
srv_config[srv_options['lcid']['des']] = self.prep_option(self.lcid.get())
|
||||||
srv_config[srv_options['ip']['des']] = self.ipadd.get()
|
srv_config[srv_options['hwid']['des']] = self.hwid.get()
|
||||||
srv_config[srv_options['port']['des']] = int(self.port.get())
|
srv_config[srv_options['count']['des']] = self.prep_option(self.count.get())
|
||||||
srv_config[srv_options['epid']['des']] = self.proper_none(self.epid.get())
|
srv_config[srv_options['activation']['des']] = self.prep_option(self.activ.get())
|
||||||
srv_config[srv_options['lcid']['des']] = int(self.lcid.get())
|
srv_config[srv_options['renewal']['des']] = self.prep_option(self.renew.get())
|
||||||
srv_config[srv_options['hwid']['des']] = self.hwid.get()
|
srv_config[srv_options['lfile']['des']] = self.prep_logfile(self.srvfile.get())
|
||||||
srv_config[srv_options['count']['des']] = self.proper_none(self.count.get())
|
srv_config[srv_options['llevel']['des']] = self.srvlevel.get()
|
||||||
srv_config[srv_options['activation']['des']] = int(self.activ.get())
|
srv_config[srv_options['sql']['des']] = self.chkval.get()
|
||||||
srv_config[srv_options['renewal']['des']] = int(self.renew.get())
|
|
||||||
srv_config[srv_options['lfile']['des']] = check_logfile(self.file.get(), srv_options['lfile']['def'])
|
|
||||||
srv_config[srv_options['llevel']['des']] = self.level.get()
|
|
||||||
srv_config[srv_options['sql']['des']] = self.chkval.get()
|
|
||||||
## TODO.
|
|
||||||
srv_config[srv_options['lsize']['des']] = 0
|
|
||||||
srv_config[srv_options['time']['des']] = None
|
|
||||||
|
|
||||||
serverqueue.put('start')
|
## TODO.
|
||||||
# wait for switch.
|
srv_config[srv_options['lsize']['des']] = 0
|
||||||
while not serverthread.is_running_server:
|
srv_config[srv_options['time']['des']] = None
|
||||||
pass
|
|
||||||
self.srv_toggle()
|
serverqueue.put('start')
|
||||||
ok = True
|
|
||||||
else:
|
|
||||||
messagebox.showerror('Invalid extension', 'Not a .log file !')
|
|
||||||
else:
|
|
||||||
messagebox.showerror('Invalid path', 'Path you have provided not found !')
|
|
||||||
return ok
|
|
||||||
|
|
||||||
def srv_actions_stop(self):
|
def srv_actions_stop(self):
|
||||||
if serverthread.is_running_server:
|
if serverthread.is_running_server:
|
||||||
srv_terminate(exit_server = True)
|
if serverthread.server is not None:
|
||||||
# wait for switch.
|
srv_terminate(exit_server = True)
|
||||||
while serverthread.is_running_server:
|
# wait for switch.
|
||||||
pass
|
while serverthread.is_running_server:
|
||||||
self.srv_toggle()
|
pass
|
||||||
self.runbtnsrv.configure(text = 'START\nSERVER', background = self.customcolors['green'],
|
else:
|
||||||
|
serverthread.is_running_server = False
|
||||||
|
self.srv_toggle_all(on_start = False)
|
||||||
|
|
||||||
|
def srv_toggle_all(self, on_start = True):
|
||||||
|
self.srv_toggle_state()
|
||||||
|
if on_start:
|
||||||
|
self.runbtnsrv.configure(text = 'STOP\nSERVER', background = self.customcolors['red'],
|
||||||
foreground = self.customcolors['white'])
|
foreground = self.customcolors['white'])
|
||||||
|
for widget in self.allopts_srv:
|
||||||
|
widget.configure(state = 'disabled')
|
||||||
|
self.runbtnclt.configure(state = 'normal')
|
||||||
|
else:
|
||||||
|
self.runbtnsrv.configure(text = 'START\nSERVER', background = self.customcolors['green'],
|
||||||
|
foreground = self.customcolors['white'])
|
||||||
|
for widget in self.allopts_srv:
|
||||||
|
widget.configure(state = 'normal')
|
||||||
self.runbtnclt.configure(state = 'disabled')
|
self.runbtnclt.configure(state = 'disabled')
|
||||||
|
|
||||||
def srv_toggle(self):
|
def srv_toggle_state(self):
|
||||||
if serverthread.is_running_server:
|
if serverthread.is_running_server:
|
||||||
txt, color = ('Server\nState:\nServing', self.customcolors['green'])
|
txt, color = ('Server\nState:\nServing', self.customcolors['green'])
|
||||||
else:
|
else:
|
||||||
@ -456,35 +484,47 @@ class KmsGui(tk.Tk):
|
|||||||
self.statesrv.configure(text = txt, foreground = color)
|
self.statesrv.configure(text = txt, foreground = color)
|
||||||
|
|
||||||
def clt_on_start(self):
|
def clt_on_start(self):
|
||||||
self.on_clear([txsrv, txclt])
|
|
||||||
self.clt_actions_start()
|
self.clt_actions_start()
|
||||||
|
# run thread for disable interrupting server and client, when client running.
|
||||||
|
self.clt_eject_thread = threading.Thread(target = self.clt_eject, name = "Thread-CltEjt")
|
||||||
|
self.clt_eject_thread.setDaemon(True)
|
||||||
|
self.clt_eject_thread.start()
|
||||||
|
|
||||||
|
self.on_clear([txsrv, txclt])
|
||||||
|
for widget in self.allopts_clt + [self.runbtnsrv, self.runbtnclt]:
|
||||||
|
widget.configure(state = 'disabled')
|
||||||
|
|
||||||
def clt_actions_start(self):
|
def clt_actions_start(self):
|
||||||
if switch_dir(os.path.dirname(self.cltfile.get())):
|
clt_config[clt_options['ip']['des']] = self.cltipadd.get()
|
||||||
if self.cltfile.get().lower().endswith('.log'):
|
clt_config[clt_options['port']['des']] = self.prep_option(self.cltport.get())
|
||||||
# Load dict.
|
clt_config[clt_options['mode']['des']] = self.cltmode.get()
|
||||||
clt_config[clt_options['ip']['des']] = self.cltipadd.get()
|
clt_config[clt_options['cmid']['des']] = self.prep_option(self.cltcmid.get())
|
||||||
clt_config[clt_options['port']['des']] = int(self.cltport.get())
|
clt_config[clt_options['name']['des']] = self.prep_option(self.cltname.get())
|
||||||
clt_config[clt_options['mode']['des']] = self.cltmode.get()
|
clt_config[clt_options['llevel']['des']] = self.cltlevel.get()
|
||||||
clt_config[clt_options['cmid']['des']] = self.proper_none(self.cltcmid.get())
|
clt_config[clt_options['lfile']['des']] = self.prep_logfile(self.cltfile.get())
|
||||||
clt_config[clt_options['name']['des']] = self.proper_none(self.cltname.get())
|
|
||||||
clt_config[clt_options['lfile']['des']] = check_logfile(self.cltfile.get(), clt_options['lfile']['def'])
|
|
||||||
clt_config[clt_options['llevel']['des']] = self.cltlevel.get()
|
|
||||||
## TODO
|
|
||||||
clt_config[clt_options['lsize']['des']] = 0
|
|
||||||
|
|
||||||
|
## TODO.
|
||||||
self.clientthread = threading.Thread(target = clt_main, name = 'Thread-Clt', args=(True,))
|
clt_config[clt_options['lsize']['des']] = 0
|
||||||
self.clientthread.setDaemon(True)
|
|
||||||
self.clientthread.start()
|
# run client (in a thread).
|
||||||
else:
|
global clientthread
|
||||||
messagebox.showerror('Invalid extension', 'Not a .log file !')
|
clientthread = client_thread(name = "Thread-Clt")
|
||||||
else:
|
clientthread.setDaemon(True)
|
||||||
messagebox.showerror('Invalid path', 'Path you have provided not found !')
|
clientthread.with_gui = True
|
||||||
|
clientthread.start()
|
||||||
|
|
||||||
|
def clt_eject(self):
|
||||||
|
while clientthread.is_alive():
|
||||||
|
sleep(0.1)
|
||||||
|
for widget in self.allopts_clt + [self.runbtnsrv, self.runbtnclt]:
|
||||||
|
widget.configure(state = 'normal')
|
||||||
|
|
||||||
def on_exit(self):
|
def on_exit(self):
|
||||||
if serverthread.is_running_server:
|
if serverthread.is_running_server:
|
||||||
srv_terminate(exit_server = True)
|
if serverthread.server is not None:
|
||||||
|
srv_terminate(exit_server = True)
|
||||||
|
else:
|
||||||
|
serverthread.is_running_server = False
|
||||||
srv_terminate(exit_thread = True)
|
srv_terminate(exit_thread = True)
|
||||||
self.destroy()
|
self.destroy()
|
||||||
|
|
||||||
|
@ -137,12 +137,10 @@ class TextRedirect(object):
|
|||||||
msg_align = [ msg[0].replace('\t', '').replace('\n', '') for msg in unformat_message([MsgMap[-2], MsgMap[-4]])]
|
msg_align = [ msg[0].replace('\t', '').replace('\n', '') for msg in unformat_message([MsgMap[-2], MsgMap[-4]])]
|
||||||
newlinecut = [-1, -2, -4, -5]
|
newlinecut = [-1, -2, -4, -5]
|
||||||
|
|
||||||
def __init__(self, srv_text_space, clt_text_space, customcolors, runclt, str_to_print, where):
|
def __init__(self, srv_text_space, clt_text_space, customcolors, str_to_print, where):
|
||||||
self.srv_text_space = srv_text_space
|
self.srv_text_space = srv_text_space
|
||||||
self.clt_text_space = clt_text_space
|
self.clt_text_space = clt_text_space
|
||||||
self.customcolors = customcolors
|
self.customcolors = customcolors
|
||||||
self.runclt = runclt
|
|
||||||
self.runclt.configure(state = 'disabled')
|
|
||||||
self.str_to_print = str_to_print
|
self.str_to_print = str_to_print
|
||||||
self.where = where
|
self.where = where
|
||||||
self.textbox_do()
|
self.textbox_do()
|
||||||
@ -151,7 +149,6 @@ class TextRedirect(object):
|
|||||||
if message == self.terminator:
|
if message == self.terminator:
|
||||||
TextRedirect.StdoutRedirect.tag_num = 0
|
TextRedirect.StdoutRedirect.tag_num = 0
|
||||||
TextRedirect.StdoutRedirect.newlinecut = [-1, -2, -4, -5]
|
TextRedirect.StdoutRedirect.newlinecut = [-1, -2, -4, -5]
|
||||||
self.runclt.configure(state = 'normal')
|
|
||||||
|
|
||||||
def textbox_write(self, tag, message, color, extras):
|
def textbox_write(self, tag, message, color, extras):
|
||||||
widget = self.textbox_choose(message)
|
widget = self.textbox_choose(message)
|
||||||
@ -231,9 +228,9 @@ class TextRedirect(object):
|
|||||||
self.clt_text_space = clt_text_space
|
self.clt_text_space = clt_text_space
|
||||||
self.customcolors = customcolors
|
self.customcolors = customcolors
|
||||||
self.tag_err = 'STDERR'
|
self.tag_err = 'STDERR'
|
||||||
|
self.xfont = tkFont.Font(font = self.srv_text_space['font'])
|
||||||
|
|
||||||
def write(self, string):
|
def write(self, string):
|
||||||
self.textbox_clear()
|
|
||||||
self.textbox_color(self.tag_err, self.srv_text_space, self.customcolors['red'], self.customcolors['black'])
|
self.textbox_color(self.tag_err, self.srv_text_space, self.customcolors['red'], self.customcolors['black'])
|
||||||
self.srv_text_space.configure(state = 'normal')
|
self.srv_text_space.configure(state = 'normal')
|
||||||
self.srv_text_space.insert('end', string, self.tag_err)
|
self.srv_text_space.insert('end', string, self.tag_err)
|
||||||
|
@ -133,20 +133,25 @@ def logger_create(log_obj, config, mode = 'a'):
|
|||||||
|
|
||||||
#----------------------------------------------------------------------------------------------------------------------------------------------------------
|
#----------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
def check_logfile(optionlog, defaultlog):
|
def check_logfile(optionlog, defaultlog, where):
|
||||||
if not isinstance(optionlog, list):
|
if not isinstance(optionlog, list):
|
||||||
optionlog = [optionlog]
|
optionlog = [optionlog]
|
||||||
|
|
||||||
lenopt = len(optionlog)
|
lenopt = len(optionlog)
|
||||||
msg_dir = "{reverse}{red}{bold}argument logfile: no such file or directory: %s. Exiting...{end}"
|
msg_dir = "{reverse}{red}{bold}argument logfile: invalid directory: '%s'. Exiting...{end}"
|
||||||
msg_long = "{reverse}{red}{bold}argument logfile: too much arguments. Exiting...{end}"
|
msg_long = "{reverse}{red}{bold}argument logfile: too much arguments. Exiting...{end}"
|
||||||
|
msg_log = "{reverse}{red}{bold}argument logfile: not a log file, invalid extension: '%s'. Exiting...{end}"
|
||||||
|
|
||||||
def checkdir(path):
|
def checkdir(path):
|
||||||
if not os.path.isdir(os.path.dirname(path)):
|
filename = os.path.basename(path)
|
||||||
pretty_printer(put_text = msg_dir %path, to_exit = True)
|
pathname = os.path.dirname(path)
|
||||||
|
if not os.path.isdir(pathname):
|
||||||
|
pretty_printer(put_text = msg_dir %pathname, where = where, to_exit = True)
|
||||||
|
elif not filename.lower().endswith('.log'):
|
||||||
|
pretty_printer(put_text = msg_log %filename, where = where, to_exit = True)
|
||||||
|
|
||||||
if lenopt > 2:
|
if lenopt > 2:
|
||||||
pretty_printer(put_text = msg_long, to_exit = True)
|
pretty_printer(put_text = msg_long, where = where, to_exit = True)
|
||||||
|
|
||||||
if 'FILESTDOUT' in optionlog:
|
if 'FILESTDOUT' in optionlog:
|
||||||
if lenopt == 1:
|
if lenopt == 1:
|
||||||
@ -157,7 +162,7 @@ def check_logfile(optionlog, defaultlog):
|
|||||||
checkdir(optionlog[1])
|
checkdir(optionlog[1])
|
||||||
else:
|
else:
|
||||||
if lenopt == 2:
|
if lenopt == 2:
|
||||||
pretty_printer(put_text = msg_long, to_exit = True)
|
pretty_printer(put_text = msg_long, where = where, to_exit = True)
|
||||||
elif lenopt == 1 and 'STDOUT' not in optionlog:
|
elif lenopt == 1 and 'STDOUT' not in optionlog:
|
||||||
# check directory path.
|
# check directory path.
|
||||||
checkdir(optionlog[0])
|
checkdir(optionlog[0])
|
||||||
|
@ -105,8 +105,9 @@ class KeyServer(socketserver.ThreadingMixIn, socketserver.TCPServer):
|
|||||||
|
|
||||||
|
|
||||||
class server_thread(threading.Thread):
|
class server_thread(threading.Thread):
|
||||||
def __init__(self, queue):
|
def __init__(self, queue, name):
|
||||||
threading.Thread.__init__(self)
|
threading.Thread.__init__(self)
|
||||||
|
self.name = name
|
||||||
self.queue = queue
|
self.queue = queue
|
||||||
self.server = None
|
self.server = None
|
||||||
self.is_running_server, self.with_gui = [False for _ in range(2)]
|
self.is_running_server, self.with_gui = [False for _ in range(2)]
|
||||||
@ -210,13 +211,18 @@ def server_options():
|
|||||||
try:
|
try:
|
||||||
srv_config.update(vars(parser.parse_args()))
|
srv_config.update(vars(parser.parse_args()))
|
||||||
# Check logfile.
|
# Check logfile.
|
||||||
srv_config['logfile'] = check_logfile(srv_config['logfile'], srv_options['lfile']['def'])
|
srv_config['logfile'] = check_logfile(srv_config['logfile'], srv_options['lfile']['def'], where = "srv")
|
||||||
except KmsException as e:
|
except KmsException as e:
|
||||||
pretty_printer(put_text = "{reverse}{red}{bold}%s. Exiting...{end}" %str(e), to_exit = True)
|
pretty_printer(put_text = "{reverse}{red}{bold}%s. Exiting...{end}" %str(e), to_exit = True)
|
||||||
|
|
||||||
def server_check():
|
def server_check():
|
||||||
|
# Check logfile (only for GUI).
|
||||||
|
if serverthread.with_gui:
|
||||||
|
srv_config['logfile'] = check_logfile(srv_config['logfile'], srv_options['lfile']['def'], where = "srv")
|
||||||
|
|
||||||
# Setup hidden or not messages.
|
# Setup hidden or not messages.
|
||||||
ShellMessage.view = ( False if any(i in ['STDOUT', 'FILESTDOUT'] for i in srv_config['logfile']) else True )
|
ShellMessage.view = ( False if any(i in ['STDOUT', 'FILESTDOUT'] for i in srv_config['logfile']) else True )
|
||||||
|
|
||||||
# Create log.
|
# Create log.
|
||||||
logger_create(loggersrv, srv_config, mode = 'a')
|
logger_create(loggersrv, srv_config, mode = 'a')
|
||||||
|
|
||||||
@ -304,6 +310,8 @@ def srv_main_with_gui(width = 950, height = 660):
|
|||||||
x = (ws / 2) - (width / 2)
|
x = (ws / 2) - (width / 2)
|
||||||
y = (hs / 2) - (height / 2)
|
y = (hs / 2) - (height / 2)
|
||||||
root.geometry('+%d+%d' %(x, y))
|
root.geometry('+%d+%d' %(x, y))
|
||||||
|
# disable maximize button.
|
||||||
|
root.resizable(0, 0)
|
||||||
root.mainloop()
|
root.mainloop()
|
||||||
|
|
||||||
class kmsServerHandler(socketserver.BaseRequestHandler):
|
class kmsServerHandler(socketserver.BaseRequestHandler):
|
||||||
@ -362,7 +370,7 @@ class kmsServerHandler(socketserver.BaseRequestHandler):
|
|||||||
|
|
||||||
|
|
||||||
serverqueue = Queue.Queue(maxsize = 0)
|
serverqueue = Queue.Queue(maxsize = 0)
|
||||||
serverthread = server_thread(serverqueue)
|
serverthread = server_thread(serverqueue, name = "Thread-Srv")
|
||||||
serverthread.setDaemon(True)
|
serverthread.setDaemon(True)
|
||||||
serverthread.start()
|
serverthread.start()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user