Example #1
0
class SanickioskScreensaverPrefs (SectionPlugin):
	default_classconfig = {
		'xscreensaver_enable': True,
		'xscreensaver_idle': '0:01:30',
		'glslideshow_duration': '',
		'glslideshow_pan': '',
		'glslideshow_fade': '3',
		'glslideshow_zoom': '100',
		'glslideshow_clip': True,
	}
	classconfig_root = True

	def init(self):
		self.title = 'Screensaver'
		self.icon = 'picture'
		self.category = 'Sanickiosk'

		self.append(self.ui.inflate('sanickiosk_screensaver:main'))
		self.binder = Binder(self, self)
		self.binder.populate()

	@on('save', 'click')
	def save(self):
		self.binder.update()
		self.save_classconfig()
		self.context.notify('info', _('Saved. Please restart Sanickiosk for changes to take effect.'))
		self.binder.populate()

		all_vars = '\n'.join([k + '="' + str(v) + '"' for k,v in self.classconfig.iteritems()])
		open('/home/kiosk/.sanickiosk/screensaver.cfg', 'w').write(all_vars) #save
Example #2
0
class Netatalk (SectionPlugin):
    config_path = '/etc/afp.conf'

    def init(self):
        self.title = 'Netatalk'
        self.icon = 'folder-close'
        self.category = _('Software')
        self.append(self.ui.inflate('netatalk:main'))

        if not os.path.exists(self.config_path):
            open(self.config_path, 'w').close()

        self.binder = Binder(None, self.find('config'))
        self.find('shares').new_item = lambda c: ShareData()
        self.config = NetatalkConfig(path=self.config_path)

    def on_page_load(self):
        self.refresh()

    def refresh(self):
        self.config.load()
        self.binder.reset(self.config.tree).autodiscover().populate()

    @on('save', 'click')
    def on_save(self):
        self.binder.update()
        self.config.save()
        self.refresh()
Example #3
0
class Netatalk(SectionPlugin):
    config_path = '/etc/afp.conf'

    def init(self):
        self.title = 'Netatalk'
        self.icon = 'folder-close'
        self.category = _('Software')
        self.append(self.ui.inflate('netatalk:main'))

        if not os.path.exists(self.config_path):
            open(self.config_path, 'w').write("[Global]")

        self.binder = Binder(None, self.find('config'))
        self.find('shares').new_item = lambda c: ShareData()
        self.config = NetatalkConfig(path=self.config_path)

    def on_page_load(self):
        self.refresh()

    def refresh(self):
        self.config.load()
        self.binder.reset(self.config.tree).autodiscover().populate()

    @on('save', 'click')
    def on_save(self):
        self.binder.update()
        self.config.save()
        self.refresh()
Example #4
0
class DHCPDPlugin(SectionPlugin):
    def init(self):
        self.title = _('DHCP Server')
        self.icon = 'sitemap'
        self.category = _('Software')

        self.append(self.ui.inflate('dhcpd:main'))

        self.config = DHCPDConfig(path='/etc/dhcp/dhcpd.conf')
        self.binder = Binder(None, self)

        for x in self.nearest(lambda x: x.bind == 'ranges'):
            x.new_item = lambda c: RangeData()
        for x in self.nearest(lambda x: x.bind == 'options'):
            x.new_item = lambda c: OptionData()
        self.find('subnets').new_item = lambda c: SubnetData()

    def on_page_load(self):
        self.config.load()
        self.binder.setup(self.config.tree).populate()

    @on('save', 'click')
    def save(self):
        self.binder.update()
        self.config.save()
class WonderShaper(SectionPlugin):
    # default config could be overwitten on main config.json
    default_classconfig = {'path': '/etc/conf.d/wondershaper.conf'}

    def init(self):
        self.title = 'WonderShaper'
        # Icons set: http://fortawesome.github.io/Font-Awesome/icons/
        self.icon = 'download-alt'
        self.category = 'DXS'

        self.append(self.ui.inflate('wondershaper:main'))

        path = self.classconfig['path']
        self.config = WonderShaperConfig(path=path)
        self.binder = Binder(None, self)

    def on_page_load(self):
        self.config.load()
        data = self.config.tree.wondershaper
        self.binder.reset(data).autodiscover().populate()

    @on('save', 'click')
    def on_save(self):
        self.binder.update()
        self.config.save()
        self.context.notify('info', 'Saved conf')
        ret = subprocess.call(['systemctl', 'restart', 'wondershaper.service'])
        if ret == 0:
            self.context.notify('info', 'Reload service')
        else:
            self.context.notify('error', 'Error on reload service')
Example #6
0
class Squid (SectionPlugin):
    def init(self):
        self.title = _('Squid')
        self.icon = 'exchange'
        self.category = _('Software')
        self.append(self.ui.inflate('squid:main'))

        self.binder = Binder(None, self.find('config'))
        self.find('acl').new_item = lambda c: ACLData()
        self.find('http_access').new_item = lambda c: HTTPAccessData()
        self.find('http_port').new_item = lambda c: HTTPPortData()
        self.find('https_port').new_item = lambda c: HTTPSPortData()
        self.config = SquidConfig(path='/etc/squid3/squid.conf')

    def on_page_load(self):
        self.refresh()

    def refresh(self):
        self.config.load()
        self.binder.reset(self.config.tree).autodiscover().populate()

    @on('save', 'click')
    def on_save(self):
        self.binder.update()
        self.config.save()
        self.refresh()
Example #7
0
class PureFTPDExtension (BaseExtension):
    default_config = {
        'created': False,
        'password': None,
    }
    name = 'FTP'

    def init(self):
        self.append(self.ui.inflate('vh-pureftpd:ext'))
        self.binder = Binder(self, self)

        if not 'username' in self.config:
            self.config['username'] = self.website.slug

        if not self.config['created']:
            self.config['password'] = str(uuid.uuid4())
            self.config['path'] = self.website.root
            self.config['created'] = True

        self.refresh()

    def refresh(self):
        self.binder.setup().populate()

    def update(self):
        self.binder.update()
Example #8
0
class SanickioskScreensaverPrefs(SectionPlugin):
    default_classconfig = {
        'xscreensaver_enable': True,
        'xscreensaver_idle': '0:01:30',
        'glslideshow_duration': '',
        'glslideshow_pan': '',
        'glslideshow_fade': '3',
        'glslideshow_zoom': '100',
        'glslideshow_clip': True,
    }
    classconfig_root = True

    def init(self):
        self.title = 'Screensaver'
        self.icon = 'picture'
        self.category = 'Sanickiosk'

        self.append(self.ui.inflate('sanickiosk_screensaver:main'))
        self.binder = Binder(self, self)
        self.binder.populate()

    @on('save', 'click')
    def save(self):
        self.binder.update()
        self.save_classconfig()
        self.context.notify(
            'info',
            _('Saved. Please restart Sanickiosk for changes to take effect.'))
        self.binder.populate()

        all_vars = '\n'.join(
            [k + '="' + str(v) + '"' for k, v in self.classconfig.iteritems()])
        open('/home/kiosk/.sanickiosk/screensaver.cfg',
             'w').write(all_vars)  #save
Example #9
0
class Supervisor (SectionPlugin):
    def init(self):
        self.title = 'Supervisor'
        self.icon = 'play'
        self.category = _('Software')
        self.append(self.ui.inflate('supervisor:main'))
        self.mgr = SupervisorServiceManager.get()
        self.binder = Binder(None, self.find('main'))
        self.find('programs').new_item = lambda c: ProgramData()
        self.config = SupervisorConfig(path=platform_select(
            default='/etc/supervisor/supervisord.conf',
            centos='/etc/supervisord.conf',
        ))
        self.find('servicebar').name = platform_select(
            centos='supervisord',
            default='supervisor',
        )
        self.find('servicebar').reload()

    def on_page_load(self):
        self.refresh()

    def refresh(self):
        self.config.load()
        self.mgr.fill(self.config.tree.programs)
        self.binder.setup(self.config.tree).populate()

    @on('save', 'click')
    def on_save(self):
        self.binder.update()
        self.config.save()
        self.refresh()
