| Server IP : 37.9.174.138 / Your IP : 216.73.216.117 Web Server : Apache System : Linux vps6.backend.sk 6.12.100+deb13-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.12.100-1 (2026-07-30) x86_64 User : ftpuser ( 1001) PHP Version : 8.4.24 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /var/www/html/ttjs.cz/dev/app/classes/ |
Upload File : |
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
* Description of ApiClass
*
* @author Maroš
*/
namespace app\classes;
class ApiClass {
/** @var UrlReader */
protected $urlReader;
/** @var RestApi */
protected $restApi;
/** @var \App */
protected $app;
/** @var Translator */
protected $translator;
/** @var ModuleConfig */
protected $cnfg;
/** @var BasicUser */
protected $loggedUser;
protected $requiresAuth = true;
protected $table;
public function __construct() {
$this->app = \App::getInstance();
$this->urlReader = UrlReader::getInstance();
$this->restApi = RestApi::getInstance();
$rc = new \ReflectionClass(get_class($this));
$this->cnfg = new ModuleConfig($rc->getFileName());
$this->translator = Translator::getInstance();
if ($this->requiresAuth) {
usleep(150000);
$this->verifyAuth();
} else {
usleep(rand(15000, 20000) * 100);
}
}
protected function verifyAuth() {
try {
$this->loggedUser = BasicUser::getLoggedUser();
} catch (\Exception $ex) {
try {
if (!isset(getallheaders()["Authorization"])) {
throw new \Exception(\app\constants\ResponseCodes::UNAUTHORIZED, \app\constants\ResponseCodes::UNAUTHORIZED);
}
$token = getallheaders()["Authorization"];
$tokenParse = explode("|", $token);
if (count($tokenParse) !== 2) {
throw new \Exception(\app\constants\ResponseCodes::INVALID_AUTH_TOKEN, \app\constants\ResponseCodes::INVALID_AUTH_TOKEN);
}
$user = new \app\classes\BasicUser($tokenParse[0], false, false, false, array(\app\constants\UserType::ENGINEER, \app\constants\UserType::ENGINEER_OPERATOR));
if ($user->authorize($token) === false) {
throw new \Exception(\app\constants\ResponseCodes::INVALID_AUTH_TOKEN, \app\constants\ResponseCodes::INVALID_AUTH_TOKEN);
}
$this->loggedUser = $user;
} catch (\Exception $ex) {
$errCode = $ex->getCode();
if ($errCode === 404) {
$errCode = \app\constants\ResponseCodes::INVALID_AUTH_TOKEN;
}
$this->restApi->setCode($errCode);
$this->restApi->setHttpResponseCode($errCode);
$this->restApi->ajaxResponse();
}
}
}
protected function setUnlockAlways(\modules\locks\code\Lock $lock) {
$unlockFunc = function () use ($lock) {
$lock->unlock();
};
$this->restApi->setAlwaysFunction($unlockFunc);
}
protected function verifyLock($lockColumn = "id", $lockId = false, $lockTable = false) {
$lock = \modules\locks\code\Lock::getLock($lockId === false ? $this->urlReader->getPost($lockColumn) : $lockId, $lockTable === false ? $this->table : $lockTable);
$lock->lock();
$this->setUnlockAlways($lock);
}
protected function verifyRights($element, $array, $function = "in_array") {
if ($function === "in_array") {
if (!in_array($element, $array)) {
throw new \Exception(\app\constants\ResponseCodes::ACCESS_DENIED, \app\constants\ResponseCodes::ACCESS_DENIED);
}
} else {
if (!key_exists($element, $array)) {
throw new \Exception(\app\constants\ResponseCodes::ACCESS_DENIED, \app\constants\ResponseCodes::ACCESS_DENIED);
}
}
}
}