public function run() { if ($this->ev->status != Session::SESSION_STATUS_DESTROYED) { return true; } $token = $this->ev->id; if (!Abstract_Session::exists($token)) { Logger::error('main', "SessionStatusChangedPendingSessionCreation:: Session '{$token}' does not exist"); return false; } $session = Abstract_Session::load($token); return $this->checkPendingSession($session); }
private static function create($session_) { Logger::debug('main', 'Starting Abstract_Session::create for \'' . $session_->id . '\''); if (Abstract_Session::exists($session_->id)) { Logger::error('main', 'Abstract_Session::create(\'' . $session_->id . '\') session already exists'); return false; } $SQL = SQL::getInstance(); $SQL->DoQuery('INSERT INTO @1 (@2) VALUES (%3)', $SQL->prefix . 'sessions', 'id', $session_->id); foreach ($session_->servers[Server::SERVER_ROLE_APS] as $fqdn => $data) { Abstract_Liaison::save('ServerSession', $fqdn, $session_->id); } return true; }
public function update($session_node_) { $sessid = $session_node_->getAttribute('id'); $buf = Abstract_Session::exists($sessid); if (!$buf) { return; } $session = Abstract_Session::load($sessid); if (!$session) { return; } //$apps_link = application_desktops_to_ids(); /* reset the current apps data */ $this->current_apps = array(); /* get the running apps for a start */ $tmp = array(); foreach ($session_node_->childNodes as $instance_node) { if ($instance_node->tagName != 'instance') { continue; } $app_pid = $instance_node->getAttribute('id'); $app_id = $instance_node->getAttribute('application'); $this->current_apps[$sessid] = $app_id; $tmp[$app_pid] = $app_id; } /* for each app that was already active, we check if it's still there * and: - if yes, drop it from $tmp - if no, regeister the end of the application */ foreach ($this->apps_raw_data as $app) { $app_pid = $app['pid']; $app_id = $app['id']; $app_running = $app['running']; if ($app_running->isDone()) { /* already ended, we don't care */ continue; } if (array_key_exists($app_pid, $tmp) && $app_id == $tmp[$app_pid]) { unset($tmp[$app_pid]); } else { $app_running->stop(); } } /* now register each remaining item in $tmp */ foreach ($tmp as $app_pid => $app_id) { $this->apps_raw_data[] = array('pid' => $app_pid, 'id' => $app_id, 'running' => new ReportRunningItem()); } }
public function run() { switch ($this->ev->status) { /* session created */ case Session::SESSION_STATUS_CREATED: $token = $this->ev->id; if (!Abstract_ReportSession::exists($token)) { if (!Abstract_Session::exists($token)) { Logger::error('main', "SessionStatusChangedReport::run failed session '{$token}' does not exist"); return false; } $session = Abstract_Session::load($token); $sessitem = new SessionReportItem($session->id, $session->user_login, $session->server, $session->start_time); $ret = Abstract_ReportSession::create($sessitem); if (!$ret) { Logger::error('main', "SessionStatusChangedReport::run failed to save SessionReportItem({$token})"); return false; } } return true; break; /* session ended */ /* session ended */ case Session::SESSION_STATUS_WAIT_DESTROY: case Session::SESSION_STATUS_DESTROYED: $token = $this->ev->id; if (!Abstract_Session::exists($token)) { Logger::error('main', "SessionStatusChangedReport::run failed session '{$token}' does not exist"); return false; } $session = Abstract_Session::load($token); $sessitem = Abstract_ReportSession::load($token); if (!is_object($sessitem)) { Logger::error('main', "SessionStatusChangedReport::run failed to load SessionReportItem({$token})"); return false; } $sessitem->end($session); Abstract_ReportSession::update_on_session_end($sessitem); return true; break; default: return true; break; } }
* but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. **/ require_once dirname(__FILE__) . '/../includes/core-minimal.inc.php'; if (Preferences::fileExists() === false) { exit(1); } //BEGIN Sessions expiration $sessions = Abstract_Session::load_all(); foreach ($sessions as $session) { if (!Abstract_Session::exists($session->id)) { // avoid operation on an already deleted Session (parallel processing) continue; } if ($session->start_time != 0 && array_key_exists('timeout', $session->settings) && $session->settings['timeout'] > 0) { if ($session->start_time + $session->settings['timeout'] < time()) { Logger::info('main', '(minutely cron) Session \'' . $session->id . '\' has expired, ending...'); $session->orderDeletion(true, Session::SESSION_END_STATUS_TIMEOUT); } } 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); } }
function get_session_history($t0, $t1, $mode_) { $result = build_array($t0, $t1, $mode_); $res_server = array(); $end_status = array(); $sql = SQL::getInstance(); $res = $sql->DoQuery('SELECT * FROM @1 WHERE @2 BETWEEN %3 AND %4;', SESSIONS_HISTORY_TABLE, 'start_stamp', date('c', $t0), date('c', $t1)); $g = $sql->FetchAllResults(); foreach ($g as $p) { if (is_null($p['stop_stamp'])) { // todo: or stop_stamp=NULL if (!Abstract_Session::exists($p['id'])) { // Before the v2.5, most of sessions report was empty ... // Logger::warning('main', 'Invalid reporting item session '.$p['id']); continue; } } $y = strtotime($p['start_stamp']); $buf = date($mode_->get_prefix(), $y); if ($p['stop_why'] == '' || is_null($p['stop_why'])) { $p['stop_why'] = 'unknown'; } if (!is_null($p['stop_stamp'])) { if (!isset($end_status[$p['stop_why']])) { $end_status[$p['stop_why']] = 0; } $end_status[$p['stop_why']] += 1; } if (!isset($result[$buf])) { continue; } if (!isset($res_server[$p['server']])) { $res_server[$p['server']] = build_array($t0, $t1, $mode_); } $res_server[$p['server']][$buf]++; $result[$buf]++; } $session_number = count($g); return array($session_number, $result, $res_server, $end_status); }
$server->setAttribute('disk_total', $ret['disk_size']['total']); $server->setAttribute('disk_free', $ret['disk_size']['free']); } $slaveserver_settings = $prefs->get('general', 'slave_server_settings'); if ($slaveserver_settings['auto_recover'] == 1) { if (!$server->isOnline()) { $server->setAttribute('status', Server::SERVER_STATUS_ONLINE); $server->getStatus(); } } Abstract_Server::save($server); //update Server cache timestamp if (array_key_exists('sessions', $ret) && is_array($ret['sessions'])) { $monitored_session = array(); foreach ($ret['sessions'] as $session) { $buf = Abstract_Session::exists($session['id']); if (!$buf) { continue; } $buf = Abstract_Session::load($session['id']); if (!$buf) { continue; } $modified = false; array_push($monitored_session, $session['id']); if (!array_key_exists($session['server'], $buf->servers[Server::SERVER_ROLE_APS])) { continue; } if ($session['status'] != $buf->servers[Server::SERVER_ROLE_APS][$session['server']]['status']) { $modified = true; $buf->setServerStatus($session['server'], $session['status']);
function return_error($errno_, $errstr_) { header('Content-Type: text/xml; charset=utf-8'); $dom = new DomDocument('1.0', 'utf-8'); $node = $dom->createElement('error'); $node->setAttribute('id', $errno_); $node->setAttribute('message', $errstr_); $dom->appendChild($node); Logger::error('main', "(client/session_status) return_error({$errno_}, {$errstr_})"); return $dom->saveXML(); } if (!array_key_exists('session_id', $_SESSION)) { echo return_error(1, 'Usage: missing "session_id" $_SESSION parameter'); die; } if (!Abstract_Session::exists($_SESSION['session_id'])) { header('Content-Type: text/xml; charset=utf-8'); $dom = new DomDocument('1.0', 'utf-8'); $session_node = $dom->createElement('session'); $session_node->setAttribute('id', $_SESSION['session_id']); $session_node->setAttribute('status', 'unknown'); $dom->appendChild($session_node); $xml = $dom->saveXML(); echo $xml; die; } $session = Abstract_Session::load($_SESSION['session_id']); if (!$session) { header('Content-Type: text/xml; charset=utf-8'); $dom = new DomDocument('1.0', 'utf-8'); $session_node = $dom->createElement('session');
private static function generate_sessionsreport_array($sessions_) { $ret = array(); foreach ($sessions_ as $session) { if (is_null($session->getStopTime())) { // todo: or stop_stamp=NULL if (!Abstract_Session::exists($session->getId())) { // Before the v2.5, most of sessions report was empty ... // Logger::warning('api', 'Invalid reporting item session '.$p['id']); continue; } } $s = self::generate_sessionreport_array($session); $ret[$s['id']] = $s; } return $ret; }