adding some style
This commit is contained in:
parent
e1f1cf09ca
commit
1778115a82
2 changed files with 192 additions and 109 deletions
215
mysecrets.py
215
mysecrets.py
|
@ -6,11 +6,11 @@ import web
|
||||||
from web import form
|
from web import form
|
||||||
|
|
||||||
db = web.database(dbn='mysql', user='mysecrets', pw='horsebatteries',
|
db = web.database(dbn='mysql', user='mysecrets', pw='horsebatteries',
|
||||||
db='mysecrets')
|
db='mysecrets')
|
||||||
|
|
||||||
urls = (
|
urls = (
|
||||||
'/secret/api/(.*)', 'api',
|
'/secret/api/(.*)', 'api',
|
||||||
'/secret/(.*)', 'index'
|
'/secret/(.*)', 'index'
|
||||||
)
|
)
|
||||||
|
|
||||||
app = web.application(urls, globals())
|
app = web.application(urls, globals())
|
||||||
|
@ -18,144 +18,145 @@ app = web.application(urls, globals())
|
||||||
render = web.template.render('templates/')
|
render = web.template.render('templates/')
|
||||||
|
|
||||||
create = form.Form(
|
create = form.Form(
|
||||||
form.Textbox('base_url', description="domain"),
|
form.Textbox('base_url', description="domain"),
|
||||||
form.Textbox('username'),
|
form.Textbox('username'),
|
||||||
form.Password('password'),
|
form.Password('password'),
|
||||||
)
|
)
|
||||||
|
|
||||||
def mkpass(size=10):
|
def mkpass(size=10):
|
||||||
validChars = string.ascii_letters + string.digits
|
validChars = string.ascii_letters + string.digits
|
||||||
validChars = validChars.strip("oO01l")
|
validChars = validChars.strip("oO01l")
|
||||||
|
|
||||||
return string.join([random.choice(validChars) for x in range(size)],"")
|
return string.join([random.choice(validChars) for x in range(size)],"")
|
||||||
|
|
||||||
def get_pair_from_url(base_url):
|
def get_pair_from_url(base_url):
|
||||||
return db.select('passwords', where='base_url LIKE "%'+base_url+'%"', order='id DESC')
|
return db.select('passwords', where='base_url LIKE "%'+base_url+'%"', order='id DESC')
|
||||||
|
|
||||||
def get_generated_from_url(base_url):
|
def get_generated_from_url(base_url):
|
||||||
gen = db.select('generated', where='base_url LIKE "%'+base_url+'%"', order='id DESC')
|
gen = db.select('generated', where='base_url LIKE "%'+base_url+'%"', order='id DESC')
|
||||||
|
|
||||||
while not len(gen) > 0:
|
while not len(gen) > 0:
|
||||||
db.insert('generated', base_url = base_url, password = mkpass())
|
db.insert('generated', base_url = base_url, password = mkpass())
|
||||||
gen = db.select('generated', where='base_url LIKE "%'+base_url+'%"')
|
gen = db.select('generated', where='base_url LIKE "%'+base_url+'%"')
|
||||||
|
|
||||||
return gen
|
return gen
|
||||||
|
|
||||||
|
|
||||||
class index:
|
class index:
|
||||||
def GET(self, method):
|
def GET(self, method):
|
||||||
if method == 'get':
|
if method == 'get':
|
||||||
if web.input():
|
if web.input():
|
||||||
i = web.input()
|
i = web.input()
|
||||||
selected = get_pair_from_url(i.base_url)
|
selected = get_pair_from_url(i.base_url)
|
||||||
|
|
||||||
if len(selected) > 0:
|
if len(selected) > 0:
|
||||||
pairs = '<ul>'
|
pairs = '<ul>'
|
||||||
for p in selected:
|
for p in selected:
|
||||||
pairs += '<li>'+p.username+', '+p.password+'</li>'
|
pairs += '<li>'+p.username+', '+p.password+'</li>'
|
||||||
pairs += '</ul>'
|
pairs += '</ul>'
|
||||||
|
|
||||||
else:
|
else:
|
||||||
pairs = "<p>Sorry buddy, you're outta luck</p>"
|
pairs = "<p>Sorry buddy, you're outta luck</p>"
|
||||||
|
|
||||||
body = '<h1>'+i.base_url+'</h1>\n'+pairs
|
body = '<h1>'+i.base_url+'</h1>\n'+pairs
|
||||||
|
|
||||||
return render.page(i.base_url, body)
|
return render.page(i.base_url, body)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
return render.page('get','<p>need input.</p>')
|
return render.page('get','<p>need input.</p>')
|
||||||
|
|
||||||
if method == 'new':
|
if method == 'new':
|
||||||
|
|
||||||
i = web.input()
|
i = web.input()
|
||||||
|
|
||||||
f = create()
|
f = create()
|
||||||
|
|
||||||
body = []
|
body = []
|
||||||
|
|
||||||
body.append('<h1>'+i.base_url+'</h1>\n')
|
body.append('<h1>'+i.base_url+'</h1>\n')
|
||||||
|
|
||||||
selected = get_pair_from_url(i.base_url)
|
selected = get_pair_from_url(i.base_url)
|
||||||
generated = get_generated_from_url(i.base_url)
|
generated = get_generated_from_url(i.base_url)
|
||||||
|
|
||||||
if selected:
|
if selected:
|
||||||
body.append('<p>Existing: \n')
|
body.append('<h2>Existing:</h2>\n<ul>')
|
||||||
for pair in selected:
|
for pair in selected:
|
||||||
body.append('('+pair.username+', '+pair.password+')\n')
|
body.append('<li>'+pair.username+', '+pair.password+'</li>\n')
|
||||||
body.append('</p>')
|
body.append('</ul>')
|
||||||
|
|
||||||
body.append('<p>Generated: ' + generated[0].password + '</p>')
|
body.append('<h2>Generated:</h2>\n<p>' + generated[0].password + '</p>\n')
|
||||||
|
body.append('<h2>Create:</h2>\n')
|
||||||
|
|
||||||
body.append('<form class="form" method="get" action="/secret/create">\n'+ \
|
body.append('<form class="form" method="get" action="/secret/create">\n'+ \
|
||||||
f.render()+ '\n<input type="submit" name="submit" id="submit"/></form>')
|
f.render()+ '\n<input type="submit" name="submit" id="submit"/></form>')
|
||||||
|
|
||||||
return render.page('create',''.join(body))
|
return render.page('create',''.join(body))
|
||||||
|
|
||||||
|
|
||||||
if method == 'create':
|
if method == 'create':
|
||||||
i = web.input()
|
i = web.input()
|
||||||
|
|
||||||
exists = db.select('passwords', where='username="'+i.username+'" and password="' +\
|
exists = db.select('passwords', where='username="'+i.username+'" and password="' +\
|
||||||
i.password+'" and base_url="'+i.base_url+'"')
|
i.password+'" and base_url="'+i.base_url+'"')
|
||||||
|
|
||||||
if not exists:
|
if not exists:
|
||||||
n = db.insert('passwords', username=i.username, password=i.password, \
|
n = db.insert('passwords', username=i.username, password=i.password, \
|
||||||
base_url=i.base_url)
|
base_url=i.base_url)
|
||||||
|
|
||||||
selected = get_pair_from_url(i.base_url)
|
selected = get_pair_from_url(i.base_url)
|
||||||
|
|
||||||
body = ['<h1>'+i.base_url+'</h1>','']
|
body = ['<h1>'+i.base_url+'</h1>','']
|
||||||
|
|
||||||
for pair in selected:
|
for pair in selected:
|
||||||
body.append('('+pair.username+', '+pair.password+')')
|
body.append('('+pair.username+', '+pair.password+')')
|
||||||
|
|
||||||
return render.page('Created', ''.join(body))
|
return render.page('Created', ''.join(body))
|
||||||
|
|
||||||
|
|
||||||
if method == 'generate':
|
if method == 'generate':
|
||||||
i = web.input()
|
i = web.input()
|
||||||
|
|
||||||
body = '<h1>'+i.base_url+'</h1>\n<p> '+get_generated_from_url(i.base_url)[0].password+'</p>'
|
body = '<h1>'+i.base_url+'</h1>\n<p> '+get_generated_from_url(i.base_url)[0].password+'</p>'
|
||||||
|
|
||||||
return render.page('Generated', body)
|
return render.page('Generated', body)
|
||||||
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
return render.page('mySecrets', '<p>These are mySecrets. There is nothing for you here.</p>')
|
return render.page('mySecrets', '<p>These are mySecrets. There is nothing for you here.</p>')
|
||||||
|
|
||||||
class api:
|
class api:
|
||||||
def GET(self, method):
|
def GET(self, method):
|
||||||
if method == "list":
|
if method == "list":
|
||||||
tmp = ''
|
tmp = ''
|
||||||
for pair in db.select('passwords'):
|
for pair in db.select('passwords'):
|
||||||
tmp += pair['base_url']+','+pair['username']+','+pair['password']+'\n'
|
tmp += pair['base_url']+','+pair['username']+','+pair['password']+'\n'
|
||||||
|
|
||||||
return tmp
|
return tmp
|
||||||
|
|
||||||
if method == "get":
|
if method == "get":
|
||||||
i = web.input()
|
i = web.input()
|
||||||
base_url = i.base_url
|
base_url = i.base_url
|
||||||
pairs = db.select('passwords', where='`base_url`="'+base_url+'"')
|
pairs = db.select('passwords', where='`base_url`="'+base_url+'"')
|
||||||
|
|
||||||
tmp = ''
|
tmp = ''
|
||||||
for pair in pairs:
|
for pair in pairs:
|
||||||
tmp += pair.username+','+pair.password+'\n'
|
tmp += pair.username+','+pair.password+'\n'
|
||||||
|
|
||||||
return tmp
|
return tmp
|
||||||
|
|
||||||
else:
|
else:
|
||||||
return 'mySecrets API ' + method
|
return 'mySecrets API ' + method
|
||||||
|
|
||||||
def POST(self, method):
|
def POST(self, method):
|
||||||
i = web.input()
|
i = web.input()
|
||||||
n = db.insert('passwords', username=i.username, password=i.password, \
|
n = db.insert('passwords', username=i.username, password=i.password, \
|
||||||
base_url=i.base_url)
|
base_url=i.base_url)
|
||||||
|
|
||||||
body = '<h1>'+i.base_url+'</h1><p>'+i.username+', '+i.password+'</p>'
|
body = '<h1>'+i.base_url+'</h1><p>'+i.username+', '+i.password+'</p>'
|
||||||
|
|
||||||
return render.page('Created', body)
|
return render.page('Created', body)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
web.wsgi.runwsgi = lambda func, addr=None: web.wsgi.runfcgi(func, addr)
|
web.wsgi.runwsgi = lambda func, addr=None: web.wsgi.runfcgi(func, addr)
|
||||||
app.run()
|
app.run()
|
||||||
|
|
|
@ -3,8 +3,90 @@ $def with (title, body)
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title>$title</title>
|
<title>$title</title>
|
||||||
|
<meta name="viewport" content="width=320" />
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
$:body
|
<style type="text/css">
|
||||||
|
/* Eric Meyer CSS Reset */
|
||||||
|
html, body, div, span, applet, object, iframe,
|
||||||
|
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
|
||||||
|
a, abbr, acronym, address, big, cite, code,
|
||||||
|
del, dfn, em, img, ins, kbd, q, s, samp,
|
||||||
|
small, strike, strong, sub, sup, tt, var,
|
||||||
|
b, u, i, center,
|
||||||
|
dl, dt, dd, ol, ul, li,
|
||||||
|
fieldset, form, label, legend,
|
||||||
|
table, caption, tbody, tfoot, thead, tr, th, td,
|
||||||
|
article, aside, canvas, details, figcaption, figure,
|
||||||
|
footer, header, hgroup, menu, nav, section, summary,
|
||||||
|
time, mark, audio, video {
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
border: 0;
|
||||||
|
outline: 0;
|
||||||
|
font-size: 100%;
|
||||||
|
font: inherit;
|
||||||
|
vertical-align: baseline;
|
||||||
|
}
|
||||||
|
/* HTML5 display-role reset for older browsers */
|
||||||
|
article, aside, details, figcaption, figure,
|
||||||
|
footer, header, hgroup, menu, nav, section {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
body {
|
||||||
|
line-height: 1;
|
||||||
|
}
|
||||||
|
ol, ul {
|
||||||
|
list-style: none;
|
||||||
|
}
|
||||||
|
blockquote, q {
|
||||||
|
quotes: none;
|
||||||
|
}
|
||||||
|
blockquote:before, blockquote:after,
|
||||||
|
q:before, q:after {
|
||||||
|
content: '';
|
||||||
|
content: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
del {
|
||||||
|
text-decoration: line-through;
|
||||||
|
}
|
||||||
|
|
||||||
|
table {
|
||||||
|
border-collapse: collapse;
|
||||||
|
border-spacing: 0;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<style type="text/css">
|
||||||
|
/* internal styling, must be after reset */
|
||||||
|
body {
|
||||||
|
font-family: Georgia;
|
||||||
|
padding: 20px;
|
||||||
|
}
|
||||||
|
h1 {
|
||||||
|
font-size: 1.3em;
|
||||||
|
font-weight: bold;
|
||||||
|
text-align: center;
|
||||||
|
padding-bottom: 20px;
|
||||||
|
padding-top: 10px;
|
||||||
|
}
|
||||||
|
h2 {
|
||||||
|
font-size: 1.1em;
|
||||||
|
font-weight: bold;
|
||||||
|
padding-bottom:5px;
|
||||||
|
padding-top:5px;
|
||||||
|
}
|
||||||
|
p {
|
||||||
|
padding-bottom: 5px;
|
||||||
|
}
|
||||||
|
form {
|
||||||
|
text-align: center;
|
||||||
|
padding: 10px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
$:body
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
Reference in a new issue