diff --git a/public_html/deployment/classes/plugins.class.php b/public_html/deployment/classes/plugins.class.php index 9a348df6f55420aae619a8be2a5035b398a49c9a..05e43b36ba9137886af3d9d70d1d7f9465631104 100644 --- a/public_html/deployment/classes/plugins.class.php +++ b/public_html/deployment/classes/plugins.class.php @@ -90,7 +90,6 @@ class ciplugins { $this->_sPlugindir=dirname(__DIR__).'/plugins'; $this->setGlobalCustoms($aGlobals); - return true; } /** diff --git a/public_html/deployment/classes/plugins_renderer.class.php b/public_html/deployment/classes/plugins_renderer.class.php index cd569f54b67f44215f6c6f81f660b03f568e5990..00abde24271a2f7c8c6f5cd3f86a3404f612ebd5 100644 --- a/public_html/deployment/classes/plugins_renderer.class.php +++ b/public_html/deployment/classes/plugins_renderer.class.php @@ -18,8 +18,9 @@ require_once('plugins.class.php'); * * @author axel */ -class plugin_renderer extends ciplugins { - +class plugin_renderer extends ciplugins +{ + // --------------------------------------------------------------- // // BELOW ARE METHODS FOR A SET SPECIFIC PLUGIN AND TYPE @@ -30,38 +31,41 @@ class plugin_renderer extends ciplugins { // --------------------------------------------------------------- // LANGUAGE TEXTS (needed in ui only) // --------------------------------------------------------------- - + /** - * get a translated text from lang_XX.json in plugin dir; + * Get a translated text from lang_XX.json in plugin dir; * If the key is missed it returns "[KEY :: LANG]" * * @see setLang() * @param string $sKey key to find in lang file * @return string */ - protected function _t($sKey){ + protected function _t(string $sKey): string + { return (isset($this->_aLang[$sKey]) && $this->_aLang[$sKey]) - ? $this->_aLang[$sKey] - : "[ $sKey :: $this->_sLang ]" + ? $this->_aLang[$sKey] + : "[ $sKey :: $this->_sLang ]" ; } /** - * set language for output of formdata and other texts. + * Set language for output of formdata and other texts. * This method loads the language file into a hash. The output of * translated texts can be done with $this->_t("your_key") * * @see _t() + * * @param string $sLang language code, i.e. "de" * @return boolean */ - public function setLang($sLang=false){ - $this->_sLang=$sLang ? $sLang : $this->_sLang; - - $oReflection=new ReflectionClass($this); - $sFile=dirname($oReflection->getFileName()) . '/lang_'.$this->_sLang.'.json'; - $this->_aLang=(file_exists($sFile)) ? json_decode(file_get_contents($sFile), 1) : $this->_aLang; - return true; + public function setLang(string $sLang = ''): bool + { + $this->_sLang = $sLang ?: $this->_sLang; + + $oReflection = new ReflectionClass($this); + $sFile = dirname($oReflection->getFileName()) . '/lang_' . $this->_sLang . '.json'; + $this->_aLang = (file_exists($sFile)) ? json_decode(file_get_contents($sFile), 1) : $this->_aLang; + return !!count($this->_aLang); } // --------------------------------------------------------------- // SETTER @@ -73,44 +77,52 @@ class plugin_renderer extends ciplugins { // --------------------------------------------------------------- /** - * for shellcmd plugins: get html code to load javascript file + * For shellcmd plugins: get html code to load javascript file * The file must exist in the plugin directory - * @params string $sFile (basename of) filename, eg. render.js + * + * @param string $sFile (basename of) filename, eg. render.js + * @return string */ - public function getHtmlLoadScript($sFile){ - return (file_exists($this->_sSelfdir.'/'.$sFile)) - ? '<script src="'.$this->_sSelfurl.'/'.$sFile.'"></script>'."\n" + public function getHtmlLoadScript(string $sFile): string + { + return (file_exists($this->_sSelfdir . '/' . $sFile)) + ? '<script src="' . $this->_sSelfurl . '/' . $sFile . '"></script>' . "\n" : '' ; } /** - * get id for an output div + * Get id for an output div * @return string */ - public function getHtmlOutId(){ - return $this->_sPluginname ? 'divPlugin'.$this->_sType.''.$this->_sPluginname : false; + public function getHtmlOutId(): string + { + return $this->_sPluginname ? 'divPlugin' . $this->_sType . '' . $this->_sPluginname : false; } + /** - * get id for the wrapper div of an output div + * Get id for the wrapper div of an output div * @return string */ - public function getHtmlOutIdWrapper(){ - return $this->getHtmlOutId().'Wrapper'; + public function getHtmlOutIdWrapper(): string + { + return $this->getHtmlOutId() . 'Wrapper'; } /** - * get html code for a shellcmd output window + * Get html code for a shellcmd output window + * @return string The HTML code */ - public function getHtmlOutwindow(){ - $aConfig=$this->getPluginConfig(); - return '<div id="'.$this->getHtmlOutIdWrapper().'" class="cmdoutbox">' - .'<div id="'.$this->getHtmlOutId().'" ' - .'class="out' - .(isset($aConfig['window-cols']) && $aConfig['window-cols'] ? ' cmd-cols-'.$aConfig['window-cols'] : '' ) - .(isset($aConfig['window-lines']) && $aConfig['window-lines'] ? ' cmd-lines-'.$aConfig['window-lines'] : '' ) - .'"></div>' - .'</div>'; + public function getHtmlOutwindow(): string + { + $aConfig = $this->getPluginConfig(); + return '<div id="' . $this->getHtmlOutIdWrapper() . '" class="cmdoutbox">' + . '<div id="' . $this->getHtmlOutId() . '" ' + . 'class="out' + . (isset($aConfig['window-cols']) && $aConfig['window-cols'] ? ' cmd-cols-' . $aConfig['window-cols'] : '') + . (isset($aConfig['window-lines']) && $aConfig['window-lines'] ? ' cmd-lines-' . $aConfig['window-lines'] : '') + . '"></div>' + . '</div>'; } // --------------------------------------------------------------- diff --git a/public_html/deployment/classes/plugins_shellcmd_request.class.php b/public_html/deployment/classes/plugins_shellcmd_request.class.php index a99ddd34b9d0d834fd601157df73ec1db55ed96c..d0064926d103a9540129e7485049e64308a55303 100644 --- a/public_html/deployment/classes/plugins_shellcmd_request.class.php +++ b/public_html/deployment/classes/plugins_shellcmd_request.class.php @@ -11,13 +11,41 @@ require_once('plugins.class.php'); class req_shellcmd { + /** + * plugin name + * @var string + */ protected $_sPlugin=false; + + /** + * pligin object + * @var object + */ protected $_oPlugin=false; - protected $_aReturn=false; + /** + * Array of return items + * TODO: might be removed + * @var array + */ + protected $_aReturn=[]; + + /** + * Configuration for the plugin + * @var array + */ protected $_aPluginConfig=[]; + /** + * Result after execution + * @var array + */ protected $_aResult=[]; + + /** + * Flag: enable debug? Default: false + * @var bool + */ protected $_debug=false; /** @@ -31,11 +59,10 @@ class req_shellcmd { // --------------------------------------------------------------- /** - * constructor - * @return bool + * Constructor */ public function __construct(){ - return $this->detectPlugin(); + $this->detectPlugin(); } // --------------------------------------------------------------- diff --git a/public_html/deployment/classes/rollout.interface.php b/public_html/deployment/classes/rollout.interface.php index 5b973b933d54f4dcb96bf4554cfb99827c6df57e..cc495b18ddc210f1744c36de6cfb9ee9f752521e 100644 --- a/public_html/deployment/classes/rollout.interface.php +++ b/public_html/deployment/classes/rollout.interface.php @@ -12,8 +12,9 @@ interface iRolloutplugin { /** * check requirements if the plugin could work + * @return array */ - public function checkRequirements(); + public function checkRequirements(): array; /** * check access to a deploy target diff --git a/public_html/deployment/classes/rollout_base.class.php b/public_html/deployment/classes/rollout_base.class.php index c8b1b214131f65b9f24416041bb7e11bfcc835ba..76dadb54081aa944f1645e673549848b0a2a2d8e 100644 --- a/public_html/deployment/classes/rollout_base.class.php +++ b/public_html/deployment/classes/rollout_base.class.php @@ -1,6 +1,6 @@ <?php require_once 'rollout.interface.php'; -require_once __DIR__.'/../../vendor/axelhahn/ahcache/cache.class.php'; +require_once __DIR__ . '/../../vendor/axelhahn/ahcache/cache.class.php'; /** * rollout_base class that will be extended in a rollout plugin @@ -8,8 +8,9 @@ require_once __DIR__.'/../../vendor/axelhahn/ahcache/cache.class.php'; * * @author axel */ -class rollout_base implements iRolloutplugin{ - +class rollout_base implements iRolloutplugin +{ + // --------------------------------------------------------------- // VARIABLES // --------------------------------------------------------------- @@ -18,18 +19,18 @@ class rollout_base implements iRolloutplugin{ * settings in the config structore for global and project based config * @var string */ - protected $_sPluginId='UNSET'; + protected $_sPluginId = 'UNSET'; /** * data with plugin infos (read from info.json) * @var array */ - protected $_aPlugininfos=false; - + protected $_aPlugininfos = false; + /** * array with translation texts - * @var type + * @var array */ - protected $_aLang=false; + protected $_aLang = []; /** * set language; 2 letter code, i.e. "de"; default language is "en" ; a @@ -44,13 +45,13 @@ class rollout_base implements iRolloutplugin{ * @var string */ protected $_sLang = 'en-en'; - + /** * string with phase of project; one of preview|stage|live - * @var type + * @var string */ protected $_sPhase = false; - + /** * global configuration of the rollout plugin * @var array @@ -61,10 +62,10 @@ class rollout_base implements iRolloutplugin{ * @var array */ protected $_aCfgProject = false; - - protected $_sNamePrefix4Project=false; // set in constructor - protected $_sNamePrefix4Phase=false; // set in constructor - + + protected $_sNamePrefix4Project = false; // set in constructor + protected $_sNamePrefix4Phase = false; // set in constructor + // --------------------------------------------------------------- // CONSTRUCTOR // --------------------------------------------------------------- @@ -79,35 +80,35 @@ class rollout_base implements iRolloutplugin{ * for project and all phases * @return boolean */ - public function __construct($aParams) { - + public function __construct($aParams) + { + // set current plugin id - taken from plugin directory name above - $oReflection=new ReflectionClass($this); - $this->_sPluginId=basename(dirname($oReflection->getFileName())); - + $oReflection = new ReflectionClass($this); + $this->_sPluginId = basename(dirname($oReflection->getFileName())); + // ----- init language - if (isset($aParams['lang'])){ + if (isset($aParams['lang'])) { $this->setLang($aParams['lang']); } else { $this->setLang(); } - + // ----- init phase - if (isset($aParams['phase'])){ + if (isset($aParams['phase'])) { $this->setPhase($aParams['phase']); } // ----- init global config - if (isset($aParams['globalcfg'])){ + if (isset($aParams['globalcfg'])) { $this->setGlobalConfig($aParams['globalcfg']); } // ----- init project config - if (isset($aParams['projectcfg'])){ + if (isset($aParams['projectcfg'])) { $this->setProjectConfig($aParams['projectcfg']); } - return true; } - + // --------------------------------------------------------------- // FORM HELPER // --------------------------------------------------------------- @@ -116,35 +117,37 @@ class rollout_base implements iRolloutplugin{ * get a string for a prefix for name attribute in form vars. * It is important to store the value in the wanted structure. * - * @param type $sPhase - * @return type + * @param string $sPhase + * @return string */ - protected function _getNamePrefix($sPhase=false){ + protected function _getNamePrefix($sPhase = false) + { return ($sPhase - ? 'phases['.$sPhase.'][plugins][rollout]['.$this->getId().']' - : 'plugins[rollout]['.$this->getId().']' + ? 'phases[' . $sPhase . '][plugins][rollout][' . $this->getId() . ']' + : 'plugins[rollout][' . $this->getId() . ']' ); } - + /** * get Data from a callback function and store it in a cache * The response type depends on the callback function * * @param string $sFunctionname name of the callback function * @param string $sKey name of the key; "project" or name of phase - * @param integr $iTtl ttl value = how many seconds to use cache - * @param integr $iTtlOnError ttl value = how many seconds to use cache if there was no response - * @return type + * @param integer $iTtl ttl value = how many seconds to use cache + * @param integer $iTtlOnError ttl value = how many seconds to use cache if there was no response + * @return mixed */ - protected function _getCallback($sFunctionname, $sKey, $iTtl=15,$iTtlOnError=10){ - $oCache=new AhCache('rollout-'.$this->getId(), 'callback-'.$sFunctionname.'-'.$sKey); - if($oCache->isExpired()){ - $aMydata= call_user_func(array($this, $sFunctionname)); + protected function _getCallback($sFunctionname, $sKey, $iTtl = 15, $iTtlOnError = 10) + { + $oCache = new AhCache('rollout-' . $this->getId(), 'callback-' . $sFunctionname . '-' . $sKey); + if ($oCache->isExpired()) { + $aMydata = call_user_func(array($this, $sFunctionname)); // echo "$sFunctionname fresh ".($aMydata ? "OK": "false")." - storing for $iTtl sec<br>"; $oCache->write($aMydata, ($aMydata ? $iTtl : $iTtlOnError)); } else { // echo "$sFunctionname from cache ... ".$oCache->iExpired()." sec <br>"; - $aMydata=$oCache->read(); + $aMydata = $oCache->read(); } // echo '<pre>'.print_r($aMydata, 1).'</pre>'; die(__METHOD__); return $aMydata; @@ -155,113 +158,115 @@ class rollout_base implements iRolloutplugin{ * @param string $sKey part of the identifier used in id of the input field * @return string */ - protected function _renderForm($aFormdata, $sKey){ + protected function _renderForm($aFormdata, $sKey) + { static $i; - if (!isset($i)){ - $i=0; + if (!isset($i)) { + $i = 0; } - $sReturn=''; - $sKeyPrefix=$this->getId().'_'.$sKey; - + $sReturn = ''; + $sKeyPrefix = $this->getId() . '_' . $sKey; + $oForm = new formgen(); foreach ($aFormdata as $elementData) { - $elementKey=$sKeyPrefix.'_'.$i++; - $sReturn.=$oForm->renderHtmlElement($elementKey, $elementData); + $elementKey = $sKeyPrefix . '_' . $i++; + $sReturn .= $oForm->renderHtmlElement($elementKey, $elementData); } return $sReturn; } - + /** * render form fields for global plugin variables * @param string $sScope scope of vars ... one of global|project|phase * @param string $sPhase optional: render global vars in a phase; if no phase was set it renders form fields for project based settings * @return string */ - protected function _renderForm4Vars($sScope, $sPhase=false){ - $sReturn=''; - + protected function _renderForm4Vars($sScope, $sPhase = false) + { + $sReturn = ''; + // test vars from info.json file - $aInfos=$this->getPluginInfos(); - if(!isset($aInfos['vars'][$sScope]) || !count($aInfos['vars'][$sScope])){ + $aInfos = $this->getPluginInfos(); + if (!isset($aInfos['vars'][$sScope]) || !count($aInfos['vars'][$sScope])) { return ''; } - - $sKey=($sPhase ? 'phase_'.$sPhase : 'project'); - $sPrefixName=$this->_getNamePrefix($sPhase); - + + $sKey = ($sPhase ? 'phase_' . $sPhase : 'project'); + $sPrefixName = $this->_getNamePrefix($sPhase); + // set defaults - to be used in placeholder attribute // no phase = project level - take global defaults of ci config // on a phase - fetch merged cofig data of project - $aDefaultValues=($sPhase ? $this->getConfig() : $this->_aCfgGlobal); - $aDefaultSource=($sPhase ? 'project' : 'global'); - + $aDefaultValues = ($sPhase ? $this->getConfig() : $this->_aCfgGlobal); + $aDefaultSource = ($sPhase ? 'project' : 'global'); + // set defaults - to be used in value attribute - $aValues=($sPhase - ? $this->_aCfgProject['phases'][$sPhase]['plugins']['rollout'][$this->getId()] - : $this->_aCfgProject['plugins']['rollout'][$this->getId()] + $aValues = ($sPhase + ? $this->_aCfgProject['phases'][$sPhase]['plugins']['rollout'][$this->getId()] + : $this->_aCfgProject['plugins']['rollout'][$this->getId()] ); - - + + // create form fields // $aFormdata[]=array('type' => 'markup','value' => '<br>'.$this->_t('section-override-'.$sScope.'-vars').':'); - $aFormdata[]=array('type' => 'markup','value' => '<div style="style: clear: left;"></div><h4>'.$this->getId() .' :: '. $sScope.'</h4>'); - - $sMiss=''; - foreach ($aInfos['vars'][$sScope] as $sVarname=>$aVarinfos){ - if ($sScope==='global' && !isset($this->_aCfgGlobal[$sVarname])){ - $sMiss.='- plugin var was not set in global CI config: "'.$sVarname.'".<br>'; + $aFormdata[] = array('type' => 'markup', 'value' => '<div style="style: clear: left;"></div><h4>' . $this->getId() . ' :: ' . $sScope . '</h4>'); + + $sMiss = ''; + foreach ($aInfos['vars'][$sScope] as $sVarname => $aVarinfos) { + if ($sScope === 'global' && !isset($this->_aCfgGlobal[$sVarname])) { + $sMiss .= '- plugin var was not set in global CI config: "' . $sVarname . '".<br>'; } - - - $sMyPlaceholder=(isset($aDefaultValues[$sVarname]) - ? htmlentities($aDefaultValues[$sVarname]) - : (isset($aVarinfos['default']) ? $aVarinfos['default'] : 'N.A.') - ); - + + + $sMyPlaceholder = (isset($aDefaultValues[$sVarname]) + ? htmlentities($aDefaultValues[$sVarname]) + : (isset($aVarinfos['default']) ? $aVarinfos['default'] : 'N.A.') + ); + // if a callback was set for this variable - if(isset($aVarinfos['callback'])){ - $aCallbackData=$this->_getCallback( - $aVarinfos['callback'], - (isset($aVarinfos['per_scope']) && $aVarinfos['per_scope'] ? $sKey : ''), - (isset($aVarinfos['ttl']) ? $aVarinfos['ttl'] : 60) + if (isset($aVarinfos['callback'])) { + $aCallbackData = $this->_getCallback( + $aVarinfos['callback'], + (isset($aVarinfos['per_scope']) && $aVarinfos['per_scope'] ? $sKey : ''), + (isset($aVarinfos['ttl']) ? $aVarinfos['ttl'] : 60) ); - if(!$aCallbackData){ - $aVarinfos['type']='text'; + if (!$aCallbackData) { + $aVarinfos['type'] = 'text'; } else { - $aEffectiveConfig=$this->getConfig($sPhase); + $aEffectiveConfig = $this->getConfig($sPhase); // echo $sKey.' ... '; print_r($aEffectiveConfig[$sVarname]); echo '<br>'; - + // mark entry as active ... for select and radio - if(isset($aEffectiveConfig[$sVarname]) && isset($aCallbackData[$aEffectiveConfig[$sVarname]])){ - $aCallbackData[$aEffectiveConfig[$sVarname]]['selected']='selected'; - $aCallbackData[$aEffectiveConfig[$sVarname]]['checked']='checked'; - $aCallbackData[$aEffectiveConfig[$sVarname]]['label'].=' ««'; - } elseif ($aVarinfos['type']==='select') { - $aCallbackData=array_merge(array('NO_SELECTED_ITEM_YET'=>array('value'=>'', 'label'=>'...')), $aCallbackData); + if (isset($aEffectiveConfig[$sVarname]) && isset($aCallbackData[$aEffectiveConfig[$sVarname]])) { + $aCallbackData[$aEffectiveConfig[$sVarname]]['selected'] = 'selected'; + $aCallbackData[$aEffectiveConfig[$sVarname]]['checked'] = 'checked'; + $aCallbackData[$aEffectiveConfig[$sVarname]]['label'] .= ' ««'; + } elseif ($aVarinfos['type'] === 'select') { + $aCallbackData = array_merge(array('NO_SELECTED_ITEM_YET' => array('value' => '', 'label' => '...')), $aCallbackData); } - + // wenn value = defaultvalue, dann value auf '' setzen (damit bei Default vom Scope // davor ein Leerstring übergeben wird - analog onfocusout im Text Input - if (isset($aCallbackData[$aDefaultValues[$sVarname]])){ - $aCallbackData[$aDefaultValues[$sVarname]]['value']=''; - $aCallbackData[$aDefaultValues[$sVarname]]['label'].=' (*)'; - } + if (isset($aCallbackData[$aDefaultValues[$sVarname]])) { + $aCallbackData[$aDefaultValues[$sVarname]]['value'] = ''; + $aCallbackData[$aDefaultValues[$sVarname]]['label'] .= ' (*)'; + } // print_r($aCallbackData[$sVarname]); echo "<br>"; } // echo '<pre>'.$sCallbackfunktion .' = '. print_r($aMydata,1 ).'</pre>'; } switch ($aVarinfos['type']) { case "password": - $sMyPlaceholder=(isset($aDefaultValues[$sVarname]) - ? '******************************' - : $sMyPlaceholder - ); - $aFormdata[]=array( + $sMyPlaceholder = (isset($aDefaultValues[$sVarname]) + ? '******************************' + : $sMyPlaceholder + ); + $aFormdata[] = array( 'type' => $aVarinfos['type'], - 'name' => $sPrefixName.'['.$sVarname.']', - 'label' => $this->_t($sVarname.'-label'), - 'title' => $this->_t($sVarname.'-hint'), + 'name' => $sPrefixName . '[' . $sVarname . ']', + 'label' => $this->_t($sVarname . '-label'), + 'title' => $this->_t($sVarname . '-hint'), 'value' => (isset($aValues[$sVarname]) ? htmlentities($aValues[$sVarname]) : ''), // 'required' => 'required', 'validate' => 'isastring', @@ -272,31 +277,32 @@ class rollout_base implements iRolloutplugin{ break; case "select": case "radio": - $aOptions=$aCallbackData; - $aFormdata[]=array( + $aOptions = $aCallbackData; + $aFormdata[] = array( 'type' => $aVarinfos['type'], - 'name' => $sPrefixName.'['.$sVarname.']', - 'label' => $this->_t($sVarname.'-label'), - 'title' => $this->_t($sVarname.'-hint'), + 'name' => $sPrefixName . '[' . $sVarname . ']', + 'label' => $this->_t($sVarname . '-label'), + 'title' => $this->_t($sVarname . '-hint'), 'validate' => 'isastring', 'options' => $aOptions, - + // 'placeholder' => $sMyPlaceholder ); break; case "text": - $aFormdata[]=array( + $aFormdata[] = array( 'type' => $aVarinfos['type'], - 'name' => $sPrefixName.'['.$sVarname.']', - 'label' => $this->_t($sVarname.'-label'), - 'ondblclick' => ($aDefaultValues[$sVarname] ? 'if (this.value==\'\') { this.value=\''.$aDefaultValues[$sVarname].'\' }' : ''), - 'onfocusout' => ($aDefaultValues[$sVarname] ? 'if (this.value==\''.$aDefaultValues[$sVarname].'\') { this.value=\'\' }' : ''), - 'title' => htmlentities($this->_t($sVarname.'-hint')."\n" - . ($this->_aCfgGlobal[$sVarname] ? '- global: '.$this->_aCfgGlobal[$sVarname]."\n" : '') - . ($this->_aCfgProject['plugins']['rollout'][$this->getId()][$sVarname] ? '- project: '.$this->_aCfgProject['plugins']['rollout'][$this->getId()][$sVarname]."\n" : '') - ) - , + 'name' => $sPrefixName . '[' . $sVarname . ']', + 'label' => $this->_t($sVarname . '-label'), + 'ondblclick' => ($aDefaultValues[$sVarname] ? 'if (this.value==\'\') { this.value=\'' . $aDefaultValues[$sVarname] . '\' }' : ''), + 'onfocusout' => ($aDefaultValues[$sVarname] ? 'if (this.value==\'' . $aDefaultValues[$sVarname] . '\') { this.value=\'\' }' : ''), + 'title' => htmlentities( + $this->_t($sVarname . '-hint') . "\n" + . ($this->_aCfgGlobal[$sVarname] ? '- global: ' . $this->_aCfgGlobal[$sVarname] . "\n" : '') + . ($this->_aCfgProject['plugins']['rollout'][$this->getId()][$sVarname] ? '- project: ' . $this->_aCfgProject['plugins']['rollout'][$this->getId()][$sVarname] . "\n" : '') + ) + , 'value' => (isset($aValues[$sVarname]) ? htmlentities($aValues[$sVarname]) : ''), // 'required' => 'required', 'validate' => 'isastring', @@ -307,19 +313,19 @@ class rollout_base implements iRolloutplugin{ break; default: - $sMiss.='- plugin var "'.$sVarname.'" was not rendered - its type "'.$aVarinfos['type'].'" is not supported in the general form renderer.<br>'; - break; + $sMiss .= '- plugin var "' . $sVarname . '" was not rendered - its type "' . $aVarinfos['type'] . '" is not supported in the general form renderer.<br>'; + break; } } // $aFormdata[]=array('type' => 'markup','value' => '<div style="style: clear: left;"></div><br><br>'); return $this->_renderForm($aFormdata, $sKey) - . ($sMiss - ? '<pre>WARNINGS:<br>'.$sMiss.'</pre>' . ($sScope==='global' ? $this -> renderCfgExample() : '' ) + . ($sMiss + ? '<pre>WARNINGS:<br>' . $sMiss . '</pre>' . ($sScope === 'global' ? $this->renderCfgExample() : '') : '' ) - ; + ; } - + /** * get a translated text from lang_XX.json in plugin dir; * If the key is missed it returns "[KEY :: LANG]" @@ -328,10 +334,11 @@ class rollout_base implements iRolloutplugin{ * @param string $sKey key to find in lang file * @return string */ - protected function _t($sKey){ + protected function _t($sKey) + { return (isset($this->_aLang[$sKey]) && $this->_aLang[$sKey]) - ? $this->_aLang[$sKey] - : "[ $sKey :: $this->_sLang ]" + ? $this->_aLang[$sKey] + : "[ $sKey :: $this->_sLang ]" ; } @@ -348,27 +355,29 @@ class rollout_base implements iRolloutplugin{ * @param string $sLang language code, i.e. "de-de" * @return boolean */ - public function setLang($sLang=false){ - $this->_sLang=$sLang ? $sLang : $this->_sLang; - - $oReflection=new ReflectionClass($this); - $sFile=dirname($oReflection->getFileName()) . '/lang_'.$this->_sLang.'.json'; - if (!file_exists($sFile)){ - $sFile=dirname($oReflection->getFileName()) . '/lang_'.$this->_sFallbackLang.'.json'; - $this->_sLang=$this->_sFallbackLang; + public function setLang($sLang = false) + { + $this->_sLang = $sLang ? $sLang : $this->_sLang; + + $oReflection = new ReflectionClass($this); + $sFile = dirname($oReflection->getFileName()) . '/lang_' . $this->_sLang . '.json'; + if (!file_exists($sFile)) { + $sFile = dirname($oReflection->getFileName()) . '/lang_' . $this->_sFallbackLang . '.json'; + $this->_sLang = $this->_sFallbackLang; } - $this->_aLang=(file_exists($sFile)) ? json_decode(file_get_contents($sFile), 1) : $this->_aLang; + $this->_aLang = (file_exists($sFile)) ? json_decode(file_get_contents($sFile), 1) : $this->_aLang; return true; } - + /** * set a phase for automatic use GETTER methods */ - public function setPhase($sPhase){ - $this->_sPhase=$sPhase; + public function setPhase($sPhase) + { + $this->_sPhase = $sPhase; return true; } - + // ---------------------------------------------------------------------- // INTERFACE :: CHECKS @@ -376,16 +385,19 @@ class rollout_base implements iRolloutplugin{ /** * check requirements if the plugin could work + * @return array */ - public function checkRequirements(){ - // no specific checks needed ... always true - return true; + public function checkRequirements(): array + { + // no specific checks needed ... always empty + return []; } /** * check access to a deploy target */ - public function checkConnectionToTarget(){ + public function checkConnectionToTarget() + { // do nothing ... always true return true; } @@ -399,8 +411,9 @@ class rollout_base implements iRolloutplugin{ * set Config ... by given global config of the current plugin * @param array $aConfigArray */ - public function setGlobalConfig($aConfigArray){ - return $this->_aCfgGlobal=$aConfigArray; + public function setGlobalConfig($aConfigArray) + { + return $this->_aCfgGlobal = $aConfigArray; } @@ -408,12 +421,13 @@ class rollout_base implements iRolloutplugin{ /** * set Config ... by given project config */ - public function setProjectConfig($aProjectConfigArray){ - $this->_aCfgProject=$aProjectConfigArray; + public function setProjectConfig($aProjectConfigArray) + { + $this->_aCfgProject = $aProjectConfigArray; // echo '<pre>'.print_r($aProjectConfigArray, 1).'</pre>'; // ----- ensure that the config structure exists // (it is easier fo handling in getConfig()) - if (!isset($this->_aCfgProject['plugins']['rollout'][$this->_sPluginId])){ + if (!isset($this->_aCfgProject['plugins']['rollout'][$this->_sPluginId])) { /* if (!isset($this->_aCfgProject['plugins']['rollout'])){ if (!isset($this->_aCfgProject['plugins'])){ @@ -423,20 +437,20 @@ class rollout_base implements iRolloutplugin{ } * */ - $this->_aCfgProject['plugins']['rollout'][$this->_sPluginId]=array('INFO'=>'created'); + $this->_aCfgProject['plugins']['rollout'][$this->_sPluginId] = array('INFO' => 'created'); } - + // unset empty project values to get global values - foreach ($this->_aCfgProject['plugins']['rollout'][$this->_sPluginId] as $sVarname=>$value){ - if ($value===''){ + foreach ($this->_aCfgProject['plugins']['rollout'][$this->_sPluginId] as $sVarname => $value) { + if ($value === '') { unset($this->_aCfgProject['plugins']['rollout'][$this->_sPluginId][$sVarname]); } } - foreach (array_keys($this->_aCfgProject['phases']) as $sMyPhase){ - if (isset($this->_aCfgProject['phases'][$sMyPhase]['plugins']['rollout'][$this->getId()])){ - foreach($this->_aCfgProject['phases'][$sMyPhase]['plugins']['rollout'][$this->getId()] as $sVarname=>$value){ - if ($value===''){ + foreach (array_keys($this->_aCfgProject['phases']) as $sMyPhase) { + if (isset($this->_aCfgProject['phases'][$sMyPhase]['plugins']['rollout'][$this->getId()])) { + foreach ($this->_aCfgProject['phases'][$sMyPhase]['plugins']['rollout'][$this->getId()] as $sVarname => $value) { + if ($value === '') { unset($this->_aCfgProject['phases'][$sMyPhase]['plugins']['rollout'][$this->getId()][$sVarname]); } } @@ -445,7 +459,7 @@ class rollout_base implements iRolloutplugin{ // TODO: return $this->_aCfgProject; } - + // ---------------------------------------------------------------------- // INTERFACE :: GETTER // ---------------------------------------------------------------------- @@ -456,14 +470,15 @@ class rollout_base implements iRolloutplugin{ * @param boolean $bMask Flag for public output; if true then mask your secrets * @return array */ - public function getConfig($sPhase=false, $bMask=false){ + public function getConfig($sPhase = false, $bMask = false) + { - $aReturn=array_merge($this->_aCfgGlobal, $this->_aCfgProject['plugins']['rollout'][$this->getId()]); - if($sPhase && isset($this->_aCfgProject['phases'][$sPhase]['plugins']['rollout'][$this->getId()])){ - $aReturn=array_merge($aReturn, $this->_aCfgProject['phases'][$sPhase]['plugins']['rollout'][$this->getId()]); + $aReturn = array_merge($this->_aCfgGlobal, $this->_aCfgProject['plugins']['rollout'][$this->getId()]); + if ($sPhase && isset($this->_aCfgProject['phases'][$sPhase]['plugins']['rollout'][$this->getId()])) { + $aReturn = array_merge($aReturn, $this->_aCfgProject['phases'][$sPhase]['plugins']['rollout'][$this->getId()]); } - if ($bMask && isset($aReturn['password'])){ - $aReturn['password']='**********'; + if ($bMask && isset($aReturn['password'])) { + $aReturn['password'] = '**********'; } return $aReturn; /* @@ -473,58 +488,63 @@ class rollout_base implements iRolloutplugin{ ; */ } - + /** * get an array with shell commands to execute * @param string $sPhase * @param boolean $bMask Flag for public output; if true then mask your secrets * @return array */ - public function getDeployCommands($sPhase, $bMask=false){ + public function getDeployCommands($sPhase, $bMask = false) + { return [ - 'echo "ERROR: The method getDeployCommamds($sPhase) was not implemented in the rollout plugin ['.$this->getId().']"', + 'echo "ERROR: The method getDeployCommamds($sPhase) was not implemented in the rollout plugin [' . $this->getId() . ']"', 'exit 1' - ]; + ]; } - + /** * get string with current ID * @return string */ - public function getId(){ + public function getId() + { return $this->_sPluginId; } - + /** * get string with plugin name (taken from plugin language file) * @return string */ - public function getName(){ + public function getName() + { return $this->_t('plugin_name'); } - + /** * get string with plugin description (taken from plugin language file) * @return string */ - public function getDescription(){ + public function getDescription() + { return $this->_t('description'); } /** * get array read from info.json - * @return type + * @return array */ - public function getPluginInfos(){ + public function getPluginInfos() + { - if ($this->_aPlugininfos){ + if ($this->_aPlugininfos) { return $this->_aPlugininfos; } - - $oReflection=new ReflectionClass($this); - $sFile=dirname($oReflection->getFileName()) . '/info.json'; - $this->_aPlugininfos= (file_exists($sFile)) + + $oReflection = new ReflectionClass($this); + $sFile = dirname($oReflection->getFileName()) . '/info.json'; + $this->_aPlugininfos = (file_exists($sFile)) ? json_decode(file_get_contents($sFile), 1) - : array('error'=> 'unable to read info file ['.$sFile.'].') + : array('error' => 'unable to read info file [' . $sFile . '].') ; return $this->_aPlugininfos; } @@ -532,12 +552,13 @@ class rollout_base implements iRolloutplugin{ // ---------------------------------------------------------------------- // INTERFACE :: RENDERER // ---------------------------------------------------------------------- - public function renderCfgExample(){ - $sReturn=''; - $sPre=' '; - - $aInfos=$this->getPluginInfos(); - $sReturn.='<pre>$aConfig = array( + public function renderCfgExample() + { + $sReturn = ''; + $sPre = ' '; + + $aInfos = $this->getPluginInfos(); + $sReturn .= '<pre>$aConfig = array( ... \'plugins\'=>array( ... @@ -545,23 +566,23 @@ class rollout_base implements iRolloutplugin{ \'rollout\'=>array( ... <strong> - \''.$this->getId().'\'=>array( - // '.$this->getName().' - // '.$this->getDescription().' - '.PHP_EOL; - + \'' . $this->getId() . '\'=>array( + // ' . $this->getName() . ' + // ' . $this->getDescription() . ' + ' . PHP_EOL; + // add global vars - if(!isset($aInfos['vars']['global']) || !count($aInfos['vars']['global'])){ - $sReturn.=$sPre.'// this plugin has no global config vars'.PHP_EOL; + if (!isset($aInfos['vars']['global']) || !count($aInfos['vars']['global'])) { + $sReturn .= $sPre . '// this plugin has no global config vars' . PHP_EOL; } else { - foreach ($aInfos['vars']['global'] as $sVar=>$aItem){ - $sReturn.=$sPre.'// '.$this->_t($sVar.'-hint').PHP_EOL; - $sReturn.=$sPre.'\''.$sVar.'\'=>\''.(isset($this->_aCfgGlobal[$sVar]) ? $this->_aCfgGlobal[$sVar] : $aItem['default']).'\','.PHP_EOL; - $sReturn.=PHP_EOL; + foreach ($aInfos['vars']['global'] as $sVar => $aItem) { + $sReturn .= $sPre . '// ' . $this->_t($sVar . '-hint') . PHP_EOL; + $sReturn .= $sPre . '\'' . $sVar . '\'=>\'' . (isset($this->_aCfgGlobal[$sVar]) ? $this->_aCfgGlobal[$sVar] : $aItem['default']) . '\',' . PHP_EOL; + $sReturn .= PHP_EOL; } } - - $sReturn.=' + + $sReturn .= ' ), </strong> ... @@ -571,32 +592,35 @@ class rollout_base implements iRolloutplugin{ );</pre>'; return $sReturn; } - protected function _renderMoreToggler($sContent){ - $sDivId='rollout-more-toggler-'.$this->getId().'-'.md5($sContent); + protected function _renderMoreToggler($sContent) + { + $sDivId = 'rollout-more-toggler-' . $this->getId() . '-' . md5($sContent); return '' - . '<button onclick="$(\'#'.$sDivId.'\').slideToggle(); return false;" class="btn btn-secondary"> ... </button>' - . '<div id="'.$sDivId.'" style="display: none;">' - . $sContent - . '</div>' - ; - + . '<button onclick="$(\'#' . $sDivId . '\').slideToggle(); return false;" class="btn btn-secondary"> ... </button>' + . '<div id="' . $sDivId . '" style="display: none;">' + . $sContent + . '</div>' + ; + } - public function renderFormdata4Project() { + public function renderFormdata4Project() + { return '' - . $this->_renderForm4Vars('project', false) - . $this->_renderForm4Vars('global', false) - // . $this->_renderFormProjectVars($this->_sNamePrefix4Project, false) - // . '<pre>DEBUG: GLOBAL settings - $this->_aCfgGlobal = ' . print_r($this->_aCfgGlobal, 1) . '</pre>' - // . '<pre>DEBUG: PROJECT settings - $this->getConfig() = ' . print_r($this->getConfig(), 1) . '</pre>' - // .'<pre>DEBUG: $this->_aCfgProject ... plugin = '.print_r($this->_aCfgProject, 1).'</pre>' + . $this->_renderForm4Vars('project', false) + . $this->_renderForm4Vars('global', false) + // . $this->_renderFormProjectVars($this->_sNamePrefix4Project, false) + // . '<pre>DEBUG: GLOBAL settings - $this->_aCfgGlobal = ' . print_r($this->_aCfgGlobal, 1) . '</pre>' + // . '<pre>DEBUG: PROJECT settings - $this->getConfig() = ' . print_r($this->getConfig(), 1) . '</pre>' + // .'<pre>DEBUG: $this->_aCfgProject ... plugin = '.print_r($this->_aCfgProject, 1).'</pre>' ; } - public function renderFormdata4Phase($sPhase){ + public function renderFormdata4Phase($sPhase) + { static $iCounter; - if(!isset($iCounter)){ - $iCounter=0; + if (!isset($iCounter)) { + $iCounter = 0; } - $sDivId='rollout-override-div-'.$this->getId().'-'.$sPhase.'-'.$iCounter; + $sDivId = 'rollout-override-div-' . $this->getId() . '-' . $sPhase . '-' . $iCounter; return '' . $this->_renderForm4Vars('phase', $sPhase) . $this->_renderMoreToggler( @@ -608,6 +632,6 @@ class rollout_base implements iRolloutplugin{ // . '<pre>DEBUG: GLOBAL settings - $this->_aCfgGlobal = ' . print_r($this->_aCfgGlobal, 1) . '</pre>' // . '<pre>DEBUG: PROJECT settings - $this->getConfig() = ' . print_r($this->getConfig(), 1) . '</pre>' // . '<pre>DEBUG: PHASE settings - $this->getConfig("'.$sMyPhase.'") = ' . print_r($this->getConfig($sMyPhase), 1) . '</pre>' - ; + ; } } diff --git a/public_html/deployment/plugins/build/tgz/build_tgz.php b/public_html/deployment/plugins/build/tgz/build_tgz.php index 743a570b348326cc4ffe2a5766e70769c7d1e686..2b7ffd4a4a6ad6002fe4c086a98ee004b41b9bf9 100644 --- a/public_html/deployment/plugins/build/tgz/build_tgz.php +++ b/public_html/deployment/plugins/build/tgz/build_tgz.php @@ -6,27 +6,30 @@ * * @author <axel.hahn@iml.unibe.ch> */ -class build_tgz extends build_base { - +class build_tgz extends build_base +{ + /** * check requirements if the plugin could work * @return array */ - public function checkRequirements() { + public function checkRequirements(): array + { return [ 'which tar' ]; } - + /** * get an array with shell commands to execute * @return array */ - public function getBuildCommands(){ + public function getBuildCommands(): array + { return [ - 'cd "'. $this->getBuildDir(). '" && tar -czf "'. $this->getOutfile().'" .' + 'cd "' . $this->getBuildDir() . '" && tar -czf "' . $this->getOutfile() . '" .' ]; } - + } diff --git a/public_html/deployment/plugins/build/zip/build_zip.php b/public_html/deployment/plugins/build/zip/build_zip.php index 2fadc359a115da1f020de2bb93ee7f625db53226..c5512f0ace4f0051e7618f5a3773184653ca3af5 100644 --- a/public_html/deployment/plugins/build/zip/build_zip.php +++ b/public_html/deployment/plugins/build/zip/build_zip.php @@ -6,18 +6,20 @@ * * @author <axel.hahn@iml.unibe.ch> */ -class build_zip extends build_base { - +class build_zip extends build_base +{ + /** * check requirements if the plugin could work * @return array */ - public function checkRequirements() { + public function checkRequirements(): array + { return [ 'which zip' ]; } - + /** * get an array with shell commands to execute * used zip params: @@ -26,11 +28,12 @@ class build_zip extends build_base { * -r recurse into directories * @return array */ - public function getBuildCommands(){ + public function getBuildCommands(): array + { return [ - 'cd "'. $this->getBuildDir(). '" && zip -9qr "'. $this->getOutfile().'" .' + 'cd "' . $this->getBuildDir() . '" && zip -9qr "' . $this->getOutfile() . '" .' ]; } - + } diff --git a/public_html/deployment/plugins/rollout/awx/rollout_awx.php b/public_html/deployment/plugins/rollout/awx/rollout_awx.php index 5bb671355cb88fb4f93a3c59ecb482075be05902..910adccf9b6584e0ceb74e939cbfbc8492b561fa 100644 --- a/public_html/deployment/plugins/rollout/awx/rollout_awx.php +++ b/public_html/deployment/plugins/rollout/awx/rollout_awx.php @@ -8,27 +8,30 @@ * * @author <axel.hahn@iml.unibe.ch> */ -class rollout_awx extends rollout_base { - +class rollout_awx extends rollout_base +{ + // url part for AWX API request to set count of results per page - protected $_sAwxApiPaging='&page_size=10000&page=1'; + protected $_sAwxApiPaging = '&page_size=10000&page=1'; /** * check requirements if the plugin could work */ - public function checkRequirements() { - // no specific checks needed ... always true - return true; + public function checkRequirements(): array + { + // no specific checks needed ... always empty + return []; } - + /** * check access to a deploy target */ - public function checkConnectionToTarget() { - // do nothing ... always true - return true; + public function checkConnectionToTarget() + { + // do nothing ... always empty + return []; } - + /** * make an http get request and return the response body * it is called by _makeRequest @@ -38,45 +41,46 @@ class rollout_awx extends rollout_base { * - postdata; for POST only * * @param array $aRequest arrayurl for Foreman API - * @return string + * @return array */ - protected function _httpRequest($aRequest=false, $iTimeout = 5) { + protected function _httpRequest($aRequest = false, $iTimeout = 5) + { if (!function_exists("curl_init")) { die("ERROR: PHP CURL module is not installed."); } - $aConfig=$this->getConfig(); - - - $ch = curl_init($aConfig['url'].$aRequest['url']); + $aConfig = $this->getConfig(); + + + $ch = curl_init($aConfig['url'] . $aRequest['url']); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $aRequest['method']); - if ($this->_aRequest['method']==='POST'){ + if ($aRequest['method'] === 'POST') { curl_setopt($ch, CURLOPT_POSTFIELDS, $aRequest['postdata']); } - if ($aConfig['user']){ - curl_setopt($ch, CURLOPT_USERPWD, $aConfig['user'].':'.$aConfig['password']); + if ($aConfig['user']) { + curl_setopt($ch, CURLOPT_USERPWD, $aConfig['user'] . ':' . $aConfig['password']); } - if (isset($aConfig['ignore-ssl-error']) && $aConfig['ignore-ssl-error']){ + if (isset($aConfig['ignore-ssl-error']) && $aConfig['ignore-ssl-error']) { curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); } - + curl_setopt($ch, CURLOPT_TIMEOUT, $iTimeout); curl_setopt($ch, CURLOPT_USERAGENT, 'IML Deployment :: rollout plugin awx ' . __CLASS__); - curl_setopt($ch, CURLOPT_HEADER,1); - curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); + curl_setopt($ch, CURLOPT_HEADER, 1); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $res = curl_exec($ch); - - $aReturn=array('info'=>curl_getinfo($ch), 'error'=>curl_error($ch)); + + $aReturn = ['info' => curl_getinfo($ch), 'error' => curl_error($ch)]; curl_close($ch); - - $sHeader=substr($res, 0, $aReturn['info']['header_size']); - $aReturn['header']=explode("\n", $sHeader); - $aReturn['body']=str_replace($sHeader, "", $res); + + $sHeader = substr($res, 0, $aReturn['info']['header_size']); + $aReturn['header'] = explode("\n", $sHeader); + $aReturn['body'] = str_replace($sHeader, "", $res); // print_r($aReturn); return $aReturn; @@ -85,84 +89,88 @@ class rollout_awx extends rollout_base { /** * get AWX inventories and return them as array for select box * [id] => array('value' => [ID], 'label' => [NAME] [ID]) - * @return array + * @return bool|array */ - public function getAwxInventories(){ - $aResponse=$this->_httpRequest(array( - 'url'=>'/inventories/?order_by=name'.$this->_sAwxApiPaging, - 'method'=>'GET', + public function getAwxInventories() + { + $aResponse = $this->_httpRequest( + array( + 'url' => '/inventories/?order_by=name' . $this->_sAwxApiPaging, + 'method' => 'GET', ) ); - if(!isset($aResponse['info']['http_code']) || $aResponse['info']['http_code']!==200){ + if (!isset($aResponse['info']['http_code']) || $aResponse['info']['http_code'] !== 200) { return false; } - $aData=json_decode($aResponse['body'], 1); - $aReturn=[]; - if (!$aData || !isset($aData['count'])){ - $aReturn[]=[ - 'value'=>false, - 'label'=>'!!! Access to awx api failed !!!' + $aData = json_decode($aResponse['body'], 1); + $aReturn = []; + if (!$aData || !isset($aData['count'])) { + $aReturn[] = [ + 'value' => false, + 'label' => '!!! Access to awx api failed !!!' ]; return $aReturn; } - if(count($aData['results']) < $aData['count']){ - $aReturn[]=[ - 'value'=>false, - 'label'=>'>>>>>>>>> WARNING: fetched ' . count($aData['results']) . ' of ' .$aData['count'] . ' items only' + if (count($aData['results']) < $aData['count']) { + $aReturn[] = [ + 'value' => false, + 'label' => '>>>>>>>>> WARNING: fetched ' . count($aData['results']) . ' of ' . $aData['count'] . ' items only' ]; } - foreach ($aData['results'] as $aItem){ - $aReturn[$aItem['id']]= [ - 'value'=>$aItem['id'], - 'label'=>$aItem['name'].' (id: '.$aItem['id'].')' + foreach ($aData['results'] as $aItem) { + $aReturn[$aItem['id']] = [ + 'value' => $aItem['id'], + 'label' => $aItem['name'] . ' (id: ' . $aItem['id'] . ')' ]; } - return $aReturn; + return $aReturn; } /** * get AWX Job Templates and return them as array for select box * [id] => array('value' => [ID], 'label' => [PLAYBOOK] [ID]) - * @return array + * @return bool|array */ - public function getAwxJobTemplates(){ - $aResponse=$this->_httpRequest(array( - 'url'=>'/job_templates/?order_by=name'.$this->_sAwxApiPaging, - 'method'=>'GET', + public function getAwxJobTemplates() + { + $aResponse = $this->_httpRequest( + array( + 'url' => '/job_templates/?order_by=name' . $this->_sAwxApiPaging, + 'method' => 'GET', ) ); - if(!isset($aResponse['info']['http_code']) || $aResponse['info']['http_code']!==200){ + if (!isset($aResponse['info']['http_code']) || $aResponse['info']['http_code'] !== 200) { return false; } - $aData=json_decode($aResponse['body'], 1); - $aReturn=[]; - if (!$aData || !isset($aData['count'])){ - $aReturn[]=[ - 'value'=>false, - 'label'=>'!!! Access to awx api failed !!!' + $aData = json_decode($aResponse['body'], 1); + $aReturn = []; + if (!$aData || !isset($aData['count'])) { + $aReturn[] = [ + 'value' => false, + 'label' => '!!! Access to awx api failed !!!' ]; return $aReturn; } - if(count($aData['results']) < $aData['count']){ - $aReturn[]=[ - 'value'=>false, - 'label'=>'>>>>>>>>> WARNING: fetched ' . count($aData['results']) . ' of ' .$aData['count'] . ' items only' + if (count($aData['results']) < $aData['count']) { + $aReturn[] = [ + 'value' => false, + 'label' => '>>>>>>>>> WARNING: fetched ' . count($aData['results']) . ' of ' . $aData['count'] . ' items only' ]; } - foreach ($aData['results'] as $aItem){ - $aReturn[$aItem['id']]= [ - 'value'=>$aItem['id'], - 'label'=>$aItem['name'].' (id: '.$aItem['id'].'; '.$aItem['playbook'].')' + foreach ($aData['results'] as $aItem) { + $aReturn[$aItem['id']] = [ + 'value' => $aItem['id'], + 'label' => $aItem['name'] . ' (id: ' . $aItem['id'] . '; ' . $aItem['playbook'] . ')' ]; } - return $aReturn; + return $aReturn; } - + /** * get array with commands to execute to deploy a package @@ -171,36 +179,37 @@ class rollout_awx extends rollout_base { * @param boolean $bMask Flag for public output; if true then mask your secrets * @return array */ - public function getDeployCommands($sPhase, $bMask=false){ - $aReturn=array(); - $aConfig=$this->getConfig($sPhase, $bMask); - + public function getDeployCommands($sPhase, $bMask = false) + { + $aReturn = array(); + $aConfig = $this->getConfig($sPhase, $bMask); + // ----- Checks: - $sCmdChecks=''; - 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; '; + $sCmdChecks = ''; + 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; '; } - $aConfig['extravars']=json_encode($aTmp); + $aConfig['extravars'] = json_encode($aTmp); } - - if(!isset($aConfig['inventory']) || !(int)$aConfig['inventory']){ - $sCmdChecks.='echo "ERROR: no awx inventory was given."; exit 1; '; + + if (!isset($aConfig['inventory']) || !(int) $aConfig['inventory']) { + $sCmdChecks .= 'echo "ERROR: no awx 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){ + $aBodyvars = array(); + foreach (['inventory' => 'inventory', 'limit' => 'limit', 'job_tags' => 'tags', 'extra_vars' => 'extravars'] as $sParam => $sVarkey) { if (isset($aConfig[$sVarkey]) && $aConfig[$sVarkey]) { - $aBodyvars[$sParam]=$aConfig[$sVarkey]; + $aBodyvars[$sParam] = $aConfig[$sVarkey]; } } - $sAuth=($aConfig['user'] ? '--user '.$aConfig['user'].':'.$aConfig['password'] : ''); - $aReturn[]=$sCmdChecks . "curl -f -k -H 'Content-Type: application/json' -XPOST -d '". json_encode($aBodyvars, JSON_PRETTY_PRINT)."' $sAuth ".$aConfig['url']."/job_templates/".$aConfig['jobtemplate']."/launch/"; + $sAuth = ($aConfig['user'] ? '--user ' . $aConfig['user'] . ':' . $aConfig['password'] : ''); + $aReturn[] = $sCmdChecks . "curl -f -k -H 'Content-Type: application/json' -XPOST -d '" . json_encode($aBodyvars, JSON_PRETTY_PRINT) . "' $sAuth " . $aConfig['url'] . "/job_templates/" . $aConfig['jobtemplate'] . "/launch/"; return $aReturn; } - + } diff --git a/public_html/deployment/plugins/rollout/default/rollout_default.php b/public_html/deployment/plugins/rollout/default/rollout_default.php index dcb10bce8e79e9f33b871e5135ba92c42c6f8255..56e742e42782ecf40f56b2743c59ed0191f7356c 100644 --- a/public_html/deployment/plugins/rollout/default/rollout_default.php +++ b/public_html/deployment/plugins/rollout/default/rollout_default.php @@ -7,22 +7,25 @@ * * @author <axel.hahn@iml.unibe.ch> */ -class rollout_default extends rollout_base { +class rollout_default extends rollout_base +{ /** * check requirements if the plugin could work */ - public function checkRequirements(){ - // no specific checks needed ... always true - return true; + public function checkRequirements(): array + { + // no specific checks needed ... always empty + return []; } /** * check access to a deploy target */ - public function checkConnectionToTarget(){ - // do nothing ... always true - return true; + public function checkConnectionToTarget() + { + // do nothing ... always empty + return []; } /** @@ -32,7 +35,8 @@ class rollout_default extends rollout_base { * @param boolean $bMask Flag for public output; if true then mask your secrets * @return array */ - public function getDeployCommands($sPhase, $bMask=false){ + public function getDeployCommands($sPhase, $bMask = false) + { return [ 'echo "SKIP"' ]; @@ -44,7 +48,8 @@ class rollout_default extends rollout_base { * * @return string */ - public function renderFormdata4Project() { + public function renderFormdata4Project() + { return $this->_t('no-cfg'); } @@ -54,7 +59,8 @@ class rollout_default extends rollout_base { * * @return string */ - public function renderFormdata4Phase($sPhase) { + public function renderFormdata4Phase($sPhase) + { return $this->_t('no-cfg'); - } + } } diff --git a/public_html/vendor/shooker/shooker.php b/public_html/vendor/shooker/shooker.php index b042bb7956478e32379fdc7e94cd9772da314b1e..8956f64a3f8092e7af7e400507c19aa8747b6d6f 100644 --- a/public_html/vendor/shooker/shooker.php +++ b/public_html/vendor/shooker/shooker.php @@ -160,5 +160,3 @@ class ShookerTrigger { array_push($this->actions, $fxn); } } - -?> \ No newline at end of file