Exemple #1
0
def delete_mode():
    """
    delete some cmds.
    """
    while 1:
        c = dinput("[l:list all comba-cmds, q:exit, s:search cmd, d xxx :delete xxx comba cmd] \n>", default='q')
        if c == 'q':
            LogControl.i('~ by')
            break
        elif c == 'l':
            for m,res in search_comba_cmds():
                LogControl.i(m, res)
        else:
            if c[0] == 's':
                cc = ''
                try:
                    cc = c.split()[1]
                except Exception as e:
                    LogControl.err(e)
                    continue
                for m,res in search_comba_cmds(cc):
                    LogControl.i(m, res)

            elif c[0] == 'd':
                cc = ''
                try:
                    cc = c.split()[1]
                except Exception as e:
                    LogControl.err(e)
                    continue

                delete_template_in_sqlite_db(cc)
                LogControl.ok("delete it.")
            else:
                continue
Exemple #2
0
    def shell(self, cmd_str, out=False, console=True):
        """
        @cmd_str
        @out=False
        @console=True
        @self.options['asyn'] = False 

        if set True will use popen no log but can see it in "/tmp/xxx.log"
        if console set False:
            no print
        if out set True:
            return res
        """
        if self.options['asyn']:
            rrun(cmd_str, "/tmp", cmd_str.split()[0])
            return 

        sta, res = getstatusoutput(cmd_str)
        if sta == 0:
            for line in res.split("\n"):
                LogControl.ok(line)
        else:
            LogControl.err(res, cmd_str)

        if out:
            return res
Exemple #3
0
def execute(cmd, help=False, console=False, **args):
    LogControl.ok('\n')
    t_dir = dir_gen()
    try:
        os.makedirs(t_dir)
    except Exception as e:
        pass
    DB_Handler = SqlEngine(database=DB_PATH)
    cmds = []
    options = set()
    for i in DB_Handler.select("templates", 'cmd', 'keys', 'output', group_key=cmd):
        cmds.append([i[0], i[2]])
        [ options.add(m) for m in i[1].split()]
    
    if help:
        LogControl.i("need to set options: ", options)
        for cmd, out in cmds:
            LogControl.i(cmd, ' -> ', out, txt_color='yellow')
        return True

    else:
        for cmd, out in cmds:
            try:
                rrun(cmd.format(**args), t_dir, out)
            except Exception as e:
                LogControl.err(e,cmd)
                LogControl.i("need to set options: ", options)
                continue

        if console:
            try:
                os.system('sleep 2 && tail -f %s/*' % t_dir)
            except KeyboardInterrupt as e:
                LogControl.info("~bye")
Exemple #4
0
 def display(code, content):
     '''
     display content
     '''
     if int(code / 200) == 1:
         res = '\n'.join([
             i.text for i in self.xpath(
                 content, "div[%s]" %
                 Baidu.config['translate_tag'], 'td', '*')
         ])
         LogControl.ok(res)
     else:
         LogControl.fail("not found this")
Exemple #5
0
def main():
    cmd_str = ' '.join(sys.argv[1:])
    if '--help' in sys.argv:
        L.i(DOC, tag="help")
        sys.exit(0)
    if ',,' in cmd_str:
        fuzz, cmd = cmd_str.split(",,")
    else:
        cmd = cmd_str
        fuzz = input_default(colored('Host run:', "blue"), "")

    choose_hosts(fuzz)

    try:
        for h in env.hosts:
            env.host_string = h
            shell(cmd, h)
    except (KeyboardInterrupt, InterruptedError) as e:
        L.ok("Bye~")
Exemple #6
0
 def _link(self, url, encoding='utf8'):
     try:
         agent = random_choice(AGS)
         res = to(url, headers={'user-agent': agent})
         if res.status_code != 200:
             raise Error404("not reachable", res.status_code)
         if self.charset:
             return url, self.parser(
                 res.content.decode(self.charset, 'ignore'))
         return url, self.parser(res.content.decode(encoding, 'ignore'))
     except HTTPError as e:
         LogControl.fail(url, e.code)
         return url, None
     except Exception as e:
         LogControl.wrn(url)
         LogControl.err(url, e, txt_color='yellow')
         return url, None
     else:
         LogControl.ok(url)
