コード例 #1
0
ファイル: main.py プロジェクト: jiningeast/netcontrol
    def get_ui(self):
        from urllib import urlopen
        ui = self.app.inflate('estacoes:main')
        t = ui.find('list')

        for x in os.popen('/usr/bin/arp-scan -q -l').read().split(
                '\n\n')[0].split('Starting')[1].split('\n')[1:]:
            tmpH = x.split()[0]
            if self.__isNetControl(tmpH):
                self.hosts.append(x.split())

        for h in self.hosts:
            t.append(
                UI.DTR(
                    UI.OutlinkLabel(url=str("http://" + h[0] + ":8000"),
                                    text="Acessar " + h[0])))

        if self._editing is not None:
            try:
                h = self.hosts[self._editing]
            except:
                h = backend.Host()
            d = self.app.inflate(
                'estacoes:edit')  # inflate and fill the dialog
            d.find('name').set('value', h)
            ui.append('main', d)  # and append it to main UI

        return ui
コード例 #2
0
ファイル: main.py プロジェクト: Ozerich/ajenti
    def get_ui(self):
        panel = UI.PluginPanel(
                    UI.Label(text='The static lookup table for hostnames'), 
                    title='Hosts', 
                    icon='/dl/hosts/icon.png'
                )

        t = UI.DataTable(UI.DataTableRow(
            UI.Label(text='IP address'),
            UI.Label(text='Hostname'),
            UI.Label(text='Aliases'),
            UI.Label(),
            header = True
        ))
        for h in self.hosts:
            t.append(UI.DataTableRow(
                UI.Label(text=h.ip),
                UI.Label(text=h.name),
                UI.Label(text=h.aliases),
                UI.DataTableCell(
                    UI.HContainer(
                        UI.MiniButton(
                            id='edit/' + str(self.hosts.index(h)), 
                            text='Edit'
                        ),
                        UI.WarningMiniButton(
                            id='del/' + str(self.hosts.index(h)),
                            text='Delete', 
                            msg='Remove %s from hosts'%h.ip
                        )
                    ),
                    hidden=True
                )
            ))
        t = UI.VContainer(
                t, 
                UI.HContainer(
                    UI.Button(text='Add host', id='add'),
                    UI.Button(text='Change hostname', id='hostname')
                )
            )

        if self._editing is not None:
            try:
                h = self.hosts[self._editing]
            except:
                h = backend.Host()
            t.append(self.get_ui_edit(h))

        if self._editing_self:
            t.append(UI.InputBox(text='Hostname:', value=self.hostname, id='dlgSelf'))

        panel.append(t)
        return panel
コード例 #3
0
ファイル: main.py プロジェクト: jiningeast/netcontrol
 def on_submit(self, event, params, vars=None):
     if params[0] == 'dlgEdit':
         if vars.getvalue('action', '') == 'OK':
             h = backend.Host()
             h.name = vars.getvalue('name', 'none')
             try:
                 self.hosts[self._editing] = h
             except:
                 self.hosts.append(h)
             backend.Config(self.app).save(self.hosts)
         self._editing = None
コード例 #4
0
ファイル: main.py プロジェクト: jiningeast/netcontrol
    def get_ui(self):
        ui = self.app.inflate('backup:main')
        t = ui.find('list')
        for h in self.hosts:
            try:
                rot = h.split('.tar.gz')[0].split('_')[-2:]
                rot = "%0.2d/%0.2d/%d -  %0.2d:%0.2d" % (int(
                    rot[0][6:8]), int(rot[0][4:6]), int(
                        rot[0][0:4]), int(rot[1][0:2]), int(rot[1][2:4]))
                ADD = True
            except:
                ADD = False
                rot = ''

            if ADD:
                t.append(
                    UI.DTR(
                        UI.Label(text=h), UI.Label(text=rot),
                        UI.HContainer(
                            UI.TipIcon(icon='/dl/core/ui/stock/refresh.png',
                                       id='restaurar/' +
                                       str(self.hosts.index(h)),
                                       text='Restaurar'),
                            UI.TipIcon(icon='/dl/core/ui/stock/delete.png',
                                       id='del/' + str(self.hosts.index(h)),
                                       text='Delete',
                                       msg='Remove %s from hosts' % h))))
            else:
                t.append(
                    UI.DTR(
                        UI.DTH(UI.Label(text=("Desconhecido: %s" % h),
                                        bold=False),
                               colspan=3)))

        if self._editing == 'fazer_backup':

            bck = self.app.inflate('backup:bck')
            bck.find('nome').set('value', 'etc_backup')
            ui.append('main', bck)  # and append it to main UI
        elif self._editing is not None:
            try:
                h = self.hosts[self._editing]
            except:
                h = backend.Host()
            d = self.app.inflate('backup:restaurar')
            msg = 'Deseja realmente restaurar o backup '
            msg += h
            d.find('restaurar_bck').set('text', msg)
            ui.append('main', d)

        return ui
