### Allow access to the plugins and dist directories ###
RewriteRule ^app/plugins/(.*)$ - [L]
RewriteRule ^app/dist/(.*)$ - [L]

### rewrite

### protected files & directories ###
RewriteRule ^((install/|README.md|app|app/core/|static/cache|static/private)) - [R=404,L,NC]


RewriteRule ^honeydb/services$ https://honeydb.io/services [R=301,L]

### app ###
RewriteRule ^index.html?$ index.php?_action=default

# RewriteRule template:
# RewriteRule ^<path>/?$ index.php?_action=<action name>
RewriteRule ^/?$ index.php?_action=home
RewriteRule ^home/?$ index.php?_action=home
RewriteRule ^hosts/?$ index.php?_action=hosts
RewriteRule ^release_notes/?$ index.php?_action=release_notes
RewriteRule ^honeydb_agents/?$ index.php?_action=honeydb_agents
RewriteRule ^honeydb_agents/(.*)/?$ index.php?_action=honeydb_agents&tab=$1
RewriteRule ^host/session-events/(.*)/?$ index.php?_action=session-events&session=$1
RewriteRule ^host-protocols/(.*)/?$ index.php?_action=host-protocols&host=$1
RewriteRule ^host-services/(.*)/?$ index.php?_action=host-services&host=$1
RewriteRule ^host-sessions/(.*)/?$ index.php?_action=host-sessions&host=$1
RewriteRule ^host/(.*)/?$ index.php?_action=host&host=$1
RewriteRule ^host3/(.*)/?$ index.php?_action=host3&host=$1
RewriteRule ^ip-history/(.*)/?$ index.php?_action=ip-history&host=$1
RewriteRule ^services/?$ index.php?_action=services
RewriteRule ^services-report/?$ index.php?_action=services-report
RewriteRule ^service/(.*)/?$ index.php?_action=service&service=$1

RewriteRule ^docs/api/monitors/?$ https://documenter.getpostman.com/view/17070515/2sB2cbZduZ [R=301,L]
RewriteRule ^docs/api/?$ https://documenter.getpostman.com/view/17070515/2sB2izDD1w [R=301,L]

RewriteRule ^generate-key/([a-z]+)/?$ index.php?_action=generate-key&key-type=$1 [L]
RewriteRule ^threats/?$ index.php?_action=threats
RewriteRule ^threats/(.*)/?$ index.php?_action=threats&tab=$1
RewriteRule ^monitors/?$ index.php?_action=monitors
RewriteRule ^monitors/create/?$ index.php?_action=monitors-create
RewriteRule ^monitors/delete/?$ index.php?_action=monitors-delete
RewriteRule ^monitors/notifications/?$ index.php?_action=monitors-notifications
RewriteRule ^monitors/logs/?$ index.php?_action=monitors-logs
RewriteRule ^twitter/?$ index.php?_action=twitter
RewriteRule ^event-data/(\d+)/?$ index.php?_action=event-data&id=$1
RewriteRule ^agents/?$ index.php?_action=agents
RewriteRule ^status/?$ index.php?_action=status
RewriteRule ^about/?$ index.php?_action=about
RewriteRule ^stats/?$ index.php?_action=stats
RewriteRule ^stats/(.*)/?$ index.php?_action=stats&stats_period=$1
RewriteRule ^workshop/? index.php?_action=workshop
RewriteRule ^plans/?$ index.php?_action=plans [L]
RewriteRule ^plans.html$ index.php?_action=plans [L]
RewriteRule ^tos/?$ index.php?_action=tos
RewriteRule ^privacy/?$ index.php?_action=privacy
RewriteRule ^interval/(\d+)/?$ index.php?_action=interval&interval=$1
RewriteRule ^data_view/(\d+)/?$ index.php?_action=data_view&data_view=$1
RewriteRule ^sponsors/?$ index.php?_action=sponsors
RewriteRule ^threatq/?$ index.php?_action=threatq
RewriteRule ^github-webhook/?$ index.php?_action=github-webhook

RewriteRule ^oauthtest/?$ index.php?_action=oauthtest

## downloads
RewriteRule ^downloads/?$ /honeydb_agents [R=301] [L]
RewriteRule ^license/?$ static/license.txt
RewriteRule ^agent-changelog/?$ static/CHANGELOG.txt

