mirror of
https://github.com/rwinkhart/sshyp.git
synced 2026-08-28 12:56:28 -04:00
Optimized RMSERVER.py port-job script
Former-commit-id: 8ac85dff97de4dabab373fa784d6cdf3d4ae3084 Former-commit-id: af32466a41e6f152507569df651eda1fa8502ef3
This commit is contained in:
+3
-1
@@ -831,7 +831,8 @@ if __name__ == "__main__":
|
||||
success_flag = True
|
||||
from stweak import global_menu
|
||||
global_menu('client', 'configuration options:')
|
||||
|
||||
|
||||
# PORT START ARGS-SERVER
|
||||
# server arguments
|
||||
else:
|
||||
if arg_count < 1:
|
||||
@@ -851,6 +852,7 @@ if __name__ == "__main__":
|
||||
elif arg_count > 2 and arguments[1] in ('add', 'del'):
|
||||
success_flag = True
|
||||
whitelist_manage(arguments[2])
|
||||
# PORT END ARGS-SERVER
|
||||
|
||||
if arg_count > 0 and success_flag == 0 and arguments[0] != 'sync':
|
||||
if device_type == 'client' and arguments[0] not in ('help', '-h', 'version', '-v', 'license'):
|
||||
|
||||
+12
-75
@@ -1,81 +1,18 @@
|
||||
#!/usr/bin/env python3
|
||||
import re
|
||||
|
||||
# SSHYNC-REMOTE
|
||||
# define PORT target
|
||||
string1 = '# PORT START SSHYNC-REMOTE'
|
||||
string2 = '# PORT END SSHYNC-REMOTE'
|
||||
|
||||
# read input file
|
||||
text = open('working/sshync.py', 'r').read()
|
||||
|
||||
# find and replace the defined PORT target
|
||||
regex = re.compile(f"\n{string1}.*?{string2}\n\n", re.DOTALL)
|
||||
new_text = re.sub(regex, '', text)
|
||||
|
||||
# write updated text
|
||||
open('working/sshync.py', 'w').write(new_text)
|
||||
|
||||
# WHITELIST-SERVER
|
||||
# define PORT target
|
||||
string1 = '# PORT START WHITELIST-SERVER'
|
||||
string2 = '# PORT END WHITELIST-SERVER'
|
||||
|
||||
# read input file
|
||||
text = open('working/sshyp.py', 'r').read()
|
||||
|
||||
# find and replace the defined PORT target
|
||||
regex = re.compile(f"\n{string1}.*?{string2}\n\n", re.DOTALL)
|
||||
new_text = re.sub(regex, '', text)
|
||||
|
||||
# write updated text
|
||||
open('working/sshyp.py', 'w').write(new_text)
|
||||
|
||||
# TWEAK-DEVTYPE
|
||||
# define PORT target
|
||||
string1 = '# PORT START TWEAK-DEVTYPE'
|
||||
string2 = '# PORT END TWEAK-DEVTYPE'
|
||||
|
||||
# set replacement text
|
||||
replacement = """_install_type = curses_radio(('client (ssh-synchronized)', 'client (offline)'),
|
||||
devtype_replacement = """_install_type = curses_radio(('client (ssh-synchronized)', 'client (offline)'),
|
||||
'device + sync type configuration')"""
|
||||
|
||||
## read input file
|
||||
text = open('working/stweak.py', 'r').read()
|
||||
targets = (('SSHYNC-REMOTE', 'sshync.py', '\n', '\n\n', ''), ('WHITELIST-SERVER', 'sshyp.py', '\n', '\n\n', ''),
|
||||
('TWEAK-DEVTYPE', 'stweak.py', '', '', devtype_replacement),
|
||||
('ARGS-SERVER', 'sshyp.py', '', '\n\n ', ''), ('HELP-SERVER', 'sshyp.py', '', '\n', ''))
|
||||
|
||||
# find and replace the defined PORT target
|
||||
regex = re.compile(f"{string1}.*?{string2}", re.DOTALL)
|
||||
new_text = re.sub(regex, replacement, text)
|
||||
|
||||
# write updated text
|
||||
open('working/stweak.py', 'w').write(new_text)
|
||||
|
||||
# ARGS-SERVER
|
||||
# define PORT target
|
||||
string1 = '# PORT START ARGS-SERVER'
|
||||
string2 = '# PORT END ARGS-SERVER'
|
||||
|
||||
# read input file
|
||||
text = open('working/sshyp.py', 'r').read()
|
||||
|
||||
# find and replace the defined PORT target
|
||||
regex = re.compile(f"{string1}.*?{string2}\n\n ", re.DOTALL)
|
||||
new_text = re.sub(regex, '', text)
|
||||
|
||||
# write updated text
|
||||
open('working/sshyp.py', 'w').write(new_text)
|
||||
|
||||
# HELP-SERVER
|
||||
# define PORT target
|
||||
string1 = '# PORT START HELP-SERVER'
|
||||
string2 = '# PORT END HELP-SERVER'
|
||||
|
||||
# read input file
|
||||
text = open('working/sshyp.py', 'r').read()
|
||||
|
||||
# find and replace the defined PORT target
|
||||
regex = re.compile(f"{string1}.*?{string2}\n", re.DOTALL)
|
||||
new_text = re.sub(regex, '', text)
|
||||
|
||||
# write updated text
|
||||
open('working/sshyp.py', 'w').write(new_text)
|
||||
for target in targets:
|
||||
# read text from target file
|
||||
text = open(f"working/{target[1]}", 'r').read()
|
||||
# compile regex and modify text
|
||||
regex = re.compile(f"{target[2]}# PORT START {target[0]}.*?# PORT END {target[0]}{target[3]}", re.DOTALL)
|
||||
new_text = re.sub(regex, target[4], text)
|
||||
# write updated text to target file
|
||||
open(f"working/{target[1]}", 'w').write(new_text)
|
||||
|
||||
Reference in New Issue
Block a user