Created
June 6, 2020 14:05
-
-
Save ezzra/664d4ec51355f0f3d939b5172deb0371 to your computer and use it in GitHub Desktop.
uberspace create account via command line
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import re | |
from bs4 import BeautifulSoup | |
import time | |
import sys | |
import os | |
account_name = sys.argv[1] | |
session = requests.Session() | |
# get session and token | |
response = session.get('https://dashboard.uberspace.de/register?lang=en') | |
soup = BeautifulSoup(response.content, features='html.parser') | |
csrf_token = soup.select_one('[name=_csrf_token]').get('value') | |
# create uberspace | |
data = { | |
'_csrf_token': csrf_token, | |
'mail': '', | |
'login': account_name, | |
'u7': '1' | |
} | |
response = session.post('https://dashboard.uberspace.de/register/create', data=data) | |
hostname = re.findall(r'{account_name}@([a-z]+)\.uberspace\.de'.format(account_name=account_name), response.text)[0] | |
soup = BeautifulSoup(response.content, features='html.parser') | |
password = soup.select_one('#web_password').get('value') | |
csrf_token = soup.select_one('[name=_csrf_token]').get('value') | |
# waiting for uberspace to be created | |
print('waiting for uberspace to be created... ', end='', flush=True) | |
while True: | |
status_code = session.get('https://dashboard.uberspace.de/dashboard/firstboot', allow_redirects=False).status_code | |
if status_code == 302: | |
print(' ok done!') | |
break | |
print('#', end='', flush=True) | |
time.sleep(5) | |
# get token from password entry page | |
response = session.get('https://dashboard.uberspace.de/dashboard/firstboot') | |
soup = BeautifulSoup(response.content, features='html.parser') | |
csrf_token = soup.select_one('[name=_csrf_token]').get('value') | |
# set account password | |
data = { | |
'_csrf_token': csrf_token, | |
'warnpasswordrecovery': '1', | |
'password': password | |
} | |
session.post('https://dashboard.uberspace.de/dashboard/set_web_password', data=data) | |
# add ssh public key | |
if sys.argv[2]: | |
print('adding ssh-key', sys.argv[2]) | |
with open(sys.argv[2]) as f: | |
ssh_key = f.read() | |
response = session.get('https://dashboard.uberspace.de/dashboard/authentication') | |
soup = BeautifulSoup(response.content, features='html.parser') | |
csrf_token = soup.select_one('[name=_csrf_token]').get('value') | |
data = { | |
'_csrf_token': csrf_token, | |
'return_to': 'authentication', | |
'ssh_key': ssh_key | |
} | |
session.post('https://dashboard.uberspace.de/dashboard/add_ssh_key', data=data) | |
# set ssh password | |
print('set ssh password', password) | |
response = session.get('https://dashboard.uberspace.de/dashboard/authentication') | |
soup = BeautifulSoup(response.content, features='html.parser') | |
csrf_token = soup.select_one('[name=_csrf_token]').get('value') | |
data = { | |
'_csrf_token': csrf_token, | |
'return_to': 'authentication', | |
'password': password | |
} | |
session.post('https://dashboard.uberspace.de/dashboard/set_ssh_password', data=data) | |
# print data | |
print() | |
print('') | |
print('Account:', account_name) | |
print('Password:', password) | |
print('Host:', hostname) | |
print() | |
if ssh_key: | |
print('logging in via ssh...') | |
os.system( | |
'ssh -i {ssh_key} {account_name}@{hostname}.uberspace.de' | |
''.format(ssh_key=sys.argv[2], account_name=account_name, hostname=hostname) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Because I have to create uberspace test accounts regularly, i have just created a script to free me of the clicking. Its a fast and dirty hack but might be useful for others too. For example, it will just break if you try using an existing account name :)
Using:
python3 uberspace-create-account.py test666
python3 uberspace-create-account.py test666 ~/.ssh/id_rsa.pub
with the latter, you will be ssh-ed in automatically once the account is created (you know, this takes up to 4 minutes).
I maybe will clean this up and add more functionality (email, custom passwords, deleting....) that are only accessible via the dashboard at the moment...But because there will be a new dashboard with api and all the stuff in the future, I don't know if the effort is worth it.