Non puoi selezionare più di 25 argomenti
Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
432 righe
14 KiB
432 righe
14 KiB
<?php |
|
|
|
global $root; |
|
global $beRoot; |
|
global $config; |
|
global $pdo; |
|
|
|
$realRoot = __DIR__; |
|
$root = __DIR__ . "/public_html"; |
|
$beRoot = __DIR__ . "/public_html/backend/"; |
|
|
|
$config = []; |
|
if(! file_exists(__DIR__ . "/config.json")) { |
|
// The config.json file does not exist. |
|
die('<h1 style="text-align: center; margin-top: 100px; color: red;">IMPOSSIBILE ACCEDERE ALLA CONFIGURAZIONE DEL SITO.<br><small>IMPOSSIBILE AVVIARE L'APPLICATIVO!!</small></h1>'); |
|
} |
|
|
|
$config = json_decode(file_get_contents(__DIR__ . "/config.json"),true); |
|
if($config === NULL) { |
|
// The config.json file is lacking the proper format. |
|
die('<h1 style="text-align: center; margin-top: 100px; color: red;">IMPOSSIBILE PROCESSARE LA CONFIGURAZIONE DEL SITO.<br><small>IMPOSSIBILE AVVIARE L'APPLICATIVO!!</small></h1>'); |
|
} |
|
|
|
$config["first_level"] = __DIR__; |
|
$config["chunk_folder"] = sys_get_temp_dir(); |
|
$config["cmds_folder"] = __DIR__."/cmds"; |
|
$config["bash_folder"] = __DIR__."/bash"; |
|
$config["cafolder"] = __DIR__."/cainfo"; |
|
$config["mediaFolder"] = __DIR__ . "/media"; |
|
$config["simog_folder"] = __DIR__."/simog"; |
|
$config["path_vocabolario"] = __DIR__."/vocabolario"; |
|
$config["jsonFolder"] = __DIR__."/json"; |
|
$config["mailFolder"] = __DIR__."/mail"; |
|
$config["user_log"] = __DIR__."/logs/user-activity"; |
|
$config["db_log"] = __DIR__."/logs/db-ops"; |
|
$config["queue_log"] = __DIR__ . "/logs/queue"; |
|
$config["npaFolder"] = __DIR__."/logs/npa"; |
|
$config["themesFolder"] = "/src/css/themes/"; |
|
$config["protocollo"] = "https://"; |
|
if (!empty($config["redirects"]) && isset($_SERVER["SERVER_NAME"])) { |
|
$redirect = $config["redirects"][$_SERVER["SERVER_NAME"]] ?? null; |
|
if (!empty($redirect)) { |
|
header("HTTP/1.1 301 Moved Permanently"); |
|
header("Location: {$config["protocollo"]}{$redirect}"); |
|
exit(); |
|
die(); |
|
} |
|
} |
|
$demoEnv = $config["demoEnv"]; |
|
$developEnv = $config["developEnv"]; |
|
|
|
date_default_timezone_set('Europe/Rome'); |
|
ini_set('display_errors', 0); |
|
ini_set('display_startup_errors', 0); |
|
error_reporting(E_ALL); |
|
|
|
$ipDisableCaptcha = ["79.8.46.241"]; |
|
|
|
$config["ipExetendedAPI"] = ["213.215.222.192", "79.8.46.241", "172.17.2.34"]; |
|
$config["publicFrontEnd"] = ""; |
|
|
|
putenv("GOOGLE_APPLICATION_CREDENTIALS=".__DIR__."/file"); |
|
if (! file_exists($config["queue_log"])) { mkdir($config["queue_log"],0777,true); } |
|
|
|
$demoEnv = $config["demoEnv"]; |
|
$developEnv = $config["developEnv"]; |
|
$manutenzione = false; |
|
|
|
if (isset($_SERVER["DEMO_ENV"]) && $_SERVER["DEMO_ENV"] === "true") { |
|
$demoEnv = TRUE; |
|
} |
|
|
|
if (isset($_SERVER["DEVELOP_ENV"]) && $_SERVER["DEVELOP_ENV"] === "true") { |
|
$developEnv = TRUE; |
|
} |
|
|
|
if (!defined('DEMO_ENV')) { |
|
define('DEMO_ENV', $demoEnv); |
|
} |
|
|
|
if (!defined('DEVELOP_ENV')) { |
|
define('DEVELOP_ENV', $developEnv); |
|
} |
|
|
|
if (!defined('ROOT_FOLDER')) { |
|
define('ROOT_FOLDER', __DIR__); |
|
} |
|
|
|
// Check for possible redirects |
|
if($config["protocollo"] == "http://" && ! DEVELOP_ENV && php_sapi_name() != "cli") { |
|
header("Location: https://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"); |
|
exit; |
|
} |
|
|
|
// Check for any enforced redirects L301. |
|
$config["link_sito"] = "{$config["protocollo"]}{$config["link_sito"]}"; |
|
if (! empty($config["redirects"]) && isset($_SERVER["SERVER_NAME"]) && ! empty($config["redirects"][$_SERVER["SERVER_NAME"]])) { |
|
header("HTTP/1.1 301 Moved Permanently"); |
|
header("Location: {$config["protocollo"]}{$config["redirects"][$_SERVER["SERVER_NAME"]]}"); |
|
exit; |
|
} |
|
|
|
// Check if the captcha needs to be disabled. |
|
$disableCaptcha = $config["disableCaptcha"]; |
|
$ipDisableCaptcha = ["93.67.152.242","79.8.46.252"]; |
|
if ((isset($_SERVER["REMOTE_ADDR"]) && in_array($_SERVER["REMOTE_ADDR"], $ipDisableCaptcha) !== FALSE) || $developEnv) { |
|
$disableCaptcha = TRUE; |
|
} |
|
|
|
date_default_timezone_set('Europe/Rome'); |
|
|
|
error_reporting(E_ALL); |
|
ini_set('display_errors', 0); |
|
ini_set('display_startup_errors', 0); |
|
|
|
if (DEVELOP_ENV) { |
|
ini_set('display_errors', 1); |
|
ini_set('display_startup_errors', 1); |
|
} |
|
|
|
$includes = [ |
|
"{$root}/inc/pdo.class.php", |
|
"{$root}/inc/save.class.php", |
|
"{$beRoot}/enti/settingsManager.class.php", |
|
"{$beRoot}/utenti/utente.class.php", |
|
"{$beRoot}/enti/ente.class.php", |
|
"{$beRoot}/albo/oeManager.class.php", |
|
"{$root}/inc/modulo.class.php", |
|
"{$beRoot}/form/formManager.class.php", |
|
"{$root}/allegati/filesManager.class.php", |
|
"{$root}/inc/cpvManager.class.php", |
|
"{$root}/inc/xml2json.php", |
|
"{$root}/inc/communicator.class.php", |
|
"{$root}/inc/dotPath.class.php", |
|
"{$beRoot}/common/massiveHelper/massiveHelper.class.php", |
|
"{$root}/inc/documentConverter.php", |
|
"{$root}/inc/tuttogareMath.class.php", |
|
"{$beRoot}/common/alertManager/alertManager.class.php", |
|
"{$root}/spid/spid.class.php", |
|
"{$beRoot}/common/pdnd/pdnd.class.php", |
|
"{$root}/inc/dataverifier.class.php", |
|
"{$root}/inc/funzioni.php", |
|
"{$root}/inc/p7m.class.php", |
|
"{$beRoot}/common/dgue/dgue.class.php", |
|
"{$beRoot}/common/dgue/models/modelBase.class.php", |
|
"{$beRoot}/common/richiesteOE/richiesteOE.class.php", |
|
"{$root}/richieste/publicRichiesteOE.class.php", |
|
"{$root}/common/busteOE/busteOE.class.php", |
|
"{$beRoot}/common/commissioni/commissione.class.php", |
|
"{$beRoot}/common/registri/registri.class.php", |
|
"{$beRoot}/common/avvisi/avvisiProcedura.class.php", |
|
"{$beRoot}/editor/editorManager.class.php", |
|
"{$beRoot}/report/reportManager.class.php", |
|
"{$beRoot}/common/pubblicitaLegale/pubblicitaLegale.class.php", |
|
"{$beRoot}/common/incarichi/incarichi.class.php", |
|
"{$root}/inc/integrazioni/integrazione.class.php", |
|
|
|
]; |
|
|
|
$__include_autoload = true; |
|
$__included_files = get_included_files(); |
|
$__included_files = array_filter($__included_files, fn($path) => strpos($path, "/cmds")); |
|
if(! empty($__included_files)) { |
|
$__included_files = array_map(fn (&$path) => substr($path, strpos($path, "/cmds")), $__included_files); |
|
$__included_files = array_flip($__included_files); |
|
if(isset($__included_files["/cmds/vendor/autoload.php"])) { |
|
$__include_autoload = false; |
|
} |
|
} |
|
|
|
if($__include_autoload) { |
|
$includes[] = __DIR__."/vendor/autoload.php"; |
|
$includes[] = "{$root}/inc/TCPDFwFooter.class.php"; |
|
} |
|
|
|
if (DEVELOP_ENV || DEMO_ENV) { |
|
$includes[] = "{$root}/inc/testCaseExecute.class.php"; |
|
} |
|
|
|
foreach($includes AS $_requiredFile) { |
|
require_once $_requiredFile; |
|
} |
|
|
|
$config["moduli"] = Modulo::getModuli(); |
|
|
|
foreach($config["moduli"] AS $_mod) { |
|
if (!empty($_mod["requirements"])) { |
|
foreach($_mod["requirements"] AS $_requiredFile) { |
|
require_once __DIR__ . $_requiredFile; |
|
} |
|
} |
|
} |
|
|
|
$skip_purify = $_ENV["__SKIP_PURIFY"] ?? false; |
|
if($skip_purify !== true) { |
|
$_GET = purifyInput($_GET); |
|
$_POST = purifyInput($_POST); |
|
} |
|
|
|
$required_js = []; |
|
$required_js[] = "/src/ckeditor5/ckeditor.js"; |
|
$required_js[] = "/src/js/app.js?date=20240724"; |
|
$required_js[] = "/src/highcharts/highcharts.js"; |
|
$required_js[] = "/src/highcharts/highcharts-more.js"; |
|
$required_js[] = "/src/typeahead/typeahead.bundle.js"; |
|
$required_js[] = "/src/js/extra/files.js"; |
|
$required_js[] = "/src/js/resumable.js"; |
|
|
|
$required_css = ["/src/css/app.css"]; |
|
$required_css[] = "/src/css/extra/files.css"; |
|
|
|
try { |
|
|
|
$pdo = new myPDO($config["db_host"], $config["db_user"], $config["db_pass"], $config["db_name"], $config['socket']); |
|
|
|
} catch (\Throwable $th) { |
|
|
|
die('<h1 style="text-align: center; margin-top: 100px; color: red;">ERRORE DI CONNESSIONE AL DATABASE.<br><small>IMPOSSIBILE AVVIARE L'APPLICATIVO!!</small></h1>'); |
|
|
|
} finally { |
|
|
|
if ($pdo->go("SHOW TABLES LIKE 'b_enti'")->rowCount() == 0 && !isset($initScript) && php_sapi_name() !== "cli") { |
|
die('<h1 style="text-align: center; margin-top: 100px; color: red;">DATABASE NON INIZIALIZZATO.<br><small>IMPOSSIBILE AVVIARE L'APPLICATIVO!!</small></h1>'); |
|
} |
|
|
|
} |
|
|
|
|
|
/////////////////////////// |
|
// CHECK LAST ACTIVITY // |
|
/////////////////////////// |
|
|
|
@session_start(); |
|
if ($developEnv || (isset($_SESSION["utente"]) && $_SESSION["utente"]->gerarchia === 1)) { |
|
ini_set('display_errors', 1); |
|
ini_set('display_startup_errors', 1); |
|
} |
|
if (!isset($pagina_login)) { |
|
$_SESSION["id_sessione"] = md5(session_id()); |
|
} |
|
$_SESSION["developEnv"] = $developEnv; |
|
$_SESSION["demoEnv"] = $demoEnv; |
|
if (!empty($_SESSION["utente"]) && isset($_SESSION['LAST_ACTIVITY']) && (time() - $_SESSION['LAST_ACTIVITY'] > 3600)) { |
|
session_unset(); session_destroy(); @session_start(); |
|
if(empty($_SERVER['HTTP_X_REQUESTED_WITH']) || strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) != 'xmlhttprequest') { |
|
echo '<meta http-equiv="refresh" content="0;URL=/index.php">'; |
|
die(); |
|
} |
|
} |
|
$_SESSION['LAST_ACTIVITY'] = time(); |
|
if (!isset($_SESSION['CREATED'])) { |
|
$_SESSION['CREATED'] = time(); |
|
} else if (time() - $_SESSION['CREATED'] > 1800) { |
|
if (!empty($_SESSION["utente"])) { |
|
$_SESSION["utente"]->regenerateID(); |
|
} else { |
|
session_regenerate_id(true); |
|
} |
|
$_SESSION['CREATED'] = time(); |
|
} |
|
|
|
//////////////////// |
|
// CHECK ente // |
|
//////////////////// |
|
if (isset($_SERVER["SERVER_NAME"])) { |
|
$ente = new ente(); |
|
if ($ente->init($_SERVER["SERVER_NAME"])) { |
|
$pdo->setConnessioneEnte($ente->codice); |
|
$_SESSION["ente"] = $ente; |
|
if (!empty($ente->getInfo()["dominio"])) { |
|
$_SESSION["config"]["link_sito"] = $config["protocollo"] . $ente->getInfo()["dominio"]; |
|
} |
|
$_SESSION["config"]["nome_sito"] = $config["nome_sito"] . " - " . $ente->getInfo()["denominazione"]; |
|
} |
|
} |
|
|
|
if (!empty($_SESSION["ente"])) { |
|
$_SESSION["ente"]->check(); |
|
if ($_SESSION["ente"]->getInfo()["manutenzione"] == "S") { |
|
$manutenzione = true; |
|
} |
|
} else { |
|
$manutenzione = false; |
|
} |
|
if (!file_exists($config["user_log"])) { |
|
mkdir($config["user_log"], 0770, true); |
|
} |
|
if (!file_exists($config["db_log"])) { |
|
mkdir($config["db_log"], 0770, true); |
|
} |
|
if (!file_exists($config["user_log"]."/lock")) { |
|
mkdir($config["user_log"]."/lock", 0770, true); |
|
} |
|
if (isset($_SERVER["HTTP_HOST"])) { |
|
$actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; |
|
} |
|
$todayLog = date("Ymd").".log"; |
|
$todayLogPath = "{$config["user_log"]}/{$todayLog}"; |
|
$yesterdayLog = date("Ymd",strtotime("Yesterday")).".log"; |
|
$yesterdayLogPath = "{$config["user_log"]}/{$yesterdayLog}"; |
|
if (file_exists($yesterdayLogPath) && !DEMO_ENV && php_sapi_name() == "cli") { |
|
$zip = new ZipArchive; |
|
if ($zip->open($yesterdayLogPath.".zip", ZipArchive::CREATE) === TRUE) |
|
{ |
|
$unlink_log = false; |
|
$unlink_tsr = false; |
|
$unlink_tsq = false; |
|
if ($zip->addFile($yesterdayLogPath,$yesterdayLog)) { |
|
$unlink_log = true; |
|
// if ($zip->addFile($yesterdayLogPath.".tsr",$yesterdayLog.".tsr")) { |
|
// $unlink_tsr = true; |
|
// if ($zip->addFile($yesterdayLogPath.".tsq",$yesterdayLog.".tsq")) { |
|
// $unlink_tsq = true; |
|
// } |
|
// } |
|
} |
|
if ($zip->close()) { |
|
if ($unlink_log) { |
|
P7Manager::putTimestamp($yesterdayLogPath.".zip"); |
|
unlink($yesterdayLogPath); |
|
} |
|
// if ($unlink_tsr) { |
|
// unlink($yesterdayLogPath.".tsr"); |
|
// } |
|
// if ($unlink_tsq) { |
|
// unlink($yesterdayLogPath.".tsq"); |
|
// } |
|
} |
|
} |
|
} |
|
|
|
$todayDbLog = date("Ymd").".log"; |
|
$todayDbLogPath = "{$config["db_log"]}/{$todayDbLog}"; |
|
$yesterdayDbLog = date("Ymd",strtotime("Yesterday")).".log"; |
|
$yesterdayDbLogPath = "{$config["db_log"]}/{$yesterdayDbLog}"; |
|
if (file_exists($yesterdayDbLogPath) && !DEMO_ENV && php_sapi_name() == "cli") { |
|
$zip = new ZipArchive; |
|
if ($zip->open($yesterdayDbLogPath.".zip", ZipArchive::CREATE) === TRUE) |
|
{ |
|
$unlink_db_log = false; |
|
$unlink_db_tsr = false; |
|
$unlink_db_tsq = false; |
|
if ($zip->addFile($yesterdayDbLogPath,$yesterdayDbLog)) { |
|
$unlink_db_log = true; |
|
// if ($zip->addFile($yesterdayDbLogPath.".tsr",$yesterdayDbLog.".tsr")) { |
|
// $unlink_db_tsr = true; |
|
// if ($zip->addFile($yesterdayDbLogPath.".tsq",$yesterdayDbLog.".tsq")) { |
|
// $unlink_db_tsq = true; |
|
// } |
|
// } |
|
} |
|
if ($zip->close()) { |
|
if ($unlink_db_log) { |
|
P7Manager::putTimestamp($yesterdayDbLogPath.".zip"); |
|
unlink($yesterdayDbLogPath); |
|
} |
|
// if ($unlink_db_tsr) { |
|
// unlink($yesterdayDbLogPath.".tsr"); |
|
// } |
|
// if ($unlink_db_tsq) { |
|
// unlink($yesterdayDbLogPath.".tsq"); |
|
// } |
|
} |
|
} |
|
} |
|
|
|
if (isset($_SESSION["utente"]->codice) && |
|
(!isset($ignoreLog) || (isset($ignoreLog) && $ignoreLog !== true)) |
|
&& $_SESSION["demoEnv"]!==true |
|
&& isset($actual_link)) { |
|
$tmp = []; |
|
$tmp[] = date("Y-m-d H:i:s"); |
|
$tmp[] = $_SESSION["utente"]->codice; |
|
$tmp[] = get_client_ip(); |
|
$tmp[] = $actual_link; |
|
$message = implode(";",$tmp); |
|
file_put_contents($todayLogPath, $message."\n", FILE_APPEND); |
|
} |
|
|
|
if ($manutenzione && !isset($ignoreRedirectManutenzione)) { |
|
echo '<meta http-equiv="refresh" content="0;URL=/manutenzione.php">'; |
|
die(); |
|
} |
|
|
|
$lang_disp = jsonToArray($root."/inc/language-available.json"); |
|
$available_lg = ["IT"]; |
|
foreach($lang_disp AS $lang_key => $lang_av) { |
|
if ($lang_av["attivo"] == "S") { |
|
$available_lg[] = $lang_key; |
|
} |
|
} |
|
if (!isset($_SESSION["language"])) { |
|
$_SESSION["language"] = "IT"; |
|
} |
|
if (isset($_GET["language"]) && in_array($_GET["language"], $available_lg, TRUE) !== false) { |
|
$selected_language = $available_lg[array_search($_GET["language"], $available_lg, TRUE)]; |
|
$_SESSION["language"] = $selected_language; |
|
} |
|
if (empty($_SESSION["config"])) { |
|
$_SESSION["config"] = [ |
|
"link_sito" => $config["link_sito"], |
|
"nome_sito" => $config["nome_sito"] |
|
]; |
|
} |
|
|
|
if (!empty($_SESSION["utente"])) { |
|
$_SESSION["utente"]->check(); |
|
} |
|
|
|
$radice = get_radice(); |
|
|
|
$_SESSION["numero_assistenza"] = (isset($_SESSION["ente"]) && !empty($_SESSION["ente"]->getInfo()["numero_assistenza_oe"])) ? $_SESSION["ente"]->getInfo()["numero_assistenza_oe"] : $config["numero_assistenza_oe"]; |
|
if (!empty($_SESSION["utente"]) && empty($_SESSION["utente"]->oe)) { |
|
$_SESSION["numero_assistenza"] = (isset($_SESSION["ente"]) && !empty($_SESSION["ente"]->getInfo()["numero_assistenza_sa"])) ? $_SESSION["ente"]->getInfo()["numero_assistenza_sa"] : $config["numero_assistenza_sa"]; |
|
} |
|
$_SESSION["email_assistenza"] = $config["email_assistenza"]; |
|
|
|
|
|
$_include_configs = [ |
|
"spid.php", |
|
"oidc.php", |
|
"tuttodocs.php", |
|
"changelogs.php", |
|
"ProcurePlus.php" |
|
]; |
|
|
|
foreach($_include_configs AS $_config_file) { |
|
$_config_path = __DIR__ . DIRECTORY_SEPARATOR . "configs" . DIRECTORY_SEPARATOR . $_config_file; |
|
if (file_exists($_config_path)) { |
|
include_once $_config_path; |
|
} |
|
}
|
|
|