示例#1
0
    def req_copy(self, cinfo ,params):
        pathsrc = self.check_and_replace_path(cinfo, agent.get_prop(params,'pathsrc',None),  self.OPERATION_EDIT)
        pathdst = self.check_and_replace_path(cinfo, agent.get_prop(params,'pathdst',None),  self.OPERATION_EDIT)
        files = agent.get_prop(params,'files',None)
        replace = agent.str2bool(agent.get_prop(params, "replace", "false"))

        arfiles = json.loads(files)
        arret=[]
        for i in range(len(arfiles)):
            nm = arfiles[i]
            fs = pathsrc + nm
            fd = pathdst + nm
            cnt = 0
            if fs==fd:
                while utils.path_exists(fd):
                    cnt+=1
                    nm = "copy " + str(cnt) + " of " + arfiles[i];
                    fd = pathdst + nm
            b = True
            if not fs==fd and fd.startswith(fs + utils.path_sep):
                b = False
            else:
                b = self._cpmv("copy", fs, fd, replace);
            if b is True:
                self._append_to_list(arret, pathdst, nm)
            else:
                arret.append({'Name': "E:" + nm})
            
        return json.dumps({'items' : arret})
示例#2
0
 def req_paste_text(self,cinfo,params):
     sret=""
     sid = agent.get_prop(params,"id", "")
     s = agent.get_prop(params,"text", "")
     dm=self._get_desktop_manager_check_permissions(cinfo,sid)
     dm.paste_text(s);
     return sret
示例#3
0
 def req_makedir(self, cinfo ,params):                                     
     path= self.check_and_replace_path(cinfo, agent.get_prop(params,'path',None), self.OPERATION_EDIT)
     name = agent.get_prop(params, "name", None)
     arret=[]
     try:
         fd = path + name
         utils.path_makedir(fd)
         self._agent_main.get_osmodule().fix_file_permissions("CREATE_DIRECTORY",fd)
         self._append_to_list(arret, path, name)
     except Exception:
         arret.append({'Name': "E:" + name})
     return json.dumps({'items' : arret})
示例#4
0
 def req_set_permissions(self, cinfo ,params):
     path= self.check_and_replace_path(cinfo, agent.get_prop(params,'path',None), self.OPERATION_EDIT)
     name = agent.get_prop(params, "name", None)
     recursive = agent.str2bool(agent.get_prop(params, "recursive", "false"))
     fs = path+name
     arret=[]
     try:
         b=self._set_permissions(fs,params,recursive)
         if b is True:
             self._append_to_list(arret, path, name)
         else:
             arret.append({'Name': "E:" + name})
     except Exception:
         arret.append({'Name': "E:" + name})
     return json.dumps({'items' : arret})
示例#5
0
 def req_read(self, cinfo ,params):
     path = self.check_and_replace_path(cinfo, agent.get_prop(params,'path',None),  self._get_app_filesystem().OPERATION_VIEW)
     position = agent.get_prop(params,'position','')
     maxline = int(agent.get_prop(params,'position','1000'))
     
     fpos = -1l
     flen = utils.path_size(path)
     if  position!="":
         fpos = int(position)
         if fpos > flen:
             fpos = -1
     arl=[]
     if fpos < flen:
         bm = self._get_app_filesystem().detect_bom_file(path)
         enc=None
         if bm is not None:
             enc = bm["Name"]
         f = utils.file_open(path, 'r')
         try:
             if (fpos!=-1):
                 f.seek(fpos)
             while True:
                 ln = f.readline()
                 if ln=="":
                     break
                 if enc is None:
                     enc="UTF-8"
                     try:
                         ln=ln.decode(enc)
                     except:
                         enc=sys.getfilesystemencoding()
                         ln=ln.decode(enc, 'replace')
                 else:
                     ln=ln.decode(enc, 'replace')
                 
                 arl.append(ln.rstrip('\n').rstrip('\r'))
                 if len(arl)>=maxline+1:
                     arl.remove(arl[0])
             if len(arl)>0:
                 arl.append("")
             fpos = f.tell()
         finally:
             f.close()
     ret={}
     ret["text"]='\n'.join(arl)
     if fpos!=-1:
         ret["position"]=str(fpos)
     return json.dumps(ret)
示例#6
0
    def req_rename(self, cinfo ,params):
        path= self.check_and_replace_path(cinfo, agent.get_prop(params,'path',None), self.OPERATION_EDIT)
        name = agent.get_prop(params, "name", None)
        newname = agent.get_prop(params, "newname", None)
        fs = path+name
        fd = path+newname
        arret=[]
        try:
            if utils.path_exists(fd):
                raise Exception("#FILEALREADYEXISTS")
            utils.path_rename(fs, fd)
            self._append_to_list(arret, path, newname)
        except Exception:
            arret.append({'Name': "E:" + newname})

        return json.dumps({'items' : arret})
示例#7
0
 def req_stopservice(self, cinfo ,params):
     name = agent.get_prop(params,"name", None)
     bok = self._osnative.service_stop(name);
     if (bok is True):
         ret = "{ok: true}"
     else:
         ret = "{ok: false}"
     return ret
示例#8
0
 def req_killtask(self, cinfo ,params):
     pid = agent.get_prop(params,"pid", None)
     bok = self._osnative.task_kill(int(pid));
     if (bok is True):
         ret = "{ok: true}"
     else:
         ret = "{ok: false}"
     return ret
示例#9
0
 def req_upload(self, cinfo ,fupload):
     path=agent.get_prop(fupload.get_properties(),'path',None);
     try:
         path = self.check_and_replace_path(cinfo, path, self.OPERATION_UPLOAD, {"check_exists": False})
         fupload.accept(path)        
     except Exception as e:
         if path is None:
             path=""
         raise e
