예제 #1
0
        def get_ui(self):
            mgr = self.app.get_backend(apis.services.IServiceManager)

            st = 'failed'
            st = mgr.get_status(self.service_name)
            try:
                st = mgr.get_status(self.service_name)
                if self.service_expected_status:
                    if self.service_expected_status != st:
                        st = 'failed'
            except:
                st = 'failed'

            self.service_status = st
            self.service_expected_status = None

            panel = UI.ServicePluginPanel(status=self.service_status,
                                          servicename=self.service_name)
            return UI.Container(panel, self.get_main_ui())
예제 #2
0
        def get_ui(self):
            from genesis.plugins.security.firewall import RuleManager, FWMonitor

            mgr = self.app.get_backend(apis.services.IServiceManager)
            rum = RuleManager(self.app)
            self._rules_list = rum.get_by_plugin(self.plugin_id)
            fwm = FWMonitor(self.app)

            res = UI.DT(UI.DTR(UI.DTH(width=20),
                               UI.DTH(UI.Label(text='Service')),
                               UI.DTH(width=20),
                               header=True),
                        width='100%',
                        noborder=True)

            alert = False

            services = self.plugin_info.services if hasattr(
                self.plugin_info, 'services') else self.services
            for s in services:
                ctl = UI.HContainer()

                try:
                    st = mgr.get_status(s['binary'])
                except:
                    st = 'failed'
                    alert = True
                try:
                    en = mgr.get_enabled(s['binary'])
                except:
                    en = 'failed'

                if st == 'running':
                    ctl.append(
                        UI.TipIcon(text='Stop',
                                   cls='servicecontrol',
                                   iconfont='gen-stop',
                                   id='stop/' + s['binary']))
                    ctl.append(
                        UI.TipIcon(text='Restart',
                                   cls='servicecontrol',
                                   iconfont='gen-loop-2',
                                   id='restart/' + s['binary']))
                else:
                    ctl.append(
                        UI.TipIcon(text='Start',
                                   cls='servicecontrol',
                                   iconfont='gen-play-2',
                                   id='start/' + s['binary']))
                    alert = True
                if en == 'enabled':
                    ctl.append(
                        UI.TipIcon(text='Disable',
                                   cls='servicecontrol',
                                   iconfont='gen-minus-circle',
                                   id='disable/' + s['binary']))
                else:
                    ctl.append(
                        UI.TipIcon(text='Enable',
                                   cls='servicecontrol',
                                   iconfont='gen-plus-circle',
                                   id='enable/' + s['binary']))

                t = UI.DTR(
                    UI.HContainer(
                        UI.IconFont(iconfont='gen-' +
                                    ('play-2' if st == 'running' else 'stop')),
                        UI.IconFont(
                            iconfont='gen-' +
                            ('checkmark' if en == 'enabled' else 'close-2')),
                    ), UI.Label(text='%s (%s)' % (s['name'], s['binary'])),
                    ctl)
                res.append(t)

            ptalert = False

            if self._rules_list != []:
                pts = UI.DT(UI.DTR(UI.DTH(width=20),
                                   UI.DTH(UI.Label(text='Application')),
                                   UI.DTH(UI.Label(text='Ports')),
                                   UI.DTH(UI.Label(text='Authorization')),
                                   UI.DTH(width=20),
                                   header=True),
                            width='100%',
                            noborder=True)
                for p in self._rules_list:
                    if p[1] == 1:
                        perm, ic, show = 'Local', 'gen-home', [2, 0]
                    elif p[1] == 2:
                        perm, ic, show = 'All', 'gen-earth', [1, 0]
                    else:
                        perm, ic, show = 'None', 'gen-close', [2, 1]
                        ptalert = True
                    pts.append(
                        UI.DTR(
                            UI.IconFont(iconfont=p[0].icon),
                            UI.Label(text=p[0].name),
                            UI.Label(text=', '.join(
                                str(x[1]) for x in p[0].ports)),
                            UI.HContainer(
                                UI.IconFont(iconfont=ic),
                                UI.Label(text=' '),
                                UI.Label(text=perm),
                            ),
                            UI.HContainer(
                                (UI.TipIcon(iconfont='gen-earth',
                                            text='Allow All',
                                            cls='servicecontrol',
                                            id='2/' +
                                            str(self._rules_list.index(p)))
                                 if 2 in show else None),
                                (UI.TipIcon(iconfont='gen-home',
                                            text='Local Only',
                                            cls='servicecontrol',
                                            id='1/' +
                                            str(self._rules_list.index(p)))
                                 if 1 in show else None),
                                (UI.TipIcon(
                                    iconfont='gen-close',
                                    text='Deny All',
                                    cls='servicecontrol',
                                    id='0/' + str(self._rules_list.index(p)),
                                    warning=
                                    'Are you sure you wish to deny all access to %s? '
                                    'This will prevent anyone (including you) from connecting to it.'
                                    % p[0].name) if 0 in show else None),
                            ),
                        ))

            panel = UI.ServicePluginPanel(
                alert=('True' if alert else 'False'),
                ports=('True' if self._rules_list != [] else 'False'),
                ptalert=('True' if ptalert else 'False'),
            )

            if self.display:
                dlg = UI.DialogBox(UI.ScrollContainer(res,
                                                      width=300,
                                                      height=300),
                                   id='dlgServices',
                                   hidecancel='True')
                return UI.Container(panel, dlg, self.get_main_ui())
            elif self.disports:
                dlg = UI.DialogBox(UI.ScrollContainer(pts,
                                                      width=300,
                                                      height=300),
                                   id='dlgPorts',
                                   hidecancel='True')
                return UI.Container(panel, dlg, self.get_main_ui())
            else:
                return UI.Container(panel, self.get_main_ui())