Skip to content

Commit

Permalink
Configurable response type for main route
Browse files Browse the repository at this point in the history
  • Loading branch information
mepley1 committed Nov 23, 2024
1 parent 446491f commit 4d1bc31
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
7 changes: 7 additions & 0 deletions project/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@
### If the following option is set to True, then no passwords will be logged at all. (Default: True)
DONT_LOG_PASSWORDS = True

### Configure the main catch-all route to return either an HTML page,
### the client IP, or just a 200 status code.
### Returning only the client IP or status code may reduce being quickly fingerprinted
### as an instance of this honeypot, at least if no application routes are requested.
### Values: 1 = HTML page (default), 2 = IP, 3 = Status code
INDEX_RESPONSE_TYPE = 1

################################################
### Database URI examples for various database systems. Default: SQLite (/honeypot/instance/db.sqlite)
### Uncomment/configure one if using something else. Users db only.
Expand Down
17 changes: 12 additions & 5 deletions project/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,18 +333,25 @@ def closeConnection(response):
conn.commit()
conn.close()

#Clear the cache so this request can appear on main.stats
# Clear the cache so this request can appear on main.stats
cache.clear()

# Calculate and log run time
t2 = time.perf_counter()
time_to_run = t2 - t1
logging.debug(f'TIME: {time_to_run}')
logging.debug(f'RUN TIME: {time_to_run}')
#logging.debug(response.status) #For testing
return response

#return jsonify(req_ip)
flash(f'IP: {req_ip}', 'info')
return render_template('index.html')
# Decide what to return, based on config. (Configure in config.py)
match current_app.config.get('INDEX_RESPONSE_TYPE'):
case 1: # HTML page
flash(f'IP: {req_ip}', 'info')
return render_template('index.html')
case 2: # Client IP
return jsonify(req_ip)
case 3 | _: # Only status code
return ('', 200)

### STATS ROUTES

Expand Down

0 comments on commit 4d1bc31

Please sign in to comment.