Compare commits

...

2 Commits

Author SHA1 Message Date
Eric Espie
8172673063 N°8632 - block parameter file from request 2026-02-20 15:15:17 +01:00
Eric Espie
cc8d834603 N°8632 - Check existence of parameter file within iTop 2026-02-19 14:22:37 +01:00
9 changed files with 75 additions and 54 deletions

View File

@@ -199,15 +199,17 @@ function RaiseAlarm($sMessage)
//////////
// Main
try {
utils::UseParamFile();
} catch (Exception $e) {
echo "Error: ".$e->GetMessage()."\n";
exit;
}
if (utils::IsModeCLI()) {
SetupUtils::CheckPhpAndExtensionsForCli(new CLIPage('Check backup utility'));
try {
utils::UseParamFile();
} catch (Exception $e) {
echo 'Error: '.$e->GetMessage()."\n";
exit;
}
$oP = new CLIPage('Check backup utility');
SetupUtils::CheckPhpAndExtensionsForCli($oP);
echo date('Y-m-d H:i:s')." - running check-backup utility\n";
try {

View File

@@ -88,16 +88,16 @@ if (utils::IsModeCLI()) {
$oP = new CLIPage(GetOperationName());
SetupUtils::CheckPhpAndExtensionsForCli($oP);
try {
utils::UseParamFile();
}
catch (Exception $e) {
ExitError($oP, $e->GetMessage());
}
} else {
$oP = new WebPage(GetOperationName());
}
try {
utils::UseParamFile();
} catch (Exception $e) {
ExitError($oP, $e->GetMessage());
}
ExecuteMainOperation($oP);
$oP->output();

View File

@@ -67,18 +67,18 @@ function ReadMandatoryParam($oP, $sParam, $sSanitizationFilter = 'parameter')
if (utils::IsModeCLI()) {
$oP = new CLIPage(Dict::S("TitleSynchroExecution"));
SetupUtils::CheckPhpAndExtensionsForCli($oP, -2);
try {
utils::UseParamFile();
} catch (Exception $e) {
$oP->p('Error: '.$e->GetMessage());
$oP->output();
exit - 2;
}
} else {
$oP = new WebPage(Dict::S("TitleSynchroExecution"));
}
try {
utils::UseParamFile();
} catch (Exception $e) {
$oP->p("Error: ".$e->GetMessage());
$oP->output();
exit -2;
}
if (utils::IsModeCLI()) {
$sAuthUser = ReadMandatoryParam($oP, 'auth_user', 'raw_data');
$sAuthPwd = ReadMandatoryParam($oP, 'auth_pwd', 'raw_data');

View File

@@ -224,18 +224,19 @@ function ChangeDateFormat($sProposedDate, $sFormat, $bDateOnly)
if (utils::IsModeCLI()) {
$oP = new CLIPage(Dict::S('TitleSynchroExecution'));
SetupUtils::CheckPhpAndExtensionsForCli($oP, -2);
try {
utils::UseParamFile();
}
catch (Exception $e) {
$oP->p('Error: '.$e->GetMessage());
$oP->output();
exit - 2;
}
} else {
$oP = new CLILikeWebPage(Dict::S('TitleSynchroExecution'));
}
try {
utils::UseParamFile();
} catch (Exception $e) {
$oP->p("Error: ".$e->GetMessage());
$oP->output();
exit -2;
}
if (utils::IsModeCLI()) {
// Next steps:
// specific arguments: 'csvfile'

View File

@@ -996,4 +996,23 @@ HTML,
],
];
}
public function testLoadParamFile()
{
$sTmpFileInsideItop = APPROOT.'env-production/itop-backup/backup.params.distrib';
$sParamName = 'auth_user';
$sParamValue = 'admin';
$sTmpFileOutsideItop = tempnam(sys_get_temp_dir(), 'utils-test');
$sParams = <<<INI
# comment
$sParamName = $sParamValue
INI;
file_put_contents($sTmpFileOutsideItop, $sParams);
self::InvokeNonPublicStaticMethod(utils::class, 'LoadParamFile', [$sTmpFileOutsideItop]);
self::assertEquals($sParamValue, utils::ReadParam($sParamName, null), "utils::LoadParamFile() should have loaded the file: $sTmpFileInsideItop");
unlink($sTmpFileOutsideItop);
}
}

View File

@@ -446,18 +446,16 @@ function ReSyncProcesses($oP, $bVerbose, $bDebug)
//
set_time_limit(0); // Some background actions may really take long to finish (like backup)
$bIsModeCLI = utils::IsModeCLI();
if ($bIsModeCLI) {
$oP = new CLIPage("iTop - cron");
SetupUtils::CheckPhpAndExtensionsForCli($oP, EXIT_CODE_FATAL);
} else {
$oP = new WebPage("iTop - cron");
}
try {
utils::UseParamFile();
$bIsModeCLI = utils::IsModeCLI();
if ($bIsModeCLI) {
$oP = new CLIPage("iTop - cron");
SetupUtils::CheckPhpAndExtensionsForCli($oP, EXIT_CODE_FATAL);
utils::UseParamFile();
} else {
$oP = new WebPage("iTop - cron");
}
$bVerbose = utils::ReadParam('verbose', false, true /* Allow CLI */);
$bDebug = utils::ReadParam('debug', false, true /* Allow CLI */);

View File

@@ -43,10 +43,12 @@ const EXIT_CODE_ERROR = -1;
const EXIT_CODE_FATAL = -2;
try {
// Do this before loging, in order to allow setting user credentials from within the file
utils::UseParamFile();
if (utils::IsModeCLI()) {
// Do this before loging, in order to allow setting user credentials from within the file
utils::UseParamFile();
}
} catch (Exception $e) {
echo "Error: ".$e->GetMessage()."<br/>\n";
echo "Error: ".$e->GetMessage()."\n";
exit(EXIT_CODE_FATAL);
}

View File

@@ -208,18 +208,19 @@ $oCtx = new ContextTag(ContextTag::TAG_IMPORT);
if (utils::IsModeCLI()) {
$oP = new CLIPage("iTop - Bulk import");
SetupUtils::CheckPhpAndExtensionsForCli($oP, -2);
try {
utils::UseParamFile();
}
catch (Exception $e) {
$oP->p('Error: '.$e->GetMessage());
$oP->output();
exit(-2);
}
} else {
$oP = new CSVPage("iTop - Bulk import");
}
try {
utils::UseParamFile();
} catch (Exception $e) {
$oP->p("Error: ".$e->GetMessage());
$oP->output();
exit(-2);
}
if (utils::IsModeCLI()) {
// Next steps:
// specific arguments: 'csvfile'

View File

@@ -91,10 +91,8 @@ if (empty($sJsonString)) {
$sProvider = '';
$oKPI = new ExecutionKPI();
try {
utils::UseParamFile();
$oKPI = new ExecutionKPI();
$oKPI->ComputeAndReport('Data model loaded');
// N°6358 - force credentials for REST calls