Example #10
0
class Exports(SectionPlugin):
    config_path = '/etc/exports'

    def init(self):
        self.title = 'NFS Exports'
        self.icon = 'hdd'
        self.category = 'System'
        self.append(self.ui.inflate('exports:main'))

        if not os.path.exists(self.config_path):
            open(self.config_path, 'w').close()

        self.config = ExportsConfig(path=self.config_path)
        self.binder = Binder(None, self)
        self.find('exports').new_item = lambda c: ExportData()
        self.find('clients').new_item = lambda c: ClientData()

    def on_page_load(self):
        self.config.load()
        self.binder.reset(self.config.tree).autodiscover().populate()

    @on('save', 'click')
    def save(self):
        self.binder.update()
        self.config.save()
        self.context.notify('info', 'Saved')
Example #11
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()
Example #12
0
class Squid(SectionPlugin):
    def init(self):
        self.title = 'Squid'
        self.icon = 'exchange'
        self.category = _('Software')
        self.append(self.ui.inflate('squid:main'))

        self.find('servicebar').name = platform_select(
            debian='squid3',
            centos='squid',
            default='squid',
        )
        self.find('servicebar').reload()

        self.binder = Binder(None, self.find('config'))
        self.find('acl').new_item = lambda c: ACLData(name='new')
        self.find('http_access').new_item = lambda c: HTTPAccessData()
        self.find('http_port').new_item = lambda c: HTTPPortData()
        self.find('https_port').new_item = lambda c: HTTPSPortData()
        for e in self.nearest(lambda x: x.id == 'options'):
            e.new_item = lambda c: ArgumentData()
        self.config = SquidConfig(path='/etc/squid3/squid.conf')

    def on_page_load(self):
        self.refresh()

    def refresh(self):
        self.config.load()
        self.binder.setup(self.config.tree).populate()

    @on('save', 'click')
    def on_save(self):
        self.binder.update()
        self.config.save()
        self.refresh()
Example #13
0
class DHCPDPlugin (SectionPlugin):
    def init(self):
        self.title = _('DHCP Server')
        self.icon = 'sitemap'
        self.category = _('Software')

        self.append(self.ui.inflate('dhcpd:main'))

        self.config = DHCPDConfig(path='/etc/dhcp/dhcpd.conf')
        self.binder = Binder(None, self)

        for x in self.nearest(lambda x: x.bind == 'ranges'):
            x.new_item = lambda c: RangeData()
        for x in self.nearest(lambda x: x.bind == 'options'):
            x.new_item = lambda c: OptionData()
        self.find('subnets').new_item = lambda c: SubnetData()

    def on_page_load(self):
        self.config.load()
        self.binder.reset(self.config.tree).autodiscover().populate()

    @on('save', 'click')
    def save(self):
        self.binder.update()
        self.config.save()
Example #14
0
class Exports (SectionPlugin):
    config_path = '/etc/exports'

    def init(self):
        self.title = _('NFS Exports')
        self.icon = 'hdd'
        self.category = _('Software')
        self.append(self.ui.inflate('exports:main'))

        if not os.path.exists(self.config_path):
            open(self.config_path, 'w').close()

        self.config = ExportsConfig(path=self.config_path)
        self.binder = Binder(None, self)
        self.find('exports').new_item = lambda c: ExportData()
        self.find('clients').new_item = lambda c: ClientData()

    def on_page_load(self):
        self.config.load()
        self.binder.reset(self.config.tree).autodiscover().populate()

    @on('save', 'click')
    def save(self):
        self.binder.update()
        self.config.save()
        self.context.notify('info', _('Saved'))
Example #15
0
class Supervisor(SectionPlugin):
    def init(self):
        self.title = 'Supervisor'
        self.icon = 'play'
        self.category = _('Software')
        self.append(self.ui.inflate('supervisor:main'))
        self.mgr = SupervisorServiceManager.get()
        self.binder = Binder(None, self.find('main'))
        self.find('programs').new_item = lambda c: ProgramData()
        self.config = SupervisorConfig(path=platform_select(
            default='/etc/supervisor/supervisord.conf',
            centos='/etc/supervisord.conf',
        ))
        self.find('servicebar').name = platform_select(
            centos='supervisord',
            default='supervisor',
        )
        self.find('servicebar').reload()

    def on_page_load(self):
        self.refresh()

    def refresh(self):
        self.config.load()
        self.mgr.fill(self.config.tree.programs)
        self.binder.setup(self.config.tree).populate()

    @on('save', 'click')
    def on_save(self):
        self.binder.update()
        self.config.save()
        self.refresh()
Example #16
0
class SimpleDemo(SectionPlugin):
    def init(self):
        self.title = "Binder"
        self.icon = "question"
        self.category = "Demo"

        self.append(self.ui.inflate("test:binder-main"))

        self.data = [Person("Alice", "123"), Person("Bob", "234")]

        self.dict = {"a": 1, "b": 2}

        self.find("data").text = repr(self.data)

        self.binder = Binder(self, self.find("bindroot"))

    @on("populate", "click")
    def on_populate(self):
        self.binder.populate()

    @on("unpopulate", "click")
    def on_unpopulate(self):
        self.binder.unpopulate()

    @on("update", "click")
    def on_update(self):
        self.binder.update()
        self.find("data").text = repr(self.data)
Example #17
0
class Netatalk(SectionPlugin):
    config_path = "/etc/afp.conf"

    def init(self):
        self.title = "Netatalk"
        self.icon = "folder-close"
        self.category = "Software"
        self.append(self.ui.inflate("netatalk:main"))

        if not os.path.exists(self.config_path):
            open(self.config_path, "w").close()

        self.binder = Binder(None, self.find("config"))
        self.find("shares").new_item = lambda c: ShareData()
        self.config = NetatalkConfig(path=self.config_path)

    def on_page_load(self):
        self.refresh()

    def refresh(self):
        self.config.load()
        self.binder.reset(self.config.tree).autodiscover().populate()

    @on("save", "click")
    def on_save(self):
        self.binder.update()
        self.config.save()
        self.refresh()
Example #18
0
class Squid (SectionPlugin):
    def init(self):
        self.title = 'Squid'
        self.icon = 'exchange'
        self.category = _('Software')
        self.append(self.ui.inflate('squid:main'))

        self.find('servicebar').name = platform_select(
            debian='squid3',
            centos='squid',
            default='squid',
        )
        self.find('servicebar').reload()

        self.binder = Binder(None, self.find('config'))
        self.find('acl').new_item = lambda c: ACLData(name='new')
        self.find('http_access').new_item = lambda c: HTTPAccessData()
        self.find('http_port').new_item = lambda c: HTTPPortData()
        self.find('https_port').new_item = lambda c: HTTPSPortData()
        for e in self.nearest(lambda x: x.id == 'options'):
            e.new_item = lambda c: ArgumentData()
        self.config = SquidConfig(path='/etc/squid3/squid.conf')

    def on_page_load(self):
        self.refresh()

    def refresh(self):
        self.config.load()
        self.binder.setup(self.config.tree).populate()

    @on('save', 'click')
    def on_save(self):
        self.binder.update()
        self.config.save()
        self.refresh()
Example #19
0
class PureFTPDExtension(BaseExtension):
    default_config = {
        'created': False,
        'password': None,
    }
    name = 'FTP'

    def init(self):
        self.append(self.ui.inflate('vh-pureftpd:ext'))
        self.binder = Binder(self, self)

        if not 'username' in self.config:
            self.config['username'] = self.website.slug

        if not self.config['created']:
            self.config['password'] = str(uuid.uuid4())
            self.config['created'] = True

        self.refresh()

    def refresh(self):
        self.binder.setup().populate()

    def update(self):
        self.binder.update()
