2017-08-04 16:28:16 +02:00
|
|
|
<?php
|
|
|
|
|
2018-06-28 15:52:56 +02:00
|
|
|
// Rimozione header X-Powered-By
|
|
|
|
header_remove('X-Powered-By');
|
|
|
|
|
2017-08-04 16:28:16 +02:00
|
|
|
// Impostazioni di configurazione PHP
|
|
|
|
date_default_timezone_set('Europe/Rome');
|
|
|
|
|
2018-02-22 09:34:46 +01:00
|
|
|
// Controllo sulla versione PHP
|
|
|
|
$minimum = '5.6.0';
|
|
|
|
if (version_compare(phpversion(), $minimum) < 0) {
|
|
|
|
echo '
|
|
|
|
<p>Stai utilizzando la versione PHP '.phpversion().', non compatibile con OpenSTAManager.</p>
|
|
|
|
|
|
|
|
<p>Aggiorna PHP alla versione >= '.$minimum.'.</p>';
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
2017-08-04 16:28:16 +02:00
|
|
|
// Caricamento delle impostazioni personalizzabili
|
|
|
|
if (file_exists(__DIR__.'/config.inc.php')) {
|
|
|
|
include_once __DIR__.'/config.inc.php';
|
|
|
|
}
|
|
|
|
|
|
|
|
// Caricamento delle dipendenze e delle librerie del progetto
|
2018-09-25 16:47:44 +02:00
|
|
|
$loader = require_once __DIR__.'/vendor/autoload.php';
|
|
|
|
|
|
|
|
$namespaces = require_once __DIR__.'/config/namespaces.php';
|
|
|
|
foreach ($namespaces as $path => $namespace) {
|
2018-09-26 12:06:24 +02:00
|
|
|
$loader->addPsr4($namespace.'\\', $path.'/custom/src');
|
|
|
|
$loader->addPsr4($namespace.'\\', $path.'/src');
|
2018-09-25 16:47:44 +02:00
|
|
|
}
|
2017-08-04 16:28:16 +02:00
|
|
|
|
2018-02-14 11:10:03 +01:00
|
|
|
// Individuazione dei percorsi di base
|
|
|
|
App::definePaths(__DIR__);
|
|
|
|
|
|
|
|
$docroot = DOCROOT;
|
|
|
|
$rootdir = ROOTDIR;
|
|
|
|
$baseurl = BASEURL;
|
|
|
|
|
2018-09-20 12:05:22 +02:00
|
|
|
$config = App::getConfig();
|
|
|
|
|
2017-08-07 13:07:18 +02:00
|
|
|
// Redirect al percorso HTTPS se impostato nella configurazione
|
2018-09-20 12:05:22 +02:00
|
|
|
if (!empty($config['redirectHTTPS']) && !isHTTPS(true)) {
|
2017-08-07 13:07:18 +02:00
|
|
|
header('HTTP/1.1 301 Moved Permanently');
|
|
|
|
header('Location: https://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
2018-07-03 15:39:29 +02:00
|
|
|
// Forza l'abilitazione del debug
|
|
|
|
// $debug = App::debug(true);
|
2017-08-04 16:28:16 +02:00
|
|
|
|
|
|
|
// Logger per la segnalazione degli errori
|
2017-09-15 16:37:19 +02:00
|
|
|
$logger = new Monolog\Logger('Logs');
|
2017-08-04 16:28:16 +02:00
|
|
|
$logger->pushProcessor(new Monolog\Processor\UidProcessor());
|
|
|
|
$logger->pushProcessor(new Monolog\Processor\WebProcessor());
|
|
|
|
|
2017-09-15 16:37:19 +02:00
|
|
|
// Registrazione globale del logger
|
|
|
|
Monolog\Registry::addLogger($logger, 'logs');
|
|
|
|
|
2017-08-04 16:28:16 +02:00
|
|
|
use Monolog\Handler\StreamHandler;
|
2017-09-15 16:37:19 +02:00
|
|
|
use Monolog\Handler\FilterHandler;
|
2017-08-04 16:28:16 +02:00
|
|
|
use Monolog\Handler\RotatingFileHandler;
|
|
|
|
|
|
|
|
$handlers = [];
|
2017-09-04 10:24:44 +02:00
|
|
|
if (!API::isAPIRequest()) {
|
|
|
|
// File di log di base (logs/error.log)
|
2018-02-14 11:10:03 +01:00
|
|
|
$handlers[] = new StreamHandler($docroot.'/logs/error.log', Monolog\Logger::ERROR);
|
|
|
|
$handlers[] = new StreamHandler($docroot.'/logs/setup.log', Monolog\Logger::EMERGENCY);
|
2017-09-04 10:24:44 +02:00
|
|
|
|
|
|
|
// Impostazioni di debug
|
2018-08-10 17:14:09 +02:00
|
|
|
if (App::debug()) {
|
2018-06-23 15:41:32 +02:00
|
|
|
// Ignora gli avvertimenti e le informazioni relative alla deprecazione di componenti
|
2017-09-20 10:33:22 +02:00
|
|
|
error_reporting(E_ALL & ~E_WARNING & ~E_NOTICE & ~E_USER_DEPRECATED);
|
2017-08-04 16:28:16 +02:00
|
|
|
|
2017-09-04 10:24:44 +02:00
|
|
|
// File di log ordinato in base alla data
|
2018-02-14 11:10:03 +01:00
|
|
|
$handlers[] = new RotatingFileHandler($docroot.'/logs/error.log', 0, Monolog\Logger::ERROR);
|
|
|
|
$handlers[] = new RotatingFileHandler($docroot.'/logs/setup.log', 0, Monolog\Logger::EMERGENCY);
|
2017-08-04 16:28:16 +02:00
|
|
|
|
2018-02-14 11:10:03 +01:00
|
|
|
$prettyPageHandler = new Whoops\Handler\PrettyPageHandler();
|
2017-08-04 16:28:16 +02:00
|
|
|
|
2018-02-14 11:10:03 +01:00
|
|
|
// Imposta Whoops come gestore delle eccezioni di default
|
|
|
|
$whoops = new Whoops\Run();
|
|
|
|
$whoops->pushHandler($prettyPageHandler);
|
2017-08-04 16:28:16 +02:00
|
|
|
|
2018-02-14 11:10:03 +01:00
|
|
|
// Abilita la gestione degli errori nel caso la richiesta sia di tipo AJAX
|
|
|
|
if (Whoops\Util\Misc::isAjaxRequest()) {
|
|
|
|
$whoops->pushHandler(new Whoops\Handler\JsonResponseHandler());
|
2017-09-04 10:24:44 +02:00
|
|
|
}
|
2018-02-14 11:10:03 +01:00
|
|
|
|
|
|
|
$whoops->register();
|
2017-08-04 16:28:16 +02:00
|
|
|
}
|
|
|
|
} else {
|
2018-02-14 11:10:03 +01:00
|
|
|
$handlers[] = new StreamHandler($docroot.'/logs/api.log', Monolog\Logger::ERROR);
|
2017-09-04 10:24:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Disabilita la segnalazione degli errori (se il debug è disabilitato)
|
2018-08-10 17:14:09 +02:00
|
|
|
if (!App::debug()) {
|
2017-08-04 16:28:16 +02:00
|
|
|
error_reporting(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Imposta il formato di salvataggio dei log
|
2018-05-11 14:48:46 +02:00
|
|
|
$pattern = '[%datetime%] %channel%.%level_name%: %message%';
|
2018-08-10 17:14:09 +02:00
|
|
|
if (App::debug()) {
|
2018-05-11 14:48:46 +02:00
|
|
|
$pattern .= ' %context%';
|
|
|
|
}
|
|
|
|
$pattern .= PHP_EOL.'%extra% '.PHP_EOL;
|
|
|
|
|
|
|
|
$monologFormatter = new Monolog\Formatter\LineFormatter($pattern);
|
|
|
|
|
2018-08-10 17:14:09 +02:00
|
|
|
if (App::debug()) {
|
2018-05-11 14:48:46 +02:00
|
|
|
$monologFormatter->includeStacktraces(true);
|
|
|
|
}
|
|
|
|
|
2017-08-04 16:28:16 +02:00
|
|
|
foreach ($handlers as $handler) {
|
2017-09-15 16:37:19 +02:00
|
|
|
$handler->setFormatter($monologFormatter);
|
|
|
|
$logger->pushHandler(new FilterHandler($handler, [$handler->getLevel()]));
|
2017-08-04 16:28:16 +02:00
|
|
|
}
|
|
|
|
|
2017-09-04 10:24:44 +02:00
|
|
|
// Imposta Monolog come gestore degli errori
|
2017-08-04 16:28:16 +02:00
|
|
|
Monolog\ErrorHandler::register($logger);
|
|
|
|
|
2018-08-10 17:14:09 +02:00
|
|
|
// Database
|
2018-09-20 12:05:22 +02:00
|
|
|
$dbo = $database = database();
|
2018-08-10 17:14:09 +02:00
|
|
|
|
2018-07-09 11:11:54 +02:00
|
|
|
// Inizializzazione della sessione
|
|
|
|
if (!API::isAPIRequest()) {
|
|
|
|
// Sicurezza della sessioni
|
|
|
|
ini_set('session.use_trans_sid', '0');
|
|
|
|
ini_set('session.use_only_cookies', '1');
|
|
|
|
|
|
|
|
session_set_cookie_params(0, $rootdir, null, isHTTPS(true));
|
|
|
|
session_start();
|
2018-08-10 17:14:09 +02:00
|
|
|
|
|
|
|
// Barra di debug (necessario per loggare tutte le query)
|
|
|
|
if (App::debug()) {
|
|
|
|
$debugbar = new DebugBar\DebugBar();
|
|
|
|
|
|
|
|
$debugbar->addCollector(new DebugBar\DataCollector\MemoryCollector());
|
|
|
|
$debugbar->addCollector(new DebugBar\DataCollector\PhpInfoCollector());
|
|
|
|
|
|
|
|
$debugbar->addCollector(new DebugBar\DataCollector\RequestDataCollector());
|
|
|
|
$debugbar->addCollector(new DebugBar\DataCollector\TimeDataCollector());
|
|
|
|
|
|
|
|
$debugbar->addCollector(new DebugBar\Bridge\MonologCollector($logger));
|
2018-09-20 11:39:03 +02:00
|
|
|
$debugbar->addCollector(new Extensions\EloquentCollector($dbo->getCapsule()));
|
2018-08-10 17:14:09 +02:00
|
|
|
}
|
2018-07-09 11:11:54 +02:00
|
|
|
}
|
|
|
|
|
2017-08-07 13:07:18 +02:00
|
|
|
// Istanziamento del gestore delle traduzioni del progetto
|
2018-09-20 12:05:22 +02:00
|
|
|
$lang = !empty($config['lang']) ? $config['lang'] : 'it';
|
|
|
|
$formatter = !empty($config['formatter']) ? $config['formatter'] : [];
|
|
|
|
$translator = trans();
|
2017-08-07 13:07:18 +02:00
|
|
|
$translator->addLocalePath($docroot.'/locale');
|
|
|
|
$translator->addLocalePath($docroot.'/modules/*/locale');
|
2017-09-19 16:20:44 +02:00
|
|
|
$translator->setLocale($lang, $formatter);
|
2017-08-04 16:28:16 +02:00
|
|
|
|
2017-08-07 13:07:18 +02:00
|
|
|
// Individuazione di versione e revisione del progetto
|
|
|
|
$version = Update::getVersion();
|
|
|
|
$revision = Update::getRevision();
|
2017-08-04 16:28:16 +02:00
|
|
|
|
2017-08-07 13:07:18 +02:00
|
|
|
// Controllo sulla presenza dei permessi di accesso basilari
|
2017-08-30 11:50:46 +02:00
|
|
|
$continue = $dbo->isInstalled() && !Update::isUpdateAvailable() && (Auth::check() || API::isAPIRequest());
|
|
|
|
|
2018-04-23 09:53:53 +02:00
|
|
|
if (!empty($skip_permissions)) {
|
|
|
|
Permissions::skip();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$continue && getURLPath() != slashes(ROOTDIR.'/index.php') && !Permissions::getSkip()) {
|
2017-09-11 18:12:41 +02:00
|
|
|
if (Auth::check()) {
|
|
|
|
Auth::logout();
|
|
|
|
}
|
|
|
|
|
|
|
|
redirect(ROOTDIR.'/index.php');
|
2017-08-04 16:28:16 +02:00
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
2017-08-07 13:07:18 +02:00
|
|
|
// Operazione aggiuntive (richieste non API)
|
|
|
|
if (!API::isAPIRequest()) {
|
2018-06-28 15:23:52 +02:00
|
|
|
// Impostazioni di Content-Type e Charset Header
|
|
|
|
header('Content-Type: text/html; charset=UTF-8');
|
|
|
|
|
2017-08-07 13:07:18 +02:00
|
|
|
// Controllo CSRF
|
2018-09-21 15:50:42 +02:00
|
|
|
if (empty($config['disableCSRF'])) {
|
|
|
|
csrfProtector::init();
|
|
|
|
}
|
2017-08-07 13:07:18 +02:00
|
|
|
|
|
|
|
// Aggiunta del wrapper personalizzato per la generazione degli input
|
2018-09-20 12:05:22 +02:00
|
|
|
if (!empty($config['HTMLWrapper'])) {
|
|
|
|
HTMLBuilder\HTMLBuilder::setWrapper($config['HTMLWrapper']);
|
2017-08-07 13:07:18 +02:00
|
|
|
}
|
2017-08-04 16:28:16 +02:00
|
|
|
|
2017-08-07 13:07:18 +02:00
|
|
|
// Aggiunta dei gestori personalizzati per la generazione degli input
|
2018-09-20 12:05:22 +02:00
|
|
|
foreach ((array) $config['HTMLHandlers'] as $key => $value) {
|
2017-08-07 13:07:18 +02:00
|
|
|
HTMLBuilder\HTMLBuilder::setHandler($key, $value);
|
|
|
|
}
|
2017-08-04 16:28:16 +02:00
|
|
|
|
2017-08-07 13:07:18 +02:00
|
|
|
// Aggiunta dei gestori per componenti personalizzate
|
2018-09-20 12:05:22 +02:00
|
|
|
foreach ((array) $config['HTMLManagers'] as $key => $value) {
|
2017-08-07 13:07:18 +02:00
|
|
|
HTMLBuilder\HTMLBuilder::setManager($key, $value);
|
|
|
|
}
|
2017-08-04 16:28:16 +02:00
|
|
|
|
2017-08-07 13:07:18 +02:00
|
|
|
// Registrazione globale del template per gli input HTML
|
|
|
|
register_shutdown_function('translateTemplate');
|
2018-06-28 15:23:52 +02:00
|
|
|
ob_start();
|
2017-08-07 13:07:18 +02:00
|
|
|
|
2018-07-19 12:47:28 +02:00
|
|
|
// Retrocompatibilità
|
2018-06-23 15:41:32 +02:00
|
|
|
$_SESSION['infos'] = isset($_SESSION['infos']) ? array_unique($_SESSION['infos']) : [];
|
|
|
|
$_SESSION['warnings'] = isset($_SESSION['warnings']) ? array_unique($_SESSION['warnings']) : [];
|
|
|
|
$_SESSION['errors'] = isset($_SESSION['errors']) ? array_unique($_SESSION['errors']) : [];
|
2017-08-07 13:07:18 +02:00
|
|
|
|
|
|
|
// Impostazione del tema grafico di default
|
2018-09-20 12:05:22 +02:00
|
|
|
$theme = !empty($config['theme']) ? $config['theme'] : 'default';
|
2017-08-07 13:07:18 +02:00
|
|
|
|
|
|
|
if ($continue) {
|
2018-05-11 14:48:46 +02:00
|
|
|
// Periodo di visualizzazione dei record
|
|
|
|
// Personalizzato
|
|
|
|
if (!empty($_GET['period_start'])) {
|
|
|
|
$_SESSION['period_start'] = $_GET['period_start'];
|
|
|
|
$_SESSION['period_end'] = $_GET['period_end'];
|
|
|
|
}
|
|
|
|
// Dal 01-01-yyy al 31-12-yyyy
|
|
|
|
elseif (!isset($_SESSION['period_start'])) {
|
|
|
|
$_SESSION['period_start'] = date('Y').'-01-01';
|
|
|
|
$_SESSION['period_end'] = date('Y').'-12-31';
|
|
|
|
}
|
|
|
|
|
2018-09-19 10:44:32 +02:00
|
|
|
$id_record = filter('id_record');
|
|
|
|
$id_parent = filter('id_parent');
|
2017-08-04 16:28:16 +02:00
|
|
|
|
2018-09-19 10:44:32 +02:00
|
|
|
Modules::setCurrent(filter('id_module'));
|
|
|
|
Plugins::setCurrent(filter('id_plugin'));
|
|
|
|
|
|
|
|
// Variabili fondamentali
|
|
|
|
$module = Modules::getCurrent();
|
|
|
|
$plugin = Plugins::getCurrent();
|
|
|
|
$structure = isset($plugin) ? $plugin : $module;
|
2017-08-04 16:28:16 +02:00
|
|
|
|
2018-09-19 10:44:32 +02:00
|
|
|
$id_module = $module['id'];
|
|
|
|
$id_plugin = $plugin['id'];
|
2017-08-07 13:07:18 +02:00
|
|
|
|
2018-09-19 10:44:32 +02:00
|
|
|
$user = Auth::user();
|
|
|
|
|
|
|
|
if (!empty($id_module)) {
|
2018-06-23 15:41:32 +02:00
|
|
|
// Segmenti
|
2018-07-19 09:58:28 +02:00
|
|
|
if (!isset($_SESSION['module_'.$id_module]['id_segment'])) {
|
2018-06-23 15:41:32 +02:00
|
|
|
$segments = Modules::getSegments($id_module);
|
2018-07-19 09:58:28 +02:00
|
|
|
$_SESSION['module_'.$id_module]['id_segment'] = isset($segments[0]['id']) ? $segments[0]['id'] : null;
|
2018-06-23 15:41:32 +02:00
|
|
|
}
|
|
|
|
|
2017-08-07 13:07:18 +02:00
|
|
|
Permissions::addModule($id_module);
|
2017-08-04 16:28:16 +02:00
|
|
|
}
|
|
|
|
|
2017-08-07 13:07:18 +02:00
|
|
|
Permissions::check();
|
2017-08-04 16:28:16 +02:00
|
|
|
}
|
|
|
|
|
2018-07-19 15:33:32 +02:00
|
|
|
// Retrocompatibilità
|
2017-09-04 10:24:44 +02:00
|
|
|
$post = Filter::getPOST();
|
|
|
|
$get = Filter::getGET();
|
|
|
|
}
|