2018-10-07 13:46:15 +03:00
|
|
|
#! /usr/bin/env perl
|
|
|
|
|
2015-07-03 04:42:36 +03:00
|
|
|
# package used to get the current working folder
|
2015-07-09 03:30:50 +03:00
|
|
|
use aamt_wrkFolder;
|
2015-07-03 04:42:36 +03:00
|
|
|
my $currentLibfolder;
|
|
|
|
# get the current working folder and unset the environment variable that has been set in the
|
|
|
|
# batch file/ shell script file
|
|
|
|
BEGIN {$currentLibfolder = main_getCurrentLibFolder();}
|
|
|
|
use vars qw/$currentLibfolder/;
|
|
|
|
use lib $currentLibfolder;
|
|
|
|
|
|
|
|
#Standard and nonstandard packages used by the tool
|
|
|
|
use strict; #for declaration of variables prior to use
|
|
|
|
use FileHandle; #for file operations
|
|
|
|
use File::Copy; #for copying the file in a local machine
|
2015-07-15 04:21:33 +03:00
|
|
|
use File::Path;
|
2015-07-03 04:42:36 +03:00
|
|
|
use LWP::Simple; #for website header information
|
|
|
|
use IO::Dir; #for directory handling
|
|
|
|
use Sys::Hostname; #
|
|
|
|
use File::Listing; #to display a list of files in a directory
|
|
|
|
use Time::localtime; #get system time information
|
|
|
|
|
|
|
|
# custom packages developed to be used by the tool
|
2015-07-09 03:30:50 +03:00
|
|
|
use aamt_constants; #for user input or error or file constants
|
|
|
|
use aamt_utilityFunctions; #for common procedures
|
|
|
|
use aamt_informationLog; #used for logging information into Log,Status or Recovery file
|
|
|
|
use aamt_userInterface; #used for user interface definition
|
|
|
|
use aamt_auth; #used for Authentication and user query module
|
|
|
|
use aamt_parse; #used for parsing the conf file and getting the site information
|
|
|
|
use aamt_parse2; #used for parsing the conf file and generating the 2D array.
|
2015-07-03 04:42:36 +03:00
|
|
|
|
|
|
|
# main subroutine starts here
|
|
|
|
my $localConfFilePath;
|
|
|
|
my $boolVersionNumber;
|
|
|
|
my $blnWISrcRet;
|
|
|
|
my $logFileReturn;
|
|
|
|
my $RecoveryMode = "";
|
2015-08-05 03:11:11 +03:00
|
|
|
my $DEBUG_MODE = 0;
|
2015-08-05 01:08:55 +03:00
|
|
|
|
2015-07-03 04:42:36 +03:00
|
|
|
eval
|
2015-08-05 01:08:55 +03:00
|
|
|
{
|
2015-07-03 04:42:36 +03:00
|
|
|
my $auqRetVal;
|
|
|
|
($auqRetVal,$localConfFilePath) = auth_main(); # AUQ module functionality
|
2018-10-07 13:46:15 +03:00
|
|
|
unless ($auqRetVal)
|
2015-07-03 04:42:36 +03:00
|
|
|
{
|
2015-07-15 04:21:33 +03:00
|
|
|
&DeleteWorkingFolder();
|
2015-07-03 04:42:36 +03:00
|
|
|
die CLEANUP_AND_EXIT;
|
2015-08-05 01:08:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (auth_isRecovery() eq "RECOVERY")
|
|
|
|
{
|
2015-08-05 03:11:11 +03:00
|
|
|
$RecoveryMode = pars_GetRecoveryCode();
|
2015-08-05 01:08:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($DEBUG_MODE) { ilog_print(1,"\nDEBUG: RECOVERY MODE: [$RecoveryMode]\n"); }
|
2015-07-03 04:42:36 +03:00
|
|
|
if ( ($RecoveryMode ne RECOVERY_MODE_1) && ($RecoveryMode ne RECOVERY_MODE_2) && ($RecoveryMode ne RECOVERY_MODE_3))
|
|
|
|
{
|
|
|
|
&pars_FirstPass($localConfFilePath); # Parser Module first pass
|
2015-08-05 01:08:55 +03:00
|
|
|
&pars_SetRecoveryCode(RECOVERY_MODE_1);
|
2015-07-03 04:42:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (($RecoveryMode ne RECOVERY_MODE_2) && ($RecoveryMode ne RECOVERY_MODE_3))
|
|
|
|
{
|
2015-08-05 01:08:55 +03:00
|
|
|
if ($DEBUG_MODE) { ilog_print(1,"\nDEBUG: CONCATENATING CONFIG FILES\n"); }
|
2015-07-03 04:42:36 +03:00
|
|
|
# Concatenate all of the configuration files in preparation for the next step where we parse the master file
|
|
|
|
use Cwd;
|
|
|
|
my $pwd = cwd();
|
|
|
|
# get the current working folder
|
|
|
|
my $strCurWorkingFolder = &utf_getCurrentWorkingFolder();
|
|
|
|
# get session name
|
|
|
|
my $strSessionName = &ilog_getSessionName();
|
|
|
|
# form the complete working folder
|
2018-12-15 15:56:34 +03:00
|
|
|
my $workingFolder = $strCurWorkingFolder . '/' . $strSessionName;
|
2015-07-03 04:42:36 +03:00
|
|
|
# change local dir
|
|
|
|
my $retwrk_changeLocalDir = wrk_changeLocalDir($workingFolder);
|
2018-10-07 13:46:15 +03:00
|
|
|
unless($retwrk_changeLocalDir)
|
2015-07-03 04:42:36 +03:00
|
|
|
{
|
|
|
|
$logFileReturn= ilog_setLogInformation('EXT_ERROR',ERR_CWD_COMMAND,'', __LINE__);
|
2018-10-07 13:46:15 +03:00
|
|
|
unless($logFileReturn)
|
2015-07-03 04:42:36 +03:00
|
|
|
{
|
|
|
|
$logFileReturn=ilog_print(ERR_INTERNAL_ERROR_CONSOLE.__LINE__,1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
# my @files = grep { -f } glob( '*.conf' );
|
|
|
|
my @files = File::Find::Rule->file()
|
|
|
|
->name("*apache*")
|
2015-07-16 06:03:12 +03:00
|
|
|
->in($workingFolder);
|
|
|
|
|
2015-07-03 04:42:36 +03:00
|
|
|
my @fhs = map { open my $fh, '<', $_; $fh } @files;
|
|
|
|
my $concatenated = '';
|
2015-07-16 06:03:12 +03:00
|
|
|
while (my $fh = shift @fhs)
|
|
|
|
{
|
2015-07-03 04:42:36 +03:00
|
|
|
while ( my $line = <$fh> )
|
|
|
|
{
|
|
|
|
$concatenated .= $line;
|
|
|
|
}
|
|
|
|
|
|
|
|
close $fh;
|
|
|
|
}
|
|
|
|
|
|
|
|
# go back to orginal dir
|
|
|
|
chdir($pwd);
|
|
|
|
|
|
|
|
my $confAllName = &utf_getCompleteFilePath(FILE_CONF_ALL);
|
|
|
|
my $HANDLE_CONF_ALL = new IO::File;
|
2018-10-07 13:46:15 +03:00
|
|
|
if(open(HANDLE_CONF_ALL,">>", $confAllName) or die ERR_FILE_OPEN)
|
2015-07-03 04:42:36 +03:00
|
|
|
{
|
|
|
|
print HANDLE_CONF_ALL $concatenated;
|
|
|
|
close(HANDLE_CONF_ALL);
|
|
|
|
}
|
2015-08-05 01:08:55 +03:00
|
|
|
|
|
|
|
my $logFilereturn = ilog_setLogInformation('REC_INFO',"FILE_CONF_ALL ".REC_ADD_EQUAL,&utf_getCompleteFilePath(FILE_CONF_ALL),'');
|
2015-07-03 04:42:36 +03:00
|
|
|
&pars_SetRecoveryCode(RECOVERY_MODE_2);
|
|
|
|
}
|
2015-08-05 01:08:55 +03:00
|
|
|
|
|
|
|
if (($RecoveryMode ne RECOVERY_MODE_3))
|
|
|
|
{
|
2015-08-05 03:11:11 +03:00
|
|
|
if ($DEBUG_MODE) { ilog_print(1,"\nDEBUG: RECOVERY MODE: [$RecoveryMode]\n"); }
|
|
|
|
&pars_Generate2D(&utf_getCompleteFilePath(FILE_CONF_ALL), &utf_getCompleteFilePath(FILE_RECOVERY), $RecoveryMode);
|
2015-08-05 01:08:55 +03:00
|
|
|
&pars_UploadPublishSettingsAllSites();
|
|
|
|
}
|
|
|
|
|
2015-07-03 04:42:36 +03:00
|
|
|
&pars_SetRecoveryCode(RECOVERY_MODE_3);
|
|
|
|
utf_setCurrentModuleName('');
|
|
|
|
&utf_gettimeinfo('1');
|
2015-07-15 04:21:33 +03:00
|
|
|
&DeleteWorkingFolder();
|
2015-07-03 04:42:36 +03:00
|
|
|
&TerminateTool();
|
|
|
|
};
|
2018-10-07 13:46:15 +03:00
|
|
|
if ($@ and $@ !~ /EXIT_TOOL_NOW/)
|
2015-07-03 04:42:36 +03:00
|
|
|
{
|
2018-10-07 13:46:15 +03:00
|
|
|
# Abnormal Termination ...
|
|
|
|
print "$@";
|
|
|
|
&DeleteWorkingFolder();
|
2015-07-03 04:42:36 +03:00
|
|
|
}
|
|
|
|
# end of main subroutine
|
|
|
|
|
|
|
|
sub TerminateTool
|
|
|
|
{
|
|
|
|
# Clean up and exit tool
|
|
|
|
&utf_DisposeFiles();
|
|
|
|
# Restore the include to the original value
|
|
|
|
@INC = @lib::ORIG_INC;
|
|
|
|
exit(0);
|
|
|
|
}
|
2015-07-15 04:21:33 +03:00
|
|
|
|
|
|
|
sub DeleteWorkingFolder
|
|
|
|
{
|
2015-07-16 06:03:12 +03:00
|
|
|
my $strYesOrNo = "";
|
2018-12-15 15:01:10 +03:00
|
|
|
|
|
|
|
# get the current working folder
|
|
|
|
my $strCurWorkingFolder = &utf_getCurrentWorkingFolder();
|
|
|
|
#get session name
|
|
|
|
my $strSessionName = &ilog_getSessionName();
|
|
|
|
#form the complete working folder
|
2018-12-15 15:56:34 +03:00
|
|
|
my $workingFolder = $strCurWorkingFolder . '/' . $strSessionName;
|
2018-12-15 15:01:10 +03:00
|
|
|
|
2015-07-15 04:21:33 +03:00
|
|
|
while($strYesOrNo!~/^\s*[YynN]\s*$/)
|
|
|
|
{
|
2018-12-15 15:01:10 +03:00
|
|
|
ilog_printf(1, " Would you like to delete the working folder $workingFolder used to store temporary settings? (Y/N):");
|
2015-07-15 04:21:33 +03:00
|
|
|
chomp($strYesOrNo = <STDIN>);
|
|
|
|
ilog_print(0,ERR_INVALID_INPUT.ERR_ONLY_YES_OR_NO)
|
|
|
|
if ($strYesOrNo!~/^\s*[YynN]\s*$/);
|
2018-12-15 15:01:10 +03:00
|
|
|
|
2015-07-15 04:21:33 +03:00
|
|
|
if ($strYesOrNo=~/^\s*[Yy]\s*$/)
|
|
|
|
{
|
2018-12-15 15:01:10 +03:00
|
|
|
rmtree([$workingFolder]);
|
2015-07-15 04:21:33 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|