Ejemplo n.º 1
0
 public function getList()
 {
     $liaisons = Abstract_Liaison::load('UserProfile', NULL, NULL);
     if (is_array($liaisons) == false) {
         Logger::error('main', 'UserDB::anyuser::getList() problem with liaison');
         return false;
     }
     $results = array();
     foreach ($liaisons as $liaison) {
         $results[] = $this->import($liaison->element);
     }
     return $results;
 }
Ejemplo n.º 2
0
 public function getUsers()
 {
     $liaisons = Abstract_Liaison::load('UserProfile', NULL, $this->id);
     if (is_array($liaisons) == false) {
         Logger::error('main', 'NetworkFolder::getUsers()');
         return false;
     }
     $userDB = UserDB::getInstance();
     $users = array();
     foreach ($liaisons as $liaison) {
         array_push($users, $liaison->element);
     }
     return $userDB->imports($users);
 }
Ejemplo n.º 3
0
/**
 * Copyright (C) 2008-2013 Ulteo SAS
 * http://www.ulteo.com
 * Author Julien LANGLOIS <*****@*****.**> 2008-2013
 * Author Laurent CLOUET <*****@*****.**> 2008-2011
 * Author Jeremy DESVAGES <*****@*****.**> 2008-2011
 * Author Vincent ROULLIER <*****@*****.**> 2013
 * Author David LECHEVALIER <*****@*****.**> 2012
 * Author David PHAM-VAN <*****@*****.**> 2013
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; version 2
 * of the License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 **/
function init_db($prefs_)
{
    // prefs must be valid
    Logger::debug('main', 'init_db');
    $modules_enable = $prefs_->get('general', 'module_enable');
    foreach ($modules_enable as $module_name) {
        if (!is_null($prefs_->get($module_name, 'enable'))) {
            $enable = $prefs_->get($module_name, 'enable');
            if (is_string($enable)) {
                $mod_name = $module_name . '_' . $enable;
                $ret_eval = call_user_func(array($mod_name, 'init'), $prefs_);
                if ($ret_eval !== true) {
                    Logger::error('main', 'init_db init module \'' . $mod_name . '\' failed');
                    return false;
                }
            } elseif (is_array($enable)) {
                foreach ($enable as $sub_module) {
                    $mod_name = $module_name . '_' . $sub_module;
                    $ret_eval = call_user_func(array($mod_name, 'init'), $prefs_);
                    if ($ret_eval !== true) {
                        Logger::error('main', 'init_db init module \'' . $mod_name . '\' failed');
                        return false;
                    }
                }
            }
        }
    }
    Logger::debug('main', 'init_db modules inited');
    // Init of Abstract
    Abstract_Server::init($prefs_);
    Abstract_ServersGroup::init($prefs_);
    Abstract_Session::init($prefs_);
    Abstract_Token::init($prefs_);
    Abstract_News::init($prefs_);
    Abstract_Script::init($prefs_);
    Abstract_Liaison::init($prefs_);
    if (class_exists("PremiumManager")) {
        PremiumManager::initdb($prefs_);
    }
    Abstract_Task::init($prefs_);
    Abstract_ReportServer::init($prefs_);
    Abstract_ReportSession::init($prefs_);
    Abstract_User_Preferences::init($prefs_);
    Abstract_UserGroup_Preferences::init($prefs_);
    Abstract_UserGroup_Rule::init($prefs_);
    Abstract_VDI::init($prefs_);
    Abstract_Network_Folder::init($prefs_);
    Abstract_AdminAction::init($prefs_);
    return true;
}
Ejemplo n.º 4
0
 public function userGroups()
 {
     Logger::debug('main', 'APPSGROUPS::userGroups (for id=' . $this->id . ')');
     $UserGroupDB = UserGroupDB::getInstance();
     $groups = Abstract_Liaison::load('UsersGroupApplicationsGroup', NULL, $this->id);
     if (is_array($groups)) {
         $result = array();
         foreach ($groups as $UGAG_liaison) {
             array_push($result, $UGAG_liaison->element);
         }
         return $UserGroupDB->imports($result);
     } else {
         Logger::error('main', 'APPSGROUPS::userGroups (for id=' . $this->id . ') load liaison liaison failed');
         return NULL;
     }
 }
