Example #1
0
    def on_submit(self, event, params, vars=None):
        if params[0] == 'dlgEdit':
            v = vars.getvalue('value', '')
            if vars.getvalue('action', '') == 'OK':
                e = backend.Entry()
                if vars.getvalue('disk', 'custom') == 'custom':
                    e.src = vars.getvalue('src', 'none')
                else:
                    e.src = vars.getvalue('disk', 'none')
                e.dst = vars.getvalue('mp', 'none')
                e.fs_type = vars.getvalue('fs', 'none')
                e.options = vars.getvalue('opts', '')
                if vars.getvalue('bind', '0') == '1':
                    e.options += ',bind'
                if vars.getvalue('loop', '0') == '1':
                    e.options += ',loop'
                if vars.getvalue('ro', '0') == '1':
                    e.options += ',ro'
                e.options = e.options.strip(',')
                if e.options.startswith('none,'):
                    e.options = e.options[5:]

                e.dump_p = int(vars.getvalue('dump_p', '0'))
                e.fsck_p = int(vars.getvalue('fsck_p', '0'))
                try:
                    self.fstab[self._editing] = e
                except:
                    self.fstab.append(e)
                backend.save(self.fstab)
            self._editing = -1
Example #2
0
    def get_default_ui(self):
        t = UI.DataTable(UI.DataTableRow(
                UI.Label(text='Source'),
                UI.Label(text='Mountpoint'),
                UI.Label(text='FS type'),
                UI.Label(text='Options'),
                UI.Label(),
                UI.Label(),
                UI.Label(), header=True
               ))
        for u in self.fstab:
            t.append(UI.DataTableRow(
                    UI.Label(text=u.src, bold=True),
                    UI.Label(text=u.dst),
                    UI.Label(text=u.fs_type),
                    UI.Label(text=u.options),
                    UI.Label(text=str(u.dump_p)),
                    UI.Label(text=str(u.fsck_p)),
                    UI.DataTableCell(
                        UI.HContainer(
                            UI.MiniButton(id='edit/'+str(self.fstab.index(u)), text='Edit'),
                            UI.WarningMiniButton(id='del/'+str(self.fstab.index(u)), text='Delete', msg='Remove %s from fstab'%u.src)
                        ),
                        hidden=True
                    )
                ))

        t = UI.VContainer(t, UI.Button(text='Add mount', id='add'))
        if self._editing != -1:
            try:
                e = self.fstab[self._editing]
            except:
                e = backend.Entry()
                e.src = '/dev/sda1'
                e.dst = '/tmp'
                e.options = 'none'
                e.fs_type = 'none'
                e.dump_p = 0
                e.fsck_p = 0
            t.append(self.get_ui_edit(e))

        return t
Example #3
0
    def get_ui(self):
        ui = self.app.inflate('filesystems:main')

        t = ui.find('list')

        for u in self.fstab:
            t.append(
                UI.DTR(
                    UI.Label(text=u.src, bold=True),
                    UI.Label(text=u.dst),
                    UI.Label(text=u.fs_type),
                    UI.Label(text=u.options),
                    UI.Label(text=str(u.dump_p)),
                    UI.Label(text=str(u.fsck_p)),
                    UI.HContainer(
                        UI.TipIcon(iconfont='gen-pencil-2',
                                   id='edit/' + str(self.fstab.index(u)),
                                   text='Edit'),
                        UI.TipIcon(iconfont='gen-cancel-circle',
                                   id='del/' + str(self.fstab.index(u)),
                                   text='Delete',
                                   warning='Remove %s from fstab' % u.src)),
                ))

        if self._editing != -1:
            try:
                e = self.fstab[self._editing]
            except:
                e = backend.Entry()
                e.src = '/dev/sda1'
                e.dst = '/tmp'
                e.options = 'none'
                e.fs_type = 'none'
                e.dump_p = 0
                e.fsck_p = 0
            self.setup_ui_edit(ui, e)

        else:
            ui.remove('dlgEdit')

        return ui
