Skip to content

Commit

Permalink
change regexp for port variable
Browse files Browse the repository at this point in the history
  • Loading branch information
bangrezz committed Jan 24, 2024
1 parent 5c95488 commit 77781d6
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions modules/cronjob.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,15 @@ def processCopyMods(self, new_filename):
for i, line in enumerate(lines):
if re.search(r'local_file = os.path.join\(os.getcwd\(\), file\)', line):
lines[i] = " local_file = os.path.join(os.getcwd(), 'fileExport', file)\n"
variables = ['username', 'password', 'port_input', 'ip_input']
variables = ['username', 'password', 'ports_input', 'ip_input']
values = [self.username, self.password, self.ip_address, self.port]
var_dict = dict(zip(variables, values))

for i, line in enumerate(lines):
for var in variables:
if re.search(fr'{var} =', line):
lines[i] = f' {var} = "{var_dict[var]}"\n'
if var == 'port_input' or var == 'ip_input':
if var == 'ports_input' or var == 'ip_input':
lines[i] = ' ' + lines[i]

lines.append('\nmain()\n')
Expand Down Expand Up @@ -293,16 +293,16 @@ def edit_cron(konfigurasi_cron):
content = file.read()
username = re.search(r'username\s*=\s*\".*\"', content)
password = re.search(r'password\s*=\s*\".*\"', content)
port_input = re.search(r'port_input\s*=\s*\".*\"', content)
ports_input = re.search(r'ports_input\s*=\s*\".*\"', content)
ip_input = re.search(r'ip_input\s*=\s*\"((\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\/\d{1,2}|(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}))(,\s*|\s*-\s*)?)*\"', content)

print(f"\033[32m" + "[i]" + "\033[0m" + " Show the variables")
if username:
print(f"[*] Username: {username.group().split('=')[1].strip().replace(chr(34), '')}")
if password:
print(f"[*] Password: {password.group().split('=')[1].strip().replace(chr(34), '')}")
if port_input:
print(f"[*] Port: {port_input.group().split('=')[1].strip().replace(chr(34), '')}")
if ports_input:
print(f"[*] Port: {ports_input.group().split('=')[1].strip().replace(chr(34), '')}")
if ip_input:
print(f"[*] IP: {ip_input.group().split('=')[1].strip().replace(chr(34), '')}\n")

Expand Down Expand Up @@ -341,7 +341,7 @@ def edit_cron(konfigurasi_cron):
if new_password:
content = re.sub(r'password\s*=\s*\".*\"', f'password = "{new_password}"', content)
if new_port_input:
content = re.sub(r'port_input\s*=\s*\".*\"', f'port_input = "{new_port_input}"', content)
content = re.sub(r'ports_input\s*=\s*\".*\"', f'port_input = "{new_port_input}"', content)
if new_ip_input:
content = re.sub(r'ip_input\s*=\s*\"((\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\/\d{1,2}|(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}))(,\s*|\s*-\s*)?)*\"', f'ip_input = "{new_ip_input}"', content)
with open(file_path, 'w') as file:
Expand Down

1 comment on commit 77781d6

@bangrezz
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#19

Please sign in to comment.