diff --git a/lib/sshyp.py b/lib/sshyp.py index 520d335..c4d6197 100755 --- a/lib/sshyp.py +++ b/lib/sshyp.py @@ -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'): diff --git a/port-jobs/RMSERVER.py b/port-jobs/RMSERVER.py index 111d428..3d6837c 100755 --- a/port-jobs/RMSERVER.py +++ b/port-jobs/RMSERVER.py @@ -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)