Esempio n. 1
0
    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
Esempio n. 2
0
File: views.py Progetto: 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)
Esempio n. 3
0
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()
Esempio n. 4
0
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'))
Esempio n. 5
0
File: views.py Progetto: Mu-L/ajenti
    def handle_api_get_fstab(self, http_context):
        """
        Load the fstab file.

        :param http_context: HttpContext
        :type http_context: HttpContext
        :return: Fstab as dict
        :rtype: dict in load mode
        """

        self.fstab_config = FSTabConfig(path='/etc/fstab')
        self.fstab_config.load()
        return self.fstab_config.tree.to_dict()
Esempio n. 6
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)
Esempio n. 7
0
File: main.py Progetto: NejcV/ajenti
    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
Esempio n. 8
0
    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
Esempio n. 9
0
    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)
Esempio n. 10
0
File: views.py Progetto: Mu-L/ajenti
class Handler(HttpPlugin):
    def __init__(self, context):
        self.context = context

    @get(r'/api/fstab/mounts')
    @endpoint(api=True)
    def handle_api_mounted(self, http_context):
        """
        Parse the output of the df command to generate a dict of mount devices.

        :param http_context: HttpContext
        :type http_context: HttpContext
        :return: Details of mounted devices
        :rtype: dict
        """

        filesystems = []

        mounted = subprocess.check_output(['df', '-PT']).decode('utf-8')
        for entry in mounted.splitlines()[1:]:
            entry = entry.split()

            device = entry[0]
            fstype = entry[1]
            mountpoint = entry[6]  # Problem with mac os ?
            used = int(entry[3]) * 1024
            size = int(entry[2]) * 1024
            usage = used / size

            filesystems.append({
                'device': device,
                'mountpoint': mountpoint,
                'used': used,
                'size': size,
                'usage': usage,
                'fstype': fstype,
            })

        return filesystems

    @post(r'/api/fstab/command_umount')
    @endpoint(api=True)
    def handle_api_umount(self, http_context):
        """
        Umount some device.

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

        mountpoint = http_context.json_body()['mountpoint']
        try:
            subprocess.check_output(['umount', mountpoint])
            return True
        except Exception as e:
            raise EndpointError(e)

    @get(r'/api/fstab')
    @endpoint(api=True)
    def handle_api_get_fstab(self, http_context):
        """
        Load the fstab file.

        :param http_context: HttpContext
        :type http_context: HttpContext
        :return: Fstab as dict
        :rtype: dict in load mode
        """

        self.fstab_config = FSTabConfig(path='/etc/fstab')
        self.fstab_config.load()
        return self.fstab_config.tree.to_dict()

    @post(r'/api/fstab')
    @endpoint(api=True)
    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)
Esempio n. 11
0
File: main.py Progetto: 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"))
Esempio n. 12
0
import os
import reconfigure

from reconfigure.configs import FSTabConfig
from reconfigure.items.fstab import FilesystemData
from functions import printScript
from functions import subProc

title = os.path.basename(__file__).replace('.py', '').split('_')[1]
logfile = constants.LOGDIR + '/setup.' + title + '.log'

printScript('', 'begin')
printScript(title)

# patch fstab with mount options
config = FSTabConfig(path='/etc/fstab')
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
Esempio n. 13
0
class Handler(HttpPlugin):
    def __init__(self, context):
        self.context = context

    @url(r'/api/get_mounted')
    @endpoint(api=True)
    def handle_api_mounted(self, http_context):

        if http_context.method == 'GET':
            filesystems = []

            mounted = subprocess.check_output(['df', '-P']).decode('utf-8')
            for entry in mounted.splitlines()[1:]:
                entry = entry.split()

                device = entry[0]
                mountpoint = entry[5]  # Problem with mac os ?
                used = int(entry[2]) * 1024
                size = int(entry[1]) * 1024
                usage = used / size

                filesystems.append({
                    'device': device,
                    'mountpoint': mountpoint,
                    'used': used,
                    'size': size,
                    'usage': usage
                })

            return filesystems

    @url(r'/api/umount')
    @endpoint(api=True)
    def handle_api_umount(self, http_context):

        if http_context.method == 'POST':
            mountpoint = http_context.json_body()['mountpoint']
            try:
                subprocess.check_output(['umount', mountpoint])
                return True
            except Exception as e:
                raise EndpointError(e)

    @url(r'/api/fstab')
    @endpoint(api=True)
    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)