Esempio n. 1
0
    def get(self):
        endpoints = []
        replace_map = (
            ("(?P<status_code>\d{3})", "{status_code: int}", str(choice(responses.keys()))),
            ("(?P<name>.+)", "{name: str}", "test_name"),
            ("(?P<value>.+)", "{value: str}", "test_value"),
            ("(?P<num>\d{1,2})", "{redirects_num: int}", '4'),
            ("(?P<username>.+)", "{username: str}", "test_username"),
            ("(?P<password>.+)", "{password: str}", "test_password"),
            ("(?P<qop>.+)", "{quality of protection: auth | auth-int}", "auth"),
            ("(?P<version>.+)", "{version: float}", "1.0"),
            ("(?P<consumer_key>.+)", "{consumer_key: str}", random_string(15)),
            ("(?P<consumer_secret>.+)", "{consumer_secret: str}", random_string(15)),
            ("(?P<pin>.+)", "{pin: str}", random_string(10)),
            ("(?P<verifier>.+)", "{pin: str}", random_string(10)),
            ("(?P<token_key>.+)", "{token_key: str}", random_string(10)),
            ("(?P<token_secret>.+)", "{token_secret: str}", random_string(10)),
            ("(?P<tmp_token_key>.+)", "{tmp_token_key: str}", random_string(10)),
            ("(?P<tmp_token_secret>.+)", "{tmp_token_secret: str}", random_string(10)),
#            ("(?<consumer_secret>.+)", "{consumer_secret: str}", random_string(15)),
            ("(?P<sleep_time>[\d\.]+)", "{sleep_time: float}", "0.0"),
            )

        for point in self.application.dirty_handlers:
            default_url = point[0]
            api_format = point[0]
            for r in replace_map:
                default_url = default_url.replace(r[0], r[2])
                api_format = api_format.replace(r[0], r[1])
            description = point[2] if len(point) >= 3 else point[1].__doc__.strip()
            endpoint = {"default_url": default_url,
                        "api_format": api_format,
                        "description": description}
            endpoints.append(endpoint)

        responses_groups = (
            (100, 200, "1xx Informational", []),
            (200, 300, "2xx Success", []),
            (300, 400, "3xx Redirection", []),
            (400, 500, "4xx Client Error", []),
            (500, 600, "5xx Server Error", []))

        groups = []
        for i, group in enumerate(responses_groups):
            groups.append([group[0], group[1], group[2],
                           [(k, v, get_status_extdescription(k)) for k, v in responses.items()
                            if group[0] <= k < group[1]]])

        self.render("index.html", endpoints=endpoints, groups=groups)
Esempio n. 2
0
File: app.py Progetto: imbolc/httphq
    def get(self, status_code):
        status_code = int(status_code)
        if status_code not in responses.keys():
            raise HTTPError(404)

        self.set_status(status_code)

        if status_code in STATUSES_WITHOUT_BODY:
            self.finish()
        elif status_code in STATUSES_WITH_LOCATION:
            self.set_header("Location", self.request.host)
        elif status_code in STATUSES_WITH_AUHT:
            self.set_header("WWW-Authenticate", 'Basic realm="Fake Realm"')
        elif status_code in STATUSES_WITH_PROXY_AUTH:
            self.set_header("Proxy-Authenticate", 'Basic realm="Fake Realm"')
        else:
            self.json_response({"tagline": str(choice(taglines)),
                            "code": status_code,
                            "description": responses.get(status_code)})
Esempio n. 3
0
 def from_cmdline(cls):
     finder_parser = ArgumentParser(
         description="rwf - a random website finder")
     finder_parser.add_argument(
         "-th", "--num-threads",
         type=int, help="set the number of website finding threads")
     finder_parser.add_argument(
         "-ct", "--conn-timeout", type=int,
         help=("set the maximum amount of seconds "
               "to attempt to connect to addresses"))
     finder_parser.add_argument(
         "-gs", "--good-statuses", type=int, nargs="+",
         help="http status codes that will cause a site to be added")
     finder_parser.add_argument(
         "-bs", "--bad-statuses", type=int, nargs="+",
         help="http status codes that will not cause a site to be added")
     finder_parser.add_argument(
         "-sec", "--sec-limit", type=int,
         help="set an amount of seconds to add to the runtime")
     finder_parser.add_argument(
         "-min", "--min-limit", type=int,
         help="set an amount of minutes to add to the runtime")
     finder_parser.add_argument(
         "-hr", "--hour-limit", type=int,
         help="set an amount of hours to add to the runtime")
     finder_parser.add_argument(
         "-e", "--site-limit", type=int,
         help=("set an amount of sites, that when "
               "found will cause finding to stop"))
     finder_parser.add_argument(
         "-a", "--addrs-limit", type=int,
         help="set an amount of addresses tested to limit the runtime")
     finder_parser.set_defaults(
         num_threads=30, conn_timeout=1,
         good_statuses=responses.keys(), bad_statuses=[])
     args = finder_parser.parse_args()
     if not (args.sec_limit or args.min_limit or args.hour_limit or
             args.addrs_limit or args.site_limit):
         finder_parser.error(
             ("At least one of --sec-limit, --min-limit, --hour-limit, \n"
              "--addrs-limit, or site-limit arguments must be given"))
     args_dict = vars(finder_parser.parse_args())
     return cls(**args_dict)
Esempio n. 4
0
 def __init__(self, num_threads=30, conn_timeout=1,
              good_statuses=responses.keys(), bad_statuses=[],
              sec_limit=None, min_limit=None, hour_limit=None,
              site_limit=None, addrs_limit=None):
     self.num_threads = num_threads
     self.conn_timeout = conn_timeout
     self.status_codes = list_diff(good_statuses, bad_statuses)
     self.start_time = None
     self.limits = {}
     self.limits["user"] = False
     self.limits["time"] = {"sec": sec_limit, "min": min_limit,
                            "hour": hour_limit}
     self.limits["time"]["total"] = self.time_limit()
     self.limits["site"] = site_limit
     self.limits["addrs"] = addrs_limit
     self.num_addrs_tested = 0
     self.num_addrs_tested_lock = RLock()
     self.num_sites_found = 0
     self.num_sites_found_lock = RLock()
     self.threads = []
     self.sites = deque()
Esempio n. 5
0
def statuses_starting_with(num):
    return filter(lambda status: str(status)[0] == str(num), responses.keys())