1) { $verify_hash = argv(1); if ($verify_hash !== $resource) { logger('resource mismatch'); killme(); } } if (!$hash) { logger('no sender hash'); killme(); } foreach (['REDIRECT_REMOTE_USER', 'HTTP_AUTHORIZATION'] as $head) { if (array_key_exists($head, $_SERVER) && substr(trim($_SERVER[$head]), 0, 9) === 'Signature') { if ($head !== 'HTTP_AUTHORIZATION') { $_SERVER['HTTP_AUTHORIZATION'] = $_SERVER[$head]; continue; } $verified = HTTPSig::verify(''); if ($verified && $verified['header_signed'] && $verified['header_valid']) { $r = hubloc_id_addr_query($verified['signer'], 1); if ($r && $r[0]['hubloc_hash'] === $hash) { $header_verified = true; } } } } if (!$header_verified) { http_status_exit(403, 'Permission denied'); } $channel = Channel::from_hash($hash); if (!$channel) { logger('error: missing info'); killme(); } if ($resolution > 0) { $r = q( "select * from photo where resource_id = '%s' and uid = %d and imgscale = %d limit 1", dbesc($resource), intval($channel['channel_id']), intval($resolution) ); if ($r) { header('Content-type: ' . $r[0]['mimetype']); if (intval($r[0]['os_storage'])) { Stdio::fcopy(dbunescbin($r[0]['content']), 'php://output'); } else { echo dbunescbin($r[0]['content']); } } killme(); } $r = attach_by_hash($resource, $channel['channel_hash'], $revision); if (!$r['success']) { logger('attach_by_hash failed: ' . $r['message']); notice($r['message'] . EOL); return; } header('Content-type: ' . $r['data']['filetype']); header('Content-Disposition: attachment; filename="' . $r['data']['filename'] . '"'); if (intval($r['data']['os_storage'])) { Stdio::fcopy(dbunescbin($r['data']['content']),'php://output'); } else { echo dbunescbin($r['data']['content']); } killme(); } }