Example #1
0
function display_record($smarty, $module_name, $local_templates_dir, &$pDB, $pACL, $arrConf, $user, $extension, $esAdministrador)
{
    $action = getParameter("action");
    $file = getParameter("id");
    $namefile = getParameter('namefile');
    $pMonitoring = new paloSantoMonitoring($pDB);
    $path_record = $arrConf['records_dir'];
    $sContenido = "";
    switch ($action) {
        case "display_record":
            if (!$esAdministrador) {
                if (!$pMonitoring->recordBelongsToUser($file, $extension)) {
                    $sContenido = _tr("You are not authorized to listen this file");
                }
            }
            if ($sContenido == "") {
                $session_id = session_id();
            }
            $ctype = record_format($pDB, $arrConf);
            $sContenido = <<<contenido
                    <embed src='index.php?menu={$module_name}&action=download&id={$file}&namefile={$namefile}&rawmode=yes&elastixSession={$session_id}' width=300, height=20 autoplay=true loop=false type="{$ctype}"></embed><br>
contenido;
            break;
    }
    $smarty->assign("CONTENT", $sContenido);
    $smarty->display("_common/popup.tpl");
}
Example #2
0
function downloadFile($smarty, $module_name, $local_templates_dir, &$pDB, $pACL, $arrConf, $user, $extension, $esAdministrador)
{
    $record = getParameter("id");
    $namefile = getParameter('namefile');
    $pMonitoring = new paloSantoMonitoring($pDB);
    if (!$esAdministrador) {
        if (!$pMonitoring->recordBelongsToUser($record, $extension)) {
            $smarty->assign("mb_title", _tr("ERROR"));
            $smarty->assign("mb_message", _tr("You are not authorized to download this file"));
            return reportMonitoring($smarty, $module_name, $local_templates_dir, $pDB, $pACL, $arrConf, $user, $extension, $esAdministrador);
        }
    }
    $path_record = $arrConf['records_dir'];
    if (is_null($record) || !preg_match('/^[[:digit:]]+\\.[[:digit:]]+$/', $record)) {
        // Missing or invalid uniqueid
        Header('HTTP/1.1 404 Not Found');
        die("<b>404 " . _tr("no_file") . " Missing or invalid uniqueid</b>");
    }
    /*
        // Check record is valid and points to an actual file
        $filebyUid = $pMonitoring->getAudioByUniqueId($record, $namefile);
        if (is_null($filebyUid) || count($filebyUid) <= 0) {
            // Uniqueid does not point to a record with specified file
            Header('HTTP/1.1 404 Not Found');
            die("<b>404 "._tr("no_file")." </b>");
        }
        $file = basename(str_replace('audio:', '', $filebyUid['userfield']));
    
    https://202.78.227.63/index.php?menu=recording&action=download&id=1391415467.79362
        &namefile=20140203-151828-1391415508.79388.gsm&rawmode=yes
    */
    $file = $namefile;
    $path = $path_record . $file;
    if ($file == 'deleted') {
        // Specified file has been deleted
        Header('HTTP/1.1 404 Not Found');
        die("<b>404 " . _tr("no_file") . " Specified file has been deleted</b>");
    }
    if (!file_exists($path)) {
        // Queue recordings might lack an extension
        $arrData = glob("{$path}*");
        if (count($arrData) > 0) {
            $path = $arrData[0];
            $file = basename($path);
        }
    }
    if (!file_exists($path) || !is_file($path)) {
        // Failed to find specified file
        Header('HTTP/1.1 404 Not Found');
        var_dump($path);
        die("<b>404 " . _tr("no_file") . " Failed to find specified file</b>");
    }
    // Set Content-Type according to file extension
    $contentTypes = array('wav' => 'audio/x-wav', 'gsm' => 'audio/x-gsm', 'mp3' => 'audio/mpeg');
    $extension = substr(strtolower($file), -3);
    if (!isset($contentTypes[$extension])) {
        // Unrecognized file extension
        Header('HTTP/1.1 404 Not Found');
        die("<b>404 " . _tr("no_file") . " </b>");
    }
    // Actually open and transmit the file
    $fp = fopen($path, 'rb');
    if (!$fp) {
        Header('HTTP/1.1 404 Not Found');
        die("<b>404 " . _tr("no_file") . " </b>");
    }
    header("Pragma: public");
    header("Expires: 0");
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    header("Cache-Control: public");
    header("Content-Description: wav file");
    header("Content-Type: " . $contentTypes[$extension]);
    header("Content-Disposition: attachment; filename=" . $file);
    header("Content-Transfer-Encoding: binary");
    header("Content-length: " . filesize($path));
    fpassthru($fp);
    fclose($fp);
}