Exemple #1
0
 def _on_auth(self, uid, creds, store):
     if not creds:
         raise tornado.web.HTTPError(500, "Storage auth failed")
     sess_id = Session.extract_session_id(self)
     sess = Session.get_session(sess_id)
     logger.debug("%s storage authenticated for with credentials %s", sess.log_str(), creds.to_json())
     sess.storage_auth_valid(self, creds, store)
     if uid != None:
         logger.debug("%s stashed credentials for %s", sess.log_str(), str(uid))
         Utils.stash_storage_creds(StorageHandlerBase.SEC_SALT, uid, creds)
Exemple #2
0
 def check_sess_and_task_timeouts():
     global logger
     #logger.debug("checking task timeouts")
     num_timeouts = Session.check_task_timeouts()
     if num_timeouts > 0:
         logger.debug("timed out " + str(num_timeouts) + " tasks")
     
     #logger.debug("checking session timeouts")
     num_timeouts = Session.check_session_timeouts()
     if num_timeouts > 0:
         logger.debug("timed out " + str(num_timeouts) + " sessions")
     
     logger.debug("websock stats: " + str(websock_router.stats.dump()))
Exemple #3
0
 def get(self):
     #logger.debug("got request url " + self.request.full_url())
     global SRVR_CFG
     global logger
     if SRVR_CFG.multiuser:
         self.sess_id = sess_id = Session.extract_session_id(self)
         self.sess = sess = Session.get_session(sess_id)
         if self.sess == None:
             logger.debug("redirecting request to home page")
             self.redirect('/static/index.html')
             #logger.debug("redirecting request for authentication")
             #self.redirect('/auth/login')
             return
         username = sess.user_name()
         userid = sess.user_id()
         userrole = sess.user_role()
         has_running_task = (None != sess.task)
         txt_shutdown = "Logout"
         txt_shutdown_msg = "Are you sure you want to logout from Circuitscape?"
         filedlg_type = "google"
         filedlg_developer_key = SRVR_CFG.cfg_get("GOOGLE_DEVELOPER_KEY")
         filedlg_app_id = SRVR_CFG.cfg_get("GOOGLE_CLIENT_ID")
     else:
         userid = username = getpass.getuser()
         userrole = ['standalone']
         has_running_task = False
         txt_shutdown = "Shutdown"
         txt_shutdown_msg = "Are you sure you want to close Circuitscape?"
         filedlg_type = "srvr"
         filedlg_developer_key = None
         filedlg_app_id = None
         sess_id = ''
     
     kwargs = {
               'username': username,
               'userid': userid,
               'userrole': userrole,
               'has_running_task': has_running_task,
               'version': cs_version,
               'author': cs_author,
               'ws_url': SRVR_CFG.ws_url,
               'sess_id': sess_id,
               'txt_shutdown': txt_shutdown,
               'txt_shutdown_msg': txt_shutdown_msg,
               'filedlg_type': filedlg_type,
               'filedlg_developer_key': filedlg_developer_key,
               'filedlg_app_id': filedlg_app_id
     }
     self.render("cs.html", **kwargs)
Exemple #4
0
 def handle_auth(self, wsmsg):
     if (not self.is_authenticated) and (wsmsg.msg_type() == WSMsg.REQ_AUTH):
         self.sess_id = wsmsg.data('sess_id')
         self.sess = sess = Session.get_session(self.sess_id)
         self.is_authenticated = (sess != None)
         if self.is_authenticated:
             sess.detach = True  # set detach mode by default
             self.work_dir = sess.work_dir()
             self.storage_creds, self.store = sess.storage()
             msg = None
         else:
             msg = 'Your login session appears to have timed out. Please sign in again.'
         return ({'success': self.is_authenticated, 'msg': msg}, not self.is_authenticated)
     return (None, not self.is_authenticated)
Exemple #5
0
def run_webgui(config):
    global SRVR_CFG
    global logger
    SRVR_CFG = ServerConfig(config)
    
    WebSocketLogger.REPLAY_NUM_MSGS = SRVR_CFG.cfg_get("replay_num_msgs", int, 10)
    Utils.temp_files_root = SRVR_CFG.cfg_get("temp_dir", str, None)
    log_lvl = SRVR_CFG.cfg_get("log_level", str, "DEBUG")
    log_lvl = getattr(logging, log_lvl)
    log_file = SRVR_CFG.cfg_get("log_file", str, None)
    
    logger = logging.getLogger('cloudCS')
    tornado_access_logger = logging.getLogger('tornado.access')
    tornado_application_logger = logging.getLogger('tornado.application')
    tornado_general_logger = logging.getLogger('tornado.general')
    
    logger.setLevel(log_lvl)
    tornado_access_logger.setLevel(log_lvl)
    tornado_application_logger.setLevel(log_lvl)
    tornado_general_logger.setLevel(log_lvl)
    
    if log_file:
        handler = logging.FileHandler(log_file)
        formatter = logging.Formatter('%(asctime)s:%(levelname)s:%(name)s:%(message)s', '%m/%d/%Y %I.%M.%S.%p')
        handler.setFormatter(formatter)
        logger.addHandler(handler)
        tornado_access_logger.addHandler(handler)
        tornado_application_logger.addHandler(handler)
        tornado_general_logger.addHandler(handler)
    else:
        logging.basicConfig()

    logger.info('starting up...')
    logger.debug("listening on - " + SRVR_CFG.listen_ip + ':' + str(SRVR_CFG.port))
    logger.debug("hostname - " + SRVR_CFG.host)
    logger.debug("multiuser - " + str(SRVR_CFG.multiuser))
    logger.debug("headless - " + str(SRVR_CFG.headless))

    AsyncRunner.DEFAULT_REPLY = {'complete': True, 'success': False}
    if (Utils.temp_files_root != None):
        AsyncRunner.FILTER_STRINGS = [Utils.temp_files_root]
    AsyncRunner.LOG_MSG = WSMsg.SHOW_LOG

    app = Application()
    server = tornado.httpserver.HTTPServer(app)
    server.listen(SRVR_CFG.port, address=SRVR_CFG.listen_ip)
    if not SRVR_CFG.headless:
        webbrowser.open(SRVR_CFG.http_url)

    if SRVR_CFG.multiuser:
        # start the session and task timeout monitor
        app.start_session_and_task_monitor()    
    
    try:
        tornado.ioloop.IOLoop.instance().start()
    except:
        logger.exception("server shutdown with exception")
        
    logger.info("shutting down...")
    try:
        Session.logout_all()
    except:
        logger.exception("exception while cleaning up")
    logger.info("server shut down")