Initial commit

master
Sven Slootweg 12 years ago
commit 6ffb044f8e

1
.gitignore vendored

@ -0,0 +1 @@
*.pyc

@ -0,0 +1,7 @@
#!/usr/local/bin/python
from flup.server.fcgi import WSGIServer
from app import app
from werkzeug.contrib.fixers import LighttpdCGIRootFix
if __name__ == '__main__':
WSGIServer(LighttpdCGIRootFix(app)).run()

123
app.py

@ -0,0 +1,123 @@
import subprocess, datetime, time
try:
import json
except ImportError:
import simplejson as json
try:
import pythonwhois
except ImportError:
print "pythonwhois is not installed!"
exit(1)
try:
import pymongo
except ImportError:
print "pymongo is not installed!"
exit(1)
from flask import Flask, request, render_template, flash, redirect, url_for
app = Flask(__name__)
app.secret_key = "er4988n439h981359n5n9n5954b0fsdfkjglqrekjt0314njn"
app.debug=True
db = pymongo.Connection()['crytowhois']
def format_date(dates):
if dates is None:
return None
else:
return dates[0].isoformat()
def get_first(options):
if options is None:
return None
else:
return options[0]
def whois(domain):
result = pythonwhois.whois(domain)
if result['creation_date'] is None and result['expiration_date'] is None and result['registrar'] is None and result['name_servers'] is None:
return None
else:
creation_date = format_date(result['creation_date'])
expiration_date = format_date(result['expiration_date'])
updated_date = format_date(result['updated_date'])
registrar = get_first(result['registrar'])
whois_server = get_first(result['whois_server'])
emails = result['emails']
nameservers = result['name_servers']
return {
'creation_date': creation_date,
'expiration_date': expiration_date,
'updated_date': updated_date,
'registrar': registrar,
'whois_server': whois_server,
'emails': emails,
'nameservers': nameservers
}
@app.route('/', methods=["GET"])
def home():
return render_template("home.tpl")
def find_whois(domain):
db_results = db['responses'].find_one({'domain': domain})
if db_results is not None:
return (db_results['timestamp'], db_results['response'])
else:
result = whois(domain)
if result is not None:
db['responses'].insert({
'domain': domain,
'response': result,
'timestamp': time.time()
})
return (time.time(), result)
else:
return (time.time(), None)
@app.route('/query', methods=["POST"])
def query():
try:
domain = request.form['domain']
if domain == "":
flash("You did not enter a domain.")
return render_template("home.tpl")
else:
return redirect(url_for('query_html', domain=domain))
except KeyError, e:
flash("You did not specify a domain.")
return render_template("home.tpl")
@app.route('/query/html/<domain>', methods=["GET"])
def query_html(domain):
retrieval_date, result = find_whois(domain)
if result is None:
flash("The specified domain does not exist.")
return render_template("home.tpl"), 404
else:
retrieval_timestamp = datetime.datetime.fromtimestamp(int(retrieval_date))
return render_template("result.tpl", domain=domain, retrieval_date=retrieval_timestamp.isoformat(), **result)
@app.route('/query/json/<domain>', methods=["GET"])
def query_json(domain):
if domain is not None:
retrieval_date, result = find_whois(domain)
result['retrieval_date'] = int(retrieval_date)
return json.dumps(result)
else:
return json.dumps(None)
if __name__ == '__main__':
app.run(host="0.0.0.0", port=1234, debug=True)

@ -0,0 +1,22 @@
server.event-handler = "poll"
$HTTP["host"] =~ "whois.cryto.net" {
server.document-root = "/var/apps/whois"
fastcgi.server = ("/" =>
((
"socket" => "/tmp/whoisapp-fcgi.sock",
"bin-path" => "/var/apps/whois/app.fcgi",
"check-local" => "disable",
"max-procs" => 1
))
)
alias.url = (
"/static" => "/var/apps/whois/static"
)
url.rewrite-once = (
"^(/static($|/.*))$" => "$1"
)
}

@ -0,0 +1,8 @@
from tornado.wsgi import WSGIContainer
from tornado.httpserver import HTTPServer
from tornado.ioloop import IOLoop
from app import app
http_server = HTTPServer(WSGIContainer(app))
http_server.listen(1234)
IOLoop.instance().start()

