[icinga-checkins] icinga.org: icinga-web/master: * Fixed encoding issues and escapeshellargs being characterset dependent ( fixes #2405)

git at icinga.org git at icinga.org
Fri Apr 20 14:50:49 CEST 2012


Module: icinga-web
Branch: master
Commit: e89813d93745a1bb5e403d4aba84e4d4f4c05a55
URL:    https://git.icinga.org/?p=icinga-web.git;a=commit;h=e89813d93745a1bb5e403d4aba84e4d4f4c05a55

Author: Jannis Mosshammer <jannis.mosshammer at netways.de>
Date:   Fri Apr 20 14:38:08 2012 +0200

* Fixed encoding issues and escapeshellargs being characterset dependent (fixes #2405)

---

 .../lib/console/LocalConsoleConnection.class.php   |    1 +
 .../Commands/CommandDispatcherModel.class.php      |    4 ++--
 .../models/Console/ConsoleCommandModel.class.php   |   11 ++++++++++-
 .../models/System/CommandSenderModel.class.php     |    1 +
 .../Icinga/ApiSimpleDataProviderModel.class.php    |    2 +-
 5 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/app/modules/Api/lib/console/LocalConsoleConnection.class.php b/app/modules/Api/lib/console/LocalConsoleConnection.class.php
index a4745aa..3a0a198 100644
--- a/app/modules/Api/lib/console/LocalConsoleConnection.class.php
+++ b/app/modules/Api/lib/console/LocalConsoleConnection.class.php
@@ -7,6 +7,7 @@ class LocalConsoleConnection extends BaseConsoleConnection {
         $this->checkFileExistence($cmd);
         
         exec($cmdString,$out,$ret);
+        
         $cmd->setReturnCode($ret);
         $cmd->setOutput($out);
     }
diff --git a/app/modules/Api/models/Commands/CommandDispatcherModel.class.php b/app/modules/Api/models/Commands/CommandDispatcherModel.class.php
index 6cd991f..da09e51 100644
--- a/app/modules/Api/models/Commands/CommandDispatcherModel.class.php
+++ b/app/modules/Api/models/Commands/CommandDispatcherModel.class.php
@@ -46,7 +46,7 @@ class Api_Commands_CommandDispatcherModel extends IcingaApiBaseModel implements
            
             if($onlySimple && !$command["isSimple"])
                 throw new Exception("Could not send command. Your user isn't allowed to send this command.");
-            
+            AppKitLogger::debug("Sending icinga-command %s",$string);
             $cmd = $this->getContext()->getModel($commandClass[0],$commandClass[1],
                                                  array(
                                                          "command" => "printf",
@@ -77,7 +77,7 @@ class Api_Commands_CommandDispatcherModel extends IcingaApiBaseModel implements
             } else if (!isset($params[$vals["alias"]])) {
                 $str .= ";";
             } else {
-                $val = $params[$vals["alias"]];
+                $val = ($params[$vals["alias"]]);
                 $val = preg_replace("/\n/"," ",$val);
                     
                 switch ($vals["type"]) {
diff --git a/app/modules/Api/models/Console/ConsoleCommandModel.class.php b/app/modules/Api/models/Console/ConsoleCommandModel.class.php
index 4296666..4572bc0 100644
--- a/app/modules/Api/models/Console/ConsoleCommandModel.class.php
+++ b/app/modules/Api/models/Console/ConsoleCommandModel.class.php
@@ -115,6 +115,7 @@ class Api_Console_ConsoleCommandModel extends IcingaApiBaseModel implements Icin
     public function getCommandString() {
         $this->isValid(true);
         $cmd = $this->command;
+
         foreach($this->arguments as $name => $arg) {
             if (!is_int($name)) {
                 $cmd .= ' '.escapeshellcmd($name);
@@ -125,7 +126,7 @@ class Api_Console_ConsoleCommandModel extends IcingaApiBaseModel implements Icin
             }
 
             if ($arg != '') {
-                $cmd .= ' '.escapeshellarg($arg);
+                $cmd .= ' '.$this->escapeshellarg($arg);
             }
         }
 
@@ -240,4 +241,12 @@ class Api_Console_ConsoleCommandModel extends IcingaApiBaseModel implements Icin
         if(!AccessConfig::canWrite($errFile,$this->host))
             throw new ApiRestrictedCommandException($errFile." is not read enabled");
     }
+    /**
+     * PHP's escapeshellarg function sometimes has problems with multibyte values like 'öäü',
+     * so it is redefined here based on PHPs source code (which is fortunately rather simple.
+     *
+     */
+    private function escapeshellarg($str) {
+       return "'".str_replace("'","\\'",$str)."'";
+    }
 }
diff --git a/app/modules/Cronks/models/System/CommandSenderModel.class.php b/app/modules/Cronks/models/System/CommandSenderModel.class.php
index 4a2b0f0..f298bd4 100644
--- a/app/modules/Cronks/models/System/CommandSenderModel.class.php
+++ b/app/modules/Cronks/models/System/CommandSenderModel.class.php
@@ -57,6 +57,7 @@ class Cronks_System_CommandSenderModel extends CronksBaseModel {
             $console = $this->getConsoleInstance($target['instance']);
             $dispatcher->setConsoleContext($console);
             AppKitLogger::debug("Submitting command %s to %s",$this->command,json_encode($target));
+
             $dispatcher->submitCommand($this->command,array_merge($target,$this->data));
             AppKitLogger::debug("Finished submitting command");
         }
diff --git a/app/modules/Web/models/Icinga/ApiSimpleDataProviderModel.class.php b/app/modules/Web/models/Icinga/ApiSimpleDataProviderModel.class.php
index 1035ef3..1391c2f 100644
--- a/app/modules/Web/models/Icinga/ApiSimpleDataProviderModel.class.php
+++ b/app/modules/Web/models/Icinga/ApiSimpleDataProviderModel.class.php
@@ -211,7 +211,7 @@ class Web_Icinga_ApiSimpleDataProviderModel extends IcingaWebBaseModel {
                                  'val' => $this->rewriteColumn($key, $val)
                              );
                 } else {
-                    $tmp[$key] = $this->rewriteColumn($key, $val);
+                    $tmp[$key] = utf8_decode($this->rewriteColumn($key, $val));
                 }
             }
             $out[] = $tmp;





More information about the icinga-checkins mailing list