#!/usr/bin/env python3 import xmlrpc.client import ssl import sys import os class N4dModules: def __init__(self,server="localhost"): context=ssl._create_unverified_context() self.client = xmlrpc.client.ServerProxy('https://%s:9779'%server,context=context,allow_none=True) self.n4d_key=self.get_n4d_key() if self.n4d_key == None: print("You need administration privileges to run this program.") sys.exit(1) self.actions={} self.actions["load-plugin"]=self.load_plugin self.actions["enable-plugin"]=self.load_plugin self.actions["disable-plugin"]=self.unload_plugin self.actions["unload-plugin"]=self.unload_plugin #def init def get_n4d_key(self): try: f=open("/etc/n4d/key") key=f.readline().strip() f.close() return key except: return None #def get_n4d_key def load_plugin(self,plugin_conf_path): return self.client.load_plugin(self.n4d_key,plugin_conf_path) #def load_plugin def unload_plugin(self,plugin_name): return self.client.unload_plugin(self.n4d_key,plugin_name) #def unload_plugin def usage(self): print("USAGE:") print("n4d-modules load-plugin | enable PLUGIN_CONF_FILE") print("n4d-modules unload-plugin | disable-plugin PLUGIN_NAME") #def usage #class N4dModules if __name__=="__main__": n4dm = N4dModules() if len(sys.argv)!=3: self.n4dm.usage() sys.exit(0) if sys.argv[1] not in n4dm.actions: self.n4dm.usage() sys.exit(0) if not os.path.exists(sys.argv[2]): print("Plugin configuration file not found [!]") sys.exit(0) if sys.argv[1] in ["load-plugin","enable-plugin"]: ret=n4dm.load_plugin(sys.argv[2]) if sys.argv[1] in ["unload-plugin","disable-plugin"]: ret=n4dm.unload_plugin(sys.argv[2]) if ret["status"]==0: sys.exit(0) else: print("Error: [%s] %s"%(ret["error_code"],ret["msg"]))