public static function create_from_server_report($server_id_, $xml_input_)
 {
     $server = Abstract_Server::load($server_id_);
     if ($server === false) {
         return;
     }
     $external_name = $server->getExternalName();
     $dom = new DomDocument('1.0', 'utf-8');
     $dom->loadXML($xml_input_);
     if (!is_object($dom)) {
         return null;
     }
     $node = $dom->getElementsByTagName('cpu');
     if ($node->length > 0) {
         $cpu = round($node->item(0)->getAttribute('load'), 2);
     } else {
         $cpu = -1;
     }
     $node = $dom->getElementsByTagName('ram');
     if ($node->length > 0) {
         $total = (double) $server->ram_total;
         $used = (double) $node->item(0)->getAttribute('used');
         if ($total > 0) {
             $ram = round($used / $total * 100, 2);
         } else {
             $ram = 0;
         }
     } else {
         $ram = -1;
     }
     $sessions = $dom->getElementsByTagName('session');
     $apps_link = application_desktops_to_ids();
     $sessions_infos = array();
     $applications_infos = array();
     /* the interesting <session> nodes of the xml are like:
     		     <session id="ID" mode="MODE" status="STATUS" user="******">
     				<instance application="APP_ID" id="ApS_ID"/>
     			</session>
     		*/
     foreach ($sessions as $session) {
         $sessid = $session->getAttribute('id');
         $sessions_infos[$sessid] = $session->getAttribute('user');
         foreach ($session->childNodes as $instance_node) {
             if ($instance_node->tagName == 'instance') {
                 $desktop = $instance_node->getAttribute('application');
                 if (!array_key_exists($desktop, $apps_link)) {
                     continue;
                 }
                 $id = $apps_link[$desktop];
                 if (!array_key_exists($id, $applications_infos)) {
                     $applications_infos[$id] = array();
                 }
                 $applications_infos[$id][] = $sessid;
             }
         }
     }
     $data = self::infos2Xml($sessions_infos, $applications_infos);
     $report = new self(time(), $server_id_, $server->fqdn, $external_name, $cpu, $ram, $data);
     return $report;
 }
 private function compute_load()
 {
     $server = Abstract_Server::load($this->fqdn);
     if ($server === false) {
         return;
     }
     if (!is_object($this->dom)) {
         return;
     }
     $node = $this->dom->getElementsByTagName('cpu');
     if ($node->length > 0) {
         $this->cpu = round($node->item(0)->getAttribute('load'), 2);
     } else {
         $this->cpu = -1;
     }
     $node = $this->dom->getElementsByTagName('ram');
     if ($node->length > 0) {
         $total = (double) $server->ram_total;
         $used = (double) $node->item(0)->getAttribute('used');
         if ($total > 0) {
             $this->ram = round($used / $total * 100, 2);
         } else {
             $this->ram = 0;
         }
     } else {
         $this->ram = -1;
     }
 }
Exemple #3
0
/**
 * 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;
}
/**
 * Copyright (C) 2012 Ulteo SAS
 * http://www.ulteo.com
 * Author Julien LANGLOIS <*****@*****.**>
 *
 * 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 webservices_load_server($addr_)
{
    $server = null;
    // First, try to detect the server using the reverse DNS resolution
    $reverse = @gethostbyaddr($addr_);
    if ($reverse !== false && $reverse != $addr_) {
        $server = Abstract_Server::load_by_fqdn($reverse);
    }
    if (is_null($server)) {
        // Then, try to detect the server using the source IP address
        $server = Abstract_Server::load_by_fqdn($addr_);
    }
    return $server;
}
function do_create_task($fqdn_)
{
    $server = Abstract_Server::load($fqdn_);
    if (!is_object($server)) {
        Logger::error('main', '(ajax/installable_applications) Server ' . $fqdn_ . ' not found');
        header('Content-Type: text/xml; charset=utf-8');
        $dom = new DomDocument('1.0', 'utf-8');
        $node = $dom->createElement('usage');
        $node->setAttribute('status', 'server not found');
        $dom->appendChild($node);
        die($dom->saveXML());
    }
    $task = new Task_available_applications('', $fqdn_);
    $manager = new Tasks_Manager();
    $manager->add($task);
    header('Content-Type: text/xml; charset=utf-8');
    $dom = new DomDocument('1.0', 'utf-8');
    $node = $dom->createElement('task');
    $node->setAttribute('id', $task->id);
    $dom->appendChild($node);
    die($dom->saveXML());
}
Exemple #6
0
        $server->locked = false;
    }
    $server->external_name = $server->fqdn;
    $server->max_sessions = 20;
    /*
    	if (! $server->isAuthorized()) {
    		echo return_error(1, 'Server is not authorized');
    		die();
    	}
    
    	if (! $server->isOnline()) {
    		echo return_error(2, 'Server is not OK');
    		die();
    	}
    
    	if (! $server->isOK()) {
    		echo return_error(3, 'Server is not online');
    		die();
    	}
    */
    Abstract_Server::save($server);
} else {
    $server = Abstract_Server::load($server_name);
}
header('Content-Type: text/xml; charset=utf-8');
$dom = new DomDocument('1.0', 'utf-8');
$node = $dom->createElement('server');
$node->setAttribute('name', $server->fqdn);
$dom->appendChild($node);
echo $dom->saveXML();
exit(0);
Exemple #7
0
    die;
}
if (!$server->isAuthorized()) {
    echo return_error(3, 'Server is not authorized');
    die;
}
$old_roles = $server->getAttribute('roles');
if ($ret['status'] == Server::SERVER_STATUS_ONLINE) {
    if (!$server->getConfiguration()) {
        echo return_error(4, 'Server does not send a valid configuration');
        die;
    }
}
// check if server's roles have been changes
$new_roles = $server->getAttribute('roles');
foreach ($old_roles as $a_role => $enable) {
    if (array_key_exists($a_role, $new_roles) == false) {
        // the server has not anymore the role
        Abstract_Server::removeRole($server->getAttribute('fqdn'), $a_role);
    }
}
$server->setStatus($ret['status']);
Abstract_Server::save($server);
header('Content-Type: text/xml; charset=utf-8');
$dom = new DomDocument('1.0', 'utf-8');
$node = $dom->createElement('server');
$node->setAttribute('name', $server->fqdn);
$node->setAttribute('status', $server->status);
$dom->appendChild($node);
echo $dom->saveXML();
exit(0);
Exemple #8
0
    $application_node = $dom->getElementsByTagName('application')->item(0);
    if (is_null($application_node)) {
        return false;
    }
    if (!$application_node->hasAttribute('id')) {
        return false;
    }
    $ret['application']['id'] = $application_node->getAttribute('id');
    return $ret;
}
$ret = parse_icon_XML(@file_get_contents('php://input'));
if (!$ret) {
    echo return_error(1, 'Server does not send a valid XML');
    die;
}
$server = Abstract_Server::load($ret['server']);
if (!$server) {
    echo return_error(2, 'Server does not exist');
    die;
}
if (!$server->isAuthorized()) {
    echo return_error(3, 'Server is not authorized');
    die;
}
$applicationDB = ApplicationDB::getInstance();
$app = $applicationDB->import($ret['application']['id']);
if (!is_object($app)) {
    echo return_error(4, 'No such application "' . $ret['application']['id'] . '"');
    die;
}
$path = $app->getIconPath();
Exemple #9
0
function action_del_sharedfolder($sharedfolder_id)
{
    $sharedfolderdb = SharedFolderDB::getInstance();
    $sharedfolder = $sharedfolderdb->import($sharedfolder_id);
    if (!$sharedfolder) {
        popup_error(_('Unable to delete this shared folder'));
        return false;
    }
    $a_server = Abstract_Server::load($sharedfolder->server);
    if (!$a_server) {
        popup_error(sprintf(_("Unable to delete shared folder on file server '%s'"), $sharedfolder->server));
        return false;
    }
    if ($sharedfolder->isUsed()) {
        popup_error(sprintf(_("Unable to delete shared folder '%s' because it is currently being used"), $sharedfolder->name));
        return false;
    }
    $ret = $a_server->deleteNetworkFolder($sharedfolder->id);
    if (!$ret) {
        popup_error(sprintf(_("Unable to delete shared folder on file server '%s'"), $sharedfolder->server));
        return false;
    }
    $buf = $sharedfolderdb->remove($sharedfolder);
    if (!$buf) {
        popup_error(_('Unable to delete this shared folder'));
        return false;
    }
    popup_info(_('Shared folder successfully deleted'));
    return true;
}
 private static function session2Xml($session_)
 {
     $dom = new DomDocument('1.0', 'utf-8');
     $dom->formatOutput = true;
     $session_node = $dom->createElement('session');
     $dom->appendChild($session_node);
     $session_node->setAttribute('id', $session_->id);
     $session_node->setAttribute('mode', $session_->mode);
     $user_node = $dom->createElement('user');
     $session_node->appendChild($user_node);
     $user_node->setAttribute('login', $session_->user_login);
     $user_node->setAttribute('display_name', $session_->user_displayname);
     // Begin session servers part
     $servers_node = $dom->createElement('servers');
     $session_node->appendChild($servers_node);
     $storage_resources = array();
     foreach ($session_->servers as $role => $servers) {
         foreach ($servers as $server_id => $data) {
             $server_node = $dom->createElement('server');
             $servers_node->appendChild($server_node);
             $server_node->setAttribute('id', $server_id);
             $server_node->setAttribute('role', $role);
             if ($session_->mode == Session::MODE_DESKTOP && $session_->server == $server_id) {
                 $server_node->setAttribute('desktop_server', 'true');
             }
             if (array_key_exists('dump', $data)) {
                 foreach ($data['dump'] as $name => $dump) {
                     $node = $dom->createElement('dump');
                     $node->setAttribute('name', $name);
                     $server_node->appendChild($node);
                     $textNode = $dom->createTextNode($dump);
                     $node->appendChild($textNode);
                 }
             }
             $server = Abstract_Server::load($server_id);
             if (!$server || $server->getAttribute('registered') === false) {
                 continue;
             }
             $server_node->setAttribute('fqdn', $server->fqdn);
             $server_node->setAttribute('type', $server->type);
             if ($role == Server::SERVER_ROLE_FS) {
                 foreach ($data as $i => $info) {
                     $storage_resource = array('rid' => $info['rid'], 'type' => $info['type'], 'server_id' => $server_id, 'server_name' => $server->getDisplayName());
                     if ($info['type'] == 'sharedfolder') {
                         $storage_resource['name'] = $info['name'];
                         $storage_resource['mode'] = $info['mode'];
                     }
                     $storage_resources[$storage_resource['rid']] = $storage_resource;
                 }
             }
         }
     }
     // Finish session servers part
     // Start storage part
     $storages_node = $dom->createElement('storages');
     $session_node->appendChild($storages_node);
     foreach ($storage_resources as $storage_rid => $storage) {
         $node = $dom->createElement('storage');
         $storages_node->appendChild($node);
         foreach ($storage as $k => $v) {
             $node->setAttribute($k, $v);
         }
     }
     // Finish storage part
     $applications = $dom->createElement('published_applications');
     $session_node->appendChild($applications);
     foreach ($session_->getPublishedApplications() as $application_id => $application) {
         $app_node = $dom->createElement('application');
         $applications->appendChild($app_node);
         $app_node->setAttribute('id', $application_id);
         $app_node->setAttribute('name', $application->getAttribute('name'));
     }
     $apps_instances_node = $dom->createElement('applications_instances');
     $session_node->appendChild($apps_instances_node);
     foreach ($session_->getClosedApplications() as $instance_id => $instance) {
         $node = $dom->createElement('instance');
         $apps_instances_node->appendChild($node);
         $node->setAttribute('id', $instance_id);
         $node->setAttribute('application', $instance['application']);
         $node->setAttribute('server', $instance['server']);
         $node->setAttribute('start', $instance['start']);
         $node->setAttribute('stop', $instance['stop']);
     }
     foreach ($session_->getRunningApplications() as $instance_id => $instance) {
         $node = $dom->createElement('instance');
         $apps_instances_node->appendChild($node);
         $node->setAttribute('id', $instance_id);
         $node->setAttribute('application', $instance['application']);
         $node->setAttribute('server', $instance['server']);
         $node->setAttribute('start', $instance['start']);
         $node->setAttribute('stop', time());
     }
     return $dom->saveXML();
 }
