X-Git-Url: https://git.cweiske.de/phancap.git/blobdiff_plain/62875bdbecc633496c712bc2fc5e0ef8f54733e3..00e918bc6ce0439f9245ce6335925d8e1e042cc2:/www/get.php diff --git a/www/get.php b/www/get.php index 5212e99..f78c3b5 100644 --- a/www/get.php +++ b/www/get.php @@ -1,8 +1,20 @@ + * @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')) { include_once __DIR__ . '/../src/phancap/Autoloader.php'; Autoloader::register(); @@ -10,15 +22,48 @@ if (file_exists(__DIR__ . '/../src/phancap/Autoloader.php')) { include_once 'phancap/Autoloader.php'; } +$config = new Config(); +$config->load(); + $options = new Options(); try { + $options->setConfig($config); $options->parse($_GET); } catch (\InvalidArgumentException $e) { header('HTTP/1.0 400 Bad Request'); header('Content-type: text/plain'); - echo $e->getMessage(); + echo $e->getMessage() . "\n"; exit(1); } -var_dump($options->values); +$auth = new Authenticator(); +try { + $auth->authenticate($config); +} catch (\Exception $e) { + header('HTTP/1.0 401 Unauthorized'); + header('Content-type: text/plain'); + echo $e->getMessage() . "\n"; + exit(1); +} + +$rep = new Repository(); +$rep->setConfig($config); +try { + $img = $rep->getImage($options); + if ($config->redirect) { + header('HTTP/1.0 302 Found'); + header('Expires: ' . date('r', $img->getExpiryDate($options))); + header('Location: ' . $img->getUrl()); + } else { + header('Content-type: ' . $img->getMimeType()); + 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"; + exit(2); +} ?>