def load_list_md5_agentbase(self):
        listmd5 = []
        self.directory = {  "program_agent" : {},
                            "version" : "",
                            "version_agent" : "",
                            "lib_agent" : {},
                            "script_agent" : {},
                            "fingerprint" : ""}
        self.directory["version"] = file_get_contents( os.path.join(self.dir_agent_base,'agentversion')).replace("\n","").replace("\r","").strip()
        self.directory["version_agent"] = hashlib.md5(self.directory["version"]).hexdigest()
        listmd5.append(self.directory["version_agent"])
        list_script_python_for_update = ['agentxmpp.py', 'launcher.py', 'connectionagent.py']

        #for fichiername in [ x for x in os.listdir(self.dir_agent_base) if x[-3:]== ".py"]:
        for fichiername in list_script_python_for_update:
            self.directory["program_agent"][fichiername] = hashlib.md5(file_get_contents( os.path.join(self.dir_agent_base,fichiername))).hexdigest()
            listmd5.append(self.directory["program_agent"][fichiername])
        for fichiername in [ x for x in os.listdir(os.path.join(self.dir_agent_base, 'lib')) if x[-3:]== ".py"]:
            self.directory["lib_agent"][fichiername]= hashlib.md5(file_get_contents( os.path.join(self.dir_agent_base,'lib',fichiername))).hexdigest()
            listmd5.append(self.directory["lib_agent"][fichiername])
        for fichiername in [ x for x in os.listdir(os.path.join(self.dir_agent_base, 'script')) if x[-3:]== ".py"]:
            self.directory["script_agent"][fichiername]= hashlib.md5(file_get_contents( os.path.join(self.dir_agent_base,'script',fichiername))).hexdigest()
            listmd5.append(self.directory["script_agent"][fichiername])
        listmd5.sort()
        self.directory["fingerprint"]=hashlib.md5(json.dumps(listmd5)).hexdigest()
 def loadkeypublictobase64(self):
     """
     Function load from file the public keys RSA as a base64 string
     """
     if os.path.exists(self.filekeypublic):
         return base64.b64encode(file_get_contents(self.filekeypublic))
     return ""
 def loadkeyalltostr(self):
     """
     Function load from file the keys complete as a string
     """
     if os.path.exists(self.fileallkey):
         return file_get_contents(self.fileallkey)
     return ""
 def loadkeyalltobase64(self):
     """
     Function load from file the keys complete as a base64 string
     """
     if os.path.exists(self.fileallkey):
         return base64.b64encode(file_get_contents(self.fileallkey))
     return ""
 def loadkeypublictostr(self):
     """
     Function load from file the public keys as a string
     """
     if os.path.exists(self.filekeypublic):
         return file_get_contents(self.filekeypublic)
     return ""
 def loadkeypublictobase64(self):
     """
     Function load from file the public keys RSA as a base64 string
     """
     if os.path.exists(self.filekeypublic):
         return base64.b64encode(file_get_contents(self.filekeypublic))
     return ""
def parsexmppjsonfile(path):
    datastr = file_get_contents(path)

    datastr = re.sub(r"(?i) *: *false", " : false", datastr)
    datastr = re.sub(r"(?i) *: *true", " : true", datastr)

    file_put_contents(path, datastr)
 def loadkeypublictostr(self):
     """
     Function load from file the public keys as a string
     """
     if os.path.exists(self.filekeypublic):
         return file_get_contents(self.filekeypublic)
     return ""
 def loadkeyalltobase64(self):
     """
     Function load from file the keys complete as a base64 string
     """
     if os.path.exists(self.fileallkey):
         return base64.b64encode(file_get_contents(self.fileallkey))
     return ""
 def loadkeyalltostr(self):
     """
     Function load from file the keys complete as a string
     """
     if os.path.exists(self.fileallkey):
         return file_get_contents(self.fileallkey)
     return ""
