Ejemplo n.º 1
0
function _moduleContent(&$smarty, $module_name)
{
    //global variables
    global $arrConf;
    global $arrConfModule;
    $arrConf = array_merge($arrConf, $arrConfModule);
    //folder path for custom templates
    $local_templates_dir = getWebDirModule($module_name);
    $pNet = new paloNetwork();
    $arrEths = $pNet->obtener_interfases_red_fisicas();
    //actions
    $accion = getAction();
    switch ($accion) {
        case "edit_network":
            $content = editNetwork($smarty, $module_name, $local_templates_dir, $pNet);
            break;
        case "edit_interface":
            $content = editInterface($smarty, $module_name, $local_templates_dir, $pNet, $arrEths);
            break;
        case "save_network":
            $content = saveNetwork($smarty, $module_name, $local_templates_dir, $pNet);
            break;
        case "save_interface":
            $content = saveInterface($smarty, $module_name, $local_templates_dir, $pNet);
            break;
        default:
            $content = formNetwork($smarty, $module_name, $local_templates_dir, $pNet, $arrEths);
            break;
    }
    return $content;
}
Ejemplo n.º 2
0
 function PaloSantoFileEndPoint($dir, $endpoint_mask = NULL)
 {
     $this->directory = $dir;
     $this->PathDPMA = "/etc/asterisk/res_digium_phone.conf";
     if (is_null($endpoint_mask)) {
         $this->ipAdressServer = $_SERVER['SERVER_ADDR'];
     } else {
         $pNetwork = new paloNetwork();
         $pInterfaces = $pNetwork->obtener_interfases_red();
         $endpoint_mask = explode("/", $endpoint_mask);
         $endpoint_network = $pNetwork->getNetAdress($endpoint_mask[0], $endpoint_mask[1]);
         foreach ($pInterfaces as $interface) {
             $mask = $pNetwork->maskToDecimalFormat($interface["Mask"]);
             $network = $pNetwork->getNetAdress($interface["Inet Addr"], $mask);
             if ($network == $endpoint_network) {
                 $this->ipAdressServer = $interface["Inet Addr"];
                 break;
             }
         }
         if (!isset($this->ipAdressServer)) {
             $this->ipAdressServer = $_SERVER['SERVER_ADDR'];
         }
     }
 }
Ejemplo n.º 3
0
 /**
  * Function that returns the name of all the network interfaces available in the system
  *
  * @return array      Array with the name of the interfaces
  */
 function obtener_nombres_interfases_red()
 {
     $pNet = new paloNetwork();
     //Se buscan las descripciones en la base de datos
     $arr_datos = array();
     $arr_descrip = array();
     $sQuery = "SELECT * FROM interfase";
     $result = $this->_DB->fetchTable($sQuery, true);
     if (is_array($result) && count($result) > 0) {
         foreach ($result as $fila) {
             $arr_descrip[$fila['dev']] = array("nombre" => $fila['nombre'], "descripcion" => $fila['descripcion']);
         }
     }
     $arr_interfases = $pNet->obtener_interfases_red();
     foreach ($arr_interfases as $dev => $datos) {
         if (array_key_exists($dev, $arr_descrip)) {
             //$arr_datos[$dev]=$arr_descrip[$dev]['nombre']." - ".$datos['Name'];
             $arr_datos[$dev] = $arr_descrip[$dev]['nombre'];
         } else {
             $arr_datos[$dev] = $datos['Name'];
         }
     }
     return $arr_datos;
 }
