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/rest/rest.php');
|
|
|
|
|
|
|
|
use Vn\Lib\Locale;
|
|
|
|
use Vn\Rest;
|
|
|
|
use Vn\Hedera\Web;
|
|
|
|
|
2015-08-17 18:02:14 +00:00
|
|
|
function myExitHandler ()
|
|
|
|
{
|
|
|
|
Web::deinit ();
|
|
|
|
Rest\Service::sendReply ();
|
2015-08-28 00:44:34 +00:00
|
|
|
closelog ();
|
2015-08-17 18:02:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function myGlobalErrorHandler ()
|
|
|
|
{
|
|
|
|
Rest\Service::setError ('PHP', 'internalError', 'An internal error has occurred');
|
|
|
|
myExitHandler ();
|
|
|
|
exit (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
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 ();
|
|
|
|
default:
|
|
|
|
Rest\Service::addWarning ('PHP', 'internalMessage', 'Something has gone wrong');
|
|
|
|
}
|
|
|
|
|
|
|
|
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');
|
|
|
|
|
2015-01-23 13:09:30 +00:00
|
|
|
Rest\Service::init ();
|
|
|
|
|
|
|
|
try {
|
2015-02-17 11:48:53 +00:00
|
|
|
Web::init ();
|
|
|
|
|
2015-01-23 13:09:30 +00:00
|
|
|
if (!Web::login ())
|
|
|
|
throw new Rest\Exception ('Auth', 'sessionExpired', s('SessionExpired'));
|
|
|
|
|
|
|
|
// Checking the client version
|
|
|
|
|
|
|
|
if (isset ($_COOKIE['hedera_version']))
|
|
|
|
{
|
|
|
|
$clientVersion = (float) $_COOKIE['hedera_version'];
|
|
|
|
|
2015-03-06 23:33:54 +00:00
|
|
|
if ($clientVersion < Web::getVersion ())
|
2015-01-23 13:09:30 +00:00
|
|
|
{
|
2015-03-06 23:33:54 +00:00
|
|
|
Web::sysInit ();
|
|
|
|
|
2015-01-23 13:09:30 +00:00
|
|
|
$row = Web::$sysConn->getRow (
|
|
|
|
'SELECT critical, changelog FROM version LIMIT 1');
|
|
|
|
|
|
|
|
if (!$row || $row['critical'])
|
|
|
|
throw new Rest\Exception ('Version', 'criticalVersion', $row['changelog']);
|
|
|
|
else
|
|
|
|
Rest\Service::addWarning ('Version', 'newVersion', $row['changelog']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Getting the action
|
|
|
|
|
|
|
|
$action = NULL;
|
|
|
|
|
|
|
|
if (isset ($_REQUEST['action']))
|
|
|
|
$action = $_REQUEST['action'];
|
|
|
|
|
|
|
|
if ($action && Vn\Hedera\checkToken ($action))
|
|
|
|
{
|
|
|
|
$actionFile = 'rest/'. $action .'.php';
|
|
|
|
|
|
|
|
if (file_exists ($actionFile))
|
|
|
|
{
|
|
|
|
Locale::addPath ('rest/'. $action);
|
|
|
|
require_once ($actionFile);
|
|
|
|
|
|
|
|
$module = new RestMod (Web::$conn);
|
|
|
|
Rest\Service::setData ($module->run ());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
throw new Rest\Exception ('Rest', 'invalidAction', s('InvalidAction'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Rest\Exception $e)
|
|
|
|
{
|
|
|
|
Rest\Service::setError ($e->getDomain (), $e->getCode (), $e->getMessage ());
|
|
|
|
}
|
|
|
|
|
2015-08-17 18:02:14 +00:00
|
|
|
myExitHandler ();
|
2015-01-23 13:09:30 +00:00
|
|
|
|
|
|
|
?>
|