@ -0,0 +1,104 @@
body
{
background-color: #FBFBFB;
padding: 0px;
margin: 0px;
font-family: 'Orienta', 'Open Sans', sans-serif;
}
label, input, button
{
font-family: 'Source Sans Pro', 'Open Sans', sans-serif;
}
#header
{
padding: 11px 18px;
background-color: #505050;
color: white;
}
#contents
{
padding: 13px 18px;
}
h1
{
margin: 0px;
}
#whois_form
{
padding: 6px 18px;
background-color: #E3E3E3;
border: 2px solid #252525;
border-radius: 8px;
}
#whois_form label, input, button
{
font-size: 22px;
color: #2D2D2D;
}
#whois_form label
{
margin-right: 10px;
font-weight: bold;
}
#whois_form button
{
padding: 2px 12px;
margin-left: 10px;
}
#whois_form input
{
padding: 3px 7px;
width: 400px;
}
h2
{
margin-bottom: 4px;
}
table th, td
{
text-align: left;
border: 1px solid #636363;
padding: 4px 9px;
}
table
{
border-collapse: collapse;
border: 2px solid black;
}
#flashes
{
list-style: none;
margin: 18px 13px 6px 18px;
border: 1px solid red;
padding: 6px 8px;
background-color: #FFBFBF;
}
#footer
{
margin: 9px 18px;
background-color: #2F2F2F;
color: white;
padding: 8px 12px;
border: 1px solid black;
border-radius: 7px;
font-size: 13px;
}
#footer a
{
color: #FFFB85;
}

@ -0,0 +1,37 @@
<!doctype html>
<html>
<head>
<title>Cryto WHOIS</title>
<link rel="stylesheet" href="/static/style.css">
<link href='http://fonts.googleapis.com/css?family=Orienta' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Source+Sans+Pro:400,700' rel='stylesheet' type='text/css'>
</head>
<body>
<div id="header">
<h1>Cryto WHOIS</h1>
Free and unlimited WHOIS lookups and JSON API
</div>
{% with messages = get_flashed_messages() %}
{% if messages %}
<ul id="flashes">
{% for message in messages %}
<li>{{ message }}</li>
{% endfor %}
</ul>
{% endif %}
{% endwith %}
<div id="contents">
<form id="whois_form" method="post" action="/query">
<label for="domain_input">Look up a domain:</label>
<input id="domain_input" type="text" name="domain">
<button type="submit" name="submit">WHOIS!</button>
</form>
{% block body %}
It would seem the page you requested was not found.
{% endblock %}
</div>
<div id="footer">
<strong>Hi. Thanks for using Cryto WHOIS.</strong> I live off donations, so any financial contribution would be <a href="http://cryto.net/~joepie91/donate.html">very welcome</a>! Source code for this site is coming soon.
</div>
</body>
</html>

@ -0,0 +1,4 @@
{% extends "base.tpl" %}
{% block body %}
{% endblock %}

@ -0,0 +1,62 @@
{% extends "base.tpl" %}
{% block body %}
<div class="whois-results">
<h2>WHOIS results</h2>
<table>
<tr>
<th>WHOIS record retrieval date:</th>
<td>{{ retrieval_date }}</td>
</tr>
{% if registrar != None %}
<tr>
<th>Registrar:</th>
<td>{{ registrar }}</td>
</tr>
{% endif %}
{% if whois_server != None %}
<tr>
<th>WHOIS server:</th>
<td>{{ whois_server }}</td>
</tr>
{% endif %}
{% if creation_date != None %}
<tr>
<th>Creation date:</th>
<td>{{ creation_date }}</td>
</tr>
{% endif %}
{% if expiration_date != None %}
<tr>
<th>Expiration date:</th>
<td>{{ expiration_date }}</td>
</tr>
{% endif %}
{% if updated_date != None %}
<tr>
<th>Record/database last updated:</th>
<td>{{ updated_date }}</td>
</tr>
{% endif %}
{% if nameservers != None %}
{% for nameserver in nameservers %}
<tr>
<th>Nameserver:</th>
<td>{{ nameserver }}</td>
</tr>
{% endfor %}
{% endif %}
{% if emails != None %}
{% for email in emails %}
<tr>
<th>Contact e-mail:</th>
<td>{{ email }}</td>
</tr>
{% endfor %}
{% endif %}
</table>
<p>
Need JSON? Try <a href="/query/json/{{ domain }}">http://whois.cryto.net/query/json/{{ domain }}</a>
</p>
</div>
{% endblock %}
Loading…
Cancel
Save