#!/usr/bin/python import xmlrpclib as x import sys class PrintaPrinterConfig: def __init__(self): self.client=x.ServerProxy("https://localhost:9779") #def init def parse_args(self,args): options=["list-controlled","list-non-controlled","enable-control","disable-control"] if len(args)<2: self.usage() if args[1] not in options: self.usage() if args[1]=="list-controlled": self.list_controlled() if args[1]=="list-non-controlled": self.list_non_controlled() if args[1]=="enable-control": self.get_n4d_key() if len(args)<3: self.usage() sys.stdout.write("* Enabling '%s' ... "%args[2]) print self.client.enable_control(self.n4d_key,"Printa",args[2]) if args[1]=="disable-control": self.get_n4d_key() if len(args)<3: self.usage() sys.stdout.write("* Disabling '%s' ... "%args[2]) print self.client.disable_control(self.n4d_key,"Printa",args[2]) #def parse_args def list_controlled(self): printers=self.client.get_controlled_printers("","Printa") for printer in printers: print printer #def list_controlled def list_non_controlled(self): printers=self.client.get_non_controlled_printers("","Printa") for printer in printers: print printer #def list_controlled def usage(self): print "USAGE: printa-printer-config {list-controlled|list-non-controlled}" print " printa-printer-config enable-control DEVICE_NAME" print " printa-printer-config disable-control DEVICE_NAME" sys.exit(0) #def usage 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 #class PrintaPrinterConfig if __name__=="__main__": ppc=PrintaPrinterConfig() ppc.parse_args(sys.argv)