Skip to content

Commit

Permalink
404
Browse files Browse the repository at this point in the history
  • Loading branch information
MarrekNozka committed May 12, 2014
1 parent 8c2189d commit 8ba34d4
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 33 deletions.
1 change: 1 addition & 0 deletions app.cgi
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ sys.path.insert(0, '.')

import webpwgen
webpwgen.run(server='cgi')

Binary file added look/Cartoon_monkey_wrench.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
59 changes: 59 additions & 0 deletions views/404.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http:https://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
%root = getURL('/')
<html xmlns="http:https://www.w3.org/1999/xhtml">
<head>
<meta name="keywords" content="pwgen, password generátor, zapamatovatelné heslo"/>
<link href="{{root}}look/styles.css" rel="stylesheet" type="text/css" />
<link href="{{root}}look/favico.png" rel="shortcut icon" type="image/png" />
<title>webPWgen</title>
</head>

<style type="text/css">
body {
color: white;
}
h1 {
/*color: #dd5756;*/
background-color: #5E905D;
padding: 1em 1em 0.5ex;
}
.right {
float: right;
}
.chyba {
font-size:150%;
background-color: #5E905D;
margin-right: 420px;
padding: 1ex;
}
.body {
margin: 1ex;
padding: 1ex;
color: black;
background-color: white;
font-size:150%;
}
</style>

<body>

<h1>{{status}}</h1>


<p class="body"><code>{{body}}</code></p>

<p class="right">
<img src="/look/Cartoon_monkey_wrench.png" alt="" width="400" height="328" />
</p>

<p class="chyba">
Pardon, ale tuto adresu neumím zpracovat.
</p>

</body>
</html>
65 changes: 32 additions & 33 deletions webpwgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
# 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
# Licence: GNU/GPL
# Úloha: web interface
############################################################################


from bottle import run, route, request, redirect, response, \
template, view, error, \
static_file, default_app, BaseTemplate
template, view, error, \
static_file, default_app, BaseTemplate
import subprocess
############################################################################

app=default_app()
app = default_app()
BaseTemplate.defaults['getURL'] = app.get_url
getURL = app.get_url

Expand All @@ -22,26 +22,28 @@
def server_static(filepath):
return static_file(filepath, root='./look')


@route('/')
@route('/<length:int>')
@route('/<length:int>/')
def choselang(length=8):
if request.get_cookie("lang"):
lang = request.get_cookie("lang")
else:
languages=acceptLanguages( request.headers['Accept-Language'] )
languages = acceptLanguages(request.headers['Accept-Language'])
languages.reverse()
try:
cs=languages.index('cs')
try:
cs = languages.index('cs')
except:
cs=-1
try:
en=languages.index('en')
cs = -1
try:
en = languages.index('en')
except:
en=-1
lang='cs' if cs>en else 'en'
en = -1
lang = 'cs' if cs > en else 'en'
redirect(getURL('/')+lang+'/'+str(length))


@route('/<lang:re:cs|en>')
@route('/<lang:re:cs|en>/')
def golang(lang):
Expand All @@ -50,37 +52,34 @@ def golang(lang):

@route('/<lang:re:cs|en>/<length:int>')
@route('/<lang:re:cs|en>/<length:int>/')
def pwgen(lang,length):
def pwgen(lang, length):
response.set_cookie("lang", lang, path=getURL('/'))
if request.query.length:
length=request.query.length
try :
length=int(length)
length= 8 if length<5 or length>40 else length
except :
length=8
if request.query.length:
if request.query.length:
length = request.query.length
try:
length = int(length)
length = 8 if length < 5 or length > 40 else length
except:
length = 8
if request.query.length:
redirect(getURL('/')+lang+'/'+str(length))
pswd= subprocess.check_output(['pwgen','-Ccn',str(length), ])
return template('base',passwords=pswd, length=length, lang=lang)
pswd = subprocess.check_output(['pwgen', '-Ccn', str(length), ])
return template('base', passwords=pswd, length=length, lang=lang)

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


############################################################################
@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

return template('404', status=error.status, body=error.body)


############################################################################
### https://gist.github.com/filippo/1106488

def acceptLanguages(browser_pref_langs):
"""Parses the request and return language list.
browser_pref_langs is the plain Accept-Language http request header
"""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.
Expand Down Expand Up @@ -110,7 +109,7 @@ def acceptLanguages(browser_pref_langs):
pass
if quality == []:
quality = float(length-i)
language = l[0]
language = l[0]
langs.append((quality, language))
if '-' in language:
baselanguage = language.split('-')[0]
Expand Down

0 comments on commit 8ba34d4

Please sign in to comment.