pywebexec 1.4.14__py3-none-any.whl → 1.4.16__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pywebexec/pywebexec.py +34 -16
- pywebexec/version.py +2 -2
- {pywebexec-1.4.14.dist-info → pywebexec-1.4.16.dist-info}/METADATA +1 -1
- {pywebexec-1.4.14.dist-info → pywebexec-1.4.16.dist-info}/RECORD +8 -8
- {pywebexec-1.4.14.dist-info → pywebexec-1.4.16.dist-info}/LICENSE +0 -0
- {pywebexec-1.4.14.dist-info → pywebexec-1.4.16.dist-info}/WHEEL +0 -0
- {pywebexec-1.4.14.dist-info → pywebexec-1.4.16.dist-info}/entry_points.txt +0 -0
- {pywebexec-1.4.14.dist-info → pywebexec-1.4.16.dist-info}/top_level.txt +0 -0
pywebexec/pywebexec.py
CHANGED
@@ -13,7 +13,7 @@ import time
|
|
13
13
|
import shlex
|
14
14
|
from gunicorn.app.base import Application
|
15
15
|
import ipaddress
|
16
|
-
from socket import gethostname, gethostbyname_ex, gethostbyaddr, inet_aton, inet_ntoa
|
16
|
+
from socket import socket, gethostname, gethostbyname_ex, gethostbyaddr, inet_aton, inet_ntoa, AF_INET, SOCK_STREAM
|
17
17
|
import ssl
|
18
18
|
import re
|
19
19
|
import pwd
|
@@ -255,10 +255,15 @@ def daemon_d(action, pidfilepath, silent=False, hostname=None, args=None):
|
|
255
255
|
if pidfile.is_locked():
|
256
256
|
pid = pidfile.read_pid()
|
257
257
|
print(f"Stopping server pid {pid}")
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
258
|
+
n = 20
|
259
|
+
while n > 0:
|
260
|
+
try:
|
261
|
+
os.kill(pid, signal.SIGINT)
|
262
|
+
time.sleep(0.25)
|
263
|
+
n -= 1
|
264
|
+
except ProcessLookupError:
|
265
|
+
return True
|
266
|
+
print("Failed to stop server", file=sys.stderr)
|
262
267
|
return True
|
263
268
|
elif action == "status":
|
264
269
|
status = pidfile.is_locked()
|
@@ -291,12 +296,14 @@ def start_term(command_id):
|
|
291
296
|
os.chdir(CWD)
|
292
297
|
start_time = datetime.now().isoformat()
|
293
298
|
user = pwd.getpwuid(os.getuid())[0]
|
299
|
+
print(f"Starting terminal session for {user} : {command_id}")
|
294
300
|
update_command_status(command_id, 'running', command="term", params=[user,os.ttyname(sys.stdout.fileno())], start_time=start_time, user=user)
|
295
301
|
output_file_path = get_output_file_path(command_id)
|
296
302
|
res = script(output_file_path)
|
297
303
|
end_time = datetime.now().isoformat()
|
298
304
|
update_command_status(command_id, status="success", end_time=end_time, exit_code=res)
|
299
|
-
|
305
|
+
print("Terminal session ended")
|
306
|
+
return res
|
300
307
|
|
301
308
|
|
302
309
|
def print_urls(command_id=None):
|
@@ -313,6 +320,11 @@ def print_urls(command_id=None):
|
|
313
320
|
print(f"{protocol}://{ip}:{args.port}{url_params}")
|
314
321
|
|
315
322
|
|
323
|
+
def is_port_in_use(address, port):
|
324
|
+
with socket(AF_INET, SOCK_STREAM) as s:
|
325
|
+
return s.connect_ex((address, port)) == 0
|
326
|
+
|
327
|
+
|
316
328
|
def parseargs():
|
317
329
|
global app, args, COMMAND_STATUS_DIR, hostname, ip
|
318
330
|
|
@@ -359,8 +371,8 @@ def parseargs():
|
|
359
371
|
os.mkdir(COMMAND_STATUS_DIR, mode=0o700)
|
360
372
|
if args.action == "term":
|
361
373
|
COMMAND_STATUS_DIR = f"{os.getcwd()}/{COMMAND_STATUS_DIR}"
|
362
|
-
start_term(str(uuid.uuid4()))
|
363
|
-
|
374
|
+
sys.exit(start_term(str(uuid.uuid4())))
|
375
|
+
|
364
376
|
(hostname, ip) = resolve(gethostname()) if args.listen == '0.0.0.0' else resolve(args.listen)
|
365
377
|
|
366
378
|
if args.tokenurl:
|
@@ -389,9 +401,6 @@ def parseargs():
|
|
389
401
|
app.config['USER'] = None
|
390
402
|
app.config['PASSWORD'] = None
|
391
403
|
|
392
|
-
if args.action != 'stop':
|
393
|
-
print("Starting server:")
|
394
|
-
print_urls()
|
395
404
|
return args
|
396
405
|
|
397
406
|
def get_status_file_path(command_id):
|
@@ -711,20 +720,29 @@ def popup(command_id):
|
|
711
720
|
def main():
|
712
721
|
global COMMAND_STATUS_DIR
|
713
722
|
basef = f"{CONFDIR}/pywebexec_{args.listen}:{args.port}"
|
723
|
+
if args.action == "restart":
|
724
|
+
daemon_d('stop', pidfilepath=basef)
|
725
|
+
args.action = "start"
|
726
|
+
port_used = is_port_in_use(args.listen, args.port)
|
727
|
+
if args.action != "stop":
|
728
|
+
print("Starting server:")
|
729
|
+
print_urls()
|
730
|
+
if args.action != "stop" and port_used:
|
731
|
+
print(f"Error: port {args.port} already in use", file=sys.stderr)
|
732
|
+
return 1
|
714
733
|
if args.action == "shareterm":
|
715
734
|
COMMAND_STATUS_DIR = f"{os.getcwd()}/{COMMAND_STATUS_DIR}"
|
735
|
+
sys.argv.remove("shareterm")
|
716
736
|
with open(basef + ".log", "ab+") as log:
|
717
|
-
pywebexec = subprocess.Popen([sys.executable] + sys.argv
|
737
|
+
pywebexec = subprocess.Popen([sys.executable] + sys.argv, stdout=log, stderr=log)
|
718
738
|
command_id = str(uuid.uuid4())
|
719
739
|
print_urls(command_id)
|
720
740
|
res = start_term(command_id)
|
741
|
+
print("Stopping server")
|
721
742
|
time.sleep(1)
|
722
743
|
pywebexec.terminate()
|
723
|
-
sys.exit()
|
744
|
+
sys.exit(res)
|
724
745
|
|
725
|
-
if args.action == "restart":
|
726
|
-
daemon_d('stop', pidfilepath=basef)
|
727
|
-
args.action = "start"
|
728
746
|
if args.action == "start":
|
729
747
|
return start_gunicorn(daemonized=True, baselog=basef)
|
730
748
|
if args.action:
|
pywebexec/version.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
pywebexec/__init__.py,sha256=4spIsVaF8RJt8S58AG_wWoORRNkws9Iwqprj27C3ljM,99
|
2
|
-
pywebexec/pywebexec.py,sha256
|
3
|
-
pywebexec/version.py,sha256=
|
2
|
+
pywebexec/pywebexec.py,sha256=095dLydKEtrihG4ld78yqy5QIbFIWO_JdugtHj10FzI,28134
|
3
|
+
pywebexec/version.py,sha256=sKRJPUEh1laY8OT9vcLeuQ7G3PQC7WcvaaimRXuCRuo,413
|
4
4
|
pywebexec/static/css/Consolas NF.ttf,sha256=DJEOzF0eqZ-kxu3Gs_VE8X0NJqiobBzmxWDGpdgGRxI,1313900
|
5
5
|
pywebexec/static/css/style.css,sha256=cGJHPFj23SQ_bFpesfUaFA3VFxhXtpRUOL_zzx3x_X8,5726
|
6
6
|
pywebexec/static/css/xterm.css,sha256=gy8_LGA7Q61DUf8ElwFQzHqHMBQnbbEmpgZcbdgeSHI,5383
|
@@ -23,9 +23,9 @@ pywebexec/static/js/xterm/xterm.js,sha256=Bzka76jZwEhVt_LlS0e0qMw7ryGa1p5qfxFyeo
|
|
23
23
|
pywebexec/templates/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
24
24
|
pywebexec/templates/index.html,sha256=DYtT555wSNhnFtzzHhPMWJireynCJNnAuTytpoORQeE,2321
|
25
25
|
pywebexec/templates/popup.html,sha256=T6_tAOUoA58sA1oxB5pb8i42RenoMdCsH8T86Gccb6Q,945
|
26
|
-
pywebexec-1.4.
|
27
|
-
pywebexec-1.4.
|
28
|
-
pywebexec-1.4.
|
29
|
-
pywebexec-1.4.
|
30
|
-
pywebexec-1.4.
|
31
|
-
pywebexec-1.4.
|
26
|
+
pywebexec-1.4.16.dist-info/LICENSE,sha256=gRJf0JPT_wsZJsUGlWPTS8Vypfl9vQ1qjp6sNbKykuA,1064
|
27
|
+
pywebexec-1.4.16.dist-info/METADATA,sha256=O_TD8MqU1G4_EpqVrGmj9Vj9LSkLwmvbQr6Ui4IpwNo,7801
|
28
|
+
pywebexec-1.4.16.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
29
|
+
pywebexec-1.4.16.dist-info/entry_points.txt,sha256=l52GBkPCXRkmlHfEyoVauyfBdg8o-CAtC8qQpOIjJK0,55
|
30
|
+
pywebexec-1.4.16.dist-info/top_level.txt,sha256=vHoHyzngrfGdm_nM7Xn_5iLmaCrf10XO1EhldgNLEQ8,10
|
31
|
+
pywebexec-1.4.16.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|