response con messaggio e codice errore in json) const ACCESS_WS_ERR = -2; // errore di accesso (lato WS => response con exit(0)) private $account = null; private $con = null; private $conSpid = null; public $lastEsito = 0; public $lastMessageError = ''; public function __construct() { return $this->_initApp(); } public function getAccount(){ return $this->account; } public function getCon(){ return $this->con; } public function getConSpid(){ return $this->conSpid; } /* CHECK IP ACCESS */ private function _checkIP() { $response = false; if (ENABLE_CHECK_IP) { if (!Utils::access_IP_control() && !Utils::checkCurrentPage('index')) { if (Utils::checkCurrentPage('_webservice')) { $this->lastEsito = self::ACCESS_ERR; $this->lastMessageError = 'Accesso scaduto: si prega di aggiornare la pagina ed effettuare il login al sistema.'; } else { Utils::RedirectTo(BASE_HTTP . "logout.php"); exit(0); } } else { $response = true; } } else { $response = true; } return $response; } /* SET DB CONNECTION */ private function _checkConnectionDB() { global $con, $conSpid; if (!isset($con)) { $connessione = new Database(DBMS, DB_SERVER, array('DB_USER' => DB_USER, 'DB_PASS' => DB_PASS)); $this->con = $connessione->db; } else { $this->con = $con; } if (!isset($conSpid)) { $connessioneSpid = new Database(DBMS, DB_SERVER, array('DB_USER' => DB_USER_SPID, 'DB_PASS' => DB_PASS_SPID)); $this->conSpid = $connessioneSpid->db; } else { $this->conSpid = $conSpid; } } private function _checkModuleAction(){ global $moduliActionAccessNoControll; $response = false; if (isset($_REQUEST["module"]) && isset($_REQUEST["action"])){ $module = $_REQUEST["module"]; $action = $_REQUEST["action"]; if (isset($moduliActionAccessNoControll[$module]) && in_array($action, $moduliActionAccessNoControll[$module])){ $response = true; } } return $response; } private function _initApp() { global $pageAccessNoControll; if ($this->_checkIP()) { session_start([ 'cookie_lifetime' => COOKIE_LIFETIME, ]); if (isset($_SESSION['ID']) && intval($_SESSION['ID']) > 0) { if (isset($_SESSION['LoggedAccount'])) { $this->lastEsito = self::SUCCESS; $this->account = Account::initAccountFromSessione(json_decode($_SESSION['LoggedAccount'], true)); } else { $this->lastEsito = self::SUCCESS; $this->account = new Account(intval($_SESSION['ID'])); } /* CONTROLLO SE NEL PERIODO DI ACCESSO HO I REQUISITI PER ACCEDERE AL SISTEMA */ if (Utils::checkCurrentPage('_webservice')) { if (!in_array($currentPageAccess, $pageAccessNoControll) && !$this->account->checkAuthApiFase()) { $this->lastEsito = self::ACCESS_WS_ERR; } } else if (!Utils::checkCurrentPage('info')) { $this->lastEsito = self::SUCCESS; $this->account->checkAuthPageFase(); } } else { $this->lastEsito = self::SUCCESS; $this->account = new Account(); $currentPageAccess = Utils::getCurrentPageCalled(); if (Utils::checkCurrentPage('_webservice') && (!in_array($currentPageAccess, $pageAccessNoControll) || !$this->_checkModuleAction())) { $this->lastEsito = self::ACCESS_ERR; $this->lastMessageError = 'Accesso scaduto: si prega di aggiornare la pagina ed effettuare il login al sistema.'; } else if (!in_array($currentPageAccess, $pageAccessNoControll) || Utils::isPrivatePageCalled()) { Utils::RedirectTo(BASE_HTTP . "index.php"); exit(0); } } } if ($this->lastEsito == self::SUCCESS){ $this->_checkConnectionDB(); } } } ?>