diff --git a/.gitignore b/.gitignore index 2b3c3ef..6d23810 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,6 @@ # App files pykms_logserver.log* pykms_logclient.log* -pykms_newlines.txt* -pykms_clean_newlines.txt* -pykms_config.pickle* pykms_database.db* etrigan.log* diff --git a/docs/Usage.md b/docs/Usage.md index a2bce55..996ef07 100644 --- a/docs/Usage.md +++ b/docs/Usage.md @@ -217,7 +217,17 @@ examples (with fictitious addresses and ports): False [('1.1.1.1', 1699), ('2.2.2.2', 1677)] [10, 15] - [True, True] + [False, False] + False + + +
python3 pykms_Server.py connect -b 12 -n 1.1.1.1,1699 -u -n 2.2.2.2,1677
+ ('0.0.0.0', 1688) + 12 + True + [('1.1.1.1', 1699), ('2.2.2.2', 1677)] + [12, 12] + [False, True] False @@ -227,7 +237,7 @@ examples (with fictitious addresses and ports): False [('1.1.1.1', 1699), ('2.2.2.2', 1677)] [8, 12] - [False, True] + [False, False] True diff --git a/py-kms/Etrigan.py b/py-kms/Etrigan.py index fd0571e..0bb2498 100644 --- a/py-kms/Etrigan.py +++ b/py-kms/Etrigan.py @@ -18,7 +18,6 @@ __copyright__ = "© Copyright 2020" __url__ = "https://github.com/SystemRage/Etrigan" __description__ = "Etrigan: a python daemonizer that rocks." -path = os.path.dirname(os.path.abspath(__file__)) class Etrigan(object): """ @@ -517,7 +516,7 @@ class JasonBlood(Etrigan): jasonblood_func() def jasonblood_func(): - with open(os.path.join(path, 'etrigan_test.txt'), 'a') as file: + with open(os.path.join('.', 'etrigan_test.txt'), 'a') as file: file.write("Yarva Demonicus Etrigan " + time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime()) + '\n') def Etrigan_parser(parser = None): @@ -535,7 +534,7 @@ def Etrigan_parser(parser = None): action = "store", dest = "etriganpid", default = "/tmp/etrigan.pid", help = "Choose a pidfile path. Default is \"/tmp/etrigan.pid\".", type = str) #'/var/run/etrigan.pid' parser.add_argument("--etrigan-log", - action = "store", dest = "etriganlog", default = os.path.join(path, "etrigan.log"), + action = "store", dest = "etriganlog", default = os.path.join('.', "etrigan.log"), help = "Use this option to choose an output log file; for not logging don't select it. Default is \"etrigan.log\".", type = str) parser.add_argument("--etrigan-lev", action = "store", dest = "etriganlev", default = "DEBUG", diff --git a/py-kms/pykms_Format.py b/py-kms/pykms_Format.py index 3c08ebd..4e404ea 100644 --- a/py-kms/pykms_Format.py +++ b/py-kms/pykms_Format.py @@ -7,6 +7,7 @@ from collections import OrderedDict import logging from io import StringIO import queue as Queue +from tempfile import gettempdir #---------------------------------------------------------------------------------------------------------------------------------------------------------- @@ -192,8 +193,8 @@ class ShellMessage(object): self.put_text = put_text self.where = where self.plaintext = [] - self.path_nl = os.path.dirname(os.path.abspath( __file__ )) + '/pykms_newlines.txt' - self.path_clean_nl = os.path.dirname(os.path.abspath( __file__ )) + '/pykms_clean_newlines.txt' + self.path_nl = os.path.join(gettempdir(), 'pykms_newlines.txt') + self.path_clean_nl = os.path.join(gettempdir(), 'pykms_clean_newlines.txt') self.queue_get = Queue.Queue() def formatter(self, msgtofrmt): diff --git a/py-kms/pykms_Misc.py b/py-kms/pykms_Misc.py index f790d3b..47e6226 100644 --- a/py-kms/pykms_Misc.py +++ b/py-kms/pykms_Misc.py @@ -483,8 +483,8 @@ def kms_parser_check_connect(config, options, userarg, zeroarg, onearg): pos2 = userarg.index(config['listen'][indx + 1]) arguments = userarg[pos1 + 1 : pos2 - 1] kms_parser_check_optionals(arguments, zeroarg, onearg, msg = 'optional connect') - assign(arguments, indx, ['-b', '--backlog'], config['backlog'], options['backlog']['def']) - assign(arguments, indx, ['-u', '--no-reuse'], config['reuse'], options['reuse']['def']) + assign(arguments, indx, ['-b', '--backlog'], config['backlog'], config['backlog_main']) + assign(arguments, indx, ['-u', '--no-reuse'], config['reuse'], config['reuse_main']) if not arguments: config['backlog'][indx] = config['backlog_main'] @@ -497,13 +497,12 @@ def kms_parser_check_connect(config, options, userarg, zeroarg, onearg): pos = userarg.index(config['listen'][indx + 1]) arguments = userarg[pos + 1:] kms_parser_check_optionals(arguments, zeroarg, onearg, msg = 'optional connect') - assign(arguments, None, ['-b', '--backlog'], config['backlog'], options['backlog']['def'], islast = True) - assign(arguments, None, ['-u', '--no-reuse'], config['reuse'], options['reuse']['def'], islast = True) + assign(arguments, None, ['-b', '--backlog'], config['backlog'], config['backlog_main'], islast = True) + assign(arguments, None, ['-u', '--no-reuse'], config['reuse'], config['reuse_main'], islast = True) if not arguments: config['backlog'][indx + 1] = config['backlog_main'] config['reuse'][indx + 1] = config['reuse_main'] - else: assign_main(userarg[1:], config) diff --git a/py-kms/pykms_Server.py b/py-kms/pykms_Server.py index 74932b5..7c8729b 100755 --- a/py-kms/pykms_Server.py +++ b/py-kms/pykms_Server.py @@ -13,7 +13,8 @@ import pickle import socketserver import queue as Queue import selectors -import getpass +from getpass import getuser +from tempfile import gettempdir from time import monotonic as time import pykms_RpcBind, pykms_RpcRequest @@ -393,7 +394,7 @@ class Etrigan(Etrigan): def server_daemon(): if 'etrigan' in srv_config.values(): - path = os.path.join('.', 'pykms_config.pickle') + path = os.path.join(gettempdir(), 'pykms_config.pickle') if srv_config['operation'] in ['stop', 'restart', 'status'] and len(sys.argv[1:]) > 2: pretty_printer(put_text = "{reverse}{red}{bold}too much arguments with etrigan '%s'. Exiting...{end}" %srv_config['operation'], @@ -419,7 +420,7 @@ def server_daemon(): logfile = srv_config['etriganlog'], loglevel = srv_config['etriganlev'], mute = srv_config['etriganmute'], pause_loop = None) - if srv_config['operation'] == 'start': + if srv_config['operation'] in ['start', 'restart']: serverdaemon.want_quit = True if srv_config['gui']: serverdaemon.funcs_to_daemonize = [server_with_gui] @@ -428,6 +429,8 @@ def server_daemon(): serverdaemon.funcs_to_daemonize = [server_without_gui.start, server_without_gui.join] indx_for_clean = lambda: (0, ) serverdaemon.quit_on_stop = [indx_for_clean, server_without_gui.clean] + elif srv_config['operation'] == 'stop': + os.remove(path) Etrigan_job(srv_config['operation'], serverdaemon) @@ -516,16 +519,19 @@ def server_check(): srv_config['listen'] = addresses def server_create(): - # Create address list (when the current user indicates execution inside the Windows Sandbox, then we wont allow port reuse - it is not supported). + # Create address list (when the current user indicates execution inside the Windows Sandbox, + # then we wont allow port reuse - it is not supported). all_address = [( srv_config['ip'], srv_config['port'], (srv_config['backlog_main'] if 'backlog_main' in srv_config else srv_options['backlog']['def']), - (srv_config['reuse_main'] if 'reuse_main' in srv_config else False if getpass.getuser() == 'WDAGUtilityAccount' else srv_options['reuse']['def']) + (srv_config['reuse_main'] if 'reuse_main' in srv_config else False if getuser() == 'WDAGUtilityAccount' \ + else srv_options['reuse']['def']) )] log_address = "TCP server listening at %s on port %d" %(srv_config['ip'], srv_config['port']) if 'listen' in srv_config: for l, b, r in zip(srv_config['listen'], srv_config['backlog'], srv_config['reuse']): + r = (False if getuser() == 'WDAGUtilityAccount' else r) all_address.append(l + (b,) + (r,)) log_address += justify("at %s on port %d" %(l[0], l[1]), indent = 56)