From 2349586a4d2d053ac0b704c487f9c2663018a0e6 Mon Sep 17 00:00:00 2001
From: hahn <hahn@AAE49.campus.unibe.ch>
Date: Mon, 31 Mar 2014 16:28:31 +0200
Subject: [PATCH] - add ssh host key - fixed: hardcoded exec of puppet agent
 --version

---
 .gitignore                                       |  3 ++-
 config/inc_projects_config.php                   |  4 ++--
 public_html/deployment/classes/project.class.php | 13 ++-----------
 3 files changed, 6 insertions(+), 14 deletions(-)

diff --git a/.gitignore b/.gitignore
index fe6dd21b..c64ff9c9 100644
--- a/.gitignore
+++ b/.gitignore
@@ -12,4 +12,5 @@ nbproject
 /config/projects/imlplayer.json
 /config/projects/imlplayer.json.ok
 /config/projects/doccom.json.ok
-/config/projects/ci.json
\ No newline at end of file
+/config/projects/ci.json
+/database/logs.db
\ No newline at end of file
diff --git a/config/inc_projects_config.php b/config/inc_projects_config.php
index e06e8926..8bce3cc5 100644
--- a/config/inc_projects_config.php
+++ b/config/inc_projects_config.php
@@ -24,11 +24,11 @@ $aConfig = array(
         // %s is name of the server (2x)
         'addkeycommand' => '/usr/bin/ssh-keygen -R %s; /usr/bin/ssh-keyscan -t rsa %s >> /home/www-data/.ssh/known_hosts',
         
+        // command to verify if puppet host is correct
         'testcommand' => 'sudo puppet --version',
+        
         // puppet agent liefert 0 oder 2 zurueck, wenn OK
         // http://docs.puppetlabs.com/references/3.4.0/man/apply.html
-        // 'command'=>'sudo puppet agent -t | fgrep -i Deploy',
-        // 'command'=>'sudo puppet agent -t --detailed-exitcodes ; echo rc=$? | egrep -v  "^rc=(0|2)$" ; typeset -i rc=(1-$?); exit $rc',
         'command' => 'sudo puppet agent -t --detailed-exitcodes ; rc=$?; if [ $rc -eq 2 ]; then rc=0; fi ; exit $rc',
     ),
     'phases' => array(
diff --git a/public_html/deployment/classes/project.class.php b/public_html/deployment/classes/project.class.php
index d7015bca..cb4c412c 100644
--- a/public_html/deployment/classes/project.class.php
+++ b/public_html/deployment/classes/project.class.php
@@ -1474,7 +1474,7 @@ class project {
             $sCmd = 'ssh ' . $this->_aConfig["installPackages"]["user"]
                     . '@' . $this->_aPrjConfig["phases"][$sPhase]["puppethost"]
                     . ' ' . $this->_aConfig["installPackages"]["command"];
-            // $sReturn.=$this->_execAndSend("ssh imldeployment@" . $this->_aPrjConfig["phases"][$sPhase]["puppethost"] . " sudo puppet agent -t | fgrep -i Deploy");
+            //  | fgrep -i Deploy
             $sReturn.=$this->_execAndSend("$sCmd");
         } else {
             $sReturn.=t("class-project-info-deploy-start-puppet-skip") . "<br>";
@@ -1554,15 +1554,6 @@ class project {
         $this->_logaction(t('finished')." saveConfig(...)", __FUNCTION__, "success");
         $this->setProjectById($sId);
         
-        foreach (array_keys($aData["phases"]) as $sPhase){
-                if ($aData["phases"][$sPhase]["puppethost"]) {
-                        $sServer=$aData["phases"][$sPhase]["puppethost"];
-                        $sCmd="/usr/bin/ssh-keygen -R $sServer; /usr/bin/ssh-keyscan -t rsa $sServer >> $sKnownhosts";
-                        echo $sCmd."<br>";
-                        exec($sCmd);
-                }
-        }
-
         return $bReturn;
     }
 
@@ -2341,6 +2332,7 @@ class project {
         foreach (array_keys($this->getPhases()) as $sPhase) {
 
             $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"] : "";
             $aForms["setup"]["form"]['input' . $i++] = array(
                 'type' => 'markup',
@@ -2378,7 +2370,6 @@ class project {
                         . '@' . $sPuppethost 
                         . ' ' . $this->_aConfig["installPackages"]["testcommand"];
                 $sOut = shell_exec($sCmd2);
-                
                 // Check auf Versionsnummer - mehr als n Zeichen ist mutmasslich eine Fehlermeldung
                 if (strlen($sOut) > 7) {
                     $sMessages.=$this->getBox("error", sprintf(t("class-project-error-setup-sudo-pupet-agent-failed"), $sPhase, $sCmd, $sOut));
-- 
GitLab