diff --git a/public_html/check-config.php b/public_html/check-config.php index 93618c13d0650c401a8e29ba5303b055b435c2bc..e217edff58165b96e5539c21a710d2c3cdd76882 100644 --- a/public_html/check-config.php +++ b/public_html/check-config.php @@ -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)) {