Exemplo n.º 1
0
    def show_log_file(self, log_file):
        ip = AppMenu.ip
        session = AppMenu.session
        if '-' not in log_file:
            return
        app, t = log_file.split("-", 1)
        t = t.split(".")[0]

        loop = asyncio.new_event_loop()
        asyncio.set_event_loop(loop)
        w = json.load(open(os.path.join(SERVER_ROOT, ip)))
        msg = Task.build_json(app, date=t, op='log', line=300, session=session)
        code, tag, msg = Comunication.SendOnce(w, msg, loop=loop)
        try:
            cc = msg['reply']['log'] + "\n ===============\n" + msg[
                'reply'].get('err_log', "")
            log('err get:', cc)
        except (KeyError, TypeError) as e:
            cc = str(msg['reply'])
            log('err get:', cc)
        TextPanel.Popup(cc,
                        x=self.start_x - self.width - 3,
                        max_height=Application.height - self.px - 5,
                        width=80,
                        y=self.py + 5,
                        screen=self.screen,
                        exit_keys=[10])
        TextPanel.Cl()
        self.Redraw()
        ShowFi(self)
Exemplo n.º 2
0
    def draw_text(self,
                  row,
                  col,
                  text,
                  max_width=None,
                  attrs=1,
                  prefix='',
                  prefix_attrs=None,
                  mark=False):
        if_run = mark
        if AppMenu.session and AppMenu.ip:
            log_file = AppMenu.session + "/" + text.strip()
            if not mark:
                if_run = IpMenu.infos[AppMenu.ip]['ps'].get(log_file, False)
                if if_run:
                    attrs = ColorConfig.get('green')
                log(log_file, if_run)
            else:
                if_run = mark

        log(attrs)
        super().draw_text(row,
                          col,
                          text,
                          max_width=max_width,
                          attrs=attrs,
                          prefix=prefix,
                          mark=if_run)
Exemplo n.º 3
0
 def refresh(self):
     self.__class__.Refresh(self)
     ip = self.get_now_text()
     if '[' in ip:
         ip = ip.split("]", 1)[1].strip()
     log(IpMenu.infos)
     session = IpMenu.infos[ip]['session']
     AppMenu.from_res(ip, session)
Exemplo n.º 4
0
 def update_when_cursor_change(self, item, ch):
     if ch in 'jk':
         if self.id == 'sess':
             log(AppMenu.ip, item)
             AppMenu.from_res(AppMenu.ip, item)
             AppMenu.session = item
     if ch in 'l':
         if self.id == 'log':
             self.show("wait .. to pull log")
             self.show_log_file(item)
Exemplo n.º 5
0
 def get_location(self, sl, sr, raw):
     color_key = self.__strage_map(raw)
     log("color map:", color_key)
     log("l:%d , r:%d ||" % (sl, sr) + raw)
     if sl == 0:
         return color_key[sl], color_key[sr]
     if color_key[sl] - color_key[sl - 1] > 1:
         if sr not in color_key:
             sr = list(color_key.keys())[-1]
         return color_key[sl - 1] + 1, color_key[sr]
     else:
         return color_key[sl], color_key[sr]
Exemplo n.º 6
0
 def Refresh(cls, context):
     try:
         ips = cls.all_ips if cls.all_ips else []
         confs = list(select('.'))
         msgs = list(build_tasks(confs, op='info', session='config'))
         Show("wait ... sync all infos", context)
         for code, tag, res in run_tasks(confs, msgs):
             if code == 0:
                 ip = res['ip']
                 cls.infos[ip] = res['reply']
         with open("/tmp/tmp_session_info.json", 'w') as fp:
             json.dump(cls.infos, fp)
         ShowFi(context)
     except Exception as e:
         log(str(e))
Exemplo n.º 7
0
 def run_task(self, target, servers, apps, session, op='run', **kwargs):
     loop = asyncio.new_event_loop()
     asyncio.set_event_loop(loop)
     msgs = Task.build_jsons(apps,
                             op=op,
                             session=session,
                             ip=target,
                             option='',
                             background=True,
                             **kwargs)
     log(msgs)
     ws = []
     for s in servers:
         with open(os.path.join(SERVER_ROOT, s)) as fp:
             w = json.load(fp)
             ws.append(w)
     mul_res = Comunication.SendMul(ws, msgs, loop=loop)
     log(mul_res)
     msgs = [i[-1] for i in mul_res]
     return msgs
Exemplo n.º 8
0
 def attack(self):
     ips = self.get_options()
     target = self.get_input('set target split by "," ')
     session = self.get_input('set session')
     session = session.replace(' ', '_')
     apps = CheckBox.Popup({i: False
                            for i in AppMenu.apps},
                           context=self,
                           exit_key=10)
     apps = CheckBox.last_popup.get_options()
     CheckBox.Cl()
     self.Redraw()
     log(apps, target)
     confs = list(select(ips))
     msgs = list(
         build_tasks(confs,
                     targets=target.split(","),
                     apps=apps,
                     session=session))
     Show("wait .. sending .. task", self)
     log(msgs)
     run_tasks(list(confs), list(msgs), callback=self.callback)
     ShowFi(self)
Exemplo n.º 9
0
    def to_green(self):
        if hasattr(self, "_file") and os.path.exists(self._file):
            with open(self._file, 'w') as fp:
                r = TextSave.load(-1)
                t = self.gather().replace(" \n", "\n")

                if ascii2filter(r) not in t or t in ascii2filter(r):
                    log(r)
                    log(t.encode())
                    log(ascii2filter(r).encode())
                    fp.write(r)
                    self.msg('rule save -> ' + self._file)
                    return
                C = self.__strage_map(r)

                if len(t) > len(C):
                    txt = r + t[len(C):]
                else:
                    txt = r[:C[len(t)]]
                fp.write(txt)
                self.msg('save -> ' + self._file)
Exemplo n.º 10
0
 def show_log(self, ip, refresh=False):
     if refresh:
         loop = asyncio.new_event_loop()
         asyncio.set_event_loop(loop)
         w = json.load(open(os.path.join(SERVER_ROOT, ip)))
         log(w)
         msg = Task.build_json('', op='info', session='config')
         code, tag, msg = Comunication.SendOnce(w, msg, loop=loop)
         log(msg)
         sessions = msg['reply']['session']
     else:
         if ip in IpMenu.infos:
             AppMenu.apps = IpMenu.infos[ip]['app']
             sessions = IpMenu.infos[ip]['session']
         else:
             loop = asyncio.new_event_loop()
             asyncio.set_event_loop(loop)
             w = json.load(open(os.path.join(SERVER_ROOT, ip)))
             msg = Task.build_json('', op='info', session='config')
             code, tag, msg = Comunication.SendOnce(w, msg, loop=loop)
             log(msg)
             sessions = msg['reply']['session']
             AppMenu.apps = msg['reply']['app']
     AppMenu.from_res(ip, sessions)
Exemplo n.º 11
0
 async def callback(self, code, tag, res):
     log(code, res)
Exemplo n.º 12
0
 def do_delete_line(self):
     y, x = self._win.getyx()
     self._win.move(y, 0)
     Textbox.do_command(self, 11)
     del TextSave.text[y]
     log("delete")
Exemplo n.º 13
0
 def __do(*args, **kargs):
     try:
         return method(*args, **kargs)
     except exp as e:
         log('in book err:', e)