Skip to content

Commit

Permalink
initial commit; start of dns module, working real-time domain check
Browse files Browse the repository at this point in the history
  • Loading branch information
progrium committed Aug 27, 2009
0 parents commit 8ad4735
Show file tree
Hide file tree
Showing 6 changed files with 157 additions and 0 deletions.
8 changes: 8 additions & 0 deletions app.yaml
@@ -0,0 +1,8 @@
application: domdori
version: 1
runtime: python
api_version: 1

handlers:
- url: .*
script: main.py
16 changes: 16 additions & 0 deletions dns.py
@@ -0,0 +1,16 @@
from google.appengine.ext import db

class Zone(db.Model):
user = db.UserProperty(auto_current_user_add=True)
domain = db.StringProperty(required=True)
ttl = db.IntegerProperty(required=True)
created = db.DateTimeProperty(auto_now_add=True)

class ResourceRecord(db.Model):
zone = db.ReferenceProperty(Zone)
name = db.StringProperty(required=True)
type = db.StringProperty(required=True)
ttl = db.IntegerProperty(required=False)
data = db.StringProperty(required=True)
created = db.DateTimeProperty(auto_now_add=True)
updated = db.DateTimeProperty(auto_now=True)
11 changes: 11 additions & 0 deletions index.yaml
@@ -0,0 +1,11 @@
indexes:

# AUTOGENERATED

# This index.yaml is automatically updated whenever the dev_appserver
# detects that a new type of query is run. If you want to manage the
# index.yaml file manually, remove the above marker line (the line
# saying "# AUTOGENERATED"). If you want to manage some indexes
# manually, move them above the marker line. The index.yaml file is
# automatically uploaded to the admin console when you next deploy
# your application using appcfg.py.
69 changes: 69 additions & 0 deletions main.py
@@ -0,0 +1,69 @@
#!/usr/bin/env python
#
# Copyright 2007 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#




import wsgiref.handlers


from google.appengine.ext import webapp
from google.appengine.api import urlfetch
from google.appengine.ext.webapp import template

ENOM_UID = 'fihn'
ENOM_PASS = '3g3r235N'

def parse_response(body):
return dict([kvp.split('=') for kvp in body.split('\r\n') if len(kvp) and not kvp[0] == ';'])

class RegisterHandler(webapp.RequestHandler):
def get(self):
self.response.out.write(template.render('templates/main.html', locals()))

class MainHandler(webapp.RequestHandler):
def get(self):
self.response.out.write(template.render('templates/main.html', locals()))

class CheckHandler(webapp.RequestHandler):
def get(self):
domain = self.request.GET['domain']
if '.' in domain:
sld, tld = domain.split('.')
else:
sld = domain
tld = '@'
url = "http://resellertest.enom.com/interface.asp?Command=Check&UID=%s&PW=%s&SLD=%s&TLD=%s" % (ENOM_UID, ENOM_PASS, sld, tld)
resp = urlfetch.fetch(url)
resp = parse_response(resp.content)
domains = {}
if tld == '@':
for n in range(3):
index = str(n+1)
domains[resp['Domain%s' % index]] = resp['RRPText%s' % index]
else:
domains[domain] = resp['RRPText']
self.response.out.write(str(domains))


def main():
application = webapp.WSGIApplication([('/', MainHandler), ('/check', CheckHandler), ('/register', RegisterHandler)], debug=True)
wsgiref.handlers.CGIHandler().run(application)


if __name__ == '__main__':
main()
21 changes: 21 additions & 0 deletions templates/base.html
@@ -0,0 +1,21 @@
<html>
<head>
<title>{% block title %}domdori - domains done right{% endblock %}</title>
<link href="/static/style.css" type="text/css" rel="stylesheet" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script>
</head>
<body>
<div id="wrapper">
<div id="header">
<h1>domdori</h1>
</div>
<div id="content">
<div style="float: right;">

</div>
<br />
{% block content %}{% endblock %}
</div>
</div>
</body>
</html>
32 changes: 32 additions & 0 deletions templates/main.html
@@ -0,0 +1,32 @@
{% extends 'base.html' %}
{% block content %}
<form action="/register">
<input name="domain" type="text" id="domain" /> <input id="register" type="submit" disabled="disabled" value="Register">
</form>
<div id="available"></div>
<script type="text/javascript">
var connection = null;
var last = null;
$('#domain').keyup(function () {
if ($('#domain').val().match(/[\w\d-]+\.[\w\d-]{2,4}$/)) {
$('#register').removeAttr('disabled');
} else {
$('#register').attr('disabled', 'disabled');
}
setTimeout(function() {
if (last != $('#domain').val()) {
last = $('#domain').val();
if (connection) { connection.abort(); }
connection = $.ajax({
type:"GET",
url: "/check?domain=" + $('#domain').val(),
success: function(data){
$("#available").html(data);
}
});
}
}, 100);

});
</script>
{% endblock %}

0 comments on commit 8ad4735

Please sign in to comment.