Exemplo n.º 1
0
function save_recording($smarty, $module_name, $local_templates_dir, &$pDB, $arrConf, $credentials)
{
    $success = false;
    $error = "";
    $domain = null;
    if ($credentials['userlevel'] != 'superadmin') {
        $domain = $credentials["domain"];
    } else {
        $domain = getParameter("organization");
    }
    $bExito = true;
    $pRecording = new paloSantoRecordings($pDB);
    if (empty($domain)) {
        $destiny_path = "/var/lib/asterisk/sounds/custom";
        $source = "custom";
    } else {
        //validamos el formato
        if (!preg_match("/^(([[:alnum:]-]+)\\.)+([[:alnum:]])+\$/", $domain)) {
            $smarty->assign("mb_title", _tr("ERROR"));
            $smarty->assign("mb_message", _tr("Invalid organization"));
            return form_Recordings($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $credentials);
        } else {
            $destiny_path = "/var/lib/asterisk/sounds/{$domain}/system";
            $source = "system";
        }
    }
    if (isset($_FILES)) {
        if ($_FILES['file_record']['name'] != "") {
            $smarty->assign("file_record_name", $_FILES['file_record']['name']);
            if (!file_exists($destiny_path)) {
                $bExito = mkdir($destiny_path, 0755, TRUE);
            }
            if (!preg_match("/^(\\w|-|\\.|\\(|\\)|\\s)+\\.(wav|WAV|Wav|gsm|GSM|Gsm|Wav49|wav49|WAV49|mp3|MP3|Mp3)\$/", $_FILES['file_record']['name']) || preg_match("/(\\.php)/", $_FILES['file_record']['name'])) {
                $smarty->assign("mb_title", _tr("ERROR"));
                $smarty->assign("mb_message", _tr("Invalid extension file ") . " " . $_FILES["file_record"]["name"]);
                $bExito = false;
                return form_Recordings($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $credentials);
            }
            if ($bExito) {
                $filenameTmp = $_FILES['file_record']['name'];
                $tmp_name = $_FILES['file_record']['tmp_name'];
                $filename = basename("{$destiny_path}/{$filenameTmp}");
                $info = pathinfo($filename);
                $file_sin_ext = $info["filename"];
                if (strlen($filenameTmp) > 50) {
                    $smarty->assign("mb_title", _tr("ERROR"));
                    $smarty->assign("mb_message", _tr("Filename's length must be max 50 characters") . ": {$filenameTmp}");
                    $bExito = false;
                } elseif ($pRecording->checkFilename($destiny_path . "/" . $filenameTmp) != true || $pRecording->checkFilename($destiny_path . "/" . $file_sin_ext . ".wav") != true) {
                    //Verificar que no existe otro archivo con el mismo nombre en la misma carpeta
                    $smarty->assign("mb_title", _tr("ERROR"));
                    $smarty->assign("mb_message", _tr("Already exists a file with same filename") . ": {$filenameTmp}");
                    $bExito = false;
                    return form_Recordings($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $credentials);
                } else {
                    // $filename = basename("$destiny_path/$filenameTmp");
                    $date = date("YMd_His");
                    $tmpFile = $date . "_" . $filename;
                    if (move_uploaded_file($tmp_name, "{$destiny_path}/{$tmpFile}")) {
                        $info = pathinfo($filename);
                        $file_sin_ext = $info["filename"];
                        $type = $pRecording->getTipeOfFile("{$destiny_path}/{$tmpFile}");
                        $continue = true;
                        if ($type == false) {
                            $error .= $pRecording->errMsg;
                            $continue = false;
                        }
                        if ($type == "audio/mpeg; charset=binary") {
                            if ($pRecording->convertMP3toWAV($destiny_path, $tmpFile, $file_sin_ext, $date) == false) {
                                $error .= $pRecording->errMsg;
                                $continue = false;
                                $bExito = false;
                            } else {
                                $filename = $file_sin_ext . ".wav";
                            }
                        }
                        if ($continue) {
                            if ($pRecording->resampleMoHFiles($destiny_path, $tmpFile, $filename) == false) {
                                $error .= $pRecording->errMsg;
                                $bExito = false;
                            }
                        }
                    } else {
                        $smarty->assign("mb_title", _tr("ERROR") . ":");
                        $smarty->assign("mb_message", _tr("Possible file upload attack") . " {$filename}");
                        return form_Recordings($smarty, $module_name, $local_templates_dir, &$pDB, $arrConf, $credentials);
                    }
                }
            } else {
                $smarty->assign("mb_title", _tr("ERROR") . ":");
                $smarty->assign("mb_message", _tr("Destiny directory couldn't be created"));
                return form_Recordings($smarty, $module_name, $local_templates_dir, &$pDB, $arrConf, $credentials);
            }
        } else {
            $smarty->assign("mb_title", _tr("ERROR") . ":");
            $smarty->assign("mb_message", _tr("Error copying the file"));
            return form_Recordings($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $credentials);
        }
    } else {
        $smarty->assign("mb_title", _tr("ERROR") . ":");
        $smarty->assign("mb_message", _tr("Error copying the file"));
        return form_Recordings($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $credentials);
    }
    if ($bExito) {
        $name = "{$destiny_path}/{$filename}";
        $pDB->beginTransaction();
        $success = $pRecording->createNewRecording($filename, $name, $source, $domain);
        if ($success) {
            $pDB->commit();
        } else {
            $pDB->rollBack();
        }
        $error .= $pRecording->errMsg;
        if ($success == false) {
            $smarty->assign("mb_title", _tr("ERROR") . ":");
            $smarty->assign("mb_message", $error);
        } else {
            $smarty->assign("mb_title", _tr("MESSAGE"));
            $smarty->assign("mb_message", _tr("Record Saved Successfully"));
        }
    } else {
        $smarty->assign("mb_title", _tr("ERROR") . ":");
        $smarty->assign("mb_message", _tr("ERROR Uploading File.") . " " . $error);
        return form_Recordings($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $credentials);
    }
    return reportRecording($smarty, $module_name, $local_templates_dir, &$pDB, $arrConf, $credentials);
}
Exemplo n.º 2
0
function new_recording($smarty, $module_name, $local_templates_dir, $arrLang, $dsn_agi_manager, $arrConf, $pDBACL)
{
    $recording_name = isset($_POST['recording_name']) ? $_POST['recording_name'] : '';
    if ($recording_name != '') {
        $pRecording = new paloSantoRecordings();
        $result = $pRecording->Obtain_Protocol_Current_User($arrConf);
        $number2call = '*77';
        if ($result != FALSE) {
            $result = $pRecording->Call2Phone($dsn_agi_manager, $result['id'], $number2call, $result['dial'], $result['description']);
            if ($result) {
                $smarty->assign("filename", $recording_name);
                $smarty->assign("mb_message", $arrLang["To continue: record a message then click on save"]);
            } else {
                $smarty->assign("mb_title", $arrLang['ERROR'] . ":");
                $smarty->assign("mb_message", $arrLang["The call couldn't be realized"]);
            }
        }
    } else {
        $smarty->assign("mb_title", $arrLang["Validation Error"]);
        $smarty->assign("mb_message", $arrLang['Insert the Recording Name']);
    }
    return form_Recordings($smarty, $module_name, $local_templates_dir, $arrLang, $pDBACL);
}