diff --git a/docker/.env b/docker/.env index 40b752e095652f103dd2b49dc0611c85d9e60c69..edab665ef52ae19c007f68f55b3744c7be96f2bf 100644 --- a/docker/.env +++ b/docker/.env @@ -1,6 +1,6 @@ # ====================================================================== # -# GENERATED BY docker/init.sh - template: ./templates/dot_env - e2cde05722688ff85d3a93e9cd55787e +# GENERATED BY init.sh - template: ./templates/dot_env - e2cde05722688ff85d3a93e9cd55787e # values to be used in docker-composer.yml # # ====================================================================== diff --git a/docker/containers/web-server/Dockerfile b/docker/containers/web-server/Dockerfile index fd26aeda16c4457c779f8ed0bcc8c64d5459e944..e5b01f06ca41f4d70f6821cdd5e2021e1210a569 100644 --- a/docker/containers/web-server/Dockerfile +++ b/docker/containers/web-server/Dockerfile @@ -1,5 +1,5 @@ # -# GENERATED BY docker/init.sh - template: ./templates/web-server-Dockerfile - 42dce773c83597a7d05af398bdd66d15 +# GENERATED BY init.sh - template: ./templates/web-server-Dockerfile - 42dce773c83597a7d05af398bdd66d15 # FROM php:8.1-apache diff --git a/docker/containers/web-server/apache/sites-enabled/vhost_app.conf b/docker/containers/web-server/apache/sites-enabled/vhost_app.conf index c223a7617906a709c511b1192b28d61fb0437c6c..872493645c22d783c78e8ae433ce97580abacc5d 100644 --- a/docker/containers/web-server/apache/sites-enabled/vhost_app.conf +++ b/docker/containers/web-server/apache/sites-enabled/vhost_app.conf @@ -1,5 +1,5 @@ # -# GENERATED BY docker/init.sh - template: ./templates/vhost_app.conf - 9a9cf79de5a3584c0cef6cb79c339c25 +# GENERATED BY init.sh - template: ./templates/vhost_app.conf - 9a9cf79de5a3584c0cef6cb79c339c25 # diff --git a/docker/containers/web-server/php/extra-php-config.ini b/docker/containers/web-server/php/extra-php-config.ini index 674b4dd6106afe25c6fb1074b64d9b7d77e91256..5cc3af6d4826463f008b05762f398fc227f58b64 100644 --- a/docker/containers/web-server/php/extra-php-config.ini +++ b/docker/containers/web-server/php/extra-php-config.ini @@ -1,5 +1,5 @@ ; -; GENERATED BY docker/init.sh - template: ./templates/extra-php-config.ini - 80c23edaf568e2c36b9926fe2339e481 +; GENERATED BY init.sh - template: ./templates/extra-php-config.ini - 80c23edaf568e2c36b9926fe2339e481 ; [PHP] diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 2b983d57879e787de6170039f05c3bd7b3fee8db..c01edc7832b3f720dfce00c51e8d49ff60cc7fdc 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -1,5 +1,5 @@ # -# GENERATED BY docker/init.sh - template: ./templates/docker-compose.yml - 97c88229bd2b5099544c013052b8d9c3 +# GENERATED BY init.sh - template: ./templates/docker-compose.yml - 97c88229bd2b5099544c013052b8d9c3 # # ====================================================================== # diff --git a/docs/config.json b/docs/config.json index 3a54d3b278197ecdafb75e6e0c4cf3ca770f162e..86070d8cb9330f76b749fa2601cb2c777304733c 100644 --- a/docs/config.json +++ b/docs/config.json @@ -14,7 +14,8 @@ "basepath": "https://git-repo.iml.unibe.ch/iml-open-source/imldeployment/tree/master/docs" }, "links": { - "GitHub Repo": "https://git-repo.iml.unibe.ch/iml-open-source/imldeployment/" + "GitHub Repo": "https://git-repo.iml.unibe.ch/iml-open-source/imldeployment/", + "IML Opensource": "https://os-docs.iml.unibe.ch/" }, "theme": "daux-blue", "search": true diff --git a/hooks/templates/config_custom.php.erb b/hooks/templates/config_custom.php.erb index 7cd0f50e77e1c65c52fa6d707f2be4b6032b8f73..db93e518db02c169732336594b9ecf4fe95c5035 100644 --- a/hooks/templates/config_custom.php.erb +++ b/hooks/templates/config_custom.php.erb @@ -98,7 +98,7 @@ return [ 'presets'=>[<%= @replace["messenger-slack-presets"] %>], ], 'email'=>[ - 'from'=>[<%= @replace["messenger-email-from"] %>], + 'from'=><%= @replace["messenger-email-from"] %>, ], ], diff --git a/public_html/appmonitor/plugins/apps/iml-appmonitor-server.php b/public_html/appmonitor/plugins/apps/iml-appmonitor-server.php index d4e9614be774e3530791c6541d72bc211a854bd2..d85938a912a4729aab293f218f0f3baf105f61a8 100644 --- a/public_html/appmonitor/plugins/apps/iml-appmonitor-server.php +++ b/public_html/appmonitor/plugins/apps/iml-appmonitor-server.php @@ -112,7 +112,7 @@ foreach(array('server/config', 'server/tmp') as $sMyDir){ // ---------------------------------------------------------------------- require_once($sApproot.'/server/classes/appmonitor-server.class.php'); $oServer=new appmonitorserver(); -$iCount=count($oServer->apiGetAppIds()); +$iCount=count($oServer->getAppIds()); $oMonitor->addCheck( array( "name" => "appcounter", diff --git a/public_html/appmonitor/plugins/checks/exec.php b/public_html/appmonitor/plugins/checks/exec.php new file mode 100644 index 0000000000000000000000000000000000000000..a343cd9fcaa323174a1156b6fefcf03838c48df2 --- /dev/null +++ b/public_html/appmonitor/plugins/checks/exec.php @@ -0,0 +1,124 @@ +<?php +/** + * ____________________________________________________________________________ + * + * _____ _____ __ _____ _ _ + * | | | | ___ ___ ___| |___ ___|_| |_ ___ ___ + * |- -| | | | |__ | .'| . | . | | | | . | | | _| . | _| + * |_____|_|_|_|_____| |__,| _| _|_|_|_|___|_|_|_|_| |___|_| + * |_| |_| + * _ _ _ + * ___| |_|___ ___| |_ + * | _| | | -_| | _| + * |___|_|_|___|_|_|_| + * + * ____________________________________________________________________________ + * + * CUSTOM CHECK BASED ON SHELL COMMANDS + * + * Execute a shell command. + * ____________________________________________________________________________ + * + * 2022-09-19 <axel.hahn@iml.unibe.ch> + * + */ +class checkExec extends appmonitorcheck{ + /** + * get default group of this check + * @param array $aParams - see run() method + * @return array + */ + public function getGroup($aParams){ + return 'service'; + } + + /** + * check execution of a command + * @param array $aParams + * array( + * "command" {string} command to execute + * "output" {bool} flag: show output; default: true + * + * "exitOK" {array} array of integegers for ok exitcodes + * "exitWarn" {array} array of integegers for exitcodes with warning + * "exitCritical" {array} array of integegers for exitcodes that result in an error + * + * // TODO ... MAYBE + * "searchOK" {string} search string that must be found in output + * "searchWarn" {string} if search string is found check returns with warning + * "searchCritical" {string} if search string is found check returns with critical + * ) + * @return boolean + */ + public function run($aParams) { + $this->_checkArrayKeys($aParams, "command"); + $_sCmd=$aParams['command']; + $_bShowOutput=isset($aParams['output']) ? !!$aParams['output'] : true; + + $_aRcOK=isset($aParams['exitOK']) ? $aParams['exitOK'] : []; + $_aRcWarning=isset($aParams['exitWarn']) ? $aParams['exitWarn'] : []; + $_aRcCritical=isset($aParams['exitCritical']) ? $aParams['exitCritical'] : []; + + $_sMode='default'; + if(count($_aRcOK) + count($_aRcWarning) + count($_aRcCritical)){ + $_sMode='exitcode'; + } + + exec($_sCmd,$aOutput, $iRc); + $_sOut=$_bShowOutput ? '<br>'.implode("<br>", $aOutput) : ''; + + switch($_sMode){ + // non-zero exitcode is an error + case "default": + if ($iRc) { + return [ + RESULT_ERROR, + 'command failed with exitcode '.$iRc.': [' . $_sCmd . ']'.$_sOut + ]; + } else { + return[ + RESULT_OK, + 'OK [' . $_sCmd . '] ' .$_sOut + ]; + }; + break;; + + // handle given custom exitcodes + case "exitcode": + if (in_array($iRc, $_aRcCritical)){ + return [ + RESULT_ERROR, + 'Critical exitcode '.$iRc.' detected: [' . $_sCmd . ']'.$_sOut + ]; + } + if (in_array($iRc, $_aRcWarning)){ + return [ + RESULT_WARNING, + 'Warning exitcode '.$iRc.' detected: [' . $_sCmd . ']'.$_sOut + ]; + } + if ($iRc == 0 || in_array($iRc, $_aRcOK)){ + return [ + RESULT_OK, + 'OK exitcode '.$iRc.' detected: [' . $_sCmd . ']'.$_sOut + ]; + } + return [ + RESULT_UNKNOWN, + 'UNKNOWN - unhandled exitcode '.$iRc.' detected: [' . $_sCmd . ']'.$_sOut + ]; + case "search": + return[ + RESULT_UNKNOWN, + 'UNKNOWN method [' . $_sMode . '] - is not implemented yet.' + ]; + break;; + default: + return[ + RESULT_UNKNOWN, + 'UNKNOWN mode [' . htmlentities($_sMode) . '].' + ]; + } // switch($_sMode) + } + +} diff --git a/public_html/appmonitor/plugins/checks/ping.php b/public_html/appmonitor/plugins/checks/ping.php new file mode 100644 index 0000000000000000000000000000000000000000..b10397d6a03351c8c3253bcf2ddf3ca298991189 --- /dev/null +++ b/public_html/appmonitor/plugins/checks/ping.php @@ -0,0 +1,110 @@ +<?php +/** + * ____________________________________________________________________________ + * + * _____ _____ __ _____ _ _ + * | | | | ___ ___ ___| |___ ___|_| |_ ___ ___ + * |- -| | | | |__ | .'| . | . | | | | . | | | _| . | _| + * |_____|_|_|_|_____| |__,| _| _|_|_|_|___|_|_|_|_| |___|_| + * |_| |_| + * _ _ _ + * ___| |_|___ ___| |_ + * | _| | | -_| | _| + * |___|_|_|___|_|_|_| + * + * ____________________________________________________________________________ + * + * CHECK PING RESPONSE TIME VIA ICMP + * ____________________________________________________________________________ + * + * 2022-07-05 <axel.hahn@iml.unibe.ch> + * 2022-09-16 <axel.hahn@iml.unibe.ch> read error before closing socket. + * 2022-11-22 <axel.hahn@iml.unibe.ch> Use exec with detecting MS Win for the ping parameter for count of pings + */ +class checkPing extends appmonitorcheck{ + /** + * get default group of this check + * @param array $aParams + * @return array + */ + public function getGroup(){ + return 'network'; + } + + /** + * check ping to a target + * @param array $aParams + * array( + * host string optional hostname to connect; default: 127.0.0.1 + * timeout integer OBSOLET (because using exec): optional timeout in sec; default: 5 + * ) + * @return boolean + */ + public function run($aParams) { + $sHost = array_key_exists('host', $aParams) ? $aParams['host'] : '127.0.0.1'; + + $sParamCount=strtoupper(substr(PHP_OS, 0, 3)) === 'WIN' ? "n" : "c"; + $iRepeat=1; + + $sCommand="ping -$sParamCount $iRepeat $sHost 2>&1"; + exec($sCommand, $aOut, $iRc); + $sOut=implode("\n", $aOut); + + if ($iRc>0){ + return [RESULT_ERROR, "ERROR: ping to $sHost failed.\n".$sOut]; + } + return [RESULT_OK, "OK: ping to $sHost\n".$sOut]; + + /* + Socket functions require root :-/ + + if (!function_exists('socket_create')){ + return [RESULT_UNKNOWN, "UNKNOWN: Unable to perform ping test. The socket module is not enabled in the php installation."]; + } + + // ICMP ping packet with a pre-calculated checksum + $package = "\x08\x00\x7d\x4b\x00\x00\x00\x00PingHost"; + $socket = socket_create(AF_INET, SOCK_RAW, getprotobyname('icmp')); + // TODO + if(!$socket){ + die("ERROR: unable to create socket"); + } + socket_set_option( + $socket, + SOL_SOCKET, + SO_RCVTIMEO, + array( + "sec"=>(isset($aParams["timeout"]) && (int)$aParams["timeout"]) ? (int)$aParams["timeout"] : $this->_iTimeoutTcp, // timeout in seconds + "usec"=>0 + ) + ); + + $start = microtime(true); + socket_connect($socket, $sHost, 0); + $connect = socket_send($socket, $package, strLen($package), 0); + if($connect){ + if (socket_read($socket, 255)){ + $result = microtime(true) - $start; + socket_close($socket); + return [RESULT_OK, + "OK: ping to $sHost", + array( + 'type'=>'counter', + 'count'=>$result, + 'visual'=>'line', + ) + + ]; + } else { + $aResult=[RESULT_ERROR, "ERROR: ping to $sHost failed after connect." . socket_strerror(socket_last_error($socket))]; + socket_close($socket); + return $aResult; + } + } else { + return [RESULT_ERROR, "ERROR: ping to $sHost failed. " . socket_strerror(socket_last_error($socket))]; + } + + */ + } + +} diff --git a/public_html/appmonitor/plugins/checks/porttcp.php b/public_html/appmonitor/plugins/checks/porttcp.php index 79afcd87ff380591f2bacb98515cbf6789f20169..3161163e1e640a5ed78797bac3bbd15abee6eeb2 100644 --- a/public_html/appmonitor/plugins/checks/porttcp.php +++ b/public_html/appmonitor/plugins/checks/porttcp.php @@ -14,10 +14,13 @@ * * ____________________________________________________________________________ * - * CHECK SWLITE CONNECTION USING PDO + * CHECK TCP CONNECTION TO A GIVEN PORT * ____________________________________________________________________________ * * 2021-10-27 <axel.hahn@iml.unibe.ch> + * 2022-07-05 <axel.hahn@iml.unibe.ch> send unknown if socket module is not activated. + * 2022-09-16 <axel.hahn@iml.unibe.ch> read error before closing socket. + * 2022-12-05 <axel.hahn@unibe.ch> add @ sign at socket functions to prevent warning * */ class checkPortTcp extends appmonitorcheck{ @@ -46,9 +49,13 @@ class checkPortTcp extends appmonitorcheck{ $sHost = array_key_exists('host', $aParams) ? $aParams['host'] : '127.0.0.1'; $iPort = (int) $aParams['port']; + if (!function_exists('socket_create')){ + return [RESULT_UNKNOWN, "UNKNOWN: Unable to perform tcp test. The socket module is not enabled in the php installation."]; + } + // from http://php.net/manual/de/sockets.examples.php - $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); + $socket = @socket_create(AF_INET, SOCK_STREAM, SOL_TCP); if ($socket === false) { return [RESULT_UNKNOWN, "ERROR: $sHost:$iPort was not checked. socket_create() failed: " . socket_strerror(socket_last_error())]; } @@ -63,10 +70,11 @@ class checkPortTcp extends appmonitorcheck{ ) ); - $result = socket_connect($socket, $sHost, $iPort); + $result = @socket_connect($socket, $sHost, $iPort); if ($result === false) { + $aResult=[RESULT_ERROR, "ERROR: $sHost:$iPort failed. " . socket_strerror(socket_last_error($socket))]; socket_close($socket); - return [RESULT_ERROR, "ERROR: $sHost:$iPort failed. " . socket_strerror(socket_last_error($socket))]; + return $aResult; } else { socket_close($socket); return [RESULT_OK, "OK: $sHost:$iPort was connected."]; diff --git a/public_html/deployment/classes/build_base.class.php b/public_html/deployment/classes/build_base.class.php index 08832899a3ee5dec7478d60725040e40da08b703..723deb290e476fcf7cb8b1f746a2838277fd084f 100644 --- a/public_html/deployment/classes/build_base.class.php +++ b/public_html/deployment/classes/build_base.class.php @@ -11,6 +11,9 @@ class build_base implements iBuildplugin{ protected $_sBuildDir = false; protected $_sOutfile = false; + + protected $_sPluginId = false; + protected $_aPlugininfos = false; protected $_sLang = "en-en"; protected $_aLang = []; diff --git a/public_html/deployment/classes/messenger.class.php b/public_html/deployment/classes/messenger.class.php index 589183a847c0e220cd8f13d21e1bcb0d9167bd1a..f888cefbadd64ea35d841a27788db0d6f4f80525 100644 --- a/public_html/deployment/classes/messenger.class.php +++ b/public_html/deployment/classes/messenger.class.php @@ -42,14 +42,16 @@ class messenger { } /** - * send an email if _aCfg['email'] exists + * send an email if _aCfg['email']['to'] exists */ private function _sendEmail(){ - if (array_key_exists('email', $this->_aCfg) && array_key_exists('to', $this->_aCfg['email']) - ) { + if (isset($this->_aCfg['email']['to']) && $this->_aCfg['email']['to']) { preg_match('/^(.*)\n/', $this->_sMessage, $aTmp); $sSubject = $aTmp[0]; - return mail($this->_aCfg['email']['to'], $sSubject, $this->_sMessage, "From: " . $this->_aCfg['email']['from'] . "\r\n" . + return mail( + $this->_aCfg['email']['to'], + $sSubject, $this->_sMessage, + "From: " . $this->_aCfg['email']['from'] . "\r\n" . "Reply-To: " . $this->_aCfg['email']['from'] . "\r\n" ); } @@ -57,15 +59,15 @@ class messenger { } /** - * send a message to slack if _aCfg['slack'] exists + * send a message to slack if _aCfg['slack']['incomingurl'] exists */ private function _sendToSlack(){ - if (array_key_exists('slack', $this->_aCfg)) { + if (isset($this->_aCfg['slack']['incomingurl']) && $this->_aCfg['slack']['incomingurl']) { require_once(__DIR__ . '/../../vendor/shooker/shooker.php'); $shkr = new Shooker(); $shkr->setupIncoming($this->_aCfg['slack']['incomingurl']); - $sUser=(array_key_exists('user', $this->_aCfg['slack'])? $this->_aCfg['slack']['user']: false); - $sIcon=(array_key_exists('icon', $this->_aCfg['slack'])? $this->_aCfg['slack']['icon']: false); + $sUser=(isset($this->_aCfg['slack']['user'])? $this->_aCfg['slack']['user']: false); + $sIcon=(isset($this->_aCfg['slack']['icon'])? $this->_aCfg['slack']['icon']: false); return $shkr->sendMessage($this->_sMessage, $sUser, $sIcon); } return false; diff --git a/public_html/deployment/classes/project.class.php b/public_html/deployment/classes/project.class.php index bee8617bda817d24772beca2ded722762e87ff53..149fafd92a6fc5e573551cff66ddf8ea074496dc 100644 --- a/public_html/deployment/classes/project.class.php +++ b/public_html/deployment/classes/project.class.php @@ -647,7 +647,7 @@ class project extends base { $this->getAllPhaseInfos(); foreach ($this->_aData["phases"] as $sPhase => $aData) { foreach (array_keys($this->_aPlaces) as $sPlace) { - if (array_key_exists($sPlace, $aData) && array_key_exists("version", $aData[$sPlace])) { + if (isset($aData[$sPlace]["version"])) { $this->_aVersions[$aData[$sPlace]["version"]][] = array('phase' => $sPhase, 'place' => $sPlace); } } diff --git a/public_html/deployment/plugins/rollout/awx/rollout_awx.php b/public_html/deployment/plugins/rollout/awx/rollout_awx.php index 41919f55bd53d82f3d09614f4add82c720eb5577..6c6df0d6bd4b1f255edf319fceba3fe07a791406 100644 --- a/public_html/deployment/plugins/rollout/awx/rollout_awx.php +++ b/public_html/deployment/plugins/rollout/awx/rollout_awx.php @@ -176,7 +176,7 @@ class rollout_awx extends rollout_base { // ----- Checks: $sCmdChecks=''; - if($aConfig['extravars']){ + if(isset($aConfig['extravars']) && $aConfig['extravars']){ $aTmp=json_decode($aConfig['extravars'], 1); if (!$aTmp || !is_array($aTmp) || !count($aTmp) ){ $sCmdChecks.='echo "ERROR: Value in extravars has wrong Syntax - this is no JSON: '.$aConfig['extravars'].'"; exit 1; '; @@ -184,14 +184,14 @@ class rollout_awx extends rollout_base { $aConfig['extravars']=json_encode($aTmp); } - if(!(int)$aConfig['inventory']){ + if(!isset($aConfig['inventory']) || !(int)$aConfig['inventory']){ $sCmdChecks.='echo "ERROR: no inventory was given."; exit 1; '; } // ----- Send variables having values only $aBodyvars=array(); foreach(['inventory'=>'inventory', 'limit'=>'limit', 'job_tags'=>'tags', 'extra_vars'=>'extravars'] as $sParam=>$sVarkey){ - if ($aConfig[$sVarkey]) { + if (isset($aConfig[$sVarkey]) && $aConfig[$sVarkey]) { $aBodyvars[$sParam]=$aConfig[$sVarkey]; } } diff --git a/public_html/valuestore/browse.php b/public_html/valuestore/browse.php index 6cda243ea0b5c2871b52644823f15712751ca453..f19da467f101fe776eb62d4062f8f8f0f81a793a 100644 --- a/public_html/valuestore/browse.php +++ b/public_html/valuestore/browse.php @@ -120,6 +120,7 @@ if(is_array($aData) && count($aData)){ // $sTable.='<tr>'; foreach ($aRow as $sKey=>$sValue){ // $sTable.='<td class="'.$sKey.'"><a href="'.$sUrl.'">'.$sValue.'</a></td>'; + $sOnclick=''; $sLabel=strstr($sValue, '"') ? htmlentities($sValue) : '<a href="#" onclick="$(\'#eFilter\').val(\''.$sValue.'\');filterTable();" title="click to filter by ['.$sValue.']">'.htmlentities($sValue).'</a>' diff --git a/public_html/valuestore/index.php b/public_html/valuestore/index.php index c94ac0fd238309d673d289516ed9b40564c5552d..9da4fb06d263612a47028375867df729eb698cbe 100644 --- a/public_html/valuestore/index.php +++ b/public_html/valuestore/index.php @@ -143,7 +143,7 @@ switch ($sAction) { // case 'other-varname': case 'version': if ($oVersion->updateVar($sVarname, $sValue)) { - echo "OK: $sVarname was updated."; + echo "OK: $sVarname was updated.".PHP_EOL."new value: $sValue".PHP_EOL; } else { echo "ERROR: update for $sVarname failed."; }