diff --git a/lib/LIXUZ/HelperModules/LixuzCTL.pm b/lib/LIXUZ/HelperModules/LixuzCTL.pm new file mode 100644 index 0000000..19ca22f --- /dev/null +++ b/lib/LIXUZ/HelperModules/LixuzCTL.pm @@ -0,0 +1,81 @@ +package LIXUZ::HelperModules::LixuzCTL; +use strict; +use warnings; +use Method::Signatures; +use LIXUZ::HelperModules::Paths qw(lixuzFSPathTo lixuzFSRoot); +use Exporter qw(import); +our @EXPORT = qw(lixuzctl lixuzctlCommand); + +func lixuzctl(@ARGS) +{ + my $success = 0; + my $r = system(lixuzctlCommand(@ARGS)); + if ($r == 0) + { + $success = 0; + } + if(wantarray()) + { + return($success,$r); + } + return $success; +} + +func lixuzctlCommand (@ARGS) +{ + my $lixuzCTLPath = lixuzFSPathTo('/tools/lixuzctl'); + if (!-e $lixuzCTLPath) + { + die($lixuzCTLPath.': does not exist'."\n"); + } + elsif (!-x $lixuzCTLPath) + { + die($lixuzCTLPath.': is not executable'."\n"); + } + my @command = (lixuzFSPathTo('/tools/lixuzctl'), qw(--quiet --web-chained), '--lixuzdir',lixuzFSRoot()); + push(@command,@ARGS); + return @command; +} + +1; +__END__ + +=pod + +=head1 DESCRIPTION + +This module provides access to run lixuzctl() commands from inside the Lixuz web +application. + +Note: if the /tools/lixuzctl file is missing or has wrong permissions when +either of the functions within this module is called the function will die with +an error message. + +=head1 SYNOPSIS + + use LIXUZ::HelperModules::LixuzCTL; + lixuzctl(..) + +=head1 FUNCTIONS + +The following functions are available from this module and are exported by default. + +=over + +=item lixuzctl(arg1,arg2,..) + +This provides access to running lixuzctl commands within Lixuz. It takes any +parameters that lixuzctl normally takes. It will then execute lixuzctl with +said parameters and return the status from lixuzctl. In scalar context it +returns a boolean value, where true means lixuzctl completed successfully and +false means lixuzctl failed. In list context it will reeturn +($success,$returnValue) where $success is the previously mentioned boolean, and +$returnValue is the raw return value as returned from the system() call. + +=item lixuzctlCommand(arg1,arg2,..) + +This is similar to lixuzctl(), but instead of executing lixuzctl it will instead +return an array containing the parameters that would have been provided to system() +by lixuzctl() in order to run lixuzctl with the provided parameters. + +=back diff --git a/tools/lixuzctl b/tools/lixuzctl index a641729..ee86327 100755 --- a/tools/lixuzctl +++ b/tools/lixuzctl @@ -120,6 +120,11 @@ sub main # duplicate messages). Right now this is treated the same as --chained, # but this could potentionally change at some later point. 'exec-chained' => \$chained, + # This indicates that this instance of lixuzctl is a child of Lixuz itself, + # meaning that it has been executed by code running within the Lixuz web + # application. Right now this is treated the same as --chained, + # but this could potentionally change at some later point. + 'web-chained' => \$chained, ); Getopt::Long::Configure('no_pass_through');