Exemple #11
0
def action(xmppobject, action, sessionid, data, message, ret, dataobj):
    logger.debug("#################################################")
    logger.debug(plugin)
    logger.debug(json.dumps(data, indent=4))
    logger.debug("#################################################")
    if "subaction" in data:
        if data['subaction'] == "update_me":
            # load version agent agentversion
            version = file_get_contents(os.path.join(
                xmppobject.config.diragentbase, "agentversion"))
            if 'descriptoragent' in data:
                if 'program_agent' in data['descriptoragent'] and len(data['descriptoragent']['program_agent']) != 0:
                    logger.debug("Update program script in remote agent [%s]" % message['from'])
                    for script_program_file in data['descriptoragent']['program_agent']:
                        logger.debug("\t- Update program script [%s]" % (script_program_file))
                        sleep(2)
                        load_and_send_remote_agent_file(
                            xmppobject, message['from'], script_program_file, "program_agent", version)
                if 'lib_agent' in data['descriptoragent'] and len(data['descriptoragent']['lib_agent']) != 0:
                    logger.debug("Update lib script in remote agent [%s]" % message['from'])
                    for script_lib_file in data['descriptoragent']['lib_agent']:
                        logger.debug("\t- Update lib script [%s]" % (script_lib_file))
                        sleep(2)
                        load_and_send_remote_agent_file(
                            xmppobject, message['from'], script_lib_file, "lib_agent", version)
                if 'script_agent' in data['descriptoragent'] and len(data['descriptoragent']['script_agent']) != 0:
                    logger.debug("Update script in remote agent [%s]" % message['from'])
                    for script_script_file in data['descriptoragent']['script_agent']:
                        logger.debug("\t- Update script [%s]" % (script_script_file))
                        sleep(2)
                        load_and_send_remote_agent_file(
                            xmppobject, message['from'], script_script_file, "script_agent", version)
 def remotefileeditaction( xmppobject, data ):
     if 'data' in data and 'action' in data['data']:
         if data['data']['action'] == 'loadfile':
             if 'file' in data['data']:
                 filename = os.path.join(directoryconffile(), data['data']['file'])
                 if os.path.isfile(filename): 
                     filedata = file_get_contents(filename)
                     data['data'] = { "result" : filedata, "error" : False , 'numerror' : 0  }
                     return json.dumps(data)
                 else:
                     data['data'] = { "result" : "error file missing",  "error" : True , 'numerror' : 128}
             else:
                 data['data'] = { "result" : "error name file missing" }
         elif data['data']['action'] == 'create':
             if 'file' in data['data'] and data['data']['file'] != "" and 'content' in data['data']:
                 filename = os.path.join(directoryconffile(), data['data']['file'])
                 file_put_contents(filename,  data['data']['content'])
                 data['data'] = { "result" : "create file %s"%filename, "error" : False , 'numerror' : 0 }
                 return json.dumps(data)
             else:
                 data['data'] = { "result" : "error create file : name file missing", "error" : True , 'numerror' : 129 }
         elif data['data']['action'] == 'save':
             if 'file' in data['data'] and data['data']['file'] != "" \
                     and 'content' in data['data']:
                 filename = os.path.join(directoryconffile(), data['data']['file'])
                 if os.path.isfile(filename):
                     #datestr = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")+".ini"
                     #newfilename = filename[:-4] + "_" + datestr
                     #copyfile(filename, newfilename)
                     file_put_contents(filename,  data['data']['content'])
                     data['data'] = { "result" : "save file %s"%filename, "error" : False , 'numerror' : 0 }
                     return json.dumps(data)
                 else:
                     data['data'] = { "result" : "error save config file %s missing"%filename, "error" : True , 'numerror' : 130 }
         elif data['data']['action'] == 'listconfigfile':
             listfileedit = [ x for x in os.listdir(directoryconffile()) if (x.endswith(".ini") or x.endswith(".ini.local"))]
             data['data'] = { "result" : listfileedit, "error" : False , 'numerror' : 0 }
             return json.dumps(data)
         else:
             data['data'] = { "result" : "error the action parameter is not correct ", "error" : True , 'numerror' : 131 }
     else:
         data['data'] = { "result" : "error action remotefileeditaction parameter incorrect", "error" : True , 'numerror' : 132 }
     return json.dumps(data)
Exemple #13
0
 def get(self, second_param):
     self.write(file_get_contents(get_path_intern('assets/index.html')))
Exemple #14
0
 def get(self):
     self.write(file_get_contents(get_path_intern('assets/bundle.js')))
 def remotefileeditaction(xmppobject, data):
     if 'data' in data and 'action' in data['data']:
         if data['data']['action'] == 'loadfile':
             if 'file' in data['data']:
                 filename = os.path.join(directoryconffile(),
                                         data['data']['file'])
                 if os.path.isfile(filename):
                     filedata = file_get_contents(filename)
                     data['data'] = {
                         "result": filedata,
                         "error": False,
                         'numerror': 0
                     }
                     return json.dumps(data)
                 else:
                     data['data'] = {
                         "result": "error file missing",
                         "error": True,
                         'numerror': 128
                     }
             else:
                 data['data'] = {"result": "error name file missing"}
         elif data['data']['action'] == 'create':
             if 'file' in data['data'] and data['data'][
                     'file'] != "" and 'content' in data['data']:
                 filename = os.path.join(directoryconffile(),
                                         data['data']['file'])
                 file_put_contents(filename, data['data']['content'])
                 data['data'] = {
                     "result": "create file %s" % filename,
                     "error": False,
                     'numerror': 0
                 }
                 return json.dumps(data)
             else:
                 data['data'] = {
                     "result": "error create file : name file missing",
                     "error": True,
                     'numerror': 129
                 }
         elif data['data']['action'] == 'save':
             if 'file' in data['data'] and data['data']['file'] != "" \
                     and 'content' in data['data']:
                 filename = os.path.join(directoryconffile(),
                                         data['data']['file'])
                 if os.path.isfile(filename):
                     #datestr = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")+".ini"
                     #newfilename = filename[:-4] + "_" + datestr
                     #copyfile(filename, newfilename)
                     file_put_contents(filename, data['data']['content'])
                     data['data'] = {
                         "result": "save file %s" % filename,
                         "error": False,
                         'numerror': 0
                     }
                     return json.dumps(data)
                 else:
                     data['data'] = {
                         "result":
                         "error save config file %s missing" % filename,
                         "error": True,
                         'numerror': 130
                     }
         elif data['data']['action'] == 'listconfigfile':
             listfileedit = [
                 x for x in os.listdir(directoryconffile())
                 if (x.endswith(".ini") or x.endswith(".ini.local"))
             ]
             data['data'] = {
                 "result": listfileedit,
                 "error": False,
                 'numerror': 0
             }
             return json.dumps(data)
         else:
             data['data'] = {
                 "result": "error the action parameter is not correct ",
                 "error": True,
                 'numerror': 131
             }
     else:
         data['data'] = {
             "result":
             "error action remotefileeditaction parameter incorrect",
             "error": True,
             'numerror': 132
         }
     return json.dumps(data)