def fix_file_permissions(self, operation, path, path_src=None): apppath = path if apppath.endswith(utils.path_sep): apppath = apppath[0:len(apppath) - 1] apppath_src = path_src if apppath_src is not None: if apppath_src.endswith(utils.path_sep): apppath_src = apppath_src[0:len(apppath_src) - 1] else: apppath_src = utils.path_dirname(path) stat_info = utils.path_stat(apppath_src) mode = stat.S_IMODE(stat_info.st_mode) if operation == "CREATE_DIRECTORY": utils.path_change_permissions(path, mode) utils.path_change_owner(path, stat_info.st_uid, stat_info.st_gid) elif operation == "CREATE_FILE": utils.path_change_permissions( path, ((mode & ~stat.S_IXUSR) & ~stat.S_IXGRP) & ~stat.S_IXOTH) utils.path_change_owner(path, stat_info.st_uid, stat_info.st_gid) elif operation == "COPY_DIRECTORY" or operation == "COPY_FILE": utils.path_change_permissions(path, mode) stat_info = utils.path_stat(utils.path_dirname( path)) #PRENDE IL GRUPPO E L'UTENTE DELLA CARTELLA PADRE utils.path_change_owner(path, stat_info.st_uid, stat_info.st_gid) elif operation == "MOVE_DIRECTORY" or operation == "MOVE_FILE": utils.path_change_permissions(path, mode) utils.path_change_owner(path, stat_info.st_uid, stat_info.st_gid)
def mkdir(self, path, mode): relpath = self._relpath(path) folder_name = os.path.basename(relpath) os.mkdir(path, mode) self.dht[relpath] = utils.path_stat(path) # update ls of parent dirname = os.path.dirname(relpath) par = self.dht[dirname] utils.rdict_update(par, {'ls':[folder_name]}) self.dht[dirname] = par
def get_service_list(self): ret=[] if self._which("systemctl"): p = subprocess.Popen("systemctl --all --full list-units | grep \.service", stdout=subprocess.PIPE, shell=True) (po, pe) = p.communicate() p.wait() if po is not None and len(po)>0: appar = po.split("\n") for appln in appar: sv = "" stcnt = -1 stapp = "" ar = appln.split(" ") for k in ar: if len(k)>0: if stcnt == -1: if k.endswith(".service"): sv+=k[0:len(k)-8] stcnt+=1 else: sv+=k else: stcnt+=1 if stcnt==3: stapp=k if stcnt != -1: if stapp == "running": st = 4 else: st = 1 ret.append({"Name":sv,"Label":"","Status":st}) else: #SYSVINIT for x in utils.path_list('/etc/init.d'): if x.lower()!="rc" and x.lower()!="rcs" and x.lower()!="halt" and x.lower()!="reboot" and x.lower()!="single": xp = "/etc/init.d/" + x st = utils.path_stat(xp) if bool(st.st_mode & stat.S_IXUSR) or bool(st.st_mode & stat.S_IXGRP) or bool(st.st_mode & stat.S_IXOTH): appf = utils.file_open("/etc/init.d/" + x) apps = appf.read() appf.close() if "status)" in apps or "status|" in apps: p = subprocess.Popen("/etc/init.d/" + x + " status", stdout=subprocess.PIPE, shell=True) (po, pe) = p.communicate() p.wait() if po is not None and len(po)>0: st = 999 if "running" in po.lower() or "started" in po.lower(): st = 4 elif "not running" in po.lower() or "not started" in po.lower() or "failed" in po.lower(): st = 1 ret.append({"Name":x,"Label":"","Status":st}) return ret
def get_file_permissions(self,path): try: import pwd import grp import stat stat_info = utils.path_stat(path) user = stat_info.st_uid try: user = pwd.getpwuid(user).pw_name except: None group = stat_info.st_gid try: group = grp.getgrgid(group).gr_name except: None smode = str(oct(stat.S_IMODE(stat_info.st_mode)))[-3:] itm={} itm["Rights"] = smode itm["Owner"] = user itm["Group"] = group return itm except: return {}