2015-01-23 13:09:30 +00:00
|
|
|
<?php
|
|
|
|
|
2015-08-28 00:44:34 +00:00
|
|
|
openlog ('hedera-web', LOG_ODELAY, LOG_LOCAL0);
|
|
|
|
|
2015-01-23 13:09:30 +00:00
|
|
|
require_once ('vn/hedera/web.php');
|
|
|
|
require_once ('vn/hedera/js.php');
|
|
|
|
require_once ('vn/hedera/util.php');
|
|
|
|
|
|
|
|
use Vn\Hedera\Web;
|
|
|
|
use Vn\Lib\Locale;
|
|
|
|
|
2015-08-17 18:02:14 +00:00
|
|
|
function myExitHandler ()
|
|
|
|
{
|
|
|
|
Web::deinit ();
|
2015-08-28 00:44:34 +00:00
|
|
|
closelog ();
|
2015-02-17 11:48:53 +00:00
|
|
|
}
|
2015-08-17 18:02:14 +00:00
|
|
|
|
|
|
|
function myGlobalErrorHandler ()
|
2015-01-23 13:09:30 +00:00
|
|
|
{
|
2015-02-17 11:48:53 +00:00
|
|
|
header ('Location: unavailable.html');
|
2015-08-17 18:02:14 +00:00
|
|
|
myExitHandler ();
|
2015-01-23 13:09:30 +00:00
|
|
|
exit (0);
|
|
|
|
}
|
|
|
|
|
2015-08-17 18:02:14 +00:00
|
|
|
function myErrorHandler ($errno, $message, $file, $line, $context)
|
|
|
|
{
|
2015-08-28 00:44:34 +00:00
|
|
|
error_log ("Error: $file($line): $message");
|
2015-08-17 18:02:14 +00:00
|
|
|
|
|
|
|
switch ($errno)
|
|
|
|
{
|
|
|
|
case E_USER_ERROR:
|
|
|
|
myGlobalErrorHandler ();
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
function myExceptionHandler ($e)
|
|
|
|
{
|
2015-08-28 00:44:34 +00:00
|
|
|
error_log (sprintf ('Exception: %s(%d): %s. Trace: %s'
|
|
|
|
,$e->getFile ()
|
|
|
|
,$e->getLine ()
|
|
|
|
,$e->getMessage ()
|
|
|
|
,$e->getTraceAsString ()
|
|
|
|
));
|
2015-08-17 18:02:14 +00:00
|
|
|
myGlobalErrorHandler ();
|
|
|
|
}
|
|
|
|
|
|
|
|
set_error_handler ('myErrorHandler', E_ALL);
|
|
|
|
set_exception_handler ('myExceptionHandler');
|
|
|
|
|
|
|
|
Web::sysInit ();
|
|
|
|
|
2015-03-15 12:44:57 +00:00
|
|
|
if (!Web::isHttps () && Web::$sysConn->getValue ('SELECT https FROM config'))
|
2015-01-23 13:09:30 +00:00
|
|
|
{
|
2015-02-17 11:48:53 +00:00
|
|
|
header ("Location: https://${_SERVER['SERVER_NAME']}${_SERVER['REQUEST_URI']}");
|
2015-01-23 13:09:30 +00:00
|
|
|
exit (0);
|
|
|
|
}
|
|
|
|
|
2015-03-15 12:44:57 +00:00
|
|
|
Web::init ();
|
|
|
|
|
2015-01-31 01:05:12 +00:00
|
|
|
// Getting the requested page
|
2015-01-23 13:09:30 +00:00
|
|
|
|
|
|
|
if (isset ($_GET['page']) && Vn\Hedera\checkToken ($_GET['page']))
|
|
|
|
$page = $_GET['page'];
|
|
|
|
else
|
2015-09-16 16:11:15 +00:00
|
|
|
$page = 'main';
|
2015-01-23 13:09:30 +00:00
|
|
|
|
|
|
|
// Checking the browser version
|
|
|
|
|
|
|
|
if (!isset ($_SESSION['skipBrowser']) && $page != 'update-browser')
|
|
|
|
{
|
|
|
|
$updateBrowser = FALSE;
|
|
|
|
|
|
|
|
if (!isset ($_GET['skipBrowser'])
|
|
|
|
&& ($browser = get_browser ($_SERVER['HTTP_USER_AGENT'])))
|
|
|
|
{
|
|
|
|
$browserVersion = $browser->version;
|
|
|
|
set_type ($browserVersion, TYPE_DOUBLE);
|
|
|
|
|
|
|
|
$minVersion = Web::$sysConn->getValue (
|
|
|
|
'SELECT version FROM browser WHERE name = #', [$browser->browser]);
|
|
|
|
|
|
|
|
$updateBrowser = $browserVersion > 0
|
|
|
|
&& isset ($minVersion) && $browserVersion < $minVersion;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($updateBrowser)
|
|
|
|
{
|
|
|
|
header ('Location: ?page=update-browser');
|
|
|
|
exit (0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
$_SESSION['skipBrowser'] = TRUE;
|
|
|
|
}
|
|
|
|
|
2015-09-01 14:10:44 +00:00
|
|
|
// If enabled, requests the user to choose between two web versions
|
|
|
|
|
|
|
|
if (FALSE && !isset ($_SESSION['skipVersionMenu']) && $page != 'version-menu')
|
|
|
|
{
|
|
|
|
$_SESSION['skipVersionMenu'] = TRUE;
|
|
|
|
header ('Location: ?page=version-menu');
|
|
|
|
}
|
|
|
|
|
2015-02-17 11:48:53 +00:00
|
|
|
// Setting the version
|
|
|
|
|
2015-03-06 23:33:54 +00:00
|
|
|
setcookie ('hedera_version', Web::getVersion ());
|
2015-02-17 11:48:53 +00:00
|
|
|
|
2015-01-31 01:05:12 +00:00
|
|
|
// Loading the requested page
|
2015-01-23 13:09:30 +00:00
|
|
|
|
|
|
|
$basePath = 'pages/'. $page;
|
|
|
|
|
|
|
|
header ('Content-Type: text/html; charset=utf-8');
|
|
|
|
|
|
|
|
if (file_exists ($basePath))
|
|
|
|
{
|
|
|
|
Locale::addPath ($basePath);
|
|
|
|
|
|
|
|
$phpFile = $basePath .'/'. $page .'.php';
|
|
|
|
|
|
|
|
if (file_exists ($phpFile))
|
|
|
|
require ($phpFile);
|
|
|
|
|
|
|
|
require ($basePath .'/html.php');
|
|
|
|
}
|
|
|
|
|
2015-08-17 18:02:14 +00:00
|
|
|
myExitHandler ();
|
2015-01-23 13:09:30 +00:00
|
|
|
|
|
|
|
?>
|