Example #20
0
class SimpleDemo (SectionPlugin):
    def init(self):
        self.title = 'Binder'
        self.icon = 'question'
        self.category = 'Demo'

        self.append(self.ui.inflate('test:binder-main'))

        self.data = [
            Person('Alice', '123'),
            Person('Bob', '234'),
        ]
        self.find('data').text = repr(self.data)

        self.binder = Binder(self, self.find('bindroot'))

    @on('populate', 'click')
    def on_populate(self):
        self.binder.populate()

    @on('unpopulate', 'click')
    def on_unpopulate(self):
        self.binder.unpopulate()

    @on('update', 'click')
    def on_update(self):
        self.binder.update()
        self.find('data').text = repr(self.data)
Example #21
0
class Resolv(SectionPlugin):
    def init(self):
        self.title = _('Nameservers')
        self.icon = 'globe'
        self.category = _('System')

        self.append(self.ui.inflate('resolv:main'))
        self.find('name-box').labels = [
            _('DNS nameserver'),
            _('Local domain name'),
            _('Search list'),
            _('Sort list'),
            _('Options')
        ]
        self.find('name-box').values = [
            'nameserver', 'domain', 'search', 'sortlist', 'options'
        ]

        self.config = ResolvConfig(path='/etc/resolv.conf')
        self.binder = Binder(None, self.find('resolv-config'))
        self.find('items').new_item = lambda c: ItemData()

    def on_page_load(self):
        self.config.load()
        self.binder.reset(self.config.tree).autodiscover().populate()

    @on('save', 'click')
    def save(self):
        self.binder.update()
        self.config.save()
Example #22
0
class Squid(SectionPlugin):
    def init(self):
        self.title = 'Squid'
        self.icon = 'exchange'
        self.category = 'Software'
        self.append(self.ui.inflate('squid:main'))

        self.binder = Binder(None, self.find('config'))
        self.find('acl').new_item = lambda c: ACLData()
        self.find('http_access').new_item = lambda c: HTTPAccessData()
        self.find('http_port').new_item = lambda c: HTTPPortData()
        self.find('https_port').new_item = lambda c: HTTPSPortData()
        self.config = SquidConfig(path='/etc/squid3/squid.conf')

        #def post_item_bind(object, collection, item, ui):
        #   ui.find('disconnect').on('click', self.on_disconnect, item)
        #self.find('connections').post_item_bind = post_item_bind

    def on_page_load(self):
        self.refresh()

    def refresh(self):
        self.config.load()
        self.binder.reset(self.config.tree).autodiscover().populate()

    @on('save', 'click')
    def on_save(self):
        self.binder.update()
        self.config.save()
        self.refresh()
Example #23
0
class WebserverPlugin(SectionPlugin):
    service_name = ''
    service_buttons = []
    hosts_available_dir = ''
    hosts_enabled_dir = ''
    template = ''
    supports_host_activation = True

    def init(self):
        self.append(self.ui.inflate('webserver_common:main'))
        self.binder = Binder(None, self)
        self.find_type('servicebar').buttons = self.service_buttons
        self.hosts_dir = AvailabilitySymlinks(self.hosts_available_dir,
                                              self.hosts_enabled_dir,
                                              self.supports_host_activation)

        def delete_host(host, c):
            c.remove(host)
            self.hosts_dir.delete(host.name)

        def on_host_bind(o, c, host, u):
            host.__old_name = host.name

        def on_host_update(o, c, host, u):
            if host.__old_name != host.name:
                self.hosts_dir.rename(host.__old_name, host.name)
            host.save()

        def new_host(c):
            name = 'untitled'
            while os.path.exists(self.hosts_dir.get_path(name)):
                name += '_'
            self.hosts_dir.open(name, 'w').write(self.template)
            return WebserverHost(self, self.hosts_dir, name)

        self.find('hosts').delete_item = delete_host
        self.find('hosts').new_item = new_host
        self.find('hosts').post_item_bind = on_host_bind
        self.find('hosts').post_item_update = on_host_update
        self.find('header-active-checkbox').visible = \
            self.find('body-active-line').visible = \
                self.supports_host_activation

    def on_page_load(self):
        self.refresh()

    @on('save-button', 'click')
    def save(self):
        self.binder.update()
        self.refresh()
        self.context.notify('info', 'Saved')

    def refresh(self):
        self.hosts = [
            WebserverHost(self, self.hosts_dir, x)
            for x in self.hosts_dir.list_available()
        ]
        self.binder.reset(self).autodiscover().populate()
        self.find_type('servicebar').reload()
Example #24
0
class NetworkPlugin(SectionPlugin):
    platforms = ["debian", "centos"]

    def init(self):
        self.title = _("Network")
        self.icon = "globe"
        self.category = _("System")
        self.net_config = INetworkConfig.get()

        self.append(self.ui.inflate("network:main"))

        def post_interface_bind(o, c, i, u):
            i.add_bits(self.ui)
            for bit in i.bits:
                u.find("bits").append(self.ui.create("tab", children=[bit], title=bit.title))
            u.find("up").on("click", self.on_up, i)
            u.find("down").on("click", self.on_down, i)
            u.find("restart").on("click", self.on_restart, i)

        def post_interface_update(o, c, i, u):
            for bit in i.bits:
                bit.apply()

        self.find("interfaces").post_item_bind = post_interface_bind
        self.find("interfaces").post_item_update = post_interface_update

        self.binder = Binder(self.net_config, self)

    def on_page_load(self):
        self.refresh()

    def refresh(self):
        self.net_config.rescan()

        sensor = Sensor.find("traffic")
        for i in self.net_config.interface_list:
            i.tx, i.rx = sensor.value(i.name)

        self.binder.reset().autodiscover().populate()
        return

    def on_up(self, iface=None):
        self.net_config.up(iface)
        self.refresh()

    def on_down(self, iface=None):
        self.net_config.down(iface)
        self.refresh()

    def on_restart(self, iface=None):
        self.on_down(iface)
        self.on_up(iface)

    @on("save", "click")
    def on_save(self):
        self.binder.update()
        self.net_config.save()
        self.refresh()
        self.context.notify("info", _("Saved"))
Example #25
0
class NetworkPlugin(SectionPlugin):
    platforms = ['debian', 'centos']

    def init(self):
        self.title = _('Network')
        self.icon = 'globe'
        self.category = _('System')
        self.net_config = INetworkConfig.get()

        self.append(self.ui.inflate('network:main'))

        def post_interface_bind(o, c, i, u):
            i.add_bits(self.ui)
            for bit in i.bits:
                u.find('bits').append(
                    self.ui.create(
                        'tab',
                        children=[bit],
                        title=bit.title,
                    ))
            u.find('up').on('click', self.on_up, i)
            u.find('down').on('click', self.on_down, i)

        def post_interface_update(o, c, i, u):
            for bit in i.bits:
                bit.apply()

        self.find('interfaces').post_item_bind = post_interface_bind
        self.find('interfaces').post_item_update = post_interface_update

        self.binder = Binder(self.net_config, self)

    def on_page_load(self):
        self.refresh()

    def refresh(self):
        self.net_config.rescan()

        sensor = Sensor.find('traffic')
        for i in self.net_config.interface_list:
            i.tx, i.rx = sensor.value(i.name)

        self.binder.reset().autodiscover().populate()
        return

    def on_up(self, iface=None):
        self.net_config.up(iface)
        self.refresh()

    def on_down(self, iface=None):
        self.net_config.down(iface)
        self.refresh()

    @on('save', 'click')
    def on_save(self):
        self.binder.update()
        self.net_config.save()
        self.refresh()
        self.context.notify('info', _('Saved'))
