mirror of
https://github.com/SystemRage/py-kms.git
synced 2024-11-25 01:35:38 +01:00
parent
56d4652de9
commit
319c6b3ef0
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,9 +1,6 @@
|
|||||||
# App files
|
# App files
|
||||||
pykms_logserver.log*
|
pykms_logserver.log*
|
||||||
pykms_logclient.log*
|
pykms_logclient.log*
|
||||||
pykms_newlines.txt*
|
|
||||||
pykms_clean_newlines.txt*
|
|
||||||
pykms_config.pickle*
|
|
||||||
pykms_database.db*
|
pykms_database.db*
|
||||||
etrigan.log*
|
etrigan.log*
|
||||||
|
|
||||||
|
@ -217,7 +217,17 @@ examples (with fictitious addresses and ports):
|
|||||||
<td>False</td>
|
<td>False</td>
|
||||||
<td>[('1.1.1.1', 1699), ('2.2.2.2', 1677)]</td>
|
<td>[('1.1.1.1', 1699), ('2.2.2.2', 1677)]</td>
|
||||||
<td>[10, 15]</td>
|
<td>[10, 15]</td>
|
||||||
<td>[True, True]</td>
|
<td>[False, False]</td>
|
||||||
|
<td>False</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><pre>python3 pykms_Server.py connect -b 12 -n 1.1.1.1,1699 -u -n 2.2.2.2,1677</pre></td>
|
||||||
|
<td>('0.0.0.0', 1688)</td>
|
||||||
|
<td>12</td>
|
||||||
|
<td>True</td>
|
||||||
|
<td>[('1.1.1.1', 1699), ('2.2.2.2', 1677)]</td>
|
||||||
|
<td>[12, 12]</td>
|
||||||
|
<td>[False, True]</td>
|
||||||
<td>False</td>
|
<td>False</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
@ -227,7 +237,7 @@ examples (with fictitious addresses and ports):
|
|||||||
<td>False</td>
|
<td>False</td>
|
||||||
<td>[('1.1.1.1', 1699), ('2.2.2.2', 1677)]</td>
|
<td>[('1.1.1.1', 1699), ('2.2.2.2', 1677)]</td>
|
||||||
<td>[8, 12]</td>
|
<td>[8, 12]</td>
|
||||||
<td>[False, True]</td>
|
<td>[False, False]</td>
|
||||||
<td>True</td>
|
<td>True</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
|
@ -18,7 +18,6 @@ __copyright__ = "© Copyright 2020"
|
|||||||
__url__ = "https://github.com/SystemRage/Etrigan"
|
__url__ = "https://github.com/SystemRage/Etrigan"
|
||||||
__description__ = "Etrigan: a python daemonizer that rocks."
|
__description__ = "Etrigan: a python daemonizer that rocks."
|
||||||
|
|
||||||
path = os.path.dirname(os.path.abspath(__file__))
|
|
||||||
|
|
||||||
class Etrigan(object):
|
class Etrigan(object):
|
||||||
"""
|
"""
|
||||||
@ -517,7 +516,7 @@ class JasonBlood(Etrigan):
|
|||||||
jasonblood_func()
|
jasonblood_func()
|
||||||
|
|
||||||
def 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')
|
file.write("Yarva Demonicus Etrigan " + time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime()) + '\n')
|
||||||
|
|
||||||
def Etrigan_parser(parser = None):
|
def Etrigan_parser(parser = None):
|
||||||
@ -535,7 +534,7 @@ def Etrigan_parser(parser = None):
|
|||||||
action = "store", dest = "etriganpid", default = "/tmp/etrigan.pid",
|
action = "store", dest = "etriganpid", default = "/tmp/etrigan.pid",
|
||||||
help = "Choose a pidfile path. Default is \"/tmp/etrigan.pid\".", type = str) #'/var/run/etrigan.pid'
|
help = "Choose a pidfile path. Default is \"/tmp/etrigan.pid\".", type = str) #'/var/run/etrigan.pid'
|
||||||
parser.add_argument("--etrigan-log",
|
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)
|
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",
|
parser.add_argument("--etrigan-lev",
|
||||||
action = "store", dest = "etriganlev", default = "DEBUG",
|
action = "store", dest = "etriganlev", default = "DEBUG",
|
||||||
|
@ -7,6 +7,7 @@ from collections import OrderedDict
|
|||||||
import logging
|
import logging
|
||||||
from io import StringIO
|
from io import StringIO
|
||||||
import queue as Queue
|
import queue as Queue
|
||||||
|
from tempfile import gettempdir
|
||||||
|
|
||||||
#----------------------------------------------------------------------------------------------------------------------------------------------------------
|
#----------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
@ -192,8 +193,8 @@ class ShellMessage(object):
|
|||||||
self.put_text = put_text
|
self.put_text = put_text
|
||||||
self.where = where
|
self.where = where
|
||||||
self.plaintext = []
|
self.plaintext = []
|
||||||
self.path_nl = os.path.dirname(os.path.abspath( __file__ )) + '/pykms_newlines.txt'
|
self.path_nl = os.path.join(gettempdir(), 'pykms_newlines.txt')
|
||||||
self.path_clean_nl = os.path.dirname(os.path.abspath( __file__ )) + '/pykms_clean_newlines.txt'
|
self.path_clean_nl = os.path.join(gettempdir(), 'pykms_clean_newlines.txt')
|
||||||
self.queue_get = Queue.Queue()
|
self.queue_get = Queue.Queue()
|
||||||
|
|
||||||
def formatter(self, msgtofrmt):
|
def formatter(self, msgtofrmt):
|
||||||
|
@ -483,8 +483,8 @@ def kms_parser_check_connect(config, options, userarg, zeroarg, onearg):
|
|||||||
pos2 = userarg.index(config['listen'][indx + 1])
|
pos2 = userarg.index(config['listen'][indx + 1])
|
||||||
arguments = userarg[pos1 + 1 : pos2 - 1]
|
arguments = userarg[pos1 + 1 : pos2 - 1]
|
||||||
kms_parser_check_optionals(arguments, zeroarg, onearg, msg = 'optional connect')
|
kms_parser_check_optionals(arguments, zeroarg, onearg, msg = 'optional connect')
|
||||||
assign(arguments, indx, ['-b', '--backlog'], config['backlog'], options['backlog']['def'])
|
assign(arguments, indx, ['-b', '--backlog'], config['backlog'], config['backlog_main'])
|
||||||
assign(arguments, indx, ['-u', '--no-reuse'], config['reuse'], options['reuse']['def'])
|
assign(arguments, indx, ['-u', '--no-reuse'], config['reuse'], config['reuse_main'])
|
||||||
|
|
||||||
if not arguments:
|
if not arguments:
|
||||||
config['backlog'][indx] = config['backlog_main']
|
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])
|
pos = userarg.index(config['listen'][indx + 1])
|
||||||
arguments = userarg[pos + 1:]
|
arguments = userarg[pos + 1:]
|
||||||
kms_parser_check_optionals(arguments, zeroarg, onearg, msg = 'optional connect')
|
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, ['-b', '--backlog'], config['backlog'], config['backlog_main'], islast = True)
|
||||||
assign(arguments, None, ['-u', '--no-reuse'], config['reuse'], options['reuse']['def'], islast = True)
|
assign(arguments, None, ['-u', '--no-reuse'], config['reuse'], config['reuse_main'], islast = True)
|
||||||
|
|
||||||
if not arguments:
|
if not arguments:
|
||||||
config['backlog'][indx + 1] = config['backlog_main']
|
config['backlog'][indx + 1] = config['backlog_main']
|
||||||
config['reuse'][indx + 1] = config['reuse_main']
|
config['reuse'][indx + 1] = config['reuse_main']
|
||||||
|
|
||||||
else:
|
else:
|
||||||
assign_main(userarg[1:], config)
|
assign_main(userarg[1:], config)
|
||||||
|
|
||||||
|
@ -13,7 +13,8 @@ import pickle
|
|||||||
import socketserver
|
import socketserver
|
||||||
import queue as Queue
|
import queue as Queue
|
||||||
import selectors
|
import selectors
|
||||||
import getpass
|
from getpass import getuser
|
||||||
|
from tempfile import gettempdir
|
||||||
from time import monotonic as time
|
from time import monotonic as time
|
||||||
|
|
||||||
import pykms_RpcBind, pykms_RpcRequest
|
import pykms_RpcBind, pykms_RpcRequest
|
||||||
@ -393,7 +394,7 @@ class Etrigan(Etrigan):
|
|||||||
|
|
||||||
def server_daemon():
|
def server_daemon():
|
||||||
if 'etrigan' in srv_config.values():
|
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:
|
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'],
|
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'],
|
logfile = srv_config['etriganlog'], loglevel = srv_config['etriganlev'],
|
||||||
mute = srv_config['etriganmute'], pause_loop = None)
|
mute = srv_config['etriganmute'], pause_loop = None)
|
||||||
|
|
||||||
if srv_config['operation'] == 'start':
|
if srv_config['operation'] in ['start', 'restart']:
|
||||||
serverdaemon.want_quit = True
|
serverdaemon.want_quit = True
|
||||||
if srv_config['gui']:
|
if srv_config['gui']:
|
||||||
serverdaemon.funcs_to_daemonize = [server_with_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]
|
serverdaemon.funcs_to_daemonize = [server_without_gui.start, server_without_gui.join]
|
||||||
indx_for_clean = lambda: (0, )
|
indx_for_clean = lambda: (0, )
|
||||||
serverdaemon.quit_on_stop = [indx_for_clean, server_without_gui.clean]
|
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)
|
Etrigan_job(srv_config['operation'], serverdaemon)
|
||||||
|
|
||||||
@ -516,16 +519,19 @@ def server_check():
|
|||||||
srv_config['listen'] = addresses
|
srv_config['listen'] = addresses
|
||||||
|
|
||||||
def server_create():
|
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 = [(
|
all_address = [(
|
||||||
srv_config['ip'], srv_config['port'],
|
srv_config['ip'], srv_config['port'],
|
||||||
(srv_config['backlog_main'] if 'backlog_main' in srv_config else srv_options['backlog']['def']),
|
(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'])
|
log_address = "TCP server listening at %s on port %d" %(srv_config['ip'], srv_config['port'])
|
||||||
|
|
||||||
if 'listen' in srv_config:
|
if 'listen' in srv_config:
|
||||||
for l, b, r in zip(srv_config['listen'], srv_config['backlog'], srv_config['reuse']):
|
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,))
|
all_address.append(l + (b,) + (r,))
|
||||||
log_address += justify("at %s on port %d" %(l[0], l[1]), indent = 56)
|
log_address += justify("at %s on port %d" %(l[0], l[1]), indent = 56)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user