#!/usr/bin/python import xmlrpclib as x import sys VARIABLE="PRINTACLIENTCONFIG" class PrintaClientConfig: def __init__(self): self.client=x.ServerProxy("https://localhost:9779") #def init def parse_args(self,args): options=["get-server-ip","set-server-ip"] if len(args)<2: self.usage() if args[1] not in options: self.usage() if args[1]=="get-server-ip": self.get_server_ip() if args[1]=="set-server-ip": self.check_root() if len(args)<3: self.usage() self.set_server_ip(args[2]) #def parse_args def check_root(self): try: f=open("/run/printa-client-config","w") f.close() return True except: pass return False #def check_root def get_server_ip(self): var=self.client.get_variable("","VariablesManager",VARIABLE) if var!=None: try: print var["server"] except: print "ERROR GETTING VALUE" sys.exit(0) #def get_server_ip def set_server_ip(self,value): self.get_n4d_key() sys.stdout.write("* Setting Printa client server ip ... ") current_value=self.client.get_variable("","VariablesManager",VARIABLE) use_add=False if current_value==None: use_add=True current_value={} current_value["server"]=value ret=[False,0] if use_add: ret=self.client.add_variable(self.n4d_key,"VariablesManager",VARIABLE,current_value,"","Printa Client Configuration",["printa"]) else: ret=self.client.set_variable(self.n4d_key,"VariablesManager",VARIABLE,current_value) print(ret[0]) sys.exit(0) #def set_server_ip def get_n4d_key(self): try: f=open("/etc/n4d/key") self.n4d_key=f.readline().strip("\n") f.close() except: print("[!] You need root privileges [!]") sys.exit(0) #def get_n4d_key def usage(self): print "USAGE: printa-printer-config get-server-ip" print " printa-printer-config set-server-ip PRINTA_SERVER_IP" sys.exit(0) #def usage #class PrintaClientConfig if __name__=="__main__": ppc=PrintaClientConfig() ppc.parse_args(sys.argv)