def umount(self, fs, rm=False): if not fs.mount: return if fs.fstype in ['crypt', 'vdisk', 'loop']: dev = None l = losetup.get_loop_devices() for x in l: if l[x].is_used() and l[x].get_filename() == fs.img: dev = l[x] break if dev and fs.fstype == 'crypt': s = shell_cs('umount /dev/mapper/%s' % fs.name, stderr=True) if s[0] != 0: raise Exception('Failed to unmount %s: %s' % (fs.name, s[1])) shell('cryptsetup luksClose %s' % fs.name) dev.unmount() elif dev: s = shell_cs('umount %s' % dev.device, stderr=True) if s[0] != 0: raise Exception('Failed to unmount %s: %s' % (fs.name, s[1])) dev.unmount() else: s = shell_cs('umount %s' % fs.dev, stderr=True) if s[0] != 0: raise Exception('Failed to unmount %s: %s' % (fs.name, s[1])) apis.poicontrol(self.app).drop_by_path(fs.mount) if rm: shutil.rmtree(fs.mount)
def umount(self, fs, rm=False): if not fs.mount: return if fs.fstype in ['crypt', 'vdisk', 'loop']: dev = None l = losetup.get_loop_devices() for x in l: if l[x].is_used() and l[x].get_filename() == fs.img: dev = l[x] break if dev and fs.fstype == 'crypt': s = shell_cs('umount /dev/mapper/%s'%fs.name, stderr=True) if s[0] != 0: raise Exception('Failed to unmount %s: %s'%(fs.name, s[1])) shell('cryptsetup luksClose %s'%fs.name) dev.unmount() elif dev: s = shell_cs('umount %s'%dev.device, stderr=True) if s[0] != 0: raise Exception('Failed to unmount %s: %s'%(fs.name, s[1])) dev.unmount() else: s = shell_cs('umount %s'%fs.name, stderr=True) if s[0] != 0: raise Exception('Failed to unmount %s: %s'%(fs.name, s[1])) apis.poicontrol(self.app).drop_by_path(fs.mount) if rm: shutil.rmtree(fs.mount)
def mount(self, fs, passwd=''): if not os.path.isdir(os.path.join('/media', fs.name)): os.mkdirs(os.path.join('/media', fs.name)) if fs.fstype in ['crypt', 'vdisk', 'loop']: dev = losetup.find_unused_loop_device() dev.mount(fs.img) if fs.fstype == 'crypt': s = shell_cs('echo "%s" | cryptsetup luksOpen %s %s'%(passwd,dev.device,fs.name), stderr=True) if s[0] != 0: dev.unmount() raise Exception('Failed to decrypt %s: %s'%(fs.name, s[1])) s = shell_cs('mount /dev/mapper/%s %s'%(fs.name, os.path.join('/media', fs.name)), stderr=True) if s[0] != 0: shell('cryptsetup luksClose %s'%fs.name) dev.unmount() raise Exception('Failed to mount %s: %s'%(fs.name, s[1])) else: s = shell_cs('mount %s %s'%(dev.device, os.path.join('/media', fs.name)), stderr=True) if s[0] != 0: dev.unmount() raise Exception('Failed to mount %s: %s'%(fs.name, s[1])) apis.poicontrol(self.app).add(fs.name, 'vdisk', fs.mount, 'filesystems', False) else: s = shell_cs('mount %s %s'%(fs.dev, os.path.join('/media', fs.name)), stderr=True) if s[0] != 0: raise Exception('Failed to mount %s: %s'%(fs.name, s[1])) apis.poicontrol(self.app).add(fs.name, 'disk', fs.mount, 'filesystems', False)
def mount(self, fs, passwd=''): if not os.path.isdir(os.path.join('/media', fs.name)): os.makedirs(os.path.join('/media', fs.name)) if fs.fstype in ['crypt', 'vdisk', 'loop']: dev = losetup.find_unused_loop_device() dev.mount(fs.img) if fs.fstype == 'crypt': s = shell_csin('cryptsetup luksOpen %s %s' % (dev.device, fs.name), passwd, stderr=True) if s[0] != 0: dev.unmount() raise Exception('Failed to decrypt %s: %s' % (fs.name, s[1])) s = shell_cs('mount /dev/mapper/%s %s' % (fs.name, os.path.join('/media', fs.name)), stderr=True) if s[0] != 0: shell('cryptsetup luksClose %s' % fs.name) dev.unmount() raise Exception('Failed to mount %s: %s' % (fs.name, s[1])) else: s = shell_cs('mount %s %s' % (dev.device, os.path.join('/media', fs.name)), stderr=True) if s[0] != 0: dev.unmount() raise Exception('Failed to mount %s: %s' % (fs.name, s[1])) apis.poicontrol(self.app).add(fs.name, 'vdisk', fs.mount, 'filesystems', 'gen-storage', False) else: s = shell_cs('mount %s %s' % (fs.dev, os.path.join('/media', fs.name)), stderr=True) if s[0] != 0: raise Exception('Failed to mount %s: %s' % (fs.name, s[1])) apis.poicontrol(self.app).add(fs.name, 'disk', fs.mount, 'filesystems', 'gen-storage', False)
def on_session_start(self): self._cfg = backend.SyncthingConfig(self.app) self._mgr = backend.SyncthingControl(self.app) self._cfg.load() # Generate points of interest fs = apis.poicontrol(self.app) exc = [] r = self._mgr.get_repos() for x in r: if x["directory"] in [y.path for y in fs.get_pois()]: exc.append(x["directory"]) for x in r: if not x["directory"] in exc: fs.add(x["id"], 'fsync', x["directory"], 'fsync', 'gen-folder', False)
if enable is True: try: self.nginx_enable(w) except: raise ReloadError('nginx') if enable is True and wa.php is True: try: self.php_reload() except: raise ReloadError('PHP-FPM') # Make sure that nginx is enabled by default cat.app.get_backend(apis.services.IServiceManager).enable('nginx') # Add the new path to tracked points of interest (POIs) apis.poicontrol(self.app).add(name, 'website', target_path, 'webapps', webapp.plugin_info.icon, False) if specialmsg: return specialmsg def add_reverse_proxy(self, name, path, addr, port, block): w = Webapp() w.name = name w.stype = 'ReverseProxy' w.path = path w.addr = addr w.port = port w.dbengine = None w.dbname = None w.dbuser = None if not block:
def show_opts_add(self, ui): poi_sel = [] for x in sorted(apis.poicontrol(self.app).get_pois(), key=lambda x: x.name): if x.ptype in ['disk', 'vdisk']: poi_sel.append(UI.DButtonItem(text=x.name, href="#", iconfont="gen-storage", onclick="$('#oc-ddir').val('"+x.path+"')")) ui.appendAll('oc-ddir', *poi_sel)
def show_opts_add(self, ui): poi_sel = [] for x in sorted(apis.poicontrol(self.app).get_pois(), key=lambda x: x.name): poi_sel.append(UI.SelectOption(text=x.name, value=x.path)) ui.appendAll('oc-ddir', *poi_sel)