You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
76 lines
1.8 KiB
Python
76 lines
1.8 KiB
Python
#!/usr/bin/env python3
|
|
|
|
import i18n
|
|
import validators
|
|
import requests
|
|
from config import *
|
|
from getpass import getpass
|
|
|
|
|
|
def firstsetup(url = "", username = ""):
|
|
config = getconfig()
|
|
# Get URL
|
|
while True:
|
|
if url != "":
|
|
url = input(i18n.t("Server URL") + " (" + url + "): ") or url
|
|
else:
|
|
url = input(i18n.t("Server URL") + ": ")
|
|
if validators.url(url):
|
|
break
|
|
else:
|
|
print(i18n.t("That doesn't look right, try again."))
|
|
# Get username
|
|
while True:
|
|
if username != "":
|
|
username = input(i18n.t("Username") + " (" + username + "): ") or username
|
|
else:
|
|
username = input(i18n.t("Username") + ": ")
|
|
if username != "":
|
|
break
|
|
# Get password
|
|
while True:
|
|
password = getpass(i18n.t("Password") + ": ")
|
|
if password != "":
|
|
break
|
|
|
|
try:
|
|
r = requests.post(url + "/api/ping", auth=(username, password))
|
|
except:
|
|
print(i18n.t("Could not connect to the server. Try again."))
|
|
firstsetup()
|
|
return
|
|
|
|
if r.status_code == 401:
|
|
print(i18n.t("Login incorrect, try again."))
|
|
firstsetup(url)
|
|
return
|
|
|
|
try:
|
|
resp = r.json()
|
|
if resp["status"] == "ERROR":
|
|
print(resp["msg"])
|
|
firstsetup(url, username)
|
|
return
|
|
config["url"] = url
|
|
config["username"] = username
|
|
config["password"] = password
|
|
saveconfig()
|
|
return
|
|
except ValueError:
|
|
print(i18n.t("Login incorrect, try again."))
|
|
firstsetup(url, username)
|
|
return
|
|
|
|
|
|
def main():
|
|
if not checkconfig():
|
|
print(i18n.t("No valid settings file found, running setup wizard."))
|
|
firstsetup()
|
|
else:
|
|
loadconfig()
|
|
print(getconfig())
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|