Beispiel #1
0
 def clear_session(self):
     res = Stack.Popup(['no', 'yes'], context=self, exit_key=10)
     if res != 'yes':
         return
     loop = asyncio.new_event_loop()
     asyncio.set_event_loop(loop)
     ips = self.get_options()
     confs = list(select(ips))
     msgs = list(build_tasks(confs, op='cla', session='config'))
     Show('delete all session in this ', self)
     run_tasks(list(confs), list(msgs), callback=self.callback)
     ShowFi(self)
     self.__class__.Refresh(self)
Beispiel #2
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))
Beispiel #3
0
def main():
    confs = list(select(''))
    # pull_all_ini(confs)
    if os.path.exists("/tmp/tmp_session_info.json"):
        with open("/tmp/tmp_session_info.json") as fp:
            IpMenu.infos = json.load(fp)

    app = Application()
    ipm = IpMenu(id='ip')
    sess = AppMenu([], id='sess')
    logs = AppMenu([], id='log')
    app.add_widget(ipm, weight=0.5)
    app.add_widget(sess, weight=0.5)
    app.add_widget(logs, weight=1)
    app.focus('ip')
    Show("wait .. to start ", ipm)
    IpMenu.Refresh(ipm)
    ShowFi(ipm)
    curses.wrapper(app.loop)
