예제 #1
0
def get_supported(agt):
    arSupportedApplications=[]
    arSupportedApplications.append("filesystem")
    arSupportedApplications.append("texteditor")
    arSupportedApplications.append("logwatch")
    arSupportedApplications.append("resource")
    #Desktop
    if agent.is_windows() or agent.is_mac():
        arSupportedApplications.append("desktop")
    elif agent.is_linux():
        if agt.get_osmodule().is_gui():
            arSupportedApplications.append("desktop")
    #Shell
    if agent.is_linux() or agent.is_mac():
        arSupportedApplications.append("shell")
    return arSupportedApplications
        
예제 #2
0
파일: resource.py 프로젝트: fahdely/rectenv
 def __init__(self, agent_main):
     self._agent_main=agent_main
     self._osnative = None
     if agent.is_windows():
         self._osnative = NativeWindows(self._agent_main)
     elif agent.is_linux():
         self._osnative = NativeLinux()
     elif agent.is_mac():
         self._osnative = NativeMac()
예제 #3
0
def get_supported(agt):
    arSupportedApplications=[]
    arSupportedApplications.append("filesystem")
    arSupportedApplications.append("texteditor")
    arSupportedApplications.append("logwatch")
    arSupportedApplications.append("resource")
    arSupportedApplications.append("desktop")
    if agent.is_linux() or agent.is_mac() or (agent.is_windows() and platform.release() == '10'):
        arSupportedApplications.append("shell")
    return arSupportedApplications
        
예제 #4
0
def get_supported(agt):
    arSupportedApplications = []
    arSupportedApplications.append("filesystem")
    arSupportedApplications.append("texteditor")
    arSupportedApplications.append("logwatch")
    arSupportedApplications.append("resource")
    arSupportedApplications.append("desktop")
    #Shell
    if agent.is_linux() or agent.is_mac():
        arSupportedApplications.append("shell")
    return arSupportedApplications
예제 #5
0
 def fix_perm(fn):
     if agent.is_mac() and self._appconsoleid!=None:
         utils.path_change_owner(fn, self._appconsoleid, -1)
         utils.path_change_permissions(fn, stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IWGRP)
