initial commit
This commit is contained in:
commit
6ee1eb2603
1 changed files with 59 additions and 0 deletions
59
mysecrets.py
Executable file
59
mysecrets.py
Executable file
|
@ -0,0 +1,59 @@
|
||||||
|
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()
|
Reference in a new issue