Пример #1
0
function endpointConfiguratedSet($smarty, $module_name, $local_templates_dir, $dsnAsterisk, $dsnSqlite, $arrConf)
{
    $paloEndPoint = new paloSantoEndPoint($dsnAsterisk, $dsnSqlite);
    $paloFileEndPoint = new PaloSantoFileEndPoint($arrConf["tftpboot_path"], $_SESSION["endpoint_mask"]);
    $arrFindVendor = array();
    //variable de ayuda, para llamar solo una vez la funcion createFilesGlobal de cada vendor
    $valid = validateParameterEndpoint($_POST, $module_name, $dsnAsterisk, $dsnSqlite);
    $count = 0;
    $error = "";
    if ($valid != false) {
        $smarty->assign("mb_title", _tr('ERROR') . ":");
        $smarty->assign("mb_message", $valid);
        $endpoint_mask = isset($_POST['endpoint_mask']) ? $_POST['endpoint_mask'] : network();
        return buildReport($_SESSION['elastix_endpoints'], $smarty, $module_name, $endpoint_mask);
    }
    foreach ($_POST as $key => $values) {
        if (substr($key, 0, 6) == "epmac_") {
            //encontre una mac seleccionada entoces por forma empirica con ayuda del mac_adress obtego los parametros q se relacionan con esa mac.
            $tmpMac = substr($key, 6);
            $count++;
            $tech = $paloEndPoint->getTech($_POST["id_device_{$tmpMac}"]);
            $freePBXParameters = $paloEndPoint->getDeviceFreePBXParameters($_POST["id_device_{$tmpMac}"], $tech);
            $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'] = $_POST["id_model_device_{$tmpMac}"];
            $tmpEndpoint['mac_adress'] = $tmpMac;
            $tmpEndpoint['id_vendor'] = $_POST["id_vendor_device_{$tmpMac}"];
            $tmpEndpoint['name_vendor'] = $_POST["name_vendor_device_{$tmpMac}"];
            $tmpEndpoint['ip_adress'] = $_POST["ip_adress_endpoint_{$tmpMac}"];
            $tmpEndpoint['comment'] = "Nada";
            //Variables usadas para parametros extras
            $name_model = $paloEndPoint->getModelById($tmpEndpoint['id_model']);
            $arrParametersOld = $paloEndPoint->getParameters($tmpEndpoint['mac_adress']);
            $arrParameters = $paloFileEndPoint->updateArrParameters($tmpEndpoint['name_vendor'], $name_model, $arrParametersOld);
            $tmpEndpoint['arrParameters'] = $arrParameters;
            if ($paloEndPoint->createEndpointDB($tmpEndpoint)) {
                //verifico si la funcion createFilesGlobal del vendor ya fue ejecutado
                if (!in_array($tmpEndpoint['name_vendor'], $arrFindVendor)) {
                    if ($paloFileEndPoint->createFilesGlobal($tmpEndpoint['name_vendor'])) {
                        $arrFindVendor[] = $tmpEndpoint['name_vendor'];
                    }
                }
                //escribir archivos
                $ArrayData['vendor'] = $tmpEndpoint['name_vendor'];
                $ArrayData['data'] = array("filename" => strtolower(str_replace(":", "", $tmpMac)), "DisplayName" => $tmpEndpoint['desc_device'], "id_device" => $tmpEndpoint['id_device'], "secret" => $tmpEndpoint['secret'], "model" => $name_model, "ip_endpoint" => $tmpEndpoint['ip_adress'], "arrParameters" => $tmpEndpoint['arrParameters'], "tech" => $tech);
                //Falta si hay error en la creacion de un archivo, ya esta para saber q error es, el problema es como manejar un error o los errores dentro del este lazo (foreach).
                //ejemplo: if($paloFile->createFiles($ArrayData)==false){ $paloFile->errMsg  (mostrar error con smarty)}
                if (!$paloFileEndPoint->createFiles($ArrayData)) {
                    if (isset($paloFileEndPoint->errMsg)) {
                        $error .= $paloFileEndPoint->errMsg . "<br />";
                    }
                }
            }
        }
    }
    if ($count > 0 && $error == "") {
        $smarty->assign("mb_title", _tr("MESSAGE"));
        $smarty->assign("mb_message", _tr("The Extension(s) parameters have been saved. Each checked phone will be configured with the new parameters once it has finished rebooting"));
    } elseif (isset($error) && $error != "") {
        $smarty->assign("mb_title", _tr("MESSAGE"));
        $message = _tr("The following errors ocurred") . ":<br />" . $error;
        $smarty->assign("mb_message", $message);
    }
    unset($_SESSION['elastix_endpoints']);
    return endpointConfiguratedShow($smarty, $module_name, $local_templates_dir, $dsnAsterisk, $dsnSqlite, $arrConf);
}
Пример #2
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;
}