Esempio n. 1
0
 def _check(version_compare_lst):
     compare_lst = ['>']
     # avoid [>= 1.1, <= 1.0]
     for compare, _ in version_compare_lst:
         compare = compare.strip('=')
         if compare != compare_lst[-1]:
             compare_lst.append(compare)
     length = len(compare_lst)
     if version_compare_lst and 0 < length < 3:
         return True
     logger.warning('maybe framework or cms had be change by developer')
     if len(version_compare_lst) < 1:
         logger.warning(
             'Reducing depth(--depth), set smaller number maybe useful')
         logger.error('unable to judge version')
         sys.exit()
     elif length > 2:
         logger.warning(
             'Enlarge depth(--depth), set larger number or max(0) maybe useful'
         )
         lst = [('version cond', )]
         for comb, ver in version_compare_lst:
             lst.append(('{} {}'.format(comb, ver), ))
         show_output(AsciiTable(lst).table)
         sys.exit()
Esempio n. 2
0
def run():
    """main function."""
    args = call_parser()
    check_run_options(args)
    depend = args.depend
    logger.info('searching %s fingerprint infomation.....', depend)
    plugin_info = search(depend)
    if not plugin_info:
        logger.error('%s can not find a fingerprint of %s', APPNAME, depend)
        logger.info('your can use --all to print all fingerprint supported.')
        # TODO: show the request fingerprint url in github
        sys.exit()
    logger.info('already found %s fingerprint.', depend)
    distri = file_distribute(plugin_info)
    logger.info('start to request hash map on %s in depth %d.', args.url,
                args.depth)
    hash_map = static_hash_map(args.url, distri, args.depth)
    logger.verbose('show the hash map: %s',
                   json.dumps(hash_map, indent=4, sort_keys=True))
    logger.info('let\'s observer which version of %s.', depend)
    version_set = make_all(hash_map, plugin_info)
    cond_lst = [
        VersionCond.from_str(''.join(comp)) for comp in calc(version_set)
    ]
    logger.info('show the possible versions of %s on %s', depend, args.url)
    result_lst = [('possible version', )]
    for version_str in plugin_info.get('versions'):
        if all((cond.match(version_str) for cond in cond_lst)):
            info = '{} v{}'.format(depend, version_str)
            logger.verbose(info)
            result_lst.append((info, ))
    show_output(AsciiTable(result_lst).table)
    sys.exit(0)
Esempio n. 3
0
def show_all():
    """show all plugin, --all/-a option."""
    logger.info('show all plugin introduction')
    table_lst = [('framework name', 'tags')]
    for plugin_info in all_plugin():
        tags = ', '.join(plugin_info.get('alias'))
        table_lst.append((plugin_info.get('framework'), tags))
    table = AsciiTable(table_lst)
    show_output(table.table)
Esempio n. 4
0
def calc(version_compare_set):
    """calcute version compare list."""
    def _get_version(version_compare):
        return str2version(version_compare[1])

    def _check(version_compare_lst):
        compare_lst = ['>']
        # avoid [>= 1.1, <= 1.0]
        for compare, _ in version_compare_lst:
            compare = compare.strip('=')
            if compare != compare_lst[-1]:
                compare_lst.append(compare)

        length = len(compare_lst)
        if 0 < length < 3:
            return True
        logger.warning('maybe framework or cms had be change by developer')
        if len(version_compare_lst) < 1:
            logger.warning('Reducing depth(--depth), set smaller number maybe useful')
            logger.error('unable to judge version')
            sys.exit()
        elif length > 2:
            logger.warning('Enlarge depth(--depth), set larger number or max(0) maybe useful')
            lst = [('version cond',)]
            for comb, ver in version_compare_lst:
                lst.append(('{} {}'.format(comb, ver),))
            show_output(AsciiTable(lst).table)
            sys.exit()

    lst = list(version_compare_set)
    lst = sorted(lst, key=_get_version)
    if _check(lst):
        if len(lst) == 1:
            show_output(' '.join(lst[0]))
            return lst
        for prev_, next_ in zip(lst[:-1], lst[1:]):
            if prev_[0].strip('=') == '>' \
                and next_[0].strip('=') == '<':
                lst = [
                    ('version cond',),
                    ('{} {}'.format(*prev_),),
                    ('{} {}'.format(*next_),)
                ]
                show_output(AsciiTable(lst).table)
                return [prev_, next_]
        if lst[0][0].strip('=') == ">":
            res = lst[-1]
        else:
            res = lst[0]
        show_output(' '.join(res))
        return res
    sys.exit()