Skip to content
Snippets Groups Projects
Commit c7ad2cbf authored by hahn's avatar hahn
Browse files

add check for required commands

parent e1232a8c
No related branches found
No related tags found
No related merge requests found
......@@ -15,18 +15,41 @@
// functions
// ----------------------------------------------------------------------
/**
* get html code to draw a colored box
* @param string $s message
* @param string $sClass css class; one of ok|info|error
* @return string
*/
function drawbox($s, $sClass) {
return '<div class="box ' . $sClass . '">' . $s . '</div>';
}
/**
* show an alert box with error message
* @param type $s
* @return type
*/
function showerror($s) {
return drawbox($s, 'error');
}
/**
* show green box with ok message
* @param type $s
* @return type
*/
function showok($s) {
return drawbox($s, 'ok');
}
/**
* check a directory if it exists and is writtable
* @global array $aErrors found errors
* @param string $sDir directory to check
* @param string $sKey key in config (for output only)
* @return boolean
*/
function checkdir($sDir, $sKey = false) {
global $aErrors;
......@@ -48,6 +71,12 @@ function checkdir($sDir, $sKey = false) {
return false;
}
/**
* check if a php module was found
* @global array $aErrors found errors
* @param array $aRequiredMods array with needed php modules; default: empty = list all current php modules
* @return boolean
*/
function checkModule($aRequiredMods=array()){
global $aErrors;
$sReturn='';
......@@ -74,6 +103,29 @@ function checkModule($aRequiredMods=array()){
return true;
}
/**
* check if a command can be executed
* @global array $aErrors found errors
* @param array $aCommands array with key=command + value=description
* @return boolean
*/
function checkCommands($aCommands){
global $aErrors;
foreach ($aCommands as $sCommand=>$sDescription){
echo 'command ['.$sCommand.'] ('.$sDescription.') - ';
system("$sCommand", $iReturn);
if($iReturn===0){
echo '<span class="ok">OK</span> ';
} else {
echo '<span class="error">does not exist</span>';
$aErrors[] = "* command $sCommand was not found or failed.\n";
}
echo '<br>';
}
return true;
}
// ----------------------------------------------------------------------
//
// main
......@@ -149,6 +201,27 @@ checkModule(array(
'PDO','curl', 'json', 'ldap', 'pdo_sqlite'
));
echo '<h2>Check executable commands</h2>'
. '<p>remark: if the apache user has no login shell then all commands will fail.</p>';
echo '<h3>basic tools</h3>';
checkCommands(array(
'which bash'=>'shell interpreter to execute hook scripts',
'which cat'=>'show content of files',
'which cp'=>'copy files',
'which ln'=>'create softlinks for version handling',
'which ls'=>'list files',
'which mkdir'=>'create working directories',
'which mv'=>'move files',
'which ps'=>'process list',
'which rm'=>'remove files and directories',
));
echo '<h3>more tools</h3>';
checkCommands(array(
'which ssh'=>'connect with ssh for remote execution',
'which rsync'=>'sync packages to puppet master',
'which git'=>'connect to git repositories',
));
echo '<h2>Result</h2>';
if (count($aErrors)) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment