adding link to del code and cleaning up some comments
This commit is contained in:
parent
34fc3a1193
commit
9679d119f5
2 changed files with 40 additions and 10 deletions
43
mysecrets.py
43
mysecrets.py
|
@ -27,6 +27,21 @@ create = form.Form(
|
||||||
form.Password('password'),
|
form.Password('password'),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def trash(id):
|
||||||
|
if db.select('passwords', where='id = "'+id+'"'):
|
||||||
|
|
||||||
|
if not db.select('trash', where='id = "'+id+'"'):
|
||||||
|
db.query('INSERT INTO trash SELECT * FROM passwords WHERE id = "'+id+'"')
|
||||||
|
|
||||||
|
orig = db.select('passwords', where='id = "'+id+'"')[0]
|
||||||
|
new = db.select('trash', where='id = "'+id+'"')[0]
|
||||||
|
|
||||||
|
if orig == new:
|
||||||
|
db.delete('passwords', where='id = "'+id+'"')
|
||||||
|
return True;
|
||||||
|
|
||||||
|
return False;
|
||||||
|
|
||||||
def get_domain(base_url):
|
def get_domain(base_url):
|
||||||
with closing(urlopen('https://mxr.mozilla.org/mozilla/source/netwerk/dns/src/effective_tld_names.dat?raw=1')) as tldFile:
|
with closing(urlopen('https://mxr.mozilla.org/mozilla/source/netwerk/dns/src/effective_tld_names.dat?raw=1')) as tldFile:
|
||||||
tlds = [line.strip() for line in tldFile if line[0] not in "/\n"]
|
tlds = [line.strip() for line in tldFile if line[0] not in "/\n"]
|
||||||
|
@ -35,12 +50,9 @@ def get_domain(base_url):
|
||||||
|
|
||||||
for i in range(-len(urlElements),0):
|
for i in range(-len(urlElements),0):
|
||||||
lastIElements = urlElements[i:]
|
lastIElements = urlElements[i:]
|
||||||
# i=-3: ["abcde","co","uk"]
|
|
||||||
# i=-2: ["co","uk"]
|
candidate = ".".join(lastIElements)
|
||||||
# i=-1: ["uk"] etc
|
wildcardCandidate = ".".join(["*"]+lastIElements[1:])
|
||||||
|
|
||||||
candidate = ".".join(lastIElements) # abcde.co.uk, co.uk, uk
|
|
||||||
wildcardCandidate = ".".join(["*"]+lastIElements[1:]) # *.co.uk, *.uk, *
|
|
||||||
exceptionCandidate = "!"+candidate
|
exceptionCandidate = "!"+candidate
|
||||||
|
|
||||||
if (exceptionCandidate in tlds):
|
if (exceptionCandidate in tlds):
|
||||||
|
@ -49,7 +61,6 @@ def get_domain(base_url):
|
||||||
return ".".join(urlElements[i-1:])
|
return ".".join(urlElements[i-1:])
|
||||||
|
|
||||||
return base_url
|
return base_url
|
||||||
|
|
||||||
|
|
||||||
def mkpass(size=10):
|
def mkpass(size=10):
|
||||||
validChars = string.ascii_letters + string.digits
|
validChars = string.ascii_letters + string.digits
|
||||||
|
@ -73,6 +84,20 @@ def get_generated_from_url(domain):
|
||||||
class index:
|
class index:
|
||||||
def GET(self, method):
|
def GET(self, method):
|
||||||
|
|
||||||
|
if method == 'del':
|
||||||
|
i = web.input()
|
||||||
|
|
||||||
|
result = trash(i.id)
|
||||||
|
|
||||||
|
if result:
|
||||||
|
body = "id: " + i.id + " deleted."
|
||||||
|
|
||||||
|
if not result:
|
||||||
|
body = "id: " + i.id + " not deleted."
|
||||||
|
|
||||||
|
return render.page('Deleted ' + i.id, body)
|
||||||
|
|
||||||
|
|
||||||
if method == 'new':
|
if method == 'new':
|
||||||
|
|
||||||
i = web.input()
|
i = web.input()
|
||||||
|
@ -91,7 +116,9 @@ class index:
|
||||||
if selected:
|
if selected:
|
||||||
body.append('<h2>Existing:</h2>\n<ul>')
|
body.append('<h2>Existing:</h2>\n<ul>')
|
||||||
for pair in selected:
|
for pair in selected:
|
||||||
body.append('<li class="pair">'+pair.username+' '+pair.password+'</li>\n')
|
body.append('<li class="pair">'+pair.username+' '+pair.password+
|
||||||
|
' <span style="vertical-align:middle;display:inline-block;"><a class="del" \
|
||||||
|
href="/secret/del?id='+str(pair.id)+'">(x)</a></span></li>\n')
|
||||||
body.append('</ul>')
|
body.append('</ul>')
|
||||||
|
|
||||||
body.append('<h2>Suggested:</h2>\n<p>' + generated[0].password + '</p>\n')
|
body.append('<h2>Suggested:</h2>\n<p>' + generated[0].password + '</p>\n')
|
||||||
|
|
|
@ -29,7 +29,6 @@ $def with (title, body)
|
||||||
font: inherit;
|
font: inherit;
|
||||||
vertical-align: baseline;
|
vertical-align: baseline;
|
||||||
}
|
}
|
||||||
/* HTML5 display-role reset for older browsers */
|
|
||||||
article, aside, details, figcaption, figure,
|
article, aside, details, figcaption, figure,
|
||||||
footer, header, hgroup, menu, nav, section {
|
footer, header, hgroup, menu, nav, section {
|
||||||
display: block;
|
display: block;
|
||||||
|
@ -60,7 +59,6 @@ $def with (title, body)
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style type="text/css">
|
<style type="text/css">
|
||||||
/* internal styling, must be after reset */
|
|
||||||
body {
|
body {
|
||||||
font-family: Georgia;
|
font-family: Georgia;
|
||||||
padding: 20px;
|
padding: 20px;
|
||||||
|
@ -81,6 +79,11 @@ $def with (title, body)
|
||||||
p {
|
p {
|
||||||
padding-bottom: 5px;
|
padding-bottom: 5px;
|
||||||
}
|
}
|
||||||
|
a.del {
|
||||||
|
font-size: .5em;
|
||||||
|
color: #F00;
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
form {
|
form {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
padding: 10px;
|
padding: 10px;
|
||||||
|
|
Reference in a new issue