示例#1
0
 def install_agent(self):
     """Installs the ossec agent in the given remote system"""
     if not  self.__authfile:
         self.__add_error("Can't create the auth file")
         return False
     smb = SambaClient(self.__authfile, SMB_WINEXEC_CONFIGURATION_FILE, self.__host)
     wine = WinExeC(self.__authfile, SMB_WINEXEC_CONFIGURATION_FILE, self.__host)
     #systemunit = wine.get_working_unit()
     origdstfile = "%s" % (os.path.basename(OSSEC_AGENT_BINARY_FILE))
     logger.info("Saving the binary file")
     if not smb.put_file(DOWNLOADS_FOLDER, os.path.basename(OSSEC_AGENT_BINARY_FILE), "", origdstfile):
         self.__add_error("Error copying the file to the remote host")
         return False
     # installs
     logger.info("Running the ossec-agent setup....")
     systemunit = wine.get_working_unit()
     if not systemunit:
         self.__add_error("Can't retrieve the system unit from remote host. Maybe I can't connect to the remote host.")
         return False
     dstfile = "%s:/%s" % (systemunit.lower(), os.path.basename(OSSEC_AGENT_BINARY_FILE))
     if not wine.run_command('%s /S' % (dstfile)):
         logger.info("Running the ossec-agent setup.... FAIL")
         self.__add_error("Error installing the ossec agent..")
         return False
     time.sleep(2)
     if not smb.remove_file(origdstfile):
         logger.info("Error removing the ossec-agent from the remote host")
         self.__add_error("Error removing the ossec-agent from the remote host")
     return True
示例#2
0
 def restart_services(self):
     """Restart services
     """
     wine = WinExeC(self.__authfile, SMB_WINEXEC_CONFIGURATION_FILE, self.__host)
     program_files_folder = wine.get_environment_variable("ProgramFiles")
     program_files_folder = program_files_folder.split(':')
     dstdir = "%s\\ossec-agent" % program_files_folder[1]
     dstdir = dstdir.encode('string-escape')
     self.__status = OssecDeployStatus.RESTARTING_SERVICES
     
     if not  wine.run_command(command='cd  \\\"%s\\\"\ & service-stop' % dstdir, send_key=True, sleep_time=3):
         self.__add_error("Error stopping the ossec-agent")
         return False
     if not  wine.run_command(command='cd  \\\"%s\\\" & service-start' % dstdir, send_key=True, sleep_time=3):
         self.__add_error("Error starting the ossec-agent")
         return False
     return True