Example #26
0
class Users (SectionPlugin):
    def init(self):
        self.title = 'Users'
        self.icon = 'group'
        self.category = 'System'
        self.append(self.ui.inflate('users:main'))

        def _sorter(x):
            u = int(x.uid)
            if u >= 1000:
                return u - 10000
            return u

        self.find('users').sorting = _sorter

        self.config = PasswdConfig(path='/etc/passwd')
        self.config_g = GroupConfig(path='/etc/group')
        self.binder = Binder(None, self.find('passwd-config'))
        self.binder_g = Binder(None, self.find('group-config'))

        self.mgr = UsersBackend.get()

    def on_page_load(self):
        self.refresh()

    def refresh(self):
        self.config.load()
        self.config_g.load()

        self.binder.reset(self.config.tree).autodiscover().populate()
        self.binder_g.reset(self.config_g.tree).autodiscover().populate()

    @on('add-user', 'click')
    def on_add_user(self):
        self.find('input-username').visible = True

    @on('input-username', 'submit')
    def on_add_user_done(self, value):
        self.mgr.add_user(value)
        self.refresh()

    @on('add-group', 'click')
    def on_add_group(self):
        self.find('input-groupname').visible = True

    @on('input-groupname', 'submit')
    def on_add_group_done(self, value):
        self.mgr.add_group(value)
        self.refresh()

    @on('save-users', 'click')
    def save_users(self):
        self.binder.update()
        self.config.save()

    @on('save-groups', 'click')
    def save_groups(self):
        self.binder_g.update()
        self.config_g.save()
Example #27
0
class NSDPlugin(SectionPlugin):
    def init(self):
        self.title = 'NSD'
        self.icon = 'globe'
        self.category = _('Software')

        self.append(self.ui.inflate('nsd:main'))

        self.config = NSDConfig(path='/etc/nsd3/nsd.conf')
        self.binder = Binder(None, self)
        self.find('zones').new_item = lambda c: ZoneData()

        def post_zone_bind(o, c, i, u):
            path = i.file
            if not path.startswith('/'):
                path = '/etc/nsd3/' + path
            exists = os.path.exists(path)
            u.find('no-file').visible = not exists
            u.find('file').visible = exists
            if exists:
                u.find('editor').value = open(path).read()

            def on_save_zone():
                open(path, 'w').write(u.find('editor').value)
                self.context.notify('info', _('Zone saved'))

            def on_create_zone():
                open(path, 'w').write("""$TTL    604800
@       IN      SOA     ns. root.ns. (
                              1         ; Serial
                         604800         ; Refresh
                          86400         ; Retry
                        2419200         ; Expire
                         604800 )       ; Negative Cache TTL
;
@                   IN      NS      ns.
example.com.        IN      A       127.0.0.1
example.com.        IN      AAAA    ::1
""")
                post_zone_bind(o, c, i, u)

            u.find('save-zone').on('click', on_save_zone)
            u.find('create-zone').on('click', on_create_zone)

        self.find('zones').post_item_bind = post_zone_bind

    def on_page_load(self):
        self.refresh()

    def refresh(self):
        self.config.load()
        self.binder.setup(self.config.tree).populate()

    @on('save', 'click')
    def save(self):
        self.binder.update()
        self.config.save()
        self.refresh()
        self.context.notify('info', _('Saved'))
Example #28
0
class BIND9Plugin (SectionPlugin):
    def init(self):
        self.title = 'BIND9'
        self.icon = 'globe'
        self.category = _('Software')

        self.append(self.ui.inflate('bind9:main'))

        self.config = BIND9Config(path='/etc/bind/named.conf')
        self.binder = Binder(None, self)
        self.find('zones').new_item = lambda c: ZoneData()

        def post_zone_bind(o, c, i, u):
            path = i.file
            if not path.startswith('/'):
                path = '/etc/bind/' + path
            exists = os.path.exists(path)
            u.find('no-file').visible = not exists
            u.find('file').visible = exists
            if exists:
                u.find('editor').value = open(path).read()

            def on_save_zone():
                open(path, 'w').write(u.find('editor').value)
                self.context.notify('info', _('Zone saved'))

            def on_create_zone():
                open(path, 'w').write("""$TTL    604800
@       IN      SOA     ns. root.ns. (
                              1         ; Serial
                         604800         ; Refresh
                          86400         ; Retry
                        2419200         ; Expire
                         604800 )       ; Negative Cache TTL
;
@                   IN      NS      ns.
example.com.        IN      A       127.0.0.1
example.com.        IN      AAAA    ::1
""")
                post_zone_bind(o, c, i, u)

            u.find('save-zone').on('click', on_save_zone)
            u.find('create-zone').on('click', on_create_zone)
        self.find('zones').post_item_bind = post_zone_bind

    def on_page_load(self):
        self.refresh()

    def refresh(self):
        self.config.load()
        self.binder.reset(self.config.tree).autodiscover().populate()

    @on('save', 'click')
    def save(self):
        self.binder.update()
        self.config.save()
        self.refresh()
        self.context.notify('info', _('Saved'))
Example #29
0
class Cron(SectionPlugin):
    def init(self):
        self.title = 'Cron'
        self.icon = 'time'
        self.category = _('System')
        self.append(self.ui.inflate('cron:main'))

        def create_task(cls):
            logging.info('[cron] created a %s' % cls.__name__)
            return cls()

        def remove_task(i, c):
            c.remove(i)
            logging.info('[cron] removed %s' % i.command)

        self.binder = Binder(None, self.find('config'))
        self.find('normal_tasks').new_item = lambda c: create_task(
            CrontabNormalTaskData)
        self.find('special_tasks').new_item = lambda c: create_task(
            CrontabSpecialTaskData)
        self.find('env_settings').new_item = lambda c: create_task(
            CrontabEnvSettingData)
        self.find('normal_tasks').delete_item = remove_task
        self.find('special_tasks').delete_item = remove_task
        self.find('env_settings').delete_item = remove_task

        self.current_user = '******'

    def on_page_load(self):
        self.refresh()

    @on('user-select', 'click')
    def on_user_select(self):
        self.current_user = self.find('users').value
        logging.info('[cron] selected user %s' % self.current_user)
        self.refresh()

    def refresh(self):
        users_select = self.find('users')
        users_select.value = self.current_user
        users = [
            x.name for x in PasswdConfig(path='/etc/passwd').load().tree.users
            if int(x.uid) >= 500 or x.name == 'root'
        ]
        users_select.values = users_select.labels = users

        self.config = CronManager.get().load_tab(self.current_user)
        self.binder.setup(self.config.tree).populate()

    @on('save', 'click')
    def on_save(self):
        self.binder.update()
        logging.info('[cron] edited tasks')
        try:
            CronManager.get().save_tab(self.current_user, self.config)
            self.refresh()
        except Exception, e:
            self.context.notify('error', e.message)
Example #30
0
class WebserverPlugin (SectionPlugin):
    service_name = ''
    service_buttons = []
    hosts_available_dir = ''
    hosts_enabled_dir = ''
    template = ''
    supports_host_activation = True

    def init(self):
        self.append(self.ui.inflate('webserver_common:main'))
        self.binder = Binder(None, self)
        self.find_type('servicebar').buttons = self.service_buttons
        self.hosts_dir = AvailabilitySymlinks(
            self.hosts_available_dir, 
            self.hosts_enabled_dir,
            self.supports_host_activation
        )

        def delete_host(host, c):
            c.remove(host)
            self.hosts_dir.delete(host.name)

        def on_host_bind(o, c, host, u):
            host.__old_name = host.name

        def on_host_update(o, c, host, u):
            if host.__old_name != host.name:
                self.hosts_dir.rename(host.__old_name, host.name)
            host.save()

        def new_host(c):
            name = 'untitled'
            while os.path.exists(self.hosts_dir.get_path(name)):
                name += '_'
            self.hosts_dir.open(name, 'w').write(self.template)
            return WebserverHost(self, self.hosts_dir, name)

        self.find('hosts').delete_item = delete_host
        self.find('hosts').new_item = new_host
        self.find('hosts').post_item_bind = on_host_bind
        self.find('hosts').post_item_update = on_host_update
        self.find('header-active-checkbox').visible = \
            self.find('body-active-line').visible = \
                self.supports_host_activation

    def on_page_load(self):
        self.refresh()

    @on('save-button', 'click')
    def save(self):
        self.binder.update()
        self.refresh()
        self.context.notify('info', 'Saved')

    def refresh(self):
        self.hosts = [WebserverHost(self, self.hosts_dir, x) for x in self.hosts_dir.list_available()]
        self.binder.reset(self).autodiscover().populate()
        self.find_type('servicebar').reload()
