コード例 #1
0
ファイル: functions.inc.php プロジェクト: bloveing/openulteo
/**
 * Copyright (C) 2008-2013 Ulteo SAS
 * http://www.ulteo.com
 * Author Julien LANGLOIS <*****@*****.**> 2008-2013
 * Author Laurent CLOUET <*****@*****.**> 2008-2011
 * Author Jeremy DESVAGES <*****@*****.**> 2008-2011
 * Author Vincent ROULLIER <*****@*****.**> 2013
 * Author David LECHEVALIER <*****@*****.**> 2012
 * Author David PHAM-VAN <*****@*****.**> 2013
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; version 2
 * of the License.
 *
 * This program is distributed in the hope that it will be useful,
 * 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.
 **/
function init_db($prefs_)
{
    // prefs must be valid
    Logger::debug('main', 'init_db');
    $modules_enable = $prefs_->get('general', 'module_enable');
    foreach ($modules_enable as $module_name) {
        if (!is_null($prefs_->get($module_name, 'enable'))) {
            $enable = $prefs_->get($module_name, 'enable');
            if (is_string($enable)) {
                $mod_name = $module_name . '_' . $enable;
                $ret_eval = call_user_func(array($mod_name, 'init'), $prefs_);
                if ($ret_eval !== true) {
                    Logger::error('main', 'init_db init module \'' . $mod_name . '\' failed');
                    return false;
                }
            } elseif (is_array($enable)) {
                foreach ($enable as $sub_module) {
                    $mod_name = $module_name . '_' . $sub_module;
                    $ret_eval = call_user_func(array($mod_name, 'init'), $prefs_);
                    if ($ret_eval !== true) {
                        Logger::error('main', 'init_db init module \'' . $mod_name . '\' failed');
                        return false;
                    }
                }
            }
        }
    }
    Logger::debug('main', 'init_db modules inited');
    // Init of Abstract
    Abstract_Server::init($prefs_);
    Abstract_ServersGroup::init($prefs_);
    Abstract_Session::init($prefs_);
    Abstract_Token::init($prefs_);
    Abstract_News::init($prefs_);
    Abstract_Script::init($prefs_);
    Abstract_Liaison::init($prefs_);
    if (class_exists("PremiumManager")) {
        PremiumManager::initdb($prefs_);
    }
    Abstract_Task::init($prefs_);
    Abstract_ReportServer::init($prefs_);
    Abstract_ReportSession::init($prefs_);
    Abstract_User_Preferences::init($prefs_);
    Abstract_UserGroup_Preferences::init($prefs_);
    Abstract_UserGroup_Rule::init($prefs_);
    Abstract_VDI::init($prefs_);
    Abstract_Network_Folder::init($prefs_);
    Abstract_AdminAction::init($prefs_);
    return true;
}
コード例 #2
0
 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;
 }
コード例 #3
0
 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());
     }
 }
コード例 #4
0
ファイル: Report.class.php プロジェクト: bloveing/openulteo
 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;
     }
 }
