Exemple #1
0
function saveVega($smarty, $module_name, $local_templates_dir, $dsnAsterisk, $dsnSqlite, $arrConf)
{
    $paloEndPoint = new paloSantoEndPoint($dsnAsterisk, $dsnSqlite);
    $paloFileEndPoint = new PaloSantoFileEndPoint($arrConf["tftpboot_path"], $_SESSION["endpoint_mask"]);
    $arrSession = getSession();
    for ($i = 0; $i < $arrSession["endpoint_configurator"]["analog_trunk_lines"]; $i++) {
        if (getParameter("line{$i}") == "" || getParameter("ID{$i}") == "" || getParameter("authentication_ID{$i}") == "") {
            $smarty->assign("mb_title", _tr("Validation Error"));
            $smarty->assign("mb_message", _tr("Fields Line, ID and authentication ID can not be empty"));
            return getLinesVegaForm($smarty, $module_name, $local_templates_dir, $dsnAsterisk, $dsnSqlite, $arrConf, true);
        } else {
            $arrSession["endpoint_configurator"]["line{$i}"] = getParameter("line{$i}");
            $arrSession["endpoint_configurator"]["ID{$i}"] = getParameter("ID{$i}");
            $arrSession["endpoint_configurator"]["authentication_ID{$i}"] = getParameter("authentication_ID{$i}");
            $arrSession["endpoint_configurator"]["num_list{$i}"] = getParameter("num_list{$i}");
            if (getParameter("enable_line{$i}")) {
                $arrSession["endpoint_configurator"]["enable_line{$i}"] = 1;
            } else {
                $arrSession["endpoint_configurator"]["enable_line{$i}"] = 0;
            }
        }
    }
    $mac = "";
    if (getParameter("mac")) {
        $mac = getParameter("mac");
    }
    $credential = $paloEndPoint->getPassword($mac);
    if (!$paloEndPoint->saveVegaData($arrSession["endpoint_configurator"])) {
        $smarty->assign("mb_title", _tr("ERROR"));
        if ($paloEndPoint->errMsg != "" && isset($paloEndPoint->errMsg)) {
            $smarty->assign("mb_message", $paloEndPoint->errMsg);
        } else {
            $smarty->assign("mb_message", _tr("In the query to database endpoint.db"));
        }
        return endpointConfiguratedShow($smarty, $module_name, $local_templates_dir, $dsnAsterisk, $dsnSqlite, $arrConf);
    }
    $tone_set = $paloEndPoint->getToneSet($arrSession["endpoint_configurator"]["country"]);
    if ($tone_set == false) {
        $smarty->assign("mb_title", _tr("ERROR"));
        $smarty->assign("mb_message", _tr("Could not get the tone set by country"));
        return endpointConfiguratedShow($smarty, $module_name, $local_templates_dir, $dsnAsterisk, $dsnSqlite, $arrConf);
    }
    //$last_password=$credential["password"];
    $result = $paloFileEndPoint->buildSangomaConfFile($arrSession["endpoint_configurator"], $tone_set, $dsnAsterisk, $dsnSqlite);
    if ($result === false || is_null($result)) {
        $smarty->assign("mb_title", _tr("ERROR"));
        if ($paloFileEndPoint->errMsg != "" && isset($paloFileEndPoint->errMsg)) {
            $smarty->assign("mb_message", $paloFileEndPoint->errMsg);
        } else {
            $smarty->assign("mb_message", _tr("Could not create the Vega configuration file"));
        }
        if (is_null($result)) {
            return getVegaData($smarty, $module_name, $local_templates_dir, $dsnAsterisk, $dsnSqlite, $arrConf);
        } else {
            return endpointConfiguratedShow($smarty, $module_name, $local_templates_dir, $dsnAsterisk, $dsnSqlite, $arrConf);
        }
    }
    $smarty->assign("mb_title", _tr("MESSAGE"));
    $smarty->assign("mb_message", _tr("The Sangoma Vega was successfully configurated. The changes will apply after the Vega is finished rebooting"));
    unset($arrSession["endpoint_configurator"]);
    unset($arrSession["elastix_endpoints"]);
    putSession($arrSession);
    return endpointConfiguratedShow($smarty, $module_name, $local_templates_dir, $dsnAsterisk, $dsnSqlite, $arrConf);
}
Exemple #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;
}