Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
MarrekNozka committed Feb 28, 2014
1 parent e7309da commit e7b8f77
Show file tree
Hide file tree
Showing 7 changed files with 264 additions and 0 deletions.
9 changes: 9 additions & 0 deletions app.wsgi
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Change working directory so relative paths (and template lookup) work again
import os
os.chdir(os.path.dirname(__file__))

print __file__

import bottle
import webpwgen
application = bottle.default_app()
6 changes: 6 additions & 0 deletions dev_server.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
# File: dev_server.sh
# Task: Bottle framework develompent wrapper
############################################################

python -m bottle --bind=localhost:8899 --debug --reload webpwgen
Binary file added look/favico.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
56 changes: 56 additions & 0 deletions look/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
@media -sass-debug-info{filename{font-family:file\:\/\/\/home\/marek\/Programming\/webpwgen\/styles\.scss}line{font-family:\000031}}
body {
background-color: #688EA1; }

@media -sass-debug-info{filename{font-family:file\:\/\/\/home\/marek\/Programming\/webpwgen\/styles\.scss}line{font-family:\000035}}
#all {
margin-left: 10%;
margin-right: 4%;
background-color: white; }

@media -sass-debug-info{filename{font-family:file\:\/\/\/home\/marek\/Programming\/webpwgen\/styles\.scss}line{font-family:\0000311}}
#head, #foot {
position: relative;
background: #5E905D;
color: white;
padding: 1em 1em 0.5ex 1em; }
@media -sass-debug-info{filename{font-family:file\:\/\/\/home\/marek\/Programming\/webpwgen\/styles\.scss}line{font-family:\0000317}}
#head a, #foot a {
color: white; }

@media -sass-debug-info{filename{font-family:file\:\/\/\/home\/marek\/Programming\/webpwgen\/styles\.scss}line{font-family:\0000322}}
#body {
position: relative; }

@media -sass-debug-info{filename{font-family:file\:\/\/\/home\/marek\/Programming\/webpwgen\/styles\.scss}line{font-family:\0000330}}
#body {
padding-left: 1em;
padding-right: 1em; }

@media -sass-debug-info{filename{font-family:file\:\/\/\/home\/marek\/Programming\/webpwgen\/styles\.scss}line{font-family:\0000335}}
.sideL {
width: 59%; }

@media -sass-debug-info{filename{font-family:file\:\/\/\/home\/marek\/Programming\/webpwgen\/styles\.scss}line{font-family:\0000338}}
.sideR {
width: 37%;
position: relative;
top: -3ex;
left: 64%;
text-align: right;
background-color: #DD5756;
color: white; }
@media -sass-debug-info{filename{font-family:file\:\/\/\/home\/marek\/Programming\/webpwgen\/styles\.scss}line{font-family:\0000347}}
.sideR span.sideR {
width: 100%;
position: absolute;
left: 0px;
padding: 1ex; }

@media -sass-debug-info{filename{font-family:file\:\/\/\/home\/marek\/Programming\/webpwgen\/styles\.scss}line{font-family:\0000355}}
.pswd {
font-family: monospace;
font-size: 130%;
padding-left: 20px;
padding-right: 20px;
max-width: 80ex; }
62 changes: 62 additions & 0 deletions styles.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
body {
background-color: #688EA1;
}

#all {
margin-left: 10%;
margin-right: 4%;
background-color: white;
}

#head {
position: relative;
background: #5E905D;
color: white;
padding: 1em 1em 0.5ex 1em;

a {
color: white;
}
}

#body {
position: relative;
}

#foot {
@extend #head;
}

#body {
padding-left: 1em;
padding-right: 1em;
}

.sideL {
width: 59%;
}
.sideR {
width: 37%;
position: relative;
top: -3ex;
left: 64%;
text-align: right;
background-color: #DD5756;
color: white;

span.sideR {
width: 100%;
position: absolute;
left: 0px;
padding: 1ex;
}
}

.pswd {
font-family: monospace ;
font-size: 130%;
padding-left: 20px;
padding-right: 20px;
max-width: 80ex;
}