コード例 #5
0
ファイル: actions.php プロジェクト: skdong/nfs-ovd
                        popup_info(sprintf(_("Session '%s' successfully deleted"), $session->id));
                    }
                }
            }
            redirect('sessions.php');
        }
    }
}
if ($_REQUEST['name'] == 'Server') {
    if (!checkAuthorization('manageServers')) {
        redirect();
    }
    if ($_REQUEST['action'] == 'del') {
        if (isset($_REQUEST['checked_servers']) && is_array($_REQUEST['checked_servers'])) {
            foreach ($_REQUEST['checked_servers'] as $fqdn) {
                $sessions = Abstract_Session::getByServer($fqdn);
                if (count($sessions) > 0) {
                    popup_error(sprintf(_("Unable to delete the server '%s' because there are active sessions on it."), $fqdn));
                    continue;
                }
                $buf = Abstract_Server::load($fqdn);
                if (is_object($buf)) {
                    $buf->orderDeletion();
                    Abstract_Server::delete($buf->fqdn);
                    popup_info(sprintf(_("Server '%s' successfully deleted"), $buf->getAttribute('fqdn')));
                }
            }
            $buf = count(Abstract_Server::load_registered(false));
            if ($buf == 0) {
                redirect('servers.php');
            } else {
コード例 #6
0
     if ($session['status'] != $buf->servers[Server::SERVER_ROLE_APS][$session['server']]['status']) {
         $modified = true;
         $buf->setServerStatus($session['server'], $session['status']);
     }
     if ($session['status'] == Session::SESSION_STATUS_ACTIVE) {
         $modified = true;
         $buf->reportRunningApplicationsOnServer($ret['server'], $session['instances']);
     }
     if ($modified === true) {
         Abstract_Session::save($buf);
     }
     //update Session cache timestamp
 }
 // Check state of sessions not present in xml
 Logger::debug('main', "Checking session from " . $server->fqdn);
 $sessions = Abstract_Session::getByServer($server->id);
 foreach ($sessions as $session) {
     Logger::debug('main', "Inspecting session " . $session->id);
     if (!array_key_exists($server->id, $session->servers[Server::SERVER_ROLE_APS])) {
         Logger::debug('main', "Session " . $session->id . " on " . $server->fqdn . " is not an APS session");
         continue;
     }
     // Check if the session id unknown by the APS
     if (!in_array($session->id, $monitored_session)) {
         $serverStatus = $session->servers[Server::SERVER_ROLE_APS][$server->id]['status'];
         // If the monitoring is received during the APS session creation,
         // monitoring do not state about creating session and the session is destroy
         if (in_array($serverStatus, array(Session::SESSION_STATUS_CREATED, Session::SESSION_STATUS_READY))) {
             if (time() - $session->start_time > DEFAULT_UNUSED_SESSION_DURATION) {
                 Logger::info('main', "Session " . $session->id . " is expired");
                 $session->setServerStatus($server->id, Session::SESSION_STATUS_DESTROYED);
コード例 #7
0
ファイル: session_dump.php プロジェクト: bloveing/openulteo
if (!$infos) {
    Logger::error('main', '(webservices/session/dump) Server does not send a valid XML (error_code: 1)');
    webservices_return_error(1, 'Server does not send a valid XML');
}
$server = webservices_load_server($_SERVER['REMOTE_ADDR']);
if (!$server) {
    Logger::error('main', '(webservices/session/dump) Server does not exist (error_code: 2)');
    webservices_return_error(2, 'Server does not exist');
}
$session = Abstract_Session::load($infos['id']);
if (!$session) {
    Logger::error('main', '(webservices/session/dump) Session does not exist (error_code: 2)');
    webservices_return_error(2, 'Session does not exist');
}
$ret = $session->setServerDump($server->id, $infos['dump']);
if ($ret === false) {
    Logger::error('main', '(webservices/session/dump) Server is not used for this session (error_code: 1)');
    webservices_return_error(1, 'Server is not used for this session');
}
$ret = Abstract_Session::save($session);
if ($ret === false) {
    Logger::error('main', '(webservices/session/dump) Unable to save session with these information (error_code: 1)');
    webservices_return_error(1, 'Unable to save session with these information');
}
header('Content-Type: text/xml; charset=utf-8');
$dom = new DomDocument('1.0', 'utf-8');
$node = $dom->createElement('session');
$node->setAttribute('id', $session->id);
$dom->appendChild($node);
echo $dom->saveXML();
exit(0);
コード例 #8
0
ファイル: start.php プロジェクト: bloveing/openulteo
    $data[$k] = $v;
}
$session->setAttribute('settings', $data);
$session->setAttribute('start_time', time());
$session->settings['aps_access_login'] = $user_login_aps;
$session->settings['aps_access_password'] = $user_password_aps;
if (isset($user_login_fs) && isset($user_password_fs)) {
    $session->settings['fs_access_login'] = $user_login_fs;
    $session->settings['fs_access_password'] = $user_password_fs;
}
if (isset($user_login_webapps) && isset($user_password_webapps)) {
    $session->settings['webapps_access_login'] = $user_login_webapps;
    $session->settings['webapps_access_password'] = $user_password_webapps;
}
$session->client_id = $client_id;
$save_session = Abstract_Session::save($session);
if (!$save_session) {
    Logger::error('main', '(client/start) failed to save session \'' . $session->id . '\' for user \'' . $user->getAttribute('login') . '\'');
    throw_response(INTERNAL_ERROR);
}
$ev->setAttributes(array('ok' => true, 'server' => $session->server, 'resume' => $session->isSuspended(), 'sessid' => $session->id));
$ev->emit();
if (!isset($old_session_id)) {
    if ($createNow == false) {
        $session->need_creation = true;
    } else {
        if (!$sessionManagement->prepareSession($session)) {
            throw_response(INTERNAL_ERROR);
        }
    }
}
コード例 #9
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);
コード例 #10
0
ファイル: SessionManagement.php プロジェクト: skdong/nfs-ovd
 public function buildServersList()
 {
     if (!$this->user) {
         Logger::error('main', 'SessionManagement::buildServersList - User is not authenticated, aborting');
         throw_response(AUTH_FAILED);
     }
     $serverRoles = $this->getServerRoles();
     $this->servers = array();
     foreach ($serverRoles as $role) {
         if (!array_key_exists($role, $this->servers)) {
             $this->servers[$role] = array();
         }
         switch ($role) {
             case Server::SERVER_ROLE_APS:
                 $applicationServerTypes = $this->getApplicationServerTypes();
                 $servers = array();
                 foreach ($applicationServerTypes as $type) {
                     $buf = $this->user->getAvailableServers($type);
                     if (is_null($buf) || !is_array($buf)) {
                         return false;
                     }
                     $servers = array_merge($servers, $buf);
                 }
                 $slave_server_settings = $this->prefs->get('general', 'slave_server_settings');
                 if (is_array($slave_server_settings) && array_key_exists('use_max_sessions_limit', $slave_server_settings) && $slave_server_settings['use_max_sessions_limit'] == 1) {
                     foreach ($servers as $k => $server) {
                         if (!isset($server->max_sessions) || $server->max_sessions == 0) {
                             continue;
                         }
                         $total = Abstract_Session::countByServer($server->fqdn);
                         if ($total >= $server->max_sessions) {
                             Logger::warning('main', 'SessionManagement::buildServersList - Server \'' . $server->fqdn . '\' has reached its "max sessions" limit, sessions cannot be launched on it anymore');
                             unset($servers[$k]);
                         }
                     }
                 }
                 if (count($servers) == 0) {
                     $event = new SessionStart(array('user' => $this->user));
                     $event->setAttribute('ok', false);
                     $event->setAttribute('error', _('No available server'));
                     $event->emit();
                     Logger::error('main', 'SessionManagement::buildServersList - No "' . $role . '" server found for User "' . $this->user->getAttribute('login') . '", aborting');
                     return false;
                 }
                 foreach ($servers as $server) {
                     $this->servers[Server::SERVER_ROLE_APS][$server->fqdn] = array('status' => Session::SESSION_STATUS_CREATED);
                 }
                 break;
             case Server::SERVER_ROLE_FS:
                 if (get_class($this) != 'SessionManagement_internal') {
                     Logger::error('main', 'SessionManagement::buildServersList - Role "' . $role . '" is not compatible with the current integration mode (' . substr(get_class($this), strlen('SessionManagement_')) . '), aborting');
                     return false;
                 }
                 $default_settings = $this->user->getSessionSettings('session_settings_defaults');
                 $enable_profiles = $default_settings['enable_profiles'] == 1 ? true : false;
                 $auto_create_profile = $default_settings['auto_create_profile'] == 1 ? true : false;
                 $start_without_profile = $default_settings['start_without_profile'] == 1 ? true : false;
                 $enable_sharedfolders = $default_settings['enable_sharedfolders'] == 1 ? true : false;
                 $start_without_all_sharedfolders = $default_settings['start_without_all_sharedfolders'] == 1 ? true : false;
                 if ($enable_profiles) {
                     $fileservers = Abstract_Server::load_available_by_role(Server::SERVER_ROLE_FS);
                     if (count($fileservers) > 0) {
                         $profiles = $this->user->getProfiles();
                         if (!is_array($profiles)) {
                             Logger::error('main', 'SessionManagement::buildServersList - getProfiles() failed for User "' . $this->user->getAttribute('login') . '", aborting');
                             return false;
                         }
                         if (count($profiles) == 1) {
                             Logger::debug('main', 'SessionManagement::buildServersList - User "' . $this->user->getAttribute('login') . '" already have a Profile, using it');
                             $profile = array_pop($profiles);
                             foreach ($fileservers as $fileserver) {
                                 if ($fileserver->fqdn != $profile->server) {
                                     continue;
                                 }
                                 if (!array_key_exists($fileserver->fqdn, $this->servers[Server::SERVER_ROLE_FS])) {
                                     $this->servers[Server::SERVER_ROLE_FS][$fileserver->fqdn] = array();
                                 }
                                 $this->servers[Server::SERVER_ROLE_FS][$fileserver->fqdn][] = array('type' => 'profile', 'server' => $fileserver, 'dir' => $profile->id);
                                 break;
                             }
                         } else {
                             Logger::debug('main', 'SessionManagement::buildServersList - User "' . $this->user->getAttribute('login') . '" does not have a Profile for now, checking for auto-creation');
                             if ($auto_create_profile) {
                                 Logger::debug('main', 'SessionManagement::buildServersList - User "' . $this->user->getAttribute('login') . '" Profile will be auto-created and used');
                                 $profileDB = ProfileDB::getInstance();
                                 $fileserver = $profileDB->chooseFileServer();
                                 if (!is_object($fileserver)) {
                                     Logger::error('main', 'SessionManagement::buildServersList - Auto-creation of Profile for User "' . $this->user->getAttribute('login') . '" failed (unable to get a valid FileServer)');
                                     return false;
                                 }
                                 $profile = new Profile();
                                 $profile->server = $fileserver->getAttribute('fqdn');
                                 if (!$profileDB->addToServer($profile, $fileserver)) {
                                     Logger::error('main', 'SessionManagement::buildServersList - Auto-creation of Profile for User "' . $this->user->getAttribute('login') . '" failed (unable to add the Profile to the FileServer)');
                                     return false;
                                 }
                                 if (!$profile->addUser($this->user)) {
                                     Logger::error('main', 'SessionManagement::buildServersList - Auto-creation of Profile for User "' . $this->user->getAttribute('login') . '" failed (unable to associate the User to the Profile)');
                                     return false;
                                 }
                                 if (!array_key_exists($fileserver->fqdn, $this->servers[Server::SERVER_ROLE_FS])) {
                                     $this->servers[Server::SERVER_ROLE_FS][$fileserver->fqdn] = array();
                                 }
                                 $this->servers[Server::SERVER_ROLE_FS][$fileserver->fqdn][] = array('type' => 'profile', 'server' => $fileserver, 'dir' => $profile->id);
                             } else {
                                 Logger::debug('main', 'SessionManagement::buildServersList - Auto-creation of Profile for User "' . $this->user->getAttribute('login') . '" disabled, checking for session without Profile');
                                 if (!$start_without_profile) {
                                     Logger::error('main', 'SessionManagement::buildServersList - User "' . $this->user->getAttribute('login') . '" does not have a valid Profile, aborting');
                                     return false;
                                 }
                                 Logger::debug('main', 'SessionManagement::buildServersList - User "' . $this->user->getAttribute('login') . '" can start a session without a valid Profile, proceeding');
                             }
                         }
                     } else {
                         Logger::debug('main', 'SessionManagement::buildServersList - No "' . $role . '" server found for User "' . $this->user->getAttribute('login') . '", checking for session without Profile');
                         if (!$start_without_profile) {
                             Logger::error('main', 'SessionManagement::buildServersList - User "' . $this->user->getAttribute('login') . '" does not have a valid Profile, aborting');
                             return false;
                         }
                         Logger::debug('main', 'SessionManagement::buildServersList - User "' . $this->user->getAttribute('login') . '" can start a session without a valid Profile, proceeding');
                     }
                 }
                 if ($enable_sharedfolders) {
                     $sharedfolders = $this->user->getSharedFolders();
                     if (!is_array($sharedfolders)) {
                         Logger::error('main', 'SessionManagement::buildServersList - getSharedFolders() failed for User "' . $this->user->getAttribute('login') . '", aborting');
                         return false;
                     }
                     if (count($sharedfolders) > 0) {
                         foreach ($sharedfolders as $sharedfolder) {
                             $fileserver = Abstract_Server::load($sharedfolder->server);
                             if (!$fileserver || !$fileserver->isOnline() || $fileserver->getAttribute('locked')) {
                                 Logger::warning('main', 'SessionManagement::buildServersList - Server "' . $sharedfolder->server . '" for SharedFolder "' . $sharedfolder->id . '" is not available');
                                 if (!$start_without_all_sharedfolders) {
                                     Logger::error('main', 'SessionManagement::buildServersList - User "' . $this->user->getAttribute('login') . '" does not have all SharedFolders available, aborting');
                                     return false;
                                 } else {
                                     Logger::debug('main', 'SessionManagement::buildServersList - User "' . $this->user->getAttribute('login') . '" can start a session without all SharedFolders available, proceeding');
                                     continue;
                                 }
                             }
                             if (!array_key_exists($fileserver->fqdn, $this->servers[Server::SERVER_ROLE_FS])) {
                                 $this->servers[Server::SERVER_ROLE_FS][$fileserver->fqdn] = array();
                             }
                             $this->servers[Server::SERVER_ROLE_FS][$fileserver->fqdn][] = array('type' => 'sharedfolder', 'server' => $fileserver, 'dir' => $sharedfolder->id, 'name' => $sharedfolder->name);
                         }
                     }
                 }
                 break;
         }
     }
     return true;
 }
コード例 #11
0
ファイル: sessions.php プロジェクト: skdong/nfs-ovd
     echo '<input type="submit" name="kill" value="' . _('Kill') . '" />';
     echo '</td>';
     echo '	</tr>';
     echo '</tfoot>';
 }
 echo '</table>';
 echo '</td><td style="vertical-align: top;">';
 echo '<table style="margin-left: auto; margin-right: 0px;" class="main_sub sortable" border="0" cellspacing="1" cellpadding="3">';
 echo '<tr class="title">';
 echo '<th>' . _('Status') . '</th>';
 echo '<th>' . _('Number of sessions') . '</th>';
 echo '</tr>';
 echo '<tfoot>';
 $i = 0;
 foreach (Session::getAllStates() as $state) {
     $total = Abstract_Session::countByStatus($state);
     if ($total == 0) {
         continue;
     }
     $css_class = 'content' . ($i++ % 2 == 0 ? 1 : 2);
     echo '<tr class="' . $css_class . '">';
     echo '<td><span class="msg_' . Session::colorStatus($state) . '">' . Session::textStatus($state) . '</span></td>';
     echo '<td style="text-align: right;">' . $total . '</td>';
     echo '</tr>';
 }
 echo '</tfoot>';
 echo '</table>';
 echo '</td></tr></table>';
 if (isset($pagechanger)) {
     echo $pagechanger;
 }
コード例 #12
0
ファイル: users.php プロジェクト: skdong/nfs-ovd
function show_manage($login, $userDB, $userGroupDB)
{
    $u = $userDB->import($login);
    if (!is_object($u)) {
        die_error('Unable to import user "' . $login . '"', __FILE__, __LINE__);
    }
    $userdb_rw = $userDB->isWriteable();
    $usergroupdb_rw = $userGroupDB->isWriteable();
    $keys = array();
    foreach ($u->getAttributesList() as $attr) {
        if (!in_array($attr, array('login', 'displayname'))) {
            $keys[] = $attr;
        }
    }
    // Users Group
    $groups_mine = $u->usersGroups();
    if (is_null($groups_mine)) {
        die_error(_('Error while requesting usergroups'), __FILE__, __LINE__);
    }
    usort($groups_mine, 'usergroup_cmp');
    $groups_all = $userGroupDB->getList(true);
    $groups_available = array();
    foreach ($groups_all as $group) {
        if (!in_array($group, $groups_mine)) {
            $groups_available[] = $group;
        }
    }
    // Sessions
    $sessions = Abstract_Session::getByUser($login);
    $has_sessions = count($sessions);
    $can_manage_users = isAuthorized('manageUsers');
    $can_manage_usersgroups = isAuthorized('manageUsersGroups');
    page_header();
    echo '<div id="users_div">';
    echo '<h1>' . $u->getAttribute('displayname') . '</h1>';
    echo '<table class="main_sub" border="0" cellspacing="1" cellpadding="5">';
    echo '<tr class="title">';
    echo '<th>' . _('Login') . '</th>';
    foreach ($keys as $key) {
        if ($key != 'password') {
            echo '<th>' . $key . '</th>';
        }
    }
    echo '<th>' . _('Locale') . '</th>';
    echo '</tr>';
    echo '<tr class="content1">';
    echo '<td>' . $u->getAttribute('login') . '</td>';
    foreach ($keys as $key) {
        if ($key != 'password') {
            if (is_array($u->getAttribute($key))) {
                $buf = implode(", ", $u->getAttribute($key));
            } else {
                $buf = $u->getAttribute($key);
            }
            echo '<td>' . $buf . '</td>';
        }
    }
    echo '<td>' . $u->getLocale() . '</td>';
    echo '</tr>';
    echo '</table>';
    if ($userdb_rw and $can_manage_users) {
        echo '<div>';
        echo '<h2>' . _('Settings') . '</h2>';
        echo '<div>';
        echo '<form action="actions.php" onsubmit="return confirm(\'' . _('Are you sure you want to delete this user?') . '\');">';
        echo '<input type="submit" value="' . _('Delete this user') . '"/>';
        echo '<input type="hidden" name="name" value="User" />';
        echo '<input type="hidden" name="action" value="del" />';
        echo '<input type="hidden" name="checked_users[]" value="' . htmlspecialchars($login) . '" />';
        echo '</form>';
        echo '</div>';
        echo '<br/><br/>';
        echo '<div>';
        echo '<form action="actions.php" method="post">';
        echo '<input type="hidden" name="name" value="User" />';
        echo '<input type="hidden" name="action" value="modify" />';
        echo '<input type="hidden" name="id" value="' . htmlspecialchars($login) . '" />';
        echo '<table class="main_sub" border="0" cellspacing="1" cellpadding="5">';
        $count = 0;
        $content = 'content' . ($count++ % 2 == 0 ? 1 : 2);
        echo '<tr class="' . $content . '">';
        echo '<th>' . _('Display name') . '</th>';
        echo '<td><input type="text" name="displayname" value="' . htmlspecialchars($u->getAttribute('displayname')) . '" /></td>';
        echo '</tr>';
        if ($u->hasAttribute('password')) {
            $content = 'content' . ($count++ % 2 == 0 ? 1 : 2);
            echo '<tr class="' . $content . '">';
            echo '<th>' . _('New password') . '</th>';
            echo '<td><input type="password" name="password" value="" /></td>';
            echo '</tr>';
        }
        foreach ($keys as $key) {
            if ($key == 'password') {
                continue;
            }
            $content = 'content' . ($count++ % 2 == 0 ? 1 : 2);
            echo '<tr class="' . $content . '">';
            echo '<th>' . $key . '</th>';
            echo '<td><input type="text" name="' . $key . '" value="' . $u->getAttribute($key) . '" /></td>';
            echo '</tr>';
        }
        $content = 'content' . ($count % 2 == 0 ? 1 : 2);
        echo '<tr class="' . $content . '">';
        echo '<td colspan="2">';
        echo '<input type="submit" name="modify" value="' . _('Save changes') . '" />';
        echo '</td>';
        echo '</tr>';
        echo '</table>';
        echo '</form>';
        echo '</div>';
    }
    // User groups part
    if (count($groups_all) > 0) {
        echo '<div>';
        echo '<h2>' . _('User groups with this user') . '</h2>';
        echo '<table border="0" cellspacing="1" cellpadding="3">';
        foreach ($groups_mine as $group) {
            echo '<tr><td>';
            if ($can_manage_usersgroups) {
                echo '<a href="usersgroup.php?action=manage&id=' . $group->getUniqueID() . '">' . $group->name . '</a>';
            } else {
                echo $group->name;
            }
            echo '</td>';
            if ($usergroupdb_rw and $can_manage_usersgroups and $group->isDefault() == false) {
                echo '<td><form action="actions.php" method="post" onsubmit="return confirm(\'' . _('Are you sure you want to delete this user from this group?') . '\');">';
                echo '<input type="hidden" name="name" value="User_UserGroup" />';
                echo '<input type="hidden" name="action" value="del" />';
                echo '<input type="hidden" name="group" value="' . $group->getUniqueID() . '" />';
                echo '<input type="hidden" name="element" value="' . htmlspecialchars($login) . '" />';
                echo '<input type="submit" value="' . _('Delete from this group') . '" />';
                echo '</form></td>';
            }
            echo '</tr>';
        }
        if (count($groups_available) > 0 && $usergroupdb_rw and $can_manage_usersgroups) {
            echo '<tr><form action="actions.php" method="post"><td>';
            echo '<input type="hidden" name="action" value="add" />';
            echo '<input type="hidden" name="name" value="User_UserGroup" />';
            echo '<input type="hidden" name="element" value="' . htmlspecialchars($login) . '" />';
            echo '<select name="group">';
            foreach ($groups_available as $group) {
                echo '<option value="' . $group->getUniqueID() . '" >' . $group->name . '</option>';
            }
            echo '</select>';
            echo '</td><td><input type="submit" value="' . _('Add to this group') . '" /></td>';
            echo '</form></tr>';
        }
        echo '</table>';
        echo "</div>\n";
    }
    $apps_s = $u->applications();
    if (is_array($apps_s) && count($apps_s) > 0) {
        echo '<br />';
        echo '<h2>' . _('Published applications') . '</h2>';
        echo '<table border="0" cellspacing="1" cellpadding="3">';
        foreach ($apps_s as $aaa) {
            echo '<tr>';
            echo '<td><img src="media/image/cache.php?id=' . $aaa->getAttribute('id') . '" alt="" title="" /></td>';
            echo '<td><a href="applications.php?action=manage&id=' . $aaa->getAttribute('id') . '">' . $aaa->getAttribute('name') . '</a></td>';
            echo '</tr>';
        }
        echo '</table>';
    }
    if ($has_sessions) {
        echo '<div>';
        echo '<h2>' . _('Active sessions') . '</h2>';
        echo '<table border="0" cellspacing="1" cellpadding="3">';
        foreach ($sessions as $session) {
            echo '<form action="sessions.php"><tr>';
            echo '<td>';
            $buf = $session->getAttribute('start_time');
            if (!$buf) {
                echo _('Not started yet');
            } else {
                echo @date('d/m/Y H:i:s', $session->getAttribute('start_time'));
            }
            echo '</td>';
            echo '<td><a href="servers.php?action=manage&fqdn=' . $session->server . '">' . $session->server . '</td>';
            echo '<td>';
            echo '<input type="hidden" name="info" value="' . $session->id . '" />';
            echo '</td><td><input type="submit" value="' . _('Information about this session') . '" /></td>';
            echo '</td>';
            echo '</tr></form>';
        }
        echo '</table>';
        echo '</div>';
    }
    echo '</div>';
    page_footer();
    die;
}
コード例 #13
0
ファイル: checkup.php プロジェクト: skdong/nfs-ovd
function checkup_liaison($type_, $element_, $group_)
{
    switch ($type_) {
        case 'ApplicationServer':
            $applicationDB = ApplicationDB::getInstance();
            $buf = $applicationDB->import($element_);
            if (!is_object($buf)) {
                return 'Application "' . $element_ . '" does not exist';
            }
            $buf = Abstract_Server::load($group_);
            if (!$buf) {
                return 'Server "' . $group_ . '" does not exist';
            }
            break;
        case 'AppsGroup':
            $applicationDB = ApplicationDB::getInstance();
            $buf = $applicationDB->import($element_);
            if (!is_object($buf)) {
                return 'Application "' . $element_ . '" does not exist';
            }
            $applicationsGroupDB = ApplicationsGroupDB::getInstance();
            $buf = $applicationsGroupDB->import($group_);
            if (!is_object($buf)) {
                return 'ApplicationsGroup "' . $group_ . '" does not exist';
            }
            break;
        case 'ApplicationMimeType':
            $applicationDB = ApplicationDB::getInstance();
            $buf = $applicationDB->import($element_);
            if (!is_object($buf)) {
                return 'Application "' . $element_ . '" does not exist';
            }
            break;
        case 'ServerSession':
            $buf = Abstract_Server::load($element_);
            if (!$buf) {
                return 'Server "' . $element_ . '" does not exist';
            }
            $buf = Abstract_Session::load($group_);
            if (!$buf) {
                return 'Session "' . $group_ . '" does not exist';
            }
            break;
        case 'UserGroupSharedFolder':
            $sharedfolderdb = SharedFolderDB::getInstance();
            $userGroupDB = UserGroupDB::getInstance();
            $buf = $userGroupDB->import($element_);
            if (!is_object($buf)) {
                return 'UserGroup "' . $element_ . '" does not exist';
            }
            $buf = $sharedfolderdb->import($group_);
            if (!$buf) {
                return 'SharedFolder "' . $group_ . '" does not exist';
            }
            break;
        case 'UserProfile':
            $profiledb = ProfileDB::getInstance();
            $userDB = UserDB::getInstance();
            $buf = $userDB->import($element_);
            if (!is_object($buf)) {
                return 'User "' . $element_ . '" does not exist';
            }
            $buf = $profiledb->import($group_);
            if (!$buf) {
                return 'Profile "' . $group_ . '" does not exist';
            }
            break;
        case 'UsersGroup':
            $userDB = UserDB::getInstance();
            $buf = $userDB->import($element_);
            if (!is_object($buf)) {
                return 'User "' . $element_ . '" does not exist';
            }
            $userGroupDB = UserGroupDB::getInstance();
            $buf = $userGroupDB->import($group_);
            if (!is_object($buf)) {
                return 'UserGroup "' . $group_ . '" does not exist';
            }
            break;
        case 'UsersGroupApplicationsGroup':
            $userGroupDB = UserGroupDB::getInstance();
            $buf = $userGroupDB->import($element_);
            if (!is_object($buf)) {
                return 'UserGroup "' . $element_ . '" does not exist';
            }
            $applicationsGroupDB = ApplicationsGroupDB::getInstance();
            $buf = $applicationsGroupDB->import($group_);
            if (!is_object($buf)) {
                return 'ApplicationsGroup "' . $group_ . '" does not exist';
            }
            break;
        case 'UsersGroupCached':
            $userDB = UserDB::getInstance();
            $buf = $userDB->import($element_);
            if (!is_object($buf)) {
                return 'User "' . $element_ . '" does not exist';
            }
            $userGroupDB = UserGroupDB::getInstance();
            $buf = $userGroupDB->import($group_);
            if (!is_object($buf)) {
                return 'UserGroup "' . $group_ . '" does not exist';
            }
            break;
    }
    return true;
}
コード例 #14
0
 public function checkPendingSession($session_)
 {
     $sessions = Abstract_Session::getByUser($session_->user_login);
     foreach ($sessions as $i => $session) {
         if ($session->id == $session_->id) {
             unset($sessions[$i]);
             continue;
         }
     }
     if (count($sessions) != 1) {
         return true;
     }
     $session = reset($sessions);
     if ($session->need_creation == 0) {
         return true;
     }
     // Start the creation
     try {
         $sessionManagement = SessionManagement::getInstance();
     } catch (Exception $err) {
         Logger::error('main', "SessionStatusChangedPendingSessionCreation:: Failed to get SessionManagement instance");
         return false;
     }
     if (!$sessionManagement->initialize()) {
         Logger::error('main', "SessionStatusChangedPendingSessionCreation:: SessionManagement initialization failed");
         return false;
     }
     $userDB = UserDB::getInstance();
     $user = $userDB->import($session->user_login);
     if (!is_object($user)) {
         Logger::error('main', 'SessionStatusChangedPendingSessionCreation:: Unable to import a valid user with login "' . $session->user_login . '"');
         return false;
     }
     $sessionManagement->user = $user;
     if (!$sessionManagement->prepareSession($session)) {
         Logger::error('main', "SessionStatusChangedPendingSessionCreation:: SessionManagement initialization failed");
         return false;
     }
     // prepareSession can take some time
     $session = Abstract_Session::load($session->id);
     $session->need_creation = 0;
     Abstract_Session::save($session);
     return true;
 }
コード例 #15
0
ファイル: server_monitoring.php プロジェクト: skdong/nfs-ovd
     $server = Abstract_Server::load($ret['server']);
     if (!$server) {
         continue;
     }
     $server->deleteNetworkFolder($share['id'], true);
     continue;
 }
 $modified = false;
 switch ($share['status']) {
     case NetworkFolder::NF_STATUS_ACTIVE:
         $disabled = 0;
         foreach ($share['users'] as $user) {
             if (in_array($user, $disabled_users)) {
                 continue;
             }
             $sessions = Abstract_Session::getByFSUser($user);
             if (count($sessions) == 0) {
                 $server = Abstract_Server::load($ret['server']);
                 if (!$server) {
                     continue;
                 }
                 if ($server->orderFSAccessDisable($user)) {
                     $disabled += 1;
                     $disabled_users[] = $user;
                 }
             }
         }
         if ($disabled == count($share['users'])) {
             $share['status'] = NetworkFolder::NF_STATUS_INACTIVE;
         }
         break;
コード例 #16
0
 public static function delete($fqdn_)
 {
     Logger::debug('main', 'Starting Abstract_Server::delete for \'' . $fqdn_ . '\'');
     if (substr($fqdn_, -1) == '.') {
         $fqdn_ = substr($fqdn_, 0, strlen($fqdn_) - 1);
     }
     $SQL = SQL::getInstance();
     $fqdn = $fqdn_;
     $SQL->DoQuery('SELECT 1 FROM @1 WHERE @2 = %3 LIMIT 1', $SQL->prefix . 'servers', 'fqdn', $fqdn);
     $total = $SQL->NumRows();
     if ($total == 0) {
         Logger::error('main', "Abstract_Server::delete({$server_}) server does not exist (NumRows == 0)");
         return false;
     }
     $sessions_liaisons = Abstract_Liaison::load('ServerSession', $fqdn_, NULL);
     foreach ($sessions_liaisons as $sessions_liaison) {
         $session = Abstract_Session::load($sessions_liaison->group);
         if (!$session) {
             continue;
         }
         $session->orderDeletion(true, Session::SESSION_END_STATUS_SERVER_DELETED);
     }
     Abstract_Liaison::delete('ServerSession', $fqdn_, NULL);
     $a_server = Abstract_Server::load($fqdn_);
     $roles = $a_server->getAttribute('roles');
     if (is_array($roles)) {
         foreach ($roles as $a_role) {
             Abstract_Server::removeRole($fqdn_, $a_role);
         }
     }
     $SQL->DoQuery('DELETE FROM @1 WHERE @2 = %3', $SQL->prefix . 'servers_properties', 'fqdn', $fqdn);
     $SQL->DoQuery('DELETE FROM @1 WHERE @2 = %3 LIMIT 1', $SQL->prefix . 'servers', 'fqdn', $fqdn);
     return true;
 }
コード例 #17
0
ファイル: reporting.php プロジェクト: skdong/nfs-ovd
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);
}
コード例 #18
0
ファイル: can_update.php プロジェクト: bloveing/openulteo
 * 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 (!defined('STDIN')) {
    echo "This script cannot be used in CGI mode.\n";
    exit(1);
}
// Check if session manager is in maintenance
try {
    $prefs = new Preferences_admin();
} catch (Exception $e) {
    echo "Internal error while loading settings, unable to continue.\n";
    exit(2);
}
if ($prefs->isValid() !== true) {
    // First install
    exit(0);
}
$system_in_maintenance = $prefs->get('general', 'system_in_maintenance');
if ($system_in_maintenance != '1') {
    echo "The Session Manager is in production mode. It's not possible to perform an upgrade until it's on maintenance mode.\n";
    exit(3);
}
// Check if there still have sessions
$nb_sessions = Abstract_Session::countByStatus();
if ($nb_sessions != 0) {
    echo "There are running sessions on the OVD farm. It's not possible to perform an upgrade until there are running sessions\n";
    exit(4);
}
exit(0);
コード例 #19
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;
 }
コード例 #20
0
 public static function delete($id_)
 {
     Logger::debug('main', 'Starting Abstract_Server::delete for \'' . $id_ . '\'');
     $SQL = SQL::getInstance();
     $SQL->DoQuery('SELECT 1 FROM #1 WHERE @2 = %3 LIMIT 1', self::table, 'id', $id_);
     $total = $SQL->NumRows();
     if ($total == 0) {
         Logger::error('main', "Abstract_Server::delete({$id_}) server does not exist (NumRows == 0)");
         return false;
     }
     $sessions_liaisons = Abstract_Liaison::load('ServerSession', $id_, NULL);
     foreach ($sessions_liaisons as $sessions_liaison) {
         $session = Abstract_Session::load($sessions_liaison->group);
         if (!$session) {
             continue;
         }
         $session->orderDeletion(true, Session::SESSION_END_STATUS_SERVER_DELETED);
     }
     Abstract_Liaison::delete('ServerSession', $id_, NULL);
     $a_server = Abstract_Server::load($id_);
     $roles = $a_server->getAttribute('roles');
     if (is_array($roles)) {
         foreach ($roles as $a_role => $role_enabled) {
             Abstract_Server::removeRole($id_, $a_role);
         }
     }
     $SQL->DoQuery('DELETE FROM #1 WHERE @2 = %3', self::table_properties, 'server', $id_);
     $SQL->DoQuery('DELETE FROM #1 WHERE @2 = %3 LIMIT 1', self::table, 'id', $id_);
     return true;
 }
コード例 #21
0
ファイル: mimetype-icon.php プロジェクト: bloveing/openulteo
    $node->setAttribute('id', $errno_);
    $node->setAttribute('message', $errstr_);
    $dom->appendChild($node);
    Logger::error('main', "(client/mimetype-icon) return_error({$errno_}, {$errstr_})");
    return $dom->saveXML();
}
if (!array_key_exists('id', $_GET)) {
    echo return_error(1, 'Usage: missing "id" $_GET parameter');
    die;
}
$prefs = Preferences::getInstance();
$web_interface_settings = $prefs->get('general', 'web_interface_settings');
if (array_key_exists('public_webservices_access', $web_interface_settings) && $web_interface_settings['public_webservices_access'] == 1) {
    // ok
} elseif (array_key_exists('session_id', $_SESSION)) {
    $session = Abstract_Session::load($_SESSION['session_id']);
    if (!$session) {
        echo return_error(3, 'No such session "' . $_SESSION['session_id'] . '"');
        die;
    }
    /*if (! in_array($_GET['id'], $session->applications)) {
    		echo return_error(4, 'Unauthorized application');
    		die();
    	}*/
} else {
    Logger::debug('main', '(client/applications) No Session id nor public_webservices_access');
    echo return_error(7, 'No Session id nor public_webservices_access');
    die;
}
$applicationDB = ApplicationDB::getInstance();
$applications = $applicationDB->getApplicationsWithMimetype($_GET['id']);
コード例 #22
0
 public function prepareWebappsAccess($session_)
 {
     if (!array_key_exists(Server::SERVER_ROLE_WEBAPPS, $session_->servers)) {
         return true;
     }
     $prepare_servers = array();
     foreach ($session_->servers[Server::SERVER_ROLE_WEBAPPS] as $server_id => $data) {
         $prepare_servers[] = $server_id;
     }
     $user_login_webapps = $session_->settings['webapps_access_login'];
     $user_password_webapps = $session_->settings['webapps_access_password'];
     $count_prepare_servers = 0;
     foreach ($prepare_servers as $prepare_server) {
         $count_prepare_servers++;
         $server = Abstract_Server::load($prepare_server);
         if (!$server) {
             continue;
         }
         if (!array_key_exists(Server::SERVER_ROLE_WEBAPPS, $server->getRoles())) {
             continue;
         }
         $dom = new DomDocument('1.0', 'utf-8');
         $session_node = $dom->createElement('session');
         $session_node->setAttribute('id', $session_->id);
         $session_node->setAttribute('mode', Session::MODE_APPLICATIONS);
         $user_node = $dom->createElement('user');
         $user_node->setAttribute('login', $user_login_webapps);
         $user_node->setAttribute('password', $user_password_webapps);
         $user_node->setAttribute('USER_LOGIN', $_POST['login']);
         $user_node->setAttribute('USER_PASSWD', $_POST['password']);
         $user_node->setAttribute('displayName', $this->user->getAttribute('displayname'));
         $session_node->appendChild($user_node);
         $applications_node = $dom->createElement('applications');
         foreach ($session_->getPublishedApplications() as $application) {
             if ($application->getAttribute('type') != 'webapp') {
                 continue;
             }
             $application_node = $dom->createElement('application');
             $application_node->setAttribute('id', $application->getAttribute('id'));
             $application_node->setAttribute('type', 'webapp');
             $application_node->setAttribute('name', $application->getAttribute('name'));
             $applications_node->appendChild($application_node);
         }
         $session_node->appendChild($applications_node);
         $dom->appendChild($session_node);
         $this->appendToSessionCreateXML($dom);
         $xml = $dom->saveXML();
         $ret_xml = query_url_post_xml($server->getBaseURL() . '/webapps/session/create', $xml);
         $ret = $this->parseSessionCreate($ret_xml);
         if (!$ret) {
             Logger::critical('main', 'SessionManagement::prepareWebappsAccess - Unable to create Session \'' . $session_->id . '\' for User \'' . $session_->user_login . '\' on Server \'' . $server->fqdn . '\', aborting');
             $session_->orderDeletion(true, Session::SESSION_END_STATUS_ERROR);
             return false;
         }
         $ret_dom = new DomDocument('1.0', 'utf-8');
         $ret_buf = @$ret_dom->loadXML($ret_xml);
         $node = $ret_dom->getElementsByTagname('session')->item(0);
         $webapps_url = $node->getAttribute('webapps-scheme') . '://' . $server->getExternalName() . ':' . $node->getAttribute('webapps-port');
         $session_->settings['webapps-url'] = $webapps_url;
         // Make sure that session object is uptodate
         $buf = Abstract_Session::load($session_->id);
         $buf->setServerStatus($server->id, Session::SESSION_STATUS_READY, NULL, Server::SERVER_ROLE_WEBAPPS);
         $buf->settings['webapps-url'] = $webapps_url;
         Abstract_Session::save($buf);
     }
     return true;
 }