예제 #6
0
 def _init_process(self):
     if self._bdestroy:
         raise Exception("Process destroyed.")
     iretry=0;
     while True:
         try:
             self._appconsoleid=None
             iretry+=1
             if agent.is_windows():
                 self._appconsoleid=self._get_osmodule().consoleSessionId();
                 if (self._get_osmodule().isWinXP()==1 or self._get_osmodule().isWin2003Server()==1) and self._appconsoleid>0:
                     self._get_osmodule().winStationConnectW()
                     time.sleep(1)
                     self._destroy_internal()
                 elif self._currentconsoleid!=None and self._appconsoleid!=self._currentconsoleid:
                     self._destroy_internal()
             elif agent.is_mac():
                 self._appconsoleid=self._get_osmodule().consoleUserId();
                 if self._currentconsoleid!=None and self._appconsoleid!=self._currentconsoleid:
                     self._destroy_internal()
                     time.sleep(1)
             
             if self._sharedmem==None:
                 self._sharedmem=sharedmem.Stream()
                 def fix_perm(fn):
                     if agent.is_mac() and self._appconsoleid!=None:
                         utils.path_change_owner(fn, self._appconsoleid, -1)
                         utils.path_change_permissions(fn, stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IWGRP)
                 fname = self._sharedmem.create(fixperm=fix_perm)
                 #RUN PROCESS
                 #if utils.path_exists("apps" + utils.path_sep + "desktop.py"): ##MI SERVE IN SVILUPPO
                 #    import compileall
                 #    compileall.compile_file("apps" + utils.path_sep + "desktop.py")
                 if agent.is_windows():
                     runaselevatore=u"False"
                     if self._get_osmodule().isUserInAdminGroup()==1:
                         if self._get_osmodule().isRunAsAdmin()==1:
                             if self._get_osmodule().isProcessElevated()==1:
                                 runaselevatore=u"True"
                     #Gestito cosi perche' sys.executable creave problemi con percorsi unicode
                     exep=sys.executable
                     pyhome=u""
                     appth="native\\service.properties"
                     if (utils.path_exists(appth)):
                         f = utils.file_open(appth, 'r', encoding='utf-8')
                         sprop = f.read()
                         f.close()
                         lns = sprop.splitlines()
                         for line in lns:
                             if line.startswith("pythonPath="):
                                 exep=line[11:]
                             elif line.startswith("pythonHome="):
                                 pyhome=line[11:]
                       
                     appcmd=u"\"" + exep + u"\" -S -m agent app=desktop " + unicode(fname) + u" " + unicode(str(self._agent_main._agent_debug_mode)) + u" windows " + runaselevatore
                     self._ppid = self._get_osmodule().startProcessAsUser(appcmd,pyhome)
                     self._currentconsoleid=self._get_osmodule().consoleSessionId();                        
                 elif agent.is_linux():
                     libenv = os.environ
                     if utils.path_exists("runtime"):
                         libenv["LD_LIBRARY_PATH"]=utils.path_absname("runtime/lib")
                     #for some distro linux command below don't works because missing runpy
                     #self._process=subprocess.Popen([sys.executable, u'-S', u'-m', u'agent' , u'app=desktop', unicode(fname), unicode(str(self._agent_main._agent_debug_mode)),u'linux'], env=libenv)
                     self._process=subprocess.Popen([sys.executable, u'agent.pyc', u'app=desktop', fname, str(self._agent_main._agent_debug_mode),u'linux'], env=libenv)
                     '''
                     stat -c%U /dev/tty2                        
                     if my_args is None: my_args = sys.argv[1:]
                     user_name, cwd = my_args[:2]
                     args = my_args[2:]
                     pw_record = pwd.getpwnam(user_name)
                     user_name      = pw_record.pw_name
                     user_home_dir  = pw_record.pw_dir
                     user_uid       = pw_record.pw_uid
                     user_gid       = pw_record.pw_gid
                     env = os.environ.copy()
                     env[ 'HOME'     ]  = user_home_dir
                     env[ 'LOGNAME'  ]  = user_name
                     env[ 'PWD'      ]  = cwd
                     env[ 'USER'     ]  = user_name
                     self._process=subprocess.Popen([sys.executable, u'agent.pyc', u'app=desktop', fname, str(self._agent_main._agent_debug_mode),u'linux'], env=libenv, preexec_fn=self._init_process_demote(1000, 1000))
                     '''
                     #GESTIRE IL RENICE
                 elif agent.is_mac():
                     self._ppid = self._agent_main.get_osmodule().exec_guilnc(self._appconsoleid,"desktop",[fname, str(self._agent_main._agent_debug_mode),u'mac'])
                     if self._ppid is not None:
                         self._currentconsoleid=self._appconsoleid
                         self._process = None
                     else:
                         self._currentconsoleid=None
                         libenv = os.environ
                         if utils.path_exists("runtime"):
                             libenv["DYLD_LIBRARY_PATH"]=utils.path_absname("runtime/lib")
                         #self._process=subprocess.Popen([sys.executable, u'agent.pyc', u'app=desktop', fname, str(self._agent_main._agent_debug_mode),u'mac'], env=libenv)
                         self._process=subprocess.Popen([sys.executable, u'-S', u'-m', u'agent' , u'app=desktop', unicode(fname), unicode(str(self._agent_main._agent_debug_mode)),u'mac'], env=libenv)
                         #GESTIRE IL RENICE
                 self._appconsoleid=None
                    
                 #Attende che il processo si attiva
                 bok=False
                 for i in range(10):
                     time.sleep(0.5)
                     if self._process!=None:
                         if self._process.poll() == None:
                             bok=True
                             break
                     elif self._ppid!=None:
                         if self._agent_main.get_osmodule().is_task_running(self._ppid):
                             bok=True
                             break
                     else:
                         break
                 if bok:
                     break
                 else:
                     raise Exception("Process not started.")
             else:
                 break
          
         except Exception as e:
             time.sleep(1)
             self._destroy_internal()
             if iretry>=3:
                 raise e