fixed pep8 in apps
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
EXPIRATION = 60 * 60 # logout after 60 minutes of inactivity
|
||||
CHECK_VERSION = True
|
||||
WEB2PY_URL = 'http://web2py.com'
|
||||
WEB2PY_VERSION_URL = WEB2PY_URL+'/examples/default/version'
|
||||
WEB2PY_VERSION_URL = WEB2PY_URL + '/examples/default/version'
|
||||
|
||||
###########################################################################
|
||||
# Preferences for EditArea
|
||||
@@ -21,7 +21,7 @@ TEXT_EDITOR_THEME = (
|
||||
"tomorrow_night_eighties", "twilight", "vibrant_ink")[0]
|
||||
|
||||
## Editor Keyboard bindings (only for ace and codemirror)
|
||||
TEXT_EDITOR_KEYBINDING = '' # 'emacs' or 'vi'
|
||||
TEXT_EDITOR_KEYBINDING = '' # 'emacs' or 'vi'
|
||||
|
||||
### edit_area only
|
||||
# The default font size, measured in 'points'. The value must be an integer > 0
|
||||
@@ -59,9 +59,9 @@ GAE_APPCFG = os.path.abspath(os.path.join('/usr/local/bin/appcfg.py'))
|
||||
|
||||
# To use web2py as a teaching tool, set MULTI_USER_MODE to True
|
||||
MULTI_USER_MODE = False
|
||||
EMAIL_SERVER = 'localhost'
|
||||
EMAIL_SENDER = 'professor@example.com'
|
||||
EMAIL_LOGIN = None
|
||||
EMAIL_SERVER = 'localhost'
|
||||
EMAIL_SENDER = 'professor@example.com'
|
||||
EMAIL_LOGIN = None
|
||||
|
||||
# configurable twitterbox, set to None/False to suppress
|
||||
TWITTER_HASH = "web2py"
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import base64, os, time
|
||||
import base64
|
||||
import os
|
||||
import time
|
||||
from gluon import portalocker
|
||||
from gluon.admin import apath
|
||||
from gluon.fileutils import read_file
|
||||
@@ -24,7 +26,8 @@ elif not request.is_local and not DEMO_MODE:
|
||||
try:
|
||||
_config = {}
|
||||
port = int(request.env.server_port or 0)
|
||||
restricted(read_file(apath('../parameters_%i.py' % port, request)), _config)
|
||||
restricted(
|
||||
read_file(apath('../parameters_%i.py' % port, request)), _config)
|
||||
|
||||
if not 'password' in _config or not _config['password']:
|
||||
raise HTTP(200, T('admin disabled because no admin password'))
|
||||
@@ -38,7 +41,8 @@ except IOError:
|
||||
raise HTTP(200,
|
||||
T('admin disabled because not supported on google app engine'))
|
||||
else:
|
||||
raise HTTP(200, T('admin disabled because unable to access password file'))
|
||||
raise HTTP(
|
||||
200, T('admin disabled because unable to access password file'))
|
||||
|
||||
|
||||
def verify_password(password):
|
||||
@@ -50,7 +54,7 @@ def verify_password(password):
|
||||
elif _config['password'].startswith('pam_user:'):
|
||||
session.pam_user = _config['password'][9:].strip()
|
||||
import gluon.contrib.pam
|
||||
return gluon.contrib.pam.authenticate(session.pam_user,password)
|
||||
return gluon.contrib.pam.authenticate(session.pam_user, password)
|
||||
else:
|
||||
return _config['password'] == CRYPT()(password)[0]
|
||||
|
||||
@@ -63,6 +67,7 @@ deny_file = os.path.join(request.folder, 'private', 'hosts.deny')
|
||||
allowed_number_of_attempts = 5
|
||||
expiration_failed_logins = 3600
|
||||
|
||||
|
||||
def read_hosts_deny():
|
||||
import datetime
|
||||
hosts = {}
|
||||
@@ -75,7 +80,7 @@ def read_hosts_deny():
|
||||
continue
|
||||
fields = line.strip().split()
|
||||
if len(fields) > 2:
|
||||
hosts[fields[0].strip()] = ( # ip
|
||||
hosts[fields[0].strip()] = ( # ip
|
||||
int(fields[1].strip()), # n attemps
|
||||
int(fields[2].strip()) # last attempts
|
||||
)
|
||||
@@ -83,28 +88,30 @@ def read_hosts_deny():
|
||||
f.close()
|
||||
return hosts
|
||||
|
||||
|
||||
def write_hosts_deny(denied_hosts):
|
||||
f = open(deny_file, 'w')
|
||||
portalocker.lock(f, portalocker.LOCK_EX)
|
||||
for key, val in denied_hosts.items():
|
||||
if time.time()-val[1] < expiration_failed_logins:
|
||||
if time.time() - val[1] < expiration_failed_logins:
|
||||
line = '%s %s %s\n' % (key, val[0], val[1])
|
||||
f.write(line)
|
||||
portalocker.unlock(f)
|
||||
f.close()
|
||||
|
||||
|
||||
def login_record(success=True):
|
||||
denied_hosts = read_hosts_deny()
|
||||
val = (0,0)
|
||||
val = (0, 0)
|
||||
if success and request.client in denied_hosts:
|
||||
del denied_hosts[request.client]
|
||||
elif not success and not request.is_local:
|
||||
val = denied_hosts.get(request.client,(0,0))
|
||||
if time.time()-val[1]<expiration_failed_logins \
|
||||
val = denied_hosts.get(request.client, (0, 0))
|
||||
if time.time() - val[1] < expiration_failed_logins \
|
||||
and val[0] >= allowed_number_of_attempts:
|
||||
return val[0] # locked out
|
||||
time.sleep(2**val[0])
|
||||
val = (val[0]+1,int(time.time()))
|
||||
return val[0] # locked out
|
||||
time.sleep(2 ** val[0])
|
||||
val = (val[0] + 1, int(time.time()))
|
||||
denied_hosts[request.client] = val
|
||||
write_hosts_deny(denied_hosts)
|
||||
return val[0]
|
||||
@@ -124,9 +131,9 @@ if session.authorized:
|
||||
session.last_time = t0
|
||||
|
||||
|
||||
if request.vars.is_mobile in ('true','false','auto'):
|
||||
if request.vars.is_mobile in ('true', 'false', 'auto'):
|
||||
session.is_mobile = request.vars.is_mobile or 'auto'
|
||||
if request.controller=='default' and request.function=='index':
|
||||
if request.controller == 'default' and request.function == 'index':
|
||||
if not request.vars.is_mobile:
|
||||
session.is_mobile = 'auto'
|
||||
if not session.is_mobile:
|
||||
@@ -141,14 +148,14 @@ else:
|
||||
if request.controller == "webservices":
|
||||
basic = request.env.http_authorization
|
||||
if not basic or not basic[:6].lower() == 'basic ':
|
||||
raise HTTP(401,"Wrong credentials")
|
||||
raise HTTP(401, "Wrong credentials")
|
||||
(username, password) = base64.b64decode(basic[6:]).split(':')
|
||||
if not verify_password(password) or MULTI_USER_MODE:
|
||||
time.sleep(10)
|
||||
raise HTTP(403,"Not authorized")
|
||||
raise HTTP(403, "Not authorized")
|
||||
elif not session.authorized and not \
|
||||
(request.controller+'/'+request.function in
|
||||
('default/index','default/user','plugin_jqmobile/index','plugin_jqmobile/about')):
|
||||
(request.controller + '/' + request.function in
|
||||
('default/index', 'default/user', 'plugin_jqmobile/index', 'plugin_jqmobile/about')):
|
||||
|
||||
if request.env.query_string:
|
||||
query_string = '?' + request.env.query_string
|
||||
@@ -165,6 +172,6 @@ elif session.authorized and \
|
||||
request.function == 'index':
|
||||
redirect(URL(request.application, 'default', 'site'))
|
||||
|
||||
if request.controller=='appadmin' and DEMO_MODE:
|
||||
if request.controller == 'appadmin' and DEMO_MODE:
|
||||
session.flash = 'Appadmin disabled in demo mode'
|
||||
redirect(URL('default','sites'))
|
||||
redirect(URL('default', 'sites'))
|
||||
|
||||
@@ -2,35 +2,41 @@
|
||||
|
||||
import os
|
||||
|
||||
def A_button(*a,**b):
|
||||
|
||||
def A_button(*a, **b):
|
||||
b['_data-role'] = 'button'
|
||||
b['_data-inline'] = 'true'
|
||||
return A(*a,**b)
|
||||
return A(*a, **b)
|
||||
|
||||
|
||||
def button(href, label):
|
||||
if is_mobile:
|
||||
ret = A_button(SPAN(label), _href=href)
|
||||
else:
|
||||
ret = A(SPAN(label),_class='button',_href=href)
|
||||
ret = A(SPAN(label), _class='button', _href=href)
|
||||
return ret
|
||||
|
||||
|
||||
def button_enable(href, app):
|
||||
if os.path.exists(os.path.join(apath(app,r=request),'DISABLED')):
|
||||
label = SPAN(T('Enable'),_style='color:red')
|
||||
if os.path.exists(os.path.join(apath(app, r=request), 'DISABLED')):
|
||||
label = SPAN(T('Enable'), _style='color:red')
|
||||
else:
|
||||
label = SPAN(T('Disable'),_style='color:green')
|
||||
id = 'enable_'+app
|
||||
return A(label,_class='button',_id=id,callback=href,target=id)
|
||||
label = SPAN(T('Disable'), _style='color:green')
|
||||
id = 'enable_' + app
|
||||
return A(label, _class='button', _id=id, callback=href, target=id)
|
||||
|
||||
|
||||
def sp_button(href, label):
|
||||
if request.user_agent().is_mobile:
|
||||
ret = A_button(SPAN(label), _href=href)
|
||||
else:
|
||||
ret = A(SPAN(label),_class='button special',_href=href)
|
||||
ret = A(SPAN(label), _class='button special', _href=href)
|
||||
return ret
|
||||
|
||||
|
||||
def helpicon():
|
||||
return IMG(_src=URL('static', 'images/help.png'), _alt='help')
|
||||
|
||||
|
||||
def searchbox(elementid):
|
||||
return TAG[''](LABEL(IMG(_id="search_start",_src=URL('static', 'images/search.png'), _alt=T('filter')), _class='icon', _for=elementid), ' ', INPUT(_id=elementid, _type='text', _size=12))
|
||||
return TAG[''](LABEL(IMG(_id="search_start", _src=URL('static', 'images/search.png'), _alt=T('filter')), _class='icon', _for=elementid), ' ', INPUT(_id=elementid, _type='text', _size=12))
|
||||
|
||||
@@ -4,35 +4,39 @@
|
||||
if MULTI_USER_MODE:
|
||||
db = DAL('sqlite://storage.sqlite') # if not, use SQLite or other DB
|
||||
from gluon.tools import *
|
||||
auth = Auth(globals(),db) # authentication/authorization
|
||||
crud = Crud(globals(),db) # for CRUD helpers using auth
|
||||
service = Service(globals()) # for json, xml, jsonrpc, xmlrpc, amfrpc
|
||||
auth = Auth(
|
||||
globals(), db) # authentication/authorization
|
||||
crud = Crud(
|
||||
globals(), db) # for CRUD helpers using auth
|
||||
service = Service(
|
||||
globals()) # for json, xml, jsonrpc, xmlrpc, amfrpc
|
||||
plugins = PluginManager()
|
||||
|
||||
mail = auth.settings.mailer
|
||||
mail.settings.server = EMAIL_SERVER
|
||||
mail.settings.sender = EMAIL_SENDER
|
||||
mail.settings.login = EMAIL_LOGIN
|
||||
mail.settings.login = EMAIL_LOGIN
|
||||
|
||||
auth.settings.extra_fields['auth_user'] = \
|
||||
[Field('is_manager','boolean',default=False,writable=False)]
|
||||
[Field('is_manager', 'boolean', default=False, writable=False)]
|
||||
auth.define_tables() # creates all needed tables
|
||||
auth.settings.registration_requires_verification = False
|
||||
auth.settings.registration_requires_approval = True
|
||||
auth.settings.reset_password_requires_verification = True
|
||||
|
||||
db.define_table('app',Field('name'),Field('owner',db.auth_user))
|
||||
db.define_table('app', Field('name'), Field('owner', db.auth_user))
|
||||
|
||||
if not session.authorized and MULTI_USER_MODE:
|
||||
if auth.user and not request.function=='user':
|
||||
if auth.user and not request.function == 'user':
|
||||
session.authorized = True
|
||||
elif not request.function=='user':
|
||||
redirect(URL('default','user/login'))
|
||||
elif not request.function == 'user':
|
||||
redirect(URL('default', 'user/login'))
|
||||
|
||||
|
||||
def is_manager():
|
||||
if not MULTI_USER_MODE:
|
||||
return True
|
||||
elif auth.user and (auth.user.id==1 or auth.user.is_manager):
|
||||
elif auth.user and (auth.user.id == 1 or auth.user.is_manager):
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
@@ -7,29 +7,30 @@ _c = request.controller
|
||||
_f = request.function
|
||||
response.title = '%s %s' % (_f, '/'.join(request.args))
|
||||
response.subtitle = 'admin'
|
||||
response.menu = [(T('Site'), _f == 'site', URL(_a,'default','site'))]
|
||||
response.menu = [(T('Site'), _f == 'site', URL(_a, 'default', 'site'))]
|
||||
|
||||
if request.vars.app or request.args:
|
||||
_t = request.vars.app or request.args[0]
|
||||
response.menu.append((T('Edit'), _c == 'default' and _f == 'design',
|
||||
URL(_a,'default','design',args=_t)))
|
||||
URL(_a, 'default', 'design', args=_t)))
|
||||
response.menu.append((T('About'), _c == 'default' and _f == 'about',
|
||||
URL(_a,'default','about',args=_t,)))
|
||||
URL(_a, 'default', 'about', args=_t,)))
|
||||
response.menu.append((T('Errors'), _c == 'default' and _f == 'errors',
|
||||
URL(_a,'default','errors',args=_t)))
|
||||
URL(_a, 'default', 'errors', args=_t)))
|
||||
response.menu.append((T('Versioning'),
|
||||
_c == 'mercurial' and _f == 'commit',
|
||||
URL(_a,'mercurial','commit',args=_t)))
|
||||
URL(_a, 'mercurial', 'commit', args=_t)))
|
||||
|
||||
if not session.authorized:
|
||||
response.menu = [(T('Login'), True, URL('site'))]
|
||||
else:
|
||||
response.menu.append((T('Logout'), False,
|
||||
URL(_a,'default',f='logout')))
|
||||
URL(_a, 'default', f='logout')))
|
||||
response.menu.append((T('Debug'), False,
|
||||
URL(_a, 'debug','interact')))
|
||||
URL(_a, 'debug', 'interact')))
|
||||
|
||||
if os.path.exists('applications/examples'):
|
||||
response.menu.append((T('Help'), False, URL('examples','default','index')))
|
||||
response.menu.append(
|
||||
(T('Help'), False, URL('examples', 'default', 'index')))
|
||||
else:
|
||||
response.menu.append((T('Help'), False, 'http://web2py.com/examples'))
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
response.files.append(URL('static','plugin_multiselect/jquery.multi-select.js'))
|
||||
response.files.append(URL('static','plugin_multiselect/multi-select.css'))
|
||||
response.files.append(URL('static','plugin_multiselect/start.js'))
|
||||
response.files.append(
|
||||
URL('static', 'plugin_multiselect/jquery.multi-select.js'))
|
||||
response.files.append(URL('static', 'plugin_multiselect/multi-select.css'))
|
||||
response.files.append(URL('static', 'plugin_multiselect/start.js'))
|
||||
|
||||
Reference in New Issue
Block a user