コード例 #23
0
ファイル: index.php プロジェクト: skdong/nfs-ovd
</div>
</div>
		</td>
		<td style="width: 20px;">
		</td>
		<td style="padding-right: 20px; text-align: left; vertical-align: top;">
<div class="container rounded" style="background: #eee; width: 99%; margin-left: auto; margin-right: auto;">
<div>
	<h2><?php 
echo _('Status');
?>
</h2>
<?php 
if ($show_status) {
    echo '<ul>';
    $count_active_sessions = Abstract_Session::countByStatus(Session::SESSION_STATUS_ACTIVE);
    $online_servers = Abstract_Server::load_by_status(Server::SERVER_STATUS_ONLINE);
    $count_online_servers = count($online_servers);
    $offline_servers = Abstract_Server::load_by_status(Server::SERVER_STATUS_OFFLINE);
    $count_offline_servers = count($offline_servers);
    $broken_servers = Abstract_Server::load_by_status(Server::SERVER_STATUS_BROKEN);
    $count_broken_servers = count($broken_servers);
    echo '<li>';
    echo $count_active_sessions . ' ';
    echo '<a href="sessions.php">';
    if ($count_active_sessions > 1) {
        echo _('active sessions');
    } else {
        echo _('active session');
    }
    echo '</a>';
コード例 #24
0
ファイル: remote_apps.php プロジェクト: bloveing/openulteo
    return $dom->saveXML();
}
if (!array_key_exists('token', $_REQUEST)) {
    echo return_error(1, 'Usage: missing "token" $_REQUEST parameter');
    die;
}
$token = Abstract_Token::load($_REQUEST['token']);
if (!$token) {
    echo return_error(2, 'No such token: ' . $_REQUEST['token']);
    die;
}
if ($token->type != 'external_apps') {
    echo return_error(3, 'Token "' . $_REQUEST['token'] . '" is invalid');
    die;
}
$session = Abstract_Session::load($token->link_to);
if (!$session) {
    echo return_error(4, 'No such session: ' . $token->link_to);
    die;
}
$userDB = UserDB::getInstance();
$user = $userDB->import($session->user_login);
if (!is_object($user)) {
    echo return_error(5, 'No such user: '******'session_id', $_SESSION)) {
    $_SESSION['session_id'] = $session->id;
}
header('Content-Type: text/xml; charset=utf-8');
$dom = new DomDocument('1.0', 'utf-8');
コード例 #25
0
ファイル: session_status.php プロジェクト: bloveing/openulteo
        $ret['reason'] = $node->getAttribute('reason');
    }
    if ($node->hasAttribute('role')) {
        $ret['role'] = $node->getAttribute('role');
    }
    return $ret;
}
$ret = parse_session_status_XML(@file_get_contents('php://input'));
if (!$ret) {
    Logger::error('main', '(webservices/session/status) Server does not send a valid XML (error_code: 1)');
    webservices_return_error(1, 'Server does not send a valid XML');
}
$server = webservices_load_server($_SERVER['REMOTE_ADDR']);
if (is_null($server)) {
    Logger::error('main', '(webservices/session/status) Server does not exist (error_code: 2)');
    webservices_return_error(2, 'Server does not exist');
}
$session = Abstract_Session::load($ret['id']);
if (!$session) {
    Logger::error('main', '(webservices/session/status) Session does not exist (error_code: 2)');
    webservices_return_error(2, 'Session does not exist');
}
$session->setServerStatus($server->id, $ret['status'], $ret['reason'], $ret['role']);
header('Content-Type: text/xml; charset=utf-8');
$dom = new DomDocument('1.0', 'utf-8');
$node = $dom->createElement('session');
$node->setAttribute('id', $session->id);
$node->setAttribute('status', $session->status);
$dom->appendChild($node);
echo $dom->saveXML();
exit(0);
コード例 #26
0
ファイル: Server.class.php プロジェクト: skdong/nfs-ovd
 public function getNbUsedSessions()
 {
     $buf = Abstract_Session::countByServer($this->fqdn);
     return $buf;
 }
