Custom client installer via Python

I am trying to follow this link instructions https://urbackup.atlassian.net/wiki/display/US/Download+custom+client+installer+via+Python

but when I run the script I get [quote=""]custom client installer via Python[/quote] I have tested the user and I am able to login with that user from the web gui I maybe missing something in the script

import http.client as http
import json
from urllib.parse import urlparse
from urllib.parse import urlencode
from base64 import b64encode
import hashlib
import socket
import shutil
import os
 
#############################
# Settings. Please edit.
#############################
 
#Your server URL
server_url = 'http://backup.com:55414/'
 
 
#If you have basic authentication via .htpasswd
server_basic_username =''
server_basic_password =''
 
 
#user needs following rights
# "settings": "all"
# "status": "some"
# "add_client": "all"
server_username= 'admin'
server_password= 'notmyrealpassword'
 
 
#############################
# Global script variables.
# Please do not modify.
#############################
 
session=""
 
def get_response(action, params):
    global server_url;
    global server_basic_username;
    global server_basic_password;
    global session;
     
    headers = {
        'Accept': 'application/json',
        'Content-Type': 'application/json; charset=UTF-8'
    }
     
    if('server_basic_username' in globals() and len(server_basic_username)>0):
        userAndPass = b64encode(str.encode(server_basic_username+":"+server_basic_password)).decode("ascii")
        headers['Authorization'] = 'Basic %s' %  userAndPass
     
    curr_server_url=server_url+"?"+urlencode({"a": action});
     
    if(len(session)>0):
        params["ses"]=session
     
    curr_server_url+="&"+urlencode(params);
     
    target = urlparse(curr_server_url)
    method = 'GET'
    body = ''
     
    if(target.scheme=='http'):
        h = http.HTTPConnection(target.hostname, target.port)
    elif(target.scheme=='https'):
        h = http.HTTPSConnection(target.hostname, target.port)
    else:
        print('Unkown scheme: '+target.scheme)
        raise Exception("Unkown scheme: "+target.scheme)
     
    h.request(
            method,
            target.path+"?"+target.query,
            body,
            headers)
     
    return h.getresponse();
 
def get_json(action, params = {}):
     
    response = get_response(action, params)
     
    if(response.status != 200):
        return ""
     
    data = response.readall();
     
    response.close()
         
    return json.loads(data.decode("utf-8"))
 
def download_file(action, outputfn, params):
     
    response = get_response(action, params);
     
    if(response.status!=200):
        return False
     
    with open(outputfn, 'wb') as outputf:
        shutil.copyfileobj(response, outputf)
         
     
    return True       
 
def md5(s):
    return hashlib.md5(s.encode()).hexdigest()
 
 
print("Logging in...")
 
salt = get_json("salt", {"username": server_username})
 
if( not ('ses' in salt) ):
    print('Username does not exist')
    exit(1)
     
session = salt["ses"];
     
if( 'salt' in salt ):
    password_md5 = md5(salt["rnd"]+md5(salt["salt"]+server_password));
     
    login = get_json("login", { "username": server_username,
                                "password": password_md5 })
     
    if('success' not in login or not login['success']):
        print('Error during login. Password wrong?')
        exit(1)
         
    print("Creating client "+socket.gethostname()+"...")
         
    status = get_json("status", { "clientname": socket.gethostname()})
     
    for client in status["client_downloads"]:
         
        if (client["name"] == socket.gethostname()):
             
            print("Downloading Installer...")
             
            if not download_file("download_client", "Client Installer.exe", {"clientid": client["id"]}):
                 
                print("Downloading client failed")
                exit(1)
                 
            print("Sucessfully downloaded client")
            os.startfile("Client Installer.exe")
            exit(0)
             
    print("Could not find client for download. No permission?")
    exit(1)

Should this be correct?

[quote=“tjohnson1989”]I am trying to follow this link instructions https://urbackup.atlassian.net/wiki/display/US/Download+custom+client+installer+via+Python

but when I run the script I get [quote=""]custom client installer via Python[/quote] [/quote]

Is this the output? How are you running the script?

I have python installed on my windows 8.1 and I am trying to run it through commandline.

This python script works great for windows, but I’d like to adjust it to work with Macs. It looks like it would rather easy, just download the Mac script instead of the Windows EXE at the end, but how would you do that? Thanks.

I’m thinking if somehow this was set to run at the end of the python script, would do the trick, replacing the downloading and running of the exe …

TF=mktemp && curl “https://server/x?a=download_client&lang=en&clientid=client_id&authkey=auth_key&os=mac” > $TF && bash $TF; rm $TF

Close. You’ll have to add "os": "mac" to download_file. And probably start it with sh installer.

thanks, here’s what you have to modify to make it a macos silent installer…

    if "already_exists" in new_client:
    print("Client already exists")
     
    status = get_json("status")
     
    if "client_downloads" in status:
        for client in status["client_downloads"]:        
            if (client["name"] == clientname):
                print("Downloading Installer...")
                 
                if not download_file("download_client", "ClientInstaller.sh",
                             {"clientid": client["id"], 
                             "os": "mac" }):
                    print("Downloading client failed")
                    exit(1)
    else:       
        print("Client already exists and login user has probably no right to access existing clients")
        exit(2)
else:
    if not "new_authkey" in new_client:
        print("Error creating new client")
        exit(3)
         
    print("Downloading Installer...")
              
    if not download_file("download_client", "ClientInstaller.sh",
                         {"clientid": new_client["new_clientid"],
                          "authkey": new_client["new_authkey"], 
                          "os": "mac"
                          }):
          
        print("Downloading client failed")
        exit(1)
      
print("Sucessfully downloaded client")
os.system('sh ClientInstaller.sh -- silent')
exit(0)

By the way, what rights does the account need? According the the script…

“status”: “some”
“add_client”: “all”
Optionally, to be able to install existing clients:
“settings”: “all”

But if you look at the urbackup manual, there is no add_client