public static function save($type_, $element_, $group_)
 {
     Logger::debug('main', "Abstract_Liaison_sql::save ({$type_},{$element_},{$group_})");
     $sql2 = SQL::getInstance();
     $table = $sql2->prefix . 'liaison';
     $res = $sql2->DoQuery('SELECT @3,@4 FROM @1 WHERE @2=%5 AND @3=%6 AND @4=%7', $table, 'type', 'element', 'group', $type_, $element_, $group_);
     if ($sql2->NumRows() > 0) {
         Logger::error('main', 'Abstract_Liaison_sql::save Liaison(type=' . $type_ . ',element=' . $element_ . ',group=' . $group_ . ') already exists');
         popup_error('liaison(type=' . $type_ . ',element=' . $element_ . ',group=' . $group_ . ') already exists');
         return false;
     }
     $res = $sql2->DoQuery('INSERT INTO @1 ( @2,@3,@4 ) VALUES ( %5,%6,%7)', $table, 'type', 'element', 'group', $type_, $element_, $group_);
     return $res !== false;
 }
 public function __call($name, $arguments)
 {
     try {
         $res = $this->service->__call($name, $arguments);
     } catch (Exception $e) {
         if ($e->faultcode == 'not_authorized') {
             popup_error(_('You are not allowed to perform this action'));
         } else {
             popup_error(self::format_soap_error_message($e));
         }
         return null;
     }
     if (defined('DEBUG_MODE') && DEBUG_MODE === true) {
         popup_info('soap Call ' . $name);
     }
     return $res;
 }
function do_save($prefs, $name)
{
    $obj = new $name();
    if (!$obj->form_valid($_POST)) {
        popup_error('Invalid form');
        return False;
    }
    $flag = $obj->form_read($_POST, $prefs);
    if ($flag === False) {
        popup_error('form_read return an error');
        return False;
    }
    if (!$prefs->backup()) {
        popup_error('Unable to save configuration');
        return False;
    }
    return True;
}
Example #4
0
function adminAuthenticate($login_, $password_)
{
    if (array_key_exists('no_ssl', $_SESSION)) {
        unset($_SESSION['no_ssl']);
    }
    try {
        $service = new SessionManager($login_, $password_, true);
        $ret = $service->test_link_connected();
    } catch (Exception $e) {
        if ($e->faultcode == 'auth_failed') {
            $_SESSION['admin_error'] = _('There was an error with your authentication');
            return false;
        }
        if (defined('DEBUG_MODE') && DEBUG_MODE === true) {
            popup_error('Unable to login the Session Manager using HTTPS method, retry with HTTP');
        }
        try {
            $service = new SessionManager($login_, $password_, false);
            $ret = $service->test_link_connected();
        } catch (Exception $e) {
            if ($e->faultcode == 'auth_failed') {
                $_SESSION['admin_error'] = _('There was an error with your authentication');
                return false;
            }
            if (defined('DEBUG_MODE') && DEBUG_MODE === true) {
                popup_error($service->format_soap_error_message($e));
            }
            die_error(_('Unable to initialize communication with Session Manager'));
        }
        $_SESSION['no_ssl'] = true;
        if (defined('DEBUG_MODE') && DEBUG_MODE === true) {
            popup_info('Succefully connected the Session Manager using HTTP method, will alwais use HTTP for this session');
        }
    }
    $_SESSION['admin_login'] = $login_;
    $_SESSION['admin_password'] = $password_;
    $_SESSION['service'] = $service;
    return true;
}
Example #5
0
 public function init()
 {
     $server = Abstract_Server::load($this->server);
     if (!is_object($server)) {
         Logger::error('apt-get', 'TASK::init for task ' . $this->id . ' returned an error (unknown server ' . $this->server . ')');
         return false;
     }
     $dom = new DomDocument('1.0', 'utf-8');
     $node = $dom->createElement('debian');
     $node->setAttribute('request', $this->getRequest());
     foreach ($this->getPackages() as $package) {
         $buf = $dom->createElement('package');
         $buf->setAttribute('name', $package);
         $node->appendChild($buf);
     }
     $dom->appendChild($node);
     $xml = $dom->saveXML();
     $xml = query_url_post_xml($server->getBaseURL() . '/aps/debian', $xml);
     if (!$xml) {
         popup_error(sprintf(_("Unable to submit Task to server '%s'"), $server->fqdn));
         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('debian_request')->item(0);
     if (is_null($node)) {
         return false;
     }
     $this->job_id = $node->getAttribute('id');
     $this->status = $node->getAttribute('status');
     return true;
 }
Example #6
0
 public function add($user_)
 {
     Logger::debug('main', 'UserDB::sql::add');
     if ($this->isOK($user_)) {
         // user already exists ?
         $user_from_db = $this->exists($user_->getAttribute('login'));
         if ($user_from_db === true) {
             Logger::error('main', 'UserDB_sql::add user (login='******'login') . ') already exists');
             popup_error(_('User already exists'));
             return false;
         }
         $query_keys = "";
         $query_values = "";
         $attributes = $user_->getAttributesList();
         foreach ($attributes as $key) {
             if ($key == 'password') {
                 $value = crypt($user_->getAttribute($key), md5($user_->getAttribute('login')));
             } else {
                 $value = $user_->getAttribute($key);
             }
             $query_keys .= '`' . $key . '`,';
             $query_values .= '"' . mysql_escape_string($value) . '",';
         }
         $query_keys = substr($query_keys, 0, -1);
         // del the last ,
         $query_values = substr($query_values, 0, -1);
         // del the last ,
         $SQL = SQL::getInstance();
         $query = 'INSERT INTO `' . $this->table . '` ( ' . $query_keys . ' ) VALUES (' . $query_values . ' )';
         $ret = $SQL->DoQuery($query);
         $id = $SQL->InsertId();
         $user_->setAttribute('id', $id);
         return $ret;
     } else {
         if ($user_->hasAttribute('login')) {
             Logger::debug('main', 'UserDB::sql::add failed (user \'' . $user_->getAttribute('login') . '\' not ok)');
         } else {
             Logger::debug('main', 'UserDB::sql::add failed (user not ok)');
         }
         return false;
     }
 }