コード例 #27
0
ファイル: hourly.php プロジェクト: bloveing/openulteo
    if (!is_array($groups)) {
        Logger::error('main', '(hourly cron) UserGroupDBDynamic_cached->getList() failed');
    } else {
        foreach ($groups as $a_group) {
            $ret = $ugdbdc->updateCache($a_group);
            if ($ret !== true) {
                Logger::error('main', '(hourly cron) UserGroupDBDynamic_cached->updateCache for group \'' . $a_group->getUniqueID() . '\' failed');
            }
        }
    }
}
//END UserGroupDBDynamic_cached update
//BEGIN Sessions time restriction
$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 (!in_array($session->status, array(Session::SESSION_STATUS_CREATING, Session::SESSION_STATUS_CREATED, Session::SESSION_STATUS_INIT, Session::SESSION_STATUS_READY, Session::SESSION_STATUS_ACTIVE))) {
        continue;
    }
    $userDB = UserDB::getInstance();
    $user = $userDB->import($session->user_login);
    if (!is_object($user)) {
        // ???
        continue;
    }
    if ($user->can_use_session()) {
        continue;
    }
コード例 #28
0
function server_display_role_aps($server, $var)
{
    $can_do_action = $var['can_do_action'];
    $can_use_apt = $var['can_use_apt'];
    $server_online = $var['server_online'];
    $applications = $var['applications'];
    $applications_available = $var['applications_available'];
    $applications_all = $var['applications_all'];
    $servers_all = $var['servers_all'];
    $servers_replication = $var['servers_replication'];
    $has_sessions = $var['has_sessions'];
    $sessions = $var['sessions'];
    $total = $var['total_sessions'];
    if (array_key_exists('pagechanger', $var)) {
        $pagechanger = $var['pagechanger'];
    }
    $tasks = array();
    $apps_in_remove = array();
    $apps_in_install = array();
    if ($server_online) {
        $tasks = $var['tasks'];
        $apps_in_install = $var['apps_in_install'];
        $apps_in_remove = $var['apps_in_remove'];
    }
    // 	if ($server->type == 'windows' && isset($server->windows_domain) && ! is_null($server->windows_domain)) {
    // 		echo '<tr><td>';
    // 		echo _('Inside Active Directory domain').': ';
    // 		echo '</td><td>';
    // 		echo $server->windows_domain;
    // 		echo '</td></tr>';
    // 	}
    echo '<table>';
    echo '<tr><td>';
    echo _('Number of available sessions on this server') . ': ';
    echo '</td><td>';
    if ($can_do_action) {
        echo '<form action="actions.php" method="post">';
        echo '<input type="hidden" name="name" value="Server" />';
        echo '<input type="hidden" name="fqdn" value="' . $server->fqdn . '" />';
        echo '<input type="hidden" name="action" value="available_sessions" />';
        echo '<input type="button" value="-" onclick="field_increase(\'number\', -1);" /> ';
    }
    echo '<input type="text" id="number" name="max_sessions" value="' . $server->getNbMaxSessions() . '" size="3" onchange="field_check_integer(this);" />';
    if ($var['can_do_action']) {
        echo ' <input type="button" value="+" onclick="field_increase(\'number\', 1);" />';
        echo ' <input type="button" value="' . _('default') . '" onclick="$(\'number\').value=\'' . $server->getDefaultMaxSessions() . '\';" />';
        echo ' <input type="submit" value="' . _('change') . '" />';
        echo '</form>';
    }
    echo '</td></tr>';
    echo '</table>';
    if ($server_online && $can_do_action && $can_use_apt) {
        echo '<div class="section">';
        echo '<h2>' . _('Install an application') . '</h2>';
        echo '<form action="actions.php" method="post">';
        echo '<input type="hidden" name="name" value="Server" />';
        echo '<input type="hidden" name="action" value="install_line">';
        echo '<input type="hidden" name="fqdn" value="' . $server->fqdn . '">';
        echo '<input type="text" name="line"> ';
        echo '<input type="submit" value="' . _('Install from a package name') . '">';
        echo '</form>';
        echo '<br />';
        echo '<div id="installableApplicationsList">';
        echo '<a href="javascript:;" onclick="toggleInstallableApplicationsList(\'' . $server->fqdn . '\'); return false;"><div style="width: 16px; height: 16px; float: left;" id="installableApplicationsList_ajax"></div></a><div style="float: left;"><a href="javascript:;" onclick="toggleInstallableApplicationsList(\'' . $server->fqdn . '\'); return false;">&nbsp;' . _('more options') . '</a></div>';
        echo '<div style="clear: both;"></div>';
        echo '<div id="installableApplicationsList_content" style="display: none;"><script type="text/javascript">Event.observe(window, \'load\', function() { offContent(\'installableApplicationsList\'); });</script></div>';
        echo '</div>';
        echo '<div id="installableApplicationsListDefault" style="display: none; visibility: hidden;">';
        echo '<form action="actions.php" method="post">';
        echo '<input type="hidden" name="name" value="Server" />';
        echo '<input type="hidden" name="action" value="install_line">';
        echo '<input type="hidden" name="fqdn" value="' . $server->fqdn . '">';
        echo '<table>';
        echo '<tr>';
        echo '<td>' . _('Category') . '</td>';
        echo '<td><div id="installable_applications_category"></div></td>';
        echo '<td></td>';
        echo '</tr>';
        echo '<tr>';
        echo '<td>' . _('Application') . '</td>';
        echo '<td><div id="installable_applications_application"></div></td> ';
        echo '<td><input type="submit" value="' . _('Install') . '" /></td>';
        echo '<td></td>';
        echo '</tr>';
        echo '</table>';
        echo '</form>';
        echo '</div>';
        echo '</div>';
        echo '<div class="section">';
        echo '<h2>' . _('Upgrade') . '</h2>';
        echo '<form action="actions.php" method="post">';
        echo '<input type="hidden" name="name" value="Server" />';
        echo '<input type="hidden" name="action" value="upgrade">';
        echo '<input type="hidden" name="fqdn" value="' . $server->fqdn . '">';
        echo '<input type="submit" value="' . _('Upgrade the internal system and applications') . '">';
        echo '</form>';
        echo '</div>';
    }
    // Application part
    if (count($applications_all) > 0) {
        $count = 0;
        echo '<div class="section">';
        echo '<h2>' . _('Applications available on this server') . '</h2>';
        echo '<table border="0" cellspacing="1" cellpadding="3">';
        if (count($applications) > 0) {
            foreach ($applications as $app) {
                $content = 'content' . ($count++ % 2 == 0 ? 1 : 2);
                $remove_in_progress = in_array($app, $apps_in_remove);
                echo '<tr class="' . $content . '">';
                echo '<td>';
                echo '<img src="media/image/cache.php?id=' . $app->getAttribute('id') . '" alt="" title="" /> ';
                echo '<a href="applications.php?action=manage&id=' . $app->getAttribute('id') . '">';
                echo $app->getAttribute('name') . '</a>';
                echo '</td>';
                if ($server_online && $can_do_action && $can_use_apt) {
                    echo '<td>';
                    if ($remove_in_progress) {
                        echo 'remove in progress';
                    } else {
                        echo '<form action="actions.php" method="post" onsubmit="return confirm(\'' . _('Are you sure you want to remove this application from this server?') . '\');">';
                        echo '<input type="hidden" name="action" value="del" />';
                        echo '<input type="hidden" name="name" value="Application_Server" />';
                        echo '<input type="hidden" name="server" value="' . $server->fqdn . '" />';
                        echo '<input type="hidden" name="application" value="' . $app->getAttribute('id') . '" />';
                        echo '<input type="submit" value="' . _('Remove from this server') . '" />';
                        echo '</form>';
                    }
                }
                echo '</td>';
                echo '</tr>';
            }
        }
        foreach ($apps_in_install as $app) {
            $content = 'content' . ($count++ % 2 == 0 ? 1 : 2);
            echo '<tr class="' . $content . '">';
            echo '<td>';
            echo '<a href="applications.php?action=manage&id=' . $app->getAttribute('id') . '">';
            echo $app->getAttribute('name') . '</a>';
            echo '</td>';
            echo '<td>' . _('install in progress') . '</td>';
            echo '</tr>';
        }
        if (count($applications_available) > 0 && $can_do_action && $can_use_apt) {
            $content = 'content' . ($count++ % 2 == 0 ? 1 : 2);
            echo '<tr class="' . $content . '"><form action="actions.php" method="post">';
            echo '<input type="hidden" name="action" value="add" />';
            echo '<input type="hidden" name="name" value="Application_Server" />';
            echo '<input type="hidden" name="server" value="' . $server->fqdn . '" />';
            echo '<td>';
            echo '<select name="application">';
            foreach ($applications_available as $app) {
                echo '<option value="' . $app->getAttribute('id') . '">' . $app->getAttribute('name') . '</option>';
            }
            echo '</select>';
            echo '</td>';
            echo '<td><input type="submit" value="' . _('Install on this server') . '" /></td>';
            echo '</form></tr>';
        }
        echo '</table>';
        echo "</div>\n";
    }
    // Server Replication part
    if (count($servers_replication) > 0 && $can_use_apt && $can_do_action) {
        echo '<div class="section">';
        // div replication
        echo '<h2>' . _('Replication') . '</h2>';
        echo '<form action="actions.php" method="post">';
        echo '<input type="hidden" name="name" value="Server" />';
        echo '<input type="hidden" name="action" value="replication" />';
        echo '<input type="hidden" name="fqdn" value="' . $server->fqdn . '" />';
        echo '<table border="0" cellspacing="1" cellpadding="3">';
        foreach ($servers_replication as $server_) {
            echo '<tr>';
            echo '<td><input class="input_checkbox" type="checkbox" name="servers[]" value="' . $server_->fqdn . '" /></td>';
            echo '<td><a href="servers.php?action=manage&fqdn=' . $server_->fqdn . '">' . $server_->fqdn . '</a></td></tr>';
        }
        echo '<tr><td></td><td><input type="submit" value="' . _('Replicate on those servers') . '" /></td></tr>';
        echo '</table>';
        echo '</form>';
        echo "</div>";
        // div replication
    }
    // Tasks part
    if (count($tasks) > 0) {
        echo '<div class="section">';
        // div tasks
        echo '<h2>' . _('Active tasks on this server') . '</h2>';
        echo '<table border="0" cellspacing="1" cellpadding="3">';
        echo '<tr class="title">';
        echo '<th>' . _('ID') . '</th>';
        echo '<th>' . _('Type') . '</th>';
        echo '<th>' . _('Status') . '</th>';
        echo '<th>' . _('Details') . '</th>';
        echo '</tr>';
        $count = 0;
        foreach ($tasks as $task) {
            $content = 'content' . ($count++ % 2 == 0 ? 1 : 2);
            if ($task->failed()) {
                $status = '<span class="msg_error">' . _('Error') . '</span>';
            } else {
                $status = '<span class="msg_ok">' . $task->status . '</span>';
            }
            echo '<tr class="' . $content . '">';
            echo '<td><a href="tasks.php?action=manage&id=' . $task->id . '">' . $task->id . '</a></td>';
            echo '<td>' . get_class($task) . '</td>';
            echo '<td>' . $status . '</td>';
            echo '<td>' . $task->getRequest() . '</td>';
            echo '</tr>';
        }
        echo '</table>';
        echo "</div>";
        // div tasks
    }
    // Sessions part
    if ($has_sessions) {
        echo '<div>';
        // div 1 has_sessions
        $total = Abstract_Session::countByServer($server->fqdn);
        echo '<h2>' . sprintf(_('Active sessions (total: %s)'), $total) . '</h2>';
        echo '<div>';
        if (isset($pagechanger)) {
            echo $pagechanger;
        }
        echo '<table border="0" cellspacing="1" cellpadding="3">';
        foreach ($sessions as $session) {
            echo '<form action="sessions.php"><tr>';
            echo '<td>';
            $buf = $session->getAttribute('start_time');
            if (!$buf) {
                echo _('Not started yet');
            } else {
                echo @date('d/m/Y H:i:s', $session->getAttribute('start_time'));
            }
            echo '</td>';
            echo '<td><a href="users.php?action=manage&id=' . $session->getAttribute('user_login') . '">' . $session->getAttribute('user_displayname') . '</td>';
            echo '<td>';
            echo '<input type="hidden" name="info" value="' . $session->id . '" />';
            echo '</td><td><input type="submit" value="' . _('Information about this session') . '" /></td>';
            echo '</td>';
            echo '</tr></form>';
        }
        echo '</table>';
        if (isset($pagechanger)) {
            echo $pagechanger;
        }
        echo '</div>';
        echo '</div>';
    }
}