diff --git a/public_html/deployment/pages/act_checkssh.php b/public_html/deployment/pages/act_checkssh.php new file mode 100644 index 0000000000000000000000000000000000000000..a25438ced3716083f3feb93c3c4d90bda40ccadb --- /dev/null +++ b/public_html/deployment/pages/act_checkssh.php @@ -0,0 +1,83 @@ +<?php + +/* ###################################################################### + + IML DEPLOYMENT + + webgui - check all ssh connections to puppet, git repos and taregt hosts + + --------------------------------------------------------------------- + 2018-02-01 Axel <axel.hahn@iml.unibe.ch> + ###################################################################### */ + +$sOK='<span class="ok">' . t('ok') . '</span>'; +$sFAILED='<span class="error">' . t('error') . '</span>'; +global $sOK; +global $sFAILED; + +// test only +// $aConfig['mirrorPackages']=array('puppet' => array('target' => 'ladmin@calcium.iml.unibe.ch:/share/imldeployment'),); + +/** + * exec a command and show OK or FAILED + * + * @global string $sOK + * @global string $sFAILED + * @param string $sCmd command to execute + * @return string + */ +function myExec($sCmd){ + global $sOK, $sFAILED; + $sReturn=''; + + exec($sCmd . " 2>&1 && echo '$sOK' || echo '$sFAILED' ", $aOut); + $sReturn .= "<pre><strong>\$ $sCmd</strong><br>" + . implode('<br>', $aOut)."<br>" + . "</pre>"; + + return $sReturn; +} + + +$sOut = '<h2>SSH</h2>'; + +if(isset($aConfig['mirrorPackages']) && count($aConfig['mirrorPackages'])){ + // test puppet + $sOut = '<h3>Puppet</h3>' + . '<ul>'; + foreach ($aConfig['mirrorPackages'] as $sServer=>$aSettings) { + $sCmd = 'ssh ' . preg_replace('#\:\/.*#', '' , $aSettings['target']) . ' echo "hello from `hostname -f`"'; + $sOut .= '<li><strong>' . $sServer . '</strong> ' . myExec($sCmd); + } + $sOut.='</ul>'; +} + +// ... then loop over all projects ... +$oPrj1 = new project(); +foreach ($oPrj1->getProjects() as $sPrj) { + $oPrj = new project($sPrj); + $aPrjConfig = $oPrj->getConfig(); + $sOut .= '<h3>' . $oPrj->getLabel() . '</h3>' + // . '<pre>'.print_r($aPrjConfig, 1).'</pre>' + . '<ul>'; + + // test repository + $sOut .= '<li>'.t('repositoryinfos').' <strong>' . $aPrjConfig['build']['url'] . '</strong> - ' + . ($oPrj->getRepoRevision() ? $sOK : $sFAILED) + ; + + // loop over phases ... + foreach (array_keys($oPrj->getPhases()) as $sPhase) { + $sOut .= '<li>'.t('phase').' <strong>' . $sPhase . '</strong><ul>'; + $sDeployhosts = array_key_exists("hosts", $aPrjConfig["phases"][$sPhase]) ? $aPrjConfig["phases"][$sPhase]["hosts"] : ""; + + if ($sDeployhosts) { + $sOut .= '<li>' . $sDeployhosts . '<br>'; + $sCmd = 'ssh ' . $aConfig["installPackages"]["user"] . '@' . $sDeployhosts . ' echo "hello from `hostname -f`"'; + $sOut.= myExec($sCmd); + } + $sOut.='</ul>'; + } + $sOut.='</ul>'; +} +echo $sOut;