# 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__


limiter = Limiter(key_func=get_remote_address)
app = FastAPI(title='Restful Harvest', description='Rest API for theHarvester powered by FastAPI', version='0.0.2')
app.state.limiter = limiter
app.add_exception_handler(RateLimitExceeded, _rate_limit_exceeded_handler)

# This is where we will host files that arise if the user specifies a filename
try:
    app.mount('/static', StaticFiles(directory='theHarvester/lib/api/static/'), name='static')
except RuntimeError:
    static_path = os.path.expanduser('~/.local/share/theHarvester/static/')
    if not os.path.isdir(static_path):
        os.makedirs(static_path)
        app.mount('/static', StaticFiles(directory='~/.local/share/theHarvester/static/'), name='static')


@app.get('/', response_class=HTMLResponse)
async def root(*, user_agent: str = Header(None)):
    # very 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'))

# 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__



limiter = Limiter(key_func=get_remote_address)
app = FastAPI(title='Restful Harvest', description='Rest API for theHarvester powered by FastAPI', version='0.0.2')
app.state.limiter = limiter
app.add_exception_handler(RateLimitExceeded, _rate_limit_exceeded_handler)

# This is where we will host files that arise if the user specifies a filename
try:
    app.mount('/static', StaticFiles(directory='theHarvester/lib/api/static/'), name='static')
except RuntimeError:
    static_path = os.path.expanduser('~/.local/share/theHarvester/static/')
    if not os.path.isdir(static_path):
        os.makedirs(static_path)
        app.mount('/static', StaticFiles(directory='~/.local/share/theHarvester/static/'), name='static')


@app.get('/', response_class=HTMLResponse)
async def root(*, user_agent: str = Header(None)):
    # very 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