コード例 #1
0
ファイル: start.php プロジェクト: bloveing/openulteo
             $session->orderDeletion(false, Session::SESSION_END_STATUS_ERROR);
             Abstract_Session::delete($session);
             break;
         }
         $createNow = false;
         break;
     case Session::SESSION_STATUS_DESTROYED:
         $session->orderDeletion(false, Session::SESSION_END_STATUS_ERROR);
         Abstract_Session::delete($session);
         $stop = true;
         break;
     case Session::SESSION_STATUS_ERROR:
     default:
         # Unknown status
         $session->orderDeletion(false, Session::SESSION_END_STATUS_ERROR);
         Abstract_Session::delete($session);
         $stop = true;
         break;
 }
 if ($stop) {
     continue;
 }
 $old_session_id = $session->id;
 $client_id = gen_unique_string();
 $session->client_id = $client_id;
 $user_login_aps = $session->settings['aps_access_login'];
 $user_password_aps = $session->settings['aps_access_password'];
 if (array_key_exists('fs_access_login', $session->settings) && array_key_exists('fs_access_password', $session->settings)) {
     $user_login_fs = $session->settings['fs_access_login'];
     $user_password_fs = $session->settings['fs_access_password'];
 }
コード例 #2
0
ファイル: minutely.php プロジェクト: bloveing/openulteo
        }
    }
    if (in_array($session->status, array(Session::SESSION_STATUS_CREATING, Session::SESSION_STATUS_CREATED, Session::SESSION_STATUS_INIT, Session::SESSION_STATUS_READY))) {
        if ($session->start_time < time() - DEFAULT_UNUSED_SESSION_DURATION) {
            Logger::info('main', '(minutely cron) Session \'' . $session->id . '\' was never used, ending...');
            $session->orderDeletion(true, Session::SESSION_END_STATUS_UNUSED);
        }
    }
    if (in_array($session->status, array(Session::SESSION_STATUS_ACTIVE))) {
        if (!$session->isAlive()) {
            Logger::info('main', '(minutely cron) Session \'' . $session->id . '\' does not exist anymore, purging...');
            $session->orderDeletion(false, Session::SESSION_END_STATUS_ERROR);
        }
    }
    if ($session->status == Session::SESSION_STATUS_DESTROYED) {
        if (!Abstract_Session::uptodate($session)) {
            Logger::info('main', '(minutely cron) Session \'' . $session->id . '\' does not exist anymore, purging...');
            $session->orderDeletion(false, Session::SESSION_END_STATUS_ERROR);
            Abstract_Session::delete($session->id);
        }
    }
    if (in_array($session->status, array(Session::SESSION_STATUS_WAIT_DESTROY, Session::SESSION_STATUS_DESTROYING))) {
        if (array_key_exists('stop_time', $session->settings) && $session->settings['stop_time'] + DESTROYING_DURATION < time()) {
            Logger::info('main', '(minutely cron) Session \'' . $session->id . '\' do not respond, purging...');
            $session->orderDeletion(false, Session::SESSION_END_STATUS_ERROR);
            Abstract_Session::delete($session->id);
        }
    }
}
//END Sessions expiration
exit(0);
コード例 #3
0
ファイル: Session.class.php プロジェクト: bloveing/openulteo
 public function setStatus($status_, $reason_ = NULL)
 {
     if ($status_ == $this->getAttribute('status')) {
         return false;
     }
     // status is already the same...
     $states = array(Session::SESSION_STATUS_CREATING => -1, Session::SESSION_STATUS_CREATED => 0, Session::SESSION_STATUS_INIT => 1, Session::SESSION_STATUS_READY => 2, Session::SESSION_STATUS_ACTIVE => 3, Session::SESSION_STATUS_INACTIVE => 3, Session::SESSION_STATUS_WAIT_DESTROY => 4, Session::SESSION_STATUS_DESTROYING => 5, Session::SESSION_STATUS_DESTROYED => 6, Session::SESSION_STATUS_ERROR => 6, Session::SESSION_STATUS_UNKNOWN => 6);
     if (array_key_exists($status_, $states) && array_key_exists($this->getAttribute('status'), $states)) {
         if ($states[$status_] < $states[$this->getAttribute('status')] && !$this->canSwitchToPreviousStatus($status_)) {
             return false;
         }
         // avoid switching Session to a previous status...
     }
     Logger::debug('main', 'Starting Session::setStatus for \'' . $this->id . '\'');
     $ev = new SessionStatusChanged(array('id' => $this->id, 'status' => $status_));
     if ($status_ == Session::SESSION_STATUS_READY) {
         Logger::info('main', 'Session start : \'' . $this->id . '\'');
         $this->setAttribute('start_time', time());
     } elseif ($status_ == Session::SESSION_STATUS_INACTIVE) {
         if (!array_key_exists('persistent', $this->settings) || $this->settings['persistent'] == 0) {
             return $this->setStatus(Session::SESSION_STATUS_WAIT_DESTROY, Session::SESSION_END_STATUS_LOGOUT);
         }
         // We prevent switch from READY to INACTIVE
         if ($this->getAttribute('status') == Session::SESSION_STATUS_READY) {
             return true;
         }
     } elseif ($status_ == Session::SESSION_STATUS_WAIT_DESTROY) {
         Logger::info('main', 'Session end : \'' . $this->id . '\' (reason: \'' . $reason_ . '\')');
         if (!array_key_exists('stop_time', $this->settings)) {
             $this->settings["stop_time"] = time();
         }
         if ($status_ == Session::SESSION_STATUS_WAIT_DESTROY && !is_null($reason_)) {
             $report_session = Abstract_ReportSession::load($this->id);
             if (is_object($report_session)) {
                 $report_session->setStopWhy($reason_);
                 Abstract_ReportSession::update($report_session);
             }
         }
         if (!$this->orderDeletion()) {
             Logger::error('main', 'Unable to order session deletion for session \'' . $this->id . '\'');
         } else {
             $ev->emit();
             return false;
         }
     } elseif ($status_ == Session::SESSION_STATUS_DESTROYED) {
         Logger::info('main', 'Session purge : \'' . $this->id . '\' (reason: \'' . $reason_ . '\')');
         if (array_key_exists(Server::SERVER_ROLE_FS, $this->servers)) {
             foreach ($this->servers[Server::SERVER_ROLE_FS] as $server_id => $data) {
                 $session_server = Abstract_Server::load($server_id);
                 if (!$session_server) {
                     Logger::error('main', 'Session::orderDeletion Unable to load server \'' . $server_id . '\'');
                     return false;
                 }
                 if (is_array($session_server->roles)) {
                     if (array_key_exists(Server::SERVER_ROLE_FS, $session_server->roles)) {
                         $buf = $session_server->orderFSAccessDisable($this->settings['fs_access_login']);
                         if (!$buf) {
                             Logger::warning('main', 'Session::orderDeletion User \'' . $this->settings['fs_access_login'] . '\' already logged out of server \'' . $session_server->fqdn . '\'');
                         }
                     }
                 }
             }
         }
         if ($status_ == Session::SESSION_STATUS_DESTROYED && !is_null($reason_)) {
             $report_session = Abstract_ReportSession::load($this->id);
             if (is_object($report_session)) {
                 $report_session->setStopWhy($reason_);
                 Abstract_ReportSession::update($report_session);
             }
         }
         $ev->emit();
         Abstract_Session::delete($this->id);
         return false;
     }
     Logger::debug('main', 'Status set to "' . $status_ . '" (' . $this->textStatus($status_) . ') for session \'' . $this->id . '\'');
     $this->setAttribute('status', $status_);
     $ev->emit();
     Abstract_Session::save($this);
     return true;
 }