コード例 #5
0
ファイル: main.py プロジェクト: Ozerich/ajenti
 def on_submit(self, event, params, vars = None):
     if params[0] == 'dlgEdit':
         v = vars.getvalue('value', '')
         if vars.getvalue('action', '') == 'OK':
             h = backend.Host()
             h.ip = vars.getvalue('ip', 'none')
             h.name = vars.getvalue('name', 'none')
             h.aliases = vars.getvalue('aliases', '')
             try:
                 self.hosts[self._editing] = h
             except:
                 self.hosts.append(h)
             backend.Config(self.app).save(self.hosts)
         self._editing = None
     if params[0] == 'dlgSelf':
         v = vars.getvalue('value', '')
         if vars.getvalue('action', '') == 'OK':
             backend.Config(self.app).sethostname(v)
         self._editing_self = None
コード例 #6
0
ファイル: main.py プロジェクト: vlara/ajenti
    def get_ui(self):
        ui = self.app.inflate('hosts:main')
        t = ui.find('list')

        for h in self.hosts:
            t.append(UI.DTR(
                UI.Label(text=h.ip),
                UI.Label(text=h.name),
                UI.Label(text=h.aliases),
                UI.HContainer(
                    UI.TipIcon(
                        icon='/dl/core/ui/stock/edit.png',
                        id='edit/' + str(self.hosts.index(h)),
                        text='Edit'
                    ),
                    UI.TipIcon(
                        icon='/dl/core/ui/stock/delete.png',
                        id='del/' + str(self.hosts.index(h)),
                        text='Delete',
                        warning='Remove %s from hosts'%h.ip
                    )
                ),
            ))

        if self._editing is not None:
            try:
                h = self.hosts[self._editing]
            except:
                h = backend.Host()
            ui.find('ip').set('value', h.ip)
            ui.find('name').set('value', h.name)
            ui.find('aliases').set('value', h.aliases)
        else:
            ui.remove('dlgEdit')

        if self._editing_self:
            ui.find('dlgSelf').set('value', self.hostname)
        else:
            ui.remove('dlgSelf')

        return ui