Example #31
0
class NetworkPlugin (SectionPlugin):
    platforms = ['debian', 'centos']

    def init(self):
        self.title = _('Network')
        self.icon = 'globe'
        self.category = _('System')
        self.net_config = INetworkConfig.get()

        self.append(self.ui.inflate('network:main'))

        def post_interface_bind(o, c, i, u):
            i.add_bits(self.ui)
            for bit in i.bits:
                u.find('bits').append(self.ui.create(
                    'tab',
                    children=[bit],
                    title=bit.title,
                ))
            u.find('up').on('click', self.on_up, i)
            u.find('down').on('click', self.on_down, i)

        def post_interface_update(o, c, i, u):
            for bit in i.bits:
                bit.apply()

        self.find('interfaces').post_item_bind = post_interface_bind
        self.find('interfaces').post_item_update = post_interface_update

        self.binder = Binder(self.net_config, self)

    def on_page_load(self):
        self.refresh()

    def refresh(self):
        self.net_config.rescan()

        sensor = Sensor.find('traffic')
        for i in self.net_config.interface_list:
            i.tx, i.rx = sensor.value(i.name)

        self.binder.reset().autodiscover().populate()
        return

    def on_up(self, iface=None):
        self.net_config.up(iface)
        self.refresh()

    def on_down(self, iface=None):
        self.net_config.down(iface)
        self.refresh()

    @on('save', 'click')
    def on_save(self):
        self.binder.update()
        self.net_config.save()
        self.refresh()
        self.context.notify('info', _('Saved'))
Example #32
0
class Teamspeak(SectionPlugin):
    def init(self):
        self.title = 'Teamspeak'
        self.icon = 'comments'
        self.category = _('Software')
        self.append(self.ui.inflate('teamspeak3:main'))
        self.backend = TeamspeakBackend.get()
        self.users = []
        self.servers = []
        self.banlist = []
        self.binder = Binder(self, self)

        def post_item_bind_users(object, collection, item, ui):
            ui.find('poke').on('click', self.on_poke, item)
            ui.find('kick').on('click', self.on_kick, item)
            ui.find('ban').on('click', self.on_ban, item)

        def post_item_bind_banlist(object, collection, item, ui):
            ui.find('unban').on('click', self.on_unban, item)

        self.find('users').post_item_bind = post_item_bind_users
        self.find('banlist').post_item_bind = post_item_bind_banlist

    def on_poke(self, item):
        self.backend.clientpoke(item.uid)
        self.context.notify('info', 'Client has been poked!')

    def on_kick(self, item):
        self.backend.clientkick(item.uid)
        self.refresh()
        self.context.notify('info', 'Client has been kicked from the server!')

    def on_ban(self, item):
        self.backend.clientban(item.username)  # @todo Change this to IP Address!
        self.refresh()
        self.context.notify('info', 'Client has been banned from the server!')

    def on_unban(self, item):
        self.backend.clientunban(item.banid)
        self.refresh()
        self.context.notify('info', 'Client has been unbanned from the server!')

    def on_page_load(self):
        self.refresh()

    def refresh(self):
        try:
            self.backend.initialize()
        except Exception as err:
            self.context.notify('error', err.message)
            self.context.launch('configure-plugin', plugin=self.backend)
            return

        self.binder.update()
        self.users = self.backend.clientlist()
        self.servers = self.backend.serverinfo()
        self.banlist = self.backend.banlist()
        self.binder.populate()
Example #33
0
class MySQLExtension (BaseExtension):
    default_config = {
        'created': False,
        'name': None,
        'user': None,
        'password': None,
    }
    name = 'MySQL'

    def init(self):
        self.append(self.ui.inflate('vh-mysql:ext'))
        self.binder = Binder(self, self)
        self.refresh()
        self.db = MySQLDB.get()

    @staticmethod
    def selftest():
        try:
            MySQLDB.get().query_databases()
        except:
            pass

    def refresh(self):
        self.binder.setup().populate()
        self.find('db-name').value = self.website.slug
        
    def update(self):
        self.binder.update()

    def on_destroy(self):
        if self.config['created']:
            self.on_delete()

    @on('create', 'click')
    def on_create(self):
        try:
            self.db.query_databases()
        except Exception, e:
            self.context.notify('error', str(e))
            self.context.launch('configure-plugin', plugin=self.db)
            return

        dbname = self.find('db-name').value
        for db in self.db.query_databases():
            if db.name == dbname:
                self.context.notify('error', 'This DB name is already used')
                return
        
        self.config['username'] = self.website.slug
        self.config['password'] = str(uuid.uuid4())
        self.config['name'] = dbname
        
        try:
            self.db.query_create(self.config['name'])
        except Exception, e:
            self.context.notify('error', str(e))
            return
Example #34
0
class SNMPDPlugin (SectionPlugin):
    service_name = platform_select(
        default='snmpd',
    )

    def init(self):
        self.title = 'SNMP'
        self.icon = 'exchange'
        self.category = _('Software')

        self.append(self.ui.inflate('snmpd:main'))

        self.find('servicebar').name = self.service_name
        self.find('servicebar').reload()

        self.snmp_config = SNMPConfig(path=platform_select(
            default='/etc/snmp/snmp.conf',
        ))

        self.binder = Binder(None, self)

    def on_page_load(self):
        self.refresh()

    def refresh(self):
        self.snmp_config.load()
        enabled_mibs = []
        for mib in self.snmp_config.tree.mibs:
            for x in mib.name.strip('-+:').split(':'):
                enabled_mibs.append(x)
        self.mibs = []
        for dirpath, dirname, filenames in os.walk('/usr/share/mibs', followlinks=True):
            for x in filenames:
                if not x.startswith('.'):
                    mib = MIBData()
                    mib.name = x
                    mib.selected = x in enabled_mibs
                    self.mibs.append(mib)
        self.mibs = sorted(self.mibs, key=lambda x: x.name)
        self.binder.setup(self).populate()

    @on('save', 'click')
    def save(self):
        self.binder.update()
        
        mib = MIBData()
        mib.name = ':'.join([x.name for x in self.mibs if x.selected])
        for x in list(self.snmp_config.tree.mibs):
            self.snmp_config.tree.mibs.remove(x)
        self.snmp_config.tree.mibs.append(mib)

        self.snmp_config.save()
        self.refresh()
        self.context.notify('info', _('Saved'))
        ServiceMultiplexor.get().get_one(self.service_name).restart()
Example #35
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'))
Example #36
0
class Cron(SectionPlugin):
    def init(self):
        self.title = "Cron"
        self.icon = "time"
        self.category = _("System")
        self.append(self.ui.inflate("cron:main"))

        def create_task(cls):
            logging.info("[cron] created a %s" % cls.__name__)
            return cls()

        def remove_task(i, c):
            c.remove(i)
            logging.info("[cron] removed %s" % getattr(i, "command", None))

        self.binder = Binder(None, self.find("config"))
        self.find("normal_tasks").new_item = lambda c: create_task(CrontabNormalTaskData)
        self.find("special_tasks").new_item = lambda c: create_task(CrontabSpecialTaskData)
        self.find("env_settings").new_item = lambda c: create_task(CrontabEnvSettingData)
        self.find("normal_tasks").delete_item = remove_task
        self.find("special_tasks").delete_item = remove_task
        self.find("env_settings").delete_item = remove_task

        self.current_user = "******"

    def on_page_load(self):
        self.refresh()

    @on("user-select", "click")
    def on_user_select(self):
        self.current_user = self.find("users").value
        logging.info("[cron] selected user %s" % self.current_user)
        self.refresh()

    def refresh(self):
        users_select = self.find("users")
        users_select.value = self.current_user
        users = [
            x.name for x in PasswdConfig(path="/etc/passwd").load().tree.users if int(x.uid) >= 500 or x.name == "root"
        ]
        users_select.values = users_select.labels = users

        self.config = CronManager.get().load_tab(self.current_user)
        self.binder.setup(self.config.tree).populate()

    @on("save", "click")
    def on_save(self):
        self.binder.update()
        logging.info("[cron] edited tasks")
        try:
            CronManager.get().save_tab(self.current_user, self.config)
            self.refresh()
        except Exception, e:
            self.context.notify("error", e.message)