コード例 #4
0
ファイル: Server.class.php プロジェクト: skdong/nfs-ovd
 public function setStatus($status_)
 {
     Logger::debug('main', 'Starting Server::setStatus for \'' . $this->fqdn . '\'');
     $ev = new ServerStatusChanged(array('fqdn' => $this->fqdn, 'status' => $status_ == 'ready' ? ServerStatusChanged::$ONLINE : ServerStatusChanged::$OFFLINE));
     switch ($status_) {
         case 'ready':
             $this->setAttribute('status', 'ready');
             if ($this->getAttribute('registered') && is_array($this->roles) && array_key_exists(Server::SERVER_ROLE_APS, $this->roles)) {
                 if (!$this->updateApplications()) {
                     Logger::critical('main', 'Server::setStatus(' . $status_ . ') - updateApplications failed, status switched to "broken"');
                     $this->setStatus(Server::SERVER_STATUS_BROKEN);
                     return false;
                 }
             }
             break;
     }
     switch ($status_) {
         case 'pending':
             Logger::warning('main', 'Status set to "pending" for server \'' . $this->fqdn . '\'');
             $this->setAttribute('status', 'pending');
             break;
         case 'ready':
             Logger::info('main', 'Status set to "ready" for server \'' . $this->fqdn . '\'');
             $this->setAttribute('status', 'ready');
             break;
         case 'down':
             Logger::warning('main', 'Status set to "down" for server \'' . $this->fqdn . '\'');
             $this->setAttribute('status', 'down');
             break;
         case 'broken':
         default:
             Logger::error('main', 'Status set to "broken" for server \'' . $this->fqdn . '\'');
             $this->setAttribute('status', 'broken');
             break;
     }
     $ev->emit();
     Abstract_Server::save($this);
     switch ($this->getAttribute('status')) {
         case 'pending':
             break;
         case 'down':
             $sessions = Abstract_Session::getByServer($this->fqdn);
             foreach ($sessions as $session) {
                 Logger::warning('main', 'Server \'' . $this->fqdn . '\' status is now "down", killing Session \'' . $session->id . '\'');
                 $session->setStatus(Session::SESSION_STATUS_WAIT_DESTROY, Session::SESSION_END_STATUS_SERVER_DOWN);
                 Abstract_Session::delete($session->id);
             }
             break;
         case 'broken':
         default:
             $sessions = Abstract_Session::getByServer($this->fqdn);
             foreach ($sessions as $session) {
                 Logger::warning('main', 'Server \'' . $this->fqdn . '\' status is now "broken", killing Session \'' . $session->id . '\'');
                 $session->setStatus(Session::SESSION_STATUS_WAIT_DESTROY, Session::SESSION_END_STATUS_SERVER_BROKEN);
                 Abstract_Session::delete($session->id);
             }
             break;
     }
     return true;
 }
コード例 #5
0
ファイル: api.php プロジェクト: bloveing/openulteo
 public function session_kill($id_)
 {
     $this->check_authorized('manageSession');
     $session = Abstract_Session::load($id_);
     if (!$session) {
         Logger::error('api', sprintf('Unknown session "%s"', $id_));
         return false;
     }
     $ret = $session->orderDeletion(true, Session::SESSION_END_STATUS_ADMINKILL);
     if (!$ret) {
         Abstract_Session::delete($session->id);
         Logger::error('api', sprintf("Unable to delete session '%s'", $session->id));
         return false;
     }
     $this->log_action('session_kill', array('id' => $id_, 'user' => $this->user_login));
     return true;
 }