X-Git-Url: https://git.cweiske.de/phancap.git/blobdiff_plain/d892ae8cecd67057e37656b2434dfb08aa7f709c..09ad15fd2ed08bbfb4ed4d70ff21f774387aa204:/www/get.php diff --git a/www/get.php b/www/get.php index 3d7395f..d4b70d3 100644 --- a/www/get.php +++ b/www/get.php @@ -1,8 +1,18 @@ + * @copyright 2014 Christian Weiske + * @license http://www.gnu.org/licenses/agpl.html GNU AGPL v3 + * @link http://cweiske.de/phancap.htm */ +namespace phancap; + header('HTTP/1.0 500 Internal Server Error'); if (file_exists(__DIR__ . '/../src/phancap/Autoloader.php')) { @@ -17,6 +27,7 @@ $config->load(); $options = new Options(); try { + $options->setConfig($config); $options->parse($_GET); } catch (\InvalidArgumentException $e) { header('HTTP/1.0 400 Bad Request'); @@ -35,14 +46,34 @@ try { exit(1); } +if (strpos($_SERVER['HTTP_USER_AGENT'], ' cutycapt ') !== false) { + //phancap is trying to render a page with an image that + // is being fetched from phancap itself, leading to an + // infinite loop + header('HTTP/1.0 500 Infinite Loop'); + header('Location: ' . $config->getCurrentUrlDir() . '/infinite.png'); + exit(3); +} + $rep = new Repository(); $rep->setConfig($config); try { $img = $rep->getImage($options); - header('HTTP/1.0 302 Found'); - header('Location: ' . $img->getUrl()); + if ($config->redirect) { + header('HTTP/1.0 302 Found'); + header('phancap-file: ' . $img->name); + header('Expires: ' . date('r', $img->getExpiryDate($options))); + header('Location: ' . $img->getUrl()); + } else { + header('HTTP/1.0 200 OK'); + header('phancap-file: ' . $img->name); + header('Content-Type: ' . $img->getMimeType()); + header('Content-Length: ' . filesize($img->getPath())); + readfile($img->getPath()); + } } catch (\Exception $e) { //FIXME: handle 404s and so properly + //FIXME: send out error image if images are preferred header('HTTP/1.0 500 Internal Server error'); header('Content-type: text/plain'); echo $e->getMessage() . "\n";