コード例 #7
0
ファイル: main.py プロジェクト: skyboyhjj/genesis
    def get_ui(self):
        self.ifacelist = []
        ui = self.app.inflate('network:main')
        ui.find('tabs').set('active', self._tab)
        cl = ui.find('connlist')
        """
        Network Config
        """

        for x in self.conn_config.connections:
            i = self.conn_config.connections[x]
            cl.append(
                UI.DTR(
                    UI.HContainer(
                        UI.IconFont(
                            iconfont=('gen-checkmark-circle' if i.up else ''),
                            text=('Connected' if i.up else ''),
                        ), ),
                    UI.Label(text=i.name),
                    UI.Label(text=i.devclass),
                    UI.Label(text=i.addressing),
                    UI.HContainer(
                        UI.TipIcon(iconfont='gen-info',
                                   text='Info',
                                   id='conninfo/' + i.name),
                        UI.TipIcon(iconfont='gen-pencil-2',
                                   text='Edit',
                                   id='editconn/' + i.name),
                        UI.TipIcon(
                            iconfont='gen-%s' % ('checkmark-circle' if not i.up
                                                 else 'minus-circle'),
                            text=('Disconnect' if i.up else 'Connect'),
                            id=('conn' + ('down' if i.up else 'up') + '/' +
                                i.name),
                            warning='%s %s? This may interrupt your session.' %
                            (('Disconnect' if i.up else 'Connect to'),
                             i.name)),
                        UI.TipIcon(iconfont='gen-%s' %
                                   ('link' if not i.enabled else 'link-2'),
                                   text=('Disable' if i.enabled else 'Enable'),
                                   id=('conn' +
                                       ('disable' if i.enabled else 'enable') +
                                       '/' + i.name)),
                        UI.TipIcon(
                            iconfont='gen-cancel-circle',
                            text='Delete',
                            id=('delconn/' + i.name),
                            warning=
                            'Delete %s? This is permanent and may interrupt your session.'
                            % (i.name))),
                ))

        nl = ui.find('devlist')

        for x in self.net_config.interfaces:
            i = self.net_config.interfaces[x]
            nl.append(
                UI.DTR(
                    UI.HContainer(
                        UI.IconFont(iconfont='gen-%s' %
                                    ('checkmark-circle' if i.up else ''),
                                    text=('Up' if i.up else '')), ),
                    UI.Label(text=i.name),
                    UI.Label(text=i.devclass),
                    UI.Label(text=self.net_config.get_ip(i.name)),
                    UI.HContainer(
                        UI.TipIcon(iconfont='gen-info',
                                   text='Info',
                                   id='intinfo/' + i.name),
                        UI.TipIcon(
                            iconfont='gen-%s' % ('checkmark-circle' if not i.up
                                                 else 'cancel-circle'),
                            text=('Down' if i.up else 'Up'),
                            id=('if' + ('down' if i.up else 'up') + '/' +
                                i.name),
                            warning=
                            'Bring %s interface %s? This may interrupt your session.'
                            % (('Down' if i.up else 'Up'), i.name)),
                        UI.TipIcon(iconfont='gen-%s' %
                                   ('link' if not i.enabled else 'link-2'),
                                   text=('Disable' if i.enabled else 'Enable'),
                                   id=('if' +
                                       ('disable' if i.enabled else 'enable') +
                                       '/' + i.name))),
                ))
            self.ifacelist.extend(i.name)

        c = ui.find('conn')

        if self._info is not None:
            c.append(
                UI.DialogBox(self.net_config.get_info(
                    self.net_config.interfaces[self._info]),
                             id='dlgInfo',
                             hidecancel=True))

        if self._conninfo is not None:
            c.append(
                UI.DialogBox(self.conn_config.get_conn_info(
                    self.conn_config.connections[self._conninfo]),
                             id='dlgConnInfo',
                             hidecancel=True))

        if self._editing_conn is not None:
            if self._editing_conn is not True:
                ce = self._editing_conn
                ui.find('name').set('value', ce.name)
                ui.find('name').set('disabled', 'true')
                ui.find('devclass').set('value', ce.devclass)
                ui.find('interface').set('value', ce.interface)
                ui.find('description').set('value', ce.description)
                ui.find('addressing').set('value', ce.addressing)
                ui.find('address').set('value', ce.address)
                ui.find('gateway').set('value', ce.gateway)
                if ce.interface[:-1] in ['wlan', 'ra', 'wifi', 'ath']:
                    ui.find('security').set('value', ce.security)
                    ui.find('essid').set('value', ce.essid)
                    if ce.security != 'none' and ce.security != 'wpa-configsection':
                        ui.find('key').set('value', ce.key)
        else:
            ui.remove('dlgEditConn')
        """
        Hosts Config
        """

        ht = ui.find('hostlist')

        for h in self.hosts:
            ht.append(
                UI.DTR(
                    UI.Label(text=h.ip),
                    UI.Label(text=h.name),
                    UI.Label(text=h.aliases),
                    UI.HContainer(
                        UI.TipIcon(iconfont='gen-pencil-2',
                                   id='edit/' + str(self.hosts.index(h)),
                                   text='Edit'),
                        UI.TipIcon(iconfont='gen-cancel-circle',
                                   id='del/' + str(self.hosts.index(h)),
                                   text='Delete',
                                   warning='Remove %s from hosts' % h.ip)),
                ))

        if self._editing is not None:
            try:
                h = self.hosts[self._editing]
            except:
                h = backend.Host()
            ui.find('ip').set('value', h.ip)
            ui.find('name').set('value', h.name)
            ui.find('aliases').set('value', h.aliases)
        else:
            ui.remove('dlgEdit')

        if self._editing_self:
            ui.find('dlgSelf').set('value', self.hostname)
        else:
            ui.remove('dlgSelf')
        """
        DNS Config
        """

        td = ui.find('list')

        for x in range(0, len(self.dns_config.nameservers)):
            i = self.dns_config.nameservers[x]
            td.append(
                UI.DTR(
                    UI.Label(text=i.cls),
                    UI.Label(text=i.address),
                    UI.HContainer(
                        UI.TipIcon(iconfont='gen-pencil-2',
                                   text='Edit',
                                   id='editns/' + str(x)),
                        UI.TipIcon(iconfont='gen-close',
                                   text='Remove',
                                   id='delns/' + str(x))),
                ))

        if self._editing_ns == None:
            ui.remove('dlgEditDNS')
        else:
            ns = self.dns_config.nameservers[self._editing_ns]
            classes = ['nameserver', 'domain', 'search', 'sortlist', 'options']
            for c in classes:
                e = ui.find('cls-' + c)
                e.set('value', c)
                e.set('selected', ns.cls == c)
            ui.find('value').set('value', ns.address)

        return ui
