Add admin password management and collapsible settings
This commit is contained in:
@@ -292,6 +292,35 @@ def network_read(iface):
|
||||
}))
|
||||
return 0
|
||||
|
||||
|
||||
def password_change(username):
|
||||
if username != 'theroot':
|
||||
return 2
|
||||
|
||||
password = sys.stdin.readline(258)
|
||||
if not password.endswith('\n'):
|
||||
return 2
|
||||
|
||||
password = password[:-1]
|
||||
|
||||
if (
|
||||
len(password) < 8
|
||||
or len(password) > 256
|
||||
or any(ord(char) < 32 or ord(char) == 127 for char in password)
|
||||
or ':' in password
|
||||
):
|
||||
return 2
|
||||
|
||||
subprocess.run(
|
||||
['/usr/sbin/chpasswd'],
|
||||
input=f'{username}:{password}\n',
|
||||
text=True,
|
||||
check=True,
|
||||
capture_output=True,
|
||||
timeout=15,
|
||||
)
|
||||
return 0
|
||||
|
||||
def main():
|
||||
if len(sys.argv) != 3: return 2
|
||||
action, value = sys.argv[1:]
|
||||
@@ -304,6 +333,7 @@ def main():
|
||||
if action == 'ntp':
|
||||
if value not in {'yes', 'no'}: return 2
|
||||
run('/usr/bin/timedatectl', 'set-ntp', 'true' if value == 'yes' else 'false'); return 0
|
||||
if action == 'password-change': return password_change(value)
|
||||
if action == 'network-read': return network_read(value)
|
||||
if action == 'network-status': return network_status()
|
||||
if action == 'network-apply': return network_apply(value)
|
||||
|
||||
Reference in New Issue
Block a user