Beispiel #4
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)
Beispiel #5
0
def main():
    args = parser.parse_args()
    w = None
    conf = get_local_config()
    #if 'last_session' not in list(conf['client'].keys()):
    #    update('client','last_session', args.session)
    #    conf = get_local_config()
    #else:
    #    update('client','last_session', args.session)

    #if 'last_op' not in list(conf['client'].keys()):
    #    update('client','last_op', args.op)
    #    conf = get_local_config()
    #
    #if 'last_app' not in list(conf['client'].keys()):
    #    if not args.app:
    #        app = ''
    #    else:
    #        app = args.app[0]
    #    update('client','last_app', app)
    #    conf = get_local_config()

    #last_session = conf['client']['last_session']
    #last_app = conf['client']['last_app']
    #last_op = conf['client']['last_op']
    #if '-s' not in sys.argv:
    #    args.session = last_session
    #if '--op' not in sys.argv and '-l' not in sys.argv :
    #    args.op = last_op

    L('session: ', args.session, 'op: ', args.op)

    if args.generate_sec_conf:
        d = {}
        ip = [
            i.strip() for i in os.popen("ifconfig").read().split("\n")
            if 'inet' in i and '127.0.0.1' not in i and '::' not in i
        ][0].split()[1]
        print("server ip: %s" % ip)
        for k in ['server_port', 'password', 'method']:
            v = input(k)
            if not v:
                raise Exception("%s : must a val" % k)
            d[k] = v
        d['server'] = ip
        with open("seed-node-server.json", "w") as fp:
            json.dump(d, fp)
        sys.exit(0)
    if args.conf:
        f = args.conf
        with open(f) as fp:
            w = json.load(fp)
            assert 'server' in w
            assert 'server_port' in w
            assert 'password' in w
            assert 'method' in w

    if args.daemon:
        if args.updater:
            if args.daemon == 'start':
                assert w is not None
                daemon_exec(pid_file="/var/run/hack-updater.pid",
                            log_file="/var/log/hack-updater.log")
                w['server_port'] = str(int(w['server_port']) + 1)
                w['server'] = 'localhost'
                run_server(w)
            elif args.daemon == 'stop':

                daemon_exec(command='stop',
                            pid_file='/var/run/hack-updater.pid',
                            log_file='/var/log/hack-updater.log')
                run_server(w)
        else:
            if args.daemon == 'start':
                assert w is not None
                daemon_exec()
                run_server(w)
            elif args.daemon == 'stop':
                daemon_exec(command='stop')
                run_server(w)

    if args.push_ini and os.path.exists(args.push_ini):
        with open(args.sync_ini) as fp:
            content = fp.read()
        data = Task.build_json('',
                               op="sync-ini",
                               session=args.session,
                               content=content)
        res = Comunication.SendOnce(w, data)
        L(res[2]['reply'])
        sys.exit(0)

    if args.vi_ini:
        data = Task.build_json('',
                               op='get-ini',
                               session=args.session,
                               **{
                                   'option': args.option,
                                   'background': args.not_background,
                                   'date': args.time
                               })
        res = Comunication.SendOnce(w, data)
        L(res[2]['reply'])
        content = editor(res[2]['reply'])
        data = Task.build_json('',
                               op="sync-ini",
                               session=args.session,
                               content=content)
        res = Comunication.SendOnce(w, data)
        try:
            L(res[2]['reply'])
        except Exception:
            L(res[2])

        if os.path.exists("/tmp/tmp.ini"):
            os.remove('/tmp/tmp.ini')
        sys.exit(0)

    if w and args.app:
        # args.op = 'run'
        if len(args.app) == 1:
            target = ''
        else:
            target = args.app[1]
        app = args.app[0]
        if args.op.strip() == 'install':
            args.session = 'config'
        data = Task.build_json(app,
                               op=args.op,
                               session=args.session,
                               **{
                                   getattr(args, 'as'): target,
                                   'option': args.option,
                                   'background': args.not_background,
                                   'date': args.time
                               })
        res = Comunication.SendOnce(w, data)
        try:
            L(res[2]['reply'])
            sys.exit(0)
        except Exception as e:
            L(res[2])
            sys.exit(1)

    if args.log:
        args.op = 'log'
        args.app = args.log[0]
        app = args.log[0]
        if len(args.log) == 2:
            lines = args.log[1]
            time = args.time
        elif len(args.log) == 3:
            lines = args.log[1]
            time = args.log[2]
        else:
            lines = '50'
            time = args.time

        data = Task.build_json(app,
                               op='log',
                               session=args.session,
                               **{
                                   'option': args.option,
                                   'background': args.not_background,
                                   'date': time,
                                   'line': lines
                               })
        res = Comunication.SendOnce(w, data)
        try:
            L(res[2]['reply'])
            sys.exit(0)
        except Exception as e:
            L(res[2])
            sys.exit(1)

    if w and args.op != 'run':
        if args.app:
            app = args.app[0]
        else:
            app = ''
        if args.op.strip() == 'install':
            args.session = 'config'
        # L("session:",args.session)
        data = Task.build_json(app,
                               op=args.op,
                               session=args.session,
                               **{
                                   'option': args.option,
                                   'background': args.not_background,
                                   'date': args.time
                               })
        res = Comunication.SendOnce(w, data)
        try:
            L(res[2]['reply'])
            sys.exit(0)
        except Exception as e:
            L(res[2])
            sys.exit(1)

    if args.test:
        args.op = 'test'
    if w and args.test:

        data = Task.build_json("", session=args.session, op="test")
        res = Comunication.SendOnce(w, data)
        L(res[2]['reply'])
        sys.exit(0)

    if args.remote_help:
        data = Task.build_json('',
                               op='ls',
                               session=args.session,
                               **{
                                   'option': args.option,
                                   'background': args.not_background,
                                   'date': args.time
                               })
        res = Comunication.SendOnce(w, data)
        try:
            L(res[2]['reply'])
            sys.exit(0)
        except Exception as e:
            L(res[2])
            sys.exit(1)

    if args.init:
        init(args.init)
        sys.exit(0)

    if args.init_from_db:
        db_file = os.path.expanduser("~/.config/seed/cache.db")
        if os.path.exists(db_file):
            res = init_from_db(db_file, args.init_from_db)
            for r in res:
                L(r)

    if args.tree:
        data = Task.build_json('tree',
                               op='run',
                               session=args.session,
                               **{
                                   getattr(args, 'as'): '/tmp/tasks',
                                   'option': args.option,
                                   'background': False,
                                   'date': args.time
                               })
        res = Comunication.SendOnce(w, data)
        try:
            L(res[2]['reply'])
            sys.exit(0)
        except Exception as e:
            L(res[2])
            sys.exit(1)

    if args.conf_select:
        confs = list(select(args.conf_select))
    else:
        sys.exit(0)
        # L(confs)
    if args.sync_ini and os.path.exists(args.sync_ini):
        confs = list(select(args.conf_select))
        push_all_ini(confs, args.sync_ini)
        sys.exit(0)

    if args.pull_ini:
        confs = list(select(args.conf_select))
        pull_all_ini(confs)
        sys.exit(0)

    if args.app:
        app = [args.app[0]]
        if len(args.app) > 1:
            target = args.app[1:]
            L("targets:", target)
        else:
            target = []
    else:
        app = []
        target = []

    msgs = list(
        build_tasks(confs,
                    apps=app,
                    op=args.op,
                    targets=target,
                    option=args.option,
                    session=args.session,
                    date=args.time,
                    background=args.not_background,
                    line=50))
    for r in run_tasks(confs, msgs):
        if 'tree' in r[2]:
            L(r[2]['tree'])
        else:

            if 'reply' in r[2] and isinstance(r[2]['reply'], dict):
                L(r[2]['ip'], r[2]['reply'])
            else:
                L(r[2])