Example #7
0
function show_manage($sharedfolder_id_)
{
    $sharedfolder = $group = $_SESSION['service']->shared_folder_info($sharedfolder_id_);
    if (is_null($sharedfolder)) {
        popup_error(sprintf(_("Failed to import shared folder '%s'"), $sharedfolder_id_));
        redirect('sharedfolders.php');
    }
    $server_displayname = $sharedfolder->server;
    $server = $_SESSION['service']->server_info($sharedfolder->server);
    if (!is_null($server)) {
        $server_displayname = $server->getDisplayName();
    }
    $usersgroupsList = new UsersGroupsList($_REQUEST);
    $all_groups = $usersgroupsList->search();
    if (!is_array($all_groups)) {
        $all_groups = array();
        popup_error(_("Failed to get User Group data"));
    }
    uasort($all_groups, "usergroup_cmp");
    $searchDiv = $usersgroupsList->getForm();
    $available_groups = array();
    $used_groups = array();
    if ($sharedfolder->hasAttribute('groups')) {
        $used_groups = array();
        $mods_by_group = array();
        $groups2 = $sharedfolder->getAttribute('groups');
        foreach ($groups2 as $mode => $groups3) {
            foreach ($groups3 as $group_id => $group_name) {
                $used_groups[$group_id] = $group_name;
                $mods_by_group[$group_id] = $mode;
            }
        }
    }
    foreach ($all_groups as $group) {
        if (array_key_exists($group->id, $used_groups) === false) {
            $available_groups[$group->id] = $group;
        }
    }
    $can_manage_sharedfolders = isAuthorized('manageSharedFolders');
    page_header();
    echo '<div id="sharedfolders_div">';
    echo '<h1>' . $sharedfolder->name . '</h1>';
    echo '<div>';
    echo '<h2>' . _('Server') . '</h2>';
    echo '<a href="servers.php?action=manage&id=' . $sharedfolder->server . '"> ' . $server_displayname . '</a>';
    echo '</div>';
    echo '<br />';
    echo '<div>';
    echo '<h2>' . _('Configuration') . '</h2>';
    echo '<table>';
    echo '<tr><td>';
    echo _('Name') . ': ';
    echo '</td><td>';
    if ($can_manage_sharedfolders) {
        echo '<form action="actions.php" method="post">';
        echo '<input type="hidden" name="name" value="SharedFolder" />';
        echo '<input type="hidden" name="action" value="rename" />';
        echo '<input type="hidden" name="id" value="' . $sharedfolder->id . '" />';
    }
    echo '<input type="text" name="sharedfolder_name" value="' . $sharedfolder->name . '" />';
    if ($can_manage_sharedfolders) {
        echo ' <input type="submit" value="' . _('Rename') . '" />';
        echo '</form>';
    }
    echo '</td></tr>';
    echo '</table>';
    echo '</div>';
    echo '<br />';
    echo '<div>';
    echo '<h2>' . _('Publications') . '</h2>';
    echo '<table border="0" cellspacing="1" cellpadding="3">';
    foreach ($used_groups as $group_id => $group_name) {
        echo '<tr>';
        echo '<td><a href="usersgroup.php?action=manage&amp;id=' . $group_id . '">' . $group_name . '</a></td>';
        echo '<td>' . $mods_by_group[$group_id] . '</td>';
        if ($can_manage_sharedfolders) {
            echo '<td><form action="actions.php" method="post" onsubmit="return confirm(\'' . _('Are you sure you want to delete this shared folder access?') . '\');">';
            echo '<input type="hidden" name="name" value="SharedFolder_ACL" />';
            echo '<input type="hidden" name="action" value="del" />';
            echo '<input type="hidden" name="sharedfolder_id" value="' . $sharedfolder->id . '" />';
            echo '<input type="hidden" name="usergroup_id" value="' . $group_id . '" />';
            echo '<input type="submit" value="' . _('Delete access to this shared folder') . '" />';
            echo '</form></td>';
        }
        echo '</tr>';
    }
    if (count($available_groups) > 0 and $can_manage_sharedfolders) {
        echo '<tr><form action="actions.php" method="post"><td>';
        echo '<input type="hidden" name="name" value="SharedFolder_ACL" />';
        echo '<input type="hidden" name="action" value="add" />';
        echo '<input type="hidden" name="sharedfolder_id" value="' . $sharedfolder->id . '" />';
        echo '<select name="usergroup_id">';
        foreach ($available_groups as $group) {
            echo '<option value="' . $group->id . '" >' . $group->name . '</option>';
        }
        echo '</select>';
        echo '</td><td>';
        echo '<select name="mode">';
        echo '<option value="rw" >' . _('Read-write') . '</option>';
        echo '<option value="ro" >' . _('Read only') . '</option>';
        echo '</select>';
        echo '</td><td><input type="submit" value="' . _('Add access to this shared folder') . '" /></td>';
        echo '</form></tr>';
    }
    echo '</table>';
    echo $searchDiv;
    echo '</div>';
    echo '</div>';
    page_footer();
}
Example #8
0
 public function add($usergroup_)
 {
     Logger::debug('main', "USERGROUPDB::add({$usergroup_})");
     $sql2 = SQL::getInstance();
     // usergroup already exists ?
     $res = $sql2->DoQuery('SELECT 1 FROM @1 WHERE @2 = %3 AND @4 = %5', $this->table, 'name', $usergroup_->name, 'description', $usergroup_->description);
     if ($sql2->NumRows($res) > 0) {
         Logger::error('main', 'UserGroupDB_sql::add usersgroup (name=' . $usergroup_->name . ',description=' . $usergroup_->description . ') already exists');
         popup_error(_('Users group already exists'));
         return false;
     }
     $res = $sql2->DoQuery('INSERT INTO @1 (@2,@3,@4) VALUES (%5,%6,%7)', $this->table, 'name', 'description', 'published', $usergroup_->name, $usergroup_->description, $usergroup_->published);
     if ($res !== false) {
         $usergroup_->id = $sql2->InsertId();
         return is_object($this->import($sql2->InsertId()));
     } else {
         return false;
     }
 }