コード例 #8
0
ファイル: main.py プロジェクト: skyboyhjj/genesis
    def on_dlg_submit(self, event, params, vars=None):
        if params[0] == 'dlgEditConn':
            v = vars.getvalue('value', '')
            if vars.getvalue('action', '') == 'OK':
                name = vars.getvalue('name', '')
                f = open('/etc/netctl/' + name, 'w')
                f.write("# automatically generated by arkOS Genesis\n")

                devclass = vars.getvalue('devclass', '')
                if devclass:
                    f.write('Connection=\'' + devclass + '\'\n')

                description = vars.getvalue('description', '')
                if description:
                    f.write('Description=\'' + description + '\'\n')

                interface = vars.getvalue('interface', '')
                if interface:
                    f.write('Interface=\'' + interface + '\'\n')

                security = vars.getvalue('security', '')
                if security:
                    f.write('Security=\'' + security + '\'\n')

                essid = vars.getvalue('essid', '')
                if essid and devclass == 'wireless':
                    f.write('ESSID=\"' + essid + '\"\n')

                addressing = vars.getvalue('addressing', '')
                if addressing:
                    f.write('IP=\'' + addressing + '\'\n')

                address = vars.getvalue('address', '')
                if address and addressing == 'static':
                    f.write('Address=(\'' + address + '\')\n')

                gateway = vars.getvalue('gateway', '')
                if gateway and addressing == 'static':
                    f.write('Gateway=\'' + gateway + '\'\n')

                key = vars.getvalue('key', '')
                if key and devclass == 'wireless':
                    f.write('Key=\"' + key + '\"\n')

                f.close()
                self.conn_config.rescan()
            self._editing_conn = None
        if params[0] == 'dlgInfo':
            self._info = None
        if params[0] == 'dlgConnInfo':
            self._conninfo = None
        if params[0] == 'dlgEdit':
            v = vars.getvalue('value', '')
            if vars.getvalue('action', '') == 'OK':
                h = backend.Host()
                h.ip = vars.getvalue('ip', 'none')
                h.name = vars.getvalue('name', 'none')
                h.aliases = vars.getvalue('aliases', '')
                try:
                    self.hosts[self._editing] = h
                except:
                    self.hosts.append(h)
                backend.Config(self.app).save(self.hosts)
            self._editing = None
        if params[0] == 'dlgSelf':
            v = vars.getvalue('value', '')
            if vars.getvalue('action', '') == 'OK':
                backend.Config(self.app).sethostname(v)
            self._editing_self = None
        if params[0] == 'dlgEditDNS':
            if vars.getvalue('action', '') == 'OK':
                try:
                    i = self.dns_config.nameservers[self._editing_ns]
                except:
                    i = Nameserver()
                    self.dns_config.nameservers.append(i)

                i.cls = vars.getvalue('cls', 'nameserver')
                i.address = vars.getvalue('address', '127.0.0.1')
                self.dns_config.save()
            self._editing_ns = None
