# Path: theHarvester/__main__.py
# async def start(rest_args=None):
#     async def store(search_engine: Any, source: str, process_param: Any = None, store_host: bool = False,
#                     store_emails: bool = False, store_ip: bool = False, store_people: bool = False,
#                     store_links: bool = False, store_results: bool = False,
#                     store_interestingurls: bool = False, store_asns: bool = False) -> None:
#     async def worker(queue):
#     async def handler(lst):
# async def entry_point():


import argparse
import os
from typing import List
from fastapi import FastAPI, Header, Query, Request
from fastapi.responses import HTMLResponse, UJSONResponse
from slowapi import Limiter, _rate_limit_exceeded_handler
from slowapi.errors import RateLimitExceeded
from slowapi.util import get_remote_address
from starlette.responses import RedirectResponse
from starlette.staticfiles import StaticFiles
from theHarvester import __main__
                                                             shodan=False,
                                                             source=','.join([]),
                                                             start=0,
                                                             take_over=False,
                                                             virtual_host=False))
    return {'dns_bruteforce': dns_bruteforce}


@app.get('/query', response_class=UJSONResponse)
@limiter.limit('2/minute')
async def query(request: Request, dns_server: str = Query(""), user_agent: str = Header(None),
                dns_brute: bool = Query(False),
                dns_lookup: bool = Query(False),
                dns_tld: bool = Query(False),
                filename: str = Query(""),
                google_dork: bool = Query(False), proxies: bool = Query(False), shodan: bool = Query(False),
                take_over: bool = Query(False), virtual_host: bool = Query(False),
                source: List[str] = Query(..., description='Data sources to query comma separated with no space'),
                limit: int = Query(500), start: int = Query(0),
                domain: str = Query(..., description='Domain to be harvested')):

    # Query function that allows user to query theHarvester rest API
    # Rate limit of 2 requests per minute
    # basic user agent filtering
    if user_agent and ('gobuster' in user_agent or 'sqlmap' in user_agent or 'rustbuster' in user_agent):
        response = RedirectResponse(app.url_path_for('bot'))
        return response
    try:
        asns, iurls, twitter_people_list, \
            linkedin_people_list, linkedin_links, \

# Path: theHarvester/__main__.py
# async def start(rest_args=None):
#     async def store(search_engine: Any, source: str, process_param: Any = None, store_host: bool = False,
#                     store_emails: bool = False, store_ip: bool = False, store_people: bool = False,
#                     store_links: bool = False, store_results: bool = False,
#                     store_interestingurls: bool = False, store_asns: bool = False) -> None:
#     async def worker(queue):
#     async def handler(lst):
# async def entry_point():


# Path: theHarvester/lib/api/api.py
import argparse
import os
from typing import List
from fastapi import FastAPI, Header, Query, Request
from fastapi.responses import HTMLResponse, UJSONResponse
from slowapi import Limiter, _rate_limit_exceeded_handler
from slowapi.errors import RateLimitExceeded
from slowapi.util import get_remote_address
from starlette.responses import RedirectResponse
from starlette.staticfiles import StaticFiles
from theHarvester import __main__

                                                             shodan=False,
                                                             source=','.join([]),
                                                             start=0,
                                                             take_over=False,
                                                             virtual_host=False))
    return {'dns_bruteforce': dns_bruteforce}


@app.get('/query', response_class=UJSONResponse)
@limiter.limit('2/minute')
async def query(request: Request, dns_server: str = Query(""), user_agent: str = Header(None),
                dns_brute: bool = Query(False),
                dns_lookup: bool = Query(False),
                dns_tld: bool = Query(False),
                filename: str = Query(""),
                google_dork: bool = Query(False), proxies: bool = Query(False), shodan: bool = Query(False),
                take_over: bool = Query(False), virtual_host: bool = Query(False),
                source: List[str] = Query(..., description='Data sources to query comma separated with no space'),
                limit: int = Query(500), start: int = Query(0),
                domain: str = Query(..., description='Domain to be harvested')):

    # Query function that allows user to query theHarvester rest API
    # Rate limit of 2 requests per minute
    # basic user agent filtering
    if user_agent and ('gobuster' in user_agent or 'sqlmap' in user_agent or 'rustbuster' in user_agent):
        response = RedirectResponse(app.url_path_for('bot'))
        return response
    try:
        asns, iurls, twitter_people_list, \
            linkedin_people_list, linkedin_links, \

            aurls, aips, aemails, ahosts = await __main__.start(argparse.Namespace(dns_brute=dns_brute,