From af3da8f078c983a83704eceab78bb82a3e427036 Mon Sep 17 00:00:00 2001 From: hahn <hahn@AAE49.campus.unibe.ch> Date: Wed, 25 Jun 2014 17:16:04 +0200 Subject: [PATCH] - added: project config: show existing ssh keys - added: project specific deploy times --- .../deployment/classes/formgen.class.php | 2 +- .../deployment/classes/project.class.php | 70 +++++++++++++++++-- 2 files changed, 65 insertions(+), 7 deletions(-) diff --git a/public_html/deployment/classes/formgen.class.php b/public_html/deployment/classes/formgen.class.php index 8d33c8ec..de7c26f1 100644 --- a/public_html/deployment/classes/formgen.class.php +++ b/public_html/deployment/classes/formgen.class.php @@ -248,7 +248,7 @@ class formgen { $this->_checkReqiredKeys($elementData, array("name")); $sFormElement.=' <input type="text" id="' . $sId . '" '; $aAllowedHtmlAttributes["text"] = explode(",", ""); - $sFormElement.=$this->_addHtmlAtrributes(explode(",", "$sDefaultAttributes,name,disabled,onkeyup,onkeydown,onchange,pattern,placeholder,required,size,value"), $elementData); + $sFormElement.=$this->_addHtmlAtrributes(explode(",", "$sDefaultAttributes,name,list,disabled,onkeyup,onkeydown,onchange,pattern,placeholder,required,size,value"), $elementData); // $sFormElement.=$this->_addHtmlAtrributes(array("name", "value", "size", "placeholder", "required"), $elementData); // IE: Return abfangen lassen // $sFormElement.=' onkeypress="return checkKey(event);"'; diff --git a/public_html/deployment/classes/project.class.php b/public_html/deployment/classes/project.class.php index 02c0581e..bb914f43 100644 --- a/public_html/deployment/classes/project.class.php +++ b/public_html/deployment/classes/project.class.php @@ -943,6 +943,41 @@ class project { } return $this->_oVcs; } + /** + * get a flat array of all existing ssh keys + * @return array + */ + private function _getSshKeys() { + $aReturn = array(); + foreach (glob($this->_aConfig["dataDir"] . "/sshkeys/*.pub") as $filename) { + $aReturn[] = str_replace(".pub", "", basename($filename)); + } + sort($aReturn); + return $aReturn; + } + + /** + * get a flat array with regexes of deploy times + * @param string $sPhase phase + * @return array + */ + private function _getDeploytimes($sPhase){ + if (!$this->isActivePhase($sPhase)){ + $sError = sprintf(t("class-project-warning-phase-not-active"), $sPhase); + $this->_logaction($sError, __FUNCTION__, "error"); + return false; + } + $aDeploytimes=array(); + if (array_key_exists("deploytimes", $this->_aConfig["phases"][$sPhase])) { + $aDeploytimes=$this->_aConfig["phases"][$sPhase]["deploytimes"]; + } + if (array_key_exists("deploytimes", $this->_aPrjConfig["phases"][$sPhase]) + && $this->_aPrjConfig["phases"][$sPhase]["deploytimes"] + ) { + $aDeploytimes=array($this->_aPrjConfig["phases"][$sPhase]["deploytimes"]); + } + return $aDeploytimes; + } // ---------------------------------------------------------------------- // SETTER @@ -1505,12 +1540,14 @@ class project { // checks // -------------------------------------------------- $sReturn.="<h3>" . t("class-project-deploy-label-checks") . "</h3>"; - if (array_key_exists("deploytimes", $this->_aConfig["phases"][$sPhase])) { + + $aDeploytimes=$this->_getDeploytimes($sPhase); + if (count($aDeploytimes)) { // check if the a deploy time is reached $sNow = date("D H:i:s"); $sReturn.=sprintf(t("class-project-info-deploy-check-deployment-times"), $sNow) . "<br>"; $bCanDeploy = false; - foreach ($this->_aConfig["phases"][$sPhase]["deploytimes"] as $sRegex) { + foreach ($aDeploytimes as $sRegex) { $sReturn.=sprintf(t("class-project-info-deploy-test-regex"), $sRegex); if (preg_match($sRegex, $sNow)) { @@ -1975,8 +2012,8 @@ class project { $sRow2.='<td class="' . $sPhase . '">' . t('url') . ': <a href="' . $this->_aPrjConfig["phases"][$sPhase]["url"] . '">' . $this->_aPrjConfig["phases"][$sPhase]["url"] . '</a><br>' . '<br>' . t('deploytimes') . ':<br>'; - if (array_key_exists("deploytimes", $this->_aConfig["phases"][$sPhase])) { - $sRow2.=implode("<br>", $this->_aConfig["phases"][$sPhase]["deploytimes"]); + if (count($this->_getDeploytimes($sPhase))) { + $sRow2.=implode("<br>", $this->_getDeploytimes($sPhase)); } else { $sRow2.=t('deploytimes-immediately'); } @@ -2042,9 +2079,9 @@ class project { case "onhold": if (array_key_exists("phases", $this->_aConfig) && array_key_exists($sPhase, $this->_aConfig["phases"])) { // $sReturn .= print_r($this->_aConfig["phases"][$sPhase], true); - if (array_key_exists("deploytimes", $this->_aConfig["phases"][$sPhase])) { + if (count($this->_getDeploytimes($sPhase))) { $sReturn .= '<br><i class="icon-time"></i> ' . t('deploytimes') . ':<br>' - . implode("<br>", array_values($this->_aConfig["phases"][$sPhase]["deploytimes"])) + . implode("<br>", array_values($this->_getDeploytimes($sPhase))) . '<br>'; } if ($bActions) { @@ -2424,6 +2461,11 @@ class project { $sMessages.=$this->getBox("error", sprintf(t('class-project-error-no-repoaccess'), $aRepodata["error"])); } + // generate datalist with exisating ssh keys for auth field + $sAuthListitems=''; + foreach ($this->_getSshKeys() as $sKey){ + $sAuthListitems.='<option value="'.$sKey.'">'; + } $aForms = array( 'setup' => array( 'meta' => array( @@ -2517,10 +2559,15 @@ class project { 'label' => t("repository-auth"), 'value' => $this->_aPrjConfig["build"]["auth"], // 'required' => 'required', + 'list' => 'listauth', // listauth is the next form id below 'validate' => 'isastring', 'size' => 100, 'placeholder' => '', ), + 'input' . $i++ => array( + 'type' => 'markup', + 'value' => '<datalist id="listauth">'.$sAuthListitems.'</datalist>', + ), 'input' . $i++ => array( 'type' => 'markup', 'value' => '<fieldset><div class="controls">' @@ -2552,6 +2599,7 @@ class project { $sUrl = array_key_exists("url", $this->_aPrjConfig["phases"][$sPhase]) ? $this->_aPrjConfig["phases"][$sPhase]["url"] : ""; // $aTmp=parse_url($sUrl); $sPuppethost=$aTmp["host"]; $sPuppethost = array_key_exists("puppethost", $this->_aPrjConfig["phases"][$sPhase]) ? $this->_aPrjConfig["phases"][$sPhase]["puppethost"] : ""; + $sDeploytimes = array_key_exists("deploytimes", $this->_aPrjConfig["phases"][$sPhase]) ? $this->_aPrjConfig["phases"][$sPhase]["deploytimes"] : ""; $aForms["setup"]["form"]['input' . $i++] = array( 'type' => 'markup', 'value' => '<table class="table">' @@ -2604,6 +2652,16 @@ class project { , ); } + $aForms["setup"]["form"]['input' . $i++] = array( + 'type' => 'text', + 'name' => 'phases[' . $sPhase . '][deploytimes]', + 'label' => t("deploytimes"), + 'value' => $sDeploytimes, + // 'required' => 'required', + 'validate' => 'isastring', + 'size' => 100, + 'placeholder' => $this->_aConfig["phases"][$sPhase]["deploytimes"][0], + ); $aForms["setup"]["form"]['input' . $i++] = array( 'type' => 'markup', 'value' => '</td></tr></tbody></table>', -- GitLab