Example #4
0
    def get_ui(self):
        ui = self.app.inflate('filesystems:main')

        t = ui.find('vdlist')

        for x in self._vdevs:
            t.append(
                UI.DTR(
                    UI.Iconfont(iconfont=x.icon), UI.Label(text=x.name),
                    UI.Label(text='Encrypted Disk' if x.fstype ==
                             'crypt' else 'Virtual Disk'),
                    UI.Label(text=str_fsize(x.size)),
                    UI.Label(text=x.mount if x.mount else 'Not Mounted'),
                    UI.HContainer(
                        UI.TipIcon(
                            iconfont='gen-key',
                            text='Encrypt Disk',
                            id=('ecvd/' + str(self._vdevs.index(x))),
                            warning=
                            'Are you sure you wish to encrypt virtual disk %s? This will erase ALL data on the disk, and is irreversible.'
                            % x.name) if x.fstype != 'crypt' else None,
                        UI.TipIcon(iconfont='gen-arrow-down-3'
                                   if x.mount else 'gen-arrow-up-3',
                                   text='Unmount' if x.mount else 'Mount',
                                   id=('umvd/' if x.mount else 'mvd/') +
                                   str(self._vdevs.index(x)))
                        if x.mount != '/' else None,
                        UI.TipIcon(
                            iconfont='gen-cancel-circle',
                            text='Delete',
                            id=('delvd/' + str(self._vdevs.index(x))),
                            warning=
                            'Are you sure you wish to delete virtual disk %s?'
                            % (x.name)) if x.delete else None,
                    )))

        t = ui.find('pdlist')

        for x in self._devs:
            if x.fstype == 'disk':
                fstype = 'Physical Disk'
            elif x.fstype == 'rom':
                fstype = 'Optical Disk Drive'
            elif x.fstype == 'part':
                fstype = 'Disk Partition'
            elif x.fstype == 'loop':
                fstype = 'Loopback'
            else:
                fstype = 'Unknown'
            t.append(
                UI.DTR(
                    UI.Iconfont(iconfont=x.icon),
                    UI.Label(text=x.name, bold=False if x.parent else True),
                    UI.Label(text=fstype), UI.Label(text=str_fsize(x.size)),
                    UI.HContainer(
                        UI.TipIcon(iconfont='gen-arrow-down-3'
                                   if x.mount else 'gen-arrow-up-3',
                                   text='Unmount' if x.mount else 'Mount',
                                   id=('umd/' if x.mount else 'md/') +
                                   str(self._devs.index(x)))
                        if x.mount != '/' and x.fstype != 'disk' else None, )))

        t = ui.find('list')

        for u in self.fstab:
            t.append(
                UI.DTR(
                    UI.Label(text=u.src, bold=True),
                    UI.Label(text=u.dst),
                    UI.Label(text=u.fs_type),
                    UI.Label(text=u.options),
                    UI.Label(text=str(u.dump_p)),
                    UI.Label(text=str(u.fsck_p)),
                    UI.HContainer(
                        UI.TipIcon(iconfont='gen-pencil-2',
                                   id='edit/' + str(self.fstab.index(u)),
                                   text='Edit'),
                        UI.TipIcon(iconfont='gen-cancel-circle',
                                   id='del/' + str(self.fstab.index(u)),
                                   text='Delete',
                                   warning='Remove %s from fstab' % u.src)),
                ))

        if self._editing != -1:
            try:
                e = self.fstab[self._editing]
            except:
                e = backend.Entry()
                e.src = '/dev/sda1'
                e.dst = '/tmp'
                e.options = 'none'
                e.fs_type = 'none'
                e.dump_p = 0
                e.fsck_p = 0
            self.setup_ui_edit(ui, e)
        else:
            ui.remove('dlgEdit')

        if self._add:
            ui.append(
                'main',
                UI.DialogBox(UI.FormLine(UI.TextInput(name='addname',
                                                      id='addname'),
                                         text='Virtual disk name'),
                             UI.FormLine(UI.TextInput(name='addsize',
                                                      id='addsize'),
                                         text='Disk size (in MB)'),
                             UI.FormLine(UI.EditPassword(
                                 id='passwd', value='Click to add password'),
                                         text='Password')
                             if self._add == 'enc' else None,
                             id='dlgAdd'))

        if self._enc:
            ui.append(
                'main',
                UI.DialogBox(UI.FormLine(UI.EditPassword(
                    id='encpasswd', value='Click to add password'),
                                         text='Password'),
                             id='dlgEnc'))

        if self._auth:
            ui.append(
                'main',
                UI.DialogBox(UI.FormLine(UI.Label(text=self._auth.name),
                                         text='For disk:'),
                             UI.FormLine(UI.TextInput(name='authpasswd',
                                                      password=True),
                                         text='Password'),
                             id='dlgAuth'))

        return ui