示例#10
0
 def req_download(self, cinfo, fdownload):
     path=agent.get_prop(fdownload.get_properties(),'path',None);
     try:
         path = self.check_and_replace_path(cinfo, path, self.OPERATION_DOWNLOAD)
         fdownload.accept(path)        
     except Exception as e:
         if path is None:
             path=""
         raise e
示例#11
0
    def req_remove(self, cinfo ,params):
        path = self.check_and_replace_path(cinfo, agent.get_prop(params,'path',None), self.OPERATION_EDIT)
        files = agent.get_prop(params,'files',None)

        arfiles = json.loads(files)
        arret=[]
        for i in range(len(arfiles)):
            fp = path + arfiles[i]
            b = True
            try:
                utils.path_remove(fp)
            except Exception:
                b=False            
            tp = None
            if b is True:
                tp="K"
            else:
                tp="E"
            arret.append({'Name': tp + ":" + arfiles[i]})
        return json.dumps({'items' : arret})
示例#12
0
 def req_copy_text(self,cinfo,params):
     sid = agent.get_prop(params,"id", "")
     dm=self._get_desktop_manager_check_permissions(cinfo,sid)
     sret={}
     sret["text"]=dm.copy_text();
     return json.dumps(sret)
示例#13
0
    def req_list(self, cinfo ,params):
        path = agent.get_prop(params,'path',None)
        
        
        only_dir = agent.str2bool(agent.get_prop(params, "onlyDir", "false"))
        only_file = agent.str2bool(agent.get_prop(params, "onlyFile", "false"))
        app_name=agent.get_prop(params, "app")
        #image_info = agent.str2bool(agent.get_prop(params, "imageInfo", "false"))
        
        
        ptfilter = agent.get_prop(params, "filter", None)
        ptfilter_ignorecase = agent.str2bool(agent.get_prop(params, "filterIgnoreCase", "false"))
        ptfilterList= agent.get_prop(params, "filterList", None)
        refilter = None
        if ptfilter is not None:
            if ptfilter_ignorecase:
                refilter = re.compile(ptfilter)
            else:
                refilter = re.compile(ptfilter,re.IGNORECASE)
        arfilterList = None
        if ptfilterList is not None:
            arfilterList = json.loads(ptfilterList)
        
        arret=[]
        if path=="$":
            if app_name is None:
                prms=self.get_permission(cinfo);
            else:
                prms=self.get_permission(cinfo,app_name);
            if prms["fullAccess"]:
                ar = self._osnative.get_resource_path()
                for i in range(len(ar)):
                    itm={}
                    app=ar[i]
                    itm["Name"]=u"D:" + app["Name"];
                    if "Size" in app:
                        itm["Length"]=app["Size"];
                    arret.append(itm)
            else:
                for permpt in prms["paths"]:
                    arret.append({'Name': 'D:' + permpt["name"]})
                    
        else:
            lst=None            
            options={}
            if app_name is not None:
                options["app"]=app_name
            pdir =self.check_and_replace_path(cinfo, path, self.OPERATION_VIEW,options)
            if not utils.path_isdir(pdir):
                raise Exception("Permission denied or read error.");
            try:
                lst=utils.path_list(pdir)
            except Exception:
                raise Exception("Permission denied or read error.");
            #Carica la lista
            for fname in lst:
                #DA GESTIRE COSI EVITA GLI ERRORI MA PER FILENAME NON UTF8 NON RECUPERA ALTRE INFO TIPO LA DIMENSIONE E DATAMODIFICA
                if not isinstance(fname, unicode):
                    fname=fname.decode("utf8","replace")
                
                if pdir==utils.path_sep:
                    fp = pdir + fname
                else:
                    fp = pdir + utils.path_sep + fname
                if (self._osnative.is_file_valid(fp)) and ((not only_dir and not only_file) or (only_dir and utils.path_isdir(fp)) or (only_file and not utils.path_isdir(fp))):
                    bok = True
                    if refilter is not None:
                        bok = refilter.match(fname);
                    if bok and arfilterList is not None:
                        for appnm in arfilterList:
                            bok = False
                            if ptfilter_ignorecase:
                                bok = (fname.lower()==appnm.lower())
                            else:  
                                bok = (fname==appnm)
                            if bok:
                                break
                    if bok is True:
                        self._append_to_list(arret, pdir, fname)
                        # if (image_info==True): DA GESTIRE Width e Height  se file di tipo Immagini

        #ORDINA PER NOME
        arret = sorted(arret, key=lambda k: k['Name'].lower())
         
        jsret = {'items' : arret, 'permissions': {"apps":{}}}
        if path!="$" and app_name is None:
            a = jsret["permissions"]["apps"]
            paths = self.get_permission_path(cinfo, u"#FILESYSTEM://" + path, {"app":"texteditor" ,"check_exists": False})
            if len(paths)>0:
                a["texteditor"]={}
            paths = self.get_permission_path(cinfo, u"#FILESYSTEM://" + path, {"app":"logwatch" ,"check_exists": False})
            if len(paths)>0:
                a["logwatch"]={}
            
            None
         
        return json.dumps(jsret)
示例#14
0
 def req_save(self, cinfo, params):
     path = self.check_and_replace_path(
         cinfo, agent.get_prop(params, 'path', None),
         self._get_app_filesystem().OPERATION_EDIT, {"check_exists": False})
     self._write(path, params)
     return None
示例#15
0
 def req_load(self, cinfo, params):
     path = self.check_and_replace_path(
         cinfo, agent.get_prop(params, 'path', None),
         self._get_app_filesystem().OPERATION_VIEW)
     ret = self._read(path)
     return json.dumps(ret)