47 changes: 47 additions & 0 deletions views/base.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http:https://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http:https://www.w3.org/1999/xhtml">
<head>
<meta name="keywords" content="pwgen, password generátor, zapamatovatelné heslo"/>
<link href="look/styles.css" rel="stylesheet" type="text/css" />
<link href="look/favico.png" rel="shortcut icon" type="image/png" />
<title>webPWgen</title>
</head>

<body>
<div id="all">
<div id="head">
<h1 class="sideL"><a href="/.">webPWgen</a></h1>
<p class=sideR><span class="sideR">
<a href="/cs/">Čeština</a>
<a href="/en/">English</a> </span>
</p>
</div>

<div id="body">
<h1>Zapamatovatelné heslo?</h1>
<form method="get">
<p> Jak dlouhé má heslo být? (číslo v rozmezí 5 až 40)<br />
<input name="length" type="text" /><input value="Generuj" type="submit" />
</p>
</form>
<h2 class="sideL">Vyber si a zapamatuj si</h2>
<p class="sideR"><span class="sideR">... nebo se jen inspiruj.</span></p>
<p>Délka hesel je {{length}}:</p>
<p class="pswd"><kbd>
{{passwords}}
</kbd></p>
</div>

<div id="foot">
<p>Powered by:
<a href="http:https://python.org">Python</a>,
<a href="http:https://bottlepy.org">Bottle</a>,
<a href="http:https://debian.org">Debian GNU/Linux</a>,
<a href="http:https://sourceforge.net/projects/pwgen/">PWgen</a>.
</p>
</div>
</div>

</body>
</html>
84 changes: 84 additions & 0 deletions webpwgen.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# -*- coding: utf8 -*-
# Soubor: main.py
# Datum: 22.02.2014 11:20
# Autor: Marek Nožka, marek <@t> tlapicka <d.t> cz
# Licence: GNU/GPL
# Úloha: web interface
############################################################################


from bottle import route, request, redirect, response, template, error, static_file
import subprocess
############################################################################

@route('/look/<filepath:path>')
def server_static(filepath):
return static_file(filepath, root='./look')

@route('/')
def pwgen():
length=request.query.length
try :
length=int(length)
length= 8 if length<5 or length>40 else length
except :
length=8
pswd= subprocess.check_output(['pwgen','-Ccn',str(length), ])
return template('base',passwords=pswd, length=length)


############################################################################

@error(404)
def notFound(error):
r='<h1>'+error.status+'</h1>'
r+='<p>Sorry. Tady nic není</p><hr />'
r+='<p>'+error.body+'</p>'
return r


############################################################################
def accept_languages(browser_pref_langs):
"""Parses the request and return language list.
browser_pref_langs is the plain Accept-Language http request header
value.
Stolen from Products.PloneLanguageTool, under GPL (c) Plone Foundation,
slightly modified.
Taken from tweetengine http:https://github.com/Arachnid/tweetengine/
"""
browser_pref_langs = browser_pref_langs.split(',')
i = 0
langs = []
length = len(browser_pref_langs)
# Parse quality strings and build a tuple like
# ((float(quality), lang), (float(quality), lang))
# which is sorted afterwards
# If no quality string is given then the list order
# is used as quality indicator
for lang in browser_pref_langs:
lang = lang.strip().lower().replace('_', '-')
if lang:
l = lang.split(';', 2)
quality = []
if len(l) == 2:
try:
q = l[1]
if q.startswith('q='):
q = q.split('=', 2)[1]
quality = float(q)
except:
pass
if quality == []:
quality = float(length-i)
language = l[0]
langs.append((quality, language))
if '-' in language:
baselanguage = language.split('-')[0]
langs.append((quality-0.001, baselanguage))
i = i + 1
# Sort and reverse it
langs.sort()
langs.reverse()
# Filter quality string
langs = map(lambda x: x[1], langs)
return langs

0 comments on commit e7b8f77

Please sign in to comment.