コード例 #9
0
    def get_ui(self):
        config = ContrBanda()
        confBanda = config.getConfigFile()
        # testando se a alguma configuracao de banda
        if confBanda.get('interface') == None or confBanda.get(
                'medida') == None or confBanda.get('banda') == None:
            ui = self.app.inflate('controle_banda:cad_banda')
            lista = ui.find('interface')
            for i in self.getInterface():
                lista.append(UI.SelectOption(value=i, text=i))
        # caso tenha uma banda já configurada segue adiante com opcoes de redefinir o controle de banda e cadastrar novos filtros etc
        else:
            ui = self.app.inflate('controle_banda:main')
            lista = ui.find('interface')
            ui.find('banda').set(
                'value', confBanda.get('banda')
            )  # mostrando a quantidade de banda que esta configurada

            med = ui.find('tipo_medida')
            if confBanda.get('medida') == 'MBytes':
                med.append(
                    UI.TipIcon(
                        icon='/dl/core/ui/stock/info.png',
                        text='Quantidade de banda em MBytes',
                    ))
            else:
                med.append(
                    UI.TipIcon(
                        icon='/dl/core/ui/stock/info.png',
                        text='Quantidade de banda em KBytes',
                    ))

            mascaras = ui.find('mascara')
            for i in range(33):
                mascaras.append(
                    UI.SelectOption(value=int(32 - i), text=int(32 - i)))
        # imprimindo interfaces que podem ser definidas
            for i in self.getInterface():
                if i == confBanda.get('interface'):
                    lista.append(
                        UI.SelectOption(value=i, text=i, selected=True))

            # imprimindo os filtros cadastrados se tiverem
            t = ui.find('list')
            if self.hosts == []:
                t.append(
                    UI.DTR(UI.DTH(
                        UI.Label(text="Nenhum filtro encontrado..."))))
            else:
                for h in self.hosts:
                    t.append(
                        UI.DTR(
                            UI.Label(text=h.ip + '/' + h.mascara),
                            UI.Label(text=(h.banda + ' ' + h.medida)),
                            UI.Label(text=h.nome),
                            UI.HContainer(
                                UI.TipIcon(
                                    icon='/dl/core/ui/stock/delete.png',
                                    id='del/' + str(h.ip),
                                    text='Remover filtro',
                                )),
                        ))

        if self._editing is not None:
            # caso o usuario tente cadastrar uma banda sem passar nenhum parametro
            if self._editing == 'error_cadastrar_banda':
                e = ui.find('error')
                e.append(
                    UI.Label(
                        text="Todos os campos tem que ser preenchidos !!!",
                        size=3))
        # trata o erro quando o usuario tenta exluir todos os filtros sendo que nao a nenhum a ser excluido
            elif self._editing == 'error_apagar_todos_filtros':
                e = ui.find('error')
                e.append(UI.Label(text='Não a nenhum filtro a ser apagado...'))
                self._editing = None
            # caso haja algum erro no cadastro de filtros
            elif self._editing == 'error_cadastrar_filtro':
                if self.errorFiltro:
                    e = self.app.inflate('controle_banda:msgerro')
                    e.find('msg').set('text', 'Filtro já cadastrado !')
                    ui.append('error', e)
                    self._editing = None
                else:
                    e = self.app.inflate('controle_banda:msgerro')
                    e.find('msg').set(
                        'text', 'Todos os campos tem que ser preenchidos !')
                    ui.append('error', e)
                    self._editing = None
            else:

                try:
                    h = self.hosts[self._editing]
                except:
                    h = backend.Host()
                d = self.app.inflate(
                    'controle_banda:edit')  # inflate and fill the dialog
                d.find('ip').set('value', h.ip)
                masc = d.find('mascara')
                for i in range(33):
                    if str(h.mascara) == str(32 - i):
                        masc.append(
                            UI.SelectOption(value=int(32 - i),
                                            text=int(32 - i),
                                            selected=True))
                    else:
                        masc.append(
                            UI.SelectOption(value=int(32 - i),
                                            text=int(32 - i)))
                d.find('banda').set('value', h.banda)
                med = d.find('medida')
                for i in ['Mbits', 'Kbits']:
                    if h.medida == i:
                        med.append(
                            UI.SelectOption(value=i, text=i, selected=True))
                    else:
                        med.append(UI.SelectOption(value=i, text=i))
                d.find('id_pc').set('value', h.id_pc)
                ui.append('lista_de_ips', d)  # and append it to main UI

        return ui