script for resetting passwords
parent
893aba958b
commit
9281eb8e63
@ -0,0 +1,35 @@
|
||||
import os
|
||||
from IPython.lib import passwd
|
||||
from jinja2 import Environment, FileSystemLoader
|
||||
from random import shuffle
|
||||
|
||||
username = input("Username: ")
|
||||
port = input("Port: ")
|
||||
servername = input("Servername: ")
|
||||
|
||||
templates_folder = "templates"
|
||||
passwords_file = "passwords.txt"
|
||||
|
||||
template_env = Environment(loader=FileSystemLoader(templates_folder))
|
||||
nbconfig = template_env.get_template("jupyter_notebook_config.py")
|
||||
|
||||
passwords = open(passwords_file).read().strip().splitlines()
|
||||
passwords = [w.lower() for w in passwords]
|
||||
shuffle(passwords)
|
||||
password = "".join(passwords[:3])
|
||||
|
||||
userdata = {}
|
||||
userdata['username'] = username
|
||||
userdata['password'] = password
|
||||
userdata['password_sha1'] = passwd(password)
|
||||
userdata['port'] = port
|
||||
userdata['servername'] = servername
|
||||
|
||||
with open("jupyter_notebook_config.temp.py", "w") as f:
|
||||
print(nbconfig.render(**userdata), file=f)
|
||||
os.system(f"sudo mv jupyter_notebook_config.temp.py /home/{username}/.jupyter/jupyter_notebook_config.py")
|
||||
os.system(f"sudo chown -R {username}:{username} /home/{username}/.jupyter")
|
||||
|
||||
os.system(f"sudo service jupyterlab@{username} restart")
|
||||
|
||||
print(f"New password: {password}")
|
Loading…
Reference in New Issue