Jan Ulrich Hasecke
2019-11-21 47bc28d554b0c474b06cdd291d6e7b8c942af359
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import random
import string
import sys
from hs.admin.api import API
from subprocess import check_output
 
paketadmin = sys.argv[1]
domainname = sys.argv[2]
projektid = sys.argv[3]
 
pw = check_output(["pass", "hostsharing/"+paketadmin]).decode("utf-8").strip("\n")
 
api = API(cas=dict(
    uri='https://login.hostsharing.net/cas/v1/tickets',
    service='https://config.hostsharing.net:443/hsar/backend'),
    credentials=dict(username=paketadmin, password=pw),
    backends=[
        'https://config.hostsharing.net:443/hsar/xmlrpc/hsadmin',
        'https://config2.hostsharing.net:443/hsar/xmlrpc/hsadmin'])
 
def pwGen(stringLength=12):
    """Function to generate a random password """
 
    password_characters = string.ascii_letters + string.digits
    return ''.join(random.choice(password_characters) for i in range(stringLength))
 
pw_dadmin = pwGen()
pw_dbuser = pwGen()
dadmin = paketadmin+'-'+domainname.replace("-", "_")
dbuser = paketadmin+'_'+projektid
dbname = paketadmin+'_'+projektid
 
api.user.add(set={'name': dadmin, 'password': pw_dadmin, 'shell': '/bin/bash'})
api.domain.add(set={'name': domainname, 'user': dadmin})
api.mysqluser.add(set={'name': dbuser, 'password': pw_dbuser})
api.mysqldb.add(set={'name': dbname, 'owner': dbuser})
 
print("Domainname:" +domainname)
print("Domain-Admin: " + dadmin + " mit dem Passwort:" +pw_dadmin)
print("Datenbank-Nutzer: " +dbuser + " Passwort:" +pw_dbuser)
print("Datenbankname: " +dbname)