From: cajus Date: Tue, 29 Jan 2008 16:11:00 +0000 (+0000) Subject: Moved to connect string to configuration X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=a7cdbf63c72518fe606d9b5a225dac04acaf9a30;p=gosa.git Moved to connect string to configuration git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@8638 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/gosa-core/include/class_daemonCommunicator.inc b/gosa-core/include/class_daemonCommunicator.inc new file mode 100644 index 000000000..b1bcd8355 --- /dev/null +++ b/gosa-core/include/class_daemonCommunicator.inc @@ -0,0 +1,40 @@ + + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +class daemonCommunicator +{ + static function send($header, $to, $data= array()) + { + $xml_message= ""; + + /* Get communication object */ + $d= new gosaSupportDaemon(TRUE,10); + + /* Prepare data */ + foreach ($data as $key => $value){ + $xml_message.= "<$key>$value"; + } + + return $d->send("
$header
$to".$xml_message."
"); + } +} + +// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: +?> diff --git a/gosa-core/include/class_gosaSupportDaemon.inc b/gosa-core/include/class_gosaSupportDaemon.inc index 398160ee3..944e1fa2d 100644 --- a/gosa-core/include/class_gosaSupportDaemon.inc +++ b/gosa-core/include/class_gosaSupportDaemon.inc @@ -39,19 +39,18 @@ Function overview: number_of_queued_entries - Returns the number of currently queued entries. */ - - class gosaSupportDaemon { + static private $s_host = ""; + static private $i_port = 0; + static private $s_encryption_key = ""; + private $o_sock = NULL; - private $s_host = ""; - private $i_port = 0; private $f_timeout = 2; private $s_error = ""; private $b_error = FALSE; private $is_connected = FALSE; - private $s_encryption_key = ""; /*! \brief Creates a new gosaSupportDaemon object. @@ -61,14 +60,28 @@ class gosaSupportDaemon @param boolean Connect Directly connect to deamon socket. @param float Timeout The timelimit for all socket actions. */ - public function __construct($host,$port,$key="secret-gosa-password",$connect=TRUE,$timeout=0.2) + public function __construct($connect=TRUE,$timeout=0.2) { - $this->s_host = $host; - $this->i_port = $port; - $this->f_timeout = $timeout; - $this->s_encryption_key = $key; - if($connect){ - $this->connect(); + #FIXME: bad idea about referencing global variables from within classes + global $config; + + # load from config, store statically + if (isset($config->current['GOSA_SI'])){ + + if (gosaSupportDaemon::$s_host == ""){ + $host= preg_replace("/^.*@([^:]+):.*$/", "$1", $config->current['GOSA_SI']); + $port= preg_replace("/^.*@[^:]+:(.*)$/", "$1", $config->current['GOSA_SI']); + $key = preg_replace("/^(.*)@[^:]+:.*$/", "$1", $config->current['GOSA_SI']); + + gosaSupportDaemon::$s_host = $host; + gosaSupportDaemon::$i_port = $port; + gosaSupportDaemon::$s_encryption_key = $key; + } + + $this->f_timeout = $timeout; + if($connect){ + $this->connect(); + } } } @@ -78,9 +91,9 @@ class gosaSupportDaemon */ public function connect() { - $this->o_sock = new Socket_Client($this->s_host,$this->i_port,TRUE,$this->f_timeout); + $this->o_sock = new Socket_Client(gosaSupportDaemon::$s_host,gosaSupportDaemon::$i_port,TRUE,$this->f_timeout); if($this->o_sock->connected()){ - $this->o_sock->setEncryptionKey($this->s_encryption_key); + $this->o_sock->setEncryptionKey(gosaSupportDaemon::$s_encryption_key); $this->is_connected = TRUE; }else{ $this->error = $this->o_sock->get_error(); @@ -516,6 +529,30 @@ class gosaSupportDaemon } return(-1); } + + + /*! \brief Returns an array containing all queued entries. + @return Array All queued entries as an array. + */ + public function send($data, $answer_expected= FALSE) + { + $this->b_error = FALSE; + $this->s_error = ""; + $ret = array(); + + if($this->connect()){ + $this->o_sock->write($data); + if ($answer_exepcted){ + $str = trim($this->o_sock->read()); + $entries = $this->xml_to_array($str); + if(isset($entries['XML']) && is_array($entries['XML'])){ + $ret = $entries; + } + } + } + return($ret); + } + } // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: diff --git a/gosa-core/plugins/addons/gotomasses/class_gotomasses.inc b/gosa-core/plugins/addons/gotomasses/class_gotomasses.inc index d4424187f..d3b15f2a7 100644 --- a/gosa-core/plugins/addons/gotomasses/class_gotomasses.inc +++ b/gosa-core/plugins/addons/gotomasses/class_gotomasses.inc @@ -26,7 +26,7 @@ class gotomasses extends plugin { /* Include config object */ $this->config= &$config; - $this->o_queue = new gosaSupportDaemon("10.3.67.111","20081","secret-gosa-password",TRUE,10); + $this->o_queue = new gosaSupportDaemon(TRUE,10); }