Пример #1
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'];
         }
     }
 }
Пример #2
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;
 }
Пример #3
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}");
}