Ejemplo n.º 5
0
 public static function load($type_, $element_ = NULL, $group_ = NULL)
 {
     if (is_null($element_) && is_null($group_)) {
         return Abstract_Liaison::loadAll($type_);
     } else {
         if (is_null($element_)) {
             return Abstract_Liaison::loadElements($type_, $group_);
         } else {
             if (is_null($group_)) {
                 return Abstract_Liaison::loadGroups($type_, $element_);
             } else {
                 return Abstract_Liaison::loadUnique($type_, $element_, $group_);
             }
         }
     }
 }
 public function updateCache()
 {
     // update the liaison
     Logger::debug('main', 'UsersGroup_dynamic_cached::updateCache for ID=' . $this->getUniqueID());
     $logins = parent::usersLogin();
     $liaisons = Abstract_Liaison::load('UsersGroupCached', NULL, $this->getUniqueID());
     foreach ($liaisons as $a_liaison) {
         if (!in_array($a_liaison->element, $logins)) {
             Abstract_Liaison::delete('UsersGroupCached', $a_liaison->element, $a_liaison->group);
         }
     }
     foreach ($logins as $a_login) {
         if (!isset($liaisons[$a_login])) {
             Abstract_Liaison::save('UsersGroupCached', $a_login, $this->getUniqueID());
         }
     }
 }
Ejemplo n.º 7
0
 public function getUserGroups()
 {
     $liaisons = Abstract_Liaison::load('UserGroupSharedFolder', NULL, $this->id);
     if (is_array($liaisons) == false) {
         Logger::error('main', 'NetworkFolder::getUserGroups()');
         return false;
     }
     $usergroupDB = UserGroupDB::getInstance();
     $usergroups = array();
     foreach ($liaisons as $liaison) {
         $usergroup = $usergroupDB->import($liaison->element);
         if (!is_object($usergroup)) {
             continue;
         }
         $usergroups[$usergroup->getUniqueID()] = $usergroup;
     }
     return $usergroups;
 }
Ejemplo n.º 8
0
 public function getUsers()
 {
     $liaisons = Abstract_Liaison::load('UserProfile', NULL, $this->id);
     if (is_array($liaisons) == false) {
         Logger::error('main', 'NetworkFolder::getUsers()');
         return false;
     }
     $userDB = UserDB::getInstance();
     $users = array();
     foreach ($liaisons as $liaison) {
         $user = $userDB->import($liaison->element);
         if (!is_object($user)) {
             continue;
         }
         $users[$user->getAttribute('login')] = $user;
     }
     return $users;
 }
Ejemplo n.º 9
0
function do_auto_clean_db($new_prefs)
{
    $prefs = Preferences::getInstance();
    $old_profile = getProfileMode($prefs);
    $new_profile = getProfileMode($new_prefs);
    $old_u = $prefs->get('UserDB', 'enable');
    $new_u = $new_prefs->get('UserDB', 'enable');
    $old_ugrp = $prefs->get('UserGroupDB', 'enable');
    $new_ugrp = $new_prefs->get('UserGroupDB', 'enable');
    $has_changed_u = False;
    $has_changed_ug = False;
    $userGroupDB = UserGroupDB::getInstance();
    if ($old_profile == $new_profile) {
        $p = new $new_profile();
        list($has_changed_u, $has_changed_ug) = $p->has_change($prefs, $new_prefs);
    }
    // If UserDB module change
    if (($old_u != $new_u || $has_changed_u) && $userGroupDB->isWriteable()) {
        // Remove Users from user groups
        Abstract_Liaison::delete('UsersGroup', NULL, NULL) or popup_error('Unable to remove Users from UserGroups');
        // check if profile must become orphan
        $mods_enable = $prefs->get('general', 'module_enable');
        $new_mods_enable = $new_prefs->get('general', 'module_enable');
        if (in_array('ProfileDB', $mods_enable) || in_array('ProfileDB', $new_mods_enable)) {
            Abstract_Liaison::delete('UserProfile', NULL, NULL);
        }
    }
    // If UserGroupDB module change
    if ($old_ugrp != $new_ugrp || $has_changed_ug) {
        // Remove Publications
        Abstract_Liaison::delete('UsersGroupApplicationsGroup', NULL, NULL) or popup_error('Unable to remove Publications');
        // Unset default usersgroup
        $new_prefs->set('general', 'user_default_group', NULL);
        // check if sharedfolder must become orphan
        $mods_enable = $prefs->get('general', 'module_enable');
        $new_mods_enable = $new_prefs->get('general', 'module_enable');
        if (in_array('SharedFolderDB', $mods_enable) || in_array('SharedFolderDB', $new_mods_enable)) {
            Abstract_Liaison::delete('UserGroupSharedFolder', NULL, NULL);
        }
    }
}
Ejemplo n.º 10
0
 public function usersGroups()
 {
     Logger::debug('main', 'Script::usersGroups');
     $userGroupDB = UserGroupDB::getInstance();
     $result = array();
     // add the default user group is enable
     $prefs = Preferences::getInstance();
     if (!$prefs) {
         Logger::critical('main', 'Script::usersGroups get prefs failed');
         die_error('get Preferences failed', __FILE__, __LINE__);
     }
     $liaison = Abstract_Liaison::load('Scripts', $this->getAttribute('name'), NULL);
     if (is_null($liaison)) {
         Logger::error('main', 'Script::usersGroups load(' . $this->getAttribute('name') . ') is null');
         return $result;
     }
     foreach ($liaison as $row) {
         $g = $userGroupDB->import($row->group);
         if (is_object($g)) {
             $result[] = $g;
         }
     }
     return $result;
 }
