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'),
|
||||
)
|
||||
|
||||
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):
|
||||
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"]
|
||||
|
@ -35,12 +50,9 @@ def get_domain(base_url):
|
|||
|
||||
for i in range(-len(urlElements),0):
|
||||
lastIElements = urlElements[i:]
|
||||
# i=-3: ["abcde","co","uk"]
|
||||
# i=-2: ["co","uk"]
|
||||
# i=-1: ["uk"] etc
|
||||
|
||||
candidate = ".".join(lastIElements) # abcde.co.uk, co.uk, uk
|
||||
wildcardCandidate = ".".join(["*"]+lastIElements[1:]) # *.co.uk, *.uk, *
|
||||
|
||||
candidate = ".".join(lastIElements)
|
||||
wildcardCandidate = ".".join(["*"]+lastIElements[1:])
|
||||
exceptionCandidate = "!"+candidate
|
||||
|
||||
if (exceptionCandidate in tlds):
|
||||
|
@ -49,7 +61,6 @@ def get_domain(base_url):
|
|||
return ".".join(urlElements[i-1:])
|
||||
|
||||
return base_url
|
||||
|
||||
|
||||
def mkpass(size=10):
|
||||
validChars = string.ascii_letters + string.digits
|
||||
|
@ -73,6 +84,20 @@ def get_generated_from_url(domain):
|
|||
class index:
|
||||
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':
|
||||
|
||||
i = web.input()
|
||||
|
@ -91,7 +116,9 @@ class index:
|
|||
if selected:
|
||||
body.append('<h2>Existing:</h2>\n<ul>')
|
||||
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('<h2>Suggested:</h2>\n<p>' + generated[0].password + '</p>\n')
|
||||
|
|
|
@ -29,7 +29,6 @@ $def with (title, body)
|
|||
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;
|
||||
|
@ -60,7 +59,6 @@ $def with (title, body)
|
|||
</style>
|
||||
|
||||
<style type="text/css">
|
||||
/* internal styling, must be after reset */
|
||||
body {
|
||||
font-family: Georgia;
|
||||
padding: 20px;
|
||||
|
@ -81,6 +79,11 @@ $def with (title, body)
|
|||
p {
|
||||
padding-bottom: 5px;
|
||||
}
|
||||
a.del {
|
||||
font-size: .5em;
|
||||
color: #F00;
|
||||
text-decoration: none;
|
||||
}
|
||||
form {
|
||||
text-align: center;
|
||||
padding: 10px;
|
||||
|
|
Reference in a new issue