Commit ad58dc25 authored by Mathieu Giraud's avatar Mathieu Giraud

Merge remote-tracking branch 'origin/rbx.vidjil.org'

Conflicts:
	server/web2py/applications/vidjil/controllers/default.py
parents f6e9c1fe a48b6430
......@@ -71,10 +71,12 @@ def edit_form():
res = {"redirect": "config/index",
"message": "config saved"}
log.info(res)
return gluon.contrib.simplejson.dumps(res, separators=(',',':'))
else :
res = {"success" : "false", "message" : error}
log.error(res)
return gluon.contrib.simplejson.dumps(res, separators=(',',':'))
def confirm():
......
......@@ -60,6 +60,7 @@ def run_request():
else :
res = {"success" : "false",
"message" : "default/run_request : " + error}
log.error(res)
return gluon.contrib.simplejson.dumps(res, separators=(',',':'))
......@@ -108,11 +109,13 @@ def get_data():
data["samples"]["original_names"].append(filename)
data["samples"]["info"].append(row.sequence_file.info)
log.info("get_data: %s -> %s" % (request.vars["patient_id"], fused_file))
return gluon.contrib.simplejson.dumps(data, separators=(',',':'))
else :
res = {"success" : "false",
"message" : "default/get_data : " + error}
log.error(res)
return gluon.contrib.simplejson.dumps(res, separators=(',',':'))
#########################################################################
......@@ -168,6 +171,7 @@ def get_analysis():
else :
res = {"success" : "false",
"message" : "default/get_analysis : " + error}
log.error(res)
return gluon.contrib.simplejson.dumps(res, separators=(',',':'))
......@@ -209,10 +213,12 @@ def save_analysis():
res = {"success" : "true",
"message" : patient_name+": analysis saved"}
log.info(res)
return gluon.contrib.simplejson.dumps(res, separators=(',',':'))
else :
res = {"success" : "false",
"message" : error}
log.error(res)
return gluon.contrib.simplejson.dumps(res, separators=(',',':'))
......@@ -274,6 +280,42 @@ def create_self_signed_cert(cert_dir):
return(ssl_created, cert_dir, CERT_FILE, KEY_FILE)
#########################################################################
def handle_error():
"""
Custom error handler that returns correct status codes,
adapted from http://www.web2pyslices.com/slice/show/1529/custom-error-routing
"""
code = request.vars.code
request_url = request.vars.request_url
ticket = request.vars.ticket
log.error("[%s] %s" % (code, ticket))
if code is not None and request_url != request.url:# Make sure error url is not current url to avoid infinite loop.
response.status = int(code) # Assign the error status code to the current response. (Must be integer to work.)
if code == '403':
return "Not authorized"
elif code == '404':
return "Not found"
elif code == '500':
# Get ticket URL:
ticket_url = "<a href='%(scheme)s://%(host)s/admin/default/ticket/%(ticket)s' target='_blank'>%(ticket)s</a>" % {'scheme':'https','host':request.env.http_host,'ticket':ticket}
# Email a notice, etc:
mail.send(to=['contact@vidjil.org'],
subject="[Vidjil] web2py error",
message="Error Ticket: %s" % ticket_url)
return "Server error"
#########################################################################
##TODO remove useless function ( maybe used by web2py internally )
......
......@@ -49,7 +49,8 @@ def add_form():
"redirect": "patient/info",
"args" : {"id" : request.vars['patient_id']}
}
log.info(res)
return gluon.contrib.simplejson.dumps(res, separators=(',',':'))
else :
......@@ -99,7 +100,8 @@ def edit_form():
res = {"file_id" : request.vars['id'],
"redirect": "patient/info",
"args" : { "id" : patient_id},
"message": "change saved"}
"message": "%s: metadata saved" % request.vars['filename']}
log.info(res)
return gluon.contrib.simplejson.dumps(res, separators=(',',':'))
def upload():
......@@ -140,6 +142,7 @@ def delete():
res = {"redirect": "patient/info",
"args" : { "id" : patient_id},
"message": "sequence file deleted"}
log.info(res)
return gluon.contrib.simplejson.dumps(res, separators=(',',':'))
else:
res = {"success" : "false", "message" : "you need admin permission to delete this file"}
......
......@@ -8,10 +8,12 @@ if request.env.http_origin:
## return patient file list
##
def info():
log.info('patient (%s)' % request.vars["id"])
if (auth.has_permission('read', 'patient', request.vars["id"]) ):
return dict(message=T('patient'))
else :
res = {"message": "acces denied"}
log.error(res)
return gluon.contrib.simplejson.dumps(res, separators=(',',':'))
......@@ -21,6 +23,7 @@ def index():
if not auth.user :
res = {"redirect" : "default/user/login"}
return gluon.contrib.simplejson.dumps(res, separators=(',',':'))
log.info('patient list')
return dict(message=T(''))
......@@ -78,6 +81,7 @@ def add_form():
res = {"redirect": "patient/info",
"args" : { "id" : id },
"message": patient_name + ": patient added"}
log.info(res)
return gluon.contrib.simplejson.dumps(res, separators=(',',':'))
else :
......@@ -128,7 +132,8 @@ def edit_form():
)
res = {"redirect": "back",
"message": "change saved"}
"message": "patient %s %s edited" % (request.vars["first_name"], request.vars["last_name"])}
log.info(res)
return gluon.contrib.simplejson.dumps(res, separators=(',',':'))
else :
......@@ -146,6 +151,7 @@ def download():
#
def confirm():
if (auth.has_permission('admin', 'patient', request.vars["id"]) ):
log.info('patient deleted')
return dict(message=T('confirm patient deletion'))
else :
res = {"message": "acces denied"}
......@@ -170,9 +176,11 @@ def delete():
res = {"redirect": "patient/index",
"success": "true",
"message": "patient ("+request.vars["id"]+") deleted"}
log.info(res)
return gluon.contrib.simplejson.dumps(res, separators=(',',':'))
else :
res = {"message": "acces denied"}
log.error(res)
return gluon.contrib.simplejson.dumps(res, separators=(',',':'))
......
......@@ -23,6 +23,7 @@ def run_all():
res = {"success" : "true",
"message" : "rerun all"}
log.info(res)
return gluon.contrib.simplejson.dumps(res, separators=(',',':'))
## display run page result
......@@ -69,7 +70,8 @@ def delete():
"args" : { "id" : patient_id,
"config_id" : config_id},
"success": "true",
"message": "run ("+str(request.vars["results_file_id"])+") deleted"}
"message": "process ("+str(request.vars["results_file_id"])+") deleted"}
log.info(res)
return gluon.contrib.simplejson.dumps(res, separators=(',',':'))
else :
res = {"message": "acces denied"}
......
......@@ -199,3 +199,56 @@ if db(db.auth_user.id > 0).count() == 0:
## after defining tables, uncomment below to enable auditing
auth.enable_record_versioning(db)
## Reverse IP
ips = {}
try:
for l in open('/home/vidjil/ips.txt'):
ip, kw = l.split()
ips[ip] = kw
except:
pass
## Logging
import logging
class MsgUserAdapter(logging.LoggerAdapter):
def process(self, msg, kwargs):
if type(msg) is dict:
msg = msg['message']
ip = request.client
if ip in ips:
ip = "%s/%s" % (ip, ips[ip])
new_msg = '%15s <%s> %s' % (ip, (auth.user.first_name if auth.user else ''), msg)
return new_msg, kwargs
#
def _init_log():
"""
adapted from http://article.gmane.org/gmane.comp.python.web2py/11091
"""
import logging
logger = logging.getLogger('vidjil') # (request.application)
if not logger.handlers:
logger.setLevel(logging.DEBUG)
handler = logging.FileHandler('/var/vidjil/vidjil.log')
handler.setLevel(logging.DEBUG)
handler.setFormatter(logging.Formatter('[%(process)d] %(asctime)s %(levelname)8s - %(filename)s:%(lineno)d\t%(message)s'))
logger.addHandler(handler)
logger.info("Creating logger")
return MsgUserAdapter(logger, {})
log = _init_log()
......@@ -51,8 +51,9 @@ def schedule_run(id_sequence, id_config):
patient_name = db.patient[id_patient].first_name + " " + db.patient[id_patient].last_name
res = {"redirect": "reload",
"message": "default/run_request : request added to run config " + config_name + " on " + filename + " for " + patient_name }
"message": "%s (%s) %s: process requested" % (patient_name, config_name, filename)}
log.info(res)
return res
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment