Passed
Push — master ( 6a1f5a...b100fb )
by Patrick
02:54
created
library/Trapdirector/TrapsActions/TrapDBQuery.php 3 patches
Indentation   +191 added lines, -191 removed lines patch added patch discarded remove patch
@@ -20,225 +20,225 @@
 block discarded – undo
20 20
 trait TrapDBQuery
21 21
 {
22 22
     
23
-    /** @return TrapsController */
24
-    abstract protected function getTrapCtrl();
23
+	/** @return TrapsController */
24
+	abstract protected function getTrapCtrl();
25 25
 
26
-    /** @return Zend_Db_Adapter_Abstract : returns DB connexion or null on error */
27
-    abstract public function getDbConn();
26
+	/** @return Zend_Db_Adapter_Abstract : returns DB connexion or null on error */
27
+	abstract public function getDbConn();
28 28
     
29
-    /** Add handler rule in traps DB
30
-     *	@param array $params : array(<db item>=><value>)
31
-     *	@return int inserted id
32
-     */
33
-    public function addHandlerRule($params)
34
-    {
35
-        // TODO Check for rule consistency
29
+	/** Add handler rule in traps DB
30
+	 *	@param array $params : array(<db item>=><value>)
31
+	 *	@return int inserted id
32
+	 */
33
+	public function addHandlerRule($params)
34
+	{
35
+		// TODO Check for rule consistency
36 36
         
37
-        $dbConn = $this->getDbConn();
38
-        if ($dbConn === null) throw new \ErrorException('uncatched db error');
39
-        // Add last modified date = creation date and username
40
-        $params['created'] = new Zend_Db_Expr('NOW()');
41
-        $params['modified'] = new 	Zend_Db_Expr('NOW()');
42
-        $params['modifier'] = $this->getTrapCtrl()->Auth()->getUser()->getUsername();
37
+		$dbConn = $this->getDbConn();
38
+		if ($dbConn === null) throw new \ErrorException('uncatched db error');
39
+		// Add last modified date = creation date and username
40
+		$params['created'] = new Zend_Db_Expr('NOW()');
41
+		$params['modified'] = new 	Zend_Db_Expr('NOW()');
42
+		$params['modifier'] = $this->getTrapCtrl()->Auth()->getUser()->getUsername();
43 43
         
44
-        $query=$dbConn->insert(
45
-            $this->getTrapCtrl()->getModuleConfig()->getTrapRuleName(),
46
-            $params
47
-            );
48
-        if($query==false)
49
-        {
50
-            return null;
51
-        }
52
-        return $dbConn->lastInsertId();
53
-    }
44
+		$query=$dbConn->insert(
45
+			$this->getTrapCtrl()->getModuleConfig()->getTrapRuleName(),
46
+			$params
47
+			);
48
+		if($query==false)
49
+		{
50
+			return null;
51
+		}
52
+		return $dbConn->lastInsertId();
53
+	}
54 54
     
55
-    /** Update handler rule in traps DB
56
-     *	@param array $params : (<db item>=><value>)
57
-     *   @param integer $ruleID : rule id in db
58
-     *	@return array affected rows
59
-     */
60
-    public function updateHandlerRule($params,$ruleID)
61
-    {
62
-        // TODO Check for rule consistency
63
-        $dbConn = $this->getDbConn();
64
-        if ($dbConn === null) throw new \ErrorException('uncatched db error');
65
-        // Add last modified date = creation date and username
66
-        $params['modified'] = new 	Zend_Db_Expr('NOW()');
67
-        $params['modifier'] = $this->getTrapCtrl()->Auth()->getUser()->getUsername();
55
+	/** Update handler rule in traps DB
56
+	 *	@param array $params : (<db item>=><value>)
57
+	 *   @param integer $ruleID : rule id in db
58
+	 *	@return array affected rows
59
+	 */
60
+	public function updateHandlerRule($params,$ruleID)
61
+	{
62
+		// TODO Check for rule consistency
63
+		$dbConn = $this->getDbConn();
64
+		if ($dbConn === null) throw new \ErrorException('uncatched db error');
65
+		// Add last modified date = creation date and username
66
+		$params['modified'] = new 	Zend_Db_Expr('NOW()');
67
+		$params['modifier'] = $this->getTrapCtrl()->Auth()->getUser()->getUsername();
68 68
         
69
-        $numRows=$dbConn->update(
70
-            $this->getTrapCtrl()->getModuleConfig()->getTrapRuleName(),
71
-            $params,
72
-            'id='.$ruleID
73
-            );
74
-        return $numRows;
75
-    }
69
+		$numRows=$dbConn->update(
70
+			$this->getTrapCtrl()->getModuleConfig()->getTrapRuleName(),
71
+			$params,
72
+			'id='.$ruleID
73
+			);
74
+		return $numRows;
75
+	}
76 76
     
77
-    /** Delete rule by id
78
-     *	@param int $ruleID rule id
79
-     */
80
-    public function deleteRule($ruleID)
81
-    {
82
-        if (!preg_match('/^[0-9]+$/',$ruleID)) { throw new Exception('Invalid id');  }
77
+	/** Delete rule by id
78
+	 *	@param int $ruleID rule id
79
+	 */
80
+	public function deleteRule($ruleID)
81
+	{
82
+		if (!preg_match('/^[0-9]+$/',$ruleID)) { throw new Exception('Invalid id');  }
83 83
         
84
-        $dbConn = $this->getDbConn();
85
-        if ($dbConn === null) throw new \ErrorException('uncatched db error');
84
+		$dbConn = $this->getDbConn();
85
+		if ($dbConn === null) throw new \ErrorException('uncatched db error');
86 86
         
87
-        $query=$dbConn->delete(
88
-            $this->getTrapCtrl()->getModuleConfig()->getTrapRuleName(),
89
-            'id='.$ruleID
90
-            );
91
-        return $query;
92
-    }
87
+		$query=$dbConn->delete(
88
+			$this->getTrapCtrl()->getModuleConfig()->getTrapRuleName(),
89
+			'id='.$ruleID
90
+			);
91
+		return $query;
92
+	}
93 93
 
94
-    /**
95
-     * Get last trap rule table modification
96
-     * @throws \ErrorException
97
-     * @return Zend_Db_Select
98
-     */
99
-    public function lastModification()
100
-    {
101
-        $dbConn = $this->getDbConn();
102
-        if ($dbConn === null) throw new \ErrorException('uncatched db error');
94
+	/**
95
+	 * Get last trap rule table modification
96
+	 * @throws \ErrorException
97
+	 * @return Zend_Db_Select
98
+	 */
99
+	public function lastModification()
100
+	{
101
+		$dbConn = $this->getDbConn();
102
+		if ($dbConn === null) throw new \ErrorException('uncatched db error');
103 103
         
104
-        $query = $dbConn->select()
105
-        ->from(
106
-            $this->getTrapCtrl()->getModuleConfig()->getTrapRuleName(),
107
-            array('lastModified'=>'UNIX_TIMESTAMP(MAX(modified))'));
108
-        $returnRow=$dbConn->fetchRow($query);
109
-        return $returnRow->lastmodified;
110
-    }
104
+		$query = $dbConn->select()
105
+		->from(
106
+			$this->getTrapCtrl()->getModuleConfig()->getTrapRuleName(),
107
+			array('lastModified'=>'UNIX_TIMESTAMP(MAX(modified))'));
108
+		$returnRow=$dbConn->fetchRow($query);
109
+		return $returnRow->lastmodified;
110
+	}
111 111
     
112
-    /** Delete trap by ip & oid
113
-     *	@param $ipAddr string source IP (v4 or v6)
114
-     *	@param $oid string oid
115
-     */
116
-    public function deleteTrap($ipAddr,$oid)
117
-    {
112
+	/** Delete trap by ip & oid
113
+	 *	@param $ipAddr string source IP (v4 or v6)
114
+	 *	@param $oid string oid
115
+	 */
116
+	public function deleteTrap($ipAddr,$oid)
117
+	{
118 118
         
119
-        $dbConn = $this->getDbConn();
120
-        if ($dbConn === null) throw new \ErrorException('uncatched db error');
121
-        $condition=null;
122
-        if ($ipAddr != null)
123
-        {
124
-            $condition="source_ip='$ipAddr'";
125
-        }
126
-        if ($oid != null)
127
-        {
128
-            $condition=($condition===null)?'':$condition.' AND ';
129
-            $condition.="trap_oid='$oid'";
130
-        }
131
-        if($condition === null) return null;
132
-        $query=$dbConn->delete(
133
-            $this->getTrapCtrl()->getModuleConfig()->getTrapTableName(),
134
-            $condition
135
-            );
136
-        // TODO test ret code etc...
137
-        return $query;
138
-    }
119
+		$dbConn = $this->getDbConn();
120
+		if ($dbConn === null) throw new \ErrorException('uncatched db error');
121
+		$condition=null;
122
+		if ($ipAddr != null)
123
+		{
124
+			$condition="source_ip='$ipAddr'";
125
+		}
126
+		if ($oid != null)
127
+		{
128
+			$condition=($condition===null)?'':$condition.' AND ';
129
+			$condition.="trap_oid='$oid'";
130
+		}
131
+		if($condition === null) return null;
132
+		$query=$dbConn->delete(
133
+			$this->getTrapCtrl()->getModuleConfig()->getTrapTableName(),
134
+			$condition
135
+			);
136
+		// TODO test ret code etc...
137
+		return $query;
138
+	}
139 139
     
140 140
     
141
-    /** count trap by ip & oid
142
-     *	@param $ipAddr string source IP (v4 or v6)
143
-     *	@param $oid string oid
144
-     */
145
-    public function countTrap($ipAddr,$oid)
146
-    {
141
+	/** count trap by ip & oid
142
+	 *	@param $ipAddr string source IP (v4 or v6)
143
+	 *	@param $oid string oid
144
+	 */
145
+	public function countTrap($ipAddr,$oid)
146
+	{
147 147
         
148
-        $dbConn = $this->getDbConn();
149
-        if ($dbConn === null) throw new \ErrorException('uncatched db error');
148
+		$dbConn = $this->getDbConn();
149
+		if ($dbConn === null) throw new \ErrorException('uncatched db error');
150 150
         
151
-        $condition=null;
152
-        if ($ipAddr != null)
153
-        {
154
-            $condition="source_ip='$ipAddr'";
155
-        }
156
-        if ($oid != null)
157
-        {
158
-            $condition=($condition===null)?'':$condition.' AND ';
159
-            $condition.="trap_oid='$oid'";
160
-        }
161
-        if($condition === null) return 0;
162
-        $query=$dbConn->select()
163
-            ->from(
164
-                $this->getTrapCtrl()->getModuleConfig()->getTrapTableName(),
165
-                array('num'=>'count(*)'))
166
-            ->where($condition);
167
-        $returnRow=$dbConn->fetchRow($query);
168
-        return $returnRow->num;
169
-    }
151
+		$condition=null;
152
+		if ($ipAddr != null)
153
+		{
154
+			$condition="source_ip='$ipAddr'";
155
+		}
156
+		if ($oid != null)
157
+		{
158
+			$condition=($condition===null)?'':$condition.' AND ';
159
+			$condition.="trap_oid='$oid'";
160
+		}
161
+		if($condition === null) return 0;
162
+		$query=$dbConn->select()
163
+			->from(
164
+				$this->getTrapCtrl()->getModuleConfig()->getTrapTableName(),
165
+				array('num'=>'count(*)'))
166
+			->where($condition);
167
+		$returnRow=$dbConn->fetchRow($query);
168
+		return $returnRow->num;
169
+	}
170 170
     
171
-    /** get configuration value
172
-     *	@param string $element : configuration name in db
173
-     */
174
-    public function getDBConfigValue($element)
175
-    {
171
+	/** get configuration value
172
+	 *	@param string $element : configuration name in db
173
+	 */
174
+	public function getDBConfigValue($element)
175
+	{
176 176
         
177
-        $dbConn = $this->getDbConn();
178
-        if ($dbConn === null) throw new \ErrorException('uncatched db error');
177
+		$dbConn = $this->getDbConn();
178
+		if ($dbConn === null) throw new \ErrorException('uncatched db error');
179 179
         
180
-        $query=$dbConn->select()
181
-        ->from(
182
-            $this->getTrapCtrl()->getModuleConfig()->getDbConfigTableName(),
183
-            array('value'=>'value'))
184
-            ->where('name=?',$element);
185
-            $returnRow=$dbConn->fetchRow($query);
186
-            if ($returnRow==null)  // value does not exists
187
-            {
188
-                $default=$this->getTrapCtrl()->getModuleConfig()->getDBConfigDefaults();
189
-                if ( ! isset($default[$element])) return null; // no default and not value
180
+		$query=$dbConn->select()
181
+		->from(
182
+			$this->getTrapCtrl()->getModuleConfig()->getDbConfigTableName(),
183
+			array('value'=>'value'))
184
+			->where('name=?',$element);
185
+			$returnRow=$dbConn->fetchRow($query);
186
+			if ($returnRow==null)  // value does not exists
187
+			{
188
+				$default=$this->getTrapCtrl()->getModuleConfig()->getDBConfigDefaults();
189
+				if ( ! isset($default[$element])) return null; // no default and not value
190 190
                 
191
-                $this->addDBConfigValue($element,$default[$element]);
192
-                return $default[$element];
193
-            }
194
-            if ($returnRow->value == null) // value id empty
195
-            {
196
-                $default=$this->getTrapCtrl()->getModuleConfig()->getDBConfigDefaults();
197
-                if ( ! isset($default[$element])) return null; // no default and not value
198
-                $this->setDBConfigValue($element,$default[$element]);
199
-                return $default[$element];
200
-            }
201
-            return $returnRow->value;
202
-    }
191
+				$this->addDBConfigValue($element,$default[$element]);
192
+				return $default[$element];
193
+			}
194
+			if ($returnRow->value == null) // value id empty
195
+			{
196
+				$default=$this->getTrapCtrl()->getModuleConfig()->getDBConfigDefaults();
197
+				if ( ! isset($default[$element])) return null; // no default and not value
198
+				$this->setDBConfigValue($element,$default[$element]);
199
+				return $default[$element];
200
+			}
201
+			return $returnRow->value;
202
+	}
203 203
     
204
-    /** add configuration value
205
-     *	@param string $element : name of config element
206
-     *   @param string $value : value
207
-     */
204
+	/** add configuration value
205
+	 *	@param string $element : name of config element
206
+	 *   @param string $value : value
207
+	 */
208 208
     
209
-    public function addDBConfigValue($element,$value)
210
-    {
209
+	public function addDBConfigValue($element,$value)
210
+	{
211 211
         
212
-        $dbConn = $this->getDbConn();
213
-        if ($dbConn === null) throw new \ErrorException('uncatched db error');
212
+		$dbConn = $this->getDbConn();
213
+		if ($dbConn === null) throw new \ErrorException('uncatched db error');
214 214
         
215
-        $query=$dbConn->insert(
216
-            $this->getTrapCtrl()->getModuleConfig()->getDbConfigTableName(),
217
-            array(
218
-                'name' => $element,
219
-                'value'=>$value
220
-            )
221
-            );
222
-        return $query;
223
-    }
215
+		$query=$dbConn->insert(
216
+			$this->getTrapCtrl()->getModuleConfig()->getDbConfigTableName(),
217
+			array(
218
+				'name' => $element,
219
+				'value'=>$value
220
+			)
221
+			);
222
+		return $query;
223
+	}
224 224
     
225
-    /** set configuration value
226
-     *	@param string $element : name of config element
227
-     *   @param string $value : value
228
-     */
229
-    public function setDBConfigValue($element,$value)
230
-    {
225
+	/** set configuration value
226
+	 *	@param string $element : name of config element
227
+	 *   @param string $value : value
228
+	 */
229
+	public function setDBConfigValue($element,$value)
230
+	{
231 231
         
232
-        $dbConn = $this->getDbConn();
233
-        if ($dbConn === null) throw new \ErrorException('uncatched db error');
232
+		$dbConn = $this->getDbConn();
233
+		if ($dbConn === null) throw new \ErrorException('uncatched db error');
234 234
         
235
-        $query=$dbConn->update(
236
-            $this->getTrapCtrl()->getModuleConfig()->getDbConfigTableName(),
237
-            array('value'=>$value),
238
-            'name=\''.$element.'\''
239
-            );
240
-        return $query;
241
-    }
235
+		$query=$dbConn->update(
236
+			$this->getTrapCtrl()->getModuleConfig()->getDbConfigTableName(),
237
+			array('value'=>$value),
238
+			'name=\''.$element.'\''
239
+			);
240
+		return $query;
241
+	}
242 242
     
243 243
     
244 244
 }
245 245
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -34,18 +34,18 @@  discard block
 block discarded – undo
34 34
     {
35 35
         // TODO Check for rule consistency
36 36
         
37
-        $dbConn = $this->getDbConn();
37
+        $dbConn=$this->getDbConn();
38 38
         if ($dbConn === null) throw new \ErrorException('uncatched db error');
39 39
         // Add last modified date = creation date and username
40
-        $params['created'] = new Zend_Db_Expr('NOW()');
41
-        $params['modified'] = new 	Zend_Db_Expr('NOW()');
42
-        $params['modifier'] = $this->getTrapCtrl()->Auth()->getUser()->getUsername();
40
+        $params['created']=new Zend_Db_Expr('NOW()');
41
+        $params['modified']=new 	Zend_Db_Expr('NOW()');
42
+        $params['modifier']=$this->getTrapCtrl()->Auth()->getUser()->getUsername();
43 43
         
44 44
         $query=$dbConn->insert(
45 45
             $this->getTrapCtrl()->getModuleConfig()->getTrapRuleName(),
46 46
             $params
47 47
             );
48
-        if($query==false)
48
+        if ($query == false)
49 49
         {
50 50
             return null;
51 51
         }
@@ -57,14 +57,14 @@  discard block
 block discarded – undo
57 57
      *   @param integer $ruleID : rule id in db
58 58
      *	@return array affected rows
59 59
      */
60
-    public function updateHandlerRule($params,$ruleID)
60
+    public function updateHandlerRule($params, $ruleID)
61 61
     {
62 62
         // TODO Check for rule consistency
63
-        $dbConn = $this->getDbConn();
63
+        $dbConn=$this->getDbConn();
64 64
         if ($dbConn === null) throw new \ErrorException('uncatched db error');
65 65
         // Add last modified date = creation date and username
66
-        $params['modified'] = new 	Zend_Db_Expr('NOW()');
67
-        $params['modifier'] = $this->getTrapCtrl()->Auth()->getUser()->getUsername();
66
+        $params['modified']=new 	Zend_Db_Expr('NOW()');
67
+        $params['modifier']=$this->getTrapCtrl()->Auth()->getUser()->getUsername();
68 68
         
69 69
         $numRows=$dbConn->update(
70 70
             $this->getTrapCtrl()->getModuleConfig()->getTrapRuleName(),
@@ -79,9 +79,9 @@  discard block
 block discarded – undo
79 79
      */
80 80
     public function deleteRule($ruleID)
81 81
     {
82
-        if (!preg_match('/^[0-9]+$/',$ruleID)) { throw new Exception('Invalid id');  }
82
+        if (!preg_match('/^[0-9]+$/', $ruleID)) { throw new Exception('Invalid id'); }
83 83
         
84
-        $dbConn = $this->getDbConn();
84
+        $dbConn=$this->getDbConn();
85 85
         if ($dbConn === null) throw new \ErrorException('uncatched db error');
86 86
         
87 87
         $query=$dbConn->delete(
@@ -98,10 +98,10 @@  discard block
 block discarded – undo
98 98
      */
99 99
     public function lastModification()
100 100
     {
101
-        $dbConn = $this->getDbConn();
101
+        $dbConn=$this->getDbConn();
102 102
         if ($dbConn === null) throw new \ErrorException('uncatched db error');
103 103
         
104
-        $query = $dbConn->select()
104
+        $query=$dbConn->select()
105 105
         ->from(
106 106
             $this->getTrapCtrl()->getModuleConfig()->getTrapRuleName(),
107 107
             array('lastModified'=>'UNIX_TIMESTAMP(MAX(modified))'));
@@ -113,10 +113,10 @@  discard block
 block discarded – undo
113 113
      *	@param $ipAddr string source IP (v4 or v6)
114 114
      *	@param $oid string oid
115 115
      */
116
-    public function deleteTrap($ipAddr,$oid)
116
+    public function deleteTrap($ipAddr, $oid)
117 117
     {
118 118
         
119
-        $dbConn = $this->getDbConn();
119
+        $dbConn=$this->getDbConn();
120 120
         if ($dbConn === null) throw new \ErrorException('uncatched db error');
121 121
         $condition=null;
122 122
         if ($ipAddr != null)
@@ -125,10 +125,10 @@  discard block
 block discarded – undo
125 125
         }
126 126
         if ($oid != null)
127 127
         {
128
-            $condition=($condition===null)?'':$condition.' AND ';
128
+            $condition=($condition === null) ? '' : $condition.' AND ';
129 129
             $condition.="trap_oid='$oid'";
130 130
         }
131
-        if($condition === null) return null;
131
+        if ($condition === null) return null;
132 132
         $query=$dbConn->delete(
133 133
             $this->getTrapCtrl()->getModuleConfig()->getTrapTableName(),
134 134
             $condition
@@ -142,10 +142,10 @@  discard block
 block discarded – undo
142 142
      *	@param $ipAddr string source IP (v4 or v6)
143 143
      *	@param $oid string oid
144 144
      */
145
-    public function countTrap($ipAddr,$oid)
145
+    public function countTrap($ipAddr, $oid)
146 146
     {
147 147
         
148
-        $dbConn = $this->getDbConn();
148
+        $dbConn=$this->getDbConn();
149 149
         if ($dbConn === null) throw new \ErrorException('uncatched db error');
150 150
         
151 151
         $condition=null;
@@ -155,10 +155,10 @@  discard block
 block discarded – undo
155 155
         }
156 156
         if ($oid != null)
157 157
         {
158
-            $condition=($condition===null)?'':$condition.' AND ';
158
+            $condition=($condition === null) ? '' : $condition.' AND ';
159 159
             $condition.="trap_oid='$oid'";
160 160
         }
161
-        if($condition === null) return 0;
161
+        if ($condition === null) return 0;
162 162
         $query=$dbConn->select()
163 163
             ->from(
164 164
                 $this->getTrapCtrl()->getModuleConfig()->getTrapTableName(),
@@ -174,28 +174,28 @@  discard block
 block discarded – undo
174 174
     public function getDBConfigValue($element)
175 175
     {
176 176
         
177
-        $dbConn = $this->getDbConn();
177
+        $dbConn=$this->getDbConn();
178 178
         if ($dbConn === null) throw new \ErrorException('uncatched db error');
179 179
         
180 180
         $query=$dbConn->select()
181 181
         ->from(
182 182
             $this->getTrapCtrl()->getModuleConfig()->getDbConfigTableName(),
183 183
             array('value'=>'value'))
184
-            ->where('name=?',$element);
184
+            ->where('name=?', $element);
185 185
             $returnRow=$dbConn->fetchRow($query);
186
-            if ($returnRow==null)  // value does not exists
186
+            if ($returnRow == null)  // value does not exists
187 187
             {
188 188
                 $default=$this->getTrapCtrl()->getModuleConfig()->getDBConfigDefaults();
189
-                if ( ! isset($default[$element])) return null; // no default and not value
189
+                if (!isset($default[$element])) return null; // no default and not value
190 190
                 
191
-                $this->addDBConfigValue($element,$default[$element]);
191
+                $this->addDBConfigValue($element, $default[$element]);
192 192
                 return $default[$element];
193 193
             }
194 194
             if ($returnRow->value == null) // value id empty
195 195
             {
196 196
                 $default=$this->getTrapCtrl()->getModuleConfig()->getDBConfigDefaults();
197
-                if ( ! isset($default[$element])) return null; // no default and not value
198
-                $this->setDBConfigValue($element,$default[$element]);
197
+                if (!isset($default[$element])) return null; // no default and not value
198
+                $this->setDBConfigValue($element, $default[$element]);
199 199
                 return $default[$element];
200 200
             }
201 201
             return $returnRow->value;
@@ -206,10 +206,10 @@  discard block
 block discarded – undo
206 206
      *   @param string $value : value
207 207
      */
208 208
     
209
-    public function addDBConfigValue($element,$value)
209
+    public function addDBConfigValue($element, $value)
210 210
     {
211 211
         
212
-        $dbConn = $this->getDbConn();
212
+        $dbConn=$this->getDbConn();
213 213
         if ($dbConn === null) throw new \ErrorException('uncatched db error');
214 214
         
215 215
         $query=$dbConn->insert(
@@ -226,10 +226,10 @@  discard block
 block discarded – undo
226 226
      *	@param string $element : name of config element
227 227
      *   @param string $value : value
228 228
      */
229
-    public function setDBConfigValue($element,$value)
229
+    public function setDBConfigValue($element, $value)
230 230
     {
231 231
         
232
-        $dbConn = $this->getDbConn();
232
+        $dbConn=$this->getDbConn();
233 233
         if ($dbConn === null) throw new \ErrorException('uncatched db error');
234 234
         
235 235
         $query=$dbConn->update(
Please login to merge, or discard this patch.
Braces   +47 added lines, -15 removed lines patch added patch discarded remove patch
@@ -35,7 +35,9 @@  discard block
 block discarded – undo
35 35
         // TODO Check for rule consistency
36 36
         
37 37
         $dbConn = $this->getDbConn();
38
-        if ($dbConn === null) throw new \ErrorException('uncatched db error');
38
+        if ($dbConn === null) {
39
+        	throw new \ErrorException('uncatched db error');
40
+        }
39 41
         // Add last modified date = creation date and username
40 42
         $params['created'] = new Zend_Db_Expr('NOW()');
41 43
         $params['modified'] = new 	Zend_Db_Expr('NOW()');
@@ -61,7 +63,9 @@  discard block
 block discarded – undo
61 63
     {
62 64
         // TODO Check for rule consistency
63 65
         $dbConn = $this->getDbConn();
64
-        if ($dbConn === null) throw new \ErrorException('uncatched db error');
66
+        if ($dbConn === null) {
67
+        	throw new \ErrorException('uncatched db error');
68
+        }
65 69
         // Add last modified date = creation date and username
66 70
         $params['modified'] = new 	Zend_Db_Expr('NOW()');
67 71
         $params['modifier'] = $this->getTrapCtrl()->Auth()->getUser()->getUsername();
@@ -82,7 +86,9 @@  discard block
 block discarded – undo
82 86
         if (!preg_match('/^[0-9]+$/',$ruleID)) { throw new Exception('Invalid id');  }
83 87
         
84 88
         $dbConn = $this->getDbConn();
85
-        if ($dbConn === null) throw new \ErrorException('uncatched db error');
89
+        if ($dbConn === null) {
90
+        	throw new \ErrorException('uncatched db error');
91
+        }
86 92
         
87 93
         $query=$dbConn->delete(
88 94
             $this->getTrapCtrl()->getModuleConfig()->getTrapRuleName(),
@@ -99,7 +105,9 @@  discard block
 block discarded – undo
99 105
     public function lastModification()
100 106
     {
101 107
         $dbConn = $this->getDbConn();
102
-        if ($dbConn === null) throw new \ErrorException('uncatched db error');
108
+        if ($dbConn === null) {
109
+        	throw new \ErrorException('uncatched db error');
110
+        }
103 111
         
104 112
         $query = $dbConn->select()
105 113
         ->from(
@@ -117,7 +125,9 @@  discard block
 block discarded – undo
117 125
     {
118 126
         
119 127
         $dbConn = $this->getDbConn();
120
-        if ($dbConn === null) throw new \ErrorException('uncatched db error');
128
+        if ($dbConn === null) {
129
+        	throw new \ErrorException('uncatched db error');
130
+        }
121 131
         $condition=null;
122 132
         if ($ipAddr != null)
123 133
         {
@@ -128,7 +138,9 @@  discard block
 block discarded – undo
128 138
             $condition=($condition===null)?'':$condition.' AND ';
129 139
             $condition.="trap_oid='$oid'";
130 140
         }
131
-        if($condition === null) return null;
141
+        if($condition === null) {
142
+        	return null;
143
+        }
132 144
         $query=$dbConn->delete(
133 145
             $this->getTrapCtrl()->getModuleConfig()->getTrapTableName(),
134 146
             $condition
@@ -146,7 +158,9 @@  discard block
 block discarded – undo
146 158
     {
147 159
         
148 160
         $dbConn = $this->getDbConn();
149
-        if ($dbConn === null) throw new \ErrorException('uncatched db error');
161
+        if ($dbConn === null) {
162
+        	throw new \ErrorException('uncatched db error');
163
+        }
150 164
         
151 165
         $condition=null;
152 166
         if ($ipAddr != null)
@@ -158,7 +172,9 @@  discard block
 block discarded – undo
158 172
             $condition=($condition===null)?'':$condition.' AND ';
159 173
             $condition.="trap_oid='$oid'";
160 174
         }
161
-        if($condition === null) return 0;
175
+        if($condition === null) {
176
+        	return 0;
177
+        }
162 178
         $query=$dbConn->select()
163 179
             ->from(
164 180
                 $this->getTrapCtrl()->getModuleConfig()->getTrapTableName(),
@@ -175,7 +191,9 @@  discard block
 block discarded – undo
175 191
     {
176 192
         
177 193
         $dbConn = $this->getDbConn();
178
-        if ($dbConn === null) throw new \ErrorException('uncatched db error');
194
+        if ($dbConn === null) {
195
+        	throw new \ErrorException('uncatched db error');
196
+        }
179 197
         
180 198
         $query=$dbConn->select()
181 199
         ->from(
@@ -183,18 +201,28 @@  discard block
 block discarded – undo
183 201
             array('value'=>'value'))
184 202
             ->where('name=?',$element);
185 203
             $returnRow=$dbConn->fetchRow($query);
186
-            if ($returnRow==null)  // value does not exists
204
+            if ($returnRow==null) {
205
+            	// value does not exists
187 206
             {
188 207
                 $default=$this->getTrapCtrl()->getModuleConfig()->getDBConfigDefaults();
189
-                if ( ! isset($default[$element])) return null; // no default and not value
208
+            }
209
+                if ( ! isset($default[$element])) {
210
+                	return null;
211
+                }
212
+                // no default and not value
190 213
                 
191 214
                 $this->addDBConfigValue($element,$default[$element]);
192 215
                 return $default[$element];
193 216
             }
194
-            if ($returnRow->value == null) // value id empty
217
+            if ($returnRow->value == null) {
218
+            	// value id empty
195 219
             {
196 220
                 $default=$this->getTrapCtrl()->getModuleConfig()->getDBConfigDefaults();
197
-                if ( ! isset($default[$element])) return null; // no default and not value
221
+            }
222
+                if ( ! isset($default[$element])) {
223
+                	return null;
224
+                }
225
+                // no default and not value
198 226
                 $this->setDBConfigValue($element,$default[$element]);
199 227
                 return $default[$element];
200 228
             }
@@ -210,7 +238,9 @@  discard block
 block discarded – undo
210 238
     {
211 239
         
212 240
         $dbConn = $this->getDbConn();
213
-        if ($dbConn === null) throw new \ErrorException('uncatched db error');
241
+        if ($dbConn === null) {
242
+        	throw new \ErrorException('uncatched db error');
243
+        }
214 244
         
215 245
         $query=$dbConn->insert(
216 246
             $this->getTrapCtrl()->getModuleConfig()->getDbConfigTableName(),
@@ -230,7 +260,9 @@  discard block
 block discarded – undo
230 260
     {
231 261
         
232 262
         $dbConn = $this->getDbConn();
233
-        if ($dbConn === null) throw new \ErrorException('uncatched db error');
263
+        if ($dbConn === null) {
264
+        	throw new \ErrorException('uncatched db error');
265
+        }
234 266
         
235 267
         $query=$dbConn->update(
236 268
             $this->getTrapCtrl()->getModuleConfig()->getDbConfigTableName(),
Please login to merge, or discard this patch.
library/Trapdirector/TrapsProcess/TrapApi.php 2 patches
Indentation   +76 added lines, -76 removed lines patch added patch discarded remove patch
@@ -17,93 +17,93 @@
 block discarded – undo
17 17
 class TrapApi
18 18
 {
19 19
 
20
-    // Constants
21
-    public const MASTER=1;
22
-    public const MASTERHA=2;
23
-    public const SAT=3;
24
-    public $stateArray = array('MASTER' => TrapApi::MASTER, 'MASTERHA' => TrapApi::MASTERHA , 'SAT' => TrapApi::SAT  );
20
+	// Constants
21
+	public const MASTER=1;
22
+	public const MASTERHA=2;
23
+	public const SAT=3;
24
+	public $stateArray = array('MASTER' => TrapApi::MASTER, 'MASTERHA' => TrapApi::MASTERHA , 'SAT' => TrapApi::SAT  );
25 25
     
26
-    /** @var integer $whoami current server : MASTER MASTERHA or SAT */
27
-    public $whoami = TrapApi::MASTER;
28
-    /** @var string $masterIP ip of master if MASTERHA or SAT  */
29
-    public $masterIP='';
30
-    /** @var integer $masterPort port of master if MASTERHA or SAT  */
31
-    public $masterPort=443;
32
-    /** @var string $masterUser user to log in API  */
33
-    public $masterUser='';
34
-    /** @var string $masterPass password */
35
-    public $masterPass='';
26
+	/** @var integer $whoami current server : MASTER MASTERHA or SAT */
27
+	public $whoami = TrapApi::MASTER;
28
+	/** @var string $masterIP ip of master if MASTERHA or SAT  */
29
+	public $masterIP='';
30
+	/** @var integer $masterPort port of master if MASTERHA or SAT  */
31
+	public $masterPort=443;
32
+	/** @var string $masterUser user to log in API  */
33
+	public $masterUser='';
34
+	/** @var string $masterPass password */
35
+	public $masterPass='';
36 36
     
37
-    /** @var Logging $logging logging class */
38
-    protected $logging;
37
+	/** @var Logging $logging logging class */
38
+	protected $logging;
39 39
     
40
-    /**
41
-     * Create TrapApi class
42
-     * @param Logging $logClass
43
-     */
44
-    function __construct($logClass)
45
-    {
46
-        $this->logging=$logClass;
47
-    }
40
+	/**
41
+	 * Create TrapApi class
42
+	 * @param Logging $logClass
43
+	 */
44
+	function __construct($logClass)
45
+	{
46
+		$this->logging=$logClass;
47
+	}
48 48
 
49
-    /**
50
-     * Return true if ode is master.
51
-     * @return boolean
52
-     */
53
-    public function isMaster()
54
-    {
55
-        return ($this->whoami == MASTER);
56
-    }
49
+	/**
50
+	 * Return true if ode is master.
51
+	 * @return boolean
52
+	 */
53
+	public function isMaster()
54
+	{
55
+		return ($this->whoami == MASTER);
56
+	}
57 57
 
58
-    /**
59
-     * return status of node
60
-     * @return number
61
-     */
62
-    public function getStatus()
63
-    {
64
-        return $this->whoami;    
65
-    }
58
+	/**
59
+	 * return status of node
60
+	 * @return number
61
+	 */
62
+	public function getStatus()
63
+	{
64
+		return $this->whoami;    
65
+	}
66 66
     
67
-    /**
68
-     * Set status os node to $status
69
-     * @param string $status
70
-     * @return boolean : true if $status is correct, or false.
71
-     */
72
-    public function setStatus(string $status)
73
-    {
74
-        if (! isset($this->stateArray[$status]))
75
-        {
76
-            return FALSE;
77
-        }
67
+	/**
68
+	 * Set status os node to $status
69
+	 * @param string $status
70
+	 * @return boolean : true if $status is correct, or false.
71
+	 */
72
+	public function setStatus(string $status)
73
+	{
74
+		if (! isset($this->stateArray[$status]))
75
+		{
76
+			return FALSE;
77
+		}
78 78
         
79
-        $this->logging->log('Setting status to : ' . $status, INFO);
79
+		$this->logging->log('Setting status to : ' . $status, INFO);
80 80
         
81
-        $this->whoami = $this->stateArray[$status];
81
+		$this->whoami = $this->stateArray[$status];
82 82
         
83
-        return TRUE;
84
-    }
83
+		return TRUE;
84
+	}
85 85
  
86
-    public function setStatusMaster()
87
-    {
88
-        $this->whoami = TrapApi::MASTER;
89
-    }
86
+	public function setStatusMaster()
87
+	{
88
+		$this->whoami = TrapApi::MASTER;
89
+	}
90 90
     
91
-    /**
92
-     * Set params for API connection
93
-     * @param string $IP
94
-     * @param int $port
95
-     * @param string $user
96
-     * @param string $pass
97
-     * @return boolean true if params are OK
98
-     */
99
-    public function setParams(string $IP, int $port, string $user, string $pass)
100
-    {
101
-        $this->masterIP = $IP;
102
-        $this->masterPort = $port;
103
-        $this->masterUser = $user;
104
-        $this->masterPass = $pass;
91
+	/**
92
+	 * Set params for API connection
93
+	 * @param string $IP
94
+	 * @param int $port
95
+	 * @param string $user
96
+	 * @param string $pass
97
+	 * @return boolean true if params are OK
98
+	 */
99
+	public function setParams(string $IP, int $port, string $user, string $pass)
100
+	{
101
+		$this->masterIP = $IP;
102
+		$this->masterPort = $port;
103
+		$this->masterUser = $user;
104
+		$this->masterPass = $pass;
105 105
         
106
-        return true;
107
-    }
106
+		return true;
107
+	}
108 108
     
109 109
 }
110 110
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -21,10 +21,10 @@  discard block
 block discarded – undo
21 21
     public const MASTER=1;
22 22
     public const MASTERHA=2;
23 23
     public const SAT=3;
24
-    public $stateArray = array('MASTER' => TrapApi::MASTER, 'MASTERHA' => TrapApi::MASTERHA , 'SAT' => TrapApi::SAT  );
24
+    public $stateArray=array('MASTER' => TrapApi::MASTER, 'MASTERHA' => TrapApi::MASTERHA, 'SAT' => TrapApi::SAT);
25 25
     
26 26
     /** @var integer $whoami current server : MASTER MASTERHA or SAT */
27
-    public $whoami = TrapApi::MASTER;
27
+    public $whoami=TrapApi::MASTER;
28 28
     /** @var string $masterIP ip of master if MASTERHA or SAT  */
29 29
     public $masterIP='';
30 30
     /** @var integer $masterPort port of master if MASTERHA or SAT  */
@@ -71,21 +71,21 @@  discard block
 block discarded – undo
71 71
      */
72 72
     public function setStatus(string $status)
73 73
     {
74
-        if (! isset($this->stateArray[$status]))
74
+        if (!isset($this->stateArray[$status]))
75 75
         {
76 76
             return FALSE;
77 77
         }
78 78
         
79
-        $this->logging->log('Setting status to : ' . $status, INFO);
79
+        $this->logging->log('Setting status to : '.$status, INFO);
80 80
         
81
-        $this->whoami = $this->stateArray[$status];
81
+        $this->whoami=$this->stateArray[$status];
82 82
         
83 83
         return TRUE;
84 84
     }
85 85
  
86 86
     public function setStatusMaster()
87 87
     {
88
-        $this->whoami = TrapApi::MASTER;
88
+        $this->whoami=TrapApi::MASTER;
89 89
     }
90 90
     
91 91
     /**
@@ -98,10 +98,10 @@  discard block
 block discarded – undo
98 98
      */
99 99
     public function setParams(string $IP, int $port, string $user, string $pass)
100 100
     {
101
-        $this->masterIP = $IP;
102
-        $this->masterPort = $port;
103
-        $this->masterUser = $user;
104
-        $this->masterPass = $pass;
101
+        $this->masterIP=$IP;
102
+        $this->masterPort=$port;
103
+        $this->masterUser=$user;
104
+        $this->masterPass=$pass;
105 105
         
106 106
         return true;
107 107
     }
Please login to merge, or discard this patch.
library/Trapdirector/Rest/RestAPI.php 3 patches
Indentation   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -14,43 +14,43 @@
 block discarded – undo
14 14
 
15 15
 class RestAPI
16 16
 {
17
-    public $version=1;
17
+	public $version=1;
18 18
     
19
-    /**
20
-     * @var TrapsController $trapController
21
-     */
22
-    protected $trapController=null;
19
+	/**
20
+	 * @var TrapsController $trapController
21
+	 */
22
+	protected $trapController=null;
23 23
     
24
-    public function __construct(TrapsController $trapCtrl)
25
-    {
26
-        $this->trapController=$trapCtrl;
27
-    }
24
+	public function __construct(TrapsController $trapCtrl)
25
+	{
26
+		$this->trapController=$trapCtrl;
27
+	}
28 28
     
29
-    public function sendJson($object)
30
-    {
31
-        $this->trapController->getResponse()->setHeader('Content-Type', 'application/json', true);        
32
-        $this->trapController->getResponse()->sendHeaders();
33
-        $this->trapController->helper_ret(json_encode($object, JSON_PRETTY_PRINT));
34
-        //$this->trapController->_helper->json($object);
35
-        //echo json_encode($object, JSON_PRETTY_PRINT) . "\n";
36
-    }
29
+	public function sendJson($object)
30
+	{
31
+		$this->trapController->getResponse()->setHeader('Content-Type', 'application/json', true);        
32
+		$this->trapController->getResponse()->sendHeaders();
33
+		$this->trapController->helper_ret(json_encode($object, JSON_PRETTY_PRINT));
34
+		//$this->trapController->_helper->json($object);
35
+		//echo json_encode($object, JSON_PRETTY_PRINT) . "\n";
36
+	}
37 37
     
38
-    protected function sendJsonError(string $error, int $retCode = 200)
39
-    {
40
-        //TODO
41
-        $this->sendJson('{"Error":"'.$error.'"}');
42
-    }
38
+	protected function sendJsonError(string $error, int $retCode = 200)
39
+	{
40
+		//TODO
41
+		$this->sendJson('{"Error":"'.$error.'"}');
42
+	}
43 43
     
44
-    public function last_modified()
45
-    {
46
-        try 
47
-        {
48
-            $query = $this->trapController->getUIDatabase()->lastModification();
49
-            return array('lastModified' => $query);
50
-        } 
51
-        catch (\ErrorException $e) 
52
-        {
53
-            return array('Error' =>  $e->getMessage());
54
-        }
55
-    }
44
+	public function last_modified()
45
+	{
46
+		try 
47
+		{
48
+			$query = $this->trapController->getUIDatabase()->lastModification();
49
+			return array('lastModified' => $query);
50
+		} 
51
+		catch (\ErrorException $e) 
52
+		{
53
+			return array('Error' =>  $e->getMessage());
54
+		}
55
+	}
56 56
 }
57 57
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
         //echo json_encode($object, JSON_PRETTY_PRINT) . "\n";
36 36
     }
37 37
     
38
-    protected function sendJsonError(string $error, int $retCode = 200)
38
+    protected function sendJsonError(string $error, int $retCode=200)
39 39
     {
40 40
         //TODO
41 41
         $this->sendJson('{"Error":"'.$error.'"}');
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
     {
46 46
         try 
47 47
         {
48
-            $query = $this->trapController->getUIDatabase()->lastModification();
48
+            $query=$this->trapController->getUIDatabase()->lastModification();
49 49
             return array('lastModified' => $query);
50 50
         } 
51 51
         catch (\ErrorException $e) 
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -47,8 +47,7 @@
 block discarded – undo
47 47
         {
48 48
             $query = $this->trapController->getUIDatabase()->lastModification();
49 49
             return array('lastModified' => $query);
50
-        } 
51
-        catch (\ErrorException $e) 
50
+        } catch (\ErrorException $e) 
52 51
         {
53 52
             return array('Error' =>  $e->getMessage());
54 53
         }
Please login to merge, or discard this patch.
library/Trapdirector/Icinga2Api.php 3 patches
Indentation   +336 added lines, -336 removed lines patch added patch discarded remove patch
@@ -8,367 +8,367 @@
 block discarded – undo
8 8
 
9 9
 class Icinga2API 
10 10
 {
11
-    protected $version = 'v1';      //< icinga2 api version
11
+	protected $version = 'v1';      //< icinga2 api version
12 12
     
13
-    protected $host;                //< icinga2 host name or IP
14
-    protected $port;                //< icinga2 api port
13
+	protected $host;                //< icinga2 host name or IP
14
+	protected $port;                //< icinga2 api port
15 15
     
16
-    protected $user;                //< user name
17
-    protected $pass;                //< user password
18
-    protected $usercert;            //< user key for certificate auth (NOT IMPLEMENTED)
19
-    protected $authmethod='pass';   //< Authentication : 'pass' or 'cert'
16
+	protected $user;                //< user name
17
+	protected $pass;                //< user password
18
+	protected $usercert;            //< user key for certificate auth (NOT IMPLEMENTED)
19
+	protected $authmethod='pass';   //< Authentication : 'pass' or 'cert'
20 20
 
21
-    protected $curl;
22
-    // http://php.net/manual/de/function.json-last-error.php#119985
23
-    protected $errorReference = [
24
-        JSON_ERROR_NONE => 'No error has occurred.',
25
-        JSON_ERROR_DEPTH => 'The maximum stack depth has been exceeded.',
26
-        JSON_ERROR_STATE_MISMATCH => 'Invalid or malformed JSON.',
27
-        JSON_ERROR_CTRL_CHAR => 'Control character error, possibly incorrectly encoded.',
28
-        JSON_ERROR_SYNTAX => 'Syntax error.',
29
-        JSON_ERROR_UTF8 => 'Malformed UTF-8 characters, possibly incorrectly encoded.',
30
-        JSON_ERROR_RECURSION => 'One or more recursive references in the value to be encoded.',
31
-        JSON_ERROR_INF_OR_NAN => 'One or more NAN or INF values in the value to be encoded.',
32
-        JSON_ERROR_UNSUPPORTED_TYPE => 'A value of a type that cannot be encoded was given.',
33
-    ];
34
-    const JSON_UNKNOWN_ERROR = 'Unknown error.';
21
+	protected $curl;
22
+	// http://php.net/manual/de/function.json-last-error.php#119985
23
+	protected $errorReference = [
24
+		JSON_ERROR_NONE => 'No error has occurred.',
25
+		JSON_ERROR_DEPTH => 'The maximum stack depth has been exceeded.',
26
+		JSON_ERROR_STATE_MISMATCH => 'Invalid or malformed JSON.',
27
+		JSON_ERROR_CTRL_CHAR => 'Control character error, possibly incorrectly encoded.',
28
+		JSON_ERROR_SYNTAX => 'Syntax error.',
29
+		JSON_ERROR_UTF8 => 'Malformed UTF-8 characters, possibly incorrectly encoded.',
30
+		JSON_ERROR_RECURSION => 'One or more recursive references in the value to be encoded.',
31
+		JSON_ERROR_INF_OR_NAN => 'One or more NAN or INF values in the value to be encoded.',
32
+		JSON_ERROR_UNSUPPORTED_TYPE => 'A value of a type that cannot be encoded was given.',
33
+	];
34
+	const JSON_UNKNOWN_ERROR = 'Unknown error.';
35 35
     
36
-    /**
37
-     * Creates Icinga2API object
38
-     * 
39
-     * @param string $host host name or IP
40
-     * @param number $port API port
41
-     */
42
-    public function __construct($host, $port = 5665)
43
-    {
44
-        $this->host=$host;
45
-        $this->port=$port;
46
-    }
47
-    /**
48
-     * Set user & pass
49
-     * @param string $user
50
-     * @param string $pass
51
-     */
52
-    public function setCredentials($user,$pass)
53
-    {
54
-        $this->user=$user;
55
-        $this->pass=$pass;
56
-        $this->authmethod='pass';
57
-    }
36
+	/**
37
+	 * Creates Icinga2API object
38
+	 * 
39
+	 * @param string $host host name or IP
40
+	 * @param number $port API port
41
+	 */
42
+	public function __construct($host, $port = 5665)
43
+	{
44
+		$this->host=$host;
45
+		$this->port=$port;
46
+	}
47
+	/**
48
+	 * Set user & pass
49
+	 * @param string $user
50
+	 * @param string $pass
51
+	 */
52
+	public function setCredentials($user,$pass)
53
+	{
54
+		$this->user=$user;
55
+		$this->pass=$pass;
56
+		$this->authmethod='pass';
57
+	}
58 58
     
59
-    /**
60
-     * Set user & certificate (NOT IMPLEMENTED @throws RuntimeException)
61
-     * @param string $user
62
-     * @param string $usercert
63
-     */
64
-    public function setCredentialskey($user,$usercert)
65
-    {
66
-        $this->user=$user;
67
-        $this->usercert=$usercert;
68
-        $this->authmethod='cert';
69
-        throw new RuntimeException('Certificate auth not implemented');
70
-    }
59
+	/**
60
+	 * Set user & certificate (NOT IMPLEMENTED @throws RuntimeException)
61
+	 * @param string $user
62
+	 * @param string $usercert
63
+	 */
64
+	public function setCredentialskey($user,$usercert)
65
+	{
66
+		$this->user=$user;
67
+		$this->usercert=$usercert;
68
+		$this->authmethod='cert';
69
+		throw new RuntimeException('Certificate auth not implemented');
70
+	}
71 71
 
72
-    public function test(array $permissions)
73
-    {
74
-       try
75
-        {
76
-            $result=$this->request('GET', "", NULL, NULL);
77
-        } 
78
-        catch (Exception $e)
79
-        {
80
-            return array(true, 'Error with API : '.$e->getMessage());
81
-        }
82
-        //var_dump($result);
83
-        $permOk=1;
84
-        $permMissing='';
85
-        if ($permissions === NULL) // If no permission check return OK after connexion
86
-        {
87
-            return array(false,'OK');
88
-        }
89
-        if (property_exists($result, 'results') && property_exists($result->results[0], 'permissions'))
90
-        {
72
+	public function test(array $permissions)
73
+	{
74
+	   try
75
+		{
76
+			$result=$this->request('GET', "", NULL, NULL);
77
+		} 
78
+		catch (Exception $e)
79
+		{
80
+			return array(true, 'Error with API : '.$e->getMessage());
81
+		}
82
+		//var_dump($result);
83
+		$permOk=1;
84
+		$permMissing='';
85
+		if ($permissions === NULL) // If no permission check return OK after connexion
86
+		{
87
+			return array(false,'OK');
88
+		}
89
+		if (property_exists($result, 'results') && property_exists($result->results[0], 'permissions'))
90
+		{
91 91
             
92
-            foreach ( $permissions as $mustPermission)
93
-            {
94
-                $curPermOK=0;
95
-                foreach ( $result->results[0]->permissions as $curPermission)
96
-                {
97
-                    $curPermission=preg_replace('/\*/','.*',$curPermission); // put * as .* to created a regexp
98
-                    if (preg_match('#'.$curPermission.'#',$mustPermission))
99
-                    {
100
-                        $curPermOK=1;
101
-                        break;
102
-                    }
103
-                }
104
-                if ($curPermOK == 0)
105
-                {
106
-                    $permOk=0;
107
-                    $permMissing=$mustPermission;
108
-                    break;
109
-                }
110
-            }
111
-            if ($permOk == 0)
112
-            {
113
-                return array(true,'API connection OK, but missing permission : '.$permMissing);
114
-            }
115
-            return array(false,'API connection OK');
92
+			foreach ( $permissions as $mustPermission)
93
+			{
94
+				$curPermOK=0;
95
+				foreach ( $result->results[0]->permissions as $curPermission)
96
+				{
97
+					$curPermission=preg_replace('/\*/','.*',$curPermission); // put * as .* to created a regexp
98
+					if (preg_match('#'.$curPermission.'#',$mustPermission))
99
+					{
100
+						$curPermOK=1;
101
+						break;
102
+					}
103
+				}
104
+				if ($curPermOK == 0)
105
+				{
106
+					$permOk=0;
107
+					$permMissing=$mustPermission;
108
+					break;
109
+				}
110
+			}
111
+			if ($permOk == 0)
112
+			{
113
+				return array(true,'API connection OK, but missing permission : '.$permMissing);
114
+			}
115
+			return array(false,'API connection OK');
116 116
             
117
-        }
118
-        return array(true,'API connection OK, but cannot get permissions');
119
-    }
117
+		}
118
+		return array(true,'API connection OK, but cannot get permissions');
119
+	}
120 120
     
121 121
     
122
-    protected function url($url) {
123
-        return sprintf('https://%s:%d/%s/%s', $this->host, $this->port, $this->version, $url);
124
-    }
122
+	protected function url($url) {
123
+		return sprintf('https://%s:%d/%s/%s', $this->host, $this->port, $this->version, $url);
124
+	}
125 125
     
126
-    /**
127
-     * Create or return curl ressource
128
-     * @throws Exception
129
-     * @return resource
130
-     */
131
-    protected function curl() {
132
-        if ($this->curl === null) {
133
-            $this->curl = curl_init(sprintf('https://%s:%d', $this->host, $this->port));
134
-            if ($this->curl === false) {
135
-                throw new Exception('CURL INIT ERROR');
136
-            }
137
-        }
138
-        return $this->curl;
139
-    }
126
+	/**
127
+	 * Create or return curl ressource
128
+	 * @throws Exception
129
+	 * @return resource
130
+	 */
131
+	protected function curl() {
132
+		if ($this->curl === null) {
133
+			$this->curl = curl_init(sprintf('https://%s:%d', $this->host, $this->port));
134
+			if ($this->curl === false) {
135
+				throw new Exception('CURL INIT ERROR');
136
+			}
137
+		}
138
+		return $this->curl;
139
+	}
140 140
 
141
-    /**
142
-     * Send a passive service check
143
-     * @param string $host : host name 
144
-     * @param string $service : service name
145
-     * @param int $state : state of service
146
-     * @param string $display : service passive check output
147
-     * @param string $perfdata : performance data as string
148
-     * @return array (status = true (oK) or false (nok), string message)
149
-     */
150
-    public function serviceCheckResult($host,$service,$state,$display,$perfdata='')
151
-    {
152
-        //Send a POST request to the URL endpoint /v1/actions/process-check-result
153
-        //actions/process-check-result?service=example.localdomain!passive-ping6
154
-        $url='actions/process-check-result';
155
-        $body=array(
156
-            "filter"        => 'service.name=="'.$service.'" && service.host_name=="'.$host.'"',
157
-            'type'          => 'Service',
158
-            "exit_status"   => $state,
159
-            "plugin_output" => $display,
160
-            "performance_data" => $perfdata
161
-        );
162
-        try 
163
-        {
164
-            $result=$this->request('POST', $url, null, $body);
165
-        } catch (Exception $e) 
166
-        {
167
-            return array(false, $e->getMessage());
168
-        }
169
-        if (property_exists($result,'error') )
170
-        {
171
-            if (property_exists($result,'status'))
172
-            {
173
-                $message=$result->status;
174
-            }
175
-            else 
176
-            {
177
-                $message="Unkown status";
178
-            }
179
-            return array(false , 'Ret code ' .$result->error.' : '.$message);
180
-        }
181
-        if (property_exists($result, 'results'))
182
-        {
183
-            if (isset($result->results[0]))
184
-            {
185
-                return array(true,'code '.$result->results[0]->code.' : '.$result->results[0]->status);
186
-            }
187
-            else
188
-            {
189
-                return array(false,'Service not found');
190
-            }
141
+	/**
142
+	 * Send a passive service check
143
+	 * @param string $host : host name 
144
+	 * @param string $service : service name
145
+	 * @param int $state : state of service
146
+	 * @param string $display : service passive check output
147
+	 * @param string $perfdata : performance data as string
148
+	 * @return array (status = true (oK) or false (nok), string message)
149
+	 */
150
+	public function serviceCheckResult($host,$service,$state,$display,$perfdata='')
151
+	{
152
+		//Send a POST request to the URL endpoint /v1/actions/process-check-result
153
+		//actions/process-check-result?service=example.localdomain!passive-ping6
154
+		$url='actions/process-check-result';
155
+		$body=array(
156
+			"filter"        => 'service.name=="'.$service.'" && service.host_name=="'.$host.'"',
157
+			'type'          => 'Service',
158
+			"exit_status"   => $state,
159
+			"plugin_output" => $display,
160
+			"performance_data" => $perfdata
161
+		);
162
+		try 
163
+		{
164
+			$result=$this->request('POST', $url, null, $body);
165
+		} catch (Exception $e) 
166
+		{
167
+			return array(false, $e->getMessage());
168
+		}
169
+		if (property_exists($result,'error') )
170
+		{
171
+			if (property_exists($result,'status'))
172
+			{
173
+				$message=$result->status;
174
+			}
175
+			else 
176
+			{
177
+				$message="Unkown status";
178
+			}
179
+			return array(false , 'Ret code ' .$result->error.' : '.$message);
180
+		}
181
+		if (property_exists($result, 'results'))
182
+		{
183
+			if (isset($result->results[0]))
184
+			{
185
+				return array(true,'code '.$result->results[0]->code.' : '.$result->results[0]->status);
186
+			}
187
+			else
188
+			{
189
+				return array(false,'Service not found');
190
+			}
191 191
             
192
-        }
193
-        return array(false,'Unkown result, open issue with this : '.print_r($result,true));
194
-    }
192
+		}
193
+		return array(false,'Unkown result, open issue with this : '.print_r($result,true));
194
+	}
195 195
  
196
-    /**
197
-     * return array of host by IP (4 or 6)
198
-     * @param string $ip
199
-     * @throws Exception
200
-     * @return array objects : array('__name','name','display_name')
201
-     */
202
-    public function getHostByIP($ip) 
203
-    {
204
-        /*
196
+	/**
197
+	 * return array of host by IP (4 or 6)
198
+	 * @param string $ip
199
+	 * @throws Exception
200
+	 * @return array objects : array('__name','name','display_name')
201
+	 */
202
+	public function getHostByIP($ip) 
203
+	{
204
+		/*
205 205
          *  curl -k -s -u  trapdirector:trapdirector -H 'X-HTTP-Method-Override: GET' -X POST 'https://localhost:5665/v1/objects/hosts' 
206 206
          *  -d '{"filter":"host.group==\"test_trap\"","attrs": ["address" ,"address6"]}'
207 207
             
208 208
             {"results":[{"attrs":{"__name":"Icinga host","address":"127.0.0.1","display_name":"Icinga host","name":"Icinga host"},"joins":{},"meta":{},"name":"Icinga host","type":"Host"}]}
209 209
          */
210 210
         
211
-        $url='objects/hosts';
212
-        $body=array(
213
-            "filter"        => 'host.address=="'.$ip.'" || host.address6=="'.$ip.'"',
214
-            "attrs"         => array('__name','name','display_name')
215
-        );
216
-        try
217
-        {
218
-            $result=$this->request('POST', $url, array('X-HTTP-Method-Override: GET'), $body);
219
-        } catch (Exception $e)
220
-        {
221
-            throw new Exception($e->getMessage());
222
-        }
211
+		$url='objects/hosts';
212
+		$body=array(
213
+			"filter"        => 'host.address=="'.$ip.'" || host.address6=="'.$ip.'"',
214
+			"attrs"         => array('__name','name','display_name')
215
+		);
216
+		try
217
+		{
218
+			$result=$this->request('POST', $url, array('X-HTTP-Method-Override: GET'), $body);
219
+		} catch (Exception $e)
220
+		{
221
+			throw new Exception($e->getMessage());
222
+		}
223 223
         
224
-        if (property_exists($result,'error') )
225
-        {
226
-            if (property_exists($result,'status'))
227
-            {
228
-                throw new Exception('Ret code ' .$result->error.' : ' . $result->status);
229
-            }
230
-            else
231
-            {
232
-                throw new Exception('Ret code ' .$result->error.' : Unkown status');
233
-            }
234
-        }
235
-        if (property_exists($result, 'results'))
236
-        {
237
-            $numHost=0;
238
-            $hostArray=array();
239
-            while (isset($result->results[$numHost]) && property_exists ($result->results[$numHost],'attrs'))
240
-            {
241
-                $hostArray[$numHost] = $result->results[$numHost]->attrs;
242
-                $numHost++;
243
-            }
244
-            return $hostArray;            
245
-        }
246
-        throw new Exception('Unkown result');
247
-    }
224
+		if (property_exists($result,'error') )
225
+		{
226
+			if (property_exists($result,'status'))
227
+			{
228
+				throw new Exception('Ret code ' .$result->error.' : ' . $result->status);
229
+			}
230
+			else
231
+			{
232
+				throw new Exception('Ret code ' .$result->error.' : Unkown status');
233
+			}
234
+		}
235
+		if (property_exists($result, 'results'))
236
+		{
237
+			$numHost=0;
238
+			$hostArray=array();
239
+			while (isset($result->results[$numHost]) && property_exists ($result->results[$numHost],'attrs'))
240
+			{
241
+				$hostArray[$numHost] = $result->results[$numHost]->attrs;
242
+				$numHost++;
243
+			}
244
+			return $hostArray;            
245
+		}
246
+		throw new Exception('Unkown result');
247
+	}
248 248
 
249
-    /**
250
-     * Get all host and IP from hostgroup
251
-     * @param string $hostGroup
252
-     * @throws Exception
253
-     * @return array : attributes : address, address6, name
254
-     */
255
-    public function getHostsIPByHostGroup($hostGroup)
256
-    {        
257
-        $url='objects/hosts';
258
-        $body=array(
259
-            "filter"        => '\"'.$hostGroup.'\" in host.groups',
260
-            "attrs"         => array('address','address','name')
261
-        );
262
-        try
263
-        {
264
-            $result=$this->request('POST', $url, array('X-HTTP-Method-Override: GET'), $body);
265
-        } catch (Exception $e)
266
-        {
267
-            throw new Exception($e->getMessage());
268
-        }
249
+	/**
250
+	 * Get all host and IP from hostgroup
251
+	 * @param string $hostGroup
252
+	 * @throws Exception
253
+	 * @return array : attributes : address, address6, name
254
+	 */
255
+	public function getHostsIPByHostGroup($hostGroup)
256
+	{        
257
+		$url='objects/hosts';
258
+		$body=array(
259
+			"filter"        => '\"'.$hostGroup.'\" in host.groups',
260
+			"attrs"         => array('address','address','name')
261
+		);
262
+		try
263
+		{
264
+			$result=$this->request('POST', $url, array('X-HTTP-Method-Override: GET'), $body);
265
+		} catch (Exception $e)
266
+		{
267
+			throw new Exception($e->getMessage());
268
+		}
269 269
         
270
-        if (property_exists($result,'error') )
271
-        {
272
-            if (property_exists($result,'status'))
273
-            {
274
-                throw new Exception('Ret code ' .$result->error.' : ' . $result->status);
275
-            }
276
-            else
277
-            {
278
-                throw new Exception('Ret code ' .$result->error.' : Unkown status');
279
-            }
280
-        }
281
-        if (property_exists($result, 'results'))
282
-        {
283
-            $numHost=0;
284
-            $hostArray=array();
285
-            while (isset($result->results[$numHost]) && property_exists ($result->results[$numHost],'attrs'))
286
-            {
287
-                $hostArray[$numHost] = $result->results[$numHost]->attrs;
288
-                $hostArray[$numHost]->name = $result->results[$numHost]->name;
289
-                $numHost++;
290
-            }
291
-            return $hostArray;
292
-        }
293
-        throw new Exception('Unkown result');
294
-    }
270
+		if (property_exists($result,'error') )
271
+		{
272
+			if (property_exists($result,'status'))
273
+			{
274
+				throw new Exception('Ret code ' .$result->error.' : ' . $result->status);
275
+			}
276
+			else
277
+			{
278
+				throw new Exception('Ret code ' .$result->error.' : Unkown status');
279
+			}
280
+		}
281
+		if (property_exists($result, 'results'))
282
+		{
283
+			$numHost=0;
284
+			$hostArray=array();
285
+			while (isset($result->results[$numHost]) && property_exists ($result->results[$numHost],'attrs'))
286
+			{
287
+				$hostArray[$numHost] = $result->results[$numHost]->attrs;
288
+				$hostArray[$numHost]->name = $result->results[$numHost]->name;
289
+				$numHost++;
290
+			}
291
+			return $hostArray;
292
+		}
293
+		throw new Exception('Unkown result');
294
+	}
295 295
     
296
-    /**
297
-     * Send request to API
298
-     * @param string $method get/post/...
299
-     * @param string $url (after /v1/ )
300
-     * @param array $headers
301
-     * @param array $body 
302
-     * @throws Exception
303
-     * @return array
304
-     */
305
-    public function request($method, $url, $headers, $body) {
306
-        $auth = sprintf('%s:%s', $this->user, $this->pass);
307
-        $curlHeaders = array("Accept: application/json");
308
-        if ($body !== null) {
309
-            $body = json_encode($body);
310
-            array_push($curlHeaders, 'Content-Type: application/json');
311
-            //array_push($curlHeaders, 'X-HTTP-Method-Override: GET');
312
-        }
313
-        //var_dump($body);
314
-        //var_dump($this->url($url));
315
-        if ($headers !== null) {
316
-            $curlFinalHeaders = array_merge($curlHeaders, $headers);
317
-        } else 
318
-        {
319
-            $curlFinalHeaders=$curlHeaders;
320
-        }
321
-        $curl = $this->curl();
322
-        $opts = array(
323
-            CURLOPT_URL		=> $this->url($url),
324
-            CURLOPT_HTTPHEADER 	=> $curlFinalHeaders,
325
-            CURLOPT_USERPWD		=> $auth,
326
-            CURLOPT_CUSTOMREQUEST	=> strtoupper($method),
327
-            CURLOPT_RETURNTRANSFER 	=> true,
328
-            CURLOPT_CONNECTTIMEOUT 	=> 10,
329
-            CURLOPT_SSL_VERIFYHOST 	=> false,
330
-            CURLOPT_SSL_VERIFYPEER 	=> false,
331
-        );
332
-        if ($body !== null) {
333
-            $opts[CURLOPT_POSTFIELDS] = $body;
334
-        }
335
-        curl_setopt_array($curl, $opts);
336
-        $res = curl_exec($curl);
337
-        if ($res === false) {
338
-            throw new Exception('CURL ERROR: ' . curl_error($curl));
339
-        }
340
-        $statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
341
-        if ($statusCode === 401) {
342
-            throw new Exception('Unable to authenticate, please check your API credentials');
343
-        }
344
-        return $this->fromJsonResult($res);
345
-    }
296
+	/**
297
+	 * Send request to API
298
+	 * @param string $method get/post/...
299
+	 * @param string $url (after /v1/ )
300
+	 * @param array $headers
301
+	 * @param array $body 
302
+	 * @throws Exception
303
+	 * @return array
304
+	 */
305
+	public function request($method, $url, $headers, $body) {
306
+		$auth = sprintf('%s:%s', $this->user, $this->pass);
307
+		$curlHeaders = array("Accept: application/json");
308
+		if ($body !== null) {
309
+			$body = json_encode($body);
310
+			array_push($curlHeaders, 'Content-Type: application/json');
311
+			//array_push($curlHeaders, 'X-HTTP-Method-Override: GET');
312
+		}
313
+		//var_dump($body);
314
+		//var_dump($this->url($url));
315
+		if ($headers !== null) {
316
+			$curlFinalHeaders = array_merge($curlHeaders, $headers);
317
+		} else 
318
+		{
319
+			$curlFinalHeaders=$curlHeaders;
320
+		}
321
+		$curl = $this->curl();
322
+		$opts = array(
323
+			CURLOPT_URL		=> $this->url($url),
324
+			CURLOPT_HTTPHEADER 	=> $curlFinalHeaders,
325
+			CURLOPT_USERPWD		=> $auth,
326
+			CURLOPT_CUSTOMREQUEST	=> strtoupper($method),
327
+			CURLOPT_RETURNTRANSFER 	=> true,
328
+			CURLOPT_CONNECTTIMEOUT 	=> 10,
329
+			CURLOPT_SSL_VERIFYHOST 	=> false,
330
+			CURLOPT_SSL_VERIFYPEER 	=> false,
331
+		);
332
+		if ($body !== null) {
333
+			$opts[CURLOPT_POSTFIELDS] = $body;
334
+		}
335
+		curl_setopt_array($curl, $opts);
336
+		$res = curl_exec($curl);
337
+		if ($res === false) {
338
+			throw new Exception('CURL ERROR: ' . curl_error($curl));
339
+		}
340
+		$statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
341
+		if ($statusCode === 401) {
342
+			throw new Exception('Unable to authenticate, please check your API credentials');
343
+		}
344
+		return $this->fromJsonResult($res);
345
+	}
346 346
     
347
-    /**
348
-     * 
349
-     * @param string $json json encoded 
350
-     * @throws Exception
351
-     * @return array json decoded
352
-     */
353
-    protected function fromJsonResult($json) {
354
-        $result = @json_decode($json);
355
-        //var_dump($json);
356
-        if ($result === null) {
357
-            throw new Exception('Parsing JSON failed: '.$this->getLastJsonErrorMessage(json_last_error()));
358
-        }
359
-        return $result;
360
-    }
347
+	/**
348
+	 * 
349
+	 * @param string $json json encoded 
350
+	 * @throws Exception
351
+	 * @return array json decoded
352
+	 */
353
+	protected function fromJsonResult($json) {
354
+		$result = @json_decode($json);
355
+		//var_dump($json);
356
+		if ($result === null) {
357
+			throw new Exception('Parsing JSON failed: '.$this->getLastJsonErrorMessage(json_last_error()));
358
+		}
359
+		return $result;
360
+	}
361 361
     
362
-    /**
363
-     * Return text error no json error
364
-     * @param string $errorCode
365
-     * @return string
366
-     */
367
-    protected function getLastJsonErrorMessage($errorCode) {
368
-        if (!array_key_exists($errorCode, $this->errorReference)) {
369
-            return self::JSON_UNKNOWN_ERROR;
370
-        }
371
-        return $this->errorReference[$errorCode];
372
-    }
362
+	/**
363
+	 * Return text error no json error
364
+	 * @param string $errorCode
365
+	 * @return string
366
+	 */
367
+	protected function getLastJsonErrorMessage($errorCode) {
368
+		if (!array_key_exists($errorCode, $this->errorReference)) {
369
+			return self::JSON_UNKNOWN_ERROR;
370
+		}
371
+		return $this->errorReference[$errorCode];
372
+	}
373 373
 }
374 374
 
Please login to merge, or discard this patch.
Spacing   +54 added lines, -54 removed lines patch added patch discarded remove patch
@@ -8,19 +8,19 @@  discard block
 block discarded – undo
8 8
 
9 9
 class Icinga2API 
10 10
 {
11
-    protected $version = 'v1';      //< icinga2 api version
11
+    protected $version='v1'; //< icinga2 api version
12 12
     
13
-    protected $host;                //< icinga2 host name or IP
14
-    protected $port;                //< icinga2 api port
13
+    protected $host; //< icinga2 host name or IP
14
+    protected $port; //< icinga2 api port
15 15
     
16
-    protected $user;                //< user name
17
-    protected $pass;                //< user password
18
-    protected $usercert;            //< user key for certificate auth (NOT IMPLEMENTED)
19
-    protected $authmethod='pass';   //< Authentication : 'pass' or 'cert'
16
+    protected $user; //< user name
17
+    protected $pass; //< user password
18
+    protected $usercert; //< user key for certificate auth (NOT IMPLEMENTED)
19
+    protected $authmethod='pass'; //< Authentication : 'pass' or 'cert'
20 20
 
21 21
     protected $curl;
22 22
     // http://php.net/manual/de/function.json-last-error.php#119985
23
-    protected $errorReference = [
23
+    protected $errorReference=[
24 24
         JSON_ERROR_NONE => 'No error has occurred.',
25 25
         JSON_ERROR_DEPTH => 'The maximum stack depth has been exceeded.',
26 26
         JSON_ERROR_STATE_MISMATCH => 'Invalid or malformed JSON.',
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
         JSON_ERROR_INF_OR_NAN => 'One or more NAN or INF values in the value to be encoded.',
32 32
         JSON_ERROR_UNSUPPORTED_TYPE => 'A value of a type that cannot be encoded was given.',
33 33
     ];
34
-    const JSON_UNKNOWN_ERROR = 'Unknown error.';
34
+    const JSON_UNKNOWN_ERROR='Unknown error.';
35 35
     
36 36
     /**
37 37
      * Creates Icinga2API object
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
39 39
      * @param string $host host name or IP
40 40
      * @param number $port API port
41 41
      */
42
-    public function __construct($host, $port = 5665)
42
+    public function __construct($host, $port=5665)
43 43
     {
44 44
         $this->host=$host;
45 45
         $this->port=$port;
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
      * @param string $user
50 50
      * @param string $pass
51 51
      */
52
-    public function setCredentials($user,$pass)
52
+    public function setCredentials($user, $pass)
53 53
     {
54 54
         $this->user=$user;
55 55
         $this->pass=$pass;
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
      * @param string $user
62 62
      * @param string $usercert
63 63
      */
64
-    public function setCredentialskey($user,$usercert)
64
+    public function setCredentialskey($user, $usercert)
65 65
     {
66 66
         $this->user=$user;
67 67
         $this->usercert=$usercert;
@@ -84,18 +84,18 @@  discard block
 block discarded – undo
84 84
         $permMissing='';
85 85
         if ($permissions === NULL) // If no permission check return OK after connexion
86 86
         {
87
-            return array(false,'OK');
87
+            return array(false, 'OK');
88 88
         }
89 89
         if (property_exists($result, 'results') && property_exists($result->results[0], 'permissions'))
90 90
         {
91 91
             
92
-            foreach ( $permissions as $mustPermission)
92
+            foreach ($permissions as $mustPermission)
93 93
             {
94 94
                 $curPermOK=0;
95
-                foreach ( $result->results[0]->permissions as $curPermission)
95
+                foreach ($result->results[0]->permissions as $curPermission)
96 96
                 {
97
-                    $curPermission=preg_replace('/\*/','.*',$curPermission); // put * as .* to created a regexp
98
-                    if (preg_match('#'.$curPermission.'#',$mustPermission))
97
+                    $curPermission=preg_replace('/\*/', '.*', $curPermission); // put * as .* to created a regexp
98
+                    if (preg_match('#'.$curPermission.'#', $mustPermission))
99 99
                     {
100 100
                         $curPermOK=1;
101 101
                         break;
@@ -110,12 +110,12 @@  discard block
 block discarded – undo
110 110
             }
111 111
             if ($permOk == 0)
112 112
             {
113
-                return array(true,'API connection OK, but missing permission : '.$permMissing);
113
+                return array(true, 'API connection OK, but missing permission : '.$permMissing);
114 114
             }
115
-            return array(false,'API connection OK');
115
+            return array(false, 'API connection OK');
116 116
             
117 117
         }
118
-        return array(true,'API connection OK, but cannot get permissions');
118
+        return array(true, 'API connection OK, but cannot get permissions');
119 119
     }
120 120
     
121 121
     
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
      */
131 131
     protected function curl() {
132 132
         if ($this->curl === null) {
133
-            $this->curl = curl_init(sprintf('https://%s:%d', $this->host, $this->port));
133
+            $this->curl=curl_init(sprintf('https://%s:%d', $this->host, $this->port));
134 134
             if ($this->curl === false) {
135 135
                 throw new Exception('CURL INIT ERROR');
136 136
             }
@@ -147,7 +147,7 @@  discard block
 block discarded – undo
147 147
      * @param string $perfdata : performance data as string
148 148
      * @return array (status = true (oK) or false (nok), string message)
149 149
      */
150
-    public function serviceCheckResult($host,$service,$state,$display,$perfdata='')
150
+    public function serviceCheckResult($host, $service, $state, $display, $perfdata='')
151 151
     {
152 152
         //Send a POST request to the URL endpoint /v1/actions/process-check-result
153 153
         //actions/process-check-result?service=example.localdomain!passive-ping6
@@ -166,9 +166,9 @@  discard block
 block discarded – undo
166 166
         {
167 167
             return array(false, $e->getMessage());
168 168
         }
169
-        if (property_exists($result,'error') )
169
+        if (property_exists($result, 'error'))
170 170
         {
171
-            if (property_exists($result,'status'))
171
+            if (property_exists($result, 'status'))
172 172
             {
173 173
                 $message=$result->status;
174 174
             }
@@ -176,21 +176,21 @@  discard block
 block discarded – undo
176 176
             {
177 177
                 $message="Unkown status";
178 178
             }
179
-            return array(false , 'Ret code ' .$result->error.' : '.$message);
179
+            return array(false, 'Ret code '.$result->error.' : '.$message);
180 180
         }
181 181
         if (property_exists($result, 'results'))
182 182
         {
183 183
             if (isset($result->results[0]))
184 184
             {
185
-                return array(true,'code '.$result->results[0]->code.' : '.$result->results[0]->status);
185
+                return array(true, 'code '.$result->results[0]->code.' : '.$result->results[0]->status);
186 186
             }
187 187
             else
188 188
             {
189
-                return array(false,'Service not found');
189
+                return array(false, 'Service not found');
190 190
             }
191 191
             
192 192
         }
193
-        return array(false,'Unkown result, open issue with this : '.print_r($result,true));
193
+        return array(false, 'Unkown result, open issue with this : '.print_r($result, true));
194 194
     }
195 195
  
196 196
     /**
@@ -211,7 +211,7 @@  discard block
 block discarded – undo
211 211
         $url='objects/hosts';
212 212
         $body=array(
213 213
             "filter"        => 'host.address=="'.$ip.'" || host.address6=="'.$ip.'"',
214
-            "attrs"         => array('__name','name','display_name')
214
+            "attrs"         => array('__name', 'name', 'display_name')
215 215
         );
216 216
         try
217 217
         {
@@ -221,24 +221,24 @@  discard block
 block discarded – undo
221 221
             throw new Exception($e->getMessage());
222 222
         }
223 223
         
224
-        if (property_exists($result,'error') )
224
+        if (property_exists($result, 'error'))
225 225
         {
226
-            if (property_exists($result,'status'))
226
+            if (property_exists($result, 'status'))
227 227
             {
228
-                throw new Exception('Ret code ' .$result->error.' : ' . $result->status);
228
+                throw new Exception('Ret code '.$result->error.' : '.$result->status);
229 229
             }
230 230
             else
231 231
             {
232
-                throw new Exception('Ret code ' .$result->error.' : Unkown status');
232
+                throw new Exception('Ret code '.$result->error.' : Unkown status');
233 233
             }
234 234
         }
235 235
         if (property_exists($result, 'results'))
236 236
         {
237 237
             $numHost=0;
238 238
             $hostArray=array();
239
-            while (isset($result->results[$numHost]) && property_exists ($result->results[$numHost],'attrs'))
239
+            while (isset($result->results[$numHost]) && property_exists($result->results[$numHost], 'attrs'))
240 240
             {
241
-                $hostArray[$numHost] = $result->results[$numHost]->attrs;
241
+                $hostArray[$numHost]=$result->results[$numHost]->attrs;
242 242
                 $numHost++;
243 243
             }
244 244
             return $hostArray;            
@@ -257,7 +257,7 @@  discard block
 block discarded – undo
257 257
         $url='objects/hosts';
258 258
         $body=array(
259 259
             "filter"        => '\"'.$hostGroup.'\" in host.groups',
260
-            "attrs"         => array('address','address','name')
260
+            "attrs"         => array('address', 'address', 'name')
261 261
         );
262 262
         try
263 263
         {
@@ -267,25 +267,25 @@  discard block
 block discarded – undo
267 267
             throw new Exception($e->getMessage());
268 268
         }
269 269
         
270
-        if (property_exists($result,'error') )
270
+        if (property_exists($result, 'error'))
271 271
         {
272
-            if (property_exists($result,'status'))
272
+            if (property_exists($result, 'status'))
273 273
             {
274
-                throw new Exception('Ret code ' .$result->error.' : ' . $result->status);
274
+                throw new Exception('Ret code '.$result->error.' : '.$result->status);
275 275
             }
276 276
             else
277 277
             {
278
-                throw new Exception('Ret code ' .$result->error.' : Unkown status');
278
+                throw new Exception('Ret code '.$result->error.' : Unkown status');
279 279
             }
280 280
         }
281 281
         if (property_exists($result, 'results'))
282 282
         {
283 283
             $numHost=0;
284 284
             $hostArray=array();
285
-            while (isset($result->results[$numHost]) && property_exists ($result->results[$numHost],'attrs'))
285
+            while (isset($result->results[$numHost]) && property_exists($result->results[$numHost], 'attrs'))
286 286
             {
287
-                $hostArray[$numHost] = $result->results[$numHost]->attrs;
288
-                $hostArray[$numHost]->name = $result->results[$numHost]->name;
287
+                $hostArray[$numHost]=$result->results[$numHost]->attrs;
288
+                $hostArray[$numHost]->name=$result->results[$numHost]->name;
289 289
                 $numHost++;
290 290
             }
291 291
             return $hostArray;
@@ -303,23 +303,23 @@  discard block
 block discarded – undo
303 303
      * @return array
304 304
      */
305 305
     public function request($method, $url, $headers, $body) {
306
-        $auth = sprintf('%s:%s', $this->user, $this->pass);
307
-        $curlHeaders = array("Accept: application/json");
306
+        $auth=sprintf('%s:%s', $this->user, $this->pass);
307
+        $curlHeaders=array("Accept: application/json");
308 308
         if ($body !== null) {
309
-            $body = json_encode($body);
309
+            $body=json_encode($body);
310 310
             array_push($curlHeaders, 'Content-Type: application/json');
311 311
             //array_push($curlHeaders, 'X-HTTP-Method-Override: GET');
312 312
         }
313 313
         //var_dump($body);
314 314
         //var_dump($this->url($url));
315 315
         if ($headers !== null) {
316
-            $curlFinalHeaders = array_merge($curlHeaders, $headers);
316
+            $curlFinalHeaders=array_merge($curlHeaders, $headers);
317 317
         } else 
318 318
         {
319 319
             $curlFinalHeaders=$curlHeaders;
320 320
         }
321
-        $curl = $this->curl();
322
-        $opts = array(
321
+        $curl=$this->curl();
322
+        $opts=array(
323 323
             CURLOPT_URL		=> $this->url($url),
324 324
             CURLOPT_HTTPHEADER 	=> $curlFinalHeaders,
325 325
             CURLOPT_USERPWD		=> $auth,
@@ -330,14 +330,14 @@  discard block
 block discarded – undo
330 330
             CURLOPT_SSL_VERIFYPEER 	=> false,
331 331
         );
332 332
         if ($body !== null) {
333
-            $opts[CURLOPT_POSTFIELDS] = $body;
333
+            $opts[CURLOPT_POSTFIELDS]=$body;
334 334
         }
335 335
         curl_setopt_array($curl, $opts);
336
-        $res = curl_exec($curl);
336
+        $res=curl_exec($curl);
337 337
         if ($res === false) {
338
-            throw new Exception('CURL ERROR: ' . curl_error($curl));
338
+            throw new Exception('CURL ERROR: '.curl_error($curl));
339 339
         }
340
-        $statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
340
+        $statusCode=curl_getinfo($curl, CURLINFO_HTTP_CODE);
341 341
         if ($statusCode === 401) {
342 342
             throw new Exception('Unable to authenticate, please check your API credentials');
343 343
         }
@@ -351,7 +351,7 @@  discard block
 block discarded – undo
351 351
      * @return array json decoded
352 352
      */
353 353
     protected function fromJsonResult($json) {
354
-        $result = @json_decode($json);
354
+        $result=@json_decode($json);
355 355
         //var_dump($json);
356 356
         if ($result === null) {
357 357
             throw new Exception('Parsing JSON failed: '.$this->getLastJsonErrorMessage(json_last_error()));
Please login to merge, or discard this patch.
Braces   +8 added lines, -11 removed lines patch added patch discarded remove patch
@@ -74,18 +74,19 @@  discard block
 block discarded – undo
74 74
        try
75 75
         {
76 76
             $result=$this->request('GET', "", NULL, NULL);
77
-        } 
78
-        catch (Exception $e)
77
+        } catch (Exception $e)
79 78
         {
80 79
             return array(true, 'Error with API : '.$e->getMessage());
81 80
         }
82 81
         //var_dump($result);
83 82
         $permOk=1;
84 83
         $permMissing='';
85
-        if ($permissions === NULL) // If no permission check return OK after connexion
84
+        if ($permissions === NULL) {
85
+        	// If no permission check return OK after connexion
86 86
         {
87 87
             return array(false,'OK');
88 88
         }
89
+        }
89 90
         if (property_exists($result, 'results') && property_exists($result->results[0], 'permissions'))
90 91
         {
91 92
             
@@ -171,8 +172,7 @@  discard block
 block discarded – undo
171 172
             if (property_exists($result,'status'))
172 173
             {
173 174
                 $message=$result->status;
174
-            }
175
-            else 
175
+            } else 
176 176
             {
177 177
                 $message="Unkown status";
178 178
             }
@@ -183,8 +183,7 @@  discard block
 block discarded – undo
183 183
             if (isset($result->results[0]))
184 184
             {
185 185
                 return array(true,'code '.$result->results[0]->code.' : '.$result->results[0]->status);
186
-            }
187
-            else
186
+            } else
188 187
             {
189 188
                 return array(false,'Service not found');
190 189
             }
@@ -226,8 +225,7 @@  discard block
 block discarded – undo
226 225
             if (property_exists($result,'status'))
227 226
             {
228 227
                 throw new Exception('Ret code ' .$result->error.' : ' . $result->status);
229
-            }
230
-            else
228
+            } else
231 229
             {
232 230
                 throw new Exception('Ret code ' .$result->error.' : Unkown status');
233 231
             }
@@ -272,8 +270,7 @@  discard block
 block discarded – undo
272 270
             if (property_exists($result,'status'))
273 271
             {
274 272
                 throw new Exception('Ret code ' .$result->error.' : ' . $result->status);
275
-            }
276
-            else
273
+            } else
277 274
             {
278 275
                 throw new Exception('Ret code ' .$result->error.' : Unkown status');
279 276
             }
Please login to merge, or discard this patch.
library/Trapdirector/TrapsProcess/TrapConfig.php 3 patches
Braces   +8 added lines, -6 removed lines patch added patch discarded remove patch
@@ -40,8 +40,7 @@  discard block
 block discarded – undo
40 40
             }
41 41
             $this->getLogging()->log($message,$log_level);
42 42
             return false;
43
-        }
44
-        else
43
+        } else
45 44
         {
46 45
             $option_var=$option_array[$option_category][$option_name];
47 46
             return true;
@@ -54,9 +53,11 @@  discard block
 block discarded – undo
54 53
     protected function getDatabaseOptions()
55 54
     {
56 55
         // Database options
57
-        if ($this->logSetup === false) // Only if logging was no setup in constructor
56
+        if ($this->logSetup === false) {
57
+        	// Only if logging was no setup in constructor
58 58
         {
59 59
             $this->getDBConfigIfSet('log_level',$this->getLogging()->debugLevel);
60
+        }
60 61
             $this->getDBConfigIfSet('log_destination',$this->getLogging()->outputMode);
61 62
             $this->getDBConfigIfSet('log_file',$this->getLogging()->outputFile);
62 63
         }
@@ -69,7 +70,9 @@  discard block
 block discarded – undo
69 70
     protected function getDBConfigIfSet($element,&$variable)
70 71
     {
71 72
         $value=$this->getDBConfig($element);
72
-        if ($value != null) $variable=$value;
73
+        if ($value != null) {
74
+        	$variable=$value;
75
+        }
73 76
     }
74 77
     
75 78
     /**
@@ -106,8 +109,7 @@  discard block
 block discarded – undo
106 109
         {
107 110
             $this->getLogging()->log('Unknown node status '.$nodeStatus.' : setting to MASTER',WARN);
108 111
             $this->getTrapApi()->setStatusMaster();
109
-        }
110
-        else 
112
+        } else 
111 113
         {
112 114
             if ($this->getTrapApi()->getStatus() != TrapApi::MASTER)
113 115
             {
Please login to merge, or discard this patch.
Indentation   +160 added lines, -160 removed lines patch added patch discarded remove patch
@@ -15,184 +15,184 @@
 block discarded – undo
15 15
 trait TrapConfig
16 16
 {
17 17
 
18
-    /** @return \Trapdirector\Logging   */
19
-    abstract public function getLogging();
20
-    /** @return \Trapdirector\TrapApi   */
21
-    abstract public function getTrapApi();
18
+	/** @return \Trapdirector\Logging   */
19
+	abstract public function getLogging();
20
+	/** @return \Trapdirector\TrapApi   */
21
+	abstract public function getTrapApi();
22 22
     
23
-    /**
24
-     * Get option from array of ini file, send message if empty
25
-     * @param string $option_array Array of ini file
26
-     * @param string $option_category category in ini file
27
-     * @param string $option_name name of option in category
28
-     * @param mixed $option_var variable to fill if found, left untouched if not found
29
-     * @param integer $log_level default 2 (warning)
30
-     * @param string $message warning message if not found
31
-     * @return boolean true if found, or false
32
-     */
33
-    protected function getOptionIfSet($option_array,$option_category,$option_name, &$option_var, $log_level = WARN, $message = null)
34
-    {
35
-        if (!isset($option_array[$option_category][$option_name]))
36
-        {
37
-            if ($message === null)
38
-            {
39
-                $message='No ' . $option_name . ' in config file: '. $this->trapModuleConfig;
40
-            }
41
-            $this->getLogging()->log($message,$log_level);
42
-            return false;
43
-        }
44
-        else
45
-        {
46
-            $option_var=$option_array[$option_category][$option_name];
47
-            return true;
48
-        }
49
-    }
23
+	/**
24
+	 * Get option from array of ini file, send message if empty
25
+	 * @param string $option_array Array of ini file
26
+	 * @param string $option_category category in ini file
27
+	 * @param string $option_name name of option in category
28
+	 * @param mixed $option_var variable to fill if found, left untouched if not found
29
+	 * @param integer $log_level default 2 (warning)
30
+	 * @param string $message warning message if not found
31
+	 * @return boolean true if found, or false
32
+	 */
33
+	protected function getOptionIfSet($option_array,$option_category,$option_name, &$option_var, $log_level = WARN, $message = null)
34
+	{
35
+		if (!isset($option_array[$option_category][$option_name]))
36
+		{
37
+			if ($message === null)
38
+			{
39
+				$message='No ' . $option_name . ' in config file: '. $this->trapModuleConfig;
40
+			}
41
+			$this->getLogging()->log($message,$log_level);
42
+			return false;
43
+		}
44
+		else
45
+		{
46
+			$option_var=$option_array[$option_category][$option_name];
47
+			return true;
48
+		}
49
+	}
50 50
 
51
-    /**
52
-     * Get options in database
53
-     */
54
-    protected function getDatabaseOptions()
55
-    {
56
-        // Database options
57
-        if ($this->logSetup === false) // Only if logging was no setup in constructor
58
-        {
59
-            $this->getDBConfigIfSet('log_level',$this->getLogging()->debugLevel);
60
-            $this->getDBConfigIfSet('log_destination',$this->getLogging()->outputMode);
61
-            $this->getDBConfigIfSet('log_file',$this->getLogging()->outputFile);
62
-        }
63
-    }
51
+	/**
52
+	 * Get options in database
53
+	 */
54
+	protected function getDatabaseOptions()
55
+	{
56
+		// Database options
57
+		if ($this->logSetup === false) // Only if logging was no setup in constructor
58
+		{
59
+			$this->getDBConfigIfSet('log_level',$this->getLogging()->debugLevel);
60
+			$this->getDBConfigIfSet('log_destination',$this->getLogging()->outputMode);
61
+			$this->getDBConfigIfSet('log_file',$this->getLogging()->outputFile);
62
+		}
63
+	}
64 64
         
65
-    /** Set $variable to value if $element found in database config table
66
-     * @param string $element
67
-     * @param string $variable
68
-     */
69
-    protected function getDBConfigIfSet($element,&$variable)
70
-    {
71
-        $value=$this->getDBConfig($element);
72
-        if ($value != null) $variable=$value;
73
-    }
65
+	/** Set $variable to value if $element found in database config table
66
+	 * @param string $element
67
+	 * @param string $variable
68
+	 */
69
+	protected function getDBConfigIfSet($element,&$variable)
70
+	{
71
+		$value=$this->getDBConfig($element);
72
+		if ($value != null) $variable=$value;
73
+	}
74 74
     
75
-    /**
76
-     *   Get data from db_config
77
-     *	@param $element string name of param
78
-     *	@return mixed : value (or null)
79
-     */
80
-    protected function getDBConfig($element)  // TODO : put this in DB class
81
-    {
82
-        $db_conn=$this->trapsDB->db_connect_trap();
83
-        $sql='SELECT value from '.$this->dbPrefix.'db_config WHERE ( name=\''.$element.'\' )';
84
-        if (($ret_code=$db_conn->query($sql)) === false) {
85
-            $this->logging->log('No result in query : ' . $sql,WARN,'');
86
-            return null;
87
-        }
88
-        $value=$ret_code->fetch();
89
-        if ($value != null && isset($value['value']))
90
-        {
91
-            return $value['value'];
92
-        }
93
-        return null;
94
-    }
75
+	/**
76
+	 *   Get data from db_config
77
+	 *	@param $element string name of param
78
+	 *	@return mixed : value (or null)
79
+	 */
80
+	protected function getDBConfig($element)  // TODO : put this in DB class
81
+	{
82
+		$db_conn=$this->trapsDB->db_connect_trap();
83
+		$sql='SELECT value from '.$this->dbPrefix.'db_config WHERE ( name=\''.$element.'\' )';
84
+		if (($ret_code=$db_conn->query($sql)) === false) {
85
+			$this->logging->log('No result in query : ' . $sql,WARN,'');
86
+			return null;
87
+		}
88
+		$value=$ret_code->fetch();
89
+		if ($value != null && isset($value['value']))
90
+		{
91
+			return $value['value'];
92
+		}
93
+		return null;
94
+	}
95 95
     
96
-    /**
97
-     * Get options from ini file
98
-     * @param array $trap_config : ini file array
99
-     */
100
-    protected function getMainOptions($trapConfig)
101
-    {
96
+	/**
97
+	 * Get options from ini file
98
+	 * @param array $trap_config : ini file array
99
+	 */
100
+	protected function getMainOptions($trapConfig)
101
+	{
102 102
         
103
-        $nodeStatus='';
104
-        $this->getOptionIfSet($trapConfig,'config','node', $nodeStatus);
105
-        if ($this->getTrapApi()->setStatus($nodeStatus) === FALSE)
106
-        {
107
-            $this->getLogging()->log('Unknown node status '.$nodeStatus.' : setting to MASTER',WARN);
108
-            $this->getTrapApi()->setStatusMaster();
109
-        }
110
-        else 
111
-        {
112
-            if ($this->getTrapApi()->getStatus() != TrapApi::MASTER)
113
-            {
114
-                // Get options to connect to API
115
-                $IP = $port = $user =  $pass = null;
116
-                $this->getOptionIfSet($trapConfig,'config','masterIP', $IP, ERROR);
117
-                $this->getOptionIfSet($trapConfig,'config','masterPort', $port, ERROR);
118
-                $this->getOptionIfSet($trapConfig,'config','masterUser', $user, ERROR);
119
-                $this->getOptionIfSet($trapConfig,'config','masterPass', $pass, ERROR);
120
-                $this->getTrapApi()->setParams($IP, $port, $user, $pass);
121
-                return;
122
-            }
123
-        }
103
+		$nodeStatus='';
104
+		$this->getOptionIfSet($trapConfig,'config','node', $nodeStatus);
105
+		if ($this->getTrapApi()->setStatus($nodeStatus) === FALSE)
106
+		{
107
+			$this->getLogging()->log('Unknown node status '.$nodeStatus.' : setting to MASTER',WARN);
108
+			$this->getTrapApi()->setStatusMaster();
109
+		}
110
+		else 
111
+		{
112
+			if ($this->getTrapApi()->getStatus() != TrapApi::MASTER)
113
+			{
114
+				// Get options to connect to API
115
+				$IP = $port = $user =  $pass = null;
116
+				$this->getOptionIfSet($trapConfig,'config','masterIP', $IP, ERROR);
117
+				$this->getOptionIfSet($trapConfig,'config','masterPort', $port, ERROR);
118
+				$this->getOptionIfSet($trapConfig,'config','masterUser', $user, ERROR);
119
+				$this->getOptionIfSet($trapConfig,'config','masterPass', $pass, ERROR);
120
+				$this->getTrapApi()->setParams($IP, $port, $user, $pass);
121
+				return;
122
+			}
123
+		}
124 124
         
125
-        // Snmptranslate binary path
126
-        $this->getOptionIfSet($trapConfig,'config','snmptranslate', $this->snmptranslate);
125
+		// Snmptranslate binary path
126
+		$this->getOptionIfSet($trapConfig,'config','snmptranslate', $this->snmptranslate);
127 127
         
128
-        // mibs path
129
-        $this->getOptionIfSet($trapConfig,'config','snmptranslate_dirs', $this->snmptranslate_dirs);
128
+		// mibs path
129
+		$this->getOptionIfSet($trapConfig,'config','snmptranslate_dirs', $this->snmptranslate_dirs);
130 130
         
131
-        // icinga2cmd path
132
-        $this->getOptionIfSet($trapConfig,'config','icingacmd', $this->icinga2cmd);
131
+		// icinga2cmd path
132
+		$this->getOptionIfSet($trapConfig,'config','icingacmd', $this->icinga2cmd);
133 133
         
134
-        // table prefix
135
-        $this->getOptionIfSet($trapConfig,'config','database_prefix', $this->dbPrefix);
134
+		// table prefix
135
+		$this->getOptionIfSet($trapConfig,'config','database_prefix', $this->dbPrefix);
136 136
         
137
-        // API options
138
-        if ($this->getOptionIfSet($trapConfig,'config','icingaAPI_host', $this->apiHostname))
139
-        {
140
-            $this->apiUse=true;
141
-            // Get API options or throw exception as not configured correctly
142
-            $this->getOptionIfSet($trapConfig,'config','icingaAPI_port', $this->apiPort,ERROR);
143
-            $this->getOptionIfSet($trapConfig,'config','icingaAPI_user', $this->apiUsername,ERROR);
144
-            $this->getOptionIfSet($trapConfig,'config','icingaAPI_password', $this->apiPassword,ERROR);
145
-        }
146
-    }
137
+		// API options
138
+		if ($this->getOptionIfSet($trapConfig,'config','icingaAPI_host', $this->apiHostname))
139
+		{
140
+			$this->apiUse=true;
141
+			// Get API options or throw exception as not configured correctly
142
+			$this->getOptionIfSet($trapConfig,'config','icingaAPI_port', $this->apiPort,ERROR);
143
+			$this->getOptionIfSet($trapConfig,'config','icingaAPI_user', $this->apiUsername,ERROR);
144
+			$this->getOptionIfSet($trapConfig,'config','icingaAPI_password', $this->apiPassword,ERROR);
145
+		}
146
+	}
147 147
     
148
-    /**
149
-     * Create and setup database class for trap & ido (if no api) db
150
-     * @param array $trap_config : ini file array
151
-     */
152
-    protected function setupDatabase($trapConfig)
153
-    {
154
-        // Trap database
155
-        if (!array_key_exists('database',$trapConfig['config']))
156
-        {
157
-            $this->logging->log("No database in config file: ".$this->trapModuleConfig,ERROR,'');
158
-            return;
159
-        }
160
-        $dbTrapName=$trapConfig['config']['database'];
161
-        $this->logging->log("Found database in config file: ".$dbTrapName,INFO );
148
+	/**
149
+	 * Create and setup database class for trap & ido (if no api) db
150
+	 * @param array $trap_config : ini file array
151
+	 */
152
+	protected function setupDatabase($trapConfig)
153
+	{
154
+		// Trap database
155
+		if (!array_key_exists('database',$trapConfig['config']))
156
+		{
157
+			$this->logging->log("No database in config file: ".$this->trapModuleConfig,ERROR,'');
158
+			return;
159
+		}
160
+		$dbTrapName=$trapConfig['config']['database'];
161
+		$this->logging->log("Found database in config file: ".$dbTrapName,INFO );
162 162
         
163
-        if ( ($dbConfig=parse_ini_file($this->icingaweb2Ressources,true)) === false)
164
-        {
165
-            $this->logging->log("Error reading ini file : ".$this->icingaweb2Ressources,ERROR,'');
166
-            return;
167
-        }
168
-        if (!array_key_exists($dbTrapName,$dbConfig))
169
-        {
170
-            $this->logging->log("No database '.$dbTrapName.' in config file: ".$this->icingaweb2Ressources,ERROR,'');
171
-            return;
172
-        }
163
+		if ( ($dbConfig=parse_ini_file($this->icingaweb2Ressources,true)) === false)
164
+		{
165
+			$this->logging->log("Error reading ini file : ".$this->icingaweb2Ressources,ERROR,'');
166
+			return;
167
+		}
168
+		if (!array_key_exists($dbTrapName,$dbConfig))
169
+		{
170
+			$this->logging->log("No database '.$dbTrapName.' in config file: ".$this->icingaweb2Ressources,ERROR,'');
171
+			return;
172
+		}
173 173
         
174
-        $this->trapsDB = new Database($this->logging,$dbConfig[$dbTrapName],$this->dbPrefix);
174
+		$this->trapsDB = new Database($this->logging,$dbConfig[$dbTrapName],$this->dbPrefix);
175 175
         
176
-        $this->logging->log("API Use : ".print_r($this->apiUse,true),DEBUG );
176
+		$this->logging->log("API Use : ".print_r($this->apiUse,true),DEBUG );
177 177
         
178
-        //TODO enable this again when API queries are all done :
179
-        //if ($this->apiUse === true) return; // In case of API use, no IDO is necessary
178
+		//TODO enable this again when API queries are all done :
179
+		//if ($this->apiUse === true) return; // In case of API use, no IDO is necessary
180 180
         
181
-        // IDO Database
182
-        if (!array_key_exists('IDOdatabase',$trapConfig['config']))
183
-        {
184
-            $this->logging->log("No IDOdatabase in config file: ".$this->trapModuleConfig,ERROR,'');
185
-        }
186
-        $dbIdoName=$trapConfig['config']['IDOdatabase'];
181
+		// IDO Database
182
+		if (!array_key_exists('IDOdatabase',$trapConfig['config']))
183
+		{
184
+			$this->logging->log("No IDOdatabase in config file: ".$this->trapModuleConfig,ERROR,'');
185
+		}
186
+		$dbIdoName=$trapConfig['config']['IDOdatabase'];
187 187
         
188
-        $this->logging->log("Found IDO database in config file: ".$dbIdoName,INFO );
189
-        if (!array_key_exists($dbIdoName,$dbConfig))
190
-        {
191
-            $this->logging->log("No database '.$dbIdoName.' in config file: ".$this->icingaweb2Ressources,ERROR,'');
192
-            return;
193
-        }
188
+		$this->logging->log("Found IDO database in config file: ".$dbIdoName,INFO );
189
+		if (!array_key_exists($dbIdoName,$dbConfig))
190
+		{
191
+			$this->logging->log("No database '.$dbIdoName.' in config file: ".$this->icingaweb2Ressources,ERROR,'');
192
+			return;
193
+		}
194 194
         
195
-        $this->trapsDB->setupIDO($dbConfig[$dbIdoName]);
196
-    }
195
+		$this->trapsDB->setupIDO($dbConfig[$dbIdoName]);
196
+	}
197 197
     
198 198
 }
199 199
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -30,15 +30,15 @@  discard block
 block discarded – undo
30 30
      * @param string $message warning message if not found
31 31
      * @return boolean true if found, or false
32 32
      */
33
-    protected function getOptionIfSet($option_array,$option_category,$option_name, &$option_var, $log_level = WARN, $message = null)
33
+    protected function getOptionIfSet($option_array, $option_category, $option_name, &$option_var, $log_level=WARN, $message=null)
34 34
     {
35 35
         if (!isset($option_array[$option_category][$option_name]))
36 36
         {
37 37
             if ($message === null)
38 38
             {
39
-                $message='No ' . $option_name . ' in config file: '. $this->trapModuleConfig;
39
+                $message='No '.$option_name.' in config file: '.$this->trapModuleConfig;
40 40
             }
41
-            $this->getLogging()->log($message,$log_level);
41
+            $this->getLogging()->log($message, $log_level);
42 42
             return false;
43 43
         }
44 44
         else
@@ -56,9 +56,9 @@  discard block
 block discarded – undo
56 56
         // Database options
57 57
         if ($this->logSetup === false) // Only if logging was no setup in constructor
58 58
         {
59
-            $this->getDBConfigIfSet('log_level',$this->getLogging()->debugLevel);
60
-            $this->getDBConfigIfSet('log_destination',$this->getLogging()->outputMode);
61
-            $this->getDBConfigIfSet('log_file',$this->getLogging()->outputFile);
59
+            $this->getDBConfigIfSet('log_level', $this->getLogging()->debugLevel);
60
+            $this->getDBConfigIfSet('log_destination', $this->getLogging()->outputMode);
61
+            $this->getDBConfigIfSet('log_file', $this->getLogging()->outputFile);
62 62
         }
63 63
     }
64 64
         
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
      * @param string $element
67 67
      * @param string $variable
68 68
      */
69
-    protected function getDBConfigIfSet($element,&$variable)
69
+    protected function getDBConfigIfSet($element, &$variable)
70 70
     {
71 71
         $value=$this->getDBConfig($element);
72 72
         if ($value != null) $variable=$value;
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
         $db_conn=$this->trapsDB->db_connect_trap();
83 83
         $sql='SELECT value from '.$this->dbPrefix.'db_config WHERE ( name=\''.$element.'\' )';
84 84
         if (($ret_code=$db_conn->query($sql)) === false) {
85
-            $this->logging->log('No result in query : ' . $sql,WARN,'');
85
+            $this->logging->log('No result in query : '.$sql, WARN, '');
86 86
             return null;
87 87
         }
88 88
         $value=$ret_code->fetch();
@@ -101,10 +101,10 @@  discard block
 block discarded – undo
101 101
     {
102 102
         
103 103
         $nodeStatus='';
104
-        $this->getOptionIfSet($trapConfig,'config','node', $nodeStatus);
104
+        $this->getOptionIfSet($trapConfig, 'config', 'node', $nodeStatus);
105 105
         if ($this->getTrapApi()->setStatus($nodeStatus) === FALSE)
106 106
         {
107
-            $this->getLogging()->log('Unknown node status '.$nodeStatus.' : setting to MASTER',WARN);
107
+            $this->getLogging()->log('Unknown node status '.$nodeStatus.' : setting to MASTER', WARN);
108 108
             $this->getTrapApi()->setStatusMaster();
109 109
         }
110 110
         else 
@@ -112,36 +112,36 @@  discard block
 block discarded – undo
112 112
             if ($this->getTrapApi()->getStatus() != TrapApi::MASTER)
113 113
             {
114 114
                 // Get options to connect to API
115
-                $IP = $port = $user =  $pass = null;
116
-                $this->getOptionIfSet($trapConfig,'config','masterIP', $IP, ERROR);
117
-                $this->getOptionIfSet($trapConfig,'config','masterPort', $port, ERROR);
118
-                $this->getOptionIfSet($trapConfig,'config','masterUser', $user, ERROR);
119
-                $this->getOptionIfSet($trapConfig,'config','masterPass', $pass, ERROR);
115
+                $IP=$port=$user=$pass=null;
116
+                $this->getOptionIfSet($trapConfig, 'config', 'masterIP', $IP, ERROR);
117
+                $this->getOptionIfSet($trapConfig, 'config', 'masterPort', $port, ERROR);
118
+                $this->getOptionIfSet($trapConfig, 'config', 'masterUser', $user, ERROR);
119
+                $this->getOptionIfSet($trapConfig, 'config', 'masterPass', $pass, ERROR);
120 120
                 $this->getTrapApi()->setParams($IP, $port, $user, $pass);
121 121
                 return;
122 122
             }
123 123
         }
124 124
         
125 125
         // Snmptranslate binary path
126
-        $this->getOptionIfSet($trapConfig,'config','snmptranslate', $this->snmptranslate);
126
+        $this->getOptionIfSet($trapConfig, 'config', 'snmptranslate', $this->snmptranslate);
127 127
         
128 128
         // mibs path
129
-        $this->getOptionIfSet($trapConfig,'config','snmptranslate_dirs', $this->snmptranslate_dirs);
129
+        $this->getOptionIfSet($trapConfig, 'config', 'snmptranslate_dirs', $this->snmptranslate_dirs);
130 130
         
131 131
         // icinga2cmd path
132
-        $this->getOptionIfSet($trapConfig,'config','icingacmd', $this->icinga2cmd);
132
+        $this->getOptionIfSet($trapConfig, 'config', 'icingacmd', $this->icinga2cmd);
133 133
         
134 134
         // table prefix
135
-        $this->getOptionIfSet($trapConfig,'config','database_prefix', $this->dbPrefix);
135
+        $this->getOptionIfSet($trapConfig, 'config', 'database_prefix', $this->dbPrefix);
136 136
         
137 137
         // API options
138
-        if ($this->getOptionIfSet($trapConfig,'config','icingaAPI_host', $this->apiHostname))
138
+        if ($this->getOptionIfSet($trapConfig, 'config', 'icingaAPI_host', $this->apiHostname))
139 139
         {
140 140
             $this->apiUse=true;
141 141
             // Get API options or throw exception as not configured correctly
142
-            $this->getOptionIfSet($trapConfig,'config','icingaAPI_port', $this->apiPort,ERROR);
143
-            $this->getOptionIfSet($trapConfig,'config','icingaAPI_user', $this->apiUsername,ERROR);
144
-            $this->getOptionIfSet($trapConfig,'config','icingaAPI_password', $this->apiPassword,ERROR);
142
+            $this->getOptionIfSet($trapConfig, 'config', 'icingaAPI_port', $this->apiPort, ERROR);
143
+            $this->getOptionIfSet($trapConfig, 'config', 'icingaAPI_user', $this->apiUsername, ERROR);
144
+            $this->getOptionIfSet($trapConfig, 'config', 'icingaAPI_password', $this->apiPassword, ERROR);
145 145
         }
146 146
     }
147 147
     
@@ -152,43 +152,43 @@  discard block
 block discarded – undo
152 152
     protected function setupDatabase($trapConfig)
153 153
     {
154 154
         // Trap database
155
-        if (!array_key_exists('database',$trapConfig['config']))
155
+        if (!array_key_exists('database', $trapConfig['config']))
156 156
         {
157
-            $this->logging->log("No database in config file: ".$this->trapModuleConfig,ERROR,'');
157
+            $this->logging->log("No database in config file: ".$this->trapModuleConfig, ERROR, '');
158 158
             return;
159 159
         }
160 160
         $dbTrapName=$trapConfig['config']['database'];
161
-        $this->logging->log("Found database in config file: ".$dbTrapName,INFO );
161
+        $this->logging->log("Found database in config file: ".$dbTrapName, INFO);
162 162
         
163
-        if ( ($dbConfig=parse_ini_file($this->icingaweb2Ressources,true)) === false)
163
+        if (($dbConfig=parse_ini_file($this->icingaweb2Ressources, true)) === false)
164 164
         {
165
-            $this->logging->log("Error reading ini file : ".$this->icingaweb2Ressources,ERROR,'');
165
+            $this->logging->log("Error reading ini file : ".$this->icingaweb2Ressources, ERROR, '');
166 166
             return;
167 167
         }
168
-        if (!array_key_exists($dbTrapName,$dbConfig))
168
+        if (!array_key_exists($dbTrapName, $dbConfig))
169 169
         {
170
-            $this->logging->log("No database '.$dbTrapName.' in config file: ".$this->icingaweb2Ressources,ERROR,'');
170
+            $this->logging->log("No database '.$dbTrapName.' in config file: ".$this->icingaweb2Ressources, ERROR, '');
171 171
             return;
172 172
         }
173 173
         
174
-        $this->trapsDB = new Database($this->logging,$dbConfig[$dbTrapName],$this->dbPrefix);
174
+        $this->trapsDB=new Database($this->logging, $dbConfig[$dbTrapName], $this->dbPrefix);
175 175
         
176
-        $this->logging->log("API Use : ".print_r($this->apiUse,true),DEBUG );
176
+        $this->logging->log("API Use : ".print_r($this->apiUse, true), DEBUG);
177 177
         
178 178
         //TODO enable this again when API queries are all done :
179 179
         //if ($this->apiUse === true) return; // In case of API use, no IDO is necessary
180 180
         
181 181
         // IDO Database
182
-        if (!array_key_exists('IDOdatabase',$trapConfig['config']))
182
+        if (!array_key_exists('IDOdatabase', $trapConfig['config']))
183 183
         {
184
-            $this->logging->log("No IDOdatabase in config file: ".$this->trapModuleConfig,ERROR,'');
184
+            $this->logging->log("No IDOdatabase in config file: ".$this->trapModuleConfig, ERROR, '');
185 185
         }
186 186
         $dbIdoName=$trapConfig['config']['IDOdatabase'];
187 187
         
188
-        $this->logging->log("Found IDO database in config file: ".$dbIdoName,INFO );
189
-        if (!array_key_exists($dbIdoName,$dbConfig))
188
+        $this->logging->log("Found IDO database in config file: ".$dbIdoName, INFO);
189
+        if (!array_key_exists($dbIdoName, $dbConfig))
190 190
         {
191
-            $this->logging->log("No database '.$dbIdoName.' in config file: ".$this->icingaweb2Ressources,ERROR,'');
191
+            $this->logging->log("No database '.$dbIdoName.' in config file: ".$this->icingaweb2Ressources, ERROR, '');
192 192
             return;
193 193
         }
194 194
         
Please login to merge, or discard this patch.
library/Trapdirector/Config/TrapModuleConfig.php 2 patches
Indentation   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -4,16 +4,16 @@  discard block
 block discarded – undo
4 4
 
5 5
 class TrapModuleConfig
6 6
 {
7
-    /********** Database configuration ***********************/
7
+	/********** Database configuration ***********************/
8 8
 	// Database prefix for tables 
9
-    protected $table_prefix; //< Database prefix for tables 	
9
+	protected $table_prefix; //< Database prefix for tables 	
10 10
 	protected $DBConfigDefaults=array(
11 11
 		'db_remove_days' => 60, // number of days before removing traps
12 12
 		'log_destination' => 'syslog', // Log destination for trap handler
13 13
 		'log_file' => '/tmp/trapdirector.log', // Log file
14 14
 		'log_level' => 2, // log level
15 15
 		'use_SnmpTrapAddess' => 1, // use SnmpTrapAddress by default
16
-	    'SnmpTrapAddess_oid' => '.1.3.6.1.6.3.18.1.3', // default snmpTrapAdress OID
16
+		'SnmpTrapAddess_oid' => '.1.3.6.1.6.3.18.1.3', // default snmpTrapAdress OID
17 17
 	);
18 18
 	// get default values for dbconfig
19 19
 	public function getDBConfigDefaults() { return $this->DBConfigDefaults;}
@@ -120,27 +120,27 @@  discard block
 block discarded – undo
120 120
 	// Note : must have 'source_ip' and 'last_sent'
121 121
 	public function getTrapHostListDisplayColumns()
122 122
 	{
123
-	    return array(
124
-	        'source_name'  =>  't.source_name',
125
-	        'source_ip'    =>  't.source_ip',
126
-	        'trap_oid'     =>  't.trap_oid',
127
-	        'count'        =>  'count(*)',
128
-	        'last_sent'    =>  'UNIX_TIMESTAMP(max(t.date_received))'
129
-	    );
123
+		return array(
124
+			'source_name'  =>  't.source_name',
125
+			'source_ip'    =>  't.source_ip',
126
+			'trap_oid'     =>  't.trap_oid',
127
+			'count'        =>  'count(*)',
128
+			'last_sent'    =>  'UNIX_TIMESTAMP(max(t.date_received))'
129
+		);
130 130
 	}
131 131
 
132 132
 	public function getTrapHostListSearchColumns()
133 133
 	{
134
-	    return array(); // No search needed on this table
134
+		return array(); // No search needed on this table
135 135
 	}
136 136
 	// Titles display in Trap List table
137 137
 	public function getTrapHostListTitles()
138 138
 	{
139
-	    return array(
140
-	        'trap_oid'		=> 'Trap OID',
141
-	        'count'		    => 'Number of traps received',
142
-	        'last_sent'     => 'Last trap received'
143
-	    );
139
+		return array(
140
+			'trap_oid'		=> 'Trap OID',
141
+			'count'		    => 'Number of traps received',
142
+			'last_sent'     => 'Last trap received'
143
+		);
144 144
 	}
145 145
 	
146 146
 	
@@ -195,7 +195,7 @@  discard block
 block discarded – undo
195 195
 			'revert_ok'		=> 'r.revert_ok',
196 196
 			'display'		=> 'r.display',
197 197
 			'modified'		=> 'UNIX_TIMESTAMP(r.modified)',
198
-            'modifier'		=> 'r.modifier'
198
+			'modifier'		=> 'r.modifier'
199 199
 		);
200 200
 	}	
201 201
 		
Please login to merge, or discard this patch.
Spacing   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -16,27 +16,27 @@  discard block
 block discarded – undo
16 16
 	    'SnmpTrapAddess_oid' => '.1.3.6.1.6.3.18.1.3', // default snmpTrapAdress OID
17 17
 	);
18 18
 	// get default values for dbconfig
19
-	public function getDBConfigDefaults() { return $this->DBConfigDefaults;}
19
+	public function getDBConfigDefaults() { return $this->DBConfigDefaults; }
20 20
 	/** Minimum DB version
21 21
 	 * @return number
22 22
 	 */
23
-	static public function getDbMinVersion() { return 2;}	
23
+	static public function getDbMinVersion() { return 2; }	
24 24
 	/** Current DB version
25 25
 	 * @return number
26 26
 	 */
27
-	static public function getDbCurVersion() { return 2;}
27
+	static public function getDbCurVersion() { return 2; }
28 28
 
29 29
 	/************ Module configuration **********************/
30 30
 	// Module base path
31 31
 	static public function urlPath() { return 'trapdirector'; }
32
-	static public function getapiUserPermissions() { return array("status", "objects/query/Host", "objects/query/Service" , "actions/process-check-result"); } //< api user permissions required
32
+	static public function getapiUserPermissions() { return array("status", "objects/query/Host", "objects/query/Service", "actions/process-check-result"); } //< api user permissions required
33 33
 	
34 34
 	
35 35
 	/*********** Log configuration *************************/
36 36
 	protected $logLevels=array(0=>'No output', 1=>'critical', 2=>'warning', 3=>'trace', 4=>'ALL');
37
-	public function getlogLevels() { return $this->logLevels;}
38
-	protected $logDestinations=array('syslog'=>'syslog','file'=>'file','display'=>'display');
39
-	public function getLogDestinations() { return $this->logDestinations;}
37
+	public function getlogLevels() { return $this->logLevels; }
38
+	protected $logDestinations=array('syslog'=>'syslog', 'file'=>'file', 'display'=>'display');
39
+	public function getLogDestinations() { return $this->logDestinations; }
40 40
 	
41 41
 	function __construct($prefix)
42 42
 	{
@@ -47,29 +47,29 @@  discard block
 block discarded – undo
47 47
 	// DB table name of trap received list : prefix 't'
48 48
 	public function getTrapTableName() 
49 49
 	{ 
50
-		return array('t' => $this->table_prefix . 'received'); 
50
+		return array('t' => $this->table_prefix.'received'); 
51 51
 	}
52 52
 	// DB table name of trap data  list : prefix 'd'
53 53
 	public function getTrapDataTableName() 
54 54
 	{ 
55
-		return array('d' => $this->table_prefix . 'received_data'); 
55
+		return array('d' => $this->table_prefix.'received_data'); 
56 56
 	}	
57 57
 
58 58
 	// DB table name of rules : prefix 'r'
59 59
 	public function getTrapRuleName() 
60 60
 	{ 
61
-		return array('r' => $this->table_prefix . 'rules'); 
61
+		return array('r' => $this->table_prefix.'rules'); 
62 62
 	}		
63 63
 	
64 64
 	// DB table name of db config : prefix 'c'
65 65
 	public function getDbConfigTableName() 
66 66
 	{ 
67
-		return array('c' => $this->table_prefix . 'db_config');
67
+		return array('c' => $this->table_prefix.'db_config');
68 68
 	}
69 69
 	
70 70
 	// Mib cache tables
71
-	public function getMIBCacheTableName() { return $this->table_prefix . 'mib_cache'; }
72
-	public function getMIBCacheTableTrapObjName() { return $this->table_prefix . 'mib_cache_trap_object'; }
71
+	public function getMIBCacheTableName() { return $this->table_prefix.'mib_cache'; }
72
+	public function getMIBCacheTableTrapObjName() { return $this->table_prefix.'mib_cache_trap_object'; }
73 73
 	
74 74
 	
75 75
 	/****************** Database queries *******************/
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
 	public function getHandlerListDisplayColumns()
151 151
 	{
152 152
 		return array(
153
-			'host_name'		=> 'r.host_name',//'UNIX_TIMESTAMP(t.date_received)',
153
+			'host_name'		=> 'r.host_name', //'UNIX_TIMESTAMP(t.date_received)',
154 154
 			'host_group_name'=> 'r.host_group_name',
155 155
 			'source_ip'		=> "CASE WHEN r.ip4 IS NULL THEN r.ip6 ELSE r.ip4 END",
156 156
 			'trap_oid'		=> 'r.trap_oid',
@@ -203,32 +203,32 @@  discard block
 block discarded – undo
203 203
 	public function trapDetailQuery()
204 204
 	{
205 205
 		return array(
206
-			'timestamp'			=> array('Date','UNIX_TIMESTAMP(t.date_received)'),
207
-			'source_ip'			=> array('Source IP','t.source_ip'),
208
-			'source_name'		=> array('Source name','t.source_name'),
209
-			'source_port'		=> array('Source port','t.source_port'),
210
-			'destination_ip'	=> array('Destination IP','t.destination_ip'),
211
-			'destination_port'	=> array('Destination port','t.destination_port'),			
212
-			'trap_oid'			=> array('Numeric OID','t.trap_oid'),
213
-			'trap_name'			=> array('Trap name','t.trap_name'),
214
-			'trap_name_mib'		=> array('Trap MIB','t.trap_name_mib'),
215
-			'status'			=> array('Processing status','t.status'),
216
-			'status_detail'		=> array('Status details','t.status_detail'),
217
-			'process_time'		=> array('Trap processing time','t.process_time'),			
206
+			'timestamp'			=> array('Date', 'UNIX_TIMESTAMP(t.date_received)'),
207
+			'source_ip'			=> array('Source IP', 't.source_ip'),
208
+			'source_name'		=> array('Source name', 't.source_name'),
209
+			'source_port'		=> array('Source port', 't.source_port'),
210
+			'destination_ip'	=> array('Destination IP', 't.destination_ip'),
211
+			'destination_port'	=> array('Destination port', 't.destination_port'),			
212
+			'trap_oid'			=> array('Numeric OID', 't.trap_oid'),
213
+			'trap_name'			=> array('Trap name', 't.trap_name'),
214
+			'trap_name_mib'		=> array('Trap MIB', 't.trap_name_mib'),
215
+			'status'			=> array('Processing status', 't.status'),
216
+			'status_detail'		=> array('Status details', 't.status_detail'),
217
+			'process_time'		=> array('Trap processing time', 't.process_time'),			
218 218
 		);
219 219
 	}
220 220
 	// Trap detail : additional data (<key> => <title> <sql select>)
221 221
 	public function trapDataDetailQuery()
222 222
 	{
223 223
 		return array(
224
-			'oid'				=> array('Numeric OID','d.oid'),
225
-			'oid_name'			=> array('Text OID','d.oid_name'),
226
-			'oid_name_mib'		=> array('MIB','d.oid_name_mib'),
227
-			'value'				=> array('Value','d.value'),
224
+			'oid'				=> array('Numeric OID', 'd.oid'),
225
+			'oid_name'			=> array('Text OID', 'd.oid_name'),
226
+			'oid_name_mib'		=> array('MIB', 'd.oid_name_mib'),
227
+			'value'				=> array('Value', 'd.value'),
228 228
 		);
229 229
 	}
230 230
 	// foreign key of trap data table
231
-	public function trapDataFK() { return 'trap_id';}
231
+	public function trapDataFK() { return 'trap_id'; }
232 232
 	
233 233
 	// Max items in a list
234 234
 	public function itemListDisplay() { return 25; }
Please login to merge, or discard this patch.
application/controllers/StatusController.php 3 patches
Indentation   +93 added lines, -93 removed lines patch added patch discarded remove patch
@@ -21,8 +21,8 @@  discard block
 block discarded – undo
21 21
 		/************  Trapdb ***********/
22 22
 		try
23 23
 		{
24
-		    $dbConn = $this->getUIDatabase()->getDbConn();
25
-		    if ($dbConn === null) throw new \ErrorException('uncatched db error');
24
+			$dbConn = $this->getUIDatabase()->getDbConn();
25
+			if ($dbConn === null) throw new \ErrorException('uncatched db error');
26 26
 			$query = $dbConn->select()->from(
27 27
 				$this->getModuleConfig()->getTrapTableName(),
28 28
 				array('COUNT(*)')
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
 		
52 52
 		try
53 53
 		{		
54
-		    $this->view->currentLogDestination=$this->getUIDatabase()->getDBConfigValue('log_destination');
54
+			$this->view->currentLogDestination=$this->getUIDatabase()->getDBConfigValue('log_destination');
55 55
 			$this->view->logDestinations=$this->getModuleConfig()->getLogDestinations();
56 56
 			$this->view->currentLogFile=$this->getUIDatabase()->getDBConfigValue('log_file');
57 57
 			$this->view->logLevels=$this->getModuleConfig()->getlogLevels();
@@ -65,23 +65,23 @@  discard block
 block discarded – undo
65 65
 		/*************** SNMP configuration ****************/
66 66
 		try
67 67
 		{
68
-		    $this->view->useSnmpTrapAddess= ( $this->getUIDatabase()->getDBConfigValue('use_SnmpTrapAddess') == 1 ) ? TRUE : FALSE;
69
-		    $this->view->SnmpTrapAddressOID=$this->getUIDatabase()->getDBConfigValue('SnmpTrapAddess_oid');
70
-		    $this->view->SnmpTrapAddressOIDDefault = ($this->view->SnmpTrapAddressOID == $this->getModuleConfig()->getDBConfigDefaults()['SnmpTrapAddess_oid'] ) ? TRUE : FALSE;
68
+			$this->view->useSnmpTrapAddess= ( $this->getUIDatabase()->getDBConfigValue('use_SnmpTrapAddess') == 1 ) ? TRUE : FALSE;
69
+			$this->view->SnmpTrapAddressOID=$this->getUIDatabase()->getDBConfigValue('SnmpTrapAddess_oid');
70
+			$this->view->SnmpTrapAddressOIDDefault = ($this->view->SnmpTrapAddressOID == $this->getModuleConfig()->getDBConfigDefaults()['SnmpTrapAddess_oid'] ) ? TRUE : FALSE;
71 71
 		    
72 72
 		}
73 73
 		catch (Exception $e)
74 74
 		{
75
-		    $this->displayExitError('status',$e->getMessage());
75
+			$this->displayExitError('status',$e->getMessage());
76 76
 		}		
77 77
 		
78 78
 	} 
79 79
   
80 80
 	/** Mib management
81
-	*	Post param : action=update_mib_db : update mib database
82
-	*	Post param : ation=check_update : check if mib update is finished
83
-	*	File post : mibfile -> save mib file
84
-	*/
81
+	 *	Post param : action=update_mib_db : update mib database
82
+	 *	Post param : ation=check_update : check if mib update is finished
83
+	 *	File post : mibfile -> save mib file
84
+	 */
85 85
 	public function mibAction()
86 86
 	{
87 87
 		$this->prepareTabs()->activate('mib');
@@ -100,22 +100,22 @@  discard block
 block discarded – undo
100 100
 					$return=exec('icingacli trapdirector mib update --pid /tmp/trapdirector_update.pid');
101 101
 					if (preg_match('/OK/',$return))
102 102
 					{
103
-					    $this->_helper->json(array('status'=>'OK'));
103
+						$this->_helper->json(array('status'=>'OK'));
104 104
 					}
105 105
 					// Error
106 106
 					$this->_helper->json(array('status'=>$return));
107 107
 				}
108 108
 				if ($action == 'check_update')
109 109
 				{
110
-				    $file=@fopen('/tmp/trapdirector_update.pid','r');
111
-				    if ($file == false)
112
-				    {   // process is dead
113
-				        $this->_helper->json(array('status'=>'tu quoque fili','err'=>'Cannot open file'));
114
-				        return;
115
-				    }
116
-				    $pid=fgets($file);
117
-				    $output=array();
118
-				    $retVal=0;
110
+					$file=@fopen('/tmp/trapdirector_update.pid','r');
111
+					if ($file == false)
112
+					{   // process is dead
113
+						$this->_helper->json(array('status'=>'tu quoque fili','err'=>'Cannot open file'));
114
+						return;
115
+					}
116
+					$pid=fgets($file);
117
+					$output=array();
118
+					$retVal=0;
119 119
 					exec('ps '.$pid,$output,$retVal);
120 120
 					if ($retVal == 0)
121 121
 					{ // process is alive
@@ -123,7 +123,7 @@  discard block
 block discarded – undo
123 123
 					}
124 124
 					else
125 125
 					{ // process is dead
126
-					    $this->_helper->json(array('status'=>'tu quoque fili','err'=>'no proc'.$pid));
126
+						$this->_helper->json(array('status'=>'tu quoque fili','err'=>'no proc'.$pid));
127 127
 					}
128 128
 				}
129 129
 				$this->_helper->json(array('status'=>'ERR : no '.$action.' action possible' ));
@@ -131,32 +131,32 @@  discard block
 block discarded – undo
131 131
 			/** Check for mib file UPLOAD */
132 132
 			if (isset($_FILES['mibfile']))
133 133
 			{
134
-			    $name=filter_var($_FILES['mibfile']['name'],FILTER_SANITIZE_STRING);
134
+				$name=filter_var($_FILES['mibfile']['name'],FILTER_SANITIZE_STRING);
135 135
 				$DirConf=explode(':',$this->Config()->get('config', 'snmptranslate_dirs'));
136 136
 				$destDir=array_shift($DirConf);
137 137
 				if (!is_dir($destDir))
138 138
 				{
139
-				    $this->view->uploadStatus="ERROR : no $destDir directory, check module configuration";
139
+					$this->view->uploadStatus="ERROR : no $destDir directory, check module configuration";
140 140
 				}
141 141
 				else
142 142
 				{
143
-				    if (!is_writable($destDir))
144
-				    {
145
-				        $this->view->uploadStatus="ERROR : $destDir directory is not writable";
146
-				    }
147
-				    else
148
-				    {
149
-				        $destination = $destDir .'/'.$name; //$this->Module()->getBaseDir() . "/mibs/$name";
150
-				        $sourceTmpNam=filter_var($_FILES['mibfile']['tmp_name'],FILTER_SANITIZE_STRING);
151
-				        if (move_uploaded_file($sourceTmpNam,$destination)===false)
152
-    				    {
153
-    				        $this->view->uploadStatus="ERROR, file $destination not loaded. Check file and path name or selinux violations";
154
-    				    }
155
-    				    else
156
-    				    {
157
-    				        $this->view->uploadStatus="File $name uploaded in $destDir";
158
-    				    }
159
-				    }
143
+					if (!is_writable($destDir))
144
+					{
145
+						$this->view->uploadStatus="ERROR : $destDir directory is not writable";
146
+					}
147
+					else
148
+					{
149
+						$destination = $destDir .'/'.$name; //$this->Module()->getBaseDir() . "/mibs/$name";
150
+						$sourceTmpNam=filter_var($_FILES['mibfile']['tmp_name'],FILTER_SANITIZE_STRING);
151
+						if (move_uploaded_file($sourceTmpNam,$destination)===false)
152
+						{
153
+							$this->view->uploadStatus="ERROR, file $destination not loaded. Check file and path name or selinux violations";
154
+						}
155
+						else
156
+						{
157
+							$this->view->uploadStatus="File $name uploaded in $destDir";
158
+						}
159
+					}
160 160
 				}
161 161
 
162 162
 			}
@@ -276,47 +276,47 @@  discard block
 block discarded – undo
276 276
 	 */
277 277
 	public function pluginsAction()
278 278
 	{
279
-	    $this->prepareTabs()->activate('plugins');
279
+		$this->prepareTabs()->activate('plugins');
280 280
 	    
281
-	    require_once($this->Module()->getBaseDir() .'/bin/trap_class.php');
282
-	    $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc');
283
-	    $Trap = new Trap($icingaweb2_etc,4);
281
+		require_once($this->Module()->getBaseDir() .'/bin/trap_class.php');
282
+		$icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc');
283
+		$Trap = new Trap($icingaweb2_etc,4);
284 284
 	    
285
-	    $this->view->pluginLoaded = htmlentities($Trap->pluginClass->registerAllPlugins(false));
285
+		$this->view->pluginLoaded = htmlentities($Trap->pluginClass->registerAllPlugins(false));
286 286
 	    
287
-	    $enabledPlugins = $Trap->pluginClass->getEnabledPlugins();
287
+		$enabledPlugins = $Trap->pluginClass->getEnabledPlugins();
288 288
 
289
-	    $pluginList = $Trap->pluginClass->pluginList();
289
+		$pluginList = $Trap->pluginClass->pluginList();
290 290
 	    
291
-	    // Plugin list and fill function name list
292
-	    $functionList=array();
293
-	    $this->view->pluginArray=array();
294
-	    foreach ($pluginList as $plugin)
295
-	    {
296
-	        $pluginDetails=$Trap->pluginClass->pluginDetails($plugin);
297
-	        $pluginDetails->enabled =  (in_array($plugin, $enabledPlugins)) ? true : false;
298
-	        $pluginDetails->catchAllTraps = ($pluginDetails->catchAllTraps === true )? 'Yes' : 'No';
299
-	        $pluginDetails->processTraps = ($pluginDetails->processTraps === true )? 'Yes' : 'No';
300
-	        $pluginDetails->description = htmlentities($pluginDetails->description);
301
-	        $pluginDetails->description = preg_replace('/\n/','<br>',$pluginDetails->description);
302
-	        array_push($this->view->pluginArray, $pluginDetails);
303
-	        // Get functions for function details
304
-	        foreach ($pluginDetails->funcArray as $function)
305
-	        {
306
-	            array_push($functionList,$function);
307
-	        }
308
-	    }
291
+		// Plugin list and fill function name list
292
+		$functionList=array();
293
+		$this->view->pluginArray=array();
294
+		foreach ($pluginList as $plugin)
295
+		{
296
+			$pluginDetails=$Trap->pluginClass->pluginDetails($plugin);
297
+			$pluginDetails->enabled =  (in_array($plugin, $enabledPlugins)) ? true : false;
298
+			$pluginDetails->catchAllTraps = ($pluginDetails->catchAllTraps === true )? 'Yes' : 'No';
299
+			$pluginDetails->processTraps = ($pluginDetails->processTraps === true )? 'Yes' : 'No';
300
+			$pluginDetails->description = htmlentities($pluginDetails->description);
301
+			$pluginDetails->description = preg_replace('/\n/','<br>',$pluginDetails->description);
302
+			array_push($this->view->pluginArray, $pluginDetails);
303
+			// Get functions for function details
304
+			foreach ($pluginDetails->funcArray as $function)
305
+			{
306
+				array_push($functionList,$function);
307
+			}
308
+		}
309 309
 	    
310
-	    // Function list with details
311
-	    $this->view->functionList=array();
312
-	    foreach ($functionList as $function)
313
-	    {
314
-	        $functionDetail = $Trap->pluginClass->getFunctionDetails($function);
315
-	        $functionDetail->params = htmlentities($functionDetail->params);
316
-	        $functionDetail->description = htmlentities($functionDetail->description);
317
-	        $functionDetail->description = preg_replace('/\n/','<br>',$functionDetail->description);
318
-	        array_push($this->view->functionList, $functionDetail);
319
-	    }
310
+		// Function list with details
311
+		$this->view->functionList=array();
312
+		foreach ($functionList as $function)
313
+		{
314
+			$functionDetail = $Trap->pluginClass->getFunctionDetails($function);
315
+			$functionDetail->params = htmlentities($functionDetail->params);
316
+			$functionDetail->description = htmlentities($functionDetail->description);
317
+			$functionDetail->description = preg_replace('/\n/','<br>',$functionDetail->description);
318
+			array_push($this->view->functionList, $functionDetail);
319
+		}
320 320
 
321 321
 	}
322 322
 	
@@ -331,30 +331,30 @@  discard block
 block discarded – undo
331 331
 		)->add('services', array(
332 332
 			'label' => $this->translate('Services management'),
333 333
 			'url'   => $this->getModuleConfig()->urlPath() . '/status/services')
334
-	    )->add('plugins', array(
335
-	        'label' => $this->translate('Plugins management'),
336
-	        'url'   => $this->getModuleConfig()->urlPath() . '/status/plugins')
337
-	    );
334
+		)->add('plugins', array(
335
+			'label' => $this->translate('Plugins management'),
336
+			'url'   => $this->getModuleConfig()->urlPath() . '/status/plugins')
337
+		);
338 338
 	} 
339 339
 }
340 340
 
341 341
 // TODO : see if useless 
342 342
 class UploadForm extends Form
343 343
 { 
344
-    public function __construct($options = null) 
345
-    {
346
-        parent::__construct($options);
347
-        $this->addElements2();
348
-    }
344
+	public function __construct($options = null) 
345
+	{
346
+		parent::__construct($options);
347
+		$this->addElements2();
348
+	}
349 349
 
350
-    public function addElements2()
351
-    {
352
-        // File Input
353
-        $file = new File('mib-file');
354
-        $file->setLabel('Mib upload');
355
-             //->setAttrib('multiple', null);
356
-        $this->addElement($file);
350
+	public function addElements2()
351
+	{
352
+		// File Input
353
+		$file = new File('mib-file');
354
+		$file->setLabel('Mib upload');
355
+			 //->setAttrib('multiple', null);
356
+		$this->addElement($file);
357 357
 		$button = new Submit("upload",array('ignore'=>false));
358 358
 		$this->addElement($button);//->setIgnore(false);
359
-    }
359
+	}
360 360
 }
Please login to merge, or discard this patch.
Spacing   +66 added lines, -66 removed lines patch added patch discarded remove patch
@@ -21,19 +21,19 @@  discard block
 block discarded – undo
21 21
 		/************  Trapdb ***********/
22 22
 		try
23 23
 		{
24
-		    $dbConn = $this->getUIDatabase()->getDbConn();
24
+		    $dbConn=$this->getUIDatabase()->getDbConn();
25 25
 		    if ($dbConn === null) throw new \ErrorException('uncatched db error');
26
-			$query = $dbConn->select()->from(
26
+			$query=$dbConn->select()->from(
27 27
 				$this->getModuleConfig()->getTrapTableName(),
28 28
 				array('COUNT(*)')
29 29
 			);			
30 30
 			$this->view->trap_count=$dbConn->fetchOne($query);
31
-			$query = $dbConn->select()->from(
31
+			$query=$dbConn->select()->from(
32 32
 				$this->getModuleConfig()->getTrapDataTableName(),
33 33
 				array('COUNT(*)')
34 34
 			);			
35 35
 			$this->view->trap_object_count=$dbConn->fetchOne($query);
36
-			$query = $dbConn->select()->from(
36
+			$query=$dbConn->select()->from(
37 37
 				$this->getModuleConfig()->getTrapRuleName(),
38 38
 				array('COUNT(*)')
39 39
 			);			
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
 		}
45 45
 		catch (Exception $e)
46 46
 		{
47
-			$this->displayExitError('status',$e->getMessage());
47
+			$this->displayExitError('status', $e->getMessage());
48 48
 		}
49 49
 		
50 50
 		/*************** Log destination *******************/
@@ -59,20 +59,20 @@  discard block
 block discarded – undo
59 59
 		}
60 60
 		catch (Exception $e)
61 61
 		{
62
-			$this->displayExitError('status',$e->getMessage());
62
+			$this->displayExitError('status', $e->getMessage());
63 63
 		}
64 64
 		
65 65
 		/*************** SNMP configuration ****************/
66 66
 		try
67 67
 		{
68
-		    $this->view->useSnmpTrapAddess= ( $this->getUIDatabase()->getDBConfigValue('use_SnmpTrapAddess') == 1 ) ? TRUE : FALSE;
68
+		    $this->view->useSnmpTrapAddess=($this->getUIDatabase()->getDBConfigValue('use_SnmpTrapAddess') == 1) ? TRUE : FALSE;
69 69
 		    $this->view->SnmpTrapAddressOID=$this->getUIDatabase()->getDBConfigValue('SnmpTrapAddess_oid');
70
-		    $this->view->SnmpTrapAddressOIDDefault = ($this->view->SnmpTrapAddressOID == $this->getModuleConfig()->getDBConfigDefaults()['SnmpTrapAddess_oid'] ) ? TRUE : FALSE;
70
+		    $this->view->SnmpTrapAddressOIDDefault=($this->view->SnmpTrapAddressOID == $this->getModuleConfig()->getDBConfigDefaults()['SnmpTrapAddess_oid']) ? TRUE : FALSE;
71 71
 		    
72 72
 		}
73 73
 		catch (Exception $e)
74 74
 		{
75
-		    $this->displayExitError('status',$e->getMessage());
75
+		    $this->displayExitError('status', $e->getMessage());
76 76
 		}		
77 77
 		
78 78
 	} 
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
 				if ($action == 'update_mib_db')
99 99
 				{ // Do the update in background
100 100
 					$return=exec('icingacli trapdirector mib update --pid /tmp/trapdirector_update.pid');
101
-					if (preg_match('/OK/',$return))
101
+					if (preg_match('/OK/', $return))
102 102
 					{
103 103
 					    $this->_helper->json(array('status'=>'OK'));
104 104
 					}
@@ -107,32 +107,32 @@  discard block
 block discarded – undo
107 107
 				}
108 108
 				if ($action == 'check_update')
109 109
 				{
110
-				    $file=@fopen('/tmp/trapdirector_update.pid','r');
110
+				    $file=@fopen('/tmp/trapdirector_update.pid', 'r');
111 111
 				    if ($file == false)
112 112
 				    {   // process is dead
113
-				        $this->_helper->json(array('status'=>'tu quoque fili','err'=>'Cannot open file'));
113
+				        $this->_helper->json(array('status'=>'tu quoque fili', 'err'=>'Cannot open file'));
114 114
 				        return;
115 115
 				    }
116 116
 				    $pid=fgets($file);
117 117
 				    $output=array();
118 118
 				    $retVal=0;
119
-					exec('ps '.$pid,$output,$retVal);
119
+					exec('ps '.$pid, $output, $retVal);
120 120
 					if ($retVal == 0)
121 121
 					{ // process is alive
122 122
 						$this->_helper->json(array('status'=>'Alive and kicking'));
123 123
 					}
124 124
 					else
125 125
 					{ // process is dead
126
-					    $this->_helper->json(array('status'=>'tu quoque fili','err'=>'no proc'.$pid));
126
+					    $this->_helper->json(array('status'=>'tu quoque fili', 'err'=>'no proc'.$pid));
127 127
 					}
128 128
 				}
129
-				$this->_helper->json(array('status'=>'ERR : no '.$action.' action possible' ));
129
+				$this->_helper->json(array('status'=>'ERR : no '.$action.' action possible'));
130 130
 			}
131 131
 			/** Check for mib file UPLOAD */
132 132
 			if (isset($_FILES['mibfile']))
133 133
 			{
134
-			    $name=filter_var($_FILES['mibfile']['name'],FILTER_SANITIZE_STRING);
135
-				$DirConf=explode(':',$this->Config()->get('config', 'snmptranslate_dirs'));
134
+			    $name=filter_var($_FILES['mibfile']['name'], FILTER_SANITIZE_STRING);
135
+				$DirConf=explode(':', $this->Config()->get('config', 'snmptranslate_dirs'));
136 136
 				$destDir=array_shift($DirConf);
137 137
 				if (!is_dir($destDir))
138 138
 				{
@@ -146,9 +146,9 @@  discard block
 block discarded – undo
146 146
 				    }
147 147
 				    else
148 148
 				    {
149
-				        $destination = $destDir .'/'.$name; //$this->Module()->getBaseDir() . "/mibs/$name";
150
-				        $sourceTmpNam=filter_var($_FILES['mibfile']['tmp_name'],FILTER_SANITIZE_STRING);
151
-				        if (move_uploaded_file($sourceTmpNam,$destination)===false)
149
+				        $destination=$destDir.'/'.$name; //$this->Module()->getBaseDir() . "/mibs/$name";
150
+				        $sourceTmpNam=filter_var($_FILES['mibfile']['tmp_name'], FILTER_SANITIZE_STRING);
151
+				        if (move_uploaded_file($sourceTmpNam, $destination) === false)
152 152
     				    {
153 153
     				        $this->view->uploadStatus="ERROR, file $destination not loaded. Check file and path name or selinux violations";
154 154
     				    }
@@ -164,13 +164,13 @@  discard block
 block discarded – undo
164 164
 		}
165 165
 		
166 166
 		// snmptranslate tests
167
-		$snmptranslate = $this->Config()->get('config', 'snmptranslate');
167
+		$snmptranslate=$this->Config()->get('config', 'snmptranslate');
168 168
 		$this->view->snmptranslate_bin=$snmptranslate;
169 169
 		$this->view->snmptranslate_state='warn';
170
-		if (is_executable ( $snmptranslate ))
170
+		if (is_executable($snmptranslate))
171 171
 		{
172
-			$translate=exec($snmptranslate . ' 1');
173
-			if (preg_match('/iso/',$translate))
172
+			$translate=exec($snmptranslate.' 1');
173
+			if (preg_match('/iso/', $translate))
174 174
 			{
175 175
 				$this->view->snmptranslate='works fine';
176 176
 				$this->view->snmptranslate_state='ok';
@@ -188,46 +188,46 @@  discard block
 block discarded – undo
188 188
 		// mib database
189 189
 		
190 190
 		$this->view->mibDbCount=$this->getMIB()->countObjects();
191
-		$this->view->mibDbCountTrap=$this->getMIB()->countObjects(null,21);
191
+		$this->view->mibDbCountTrap=$this->getMIB()->countObjects(null, 21);
192 192
 		
193 193
 		// mib dirs
194 194
 		$DirConf=$this->Config()->get('config', 'snmptranslate_dirs');
195
-		$dirArray=explode(':',$DirConf);
195
+		$dirArray=explode(':', $DirConf);
196 196
 
197 197
 		// Get base directories from net-snmp-config
198 198
 		$output=$matches=array();
199 199
 		$retVal=0;
200
-		$sysDirs=exec('net-snmp-config --default-mibdirs',$output,$retVal);
201
-		if ($retVal==0)
200
+		$sysDirs=exec('net-snmp-config --default-mibdirs', $output, $retVal);
201
+		if ($retVal == 0)
202 202
 		{
203
-			$dirArray=array_merge($dirArray,explode(':',$sysDirs));
203
+			$dirArray=array_merge($dirArray, explode(':', $sysDirs));
204 204
 		}
205 205
 		else
206 206
 		{
207
-			$translateOut=exec($this->Config()->get('config', 'snmptranslate') . ' -Dinit_mib .1.3 2>&1 | grep MIBDIRS');
208
-			if (preg_match('/MIBDIRS.*\'([^\']+)\'/',$translateOut,$matches))
207
+			$translateOut=exec($this->Config()->get('config', 'snmptranslate').' -Dinit_mib .1.3 2>&1 | grep MIBDIRS');
208
+			if (preg_match('/MIBDIRS.*\'([^\']+)\'/', $translateOut, $matches))
209 209
 			{
210
-				$dirArray=array_merge($dirArray,explode(':',$matches[1]));
210
+				$dirArray=array_merge($dirArray, explode(':', $matches[1]));
211 211
 			}
212 212
 			else
213 213
 			{
214
-				array_push($dirArray,'Install net-snmp-config to see system directories');
214
+				array_push($dirArray, 'Install net-snmp-config to see system directories');
215 215
 			}
216 216
 		}
217 217
 		
218 218
 		$this->view->dirArray=$dirArray;
219 219
 		
220 220
 		$output=null;
221
-		foreach (explode(':',$DirConf) as $mibdir)
221
+		foreach (explode(':', $DirConf) as $mibdir)
222 222
 		{
223
-			exec('ls '.$mibdir.' | grep -v traplist.txt',$output);
223
+			exec('ls '.$mibdir.' | grep -v traplist.txt', $output);
224 224
 		}
225 225
 		//$i=0;$listFiles='';while (isset($output[$i])) $listFiles.=$output[$i++];
226 226
 		//$this->view->fileList=explode(' ',$listFiles);
227 227
 		$this->view->fileList=$output;
228 228
 		
229 229
 		// Zend form 
230
-		$this->view->form= new UploadForm();
230
+		$this->view->form=new UploadForm();
231 231
 		//$this->view->form= new Form('upload-form');
232 232
 		
233 233
 		
@@ -251,18 +251,18 @@  discard block
 block discarded – undo
251 251
 		$this->view->templateForm_output='';
252 252
 		if (isset($postData['template_name']) && isset($postData['template_revert_time']))
253 253
 		{
254
-			$template_create = 'icingacli director service create --json \'{ "check_command": "dummy", ';
255
-			$template_create .= '"check_interval": "' .$postData['template_revert_time']. '", "check_timeout": "20", "disabled": false, "enable_active_checks": true, "enable_event_handler": true, "enable_notifications": true, "enable_passive_checks": true, "enable_perfdata": true, "max_check_attempts": "1", ';
256
-			$template_create .= '"object_name": "'.$postData['template_name'].'", "object_type": "template", "retry_interval": "'.$postData['template_revert_time'].'"}\'';
254
+			$template_create='icingacli director service create --json \'{ "check_command": "dummy", ';
255
+			$template_create.='"check_interval": "'.$postData['template_revert_time'].'", "check_timeout": "20", "disabled": false, "enable_active_checks": true, "enable_event_handler": true, "enable_notifications": true, "enable_passive_checks": true, "enable_perfdata": true, "max_check_attempts": "1", ';
256
+			$template_create.='"object_name": "'.$postData['template_name'].'", "object_type": "template", "retry_interval": "'.$postData['template_revert_time'].'"}\'';
257 257
 			$output=array();
258 258
 			$ret_code=0;
259
-			exec($template_create,$output,$ret_code);
259
+			exec($template_create, $output, $ret_code);
260 260
 			if ($ret_code != 0)
261 261
 			{
262
-				$this->displayExitError("Status -> Services","Error creating template : ".$output[0].'<br>Command was : '.$template_create);
262
+				$this->displayExitError("Status -> Services", "Error creating template : ".$output[0].'<br>Command was : '.$template_create);
263 263
 			}
264
-			exec('icingacli director config deploy',$output,$ret_code);
265
-			$this->view->templateForm_output='Template '.$postData['template_name']. ' created';
264
+			exec('icingacli director config deploy', $output, $ret_code);
265
+			$this->view->templateForm_output='Template '.$postData['template_name'].' created';
266 266
 		}
267 267
 		
268 268
 		// template creation form
@@ -278,15 +278,15 @@  discard block
 block discarded – undo
278 278
 	{
279 279
 	    $this->prepareTabs()->activate('plugins');
280 280
 	    
281
-	    require_once($this->Module()->getBaseDir() .'/bin/trap_class.php');
281
+	    require_once($this->Module()->getBaseDir().'/bin/trap_class.php');
282 282
 	    $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc');
283
-	    $Trap = new Trap($icingaweb2_etc,4);
283
+	    $Trap=new Trap($icingaweb2_etc, 4);
284 284
 	    
285
-	    $this->view->pluginLoaded = htmlentities($Trap->pluginClass->registerAllPlugins(false));
285
+	    $this->view->pluginLoaded=htmlentities($Trap->pluginClass->registerAllPlugins(false));
286 286
 	    
287
-	    $enabledPlugins = $Trap->pluginClass->getEnabledPlugins();
287
+	    $enabledPlugins=$Trap->pluginClass->getEnabledPlugins();
288 288
 
289
-	    $pluginList = $Trap->pluginClass->pluginList();
289
+	    $pluginList=$Trap->pluginClass->pluginList();
290 290
 	    
291 291
 	    // Plugin list and fill function name list
292 292
 	    $functionList=array();
@@ -294,16 +294,16 @@  discard block
 block discarded – undo
294 294
 	    foreach ($pluginList as $plugin)
295 295
 	    {
296 296
 	        $pluginDetails=$Trap->pluginClass->pluginDetails($plugin);
297
-	        $pluginDetails->enabled =  (in_array($plugin, $enabledPlugins)) ? true : false;
298
-	        $pluginDetails->catchAllTraps = ($pluginDetails->catchAllTraps === true )? 'Yes' : 'No';
299
-	        $pluginDetails->processTraps = ($pluginDetails->processTraps === true )? 'Yes' : 'No';
300
-	        $pluginDetails->description = htmlentities($pluginDetails->description);
301
-	        $pluginDetails->description = preg_replace('/\n/','<br>',$pluginDetails->description);
297
+	        $pluginDetails->enabled=(in_array($plugin, $enabledPlugins)) ? true : false;
298
+	        $pluginDetails->catchAllTraps=($pluginDetails->catchAllTraps === true) ? 'Yes' : 'No';
299
+	        $pluginDetails->processTraps=($pluginDetails->processTraps === true) ? 'Yes' : 'No';
300
+	        $pluginDetails->description=htmlentities($pluginDetails->description);
301
+	        $pluginDetails->description=preg_replace('/\n/', '<br>', $pluginDetails->description);
302 302
 	        array_push($this->view->pluginArray, $pluginDetails);
303 303
 	        // Get functions for function details
304 304
 	        foreach ($pluginDetails->funcArray as $function)
305 305
 	        {
306
-	            array_push($functionList,$function);
306
+	            array_push($functionList, $function);
307 307
 	        }
308 308
 	    }
309 309
 	    
@@ -311,10 +311,10 @@  discard block
 block discarded – undo
311 311
 	    $this->view->functionList=array();
312 312
 	    foreach ($functionList as $function)
313 313
 	    {
314
-	        $functionDetail = $Trap->pluginClass->getFunctionDetails($function);
315
-	        $functionDetail->params = htmlentities($functionDetail->params);
316
-	        $functionDetail->description = htmlentities($functionDetail->description);
317
-	        $functionDetail->description = preg_replace('/\n/','<br>',$functionDetail->description);
314
+	        $functionDetail=$Trap->pluginClass->getFunctionDetails($function);
315
+	        $functionDetail->params=htmlentities($functionDetail->params);
316
+	        $functionDetail->description=htmlentities($functionDetail->description);
317
+	        $functionDetail->description=preg_replace('/\n/', '<br>', $functionDetail->description);
318 318
 	        array_push($this->view->functionList, $functionDetail);
319 319
 	    }
320 320
 
@@ -324,16 +324,16 @@  discard block
 block discarded – undo
324 324
 	{
325 325
 		return $this->getTabs()->add('status', array(
326 326
 			'label' => $this->translate('Status'),
327
-			'url'   => $this->getModuleConfig()->urlPath() . '/status')
327
+			'url'   => $this->getModuleConfig()->urlPath().'/status')
328 328
 		)->add('mib', array(
329 329
 			'label' => $this->translate('MIB Management'),
330
-			'url'   => $this->getModuleConfig()->urlPath() . '/status/mib')
330
+			'url'   => $this->getModuleConfig()->urlPath().'/status/mib')
331 331
 		)->add('services', array(
332 332
 			'label' => $this->translate('Services management'),
333
-			'url'   => $this->getModuleConfig()->urlPath() . '/status/services')
333
+			'url'   => $this->getModuleConfig()->urlPath().'/status/services')
334 334
 	    )->add('plugins', array(
335 335
 	        'label' => $this->translate('Plugins management'),
336
-	        'url'   => $this->getModuleConfig()->urlPath() . '/status/plugins')
336
+	        'url'   => $this->getModuleConfig()->urlPath().'/status/plugins')
337 337
 	    );
338 338
 	} 
339 339
 }
@@ -341,7 +341,7 @@  discard block
 block discarded – undo
341 341
 // TODO : see if useless 
342 342
 class UploadForm extends Form
343 343
 { 
344
-    public function __construct($options = null) 
344
+    public function __construct($options=null) 
345 345
     {
346 346
         parent::__construct($options);
347 347
         $this->addElements2();
@@ -350,11 +350,11 @@  discard block
 block discarded – undo
350 350
     public function addElements2()
351 351
     {
352 352
         // File Input
353
-        $file = new File('mib-file');
353
+        $file=new File('mib-file');
354 354
         $file->setLabel('Mib upload');
355 355
              //->setAttrib('multiple', null);
356 356
         $this->addElement($file);
357
-		$button = new Submit("upload",array('ignore'=>false));
358
-		$this->addElement($button);//->setIgnore(false);
357
+		$button=new Submit("upload", array('ignore'=>false));
358
+		$this->addElement($button); //->setIgnore(false);
359 359
     }
360 360
 }
Please login to merge, or discard this patch.
Braces   +14 added lines, -23 removed lines patch added patch discarded remove patch
@@ -22,7 +22,9 @@  discard block
 block discarded – undo
22 22
 		try
23 23
 		{
24 24
 		    $dbConn = $this->getUIDatabase()->getDbConn();
25
-		    if ($dbConn === null) throw new \ErrorException('uncatched db error');
25
+		    if ($dbConn === null) {
26
+		    	throw new \ErrorException('uncatched db error');
27
+		    }
26 28
 			$query = $dbConn->select()->from(
27 29
 				$this->getModuleConfig()->getTrapTableName(),
28 30
 				array('COUNT(*)')
@@ -41,8 +43,7 @@  discard block
 block discarded – undo
41 43
  			
42 44
 			$this->view->trap_days_delete=$this->getUIDatabase()->getDBConfigValue('db_remove_days');
43 45
 			
44
-		}
45
-		catch (Exception $e)
46
+		} catch (Exception $e)
46 47
 		{
47 48
 			$this->displayExitError('status',$e->getMessage());
48 49
 		}
@@ -56,8 +57,7 @@  discard block
 block discarded – undo
56 57
 			$this->view->currentLogFile=$this->getUIDatabase()->getDBConfigValue('log_file');
57 58
 			$this->view->logLevels=$this->getModuleConfig()->getlogLevels();
58 59
 			$this->view->currentLogLevel=$this->getUIDatabase()->getDBConfigValue('log_level');
59
-		}
60
-		catch (Exception $e)
60
+		} catch (Exception $e)
61 61
 		{
62 62
 			$this->displayExitError('status',$e->getMessage());
63 63
 		}
@@ -69,8 +69,7 @@  discard block
 block discarded – undo
69 69
 		    $this->view->SnmpTrapAddressOID=$this->getUIDatabase()->getDBConfigValue('SnmpTrapAddess_oid');
70 70
 		    $this->view->SnmpTrapAddressOIDDefault = ($this->view->SnmpTrapAddressOID == $this->getModuleConfig()->getDBConfigDefaults()['SnmpTrapAddess_oid'] ) ? TRUE : FALSE;
71 71
 		    
72
-		}
73
-		catch (Exception $e)
72
+		} catch (Exception $e)
74 73
 		{
75 74
 		    $this->displayExitError('status',$e->getMessage());
76 75
 		}		
@@ -120,8 +119,7 @@  discard block
 block discarded – undo
120 119
 					if ($retVal == 0)
121 120
 					{ // process is alive
122 121
 						$this->_helper->json(array('status'=>'Alive and kicking'));
123
-					}
124
-					else
122
+					} else
125 123
 					{ // process is dead
126 124
 					    $this->_helper->json(array('status'=>'tu quoque fili','err'=>'no proc'.$pid));
127 125
 					}
@@ -137,22 +135,19 @@  discard block
 block discarded – undo
137 135
 				if (!is_dir($destDir))
138 136
 				{
139 137
 				    $this->view->uploadStatus="ERROR : no $destDir directory, check module configuration";
140
-				}
141
-				else
138
+				} else
142 139
 				{
143 140
 				    if (!is_writable($destDir))
144 141
 				    {
145 142
 				        $this->view->uploadStatus="ERROR : $destDir directory is not writable";
146
-				    }
147
-				    else
143
+				    } else
148 144
 				    {
149 145
 				        $destination = $destDir .'/'.$name; //$this->Module()->getBaseDir() . "/mibs/$name";
150 146
 				        $sourceTmpNam=filter_var($_FILES['mibfile']['tmp_name'],FILTER_SANITIZE_STRING);
151 147
 				        if (move_uploaded_file($sourceTmpNam,$destination)===false)
152 148
     				    {
153 149
     				        $this->view->uploadStatus="ERROR, file $destination not loaded. Check file and path name or selinux violations";
154
-    				    }
155
-    				    else
150
+    				    } else
156 151
     				    {
157 152
     				        $this->view->uploadStatus="File $name uploaded in $destDir";
158 153
     				    }
@@ -174,13 +169,11 @@  discard block
 block discarded – undo
174 169
 			{
175 170
 				$this->view->snmptranslate='works fine';
176 171
 				$this->view->snmptranslate_state='ok';
177
-			}
178
-			else
172
+			} else
179 173
 			{
180 174
 				$this->view->snmptranslate='can execute but no resolution';
181 175
 			}
182
-		}
183
-		else
176
+		} else
184 177
 		{
185 178
 			$this->view->snmptranslate='cannot execute';
186 179
 		}
@@ -201,15 +194,13 @@  discard block
 block discarded – undo
201 194
 		if ($retVal==0)
202 195
 		{
203 196
 			$dirArray=array_merge($dirArray,explode(':',$sysDirs));
204
-		}
205
-		else
197
+		} else
206 198
 		{
207 199
 			$translateOut=exec($this->Config()->get('config', 'snmptranslate') . ' -Dinit_mib .1.3 2>&1 | grep MIBDIRS');
208 200
 			if (preg_match('/MIBDIRS.*\'([^\']+)\'/',$translateOut,$matches))
209 201
 			{
210 202
 				$dirArray=array_merge($dirArray,explode(':',$matches[1]));
211
-			}
212
-			else
203
+			} else
213 204
 			{
214 205
 				array_push($dirArray,'Install net-snmp-config to see system directories');
215 206
 			}
Please login to merge, or discard this patch.
application/controllers/HelperController.php 3 patches
Indentation   +143 added lines, -143 removed lines patch added patch discarded remove patch
@@ -12,8 +12,8 @@  discard block
 block discarded – undo
12 12
 {
13 13
 	
14 14
 	/** Get host list with filter (IP or name) : host=<filter>
15
-	*	returns in JSON : status=>OK/NOK  hosts=>array of hosts
16
-	*/
15
+	 *	returns in JSON : status=>OK/NOK  hosts=>array of hosts
16
+	 */
17 17
 	public function gethostsAction()
18 18
 	{
19 19
 		$postData=$this->getRequest()->getPost();
@@ -32,8 +32,8 @@  discard block
 block discarded – undo
32 32
 	}
33 33
 	
34 34
 	/** Get hostgroup list with filter (name) : hostgroup=<hostFilter>
35
-	*	returns in JSON : status=>OK/NOK  hosts=>array of hosts
36
-	*/
35
+	 *	returns in JSON : status=>OK/NOK  hosts=>array of hosts
36
+	 */
37 37
 	public function gethostgroupsAction()
38 38
 	{
39 39
 		$postData=$this->getRequest()->getPost();
@@ -52,11 +52,11 @@  discard block
 block discarded – undo
52 52
 	}
53 53
 	
54 54
 	/** Get service list by host name ( host=<host> )
55
-	*	returns in JSON : 
56
-	*		status=>OK/No services found/More than one host matches
57
-	*		services=>array of services (name)
58
-	*		hostid = host object id or -1 if not found.
59
-	*/
55
+	 *	returns in JSON : 
56
+	 *		status=>OK/No services found/More than one host matches
57
+	 *		services=>array of services (name)
58
+	 *		hostid = host object id or -1 if not found.
59
+	 */
60 60
 	public function getservicesAction()
61 61
 	{
62 62
 		$postData=$this->getRequest()->getPost();
@@ -98,11 +98,11 @@  discard block
 block discarded – undo
98 98
 	}
99 99
 	
100 100
 	/** Get service list by host group ( name=<host> )
101
-	*	returns in JSON : 
102
-	*		status=>OK/No services found/More than one host matches
103
-	*		services=>array of services (name)
104
-	*		groupid = group object id or -1 if not found.
105
-	*/
101
+	 *	returns in JSON : 
102
+	 *		status=>OK/No services found/More than one host matches
103
+	 *		services=>array of services (name)
104
+	 *		groupid = group object id or -1 if not found.
105
+	 */
106 106
 	public function gethostgroupservicesAction()
107 107
 	{
108 108
 		$postData=$this->getRequest()->getPost();
@@ -132,10 +132,10 @@  discard block
 block discarded – undo
132 132
 	}
133 133
 
134 134
 	/** Get traps from mib  : entry : mib=<mib>
135
-	*	returns in JSON : 
136
-	*		status=>OK/No mib/Error getting mibs
137
-	*		traps=>array of array( oid -> name)
138
-	*/
135
+	 *	returns in JSON : 
136
+	 *		status=>OK/No mib/Error getting mibs
137
+	 *		traps=>array of array( oid -> name)
138
+	 */
139 139
 	public function gettrapsAction()
140 140
 	{
141 141
 		$postData=$this->getRequest()->getPost();
@@ -155,10 +155,10 @@  discard block
 block discarded – undo
155 155
 	}	
156 156
 
157 157
 	/** Get trap objects from mib  : entry : trap=<oid>
158
-	*	returns in JSON : 
159
-	*		status=>OK/no trap/not found
160
-	*		objects=>array of array( oid -> name, oid->mib)
161
-	*/
158
+	 *	returns in JSON : 
159
+	 *		status=>OK/no trap/not found
160
+	 *		objects=>array of array( oid -> name, oid->mib)
161
+	 */
162 162
 	public function gettrapobjectsAction()
163 163
 	{
164 164
 		$postData=$this->getRequest()->getPost();
@@ -178,8 +178,8 @@  discard block
 block discarded – undo
178 178
 	}	
179 179
 	
180 180
 	/** Get list of all loaded mibs : entry : none
181
-	*	return : array of strings.
182
-	*/
181
+	 *	return : array of strings.
182
+	 */
183 183
 	public function getmiblistAction()
184 184
 	{
185 185
 		try
@@ -194,10 +194,10 @@  discard block
 block discarded – undo
194 194
 	}
195 195
 	
196 196
 	/** Get MIB::Name from OID : entry : oid
197
-	*		status=>OK/No oid/not found
198
-	*		mib=>string
199
-	*		name=>string
200
-	*/	
197
+	 *		status=>OK/No oid/not found
198
+	 *		mib=>string
199
+	 *		name=>string
200
+	 */	
201 201
 	public function translateoidAction()
202 202
 	{
203 203
 		$postData=$this->getRequest()->getPost();
@@ -218,7 +218,7 @@  discard block
 block discarded – undo
218 218
 					'name' => $object['name'],
219 219
 					'type' => $object['type'],
220 220
 					'type_enum' => $object['type_enum'],
221
-				    'description' => $object['description']
221
+					'description' => $object['description']
222 222
 				)
223 223
 			);
224 224
 		}
@@ -226,10 +226,10 @@  discard block
 block discarded – undo
226 226
 	}
227 227
 	
228 228
 	/** Save or execute database purge of <n> days
229
-	*	days=>int 
230
-	*	action=>save/execute
231
-	*	return : status=>OK/Message error
232
-	*/
229
+	 *	days=>int 
230
+	 *	action=>save/execute
231
+	 *	return : status=>OK/Message error
232
+	 */
233 233
 	public function dbmaintenanceAction()
234 234
 	{
235 235
 		
@@ -244,7 +244,7 @@  discard block
 block discarded – undo
244 244
 		{
245 245
 			try
246 246
 			{
247
-			    $this->getUIDatabase()->setDBConfigValue('db_remove_days',$days);
247
+				$this->getUIDatabase()->setDBConfigValue('db_remove_days',$days);
248 248
 			}
249 249
 			catch (Exception $e)
250 250
 			{
@@ -282,33 +282,33 @@  discard block
 block discarded – undo
282 282
 	 */
283 283
 	public function snmpconfigAction()
284 284
 	{
285
-	    $postData=$this->getRequest()->getPost();
285
+		$postData=$this->getRequest()->getPost();
286 286
 	    
287
-	    $snmpUse = $this->checkPostVar($postData, 'useTrapAddr', '0|1');
287
+		$snmpUse = $this->checkPostVar($postData, 'useTrapAddr', '0|1');
288 288
 	    
289
-	    $snmpOID = $this->checkPostVar($postData, 'trapAddrOID', '^[\.0-9]+$');
289
+		$snmpOID = $this->checkPostVar($postData, 'trapAddrOID', '^[\.0-9]+$');
290 290
 	    	    
291
-	    try
292
-	    {
293
-	        $this->getUIDatabase()->setDBConfigValue('use_SnmpTrapAddess',$snmpUse);
294
-	        $this->getUIDatabase()->setDBConfigValue('SnmpTrapAddess_oid',$snmpOID);
295
-	    }
296
-	    catch (Exception $e)
297
-	    {
298
-	        $this->_helper->json(array('status'=>'Save error : '.$e->getMessage() ));
299
-	        return;
300
-	    }
301
-	    $this->_helper->json(array('status'=>'OK'));
302
-	    return;
291
+		try
292
+		{
293
+			$this->getUIDatabase()->setDBConfigValue('use_SnmpTrapAddess',$snmpUse);
294
+			$this->getUIDatabase()->setDBConfigValue('SnmpTrapAddess_oid',$snmpOID);
295
+		}
296
+		catch (Exception $e)
297
+		{
298
+			$this->_helper->json(array('status'=>'Save error : '.$e->getMessage() ));
299
+			return;
300
+		}
301
+		$this->_helper->json(array('status'=>'OK'));
302
+		return;
303 303
 	    
304 304
 	}
305 305
 	
306 306
 	/** Save log output to db
307
-	*	destination=>log destination 
308
-	*	file=>file name
309
-	*	level => int 
310
-	*	return : status=>OK/Message error
311
-	*/
307
+	 *	destination=>log destination 
308
+	 *	file=>file name
309
+	 *	level => int 
310
+	 *	return : status=>OK/Message error
311
+	 */
312 312
 	public function logdestinationAction()
313 313
 	{
314 314
 		$postData=$this->getRequest()->getPost();
@@ -327,8 +327,8 @@  discard block
 block discarded – undo
327 327
 			$fileHandler=@fopen($file,'w');
328 328
 			if ($fileHandler == false)
329 329
 			{   // File os note writabe / cannot create
330
-			    $this->_helper->json(array('status'=>'File not writable :  '.$file));
331
-			    return;
330
+				$this->_helper->json(array('status'=>'File not writable :  '.$file));
331
+				return;
332 332
 			}
333 333
 		}
334 334
 		else
@@ -348,9 +348,9 @@  discard block
 block discarded – undo
348 348
 				
349 349
 		try
350 350
 		{
351
-		    $this->getUIDatabase()->setDBConfigValue('log_destination',$destination);
352
-		    $this->getUIDatabase()->setDBConfigValue('log_file',$file);
353
-		    $this->getUIDatabase()->setDBConfigValue('log_level',$level);
351
+			$this->getUIDatabase()->setDBConfigValue('log_destination',$destination);
352
+			$this->getUIDatabase()->setDBConfigValue('log_file',$file);
353
+			$this->getUIDatabase()->setDBConfigValue('log_level',$level);
354 354
 		}
355 355
 		catch (Exception $e)
356 356
 		{
@@ -370,33 +370,33 @@  discard block
 block discarded – undo
370 370
 	public function testruleAction()
371 371
 	{
372 372
 	    
373
-	    $postData=$this->getRequest()->getPost();
373
+		$postData=$this->getRequest()->getPost();
374 374
 	   
375
-	    $rule = $this->checkPostVar($postData, 'rule', '.*');
375
+		$rule = $this->checkPostVar($postData, 'rule', '.*');
376 376
 
377
-	    $action = $this->checkPostVar($postData, 'action', 'evaluate');
377
+		$action = $this->checkPostVar($postData, 'action', 'evaluate');
378 378
 
379
-	    if ($action == 'evaluate')
380
-	    {
381
-	        try
382
-	        {
383
-	            require_once($this->Module()->getBaseDir() .'/bin/trap_class.php');
384
-	            $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc');
385
-	            $trap = new Trap($icingaweb2_etc);
386
-	            // Cleanup spaces before eval
387
-	            $rule=$trap->ruleClass->eval_cleanup($rule);
388
-	            // Eval
389
-	            $item=0;
390
-	            $rule=$trap->ruleClass->evaluation($rule,$item);
391
-	        }
392
-	        catch (Exception $e)
393
-	        {
394
-	            $this->_helper->json(array('status'=>'Evaluation error : '.$e->getMessage() ));
395
-	            return;
396
-	        }
397
-	        $return=($rule==true)?'true':'false';
398
-	        $this->_helper->json(array('status'=>'OK', 'message' => $return));
399
-	    }
379
+		if ($action == 'evaluate')
380
+		{
381
+			try
382
+			{
383
+				require_once($this->Module()->getBaseDir() .'/bin/trap_class.php');
384
+				$icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc');
385
+				$trap = new Trap($icingaweb2_etc);
386
+				// Cleanup spaces before eval
387
+				$rule=$trap->ruleClass->eval_cleanup($rule);
388
+				// Eval
389
+				$item=0;
390
+				$rule=$trap->ruleClass->evaluation($rule,$item);
391
+			}
392
+			catch (Exception $e)
393
+			{
394
+				$this->_helper->json(array('status'=>'Evaluation error : '.$e->getMessage() ));
395
+				return;
396
+			}
397
+			$return=($rule==true)?'true':'false';
398
+			$this->_helper->json(array('status'=>'OK', 'message' => $return));
399
+		}
400 400
 	    
401 401
 	}	
402 402
 
@@ -407,35 +407,35 @@  discard block
 block discarded – undo
407 407
 	 */
408 408
 	public function pluginAction()
409 409
 	{
410
-	    $postData=$this->getRequest()->getPost();
410
+		$postData=$this->getRequest()->getPost();
411 411
 	    
412
-	    $pluginName = $this->checkPostVar($postData, 'name', '.*');
412
+		$pluginName = $this->checkPostVar($postData, 'name', '.*');
413 413
 	    
414
-	    $action = $this->checkPostVar($postData, 'action', 'enable|disable');
414
+		$action = $this->checkPostVar($postData, 'action', 'enable|disable');
415 415
 	    
416
-        try
417
-        {
418
-            require_once($this->Module()->getBaseDir() .'/bin/trap_class.php');
419
-            $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc');
420
-            $trap = new Trap($icingaweb2_etc);
421
-            // Enable plugin.
422
-            $action=($action == 'enable') ? true : false;
423
-            $retVal=$trap->pluginClass->enablePlugin($pluginName, $action);
416
+		try
417
+		{
418
+			require_once($this->Module()->getBaseDir() .'/bin/trap_class.php');
419
+			$icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc');
420
+			$trap = new Trap($icingaweb2_etc);
421
+			// Enable plugin.
422
+			$action=($action == 'enable') ? true : false;
423
+			$retVal=$trap->pluginClass->enablePlugin($pluginName, $action);
424 424
             
425
-        }
426
-        catch (Exception $e)
427
-        {
428
-            $this->_helper->json(array('status'=>'Action error : '.$e->getMessage() ));
429
-            return;
430
-        }
431
-        if ($retVal === true)
432
-        {
433
-            $this->_helper->json(array('status'=>'OK'));
434
-        }
435
-        else
436
-        {
437
-            $this->_helper->json(array('status'=>'Error, see logs'));
438
-        }
425
+		}
426
+		catch (Exception $e)
427
+		{
428
+			$this->_helper->json(array('status'=>'Action error : '.$e->getMessage() ));
429
+			return;
430
+		}
431
+		if ($retVal === true)
432
+		{
433
+			$this->_helper->json(array('status'=>'OK'));
434
+		}
435
+		else
436
+		{
437
+			$this->_helper->json(array('status'=>'Error, see logs'));
438
+		}
439 439
 	}
440 440
 	
441 441
 	/** Function evaluation
@@ -445,49 +445,49 @@  discard block
 block discarded – undo
445 445
 	 */
446 446
 	public function functionAction()
447 447
 	{
448
-	    $postData=$this->getRequest()->getPost();
448
+		$postData=$this->getRequest()->getPost();
449 449
 	    
450
-	    $functionString = $this->checkPostVar($postData, 'function', '.*');
450
+		$functionString = $this->checkPostVar($postData, 'function', '.*');
451 451
 	    
452
-	    $this->checkPostVar($postData, 'action', 'evaluate');
452
+		$this->checkPostVar($postData, 'action', 'evaluate');
453 453
 	    
454
-	    // Only one action possible for now, no tests on action.
455
-	    try
456
-	    {
457
-	        require_once($this->Module()->getBaseDir() .'/bin/trap_class.php');
458
-	        $icingaweb2Etc=$this->Config()->get('config', 'icingaweb2_etc');
459
-	        $trap = new Trap($icingaweb2Etc);
460
-	        // load all plugins in case tested function is not enabled.
461
-	        $trap->pluginClass->registerAllPlugins(false);
462
-	        // Clean all spaces
463
-	        $functionString = $trap->ruleClass->eval_cleanup($functionString);
464
-	        // Eval functions
465
-	        $result = $trap->pluginClass->evaluateFunctionString($functionString);	        
466
-	    }
467
-	    catch (Exception $e)
468
-	    {
469
-	        $this->_helper->json(array('status'=>'Action error : '.$e->getMessage() ));
470
-	        return;
471
-	    }
454
+		// Only one action possible for now, no tests on action.
455
+		try
456
+		{
457
+			require_once($this->Module()->getBaseDir() .'/bin/trap_class.php');
458
+			$icingaweb2Etc=$this->Config()->get('config', 'icingaweb2_etc');
459
+			$trap = new Trap($icingaweb2Etc);
460
+			// load all plugins in case tested function is not enabled.
461
+			$trap->pluginClass->registerAllPlugins(false);
462
+			// Clean all spaces
463
+			$functionString = $trap->ruleClass->eval_cleanup($functionString);
464
+			// Eval functions
465
+			$result = $trap->pluginClass->evaluateFunctionString($functionString);	        
466
+		}
467
+		catch (Exception $e)
468
+		{
469
+			$this->_helper->json(array('status'=>'Action error : '.$e->getMessage() ));
470
+			return;
471
+		}
472 472
 	    
473
-        $result = ($result === true)?'True':'False';
474
-        $this->_helper->json(array('status'=>'OK','message' => $result));
473
+		$result = ($result === true)?'True':'False';
474
+		$this->_helper->json(array('status'=>'OK','message' => $result));
475 475
 	}
476 476
 
477
-    /**************   Utilities **********************/
477
+	/**************   Utilities **********************/
478 478
 
479 479
 	private function checkPostVar(array $postData,string $postVar, string $validRegexp) : string
480 480
 	{
481
-	    if (!isset ($postData[$postVar]))
482
-	    {
483
-	        $this->_helper->json(array('status'=>'No ' . $postVar));
484
-	        return '';
485
-	    }
486
-	    if (preg_match('/'.$validRegexp.'/', $postData[$postVar]) != 1)
487
-	    {
488
-	        $this->_helper->json(array('status'=>'Unknown ' . $postVar . ' value '.$postData[$postVar]));
489
-	        return '';
490
-	    }
491
-	    return $postData[$postVar];
481
+		if (!isset ($postData[$postVar]))
482
+		{
483
+			$this->_helper->json(array('status'=>'No ' . $postVar));
484
+			return '';
485
+		}
486
+		if (preg_match('/'.$validRegexp.'/', $postData[$postVar]) != 1)
487
+		{
488
+			$this->_helper->json(array('status'=>'Unknown ' . $postVar . ' value '.$postData[$postVar]));
489
+			return '';
490
+		}
491
+		return $postData[$postVar];
492 492
 	}
493 493
 }
Please login to merge, or discard this patch.
Spacing   +65 added lines, -65 removed lines patch added patch discarded remove patch
@@ -18,14 +18,14 @@  discard block
 block discarded – undo
18 18
 	{
19 19
 		$postData=$this->getRequest()->getPost();
20 20
 		
21
-		$hostFilter = $this->checkPostVar($postData, 'hostFilter', '.*');
21
+		$hostFilter=$this->checkPostVar($postData, 'hostFilter', '.*');
22 22
 		
23
-		$retHosts=array('status'=>'OK','hosts' => array());
23
+		$retHosts=array('status'=>'OK', 'hosts' => array());
24 24
 
25 25
 		$hosts=$this->getUIDatabase()->getHostByIP($hostFilter);
26 26
 		foreach ($hosts as $val)
27 27
 		{
28
-			array_push($retHosts['hosts'],$val->name);
28
+			array_push($retHosts['hosts'], $val->name);
29 29
 		}
30 30
 		
31 31
 		$this->_helper->json($retHosts);
@@ -38,14 +38,14 @@  discard block
 block discarded – undo
38 38
 	{
39 39
 		$postData=$this->getRequest()->getPost();
40 40
 		
41
-		$hostFilter = $this->checkPostVar($postData, 'hostFilter', '.*');
41
+		$hostFilter=$this->checkPostVar($postData, 'hostFilter', '.*');
42 42
 		
43
-		$retHosts=array('status'=>'OK','hosts' => array());
43
+		$retHosts=array('status'=>'OK', 'hosts' => array());
44 44
 
45 45
 		$hosts=$this->getUIDatabase()->getHostGroupByName($hostFilter);
46 46
 		foreach ($hosts as $val)
47 47
 		{
48
-			array_push($retHosts['hosts'],$val->name);
48
+			array_push($retHosts['hosts'], $val->name);
49 49
 		}
50 50
 		
51 51
 		$this->_helper->json($retHosts);
@@ -68,31 +68,31 @@  discard block
 block discarded – undo
68 68
 		}
69 69
 		else
70 70
 		{
71
-			$this->_helper->json(array('status'=>'No Hosts','hostid' => -1));
71
+			$this->_helper->json(array('status'=>'No Hosts', 'hostid' => -1));
72 72
 			return;
73 73
 		}
74 74
 		
75 75
 		$hostArray=$this->getUIDatabase()->getHostByName($host);
76 76
 		if (count($hostArray) > 1)
77 77
 		{	
78
-			$this->_helper->json(array('status'=>'More than one host matches','hostid' => -1));
78
+			$this->_helper->json(array('status'=>'More than one host matches', 'hostid' => -1));
79 79
 			return;
80 80
 		}
81 81
 		else if (count($hostArray) == 0)
82 82
 		{
83
-			$this->_helper->json(array('status'=>'No host matches','hostid' => -1));
83
+			$this->_helper->json(array('status'=>'No host matches', 'hostid' => -1));
84 84
 			return;
85 85
 		}
86 86
 		$services=$this->getUIDatabase()->getServicesByHostid($hostArray[0]->id);
87 87
 		if (count($services) < 1)
88 88
 		{
89
-			$this->_helper->json(array('status'=>'No services found for host','hostid' => $hostArray[0]->id));
89
+			$this->_helper->json(array('status'=>'No services found for host', 'hostid' => $hostArray[0]->id));
90 90
 			return;
91 91
 		}
92
-		$retServices=array('status'=>'OK','services' => array(),'hostid' => $hostArray[0]->id);
92
+		$retServices=array('status'=>'OK', 'services' => array(), 'hostid' => $hostArray[0]->id);
93 93
 		foreach ($services as $val)
94 94
 		{
95
-			array_push($retServices['services'],array($val->id , $val->name));
95
+			array_push($retServices['services'], array($val->id, $val->name));
96 96
 		}
97 97
 		$this->_helper->json($retServices);
98 98
 	}
@@ -107,26 +107,26 @@  discard block
 block discarded – undo
107 107
 	{
108 108
 		$postData=$this->getRequest()->getPost();
109 109
 		
110
-		$host = $this->checkPostVar($postData, 'host', '.+');
110
+		$host=$this->checkPostVar($postData, 'host', '.+');
111 111
 		
112 112
 		$hostArray=$this->getUIDatabase()->getHostGroupByName($host);
113 113
 		if (count($hostArray) > 1)
114 114
 		{	
115
-			$this->_helper->json(array('status'=>'More than one hostgroup matches','hostid' => -1));
115
+			$this->_helper->json(array('status'=>'More than one hostgroup matches', 'hostid' => -1));
116 116
 			return;
117 117
 		}
118 118
 		else if (count($hostArray) == 0)
119 119
 		{
120
-			$this->_helper->json(array('status'=>'No hostgroup matches','hostid' => -1));
120
+			$this->_helper->json(array('status'=>'No hostgroup matches', 'hostid' => -1));
121 121
 			return;
122 122
 		}
123 123
 		$services=$this->getUIDatabase()->getServicesByHostGroupid($hostArray[0]->id);
124 124
 		if (count($services) < 1)
125 125
 		{
126
-			$this->_helper->json(array('status'=>'No services found for hostgroup','hostid' => $hostArray[0]->id));
126
+			$this->_helper->json(array('status'=>'No services found for hostgroup', 'hostid' => $hostArray[0]->id));
127 127
 			return;
128 128
 		}
129
-		$retServices=array('status'=>'OK','services' => $services,'hostid' => $hostArray[0]->id);
129
+		$retServices=array('status'=>'OK', 'services' => $services, 'hostid' => $hostArray[0]->id);
130 130
 		
131 131
 		$this->_helper->json($retServices);
132 132
 	}
@@ -140,12 +140,12 @@  discard block
 block discarded – undo
140 140
 	{
141 141
 		$postData=$this->getRequest()->getPost();
142 142
 		
143
-		$mib = $this->checkPostVar($postData, 'mib', '.*');
143
+		$mib=$this->checkPostVar($postData, 'mib', '.*');
144 144
 
145 145
 		try
146 146
 		{
147 147
 			$traplist=$this->getMIB()->getTrapList($mib);
148
-			$retTraps=array('status'=>'OK','traps' => $traplist);
148
+			$retTraps=array('status'=>'OK', 'traps' => $traplist);
149 149
 		} 
150 150
 		catch (Exception $e) 
151 151
 		{ 
@@ -163,12 +163,12 @@  discard block
 block discarded – undo
163 163
 	{
164 164
 		$postData=$this->getRequest()->getPost();
165 165
 		
166
-		$trap = $this->checkPostVar($postData, 'trap', '.*');
166
+		$trap=$this->checkPostVar($postData, 'trap', '.*');
167 167
 		
168 168
 		try
169 169
 		{
170 170
 			$objectlist=$this->getMIB()->getObjectList($trap);
171
-			$retObjects=array('status'=>'OK','objects' => $objectlist);
171
+			$retObjects=array('status'=>'OK', 'objects' => $objectlist);
172 172
 		} 
173 173
 		catch (Exception $e) 
174 174
 		{ 
@@ -202,7 +202,7 @@  discard block
 block discarded – undo
202 202
 	{
203 203
 		$postData=$this->getRequest()->getPost();
204 204
 		
205
-		$oid = $this->checkPostVar($postData, 'oid', '.*');
205
+		$oid=$this->checkPostVar($postData, 'oid', '.*');
206 206
 		
207 207
 		// Try to get oid name from snmptranslate
208 208
 		if (($object=$this->getMIB()->translateOID($oid)) == null)
@@ -235,20 +235,20 @@  discard block
 block discarded – undo
235 235
 		
236 236
 		$postData=$this->getRequest()->getPost();
237 237
 		
238
-		$days = $this->checkPostVar($postData, 'days', '^[0-9]+$');
238
+		$days=$this->checkPostVar($postData, 'days', '^[0-9]+$');
239 239
 		$days=intval($days);
240 240
 
241
-		$action = $this->checkPostVar($postData, 'action', 'save|execute');
241
+		$action=$this->checkPostVar($postData, 'action', 'save|execute');
242 242
 		
243 243
 		if ($action == 'save')
244 244
 		{
245 245
 			try
246 246
 			{
247
-			    $this->getUIDatabase()->setDBConfigValue('db_remove_days',$days);
247
+			    $this->getUIDatabase()->setDBConfigValue('db_remove_days', $days);
248 248
 			}
249 249
 			catch (Exception $e)
250 250
 			{
251
-				$this->_helper->json(array('status'=>'Save error : '.$e->getMessage() ));
251
+				$this->_helper->json(array('status'=>'Save error : '.$e->getMessage()));
252 252
 				return;
253 253
 			}
254 254
 			$this->_helper->json(array('status'=>'OK'));
@@ -258,16 +258,16 @@  discard block
 block discarded – undo
258 258
 		{
259 259
 			try
260 260
 			{
261
-				require_once($this->Module()->getBaseDir() .'/bin/trap_class.php');
261
+				require_once($this->Module()->getBaseDir().'/bin/trap_class.php');
262 262
 				$icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc');
263 263
 				$debug_level=4;
264
-				$trap = new Trap($icingaweb2_etc);
265
-				$trap->setLogging($debug_level,'syslog');
264
+				$trap=new Trap($icingaweb2_etc);
265
+				$trap->setLogging($debug_level, 'syslog');
266 266
 				$trap->eraseOldTraps($days);
267 267
 			}
268 268
 			catch (Exception $e)
269 269
 			{
270
-				$this->_helper->json(array('status'=>'execute error : '.$e->getMessage() ));
270
+				$this->_helper->json(array('status'=>'execute error : '.$e->getMessage()));
271 271
 				return;
272 272
 			}			
273 273
 			$this->_helper->json(array('status'=>'OK'));
@@ -284,18 +284,18 @@  discard block
 block discarded – undo
284 284
 	{
285 285
 	    $postData=$this->getRequest()->getPost();
286 286
 	    
287
-	    $snmpUse = $this->checkPostVar($postData, 'useTrapAddr', '0|1');
287
+	    $snmpUse=$this->checkPostVar($postData, 'useTrapAddr', '0|1');
288 288
 	    
289
-	    $snmpOID = $this->checkPostVar($postData, 'trapAddrOID', '^[\.0-9]+$');
289
+	    $snmpOID=$this->checkPostVar($postData, 'trapAddrOID', '^[\.0-9]+$');
290 290
 	    	    
291 291
 	    try
292 292
 	    {
293
-	        $this->getUIDatabase()->setDBConfigValue('use_SnmpTrapAddess',$snmpUse);
294
-	        $this->getUIDatabase()->setDBConfigValue('SnmpTrapAddess_oid',$snmpOID);
293
+	        $this->getUIDatabase()->setDBConfigValue('use_SnmpTrapAddess', $snmpUse);
294
+	        $this->getUIDatabase()->setDBConfigValue('SnmpTrapAddess_oid', $snmpOID);
295 295
 	    }
296 296
 	    catch (Exception $e)
297 297
 	    {
298
-	        $this->_helper->json(array('status'=>'Save error : '.$e->getMessage() ));
298
+	        $this->_helper->json(array('status'=>'Save error : '.$e->getMessage()));
299 299
 	        return;
300 300
 	    }
301 301
 	    $this->_helper->json(array('status'=>'OK'));
@@ -313,7 +313,7 @@  discard block
 block discarded – undo
313 313
 	{
314 314
 		$postData=$this->getRequest()->getPost();
315 315
 		
316
-		$destination = $this->checkPostVar($postData, 'destination', '.*');
316
+		$destination=$this->checkPostVar($postData, 'destination', '.*');
317 317
 		$logDest=$this->getModuleConfig()->getLogDestinations();
318 318
 		if (!isset($logDest[$destination]))
319 319
 		{
@@ -324,7 +324,7 @@  discard block
 block discarded – undo
324 324
 		if (isset($postData['file']))
325 325
 		{ 
326 326
 			$file=$postData['file'];
327
-			$fileHandler=@fopen($file,'w');
327
+			$fileHandler=@fopen($file, 'w');
328 328
 			if ($fileHandler == false)
329 329
 			{   // File os note writabe / cannot create
330 330
 			    $this->_helper->json(array('status'=>'File not writable :  '.$file));
@@ -344,17 +344,17 @@  discard block
 block discarded – undo
344 344
 			}
345 345
 		}
346 346
 
347
-		$level = $this->checkPostVar($postData, 'level', '[0-9]');
347
+		$level=$this->checkPostVar($postData, 'level', '[0-9]');
348 348
 				
349 349
 		try
350 350
 		{
351
-		    $this->getUIDatabase()->setDBConfigValue('log_destination',$destination);
352
-		    $this->getUIDatabase()->setDBConfigValue('log_file',$file);
353
-		    $this->getUIDatabase()->setDBConfigValue('log_level',$level);
351
+		    $this->getUIDatabase()->setDBConfigValue('log_destination', $destination);
352
+		    $this->getUIDatabase()->setDBConfigValue('log_file', $file);
353
+		    $this->getUIDatabase()->setDBConfigValue('log_level', $level);
354 354
 		}
355 355
 		catch (Exception $e)
356 356
 		{
357
-			$this->_helper->json(array('status'=>'Save error : '.$e->getMessage() ));
357
+			$this->_helper->json(array('status'=>'Save error : '.$e->getMessage()));
358 358
 			return;
359 359
 		}
360 360
 		$this->_helper->json(array('status'=>'OK'));
@@ -372,29 +372,29 @@  discard block
 block discarded – undo
372 372
 	    
373 373
 	    $postData=$this->getRequest()->getPost();
374 374
 	   
375
-	    $rule = $this->checkPostVar($postData, 'rule', '.*');
375
+	    $rule=$this->checkPostVar($postData, 'rule', '.*');
376 376
 
377
-	    $action = $this->checkPostVar($postData, 'action', 'evaluate');
377
+	    $action=$this->checkPostVar($postData, 'action', 'evaluate');
378 378
 
379 379
 	    if ($action == 'evaluate')
380 380
 	    {
381 381
 	        try
382 382
 	        {
383
-	            require_once($this->Module()->getBaseDir() .'/bin/trap_class.php');
383
+	            require_once($this->Module()->getBaseDir().'/bin/trap_class.php');
384 384
 	            $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc');
385
-	            $trap = new Trap($icingaweb2_etc);
385
+	            $trap=new Trap($icingaweb2_etc);
386 386
 	            // Cleanup spaces before eval
387 387
 	            $rule=$trap->ruleClass->eval_cleanup($rule);
388 388
 	            // Eval
389 389
 	            $item=0;
390
-	            $rule=$trap->ruleClass->evaluation($rule,$item);
390
+	            $rule=$trap->ruleClass->evaluation($rule, $item);
391 391
 	        }
392 392
 	        catch (Exception $e)
393 393
 	        {
394
-	            $this->_helper->json(array('status'=>'Evaluation error : '.$e->getMessage() ));
394
+	            $this->_helper->json(array('status'=>'Evaluation error : '.$e->getMessage()));
395 395
 	            return;
396 396
 	        }
397
-	        $return=($rule==true)?'true':'false';
397
+	        $return=($rule == true) ? 'true' : 'false';
398 398
 	        $this->_helper->json(array('status'=>'OK', 'message' => $return));
399 399
 	    }
400 400
 	    
@@ -409,15 +409,15 @@  discard block
 block discarded – undo
409 409
 	{
410 410
 	    $postData=$this->getRequest()->getPost();
411 411
 	    
412
-	    $pluginName = $this->checkPostVar($postData, 'name', '.*');
412
+	    $pluginName=$this->checkPostVar($postData, 'name', '.*');
413 413
 	    
414
-	    $action = $this->checkPostVar($postData, 'action', 'enable|disable');
414
+	    $action=$this->checkPostVar($postData, 'action', 'enable|disable');
415 415
 	    
416 416
         try
417 417
         {
418
-            require_once($this->Module()->getBaseDir() .'/bin/trap_class.php');
418
+            require_once($this->Module()->getBaseDir().'/bin/trap_class.php');
419 419
             $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc');
420
-            $trap = new Trap($icingaweb2_etc);
420
+            $trap=new Trap($icingaweb2_etc);
421 421
             // Enable plugin.
422 422
             $action=($action == 'enable') ? true : false;
423 423
             $retVal=$trap->pluginClass->enablePlugin($pluginName, $action);
@@ -425,7 +425,7 @@  discard block
 block discarded – undo
425 425
         }
426 426
         catch (Exception $e)
427 427
         {
428
-            $this->_helper->json(array('status'=>'Action error : '.$e->getMessage() ));
428
+            $this->_helper->json(array('status'=>'Action error : '.$e->getMessage()));
429 429
             return;
430 430
         }
431 431
         if ($retVal === true)
@@ -447,45 +447,45 @@  discard block
 block discarded – undo
447 447
 	{
448 448
 	    $postData=$this->getRequest()->getPost();
449 449
 	    
450
-	    $functionString = $this->checkPostVar($postData, 'function', '.*');
450
+	    $functionString=$this->checkPostVar($postData, 'function', '.*');
451 451
 	    
452 452
 	    $this->checkPostVar($postData, 'action', 'evaluate');
453 453
 	    
454 454
 	    // Only one action possible for now, no tests on action.
455 455
 	    try
456 456
 	    {
457
-	        require_once($this->Module()->getBaseDir() .'/bin/trap_class.php');
457
+	        require_once($this->Module()->getBaseDir().'/bin/trap_class.php');
458 458
 	        $icingaweb2Etc=$this->Config()->get('config', 'icingaweb2_etc');
459
-	        $trap = new Trap($icingaweb2Etc);
459
+	        $trap=new Trap($icingaweb2Etc);
460 460
 	        // load all plugins in case tested function is not enabled.
461 461
 	        $trap->pluginClass->registerAllPlugins(false);
462 462
 	        // Clean all spaces
463
-	        $functionString = $trap->ruleClass->eval_cleanup($functionString);
463
+	        $functionString=$trap->ruleClass->eval_cleanup($functionString);
464 464
 	        // Eval functions
465
-	        $result = $trap->pluginClass->evaluateFunctionString($functionString);	        
465
+	        $result=$trap->pluginClass->evaluateFunctionString($functionString);	        
466 466
 	    }
467 467
 	    catch (Exception $e)
468 468
 	    {
469
-	        $this->_helper->json(array('status'=>'Action error : '.$e->getMessage() ));
469
+	        $this->_helper->json(array('status'=>'Action error : '.$e->getMessage()));
470 470
 	        return;
471 471
 	    }
472 472
 	    
473
-        $result = ($result === true)?'True':'False';
474
-        $this->_helper->json(array('status'=>'OK','message' => $result));
473
+        $result=($result === true) ? 'True' : 'False';
474
+        $this->_helper->json(array('status'=>'OK', 'message' => $result));
475 475
 	}
476 476
 
477 477
     /**************   Utilities **********************/
478 478
 
479
-	private function checkPostVar(array $postData,string $postVar, string $validRegexp) : string
479
+	private function checkPostVar(array $postData, string $postVar, string $validRegexp) : string
480 480
 	{
481 481
 	    if (!isset ($postData[$postVar]))
482 482
 	    {
483
-	        $this->_helper->json(array('status'=>'No ' . $postVar));
483
+	        $this->_helper->json(array('status'=>'No '.$postVar));
484 484
 	        return '';
485 485
 	    }
486 486
 	    if (preg_match('/'.$validRegexp.'/', $postData[$postVar]) != 1)
487 487
 	    {
488
-	        $this->_helper->json(array('status'=>'Unknown ' . $postVar . ' value '.$postData[$postVar]));
488
+	        $this->_helper->json(array('status'=>'Unknown '.$postVar.' value '.$postData[$postVar]));
489 489
 	        return '';
490 490
 	    }
491 491
 	    return $postData[$postVar];
Please login to merge, or discard this patch.
Braces   +17 added lines, -34 removed lines patch added patch discarded remove patch
@@ -65,8 +65,7 @@  discard block
 block discarded – undo
65 65
 		if (isset($postData['host']))
66 66
 		{
67 67
 			$host=$postData['host'];
68
-		}
69
-		else
68
+		} else
70 69
 		{
71 70
 			$this->_helper->json(array('status'=>'No Hosts','hostid' => -1));
72 71
 			return;
@@ -77,8 +76,7 @@  discard block
 block discarded – undo
77 76
 		{	
78 77
 			$this->_helper->json(array('status'=>'More than one host matches','hostid' => -1));
79 78
 			return;
80
-		}
81
-		else if (count($hostArray) == 0)
79
+		} else if (count($hostArray) == 0)
82 80
 		{
83 81
 			$this->_helper->json(array('status'=>'No host matches','hostid' => -1));
84 82
 			return;
@@ -114,8 +112,7 @@  discard block
 block discarded – undo
114 112
 		{	
115 113
 			$this->_helper->json(array('status'=>'More than one hostgroup matches','hostid' => -1));
116 114
 			return;
117
-		}
118
-		else if (count($hostArray) == 0)
115
+		} else if (count($hostArray) == 0)
119 116
 		{
120 117
 			$this->_helper->json(array('status'=>'No hostgroup matches','hostid' => -1));
121 118
 			return;
@@ -146,8 +143,7 @@  discard block
 block discarded – undo
146 143
 		{
147 144
 			$traplist=$this->getMIB()->getTrapList($mib);
148 145
 			$retTraps=array('status'=>'OK','traps' => $traplist);
149
-		} 
150
-		catch (Exception $e) 
146
+		} catch (Exception $e) 
151 147
 		{ 
152 148
 			$retTraps=array('status' => 'Error getting mibs');
153 149
 		}
@@ -169,8 +165,7 @@  discard block
 block discarded – undo
169 165
 		{
170 166
 			$objectlist=$this->getMIB()->getObjectList($trap);
171 167
 			$retObjects=array('status'=>'OK','objects' => $objectlist);
172
-		} 
173
-		catch (Exception $e) 
168
+		} catch (Exception $e) 
174 169
 		{ 
175 170
 			$retObjects=array('status' => 'not found');
176 171
 		}
@@ -185,8 +180,7 @@  discard block
 block discarded – undo
185 180
 		try
186 181
 		{
187 182
 			$miblist=$this->getMIB()->getMIBList();
188
-		} 
189
-		catch (Exception $e) 
183
+		} catch (Exception $e) 
190 184
 		{ 
191 185
 			$miblist=array('Error getting mibs');
192 186
 		}
@@ -209,8 +203,7 @@  discard block
 block discarded – undo
209 203
 		{
210 204
 			$this->_helper->json(array('status'=>'Not found'));
211 205
 			return;
212
-		}
213
-		else
206
+		} else
214 207
 		{
215 208
 			$this->_helper->json(
216 209
 				array('status'=>'OK',
@@ -245,8 +238,7 @@  discard block
 block discarded – undo
245 238
 			try
246 239
 			{
247 240
 			    $this->getUIDatabase()->setDBConfigValue('db_remove_days',$days);
248
-			}
249
-			catch (Exception $e)
241
+			} catch (Exception $e)
250 242
 			{
251 243
 				$this->_helper->json(array('status'=>'Save error : '.$e->getMessage() ));
252 244
 				return;
@@ -264,8 +256,7 @@  discard block
 block discarded – undo
264 256
 				$trap = new Trap($icingaweb2_etc);
265 257
 				$trap->setLogging($debug_level,'syslog');
266 258
 				$trap->eraseOldTraps($days);
267
-			}
268
-			catch (Exception $e)
259
+			} catch (Exception $e)
269 260
 			{
270 261
 				$this->_helper->json(array('status'=>'execute error : '.$e->getMessage() ));
271 262
 				return;
@@ -292,8 +283,7 @@  discard block
 block discarded – undo
292 283
 	    {
293 284
 	        $this->getUIDatabase()->setDBConfigValue('use_SnmpTrapAddess',$snmpUse);
294 285
 	        $this->getUIDatabase()->setDBConfigValue('SnmpTrapAddess_oid',$snmpOID);
295
-	    }
296
-	    catch (Exception $e)
286
+	    } catch (Exception $e)
297 287
 	    {
298 288
 	        $this->_helper->json(array('status'=>'Save error : '.$e->getMessage() ));
299 289
 	        return;
@@ -330,14 +320,12 @@  discard block
 block discarded – undo
330 320
 			    $this->_helper->json(array('status'=>'File not writable :  '.$file));
331 321
 			    return;
332 322
 			}
333
-		}
334
-		else
323
+		} else
335 324
 		{
336 325
 			if ($destination != 'file')
337 326
 			{
338 327
 				$file=null;
339
-			}
340
-			else
328
+			} else
341 329
 			{
342 330
 				$this->_helper->json(array('status'=>'No file'));
343 331
 				return;
@@ -351,8 +339,7 @@  discard block
 block discarded – undo
351 339
 		    $this->getUIDatabase()->setDBConfigValue('log_destination',$destination);
352 340
 		    $this->getUIDatabase()->setDBConfigValue('log_file',$file);
353 341
 		    $this->getUIDatabase()->setDBConfigValue('log_level',$level);
354
-		}
355
-		catch (Exception $e)
342
+		} catch (Exception $e)
356 343
 		{
357 344
 			$this->_helper->json(array('status'=>'Save error : '.$e->getMessage() ));
358 345
 			return;
@@ -388,8 +375,7 @@  discard block
 block discarded – undo
388 375
 	            // Eval
389 376
 	            $item=0;
390 377
 	            $rule=$trap->ruleClass->evaluation($rule,$item);
391
-	        }
392
-	        catch (Exception $e)
378
+	        } catch (Exception $e)
393 379
 	        {
394 380
 	            $this->_helper->json(array('status'=>'Evaluation error : '.$e->getMessage() ));
395 381
 	            return;
@@ -422,8 +408,7 @@  discard block
 block discarded – undo
422 408
             $action=($action == 'enable') ? true : false;
423 409
             $retVal=$trap->pluginClass->enablePlugin($pluginName, $action);
424 410
             
425
-        }
426
-        catch (Exception $e)
411
+        } catch (Exception $e)
427 412
         {
428 413
             $this->_helper->json(array('status'=>'Action error : '.$e->getMessage() ));
429 414
             return;
@@ -431,8 +416,7 @@  discard block
 block discarded – undo
431 416
         if ($retVal === true)
432 417
         {
433 418
             $this->_helper->json(array('status'=>'OK'));
434
-        }
435
-        else
419
+        } else
436 420
         {
437 421
             $this->_helper->json(array('status'=>'Error, see logs'));
438 422
         }
@@ -463,8 +447,7 @@  discard block
 block discarded – undo
463 447
 	        $functionString = $trap->ruleClass->eval_cleanup($functionString);
464 448
 	        // Eval functions
465 449
 	        $result = $trap->pluginClass->evaluateFunctionString($functionString);	        
466
-	    }
467
-	    catch (Exception $e)
450
+	    } catch (Exception $e)
468 451
 	    {
469 452
 	        $this->_helper->json(array('status'=>'Action error : '.$e->getMessage() ));
470 453
 	        return;
Please login to merge, or discard this patch.