Example #5
0
    def on_submit(self, event, params, vars=None):
        if params[0] == 'dlgAdd':
            if vars.getvalue('action', '') == 'OK':
                name = vars.getvalue('addname', '')
                size = vars.getvalue('addsize', '')
                passwd = vars.getvalue('passwd', '')
                if not name or not size:
                    self.put_message('err', 'Must choose a name and size')
                elif name in [x.name for x in self._vdevs]:
                    self.put_message(
                        'err',
                        'You already have a virtual disk with that name')
                elif re.search('\.|-|`|\\\\|\/|[ ]', name):
                    self.put_message(
                        'err',
                        'Disk name must not contain spaces, dots, dashes or special characters'
                    )
                elif not can_be_int(size):
                    self.put_message('err',
                                     'Size must be a number in megabytes')
                elif self._add == 'enc' and not passwd:
                    self.put_message('err', 'Must choose a password')
                elif self._add == 'enc' and passwd != vars.getvalue(
                        'passwdb', ''):
                    self.put_message('err', 'Passwords must match')
                elif self._add == 'enc':
                    x = self._fsc.add_vdisk(name, size)
                    self._fsc.encrypt_vdisk(x, passwd, mount=True)
                else:
                    self._fsc.add_vdisk(name, size, mount=True)
            self._add = None
        if params[0] == 'dlgEdit':
            v = vars.getvalue('value', '')
            if vars.getvalue('action', '') == 'OK':
                e = backend.Entry()
                if vars.getvalue('disk', 'custom') == 'custom':
                    e.src = vars.getvalue('src', 'none')
                else:
                    e.src = vars.getvalue('disk', 'none')
                e.dst = vars.getvalue('mp', 'none')
                e.fs_type = vars.getvalue('fs', 'none')
                e.options = vars.getvalue('opts', '')
                if vars.getvalue('bind', '0') == '1':
                    e.options += ',bind'
                if vars.getvalue('loop', '0') == '1':
                    e.options += ',loop'
                if vars.getvalue('ro', '0') == '1':
                    e.options += ',ro'
                e.options = e.options.strip(',')
                if e.options.startswith('none,'):
                    e.options = e.options[5:]

                e.dump_p = int(vars.getvalue('dump_p', '0'))
                e.fsck_p = int(vars.getvalue('fsck_p', '0'))
                try:
                    self.fstab[self._editing] = e
                except:
                    self.fstab.append(e)
                backend.save(self.fstab)
            self._editing = -1
        if params[0] == 'dlgAuth':
            if vars.getvalue('action', '') == 'OK':
                try:
                    self._fsc.mount(self._auth,
                                    vars.getvalue('authpasswd', ''))
                    self.put_message(
                        'info',
                        'Virtual disk decrypted and mounted successfully')
                except Exception, e:
                    self.put_message('err', str(e))
                self._auth = None