Ejemplo n.º 11
0
 public function remove($usergroup_)
 {
     Logger::debug('main', 'UserGroupDBDynamic_cached::remove');
     // first we delete liaisons
     $sql2 = SQL::getInstance();
     $liaisons = Abstract_Liaison::load('UsersGroupApplicationsGroup', $usergroup_->id, NULL);
     foreach ($liaisons as $liaison) {
         Abstract_Liaison::delete('UsersGroupApplicationsGroup', $liaison->element, $liaison->group);
     }
     foreach ($liaisons as $liaison) {
         Abstract_Liaison::delete('UsersGroup', NULL, $usergroup_->getUniqueID());
     }
     // second we delete the group
     $res = $sql2->DoQuery('DELETE FROM @1 WHERE @2 = %3', $this->table, 'id', $usergroup_->id);
     if ($res === false) {
         Logger::error('main', 'UserGroupDBDynamic_cached::remove Failed to remove group from SQL DB');
         return false;
     }
     // third we delete the rules
     $rules = UserGroup_Rules::getByUserGroupId($usergroup_->getUniqueID());
     foreach ($rules as $a_rule) {
         if (Abstract_UserGroup_Rule::delete($a_rule->id) === false) {
             Logger::error('main', 'UserGroupDBDynamic_cached::remove Failed to remove rule from SQL DB');
             return false;
         }
     }
     return true;
 }
Ejemplo n.º 12
0
 public function delUserGroupToSharedFolder($usergroup_, $sharedfolder_)
 {
     if (!is_object($usergroup_)) {
         Logger::error('main', "SharedFolderDB::internal::delUserGroupToSharedFolder, parameter 'usergroup' is not correct, usergroup: " . serialize($usergroup_));
         return false;
     }
     if (!is_object($sharedfolder_)) {
         Logger::error('main', "SharedFolderDB::internal::delUserGroupToSharedFolder, parameter 'sharedfolder' is not correct, networkfolder_: " . serialize($sharedfolder_));
         return false;
     }
     return Abstract_Liaison::delete('UserGroupSharedFolder', $usergroup_->getUniqueID(), $sharedfolder_->id);
 }
Ejemplo n.º 13
0
 public function get_all_published_servers()
 {
     Logger::debug('main', "USER::get_all_published_servers");
     $servers = array();
     $liaisons = Abstract_Liaison::load('UsersGroupServersGroup', NULL, NULL);
     foreach ($liaisons as $liaison) {
         $liaisons2 = Abstract_Liaison::load('ServersGroup', NULL, $liaison->group);
         foreach ($liaisons2 as $liaison2) {
             $servers[] = $liaison2->element;
         }
     }
     return $servers;
 }
Ejemplo n.º 14
0
function show_manage($id, $applicationDB)
{
    global $types;
    $applicationsGroupDB = ApplicationsGroupDB::getInstance();
    $app = $applicationDB->import($id);
    if (!is_object($app)) {
        return false;
    }
    $is_rw = $applicationDB->isWriteable();
    $can_manage_applications = isAuthorized('manageApplications');
    // App groups
    $appgroups = $applicationsGroupDB->getList();
    $groups_id = array();
    $liaisons = Abstract_Liaison::load('AppsGroup', $app->getAttribute('id'), NULL);
    foreach ($liaisons as $liaison) {
        $groups_id[] = $liaison->group;
    }
    $groups = array();
    $groups_available = array();
    foreach ($appgroups as $group) {
        if (in_array($group->id, $groups_id)) {
            $groups[] = $group;
        } else {
            $groups_available[] = $group;
        }
    }
    $servers_all = Abstract_Server::load_available_by_role(Server::SERVER_ROLE_APS, true);
    $liaisons = Abstract_Liaison::load('ApplicationServer', $app->getAttribute('id'), NULL);
    $servers_id = array();
    foreach ($liaisons as $liaison) {
        $servers_id[] = $liaison->group;
    }
    $servers = array();
    $servers_available = array();
    foreach ($servers_all as $server) {
        if (in_array($server->fqdn, $servers_id)) {
            $servers[] = $server;
        } elseif (!$server->isOnline()) {
            continue;
        } elseif ($server->type != $app->getAttribute('type')) {
            continue;
        } else {
            $servers_available[] = $server;
        }
    }
    $mimes = $applicationDB->getAllMimeTypes();
    $mimeliste1 = $app->getMimeTypes();
    $mimeliste2 = array();
    foreach ($mimes as $mime) {
        if (!in_array($mime, $mimeliste1)) {
            $mimeliste2[] = $mime;
        }
    }
    $can_manage_server = isAuthorized('manageServers');
    page_header();
    echo '<div>';
    echo '<h1><img src="media/image/cache.php?id=' . $app->getAttribute('id') . '" alt="" title="" /> ' . $app->getAttribute('name') . '</h1>';
    echo '<table class="main_sub" border="0" cellspacing="1" cellpadding="3">';
    echo '<tr class="title">';
    // 	echo '<th>'._('Package').'</th>';
    echo '<th>' . _('Type') . '</th>';
    echo '<th>' . _('Description') . '</th>';
    echo '<th>' . _('Command') . '</th>';
    if ($is_rw and $can_manage_applications) {
        echo '<th></th>';
    }
    echo '</tr>';
    echo '<tr class="content1">';
    // 		echo '<td>'.$app->getAttribute('package').'</td>';
    echo '<td style="text-align: center;"><img src="media/image/server-' . $app->getAttribute('type') . '.png" alt="' . $app->getAttribute('type') . '" title="' . $app->getAttribute('type') . '" /><br />' . $app->getAttribute('type') . '</td>';
    echo '<td>' . $app->getAttribute('description') . '</td>';
    echo '<td>';
    echo $app->getAttribute('executable_path');
    echo '</td>';
    if ($is_rw and $can_manage_applications) {
        echo '<td>';
        echo '<form action="actions.php" method="post" onsubmit="return confirm(\'' . _('Are you sure you want to delete this application?') . '\');">';
        echo '<input type="hidden" name="name" value="Application_static" />';
        echo '<input type="hidden" name="action" value="del" />';
        echo '<input type="hidden" name="checked_applications[]" value="' . $app->getAttribute('id') . '" />';
        echo '<input type="submit"  value="' . _('Delete') . '" />';
        echo '</form>';
        echo '</td>';
    }
    echo '</tr>';
    echo '</table>';
    if ($is_rw and $can_manage_applications) {
        echo '<br />';
        echo '<form action="actions.php" method="post"">';
        echo '<input type="hidden" name="name" value="Application" />';
        echo '<input type="hidden" name="action" value="clone" />';
        echo '<input type="hidden" name="id" value="' . $app->getAttribute('id') . '" />';
        echo '<input type="submit" value="' . _('Clone to new application') . '"/>';
        echo '</form>';
        echo '<br />';
        echo '<h2>' . _('Modify') . '</h2>';
        echo '<div id="application_modify">';
        echo '<form id="delete_icon" action="actions.php" method="post" style="display: none;">';
        echo '<input type="hidden" name="name" value="Application_static" />';
        echo '<input type="hidden" name="action" value="del_icon" />';
        echo '<input type="hidden" name="checked_applications[]" value="' . $app->getAttribute('id') . '" />';
        echo '</form>';
        echo '<form action="actions.php" method="post" enctype="multipart/form-data" >';
        // form A
        echo '<input type="hidden" name="name" value="Application_static" />';
        echo '<input type="hidden" name="action" value="modify" />';
        echo '<input type="hidden" name="published" value="1" />';
        echo '<input type="hidden" name="static" value="1" />';
        echo '<input type="hidden" name="id" value="' . $app->getAttribute('id') . '" />';
        echo '<table class="main_sub" border="0" cellspacing="1" cellpadding="5">';
        $count = 1;
        $app->setAttribute('application_name', $app->getAttribute('name'));
        // ugly hack
        $app->unsetAttribute('name');
        $attr_list = $app->getAttributesList();
        foreach ($attr_list as $k => $v) {
            if (in_array($v, array('id', 'type', 'static', 'published', 'desktopfile', 'package', 'revision'))) {
                unset($attr_list[$k]);
            }
        }
        asort($attr_list);
        foreach ($attr_list as $attr_name) {
            $content = 'content' . ($count++ % 2 == 0 ? 1 : 2);
            echo '<tr class="' . $content . '">';
            echo '<td style="text-transform: capitalize;">';
            if ($attr_name == 'executable_path') {
                echo _('Command');
            } else {
                if ($attr_name == 'application_name') {
                    echo _('Name');
                } else {
                    echo _($attr_name);
                }
            }
            echo '</td>';
            echo '<td>';
            echo '<input type="text" name="' . $attr_name . '" value="' . htmlspecialchars($app->getAttribute($attr_name)) . '" style="with:100%;"/>';
            echo '<input type="hidden" name="attributes_send[]" value="' . $attr_name . '" />';
            echo '</td>';
            echo '</tr>';
        }
        if (get_classes_startwith('Imagick') != array()) {
            $content = 'content' . ($count++ % 2 == 0 ? 1 : 2);
            echo '<tr class="' . $content . '">';
            echo '<td>' . _('Icon') . '</td>';
            echo '<td>';
            if ($app->getIconPath() != $app->getDefaultIconPath() && file_exists($app->getIconPath())) {
                echo '<img src="media/image/cache.php?id=' . $app->getAttribute('id') . '" alt="" title="" /> ';
                echo '<input type="button" value="' . _('Delete this icon') . '" onclick="return confirm(\'' . _('Are you sure you want to delete this icon?') . '\') && $(\'delete_icon\').submit();"/>';
                echo '<br />';
            }
            echo '<input type="file"  name="file_icon" /> ';
            echo '</td>';
            echo '</tr>';
        } else {
            Logger::info('main', 'No Imagick support found');
        }
        $content = 'content' . ($count++ % 2 == 0 ? 1 : 2);
        echo '<tr class="' . $content . '">';
        echo '<td colspan="2">';
        echo '<input type="submit" value="' . _('Modify') . '" />';
        echo '</td>';
        echo '</tr>';
        echo '</table>';
        echo '</form>';
        // form A
        echo '</div>';
        // application_modify
    }
    if (count($servers) + count($servers_available) > 0) {
        echo '<div>';
        echo '<h2>' . _('Servers with this application') . '</h2>';
        echo '<table border="0" cellspacing="1" cellpadding="3">';
        foreach ($servers as $server) {
            echo '<tr><td>';
            echo '<a href="servers.php?action=manage&fqdn=' . $server->fqdn . '">' . $server->fqdn . '</a>';
            echo '</td>';
            echo '<td>';
            if ($server->isOnline() and $can_manage_server) {
                echo '<form action="actions.php" method="post" onsubmit="return confirm(\'' . _('Are you sure you want to remove this application from this server?') . '\');">';
                echo '<input type="hidden" name="action" value="del" />';
                echo '<input type="hidden" name="name" value="Application_Server" />';
                echo '<input type="hidden" name="application" value="' . $id . '" />';
                echo '<input type="hidden" name="server" value="' . $server->fqdn . '" />';
                echo '<input type="submit" value="' . _('Remove from this server') . '"/>';
                echo '</form>';
            }
            echo '</td>';
            echo '</tr>';
        }
        if (count($servers_available) > 0 and $can_manage_server) {
            echo '<tr>';
            echo '<form action="actions.php" method="post"><td>';
            echo '<input type="hidden" name="name" value="Application_Server" />';
            echo '<input type="hidden" name="action" value="add" />';
            echo '<input type="hidden" name="application" value="' . $id . '" />';
            echo '<select name="server">';
            foreach ($servers_available as $server) {
                echo '<option value="' . $server->fqdn . '">' . $server->fqdn . '</option>';
            }
            echo '</select>';
            echo '</td><td><input type="submit" value="' . _('Add to this server') . '" /></td>';
            echo '</form>';
            echo '</tr>';
        }
        echo '</table>';
        echo "<div>\n";
    }
    if (count($appgroups) > 0) {
        echo '<div>';
        echo '<h2>' . _('Groups with this application') . '</h2>';
        echo '<table border="0" cellspacing="1" cellpadding="3">';
        foreach ($groups as $group) {
            echo '<tr>';
            echo '<td>';
            echo '<a href="appsgroup.php?action=manage&id=' . $group->id . '">' . $group->name . '</a>';
            echo '</td>';
            echo '<td><form action="actions.php" method="post" onsubmit="return confirm(\'' . _('Are you sure you want to delete this application from this group?') . '\');">';
            echo '<input type="hidden" name="name" value="Application_ApplicationGroup" />';
            echo '<input type="hidden" name="action" value="del" />';
            echo '<input type="hidden" name="element" value="' . $id . '" />';
            echo '<input type="hidden" name="group" value="' . $group->id . '" />';
            echo '<input type="submit" value="' . _('Delete from this group') . '" />';
            echo '</form></td>';
            echo '</tr>';
        }
        if (count($groups_available) > 0) {
            echo '<tr>';
            echo '<form action="actions.php" method="post"><td>';
            echo '<input type="hidden" name="name" value="Application_ApplicationGroup" />';
            echo '<input type="hidden" name="action" value="add" />';
            echo '<input type="hidden" name="element" value="' . $id . '" />';
            echo '<select name="group">';
            foreach ($groups_available as $group) {
                echo '<option value="' . $group->id . '">' . $group->name . '</option>';
            }
            echo '</select>';
            echo '</td><td><input type="submit" value="' . _('Add to this group') . '" /></td>';
            echo '</form>';
            echo '</tr>';
        }
        echo '</table>';
        echo "<div>\n";
    }
    // Mime-Type part
    echo '<div>';
    echo '<h2>' . _('Mime-Types') . '</h2>';
    echo '<div>';
    echo '<table border="0" cellspacing="1" cellpadding="3">';
    foreach ($mimeliste1 as $mime) {
        echo '<tr><td>';
        echo '<a href="mimetypes.php?action=manage&id=' . urlencode($mime) . '">' . $mime . '</a>';
        echo '</td>';
        echo '<td>';
        echo '<form action="actions.php" method="post">';
        echo '<input type="hidden" name="name" value="Application_MimeType" />';
        echo '<input type="hidden" name="action" value="del" />';
        echo '<input type="hidden" name="id" value="' . $app->getAttribute('id') . '" />';
        echo '<input type="hidden" name="mime" value="' . $mime . '" />';
        echo '<input type="submit" value="' . _('Del') . '"/>';
        echo '</form>';
        echo '</td>';
        echo '</tr>';
    }
    if (is_array($mimeliste2) && count($mimeliste2) > 0) {
        echo '<tr>';
        echo '<form action="actions.php" method="post">';
        echo '<input type="hidden" name="name" value="Application_MimeType" />';
        echo '<input type="hidden" name="action" value="add" />';
        echo '<input type="hidden" name="id" value="' . $app->getAttribute('id') . '" />';
        echo '<td>';
        echo '<select name="mime">';
        foreach ($mimeliste2 as $mime) {
            echo '<option>' . $mime . '</option>';
        }
        echo '</select>';
        echo '</td>';
        echo '<td>';
        echo '<input type="submit" value="' . _('Add') . '"/>';
        echo '</td>';
        echo '</form>';
        echo '</tr>';
    }
    echo '<tr>';
    echo '<form action="actions.php" method="post">';
    echo '<input type="hidden" name="name" value="Application_MimeType" />';
    echo '<input type="hidden" name="action" value="add" />';
    echo '<input type="hidden" name="id" value="' . $app->getAttribute('id') . '" />';
    echo '<td>' . _('Custom Mime-Type: ') . '<input type="text" name="mime" /></td>';
    echo '<td>';
    echo '<input type="submit" value="' . _('Add') . '"/>';
    echo '</td>';
    echo '</form>';
    echo '</tr>';
    echo '</table>';
    echo '</div>';
    echo '</div>';
    // mime div
    echo '</div>';
    echo '</div>';
    echo '</div>';
    echo '</div>';
    echo '</div>';
    echo '</div>';
    page_footer();
    die;
}
Ejemplo n.º 15
0
 public function addUserToProfile($user_, $profile_)
 {
     if (!is_object($user_)) {
         Logger::error('main', "ProfileDB::internal::addUserToProfile, parameter 'user' is not correct, user: "******"ProfileDB::internal::addUserToProfile, parameter 'profile' is not correct, profile: " . serialize($profile_));
         return false;
     }
     return Abstract_Liaison::save('UserProfile', $user_->getAttribute('login'), $profile_->id);
 }
Ejemplo n.º 16
0
 public function remove($usergroup_)
 {
     Logger::debug('main', "USERGROUPDB::remove({$usergroup_})");
     if (array_key_exists($usergroup_->id, $this->cache)) {
         unset($this->cache[$usergroup_->id]);
     }
     // first we delete liaisons
     $sql2 = SQL::getInstance();
     Abstract_Liaison::delete('UsersGroupApplicationsGroup', $usergroup_->getUniqueID(), NULL);
     Abstract_Liaison::delete('UsersGroup', NULL, $usergroup_->getUniqueID());
     // second we delete sharedfolder acls for the group
     if (Preferences::moduleIsEnabled('SharedFolderDB')) {
         $sharedfolderdb = SharedFolderDB::getInstance();
         $networkfolders = $sharedfolderdb->importFromUsergroup($usergroup_->getUniqueID());
         if (is_array($networkfolders) && count($networkfolders) > 0) {
             foreach ($networkfolders as $networkfolder) {
                 $networkfolder->delUserGroup($usergroup_);
             }
         }
     }
     // third remove the preferences if it is default
     if ($usergroup_->isDefault()) {
         // unset the default usergroup
         $prefs = new Preferences_admin();
         $mods_enable = $prefs->set('general', 'user_default_group', '');
         $prefs->backup();
     }
     // fourth we delete the group
     $res = $sql2->DoQuery('DELETE FROM @1 WHERE @2 = %3', $this->table, 'id', $usergroup_->id);
     return $res !== false;
 }
Ejemplo n.º 17
0
 public function remove($group_)
 {
     Logger::debug('main', "ApplicationsGroupDB::sql::remove({$group_})");
     if (!is_object($group_)) {
         Logger::error('main', "ApplicationsGroupDB::sql::remove({$group_}) the parameter is not a object");
         return false;
     }
     if (array_key_exists($group_->id, $this->cache)) {
         unset($this->cache[$group_->id]);
     }
     // first we delete liaison
     Abstract_Liaison::delete('UsersGroupApplicationsGroup', NULL, $group_->id);
     Abstract_Liaison::delete('AppsGroup', NULL, $group_->id);
     // second we delete the group
     $sql2 = SQL::getInstance();
     $res = $sql2->DoQuery('DELETE FROM @1 WHERE @2 = %3', $this->table, 'id', $group_->id);
     return $res !== false;
 }
Ejemplo n.º 18
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;
}
Ejemplo n.º 19
0
 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;
 }
Ejemplo n.º 20
0
 public static function getAllMimeTypes()
 {
     $mimes = array();
     $liaisons = Abstract_Liaison::load('ApplicationMimeType', NULL, NULL);
     if (is_array($liaisons)) {
         foreach ($liaisons as $elem) {
             if (!in_array($elem->group, $mimes)) {
                 $mimes[] = $elem->group;
             }
         }
     }
     return $mimes;
 }