Ejemplo n.º 4
0
function saveRules($smarty, $module_name, $local_templates_dir, &$pDB, $arrConf)
{
    $arrValues = array();
    $str_error = "";
    $arrFormNew = createFieldForm($pDB);
    $oForm = new paloForm($smarty, $arrFormNew);
    $id = getParameter("id");
    $arrValues['id'] = $id;
    if ($id == "") {
        $state = "new";
    } else {
        $state = "edit";
    }
    //************************************************************************************************************
    //** TRAFFIC **
    //************************************************************************************************************
    $arrValues['traffic'] = getParameter("id_traffic");
    if ($arrValues['traffic'] == "INPUT") {
        $arrValues['interface_in'] = getParameter("interface_in");
        if (strlen($arrValues['interface_in']) == 0) {
            $str_error .= strlen($str_error) == 0 ? "interface_in" : ", interface_in";
        }
        $arrValues['interface_out'] = null;
    } else {
        if ($arrValues['traffic'] == "OUTPUT") {
            $arrValues['interface_out'] = getParameter("interface_out");
            if (strlen($arrValues['interface_out']) == 0) {
                $str_error .= strlen($str_error) == 0 ? "interface_out" : ", interface_out";
            }
            $arrValues['interface_in'] = null;
        } else {
            if ($arrValues['traffic'] == "FORWARD") {
                $arrValues['interface_in'] = getParameter("interface_in");
                if (strlen($arrValues['interface_in']) == 0) {
                    $str_error .= strlen($str_error) == 0 ? "interface_in" : ", interface_in";
                }
                $arrValues['interface_out'] = getParameter("interface_out");
                if (strlen($arrValues['interface_out']) == 0) {
                    $str_error .= strlen($str_error) == 0 ? "interface_out" : ", interface_out";
                }
            }
        }
    }
    //************************************************************************************************************
    //** SOURCE **
    //************************************************************************************************************
    $arrValues['ip_source'] = getParameter("ip_source");
    $arrValues['mask_source'] = getParameter("mask_source");
    $arrValues['ip_destin'] = getParameter("ip_destin");
    $arrValues['mask_destin'] = getParameter("mask_destin");
    //************************************************************************************************************
    //** PROTOCOL **
    //************************************************************************************************************
    $arrValues['protocol'] = getParameter("id_protocol");
    if ($arrValues['protocol'] == 'TCP' || $arrValues['protocol'] == 'UDP') {
        $arrValues['port_in'] = getParameter("port_in");
        if (strlen($arrValues['port_in']) == 0) {
            $str_error .= strlen($str_error) == 0 ? "port_in" : ", port_in";
        }
        $arrValues['port_out'] = getParameter("port_out");
        if (strlen($arrValues['port_out']) == 0) {
            $str_error .= strlen($str_error) == 0 ? "port_out" : ", port_out";
        }
        $arrValues['type_icmp'] = null;
        $arrValues['id_ip'] = null;
        $arrValues['state'] = "";
    } else {
        if ($arrValues['protocol'] == 'ICMP') {
            $arrValues['port_in'] = null;
            $arrValues['port_out'] = null;
            $arrValues['state'] = "";
            $arrValues['type_icmp'] = getParameter("type_icmp");
            if (strlen($arrValues['type_icmp']) == 0) {
                $str_error .= strlen($str_error) == 0 ? "type" : ", type";
            }
            $arrValues['id_ip'] = null;
        } else {
            if ($arrValues['protocol'] == 'IP') {
                $arrValues['port_in'] = null;
                $arrValues['port_out'] = null;
                $arrValues['type_icmp'] = null;
                $arrValues['state'] = "";
                $arrValues['id_ip'] = getParameter("id_ip");
                if (strlen($arrValues['id_ip']) == 0) {
                    $str_error .= strlen($str_error) == 0 ? "id" : ", id";
                }
            } else {
                if ($arrValues['protocol'] == 'STATE') {
                    $arrValues['port_in'] = null;
                    $arrValues['port_out'] = null;
                    $arrValues['type_icmp'] = null;
                    $arrValues['id_ip'] = null;
                    $established = getParameter("established");
                    $related = getParameter("related");
                    if ($established == "on") {
                        $arrValues['state'] = "Established";
                        if ($related == "on") {
                            $arrValues['state'] .= ",Related";
                        }
                    } else {
                        if ($related == "on") {
                            $arrValues['state'] = "Related";
                        } else {
                            $str_error .= strlen($str_error) == 0 ? _tr("You have to select at least one state") : ", " . _tr("You have to select at least one state");
                        }
                    }
                } else {
                    $arrValues['port_in'] = "";
                    $arrValues['port_out'] = "";
                    $arrValues['type_icmp'] = "";
                    $arrValues['id_ip'] = "";
                    $arrValues['state'] = "";
                }
            }
        }
    }
    //************************************************************************************************************
    //** TARGET **
    //************************************************************************************************************
    $arrValues['target'] = getParameter("target");
    if (strlen($arrValues['target']) == 0) {
        $str_error .= strlen($str_error) == 0 ? "target" : ", target";
    }
    $arrValues['orden'] = getParameter("orden");
    //**********************
    //MENSSAGE ERROR
    //**********************
    if (strlen($str_error) != 0) {
        $smarty->assign("mb_title", "ERROR");
        $smarty->assign("mb_message", $str_error);
        return newRules($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $arrValues, $state);
    }
    if (!$oForm->validateForm($_POST)) {
        // Falla la validación básica del formulario
        $strErrorMsg = "<b>" . _tr('The following fields contain errors') . ":</b><br/>";
        $arrErrores = $oForm->arrErroresValidacion;
        if (is_array($arrErrores) && count($arrErrores) > 0) {
            foreach ($arrErrores as $k => $v) {
                $strErrorMsg .= "{$k}: [{$v['mensaje']}] <br /> ";
            }
        }
        $smarty->assign("mb_title", _tr("Validation Error"));
        $smarty->assign("mb_message", $strErrorMsg);
        return newRules($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $arrValues, $state);
    } else {
        if ($arrValues['mask_source'] > 32 || $arrValues['mask_destin'] > 32) {
            $smarty->assign("mb_title", _tr("Validation Error"));
            $smarty->assign("mb_message", _tr("The bit masks must be values less than 33"));
            return newRules($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $arrValues, $state);
        } else {
            if ($arrValues['ip_source'] != "0.0.0.0" && $arrValues['ip_source'] != "" && $arrValues['mask_source'] == "0" || $arrValues['ip_destin'] != "0.0.0.0" && $arrValues['ip_destin'] != "" && $arrValues['mask_destin'] == "0") {
                $smarty->assign("mb_title", _tr("Validation Error"));
                $smarty->assign("mb_message", _tr("Wrong Mask"));
                return newRules($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $arrValues, $state);
            }
        }
    }
    $arrValues['ip_source'] = $arrValues['ip_source'] == "" ? "0.0.0.0" : $arrValues['ip_source'];
    $arrValues['ip_destin'] = $arrValues['ip_destin'] == "" ? "0.0.0.0" : $arrValues['ip_destin'];
    $ipOrigen = explode(".", $arrValues['ip_source']);
    $ipDestino = explode(".", $arrValues['ip_destin']);
    if ($ipOrigen[0] > 255 || $ipOrigen[1] > 255 || $ipOrigen[2] > 255 || $ipOrigen[3] > 255 || $ipDestino[0] > 255 || $ipDestino[1] > 255 || $ipDestino[2] > 255 || $ipDestino[3] > 255) {
        $smarty->assign("mb_title", _tr("Validation Error"));
        $smarty->assign("mb_message", _tr("Wrong value for ip"));
        return newRules($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $arrValues, $state);
    }
    $arrValues['mask_source'] = $arrValues['ip_source'] == "0.0.0.0" ? "0" : $arrValues['mask_source'];
    $arrValues['mask_destin'] = $arrValues['ip_destin'] == "0.0.0.0" ? "0" : $arrValues['mask_destin'];
    $pNet = new paloNetwork();
    $oPalo = new paloSantoRules($pDB);
    if ($arrValues['ip_source'] != "0.0.0.0" && $arrValues['mask_source'] != "" && $arrValues['ip_source'] != "") {
        $arrValues['ip_source'] = $pNet->getNetAdress($arrValues['ip_source'], $arrValues['mask_source']);
    }
    if ($arrValues['ip_destin'] != "0.0.0.0" && $arrValues['mask_destin'] != "" && $arrValues['ip_destin'] != "") {
        $arrValues['ip_destin'] = $pNet->getNetAdress($arrValues['ip_destin'], $arrValues['mask_destin']);
    }
    if ($id == "") {
        if ($oPalo->saveRule($arrValues) == true) {
            $smarty->assign("mb_title", "MESSAGE");
            $smarty->assign("mb_message", _tr("Successful Save"));
        } else {
            $smarty->assign("mb_title", "ERROR");
            $smarty->assign("mb_message", $oPalo->errMsg);
            return newRules($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $arrValues, $state);
        }
    } else {
        if ($oPalo->updateRule($arrValues, $id) == true) {
            $smarty->assign("mb_title", "MESSAGE");
            $smarty->assign("mb_message", _tr("Successful Update"));
        } else {
            $smarty->assign("mb_title", "ERROR");
            $smarty->assign("mb_message", $oPalo->errMsg);
            return newRules($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $arrValues, $state);
        }
    }
    return reportRules($smarty, $module_name, $local_templates_dir, $pDB, $arrConf);
}
Ejemplo n.º 5
0
function serviceUpdateDHCP($smarty, $module_name, $local_templates_dir, &$oForm)
{
    $in_ip_ini_1 = trim($_POST['in_ip_ini_1']);
    $in_ip_ini_2 = trim($_POST['in_ip_ini_2']);
    $in_ip_ini_3 = trim($_POST['in_ip_ini_3']);
    $in_ip_ini_4 = trim($_POST['in_ip_ini_4']);
    $ip_ini = "{$in_ip_ini_1}.{$in_ip_ini_2}.{$in_ip_ini_3}.{$in_ip_ini_4}";
    $in_ip_fin_1 = trim($_POST['in_ip_fin_1']);
    $in_ip_fin_2 = trim($_POST['in_ip_fin_2']);
    $in_ip_fin_3 = trim($_POST['in_ip_fin_3']);
    $in_ip_fin_4 = trim($_POST['in_ip_fin_4']);
    $ip_fin = "{$in_ip_fin_1}.{$in_ip_fin_2}.{$in_ip_fin_3}.{$in_ip_fin_4}";
    $in_dns1_1 = trim($_POST['in_dns1_1']);
    $in_dns1_2 = trim($_POST['in_dns1_2']);
    $in_dns1_3 = trim($_POST['in_dns1_3']);
    $in_dns1_4 = trim($_POST['in_dns1_4']);
    $ip_dns1 = "{$in_dns1_1}.{$in_dns1_2}.{$in_dns1_3}.{$in_dns1_4}";
    $in_dns2_1 = trim($_POST['in_dns2_1']);
    $in_dns2_2 = trim($_POST['in_dns2_2']);
    $in_dns2_3 = trim($_POST['in_dns2_3']);
    $in_dns2_4 = trim($_POST['in_dns2_4']);
    $ip_dns2 = "{$in_dns2_1}.{$in_dns2_2}.{$in_dns2_3}.{$in_dns2_4}";
    $in_wins_1 = trim($_POST['in_wins_1']);
    $in_wins_2 = trim($_POST['in_wins_2']);
    $in_wins_3 = trim($_POST['in_wins_3']);
    $in_wins_4 = trim($_POST['in_wins_4']);
    $ip_wins = "{$in_wins_1}.{$in_wins_2}.{$in_wins_3}.{$in_wins_4}";
    $in_gw_1 = trim($_POST['in_gw_1']);
    $in_gw_2 = trim($_POST['in_gw_2']);
    $in_gw_3 = trim($_POST['in_gw_3']);
    $in_gw_4 = trim($_POST['in_gw_4']);
    $ip_gw = "{$in_gw_1}.{$in_gw_2}.{$in_gw_3}.{$in_gw_4}";
    /*$in_gw_nm_1 = trim($_POST['in_gwm_1']); $in_gw_nm_2 = trim($_POST['in_gwm_2']);
      $in_gw_nm_3 = trim($_POST['in_gwm_3']); $in_gw_nm_4 = trim($_POST['in_gwm_4']);
      $ip_gw_nm   = "$in_gw_nm_1.$in_gw_nm_2.$in_gw_nm_3.$in_gw_nm_4";*/
    $ip_gw_nm = "";
    $in_lease_time = trim($_POST['in_lease_time']);
    // Rango de IPs
    $val = new PaloValidar();
    $val->clear();
    $continuar = $val->validar(_tr("Start range of IPs"), $ip_ini, "ip") && $val->validar(_tr("End range of IPs"), $ip_fin, "ip");
    //si las IPs son válidas continuo validando si concuerdan con alguna interfaz
    //obtener las interfaces del sistema y verificar que el rango de ips pertenecen a alguna de las interfases
    $paloNet = new paloNetwork();
    $paloDHCP = new PaloSantoDHCP();
    $interfazEncontrada = FALSE;
    $configuracion_de_red_actual = array();
    if ($continuar) {
        $interfases = $paloNet->obtener_interfases_red();
        $valorIP = "";
        $valorMask = "";
        $IpSubred = "";
        foreach ($interfases as $dev => $datos) {
            if ($dev != "lo" && !$interfazEncontrada) {
                $valorIP = $datos["Inet Addr"];
                $valorMask = $datos["Mask"];
                if (isset($val->arrErrores[_tr("Start range of IPs")]['mensaje'])) {
                    unset($val->arrErrores[_tr("Start range of IPs")]);
                }
                if (isset($val->arrErrores[_tr("End range of IPs")]['mensaje'])) {
                    unset($val->arrErrores[_tr("End range of IPs")]);
                }
                $IPSubnet = $paloDHCP->calcularIpSubred($valorIP, $valorMask);
                //verificar si la IP inicial pertenece a esa red
                //si no pertenece se guarda mensaje de error, sino se verifica la Ip final
                $IpSubredIni = $paloDHCP->calcularIpSubred($ip_ini, $valorMask);
                if ($IpSubredIni != $IPSubnet) {
                    $val->arrErrores[_tr("Start range of IPs")]['mensaje'] = _tr("The start IP is outside the LAN network");
                } else {
                    $IpSubredFin = $paloDHCP->calcularIpSubred($ip_fin, $valorMask);
                    if ($IpSubredFin != $IPSubnet) {
                        $val->arrErrores[_tr("End range of IPs")]['mensaje'] = _tr("The final IP is outside the LAN network");
                    } else {
                        //encontro una interfaz, esta se adopta
                        $configuracion_de_red_actual["lan_mask"] = $valorMask;
                        $configuracion_de_red_actual["lan_ip"] = $valorIP;
                        $interfazEncontrada = TRUE;
                        break;
                    }
                }
            }
        }
    }
    if (!$interfazEncontrada) {
        //el rango de Ips proporcionado no pertenece a ninguna de las interfases
        $val->arrErrores[_tr("DHCP Server")]['mensaje'] = _tr("IP Range is invalid for available devices");
    }
    if ($ip_dns1 != "...") {
        $val->validar("DNS 1", $ip_dns1, "ip");
    }
    if ($ip_dns2 != "...") {
        $val->validar("DNS 2", $ip_dns2, "ip");
    }
    if ($ip_wins != "...") {
        $val->validar("WINS", $ip_wins, "ip");
    }
    if ($ip_gw != "...") {
        if ($val->validar("Gateway", $ip_gw, "ip")) {
            if ($interfazEncontrada) {
                $IPSubnet = $paloDHCP->calcularIpSubred($configuracion_de_red_actual["lan_ip"], $configuracion_de_red_actual["lan_mask"]);
                $IpSubredGw = $paloDHCP->calcularIpSubred($ip_gw, $configuracion_de_red_actual["lan_mask"]);
                if ($IpSubredGw != $IPSubnet) {
                    $val->arrErrores['Gateway']['mensaje'] = _tr("Gateway is outside the LAN network");
                }
            }
        }
    }
    $val->validar(_tr('Time of client refreshment'), $in_lease_time, "numeric");
    if ($in_lease_time > 50000 or $in_lease_time < 1) {
        $val->arrErrores[_tr('Time of client refreshment')]['mensaje'] = _tr("Value outside the range (1-50000)");
    }
    //Veo si hubieron errores
    $msgErrorVal = "";
    $huboError = false;
    if ($val->existenErroresPrevios() || !$interfazEncontrada) {
        foreach ($val->arrErrores as $nombreVar => $arrVar) {
            $msgErrorVal .= "<b>" . $nombreVar . "</b>: " . $arrVar['mensaje'] . "<br>";
        }
        $smarty->assign("mb_title", _tr("The following fields contain errors"));
        $smarty->assign("mb_message", $msgErrorVal);
        $huboError = true;
    } else {
        // Pase la validacion, empiezo a generar la data que constituira el archivo de configuracion nuevo
        if (!$paloDHCP->updateFileConfDHCP($ip_gw, $ip_gw_nm, $ip_wins, $ip_dns1, $ip_dns2, $IPSubnet, $configuracion_de_red_actual, $ip_ini, $ip_fin, $in_lease_time)) {
            $smarty->assign("mb_title", _tr("Update Error") . ":");
            $smarty->assign("mb_message", $paloDHCP->errMsg);
            $huboError = true;
        }
    }
    if ($huboError) {
        $statusDHCP = $paloDHCP->getStatusServiceDHCP();
        if ($statusDHCP == "active") {
            $smarty->assign("DHCP_STATUS", "<font color='#00AA00'>" . _tr('Active') . "</font>");
            $smarty->assign("SERVICE_STARING", true);
        } else {
            if ($statusDHCP == "desactive") {
                $smarty->assign("DHCP_STATUS", "<font color='#FF0000'>" . _tr('Inactive') . "</font>");
                $smarty->assign("SERVICE_STARING", false);
            }
        }
        return $oForm->fetchForm("{$local_templates_dir}/dhcp.tpl", _tr("DHCP Configuration"), $_POST);
    }
    header("Location: ?menu={$module_name}");
}
Ejemplo n.º 6
0
function network()
{
    /* OJO: paloNetwork::getNetAdress() ha sido reescrito y es ahora una función
     * estática. Si PHP se queja de que la función no puede llamarse en contexto
     * estático, NO PARCHE AQUí. En su lugar, actualice a 
     * elastix-system-2.3.0-10 o superior. El spec de elastix-pbx ya tiene este
     * requerimiento mínimo. */
    $ip = $_SERVER['SERVER_ADDR'];
    $total = subMask($ip);
    return paloNetwork::getNetAdress($ip, $total) . "/" . $total;
}
Ejemplo n.º 7
0
function _moduleContent(&$smarty, $module_name)
{
    include_once "libs/paloSantoForm.class.php";
    include_once "libs/paloSantoNetwork.class.php";
    include_once "libs/paloSantoGrid.class.php";
    include_once "modules/{$module_name}/configs/default.conf.php";
    $lang = get_language();
    $base_dir = dirname($_SERVER['SCRIPT_FILENAME']);
    $lang_file = "modules/{$module_name}/lang/{$lang}.lang";
    if (file_exists("{$base_dir}/{$lang_file}")) {
        include_once "{$lang_file}";
    } else {
        include_once "modules/{$module_name}/lang/en.lang";
    }
    //global variables
    global $arrConf;
    global $arrConfModule;
    global $arrLang;
    global $arrLangModule;
    $arrConf = array_merge($arrConf, $arrConfModule);
    $arrLang = array_merge($arrLang, $arrLangModule);
    //folder path for custom templates
    $base_dir = dirname($_SERVER['SCRIPT_FILENAME']);
    $templates_dir = isset($arrConf['templates_dir']) ? $arrConf['templates_dir'] : 'themes';
    $local_templates_dir = "{$base_dir}/modules/{$module_name}/" . $templates_dir . '/' . $arrConf['theme'];
    $arrFormNetwork = array("host" => array("LABEL" => "{$arrLang['Host']} (Ex. host.example.com)", "REQUIRED" => "yes", "INPUT_TYPE" => "TEXT", "INPUT_EXTRA_PARAM" => "", "VALIDATION_TYPE" => "domain", "VALIDATION_EXTRA_PARAM" => ""), "dns1" => array("LABEL" => $arrLang["Primary DNS"], "REQUIRED" => "yes", "INPUT_TYPE" => "TEXT", "INPUT_EXTRA_PARAM" => "", "VALIDATION_TYPE" => "ip", "VALIDATION_EXTRA_PARAM" => ""), "dns2" => array("LABEL" => $arrLang["Secondary DNS"], "REQUIRED" => "no", "INPUT_TYPE" => "TEXT", "INPUT_EXTRA_PARAM" => "", "VALIDATION_TYPE" => "ip", "VALIDATION_EXTRA_PARAM" => ""), "gateway" => array("LABEL" => $arrLang["Default Gateway"], "REQUIRED" => "yes", "INPUT_TYPE" => "TEXT", "INPUT_EXTRA_PARAM" => "", "VALIDATION_TYPE" => "ip", "VALIDATION_EXTRA_PARAM" => ""));
    $arrFormInterfase = array("ip" => array("LABEL" => $arrLang["IP Address"], "REQUIRED" => "yes", "INPUT_TYPE" => "TEXT", "INPUT_EXTRA_PARAM" => "", "VALIDATION_TYPE" => "ip", "VALIDATION_EXTRA_PARAM" => ""), "mask" => array("LABEL" => $arrLang["Network Mask"], "REQUIRED" => "yes", "INPUT_TYPE" => "TEXT", "INPUT_EXTRA_PARAM" => "", "VALIDATION_TYPE" => "mask", "VALIDATION_EXTRA_PARAM" => ""), "type" => array("LABEL" => $arrLang["Interface Type"], "REQUIRED" => "yes", "INPUT_TYPE" => "RADIO", "INPUT_EXTRA_PARAM" => array("static" => "Static", "dhcp" => "DHCP"), "VALIDATION_TYPE" => "text", "VALIDATION_EXTRA_PARAM" => ""), "dev_id" => array("LABEL" => $arrLang["Device"], "REQUIRED" => "yes", "INPUT_TYPE" => "HIDDEN", "INPUT_EXTRA_PARAM" => "", "VALIDATION_TYPE" => "ereg", "VALIDATION_EXTRA_PARAM" => "^eth[[:digit:]]{1,2}\$"));
    $strReturn = "";
    $pNet = new paloNetwork();
    // MANEJO DE ACCIONES
    if (isset($_POST['edit'])) {
        $arrNetwork = $pNet->obtener_configuracion_red();
        if (is_array($arrNetwork)) {
            $arrNetworkData['dns1'] = isset($arrNetwork['dns'][0]) ? $arrNetwork['dns'][0] : '';
            $arrNetworkData['dns2'] = isset($arrNetwork['dns'][1]) ? $arrNetwork['dns'][1] : '';
            $arrNetworkData['host'] = isset($arrNetwork['host']) ? $arrNetwork['host'] : '';
            $arrNetworkData['gateway'] = isset($arrNetwork['gateway']) ? $arrNetwork['gateway'] : '';
        }
        $oForm = new paloForm($smarty, $arrFormNetwork);
        $smarty->assign("ETHERNET_INTERFASES_LIST", "");
        $smarty->assign("CANCEL", $arrLang["Cancel"]);
        $smarty->assign("SAVE", $arrLang["Save"]);
        $smarty->assign("REQUIRED_FIELD", $arrLang["Required field"]);
        $smarty->assign("icon", "modules/network_parameters/images/system_network_network_parameters.png");
        $strReturn = $oForm->fetchForm("{$local_templates_dir}/network.tpl", $arrLang["Network Parameters"], $arrNetworkData);
    } else {
        if (isset($_POST['save_network_changes'])) {
            $oForm = new paloForm($smarty, $arrFormNetwork);
            if ($oForm->validateForm($_POST)) {
                $arrNetConf['host'] = $_POST['host'];
                $arrNetConf['dns_ip_1'] = $_POST['dns1'];
                $arrNetConf['dns_ip_2'] = $_POST['dns2'];
                $arrNetConf['gateway_ip'] = $_POST['gateway'];
                $pNet->escribir_configuracion_red_sistema($arrNetConf);
                if (!empty($pNet->errMsg)) {
                    $smarty->assign("mb_message", $pNet->errMsg);
                } else {
                    header("Location: index.php?menu=network");
                }
            } else {
                // Error
                $smarty->assign("mb_title", $arrLang["Validation Error"]);
                $arrErrores = $oForm->arrErroresValidacion;
                $strErrorMsg = "<b>{$arrLang['The following fields contain errors']}:</b><br>";
                foreach ($arrErrores as $k => $v) {
                    $strErrorMsg .= "{$k}, ";
                }
                $strErrorMsg .= "";
                $smarty->assign("mb_message", $strErrorMsg);
                $smarty->assign("CANCEL", $arrLang["Cancel"]);
                $smarty->assign("SAVE", $arrLang["Save"]);
                $smarty->assign("REQUIRED_FIELD", $arrLang["Required field"]);
                $strReturn = $oForm->fetchForm("{$local_templates_dir}/network.tpl", $arrLang["Network Parameters"], $_POST);
            }
            $smarty->assign("icon", "modules/network_parameters/images/system_network_network_parameters.png");
            // Se aplasto el boton de grabar los cambios en la red
        } else {
            if (isset($_POST['cancel_interfase_edit'])) {
                header("Location: index.php?menu=network");
            } else {
                if (isset($_POST['save_interfase_changes'])) {
                    $oForm = new paloForm($smarty, $arrFormInterfase);
                    if ($oForm->validateForm($_POST)) {
                        $smarty->assign("icon", "modules/network_parameters/images/system_network_network_parameters.png");
                        if ($pNet->escribirConfiguracionInterfaseRed($_POST['dev_id'], $_POST['type'], $_POST['ip'], $_POST['mask'])) {
                            header("Location: index.php?menu=network");
                        } else {
                            $smarty->assign("mb_message", $pNet->errMsg);
                        }
                    } else {
                        // Error
                        $smarty->assign("mb_title", $arrLang["Validation Error"]);
                        $arrErrores = $oForm->arrErroresValidacion;
                        $strErrorMsg = "<b>{$arrLang['The following fields contain errors']}:</b><br>";
                        foreach ($arrErrores as $k => $v) {
                            $strErrorMsg .= "{$k}, ";
                        }
                        $strErrorMsg .= "";
                        $smarty->assign("mb_message", $strErrorMsg);
                        $smarty->assign("CANCEL", $arrLang["Cancel"]);
                        $smarty->assign("APPLY_CHANGES", $arrLang["Apply changes"]);
                        $smarty->assign("REQUIRED_FIELD", $arrLang["Required field"]);
                        $smarty->assign("EDIT_PARAMETERS", $arrLang["Edit Network Parameters"]);
                        $smarty->assign("icon", "/modules/{$module_name}/images/system_hardware_detector.png");
                        $smarty->assign("CONFIRM_EDIT", $arrLang["Are you sure you want to edit network parameters?"]);
                        $strReturn = $oForm->fetchForm("{$local_templates_dir}/network_edit_interfase.tpl", "{$arrLang['Edit Interface']} \"Ethernet ??\"", $_POST);
                    }
                } else {
                    if (isset($_GET['action']) && $_GET['action'] == "editInterfase") {
                        // TODO: Revisar si el $_GET['id'] contiene un id valido
                        $arrEths = $pNet->obtener_interfases_red_fisicas();
                        $arrEth = $arrEths[$_GET['id']];
                        if (is_array($arrEth)) {
                            $arrInterfaseData['ip'] = $arrEth['Inet Addr'];
                            $arrInterfaseData['mask'] = $arrEth['Mask'];
                            $arrInterfaseData['type'] = $arrEth['Type'];
                            $arrInterfaseData['dev_id'] = $_GET['id'];
                        }
                        $oForm = new paloForm($smarty, $arrFormInterfase);
                        $smarty->assign("CANCEL", $arrLang["Cancel"]);
                        $smarty->assign("APPLY_CHANGES", $arrLang["Apply changes"]);
                        $smarty->assign("REQUIRED_FIELD", $arrLang["Required field"]);
                        $smarty->assign("EDIT_PARAMETERS", $arrLang["Edit Network Parameters"]);
                        $smarty->assign("icon", "/modules/{$module_name}/images/system_hardware_detector.png");
                        $smarty->assign("CONFIRM_EDIT", $arrLang["Are you sure you want to edit network parameters?"]);
                        $strReturn = $oForm->fetchForm("{$local_templates_dir}/network_edit_interfase.tpl", "{$arrLang['Edit Interface']} \"" . $arrEth['Name'] . "\"", $arrInterfaseData);
                    } else {
                        // SECCION NETWORK PARAMETERS
                        $arrNetwork = $pNet->obtener_configuracion_red();
                        if (is_array($arrNetwork)) {
                            $arrNetworkData['dns1'] = isset($arrNetwork['dns'][0]) ? $arrNetwork['dns'][0] : '';
                            $arrNetworkData['dns2'] = isset($arrNetwork['dns'][1]) ? $arrNetwork['dns'][1] : '';
                            $arrNetworkData['host'] = isset($arrNetwork['host']) ? $arrNetwork['host'] : '';
                            $arrNetworkData['gateway'] = isset($arrNetwork['gateway']) ? $arrNetwork['gateway'] : '';
                        }
                        $oForm = new paloForm($smarty, $arrFormNetwork);
                        $oForm->setViewMode();
                        // SECCION ETHERNET LIST
                        $arrData = array();
                        $arrEths = $pNet->obtener_interfases_red_fisicas();
                        $end = count($arrEths);
                        foreach ($arrEths as $idEth => $arrEth) {
                            $arrTmp = array();
                            $arrTmp[0] = "&nbsp;<a href='?menu=network&action=editInterfase&id={$idEth}'>" . $arrEth['Name'] . "</a>";
                            $arrTmp[1] = strtoupper($arrEth['Type']);
                            $arrTmp[2] = $arrEth['Inet Addr'];
                            $arrTmp[3] = $arrEth['Mask'];
                            $arrTmp[4] = $arrEth['HWaddr'];
                            $arrTmp[5] = isset($arrEth['HW_info']) ? $arrEth['HW_info'] : '';
                            //- Deberia acotar este campo pues puede ser muy largo
                            $arrTmp[6] = $arrEth['Running'] == "Yes" ? "<font color=green>{$arrLang["Connected"]}</font>" : "<font color=red>{$arrLang["Not Connected"]}</font>";
                            $arrData[] = $arrTmp;
                        }
                        $oGrid = new paloSantoGrid($smarty);
                        $oGrid->pagingShow(false);
                        $arrGrid = array("title" => $arrLang["Ethernet Interfaces List"], "icon" => "/modules/{$module_name}/images/system_hardware_detector.png", "width" => "99%", "start" => "1", "end" => $end, "total" => $end, "columns" => array(0 => array("name" => $arrLang["Device"], "property1" => ""), 1 => array("name" => $arrLang["Type"], "property1" => ""), 2 => array("name" => $arrLang["IP"], "property1" => ""), 3 => array("name" => $arrLang["Mask"], "property1" => ""), 4 => array("name" => $arrLang["MAC Address"], "property1" => ""), 5 => array("name" => $arrLang["HW Info"], "property1" => ""), 6 => array("name" => $arrLang["Status"], "property1" => "")));
                        $htmlGrid = $oGrid->fetchGrid($arrGrid, $arrData, $arrLang);
                        $smarty->assign("ETHERNET_INTERFASES_LIST", $htmlGrid);
                        $smarty->assign("EDIT_PARAMETERS", $arrLang["Edit Network Parameters"]);
                        $smarty->assign("REQUIRED_FIELD", $arrLang["Required field"]);
                        $smarty->assign("icon", "modules/network_parameters/images/system_network_network_parameters.png");
                        // DISPLAY
                        $strReturn = $oForm->fetchForm("{$local_templates_dir}/network.tpl", $arrLang["Network Parameters"], $arrNetworkData);
                    }
                }
            }
        }
    }
    return $strReturn;
}
Ejemplo n.º 8
0
function network()
{
    $ip = $_SERVER['SERVER_ADDR'];
    $total = subMask($ip);
    return paloNetwork::getNetAdress($ip, $total) . "/" . $total;
}