Organise change_manager code, fix root passwd bug
This commit is contained in:
parent
f4cbceed1c
commit
e79969805d
1 changed files with 7 additions and 52 deletions
|
|
@ -41,13 +41,13 @@ def set_root_password(new_pass):
|
||||||
print(f"Issue unlocking root account")
|
print(f"Issue unlocking root account")
|
||||||
print(unlock_result)
|
print(unlock_result)
|
||||||
return False
|
return False
|
||||||
|
else:
|
||||||
|
result = run(["passwd", "-s", "root"],capture_output = True, text = True, input=new_pass)
|
||||||
|
if result.returncode != 0:
|
||||||
|
print(f"Issue setting password for root account")
|
||||||
|
print(result)
|
||||||
|
return False
|
||||||
else:
|
else:
|
||||||
result = run(["passwd", "-s", "root"],capture_output = True, text = True, input=new_pass)
|
|
||||||
if result.returncode != 0:
|
|
||||||
print(f"Issue setting password for root account")
|
|
||||||
print(result)
|
|
||||||
return False
|
|
||||||
|
|
||||||
print(f"Root account password set successfully.")
|
print(f"Root account password set successfully.")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
@ -99,41 +99,6 @@ def change_service_status(setting, service):
|
||||||
else:
|
else:
|
||||||
return(disable_service(service))
|
return(disable_service(service))
|
||||||
|
|
||||||
def change_keanu_weblite_config(new_hostname):
|
|
||||||
regex = re.compile('aut ?= ?"([^"]*)"')
|
|
||||||
target_file = "/var/www/html/chat/assets/index-xXHv_nhZ.js"
|
|
||||||
match_changed = False
|
|
||||||
with open(target_file, "r") as f:
|
|
||||||
lines = f.readlines()
|
|
||||||
match_exists = False
|
|
||||||
try:
|
|
||||||
for i,line in enumerate(lines):
|
|
||||||
match = regex.search(line)
|
|
||||||
if match:
|
|
||||||
match_exists = True
|
|
||||||
old_hostname = match.group(1)
|
|
||||||
print(f"Old hostname {old_hostname}, new is {new_hostname}")
|
|
||||||
if old_hostname != new_hostname:
|
|
||||||
lines[i] = re.sub(old_hostname, new_hostname, lines[i])
|
|
||||||
match_changed = True
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
print(f"Old hostname same as new, not changing Keanu config")
|
|
||||||
if not match_exists:
|
|
||||||
print("Keanu weblite match not found!")
|
|
||||||
return False
|
|
||||||
except Exception as e:
|
|
||||||
print(e)
|
|
||||||
print(line)
|
|
||||||
if match_changed and lines:
|
|
||||||
new_lines = "".join(lines)
|
|
||||||
with open(target_file, "w") as f:
|
|
||||||
print(f"Writing changed file {target_file}.")
|
|
||||||
f.write(new_lines)
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
def change_line_in_file(target_file: str, regex: str, replacement: str):
|
def change_line_in_file(target_file: str, regex: str, replacement: str):
|
||||||
regex = re.compile(regex)
|
regex = re.compile(regex)
|
||||||
if not os.path.isfile(target_file):
|
if not os.path.isfile(target_file):
|
||||||
|
|
@ -194,17 +159,7 @@ def check_settings(raspap_installed: bool):
|
||||||
if s == "enable_deltachat":
|
if s == "enable_deltachat":
|
||||||
needs_restart = change_service_status("enable_deltachat", "madmail") or needs_restart
|
needs_restart = change_service_status("enable_deltachat", "madmail") or needs_restart
|
||||||
if s == "butterbox_hostname":
|
if s == "butterbox_hostname":
|
||||||
# change in keanu-weblite compiled assets
|
# change in /etc/hostname
|
||||||
new_hostname=f"{load_setting('butterbox_hostname')}.local"
|
|
||||||
# result_keanu = change_keanu_weblite_config(new_hostname)
|
|
||||||
# print(f"Changing keanu weblite assets {result_keanu}")
|
|
||||||
# # change in butterbox-dendrite.conf
|
|
||||||
# regex_matrix_server = " server_name:.*?.local\n"
|
|
||||||
# result_matrix = change_line_in_file("../dendrite/butterbox-dendrite.conf", regex_matrix_server,
|
|
||||||
# f" server_name: {load_setting("butterbox_hostname")}.local\n")
|
|
||||||
# print(f"Changing dendrite config: {result_matrix}")
|
|
||||||
# change in /etc/hostname
|
|
||||||
|
|
||||||
print("Writing new hostname to /etc/hostname")
|
print("Writing new hostname to /etc/hostname")
|
||||||
with open("/etc/hostname", 'w') as f:
|
with open("/etc/hostname", 'w') as f:
|
||||||
f.write(load_setting('butterbox_hostname'))
|
f.write(load_setting('butterbox_hostname'))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue