Esempio n. 1
0
function resetDefaultMenu($uuid)
{
    $ret = xmlrpc_resetComputerBootMenu($uuid);
    if (!isXMLRPCError() && $ret) {
        new NotifyWidgetSuccess(sprintf(_T("Default menu has been successfully restored.", "imaging")));
    }
}
Esempio n. 2
0
function auth_user($login, $pass)
{
    global $conf;
    global $error;
    if ($login == "" || $pass == "") {
        return false;
    }
    $param = array();
    $param[] = $login;
    $param[] = prepare_string($pass);
    $ret = xmlCall("base.ldapAuth", $param);
    if ($ret != "1") {
        if (!isXMLRPCError()) {
            $error = _("Invalid login");
        }
        return false;
    }
    $subscription = getSubscriptionInformation(true);
    if ($subscription['is_subsscribed']) {
        $msg = array();
        if ($subscription['too_much_users']) {
            $msg[] = _("users");
        }
        if ($subscription['too_much_computers']) {
            $msg[] = _("computers");
        }
        if (count($msg) > 0) {
            $warn = sprintf(_('WARNING: The number of registered %s is exceeding your license.'), implode($msg, _(' and ')));
            new NotifyWidgetWarning($warn);
        }
    }
    return true;
}
Esempio n. 3
0
function updateFailoverConfig($FH)
{
    global $result;
    global $error;
    setFailoverConfig($FH->getPostValue("primaryIp"), $FH->getPostValue("secondaryIp"), $FH->getPostValue("primaryPort"), $FH->getPostValue("secondaryPort"), $FH->getPostValue("delay"), $FH->getPostValue("update"), $FH->getPostValue("balance"), $FH->getPostValue("mclt"), $FH->getPostValue("split"));
    if (!isXMLRPCError()) {
        $result .= _T("Failover configuration updated.") . "<br />";
        $result .= _T("You must restart DHCP services.") . "<br />";
    } else {
        $error .= _T("Failed to update the failover configuration.") . "<br />";
    }
}
Esempio n. 4
0
/*
 * Display right top shortcuts menu
 */
right_top_shortcuts_display();

if (isset($_POST['bsync'])) {
    if (isset($params['uuid'])) {
        $ret = xmlrpc_synchroComputer($params['uuid']);
    } else {
        $ret = xmlrpc_synchroProfile($params['gid']);
    }
    // goto images list
    if ($ret[0] and !isXMLRPCError()) {
        /* insert notification code here if needed */
    } elseif (!$ret[0] and !isXMLRPCError()) {
         unset($_SESSION["imaging.isComputerInProfileRegistered_".$params['uuid']]);
         unset($_SESSION["imaging.isComputerRegistered_".$params['uuid']]);
         if (!xmlrpc_isComputerInProfileRegistered($params['uuid']) && !xmlrpc_isComputerRegistered($params['uuid'])) {
            new NotifyWidgetFailure(sprintf(_T("This computer is no longer registered : %s", "imaging"), $params['uuid']));
            header("Location: ".urlStrRedirect("base/computers/index", $params));
            exit;
         } else {
            new NotifyWidgetFailure(sprintf(_T("Boot Menu Generation failed for : %s", "imaging"), implode(', ', $ret[1])));
         }
    }
}