Example #6
0
    def get_ui(self):
        if self._redirect is not None:
            r = self._redirect
            self._redirect = None
            return r

        ui = self.app.inflate('filesystems:main')

        t = ui.find('vdlist')

        for x in self._vdevs:
            t.append(UI.DTR(
                UI.Iconfont(iconfont=x.icon),
                UI.Label(text=x.name),
                UI.Label(text='Encrypted Disk' if x.fstype == 'crypt' else 'Virtual Disk'),
                UI.Label(text=str_fsize(x.size)),
                UI.LinkLabel(text=x.mount, id='open/%s'%self.enc_file(x.mount)) if x.mount else UI.Label(text='Not Mounted'),
                UI.HContainer(
                    UI.TipIcon(iconfont='gen-key', 
                        text='Encrypt Disk', 
                        id=('ecvd/' + str(self._vdevs.index(x))),
                        warning='Are you sure you wish to encrypt virtual disk %s? This will erase ALL data on the disk, and is irreversible.'%x.name
                    ) if x.fstype != 'crypt' else None,
                    UI.TipIcon(iconfont='gen-arrow-down-3' if x.mount else 'gen-arrow-up-3', 
                        text='Unmount' if x.mount else 'Mount', 
                        id=('umvd/' if x.mount else 'mvd/') + str(self._vdevs.index(x))
                    ) if x.mount != '/' else None,
                    UI.TipIcon(iconfont='gen-cancel-circle', 
                        text='Delete', 
                        id=('delvd/' + str(self._vdevs.index(x))), 
                        warning='Are you sure you wish to delete virtual disk %s?' % (x.name)
                    ) if x.delete else None,
                )
            ))

        t = ui.find('pdlist')

        for x in self._devs:
            if x.fstype == 'disk':
                fstype = 'Physical Disk'
            elif x.fstype == 'rom':
                fstype = 'Optical Disk Drive'
            elif x.fstype == 'part':
                fstype = 'Disk Partition'
            elif x.fstype == 'loop':
                fstype = 'Loopback'
            else:
                fstype = 'Unknown'
            t.append(UI.DTR(
                UI.Iconfont(iconfont=x.icon),
                UI.Label(text=x.name, bold=False if x.parent else True),
                UI.Label(text=fstype),
                UI.Label(text=str_fsize(x.size)),
                UI.LinkLabel(text=x.mount, id='open/%s'%self.enc_file(x.mount)) if x.mount else UI.Label(text='Not Mounted'),
                UI.HContainer(
                    UI.TipIcon(iconfont='gen-arrow-down-3' if x.mount else 'gen-arrow-up-3', 
                        text='Unmount' if x.mount else 'Mount', 
                        id=('umd/' if x.mount else 'md/') + str(self._devs.index(x))
                    ) if x.mount != '/' and x.fstype != 'disk' else None,
                )
            ))

        t = ui.find('list')

        for u in self.fstab:
            t.append(UI.DTR(
                    UI.Label(text=u.src, bold=True),
                    UI.Label(text=u.dst),
                    UI.Label(text=u.fs_type),
                    UI.Label(text=u.options),
                    UI.Label(text=str(u.dump_p)),
                    UI.Label(text=str(u.fsck_p)),
                    UI.HContainer(
                        UI.TipIcon(iconfont='gen-pencil-2', id='edit/'+str(self.fstab.index(u)), text='Edit'),
                        UI.TipIcon(iconfont='gen-cancel-circle', id='del/'+str(self.fstab.index(u)), text='Delete', warning='Remove %s from fstab'%u.src)
                    ),
                ))

        for x in self._cfg.cipher_opts:
            ui.find('dcipher').append(UI.SelectOption(text=x, value=x, id=x, selected=x==self._cfg.cipher))
        for x in self._cfg.dhash_opts:
            ui.find('dhash').append(UI.SelectOption(text=x, value=x, id=x, selected=x==self._cfg.dhash))
        ui.find('dkeysize').set('value', self._cfg.keysize)

        if self._editing != -1:
            try:
                e = self.fstab[self._editing]
            except:
                e = backend.Entry()
                e.src = '/dev/sda1'
                e.dst = '/tmp'
                e.options = 'none'
                e.fs_type = 'none'
                e.dump_p = 0
                e.fsck_p = 0
            self.setup_ui_edit(ui, e)
        else:
            ui.remove('dlgEdit')

        if self._add:
            ui.append('main', UI.DialogBox(
                UI.FormLine(
                    UI.TextInput(name='addname', id='addname'),
                    text='Virtual disk name', feedback="gen-storage", iid="addname"
                ),
                UI.FormLine(
                    UI.TextInput(name='addsize', id='addsize'),
                    text='Disk size (in MB)', feedback="gen-storage", iid="addsize"
                ),
                UI.Formline(UI.TextInput(id='passwd', name="passwd", password=True, verify="password", verifywith="passwd"),
                    text="Password", feedback="gen-lock", iid="passwd"
                ) if self._add == 'enc' else None,
                UI.Formline(UI.TextInput(id='passwdb', name="passwdb", password=True, verify="password", verifywith="passwd"),
                    text="Confirm password", feedback="gen-lock", iid="passwdb"
                ) if self._add == 'enc' else None,
                id='dlgAdd', title="Adding %s disk" % ('encrypted' if self._add == 'enc' else 'virtual'), iconfont="gen-storage"
            ))

        if self._enc:
            ui.append('main', UI.DialogBox(
                UI.Formline(UI.TextInput(id='encpasswd', name="encpasswd", password=True, verify="password", verifywith="encpasswd"),
                    text="Password", feedback="gen-lock", iid="encpasswd"
                ),
                UI.Formline(UI.TextInput(id='encpasswdb', name="encpasswdb", password=True, verify="password", verifywith="encpasswd"),
                    text="Confirm password", feedback="gen-lock", iid="encpasswdb"
                ),
                id='dlgEnc', title="Encrypting virtual disk %s" % self._enc.name, iconfont="gen-lock"
            ))

        if self._auth:
            ui.append('main', UI.Authorization(
                app='Filesystems',
                reason='Decrypt %s'%self._auth.img,
                label='Please enter your encryption passphrase'
            ))

        return ui
Example #7
0
def Text_Entry(message="Enter Text:", pos=(0, 0), color=(0, 0, 0), size=12):
    entry = backend.Entry(message, pos, color, size)
    return entry.entry