diff --git a/CHANGELOG.md b/CHANGELOG.md index ff90fa5..10d1c82 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +### py-kms_2020-02-02 +- Optimized pretty-print messages process. +- Added -F FILESTDOUT option. +- Added deamonization options (via [Etrigan](https://github.com/SystemRage/Etrigan) project). +- py-kms GUI resurrected (and improved). +- Cleaned, cleaned, cleaned. + ### py-kms_2019-05-15 - Merging for Python2 / Python3 compatibility all-in-one. - Added new options: diff --git a/README.md b/README.md index 74cbcce..7d76c9d 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ _py-kms_ is a port of node-kms created by [cyrozap](http://forums.mydigitallife. - Windows 7 - Windows 8 - Windows 8.1 - - Windows 10 ( 1511 / 1607 / 1703 / 1709 / 1803 / 1809 / 1903 ) + - Windows 10 ( 1511 / 1607 / 1703 / 1709 / 1803 / 1809 / 1903 / 1909 ) - Windows Server 2008 - Windows Server 2008 R2 - Windows Server 2012 @@ -39,16 +39,19 @@ _py-kms_ is a port of node-kms created by [cyrozap](http://forums.mydigitallife. # Usage - __NOTE__: Pay attention to how invoke scripts, if you want to run with python2 use ```python...``` while for python3 use ```python3...```, also depending on the Python versions that resides in your PC. -- To start the server, execute ```python pykms_Server.py [IPADDRESS] [PORT]```. - The default _IPADDRESS_ is "0.0.0.0" ( all interfaces ) and the default _PORT_ is "1688". -- To run the client (only for testing purposes), use ```python pykms_Client.py IPADDRESS [PORT]```. -Argument _IPADDRESS_ is always required, while the default _PORT_ is "1688", so a valid command is: ```python pykms_Client.py 0.0.0.0``` -- To show the help pages type: ```python pykms_Server.py -h``` and ```python pykms_Client.py -h``` -- To generate a random HWID use ```-w``` option: ```python pykms_Server.py -w RANDOM``` -- To get the HWID from any server use the client, for example type: ```python pykms_Client.py 0.0.0.0 1688 -m Windows8.1 -V INFO``` -- To view a minimal set of logging information use ```-V MINI``` option, for example: ```python pykms_Server.py -V MINI``` -- To redirect logging on stdout use ```-F STDOUT``` option, for example: ```python pykms_Server.py -F STDOUT``` -- For launching py-kms GUI make executable all _.py_ files in _py-kms_ directory ```chmod +x /path/to/scripts/py-kms/*.py```, then simply run ```pykms_Server.py``` double-clicking. +- To start the server, execute ```python pykms_Server.py [IPADDRESS] [PORT]```, the default _IPADDRESS_ is "0.0.0.0" ( all interfaces ) and the default _PORT_ is "1688". +- To run the client (only for testing purposes), use ```python pykms_Client.py [IPADDRESS] [PORT]```, with the same defaults of ```pykms_Server.py```. +- To show the help pages type: ```python pykms_Server.py -h``` and ```python pykms_Client.py -h```. +- To generate a random HWID use ```-w``` option: ```python pykms_Server.py -w RANDOM```. +- To get the HWID from any server use the client, for example type: ```python pykms_Client.py 0.0.0.0 1688 -m Windows8.1 -V INFO```. +- To view a minimal set of logging information use ```-V MINI``` option, for example: ```python pykms_Server.py -F /path/to/your/logfile.log -V MINI```. +- To redirect logging on stdout use ```-F STDOUT``` option, for example: ```python pykms_Server.py -F STDOUT -V DEBUG```. +- You can create logfile and view logging information on stdout at the same time with ```-F FILESTDOUT``` option, for example: ```python pykms_Server.py -F FILESTDOUT /path/to/your/logfile.log -V DEBUG```. +- Select timeout (seconds) for py-kms with ```-t``` option, for example ```python pykms_Server.py -t 10``` +- For launching py-kms GUI make executable ```pykms_Server.py``` file with ```chmod +x /path/to/folder/py-kms/pykms_Server.py```, then simply run ```pykms_Server.py``` double-clicking. +- You can run py-kms deamonized (via [Etrigan](https://github.com/SystemRage/Etrigan)) using a command like: ```python pykms_Server.py etrigan start``` and stop it with: ```python pykms_Server.py etrigan stop```. +- With Etrigan you have another way to launch py-kms GUI (specially suitable if you're using a virtualenv), so: ```python pykms_Server.py etrigan start -g``` +and stop the GUI with the same precedent command (or interact with EXIT button). # Other Important Stuff Consult the [Wiki](https://github.com/SystemRage/py-kms/wiki) for more information about activation with _py-kms_ and to get GVLK keys. diff --git a/py-kms/pykms_Client.py b/py-kms/pykms_Client.py index 01ab761..f208680 100644 --- a/py-kms/pykms_Client.py +++ b/py-kms/pykms_Client.py @@ -22,7 +22,7 @@ from pykms_RequestV6 import kmsRequestV6 from pykms_RpcBase import rpcBase from pykms_DB2Dict import kmsDB2Dict from pykms_Misc import logger_create, check_logfile -from pykms_Misc import KmsParser, KmsException +from pykms_Misc import KmsParser, KmsException, KmsHelper from pykms_Format import justify, byterize, enco, deco, ShellMessage, pretty_printer clt_version = "py-kms_2020-02-02" @@ -66,35 +66,39 @@ log info on stdout. Type \"FILESTDOUT\" to combine previous actions.', } def client_options(): - parser = KmsParser(description = clt_description, epilog = 'version: ' + clt_version) - parser.add_argument("ip", nargs = "?", action = "store", default = clt_options['ip']['def'], help = clt_options['ip']['help'], type = str) - parser.add_argument("port", nargs = "?", action = "store", default = clt_options['port']['def'], help = clt_options['port']['help'], type = int) - parser.add_argument("-m", "--mode", dest = clt_options['mode']['des'], default = clt_options['mode']['def'], choices = clt_options['mode']['choi'], - help = clt_options['mode']['help'], type = str) - parser.add_argument("-c", "--cmid", dest = clt_options['cmid']['des'], default = clt_options['cmid']['def'], help = clt_options['cmid']['help'], type = str) - parser.add_argument("-n", "--name", dest = clt_options['name']['des'] , default = clt_options['name']['def'], help = clt_options['name']['help'], type = str) - parser.add_argument("-V", "--loglevel", dest = clt_options['llevel']['des'], action = "store", choices = clt_options['llevel']['choi'], - default = clt_options['llevel']['def'], help = clt_options['llevel']['help'], type = str) - parser.add_argument("-F", "--logfile", nargs = "+", action = "store", dest = clt_options['lfile']['des'], default = clt_options['lfile']['def'], - help = clt_options['lfile']['help'], type = str) - parser.add_argument("-S", "--logsize", dest = clt_options['lsize']['des'], action = "store", default = clt_options['lsize']['def'], - help = clt_options['lsize']['help'], type = float) + try: + client_parser = KmsParser(description = clt_description, epilog = 'version: ' + clt_version, add_help = False, allow_abbrew = False) + except TypeError: + client_parser = KmsParser(description = clt_description, epilog = 'version: ' + clt_version, add_help = False) + client_parser.add_argument("ip", nargs = "?", action = "store", default = clt_options['ip']['def'], + help = clt_options['ip']['help'], type = str) + client_parser.add_argument("port", nargs = "?", action = "store", default = clt_options['port']['def'], + help = clt_options['port']['help'], type = int) + client_parser.add_argument("-m", "--mode", dest = clt_options['mode']['des'], default = clt_options['mode']['def'], + choices = clt_options['mode']['choi'], help = clt_options['mode']['help'], type = str) + client_parser.add_argument("-c", "--cmid", dest = clt_options['cmid']['des'], default = clt_options['cmid']['def'], + help = clt_options['cmid']['help'], type = str) + client_parser.add_argument("-n", "--name", dest = clt_options['name']['des'] , default = clt_options['name']['def'], + help = clt_options['name']['help'], type = str) + client_parser.add_argument("-V", "--loglevel", dest = clt_options['llevel']['des'], action = "store", + choices = clt_options['llevel']['choi'], default = clt_options['llevel']['def'], + help = clt_options['llevel']['help'], type = str) + client_parser.add_argument("-F", "--logfile", nargs = "+", action = "store", dest = clt_options['lfile']['des'], + default = clt_options['lfile']['def'], help = clt_options['lfile']['help'], type = str) + client_parser.add_argument("-S", "--logsize", dest = clt_options['lsize']['des'], action = "store", + default = clt_options['lsize']['def'], help = clt_options['lsize']['help'], type = float) + client_parser.add_argument("-h", "--help", action = "help", help = "show this help message and exit") try: - clt_config.update(vars(parser.parse_args())) - # Check logfile. - clt_config['logfile'] = check_logfile(clt_config['logfile'], clt_options['lfile']['def'], where = "clt") + if "-h" in sys.argv[1:]: + KmsHelper().printer(parsers = [client_parser]) + clt_config.update(vars(client_parser.parse_args())) except KmsException as e: pretty_printer(put_text = "{reverse}{red}{bold}%s. Exiting...{end}" %str(e), to_exit = True) 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 + # Check logfile. + clt_config['logfile'] = check_logfile(clt_config['logfile'], clt_options['lfile']['def'], where = "clt") # Setup hidden or not messages. ShellMessage.view = ( False if any(i in ['STDOUT', 'FILESTDOUT'] for i in clt_config['logfile']) else True ) diff --git a/py-kms/pykms_GuiBase.py b/py-kms/pykms_GuiBase.py index 2430602..72df2cc 100644 --- a/py-kms/pykms_GuiBase.py +++ b/py-kms/pykms_GuiBase.py @@ -488,7 +488,7 @@ class KmsGui(tk.Tk): def clt_on_start(self): self.clt_actions_start() - # run thread for disable interrupting server and client, when client running. + # run thread for disabling interrupt 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() @@ -510,14 +510,13 @@ class KmsGui(tk.Tk): clt_config[clt_options['lsize']['des']] = 0 # run client (in a thread). - global clientthread - clientthread = client_thread(name = "Thread-Clt") - clientthread.setDaemon(True) - clientthread.with_gui = True - clientthread.start() + self.clientthread = client_thread(name = "Thread-Clt") + self.clientthread.setDaemon(True) + self.clientthread.with_gui = True + self.clientthread.start() def clt_eject(self): - while clientthread.is_alive(): + while self.clientthread.is_alive(): sleep(0.1) for widget in self.allopts_clt + [self.runbtnsrv, self.runbtnclt]: widget.configure(state = 'normal') diff --git a/py-kms/pykms_Misc.py b/py-kms/pykms_Misc.py index 1fbd4bb..3db56a5 100644 --- a/py-kms/pykms_Misc.py +++ b/py-kms/pykms_Misc.py @@ -223,26 +223,34 @@ class KmsParser(argparse.ArgumentParser): raise KmsException(message) class KmsHelper(object): - def replace(self, parser): + def replace(self, parser, replace_epilog_with): text = parser.format_help().splitlines() help_list = [] for line in text: if line == parser.description: continue if line == parser.epilog: - line = 80 * '*' + '\n' + line = replace_epilog_with help_list.append(line) return help_list def printer(self, parsers): - parser_base, parser_adj, parser_sub = parsers + if len(parsers) == 3: + parser_base, parser_adj, parser_sub = parsers + replace_epilog_with = 80 * '*' + '\n' + elif len(parsers) == 1: + parser_base = parsers[0] + replace_epilog_with = '' print('\n' + parser_base.description) print(len(parser_base.description) * '-' + '\n') - for line in self.replace(parser_base): - print(line) - print(parser_adj.description + '\n') - for line in self.replace(parser_sub): + for line in self.replace(parser_base, replace_epilog_with): print(line) + try: + print(parser_adj.description + '\n') + for line in self.replace(parser_sub, replace_epilog_with): + print(line) + except: + pass print('\n' + len(parser_base.epilog) * '-') print(parser_base.epilog + '\n') parser_base.exit() diff --git a/py-kms/pykms_Server.py b/py-kms/pykms_Server.py index f8e259d..883d0de 100755 --- a/py-kms/pykms_Server.py +++ b/py-kms/pykms_Server.py @@ -188,35 +188,35 @@ log info on stdout. Type \"FILESTDOUT\" to combine previous actions.', def server_options(): try: - main_parser = KmsParser(description = srv_description, epilog = 'version: ' + srv_version, add_help = False, allow_abbrev = False) + server_parser = KmsParser(description = srv_description, epilog = 'version: ' + srv_version, add_help = False, allow_abbrev = False) except TypeError: - main_parser = KmsParser(description = srv_description, epilog = 'version: ' + srv_version, add_help = False) + server_parser = KmsParser(description = srv_description, epilog = 'version: ' + srv_version, add_help = False) - main_parser.add_argument("ip", nargs = "?", action = "store", default = srv_options['ip']['def'], help = srv_options['ip']['help'], type = str) - main_parser.add_argument("port", nargs = "?", action = "store", default = srv_options['port']['def'], help = srv_options['port']['help'], type = int) - main_parser.add_argument("-e", "--epid", action = "store", dest = srv_options['epid']['des'], default = srv_options['epid']['def'], - help = srv_options['epid']['help'], type = str) - main_parser.add_argument("-l", "--lcid", action = "store", dest = srv_options['lcid']['des'], default = srv_options['lcid']['def'], - help = srv_options['lcid']['help'], type = int) - main_parser.add_argument("-c", "--client-count", action = "store", dest = srv_options['count']['des'] , default = srv_options['count']['def'], - help = srv_options['count']['help'], type = int) - main_parser.add_argument("-a", "--activation-interval", action = "store", dest = srv_options['activation']['des'], - default = srv_options['activation']['def'], help = srv_options['activation']['help'], type = int) - main_parser.add_argument("-r", "--renewal-interval", action = "store", dest = srv_options['renewal']['des'], default = srv_options['renewal']['def'], - help = srv_options['renewal']['help'], type = int) - main_parser.add_argument("-s", "--sqlite", action = "store_const", dest = srv_options['sql']['des'], const = True, default = srv_options['sql']['def'], - help = srv_options['sql']['help']) - main_parser.add_argument("-w", "--hwid", action = "store", dest = srv_options['hwid']['des'], default = srv_options['hwid']['def'], - help = srv_options['hwid']['help'], type = str) - main_parser.add_argument("-t", "--timeout", action = "store", dest = srv_options['time']['des'], default = srv_options['time']['def'], - help = srv_options['time']['help'], type = int) - main_parser.add_argument("-V", "--loglevel", action = "store", dest = srv_options['llevel']['des'], choices = srv_options['llevel']['choi'], - default = srv_options['llevel']['def'], help = srv_options['llevel']['help'], type = str) - main_parser.add_argument("-F", "--logfile", nargs = "+", action = "store", dest = srv_options['lfile']['des'], default = srv_options['lfile']['def'], - help = srv_options['lfile']['help'], type = str) - main_parser.add_argument("-S", "--logsize", action = "store", dest = srv_options['lsize']['des'], default = srv_options['lsize']['def'], - help = srv_options['lsize']['help'], type = float) - main_parser.add_argument("-h", "--help", action = "help", help = "show this help message and exit") + server_parser.add_argument("ip", nargs = "?", action = "store", default = srv_options['ip']['def'], help = srv_options['ip']['help'], type = str) + server_parser.add_argument("port", nargs = "?", action = "store", default = srv_options['port']['def'], help = srv_options['port']['help'], type = int) + server_parser.add_argument("-e", "--epid", action = "store", dest = srv_options['epid']['des'], default = srv_options['epid']['def'], + help = srv_options['epid']['help'], type = str) + server_parser.add_argument("-l", "--lcid", action = "store", dest = srv_options['lcid']['des'], default = srv_options['lcid']['def'], + help = srv_options['lcid']['help'], type = int) + server_parser.add_argument("-c", "--client-count", action = "store", dest = srv_options['count']['des'] , default = srv_options['count']['def'], + help = srv_options['count']['help'], type = int) + server_parser.add_argument("-a", "--activation-interval", action = "store", dest = srv_options['activation']['des'], + default = srv_options['activation']['def'], help = srv_options['activation']['help'], type = int) + server_parser.add_argument("-r", "--renewal-interval", action = "store", dest = srv_options['renewal']['des'], default = srv_options['renewal']['def'], + help = srv_options['renewal']['help'], type = int) + server_parser.add_argument("-s", "--sqlite", action = "store_const", dest = srv_options['sql']['des'], const = True, default = srv_options['sql']['def'], + help = srv_options['sql']['help']) + server_parser.add_argument("-w", "--hwid", action = "store", dest = srv_options['hwid']['des'], default = srv_options['hwid']['def'], + help = srv_options['hwid']['help'], type = str) + server_parser.add_argument("-t", "--timeout", action = "store", dest = srv_options['time']['des'], default = srv_options['time']['def'], + help = srv_options['time']['help'], type = int) + server_parser.add_argument("-V", "--loglevel", action = "store", dest = srv_options['llevel']['des'], choices = srv_options['llevel']['choi'], + default = srv_options['llevel']['def'], help = srv_options['llevel']['help'], type = str) + server_parser.add_argument("-F", "--logfile", nargs = "+", action = "store", dest = srv_options['lfile']['des'], default = srv_options['lfile']['def'], + help = srv_options['lfile']['help'], type = str) + server_parser.add_argument("-S", "--logsize", action = "store", dest = srv_options['lsize']['des'], default = srv_options['lsize']['def'], + help = srv_options['lsize']['help'], type = float) + server_parser.add_argument("-h", "--help", action = "help", help = "show this help message and exit") try: daemon_parser = KmsParser(description = "daemon options inherited from Etrigan", add_help = False, allow_abbrev = False) @@ -234,11 +234,11 @@ def server_options(): try: if "-h" in sys.argv[1:]: - KmsHelper().printer(parsers = [main_parser, daemon_parser, etrigan_parser]) + KmsHelper().printer(parsers = [server_parser, daemon_parser, etrigan_parser]) # Set defaults for config. # case: python3 pykms_Server.py - srv_config.update(vars(main_parser.parse_args([]))) + srv_config.update(vars(server_parser.parse_args([]))) # Eventually set daemon values for config. if 'etrigan' in sys.argv[1:]: if 'etrigan' == sys.argv[1]: @@ -250,7 +250,7 @@ def server_options(): srv_config.update(vars(daemon_parser.parse_args(sys.argv[2:]))) else: # case: python3 pykms_Server.py 1.2.3.4 1234 --main_optionals etrigan start --daemon_optionals - knw_args, knw_extras = main_parser.parse_known_args() + knw_args, knw_extras = server_parser.parse_known_args() # fix for logfile option (at the end) that catchs etrigan parser options. if 'etrigan' in knw_args.logfile: indx = knw_args.logfile.index('etrigan') @@ -265,7 +265,7 @@ def server_options(): else: # Update dict config. # case: python3 pykms_Server.py 1.2.3.4 1234 --main_optionals - knw_args, knw_extras = main_parser.parse_known_args() + knw_args, knw_extras = server_parser.parse_known_args() if knw_extras != []: raise KmsException("unrecognized arguments: %s" %' '.join(knw_extras)) else: