コード例 #1
0
ファイル: main.py プロジェクト: kingctan/ajenti
class Filesystems(SectionPlugin):
    def init(self):
        self.title = _('Filesystems')
        self.icon = 'hdd'
        self.category = _('System')
        self.append(self.ui.inflate('fstab:main'))

        self.find('type').labels = [
            'Auto', 'EXT2', 'EXT3', 'EXT4', 'NTFS', 'FAT', 'ZFS', 'ReiserFS',
            'Samba', 'None', 'Loop'
        ]
        self.find('type').values = [
            'auto', 'ext2', 'ext3', 'ext4', 'ntfs', 'vfat', 'zfs', 'reiser',
            'smb', 'none', 'loop'
        ]

        self.fstab_config = FSTabConfig(path='/etc/fstab')
        self.mounts = MountsBackend.get()

        self.binder = Binder(None, self)
        self.find('fstab').find(
            'filesystems').new_item = lambda c: FilesystemData()

        def post_mount_bind(object, collection, item, ui):
            ui.find('umount').on('click', self.on_umount, item)

        self.find('mounts').find(
            'filesystems').post_item_bind = post_mount_bind

    def on_page_load(self):
        self.refresh()

    def on_umount(self, mount):
        subprocess.call(['umount', mount.mountpoint])
        self.context.notify('info', _('Unmounted'))
        self.refresh()

    @on('mount-all', 'click')
    def on_mount_all(self):
        if subprocess.call(['mount', '-a']):
            self.context.notify('error', _('mount -a failed'))
        self.refresh()

    @on('refresh', 'click')
    def refresh(self):
        self.reload_disks()
        self.fstab_config.load()
        self.fstab = self.fstab_config.tree
        self.mounts.reload()
        self.binder.reset(self).autodiscover().populate()

    def reload_disks(self):
        lst = disks.list_devices(by_uuid=True, by_id=True, by_label=True)
        self.find('device').labels = [x[0] for x in lst]
        self.find('device').values = [x[1] for x in lst]

    @on('save', 'click')
    def save(self):
        self.binder.update()
        self.fstab_config.save()
コード例 #2
0
ファイル: main.py プロジェクト: AojiaoZero/ajenti
class Filesystems (SectionPlugin):
    def init(self):
        self.title = _('Filesystems')
        self.icon = 'hdd'
        self.category = _('System')
        self.append(self.ui.inflate('fstab:main'))

        self.find('type').labels = ['Auto', 'EXT2', 'EXT3', 'EXT4', 'NTFS', 'FAT', 'ZFS', 'ReiserFS', 'Samba', 'None', 'Loop']
        self.find('type').values = ['auto', 'ext2', 'ext3', 'ext4', 'ntfs', 'vfat', 'zfs', 'reiser',  'smb',   'none', 'loop']

        self.fstab_config = FSTabConfig(path='/etc/fstab')
        self.mounts = MountsBackend.get()

        self.binder = Binder(None, self)
        self.find('fstab').find('filesystems').new_item = lambda c: FilesystemData()

        def post_mount_bind(object, collection, item, ui):
            ui.find('umount').on('click', self.on_umount, item)

        self.find('mounts').find('filesystems').post_item_bind = post_mount_bind

    def on_page_load(self):
        self.refresh()

    def on_umount(self, mount):
        subprocess.call(['umount', mount.mountpoint])
        self.context.notify('info', _('Unmounted'))
        self.refresh()

    @on('mount-all', 'click')
    def on_mount_all(self):
        self.save()
        if subprocess.call(['mount', '-a']):
            self.context.notify('error', _('mount -a failed'))
        self.refresh()

    @on('refresh', 'click')
    def refresh(self):
        self.binder.unpopulate()
        self.reload_disks()
        self.fstab_config.load()
        self.fstab = self.fstab_config.tree
        self.mounts.reload()
        self.binder.setup(self).populate()

    def reload_disks(self):
        lst = disks.list_devices(by_uuid=True, by_id=True, by_label=True)
        self.find('device').labels = [x[0] for x in lst]
        self.find('device').values = [x[1] for x in lst]

    @on('save', 'click')
    def save(self):
        self.binder.update()
        self.fstab_config.save()
        self.context.notify('info', _('Saved'))
コード例 #3
0
ファイル: views.py プロジェクト: Mu-L/ajenti
    def handle_api_set_fstab(self, http_context):
        """
        Write the fstab file.
        Make a backup when save a new fstab file.

        :param http_context: HttpContext
        :type http_context: HttpContext
        :return: Success or not
        :rtype: bool or throw error in save mode
        """

        config = http_context.json_body()['config']
        new_fstab = FSTabConfig(content='')
        new_fstab.load()

        for filesystem in config:
            device = FilesystemData()
            for prop, value in filesystem.items():
                setattr(device, prop, value)
            new_fstab.tree.filesystems.append(device)

        data = new_fstab.save()[None]

        # Always make a backup
        os.rename('/etc/fstab', '/etc/fstab.bak')

        try:
            with open('/etc/fstab', 'w') as f:
                f.write(data)
            return True
        except Exception as e:
            raise EndpointError(e)
