Exemplo n.º 1
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);
}
Exemplo n.º 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;
}