3 * Create a website screenshot API
9 * @author Christian Weiske <cweiske@cweiske.de>
10 * @copyright 2014 Christian Weiske
11 * @license http://www.gnu.org/licenses/agpl.html GNU AGPL v3
12 * @link http://cweiske.de/phancap.htm
16 header('HTTP/1.0 500 Internal Server Error');
18 if (file_exists(__DIR__ . '/../src/phancap/Autoloader.php')) {
19 include_once __DIR__ . '/../src/phancap/Autoloader.php';
20 Autoloader::register();
22 include_once 'phancap/Autoloader.php';
25 $config = new Config();
28 $options = new Options();
30 $options->setConfig($config);
31 $options->parse($_GET);
32 } catch (\InvalidArgumentException $e) {
33 header('HTTP/1.0 400 Bad Request');
34 header('Content-type: text/plain');
35 echo $e->getMessage() . "\n";
39 $auth = new Authenticator();
41 $auth->authenticate($config);
42 } catch (\Exception $e) {
43 header('HTTP/1.0 401 Unauthorized');
44 header('Content-type: text/plain');
45 echo $e->getMessage() . "\n";
49 if (strpos($_SERVER['HTTP_USER_AGENT'], ' cutycapt ') !== false) {
50 //phancap is trying to render a page with an image that
51 // is being fetched from phancap itself, leading to an
53 header('HTTP/1.0 500 Infinite Loop');
54 header('Location: ' . $config->getCurrentUrlDir() . '/infinite.png');
58 $rep = new Repository();
59 $rep->setConfig($config);
61 $img = $rep->getImage($options);
62 if ($config->redirect) {
63 header('HTTP/1.0 302 Found');
64 header('Expires: ' . date('r', $img->getExpiryDate($options)));
65 header('Location: ' . $img->getUrl());
67 header('Content-type: ' . $img->getMimeType());
68 readfile($img->getPath());
70 } catch (\Exception $e) {
71 //FIXME: handle 404s and so properly
72 //FIXME: send out error image if images are preferred
73 header('HTTP/1.0 500 Internal Server error');
74 header('Content-type: text/plain');
75 echo $e->getMessage() . "\n";