Esempio n. 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);
}