Example #37
0
class SanickioskScreensaverPrefs (SectionPlugin):
	default_classconfig = {
		'enable_browser': False,
		'home_url': 'http://*****:*****@on('save', 'click')
	def save(self):
		self.binder.update()
		self.save_classconfig()
		self.context.notify('info', _('Настройките са запаметени. Моля, рестартирайте киоска.'))
		self.binder.populate()

		#all_vars = '\n'.join([k + '="' + str(v) + '"' for k,v in self.classconfig.iteritems()])
		for k,v in self.classconfig.iteritems():
		    if k == 'enable_browser':
			    enable_browser = "X-GNOME-Autostart-enabled=%s" % str(v).lower()
		    if k == 'home_url':
			    home_url = v.lower()
        
        	if enable_browser == "X-GNOME-Autostart-enabled=true":
			ajenti_config = "/etc/ajenti/config.json"
            
            		#Disable Video Mode
            	    	subprocess.call(['sed', '-i', r's/\\"enable_videos\\": true/\\"enable_videos\\": false/g', ajenti_config])
            	    	subprocess.call(['sed', '-i', r's/X-GNOME-Autostart-enabled=true/X-GNOME-Autostart-enabled=false/g', "/home/kiosk/.config/autostart/2-videos.desktop"])
            
            	    	#Disable Photo Mode
            	    	subprocess.call(['sed', '-i', r's/\\"photos_enable\\": true/\\"photos_enable\\": false/g', ajenti_config])
            	    	subprocess.call(['sed', '-i', r's/X-GNOME-Autostart-enabled=true/X-GNOME-Autostart-enabled=false/g', "/home/kiosk/.config/autostart/2-photos.desktop"])
        
        	cfg = ("[Desktop Entry]\n"
			"Type=Application\n"
			"Exec=chromium-browser --kiosk --no-first-run --disable-infobars --disable-session-crashed-bubble %s\n"
			"Hidden=false\n"
			"NoDisplay=false\n"
			"%s\n"
			"Name[en_US]=2-browser\n"
			"Name=2-browser\n"
			"Comment[en_US]=\n"
			"Comment=") % (home_url, enable_browser)
        
        	open('/home/kiosk/.config/autostart/2-browser.desktop', 'w').write(cfg) #save
Example #38
0
class SanickioskScreensaverPrefs (SectionPlugin):
	default_classconfig = {
		    'enable_videos': False,
    		'video_volume': 50
	}
	classconfig_root = True

	def init(self):
		self.title = 'Режим Видео'
		self.icon = 'facetime-video'
		self.category = 'Kiosk'

		self.append(self.ui.inflate('kiosk_videos:main'))
		self.binder = Binder(self, self)
		self.binder.populate()

	@on('save', 'click')
	def save(self):
		self.binder.update()
		self.save_classconfig()
		self.context.notify('info', _('Настройките са запаметени. Моля, рестартирайте киоска.'))
		self.binder.populate()

		#all_vars = '\n'.join([k + '="' + str(v) + '"' for k,v in self.classconfig.iteritems()])
		for k,v in self.classconfig.iteritems():
		    if k == 'enable_videos':
			enable_videos = "X-GNOME-Autostart-enabled=%s" % str(v).lower()
		    if k == 'video_volume':
			video_volume = v.lower()
		
		if enable_videos == "X-GNOME-Autostart-enabled=true":
		    ajenti_config = "/etc/ajenti/config.json"
		    
		    #Disable Browser Mode
		    subprocess.call(['sed', '-i', r's/\\"enable_browser\\": true/\\"enable_browser\\": false/g', ajenti_config])
		    subprocess.call(['sed', '-i', r's/X-GNOME-Autostart-enabled=true/X-GNOME-Autostart-enabled=false/g', "/home/kiosk/.config/autostart/2-browser.desktop"])

		    #Disable Photo Mode
		    subprocess.call(['sed', '-i', r's/\\"photos_enable\\": true/\\"photos_enable\\": false/g', ajenti_config])
		    subprocess.call(['sed', '-i', r's/X-GNOME-Autostart-enabled=true/X-GNOME-Autostart-enabled=false/g', "/home/kiosk/.config/autostart/2-photos.desktop"])

		cfg = ("[Desktop Entry]\n"
		    "Type=Application\n"
		    "Exec=/home/kiosk/.kiosk/videos.sh %s\n"
		    "Hidden=false\n"
		    "NoDisplay=false\n"
		    "%s\n"
		    "Name[en_US]=2-videos\n"
		    "Name=2-videos\n"
		    "Comment[en_US]=\n"
		    "Comment=") % (video_volume, enable_videos)
		    		    
		open('/home/kiosk/.config/autostart/2-videos.desktop', 'w').write(cfg) #save
Example #39
0
class Cron (SectionPlugin):
    def init(self):
        self.title = 'Cron'
        self.icon = 'time'
        self.category = _('System')
        self.append(self.ui.inflate('cron:main'))

        def create_task(cls):
            logging.info('[cron] created a %s' % cls.__name__)
            return cls()

        def remove_task(i, c):
            c.remove(i)
            logging.info('[cron] removed %s' % getattr(i, 'command', None))

        self.binder = Binder(None, self.find('config'))
        self.find('normal_tasks').new_item = lambda c: create_task(CrontabNormalTaskData)
        self.find('special_tasks').new_item = lambda c: create_task(CrontabSpecialTaskData)
        self.find('env_settings').new_item = lambda c: create_task(CrontabEnvSettingData)
        self.find('normal_tasks').delete_item = remove_task
        self.find('special_tasks').delete_item = remove_task
        self.find('env_settings').delete_item = remove_task

        self.current_user = '******'

    def on_page_load(self):
        self.refresh()

    @on('user-select', 'click')
    def on_user_select(self):
        self.current_user = self.find('users').value
        logging.info('[cron] selected user %s' % self.current_user)
        self.refresh()

    def refresh(self):
        users_select = self.find('users')
        users_select.value = self.current_user
        users = [x.name for x in PasswdConfig(path='/etc/passwd').load().tree.users]
        users_select.values = users_select.labels = users

        self.config = CronManager.get().load_tab(self.current_user)
        self.binder.setup(self.config.tree).populate()

    @on('save', 'click')
    def on_save(self):
        self.binder.update()
        logging.info('[cron] edited tasks')
        try:
            CronManager.get().save_tab(self.current_user, self.config)
            self.refresh()
        except Exception as e:
            self.context.notify('error', e.message)
Example #40
0
class CloudFlare(SectionPlugin):
    def init(self):
        self.title = _('CloudFlare')
        self.icon = 'cloud'
        self.category = _('Web')

        self.append(self.ui.inflate('cloudflare:main'))
        self.find('type-box').labels = [
            'A', 'CNAME', 'MX', 'TXT', 'SPF', 'AAAA', 'NS', 'LOC'
        ]
        self.find('type-box').values = [
            'A', 'CNAME', 'MX', 'TXT', 'SPF', 'AAAA', 'NS', 'LOC'
        ]
        self.find('records').new_item = lambda c: Record(
            type='A', name='', content='', ttl=1)
        self.find('records').delete_item = self.delete

        self.zone_new = {}
        self.current_zone = None

        self.backend = CloudFlareBackend.get()
        self.binder_config = Binder(self.backend, self.find('config'))
        self.binder = Binder(None, self)

        def post_zone_del_bind(object, collection, item, ui):
            ui.find('zone-delete').on('click', self.on_zone_delete, item)

        self.find('zones-setup').find(
            'zones-list').post_item_bind = post_zone_del_bind

    def on_page_load(self):
        self.refresh()
        pass

    @on('zone-select', 'click')
    def on_zone_select(self):
        self.current_zone = self.find('zones').value
        self.refresh()

    @on('zone-add', 'click')
    def on_zone_add(self):
        self.binder.update()

        try:
            self.backend.zone_add(self.zone_new['name'],
                                  self.zone_new['resolve_to'],
                                  self.zone_new['subdomains'])
            self.zone_new = {}
        except Exception, e:
            self.context.notify('error', e.message)

        self.refresh()
Example #41
0
class LinuxIfUpDownNetworkConfigSet (NetworkConfigBit):
    cls = 'linux-ifupdown'
    title = 'Scripts'

    def init(self):
        self.append(self.ui.inflate('network:bit-linux-ifupdown'))
        self.binder = Binder(None, self)

    def refresh(self):
        self.binder.setup(self.iface).populate()

    def apply(self):
        self.binder.update()
Example #42
0
class LinuxIPv4NetworkConfigSet(NetworkConfigBit):
    cls = 'linux-ipv4'
    title = 'IPv4'

    def init(self):
        self.append(self.ui.inflate('network:bit-linux-ipv4'))
        self.binder = Binder(None, self)

    def refresh(self):
        self.binder.setup(self.iface).populate()

    def apply(self):
        self.binder.update()
Example #43
0
class LinuxDHCPNetworkConfigSet(NetworkConfigBit):
    cls = 'linux-dhcp'
    title = 'DHCP'

    def init(self):
        self.append(self.ui.inflate('network:bit-linux-dhcp'))
        self.binder = Binder(self.iface, self)

    def refresh(self):
        self.binder.reset(self.iface).autodiscover().populate()

    def apply(self):
        self.binder.update()
Example #44
0
class LinuxDHCPNetworkConfigSet (NetworkConfigBit):
    cls = 'linux-dhcp'
    title = 'DHCP'

    def init(self):
        self.append(self.ui.inflate('network:bit-linux-dhcp'))
        self.binder = Binder(None, self)

    def refresh(self):
        self.binder.setup(self.iface).populate()

    def apply(self):
        self.binder.update()
Example #45
0
class LinuxIfUpDownNetworkConfigSet(NetworkConfigBit):
    cls = 'linux-ifupdown'
    title = 'Scripts'

    def init(self):
        self.append(self.ui.inflate('network:bit-linux-ifupdown'))
        self.binder = Binder(self.iface, self)

    def refresh(self):
        self.binder.reset(self.iface).autodiscover().populate()

    def apply(self):
        self.binder.update()
Example #46
0
class LinuxBasicNetworkConfigSet (NetworkConfigBit):
    cls = 'linux-basic'
    title = 'Basic'

    def init(self):
        self.append(self.ui.inflate('network:bit-linux-basic'))
        self.binder = Binder(self.iface, self)

    def refresh(self):
        self.binder.reset(self.iface).autodiscover().populate()

    def apply(self):
        self.binder.update()
Example #47
0
class Munin(SectionPlugin):
    def init(self):
        self.title = 'Munin'
        self.icon = 'stethoscope'
        self.category = _('Software')
        self.append(self.ui.inflate('munin:main'))

        def post_graph_bind(o, c, i, u):
            for plot in u.nearest(lambda x: x.typeid == 'munin:plot'):
                plot.on('widget', self.on_add_widget, i)

        self.find('graphs').post_item_bind = post_graph_bind

        self.munin_client = MuninClient.get()
        self.binder = Binder(None, self)

    def on_page_load(self):
        self.refresh()

    def on_add_widget(self, graph, url=None, period=None):
        self.context.launch('dashboard-add-widget',
                            cls=MuninWidget,
                            config={
                                'url': url,
                                'period': period
                            })

    def refresh(self):
        self.munin_client.reset()
        try:
            self.munin_client.fetch_domains()
        except requests.ConnectionError as e:
            self.find_type('tabs').active = 1
            self.context.notify(
                'error',
                _('Couldn\'t connect to Munin: %s') % e.message)
        except Exception as e:
            self.find_type('tabs').active = 1
            if e.message == 'auth':
                self.context.notify('error',
                                    _('Munin HTTP authentication failed'))
            else:
                raise
        self.binder.setup(self.munin_client).populate()

    @on('save-button', 'click')
    def save(self):
        self.binder.update()
        self.munin_client.save_classconfig()
        self.refresh()
        self.find_type('tabs').active = 0
Example #48
0
class SanickioskScreensaverPrefs (SectionPlugin):
	default_classconfig = {
		'photos_enable': False,
	}
	classconfig_root = True

	def init(self):
		self.title = 'Режим Снимки'
		self.icon = 'picture'
		self.category = 'Kiosk'

		self.append(self.ui.inflate('kiosk_photos:main'))
		self.binder = Binder(self, self)
		self.binder.populate()

	@on('save', 'click')
	def save(self):
		self.binder.update()
		self.save_classconfig()
		self.context.notify('info', _('Настройките са запаметени. Моля, рестартирайте киоска.'))
		self.binder.populate()

		#all_vars = '\n'.join([k + '="' + str(v) + '"' for k,v in self.classconfig.iteritems()])
        	for k,v in self.classconfig.iteritems():
			if k == 'photos_enable':
				photos_enable = "X-GNOME-Autostart-enabled=%s" % str(v).lower()
        
        	if photos_enable == "X-GNOME-Autostart-enabled=true":
			ajenti_config = "/etc/ajenti/config.json"
		
		#Disable Browser Mode
            	subprocess.call(['sed', '-i', r's/\\"enable_browser\\": true/\\"enable_browser\\": false/g', ajenti_config])
            	subprocess.call(['sed', '-i', r's/X-GNOME-Autostart-enabled=true/X-GNOME-Autostart-enabled=false/g', "/home/kiosk/.config/autostart/2-browser.desktop"])
            
            	#Disable Video Mode
            	subprocess.call(['sed', '-i', r's/\\"enable_videos\\": true/\\"enable_videos\\": false/g', ajenti_config])
            	subprocess.call(['sed', '-i', r's/X-GNOME-Autostart-enabled=true/X-GNOME-Autostart-enabled=false/g', "/home/kiosk/.config/autostart/2-videos.desktop"])
            
        	cfg = ("[Desktop Entry]\n"
		"Type=Application\n"
            	"Exec=feh --recursive --quiet --randomize --full-screen --borderless --reload 300 --slideshow-delay 10 --no-menus --auto-zoom --hide-pointer /home/kiosk/Photos/\n"
            	"Hidden=false\n"
            	"NoDisplay=false\n"
            	"%s\n"
            	"Name[en_US]=2-photos\n"
            	"Name=2-photos\n"
            	"Comment[en_US]=\n"
            	"Comment=") % (photos_enable)
            
        	open('/home/kiosk/.config/autostart/2-photos.desktop', 'w').write(cfg) #save
Example #49
0
class WebserverPlugin(SectionPlugin):
    service_name = ""
    service_buttons = []
    hosts_available_dir = ""
    hosts_enabled_dir = ""
    template = ""

    def init(self):
        self.append(self.ui.inflate("webserver_common:main"))
        self.binder = Binder(None, self)
        self.find_type("servicebar").buttons = self.service_buttons
        self.hosts_dir = AvailabilitySymlinks(self.hosts_available_dir, self.hosts_enabled_dir)

        def delete_host(host, c):
            c.remove(host)
            self.hosts_dir.delete(host.name)

        def on_host_bind(o, c, host, u):
            host.__old_name = host.name

        def on_host_update(o, c, host, u):
            if host.__old_name != host.name:
                self.hosts_dir.rename(host.__old_name, host.name)
            host.save()

        def new_host(c):
            name = "untitled"
            self.hosts_dir.open(name, "w").write(self.template)
            return WebserverHost(self.hosts_dir, name)

        self.find("hosts").delete_item = delete_host
        self.find("hosts").new_item = new_host
        self.find("hosts").post_item_bind = on_host_bind
        self.find("hosts").post_item_update = on_host_update

    def on_page_load(self):
        self.refresh()

    @on("save-button", "click")
    def save(self):
        self.binder.update()
        self.refresh()
        self.context.notify("info", "Saved")

    def refresh(self):
        self.hosts = [WebserverHost(self.hosts_dir, x) for x in self.hosts_dir.list_available()]
        self.binder.reset(self).autodiscover().populate()
        self.find_type("servicebar").reload()
Example #50
0
class CloudFlare (SectionPlugin):
    def init(self):
        self.title = _('CloudFlare')
        self.icon = 'cloud'
        self.category = _('Web')

        self.append(self.ui.inflate('cloudflare:main'))
        self.find('type-box').labels = ['A', 'CNAME', 'MX', 'TXT', 'SPF', 'AAAA', 'NS', 'LOC']
        self.find('type-box').values = ['A', 'CNAME', 'MX', 'TXT', 'SPF', 'AAAA', 'NS', 'LOC']
        self.find('records').new_item = lambda c: Record(type = 'A', name='', content='', ttl=1)
        self.find('records').delete_item = self.delete

        self.zone_new = {}
        self.current_zone = None

        self.backend = CloudFlareBackend.get()
        self.binder_config = Binder(self.backend, self.find('config'))
        self.binder = Binder(None, self)

        def post_zone_del_bind(object, collection, item, ui):
            ui.find('zone-delete').on('click', self.on_zone_delete, item)

        self.find('zones-setup').find('zones-list').post_item_bind = post_zone_del_bind

    def on_page_load(self):
        self.refresh()
        pass

    @on('zone-select', 'click')
    def on_zone_select(self):
        self.current_zone = self.find('zones').value
        self.refresh()

    @on('zone-add', 'click')
    def on_zone_add(self):
        self.binder.update()

        try:
            self.backend.zone_add(self.zone_new['name'], self.zone_new['resolve_to'], self.zone_new['subdomains'])
            self.zone_new = {}
        except Exception, e:
            self.context.notify('error', e.message)

        self.refresh()
Example #51
0
class ProcessesExtension(BaseExtension):
    default_config = {
        'processes': [],
    }
    name = _('Processes')

    def init(self):
        self.append(self.ui.inflate('vh:ext-processes'))
        self.binder = Binder(self, self)
        self.find('processes').new_item = lambda c: WebsiteProcess()
        self.refresh()

    def refresh(self):
        self.processes = [WebsiteProcess(x) for x in self.config['processes']]
        self.binder.setup().populate()

    def update(self):
        self.binder.update()
        self.config['processes'] = [x.save() for x in self.processes]
Example #52
0
class ProcessesExtension (BaseExtension):
    default_config = {
        'processes': [],
    }
    name = _('Processes')

    def init(self):
        self.append(self.ui.inflate('vh:ext-processes'))
        self.binder = Binder(self, self)
        self.find('processes').new_item = lambda c: WebsiteProcess()
        self.refresh()

    def refresh(self):
        self.processes = [WebsiteProcess(x) for x in self.config['processes']]
        self.binder.setup().populate()

    def update(self):
        self.binder.update()
        self.config['processes'] = [x.save() for x in self.processes]
Example #53
0
class Cron(SectionPlugin):
    def init(self):
        self.title = 'Cron'
        self.icon = 'time'
        self.category = _('System')
        self.append(self.ui.inflate('cron:main'))

        self.binder = Binder(None, self.find('config'))
        self.find('normal_tasks').new_item = lambda c: CrontabNormalTaskData()
        self.find(
            'special_tasks').new_item = lambda c: CrontabSpecialTaskData()
        self.find('env_settings').new_item = lambda c: CrontabEnvSettingData()

        self.current_user = '******'

    def on_page_load(self):
        self.refresh()

    @on('user-select', 'click')
    def on_user_select(self):
        self.current_user = self.find('users').value
        self.refresh()

    def refresh(self):
        users_select = self.find('users')
        users_select.value = self.current_user
        users = [
            x.name for x in PasswdConfig(path='/etc/passwd').load().tree.users
        ]
        users_select.values = users_select.labels = users

        self.config = CronManager.get().load_tab(self.current_user)
        self.binder.reset(self.config.tree).autodiscover().populate()

    @on('save', 'click')
    def on_save(self):
        self.binder.update()
        try:
            CronManager.get().save_tab(self.current_user, self.config)
            self.refresh()
        except Exception, e:
            self.context.notify('error', e.message)
Example #54
0
class Hosts(SectionPlugin):
    def init(self):
        self.title = _('Hosts')
        self.icon = 'sitemap'
        self.category = _('System')

        self.append(self.ui.inflate('hosts:main'))

        self.config = HostsConfig(path='/etc/hosts')
        self.binder = Binder(None, self.find('hosts-config'))
        self.find('aliases').new_item = lambda c: AliasData()
        self.find('hosts').new_item = lambda c: HostData()

    def on_page_load(self):
        self.config.load()
        self.binder.setup(self.config.tree).populate()

    @on('save', 'click')
    def save(self):
        self.binder.update()
        self.config.save()
Example #55
0
class NTPDPlugin(SectionPlugin):
    service_name = platform_select(
        default='ntp',
        centos='ntpd',
    )

    def init(self):
        self.title = _('Date & Time')
        self.icon = 'time'
        self.category = _('Software')

        self.append(self.ui.inflate('ntpd:main'))

        self.find('servicebar').name = self.service_name
        self.find('servicebar').reload()

        self.config = NTPDConfig(
            path=platform_select(default='/etc/ntp.conf', ))

        self.binder = Binder(None, self)

        self.find('servers').new_item = lambda c: ServerData()

    def on_page_load(self):
        self.refresh()

    def refresh(self):
        self.config.load()
        self.now = int(time.time())
        self.binder.setup(self).populate()

    @on('set', 'click')
    def on_set(self):
        self.binder.update()
        d = datetime.fromtimestamp(self.now)
        s = d.strftime('%m%d%H%M%Y')
        subprocess.call(['date', s])
        self.refresh()

    @on('sync', 'click')
    def on_sync(self):
        self.binder.update()
        if len(self.config.tree.servers) == 0:
            self.context.notify('error', _('No servers defined'))
            return
        server = self.config.tree.servers[0].address
        output = subprocess.check_output(['ntpdate', '-u', server])
        self.context.notify('info', _('Done'))
        self.context.notify('info', output)
        self.refresh()

    @on('save', 'click')
    def save(self):
        self.binder.update()
        self.config.save()
        self.refresh()
        self.context.notify('info', _('Saved'))
        ServiceMultiplexor.get().get_one(self.service_name).restart()
Example #56
0
class Supervisor(SectionPlugin):
    def init(self):
        self.title = 'Supervisor'
        self.icon = 'play'
        self.category = 'Software'
        self.append(self.ui.inflate('supervisor:main'))
        self.mgr = SupervisorServiceManager.get()
        self.binder = Binder(None, self.find('main'))
        self.find('programs').new_item = lambda c: ProgramData()
        self.config = SupervisorConfig(path='/etc/supervisor/supervisord.conf')

    def on_page_load(self):
        self.refresh()

    def refresh(self):
        self.config.load()
        self.mgr.fill(self.config.tree.programs)
        self.binder.reset(self.config.tree).autodiscover().populate()

    @on('save', 'click')
    def on_save(self):
        self.binder.update()
        self.config.save()
        self.refresh()