60 lines
1.2 KiB
Python
60 lines
1.2 KiB
Python
|
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()
|