示例#1
0
文件: control.py 项目: ardnet/genesis
 def add_webapp(self, d):
     servers = ServerManager(self.app)
     s = servers.add('webapps', d[0], d[0] + ' (' + d[1] + ')', 'gen-earth',
                     [('tcp', d[2])])
     RuleManager(self.app).set(s, 2)
     FWMonitor(self.app).regen()
     FWMonitor(self.app).save()
示例#2
0
 def on_service_control(self, event, params, vars=None):
     from genesis.plugins.security.firewall import RuleManager, FWMonitor
     if params[0] == 'services':
         self.display = True
     if params[0] == 'security':
         self.disports = True
     if params[0] == '2':
         RuleManager(self.app).set(self._rules_list[int(params[1])][0],
                                   2)
         FWMonitor(self.app).regen()
     if params[0] == '1':
         RuleManager(self.app).set(self._rules_list[int(params[1])][0],
                                   1)
         FWMonitor(self.app).regen()
     if params[0] == '0':
         sel = self._rules_list[int(params[1])][0]
         RuleManager(self.app).set(sel, 0)
         FWMonitor(self.app).regen()
     if params[0] == 'restart':
         mgr = self.app.get_backend(apis.services.IServiceManager)
         mgr.restart(params[1])
     if params[0] == 'start':
         mgr = self.app.get_backend(apis.services.IServiceManager)
         mgr.start(params[1])
     if params[0] == 'stop':
         mgr = self.app.get_backend(apis.services.IServiceManager)
         mgr.stop(params[1])
     if params[0] == 'enable':
         mgr = self.app.get_backend(apis.services.IServiceManager)
         mgr.enable(params[1])
     if params[0] == 'disable':
         mgr = self.app.get_backend(apis.services.IServiceManager)
         mgr.disable(params[1])
示例#3
0
 def remove(self, id):
     servers = ServerManager(self.app)
     if servers.get_by_plugin(id) != []:
         RuleManager(self.app).remove_by_plugin(id)
         servers.remove_by_plugin(id)
         FWMonitor(self.app).regen()
         FWMonitor(self.app).save()
示例#4
0
 def remove_webapp(self, sid):
     servers = ServerManager(self.app)
     s = servers.get(sid)[0]
     RuleManager(self.app).remove(s)
     servers.remove(sid)
     FWMonitor(self.app).regen()
     FWMonitor(self.app).save()
示例#5
0
 def remove_webapp(self, sid):
     servers = ServerManager(self.app)
     s = servers.get(sid)
     if s:
         s = s[0]
     else:
         return
     RuleManager(self.app).remove(s)
     servers.remove(sid)
     FWMonitor(self.app).regen()
     FWMonitor(self.app).save()
示例#6
0
 def session_start(self):
     servers = ServerManager(self.app)
     servers.add('arkos', 'genesis', 'Genesis', 'gen-arkos-round',
         [('tcp', self.app.gconfig.get('genesis', 'bind_port'))])
     servers.add('arkos', 'beacon', 'Beacon', 'gen-arkos-round',
         [('tcp', '8765')])
     servers.scan_plugins()
     servers.scan_webapps()
     RuleManager(self.app).scan_servers()
     FWMonitor(self.app).regen()
     FWMonitor(self.app).save()
示例#7
0
 def change_webapp(self, old_id, new_id, type, port):
     servers = ServerManager(self.app)
     rm = RuleManager(self.app)
     s = servers.get(old_id)[0]
     r = rm.get(s)
     rm.remove(s)
     servers.update(old_id, new_id, new_id + ' (' + type + ')', 'gen-earth',
                    [('tcp', port)])
     rm.set(s, r)
     FWMonitor(self.app).regen()
     FWMonitor(self.app).save()
示例#8
0
 def change_webapp(self, oldsite, newsite):
     servers = ServerManager(self.app)
     rm = RuleManager(self.app)
     s = servers.get(oldsite.name)[0]
     r = rm.get(s)
     rm.remove(s)
     servers.update(oldsite.name, newsite.name, 
         newsite.name + ' (' + newsite.stype + ')',
         'gen-earth', [('tcp', newsite.port)])
     rm.set(s, r)
     FWMonitor(self.app).regen()
     FWMonitor(self.app).save()
示例#9
0
 def port_changed(self, s):
     sm = ServerManager(self.app)
     rm = RuleManager(self.app)
     for p in s.services:
         try:
             if p[2] != [] and sm.get(p[1]) != []:
                 sg = sm.get(p[1])[0]
                 r = rm.get(sg)
                 rm.remove(sg)
                 sm.update(p[1], p[1], p[0], s.iconfont, p[2])
                 rm.set(sg, r)
             elif p[2] != []:
                 sg = sm.get(p[1])[0]
                 sm.add(s.plugin_id, p[1], p[0], s.iconfont, p[2])
                 rm.set(sg, 2)
             FWMonitor(self.app).regen()
             FWMonitor(self.app).save()
         except IndexError:
             continue
示例#10
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())
示例#11
0
 def refresh(self):
     servers = ServerManager(self.app)
     servers.scan_plugins()
     RuleManager(self.app).scan_servers()
     FWMonitor(self.app).regen()
     FWMonitor(self.app).save()