## deploy!
RewriteRule ^deploy/?$ index.php?_action=deploy
#RewriteRule ^deploy/settings/?$ index.php?_action=deploy&c=settings
RewriteRule ^deploy/profiles/?$ index.php?_action=deploy&c=profiles
RewriteRule ^deploy/deployments/?$ index.php?_action=deploy&c=deployments
RewriteRule ^deploy/deployment/?$ index.php?_action=deploy&c=deployment
RewriteRule ^deploy/images/?$ index.php?_action=deploy&c=images
RewriteRule ^deploy/deployment/([0-9]+)/?$ index.php?_action=deploy&c=deployment&id=$1
RewriteRule ^deploy/start/([0-9]+)/?$ index.php?_action=deploy&c=start&id=$1
RewriteRule ^deploy/restart/([0-9]+)/?$ index.php?_action=deploy&c=restart&id=$1
RewriteRule ^deploy/stop/([0-9]+)/?$ index.php?_action=deploy&c=stop&id=$1
RewriteRule ^deploy/delete/([0-9]+)/?$ index.php?_action=deploy&c=delete&id=$1
RewriteRule ^deploy/configure/([0-9]+)/?$ index.php?_action=deploy&c=configure&id=$1
RewriteRule ^deploy/configuration/([0-9]+)/?$ index.php?_action=deploy&c=configuration&id=$1
RewriteRule ^deploy/latest_version/?$ index.php?_action=deploy&c=latestversion
RewriteRule ^deploy/version/([0-9]+)/?$ index.php?_action=deploy&c=version&id=$1

RewriteRule ^login/method$ index.php?_action=login-method [L]
RewriteCond %{QUERY_STRING} ^code\=([\w]+)$
RewriteRule ^login/github$ index.php?_action=login-github&code=%1 [L]
RewriteRule ^login/github/?$ index.php?_action=login-github

# honeydb/login/twitter?oauth_token=bCJ2oAAAAAAAhosYAAABT-dCtdg&oauth_verifier=g1IqXeehY2eUXxjoQCJww0EzZvjQ78Sk
RewriteCond %{QUERY_STRING} ^oauth_token\=([a-zA-z0-9\-\_\=]+)\&oauth_verifier\=([a-zA-z0-9\-\_\=]+)$
RewriteRule ^login/twitter$ index.php?_action=login-twitter&oauth_token=%1&oauth_verifier=%2 [L]
RewriteRule ^login/twitter/?$ index.php?_action=login-twitter [L]
RewriteRule ^login/google/?$ index.php?_action=login-google [L]
RewriteRule ^login/email/?$ index.php?_action=login-email [QSA] [L]

### api ###
RewriteRule ^api/?$ index.php?_api=true&_action=default
RewriteRule ^api/bad-hosts$ index.php?_api=true&_action=bad-hosts
RewriteRule ^api/bad-hosts-7d$ index.php?_api=true&_action=bad-hosts-7d
RewriteRule ^api/bad-hosts-daily$ index.php?_api=true&_action=bad-hosts-daily
RewriteRule ^api/bad-hosts/mydata$ index.php?_api=true&_action=bad-hosts&mydata=1
RewriteRule ^api/bad-hosts/([a-zA-Z0-9\_\.\-]{1,20})/mydata$ index.php?_api=true&_action=bad-hosts-service&service=$1&mydata=1
RewriteRule ^api/bad-hosts/([a-zA-Z0-9\_\.\-]{1,20})$ index.php?_api=true&_action=bad-hosts-service&service=$1

RewriteRule ^api/ip-history/([0-9\.]+)$ index.php?_api=true&_action=ip-history&host=$1 [L]
RewriteRule ^api/ip-context/([0-9\.]+)$ index.php?_api=true&_action=ip-context&ip_address=$1 [L]
RewriteRule ^api/payload-context/([a-z0-9]{32})$ index.php?_api=true&_action=payload-context&hash=$1 [L]
RewriteRule ^api/cve/ip/([0-9\.]+)$ index.php?_api=true&_action=cve&ip_address=$1 [L]
RewriteRule ^api/cve/([A-Za-z0-9\.\-]+)$ index.php?_api=true&_action=cve&cve_id=$1 [L]

