No direct script access allowed'); use IR\App\Helpers\Authentication; use IR\App\Helpers\Page; use IR\Core\Application; use IR\Http\Request; use IR\Mvc\Controller; class TrackingSystem extends Controller { protected $app; protected $authenticatedUser; public function init() { $this->app = Application::getCurrent(); $this->app->database('system')->connect(); if(!Authentication::isUserAuthenticated()) { Page::redirect($this->app->http->request->getBaseURL() . RDS . 'auth' . RDS . 'login.' . DEFAULT_EXTENSION); } Authentication::checkUserRoles(); $this->authenticatedUser = Authentication::getAuthenticatedUser(); } /** * @name main * @before init * @after closeConnections,checkForMessage */ public function main() { $this->masterView->set([ 'tracking_system' => 'true' ]); $this->pageView->set([ 'trackingIp' => '151.80.235.110' ]); } /** * @name checkStatus * @before init * @after closeConnections */ public function checkStatus() { $result = ['status' => 'error', 'message' => 'Unknown error', 'data' => []]; try { $trackingIp = '151.80.235.110'; $checks = []; $checks['config'] = ['name' => 'Configuration Files', 'status' => file_exists('/opt/wevads/config/init.conf.php') ? 'ok' : 'error']; $fp = @fsockopen($trackingIp, 80, $errno, $errstr, 5); $checks['connectivity'] = ['name' => 'Tracking Server', 'status' => $fp ? 'ok' : 'error', 'details' => ['ip' => $trackingIp]]; if($fp) fclose($fp); $allOk = $checks['config']['status'] == 'ok' && $checks['connectivity']['status'] == 'ok'; $result = ['status' => $allOk ? 'success' : 'warning', 'message' => $allOk ? 'All systems operational!' : 'Some issues detected', 'data' => ['checks' => $checks, 'tracking_ip' => $trackingIp]]; } catch (\Exception $e) { $result = ['status' => 'error', 'message' => $e->getMessage(), 'data' => []]; } die(json_encode($result)); } public function closeConnections() { $this->app->database('system')->disconnect(); } public function checkForMessage() { Page::checkForMessage($this); } }