Skip to content

Commit

Permalink
The '--password' flag can now be used to change an existing password …
Browse files Browse the repository at this point in the history
…for the settings page
  • Loading branch information
aledipa committed May 21, 2024
1 parent f307c7c commit 3a06041
Showing 1 changed file with 30 additions and 29 deletions.
59 changes: 30 additions & 29 deletions src/FreeGPT4_Server.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
"--password",
action='store',
required=False,
help="Optional, set a password for the settings page [mandatory in docker envirtonment]",
help="Set or change the password for the settings page [mandatory in docker envirtonment]",
)
parser.add_argument(
"--cookie-file",
Expand Down Expand Up @@ -218,37 +218,39 @@
if (args.enable_gui):
# Asks for password to set to lock the settings page
# Checks if settings.json contains a password
if (data["password"] == ""):
try:
if (args.password != None):
password = args.password
confirm_password = password
else:
try:
if (args.password != None):
password = args.password
confirm_password = password
else:
if (data["password"] == ""):
password = getpass.getpass("Settings page password:\n > ")
confirm_password = getpass.getpass("Confirm password:\n > ")
if(password == "" or confirm_password == ""):
print("[X] Password cannot be empty")
exit()
if (password != confirm_password):
print("[X] Passwords don't match")
exit()
else:
password = generate_password_hash(password)
confirm_password = generate_password_hash(confirm_password)
print("[V] Password set.")
try:
data["password"] = password
with open(SETTINGS_FILE, "w") as f:
json.dump(data, f)
f.close()
print("[V] Password saved.")
except Exception as error:
print("[X] Error:", error)
exit()

except Exception as error:
print("[X] Error:", error)
if((password == "" or confirm_password == "") and (data["password"] == "")):
print("[X] Password cannot be empty")
exit()

if ((password != confirm_password) and (data["password"] == "")):
print("[X] Passwords don't match")
exit()
else:
password = generate_password_hash(password)
confirm_password = generate_password_hash(confirm_password)
print("[V] Password set.")
try:
data["password"] = password
with open(SETTINGS_FILE, "w") as f:
json.dump(data, f)
f.close()
print("[V] Password saved.")
except Exception as error:
print("[X] Error:", error)
exit()

except Exception as error:
print("[X] Error:", error)
exit()
else:
print("[!] GUI disabled")

Expand Down Expand Up @@ -286,7 +288,6 @@ def saveSettings(request, file):

if (args.enable_proxies or data["proxies"]):
# Extracts the proxies from the form
# print("Proxies enabled")
proxies = []
i = 1
while True:
Expand Down

0 comments on commit 3a06041

Please sign in to comment.