コード例 #4
0
    def handle_api_fstab(self, http_context):

        if http_context.method == 'GET':
            self.fstab_config = FSTabConfig(path='/etc/fstab')
            self.fstab_config.load()
            return self.fstab_config.tree.to_dict()

        if http_context.method == 'POST':
            config = http_context.json_body()['config']
            new_fstab = FSTabConfig(content='')
            new_fstab.load()

            for filesystem in config:
                device = FilesystemData()
                for property, value in filesystem.items():
                    setattr(device, property, value)
                new_fstab.tree.filesystems.append(device)

            data = new_fstab.save()[None]

            # Always make a backup
            os.rename('/etc/fstab', '/etc/fstab.bak')

            try:
                with open('/etc/fstab', 'w') as f:
                    f.write(data)
                return True
            except Exception as e:
                raise EndpointError(e)
コード例 #5
0
ファイル: views.py プロジェクト: starnetwork/ajenti
    def handle_api_fstab(self, http_context):
        """
        Load (through get) and write (through post) the fstab file.
        Make a backup when save a new fstab file.
        Method GET.
        Method POST.

        :param http_context: HttpContext
        :type http_context: HttpContext
        :return: Fstab as dict in load mode, success or not in save mode
        :rtype: dict in load mode, bool or throw error in save mode
        """

        if http_context.method == 'GET':
            self.fstab_config = FSTabConfig(path='/etc/fstab')
            self.fstab_config.load()
            return self.fstab_config.tree.to_dict()

        if http_context.method == 'POST':
            config = http_context.json_body()['config']
            new_fstab = FSTabConfig(content='')
            new_fstab.load()

            for filesystem in config:
                device = FilesystemData()
                for prop, value in filesystem.items():
                    setattr(device, prop, value)
                new_fstab.tree.filesystems.append(device)

            data = new_fstab.save()[None]

            # Always make a backup
            os.rename('/etc/fstab', '/etc/fstab.bak')

            try:
                with open('/etc/fstab', 'w') as f:
                    f.write(data)
                return True
            except Exception as e:
                raise EndpointError(e)
コード例 #6
0
ファイル: main.py プロジェクト: NejcV/ajenti
class Filesystems(SectionPlugin):
    def init(self):
        self.title = _("Filesystems")
        self.icon = "hdd"
        self.category = _("System")
        self.append(self.ui.inflate("fstab:main"))

        self.find("type").labels = [
            "Auto",
            "EXT2",
            "EXT3",
            "EXT4",
            "NTFS",
            "FAT",
            "ZFS",
            "ReiserFS",
            "Samba",
            "None",
            "Loop",
        ]
        self.find("type").values = [
            "auto",
            "ext2",
            "ext3",
            "ext4",
            "ntfs",
            "vfat",
            "zfs",
            "reiser",
            "smb",
            "none",
            "loop",
        ]

        self.fstab_config = FSTabConfig(path="/etc/fstab")
        self.mounts = MountsBackend.get()

        self.binder = Binder(None, self)
        self.find("fstab").find("filesystems").new_item = lambda c: FilesystemData()

        def post_mount_bind(object, collection, item, ui):
            ui.find("umount").on("click", self.on_umount, item)

        self.find("mounts").find("filesystems").post_item_bind = post_mount_bind

    def on_page_load(self):
        self.refresh()

    def on_umount(self, mount):
        subprocess.call(["umount", mount.mountpoint])
        self.context.notify("info", _("Unmounted"))
        self.refresh()

    @on("mount-all", "click")
    def on_mount_all(self):
        self.save()
        if subprocess.call(["mount", "-a"]):
            self.context.notify("error", _("mount -a failed"))
        self.refresh()

    @on("refresh", "click")
    def refresh(self):
        self.binder.unpopulate()
        self.reload_disks()
        self.fstab_config.load()
        self.fstab = self.fstab_config.tree
        self.mounts.reload()
        self.binder.setup(self).populate()

    def reload_disks(self):
        lst = disks.list_devices(by_uuid=True, by_id=True, by_label=True)
        self.find("device").labels = [x[0] for x in lst]
        self.find("device").values = [x[1] for x in lst]

    @on("save", "click")
    def save(self):
        self.binder.update()
        self.fstab_config.save()
        self.context.notify("info", _("Saved"))
コード例 #7
0
config.load()
c = 0
mountpoints = ['/', '/srv']
while True:
    # try all fstab entries
    try:
        for i in mountpoints:
            # if mountpoint matches change mount options
            if config.tree.filesystems[c].mountpoint == i:
                msg = 'Modifying mount options for ' + i + ' '
                printScript(msg, '', False, False, True)
                try:
                    # get mount options from constants
                    config.tree.filesystems[c].options = constants.ROOTMNTOPTS
                    # save fstab
                    config.save()
                    printScript(' Success!', '', True, True, False, len(msg))
                except:
                    printScript(' Failed!', '', True, True, False, len(msg))
                    sys.exit(1)
                msg = 'Remounting ' + i + ' '
                printScript(msg, '', False, False, True)
                # try to remount filesystem with new options
                try:
                    subProc('mount -o remount ' + i, logfile)
                    printScript(' Success!', '', True, True, False, len(msg))
                except:
                    printScript(' Failed!', '', True, True, False, len(msg))
                    sys.exit(1)
        # next entry
        c += 1