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-28 10:15:05 +02:00
|
|
|
$loader->addPsr4($namespace.'\\', __DIR__.'/'.$path.'/custom/src');
|
|
|
|
$loader->addPsr4($namespace.'\\', __DIR__.'/'.$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-12-28 08:07:56 +01:00
|
|
|
/* GESTIONE DEGLI ERRORI */
|
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');
|
|
|
|
|
|
|
|
use Monolog\Handler\FilterHandler;
|
2017-08-04 16:28:16 +02:00
|
|
|
use Monolog\Handler\RotatingFileHandler;
|
2018-12-29 12:03:22 +01:00
|
|
|
use Monolog\Handler\StreamHandler;
|
2017-08-04 16:28:16 +02:00
|
|
|
|
|
|
|
$handlers = [];
|
2019-07-19 15:23:00 +02:00
|
|
|
if (!API\Response::isAPIRequest()) {
|
2019-01-11 12:02:11 +01:00
|
|
|
// File di log di base (logs/error.log, logs/setup.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);
|
2019-01-11 12:02:11 +01:00
|
|
|
|
|
|
|
// Messaggi grafici per l'utente
|
2019-01-06 14:18:48 +01:00
|
|
|
$handlers[] = new Extensions\MessageHandler(Monolog\Logger::ERROR);
|
2017-09-04 10:24:44 +02:00
|
|
|
|
2019-01-11 12:02:11 +01:00
|
|
|
// File di log ordinati in base alla data
|
2018-08-10 17:14:09 +02:00
|
|
|
if (App::debug()) {
|
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);
|
2019-01-11 12:02:11 +01:00
|
|
|
}
|
2017-08-04 16:28:16 +02:00
|
|
|
|
2019-01-11 12:02:11 +01:00
|
|
|
// Inizializzazione Whoops
|
|
|
|
$whoops = new Whoops\Run();
|
2017-08-04 16:28:16 +02:00
|
|
|
|
2019-01-15 19:01:25 +01:00
|
|
|
if (App::debug()) {
|
2019-01-11 12:02:11 +01:00
|
|
|
$whoops->pushHandler(new Whoops\Handler\PrettyPageHandler());
|
|
|
|
}
|
2018-02-14 11:10:03 +01:00
|
|
|
|
2019-01-11 12:02:11 +01:00
|
|
|
// Abilita la gestione degli errori nel caso la richiesta sia di tipo AJAX
|
2019-01-15 19:01:25 +01:00
|
|
|
if (Whoops\Util\Misc::isAjaxRequest()) {
|
2019-01-11 12:02:11 +01:00
|
|
|
$whoops->pushHandler(new Whoops\Handler\JsonResponseHandler());
|
2017-08-04 16:28:16 +02:00
|
|
|
}
|
2019-01-11 12:02:11 +01:00
|
|
|
|
|
|
|
$whoops->register();
|
2019-02-15 10:42:39 +01:00
|
|
|
|
|
|
|
// Aggiunta di Monolog a Whoops
|
|
|
|
$whoops->pushHandler(function ($exception, $inspector, $run) use ($logger) {
|
|
|
|
$logger->addError($exception->getMessage(), [
|
|
|
|
'code' => $exception->getCode(),
|
|
|
|
'message' => $exception->getMessage(),
|
|
|
|
'file' => $exception->getFile(),
|
|
|
|
'line' => $exception->getLine(),
|
|
|
|
'trace' => $exception->getTraceAsString(),
|
|
|
|
]);
|
|
|
|
});
|
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
|
|
|
}
|
|
|
|
|
2019-01-11 12:02:11 +01:00
|
|
|
// Disabilita i messaggi nativi di PHP
|
|
|
|
ini_set('display_errors', 0);
|
|
|
|
// Ignora gli avvertimenti e le informazioni relative alla deprecazione di componenti
|
|
|
|
error_reporting(E_ALL & ~E_WARNING & ~E_NOTICE & ~E_USER_DEPRECATED & ~E_STRICT);
|
2018-05-11 14:48:46 +02:00
|
|
|
|
2019-01-11 12:02:11 +01:00
|
|
|
$pattern = '[%datetime%] %channel%.%level_name%: %message% %context%'.PHP_EOL.'%extra% '.PHP_EOL;
|
2018-05-11 14:48:46 +02:00
|
|
|
$monologFormatter = new Monolog\Formatter\LineFormatter($pattern);
|
2019-01-11 12:02:11 +01:00
|
|
|
$monologFormatter->includeStacktraces(App::debug());
|
2018-05-11 14:48:46 +02:00
|
|
|
|
2019-01-06 14:18:48 +01:00
|
|
|
// Filtra gli errori per livello preciso del gestore dedicato
|
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
|
2019-01-06 14:18:48 +01:00
|
|
|
Monolog\ErrorHandler::register($logger, [], Monolog\Logger::ERROR, Monolog\Logger::ERROR);
|
2017-08-04 16:28:16 +02:00
|
|
|
|
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-12-28 08:07:56 +01:00
|
|
|
/* SESSIONE */
|
2019-07-19 15:23:00 +02:00
|
|
|
if (!API\Response::isAPIRequest()) {
|
2018-07-09 11:11:54 +02:00
|
|
|
// 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
|
|
|
}
|
|
|
|
|
2018-12-28 08:07:56 +01:00
|
|
|
/* INTERNAZIONALIZZAZIONE */
|
2017-08-07 13:07:18 +02:00
|
|
|
// Istanziamento del gestore delle traduzioni del progetto
|
2019-08-02 13:21:21 +02:00
|
|
|
$lang = !empty($config['lang']) ? $config['lang'] : $_GET['lang'];
|
2018-09-20 12:05:22 +02:00
|
|
|
$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
|
|
|
|
2018-12-28 08:07:56 +01:00
|
|
|
/* ACCESSO E INSTALLAZIONE */
|
2017-08-07 13:07:18 +02:00
|
|
|
// Controllo sulla presenza dei permessi di accesso basilari
|
2019-07-19 15:23:00 +02:00
|
|
|
$continue = $dbo->isInstalled() && !Update::isUpdateAvailable() && (Auth::check() || API\Response::isAPIRequest());
|
2017-08-30 11:50:46 +02:00
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2018-12-28 08:07:56 +01:00
|
|
|
/* INIZIALIZZAZIONE GENERALE */
|
2017-08-07 13:07:18 +02:00
|
|
|
// Operazione aggiuntive (richieste non API)
|
2019-07-19 15:23:00 +02:00
|
|
|
if (!API\Response::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');
|
2019-07-26 11:57:59 +02:00
|
|
|
$id_record = $id_record == $id_parent ? '' : $id_record;
|
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();
|
|
|
|
}
|
2019-01-11 12:02:11 +01:00
|
|
|
|
|
|
|
// Inclusione dei file modutil.php
|
|
|
|
// TODO: sostituire * con lista module dir {aggiornamenti,anagrafiche,articoli}
|
|
|
|
// TODO: sostituire tutte le funzioni dei moduli con classi Eloquent relative
|
|
|
|
$files = glob(__DIR__.'/{modules,plugins}/*/modutil.php', GLOB_BRACE);
|
|
|
|
$custom_files = glob(__DIR__.'/{modules,plugins}/*/custom/modutil.php', GLOB_BRACE);
|
|
|
|
foreach ($custom_files as $key => $value) {
|
|
|
|
$index = array_search(str_replace('custom/', '', $value), $files);
|
|
|
|
if ($index !== false) {
|
|
|
|
unset($files[$index]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$list = array_merge($files, $custom_files);
|
|
|
|
foreach ($list as $file) {
|
|
|
|
include_once $file;
|
|
|
|
}
|
2019-07-19 16:51:52 +02:00
|
|
|
|
|
|
|
// Inclusione dei file vendor/autoload.php di Composer
|
|
|
|
$files = glob(__DIR__.'/{modules,plugins}/*/vendor/autoload.php', GLOB_BRACE);
|
|
|
|
$custom_files = glob(__DIR__.'/{modules,plugins}/*/custom/vendor/autoload.php', GLOB_BRACE);
|
|
|
|
foreach ($custom_files as $key => $value) {
|
|
|
|
$index = array_search(str_replace('custom/', '', $value), $files);
|
|
|
|
if ($index !== false) {
|
|
|
|
unset($files[$index]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$list = array_merge($files, $custom_files);
|
|
|
|
foreach ($list as $file) {
|
|
|
|
include_once $file;
|
|
|
|
}
|