if (isset($params['uuid'])) {
    $_GET['type'] = '';
    $_GET['target_uuid'] = $params['uuid'];
Esempio n. 5
0
function start_a_command($proxy = array())
{
    if ($_POST['editConvergence']) {
        $changed_params = getChangedParams($_POST);
        if ($changed_params == array('active')) {
            print "We have to edit command....";
        }
    }
    $error = "";
    if (!check_date($_POST)) {
        $error .= _T("Your start and end dates are not coherent, please check them.<br/>", "msc");
    }
    # should add some other tests on fields (like int are int? ...)
    if ($error != '') {
        new NotifyWidgetFailure($error);
        complete_post();
        $url = "base/computers/msctabs?";
        foreach ($_GET as $k => $v) {
            $url .= "{$v}={$k}";
        }
        header("Location: " . urlStrRedirect("msc/logs/viewLogs", array_merge($_GET, $_POST, array('failure' => True))));
        exit;
    }
    // Vars seeding
    $post = $_POST;
    $from = $post['from'];
    $path = explode('|', $from);
    $module = $path[0];
    $submod = $path[1];
    $page = $path[2];
    $params = array();
    foreach (array('start_script', 'clean_on_success', 'do_reboot', 'do_wol', 'next_connection_delay', 'max_connection_attempt', 'do_inventory', 'ltitle', 'parameters', 'papi', 'maxbw', 'deployment_intervals', 'max_clients_per_proxy', 'launchAction') as $param) {
        $params[$param] = $post[$param];
    }
    $halt_to = array();
    foreach ($post as $p => $v) {
        if (preg_match('/^issue_halt_to_/', $p)) {
            $p = preg_replace('/^issue_halt_to_/', '', $p);
            if ($v == 'on') {
                $halt_to[] = $p;
            }
        }
    }
    $params['issue_halt_to'] = $halt_to;
    $p_api = new ServerAPI();
    $p_api->fromURI($post['papi']);
    foreach (array('start_date', 'end_date') as $param) {
        if ($post[$param] == _T("now", "msc")) {
            $params[$param] = "0000-00-00 00:00:00";
        } elseif ($post[$param] == _T("never", "msc")) {
            $params[$param] = "0000-00-00 00:00:00";
        } else {
            $params[$param] = $post[$param];
        }
    }
    $pid = $post['pid'];
    $mode = $post['copy_mode'];
    if (isset($post['uuid']) && $post['uuid']) {
        // command on a single target
        $hostname = $post['hostname'];
        $uuid = $post['uuid'];
        $target = array($uuid);
        $tab = 'tablogs';
        /* record new command */
        $id = add_command_api($pid, $target, $params, $p_api, $mode, NULL);
        if (!isXMLRPCError()) {
            scheduler_start_these_commands('', array($id));
            /* then redirect to the logs page */
            header("Location: " . urlStrRedirect("msc/logs/viewLogs", array('tab' => $tab, 'uuid' => $uuid, 'hostname' => $hostname, 'cmd_id' => $id)));
            exit;
        } else {
            /* Return to the launch tab, the backtrace will be displayed */
            header("Location: " . urlStrRedirect("msc/logs/viewLogs", array('tab' => 'tablaunch', 'uuid' => $uuid, 'hostname' => $hostname)));
            exit;
        }
    } else {
        # command on a whole group
        $gid = $post['gid'];
        $tab = 'grouptablogs';
        // record new command
        // given a proxy list and a proxy style, we now have to build or proxy chain
        // target structure is an dict using the following stucture: "priority" => array(proxies)
        $ordered_proxies = array();
        if ($_POST['proxy_mode'] == 'multiple') {
            // first case: split mode; every proxy got the same priority (1 in our case)
            foreach ($proxy as $p) {
                array_push($ordered_proxies, array('uuid' => $p, 'priority' => 1, 'max_clients' => $_POST['max_clients_per_proxy']));
            }
            $params['proxy_mode'] = 'split';
        } elseif ($_POST['proxy_mode'] == 'single') {
            // second case: queue mode; one priority level per proxy, starting at 1
            $current_priority = 1;
            foreach ($proxy as $p) {
                array_push($ordered_proxies, array('uuid' => $p, 'priority' => $current_priority, 'max_clients' => $_POST['max_clients_per_proxy']));
                $current_priority += 1;
            }
            $params['proxy_mode'] = 'queue';
        }
        if (quick_get('convergence')) {
            $active = $_POST['active'] == 'on' ? 1 : 0;
            $cmd_type = 2;
            // Convergence command type
            if (quick_get('editConvergence')) {
                /* Stop command */
                $cmd_id = xmlrpc_get_convergence_command_id($gid, $p_api, $pid);
                stop_command($cmd_id);
                /* Set end date of this command to now(), don't touch to start date */
                $start_date = _get_command_start_date($cmd_id);
                extend_command($cmd_id, $start_date, date("Y-m-d H:i:s"));
                /* Create new command */
                $deploy_group_id = xmlrpc_get_deploy_group_id($gid, $p_api, $pid);
                $command_id = add_command_api($pid, NULL, $params, $p_api, $mode, $deploy_group_id, $ordered_proxies, $cmd_type);
                if (!$active) {
                    // If this convergence is not active, expire this command
                    $start_date = _get_command_start_date($command_id);
                    extend_command($command_id, $start_date, date("Y-m-d H:i:s"));
                }
                /* Update convergence DB */
                $updated_datas = array('active' => $active, 'commandId' => intval($command_id), 'cmdPhases' => $params);
                xmlrpc_edit_convergence_datas($gid, $p_api, $pid, $updated_datas);
            } else {
                /* Create convergence */
                // create sub-groups
                $group = new Group($gid, True);
                $package = to_package(getPackageDetails($p_api, $pid));
                $convergence_groups = $group->createConvergenceGroups($package);
                $deploy_group_id = $convergence_groups['deploy_group_id'];
                $done_group_id = $convergence_groups['done_group_id'];
                // Add command on sub-group
                $command_id = add_command_api($pid, NULL, $params, $p_api, $mode, $deploy_group_id, $ordered_proxies, $cmd_type);
                if (!$active) {
                    // If this convergence is not active, expire this command
                    $start_date = _get_command_start_date($command_id);
                    extend_command($command_id, $start_date, date("Y-m-d H:i:s"));
                }
                // feed convergence db
                xmlrpc_add_convergence_datas($gid, $deploy_group_id, $done_group_id, $pid, $p_api, intval($command_id), $active, $params);
            }
            header("Location: " . urlStrRedirect("base/computers/groupmsctabs", array('gid' => $gid)));
            exit;
        } else {
            $id = add_command_api($pid, NULL, $params, $p_api, $mode, $gid, $ordered_proxies);
            scheduler_start_these_commands('', array($id));
            // then redirect to the logs page
            header("Location: " . urlStrRedirect("msc/logs/viewLogs", array('tab' => $tab, 'gid' => $gid, 'cmd_id' => $id, 'proxy' => $proxy)));
            exit;
        }
    }
}
Esempio n. 6
0
    $f->add(new HiddenTpl("target_name"), array("value" => $target_name, "hide" => True));
    $f->add(new HiddenTpl("type"), array("value" => $type, "hide" => True));
    $f->pop();
    $f->addButton("bunregister2", _T("Unregister this computer", 'imaging'));
    $f->addButton("cancel", _T("Cancel", "imaging"), 'btnSecondary');
    $f->display();
} else {
    if (isset($_POST["bunregister2"])) {
        $type = $_POST["type"];
        $target_uuid = $_POST['target_uuid'];
        $target_name = $_POST['target_name'];
        $params['target_uuid'] = $target_uuid;
        $params['target_name'] = $target_name;
        $params['backup'] = $_POST['backup'];
        $ret = xmlrpc_delComputersImaging(array($target_uuid), $params['backup'] ? true : false);
        if ($ret[0] and !isXMLRPCError()) {
            new NotifyWidgetSuccess(sprintf(_T("The computer %s has correctly been unregistered from imaging", 'imaging'), $target_name));
            unset($_SESSION["imaging.isComputerRegistered_" . $target_uuid]);
            header("Location: " . urlStrRedirect("base/computers/register_target", $params));
            exit;
        } else {
            new NotifyWidgetFailure(sprintf(_T("Failed to unregister the computer %s", 'imaging'), $target_name));
        }
        $is_unregistering = True;
    } else {
        /*
         * type: 'group' for a profile, '' for a single computer
         */
        $type = $_GET["type"];
        $target_uuid = $_GET['target_uuid'];
        $target_name = $_GET['target_name'];
Esempio n. 7
0
/**
 * Make a XML-RPC call
 * If the global variable $errorStatus is not zero, the XML-RPC call is not
 * done, and this function returns nothing.
 *
 * @param $method name of the method
 * @param $params array with param
 * @return the XML-RPC call result
 */
function xmlCall($method, $params = null)
{
    global $errorStatus;
    global $errorDesc;
    global $conf;
    if (isXMLRPCError()) {
        // Don't do a XML-RPC call if a previous one failed
        return;
    }
    /*
      Set defaut login/pass if not set.
      The credentials are used to authenticate the web interface to the XML-RPC
      server.
    */
    if (!isset($conf["global"]["login"])) {
        $conf["global"]["login"] = "******";
        $conf["global"]["password"] = "******";
    }
    $output_options = array("output_type" => "xml", "verbosity" => "pretty", "escaping" => array("markup"), "version" => "xmlrpc", "encoding" => "UTF-8");
    $request = xmlrpc_encode_request($method, $params, $output_options);
    /* We build the HTTP POST that will be sent */
    $host = $_SESSION["XMLRPC_agent"]["host"] . ":" . $_SESSION["XMLRPC_agent"]["port"];
    $url = "/";
    $httpQuery = "POST " . $url . " HTTP/1.0\r\n";
    $httpQuery .= "User-Agent: MMC web interface\r\n";
    $httpQuery .= "Host: " . $host . "\r\n";
    $httpQuery .= "Content-Type: text/xml\r\n";
    $httpQuery .= "Content-Length: " . strlen($request) . "\r\n";
    /* Don't set the RPC session cookie if the user is on the login page */
    if ($method == "base.ldapAuth" || $method == "base.tokenAuthenticate") {
        unset($_SESSION["RPCSESSION"]);
        $httpQuery .= "X-Browser-IP: " . $_SERVER["REMOTE_ADDR"] . "\r\n";
        $httpQuery .= "X-Browser-HOSTNAME: " . gethostbyaddr($_SERVER["REMOTE_ADDR"]) . "\r\n";
    } else {
        $httpQuery .= "Cookie: " . $_SESSION["RPCSESSION"] . "\r\n";
    }
    $httpQuery .= "Authorization: Basic " . base64_encode($conf["global"]["login"] . ":" . $conf["global"]["password"]) . "\r\n\r\n";
    $httpQuery .= $request;
    $sock = null;
    /* Connect to the XML-RPC server */
    if ($_SESSION["XMLRPC_agent"]["scheme"] == "https") {
        $prot = "ssl://";
    } else {
        $prot = "";
    }
    list($sock, $errNo, $errString) = openSocket($prot, $conf);
    if (!$sock) {
        /* Connection failure */
        $errObj = new ErrorHandlingItem('');
        $errObj->setMsg(_("Can't connect to MMC agent"));
        $errObj->setAdvice(_("MMC agent seems to be down or not correctly configured.") . '<br/> Error: ' . $errNo . ' - ' . $errString);
        $errObj->setTraceBackDisplay(false);
        $errObj->setSize(400);
        $errObj->process('');
        $errorStatus = 1;
        return FALSE;
    }
    /* Send the HTTP POST */
    if (!fwrite($sock, $httpQuery, strlen($httpQuery))) {
        /* Failure */
        $errObj = new ErrorHandlingItem('');
        $errObj->setMsg(_("Can't send XML-RPC request to MMC agent"));
        $errObj->setAdvice(_("MMC agent seems to be not correctly configured."));
        $errObj->setTraceBackDisplay(false);
        $errObj->setSize(400);
        $errObj->process('');
        $errorStatus = 1;
        return FALSE;
    }
    fflush($sock);
    /* Get the response from the server */
    $xmlResponse = '';
    while (!feof($sock)) {
        $ret = fread($sock, 8192);
        $info = stream_get_meta_data($sock);
        if ($info['timed_out']) {
            $errObj = new ErrorHandlingItem('');
            $errObj->setMsg(_('MMC agent communication problem'));
            $errObj->setAdvice(_('Timeout when reading data from the MMC agent. Please check network connectivity and server load.'));
            $errObj->setTraceBackDisplay(false);
            $errObj->setSize(400);
            $errObj->process('');
            $errorStatus = 1;
            return FALSE;
        }
        if ($ret === False) {
            $errObj = new ErrorHandlingItem('');
            $errObj->setMsg(_("Error while reading MMC agent XML-RPC response."));
            $errObj->setAdvice(_("Please check network connectivity."));
            $errObj->setTraceBackDisplay(false);
            $errObj->setSize(400);
            $errObj->process('');
            $errorStatus = 1;
            return FALSE;
        }
        $xmlResponse .= $ret;
    }
    fclose($sock);
    /* Process the response */
    if (!strlen($xmlResponse)) {
        $errObj = new ErrorHandlingItem('');
        $errObj->setMsg(_("MMC agent communication problem"));
        $errObj->setAdvice(_("Can't communicate with MMC agent. Please check you're using the right TCP port and the right protocol."));
        $errObj->setTraceBackDisplay(false);
        $errObj->setSize(400);
        $errObj->process('');
        $errorStatus = 1;
        return FALSE;
    }
    /* Process the received HTTP header */
    $pos = strpos($xmlResponse, "\r\n\r\n");
    $httpHeader = substr($xmlResponse, 0, $pos);
    if ($method == "base.ldapAuth" || $method == "base.tokenAuthenticate") {
        if ($method == "base.tokenAuthenticate") {
            $_SESSION["AUTH_METHOD"] = "token";
        } else {
            $_SESSION["AUTH_METHOD"] = "login";
        }
        /* The RPC server must send us a session cookie */
        if (preg_match("/(TWISTED_SESSION=[0-9a-f]+);/", $httpHeader, $match) > 0) {
            $_SESSION["RPCSESSION"] = $match[1];
        } else {
            /* Can't get a session from the Twisted XML-RPC server */
            $errObj = new ErrorHandlingItem('');
            $errObj->setMsg(_("MMC agent communication problem"));
            $errObj->setAdvice(_("The MMC agent didn't give us a session number. Please check the MMC agent version."));
            $errObj->setTraceBackDisplay(false);
            $errObj->setSize(400);
            $errObj->process('');
            $errorStatus = 1;
            return False;
        }
    }
    /* Process the XML response */
    $xmlResponse = substr($xmlResponse, $pos + 4);
    /*
       Test if the XMLRPC result is a boolean value set to False.
       If it is the case, xmlrpc_decode will return an empty string.
       So we need to test this special case.
    
       Looks like this bug is fixed in latest PHP version. At least it works
       with PHP 5.2.0.
    */
    $booleanFalse = "<?xml version='1.0' ?>\n<methodResponse>\n<params>\n<param>\n<value><boolean>0</boolean></value>\n</param>\n</params>\n</methodResponse>\n";
    if ($xmlResponse == $booleanFalse) {
        $xmlResponse = False;
    } else {
        $xmlResponseTmp = xmlrpc_decode($xmlResponse, "UTF-8");
        /* if we cannot decode in UTF-8 */
        if (!$xmlResponseTmp) {
            /* Maybe we received data encoded in ISO latin 1, so convert them
               to UTF8 first*/
            $xmlResponse = iconv("ISO-8859-1", "UTF-8", $xmlResponse);
            $xmlResponse = xmlrpc_decode($xmlResponse, "UTF-8");
        } else {
            $xmlResponse = $xmlResponseTmp;
        }
    }
    /* If debug is on, print the XML-RPC call and result */
    if ($conf["debug"]["level"] != 0) {
        $str = '<div class="alert alert-info">';
        $str .= "XML RPC CALL FUNCTION: {$method}(";
        if (!$params) {
            $params = "null";
        } else {
            if (is_array($params)) {
                $str .= var_export($params, True);
            } else {
                $str .= $params;
            }
        }
        $str .= ')';
        if (is_array($xmlResponse)) {
            $str .= "<pre>";
            $str .= "result : ";
            $str .= var_export($xmlResponse, True);
            $str .= "</pre>";
        } else {
            $str .= "result : " . $xmlResponse;
        }
        $str .= '</div>';
        echo $str;
    }
    /* If the XML-RPC server sent a fault, display an error */
    if (is_array($xmlResponse) && isset($xmlResponse["faultCode"])) {
        if ($xmlResponse["faultCode"] == "8003") {
            /*
             Fault 8003 means the session with the XML-RPC server has expired.
             So we make the current PHP session expire, so that the user is
             redirected to the login page.
            */
            require_once 'modules/base/includes/users-xmlrpc.inc.php';
            // Create a template array to store important session vars
            $temp = array();
            // Session keys to keep
            $keys = array('ip_addr', 'XMLRPC_agent', 'agent', 'XMLRPC_server_description', 'AUTH_METHOD', 'login', 'pass', 'expire', 'lang', 'RPCSESSION', 'aclattr', 'acltab', 'acl', 'supportModList', 'modListVersion', 'doeffect', 'modulesList');
            // Saving session params
            foreach ($keys as $key) {
                if (isset($_SESSION[$key])) {
                    $temp[$key] = $_SESSION[$key];
                }
            }
            // Destroy and recreate session to eliminate
            // modules session params
            session_destroy();
            session_start();
            // Restoring session params
            foreach ($keys as $key) {
                if (isset($temp[$key])) {
                    $_SESSION[$key] = $temp[$key];
                }
            }
            if (auth_user($temp['login'], $temp['pass'])) {
                // If login succeed, retry call after relogin
                return xmlCall($method, $params);
            } else {
                // Logout and request a new login
                unset($_SESSION["expire"]);
                $_SESSION["agentsessionexpired"] = 1;
                $root = $conf["global"]["root"];
                header("Location: {$root}" . "main.php");
                exit;
            }
        }
        /* Try to find an error handler */
        $result = findErrorHandling($xmlResponse["faultCode"]);
        if (!is_object($result) and $result == -1) {
            /* We didn't find one */
            $result = new ErrorHandlingItem('');
            $result->setMsg(_("unknown error"));
            $result->setAdvice(_("This exception is unknown. Please contact us to add an error handling on this error."));
        }
        $result->process($xmlResponse);
        $errorStatus = 1;
        $errorDesc = $xmlResponse["faultCode"];
        return False;
    }
    /* Return the result of the remote procedure call */
    return $xmlResponse;
}
Esempio n. 8
0
# synchronization of locations
global $SYNCHROSTATE_UNKNOWN;
global $SYNCHROSTATE_TODO;
global $SYNCHROSTATE_SYNCHRO;
global $SYNCHROSTATE_RUNNING;
global $SYNCHROSTATE_INIT_ERROR;
$location = getCurrentLocation();
if (isset($_POST['bsync'])) {
    $params['bsync'] = '1';
    $ret = xmlrpc_synchroLocation($_POST['location_uuid']);
    // goto images list
    if ((is_array($ret) and $ret[0] or !is_array($ret) and $ret) and !isXMLRPCError()) {
        /* insert notification code here if needed */
    } elseif (!$ret[0] and !isXMLRPCError()) {
        new NotifyWidgetFailure(sprintf(_T("Boot menu generation failed for package server: %s<br /><br />Check /var/log/mmc/pulse2-package-server.log", "imaging"), implode(', ', $ret[1])));
    } elseif (isXMLRPCError()) {
        new NotifyWidgetFailure(sprintf(_T("Boot menu generation failed for package server: %s<br /><br />Check /var/log/mmc/pulse2-package-server.log", "imaging"), implode(', ', $ret[1])));
    }
}
# needed in the case we have to go back to the good list.
$params['from'] = $_GET['action'];
$params['module'] = $_GET['module'];
$params['submod'] = $_GET['submod'];
$params['action'] = $_GET['action'];
if (displayLocalisationBar()) {
    $location = getCurrentLocation();
    $ajax = new AjaxLocation("modules/imaging/manage/{$page}.php", "container_{$page}", "location", $params);
    list($list, $values) = getEntitiesSelectableElements();
    $ajax->setElements($list);
    $ajax->setElementsVal($values);
    if ($location) {
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * MMC 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 MMC; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */
require_once "modules/pkgs/includes/xmlrpc.php";
if (isset($_POST["bconfirm"])) {
    activateAppstreamFlow($_POST['id'], $_POST['package_name'], $_POST['package_label'], $_POST['duration']);
    if (!isXMLRPCError() and $ret != -1) {
        new NotifyWidgetSuccess(_T("The stream has been added successfully. You will receive the latest updates of this stream directly in your package list.", "pkgs"));
    }
    if ($ret == -1) {
        new NotifyWidgetFailure(_T("Unable to add stream.", "pkgs"));
    }
    header("Location: " . urlStrRedirect("pkgs/pkgs/appstreamSettings", array()));
    exit;
} else {
    $id = $_GET['id'];
    $package_name = $_GET['package_name'];
    $package_label = $_GET['package_label'];
    $duration = $_GET['duration'];
    $f = new PopupForm(_T("Activate this Appstream stream?"));
    $hidden = new HiddenTpl("id");
    $f->add($hidden, array("value" => $id, "hide" => True));
Esempio n. 10
0
require_once "modules/backuppc/includes/xmlrpc.php";
require_once "modules/backuppc/includes/functions.php";
require_once "modules/backuppc/includes/html.inc.php";
require_once "modules/base/includes/computers.inc.php";
require "graph/navbar.inc.php";
require "localSidebar.php";
$computer_name = $_GET['cn'];
$uuid = $_GET['objectUUID'];
// ==========================================================
// Receiving request to set backup for host
// ==========================================================
if (isset($_POST['setBackup'], $_POST['host'])) {
    $response = set_backup_for_host($_POST['host']);
    // Checking reponse
    if (isset($response)) {
        if (isXMLRPCError() || $response['err']) {
            new NotifyWidgetFailure(nl2br($response['errtext']));
        } else {
            new NotifyWidgetSuccess(sprintf(_T('Computer %s has been added to backup system successfully.<br />You can now configure its filesets and scheduling.', 'backuppc'), $computer_name));
            $_GET['tab'] = 'tab2';
        }
    }
    // Setting default profile to nightly
    set_host_period_profile($_POST['host'], 1);
    $rep = getComputersOS($_POST['host']);
    $os = $rep[0]['OSName'];
    // Init best profile
    $bestProfile = NULL;
    $bestSim = 0;
    $backup_profiles = get_backup_profiles();
    foreach ($backup_profiles as $profile) {
Esempio n. 11
0
 /**
  * Returns array('success'=>true) or array('error'=>'error message')
  */
 function handleUpload($uploadDirectory, $random_dir, $p_api_id, $replaceOldFile = FALSE)
 {
     $uploadDirectory .= '/' . $random_dir . '/';
     if (!is_writable($uploadDirectory)) {
         return array('error' => "Server error. Upload directory isn't writable.");
     }
     if (!$this->file) {
         return array('error' => 'No files were uploaded.');
     }
     $size = $this->file->getSize();
     if ($size == 0) {
         return array('error' => 'File is empty');
     }
     if ($size > $this->sizeLimit) {
         return array('error' => 'File is too large');
     }
     $pathinfo = pathinfo($this->file->getName());
     $filename = $pathinfo['filename'];
     //$filename = md5(uniqid());
     $ext = @$pathinfo['extension'];
     // hide notices if extension is empty
     if ($this->allowedExtensions && !in_array(strtolower($ext), $this->allowedExtensions)) {
         $these = implode(', ', $this->allowedExtensions);
         return array('error' => 'File has an invalid extension, it should be one of ' . $these . '.');
     }
     $ext = $ext == '' ? $ext : '.' . $ext;
     if (!$replaceOldFile) {
         /// don't overwrite previous files that were uploaded
         while (file_exists($uploadDirectory . $filename . $ext)) {
             $filename .= rand(10, 99);
         }
     }
     $this->uploadName = $filename . $ext;
     if ($this->file->save($uploadDirectory . $filename . $ext)) {
         // If file pushed to temp directory, push it to MMC agent
         $filename = $filename . $ext;
         $upload_tmp_dir = sys_get_temp_dir();
         $files = array();
         // If mmc-agent is not on the same machine than apache server
         // send binary files with XMLRPC (base64 encoded)
         // else mmc-agent will directly get it from tmp directory
         $mmc_ip = xmlrpc_getMMCIP();
         $local_mmc = in_array($mmc_ip, array('127.0.0.1', 'localhost', $_SERVER['SERVER_ADDR'])) ? True : False;
         $filebinary = False;
         if (!$local_mmc) {
             $file = $upload_tmp_dir . '/' . $random_dir . '/' . $filename;
             // Read and put content of $file to $filebinary
             $filebinary = fread(fopen($file, "r"), filesize($file));
         }
         $files[] = array("filename" => $filename, "filebinary" => $local_mmc ? False : base64_encode($filebinary), "tmp_dir" => $local_mmc ? $upload_tmp_dir : False);
         $push_package_result = pushPackage($p_api_id, $random_dir, $files, $local_mmc);
         // Delete package from PHP /tmp dir
         delete_directory($upload_tmp_dir . '/' . $random_dir);
         if (!isXMLRPCError() and $push_package_result) {
             return array('success' => true);
         } else {
             return array('error' => 'Could not save uploaded file.' . 'The upload was cancelled, or server error encountered');
         }
     } else {
         return array('error' => 'Could not save uploaded file.' . 'The upload was cancelled, or server error encountered');
     }
 }
Esempio n. 12
0
if (isset($_POST["badd"])) {
    $groupname = $_POST["groupname"];
    $groupdesc = stripslashes($_POST["groupdesc"]);
    $result = create_group($error, $groupname);
    change_group_desc($groupname, $groupdesc);
    if (!isXMLRPCError()) {
        new NotifyWidgetSuccess(sprintf(_("Group %s successfully added"), $groupname));
        header("Location: " . urlStrRedirect("base/groups/index"));
        exit;
    }    
} else if (isset($_POST["bmodify"])) {
    $groupname = $_POST["groupname"];
    $groupdesc = stripslashes($_POST["groupdesc"]);
    change_group_desc($groupname, $groupdesc);
    callPluginFunction("changeGroup", array($_POST));
    if (!isXMLRPCError()) new NotifyWidgetSuccess(sprintf(_("Group %s successfully modified"), $groupname));
}


if ($_GET["action"] == "add") {
    $title = _("Add group");
    $groupname = "";
    $groupdesc = "";
    $detailArr = array();
} else {
    $title = _("Edit group");
    $groupname = $_GET["group"];
    $detailArr = get_detailed_group($groupname);
    if (isset($detailArr["description"])) $groupdesc = htmlspecialchars($detailArr["description"][0]);
    else $groupdesc = "";
}
Esempio n. 13
0
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with MMC; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */
require "modules/samba4/includes/machines-xmlrpc.inc.php";
if (isset($_GET["machine"])) {
    $machine = urldecode($_GET["machine"]);
}
if (isset($_POST["machine"])) {
    $machine = $_POST["machine"];
}
if (isset($_POST["bdeleletemachine"])) {
    $deleteActionSuccess = deleteMachine($machine);
    if (!isXMLRPCError() and $deleteActionSuccess) {
        $computerDeletedMessage = sprintf(_T("Computer <strong>%s</strong> deleted.", "samba4"), $machine);
        new NotifyWidgetSuccess($computerDeletedMessage);
    } else {
        $computerDeletedMessage = sprintf(_T("There has been a problem while deleting <strong>%s</strong> computer.", "samba4"), $machine);
        new NotifyWidgetFailure($computerDeletedMessage);
    }
    header("location: " . urlStrRedirect('samba4/machines/index'));
    exit;
} else {
    $form = new PopupForm(_T("Delete a computer", "samba4"));
    $form->addText(sprintf(_T("You will delete the %s computer", "samba4"), "<strong>{$machine}</strong>"));
    $form->addValidateButton("bdeleletemachine");
    $form->addCancelButton("bback");
    $form->display();
}
Esempio n. 14
0
 /**
  * Returns array('success'=>true) or array('error'=>'error message')
  */
 function handleUpload($uploadDirectory, $random_dir, $p_api_id, $replaceOldFile = FALSE)
 {
     $uploadDirectory .= '/' . $random_dir . '/';
     if (!is_writable($uploadDirectory)) {
         return array('error' => "Server error. Upload directory isn't writable.");
     }
     if (!$this->file) {
         return array('error' => 'No files were uploaded.');
     }
     $size = $this->file->getSize();
     if ($size == 0) {
         return array('error' => 'File is empty');
     }
     if ($size > $this->sizeLimit) {
         return array('error' => 'File is too large');
     }
     $pathinfo = pathinfo($this->file->getName());
     $filename = $pathinfo['filename'];
     //$filename = md5(uniqid());
     $ext = @$pathinfo['extension'];
     // hide notices if extension is empty
     if ($this->allowedExtensions && !in_array(strtolower($ext), $this->allowedExtensions)) {
         $these = implode(', ', $this->allowedExtensions);
         return array('error' => 'File has an invalid extension, it should be one of ' . $these . '.');
     }
     $ext = $ext == '' ? $ext : '.' . $ext;
     if (!$replaceOldFile) {
         /// don't overwrite previous files that were uploaded
         while (file_exists($uploadDirectory . $filename . $ext)) {
             $filename .= rand(10, 99);
         }
     }
     $this->uploadName = $filename . $ext;
     if ($this->file->save($uploadDirectory . $filename . $ext)) {
         // If file pushed to temp directory, push it to package server
         $filename = $filename . $ext;
         $upload_tmp_dir = sys_get_temp_dir();
         $files = array();
         $file = $upload_tmp_dir . '/' . $random_dir . '/' . $filename;
         // Read and put content of $file to $filebinary
         $filebinary = fread(fopen($file, "r"), filesize($file));
         $files[] = array("filename" => $filename, "filebinary" => base64_encode($filebinary));
         $push_package_result = pushPackage($p_api_id, $random_dir, $files);
         // Delete package from PHP /tmp dir
         delete_directory($upload_tmp_dir . '/' . $random_dir);
         if (!isXMLRPCError() and $push_package_result) {
             return array('success' => true);
         } else {
             return array('error' => 'Could not save uploaded file.' . 'The upload was cancelled, or server error encountered');
         }
     } else {
         return array('error' => 'Could not save uploaded file.' . 'The upload was cancelled, or server error encountered');
     }
 }
Esempio n. 15
0
File: edit.php Progetto: psyray/mmc
function _displaySuccessMessage($success, $message)
{
    if (!isXMLRPCError() and $success) {
        new NotifyWidgetSuccess($message);
    } else {
        global $errorStatus;
        $errorStatus = 0;
    }
}
Esempio n. 16
0
/**
 * Function called for changing user attributes
 * @param $FH FormHandler of the page
 * @param $mode add or edit mode
 */
function _samba_changeUser($FH, $mode)
{
    global $error;
    global $result;
    # check users profiles setup
    $globalProfiles = xmlCall("samba.isProfiles");
    # Already existing SAMBA user
    if (hasSmbAttr($FH->getPostValue("uid"))) {
        # Remove atrributes
        if (!$FH->getPostValue("isSamba")) {
            rmSmbAttr($FH->getPostValue("uid"));
            $result .= _T("Samba attributes deleted.", "samba") . "<br />";
        } else {
            # Remove passwords from the $_POST array coming from the add/edit user page
            # because we don't want to send them again via RPC.
            $FH->delPostValue("pass");
            $FH->delPostValue("confpass");
            // Format samba attributes
            if ($FH->isUpdated("sambaPwdMustChange")) {
                if ($FH->getValue("sambaPwdMustChange") == "on") {
                    // force user to change password
                    $FH->setValue("sambaPwdMustChange", "0");
                    $FH->setValue("sambaPwdLastSet", "0");
                } else {
                    $FH->setValue("sambaPwdMustChange", "");
                    $FH->setValue("sambaPwdLastSet", (string) time());
                }
            }
            // account expiration
            if ($FH->isUpdated("sambaKickoffTime")) {
                $datetime = $FH->getValue("sambaKickoffTime");
                // 2010-09-23 18:32:00
                if (strlen($datetime) == 19) {
                    $timestamp = mktime(substr($datetime, -8, 2), substr($datetime, -5, 2), substr($datetime, -2, 2), substr($datetime, 5, 2), substr($datetime, 8, 2), substr($datetime, 0, 4));
                    $FH->setValue("sambaKickoffTime", "{$timestamp}");
                } else {
                    $FH->setValue("sambaKickoffTime", "");
                }
            }
            // Network profile path
            if ($FH->isUpdated("sambaProfilePath") && !$globalProfiles) {
                $FH->setValue("sambaProfilePath", $FH->getPostValue("sambaProfilePath"));
            }
            if (!$FH->getPostValue("hasProfile") && $FH->getPostValue("old_hasProfile") == "on") {
                $FH->setValue("sambaProfilePath", "");
            }
            // change attributes
            changeSmbAttr($FH->getPostValue("uid"), $FH->getValues());
            if (isEnabledUser($FH->getPostValue("uid"))) {
                if ($FH->getPostValue('isSmbDesactive')) {
                    smbDisableUser($FH->getPostValue("uid"));
                    $result .= _T("Samba account disabled.", "samba") . "<br />";
                }
            } else {
                if (!$FH->getPostValue('isSmbDesactive')) {
                    smbEnableUser($FH->getPostValue("uid"));
                    $result .= _T("Samba account enabled.", "samba") . "<br />";
                }
            }
            if (isLockedUser($FH->getPostValue("uid"))) {
                if (!$FH->getPostValue('isSmbLocked')) {
                    smbUnlockUser($FH->getPostValue("uid"));
                }
            } else {
                if ($FH->getPostValue('isSmbLocked')) {
                    smbLockUser($FH->getPostValue("uid"));
                }
            }
        }
    } else {
        //if not have smb attributes
        if ($FH->getPostValue("isSamba")) {
            # Add SAMBA attributes
            addSmbAttr($FH->getPostValue("uid"), $FH->getPostValue("pass"));
            if (!isXMLRPCError()) {
                // Format samba attributes
                if ($FH->getPostValue("sambaPwdMustChange") == "on") {
                    $FH->setPostValue("sambaPwdMustChange", "0");
                    $FH->setPostValue("sambaPwdLastSet", "0");
                } else {
                    $FH->setPostValue("sambaPwdMustChange", "");
                }
                // Account expiration
                if ($FH->isUpdated("sambaKickoffTime")) {
                    $datetime = $FH->getValue("sambaKickoffTime");
                    // 2010-09-23 18:32:00
                    if (strlen($datetime) == 19) {
                        $timestamp = mktime(substr($datetime, -8, 2), substr($datetime, -5, 2), substr($datetime, -2, 2), substr($datetime, 5, 2), substr($datetime, 8, 2), substr($datetime, 0, 4));
                        $FH->setPostValue("sambaKickoffTime", "{$timestamp}");
                    } else {
                        $FH->setPostValue("sambaKickoffTime", "");
                    }
                }
                // Network profile
                // Clear profile path if global profiles are on
                if (!$FH->getPostValue("hasProfile") == "on" || $globalProfiles) {
                    $FH->setPostValue("sambaProfilePath", "");
                }
                changeSmbAttr($FH->getPostValue("uid"), $FH->getPostValues());
                if (!isXMLRPCError()) {
                    $result .= _T("Samba attributes added.", "samba") . "<br />";
                } else {
                    $error .= _T("Failed to add Samba attributes.", "samba") . "<br />";
                }
            } else {
                // rollback operation
                global $errorStatus;
                $errorStatus = 0;
                rmSmbAttr($FH->getPostValue("uid"));
                $error .= _T("Failed to add Samba attributes.", "samba") . "<br />";
            }
        }
    }
    return 0;
}
Esempio n. 17
0
function create_group(&$error, $group)
{
    if ($group == "") {
        $error = "Groupe nul";
        return;
    }
    if (in_array($group, get_groups($error))) {
        $error = sprintf(_("Group %s already exist"), $group);
        return;
    }
    $ret = xmlCall("base.createGroup", $group);
    if (in_array("samba", $_SESSION["supportModList"])) {
        // FIXME: should be a choice made by the user
        // Samba plugin is enabled, so we make this group a Samba group,
        // but only if we are a PDC.
        $pdc = xmlCall("samba.isPdc", null);
        if ($pdc) {
            xmlCall("samba.makeSambaGroup", array($group));
        }
    }
    if (!isXMLRPCError()) {
        return sprintf(_("Group %s created"), $group);
    } else {
        return;
    }
}
Esempio n. 18
0
            header("Location: " . urlStrRedirect("mail/domains/index"));
            exit;
        }
    } else {
        if (isset($_POST["bedit"]) || isset($_POST["breset"])) {
            setVDomainDescription($domainname, $description);
            if (strlen($domainquota)) {
                setVDomainQuota($domainname, $domainquota);
            }
            $result = _T("The mail domain has been modified.", "mail") . "<br />";
            if (isset($_POST["breset"])) {
                resetUsersVDomainQuota($domainname);
                $result .= _T(" The quota of all users of this mail domain have been reset.") . "<br />";
            }
            // Display result message
            if ($result && !isXMLRPCError()) {
                new NotifyWidgetSuccess($result);
            }
        }
    }
}
$p = new PageGenerator($title);
$p->setSideMenu($sidemenu);
$p->display();
$f = new ValidatingForm();
$f->push(new Table());
if ($mode == "add") {
    $domainTpl = new DomainInputTpl("domainname");
} else {
    $domainTpl = new HiddenTpl("domainname");
}
Esempio n. 19
0
     $cbx = array($random_dir);
 } else {
     if ($_POST['package-method'] == "package") {
         $cbx = array();
         foreach ($_POST as $post => $v) {
             if (preg_match("/cbx_/", $post) > 0) {
                 $cbx[] = preg_replace("/cbx_/", "", $post);
             }
         }
         if (isset($_POST['rdo_files'])) {
             $cbx[] = $_POST['rdo_files'];
         }
     }
 }
 $ret = associatePackages($p_api_id, $pid, $cbx, $level);
 if (!isXMLRPCError() and is_array($ret)) {
     if ($ret[0]) {
         $explain = '';
         if (count($ret) > 1) {
             $explain = sprintf(" : <br/>%s", implode("<br/>", $ret[1]));
         }
         new NotifyWidgetSuccess(sprintf(_T("Files successfully associated with package <b>%s (%s)</b>%s", "pkgs"), $plabel, $pversion, $explain));
         header("Location: " . urlStrRedirect("pkgs/pkgs/index", array('location' => base64_encode($p_api_id))));
         exit;
     } else {
         $reason = '';
         if (count($ret) > 1) {
             $reason = sprintf(" : <br/>%s", $ret[1]);
         }
         new NotifyWidgetFailure(sprintf(_T("Failed to associate files%s", "pkgs"), $reason));
     }
Esempio n. 20
0
            if (isset($_POST["bassoc"])) {
                // If no error with sending package infos, push package previously uploaded
                $package_id = $ret[3]['id'];
                $upload_tmp_dir = sys_get_temp_dir();
                $file_list = get_directory_list($upload_tmp_dir . '/' . $random_dir);
                $files = array();
                foreach ($file_list as $filename) {
                    $file = $upload_tmp_dir . '/' . $random_dir . '/' . $filename;
                    // Read and put content of $file to $filebinary
                    $filebinary = fread(fopen($file, "r"), filesize($file));
                    $files[] = array("filename" => $filename, "filebinary" => base64_encode($filebinary));
                }
                $push_package_result = pushPackage($p_api_id, $random_dir, $files);
                // Delete package from PHP /tmp dir
                delete_directory($upload_tmp_dir . '/' . $random_dir);
                if (!isXMLRPCError() and $push_package_result) {
                    header("Location: " . urlStrRedirect("pkgs/pkgs/associate_files", array('p_api' => base64_encode($p_api_id), 'random_dir' => base64_encode($random_dir), 'pid' => base64_encode($ret[3]['id']), 'plabel' => base64_encode($ret[3]['label']), 'pversion' => base64_encode($ret[3]['version']), 'mode' => $_POST['mode'])));
                    exit;
                }
            }
        } else {
            new NotifyWidgetFailure($ret[1]);
        }
    } else {
        new NotifyWidgetFailure(_T("Package failed to save", "pkgs"));
    }
}
$p_api_id = base64_decode($_GET['p_api']);
//title differ with action
if ($_GET["action"] == "add") {
    $title = _T("Add a package", "pkgs");
Esempio n. 21
0
 function modify()
 {
     if ($this->modifiable) {
         $user = $this->user;
         $login = $user["login"];
         // the following are not permitted to be changed yet
         unset($user["login"], $user["firstname"], $user["surname"], $user["homedir"], $user["createhomedir"], $user["primaryGroup"]);
         if (key_exists("password", $user)) {
             $ret = callPluginFunction("changeUserPasswd", array(array($login, prepare_string($user["password"]))));
             if (isXMLRPCError()) {
                 foreach ($ret as $info) {
                     $this->result .= _("Password not updated") . "<br/>";
                 }
                 # set errorStatus to 0 in order to make next xmlcalls
                 global $errorStatus;
                 $errorStatus = 0;
             } else {
                 //update result display
                 $this->result .= _("Password updated.") . "<br />";
             }
             unset($user["password"]);
         }
         if (count($user) > 0) {
             foreach ($user as $attribute => $value) {
                 if ($this->checkAttribute($attribute)) {
                     changeUserAttributes($login, $attribute, $value);
                 } else {
                     unset($user[$attribute]);
                 }
             }
             $this->result .= count($user) . _T("Attribute(s) modified", "bulkimport");
         }
     }
 }
Esempio n. 22
0
    }
} else {
    if (isset($_POST["bmodify"])) {
        $groupname = $_POST["groupname"];
        $groupdesc = stripslashes($_POST["groupdesc"]);
        change_group_desc($groupname, $groupdesc);
        $error = false;
        $ret = callPluginFunction("changeGroup", array($_POST));
        var_dump($err);
        foreach ($ret as $plugin => $result) {
            if ($result === false) {
                $error = true;
                break;
            }
        }
        if (!$error && !isXMLRPCError()) {
            new NotifyWidgetSuccess(sprintf(_("Group %s successfully modified"), $groupname));
        }
        redirectTo(urlStrRedirect("base/groups/edit", array("group" => $groupname)));
    }
}
if ($_GET["action"] == "add") {
    $title = _("Add group");
    $groupname = "";
    $groupdesc = "";
    $detailArr = array();
} else {
    $title = _("Edit group");
    $groupname = $_GET["group"];
    $detailArr = get_detailed_group($groupname);
    if (isset($detailArr["description"])) {
Esempio n. 23
0
require_once 'modules/imaging/includes/includes.php';
require_once 'modules/imaging/includes/xmlrpc.inc.php';
require_once 'modules/imaging/includes/web_def.inc.php';
$location = getCurrentLocation();
if (isset($_POST["bconfirm"])) {
    $params = getParams();
    $item_uuid = $_POST['itemid'];
    $label = urldecode($_POST['itemlabel']);
    $ret = xmlrpc_delServiceToLocation($item_uuid, $location, $params);
    // goto images list
    if ($ret[0] and !isXMLRPCError()) {
        $str = sprintf(_T("Service <strong>%s</strong> removed from default boot menu", "imaging"), $label);
        new NotifyWidgetSuccess($str);
        // Synchronize boot menu
        $ret = xmlrpc_synchroLocation($location);
        if (isXMLRPCError()) {
            new NotifyWidgetFailure(sprintf(_T("Boot menu generation failed for package server: %s", "imaging"), implode(', ', $ret[1])));
        }
        header("Location: " . urlStrRedirect("imaging/manage/service", $params));
        exit;
    } elseif ($ret[0]) {
        header("Location: " . urlStrRedirect("imaging/manage/service", $params));
        exit;
    } else {
        new NotifyWidgetFailure($ret[1]);
    }
}
$params = getParams();
$item_uuid = $_GET['itemid'];
$label = urldecode($_GET['itemlabel']);
$f = new PopupForm(sprintf(_T("Remove the boot service <b>%s</b> from the default boot menu", "imaging"), $label));
Esempio n. 24
0
/**
 * Call the given function in all available plugins
 * @param $function The function name to execute
 * @param $paramArr The array of parameters for the function
 * @param $reverse  If true, the plugins are considered in reverse priority
 *
 * This function will try to call all _$plugins_$functionName function
 * The plugins are looked up according to their priority, and in reverse order if $reverse = True
 */
function callPluginFunction($function, $paramArr = null, $reverse = False)
{
    /* Fetch and order available plugins for the current logged user */
    $list = $_SESSION["modulesList"];
    if ($reverse) {
        $list = array_reverse($list);
    }
    /*
      If the user try to change his/her password, we do it for each available
      module, and we bypass all ACL check
    */
    if ($function == "changeUserPasswd" || $function == "baseEdit") {
        /* Change password for all modules, even those where the user has no right. */
        $list = $_SESSION["supportModList"];
        global $conf;
        foreach ($list as $module) {
            if (!function_exists("_" . $module . "_" . "changeUserPasswd")) {
                includePublicFunc(array($conf["global"]["rootfsmodules"] . "/{$module}"));
            }
        }
    }
    $result = array();
    foreach ($list as $item) {
        $functionName = "_" . $item . "_" . $function;
        if (function_exists($functionName)) {
            $result[$item] = call_user_func_array($functionName, $paramArr);
            if (isXMLRPCError()) {
                /* Break the loop if there is an error */
                global $errorDesc;
                $result[$item] = $errorDesc;
                break;
            }
        }
    }
    return $result;
}
Esempio n. 25
0
                $action = $service . "/DNAT";
                $proto = "";
                $port = "";
            }
            $source = $_POST['source'];
            $destination = $_POST['destination'];
            if ($src_ip) {
                $source = $source . ':' . $src_ip;
            }
            if ($dest_port) {
                $destination = $destination . ":" . $dest_ip . ":" . $dest_port;
            } else {
                $destination = $destination . ":" . $dest_ip;
            }
            addRule($action, $source, $destination, $proto, $port);
            if (!isXMLRPCError()) {
                $n = new NotifyWidgetSuccess(_T("Rule added."));
                handleServicesModule($n, array("shorewall" => _T("Firewall")));
                header("Location: " . urlStrRedirect("shorewall/shorewall/" . $page));
                exit;
            } else {
                new NotifyWidgetFailure(_T("Failed to add the rule."));
            }
        }
    } else {
        new NotifyWidgetFailure(_T("Service must be specified."));
    }
}
if (isset($_POST['brestart'])) {
    redirectTo(urlStrRedirect("shorewall/shorewall/restart_service", array("page" => $page)));
}
Esempio n. 26
0
File: edit.php Progetto: psyray/mmc
/* Displaying the page title */
$page = new PageGenerator(_T("Edit computer", "samba4"));
$sidemenu->forceActiveItem("index");
$page->setSideMenu($sidemenu);
$page->display();
/* Getting the computer name from the GET request */
if (!isset($_GET["machine"])) {
    $name = False;
} else {
    $name = $_GET["machine"];
}
/* If the edit form has been submited */
if (isset($_POST["bmachineedit"])) {
    list($name, $description, $enabled) = _parseEditMachineForm();
    $editSuccess = editMachine($name, array($name, $description, $enabled));
    if (!isXMLRPCError() and $editSuccess) {
        new NotifyWidgetSuccess(_T("Computer successfully modified."));
        header("Location: " . urlStrRedirect("samba4/machines/index"));
        exit;
    }
}
/* Showing the edit machine details form */
if ($name) {
    $machineDetails = getMachine($name);
    $form = new ValidatingForm();
    $form->push(new Table());
    $tr = new TrFormElement(_T("Computer name", "samba4"), new HiddenTpl("name"));
    $form->add($tr, array("value" => $machineDetails["name"], "required" => True));
    $tr = new TrFormElement(_T("Computer description", "samba4"), new InputTpl("description"));
    $form->add($tr, array("value" => $machineDetails["description"], "required" => True));
    $tr = new TrFormElement(_T("Computer account is enabled", "samba4"), new CheckboxTpl("enabled"), array("tooltip" => _T("If checked, the computer account is enabled", "samba4")));