Example #9
0
function disable_hostDB($SQL, $table, $id_host)
{
    $query = 'SELECT * FROM `' . $table . '` WHERE register="yes" AND id_host=' . $id_host;
    $res = $SQL->DoQuery($query);
    $nb = $SQL->NumRows();
    if (!$nb) {
        popup_error(_('Cannot disable host because it is not enabled!'));
    }
    $query = 'DELETE FROM `' . $table . '` WHERE id_host=' . $id_host;
    $res = $SQL->DoQuery($query);
    $nb = $SQL->NumRows();
    if ($nb) {
        popup_info(_('Host has been disabled!'));
    } else {
        popup_error(_('An error occured during disabling host, cannot disable host!'));
    }
}
Example #10
0
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 '&nbsp<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'] . '&nbsp;<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;
}
Example #11
0
function die_error($msg_)
{
    popup_error($msg_);
    redirect('error.php');
}
Example #12
0
function checkAuthorization($policy_)
{
    if (isAuthorized($policy_)) {
        return true;
    }
    popup_error(_('You are not allowed to perform this action'));
    return false;
}
Example #13
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 server_display_role_preparation_aps($server)
{
    $ret = array();
    $server_online = $server->isOnline();
    $applications_all = $_SESSION['service']->applications_list();
    $applications = array();
    foreach ($server->applications as $application_id => $application_name) {
        if (array_key_exists($application_id, $applications_all)) {
            $applications[] = $applications_all[$application_id];
        }
    }
    uasort($applications, 'application_cmp');
    $applications_available = array();
    $static_applications_available = array();
    if (!$server_online && count($applications) == 0) {
        $applications_all = array();
    }
    $servers_replication = $_SESSION['service']->servers_list('online');
    if (is_null($servers_replication)) {
        $servers_replication = array();
    }
    foreach ($servers_replication as $k => $v) {
        if ($v->id == $server->id) {
            unset($servers_replication[$k]);
        }
        if ($v->type != $server->getAttribute('type')) {
            unset($servers_replication[$k]);
        }
        if (!array_key_exists(Server::SERVER_ROLE_APS, $v->roles)) {
            unset($servers_replication[$k]);
        }
        if ($server->hasAttribute('ulteo_system') == false || $server->getAttribute('ulteo_system') == 0) {
            unset($servers_replication[$k]);
        }
    }
    $sessions = array();
    $total = 0;
    if ($server->hasAttribute('sessions_number')) {
        $total = $server->getAttribute('sessions_number');
    }
    if ($total > 0) {
        $has_sessions = true;
        $search_limit = $_SESSION['configuration']['max_items_per_page'];
        if ($total > $search_limit) {
            if (!isset($_GET['start']) || (!is_numeric($_GET['start']) || $_GET['start'] >= $total)) {
                $start = 0;
            } else {
                $start = $_GET['start'];
            }
            $pagechanger = get_pagechanger('servers.php?action=manage&id=' . $server->id . '&', $search_limit, $total);
            $sessions = $_SESSION['service']->sessions_list_by_server($server->id, $start);
        } else {
            $sessions = $_SESSION['service']->sessions_list_by_server($server->id);
        }
    } else {
        $has_sessions = false;
    }
    $external_name_checklist = array('localhost', '127.0.0.1');
    if (in_array($server->getExternalName(), $external_name_checklist)) {
        popup_error(sprintf(_('Server "%s": redirection name may be invalid!'), $server->getDisplayName()));
    }
    if ($server_online) {
        $apps_in_remove = array();
        $apps_in_install = array();
        $tasks = array();
        if ($server_online) {
            $all_tasks = $_SESSION['service']->tasks_list();
            if (is_null($all_tasks)) {
                $all_tasks = array();
            }
            foreach ($all_tasks as $task) {
                if ($task->getAttribute('server') != $server->id) {
                    continue;
                }
                if (!$task->succeed()) {
                    $tasks[] = $task;
                }
            }
            foreach ($tasks as $task) {
                if ($task->hasAttribute('applications')) {
                    continue;
                }
                if ($task->getAttribute('type') == 'Task_install') {
                    foreach ($task->getAttribute('applications') as $app) {
                        if (!in_array($app, $apps_in_install)) {
                            $apps_in_install[] = $app;
                        }
                    }
                }
                if ($task->getAttribute('type') == 'Task_remove') {
                    foreach ($task->getAttribute('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;
                }
                if ($app->getAttribute('static') == 1) {
                    $static_applications_available[] = $app;
                } else {
                    $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['static_applications_available'] = $static_applications_available;
    $ret['applications_all'] = $applications_all;
    $ret['servers_replication'] = $servers_replication;
    return $ret;
}
Example #15
0
function get_html($id_)
{
    $session = $_SESSION['service']->session_report_info($id_);
    if (!$session) {
        popup_error(sprintf(_('Unknown session %s'), $id_));
        return false;
    }
    $user = $_SESSION['service']->user_info($session->getUser());
    $mode = '<em>' . _('unknown') . '</em>';
    $servers = array();
    $published_applications = array();
    $applications_instances = array();
    $storages = array();
    $dom = new DomDocument('1.0', 'utf-8');
    $ret = @$dom->loadXML($session->getData());
    if ($ret) {
        $root_node = $dom->documentElement;
        if ($root_node->hasAttribute('mode')) {
            $mode = $root_node->getAttribute('mode');
        }
        foreach ($dom->getElementsByTagName('server') as $node) {
            if (!($node->hasAttribute('id') && $node->hasAttribute('role'))) {
                // Not enough information to continue ...
                continue;
            }
            $server = array();
            $server['id'] = $node->getAttribute('id');
            if ($node->hasAttribute('fqdn')) {
                $server['fqdn'] = $node->getAttribute('fqdn');
                $server['name'] = $server['fqdn'];
            } else {
                $server['name'] = $server['id'];
            }
            $server['role'] = $node->getAttribute('role');
            $server['desktop_server'] = $node->hasAttribute('desktop_server');
            if ($node->hasAttribute('type')) {
                $server['type'] = $node->getAttribute('type');
            }
            $server['dump'] = array();
            foreach ($node->childNodes as $child_node) {
                if ($child_node->nodeName != 'dump') {
                    continue;
                }
                if (!$child_node->hasAttribute('name')) {
                    continue;
                }
                $name = $child_node->getAttribute('name');
                $server['dump'][$name] = base64_decode($child_node->textContent);
            }
            $server_obj = $_SESSION['service']->server_info($server['id']);
            if (is_object($server_obj)) {
                $server['obj'] = $server_obj;
            }
            $servers[] = $server;
            // can be the same server twice with different role ... ToDO: fix that on backend side
        }
        foreach ($dom->getElementsByTagName('storage') as $node) {
            $s = nodeattrs2array($node);
            $storages[$s['rid']] = $s;
        }
        foreach ($dom->getElementsByTagName('application') as $node) {
            if (!$node->hasAttribute('id')) {
                // Not enough information to continue ...
                continue;
            }
            $application = array('id' => $node->getAttribute('id'));
            if ($node->hasAttribute('name')) {
                $application['name'] = $node->getAttribute('name');
            }
            $app_buf = $_SESSION['service']->application_info($application['id']);
            if (is_object($app_buf)) {
                $application['obj'] = $app_buf;
            }
            $published_applications[$application['id']] = $application;
        }
        foreach ($dom->getElementsByTagName('instance') as $node) {
            if (!($node->hasAttribute('id') && $node->hasAttribute('application') && $node->hasAttribute('server') && $node->hasAttribute('start') && $node->hasAttribute('stop'))) {
                // Not enough information to continue ...
                continue;
            }
            $instance = array('id' => $node->getAttribute('id'));
            $instance['application'] = $node->getAttribute('application');
            $instance['server'] = $node->getAttribute('server');
            $instance['start'] = $node->getAttribute('start');
            $instance['stop'] = $node->getAttribute('stop');
            if (!array_key_exists($instance['application'], $published_applications)) {
                continue;
            }
            $applications_instances[] = $instance;
        }
    }
    $ret = '';
    $ret .= '<ul>';
    $ret .= '<li><strong>User:</strong> ';
    if (is_object($user)) {
        $ret .= '' . $user->getAttribute('displayname') . ' (login: '******'login') . ')';
    } else {
        $ret .= $session->getUser() . ' <span><em>' . _('does not exist') . '</em></span>';
    }
    $ret .= '</li>';
    $ret .= '<li><strong>Mode:</strong> ' . $mode . '</li>';
    $ret .= '<li><strong>Started:</strong> ';
    $ret .= $session->getStartTime();
    $ret .= '</li>';
    $ret .= '<li><strong>Stopped:</strong> ';
    $ret .= $session->getStopTime();
    if (!is_null($session->getStopWhy()) && strlen($session->getStopWhy()) > 0) {
        $ret .= ' <em>(' . $session->getStopWhy() . ')</em>';
    }
    $ret .= '</li>';
    $ret .= '</ul>';
    $ret .= '<div>';
    $ret .= '<h2>Servers</h2>';
    if (count($servers) == 0) {
        $ret .= 'No information available';
    } else {
        $ret .= '<ul>';
        foreach ($servers as $server) {
            $ret .= '<li>';
            if (array_key_exists('obj', $server)) {
                $ret .= $server['obj']->getDisplayName() . ' (id: ' . $server['obj']->id . ')';
            } else {
                $ret .= $server['name'];
                $ret .= ' <span><em>' . _('does not exist') . '</em></span>';
            }
            $infos = array();
            $infos[] = 'role: ' . $server['role'];
            if ($mode == Session::MODE_DESKTOP && $server['desktop_server']) {
                $infos[] = 'desktop server';
            }
            if (array_key_exists('type', $server)) {
                $infos[] = '(OS: ' . $server['type'] . ')';
            }
            $ret .= ' ' . implode(', ', $infos);
            if (count($server['dump']) > 0) {
                $ret .= '<div style="margin-left: 20px;">';
                $ret .= '<ul>';
                foreach ($server['dump'] as $name => $dump) {
                    $ret .= '<li>' . $name . '&nbsp;';
                    $ret .= '<pre style="margin-left: 20px; font-size: small;">' . $dump . '</pre>';
                    $ret .= '</li>';
                }
                $ret .= '</ul>';
                $ret .= '</div>';
            }
            $ret .= '</li>';
        }
        $ret .= '</ul>';
    }
    $ret .= '</div>';
    $ret .= '<div>';
    $ret .= '<h2>Published applications</h2>';
    if (count($published_applications) == 0) {
        $ret .= _('No information available');
    } else {
        $ret .= '<ul>';
        foreach ($published_applications as $app_id => $application) {
            $ret .= '<li>';
            if (isset($application['obj'])) {
                // 				$ret.= '<img class="icon32" src="media/image/cache.php?id='.$application['obj']->getAttribute('id').'" alt="" title="" /> ';
                $ret .= $application['obj']->getAttribute('name') . ' (id: ' . $application['obj']->getAttribute('id') . ')';
            } else {
                if (array_key_exists('name', $application)) {
                    $ret .= '<span>' . $application['name'] . '</span>';
                } else {
                    $ret .= '<span>' . sprintf('Unknown application (id: %s)', $application['id']) . '</span>';
                }
                $ret .= '&nbsp;<span><em>' . _('does not exist') . '</em></span>';
            }
            $ret .= '</li>';
        }
        $ret .= '</ul>';
    }
    $ret .= '</div>';
    $ret .= '<div>';
    $ret .= '<h2>Used applications</h2>';
    if (count($applications_instances) == 0) {
        $ret .= 'No information available';
    } else {
        $ret .= '<ul>';
        foreach ($applications_instances as $instance) {
            $application = $published_applications[$instance['application']];
            $ret .= '<li>';
            if (array_key_exists('obj', $application)) {
                // 				$ret.= '<img class="icon32" src="media/image/cache.php?id='.$application['obj']->getAttribute('id').'" alt="" title="" /> ';
                $ret .= '<a href="applications.php?action=manage&id=' . $application['obj']->getAttribute('id') . '">' . $application['obj']->getAttribute('name') . '</a>';
            } else {
                if (array_key_exists('name', $application)) {
                    $ret .= '<span>' . $application['name'] . '</span>';
                } else {
                    $ret .= '<span>' . sprintf(_('Unknown application (id: %s)'), $application['id']) . '</span>';
                }
                $ret .= '&nbsp;<span><em>' . _('does not exist') . '</em></span>';
            }
            $ret .= ' - ';
            $duration = sprintf('%0.2f', ($instance['stop'] - $instance['start']) / 60);
            $ret .= str_replace(array('%SERVER%', '%DURATION%', '%STARTED_TIME%', '%STOPPED_TIME%'), array($instance['server'], $duration, strftime('%T', $instance['start']), strftime('%T', $instance['stop'])), _('executed on server %SERVER% during %DURATION%m (started at %STARTED_TIME%, stopped at %STOPPED_TIME%)'));
            $ret .= '</li>';
        }
        $ret .= '</ul>';
    }
    $ret .= '</div>';
    $ret .= '<div>';
    $ret .= '<h2>' . _('Storage') . '</h2>';
    if (count($storages) == 0) {
        $ret .= _('No information available');
    } else {
        $ret .= '<ul>';
        foreach ($storages as $storage_id => $storage) {
            if ($storage['type'] != 'profile') {
                continue;
            }
            $ret .= '<li>User profile on server: ' . $storage['server_name'] . ' (' . $storage['server_id'] . ')' . '</li>';
        }
        foreach ($storages as $storage_id => $storage) {
            if ($storage['type'] == 'profile') {
                continue;
            }
            $ret .= '<li>Shared foler - ' . $storage['name'] . ' <em>(' . $storage['mode'] . ')</em> on server: ' . $storage['server_name'] . ' (' . $storage['server_id'] . ')</li>';
        }
        $ret .= '</ul>';
    }
    $ret .= '</div>';
    return $ret;
}
Example #16
0
 public function isOnline()
 {
     if ($this->getAttribute('status') != 'ready') {
         Logger::debug('main', 'Server::isOnline server "' . $this->fqdn . ':' . $this->web_port . '" is not "ready"');
         return false;
     }
     $warn = false;
     if (!$this->hasAttribute('status') || !$this->uptodateAttribute('status')) {
         $warn = true;
         $this->getStatus();
     }
     if ($this->hasAttribute('status') && $this->getAttribute('status') == 'ready') {
         return true;
     }
     if ($warn === true && $this->getAttribute('locked') == 0) {
         popup_error('"' . $this->fqdn . '": ' . _('is NOT online!'));
         Logger::error('main', '"' . $this->fqdn . '": is NOT online!');
     }
     $this->isNotReady();
     return false;
 }
Example #17
0
function action_del_sharedfolder_acl($sharedfolder_id_, $usergroup_id_)
{
    $sharedfolder = $_SESSION['service']->shared_folder_info($sharedfolder_id_);
    if (!$sharedfolder) {
        popup_error(_('Unable to delete this shared folder access'));
        return false;
    }
    $ret = $_SESSION['service']->shared_folder_remove_group($usergroup_id_, $sharedfolder_id_);
    if ($ret === true) {
        popup_info(_('Shared folder successfully modified'));
        return true;
    } else {
        popup_error(sprintf(_("Unable to modify shared folder named '%s'"), $sharedfolder->name));
        return false;
    }
}
Example #18
0
function action_del_sharedfolder_acl($sharedfolder_id_, $usergroup_id_)
{
    $sharedfolderdb = SharedFolderDB::getInstance();
    $sharedfolder = $sharedfolderdb->import($sharedfolder_id_);
    if (!$sharedfolder) {
        popup_error(_('Unable to delete this shared folder access'));
        return false;
    }
    $usergroupDB = UserGroupDB::getInstance();
    $group = $usergroupDB->import($usergroup_id_);
    if (is_object($group) === false) {
        popup_error(_('Unable to load usergroup'));
        return false;
    }
    $ret = $sharedfolder->delUserGroup($group);
    if ($ret === true) {
        popup_info(_('Shared folder successfully modified'));
        return true;
    } else {
        popup_error(sprintf(_("Unable to modify shared folder named '%s'"), $sharedfolder->name));
        return false;
    }
}
Example #19
0
function show_default()
{
    $tasks = $_SESSION['service']->tasks_list();
    if (is_null($tasks)) {
        popup_error(_('Internal error requestings tasks'));
        redirect();
    }
    $servers_ = $_SESSION['service']->getOnlineServersList();
    if (is_null($servers_)) {
        $servers_ = array();
    }
    $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($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 ($tasks as $task) {
            $content = 'content' . ($count++ % 2 == 0 ? 1 : 2);
            if (array_key_exists($task->server, $servers_)) {
                $server_name = $servers_[$task->server]->getDisplayName();
            } else {
                $server_name = $task->server;
            }
            $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>' . $task->getAttribute('type') . '</td>';
            echo '<td><a href="servers.php?action=manage&id=' . $task->server . '">' . $server_name . '</a></td>';
            echo '<td>' . $status . '</td>';
            echo '<td>' . $task->getAttribute('request') . '</td>';
            // todo !!!
            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>';
    }
    $can_do_action = False;
    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->id . '">' . $server->getDisplayName() . '</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->id . '">' . $server->getDisplayName() . '</option>';
        }
        echo '</select> &nbsp; ';
        echo '<input type="submit" name="submit" value="' . _('Upgrade') . '" />';
        echo '</form>';
    }
    echo '</div>';
    page_footer();
    die;
}
Example #20
0
require_once dirname(dirname(__FILE__)) . '/includes/core.inc.php';
require_once dirname(dirname(__FILE__)) . '/includes/page_template.php';
if (isset($_POST['cleanup']) && $_POST['cleanup'] == 1 && array_key_exists('type', $_POST)) {
    switch ($_POST['type']) {
        case 'liaison':
            $_SESSION['service']->cleanup_liaisons();
            break;
        case 'preferences':
            $_SESSION['service']->cleanup_preferences();
            break;
    }
    redirect('checkup.php');
}
$checkup = $_SESSION['service']->checkup();
if (is_null($checkup)) {
    popup_error(_('Unable to load checkup'));
    redirect();
}
$everything_ok = true;
page_header();
echo '<h1>' . _('Checkup') . '</h1>';
echo '<h2>' . _('PHP Modules') . '</h2>';
$PHP_modules = $checkup['php'];
if (in_array(false, $PHP_modules)) {
    echo '<table border="0" cellspacing="1" cellpadding="3">';
    foreach ($PHP_modules as $name => $available) {
        echo '<tr>';
        echo '<td><span style="color: #666; font-weight: bold;">' . $name . '</span></td>';
        echo '<td>&nbsp;</td>';
        echo '<td>';
        if ($available === true) {
Example #21
0
 public function addToServer($sharedfolder_, $an_fs_server_)
 {
     Logger::debug('main', "SharedFolderDB::internal::addToServer({$sharedfolder_}, {$an_fs_server_})");
     if (is_object($sharedfolder_) == false) {
         Logger::error('main', 'SharedFolderDB::internal sharedfolder parameter is not an object (content: ' . serialize($sharedfolder_));
         return false;
     }
     if (is_object($an_fs_server_) == false) {
         Logger::error('main', 'SharedFolderDB::internal fs parameter is not an object (content: ' . serialize($an_fs_server_));
         return false;
     }
     $sharedfolder_->server = $an_fs_server_->fqdn;
     if ($this->exists($sharedfolder_->id) === false) {
         // we save the object first
         $ret = $this->add($sharedfolder_);
         // 			if ($ret !== true) {
         // 				Logger::error('main', "SharedFolderDB::internal failed to add $sharedfolder_ to the DB");
         // 				return false;
         // 			}
     }
     // do the request to the server
     $ret = $an_fs_server_->createNetworkFolder($sharedfolder_->id);
     if (!$ret) {
         popup_error(sprintf(_("SharedFolderDB::internal Unable to create shared folder on file server '%s'"), $sharedfolder_->server));
         $this->remove($sharedfolder_);
         return false;
     }
     return true;
 }
Example #22
0
    }
    $_SESSION['redirect'] = base64_encode($_SERVER['REQUEST_URI']);
    redirect('login.php');
}
try {
    // It seems the SoapClient object is not serialized correctly in $_SESSION object.
    // So create a new instance for each connection ...
    $service = new SessionManager($_SESSION['admin_login'], $_SESSION['admin_password'], !array_key_exists('no_ssl', $_SESSION));
    // At the moment, get the configuration at each connection.
    // In the future, this part will be cached for a time range to avoid requesting the Session Manager each time ...
    $configuration = $service->getInitialConfiguration();
} catch (Exception $e) {
    unset($_SESSION['admin_login']);
    unset($_SESSION['admin_password']);
    if ($e->faultcode == 'auth_failed') {
        $_SESSION['admin_error'] = _('You have been disconnected from the Session Manager');
        redirect('login.php');
    }
    die_error(_('Unable to initialize communication with Session Manager'));
}
$_SESSION['service'] = $service;
$_SESSION['configuration'] = $configuration;
if (array_key_exists('admin_language', $_SESSION['configuration'])) {
    $lang = $_SESSION['configuration']['admin_language'];
    if ($lang != 'auto') {
        set_language($lang);
    }
}
if (array_key_exists('system_in_maintenance', $_SESSION['configuration']) && $_SESSION['configuration']['system_in_maintenance'] == '1') {
    popup_error(_('The system is in maintenance mode'));
}
Example #23
0
function do_validate()
{
    if ($_SESSION['wizard']['use_users'] == 'users') {
        if (!checkAuthorization('manageUsersGroups')) {
            redirect();
        }
        $g = new UsersGroup(array('id' => NULL, 'name' => $_SESSION['wizard']['user_group_name'], 'description' => $_SESSION['wizard']['user_group_description'], 'published' => 1));
        $res = $_SESSION['service']->users_group_add($g->getAttribute('name'), $g->getAttribute('description'));
        if (is_null($res)) {
            popup_error(_('Cannot create User Group'));
        }
        $g->id = $res;
        $g->setAttribute('id', $res);
        $users = $_SESSION['wizard']['users'];
        foreach ($users as $user) {
            $_SESSION['service']->users_group_add_user($user, $g->id);
        }
        $usergroups = array($g->id);
    } else {
        $usergroups = $_SESSION['wizard']['usergroups'];
    }
    if ($_SESSION['wizard']['use_apps'] == 'apps') {
        if (!checkAuthorization('manageApplicationsGroups')) {
            redirect();
        }
        $g = new ApplicationsGroup(array('id' => NULL, 'name' => $_SESSION['wizard']['application_group_name'], 'description' => $_SESSION['wizard']['application_group_description'], 'published' => 1));
        $res = $_SESSION['service']->applications_group_add($g->getAttribute('name'), $g->getAttribute('description'));
        if (!$res) {
            popup_error(_('Cannot create Application Group'));
        }
        $g->id = $res;
        $g->setAttribute('id', $res);
        $apps = $_SESSION['wizard']['apps'];
        foreach ($apps as $app) {
            $ret = $_SESSION['service']->applications_group_add_application($app, $g->id);
        }
        $appgroups = array($g->id);
    } else {
        $appgroups = $_SESSION['wizard']['appgroups'];
    }
    foreach ($usergroups as $usergroup) {
        foreach ($appgroups as $appgroup) {
            $_SESSION['service']->publication_add($usergroup, $appgroup);
        }
    }
    if (isset($_SESSION['wizard'])) {
    }
    unset($_SESSION['wizard']);
    redirect('publications.php');
    die;
}
Example #24
0
function show_manage($sharedfolder_id_)
{
    $sharedfolderdb = SharedFolderDB::getInstance();
    $sharedfolder = $sharedfolderdb->import($sharedfolder_id_);
    if (!is_object($sharedfolder)) {
        popup_error(sprintf(_("Failed to import shared folder '%s'"), $sharedfolder_id_));
        redirect('sharedfolders.php');
    }
    $userGroupDB = UserGroupDB::getInstance();
    $all_groups = $userGroupDB->getList(true);
    $available_groups = array();
    $used_groups = $sharedfolder->getUserGroups();
    foreach ($all_groups as $group) {
        if (array_key_exists($group->getUniqueID(), $used_groups) === false) {
            $available_groups[$group->getUniqueID()] = $group;
        }
    }
    $can_manage_sharedfolders = isAuthorized('manageSharedFolders');
    page_header();
    echo '<div id="sharedfolders_div">';
    echo '<h1>' . $sharedfolder->name . '</h1>';
    echo '<div>';
    echo '<h2>' . _('Server') . '</h2>';
    echo '<a href="servers.php?action=manage&fqdn=' . $sharedfolder->server . '"> ' . $sharedfolder->server . '</a>';
    echo '</div>';
    echo '<br />';
    echo '<div>';
    echo '<h2>' . _('Configuration') . '</h2>';
    echo '<table>';
    echo '<tr><td>';
    echo _('Name') . ': ';
    echo '</td><td>';
    if ($can_manage_sharedfolders) {
        echo '<form action="actions.php" method="post">';
        echo '<input type="hidden" name="name" value="SharedFolder" />';
        echo '<input type="hidden" name="action" value="rename" />';
        echo '<input type="hidden" name="id" value="' . $sharedfolder->id . '" />';
    }
    echo '<input type="text" name="sharedfolder_name" value="' . $sharedfolder->name . '" />';
    if ($can_manage_sharedfolders) {
        echo ' <input type="submit" value="' . _('Rename') . '" />';
        echo '</form>';
    }
    echo '</td></tr>';
    echo '</table>';
    echo '</div>';
    echo '<br />';
    echo '<div>';
    echo '<h2>' . _('ACL') . '</h2>';
    echo '<table border="0" cellspacing="1" cellpadding="3">';
    foreach ($used_groups as $group) {
        echo '<tr>';
        echo '<td><a href="usersgroup.php?action=manage&amp;id=' . $group->getUniqueID() . '">' . $group->name . '</a></td>';
        if ($can_manage_sharedfolders) {
            echo '<td><form action="actions.php" method="post" onsubmit="return confirm(\'' . _('Are you sure you want to delete this shared folder access?') . '\');">';
            echo '<input type="hidden" name="name" value="SharedFolder_ACL" />';
            echo '<input type="hidden" name="action" value="del" />';
            echo '<input type="hidden" name="sharedfolder_id" value="' . $sharedfolder->id . '" />';
            echo '<input type="hidden" name="usergroup_id" value="' . $group->getUniqueID() . '" />';
            echo '<input type="submit" value="' . _('Delete access to this shared folder') . '" />';
            echo '</form></td>';
        }
        echo '</tr>';
    }
    if (count($available_groups) > 0 and $can_manage_sharedfolders) {
        echo '<tr><form action="actions.php" method="post"><td>';
        echo '<input type="hidden" name="name" value="SharedFolder_ACL" />';
        echo '<input type="hidden" name="action" value="add" />';
        echo '<input type="hidden" name="sharedfolder_id" value="' . $sharedfolder->id . '" />';
        echo '<select name="usergroup_id">';
        foreach ($available_groups as $group) {
            echo '<option value="' . $group->getUniqueID() . '" >' . $group->name . '</option>';
        }
        echo '</select>';
        echo '</td><td><input type="submit" value="' . _('Add access to this shared folder') . '" /></td>';
        echo '</form></tr>';
    }
    echo '</table>';
    echo '</div>';
    echo '</div>';
    page_footer();
}
Example #25
0
            $buf = $prefs->get('general', 'admin_language');
            $language = locale2unix($buf);
            setlocale(LC_ALL, $language . '.UTF-8');
            // configuration saved
            popup_info(_('Configuration successfully saved'));
            redirect('index.php');
        } else {
            header_static(_('Configuration'));
            echo 'problem : configuration not saved<br>';
            // TODO (class msg...) + gettext
            footer_static();
        }
    } else {
        // conf not valid
        if ($setup) {
            popup_error('Error : ' . $ret);
            redirect('configuration.php?action=init');
        } else {
            header_static(_('Configuration'));
            echo '<p class="msg_error centered">' . $ret . '</p>';
            print_prefs($prefs);
            footer_static();
        }
    }
} else {
    $can_manage_configuration = isAuthorized('manageConfiguration');
    if (isset($_GET['action']) && $_GET['action'] == 'init') {
        try {
            $prefs = new Preferences_admin();
        } catch (Exception $e) {
        }
Example #26
0
function getNB_SESSION($mode_)
{
    if (isset($_GET['from'])) {
        $t0 = strtotime($_GET['from']);
    } else {
        $t0 = strtotime($mode_->get_default_from());
    }
    if (isset($_GET['to'])) {
        $t1 = strtotime($_GET['to']);
    } else {
        $t1 = time();
    }
    if (isset($_GET['server'])) {
        $server_part = 'AND server="' . $_GET['server'] . '"';
    } else {
        $server_part = '';
    }
    $t0 = $mode_->transform_date($t0);
    $t1 = $mode_->transform_date($t1);
    if ($t0 > $t1) {
        popup_error(_('Error: "from" date is after "to" date, switching'));
        $buf = $t0;
        $t0 = $t1;
        $t1 = $buf;
    }
    if ($t1 > time()) {
        popup_error(_('Error: "to" field is in the future, switch to the current time'));
        $t1 = $mode_->transform_date(time());
    }
    $t2 = strtotime($mode_->get_next(), $t1);
    $prefs = Preferences::getInstance();
    $mysql_conf = $prefs->get('general', 'sql');
    $sql = SQL::getInstance();
    $res = $sql->DoQuery('SELECT * FROM @1 WHERE @2 BETWEEN %3 AND %4 ' . $server_part . ' AND ( @5 <= %4 OR ( @6 IS NULL AND id IN (SELECT id FROM @7)))', SESSIONS_HISTORY_TABLE, 'start_stamp', date('c', $t0), date('c', $t2), 'stop_stamp', 'stop_stamp', $mysql_conf['prefix'] . 'sessions');
    $result_nb_sessions = build_array($t0, $t2, $mode_);
    $g = $sql->FetchAllResults();
    foreach ($g as $p) {
        $y = strtotime($p['start_stamp']);
        $buf = date($mode_->get_prefix(), $y);
        foreach ($result_nb_sessions as $k => $v) {
            if ($buf > $k) {
                continue;
            }
            if (is_null($p['stop_stamp'])) {
                $result_nb_sessions[$k] += 1;
            } else {
                $time_stop = strtotime($p['stop_stamp']);
                $str_stop = date($mode_->get_prefix(), $time_stop);
                if ($str_stop >= $k) {
                    $result_nb_sessions[$k] += 1;
                } else {
                    break;
                }
            }
        }
    }
    return $result_nb_sessions;
}
Example #27
0
function show_default()
{
    $usersList = new UsersList($_REQUEST);
    $us = $usersList->search();
    $searchDiv = $usersList->getForm();
    $users_info = array();
    foreach ($us as $user) {
        $user_info = $_SESSION['service']->session_simulate($user->getAttribute('login'));
        if (is_null($user_info)) {
            popup_error(sprintf(_('Unable to perform session simulation for user %s'), $user->getAttribute('login')));
            continue;
        }
        $user_info['user'] = $user;
        $users_info[] = $user_info;
    }
    page_header();
    echo '<h2>' . _('Users') . '</h2>';
    echo $searchDiv;
    if (count($users_info) == 0) {
        echo _('No available users') . '<br />';
    } else {
        echo '<table id="users_table" class="main_sub sortable" border="0" cellspacing="1" cellpadding="3">';
        echo '<thead>';
        echo '<tr class="title2">';
        echo '<th class="unsortable" colspan="3">' . _('Users') . '</th>';
        echo '<th colspan="2">' . _('Applications') . '</th>';
        echo '<th>' . _('Folders') . '</th>';
        echo '<th>' . _('Session') . '</th>';
        echo '</tr>';
        echo '<tr class="title">';
        echo '<th>' . _('Login') . '</th>';
        echo '<th>' . _('Name') . '</th>';
        echo '<th>' . _('In these User Groups') . '</th>';
        echo '<th>' . _('Published Application Groups') . '</th>';
        echo '<th>' . _('Access to these applications') . '</th>';
        echo '<th>' . _('Access to these folders') . '</th>';
        echo '</tr>';
        echo '</thead>';
        echo '<tbody>';
        $count = 0;
        foreach ($users_info as $user_info) {
            $u = $user_info['user'];
            echo '<tr class="content';
            if ($count % 2 == 0) {
                echo '1';
            } else {
                echo '2';
            }
            echo '">';
            echo '<td><a href="users.php?action=manage&id=' . $u->getAttribute('login') . '">' . $u->getAttribute('login') . '</a></td>';
            // login
            echo '<td><a href="users.php?action=manage&id=' . $u->getAttribute('login') . '">' . $u->getAttribute('displayname') . '</a></td>';
            //nam
            echo '<td>';
            if (count($user_info['user_grps']) == 0) {
                echo '<em>' . _('Not in any User Group') . '</em>';
            } else {
                echo '<table border="0" cellspacing="1" cellpadding="3">';
                foreach ($user_info['user_grps'] as $group_id => $group_name) {
                    echo '<tr>';
                    echo '<td><a href="usersgroup.php?action=manage&id=' . $group_id . '">' . $group_name . '</a></td>';
                    echo '</tr>';
                }
                if ($user_info['groups_partial_list'] === true) {
                    echo '<tr><td style="text-align: center;"><strong><a href="users.php?action=manage&id=' . $u->getAttribute('login') . '">...</a></strong></td></tr>';
                }
                echo '</table>';
            }
            echo '</td>';
            if (count($user_info['apps_grps']) == 0) {
                echo '<td colspan="2">';
                echo '<em>' . _('No publications') . '</em>';
                echo '</td>';
            } else {
                echo '<td>';
                echo '<table border="0" cellspacing="1" cellpadding="3">';
                foreach ($user_info['apps_grps'] as $group_id => $group_name) {
                    echo '<tr>';
                    echo '<td><a href="appsgroup.php?action=manage&id=' . $group_id . '">' . $group_name . '</a></td>';
                    echo '</tr>';
                }
                echo '</table>';
                echo '</td>';
                echo '<td>';
                // in app
                if (count($user_info['apps']) == 0) {
                    echo '<em>' . _('No application in these groups') . '</em>';
                } else {
                    echo '<table border="0" cellspacing="1" cellpadding="3">';
                    foreach ($user_info['apps'] as $application_id => $aaa) {
                        echo '<tr>';
                        echo '<td><img class="icon32" src="media/image/cache.php?id=' . $aaa['id'] . '" alt="" title="" /></td>';
                        echo '<td><a href="applications.php?action=manage&id=' . $aaa['id'] . '">' . $aaa['name'] . '</a></td>';
                        echo '<td style="text-align: center;"><img src="media/image/server-' . $aaa['type'] . '.png" width="16" height="16" alt="' . $aaa['type'] . '" title="' . $aaa['type'] . '" /></td>';
                        echo '</tr>';
                    }
                    echo '</table>';
                }
                echo '</td>';
            }
            echo '<td>';
            if (count($user_info['profiles']) + count($user_info['shared_folders']) > 0) {
                echo '<table border="0" cellspacing="1" cellpadding="3">';
                foreach ($user_info['profiles'] as $profile_id => $profile_name) {
                    echo '<tr>';
                    echo '<td>' . _('Profile') . '</td>';
                    echo '<td>';
                    echo '<a href="profiles.php?action=manage&id=' . $profile_id . '">' . $profile_name . '</a></td>';
                    echo '</tr>';
                }
                foreach ($user_info['shared_folders'] as $share_id => $info) {
                    echo '<tr>';
                    echo '<td>' . _('Shared folder') . '</td>';
                    echo '<td>';
                    echo '<a href="sharedfolders.php?action=manage&id=' . $share_id . '">' . $info['share_name'] . '</a> (' . _('mode: ') . $info['mode'] . ')</td>';
                    echo '</tr>';
                }
                echo '</table>';
            }
            echo '</td>';
            echo '<td style="white-space: nowrap;">';
            echo '<div>';
            if ($user_info['can_start_session_desktop'] === true) {
                // add tooltip
                echo '<img src="media/image/ok.png" alt="" title="" />';
            } else {
                $reason = null;
                if (array_key_exists('cannot_start_session_reason', $user_info)) {
                    $reason = $user_info['cannot_start_session_reason'];
                }
                $reason = get_error_code_translation($reason);
                echo '<span onmouseover="showInfoBulle(\'' . str_replace("'", "&rsquo;", htmlspecialchars($reason)) . '\'); return false;" onmouseout="hideInfoBulle(); return false;">';
                echo '<img src="media/image/cancel.png" alt="" title="" />';
                echo '</span>';
            }
            echo ' ' . _('Desktop');
            echo '</div>';
            echo '<div>';
            if ($user_info['can_start_session_applications'] === true) {
                echo '<img src="media/image/ok.png" alt="" title="" />';
            } else {
                $reason = null;
                if (array_key_exists('cannot_start_session_reason', $user_info)) {
                    $reason = $user_info['cannot_start_session_reason'];
                }
                $reason = get_error_code_translation($reason);
                echo '<span onmouseover="showInfoBulle(\'' . str_replace("'", "&rsquo;", htmlspecialchars($reason)) . '\'); return false;" onmouseout="hideInfoBulle(); return false;">';
                echo '<img src="media/image/cancel.png" alt="" title="" />';
                echo '</span>';
            }
            echo ' ' . _('Applications');
            echo '</div>';
            echo '</td>';
            echo '</tr>';
            $count++;
        }
        echo '</tbody>';
        echo '</table>';
    }
    page_footer();
}
Example #28
0
function getNB_SESSION($mode_)
{
    if (isset($_GET['from'])) {
        $t0 = strtotime($_GET['from']);
    } else {
        $t0 = strtotime($mode_->get_default_from());
    }
    if (isset($_GET['to'])) {
        $t1 = strtotime($_GET['to']);
    } else {
        $t1 = time();
    }
    if (isset($_GET['server'])) {
        $server = $_GET['server'];
    } else {
        $server = null;
    }
    $t0 = $mode_->transform_date($t0);
    $t1 = $mode_->transform_date($t1);
    if ($t0 > $t1) {
        popup_error(_('Error: "from" date is after "to" date, the current time will be used'));
        $buf = $t0;
        $t0 = $t1;
        $t1 = $buf;
    }
    if ($t1 > time()) {
        popup_error(_('Error: "to" field is in the future, the current time will be used'));
        $t1 = $mode_->transform_date(time());
    }
    $t2 = strtotime($mode_->get_next(), $t1);
    $sessions = $_SESSION['service']->sessions_reports_list2($t0, $t2, $server);
    if (is_null($sessions)) {
        $sessions = array();
    }
    $result_nb_sessions = build_array($t0, $t2, $mode_);
    foreach ($sessions as $session) {
        $y = strtotime($session->getStartTime());
        $buf = date($mode_->get_prefix(), $y);
        foreach ($result_nb_sessions as $k => $v) {
            if ($buf > $k) {
                continue;
            }
            if (is_null($session->getStopTime())) {
                $result_nb_sessions[$k] += 1;
            } else {
                $time_stop = strtotime($session->getStopTime());
                $str_stop = date($mode_->get_prefix(), $time_stop);
                if ($str_stop >= $k) {
                    $result_nb_sessions[$k] += 1;
                } else {
                    break;
                }
            }
        }
    }
    return $result_nb_sessions;
}
Example #29
0
function checkAuthorization($policy_)
{
    if (isAuthorized($policy_)) {
        return true;
    }
    if (array_key_exists('admin_ovd_user', $_SESSION)) {
        Logger::warning('main', 'User(login='******'admin_ovd_user']->getAttribute('login') . ') is  not allowed to perform ' . $policy_ . '.');
    } else {
        Logger::warning('main', 'The user is not logged so he is not allowed to perform ' . $policy_ . '.');
    }
    popup_error(_('You are not allowed to perform this action'));
    return false;
}
Example #30
0
function do_validate()
{
    if ($_SESSION['wizard']['use_users'] == 'users') {
        if (!checkAuthorization('manageUsersGroups')) {
            redirect();
        }
        $userGroupDB = UserGroupDB::getInstance();
        if (!$userGroupDB->isWriteable()) {
            return false;
        }
        $g = new UsersGroup(NULL, $_SESSION['wizard']['user_group_name'], $_SESSION['wizard']['user_group_description'], 1);
        $res = $userGroupDB->add($g);
        if (!$res || !is_object($g) || $g->id == NULL) {
            popup_error(_('Cannot create usergroup'));
        }
        $users = $_SESSION['wizard']['users'];
        foreach ($users as $user) {
            Abstract_Liaison::save('UsersGroup', $user, $g->getUniqueID());
        }
        $usergroups = array($g->getUniqueID());
    } else {
        $usergroups = $_SESSION['wizard']['usergroups'];
    }
    if ($_SESSION['wizard']['use_apps'] == 'apps') {
        if (!checkAuthorization('manageApplicationsGroups')) {
            redirect();
        }
        $g = new AppsGroup(NULL, $_SESSION['wizard']['application_group_name'], $_SESSION['wizard']['application_group_description'], 1);
        $applicationsGroupDB = ApplicationsGroupDB::getInstance();
        $res = $applicationsGroupDB->add($g);
        if (!$res || !is_object($g) || $g->id == NULL) {
            popup_error(_('Cannot create application group'));
        }
        $apps = $_SESSION['wizard']['apps'];
        foreach ($apps as $app) {
            Abstract_Liaison::save('AppsGroup', $app, $g->id);
        }
        $appgroups = array($g->id);
    } else {
        $appgroups = $_SESSION['wizard']['appgroups'];
    }
    foreach ($usergroups as $usergroup) {
        foreach ($appgroups as $appgroup) {
            $exists = Abstract_Liaison::load('UsersGroupApplicationsGroup', $usergroup, $appgroup);
            if (is_object($exists) === false) {
                Abstract_Liaison::save('UsersGroupApplicationsGroup', $usergroup, $appgroup);
            }
        }
    }
    if (isset($_SESSION['wizard'])) {
    }
    unset($_SESSION['wizard']);
    redirect('publications.php');
    die;
}