0
1
Fork 0
hedera-web-mindshore/package/usr/share/hedera-web/rest.php

71 lines
1.5 KiB
PHP
Raw Normal View History

<?php
require_once ('vn/hedera/web.php');
require_once ('vn/rest/rest.php');
use Vn\Lib\Locale;
use Vn\Rest;
use Vn\Hedera\Web;
Rest\Service::init ();
Web::init ();
try {
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'];
if ($clientVersion < $_SESSION['version'])
{
$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 ());
}
catch (Exception $e)
{
Rest\Service::setError ('PHP', 'exception', $e->getMessage ());
}
Web::deinit ();
Rest\Service::sendReply ();
?>