17 lines
737 B
Python
Executable File
17 lines
737 B
Python
Executable File
import sys, re
|
|
new_ip = sys.argv[1]
|
|
config_path = '/opt/stalwart/etc/config.toml'
|
|
content = open(config_path).read()
|
|
new_section = '[server.allowed-ip]\n"' + new_ip + '" = true\n'
|
|
if '[server.allowed-ip]' in content:
|
|
content = re.sub(r'\[server\.allowed-ip\].*?(?=\n\[|\Z)', new_section, content, flags=re.DOTALL)
|
|
else:
|
|
content = content.rstrip() + '\n\n' + new_section
|
|
open(config_path, 'w').write(content)
|
|
print(f'Updated allowed-ip to {new_ip}')
|
|
|
|
# After writing config, commit to git
|
|
import subprocess
|
|
subprocess.run(['git', '-C', '/opt/stalwart/etc', 'add', 'config.toml'], capture_output=True)
|
|
subprocess.run(['git', '-C', '/opt/stalwart/etc', 'commit', '-m', f'auto: allowed-ip updated to {new_ip}'], capture_output=True)
|