Пример #1
0
function saveConfigs($smarty, $module_name, $local_templates_dir, $pDB, $arrCredentials)
{
    $val = new PaloValidar();
    $bGuardar = TRUE;
    // Validar toda la lista de IPs
    $_POST['lista_hosts'] = trim($_POST['lista_hosts']);
    $arrHostsFinal = empty($_POST['lista_hosts']) ? array() : explode("\n", $_POST['lista_hosts']);
    if (count($arrHostsFinal) <= 0) {
        $bGuardar = FALSE;
        $smarty->assign(array('mb_title' => _tr('Error'), 'mb_message' => _tr('No IP entered, you must keep at least the IP 127.0.0.1')));
    } else {
        foreach (array_keys($arrHostsFinal) as $k) {
            $arrHostsFinal[$k] = trim($arrHostsFinal[$k]);
            $bGuardar = $bGuardar && ($arrHostsFinal[$k] == 'localhost' || $val->validar(_tr('IP') . ' ' . $arrHostsFinal[$k], $arrHostsFinal[$k], 'ip'));
        }
    }
    // Formato de errores de validación
    if ($val->existenErroresPrevios()) {
        $msgErrorVal = _tr('Validation Error') . '<br/><br/>';
        foreach ($val->arrErrores as $nombreVar => $arrVar) {
            $msgErrorVal .= "<b>{$nombreVar}</b>: {$arrVar['mensaje']}<br/>";
        }
        $smarty->assign(array('mb_title' => _tr('Error'), 'mb_message' => $msgErrorVal));
        $bGuardar = FALSE;
    }
    if ($bGuardar) {
        // Si no hay errores de validacion entonces ingreso las redes al archivo de host
        $output = NULL;
        $retval = NULL;
        exec('/usr/bin/elastix-helper faxconfig setfaxhosts ' . implode(' ', $arrHostsFinal) . ' 2>&1', $output, $retval);
        if ($retval == 0) {
            $smarty->assign(array('mb_title' => _tr('Message'), 'mb_message' => _tr('Configuration updated successfully')));
        } else {
            $smarty->assign(array('mb_title' => _tr('Error'), 'mb_message' => _tr('Write error when writing the new configuration.') . ' ' . implode(' ', $output)));
        }
    }
    return showConfigs($smarty, $module_name, $local_templates_dir, $pDB, $arrCredentials);
}
Пример #2
0
 function validateForm($arrCollectedVars)
 {
     $arrCollectedVars = array_merge($arrCollectedVars, $_FILES);
     include_once "libs/paloSantoValidar.class.php";
     $oVal = new PaloValidar();
     foreach ($arrCollectedVars as $varName => $varValue) {
         // Valido si la variable colectada esta en $this->arrFormElements
         if (@array_key_exists($varName, $this->arrFormElements)) {
             if ($this->arrFormElements[$varName]['INPUT_TYPE'] == 'FILE') {
                 $varValue = $_FILES[$varName]['name'];
             }
             if ($this->arrFormElements[$varName]['REQUIRED'] == 'yes' or $this->arrFormElements[$varName]['REQUIRED'] != 'yes' and !empty($varValue)) {
                 $editable = isset($this->arrFormElements[$varName]['EDITABLE']) ? $this->arrFormElements[$varName]['EDITABLE'] : "yes";
                 if ($this->modo == 'input' || ($this->modo == 'edit' and $editable != 'no')) {
                     $oVal->validar($this->arrFormElements[$varName]['LABEL'], $varValue, $this->arrFormElements[$varName]['VALIDATION_TYPE'], $this->arrFormElements[$varName]['VALIDATION_EXTRA_PARAM']);
                 }
             }
         }
     }
     if ($oVal->existenErroresPrevios()) {
         $this->arrErroresValidacion = $oVal->obtenerArregloErrores();
         return false;
     } else {
         return true;
     }
 }
