This repository has been archived on 2023-01-03. You can view files and clone it, but cannot push or open issues or pull requests.
mysecrets/mysecrets.py
2012-02-27 18:27:50 -08:00

59 lines
1.2 KiB
Python
Executable file

import web
db = web.database(dbn='mysql', user='mysecrets', pw='horsebatteries',
db='mysecrets')
urls = (
'/secret/', 'index',
'/secret/api/(.*)', 'api'
)
app = web.application(urls, globals())
class index:
def GET(self):
return '''\
<html>
<head>
<title>mySecrets</title>
</head>
<body>
These are mySecrets. There is nothing for you here.
</body>
</html>'''
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:
tmp += pair.username+','+pair.password+'\n'
return tmp
else:
return 'mySecrets API ' + method
def POST(self, method):
if method == "create":
i = web.input()
n = db.insert('passwords', username=i.username, password=i.password, \
base_url=i.base_url)
return 'Created.'
else:
return 'No method.'
if __name__ == "__main__":
app.run()