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']; } } }
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); }
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; }
function network() { $ip = $_SERVER['SERVER_ADDR']; $total = subMask($ip); return paloNetwork::getNetAdress($ip, $total) . "/" . $total; }