public static function getInstance() { if (empty(self::$_dbn)) { $user = '******'; $pass = 1234; $dsn = 'mysql:host=localhost;dbname=test'; $opt = array(\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION, \PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_ASSOC); self::$_dbn = new \PDO($dsn, $user, $pass, $opt); } return self::$_dbn; }
/** * Load the iGrad application object into $this. */ public function loadApplication() { // nothing to do if application has been loaded if ($this->Application !== null) { return; } $psp_user_id = (int) $this->ordernumber; $appid = ApplicationDB::appid_for_pspid($psp_user_id); if (!$appid) { throw new Exception("Appid not found for psp_user_id of {$psp_user_id}"); } $f = ApplicationDB::applicationForm($appid); $this->Application = new Application($appid, $f); }
public static function getInstance() { if (is_null(self::$instance)) { $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)) { die_error(_('Module ApplicationDB must be enabled'), __FILE__, __LINE__); } $mod_app_name = 'ApplicationDB_' . $prefs->get('ApplicationDB', 'enable'); self::$instance = new $mod_app_name(); } return self::$instance; }
public function toXML($ApS = NULL) { $list_attr = $this->getAttributesList(); foreach ($list_attr as $k => $v) { if (in_array($v, array('executable_path'))) { unset($list_attr[$k]); } } if (is_object($ApS)) { //$this->attributes['type'] = $ApS->type; if (array_key_exists($ApS->type, $this->default_browser)) { $browser_id = $this->default_browser[$ApS->type]; $applicationDB = ApplicationDB::getInstance(); $browser = $applicationDB->import($browser_id); if (!is_object($browser)) { Logger::error('main', 'Application_webapp::toXML failed to load browser (id=' . $browser_id . ')'); } } } else { // ugly echo "is NOT object(ApS)\n"; $this->attributes['type'] = 'linux'; } $dom = new DomDocument('1.0', 'utf-8'); $application_node = $dom->createElement('application'); $executable_node = $dom->createElement('executable'); //TODO Perhaps this is highly related with the webapps and the way they work in the portal Logger::info('main', 'Application_webapp::toXML is using hardcoded firefox path. Check this)'); if ($this->hasAttribute('executable_path')) { $executable_node->setAttribute('command', 'firefox ' . $this->attributes['executable_path']); } // executable_path <=> slaveserver_host foreach ($list_attr as $attr_name) { $application_node->setAttribute($attr_name, $this->attributes[$attr_name]); } $application_node->appendChild($executable_node); $dom->appendChild($application_node); return $dom->saveXML(); }
function show_manage($id_) { $applicationDB = ApplicationDB::getInstance(); $applications = $applicationDB->getApplicationsWithMimetype($id_); page_header(); echo '<div>'; echo '<h1>' . _('Mime-Type') . ' - ' . $id_ . '</h1>'; echo '<div>'; if (count($applications) == 0) { echo _('No application with this mime-type') . '<br />'; } else { echo '<table class="main_sub sortable" id="applications_list_table" border="0" cellspacing="1" cellpadding="5">'; echo '<thead>'; echo '<tr class="title">'; echo '<th>' . _('Name') . '</th>'; echo '<th>' . _('OS') . '</th>'; echo '</tr>'; echo '</thead>'; echo '<tbody>'; $count = 0; foreach ($applications as $app) { $content = 'content' . ($count++ % 2 == 0 ? 1 : 2); echo '<tr class="' . $content . '">'; echo '<td><a href="applications.php?action=manage&id=' . $app->getAttribute('id') . '">'; echo '<img src="media/image/cache.php?id=' . $app->getAttribute('id') . '" alt="" title="" /> '; echo $app->getAttribute('name'); echo '</a></td>'; echo '<td><img src="media/image/server-' . $app->getAttribute('type') . '.png" alt="' . $app->getAttribute('type') . '" title="' . $app->getAttribute('type') . '" /></td>'; echo '</tr>'; } echo '</tbody>'; echo '</table>'; } echo '</div>'; echo '</div>'; page_footer(); die; }
} $ret['application']['id'] = $application_node->getAttribute('id'); return $ret; } $ret = parse_icon_XML(@file_get_contents('php://input')); if (!$ret) { Logger::error('main', '(webservices/application/icon) Server does not send a valid XML (error_code: 1)'); webservices_return_error(1, 'Server does not send a valid XML'); } $server = webservices_load_server($_SERVER['REMOTE_ADDR']); if (!$server) { Logger::error('main', '(webservices/application/icon) Server does not exist (error_code: 2)'); webservices_return_error(2, 'Server does not exist'); } if (!$server->isAuthorized()) { Logger::error('main', '(webservices/application/icon) Server is not authorized (error_code: 3)'); webservices_return_error(3, 'Server is not authorized'); } $applicationDB = ApplicationDB::getInstance(); $app = $applicationDB->import($ret['application']['id']); if (!is_object($app)) { Logger::error('main', '(webservices/application/icon) No such application "' . $ret['application']['id'] . '" (error_code: 4)'); webservices_return_error(4, 'No such application "' . $ret['application']['id'] . '"'); } $path = $app->getIconPath(); if (!file_exists($path)) { Logger::error('main', '(webservices/application/icon) No icon available for application "' . $ret['application']['id'] . '" (error_code: 5)'); webservices_return_error(5, 'No icon available for application "' . $ret['application']['id'] . '"'); } header('Content-Type: image/png'); echo @file_get_contents($path, LOCK_EX);
function show_manage($id_) { // $session = Abstract_ReportSession::load($id_); $session = get_session_reporting($id_); if (!$session) { popup_error(sprintf(_('Unknown session %s'), $id_)); redirect(); } $userDB = UserDB::getInstance(); $user = $userDB->import($session['user']); $applicationDB = ApplicationDB::getInstance(); $applications = array(); $dom = new DomDocument('1.0', 'utf-8'); $ret = @$dom->loadXML($session['data']); if ($ret) { foreach ($dom->getElementsByTagName('application') as $node) { $application = array(); foreach ($node->childNodes as $child_node) { $name = $child_node->nodeName; if ($name == '#text') { continue; } $application[$name] = $child_node->nodeValue; } $applications[] = $application; } } for ($i = 0; $i < count($applications); $i++) { $app_buf = $applicationDB->import($applications[$i]['id']); if (is_object($app_buf)) { $applications[$i]["obj"] = $app_buf; } } page_header(); echo '<h1>' . str_replace('%ID%', $session['id'], _('Archived session - %ID%')) . '</h1>'; echo '<ul>'; echo '<li><strong>' . _('User:'******'</strong> '; if (is_object($user)) { echo '<a href="users.php?action=manage&id=' . $user->getAttribute('login') . '">' . $user->getAttribute('displayname') . '</a>'; } else { echo $session['user'] . ' <span><em>' . _('Not existing anymore') . '</em></span>'; } echo '</li>'; echo '<li><strong>' . _('Started:') . '</strong> '; echo $session['start_stamp']; echo '</li>'; echo '<li><strong>' . _('Stopped:') . '</strong> '; echo $session['stop_stamp']; if (isset($session['stop_why']) && strlen($session['stop_why']) > 0) { echo ' <em>(' . $session['stop_why'] . ')</em>'; } echo '</li>'; echo '</ul>'; if (count($applications) > 0) { echo '<div>'; echo '<h2>' . _('Used applications') . '</h2>'; echo '<ul>'; foreach ($applications as $application) { echo '<li>'; if (isset($application['obj'])) { echo '<img src="media/image/cache.php?id=' . $application['obj']->getAttribute('id') . '" alt="" title="" /> '; echo '<a href="applications.php?action=manage&id=' . $application['obj']->getAttribute('id') . '">' . $application['obj']->getAttribute('name') . '</a>'; } else { echo $application['id'] . ' <span><em>' . _('not existing anymore') . '</em></span>'; } if ($application['start'] - $application['start'] > 0) { echo ' - (' . ($application['start'] - $application['start']) / 60 . 'm)'; } echo '</li>'; } echo '</ul>'; echo '</div>'; } page_footer(); die; }
public function applications($type = NULL, $with_static_ = true) { Logger::debug('main', "USER::applications(type={$type}, with_static={$with_static_})"); $applicationDB = ApplicationDB::getInstance(); $my_applications_id = array(); $my_applications = array(); $appgroups_id = $this->appsGroups(); foreach ($appgroups_id as $agrp_id) { $els = Abstract_Liaison::load('AppsGroup', NULL, $agrp_id); if (is_array($els)) { foreach ($els as $e) { array_push($my_applications_id, $e->element); } } } $my_applications_id = array_unique($my_applications_id); foreach ($my_applications_id as $id) { $app = $applicationDB->import($id); if (is_object($app)) { if ($type != NULL) { if ($app->getAttribute('type') == $type) { if ($app->getAttribute('static')) { if ($with_static_) { $my_applications[] = $app; } } else { $my_applications[] = $app; } } } else { if ($app->getAttribute('static')) { if ($with_static_) { $my_applications[] = $app; } } else { $my_applications[] = $app; } } } } return $my_applications; }
function show_step5() { page_header(); echo '<div>'; echo '<h1><a href="wizard.php">' . _('Publication Wizard') . '</a> - ' . _('Confirmation') . '</h1>'; echo '<p>' . _('Are you sure that you want to create this publication?') . '</p>'; echo '<table style="width: 50%;" border="0" cellspacing="1" cellpadding="3">'; echo '<tr>'; echo '<td style="text-align: left; vertical-align: top;">'; echo '<div class="container rounded" style="background: #eee;">'; if ($_SESSION['wizard']['use_users'] == 'usergroups') { $usergroupDB = UserGroupDB::getInstance(); echo '<p style="font-weight: bold;">'; if (count($_SESSION['wizard']['usergroups']) == 1) { echo _('Between this users group'); } else { echo _('Between these users groups'); } echo '</p>'; echo '<ul>'; foreach ($_SESSION['wizard']['usergroups'] as $ug_id) { $ug = $usergroupDB->import($ug_id); if (!is_object($ug)) { Logger::warning('main', '(admin/wizard) Usergroup \'' . $ug_id . '\' import failed'); continue; } echo '<li>' . $ug->name . '</li>'; } echo '</ul>'; } elseif ($_SESSION['wizard']['use_users'] == 'users') { $userDB = UserDB::getInstance(); echo '<p style="font-weight: bold;">'; echo _('Between this newly created users group'); echo '</p>'; echo '<ul>'; echo '<li><strong>' . _('Name:') . '</strong> ' . $_SESSION['wizard']['user_group_name'] . '</li>'; echo '<li><strong>' . _('Description: ') . '</strong> ' . $_SESSION['wizard']['user_group_description'] . '</li>'; echo '<li><strong>' . _('Users:') . '</strong> <ul>'; foreach ($_SESSION['wizard']['users'] as $user_login) { $user = $userDB->import($user_login); if (!is_object($user)) { Logger::warning('main', '(admin/wizard) User \'' . $user_login . '\' import failed'); continue; } echo '<li>' . $user->getAttribute('displayname') . '</li>'; } echo '</ul></li>'; echo '</ul>'; } echo '</div>'; echo '</td>'; echo '<td style="width: 50px;">'; echo '</td>'; echo '<td style="text-align: left; vertical-align: top;">'; echo '<div class="container rounded" style="background: #eee;">'; if ($_SESSION['wizard']['use_apps'] == 'appgroups') { $applicationsGroupDB = ApplicationsGroupDB::getInstance(); echo '<p style="font-weight: bold;">'; if (count($_SESSION['wizard']['appgroups']) == 1) { echo _('and this applications group'); } else { echo _('and these applications groups'); } echo '</p>'; echo '<ul>'; foreach ($_SESSION['wizard']['appgroups'] as $ag_id) { $appgroup = $applicationsGroupDB->import($ag_id); if (is_object($appgroup)) { echo '<li>' . $appgroup->name . '</li>'; } } echo '</ul>'; } elseif ($_SESSION['wizard']['use_apps'] == 'apps') { $applicationDB = ApplicationDB::getInstance(); echo '<p style="font-weight: bold;">'; echo _('and this newly created applications group'); echo '</p>'; echo '<ul>'; echo '<li><strong>' . _('Name:') . '</strong> ' . $_SESSION['wizard']['application_group_name'] . '</li>'; echo '<li><strong>' . _('Description: ') . '</strong> ' . $_SESSION['wizard']['application_group_description'] . '</li>'; echo '<li><strong>' . _('Applications:') . '</strong> <ul>'; foreach ($_SESSION['wizard']['apps'] as $application_id) { $application = $applicationDB->import($application_id); if (!is_object($application)) { Logger::warning('main', '(admin/wizard) Application \'' . $application_id . '\' import failed'); continue; } echo '<li>' . $application->getAttribute('name') . '</li>'; } echo '</ul></li>'; echo '</ul>'; } echo '</div>'; echo '</td>'; echo '</tr>'; echo '</table>'; echo '<form action="" method="post">'; echo '<input type="hidden" name="from" value="step5" />'; echo '<table style="width: 50%;" class="" border="0" cellspacing="1" cellpadding="5">'; echo '<tr>'; echo '<td colspan="2">'; echo '<table style="width: 100%;" border="0" cellspacing="0" cellpadding="0">'; echo '<tr>'; echo '<td style="text-align: left;">'; echo '<input type="submit" name="submit_previous" value="' . _('Previous') . '" />'; echo '</td>'; echo '<td style="text-align: right;">'; echo '<input type="submit" name="submit_next" value="' . _('Confirm') . '" />'; echo '</td>'; echo '</tr>'; echo '</table>'; echo '</td>'; echo '</tr>'; echo '</table>'; echo '</form>'; echo '</div>'; page_footer(); die; }
public function updateApplications() { Logger::debug('main', 'Server::updateApplications'); if (!is_array($this->roles) || !array_key_exists(Server::SERVER_ROLE_APS, $this->roles)) { Logger::critical('main', 'SERVER::updateApplications - Not an ApS'); return false; } if (!$this->isOnline()) { Logger::debug('main', 'Server::updateApplications server "' . $this->fqdn . ':' . $this->web_port . '" is not online'); return false; } $applicationDB = ApplicationDB::getInstance(); $xml = query_url($this->getBaseURL() . '/aps/applications'); if (!$xml) { $this->isUnreachable(); Logger::error('main', 'Server::updateApplications server \'' . $this->fqdn . '\' is unreachable'); return false; } if (!is_string($xml)) { Logger::error('main', 'Server::updateApplications invalid xml1'); return false; } if (substr($xml, 0, 5) == 'ERROR') { $this->returnedError(); Logger::error('main', 'Server::updateApplications invalid xml2'); return false; } if ($xml == '') { Logger::error('main', 'Server::updateApplications invalid xml3'); return false; } $dom = new DomDocument('1.0', 'utf-8'); @$dom->loadXML($xml); $root = $dom->documentElement; // before adding application, we remove all previous applications $previous_liaison = Abstract_Liaison::load('ApplicationServer', NULL, $this->fqdn); // see end of function $current_liaison_key = array(); $application_node = $dom->getElementsByTagName("application"); $sync_apps = array(); foreach ($application_node as $app_node) { $app_name = ''; $app_description = ''; $app_path_exe = ''; $app_path_args = NULL; $app_package = NULL; $app_desktopfile = NULL; if ($app_node->hasAttribute("name")) { $app_name = $app_node->getAttribute("name"); } if ($app_node->hasAttribute("description")) { $app_description = $app_node->getAttribute("description"); } if ($app_node->hasAttribute("package")) { $app_package = $app_node->getAttribute("package"); } if ($app_node->hasAttribute("desktopfile")) { $app_desktopfile = $app_node->getAttribute("desktopfile"); } $local_id = $app_node->getAttribute("id"); $exe_node = $app_node->getElementsByTagName('executable')->item(0); if ($exe_node->hasAttribute("command")) { $command = $exe_node->getAttribute("command"); $command = str_replace(array("%U", "%u", "%c", "%i", "%f", "%m"), "", $command); $app_path_exe = trim($command); } $mimetypes = array(); $mime_nodes = $app_node->getElementsByTagName('mime'); foreach ($mime_nodes as $mime_node) { if (!$mime_node->hasAttribute("type")) { continue; } $mimetypes[] = $mime_node->getAttribute("type"); } $a = new Application(NULL, $app_name, $app_description, $this->getAttribute('type'), $app_path_exe, $app_package, true, $app_desktopfile); $a->setMimeTypes($mimetypes); $a_search = $applicationDB->search($app_name, $app_description, $this->getAttribute('type'), $app_path_exe); if (is_object($a_search)) { //already in DB // echo $app_name." already in DB\n"; $a = $a_search; } else { // echo $app_name." NOT in DB\n"; if ($applicationDB->isWriteable() == false) { Logger::debug('main', 'Server::updateApplications applicationDB is not writeable'); } else { if ($applicationDB->add($a) == false) { //echo 'app '.$app_name." not insert<br>\n"; return false; } } } if ($applicationDB->isWriteable() == true) { if ($applicationDB->isOK($a) == true) { // we add the app to the server if (!is_object(Abstract_Liaison::load('ApplicationServer', $a->getAttribute('id'), $this->fqdn))) { $ret = Abstract_Liaison::save('ApplicationServer', $a->getAttribute('id'), $this->fqdn); if ($ret === false) { Logger::error('main', 'Server::updateApplications failed to save application'); return $ret; } } $current_liaison_key[] = $a->getAttribute('id'); } else { //echo "Application not ok<br>\n"; } } $sync_apps[$local_id] = $a->getAttribute('id'); } $previous_liaison_key = array_keys($previous_liaison); foreach ($previous_liaison_key as $key) { if (in_array($key, $current_liaison_key) == false) { $a = $applicationDB->import($key); if (is_null($a) || $a->getAttribute('static') == false) { Abstract_Liaison::delete('ApplicationServer', $key, $this->fqdn); } } } if (count($sync_apps) > 0) { $dom = new DomDocument('1.0', 'utf-8'); $applications_node = $dom->createElement('applications'); foreach ($sync_apps as $local_id => $id) { $application_node = $dom->createElement('application'); $application_node->setAttribute('id', $id); $application_node->setAttribute('local_id', $local_id); $applications_node->appendChild($application_node); } $dom->appendChild($applications_node); $xml = $dom->saveXML(); query_url_post_xml($this->getBaseURL() . '/aps/applications/ids', $xml); foreach ($sync_apps as $local_id => $id) { $a = $applicationDB->import($id); if (!is_object($a)) { continue; } if (!file_exists($a->getIconPathRW())) { $this->getApplicationIcon($a->getAttribute('id')); } } } return true; }
function application_desktops_to_ids() { $applicationDB = ApplicationDB::getInstance(); $all_applications = $applicationDB->getList(); $ret = array(); foreach ($all_applications as $app) { $ret[$app->getAttribute('desktopfile')] = (int) $app->getAttribute('id'); } return $ret; }
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; }
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; }
public static function removeRole($fqdn_, $role_) { Logger::debug('main', "Starting Abstract_Server::removeRole for '{$fqdn_}' removing '{$role_}'"); if (substr($fqdn_, -1) == '.') { $fqdn_ = substr($fqdn_, 0, strlen($fqdn_) - 1); } $a_server = Abstract_Server::load($fqdn_); if (is_object($a_server) == false) { Logger::error('main', "Starting Abstract_Server::removeRole error failed to load server '{$fqdn_}'"); return false; } $roles = $a_server->getAttribute('roles'); if (is_array($roles) == false) { return false; } if (in_array($role_, $roles) == false) { return false; } switch ($role_) { case Server::SERVER_ROLE_APS: $prefs = Preferences::getInstance(); if (!$prefs) { die_error('get Preferences failed', __FILE__, __LINE__); } $slave_server_settings = $prefs->get('general', 'slave_server_settings'); $remove_orphan = (bool) $slave_server_settings['remove_orphan']; Abstract_Liaison::delete('ApplicationServer', NULL, $fqdn_); if ($remove_orphan) { $apps = $a_server->getApplications(); $applicationDB = ApplicationDB::getInstance(); // remove the orphan applications if (is_array($apps)) { foreach ($apps as $an_application) { if ($an_application->isOrphan()) { Logger::debug('main', "Abstract_Server::delete {$an_application} is orphan"); $applicationDB->remove($an_application); } } } } $tm = new Tasks_Manager(); $tm->load_from_server($fqdn_); foreach ($tm->tasks as $a_task) { $tm->remove($a_task->id); } break; case Server::SERVER_ROLE_FS: if (Preferences::moduleIsEnabled('ProfileDB')) { $profiledb = ProfileDB::getInstance(); $folders = $profiledb->importFromServer($fqdn_); foreach ($folders as $a_folder) { $profiledb->remove($a_folder->id); } } if (Preferences::moduleIsEnabled('SharedFolderDB')) { $sharedfolderdb = SharedFolderDB::getInstance(); $folders = $sharedfolderdb->importFromServer($fqdn_); foreach ($folders as $a_folder) { $profiledb->remove($a_folder->id); } } break; // case Server::SERVER_ROLE_GATEWAY: // break; } return true; }
function show_manage($id) { $applicationsGroupDB = ApplicationsGroupDB::getInstance(); $group = $applicationsGroupDB->import($id); if (!is_object($group)) { die_error('Import Group "' . $id . '" failed', __FILE__, __LINE__); } if ($group->published) { $status = '<span class="msg_ok">' . _('Enabled') . '</span>'; $status_change = _('Block'); $status_change_value = 0; } else { $status = '<span class="msg_error">' . _('Blocked') . '</span>'; $status_change = _('Enable'); $status_change_value = 1; } $applicationDB = ApplicationDB::getInstance(); $userGroupDB = UserGroupDB::getInstance(); $applications_all = $applicationDB->getList(true); $applications_id = array(); $liaisons = Abstract_Liaison::load('AppsGroup', NULL, $id); foreach ($liaisons as $liaison) { $applications_id[] = $liaison->element; } $applications = array(); $applications_available = array(); foreach ($applications_all as $application) { if (!in_array($application->getAttribute('id'), $applications_id)) { $applications_available[] = $application; } else { $applications[] = $application; } } // Publications $groups_users = array(); foreach (Abstract_Liaison::load('UsersGroupApplicationsGroup', NULL, $id) as $group_liaison) { $obj = $userGroupDB->import($group_liaison->element); if (is_object($obj)) { $groups_users[] = $obj; } } $groups_users_all = $userGroupDB->getList(true); $groups_users_available = array(); foreach ($groups_users_all as $group_users) { if (!in_array($group_users, $groups_users)) { $groups_users_available[] = $group_users; } } $can_manage_applicationsgroups = isAuthorized('manageApplicationsGroups'); $can_manage_publications = isAuthorized('managePublications'); page_header(); echo '<div>'; echo '<h1><a href="?">' . _('Application groups management') . '</a> - ' . $group->name . '</h1>'; echo '<table class="main_sub" border="0" cellspacing="1" cellpadding="3">'; echo '<tr class="title">'; echo '<th>' . _('Description') . '</th>'; echo '<th>' . _('Status') . '</th>'; echo '</tr>'; echo '<tr class="content1">'; echo '<td>' . $group->description . '</td>'; echo '<td>' . $status . '</td>'; echo '</tr>'; echo '</table>'; if ($can_manage_applicationsgroups) { echo '<div>'; echo '<h2>' . _('Settings') . '</h2>'; echo '<form action="actions.php" method="post" onsubmit="return confirm(\'' . _('Are you sure you want to delete this group?') . '\');">'; echo '<input type="submit" value="' . _('Delete this group') . '"/>'; echo '<input type="hidden" name="name" value="ApplicationsGroup" />'; echo '<input type="hidden" name="action" value="del" />'; echo '<input type="hidden" name="checked_groups[]" value="' . $id . '" />'; echo '<input type="hidden" name="id" value="' . $id . '" />'; echo '</form>'; echo '<br/>'; echo '<form action="actions.php" method="post">'; echo '<input type="hidden" name="name" value="ApplicationsGroup" />'; echo '<input type="hidden" name="action" value="modify" />'; echo '<input type="hidden" name="id" value="' . $id . '" />'; echo '<input type="hidden" name="published_appsgroup" value="' . $status_change_value . '" />'; echo '<input type="submit" value="' . $status_change . '"/>'; echo '</form>'; echo '<br/>'; echo '<form action="actions.php" method="post">'; echo '<input type="hidden" name="name" value="ApplicationsGroup" />'; echo '<input type="hidden" name="action" value="modify" />'; echo '<input type="hidden" name="id" value="' . $id . '" />'; echo '<input type="text" name="name_appsgroup" value="' . $group->name . '" size="50" /> '; echo '<input type="submit" value="' . _('Update the name') . '"/>'; echo '</form>'; echo '<br/>'; echo '<form action="actions.php" method="post">'; echo '<input type="hidden" name="name" value="ApplicationsGroup" />'; echo '<input type="hidden" name="action" value="modify" />'; echo '<input type="hidden" name="id" value="' . $id . '" />'; echo '<input type="text" name="description_appsgroup" value="' . $group->description . '" size="50" /> '; echo '<input type="submit" value="' . _('Update the description') . '"/>'; echo '</form>'; echo '<br/>'; } // Application part if (count($applications_all) > 0 and $can_manage_applicationsgroups or count($applications) > 0) { echo '<div>'; echo '<h2>' . _('List of applications in this group') . '</h2>'; echo '<table border="0" cellspacing="1" cellpadding="3">'; if (count($applications) > 0) { foreach ($applications as $application) { echo '<tr>'; echo '<td><img src="media/image/cache.php?id=' . $application->getAttribute('id') . '" alt="' . $application->getAttribute('name') . '" title="' . $application->getAttribute('name') . '" /> <a href="applications.php?action=manage&id=' . $application->getAttribute('id') . '">' . $application->getAttribute('name') . '</a>'; echo '</td>'; if ($can_manage_applicationsgroups) { 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="action" value="del" />'; echo '<input type="hidden" name="name" value="Application_ApplicationGroup" />'; echo '<input type="hidden" name="group" value="' . $id . '" />'; echo '<input type="hidden" name="element" value="' . $application->getAttribute('id') . '" />'; echo '<input type="submit" value="' . _('Delete from this group') . '" />'; echo '</form>'; echo '</td>'; } echo '</tr>'; } } if (count($applications_available) > 0 and $can_manage_applicationsgroups) { echo '<tr><form action="actions.php" method="post"><td>'; echo '<input type="hidden" name="action" value="add" />'; echo '<input type="hidden" name="name" value="Application_ApplicationGroup" />'; echo '<input type="hidden" name="group" value="' . $id . '" />'; echo '<select name="element">'; foreach ($applications_available as $application) { echo '<option value="' . $application->getAttribute('id') . '" >' . $application->getAttribute('name') . ' (' . $application->getAttribute('type') . ')</option>'; } echo '</select>'; echo '</td><td><input type="submit" value="' . _('Add to this group') . '" /></td>'; echo '</form></tr>'; } echo '</table>'; echo '</div>'; } /* // Servers echo '<div>'; echo '<h2>'._('List of servers including this group').'</h2>'; echo '<table border="0" cellspacing="1" cellpadding="3">'; if (count($servers) == 0) echo '<tr><td colspan="2">'._('No server has this group').'</td></tr>'; else { foreach($servers as $server) { echo '<tr>'; echo '<td><a href="servers.php?action=manage&id='.$server->fqdn.'">'.$server->fqdn.'</a>'; echo '</td>'; echo '<td>'; echo '<form action="actions.php" method="post" onsubmit="return confirm(\''._('Are you sure you want to delete this group from this server?').'\');">'; echo '<input type="hidden" name="action" value="del" />'; echo '<input type="hidden" name="name" value="ApplicationGroup_Server" />'; echo '<input type="hidden" name="group" value="'.$id.'" />'; echo '<input type="hidden" name="server" value="'.$server->fqdn.'" />'; echo '<input type="submit" value="'._('Delete from this group').'" /> FIXME'; echo '</form>'; echo '</td>'; echo '</tr>'; } } if (count ($servers_available) ==0) echo '<tr><td colspan="2">'._('Not any available server to add').'</td></tr>'; else { echo '<tr><form action="actions.php" method="post"><td>'; echo '<input type="hidden" name="action" value="add" />'; echo '<input type="hidden" name="name" value="Application_ApplicationGroup" />'; echo '<input type="hidden" name="group" value="'.$id.'" />'; echo '<select name="element">'; foreach($servers_available as $servers) echo '<option value="'.$server->fqdn.'" >'.$server->fqdn.'</option>'; echo '</select>'; echo '</td><td><input type="submit" value="'._('Add to this server').'" /></td>'; echo '</form></tr>'; } echo '</table>'; echo '</div>'; */ // Publication part if (count($groups_users_all) > 0) { echo '<div>'; echo '<h2>' . _('List of publications for this group') . '</h1>'; echo '<table border="0" cellspacing="1" cellpadding="3">'; if (count($groups_users) > 0) { foreach ($groups_users as $group_users) { echo '<tr>'; echo '<td><a href="usersgroup.php?action=manage&id=' . $group_users->getUniqueID() . '">' . $group_users->name . '</td>'; if ($can_manage_publications) { echo '<td>'; echo '<form action="actions.php" method="post" onsubmit="return confirm(\'' . _('Are you sure you want to delete this publication?') . '\');">'; echo '<input type="hidden" name="action" value="del" />'; echo '<input type="hidden" name="name" value="Publication" />'; echo '<input type="hidden" name="group_a" value="' . $id . '" />'; echo '<input type="hidden" name="group_u" value="' . $group_users->getUniqueID() . '" />'; echo '<input type="submit" value="' . _('Delete this publication') . '" />'; echo '</form>'; echo '</td>'; } echo '</tr>'; } } if (count($groups_users_available) > 0 and $can_manage_publications) { echo '<tr><form action="actions.php" method="get"><td>'; echo '<input type="hidden" name="action" value="add" />'; echo '<input type="hidden" name="name" value="Publication" />'; echo '<input type="hidden" name="group_a" value="' . $id . '" />'; echo '<select name="group_u">'; foreach ($groups_users_available as $group_users) { echo '<option value="' . $group_users->getUniqueID() . '" >' . $group_users->name . '</option>'; } echo '</select>'; echo '</td><td><input type="submit" value="' . _('Add this publication') . '" /></td>'; echo '</form></tr>'; } echo '</table>'; echo '</div>'; } echo '</div>'; echo '</div>'; echo '</div>'; page_footer(); die; }
function server_display_role_preparation_aps($server) { $ret = array(); $server_online = $server->isOnline(); if ($server_online) { $buf = $server->updateApplications(); if (!$buf) { popup_error(_('Cannot list available applications')); } } $applicationDB = ApplicationDB::getInstance(); $applications_all = $applicationDB->getList(true); $applications = $server->getApplications(); if (!is_array($applications)) { $applications = array(); } usort($applications, 'application_cmp'); $applications_available = array(); $static_applications_available = array(); if (!$server_online && count($applications) == 0) { $applications_all = array(); } $servers_all = Abstract_Server::load_by_status(Server::SERVER_STATUS_ONLINE); foreach ($servers_all as $k => $v) { if ($v->fqdn == $server->fqdn) { unset($servers_all[$k]); } } $servers_replication = Abstract_Server::load_by_status(Server::SERVER_STATUS_ONLINE); foreach ($servers_replication as $k => $v) { if ($v->fqdn == $server->fqdn) { unset($servers_replication[$k]); } if ($v->type != $server->getAttribute('type')) { unset($servers_replication[$k]); } if (!array_key_exists('aps', $v->roles) || $v->roles['aps'] !== true) { unset($servers_replication[$k]); } if ($server->hasAttribute('ulteo_system') == false || $server->getAttribute('ulteo_system') == 0) { unset($servers_replication[$k]); } } $sessions = array(); $total = Abstract_Session::countByServer($_GET['fqdn']); if ($total > 0) { $has_sessions = true; $prefs = Preferences::getInstance(); if (!$prefs) { die_error('get Preferences failed', __FILE__, __LINE__); } if ($total > $prefs->get('general', 'max_items_per_page')) { if (!isset($_GET['start']) || (!is_numeric($_GET['start']) || $_GET['start'] >= $total)) { $start = 0; } else { $start = $_GET['start']; } $pagechanger = get_pagechanger('servers.php?action=manage&fqdn=' . $_GET['fqdn'] . '&', $prefs->get('general', 'max_items_per_page'), $total); $sessions = Abstract_Session::getByServer($_GET['fqdn'], $prefs->get('general', 'max_items_per_page'), $start); } else { $sessions = Abstract_Session::getByServer($_GET['fqdn']); } } else { $has_sessions = false; } $external_name_checklist = array('localhost', '127.0.0.1'); if (in_array($server->fqdn, $external_name_checklist) && in_array($server->getAttribute('external_name'), $external_name_checklist)) { popup_error(sprintf(_('Server "%s": redirection name may be invalid!'), $server->fqdn)); } if ($server->getAttribute('external_name') == '') { popup_error(sprintf(_('Server "%s": redirection name cannot be empty!'), $server->fqdn)); } if ($server_online) { //FIX ME ? $tm = new Tasks_Manager(); $tm->load_from_server($server->fqdn); $tm->refresh_all(); $apps_in_remove = array(); $apps_in_install = array(); $tasks = array(); if ($server_online) { foreach ($tm->tasks as $task) { if (!$task->succeed()) { $tasks[] = $task; } } foreach ($tasks as $task) { if (get_class($task) == 'Task_install') { foreach ($task->applications as $app) { if (!in_array($app, $apps_in_install)) { $apps_in_install[] = $app; } } } if (get_class($task) == 'Task_remove') { foreach ($task->applications as $app) { if (!in_array($app, $apps_in_remove)) { $apps_in_remove[] = $app; } } } } foreach ($applications_all as $app) { if (in_array($app, $applications)) { continue; } if (in_array($app, $apps_in_install)) { continue; } if ($app->getAttribute('type') != $server->getAttribute('type')) { continue; } $applications_available[] = $app; } } $ret['tasks'] = $tasks; $ret['apps_in_install'] = $apps_in_install; $ret['apps_in_remove'] = $apps_in_remove; } $ret['can_do_action'] = isAuthorized('manageServers'); $ret['web_port'] = $server->getAttribute('web_port'); $ret['can_use_apt'] = isset($server->ulteo_system) && $server->ulteo_system == 1 ? true : false; $ret['server_online'] = $server_online; $ret['sessions'] = $sessions; $ret['has_sessions'] = $has_sessions; $ret['total_sessions'] = $total; if (isset($pagechanger)) { $ret['pagechanger'] = $pagechanger; } $ret['applications'] = $applications; $ret['applications_available'] = $applications_available; $ret['applications_all'] = $applications_all; $ret['servers_all'] = $servers_all; $ret['servers_replication'] = $servers_replication; return $ret; }