Пример #1
0
    $mail = send_email($work->TO, $config['OPTS']['EMAIL_FROM'], $work->SUBJECT, $work->BODY);
    // Do some garbage collection and return results
    unset($work);
    gc_collect_cycles();
    return $mail;
});
$gmw->addFunction('fetch_media', function (GearmanJob $job) use(&$config) {
    $work = json_decode($job->workload());
    // This could be done using curl_multi, but we don't need parallelism
    // here since it's already a background task.
    $attachments = '';
    $fails = 0;
    for ($i = 0; $i < $work->MEDIA->NUMMEDIA; $i++) {
        $purl = parse_url($work->MEDIA->{'MEDIAURL' . $i});
        $url = unparse_url($purl, $config['ACCOUNTS'][$work->SID]['APISID'], $config['ACCOUNTS'][$work->SID]['APISECRET']);
        $filename = time() . '-' . sprintf('%u', crc32($url)) . '.' . mime_to_ext($work->MEDIA->{'MEDIACONTENTTYPE' . $i});
        // Fetch media item and write to file
        $ch = curl_init();
        $fp = fopen($config['OPTS']['MEDIA_PATH'] . '/' . $filename, 'w');
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_FILE, $fp);
        // Twilio media URLs are api.twilio.com, but they have redirects to Amazon AWS
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($ch, CURLOPT_MAXREDIRS, 3);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        $ex = curl_exec($ch);
        curl_close($ch);
        fclose($fp);
        // Delete the file if there was an error, and bump the fail count
        if ($ex === FALSE) {
Пример #2
0
foreach ($config['LOCALUSERS'] as $userhash) {
    $endhash = md5($_SERVER['REQUEST_METHOD'] . ':' . $data['uri']);
    $valid_response = md5($userhash . ':' . $data['nonce'] . ':' . $data['nc'] . ':' . $data['cnonce'] . ':' . $data['qop'] . ':' . $endhash);
    if ($data['response'] == $valid_response) {
        $authsuccess = 1;
        break;
    }
}
if (!$authsuccess) {
    die('Error: Username/password combination is invalid.  <a href="' . $_SERVER['REQUEST_URI'] . '&logout=true">Logout</a>, then try again.');
}
// All good, present the file
if ($fd = fopen($filepath, 'r')) {
    $fsize = filesize($filepath);
    $path_parts = pathinfo($filepath);
    $mime = mime_to_ext($path_parts['extension'], true);
    header('Content-type: ' . $mime);
    header('Content-Disposition: ' . (isset($_GET['dl']) ? 'attachment; ' : '') . 'filename="' . $path_parts['basename'] . '"');
    header('Content-length: ' . $fsize);
    header('Cache-control: private');
    while (!feof($fd)) {
        $buffer = fread($fd, 2048);
        print $buffer;
    }
}
fclose($fd);
exit;
// Parse and validate HTTP digest
function http_digest_parse($txt)
{
    $needed_parts = array('nonce' => 1, 'nc' => 1, 'cnonce' => 1, 'qop' => 1, 'username' => 1, 'uri' => 1, 'response' => 1);