RewriteRule ^api/payload-history/([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)$ index.php?_api=true&_action=payload-history&ip_address=$1 [L] # /1.1.1.1
RewriteRule ^api/payload-history/([0-9]{4})$ index.php?_api=true&_action=payload-history&year=$1 [L] # /2014
RewriteRule ^api/payload-history/([0-9]{4})/([0-9]{1,2})$ index.php?_api=true&_action=payload-history&year=$1&month=$2 [L] # /2014/05
RewriteRule ^api/payload-history/attributes/?$ index.php?_api=true&_action=payload-history&attributes=1 [L] # /attributes
RewriteRule ^api/payload-history/attributes/([a-zA-Z0-9\_\.\-\/]{1,50})?$ index.php?_api=true&_action=payload-history&attribute=$1 [L] # /attributes/shell-command-test
RewriteRule ^api/payload-history/remote-hosts/?$ index.php?_api=true&_action=payload-history&remote_hosts=1 [L] # /remote-hosts
RewriteRule ^api/payload-history/remote-hosts/([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)$ index.php?_api=true&_action=payload-history&remote_host=$1 [L] # /attributes/1.1.1.1
RewriteRule ^api/payload-history/services/?$ index.php?_api=true&_action=payload-history&services=1 [L] # /services
RewriteRule ^api/payload-history/([a-zA-Z0-9\_\.\-]{1,20})$ index.php?_api=true&_action=payload-history&service=$1 [L] # /HTTP
RewriteRule ^api/payload-history/([a-z0-9]{32})/remote-hosts/([0-9]{4})$ index.php?_api=true&_action=payload-history&hash_ips=$1&year=$2 [L] # /abc123/remote-hosts/2014
RewriteRule ^api/payload-history/([a-z0-9]{32})$ index.php?_api=true&_action=payload-history&hash=$1 [L] # /abc123

RewriteRule ^api/services$ index.php?_api=true&_action=services
RewriteRule ^api/services/mydata$ index.php?_api=true&_action=services&mydata=1

RewriteRule ^api/sensor-data/mydata$ index.php?_api=true&_action=sensor-data&mydata=1 [QSA]
RewriteRule ^api/sensor-data$ index.php?_api=true&_action=sensor-data&mydata=0 [QSA]
RewriteRule ^api/sensor-data2$ index.php?_api=true&_action=sensor-data2&mydata=0 [QSA]
RewriteRule ^api/sensor-data/count/mydata$ index.php?_api=true&_action=sensor-data-count&mydata=1 [QSA]
RewriteRule ^api/sensor-data/count$ index.php?_api=true&_action=sensor-data-count&mydata=0 [QSA]
RewriteRule ^api/twitter-threat-feed$ index.php?_api=true&_action=twitter-threat-feed
RewriteRule ^api/twitter-threat-feed/([0-9\.]+)$ index.php?_api=true&_action=twitter-threat-feed-host&host=$1

RewriteRule ^api/stats$ index.php?_api=true&_action=stats [QSA]
RewriteRule ^api/stats/asn$ index.php?_api=true&_action=stats-asn [QSA]
RewriteRule ^api/stats/mysql-event-buffer$ index.php?_api=true&_action=stats-mysql-event-buffer

RewriteRule ^api/nodes$ index.php?_api=true&_action=nodes
RewriteRule ^api/nodes/mydata$ index.php?_api=true&_action=nodes&mydata=1

RewriteRule ^api/hmac$ index.php?_api=true&_action=hmac
RewriteRule ^api/test/([a-z_]+)$ index.php?_api=true&_action=test&thing=$1

### HELPER APIs
RewriteRule ^api/agents/?$ index.php?_api=true&_action=agents

RewriteRule ^api/myipaddress/?$ index.php?_api=true&_action=myipaddress

RewriteRule ^api/internet-scanner/([0-9\.]+)/?$ index.php?_api=true&_action=internet-scanner&data=0&host=$1
RewriteRule ^api/internet-scanner/info/([0-9\.]+)/?$ index.php?_api=true&_action=internet-scanner&internet_scanner_info=1&host=$1

RewriteRule ^api/ipinfo/([0-9\.]+)$ index.php?_api=true&_action=ipinfo&host=$1
RewriteRule ^api/ipinfo/bogon/([0-9\.]+)$ index.php?_api=true&_action=ipinfo-bogon&host=$1
RewriteRule ^api/ipinfo/tor/([0-9\.]+)$ index.php?_api=true&_action=ipinfo-tor&host=$1
RewriteRule ^api/ipinfo/sansip/([0-9\.]+)$ index.php?_api=true&_action=ipinfo-sansip&host=$1
RewriteRule ^api/ipinfo/ciarmy/([0-9\.]+)$ index.php?_api=true&_action=ipinfo-ciarmy&host=$1
RewriteRule ^api/ipinfo/et-compromised/([0-9\.]+)$ index.php?_api=true&_action=ipinfo-et-compromised&host=$1
RewriteRule ^api/ipinfo/project-honeypot/([0-9\.]+)$ index.php?_api=true&_action=ipinfo-project-honeypot&host=$1
RewriteRule ^api/ipinfo/pallebone/([0-9\.]+)$ index.php?_api=true&_action=ipinfo-pallebone&host=$1
RewriteRule ^api/ipinfo/threatfox/([0-9\.]+)$ index.php?_api=true&_action=ipinfo-threatfox&host=$1
RewriteRule ^api/ipinfo/blocklist_net_ua/([0-9\.]+)$ index.php?_api=true&_action=ipinfo-blocklist_net_ua&host=$1
RewriteRule ^api/ipinfo/ssl/([0-9\.]+)$ index.php?_api=true&_action=ipinfo-ssl&host=$1

RewriteRule ^api/netinfo/lookup/([0-9\.]+)$ index.php?_api=true&_action=netinfo-lookup&host=$1
RewriteRule ^api/netinfo/network\-addresses/([0-9\.\/]+)/?$ index.php?_api=true&_action=netinfo-network-addresses&cidr=$1
RewriteRule ^api/netinfo/prefixes/([0-9]+){1,10}$ index.php?_api=true&_action=netinfo-prefixes&asn=$1
RewriteRule ^api/netinfo/as-name/([0-9]+){1,10}$ index.php?_api=true&_action=netinfo-as-name&asn=$1
RewriteRule ^api/netinfo/geolocation/([0-9\.]+)$ index.php?_api=true&_action=netinfo-geolocation&host=$1

RewriteRule ^api/datacenter/aws$ index.php?_api=true&_action=datacenter-aws
RewriteRule ^api/datacenter/gcp$ index.php?_api=true&_action=datacenter-gcp
RewriteRule ^api/datacenter/ibm$ index.php?_api=true&_action=datacenter-ibm
RewriteRule ^api/datacenter/azure$ index.php?_api=true&_action=datacenter-azure
RewriteRule ^api/datacenter/azure/china$ index.php?_api=true&_action=datacenter-azure-china
RewriteRule ^api/datacenter/azure/germany$ index.php?_api=true&_action=datacenter-azure-germany
RewriteRule ^api/datacenter/azure/gov$ index.php?_api=true&_action=datacenter-azure-gov
RewriteRule ^api/datacenter/oracle$ index.php?_api=true&_action=datacenter-oracle
RewriteRule ^api/datacenter/cloudflare$ index.php?_api=true&_action=datacenter-cloudflare

RewriteRule ^api/explorer/countByDay$ index.php?_api=true&_action=count-by-day [QSA]
RewriteRule ^api/explorer/eventsByDay$ index.php?_api=true&_action=events-by-day [QSA]
RewriteRule ^api/explorer/countByService$ index.php?_api=true&_action=count-by-service [QSA]
RewriteRule ^api/explorer/countByIp$ index.php?_api=true&_action=count-by-ip [QSA]
RewriteRule ^api/explorer/events$ index.php?_api=true&_action=events [QSA]

RewriteRule ^api/service-config/?$ index.php?_api=true&_action=service-config
RewriteRule ^api/service-config/([a-z_-]+)$ index.php?_api=true&_action=service-config&profile=$1

### MONITORS APIs
RewriteRule ^api/monitors/?$ index.php?_api=true&_action=monitors [QSA] [L]
RewriteRule ^api/monitors/logs$ index.php?_api=true&_action=monitors-logs [QSA] [L]
RewriteRule ^api/monitors/logs/(?P<guid>\w.+)$ index.php?_api=true&_action=monitors-logs&client_id=$1 [QSA] [L]
RewriteRule ^api/monitors/notifications$ index.php?_api=true&_action=monitors-notifications [L]
RewriteRule ^api/monitors/notifications/(?P<guid>\w.+)$ index.php?_api=true&_action=monitors-notifications&client_id=$1 [QSA] [L]
RewriteRule ^api/monitors/clients$ index.php?_api=true&_action=monitors-clients&clients=true [QSA] [L]
RewriteRule ^api/monitors/clients/(?P<guid>\w.+)$ index.php?_api=true&_action=monitors-clients&clients=true&client_id=$1 [QSA] [L]
RewriteRule ^api/monitors/(?P<guid>\w.+)$ index.php?_api=true&_action=monitors&client_id=$1 [QSA] [L]


### Cache Generrate APIs
RewriteRule ^api/cache/generate/(.*)/?$ index.php?_api=true&_action=cache-generate&target=$1 [QSA] [L]
RewriteRule ^api/cache/get/(.*)/?$ index.php?_api=true&_action=cache-get&target=$1 [QSA] [L]

### core ###
RewriteRule ^csp-report/?$ index.php?_action=csp-report
RewriteRule ^login/?$ index.php?_action=login
RewriteRule ^iforgot/?$ index.php?_action=forgot
RewriteRule ^iforgot/password/?$ index.php?_action=forgot
RewriteRule ^iforgot/reset/?$ index.php?_action=forgot&c=reset
RewriteRule ^iforgot/validate/(?P<code>\w.+)?$ index.php?_action=forgot&c=validate&code=$1
RewriteRule ^logout/?$ index.php?_action=logout
RewriteRule ^register/?$ index.php?_action=register
RewriteRule ^register/invite/?$ index.php?_action=register&c=invite
RewriteRule ^register/validate/(?P<code>\w.+)?$ index.php?_action=register&c=validate&code=$1
RewriteRule ^register/activate index.php?_action=register&c=activate