Пример #3
0
function _moduleContent(&$smarty, $module_name)
{
    include_once "libs/paloSantoValidar.class.php";
    //include module files
    include_once "modules/{$module_name}/configs/default.conf.php";
    //include file language agree to elastix configuration
    //if file language not exists, then include language by default (en)
    $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
    $templates_dir = isset($arrConf['templates_dir']) ? $arrConf['templates_dir'] : 'themes';
    $local_templates_dir = "{$base_dir}/modules/{$module_name}/" . $templates_dir . '/' . $arrConf['theme'];
    $contenido = '';
    $bGuardar = TRUE;
    $msgErrorVal = "";
    $conf_relay = "/etc/postfix/network_table";
    $val = new PaloValidar();
    if (isset($_POST['update_relay'])) {
        $in_redes_relay = trim($_POST['redes_relay']);
        if (!empty($in_redes_relay)) {
            $arrRedesRelay = array_map('trim', explode("\n", $in_redes_relay));
            // Ahora valido que las redes estén en formato correcto
            if (is_array($arrRedesRelay) and count($arrRedesRelay) > 0) {
                foreach ($arrRedesRelay as $redRelay) {
                    //validar
                    $redRelay = trim($redRelay);
                    $val->validar("{$arrLang['Network']} {$redRelay}", $redRelay, "ip/mask");
                }
            } else {
                $smarty->assign("mb_title", $arrLang["Error"]);
                $smarty->assign("mb_message", $arrLang["No network entered, you must keep at least the net 127.0.0.1/32"]);
                $bGuardar = FALSE;
            }
        } else {
            // El textarea esta vacia
            $bGuardar = FALSE;
            $smarty->assign("mb_title", $arrLang["Error"]);
            $smarty->assign("mb_message", $arrLang["No network entered, you must keep at least the net 127.0.0.1/32"]);
        }
        if ($val->existenErroresPrevios()) {
            foreach ($val->arrErrores as $nombreVar => $arrVar) {
                $msgErrorVal .= "<b>" . $nombreVar . "</b>: " . $arrVar['mensaje'] . "<br>";
            }
            $smarty->assign("mb_title", $arrLang["Message"]);
            $smarty->assign("mb_message", $arrLang["Validation Error"] . "<br><br>{$msgErrorVal}");
            $bGuardar = FALSE;
        }
        if ($bGuardar) {
            // Si no hay errores de validacion entonces ingreso las redes al archivo de relay /etc/postfix/network_table
            $output = $retval = NULL;
            exec('/usr/bin/elastix-helper relayconfig ' . implode(' ', array_map('escapeshellarg', $arrRedesRelay)) . ' 2>&1', $output, $retval);
            if ($retval != 0) {
                $smarty->assign(array('mb_title' => _tr('Error'), 'mb_message' => _tr('Write error when writing the new configuration.') . ': ' . implode('<br/>', $output)));
            } else {
                $smarty->assign(array('mb_title' => _tr('Message'), 'mb_message' => _tr('Configuration updated successfully')));
            }
        }
    }
    if (file_exists($conf_relay)) {
        if ($fh = @fopen($conf_relay, "r")) {
            while ($linea = fgets($fh, 1024)) {
                $contenido .= $linea;
            }
            fclose($fh);
        } else {
            // Si no se puede abrir el archivo se debe mostrar mensaje de error
            $smarty->assign("mb_title", $arrLang["Error"]);
            $smarty->assign("mb_message", $arrLang["Could not read the relay configuration."]);
        }
    } else {
        // Si el archivo no existe algo anda mal.
        $smarty->assign("mb_title", $arrLang["Error"]);
        $smarty->assign("mb_message", $arrLang["Could not read the relay configuration."]);
    }
    $relay_msg = $arrLang["message about email relay"];
    $smarty->assign("APPLY_CHANGES", $arrLang["Apply changes"]);
    $smarty->assign("EMAIL_RELAY_MSG", $relay_msg);
    $smarty->assign("RELAY_CONTENT", $contenido);
    $smarty->assign("title", $arrLang["Networks which can RELAY"]);
    $contenidoModulo = $smarty->fetch("file:{$local_templates_dir}/form_relay.tpl");
    return $contenidoModulo;
}
Пример #4
0
function editEmailRelay($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $arrCredentials)
{
    $conf_relay = "/etc/postfix/network_table";
    $in_redes_relay = trim($_POST['redes_relay']);
    $val = new PaloValidar();
    $bGuardar = true;
    if (!empty($in_redes_relay)) {
        $arrRedesRelay = array_map('trim', explode("\n", $in_redes_relay));
        // Ahora valido que las redes estén en formato correcto
        if (is_array($arrRedesRelay) and count($arrRedesRelay) > 0) {
            foreach ($arrRedesRelay as $redRelay) {
                //validar
                $redRelay = trim($redRelay);
                $val->validar(_tr("Network") . " {$redRelay}", $redRelay, "ip/mask");
            }
        } else {
            $smarty->assign("mb_title", _tr("Error"));
            $smarty->assign("mb_message", _tr("No network entered, you must keep at least the net 127.0.0.1/32"));
            $bGuardar = FALSE;
        }
    } else {
        // El textarea esta vacia
        $bGuardar = FALSE;
        $smarty->assign("mb_title", _tr("Error"));
        $smarty->assign("mb_message", _tr("No network entered, you must keep at least the net 127.0.0.1/32"));
    }
    if ($val->existenErroresPrevios()) {
        foreach ($val->arrErrores as $nombreVar => $arrVar) {
            $msgErrorVal .= "<b>" . $nombreVar . "</b>: " . $arrVar['mensaje'] . "<br>";
        }
        $smarty->assign("mb_title", _tr("Message"));
        $smarty->assign("mb_message", _tr("Validation Error") . "<br><br>{$msgErrorVal}");
        $bGuardar = FALSE;
    }
    if ($bGuardar) {
        // Si no hay errores de validacion entonces ingreso las redes al archivo de relay /etc/postfix/network_table
        $output = $retval = NULL;
        exec('/usr/bin/elastix-helper relayconfig ' . implode(' ', array_map('escapeshellarg', $arrRedesRelay)) . ' 2>&1', $output, $retval);
        if ($retval != 0) {
            $smarty->assign(array('mb_title' => _tr('Error'), 'mb_message' => _tr('Write error when writing the new configuration.') . ': ' . implode('<br/>', $output)));
        } else {
            $smarty->assign(array('mb_title' => _tr('Message'), 'mb_message' => _tr('Configuration updated successfully')));
        }
    }
    return reportEmailRelay($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $arrCredentials);
}
Пример #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}");
}
Пример #6
0
function endpointConfiguratedShow($smarty, $module_name, $local_templates_dir, $dsnAsterisk, $dsnSqlite, $arrConf)
{
    $arrData = array();
    if (!isset($_SESSION['elastix_endpoints']) || !is_array($_SESSION['elastix_endpoints']) || empty($_SESSION['elastix_endpoints'])) {
        $paloFileEndPoint = new PaloSantoFileEndPoint($arrConf["tftpboot_path"], $_SESSION["endpoint_mask"]);
        $paloEndPoint = new paloSantoEndPoint($dsnAsterisk, $dsnSqlite);
        $arrEndpointsConf = $paloEndPoint->listEndpointConf();
        $arrVendor = $paloEndPoint->listVendor();
        $arrDeviceFreePBX = $paloEndPoint->getDeviceFreePBX();
        $arrDeviceFreePBXAll = $paloEndPoint->getDeviceFreePBX(true);
        $endpoint_mask = isset($_POST['endpoint_mask']) ? $_POST['endpoint_mask'] : network();
        $_SESSION["endpoint_mask"] = $endpoint_mask;
        $pValidator = new PaloValidar();
        if (!$pValidator->validar('endpoint_mask', $endpoint_mask, 'ip/mask')) {
            $smarty->assign("mb_title", _tr('ERROR') . ":");
            $strErrorMsg = "";
            if (is_array($pValidator->arrErrores) && count($pValidator->arrErrores) > 0) {
                foreach ($pValidator->arrErrores as $k => $v) {
                    $strErrorMsg .= "{$k}, ";
                }
            }
            $smarty->assign("mb_message", _tr('Invalid Format in Parameter') . ": " . $strErrorMsg);
        } else {
            $pattonDevices = $paloEndPoint->getPattonDevices();
            $arrEndpointsMap = $paloEndPoint->endpointMap($endpoint_mask, $arrVendor, $arrEndpointsConf, $pattonDevices);
            if ($arrEndpointsMap == false) {
                $smarty->assign("mb_title", _tr('ERROR') . ":");
                $smarty->assign("mb_message", $paloEndPoint->errMsg);
            }
            if (is_array($arrEndpointsMap) && count($arrEndpointsMap) > 0) {
                $cont = 0;
                foreach ($arrEndpointsMap as $key => $endspoint) {
                    $flag = 0;
                    $cont++;
                    if (isset($endspoint['model_no']) && $endspoint['model_no'] != "") {
                        if ($paloEndPoint->modelSupportIAX($endspoint['model_no'])) {
                            $comboDevices = combo($arrDeviceFreePBXAll, $endspoint['account']);
                        } else {
                            $comboDevices = combo($arrDeviceFreePBX, $endspoint['account']);
                        }
                    } else {
                        $comboDevices = combo(array("Unselected" => _tr("Unselected")), "");
                    }
                    if ($endspoint['configurated']) {
                        $unset = "<input type='checkbox' name='epmac_{$endspoint['mac_adress']}'  />";
                        $report = $paloEndPoint->compareDevicesAsteriskSqlite($endspoint['account']);
                    } else {
                        $unset = "";
                    }
                    if ($endspoint['desc_vendor'] == "Unknown") {
                        $endspoint['desc_vendor'] = $paloEndPoint->getDescription($endspoint['name_vendor']);
                    }
                    $macWithout2Points = str_replace(":", "", $endspoint['mac_adress']);
                    $currentExtension = $paloEndPoint->getExtension($endspoint['ip_adress']);
                    if ($endspoint["name_vendor"] == "Patton") {
                        $arrTmp[0] = "";
                        $arrTmp[1] = "";
                        $arrTmp[5] = $endspoint["model_no"];
                        $arrTmp[6] = "<a href='?menu={$module_name}&action=patton_data&mac={$endspoint['mac_adress']}'>" . _tr("Data Configuration") . "</a>";
                        $configured = false;
                        foreach ($arrEndpointsConf as $arrConf) {
                            if (in_array($endspoint["mac_adress"], $arrConf)) {
                                $configured = true;
                                break;
                            }
                        }
                        if ($configured) {
                            $arrTmp[7] = "<font color = 'green'>" . _tr("Configured") . "</font>";
                        } else {
                            $arrTmp[7] = _tr("Not Configured");
                        }
                        $_SESSION['endpoint_model'][$endspoint['mac_adress']] = $endspoint["model_no"];
                    } elseif ($endspoint["name_vendor"] == "Sangoma") {
                        $arrTmp[0] = "";
                        $arrTmp[1] = "";
                        // $arrTmp[5] = $endspoint["model_no"];
                        //  $arrTmp[5] = "<select name='id_model_device_{$endspoint['mac_adress']}' onchange='getDevices(this,\"$macWithout2Points\");'>".combo($paloEndPoint->getAllModelsVendor($endspoint['name_vendor']),$endspoint['model_no'])."</select>";
                        $arrPorts = $paloFileEndPoint->getSangomaPorts($endspoint['ip_adress'], $endspoint["mac_adress"], $dsnAsterisk, $dsnSqlite, 2);
                        if ($arrPorts == null) {
                            $arrPorts['fxo'] = "?";
                            $arrPorts['fxs'] = "?";
                        }
                        $arrTmp[5] = $paloFileEndPoint->getSangomaModel($endspoint['ip_adress'], $endspoint["mac_adress"], $dsnAsterisk, $dsnSqlite, 1) . "FXO: " . $arrPorts['fxo'] . " FXS: " . $arrPorts['fxs'];
                        $arrTmp[6] = "<a href='?menu={$module_name}&action=vega_data&mac={$endspoint['mac_adress']}'>" . _tr("Data Configuration") . "</a>";
                        $configured = false;
                        foreach ($arrEndpointsConf as $arrConf) {
                            if (in_array($endspoint["mac_adress"], $arrConf)) {
                                $configured = true;
                                break;
                            }
                        }
                        if ($configured) {
                            $arrTmp[7] = "<font color = 'green'>" . _tr("Configured") . "</font>";
                        } else {
                            $arrTmp[7] = _tr("Not Configured");
                        }
                        $_SESSION['endpoint_model'][$endspoint['mac_adress']] = $endspoint["model_no"];
                    } else {
                        if ($endspoint["name_vendor"] == "Grandstream") {
                            $arr = $paloFileEndPoint->getModelElastix("admin", "admin", $endspoint['ip_adress'], 2);
                            if ($arr) {
                                $flag = 1;
                                $endpointElastix = $paloEndPoint->getVendorByName("Elastix");
                                $endspoint['name_vendor'] = $endpointElastix["name"];
                                $endspoint['desc_vendor'] = $endpointElastix["description"];
                                $endspoint['id_vendor'] = $endpointElastix["id"];
                            }
                        }
                        $arrTmp[0] = "<input type='checkbox' name='epmac_{$endspoint['mac_adress']}'  />";
                        $arrTmp[1] = $unset;
                        $arrTmp[5] = "<select name='id_model_device_{$endspoint['mac_adress']}' onchange='getDevices(this,\"{$macWithout2Points}\");'>" . combo($paloEndPoint->getAllModelsVendor($endspoint['name_vendor']), $endspoint['model_no']) . "</select>";
                        $arrTmp[6] = "<select name='id_device_{$endspoint['mac_adress']}' id='id_device_{$macWithout2Points}'   >{$comboDevices}</select>";
                        if ($currentExtension != "Not Registered") {
                            $arrTmp[7] = "<font color = 'green'>{$currentExtension}</font>";
                        } else {
                            $arrTmp[7] = $currentExtension;
                        }
                    }
                    $arrTmp[2] = $endspoint['mac_adress'];
                    //$arrTmp[3] = "<div class='chkbox' id=".$cont." style='width:135px;'><div class='resp_".$cont."'><a href='http://{$endspoint['ip_adress']}/' target='_blank' id='a_".$cont."' style='float:left;'>{$endspoint['ip_adress']}</a><input type='hidden' name='ip_adress_endpoint_{$endspoint['mac_adress']}' id='hid_".$cont."' value='{$endspoint['ip_adress']}' />"."<input type='checkbox' id='chk_".$cont."' name='{$endspoint['mac_adress']}' style='margin-top:1px;' /></div></div>";
                    $arrTmp[3] = "<a href='http://{$endspoint['ip_adress']}/' target='_blank'>{$endspoint['ip_adress']}</a><input type='hidden' name='ip_adress_endpoint_{$endspoint['mac_adress']}' value='{$endspoint['ip_adress']}' />";
                    $arrTmp[4] = $endspoint['name_vendor'] . " / " . $endspoint['desc_vendor'] . "&nbsp;<input type='hidden' name='id_vendor_device_{$endspoint['mac_adress']}' value='{$endspoint['id_vendor']}' />&nbsp;<input type='hidden' name='name_vendor_device_{$endspoint['mac_adress']}' value='{$endspoint['name_vendor']}' />";
                    $arrData[] = $arrTmp;
                    $_SESSION["endpoint_ip"][$endspoint['mac_adress']] = $endspoint['ip_adress'];
                }
                $_SESSION['elastix_endpoints'] = $arrData;
                $_SESSION['grid'] = $arrData;
                //Lo guardo en la session para hacer mucho mas rapido el proceso
                //de configuracion de los endpoint. Solo la primera vez corre el
                //comado nmap y cuando quiera el usuario correrlo de nuevo lo debe
                //hacer por medio del boton Discover Endpoints in this Network, ahi de nuevo vuelve a
                //construir el arreglo $arrData.
            }
        }
    } else {
        $arrData = $_SESSION['elastix_endpoints'];
    }
    if (!isset($endpoint_mask)) {
        $endpoint_mask = network();
    }
    return buildReport($arrData, $smarty, $module_name, $endpoint_mask);
}
Пример #7
0
function load_endpoint_from_csv($smarty, $arrLang, $ruta_archivo_csv, $base_dir, $dsnAsterisk, $dsnSqlite, $module_name, $local_templates_dir, $arrConf)
{
    $paloEndPoint = new paloSantoEndPoint($dsnAsterisk, $dsnSqlite);
    $arrEndpointsConf = $paloEndPoint->listEndpointConf();
    $arrVendor = $paloEndPoint->listVendor();
    $endpoint_mask = isset($_POST['endpoint_mask']) ? $_POST['endpoint_mask'] : network();
    $pValidator = new PaloValidar();
    $arrFindVendor = array();
    //variable de ayuda, para llamar solo una vez la funcion createFilesGlobal de cada vendor
    $arrayColumnas = array();
    $result = isValidCSV($arrLang, $ruta_archivo_csv, $arrayColumnas);
    if ($result != "valided") {
        $smarty->assign("mb_title", _tr('ERROR') . ":");
        $smarty->assign("mb_message", $result);
        return false;
    }
    if (!$pValidator->validar('endpoint_mask', $endpoint_mask, 'ip/mask')) {
        $smarty->assign("mb_title", _tr('ERROR') . ":");
        $smarty->assign("mb_message", _tr('Invalid Format IP address'));
        return false;
    }
    $pattonDevices = $paloEndPoint->getPattonDevices();
    $arrles = $paloEndPoint->endpointMap($endpoint_mask, $arrVendor, $arrEndpointsConf, $pattonDevices, true);
    if (!(is_array($arrles) && count($arrles) > 0)) {
        $smarty->assign("mb_title", _tr('ERROR') . ":");
        $smarty->assign("mb_message", _tr("There weren't  endpoints in the subnet."));
        return false;
    }
    $hArchivo = fopen($ruta_archivo_csv, 'r+');
    $lineProcessed = 0;
    $line = 0;
    $msg = "";
    if ($hArchivo) {
        $paloFileEndPoint = new PaloSantoFileEndPoint($arrConf["tftpboot_path"], $endpoint_mask);
        //Linea 1 header ignorada
        $tupla = fgetcsv($hArchivo, 4096, ",");
        //Desde linea 2 son datos
        while ($tupla = fgetcsv($hArchivo, 4096, ",")) {
            $line++;
            if (is_array($tupla) && count($tupla) >= 4) {
                $arrEndpoint = csv2Array($tupla, $arrayColumnas);
                if ($arrEndpoint['data'] == null) {
                    $msg .= _tr("Line") . " {$line}: {$arrEndpoint['msg']} <br />";
                } else {
                    $name_model = $arrEndpoint['data']['Model'];
                    $extension = $arrEndpoint['data']['Ext'];
                    $MAC = $arrEndpoint['data']['MAC'];
                    $macTMP = strtolower($MAC);
                    $macTMP = str_replace(":", "", $macTMP);
                    if (isset($arrles[$macTMP])) {
                        // Si el endpoint fue encontrado en la red.
                        $currentEndpointIP = $arrles[$macTMP]['ip_adress'];
                        $tech = $paloEndPoint->getTech($extension);
                        $freePBXParameters = $paloEndPoint->getDeviceFreePBXParameters($extension, $tech);
                        if (!(is_array($freePBXParameters) && count($freePBXParameters) > 0)) {
                            $msg .= _tr("Line") . " {$line}: " . _tr("Extension") . "  {$extension} (tech:{$tech})" . _tr("has not been created.") . "<br />";
                            continue;
                        }
                        $dataVendor = $paloEndPoint->getVendor(substr($MAC, 0, 8));
                        if ($dataVendor["name"] == "Grandstream") {
                            $arr = $paloFileEndPoint->getModelElastix("admin", "admin", $currentEndpointIP, 2);
                            if ($arr) {
                                $endpointElastix = $paloEndPoint->getVendorByName("Elastix");
                                $dataVendor["id"] = $endpointElastix["id"];
                                $dataVendor["name"] = $endpointElastix["name"];
                            }
                        }
                        $dataModel = $paloEndPoint->getModelByVendor($dataVendor["id"], $name_model);
                        if (!(is_array($dataVendor) && count($dataVendor) > 0)) {
                            $msg .= _tr("Line") . " {$line}: Vendor {$dataVendor['name']}" . _tr("not supported.") . "<br />";
                            continue;
                        }
                        if (!(is_array($dataModel) && count($dataModel) > 0)) {
                            //No existe el modelo
                            $msg .= _tr("Line") . "{$line}: Model {$name_model} of vendor {$dataVendor['name']}" . _tr("not supported.") . "<br />";
                            continue;
                        }
                        $tmpEndpoint['id_device'] = $freePBXParameters['id_device'];
                        $tmpEndpoint['desc_device'] = $freePBXParameters['desc_device'];
                        $tmpEndpoint['account'] = $freePBXParameters['account_device'];
                        $tmpEndpoint['secret'] = $freePBXParameters['secret_device'];
                        $tmpEndpoint['id_model'] = $dataModel["id"];
                        $tmpEndpoint['mac_adress'] = $MAC;
                        $tmpEndpoint['id_vendor'] = $dataVendor["id"];
                        $tmpEndpoint['name_vendor'] = $dataVendor["name"];
                        $tmpEndpoint['ip_adress'] = $currentEndpointIP;
                        $tmpEndpoint['comment'] = "Nada";
                        $arrParametersOld = $paloEndPoint->getParameters($MAC);
                        $arrParameters = $paloFileEndPoint->updateArrParameters($dataVendor["name"], $name_model, $arrParametersOld);
                        $tmpEndpoint['arrParameters'] = array_merge($arrParameters, $arrEndpoint['data']);
                        if ($paloEndPoint->createEndpointDB($tmpEndpoint)) {
                            //verifico si la funcion createFilesGlobal del vendor ya fue ejecutado
                            if (!in_array($dataVendor["name"], $arrFindVendor)) {
                                if ($paloFileEndPoint->createFilesGlobal($dataVendor["name"])) {
                                    $arrFindVendor[] = $dataVendor["name"];
                                }
                            }
                            //escribir archivos
                            $ArrayData['vendor'] = $dataVendor["name"];
                            $ArrayData['data'] = array("filename" => strtolower(str_replace(":", "", $MAC)), "DisplayName" => $tmpEndpoint['desc_device'], "id_device" => $tmpEndpoint['id_device'], "secret" => $tmpEndpoint['secret'], "model" => $dataModel['name'], "ip_endpoint" => $tmpEndpoint['ip_adress'], "arrParameters" => $tmpEndpoint['arrParameters'], "tech" => $tech);
                            if (!$paloFileEndPoint->createFiles($ArrayData)) {
                                if (isset($paloFileEndPoint->errMsg)) {
                                    $msg .= _tr("Line") . "{$line}: " . _tr("{$paloFileEndPoint->errMsg}.") . "<br />";
                                } else {
                                    $msg .= _tr("Line") . "{$line}: " . _tr("Error, Technology Device (SIP/IAX) not supported on endpoint.") . "<br />";
                                }
                            } else {
                                $lineProcessed++;
                            }
                        }
                    } else {
                        $v = isset($dataVendor['name']) ? $dataVendor['name'] : $arrEndpoint['data']['Vendor'];
                        $msg .= _tr("Line") . "{$line}: " . _tr("Endpoint wasn't founded in subnet.") . "(vendor:{$v} - model:{$name_model} - Ext:{$extension})<br />";
                    }
                }
            }
        }
        $smarty->assign("mb_title", _tr('Resume') . ":");
        $msg = _tr("Total endpoint processed") . ": {$lineProcessed} <br /> <br />{$msg}";
        $smarty->assign("mb_message", $msg);
        unlink($ruta_archivo_csv);
    }
    return true;
}
Пример #8
0
function _moduleContent(&$smarty, $module_name)
{
    //include module files
    include_once "modules/{$module_name}/configs/default.conf.php";
    load_language_module($module_name);
    //global variables
    global $arrConf;
    global $arrConfModule;
    $arrConf = array_merge($arrConf, $arrConfModule);
    //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'];
    // Textos estáticos
    $smarty->assign(array('APPLY_CHANGES' => _tr('Save'), 'EMAIL_RELAY_MSG' => _tr('These IPs are allowed to send faxes through Elastix.  You must insert one IP per row.  We recommend keeping localhost and 127.0.0.1  in the configuration because some processes could need them.'), 'title' => _tr('Clients allowed to send faxes')));
    $smarty->assign("icon", "/modules/{$module_name}/images/fax_fax_clients.png");
    if (isset($_POST['update_hosts'])) {
        $val = new PaloValidar();
        $bGuardar = TRUE;
        // Validar toda la lista de IPs
        $_POST['lista_hosts'] = trim($_POST['lista_hosts']);
        $arrHostsFinal = empty($_POST['lista_hosts']) ? array() : explode("\n", $_POST['lista_hosts']);
        if (count($arrHostsFinal) <= 0) {
            $bGuardar = FALSE;
            $smarty->assign(array('mb_title' => _tr('Error'), 'mb_message' => _tr('No IP entered, you must keep at least the IP 127.0.0.1')));
        } else {
            foreach (array_keys($arrHostsFinal) as $k) {
                $arrHostsFinal[$k] = trim($arrHostsFinal[$k]);
                $bGuardar = $bGuardar && ($arrHostsFinal[$k] == 'localhost' || $val->validar(_tr('IP') . ' ' . $arrHostsFinal[$k], $arrHostsFinal[$k], 'ip'));
            }
        }
        // Formato de errores de validación
        if ($val->existenErroresPrevios()) {
            $msgErrorVal = _tr('Validation Error') . '<br/><br/>';
            foreach ($val->arrErrores as $nombreVar => $arrVar) {
                $msgErrorVal .= "<b>{$nombreVar}</b>: {$arrVar['mensaje']}<br/>";
            }
            $smarty->assign(array('mb_title' => _tr('Error'), 'mb_message' => $msgErrorVal));
            $bGuardar = FALSE;
        }
        if ($bGuardar) {
            // Si no hay errores de validacion entonces ingreso las redes al archivo de host
            $output = NULL;
            $retval = NULL;
            exec('/usr/bin/elastix-helper faxconfig --setfaxhosts ' . implode(' ', $arrHostsFinal) . ' 2>&1', $output, $retval);
            if ($retval == 0) {
                $smarty->assign(array('mb_title' => _tr('Message'), 'mb_message' => _tr('Configuration updated successfully')));
            } else {
                $smarty->assign(array('mb_title' => _tr('Error'), 'mb_message' => _tr('Write error when writing the new configuration.') . ' ' . implode(' ', $output)));
            }
        }
    }
    // Listar IPs actualmente permitidas
    $output = NULL;
    $retval = NULL;
    exec('/usr/bin/elastix-helper faxconfig --getfaxhosts 2>&1', $output, $retval);
    if ($retval != 0) {
        $smarty->assign(array('mb_title' => _tr('Error'), 'mb_message' => _tr('Could not read the clients configuration.')));
    }
    $smarty->assign("RELAY_CONTENT", implode("\n", $output));
    return $smarty->fetch("file:{$local_templates_dir}/form_hosts.tpl");
}