Lint Python scripts

This commit is contained in:
Anthony Wang 2021-12-03 19:46:51 -06:00
parent 5866de7915
commit f91da4f99d
Signed by: a
GPG key ID: BC96B00AEC5F2D76
5 changed files with 21 additions and 17 deletions

18
adduser
View file

@ -32,7 +32,8 @@ else:
# Password
if interactive:
password = os.popen('tr -dc A-Za-z0-9 </dev/urandom | head -c 16; echo ""').read()[:-1]
password = os.popen(
'tr -dc A-Za-z0-9 </dev/urandom | head -c 16; echo ""').read()[:-1]
print('Password:', password)
hashedpassword = os.popen('slappasswd -s "' + password + '"').read()[:-1]
else:
@ -91,7 +92,8 @@ if interactive:
os.remove(filename)
exit(0)
else:
ret = os.system('ldapadd -D "cn=Manager,dc=exozy,dc=me" -w "' + sys.argv[6] + '" -f ' + filename)
ret = os.system('ldapadd -D "cn=Manager,dc=exozy,dc=me" -w "' +
sys.argv[6] + '" -f ' + filename)
if ret != 0:
os.remove(filename)
exit(0)
@ -101,12 +103,14 @@ else:
# Configure user
os.system('sudo mkhomedir_helper ' + username + ' 077')
os.system('sudo -u ' + username + ' mkdir /home/' + username + '/.config')
os.system('sudo -u ' + username + ' flatpak remote-add --if-not-exists flathub https://dl.flathub.org/repo/flathub.flatpakrepo --user')
os.system('sudo -u ' + username + ' xdg-settings set default-web-browser firefox.desktop')
os.system('sudo -u ' + username +
' flatpak remote-add --if-not-exists flathub https://dl.flathub.org/repo/flathub.flatpakrepo --user')
os.system('sudo -u ' + username +
' xdg-settings set default-web-browser firefox.desktop')
# Set up rootless Podman
# https://wiki.archlinux.org/title/Podman#Set_subuid_and_subgid
start = str((int(uid) - 999) * 100000)
end = str(int(start) + 65535) # Allocate 65536 UIDs
os.system('sudo usermod --add-subuids ' + start + '-' + end + ' --add-subgids ' + start + '-' + end + ' ' + username)
end = str(int(start) + 65535) # Allocate 65536 UIDs
os.system('sudo usermod --add-subuids ' + start + '-' + end +
' --add-subgids ' + start + '-' + end + ' ' + username)

View file

@ -16,11 +16,10 @@ if confirm != 'y':
# Delete user
os.system('ldapdelete -W -D "cn=Manager,dc=exozy,dc=me" "uid=' + username + ',ou=People,dc=exozy,dc=me" "cn=' + username + ',ou=Group,dc=exozy,dc=me"')
os.system('ldapdelete -W -D "cn=Manager,dc=exozy,dc=me" "uid=' + username +
',ou=People,dc=exozy,dc=me" "cn=' + username + ',ou=Group,dc=exozy,dc=me"')
# Cleanup
os.system('sudo rm -rf /home/' + username)
os.system('sudo sed -i \'/' + username + '/d\' /etc/subuid')
os.system('sudo sed -i \'/' + username + '/d\' /etc/subgid')

View file

@ -14,4 +14,3 @@ else:
# Modify user
os.system('ldapvi --user ' + bind_user)

View file

@ -4,13 +4,15 @@ import os
from json import loads
from http.server import BaseHTTPRequestHandler, HTTPServer
class Server(BaseHTTPRequestHandler):
def do_POST(self):
content_length = int(self.headers['Content-Length'])
data = loads(self.rfile.read(content_length).decode('utf-8'))
data['password'] = os.popen('slappasswd -s "' + data['password'] + '"').read()[:-1]
data['password'] = os.popen(
'slappasswd -s "' + data['password'] + '"').read()[:-1]
print(data)
if data['code'] != code:
print('Incorrect code')
return
@ -21,12 +23,13 @@ class Server(BaseHTTPRequestHandler):
print('Cannot contain double quotes')
return
os.system('adduser "' + data['username'] + '" "' + data['firstname'].capitalize() + '" "' + data['lastname'].capitalize() + '" "' + data['email'] + '" "' + data['password'] + '" "' + ldap_pass + '"')
os.system('adduser "' + data['username'] + '" "' + data['firstname'].capitalize() + '" "' +
data['lastname'].capitalize() + '" "' + data['email'] + '" "' + data['password'] + '" "' + ldap_pass + '"')
self.send_response(200)
self.send_header('Content-type', 'text/html')
self.end_headers()
ldap_pass = input('LDAP password: ')
code = input('Registration code: ')

View file

@ -4,5 +4,4 @@ import sys
import os
for room in sys.argv:
os.system('echo "y" | synadm room delete ' + room)
os.system('echo "y" | synadm room delete ' + room)