Exemple #11
0
function show_default($tm)
{
    $servers_ = Abstract_Server::load_by_status(Server::SERVER_STATUS_ONLINE);
    $servers = array();
    foreach ($servers_ as $server) {
        if (isset($server->ulteo_system) && $server->ulteo_system == 1) {
            $servers[] = $server;
        }
    }
    $can_do_action = isAuthorized('manageServers');
    page_header();
    echo '<div id="tasks_div">';
    echo '<h1>' . _('Tasks') . '</h1>';
    if (count($tm->tasks) > 0) {
        echo '<div id="tasks_list_div">';
        echo '<h2>' . _('List of tasks') . '</h2>';
        echo '<table class="main_sub sortable" id="tasks_list_table" border="0" cellspacing="1" cellpadding="5">';
        echo '<thead>';
        echo '<tr class="title">';
        echo '<th>' . _('ID') . '</th>';
        echo '<th>' . _('Creation time') . '</th>';
        echo '<th>' . _('Type') . '</th>';
        echo '<th>' . _('Server') . '</th>';
        echo '<th>' . _('Status') . '</th>';
        echo '<th>' . _('Details') . '</th>';
        echo '</tr>';
        echo '</thead>';
        echo '<tbody>';
        $count = 0;
        foreach ($tm->tasks as $task) {
            $content = 'content' . ($count++ % 2 == 0 ? 1 : 2);
            $can_remove = $task->succeed() || $task->failed();
            if ($task->succeed()) {
                $status = '<span class="msg_ok">' . _('Finished') . '</span>';
            } elseif ($task->failed()) {
                $status = '<span class="msg_error">' . _('Error') . '</span>';
            } elseif ($task->status == 'in progress') {
                $status = '<span class="msg_warn">' . _('In progress') . '</span>';
            } else {
                $status = $task->status;
            }
            echo '<tr class="' . $content . '">';
            echo '<td><a href="?action=manage&id=' . $task->id . '">' . $task->id . '</a></td>';
            echo '<td>' . date('Y-m-d H:i:s', $task->t_begin) . '</td>';
            echo '<td>' . get_class($task) . '</td>';
            echo '<td><a href="servers.php?action=manage&fqdn=' . $task->server . '">' . $task->server . '</a></td>';
            echo '<td>' . $status . '</td>';
            echo '<td>' . $task->getRequest() . '</td>';
            if ($can_do_action) {
                echo '<td>';
                if ($can_remove) {
                    echo '<form action="actions.php" method="post">';
                    echo '<input type="hidden" name="name" value="Task" />';
                    echo '<input type="hidden" name="action" value="del" />';
                    echo '<input type="hidden" name="checked_tasks[]" value="' . $task->id . '" />';
                    echo '<input type="submit" value="' . _('Delete') . '" />';
                    echo '</form>';
                }
                echo '</td>';
            }
            echo '</tr>';
        }
        echo '</tbody>';
        echo '</table>';
        echo '</div>';
    }
    if (count($servers) > 0 && $can_do_action) {
        echo '<h2>' . _('Install an application from a package name') . '</h2>';
        echo '<form action="actions.php" method="post">';
        echo '<input type="hidden" name="name" value="Task" />';
        echo '<input type="hidden" name="action" value="add" />';
        echo '<select name="server">';
        foreach ($servers as $server) {
            echo '<option value="' . $server->fqdn . '">' . $server->fqdn . '</option>';
        }
        echo '</select> &nbsp; ';
        echo '<input type="text" name="request" value="" /> &nbsp; ';
        echo '<input type="hidden" name="type" value="install_from_line" />';
        echo '<input type="submit" name="submit" value="' . _('Install') . '" />';
        echo '</form>';
        echo '<h2>' . _('Upgrade the internal system and applications') . '</h2>';
        echo '<form action="actions.php" method="post">';
        echo '<input type="hidden" name="name" value="Task" />';
        echo '<input type="hidden" name="action" value="add" />';
        echo '<input type="hidden" name="type" value="upgrade" />';
        echo '<input type="hidden" name="request" value="" />';
        // hack for the task creation
        echo '<select name="server">';
        foreach ($servers as $server) {
            echo '<option value="' . $server->fqdn . '">' . $server->fqdn . '</option>';
        }
        echo '</select> &nbsp; ';
        echo '<input type="submit" name="submit" value="' . _('Upgrade') . '" />';
        echo '</form>';
    }
    echo '</div>';
    page_footer();
    die;
}
Exemple #12
0
 public function getAvailableServers($type_ = NULL)
 {
     $prefs = Preferences::getInstance();
     if (!$prefs) {
         die_error('get Preferences failed', __FILE__, __LINE__);
     }
     $default_settings = $prefs->get('general', 'session_settings_defaults');
     $launch_without_apps = (int) $default_settings['launch_without_apps'];
     $user_profile_mode = $prefs->get('UserDB', 'enable');
     $prefs_ad = $prefs->get('UserDB', 'activedirectory');
     // get the list of server who the user can launch his applications
     $slave_server_settings = $prefs->get('general', 'slave_server_settings');
     $default_settings = $prefs->get('general', 'session_settings_defaults');
     $available_servers = Abstract_Server::load_available_by_role_sorted_by_load_balancing(Server::SERVER_ROLE_APS);
     $applications = $this->applications($type_, true);
     $servers_to_use = array();
     foreach ($available_servers as $fqdn => $server) {
         if (!is_null($type_) && $server->getAttribute('type') != $type_) {
             continue;
         }
         if (count($applications) == 0) {
             break;
         }
         $applications_from_server = $server->getApplications();
         foreach ($applications_from_server as $k => $an_server_application) {
             if (in_array($an_server_application, $applications)) {
                 $servers_to_use[] = $server;
                 unset($applications[array_search($an_server_application, $applications)]);
             }
         }
     }
     $servers_to_use = array_unique($servers_to_use);
     // TODO: bug if the user have static application
     if (count($applications) == 0) {
         return $servers_to_use;
     } else {
         if ($launch_without_apps == 1) {
             return $servers_to_use;
         } else {
             $application = array_pop($applications);
             Logger::error('main', "USER::getAvailableServers() no server found for user '" . $this->getAttribute('login') . "'. User's publication are not right, at least application named '" . $application->getAttribute('name') . "' does not have an available server");
             return NULL;
         }
     }
 }
 public function prepareAPSAccess($session_)
 {
     $remote_desktop_settings = $this->user->getSessionSettings('remote_desktop_settings');
     $default_settings = $this->user->getSessionSettings('session_settings_defaults');
     $prepare_servers = array();
     # No_desktop option management
     if (isset($this->no_desktop) && $this->no_desktop === true) {
         if ($authorize_no_desktop === true) {
             $no_desktop_process = 1;
         } else {
             Logger::warning('main', 'SessionManagement::prepareAPSAccess - Cannot apply no_desktop parameter because policy forbid it');
         }
     }
     if ($default_settings['use_known_drives'] == 1) {
         $use_known_drives = 'true';
     }
     $profile_mode = $default_settings['profile_mode'];
     $use_local_ime = $session_->settings['use_local_ime'];
     $desktop_icons = $remote_desktop_settings['desktop_icons'];
     $need_valid_profile = $default_settings['start_without_profile'] == 0;
     $user_login_aps = $session_->settings['aps_access_login'];
     $user_password_aps = $session_->settings['aps_access_password'];
     $user_login_fs = $session_->settings['fs_access_login'];
     $user_password_fs = $session_->settings['fs_access_password'];
     $remote_desktop_settings = $this->user->getSessionSettings('remote_desktop_settings');
     $allow_external_applications = array_key_exists('allow_external_applications', $remote_desktop_settings) && $remote_desktop_settings['allow_external_applications'] == 1;
     if (isset($this->language)) {
         $locale = locale2unix($this->language);
     } else {
         $locale = $this->user->getLocale();
     }
     if (isset($this->timezone) && $this->timezone != '') {
         $timezone = $this->timezone;
     }
     if ($session_->mode == Session::MODE_DESKTOP) {
         $have_external_apps = false;
         if (array_key_exists(Server::SERVER_ROLE_APS, $session_->servers)) {
             $have_external_apps |= count($session_->servers[Server::SERVER_ROLE_APS]) > 1;
         }
         if (array_key_exists(Server::SERVER_ROLE_WEBAPPS, $session_->servers)) {
             $have_external_apps |= count($session_->servers[Server::SERVER_ROLE_WEBAPPS]) > 0;
         }
         if ($session_->mode == Session::MODE_DESKTOP && $allow_external_applications && $have_external_apps) {
             $external_apps_token = new Token(gen_unique_string());
             $external_apps_token->type = 'external_apps';
             $external_apps_token->link_to = $session_->id;
             $external_apps_token->valid_until = 0;
             Abstract_Token::save($external_apps_token);
         }
         $prepare_servers[] = $session_->server;
     }
     if ($session_->mode == Session::MODE_APPLICATIONS || $session_->mode == Session::MODE_DESKTOP && $allow_external_applications) {
         foreach ($session_->servers[Server::SERVER_ROLE_APS] as $server_id => $data) {
             if ($session_->mode == Session::MODE_DESKTOP && $allow_external_applications && $server_id == $session_->server) {
                 continue;
             }
             $prepare_servers[] = $server_id;
         }
     }
     $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_APS, $server->getRoles())) {
             continue;
         }
         $server_applications = $server->getApplications();
         if (!is_array($server_applications)) {
             $server_applications = array();
         }
         $available_applications = array();
         foreach ($server_applications as $server_application) {
             $available_applications[] = $server_application->getAttribute('id');
         }
         $dom = new DomDocument('1.0', 'utf-8');
         $session_node = $dom->createElement('session');
         $session_node->setAttribute('id', $session_->id);
         $session_node->setAttribute('mode', $session_->mode == Session::MODE_DESKTOP && $count_prepare_servers == 1 ? Session::MODE_DESKTOP : Session::MODE_APPLICATIONS);
         // OvdShell Configuration
         $shell_node = $dom->createElement('shell');
         $session_node->appendChild($shell_node);
         if (isset($external_apps_token)) {
             $setting_node = $dom->createElement('setting');
             $setting_node->setAttribute('name', 'external_apps_token');
             $setting_node->setAttribute('value', $external_apps_token->id);
             $shell_node->appendChild($setting_node);
         }
         if (isset($this->start_apps) && is_array($this->start_apps)) {
             $start_apps = $this->start_apps;
             $applicationDB = ApplicationDB::getInstance();
             foreach ($start_apps as $start_app) {
                 $app = $applicationDB->import($start_app['id']);
                 if (!is_object($app)) {
                     Logger::error('main', 'SessionManagement::prepareAPSAccess - No such application for id \'' . $start_app['id'] . '\'');
                     throw_response(SERVICE_NOT_AVAILABLE);
                 }
                 $apps = $session_->getPublishedApplications();
                 $ok = false;
                 foreach ($apps as $user_app) {
                     if ($user_app->getAttribute('id') == $start_app['id']) {
                         $ok = true;
                         break;
                     }
                 }
                 if ($ok === false) {
                     Logger::error('main', 'SessionManagement::prepareAPSAccess - Application not available for user \'' . $user->getAttribute('login') . '\' id \'' . $start_app['id'] . '\'');
                     return false;
                 }
             }
         }
         foreach (array('no_desktop_process', 'use_known_drives', 'profile_mode', 'use_local_ime') as $parameter) {
             if (!isset(${$parameter})) {
                 continue;
             }
             $setting_node = $dom->createElement('setting');
             $setting_node->setAttribute('name', $parameter);
             $setting_node->setAttribute('value', ${$parameter});
             $shell_node->appendChild($setting_node);
         }
         foreach (array('desktop_icons', 'locale', 'timezone', 'need_valid_profile') as $parameter) {
             if (!isset(${$parameter})) {
                 continue;
             }
             $parameter_node = $dom->createElement('parameter');
             $parameter_node->setAttribute('name', $parameter);
             $parameter_node->setAttribute('value', ${$parameter});
             $session_node->appendChild($parameter_node);
         }
         $scripts = $this->user->scripts();
         if (is_array($scripts)) {
             $scripts_node = $dom->createElement('scripts');
             foreach ($scripts as $script) {
                 $script_node = $dom->createElement('script');
                 $script_node->setAttribute('id', $script->getAttribute('id'));
                 $script_node->setAttribute('type', $script->getAttribute('type'));
                 $script_node->setAttribute('name', $script->getAttribute('name'));
                 $scripts_node->appendChild($script_node);
             }
             $shell_node->appendChild($scripts_node);
         }
         $user_node = $dom->createElement('user');
         $user_node->setAttribute('login', $user_login_aps);
         $user_node->setAttribute('password', $user_password_aps);
         $user_node->setAttribute('displayName', $this->user->getAttribute('displayname'));
         $session_node->appendChild($user_node);
         if (array_key_exists(Server::SERVER_ROLE_FS, $session_->servers)) {
             foreach ($session_->servers[Server::SERVER_ROLE_FS] as $server_id => $netfolders) {
                 $fs_server = Abstract_Server::load($server_id);
                 foreach ($netfolders as $netfolder) {
                     $uri = 'cifs://' . $fs_server->getExternalName() . '/' . $netfolder['dir'];
                     $netfolder_node = $dom->createElement($netfolder['type']);
                     $netfolder_node->setAttribute('rid', $netfolder['rid']);
                     $netfolder_node->setAttribute('uri', $uri);
                     if ($netfolder['type'] == 'profile') {
                         $netfolder_node->setAttribute('profile_mode', $profile_mode);
                     }
                     if ($netfolder['type'] == 'sharedfolder') {
                         $netfolder_node->setAttribute('name', $netfolder['name']);
                         $netfolder_node->setAttribute('mode', $netfolder['mode']);
                     }
                     $netfolder_node->setAttribute('login', $user_login_fs);
                     $netfolder_node->setAttribute('password', $user_password_fs);
                     $session_node->appendChild($netfolder_node);
                 }
             }
         }
         foreach ($this->forced_sharedfolders as $share) {
             $sharedfolder_node = $dom->createElement('sharedfolder');
             $sharedfolder_node->setAttribute('rid', $share['rid']);
             $sharedfolder_node->setAttribute('uri', $share['uri']);
             $sharedfolder_node->setAttribute('name', $share['name']);
             if (array_key_exists('login', $share) && array_key_exists('password', $share)) {
                 $sharedfolder_node->setAttribute('login', $share['login']);
                 $sharedfolder_node->setAttribute('password', $share['password']);
             }
             $session_node->appendChild($sharedfolder_node);
         }
         // Pass custom shared folders to the server
         foreach (Plugin::dispatch('getSharedFolders', $server) as $plugin => $results) {
             foreach ($results as $sharedfolder) {
                 $sharedfolder_ok = true;
                 $sharedfolder_node = $dom->createElement('sharedfolder');
                 foreach (array('uri', 'name', 'rid') as $key) {
                     if (array_key_exists($key, $sharedfolder)) {
                         $sharedfolder_node->setAttribute($key, $sharedfolder[$key]);
                     } else {
                         Logger::error('main', 'SharedFolder is missing ' . $key . ' parameter in ' . $plugin);
                         $sharedfolder_ok = false;
                     }
                 }
                 foreach (array('login', 'password') as $key) {
                     if (array_key_exists($key, $sharedfolder)) {
                         $sharedfolder_node->setAttribute($key, $sharedfolder[$key]);
                     }
                 }
                 if (($have_login = array_key_exists('login', $sharedfolder)) != array_key_exists('password', $sharedfolder) && $have_login) {
                     Logger::error('main', 'SharedFolder login and password are both required if one is present in ' . $plugin);
                     $sharedfolder_ok = false;
                 }
                 if ($sharedfolder_ok) {
                     $session_node->appendChild($sharedfolder_node);
                 }
             }
         }
         foreach ($session_->getPublishedApplications() as $application) {
             if ($application->getAttribute('type') != $server->getAttribute('type')) {
                 continue;
             }
             if (!in_array($application->getAttribute('id'), $available_applications)) {
                 continue;
             }
             $application_node = $dom->createElement('application');
             $application_node->setAttribute('id', $application->getAttribute('id'));
             $application_node->setAttribute('name', $application->getAttribute('name'));
             if (!$application->getAttribute('static')) {
                 $application_node->setAttribute('mode', 'local');
             } else {
                 $application_node->setAttribute('mode', 'static');
             }
             $session_node->appendChild($application_node);
         }
         if (isset($start_apps) && is_array($start_apps)) {
             $start_node = $dom->createElement('start');
             foreach ($start_apps as $start_app) {
                 $application_node = $dom->createElement('application');
                 $application_node->setAttribute('app_id', $start_app['id']);
                 if (array_key_exists('arg', $start_app) && !is_null($start_app['arg'])) {
                     $application_node->setAttribute('arg', $start_app['arg']);
                 }
                 if (array_key_exists('file', $start_app)) {
                     $file_node = $dom->createElement('file');
                     $file_node->setAttribute('type', $start_app['file']['type']);
                     $file_node->setAttribute('location', $start_app['file']['location']);
                     $file_node->setAttribute('path', $start_app['file']['path']);
                     $application_node->appendChild($file_node);
                 }
                 $start_node->appendChild($application_node);
             }
             $session_node->appendChild($start_node);
         }
         $dom->appendChild($session_node);
         $this->appendToSessionCreateXML($dom);
         $xml = $dom->saveXML();
         $session_create_xml = query_url_post_xml($server->getBaseURL() . '/aps/session/create', $xml);
         $ret = $this->parseSessionCreate($session_create_xml);
         if (!$ret) {
             Logger::critical('main', 'SessionManagement::prepareAPSAccess - 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;
         }
     }
     return true;
 }