Exemple #7
0
 def tree_dict(d, func, key=None, lfunc=None):
     if isinstance(d, dict):
         for item in d:
             tree_dict(d[item], func, key=item)
     elif isinstance(d, list):
         for item in d:
             if lfunc:
                 tree_dict(item, lfunc)
             else:
                 tree_dict(item, func)
     else:
         if key:
             if key == 'dst':
                 LogControl.ok(d,
                               txt_color='green',
                               txt_attr=['underline', 'bold'])
             else:
                 func(d, key)
         else:
             func(d)
Exemple #8
0
def create_multi_templates(debug=False):
    """
    create a multi-cmd template.
    """
    cmd_group_name = dinput("cmd group's name?\n[q: exit]>", default='q')
    if cmd_group_name == 'q':
        return False
    while 1:
        cmd_t = dinput('which cmd?\n[q :exit]>', default='q').split()
        if cmd_t[0] == 'q':
            break
        # print(cmd_t)
        vals = list(search_cmd(*cmd_t).values())
        if len(vals) == 0:
            continue

        if isinstance(vals[0], list) :
            vals = [i.strip() for i in vals[0]]

        if not vals:
            continue
        for i, v in enumerate(vals):
            LogControl.ok(i, v, txt_color='cyan')
        cmd_d = vals[int(dinput('choose a ID , (deafult 0)', default=0))]

        k_in = 2
        while 1:
            k_in = dinput('\n%s\nchoose parts to replace ,separate by ' ' [default 2] set :' % colored(cmd_d, attrs=['bold']), default='1')
            k = [int(i) for i in k_in.split()]
            cmd_args = cmd_d.decode('utf8').split() if isinstance(cmd_d, bytes) else cmd_d.split()
            mvals = {}
            for kv in k:
                cmd_args[kv] = colored(cmd_args[kv], attrs=['underline'])
                v = dinput('%s |[-r: reset parts, default: -r] %d=' % (' '.join(cmd_args), kv), default='-r')
                if v == '-r':
                    LogControl.fail("reset")
                    continue
                mvals[v] = kv
                st, key, out = create_single_template(cmd_d, debug=debug, **mvals)
                save_template_to_sqlite_db(cmd_group_name, st, key, out)
            break
Exemple #9
0
    def __init__(self,
                 ssl=True,
                 asyn=True,
                 debug=False,
                 db=False,
                 database=None,
                 proxy=False):
        self.url_pre = 'https://www.' if ssl else 'https//www.'
        self.search_name = self.__class__.__name__.lower()
        self.host = self.url_pre + self.search_name + '.com'
        self.agent = random_choice(AGS)
        self.asyn = None
        self.db = None
        self.debug = debug
        self.proxy = None
        self.grep_html_content = dict()

        if asyn:
            self.asyn = Exe(20)

        if proxy:
            LogControl.info("loading proxy..", end='')
            self.proxy = proxy  #Mongo('local').find("setting")[0].get("proxy")
            if self.proxy:
                LogControl.ok("")

        if db:
            self.use_db = db
            db_path = os.path.join(
                os.getenv("HOME"),
                '.Search-engine-sqlite3-db.db') if not database else database
            self.db_path = db_path
            self.db = SqlEngine(database=db_path)
            if not self.db.table_list():
                self.db.create(self.search_name,
                               query=str,
                               content=str,
                               type='web')
Exemple #10
0
    def del_res(self):

        """
        delete some cmds.
        """
        while 1:
            c = dinput("[l:list all res, q:exit, s:search cmd, d xxx :delete xxx comba cmd] \n>", default='q')
            if c == 'q':
                LogControl.i('~ by')
                break
            elif c == 'l':
                for res in self.get_res():
                    LogControl.i(res[0], res[1:])
            else:
                if c[0] == 's':
                    cc = ''
                    try:
                        cc = c.split()[1]
                    except Exception as e:
                        LogControl.err(e)
                        continue
                    for res in self.get_res(grep=cc):
                        LogControl.i(res[0], res[1:])

                elif c[0] == 'd':
                    cc = ''
                    try:
                        cc = c.split()[1]
                    except Exception as e:
                        LogControl.err(e)
                        continue

                    self.db.delete(self.table, id=cc)
                    LogControl.ok("delete it.")
                else:
                    continue
Exemple #11
0
 def single_display(val, key=None, level=1):
     if key:
         LogControl.ok('[' + key + ']', '\t', val)
     else:
         LogControl.info('\t\t' + '   ' * level, val)