2012-02-28 02:27:50 +00:00
|
|
|
import web
|
2012-02-28 06:12:05 +00:00
|
|
|
from web import form
|
2012-02-28 02:27:50 +00:00
|
|
|
|
|
|
|
db = web.database(dbn='mysql', user='mysecrets', pw='horsebatteries',
|
|
|
|
db='mysecrets')
|
2012-02-28 06:12:05 +00:00
|
|
|
|
2012-02-28 02:27:50 +00:00
|
|
|
urls = (
|
2012-02-28 06:12:05 +00:00
|
|
|
'/secret/api/(.*)', 'api',
|
|
|
|
'/secret/(.*)', 'index'
|
2012-02-28 02:27:50 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
app = web.application(urls, globals())
|
|
|
|
|
2012-02-28 06:12:05 +00:00
|
|
|
render = web.template.render('templates/')
|
|
|
|
|
|
|
|
create = form.Form(
|
|
|
|
form.Textbox('base_url', description="domain"),
|
|
|
|
form.Textbox('username'),
|
|
|
|
form.Password('password'),
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class index:
|
|
|
|
def GET(self, method):
|
|
|
|
if method == 'get':
|
|
|
|
if web.input():
|
|
|
|
i = web.input()
|
|
|
|
selected = db.select('passwords', where='`base_url`="'+i.base_url+'"')
|
|
|
|
|
|
|
|
if len(selected) > 0:
|
|
|
|
pairs = '<ul>'
|
|
|
|
for p in selected:
|
|
|
|
pairs += '<li>'+p.username+', '+p.password+'</li>'
|
|
|
|
pairs += '</ul>'
|
|
|
|
|
|
|
|
else:
|
|
|
|
pairs = "<p>Sorry buddy, you're outta luck</p>"
|
|
|
|
|
|
|
|
body = '<h1>'+i.base_url+'</h1>\n'+pairs
|
|
|
|
|
|
|
|
return render.page(i.base_url, body)
|
|
|
|
|
|
|
|
else:
|
|
|
|
return render.page('get','<p>need input.</p>')
|
|
|
|
|
|
|
|
if method == 'new':
|
|
|
|
f = create()
|
|
|
|
|
|
|
|
body = '<h1>Create</h1>\n<form class="form" method="get" \
|
|
|
|
action="/secret/create">\n'+\
|
|
|
|
f.render()+ '\n<input type="submit" name="submit" id="submit"/></form>'
|
|
|
|
|
|
|
|
return render.page('create',body)
|
|
|
|
|
|
|
|
|
|
|
|
if method == 'create':
|
|
|
|
i = web.input()
|
|
|
|
n = db.insert('passwords', username=i.username, password=i.password, \
|
|
|
|
base_url=i.base_url)
|
|
|
|
|
|
|
|
body = '<h1>'+i.base_url+'</h1><p>'+i.username+', '+i.password+'</p>'
|
|
|
|
|
|
|
|
return render.page('Created', body)
|
|
|
|
|
|
|
|
|
|
|
|
else:
|
|
|
|
return render.page('mySecrets', '<p>These are mySecrets. There is nothing for you here.</p>')
|
2012-02-28 02:27:50 +00:00
|
|
|
|
|
|
|
class api:
|
|
|
|
def GET(self, method):
|
|
|
|
if method == "list":
|
|
|
|
tmp = ''
|
|
|
|
for pair in db.select('passwords'):
|
|
|
|
tmp += pair['base_url']+','+pair['username']+','+pair['password']+'\n'
|
|
|
|
|
|
|
|
return tmp
|
|
|
|
|
|
|
|
if method == "get":
|
|
|
|
i = web.input()
|
|
|
|
base_url = i.base_url
|
|
|
|
pairs = db.select('passwords', where='`base_url`="'+base_url+'"')
|
|
|
|
|
|
|
|
tmp = ''
|
|
|
|
for pair in pairs:
|
2012-02-28 06:12:05 +00:00
|
|
|
tmp += pair.username+','+pair.password+'\n'
|
2012-02-28 02:27:50 +00:00
|
|
|
|
|
|
|
return tmp
|
|
|
|
|
|
|
|
else:
|
|
|
|
return 'mySecrets API ' + method
|
|
|
|
|
|
|
|
def POST(self, method):
|
2012-02-28 06:12:05 +00:00
|
|
|
i = web.input()
|
|
|
|
n = db.insert('passwords', username=i.username, password=i.password, \
|
|
|
|
base_url=i.base_url)
|
|
|
|
|
|
|
|
body = '<h1>'+i.base_url+'</h1><p>'+i.username+', '+i.password+'</p>'
|
|
|
|
|
|
|
|
return render.page('Created', body)
|
2012-02-28 02:27:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2012-02-28 06:12:05 +00:00
|
|
|
app.run()
|