From 38017d454d44b8945bf5d9758f7029c9c159aca7 Mon Sep 17 00:00:00 2001 From: root Date: Mon, 25 Dec 2017 21:44:27 +0000 Subject: [PATCH] WTFISMYIP.dn http service --- nginx.conf | 16 +++++++++++ server.py | 61 +++++++++++++++++++++++++++++++++++++++++ templates/index.html | 51 +++++++++++++++++++++++++++++++++++ templates/style.css | 64 ++++++++++++++++++++++++++++++++++++++++++++ wtfismyip.ini | 9 +++++++ 5 files changed, 201 insertions(+) create mode 100644 nginx.conf create mode 100644 server.py create mode 100644 templates/index.html create mode 100644 templates/style.css create mode 100644 wtfismyip.ini diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..df4cb88 --- /dev/null +++ b/nginx.conf @@ -0,0 +1,16 @@ +server { + listen [::]:80; + listen 0.0.0.0:80; + + server_name wtfismyip.dn *.wtfismyip.dn; + + location / { + include uwsgi_params; + uwsgi_pass unix:/run/uwsgi/app/wtfismyip/socket; + more_set_headers 'Access-Control-Allow-Origin: *'; + } + + location /style.css { + alias /srv/www/wtfismyip.dn/templates/style.css; + } +} diff --git a/server.py b/server.py new file mode 100644 index 0000000..7c68213 --- /dev/null +++ b/server.py @@ -0,0 +1,61 @@ +#!/usr/bin/python3 + +from flask import request, render_template +from socket import gethostbyaddr +from flask import Flask + +import json +import binascii +import os +import sqlite3 + +app = Flask(__name__) + +@app.route("/") +def index(): + remote_addr = request.remote_addr + hostname = remote_addr + try: + hostname = gethostbyaddr(remote_addr)[0] + except: + pass + + token=os.urandom(16) + token='tok' + binascii.hexlify(token).decode() + + return render_template("index.html", remote_addr=remote_addr, hostname=hostname, token=token) + +@app.route("/api") +def api(): + remote_addr = request.remote_addr + hostname = remote_addr + try: + hostname = gethostbyaddr(remote_addr)[0] + except: + pass + + data = { + 'ipaddress' : remote_addr, + 'hostname' : hostname + } + return json.dumps(data) + +@app.route("/named/") +def named(token): + sqlite = sqlite3.connect("tokens.sqlite") + response = [] + with sqlite: + cur = sqlite.cursor() + cur.execute("SELECT DISTINCT ip FROM token WHERE token = ?", (token, )) + for row in cur: + hostname = row[0] + try: + hostname = gethostbyaddr(hostname)[0] + except: + pass + + response.append((row[0], hostname)) + + print(response) + return json.dumps(response) + diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..6d0d932 --- /dev/null +++ b/templates/index.html @@ -0,0 +1,51 @@ + + + + WTF IS MY DARKNET IP? + + + + + +
+

WTF IS MY DARKNET IP?

+ + +

+ For automated checks use our fancy shiny new API! +

+ + + + + + + + + + +
Preferred{{remote_addr}}{{hostname}}
IPv4No connectivity
IPv6No connectivity
+ +

WTF are my DNS Servers?

+ + +
+
+ + diff --git a/templates/style.css b/templates/style.css new file mode 100644 index 0000000..ab8adf4 --- /dev/null +++ b/templates/style.css @@ -0,0 +1,64 @@ +@font-face { + font-family: Concourse; + src: url('https://static.siccegge.de/WOFF/OTF/Concourse T3 Regular.woff'); +} +@font-face { + font-family: Equity; + src: url('https://static.siccegge.de/WOFF/OTF/Equity Text A Regular.woff'); +} +@font-face { + font-family: SourceCodePro; + src: url('https://static.siccegge.de/WOFF/OTF/SourceCodePro-Regular.otf.woff'); +} +* { + font-family: Equity; + text-rendering: optimizeLegibility; + font-variant-ligatures: common-ligatures; + font-kerning: normal; + line-height: 1.3; + margin: 0; + padding:0; +} +h1, h2, h3, h4, h5, h6, h7 { + font-family: Concourse; + padding-bottom: .5em; +} +ul { + margin-left: 2em; +} +p { + margin-bottom: 1em; +} +td { + padding: .5em; +} +.document { + margin-left: auto; + margin-right: auto; + margin-top: 1em; + margin-bottom: 1em; + width: 90%; + max-width: 50em; +} +@media (max-width: 45em) { + .document { + border: none; + width: 100%; + margin: 0px; + } +} +.align-left { + float:left; + padding-right: 1em; + padding-bottom: 1em; +} +.section { + margin-bottom: 1em; + float:left; + clear:both; + min-width: 26em; +} +.code { + padding-left: 1em; + font-family: SourceCodePro; +} diff --git a/wtfismyip.ini b/wtfismyip.ini new file mode 100644 index 0000000..9d02649 --- /dev/null +++ b/wtfismyip.ini @@ -0,0 +1,9 @@ +[uwsgi] +plugins = python3 +uid = www-data +gid = www-data +processes = 2 +threads = 4 +pythonpath = /srv/www/wtfismyip.dn +module = server:app +chdir = /srv/www/wtfismyip.dn -- 2.39.5