Exemple #14
0
 public function orderDisonnect()
 {
     Logger::debug('main', 'Starting Session::orderDisonnect for \'' . $this->id . '\'');
     $servers = array();
     if ($this->mode == self::MODE_DESKTOP) {
         array_push($servers, $this->server);
     } else {
         if (!array_key_exists(Server::SERVER_ROLE_APS, $this->servers)) {
             Logger::error('main', 'Unable to disconnect session because not using any ApS servers');
             return false;
         }
         $servers = array_keys($this->servers[Server::SERVER_ROLE_APS]);
     }
     $ret = true;
     foreach ($servers as $server_id) {
         $server = Abstract_Server::load($server_id);
         if (!$server) {
             Logger::error('main', 'Session::orderDisonnect Unable to load server \'' . $server_id . '\'');
             $ret = false;
         }
         $res = $server->orderSessionDisconnect($this->id);
         if (!$res) {
             $ret = false;
         }
     }
     return $ret;
 }
Exemple #15
0
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;
}
 * 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';
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', "(webservices/application_icon) return_error({$errno_}, {$errstr_})");
    return $dom->saveXML();
}
$server = Abstract_Server::load($_SERVER['REMOTE_ADDR']);
if (!$server) {
    echo return_error(1, 'Server does not exist');
    die;
}
if (!$server->isAuthorized()) {
    echo return_error(2, 'Server is not authorized');
    die;
}
header('Content-Type: text/xml; charset=utf-8');
$dom = new DomDocument('1.0', 'utf-8');
$node = $dom->createElement('applications');
$applications = $server->getApplications();
if (is_array($applications)) {
    foreach ($applications as $app) {
        if (!$app->getAttribute('static')) {
Exemple #17
0
function download_log($where_, $name_, $server_ = NULL)
{
    if ($where_ == 'sm') {
        header('Content-Type: application/octet-stream');
        header('Content-Disposition: attachment; filename=sessionmanager_' . $name_);
        $filename = SESSIONMANAGER_LOGS . '/main.log';
        $fp = @fopen($filename, 'r');
        if ($fp !== false) {
            while ($str = fgets($fp, 4096)) {
                echo $str;
            }
        }
        @fclose($fp);
    } elseif ($where_ == 'aps') {
        header('Content-Type: application/octet-stream');
        header('Content-Disposition: attachment; filename=slaveserver_' . $server_ . '.log');
        $server = Abstract_Server::load($server_);
        if (!$server) {
            Logger::error('main', '(admin/logs) download_log() - cannot load Server \'' . $server_ . '\'');
            redirect();
        }
        $buf = new Server_Logs($server);
        $buf->process();
        while ($str = $buf->getContent()) {
            echo $str;
        }
    }
    die;
}
Exemple #18
0
 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;
 }
Exemple #19
0
 public function orderAction($action_)
 {
     $server = Abstract_Server::load($this->server);
     if (!$server) {
         Logger::error('main', 'VDI_VM::orderAction unable to load Server \'' . $this->server . '\'');
         return false;
     }
     $dom = new DomDocument('1.0', 'utf-8');
     $node = $dom->createElement('vm');
     $node->setAttribute('id', $this->id);
     $node->setAttribute('action', $action_);
     $dom->appendChild($node);
     $xml = $dom->saveXML();
     $xml = query_url_post_xml($server->getBaseURL() . '/hypervisor/vm/manage', $xml);
     if (!$xml) {
         $server->isUnreachable();
         Logger::error('main', 'VDI_VM::orderAction server \'' . $server->fqdn . '\' is unreachable');
         return false;
     }
     $dom = new DomDocument('1.0', 'utf-8');
     $buf = @$dom->loadXML($xml);
     if (!$buf) {
         return false;
     }
     if (!$dom->hasChildNodes()) {
         return false;
     }
     $node = $dom->getElementsByTagname('vm')->item(0);
     if (is_null($node)) {
         return false;
     }
     $status = $node->getAttribute('status');
     if ($status != 'OK') {
         Logger::error('main', 'VDI_VM::orderAction failed');
         return false;
     }
     return true;
 }
Exemple #20
0
 *
 * 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.
 **/
require_once dirname(__FILE__) . '/../admin/includes/core-minimal.inc.php';
if (Preferences::fileExists() === false) {
    exit(1);
}
//BEGIN Updating logs cache
$servers = Abstract_Server::load_all();
foreach ($servers as $server) {
    $buf = new Server_Logs($server);
    $buf->process();
}
//END Updating logs cache
//BEGIN UserGroupDBDynamic_cached update
if (Preferences::moduleIsEnabled('UserGroupDBDynamicCached')) {
    $ugdbdc = UserGroupDBDynamicCached::getInstance();
    $groups = $ugdbdc->getList();
    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) {
Exemple #21
0
                echo '<table border="0" cellspacing="1" cellpadding="3">';
                foreach ($serv_s as $s) {
                    echo '<tr><td><strong>(' . $s->getAttribute('type') . ')</strong></td><td><a href="servers.php?action=manage&fqdn=' . $s->fqdn . '">' . $s->fqdn . '</a></td></tr>';
                }
                echo '</table>';
            }
            echo '</td>';
            echo '</tr>';
            $count++;
        }
        echo '</tbody>';
        echo '</table>';
    }
}
echo '<h2>' . _('List of servers') . '</h2>';
$servs_all = Abstract_Server::load_all();
if (is_null($servs_all)) {
    echo _('No server available') . '<br />';
} else {
    if (count($servs_all) == 0) {
        echo _('No server available') . '<br />';
    } else {
        ?>
		<table id="servers_table" class="main_sub sortable" border="0" cellspacing="1" cellpadding="3">
		<thead>
		<tr class="title">
			<th><?php 
        echo _('FQDN');
        ?>
</th>
			<th><?php 
Exemple #22
0
function show_manage($fqdn)
{
    $server = Abstract_Server::load($fqdn);
    if (!$server || $server->getAttribute('registered') === false) {
        redirect('servers.php');
    }
    $server_online = $server->isOnline();
    if ($server_online) {
        $buf = $server->getMonitoring();
        if ($buf === false) {
            popup_error(sprintf(_('Cannot get server monitoring for \'%s\''), $server->getAttribute('fqdn')));
        }
        Abstract_Server::save($server);
    }
    $buf_status = $server->getAttribute('status');
    if ($buf_status == 'down') {
        $status_error_msg = _('Warning: server is offline');
    } elseif ($buf_status == 'broken') {
        $status_error_msg = _('Warning: server is broken');
    }
    $server_lock = $server->getAttribute('locked');
    if ($server_lock) {
        $switch_button = _('Switch to production');
        $switch_value = 0;
    } else {
        $switch_button = _('Switch to maintenance');
        $switch_value = 1;
    }
    ksort($server->roles);
    $var = array();
    foreach ($server->roles as $role => $bool) {
        $ret = server_display_role_preparation($role, $server);
        if (!is_bool($ret)) {
            $var[$role] = $ret;
        } else {
            Logger::debug('main', 'server_display_role_preparation failed for server ' . $server->fqdn . ' role ' . $role);
        }
    }
    $can_do_action = isAuthorized('manageServers');
    page_header();
    echo '<script type="text/javascript" src="media/script/ajax/servers.js" charset="utf-8"></script>';
    echo '<div id="servers_div">';
    echo '<h1>' . $server->fqdn . '</h1>';
    //   if ($server_online === false)
    //     echo '<h2><p class="msg_error centered">'.$status_error_msg.'</p></h2>';
    echo '<div class="section">';
    echo '<h2>' . _('Monitoring') . '</h2>';
    echo '<table class="main_sub" border="0" cellspacing="1" cellpadding="3">';
    echo '<tr class="title">';
    echo '<th>' . _('Type') . '</th><th>' . _('Version') . '</th><th>' . _('Status') . '</th>';
    echo '<th>' . _('Details') . '</th>';
    if ($server_online) {
        echo '<th>' . _('Monitoring') . '</th>';
    }
    echo '</tr>';
    echo '<tr class="content1">';
    echo '<td style="text-align: center;"><img src="media/image/server-' . $server->stringType() . '.png" alt="' . $server->stringType() . '" title="' . $server->stringType() . '" /><br />' . $server->stringType() . '</td>';
    echo '<td>' . $server->stringVersion() . '</td>';
    echo '<td>' . $server->stringStatus() . '</td>';
    echo '<td>' . _('CPU') . '; : ' . $server->getAttribute('cpu_model') . '  (' . $server->getAttribute('cpu_nb_cores') . ' ';
    echo $server->getAttribute('cpu_nb_cores') > 1 ? _('cores') : _('core');
    echo ')<br />' . _('RAM') . ' : ' . round($server->getAttribute('ram_total') / 1024) . ' ' . _('MB') . '</td>';
    if ($server_online) {
        echo '<td>';
        echo _('CPU usage') . ': ' . $server->getCpuUsage() . '%<br />';
        echo display_loadbar($server->getCpuUsage());
        echo _('RAM usage') . ': ' . $server->getRamUsage() . '%<br />';
        echo display_loadbar($server->getRamUsage());
        foreach ($server->roles as $role => $enabled) {
            if ($enabled === false) {
                continue;
            }
            switch ($role) {
                case 'aps':
                    echo _('Sessions usage') . ': ' . $server->getSessionUsage() . '%<br />';
                    echo display_loadbar($server->getSessionUsage() > 100 ? 100 : $server->getSessionUsage());
                    break;
                case 'fs':
                    echo _('Disk usage') . ': ' . $server->getDiskUsage() . '%<br />';
                    echo display_loadbar($server->getDiskUsage() > 100 ? 100 : $server->getDiskUsage());
                    break;
            }
        }
        echo '</td>';
    }
    echo '</tr>';
    echo '</table>';
    echo '</div>';
    echo '<div class="section">';
    echo '<h2>' . _('Configuration') . '</h2>';
    echo '<table>';
    echo '<tr><td>';
    echo _('Redirection name for 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="external_name" />';
    }
    echo '<input type="text" name="external_name" value="' . $server->getAttribute('external_name') . '" />';
    if ($can_do_action) {
        echo ' <input type="submit" value="' . _('change') . '" />';
        echo '</form>';
    }
    echo "</td></tr>\n";
    if ($can_do_action) {
        if ($server_online || $switch_value == 1) {
            echo '<tr><td></td><td>';
            echo '<form action="actions.php" method="post">';
            echo '<input type="hidden" name="name" value="Server" />';
            echo '<input type="hidden" name="checked_servers[]" value="' . $server->fqdn . '" />';
            echo '<input type="hidden" name="action" value="maintenance" />';
            if ($switch_value == 0) {
                echo '<input type="hidden" name="to_production" value="to_production"/>';
            } else {
                echo '<input type="hidden" name="to_maintenance" value="to_maintenance"/>';
            }
            echo '<input';
            if ($switch_value == 0) {
                echo ' style="background: #05a305; color: #fff; font-weight: bold;"';
            }
            echo ' type="submit" value="' . $switch_button . '"/>';
            echo '</form>';
            echo '</td></tr>';
        }
        if ($server_lock || !$server_online) {
            echo '<tr><td></td><td>';
            echo '<form action="actions.php" method="get" onsubmit="return confirm(\'' . _('Are you sure you want to delete this server?') . '\');">';
            echo '<input type="hidden" name="name" value="Server" />';
            echo '<input type="hidden" name="action" value="del" />';
            echo '<input type="hidden" name="checked_servers[]" value="' . $server->fqdn . '" />';
            echo '<input type="submit" value="' . _('Delete') . '" />';
            echo '</form>';
            echo '</td></tr>';
        }
    }
    echo '</table>';
    echo '</div>';
    foreach ($server->roles as $role => $bool) {
        if (array_key_exists($role, $var)) {
            echo '<div>';
            // div role
            echo '<fieldset class="role">';
            echo '<legend>' . sprintf(_('Role: %s'), strtoupper($role)) . '</legend>';
            echo server_display_role($role, $server, $var[$role]);
            echo '</fieldset>';
            echo '</div>';
        }
    }
    page_footer();
    die;
}
function show_manage($id, $applicationDB)
{
    global $types;
    $applicationsGroupDB = ApplicationsGroupDB::getInstance();
    $app = $applicationDB->import($id);
    if (!is_object($app)) {
        return false;
    }
    $is_rw = $applicationDB->isWriteable();
    $can_manage_applications = isAuthorized('manageApplications');
    // App groups
    $appgroups = $applicationsGroupDB->getList();
    $groups_id = array();
    $liaisons = Abstract_Liaison::load('AppsGroup', $app->getAttribute('id'), NULL);
    foreach ($liaisons as $liaison) {
        $groups_id[] = $liaison->group;
    }
    $groups = array();
    $groups_available = array();
    foreach ($appgroups as $group) {
        if (in_array($group->id, $groups_id)) {
            $groups[] = $group;
        } else {
            $groups_available[] = $group;
        }
    }
    $servers_all = Abstract_Server::load_available_by_role(Server::SERVER_ROLE_APS, true);
    $liaisons = Abstract_Liaison::load('ApplicationServer', $app->getAttribute('id'), NULL);
    $servers_id = array();
    foreach ($liaisons as $liaison) {
        $servers_id[] = $liaison->group;
    }
    $servers = array();
    $servers_available = array();
    foreach ($servers_all as $server) {
        if (in_array($server->fqdn, $servers_id)) {
            $servers[] = $server;
        } elseif (!$server->isOnline()) {
            continue;
        } elseif ($server->type != $app->getAttribute('type')) {
            continue;
        } else {
            $servers_available[] = $server;
        }
    }
    $mimes = $applicationDB->getAllMimeTypes();
    $mimeliste1 = $app->getMimeTypes();
    $mimeliste2 = array();
    foreach ($mimes as $mime) {
        if (!in_array($mime, $mimeliste1)) {
            $mimeliste2[] = $mime;
        }
    }
    $can_manage_server = isAuthorized('manageServers');
    page_header();
    echo '<div>';
    echo '<h1><img src="media/image/cache.php?id=' . $app->getAttribute('id') . '" alt="" title="" /> ' . $app->getAttribute('name') . '</h1>';
    echo '<table class="main_sub" border="0" cellspacing="1" cellpadding="3">';
    echo '<tr class="title">';
    // 	echo '<th>'._('Package').'</th>';
    echo '<th>' . _('Type') . '</th>';
    echo '<th>' . _('Description') . '</th>';
    echo '<th>' . _('Command') . '</th>';
    if ($is_rw and $can_manage_applications) {
        echo '<th></th>';
    }
    echo '</tr>';
    echo '<tr class="content1">';
    // 		echo '<td>'.$app->getAttribute('package').'</td>';
    echo '<td style="text-align: center;"><img src="media/image/server-' . $app->getAttribute('type') . '.png" alt="' . $app->getAttribute('type') . '" title="' . $app->getAttribute('type') . '" /><br />' . $app->getAttribute('type') . '</td>';
    echo '<td>' . $app->getAttribute('description') . '</td>';
    echo '<td>';
    echo $app->getAttribute('executable_path');
    echo '</td>';
    if ($is_rw and $can_manage_applications) {
        echo '<td>';
        echo '<form action="actions.php" method="post" onsubmit="return confirm(\'' . _('Are you sure you want to delete this application?') . '\');">';
        echo '<input type="hidden" name="name" value="Application_static" />';
        echo '<input type="hidden" name="action" value="del" />';
        echo '<input type="hidden" name="checked_applications[]" value="' . $app->getAttribute('id') . '" />';
        echo '<input type="submit"  value="' . _('Delete') . '" />';
        echo '</form>';
        echo '</td>';
    }
    echo '</tr>';
    echo '</table>';
    if ($is_rw and $can_manage_applications) {
        echo '<br />';
        echo '<form action="actions.php" method="post"">';
        echo '<input type="hidden" name="name" value="Application" />';
        echo '<input type="hidden" name="action" value="clone" />';
        echo '<input type="hidden" name="id" value="' . $app->getAttribute('id') . '" />';
        echo '<input type="submit" value="' . _('Clone to new application') . '"/>';
        echo '</form>';
        echo '<br />';
        echo '<h2>' . _('Modify') . '</h2>';
        echo '<div id="application_modify">';
        echo '<form id="delete_icon" action="actions.php" method="post" style="display: none;">';
        echo '<input type="hidden" name="name" value="Application_static" />';
        echo '<input type="hidden" name="action" value="del_icon" />';
        echo '<input type="hidden" name="checked_applications[]" value="' . $app->getAttribute('id') . '" />';
        echo '</form>';
        echo '<form action="actions.php" method="post" enctype="multipart/form-data" >';
        // form A
        echo '<input type="hidden" name="name" value="Application_static" />';
        echo '<input type="hidden" name="action" value="modify" />';
        echo '<input type="hidden" name="published" value="1" />';
        echo '<input type="hidden" name="static" value="1" />';
        echo '<input type="hidden" name="id" value="' . $app->getAttribute('id') . '" />';
        echo '<table class="main_sub" border="0" cellspacing="1" cellpadding="5">';
        $count = 1;
        $app->setAttribute('application_name', $app->getAttribute('name'));
        // ugly hack
        $app->unsetAttribute('name');
        $attr_list = $app->getAttributesList();
        foreach ($attr_list as $k => $v) {
            if (in_array($v, array('id', 'type', 'static', 'published', 'desktopfile', 'package', 'revision'))) {
                unset($attr_list[$k]);
            }
        }
        asort($attr_list);
        foreach ($attr_list as $attr_name) {
            $content = 'content' . ($count++ % 2 == 0 ? 1 : 2);
            echo '<tr class="' . $content . '">';
            echo '<td style="text-transform: capitalize;">';
            if ($attr_name == 'executable_path') {
                echo _('Command');
            } else {
                if ($attr_name == 'application_name') {
                    echo _('Name');
                } else {
                    echo _($attr_name);
                }
            }
            echo '</td>';
            echo '<td>';
            echo '<input type="text" name="' . $attr_name . '" value="' . htmlspecialchars($app->getAttribute($attr_name)) . '" style="with:100%;"/>';
            echo '<input type="hidden" name="attributes_send[]" value="' . $attr_name . '" />';
            echo '</td>';
            echo '</tr>';
        }
        if (get_classes_startwith('Imagick') != array()) {
            $content = 'content' . ($count++ % 2 == 0 ? 1 : 2);
            echo '<tr class="' . $content . '">';
            echo '<td>' . _('Icon') . '</td>';
            echo '<td>';
            if ($app->getIconPath() != $app->getDefaultIconPath() && file_exists($app->getIconPath())) {
                echo '<img src="media/image/cache.php?id=' . $app->getAttribute('id') . '" alt="" title="" /> ';
                echo '<input type="button" value="' . _('Delete this icon') . '" onclick="return confirm(\'' . _('Are you sure you want to delete this icon?') . '\') && $(\'delete_icon\').submit();"/>';
                echo '<br />';
            }
            echo '<input type="file"  name="file_icon" /> ';
            echo '</td>';
            echo '</tr>';
        } else {
            Logger::info('main', 'No Imagick support found');
        }
        $content = 'content' . ($count++ % 2 == 0 ? 1 : 2);
        echo '<tr class="' . $content . '">';
        echo '<td colspan="2">';
        echo '<input type="submit" value="' . _('Modify') . '" />';
        echo '</td>';
        echo '</tr>';
        echo '</table>';
        echo '</form>';
        // form A
        echo '</div>';
        // application_modify
    }
    if (count($servers) + count($servers_available) > 0) {
        echo '<div>';
        echo '<h2>' . _('Servers with this application') . '</h2>';
        echo '<table border="0" cellspacing="1" cellpadding="3">';
        foreach ($servers as $server) {
            echo '<tr><td>';
            echo '<a href="servers.php?action=manage&fqdn=' . $server->fqdn . '">' . $server->fqdn . '</a>';
            echo '</td>';
            echo '<td>';
            if ($server->isOnline() and $can_manage_server) {
                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="application" value="' . $id . '" />';
                echo '<input type="hidden" name="server" value="' . $server->fqdn . '" />';
                echo '<input type="submit" value="' . _('Remove from this server') . '"/>';
                echo '</form>';
            }
            echo '</td>';
            echo '</tr>';
        }
        if (count($servers_available) > 0 and $can_manage_server) {
            echo '<tr>';
            echo '<form action="actions.php" method="post"><td>';
            echo '<input type="hidden" name="name" value="Application_Server" />';
            echo '<input type="hidden" name="action" value="add" />';
            echo '<input type="hidden" name="application" value="' . $id . '" />';
            echo '<select name="server">';
            foreach ($servers_available as $server) {
                echo '<option value="' . $server->fqdn . '">' . $server->fqdn . '</option>';
            }
            echo '</select>';
            echo '</td><td><input type="submit" value="' . _('Add to this server') . '" /></td>';
            echo '</form>';
            echo '</tr>';
        }
        echo '</table>';
        echo "<div>\n";
    }
    if (count($appgroups) > 0) {
        echo '<div>';
        echo '<h2>' . _('Groups with this application') . '</h2>';
        echo '<table border="0" cellspacing="1" cellpadding="3">';
        foreach ($groups as $group) {
            echo '<tr>';
            echo '<td>';
            echo '<a href="appsgroup.php?action=manage&id=' . $group->id . '">' . $group->name . '</a>';
            echo '</td>';
            echo '<td><form action="actions.php" method="post" onsubmit="return confirm(\'' . _('Are you sure you want to delete this application from this group?') . '\');">';
            echo '<input type="hidden" name="name" value="Application_ApplicationGroup" />';
            echo '<input type="hidden" name="action" value="del" />';
            echo '<input type="hidden" name="element" value="' . $id . '" />';
            echo '<input type="hidden" name="group" value="' . $group->id . '" />';
            echo '<input type="submit" value="' . _('Delete from this group') . '" />';
            echo '</form></td>';
            echo '</tr>';
        }
        if (count($groups_available) > 0) {
            echo '<tr>';
            echo '<form action="actions.php" method="post"><td>';
            echo '<input type="hidden" name="name" value="Application_ApplicationGroup" />';
            echo '<input type="hidden" name="action" value="add" />';
            echo '<input type="hidden" name="element" value="' . $id . '" />';
            echo '<select name="group">';
            foreach ($groups_available as $group) {
                echo '<option value="' . $group->id . '">' . $group->name . '</option>';
            }
            echo '</select>';
            echo '</td><td><input type="submit" value="' . _('Add to this group') . '" /></td>';
            echo '</form>';
            echo '</tr>';
        }
        echo '</table>';
        echo "<div>\n";
    }
    // Mime-Type part
    echo '<div>';
    echo '<h2>' . _('Mime-Types') . '</h2>';
    echo '<div>';
    echo '<table border="0" cellspacing="1" cellpadding="3">';
    foreach ($mimeliste1 as $mime) {
        echo '<tr><td>';
        echo '<a href="mimetypes.php?action=manage&id=' . urlencode($mime) . '">' . $mime . '</a>';
        echo '</td>';
        echo '<td>';
        echo '<form action="actions.php" method="post">';
        echo '<input type="hidden" name="name" value="Application_MimeType" />';
        echo '<input type="hidden" name="action" value="del" />';
        echo '<input type="hidden" name="id" value="' . $app->getAttribute('id') . '" />';
        echo '<input type="hidden" name="mime" value="' . $mime . '" />';
        echo '<input type="submit" value="' . _('Del') . '"/>';
        echo '</form>';
        echo '</td>';
        echo '</tr>';
    }
    if (is_array($mimeliste2) && count($mimeliste2) > 0) {
        echo '<tr>';
        echo '<form action="actions.php" method="post">';
        echo '<input type="hidden" name="name" value="Application_MimeType" />';
        echo '<input type="hidden" name="action" value="add" />';
        echo '<input type="hidden" name="id" value="' . $app->getAttribute('id') . '" />';
        echo '<td>';
        echo '<select name="mime">';
        foreach ($mimeliste2 as $mime) {
            echo '<option>' . $mime . '</option>';
        }
        echo '</select>';
        echo '</td>';
        echo '<td>';
        echo '<input type="submit" value="' . _('Add') . '"/>';
        echo '</td>';
        echo '</form>';
        echo '</tr>';
    }
    echo '<tr>';
    echo '<form action="actions.php" method="post">';
    echo '<input type="hidden" name="name" value="Application_MimeType" />';
    echo '<input type="hidden" name="action" value="add" />';
    echo '<input type="hidden" name="id" value="' . $app->getAttribute('id') . '" />';
    echo '<td>' . _('Custom Mime-Type: ') . '<input type="text" name="mime" /></td>';
    echo '<td>';
    echo '<input type="submit" value="' . _('Add') . '"/>';
    echo '</td>';
    echo '</form>';
    echo '</tr>';
    echo '</table>';
    echo '</div>';
    echo '</div>';
    // mime div
    echo '</div>';
    echo '</div>';
    echo '</div>';
    echo '</div>';
    echo '</div>';
    echo '</div>';
    page_footer();
    die;
}
Exemple #24
0
 public function get_AllInfos()
 {
     $server = Abstract_Server::load($this->server);
     if (!is_object($server)) {
         Logger::error('apt-get', 'TASK::get_AllInfos for task ' . $this->id . ' returned an error (unknown server ' . $this->server . ')');
         return false;
     }
     $infos = array();
     foreach (array('stdout', 'stderr') as $elem) {
         $infos[$elem] = query_url_no_error($server->getBaseURL() . '/aps/debian/' . $this->job_id . '/' . $elem);
     }
     return $infos;
 }
Exemple #25
0
 public function chooseFileServer()
 {
     $available_servers = Abstract_Server::load_available_by_role_sorted_by_load_balancing(Server::SERVER_ROLE_FS);
     if (is_array($available_servers)) {
         $server = array_shift($available_servers);
         if (is_object($server)) {
             return $server;
         }
     }
     return false;
 }
Exemple #26
0
 * 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';
Logger::debug('main', 'Starting webservices/application.php');
if (!isset($_GET['id'])) {
    Logger::error('main', '(webservices/application) Missing parameter : id');
    header('HTTP/1.1 400 Bad Request');
    die('ERROR - NO $_GET[\'id\']');
}
if (!isset($_GET['fqdn'])) {
    Logger::error('main', '(webservices/application) Missing parameter : fqdn');
    die('ERROR - NO $_GET[\'fqdn\']');
}
$buf = Abstract_Server::load($_GET['fqdn']);
if (!$buf || !$buf->isAuthorized()) {
    Logger::error('main', '(webservices/application) Server not authorized : ' . $_GET['fqdn'] . ' == ' . @gethostbyname($_GET['fqdn']) . ' ?');
    die('Server not authorized');
}
Logger::debug('main', '(webservices/application) Security check OK');
$prefs = Preferences::getInstance();
if (!$prefs) {
    die_error('get Preferences failed', __FILE__, __LINE__);
}
$mods_enable = $prefs->get('general', 'module_enable');
if (!in_array('ApplicationDB', $mods_enable)) {
    Logger::error('main', '(webservices/application) Module ApplicationDB must be enabled');
    header('HTTP/1.1 400 Bad Request');
    die;
}
Exemple #27
0
		<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>';
    echo '</li>';
    echo '<li>';
    echo $count_online_servers . ' ';
    echo '<a href="servers.php">';
    if ($count_online_servers > 1) {
Exemple #28
0
        }
        $application_node = $dom->createElement('application');
        $application_node->setAttribute('id', $application->getAttribute('id'));
        $application_node->setAttribute('name', $application->getAttribute('name'));
        foreach ($application->getMimeTypes() as $mimetype) {
            $mimetype_node = $dom->createElement('mime');
            $mimetype_node->setAttribute('type', $mimetype);
            $application_node->appendChild($mimetype_node);
        }
        $server_node->appendChild($application_node);
    }
    $session_node->appendChild($server_node);
} elseif ($session->mode == Session::MODE_APPLICATIONS) {
    $defined_apps = array();
    foreach ($session->servers[Server::SERVER_ROLE_APS] as $fqdn => $data) {
        $server = Abstract_Server::load($fqdn);
        if (!$server) {
            continue;
        }
        if (!is_array($server->roles) || !array_key_exists(Server::SERVER_ROLE_APS, $server->roles)) {
            continue;
        }
        $server_applications = $server->getApplications();
        if (!is_array($server_applications)) {
            $server_applications = array();
        }
        $available_applications = array();
        foreach ($server_applications as $server_application) {
            $available_applications[] = $server_application->getAttribute('id');
        }
        $server_node = $dom->createElement('server');
Exemple #29
0
            $application_node = $dom->createElement('application');
            $application_node->setAttribute('id', $application->getAttribute('id'));
            $application_node->setAttribute('name', $application->getAttribute('name'));
            foreach ($application->getMimeTypes() as $mimetype) {
                $mimetype_node = $dom->createElement('mime');
                $mimetype_node->setAttribute('type', $mimetype);
                $application_node->appendChild($mimetype_node);
            }
            $server_node->appendChild($application_node);
        }
        $session_node->appendChild($server_node);
    }
}
if (array_key_exists(Server::SERVER_ROLE_WEBAPPS, $session->servers)) {
    foreach ($session->servers[Server::SERVER_ROLE_WEBAPPS] as $server_id => $data) {
        $server = Abstract_Server::load($server_id);
        if (!$server) {
            throw_response(INTERNAL_ERROR);
        }
        if (!array_key_exists(Server::SERVER_ROLE_WEBAPPS, $server->getRoles())) {
            throw_response(INTERNAL_ERROR);
        }
        $server_node = $dom->createElement('webapp-server');
        $server_node->setAttribute('type', 'webapps');
        $server_node->setAttribute('base-url', $server->getBaseURL());
        $server_node->setAttribute('webapps-url', $session->settings['webapps-url']);
        $server_node->setAttribute('login', $user_login_webapps);
        $server_node->setAttribute('password', $user_password_webapps);
        foreach ($session->getPublishedApplications() as $application) {
            if ($application->getAttribute('type') != 'webapp') {
                continue;
Exemple #30
0
function parse_monitoring_XML($xml_)
{
    if (!$xml_ || strlen($xml_) == 0) {
        return false;
    }
    $dom = new DomDocument('1.0', 'utf-8');
    $buf = @$dom->loadXML($xml_);
    if (!$buf) {
        return false;
    }
    if (!$dom->hasChildNodes()) {
        return false;
    }
    $server_node = $dom->getElementsByTagName('server')->item(0);
    if (is_null($server_node)) {
        return false;
    }
    if (!$server_node->hasAttribute('name')) {
        return false;
    }
    if (!Abstract_Server::exists($server_node->getAttribute('name'))) {
        die;
    }
    // An unknown Server should not send monitoring, so we reject it...
    $server = Abstract_Server::load($server_node->getAttribute('name'));
    if (!$server) {
        return false;
    }
    if (!$server->isAuthorized()) {
        return false;
    }
    $ret = array('server' => $server_node->getAttribute('name'));
    $cpu_node = $dom->getElementsByTagName('cpu')->item(0);
    if (is_null($cpu_node)) {
        return false;
    }
    if (!$cpu_node->hasAttribute('load')) {
        return false;
    }
    $ret['cpu_load'] = $cpu_node->getAttribute('load');
    $ram_node = $dom->getElementsByTagName('ram')->item(0);
    if (is_null($ram_node)) {
        return false;
    }
    if (!$ram_node->hasAttribute('used')) {
        return false;
    }
    $ret['ram_used'] = $ram_node->getAttribute('used');
    $role_nodes = $dom->getElementsByTagName('role');
    foreach ($role_nodes as $role_node) {
        if (!$role_node->hasAttribute('name')) {
            return false;
        }
        switch ($role_node->getAttribute('name')) {
            case 'ApplicationServer':
                $ret['sessions'] = array();
                $session_nodes = $dom->getElementsByTagName('session');
                foreach ($session_nodes as $session_node) {
                    $ret['sessions'][$session_node->getAttribute('id')] = array('id' => $session_node->getAttribute('id'), 'server' => $_SERVER['REMOTE_ADDR'], 'status' => $session_node->getAttribute('status'), 'instances' => array());
                    $childnodes = $session_node->childNodes;
                    foreach ($childnodes as $childnode) {
                        if ($childnode->nodeName != 'instance') {
                            continue;
                        }
                        $ret['sessions'][$session_node->getAttribute('id')]['instances'][$childnode->getAttribute('id')] = $childnode->getAttribute('application');
                    }
                    $token = $session_node->getAttribute('id');
                    if (Abstract_ReportSession::exists($session_node->getAttribute('id'))) {
                        $report = Abstract_ReportSession::load($session_node->getAttribute('id'));
                        if (is_object($report)) {
                            $report->update($session_node);
                        }
                    }
                }
                $sri = new ServerReportItem($ret['server'], $xml_);
                $sri->save();
                break;
            case 'FileServer':
                $size_node = $dom->getElementsByTagName('size')->item(0);
                if (is_null($size_node)) {
                    break;
                }
                $ret['disk_size'] = array('total' => NULL, 'free' => NULL);
                if ($size_node->hasAttribute('total')) {
                    $ret['disk_size']['total'] = $size_node->getAttribute('total');
                }
                if ($size_node->hasAttribute('free')) {
                    $ret['disk_size']['free'] = $size_node->getAttribute('free');
                }
                $ret['shares'] = array();
                $share_nodes = $dom->getElementsByTagName('share');
                foreach ($share_nodes as $share_node) {
                    $ret['shares'][$share_node->getAttribute('id')] = array('id' => $share_node->getAttribute('id'), 'status' => $share_node->getAttribute('status'), 'users' => array());
                    $user_nodes = $share_node->getElementsByTagName('user');
                    foreach ($user_nodes as $user_node) {
                        $ret['shares'][$share_node->getAttribute('id')]['users'][] = $user_node->getAttribute('login');
                    }
                }
                break;
        }
    }
    return $ret;
}