2013-08-09 20:57:25 +04:00
|
|
|
<?php
|
2018-06-27 20:09:41 +03:00
|
|
|
|
2024-01-25 01:06:23 +03:00
|
|
|
if (version_compare(\PHP_VERSION, '7.4.0') === -1) {
|
|
|
|
http_response_code(500);
|
|
|
|
print 'RSS-Bridge requires minimum PHP version 7.4';
|
|
|
|
exit;
|
|
|
|
}
|
2018-06-27 20:09:41 +03:00
|
|
|
|
2024-02-02 20:06:08 +03:00
|
|
|
if (! is_readable(__DIR__ . '/lib/bootstrap.php')) {
|
|
|
|
http_response_code(500);
|
|
|
|
print 'Unable to read lib/bootstrap.php. Check file permissions.';
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
2024-01-25 01:06:23 +03:00
|
|
|
require_once __DIR__ . '/lib/bootstrap.php';
|
2023-10-12 23:14:04 +03:00
|
|
|
|
|
|
|
set_exception_handler(function (\Throwable $e) {
|
2024-01-25 01:06:23 +03:00
|
|
|
$response = new Response(render(__DIR__ . '/templates/exception.html.php', ['e' => $e]), 500);
|
|
|
|
$response->send();
|
2023-10-12 23:14:04 +03:00
|
|
|
RssBridge::getLogger()->error('Uncaught Exception', ['e' => $e]);
|
|
|
|
});
|
|
|
|
|
|
|
|
set_error_handler(function ($code, $message, $file, $line) {
|
|
|
|
if ((error_reporting() & $code) === 0) {
|
2024-01-25 01:06:23 +03:00
|
|
|
// Deprecation messages and other masked errors are typically ignored here
|
2023-10-12 23:14:04 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// In the future, uncomment this:
|
|
|
|
//throw new \ErrorException($message, 0, $code, $file, $line);
|
|
|
|
$text = sprintf(
|
|
|
|
'%s at %s line %s',
|
|
|
|
sanitize_root($message),
|
|
|
|
sanitize_root($file),
|
|
|
|
$line
|
|
|
|
);
|
|
|
|
RssBridge::getLogger()->warning($text);
|
|
|
|
});
|
|
|
|
|
|
|
|
// There might be some fatal errors which are not caught by set_error_handler() or \Throwable.
|
|
|
|
register_shutdown_function(function () {
|
|
|
|
$error = error_get_last();
|
|
|
|
if ($error) {
|
|
|
|
$message = sprintf(
|
|
|
|
'(shutdown) %s: %s in %s line %s',
|
|
|
|
$error['type'],
|
|
|
|
sanitize_root($error['message']),
|
|
|
|
sanitize_root($error['file']),
|
|
|
|
$error['line']
|
|
|
|
);
|
|
|
|
RssBridge::getLogger()->error($message);
|
|
|
|
if (Debug::isEnabled()) {
|
2024-01-25 01:06:23 +03:00
|
|
|
// This output can interfere with json output etc
|
|
|
|
// This output is written at the bottom
|
2023-10-12 23:14:04 +03:00
|
|
|
print sprintf("<pre>%s</pre>\n", e($message));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2024-01-25 01:06:23 +03:00
|
|
|
$errors = Configuration::checkInstallation();
|
|
|
|
if ($errors) {
|
|
|
|
http_response_code(500);
|
|
|
|
print '<pre>' . implode("\n", $errors) . '</pre>';
|
|
|
|
exit;
|
|
|
|
}
|
2024-01-09 22:33:35 +03:00
|
|
|
|
2024-01-25 01:06:23 +03:00
|
|
|
// Consider: ini_set('error_reporting', E_ALL & ~E_DEPRECATED);
|
|
|
|
|
|
|
|
date_default_timezone_set(Configuration::getConfig('system', 'timezone'));
|
|
|
|
|
|
|
|
try {
|
|
|
|
$rssBridge = new RssBridge();
|
|
|
|
$response = $rssBridge->main($argv ?? []);
|
|
|
|
$response->send();
|
|
|
|
} catch (\Throwable $e) {
|
|
|
|
// Probably an exception inside an action
|
|
|
|
RssBridge::getLogger()->error('Exception in RssBridge::main()', ['e' => $e]);
|
|
|
|
http_response_code(500);
|
|
|
|
print render(__DIR__ . '/templates/exception.html.php', ['e' => $e]);
|
|
|
|
}
|