Beispiel #1
0
function doPost()
{
    global $error, $conf_centreon;
    $db = dbConnect($conf_centreon['hostCentreon'], $conf_centreon['user'], $conf_centreon['password'], $conf_centreon['db'], true);
    if (isset($_POST["net"])) {
        $nbPlage = mysql_query("SELECT count(*) FROM mod_discovery_rangeip WHERE id!=0;");
        $nbPlageData = mysql_fetch_array($nbPlage);
        if ($nbPlageData[0] <= 15) {
            $tmp = explode(" ", $_POST["net"]);
            if (isset($tmp[1])) {
                if (validateIpAddress($tmp[0]) && validateMask($tmp[1])) {
                    $netAddr = ip2Subnet($tmp[0], $tmp[1]);
                    if (mysql_num_rows(mysql_query("SELECT * FROM mod_discovery_rangeip WHERE plage='" . $netAddr . "';")) == 0) {
                        $poller = findPoller($netAddr, maskToCidr($tmp[1]));
                        if (!mysql_query("INSERT INTO mod_discovery_rangeip (plage,masque,cidr,nagios_server_id) VALUES('" . $netAddr . "','" . $tmp[1] . "','" . maskToCidr($tmp[1]) . "','" . $poller["poller_id"] . "');")) {
                            echo mysql_error();
                        }
                    } else {
                        $error = 2;
                    }
                } else {
                    $error = 1;
                }
            } else {
                $tmp = explode("/", $_POST["net"]);
                if ($tmp[1]) {
                    if (validateIpAddress($tmp[0]) && validateCidr($tmp[1])) {
                        $netAddr = ip2Subnet($tmp[0], cidrToMask($tmp[1]));
                        if (mysql_num_rows(mysql_query("SELECT * FROM mod_discovery_rangeip WHERE plage='" . $netAddr . "';")) == 0) {
                            $poller = findPoller($netAddr, $tmp[1]);
                            if (!mysql_query("INSERT INTO mod_discovery_rangeip (plage,masque,cidr,nagios_server_id) VALUES('" . $netAddr . "','" . cidrToMask($tmp[1]) . "','" . $tmp[1] . "','" . $poller["poller_id"] . "');")) {
                                echo mysql_error();
                            }
                        } else {
                            $error = 2;
                        }
                    } else {
                        $error = 1;
                    }
                } else {
                    $error = 1;
                }
            }
        } else {
            $error = 3;
        }
        unset($_POST);
    }
    if (isset($_POST["ClearAll"])) {
        if ($_POST["ClearAll"] == " Clear All ") {
            clearArray();
        }
    }
    if (isset($_GET["id"])) {
        clearRow($_GET["id"]);
        unset($_GET);
    }
    doInput($error);
    doFormTab($error);
    dbClose($db);
}
Beispiel #2
0
/**
 * callHooker()
 * 
 * Calling the classes and the methods.
 * 
 * @return void
 */
function callHooker()
{
    global $url, $default, $view, $parameters, $mainController;
    //celaring all variables in the $_POST and $_GET avoiding sql or html code injection
    $_POST = clearArray($_POST);
    $_GET = clearArray($_GET);
    $parameters = array();
    if (!isset($url)) {
        $controller = $default['controller'];
        $action = $default['action'];
    } else {
        $urlArray = explode('/', $url);
        $urlArray = clearArray($urlArray);
        $controller = $urlArray[0];
        array_shift($urlArray);
        if (isset($urlArray[0])) {
            $action = $urlArray[0];
            array_shift($urlArray);
        } else {
            $action = 'index';
        }
        $parameters = $urlArray;
    }
    $controllerName = ucfirst($controller) . 'Controller';
    $mainController = $controller;
    /** If the class doesn't exist call the default controller and action **/
    if (!class_exists($controllerName)) {
        /** MAKE A LOG HERE **/
        $controller = $default['controller'];
        $action = $default['action'];
        $controllerName = ucfirst($controller) . 'Controller';
    }
    if (!(int) method_exists($controllerName, $action)) {
        /** MAKE A LOG HERE **/
        $controller = ucfirst($default['controller']);
        $action = $default['action'];
        $controllerName = $controller . 'Controller';
    }
    /** Calling the classes and the actions with the right parameter **/
    //the View
    $view = new View($controller, $action);
    //beforeClass
    $newAction = 'before' . $controller;
    if ((int) method_exists($controllerName, $newAction)) {
        $dispatcher = new $controllerName($controller, $newAction);
        call_user_func(array($dispatcher, $newAction));
    }
    //beforeAction
    $newAction = 'before' . $action;
    if ((int) method_exists($controllerName, $newAction)) {
        $dispatcher = new $controllerName($controller, $newAction);
        call_user_func(array($dispatcher, $newAction));
    }
    //calling the Action
    $dispatcher = new $controllerName($controller, $action);
    call_user_func_array(array($dispatcher, $action), $parameters);
    //afterAction
    $newAction = 'after' . $action;
    if ((int) method_exists($controllerName, $newAction)) {
        $dispatcher = new $controllerName($controller, $newAction);
        call_user_func(array($dispatcher, $newAction));
    }
    //afterClass
    $newAction = 'after' . $controller;
    if ((int) method_exists($controllerName, $newAction)) {
        $dispatcher = new $controllerName($controller, $newAction);
        call_user_func(array($dispatcher, $newAction));
    }
    $view->callingTemplate();
    return 1;
}
Beispiel #3
0
function clearArray($a) 
{
  $ar = array();
  $qcb = get_magic_quotes_gpc() ? "stripslashes" : "nop";
  foreach ($a as $k=>$v)
    if (is_array($v))
      $ar[$k] = clearArray($v);
    else
      $ar[$k] = $qcb($v);
  return $ar;
}