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; }
public function getAvailableApplicationServers() { $servers = Abstract_Server::load_available_by_role(Server::SERVER_ROLE_APS); $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->id); 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]); } } } return $servers; }
public function script_add($name_, $os_, $type_, $data_) { $this->check_authorized('manageScripts'); $script = new Script(''); $script->name = $name_; $script->type = $type_; $script->os = $os_; $script->data = $data_; $ret = Abstract_Script::save($script); if ($ret !== true) { return false; } $servers = Abstract_Server::load_available_by_role(Server::SERVER_ROLE_APS, true); foreach ($servers as $server) { $server->syncScripts(); } return $script->id; }
public static function load_available_by_role_sorted_by_load_balancing($role_) { $prefs = Preferences::getInstance(); if (!$prefs) { Logger::critical('main', 'get Preferences failed in ' . __FILE__ . ' line ' . __LINE__); return array(); } $slave_server_settings = $prefs->get('general', 'slave_server_settings'); $key = 'load_balancing_' . $role_; if (!array_key_exists($key, $slave_server_settings)) { Logger::error('main', 'USER::getAvailableServer $slave_server_settings[\'' . $key . '\'] not set'); return array(); } $criterions = $slave_server_settings[$key]; if (is_null($criterions)) { Logger::error('main', 'USER::getAvailableServer criterions is null'); return array(); } $available_servers = Abstract_Server::load_available_by_role($role_); $server_object = array(); $servers = array(); $servers2 = array(); if (is_array($available_servers)) { foreach ($available_servers as $server) { $val = 0; foreach ($criterions as $criterion_name => $criterion_value) { $name_class1 = 'DecisionCriterion_' . $criterion_name; $d1 = new $name_class1($server); if ($d1->applyOnRole($role_)) { $r1 = $d1->get(); $val += $r1 * $criterion_value; } } $servers[$server->fqdn] = $val; $server_object[$server->fqdn] = $server; } arsort($servers); foreach ($servers as $fqdn => $val) { $servers2[$fqdn] = $server_object[$fqdn]; } } return $servers2; }
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; }
public static function load_available_by_role_sorted_by_load_balancing($role_) { $available_servers = Abstract_Server::load_available_by_role($role_); return Server::fire_load_balancing($available_servers, $role_); }