Ejemplo n.º 21
0
        $l = Abstract_Liaison::load('UsersGroupApplicationsGroup', $_REQUEST['group_u'], $_REQUEST['group_a']);
        if (is_null($l)) {
            $ret = Abstract_Liaison::save('UsersGroupApplicationsGroup', $_REQUEST['group_u'], $_REQUEST['group_a']);
            if ($ret === true) {
                popup_info(_('Publication successfully added'));
            } else {
                popup_error(_('Unable to save the publication'));
            }
        } else {
            popup_error(_('This publication already exists'));
        }
    }
    if ($_REQUEST['action'] == 'del') {
        $l = Abstract_Liaison::load('UsersGroupApplicationsGroup', $_REQUEST['group_u'], $_REQUEST['group_a']);
        if (!is_null($l)) {
            $ret = Abstract_Liaison::delete('UsersGroupApplicationsGroup', $_REQUEST['group_u'], $_REQUEST['group_a']);
            if ($ret === true) {
                popup_info(_('Publication successfully deleted'));
            } else {
                popup_error(_('Unable to delete the publication'));
            }
        } else {
            popup_error(_('This publication does not exist'));
        }
    }
}
if ($_REQUEST['name'] == 'UserGroup') {
    if (!checkAuthorization('manageUsersGroups')) {
        redirect();
    }
    $userGroupDB = UserGroupDB::getInstance();
Ejemplo n.º 22
0
$buf = Abstract_Server::load($_GET['fqdn']);
if (!$buf || !$buf->isAuthorized()) {
    Logger::error('main', '(webservices/application) Server not authorized : ' . $_GET['fqdn'] . ' == ' . @gethostbyname($_GET['fqdn']) . ' ?');
    die('Server not authorized');
}
Logger::debug('main', '(webservices/application) Security check OK');
$prefs = Preferences::getInstance();
if (!$prefs) {
    die_error('get Preferences failed', __FILE__, __LINE__);
}
$mods_enable = $prefs->get('general', 'module_enable');
if (!in_array('ApplicationDB', $mods_enable)) {
    Logger::error('main', '(webservices/application) Module ApplicationDB must be enabled');
    header('HTTP/1.1 400 Bad Request');
    die;
}
$applicationDB = ApplicationDB::getInstance();
$app = $applicationDB->import($_GET['id']);
if (!is_object($app)) {
    Logger::error('main', '(webservices/application) error final');
    header('HTTP/1.1 404 Not Found');
    die;
}
if ($app->getAttribute('static')) {
    if (!is_object(Abstract_Liaison::load('StaticApplicationServer', $app->getAttribute('id'), $buf->fqdn))) {
        Abstract_Liaison::save('StaticApplicationServer', $app->getAttribute('id'), $buf->fqdn);
    }
}
header('Content-Type: text/xml; charset=utf-8');
echo $app->toXML($buf);
die;
Ejemplo n.º 23
0
function cleanup_liaison($type_, $element_, $group_)
{
    if (checkup_liaison($type_, $element_, $group_) !== true) {
        Abstract_Liaison::delete($type_, $element_, $group_);
        return true;
    }
    return false;
}
Ejemplo n.º 24
0
 public function isOrphan()
 {
     Logger::debug('main', 'Application::isOrphan');
     $liaisons = Abstract_Liaison::load('ApplicationServer', $this->getAttribute('id'), NULL);
     if (is_array($liaisons) && count($liaisons) == 0) {
         return true;
     }
     return false;
 }
Ejemplo n.º 25
0
 public function getGroupsContains($contains_, $attributes_ = array('name', 'description'), $limit_ = 0, $user_ = null)
 {
     if (!is_null($user_)) {
         $liasons = Abstract_Liaison::load('UsersGroup', $user_->getAttribute('id'), NULL);
         $groups2 = array();
         if (is_array($liasons)) {
             foreach ($liasons as $group_id => $liason) {
                 array_push($groups2, $group_id);
             }
         }
     }
     $groups = array();
     $count = 0;
     $sizelimit_exceeded = false;
     $list = $this->getList();
     foreach ($list as $a_group) {
         if (!is_null($user_) && !in_array($a_group->getUniqueID(), $groups2)) {
             continue;
         }
         foreach ($attributes_ as $an_attribute) {
             if ($contains_ == '' or isset($a_group->{$an_attribute}) and is_string(strstr($a_group->{$an_attribute}, $contains_))) {
                 $groups[] = $a_group;
                 $count++;
                 if ($limit_ > 0 && $count >= $limit_) {
                     $sizelimit_exceeded = next($list) !== false;
                     // is it the last element ?
                     return array($users, $sizelimit_exceeded);
                 }
                 break;
             }
         }
     }
     return array($groups, $sizelimit_exceeded);
 }
 public function delete($group_)
 {
     Logger::debug('main', "Abstract_ServersGroup::delete({$group_})");
     if (!is_object($group_)) {
         Logger::error('main', "Abstract_ServersGroup::delete({$group_}) the parameter is not a object");
         return false;
     }
     if (array_key_exists($group_->id, self::$cache)) {
         unset(self::$cache[$group_->id]);
     }
     // first we delete liaison
     Abstract_Liaison::delete('UsersGroupServersGroup', NULL, $group_->id);
     Abstract_Liaison::delete('ServersGroup', NULL, $group_->id);
     // second we delete the group
     $SQL = SQL::getInstance();
     $res = $SQL->DoQuery('DELETE FROM #1 WHERE @2 = %3', self::table, 'id', $group_->id);
     return $res !== false;
 }
Ejemplo n.º 27
0
 public static function delete($id_)
 {
     Logger::debug('main', 'Starting Abstract_Session::delete for \'' . $id_ . '\'');
     $SQL = SQL::getInstance();
     $id = $id_;
     $SQL->DoQuery('SELECT 1 FROM @1 WHERE @2 = %3 LIMIT 1', $SQL->prefix . 'sessions', 'id', $id);
     $total = $SQL->NumRows();
     if ($total == 0) {
         Logger::error('main', "Abstract_Session::delete({$id_}) session does not exist (NumRows == 0)");
         return false;
     }
     $SQL->DoQuery('DELETE FROM @1 WHERE @2 = %3 LIMIT 1', $SQL->prefix . 'sessions', 'id', $id);
     Abstract_Liaison::delete('ServerSession', NULL, $id_);
     $tokens = Abstract_Token::load_by_session($id_);
     foreach ($tokens as $token) {
         Abstract_Token::delete($token->id);
     }
     return true;
 }
Ejemplo n.º 28
0
 public function remove($user_)
 {
     Logger::debug('main', 'UserDB::sql::remove');
     if (is_object($user_) && $user_->hasAttribute('login')) {
         $SQL = SQL::getInstance();
         // first we delete all liaisons
         $liaisons = Abstract_Liaison::load('UsersGroup', $user_->getAttribute('login'), NULL);
         foreach ($liaisons as $liaison) {
             Abstract_Liaison::delete('UsersGroup', $liaison->element, $liaison->group);
         }
         // second we delete the user
         return $SQL->DoQuery('DELETE FROM @1 WHERE @2 = %3', $this->table, 'login', $user_->getAttribute('login'));
     } else {
         Logger::debug('main', 'UserDB::sql::remove failed (user not ok)');
         return false;
     }
 }
Ejemplo n.º 29
0
 public function updatePolicy($new_policy_)
 {
     $old_policy = $this->getPolicy();
     Abstract_Liaison::delete('ACL', $this->getUniqueID(), NULL);
     foreach ($new_policy_ as $a_policy => $allow) {
         if ($allow) {
             Abstract_Liaison::save('ACL', $this->getUniqueID(), $a_policy);
         }
     }
 }
Ejemplo n.º 30
0
 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;
 }