Passed
Push — master ( 57a389...e15d84 )
by Patrick
02:12
created
library/Trapdirector/TrapsController.php 3 patches
Indentation   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -43,8 +43,8 @@  discard block
 block discarded – undo
43 43
 	
44 44
 	
45 45
 	/** Get instance of TrapModuleConfig class
46
-	*	@return TrapModuleConfig
47
-	*/
46
+	 *	@return TrapModuleConfig
47
+	 */
48 48
 	public function getModuleConfig() 
49 49
 	{
50 50
 		if ($this->moduleConfig == Null) 
@@ -76,12 +76,12 @@  discard block
 block discarded – undo
76 76
 	 */
77 77
 	public function getTrapHostListTable()
78 78
 	{
79
-	    if ($this->trapTableHostList == Null) 
79
+		if ($this->trapTableHostList == Null) 
80 80
 		{
81
-	        $this->trapTableHostList = new TrapTableHostList();
82
-	        $this->trapTableHostList->setConfig($this->getModuleConfig());
83
-	    }
84
-	    return $this->trapTableHostList;
81
+			$this->trapTableHostList = new TrapTableHostList();
82
+			$this->trapTableHostList->setConfig($this->getModuleConfig());
83
+		}
84
+		return $this->trapTableHostList;
85 85
 	}
86 86
 	
87 87
 	/**
@@ -102,23 +102,23 @@  discard block
 block discarded – undo
102 102
 	 */
103 103
 	public function getUIDatabase()
104 104
 	{
105
-	    if ($this->UIDatabase == Null)
106
-	    {
107
-	        $this->UIDatabase = new UIDatabase($this);
105
+		if ($this->UIDatabase == Null)
106
+		{
107
+			$this->UIDatabase = new UIDatabase($this);
108 108
 	       
109
-	    }
110
-	    return $this->UIDatabase;
109
+		}
110
+		return $this->UIDatabase;
111 111
 	}
112 112
 	
113
-    protected function applyPaginationLimits(Paginatable $paginatable, $limit = 25, $offset = null)
114
-    {
115
-        $limit = $this->params->get('limit', $limit);
116
-        $page = $this->params->get('page', $offset);
113
+	protected function applyPaginationLimits(Paginatable $paginatable, $limit = 25, $offset = null)
114
+	{
115
+		$limit = $this->params->get('limit', $limit);
116
+		$page = $this->params->get('page', $offset);
117 117
 
118
-        $paginatable->limit($limit, $page > 0 ? ($page - 1) * $limit : 0);
118
+		$paginatable->limit($limit, $page > 0 ? ($page - 1) * $limit : 0);
119 119
 
120
-        return $paginatable;
121
-    }	
120
+		return $paginatable;
121
+	}	
122 122
 	
123 123
 	public function displayExitError($source,$message)
124 124
 	{	// TODO : check better ways to transmit data (with POST ?)
@@ -127,33 +127,33 @@  discard block
 block discarded – undo
127 127
 	
128 128
 	protected function checkReadPermission()
129 129
 	{
130
-        if (! $this->Auth()->hasPermission('trapdirector/view')) {
131
-            $this->displayExitError('Permissions','No permission fo view content');
132
-        }		
130
+		if (! $this->Auth()->hasPermission('trapdirector/view')) {
131
+			$this->displayExitError('Permissions','No permission fo view content');
132
+		}		
133 133
 	}
134 134
 
135 135
 	protected function checkConfigPermission()
136 136
 	{
137
-        if (! $this->Auth()->hasPermission('trapdirector/config')) {
138
-            $this->displayExitError('Permissions','No permission fo configure');
139
-        }		
137
+		if (! $this->Auth()->hasPermission('trapdirector/config')) {
138
+			$this->displayExitError('Permissions','No permission fo configure');
139
+		}		
140 140
 	}
141 141
 	
142
-    /**
143
-     * Check if user has write permission
144
-     * @param number $check optional : if set to 1, return true (user has permission) or false instead of displaying error page
145
-     * @return boolean : user has permission
146
-     */
142
+	/**
143
+	 * Check if user has write permission
144
+	 * @param number $check optional : if set to 1, return true (user has permission) or false instead of displaying error page
145
+	 * @return boolean : user has permission
146
+	 */
147 147
 	protected function checkModuleConfigPermission($check=0)
148 148
 	{
149
-        if (! $this->Auth()->hasPermission('trapdirector/module_config')) {
150
-            if ($check == 0)
151
-            {
152
-                $this->displayExitError('Permissions','No permission fo configure module');
153
-            }
154
-            return false;
155
-        }
156
-        return true;
149
+		if (! $this->Auth()->hasPermission('trapdirector/module_config')) {
150
+			if ($check == 0)
151
+			{
152
+				$this->displayExitError('Permissions','No permission fo configure module');
153
+			}
154
+			return false;
155
+		}
156
+		return true;
157 157
 	}
158 158
 
159 159
 	/*************************  Trap class get **********************/
@@ -173,18 +173,18 @@  discard block
 block discarded – undo
173 173
 	/************************** MIB related **************************/
174 174
 	
175 175
 	/** Get MIBLoader class
176
-	*	@return MIBLoader class
177
-	*/
176
+	 *	@return MIBLoader class
177
+	 */
178 178
 	protected function getMIB()
179 179
 	{
180 180
 		if ($this->MIBData == null)
181 181
 		{
182
-		    $dbConn = $this->getUIDatabase()->getDbConn();
183
-		    if ($dbConn === null) throw new \ErrorException('uncatched db error');
182
+			$dbConn = $this->getUIDatabase()->getDbConn();
183
+			if ($dbConn === null) throw new \ErrorException('uncatched db error');
184 184
 			$this->MIBData=new MIBLoader(
185 185
 				$this->Config()->get('config', 'snmptranslate'),
186 186
 				$this->Config()->get('config', 'snmptranslate_dirs'),
187
-			    $dbConn,
187
+				$dbConn,
188 188
 				$this->getModuleConfig()
189 189
 			);
190 190
 		}
@@ -194,13 +194,13 @@  discard block
 block discarded – undo
194 194
 	/**************************  Database queries *******************/		
195 195
 	
196 196
 	/** Check if director is installed
197
-	*	@return bool true/false
198
-	*/
197
+	 *	@return bool true/false
198
+	 */
199 199
 	protected function isDirectorInstalled()
200 200
 	{
201
-	    $output=array();
202
-	    exec('icingacli module list',$output);
203
-	    foreach ($output as $line)
201
+		$output=array();
202
+		exec('icingacli module list',$output);
203
+		foreach ($output as $line)
204 204
 		{
205 205
 			if (preg_match('/^director .*enabled/',$line))
206 206
 			{
Please login to merge, or discard this patch.
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
 			{
55 55
 				$this->redirectNow('trapdirector/settings?message=No database prefix');
56 56
 			}
57
-			$this->moduleConfig = new TrapModuleConfig($db_prefix);
57
+			$this->moduleConfig=new TrapModuleConfig($db_prefix);
58 58
 		}
59 59
 		return $this->moduleConfig;
60 60
 	}
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
 	 */
66 66
 	public function getTrapListTable() {
67 67
 		if ($this->trapTableList == Null) {
68
-			$this->trapTableList = new TrapTableList();
68
+			$this->trapTableList=new TrapTableList();
69 69
 			$this->trapTableList->setConfig($this->getModuleConfig());
70 70
 		}
71 71
 		return $this->trapTableList;
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
 	{
79 79
 	    if ($this->trapTableHostList == Null) 
80 80
 		{
81
-	        $this->trapTableHostList = new TrapTableHostList();
81
+	        $this->trapTableHostList=new TrapTableHostList();
82 82
 	        $this->trapTableHostList->setConfig($this->getModuleConfig());
83 83
 	    }
84 84
 	    return $this->trapTableHostList;
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
 	{
92 92
 		if ($this->handlerTableList == Null) 
93 93
 		{
94
-			$this->handlerTableList = new HandlerTableList();
94
+			$this->handlerTableList=new HandlerTableList();
95 95
 			$this->handlerTableList->setConfig($this->getModuleConfig());
96 96
 		}
97 97
 		return $this->handlerTableList;
@@ -104,38 +104,38 @@  discard block
 block discarded – undo
104 104
 	{
105 105
 	    if ($this->UIDatabase == Null)
106 106
 	    {
107
-	        $this->UIDatabase = new UIDatabase($this);
107
+	        $this->UIDatabase=new UIDatabase($this);
108 108
 	       
109 109
 	    }
110 110
 	    return $this->UIDatabase;
111 111
 	}
112 112
 	
113
-    protected function applyPaginationLimits(Paginatable $paginatable, $limit = 25, $offset = null)
113
+    protected function applyPaginationLimits(Paginatable $paginatable, $limit=25, $offset=null)
114 114
     {
115
-        $limit = $this->params->get('limit', $limit);
116
-        $page = $this->params->get('page', $offset);
115
+        $limit=$this->params->get('limit', $limit);
116
+        $page=$this->params->get('page', $offset);
117 117
 
118 118
         $paginatable->limit($limit, $page > 0 ? ($page - 1) * $limit : 0);
119 119
 
120 120
         return $paginatable;
121 121
     }	
122 122
 	
123
-	public function displayExitError($source,$message)
123
+	public function displayExitError($source, $message)
124 124
 	{	// TODO : check better ways to transmit data (with POST ?)
125 125
 		$this->redirectNow('trapdirector/error?source='.$source.'&message='.$message);
126 126
 	}
127 127
 	
128 128
 	protected function checkReadPermission()
129 129
 	{
130
-        if (! $this->Auth()->hasPermission('trapdirector/view')) {
131
-            $this->displayExitError('Permissions','No permission fo view content');
130
+        if (!$this->Auth()->hasPermission('trapdirector/view')) {
131
+            $this->displayExitError('Permissions', 'No permission fo view content');
132 132
         }		
133 133
 	}
134 134
 
135 135
 	protected function checkConfigPermission()
136 136
 	{
137
-        if (! $this->Auth()->hasPermission('trapdirector/config')) {
138
-            $this->displayExitError('Permissions','No permission fo configure');
137
+        if (!$this->Auth()->hasPermission('trapdirector/config')) {
138
+            $this->displayExitError('Permissions', 'No permission fo configure');
139 139
         }		
140 140
 	}
141 141
 	
@@ -146,10 +146,10 @@  discard block
 block discarded – undo
146 146
      */
147 147
 	protected function checkModuleConfigPermission($check=0)
148 148
 	{
149
-        if (! $this->Auth()->hasPermission('trapdirector/module_config')) {
149
+        if (!$this->Auth()->hasPermission('trapdirector/module_config')) {
150 150
             if ($check == 0)
151 151
             {
152
-                $this->displayExitError('Permissions','No permission fo configure module');
152
+                $this->displayExitError('Permissions', 'No permission fo configure module');
153 153
             }
154 154
             return false;
155 155
         }
@@ -161,10 +161,10 @@  discard block
 block discarded – undo
161 161
 	{ // TODO : try/catch here ? or within caller
162 162
 		if ($this->trapClass == null)
163 163
 		{
164
-			require_once($this->Module()->getBaseDir() .'/bin/trap_class.php');
164
+			require_once($this->Module()->getBaseDir().'/bin/trap_class.php');
165 165
 			$icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc');
166 166
 			//$debug_level=4;
167
-			$this->trapClass = new Trap($icingaweb2_etc);
167
+			$this->trapClass=new Trap($icingaweb2_etc);
168 168
 			//$Trap->setLogging($debug_level,'syslog');
169 169
 		}
170 170
 		return $this->trapClass;
@@ -179,7 +179,7 @@  discard block
 block discarded – undo
179 179
 	{
180 180
 		if ($this->MIBData == null)
181 181
 		{
182
-		    $dbConn = $this->getUIDatabase()->getDbConn();
182
+		    $dbConn=$this->getUIDatabase()->getDbConn();
183 183
 		    if ($dbConn === null) throw new \ErrorException('uncatched db error');
184 184
 			$this->MIBData=new MIBLoader(
185 185
 				$this->Config()->get('config', 'snmptranslate'),
@@ -199,10 +199,10 @@  discard block
 block discarded – undo
199 199
 	protected function isDirectorInstalled()
200 200
 	{
201 201
 	    $output=array();
202
-	    exec('icingacli module list',$output);
202
+	    exec('icingacli module list', $output);
203 203
 	    foreach ($output as $line)
204 204
 		{
205
-			if (preg_match('/^director .*enabled/',$line))
205
+			if (preg_match('/^director .*enabled/', $line))
206 206
 			{
207 207
 				return true;
208 208
 			}
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -180,7 +180,9 @@
 block discarded – undo
180 180
 		if ($this->MIBData == null)
181 181
 		{
182 182
 		    $dbConn = $this->getUIDatabase()->getDbConn();
183
-		    if ($dbConn === null) throw new \ErrorException('uncatched db error');
183
+		    if ($dbConn === null) {
184
+		    	throw new \ErrorException('uncatched db error');
185
+		    }
184 186
 			$this->MIBData=new MIBLoader(
185 187
 				$this->Config()->get('config', 'snmptranslate'),
186 188
 				$this->Config()->get('config', 'snmptranslate_dirs'),
Please login to merge, or discard this patch.
library/Trapdirector/TrapsActions/IdoDBQuery.php 3 patches
Indentation   +218 added lines, -218 removed lines patch added patch discarded remove patch
@@ -16,243 +16,243 @@
 block discarded – undo
16 16
 trait IdoDBQuery
17 17
 {
18 18
 
19
-    /** Get host(s) by IP (v4 or v6) or by name in IDO database
20
-     *	does not catch exceptions
21
-     *	@return array of objects ( name, id (object_id), display_name)
22
-     */
23
-    public function getHostByIP($ip)
24
-    {
25
-        // select a.name1, b.display_name from icinga.icinga_objects AS a , icinga.icinga_hosts AS b WHERE (b.address = '192.168.56.101' OR b.address6= '123456') and b.host_object_id=a.object_id
26
-        $dbConn = $this->getIdoDbConn();
27
-        if ($dbConn === null) throw new \ErrorException('uncatched db error');
19
+	/** Get host(s) by IP (v4 or v6) or by name in IDO database
20
+	 *	does not catch exceptions
21
+	 *	@return array of objects ( name, id (object_id), display_name)
22
+	 */
23
+	public function getHostByIP($ip)
24
+	{
25
+		// select a.name1, b.display_name from icinga.icinga_objects AS a , icinga.icinga_hosts AS b WHERE (b.address = '192.168.56.101' OR b.address6= '123456') and b.host_object_id=a.object_id
26
+		$dbConn = $this->getIdoDbConn();
27
+		if ($dbConn === null) throw new \ErrorException('uncatched db error');
28 28
         
29
-        // TODO : check for SQL injections
30
-        $query=$dbConn->select()
31
-        ->from(
32
-            array('a' => 'icinga_objects'),
33
-            array('name' => 'a.name1','id' => 'object_id'))
34
-            ->join(
35
-                array('b' => 'icinga_hosts'),
36
-                'b.host_object_id=a.object_id',
37
-                array('display_name' => 'b.display_name'))
38
-                ->where("(b.address LIKE '%".$ip."%' OR b.address6 LIKE '%".$ip."%' OR a.name1 LIKE '%".$ip."%' OR b.display_name LIKE '%".$ip."%') and a.is_active = 1");
39
-                return $dbConn->fetchAll($query);
40
-    }
29
+		// TODO : check for SQL injections
30
+		$query=$dbConn->select()
31
+		->from(
32
+			array('a' => 'icinga_objects'),
33
+			array('name' => 'a.name1','id' => 'object_id'))
34
+			->join(
35
+				array('b' => 'icinga_hosts'),
36
+				'b.host_object_id=a.object_id',
37
+				array('display_name' => 'b.display_name'))
38
+				->where("(b.address LIKE '%".$ip."%' OR b.address6 LIKE '%".$ip."%' OR a.name1 LIKE '%".$ip."%' OR b.display_name LIKE '%".$ip."%') and a.is_active = 1");
39
+				return $dbConn->fetchAll($query);
40
+	}
41 41
     
42
-    /** Get host(s) by name in IDO database
43
-     *	does not catch exceptions
44
-     *	@return array of objects ( name, id (object_id), display_name)
45
-     */
46
-    public function getHostByName($name)
47
-    {
48
-        // select a.name1, b.display_name from icinga.icinga_objects AS a , icinga.icinga_hosts AS b WHERE (b.address = '192.168.56.101' OR b.address6= '123456') and b.host_object_id=a.object_id
49
-        $dbConn = $this->getIdoDbConn();
50
-        if ($dbConn === null) throw new \ErrorException('uncatched db error');
42
+	/** Get host(s) by name in IDO database
43
+	 *	does not catch exceptions
44
+	 *	@return array of objects ( name, id (object_id), display_name)
45
+	 */
46
+	public function getHostByName($name)
47
+	{
48
+		// select a.name1, b.display_name from icinga.icinga_objects AS a , icinga.icinga_hosts AS b WHERE (b.address = '192.168.56.101' OR b.address6= '123456') and b.host_object_id=a.object_id
49
+		$dbConn = $this->getIdoDbConn();
50
+		if ($dbConn === null) throw new \ErrorException('uncatched db error');
51 51
         
52
-        // TODO : check for SQL injections
53
-        $query=$dbConn->select()
54
-        ->from(
55
-            array('a' => 'icinga_objects'),
56
-            array('name' => 'a.name1','id' => 'object_id'))
57
-            ->join(
58
-                array('b' => 'icinga_hosts'),
59
-                'b.host_object_id=a.object_id',
60
-                array('display_name' => 'b.display_name'))
61
-                ->where("a.name1 = '$name'");
62
-                return $dbConn->fetchAll($query);
63
-    }
52
+		// TODO : check for SQL injections
53
+		$query=$dbConn->select()
54
+		->from(
55
+			array('a' => 'icinga_objects'),
56
+			array('name' => 'a.name1','id' => 'object_id'))
57
+			->join(
58
+				array('b' => 'icinga_hosts'),
59
+				'b.host_object_id=a.object_id',
60
+				array('display_name' => 'b.display_name'))
61
+				->where("a.name1 = '$name'");
62
+				return $dbConn->fetchAll($query);
63
+	}
64 64
     
65
-    /** Get host groups by  name in IDO database
66
-     *	does not catch exceptions
67
-     *	@return array of objects ( name, id (object_id), display_name)
68
-     */
69
-    public function getHostGroupByName($ip)
70
-    {
71
-        // select a.name1, b.display_name from icinga.icinga_objects AS a , icinga.icinga_hosts AS b WHERE (b.address = '192.168.56.101' OR b.address6= '123456') and b.host_object_id=a.object_id
72
-        $dbConn = $this->getIdoDbConn();
73
-        if ($dbConn === null) throw new \ErrorException('uncatched db error');
74
-        // TODO : check for SQL injections
75
-        $query=$dbConn->select()
76
-        ->from(
77
-            array('a' => 'icinga_objects'),
78
-            array('name' => 'a.name1','id' => 'object_id'))
79
-            ->join(
80
-                array('b' => 'icinga_hostgroups'),
81
-                'b.hostgroup_object_id=a.object_id',
82
-                array('display_name' => 'b.alias'))
83
-                ->where("(a.name1 LIKE '%".$ip."%' OR b.alias LIKE '%".$ip."%') and a.is_active = 1");
84
-                return $dbConn->fetchAll($query);
85
-    }
65
+	/** Get host groups by  name in IDO database
66
+	 *	does not catch exceptions
67
+	 *	@return array of objects ( name, id (object_id), display_name)
68
+	 */
69
+	public function getHostGroupByName($ip)
70
+	{
71
+		// select a.name1, b.display_name from icinga.icinga_objects AS a , icinga.icinga_hosts AS b WHERE (b.address = '192.168.56.101' OR b.address6= '123456') and b.host_object_id=a.object_id
72
+		$dbConn = $this->getIdoDbConn();
73
+		if ($dbConn === null) throw new \ErrorException('uncatched db error');
74
+		// TODO : check for SQL injections
75
+		$query=$dbConn->select()
76
+		->from(
77
+			array('a' => 'icinga_objects'),
78
+			array('name' => 'a.name1','id' => 'object_id'))
79
+			->join(
80
+				array('b' => 'icinga_hostgroups'),
81
+				'b.hostgroup_object_id=a.object_id',
82
+				array('display_name' => 'b.alias'))
83
+				->where("(a.name1 LIKE '%".$ip."%' OR b.alias LIKE '%".$ip."%') and a.is_active = 1");
84
+				return $dbConn->fetchAll($query);
85
+	}
86 86
     
87 87
     
88
-    /** Get host IP (v4 and v6) by name in IDO database
89
-     *	does not catch exceptions
90
-     *	@return array ( name, display_name, ip4, ip6)
91
-     */
92
-    public function getHostInfoByID($id)
93
-    {
94
-        if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id');  }
95
-        $dbConn = $this->getIdoDbConn();
96
-        if ($dbConn === null) throw new \ErrorException('uncatched db error');
97
-        $query=$dbConn->select()
98
-        ->from(
99
-            array('a' => 'icinga_objects'),
100
-            array('name' => 'a.name1'))
101
-            ->join(
102
-                array('b' => 'icinga_hosts'),
103
-                'b.host_object_id=a.object_id',
104
-                array('ip4' => 'b.address', 'ip6' => 'b.address6', 'display_name' => 'b.display_name'))
105
-                ->where("a.object_id = '".$id."'");
106
-                return $dbConn->fetchRow($query);
107
-    }
88
+	/** Get host IP (v4 and v6) by name in IDO database
89
+	 *	does not catch exceptions
90
+	 *	@return array ( name, display_name, ip4, ip6)
91
+	 */
92
+	public function getHostInfoByID($id)
93
+	{
94
+		if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id');  }
95
+		$dbConn = $this->getIdoDbConn();
96
+		if ($dbConn === null) throw new \ErrorException('uncatched db error');
97
+		$query=$dbConn->select()
98
+		->from(
99
+			array('a' => 'icinga_objects'),
100
+			array('name' => 'a.name1'))
101
+			->join(
102
+				array('b' => 'icinga_hosts'),
103
+				'b.host_object_id=a.object_id',
104
+				array('ip4' => 'b.address', 'ip6' => 'b.address6', 'display_name' => 'b.display_name'))
105
+				->where("a.object_id = '".$id."'");
106
+				return $dbConn->fetchRow($query);
107
+	}
108 108
     
109 109
     
110
-    /** Get host by objectid  in IDO database
111
-     *	does not catch exceptions
112
-     *	@return array of objects ( id, name, display_name, ip, ip6,  )
113
-     */
114
-    public function getHostByObjectID($id) // TODO : duplicate of getHostInfoByID above
115
-    {
116
-        if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id');  }
117
-        $dbConn = $this->getIdoDbConn();
118
-        if ($dbConn === null) throw new \ErrorException('uncatched db error');
119
-        $query=$dbConn->select()
120
-        ->from(
121
-            array('a' => 'icinga_objects'),
122
-            array('name' => 'a.name1','id' => 'a.object_id'))
123
-            ->join(
124
-                array('b' => 'icinga_hosts'),
125
-                'b.host_object_id=a.object_id',
126
-                array('display_name' => 'b.display_name' , 'ip' => 'b.address', 'ip6' => 'b.address6'))
127
-                ->where('a.object_id = ?',$id);
128
-                return $dbConn->fetchRow($query);
129
-    }
110
+	/** Get host by objectid  in IDO database
111
+	 *	does not catch exceptions
112
+	 *	@return array of objects ( id, name, display_name, ip, ip6,  )
113
+	 */
114
+	public function getHostByObjectID($id) // TODO : duplicate of getHostInfoByID above
115
+	{
116
+		if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id');  }
117
+		$dbConn = $this->getIdoDbConn();
118
+		if ($dbConn === null) throw new \ErrorException('uncatched db error');
119
+		$query=$dbConn->select()
120
+		->from(
121
+			array('a' => 'icinga_objects'),
122
+			array('name' => 'a.name1','id' => 'a.object_id'))
123
+			->join(
124
+				array('b' => 'icinga_hosts'),
125
+				'b.host_object_id=a.object_id',
126
+				array('display_name' => 'b.display_name' , 'ip' => 'b.address', 'ip6' => 'b.address6'))
127
+				->where('a.object_id = ?',$id);
128
+				return $dbConn->fetchRow($query);
129
+	}
130 130
     
131
-    /** Get services from object ( host_object_id) in IDO database
132
-     *	does not catch exceptions
133
-     *	@param $id	int object_id
134
-     *	@return array display_name (of service), service_object_id
135
-     */
136
-    public function getServicesByHostid($id)
137
-    {
138
-        // select a.name1, b.display_name from icinga.icinga_objects AS a , icinga.icinga_hosts AS b WHERE (b.address = '192.168.56.101' OR b.address6= '123456') and b.host_object_id=a.object_id
139
-        if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id');  }
140
-        $dbConn = $this->getIdoDbConn();
141
-        if ($dbConn === null) throw new \ErrorException('uncatched db error');
142
-        $query=$dbConn->select()
143
-        ->from(
144
-            array('s' => 'icinga_services'),
145
-            array('name' => 's.display_name','id' => 's.service_object_id'))
146
-            ->join(
147
-                array('a' => 'icinga_objects'),
148
-                's.service_object_id=a.object_id',
149
-                array('is_active'=>'a.is_active','name2'=>'a.name2'))
150
-                ->where('s.host_object_id='.$id.' AND a.is_active = 1');
151
-                return $dbConn->fetchAll($query);
152
-    }
131
+	/** Get services from object ( host_object_id) in IDO database
132
+	 *	does not catch exceptions
133
+	 *	@param $id	int object_id
134
+	 *	@return array display_name (of service), service_object_id
135
+	 */
136
+	public function getServicesByHostid($id)
137
+	{
138
+		// select a.name1, b.display_name from icinga.icinga_objects AS a , icinga.icinga_hosts AS b WHERE (b.address = '192.168.56.101' OR b.address6= '123456') and b.host_object_id=a.object_id
139
+		if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id');  }
140
+		$dbConn = $this->getIdoDbConn();
141
+		if ($dbConn === null) throw new \ErrorException('uncatched db error');
142
+		$query=$dbConn->select()
143
+		->from(
144
+			array('s' => 'icinga_services'),
145
+			array('name' => 's.display_name','id' => 's.service_object_id'))
146
+			->join(
147
+				array('a' => 'icinga_objects'),
148
+				's.service_object_id=a.object_id',
149
+				array('is_active'=>'a.is_active','name2'=>'a.name2'))
150
+				->where('s.host_object_id='.$id.' AND a.is_active = 1');
151
+				return $dbConn->fetchAll($query);
152
+	}
153 153
     
154
-    /** Get services from hostgroup object id ( hostgroup_object_id) in IDO database
155
-     * 	gets all hosts in hostgroup and return common services
156
-     *	does not catch exceptions
157
-     *	@param $id	int object_id
158
-     *	@return array display_name (of service), service_object_id
159
-     */
160
-    public function getServicesByHostGroupid($id)
161
-    {
162
-        if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id');  }
163
-        $dbConn = $this->getIdoDbConn();
164
-        if ($dbConn === null) throw new \ErrorException('uncatched db error');
165
-        $query=$dbConn->select()
166
-        ->from(
167
-            array('s' => 'icinga_hostgroup_members'),
168
-            array('host_object_id' => 's.host_object_id'))
169
-            ->join(
170
-                array('a' => 'icinga_hostgroups'),
171
-                's.hostgroup_id=a.hostgroup_id',
172
-                'hostgroup_object_id')
173
-                ->where('a.hostgroup_object_id='.$id);
174
-                $hosts=$dbConn->fetchAll($query);
175
-                $common_services=array();
176
-                $num_hosts=count($hosts);
177
-                foreach ($hosts as $key => $host)
178
-                { // For each host, get all services and add in common_services if not found or add counter
179
-                    $host_services=$this->getServicesByHostid($host->host_object_id);
180
-                    foreach($host_services as $service)
181
-                    {
182
-                        if (isset($common_services[$service->name2]['num']))
183
-                        {
184
-                            $common_services[$service->name2]['num'] +=1;
185
-                        }
186
-                        else
187
-                        {
188
-                            $common_services[$service->name2]['num']=1;
189
-                            $common_services[$service->name2]['name']=$service->name;
190
-                        }
191
-                    }
192
-                }
193
-                $result=array();
154
+	/** Get services from hostgroup object id ( hostgroup_object_id) in IDO database
155
+	 * 	gets all hosts in hostgroup and return common services
156
+	 *	does not catch exceptions
157
+	 *	@param $id	int object_id
158
+	 *	@return array display_name (of service), service_object_id
159
+	 */
160
+	public function getServicesByHostGroupid($id)
161
+	{
162
+		if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id');  }
163
+		$dbConn = $this->getIdoDbConn();
164
+		if ($dbConn === null) throw new \ErrorException('uncatched db error');
165
+		$query=$dbConn->select()
166
+		->from(
167
+			array('s' => 'icinga_hostgroup_members'),
168
+			array('host_object_id' => 's.host_object_id'))
169
+			->join(
170
+				array('a' => 'icinga_hostgroups'),
171
+				's.hostgroup_id=a.hostgroup_id',
172
+				'hostgroup_object_id')
173
+				->where('a.hostgroup_object_id='.$id);
174
+				$hosts=$dbConn->fetchAll($query);
175
+				$common_services=array();
176
+				$num_hosts=count($hosts);
177
+				foreach ($hosts as $key => $host)
178
+				{ // For each host, get all services and add in common_services if not found or add counter
179
+					$host_services=$this->getServicesByHostid($host->host_object_id);
180
+					foreach($host_services as $service)
181
+					{
182
+						if (isset($common_services[$service->name2]['num']))
183
+						{
184
+							$common_services[$service->name2]['num'] +=1;
185
+						}
186
+						else
187
+						{
188
+							$common_services[$service->name2]['num']=1;
189
+							$common_services[$service->name2]['name']=$service->name;
190
+						}
191
+					}
192
+				}
193
+				$result=array();
194 194
                 
195
-                //print_r($common_services);
196
-                foreach (array_keys($common_services) as $key)
197
-                {
198
-                    if ($common_services[$key]['num'] == $num_hosts)
199
-                    {
200
-                        array_push($result,array($key,$common_services[$key]['name']));
201
-                    }
202
-                }
195
+				//print_r($common_services);
196
+				foreach (array_keys($common_services) as $key)
197
+				{
198
+					if ($common_services[$key]['num'] == $num_hosts)
199
+					{
200
+						array_push($result,array($key,$common_services[$key]['name']));
201
+					}
202
+				}
203 203
                 
204
-                return $result;
205
-    }
204
+				return $result;
205
+	}
206 206
     
207
-    /** Get services object id by host name / service name in IDO database
208
-     *	does not catch exceptions
209
-     *	@param $hostname string host name
210
-     *	@param $name string service name
211
-     *	@return array  service id
212
-     */
213
-    public function getServiceIDByName($hostname,$name)
214
-    {
215
-        $dbConn = $this->getIdoDbConn();
216
-        if ($dbConn === null) throw new \ErrorException('uncatched db error');
207
+	/** Get services object id by host name / service name in IDO database
208
+	 *	does not catch exceptions
209
+	 *	@param $hostname string host name
210
+	 *	@param $name string service name
211
+	 *	@return array  service id
212
+	 */
213
+	public function getServiceIDByName($hostname,$name)
214
+	{
215
+		$dbConn = $this->getIdoDbConn();
216
+		if ($dbConn === null) throw new \ErrorException('uncatched db error');
217 217
         
218
-        if ($name == null)
219
-        {
220
-            return array();
221
-        }
218
+		if ($name == null)
219
+		{
220
+			return array();
221
+		}
222 222
         
223
-        $query=$dbConn->select()
224
-        ->from(
225
-            array('s' => 'icinga_services'),
226
-            array('name' => 's.display_name','id' => 's.service_object_id'))
227
-            ->join(
228
-                array('a' => 'icinga_objects'),
229
-                's.service_object_id=a.object_id',
230
-                'is_active')
231
-                ->where('a.name2=\''.$name.'\' AND a.name1=\''.$hostname.'\' AND a.is_active = 1');
223
+		$query=$dbConn->select()
224
+		->from(
225
+			array('s' => 'icinga_services'),
226
+			array('name' => 's.display_name','id' => 's.service_object_id'))
227
+			->join(
228
+				array('a' => 'icinga_objects'),
229
+				's.service_object_id=a.object_id',
230
+				'is_active')
231
+				->where('a.name2=\''.$name.'\' AND a.name1=\''.$hostname.'\' AND a.is_active = 1');
232 232
                 
233
-                return $dbConn->fetchAll($query);
234
-    }
233
+				return $dbConn->fetchAll($query);
234
+	}
235 235
     
236
-    /** Get object name from object_id  in IDO database
237
-     *	does not catch exceptions
238
-     *	@param int $id object_id (default to null, used first if not null)
239
-     *	@return array name1 (host) name2 (service)
240
-     */
241
-    public function getObjectNameByid($id)
242
-    {
243
-        // select a.name1, b.display_name from icinga.icinga_objects AS a , icinga.icinga_hosts AS b WHERE (b.address = '192.168.56.101' OR b.address6= '123456') and b.host_object_id=a.object_id
244
-        if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id');  }
245
-        $dbConn = $this->getIdoDbConn();
246
-        if ($dbConn === null) throw new \ErrorException('uncatched db error');
236
+	/** Get object name from object_id  in IDO database
237
+	 *	does not catch exceptions
238
+	 *	@param int $id object_id (default to null, used first if not null)
239
+	 *	@return array name1 (host) name2 (service)
240
+	 */
241
+	public function getObjectNameByid($id)
242
+	{
243
+		// select a.name1, b.display_name from icinga.icinga_objects AS a , icinga.icinga_hosts AS b WHERE (b.address = '192.168.56.101' OR b.address6= '123456') and b.host_object_id=a.object_id
244
+		if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id');  }
245
+		$dbConn = $this->getIdoDbConn();
246
+		if ($dbConn === null) throw new \ErrorException('uncatched db error');
247 247
         
248
-        $query=$dbConn->select()
249
-        ->from(
250
-            array('a' => 'icinga_objects'),
251
-            array('name1' => 'a.name1','name2' => 'a.name2'))
252
-            ->where('a.object_id='.$id.' AND a.is_active = 1');
248
+		$query=$dbConn->select()
249
+		->from(
250
+			array('a' => 'icinga_objects'),
251
+			array('name1' => 'a.name1','name2' => 'a.name2'))
252
+			->where('a.object_id='.$id.' AND a.is_active = 1');
253 253
             
254
-            return $dbConn->fetchRow($query);
255
-    }
254
+			return $dbConn->fetchRow($query);
255
+	}
256 256
     
257 257
     
258 258
 }
259 259
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -23,14 +23,14 @@  discard block
 block discarded – undo
23 23
     public function getHostByIP($ip)
24 24
     {
25 25
         // select a.name1, b.display_name from icinga.icinga_objects AS a , icinga.icinga_hosts AS b WHERE (b.address = '192.168.56.101' OR b.address6= '123456') and b.host_object_id=a.object_id
26
-        $dbConn = $this->getIdoDbConn();
26
+        $dbConn=$this->getIdoDbConn();
27 27
         if ($dbConn === null) throw new \ErrorException('uncatched db error');
28 28
         
29 29
         // TODO : check for SQL injections
30 30
         $query=$dbConn->select()
31 31
         ->from(
32 32
             array('a' => 'icinga_objects'),
33
-            array('name' => 'a.name1','id' => 'object_id'))
33
+            array('name' => 'a.name1', 'id' => 'object_id'))
34 34
             ->join(
35 35
                 array('b' => 'icinga_hosts'),
36 36
                 'b.host_object_id=a.object_id',
@@ -46,14 +46,14 @@  discard block
 block discarded – undo
46 46
     public function getHostByName($name)
47 47
     {
48 48
         // select a.name1, b.display_name from icinga.icinga_objects AS a , icinga.icinga_hosts AS b WHERE (b.address = '192.168.56.101' OR b.address6= '123456') and b.host_object_id=a.object_id
49
-        $dbConn = $this->getIdoDbConn();
49
+        $dbConn=$this->getIdoDbConn();
50 50
         if ($dbConn === null) throw new \ErrorException('uncatched db error');
51 51
         
52 52
         // TODO : check for SQL injections
53 53
         $query=$dbConn->select()
54 54
         ->from(
55 55
             array('a' => 'icinga_objects'),
56
-            array('name' => 'a.name1','id' => 'object_id'))
56
+            array('name' => 'a.name1', 'id' => 'object_id'))
57 57
             ->join(
58 58
                 array('b' => 'icinga_hosts'),
59 59
                 'b.host_object_id=a.object_id',
@@ -69,13 +69,13 @@  discard block
 block discarded – undo
69 69
     public function getHostGroupByName($ip)
70 70
     {
71 71
         // select a.name1, b.display_name from icinga.icinga_objects AS a , icinga.icinga_hosts AS b WHERE (b.address = '192.168.56.101' OR b.address6= '123456') and b.host_object_id=a.object_id
72
-        $dbConn = $this->getIdoDbConn();
72
+        $dbConn=$this->getIdoDbConn();
73 73
         if ($dbConn === null) throw new \ErrorException('uncatched db error');
74 74
         // TODO : check for SQL injections
75 75
         $query=$dbConn->select()
76 76
         ->from(
77 77
             array('a' => 'icinga_objects'),
78
-            array('name' => 'a.name1','id' => 'object_id'))
78
+            array('name' => 'a.name1', 'id' => 'object_id'))
79 79
             ->join(
80 80
                 array('b' => 'icinga_hostgroups'),
81 81
                 'b.hostgroup_object_id=a.object_id',
@@ -91,8 +91,8 @@  discard block
 block discarded – undo
91 91
      */
92 92
     public function getHostInfoByID($id)
93 93
     {
94
-        if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id');  }
95
-        $dbConn = $this->getIdoDbConn();
94
+        if (!preg_match('/^[0-9]+$/', $id)) { throw new Exception('Invalid id'); }
95
+        $dbConn=$this->getIdoDbConn();
96 96
         if ($dbConn === null) throw new \ErrorException('uncatched db error');
97 97
         $query=$dbConn->select()
98 98
         ->from(
@@ -113,18 +113,18 @@  discard block
 block discarded – undo
113 113
      */
114 114
     public function getHostByObjectID($id) // TODO : duplicate of getHostInfoByID above
115 115
     {
116
-        if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id');  }
117
-        $dbConn = $this->getIdoDbConn();
116
+        if (!preg_match('/^[0-9]+$/', $id)) { throw new Exception('Invalid id'); }
117
+        $dbConn=$this->getIdoDbConn();
118 118
         if ($dbConn === null) throw new \ErrorException('uncatched db error');
119 119
         $query=$dbConn->select()
120 120
         ->from(
121 121
             array('a' => 'icinga_objects'),
122
-            array('name' => 'a.name1','id' => 'a.object_id'))
122
+            array('name' => 'a.name1', 'id' => 'a.object_id'))
123 123
             ->join(
124 124
                 array('b' => 'icinga_hosts'),
125 125
                 'b.host_object_id=a.object_id',
126
-                array('display_name' => 'b.display_name' , 'ip' => 'b.address', 'ip6' => 'b.address6'))
127
-                ->where('a.object_id = ?',$id);
126
+                array('display_name' => 'b.display_name', 'ip' => 'b.address', 'ip6' => 'b.address6'))
127
+                ->where('a.object_id = ?', $id);
128 128
                 return $dbConn->fetchRow($query);
129 129
     }
130 130
     
@@ -136,17 +136,17 @@  discard block
 block discarded – undo
136 136
     public function getServicesByHostid($id)
137 137
     {
138 138
         // select a.name1, b.display_name from icinga.icinga_objects AS a , icinga.icinga_hosts AS b WHERE (b.address = '192.168.56.101' OR b.address6= '123456') and b.host_object_id=a.object_id
139
-        if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id');  }
140
-        $dbConn = $this->getIdoDbConn();
139
+        if (!preg_match('/^[0-9]+$/', $id)) { throw new Exception('Invalid id'); }
140
+        $dbConn=$this->getIdoDbConn();
141 141
         if ($dbConn === null) throw new \ErrorException('uncatched db error');
142 142
         $query=$dbConn->select()
143 143
         ->from(
144 144
             array('s' => 'icinga_services'),
145
-            array('name' => 's.display_name','id' => 's.service_object_id'))
145
+            array('name' => 's.display_name', 'id' => 's.service_object_id'))
146 146
             ->join(
147 147
                 array('a' => 'icinga_objects'),
148 148
                 's.service_object_id=a.object_id',
149
-                array('is_active'=>'a.is_active','name2'=>'a.name2'))
149
+                array('is_active'=>'a.is_active', 'name2'=>'a.name2'))
150 150
                 ->where('s.host_object_id='.$id.' AND a.is_active = 1');
151 151
                 return $dbConn->fetchAll($query);
152 152
     }
@@ -159,8 +159,8 @@  discard block
 block discarded – undo
159 159
      */
160 160
     public function getServicesByHostGroupid($id)
161 161
     {
162
-        if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id');  }
163
-        $dbConn = $this->getIdoDbConn();
162
+        if (!preg_match('/^[0-9]+$/', $id)) { throw new Exception('Invalid id'); }
163
+        $dbConn=$this->getIdoDbConn();
164 164
         if ($dbConn === null) throw new \ErrorException('uncatched db error');
165 165
         $query=$dbConn->select()
166 166
         ->from(
@@ -177,11 +177,11 @@  discard block
 block discarded – undo
177 177
                 foreach ($hosts as $key => $host)
178 178
                 { // For each host, get all services and add in common_services if not found or add counter
179 179
                     $host_services=$this->getServicesByHostid($host->host_object_id);
180
-                    foreach($host_services as $service)
180
+                    foreach ($host_services as $service)
181 181
                     {
182 182
                         if (isset($common_services[$service->name2]['num']))
183 183
                         {
184
-                            $common_services[$service->name2]['num'] +=1;
184
+                            $common_services[$service->name2]['num']+=1;
185 185
                         }
186 186
                         else
187 187
                         {
@@ -197,7 +197,7 @@  discard block
 block discarded – undo
197 197
                 {
198 198
                     if ($common_services[$key]['num'] == $num_hosts)
199 199
                     {
200
-                        array_push($result,array($key,$common_services[$key]['name']));
200
+                        array_push($result, array($key, $common_services[$key]['name']));
201 201
                     }
202 202
                 }
203 203
                 
@@ -210,9 +210,9 @@  discard block
 block discarded – undo
210 210
      *	@param $name string service name
211 211
      *	@return array  service id
212 212
      */
213
-    public function getServiceIDByName($hostname,$name)
213
+    public function getServiceIDByName($hostname, $name)
214 214
     {
215
-        $dbConn = $this->getIdoDbConn();
215
+        $dbConn=$this->getIdoDbConn();
216 216
         if ($dbConn === null) throw new \ErrorException('uncatched db error');
217 217
         
218 218
         if ($name == null)
@@ -223,7 +223,7 @@  discard block
 block discarded – undo
223 223
         $query=$dbConn->select()
224 224
         ->from(
225 225
             array('s' => 'icinga_services'),
226
-            array('name' => 's.display_name','id' => 's.service_object_id'))
226
+            array('name' => 's.display_name', 'id' => 's.service_object_id'))
227 227
             ->join(
228 228
                 array('a' => 'icinga_objects'),
229 229
                 's.service_object_id=a.object_id',
@@ -241,14 +241,14 @@  discard block
 block discarded – undo
241 241
     public function getObjectNameByid($id)
242 242
     {
243 243
         // select a.name1, b.display_name from icinga.icinga_objects AS a , icinga.icinga_hosts AS b WHERE (b.address = '192.168.56.101' OR b.address6= '123456') and b.host_object_id=a.object_id
244
-        if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id');  }
245
-        $dbConn = $this->getIdoDbConn();
244
+        if (!preg_match('/^[0-9]+$/', $id)) { throw new Exception('Invalid id'); }
245
+        $dbConn=$this->getIdoDbConn();
246 246
         if ($dbConn === null) throw new \ErrorException('uncatched db error');
247 247
         
248 248
         $query=$dbConn->select()
249 249
         ->from(
250 250
             array('a' => 'icinga_objects'),
251
-            array('name1' => 'a.name1','name2' => 'a.name2'))
251
+            array('name1' => 'a.name1', 'name2' => 'a.name2'))
252 252
             ->where('a.object_id='.$id.' AND a.is_active = 1');
253 253
             
254 254
             return $dbConn->fetchRow($query);
Please login to merge, or discard this patch.
Braces   +28 added lines, -11 removed lines patch added patch discarded remove patch
@@ -24,7 +24,9 @@  discard block
 block discarded – undo
24 24
     {
25 25
         // select a.name1, b.display_name from icinga.icinga_objects AS a , icinga.icinga_hosts AS b WHERE (b.address = '192.168.56.101' OR b.address6= '123456') and b.host_object_id=a.object_id
26 26
         $dbConn = $this->getIdoDbConn();
27
-        if ($dbConn === null) throw new \ErrorException('uncatched db error');
27
+        if ($dbConn === null) {
28
+        	throw new \ErrorException('uncatched db error');
29
+        }
28 30
         
29 31
         // TODO : check for SQL injections
30 32
         $query=$dbConn->select()
@@ -47,7 +49,9 @@  discard block
 block discarded – undo
47 49
     {
48 50
         // select a.name1, b.display_name from icinga.icinga_objects AS a , icinga.icinga_hosts AS b WHERE (b.address = '192.168.56.101' OR b.address6= '123456') and b.host_object_id=a.object_id
49 51
         $dbConn = $this->getIdoDbConn();
50
-        if ($dbConn === null) throw new \ErrorException('uncatched db error');
52
+        if ($dbConn === null) {
53
+        	throw new \ErrorException('uncatched db error');
54
+        }
51 55
         
52 56
         // TODO : check for SQL injections
53 57
         $query=$dbConn->select()
@@ -70,7 +74,9 @@  discard block
 block discarded – undo
70 74
     {
71 75
         // select a.name1, b.display_name from icinga.icinga_objects AS a , icinga.icinga_hosts AS b WHERE (b.address = '192.168.56.101' OR b.address6= '123456') and b.host_object_id=a.object_id
72 76
         $dbConn = $this->getIdoDbConn();
73
-        if ($dbConn === null) throw new \ErrorException('uncatched db error');
77
+        if ($dbConn === null) {
78
+        	throw new \ErrorException('uncatched db error');
79
+        }
74 80
         // TODO : check for SQL injections
75 81
         $query=$dbConn->select()
76 82
         ->from(
@@ -93,7 +99,9 @@  discard block
 block discarded – undo
93 99
     {
94 100
         if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id');  }
95 101
         $dbConn = $this->getIdoDbConn();
96
-        if ($dbConn === null) throw new \ErrorException('uncatched db error');
102
+        if ($dbConn === null) {
103
+        	throw new \ErrorException('uncatched db error');
104
+        }
97 105
         $query=$dbConn->select()
98 106
         ->from(
99 107
             array('a' => 'icinga_objects'),
@@ -115,7 +123,9 @@  discard block
 block discarded – undo
115 123
     {
116 124
         if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id');  }
117 125
         $dbConn = $this->getIdoDbConn();
118
-        if ($dbConn === null) throw new \ErrorException('uncatched db error');
126
+        if ($dbConn === null) {
127
+        	throw new \ErrorException('uncatched db error');
128
+        }
119 129
         $query=$dbConn->select()
120 130
         ->from(
121 131
             array('a' => 'icinga_objects'),
@@ -138,7 +148,9 @@  discard block
 block discarded – undo
138 148
         // select a.name1, b.display_name from icinga.icinga_objects AS a , icinga.icinga_hosts AS b WHERE (b.address = '192.168.56.101' OR b.address6= '123456') and b.host_object_id=a.object_id
139 149
         if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id');  }
140 150
         $dbConn = $this->getIdoDbConn();
141
-        if ($dbConn === null) throw new \ErrorException('uncatched db error');
151
+        if ($dbConn === null) {
152
+        	throw new \ErrorException('uncatched db error');
153
+        }
142 154
         $query=$dbConn->select()
143 155
         ->from(
144 156
             array('s' => 'icinga_services'),
@@ -161,7 +173,9 @@  discard block
 block discarded – undo
161 173
     {
162 174
         if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id');  }
163 175
         $dbConn = $this->getIdoDbConn();
164
-        if ($dbConn === null) throw new \ErrorException('uncatched db error');
176
+        if ($dbConn === null) {
177
+        	throw new \ErrorException('uncatched db error');
178
+        }
165 179
         $query=$dbConn->select()
166 180
         ->from(
167 181
             array('s' => 'icinga_hostgroup_members'),
@@ -182,8 +196,7 @@  discard block
 block discarded – undo
182 196
                         if (isset($common_services[$service->name2]['num']))
183 197
                         {
184 198
                             $common_services[$service->name2]['num'] +=1;
185
-                        }
186
-                        else
199
+                        } else
187 200
                         {
188 201
                             $common_services[$service->name2]['num']=1;
189 202
                             $common_services[$service->name2]['name']=$service->name;
@@ -213,7 +226,9 @@  discard block
 block discarded – undo
213 226
     public function getServiceIDByName($hostname,$name)
214 227
     {
215 228
         $dbConn = $this->getIdoDbConn();
216
-        if ($dbConn === null) throw new \ErrorException('uncatched db error');
229
+        if ($dbConn === null) {
230
+        	throw new \ErrorException('uncatched db error');
231
+        }
217 232
         
218 233
         if ($name == null)
219 234
         {
@@ -243,7 +258,9 @@  discard block
 block discarded – undo
243 258
         // select a.name1, b.display_name from icinga.icinga_objects AS a , icinga.icinga_hosts AS b WHERE (b.address = '192.168.56.101' OR b.address6= '123456') and b.host_object_id=a.object_id
244 259
         if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id');  }
245 260
         $dbConn = $this->getIdoDbConn();
246
-        if ($dbConn === null) throw new \ErrorException('uncatched db error');
261
+        if ($dbConn === null) {
262
+        	throw new \ErrorException('uncatched db error');
263
+        }
247 264
         
248 265
         $query=$dbConn->select()
249 266
         ->from(
Please login to merge, or discard this patch.
library/Trapdirector/TrapsActions/UIDatabase.php 2 patches
Indentation   +256 added lines, -256 removed lines patch added patch discarded remove patch
@@ -19,30 +19,30 @@  discard block
 block discarded – undo
19 19
  */
20 20
 class DBException extends Exception
21 21
 {
22
-    /** @var array $returnArray */
23
-    private $returnArray;
22
+	/** @var array $returnArray */
23
+	private $returnArray;
24 24
     
25
-    /**
26
-     * Buil DBException
27
-     * @param array $retarray
28
-     * @param string $message
29
-     * @param int $code
30
-     * @param Exception $previous
31
-     */
32
-    public function __construct(array $retarray, string $message = null, int $code = 0, Exception $previous = null)
33
-    {
34
-        parent::__construct($message,$code,$previous);
35
-        $this->returnArray = $retarray;
36
-    }
25
+	/**
26
+	 * Buil DBException
27
+	 * @param array $retarray
28
+	 * @param string $message
29
+	 * @param int $code
30
+	 * @param Exception $previous
31
+	 */
32
+	public function __construct(array $retarray, string $message = null, int $code = 0, Exception $previous = null)
33
+	{
34
+		parent::__construct($message,$code,$previous);
35
+		$this->returnArray = $retarray;
36
+	}
37 37
     
38
-    /**
39
-     * Get exception array
40
-     * @return array
41
-     */
42
-    public function getArray()
43
-    {
44
-        return $this->returnArray;
45
-    }
38
+	/**
39
+	 * Get exception array
40
+	 * @return array
41
+	 */
42
+	public function getArray()
43
+	{
44
+		return $this->returnArray;
45
+	}
46 46
 }
47 47
 
48 48
 /**
@@ -56,274 +56,274 @@  discard block
 block discarded – undo
56 56
  */
57 57
 class UIDatabase //extends TrapDBQuery
58 58
 {
59
-    use TrapDBQuery,IdoDBQuery;
59
+	use TrapDBQuery,IdoDBQuery;
60 60
     
61
-    /** @var TrapsController $trapController TrapController 'parent' class */
62
-    protected  $trapController=null;
61
+	/** @var TrapsController $trapController TrapController 'parent' class */
62
+	protected  $trapController=null;
63 63
     
64
-    /** @var Selectable $trapDB Trap Database*/
65
-    protected $trapDB=null;
64
+	/** @var Selectable $trapDB Trap Database*/
65
+	protected $trapDB=null;
66 66
  
67
-    /** @var Selectable $trapDB Icinga IDO database*/
68
-    protected $idoDB=null;
67
+	/** @var Selectable $trapDB Icinga IDO database*/
68
+	protected $idoDB=null;
69 69
     
70
-    /** @var array $testResult */
71
-    protected $testResult;
70
+	/** @var array $testResult */
71
+	protected $testResult;
72 72
     
73
-    /**
74
-     * 
75
-     * @param TrapsController $trapCtrl
76
-     */
77
-    function __construct(TrapsController $trapCtrl)
78
-    {
79
-        $this->trapController=$trapCtrl;
80
-    }
73
+	/**
74
+	 * 
75
+	 * @param TrapsController $trapCtrl
76
+	 */
77
+	function __construct(TrapsController $trapCtrl)
78
+	{
79
+		$this->trapController=$trapCtrl;
80
+	}
81 81
     
82
-    protected function getTrapCtrl()
83
-    {
84
-        return $this->trapController;
85
-    }
82
+	protected function getTrapCtrl()
83
+	{
84
+		return $this->trapController;
85
+	}
86 86
     
87
-    /**
88
-     * Test if database version >= min database version
89
-     * 
90
-     * @param \Zend_Db_Adapter_Abstract $dbConn
91
-     * @param int $min Minimum version
92
-     * @param bool $test Test mode
93
-     * @param string $DBname Name of DB
94
-     * @return bool true if OK, false if version < min version
95
-     * @throws Exception if error and test = true
96
-     */
97
-    protected function testDbVersion($dbAdapter,int $min,bool $test, string $DBname)
98
-    {
99
-        try
100
-        {
101
-            $query = $dbAdapter->select()
102
-            ->from($this->trapController->getModuleConfig()->getDbConfigTableName(),'value')
103
-            ->where('name=\'db_version\'');
104
-            $version=$dbAdapter->fetchRow($query);
105
-            if ( ($version == null) || ! property_exists($version,'value') )
106
-            {
107
-                if ($test === true) 
108
-                {
109
-                    $this->testResult = array(4,$DBname);
110
-                    return false;
111
-                }
112
-                $this->trapController->redirectNow('trapdirector/settings?dberror=4');
113
-                return false;
114
-            }
115
-            if ($version->value < $min)
116
-            {
117
-                if ($test === true) 
118
-                {
119
-                    $this->testResult = array(5,$version->value,$min);
120
-                    return false;
121
-                }
122
-                $this->trapController->redirectNow('trapdirector/settings?dberror=5');
123
-                return false;
124
-            }
125
-        }
126
-        catch (Exception $e)
127
-        {
128
-            if ($test === true) 
129
-            {
130
-                $this->testResult = array(3,$DBname,$e->getMessage());
131
-                return false;
132
-            }
133
-            $this->trapController->redirectNow('trapdirector/settings?dberror=4');
134
-            return false;
135
-        }
136
-        return true;
137
-    }
87
+	/**
88
+	 * Test if database version >= min database version
89
+	 * 
90
+	 * @param \Zend_Db_Adapter_Abstract $dbConn
91
+	 * @param int $min Minimum version
92
+	 * @param bool $test Test mode
93
+	 * @param string $DBname Name of DB
94
+	 * @return bool true if OK, false if version < min version
95
+	 * @throws Exception if error and test = true
96
+	 */
97
+	protected function testDbVersion($dbAdapter,int $min,bool $test, string $DBname)
98
+	{
99
+		try
100
+		{
101
+			$query = $dbAdapter->select()
102
+			->from($this->trapController->getModuleConfig()->getDbConfigTableName(),'value')
103
+			->where('name=\'db_version\'');
104
+			$version=$dbAdapter->fetchRow($query);
105
+			if ( ($version == null) || ! property_exists($version,'value') )
106
+			{
107
+				if ($test === true) 
108
+				{
109
+					$this->testResult = array(4,$DBname);
110
+					return false;
111
+				}
112
+				$this->trapController->redirectNow('trapdirector/settings?dberror=4');
113
+				return false;
114
+			}
115
+			if ($version->value < $min)
116
+			{
117
+				if ($test === true) 
118
+				{
119
+					$this->testResult = array(5,$version->value,$min);
120
+					return false;
121
+				}
122
+				$this->trapController->redirectNow('trapdirector/settings?dberror=5');
123
+				return false;
124
+			}
125
+		}
126
+		catch (Exception $e)
127
+		{
128
+			if ($test === true) 
129
+			{
130
+				$this->testResult = array(3,$DBname,$e->getMessage());
131
+				return false;
132
+			}
133
+			$this->trapController->redirectNow('trapdirector/settings?dberror=4');
134
+			return false;
135
+		}
136
+		return true;
137
+	}
138 138
     
139
-    /**	Get Database connexion
140
-     *	@param $DBname string DB name in resource.ini_ge
141
-     *	@param $test bool if set to true, returns error code and not database
142
-     *	@param $test_version bool if set to flase, does not test database version of trapDB
143
-     *  @throws DBException if test = true and error
144
-     *	@return Selectable|null : if test=false, returns DB connexion, else array(error_num,message) or null on error.
145
-     */
146
-    protected function getDbByName($DBname , $test = false , $test_version = true)
147
-    {
148
-        try
149
-        {
150
-            $dbconn = IcingaDbConnection::fromResourceName($DBname);
151
-        }
152
-        catch (Exception $e)
153
-        {
154
-            if ($test === true) 
155
-            {
156
-                throw new DBException(array(2,$DBname));
157
-            }
158
-            $this->trapController->redirectNow('trapdirector/settings?dberror=2');
159
-            return null;
160
-        }
139
+	/**	Get Database connexion
140
+	 *	@param $DBname string DB name in resource.ini_ge
141
+	 *	@param $test bool if set to true, returns error code and not database
142
+	 *	@param $test_version bool if set to flase, does not test database version of trapDB
143
+	 *  @throws DBException if test = true and error
144
+	 *	@return Selectable|null : if test=false, returns DB connexion, else array(error_num,message) or null on error.
145
+	 */
146
+	protected function getDbByName($DBname , $test = false , $test_version = true)
147
+	{
148
+		try
149
+		{
150
+			$dbconn = IcingaDbConnection::fromResourceName($DBname);
151
+		}
152
+		catch (Exception $e)
153
+		{
154
+			if ($test === true) 
155
+			{
156
+				throw new DBException(array(2,$DBname));
157
+			}
158
+			$this->trapController->redirectNow('trapdirector/settings?dberror=2');
159
+			return null;
160
+		}
161 161
         
162
-        try
163
-        {
164
-            $dbAdapter=$dbconn->getDbAdapter();
162
+		try
163
+		{
164
+			$dbAdapter=$dbconn->getDbAdapter();
165 165
             
166
-        }
167
-        catch (Exception $e)
168
-        {
169
-            if ($test === true)
170
-            {
171
-                throw new DBException(array(3,$DBname,$e->getMessage()));
172
-            }
173
-            $this->trapController->redirectNow('trapdirector/settings?dberror=3');
174
-            return null;
175
-        }
166
+		}
167
+		catch (Exception $e)
168
+		{
169
+			if ($test === true)
170
+			{
171
+				throw new DBException(array(3,$DBname,$e->getMessage()));
172
+			}
173
+			$this->trapController->redirectNow('trapdirector/settings?dberror=3');
174
+			return null;
175
+		}
176 176
         
177
-        if ($test_version == true) {
178
-            $testRet=$this->testDbVersion($dbAdapter, $this->trapController->getModuleConfig()->getDbMinVersion(), $test, $DBname);
179
-            if ($testRet !== true) 
180
-            {
181
-                throw new DBException($this->testResult);
182
-            }
183
-        }
177
+		if ($test_version == true) {
178
+			$testRet=$this->testDbVersion($dbAdapter, $this->trapController->getModuleConfig()->getDbMinVersion(), $test, $DBname);
179
+			if ($testRet !== true) 
180
+			{
181
+				throw new DBException($this->testResult);
182
+			}
183
+		}
184 184
         
185
-        return $dbconn;
186
-    }
185
+		return $dbconn;
186
+	}
187 187
 
188
-    /**
189
-     * Get Trap database
190
-     * @return Selectable|null : returns DB connexion or null on error.
191
-     */
192
-    public function getDb()
193
-    {
194
-        if ( $this->trapDB != null ) return $this->trapDB;
188
+	/**
189
+	 * Get Trap database
190
+	 * @return Selectable|null : returns DB connexion or null on error.
191
+	 */
192
+	public function getDb()
193
+	{
194
+		if ( $this->trapDB != null ) return $this->trapDB;
195 195
         
196 196
         
197
-        $dbresource=$this->trapController->Config()->get('config', 'database');
197
+		$dbresource=$this->trapController->Config()->get('config', 'database');
198 198
         
199
-        if ( ! $dbresource )
200
-        {
201
-            $this->trapController->redirectNow('trapdirector/settings?dberror=1');
202
-            return null;
203
-        }
199
+		if ( ! $dbresource )
200
+		{
201
+			$this->trapController->redirectNow('trapdirector/settings?dberror=1');
202
+			return null;
203
+		}
204 204
 
205
-        try {
206
-            $this->trapDB = $this->getDbByName($dbresource,false,true);
207
-        } catch (DBException $e) {
208
-            return null; // Should not happen as test = false
209
-        }
205
+		try {
206
+			$this->trapDB = $this->getDbByName($dbresource,false,true);
207
+		} catch (DBException $e) {
208
+			return null; // Should not happen as test = false
209
+		}
210 210
         
211
-        //$this->trapDB->getConnection();
211
+		//$this->trapDB->getConnection();
212 212
         
213
-        return $this->trapDB;
214
-    }
213
+		return $this->trapDB;
214
+	}
215 215
 
216
-    /**
217
-     * Get Zend adapter of DB.
218
-     * @return \Zend_Db_Adapter_Abstract|null
219
-     */
220
-    public function getDbConn()
221
-    {
222
-        if ($this->getDb() == null) return null;
223
-        return $this->getDb()->getConnection();
224
-    }
216
+	/**
217
+	 * Get Zend adapter of DB.
218
+	 * @return \Zend_Db_Adapter_Abstract|null
219
+	 */
220
+	public function getDbConn()
221
+	{
222
+		if ($this->getDb() == null) return null;
223
+		return $this->getDb()->getConnection();
224
+	}
225 225
     
226
-    /**
227
-     * Test Trap database
228
-     * @param boolean $test
229
-     * @throws DBException on error.
230
-     * @return \Zend_Db_Adapter_Abstract|array|null : if test=false, returns DB connexion, else array(error_num,message) or null on error.
231
-     */
232
-    public function testGetDb()
233
-    {       
234
-        $dbresource=$this->trapController->Config()->get('config', 'database');
226
+	/**
227
+	 * Test Trap database
228
+	 * @param boolean $test
229
+	 * @throws DBException on error.
230
+	 * @return \Zend_Db_Adapter_Abstract|array|null : if test=false, returns DB connexion, else array(error_num,message) or null on error.
231
+	 */
232
+	public function testGetDb()
233
+	{       
234
+		$dbresource=$this->trapController->Config()->get('config', 'database');
235 235
         
236
-        if ( ! $dbresource )
237
-        {
238
-                throw new DBException(array(1,''));
239
-        }
236
+		if ( ! $dbresource )
237
+		{
238
+				throw new DBException(array(1,''));
239
+		}
240 240
         
241
-        $this->trapDB = $this->getDbByName($dbresource,true,true);       
242
-        return;
243
-    }
241
+		$this->trapDB = $this->getDbByName($dbresource,true,true);       
242
+		return;
243
+	}
244 244
     
245 245
 
246
-    /**
247
-     * Get IDO Database
248
-     * @return \Zend_Db_Adapter_Abstract|NULL  returns DB connexion or null on error.
249
-     */
250
-    public function getIdoDb()
251
-    {
252
-        if ( $this->idoDB != null ) return $this->idoDB;
253
-        // TODO : get ido database directly from icingaweb2 config -> (or not if using only API)
254
-        $dbresource=$this->trapController->Config()->get('config', 'IDOdatabase');;
246
+	/**
247
+	 * Get IDO Database
248
+	 * @return \Zend_Db_Adapter_Abstract|NULL  returns DB connexion or null on error.
249
+	 */
250
+	public function getIdoDb()
251
+	{
252
+		if ( $this->idoDB != null ) return $this->idoDB;
253
+		// TODO : get ido database directly from icingaweb2 config -> (or not if using only API)
254
+		$dbresource=$this->trapController->Config()->get('config', 'IDOdatabase');;
255 255
         
256
-        if ( ! $dbresource )
257
-        {
258
-            $this->trapController->redirectNow('trapdirector/settings?idodberror=1');
259
-            return null;
260
-        }
256
+		if ( ! $dbresource )
257
+		{
258
+			$this->trapController->redirectNow('trapdirector/settings?idodberror=1');
259
+			return null;
260
+		}
261 261
         
262
-        try
263
-        {
264
-            $dbconn = IcingaDbConnection::fromResourceName($dbresource);
265
-        }
266
-        catch (Exception $e)
267
-        {
268
-            $this->trapController->redirectNow('trapdirector/settings?idodberror=2');
269
-            return null;
270
-        }
262
+		try
263
+		{
264
+			$dbconn = IcingaDbConnection::fromResourceName($dbresource);
265
+		}
266
+		catch (Exception $e)
267
+		{
268
+			$this->trapController->redirectNow('trapdirector/settings?idodberror=2');
269
+			return null;
270
+		}
271 271
 
272
-        $this->idoDB = $dbconn;
273
-        return $this->idoDB;
274
-    }
272
+		$this->idoDB = $dbconn;
273
+		return $this->idoDB;
274
+	}
275 275
 
276 276
 
277
-    /**
278
-     * Get Zend adapter of DB.
279
-     * @return \Zend_Db_Adapter_Abstract|null
280
-     */
281
-    public function getIdoDbConn()
282
-    {
283
-        if ($this->getIdoDb() == null) return null;
284
-        return $this->getIdoDb()->getConnection();
285
-    }
277
+	/**
278
+	 * Get Zend adapter of DB.
279
+	 * @return \Zend_Db_Adapter_Abstract|null
280
+	 */
281
+	public function getIdoDbConn()
282
+	{
283
+		if ($this->getIdoDb() == null) return null;
284
+		return $this->getIdoDb()->getConnection();
285
+	}
286 286
     
287
-    /**
288
-     * Get IDO Database
289
-     * @param boolean $test
290
-     * @throws DBException on error
291
-     */
292
-    public function testGetIdoDb()
293
-    {
294
-        // TODO : get ido database directly from icingaweb2 config -> (or not if using only API)
295
-        $dbresource=$this->trapController->Config()->get('config', 'IDOdatabase');;
287
+	/**
288
+	 * Get IDO Database
289
+	 * @param boolean $test
290
+	 * @throws DBException on error
291
+	 */
292
+	public function testGetIdoDb()
293
+	{
294
+		// TODO : get ido database directly from icingaweb2 config -> (or not if using only API)
295
+		$dbresource=$this->trapController->Config()->get('config', 'IDOdatabase');;
296 296
         
297
-        if ( ! $dbresource )
298
-        {
299
-            throw new DBException(array(1,'No database in config.ini'));
300
-        }
297
+		if ( ! $dbresource )
298
+		{
299
+			throw new DBException(array(1,'No database in config.ini'));
300
+		}
301 301
         
302
-        try
303
-        {
304
-            $dbconn = IcingaDbConnection::fromResourceName($dbresource);
305
-        }
306
-        catch (Exception $e)
307
-        {
308
-            throw new DBException( array(2,"Database $dbresource does not exists in IcingaWeb2") );
309
-        }
302
+		try
303
+		{
304
+			$dbconn = IcingaDbConnection::fromResourceName($dbresource);
305
+		}
306
+		catch (Exception $e)
307
+		{
308
+			throw new DBException( array(2,"Database $dbresource does not exists in IcingaWeb2") );
309
+		}
310 310
                
311
-        try
312
-        {
313
-            $query = $dbconn->select()
314
-            ->from('icinga_dbversion',array('version'));
315
-            $version=$dbconn->fetchRow($query);
316
-            if ( ($version == null) || ! property_exists($version,'version') )
317
-            {
318
-                throw new DBException( array(4,"$dbresource does not look like an IDO database"));
319
-            }
320
-        }
321
-        catch (Exception $e)
322
-        {
323
-            throw new DBException( array(3,"Error connecting to $dbresource : " . $e->getMessage()));
324
-        }
311
+		try
312
+		{
313
+			$query = $dbconn->select()
314
+			->from('icinga_dbversion',array('version'));
315
+			$version=$dbconn->fetchRow($query);
316
+			if ( ($version == null) || ! property_exists($version,'version') )
317
+			{
318
+				throw new DBException( array(4,"$dbresource does not look like an IDO database"));
319
+			}
320
+		}
321
+		catch (Exception $e)
322
+		{
323
+			throw new DBException( array(3,"Error connecting to $dbresource : " . $e->getMessage()));
324
+		}
325 325
         
326
-        return;
327
-    }
326
+		return;
327
+	}
328 328
     
329 329
 }
330 330
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -29,10 +29,10 @@  discard block
 block discarded – undo
29 29
      * @param int $code
30 30
      * @param Exception $previous
31 31
      */
32
-    public function __construct(array $retarray, string $message = null, int $code = 0, Exception $previous = null)
32
+    public function __construct(array $retarray, string $message=null, int $code=0, Exception $previous=null)
33 33
     {
34
-        parent::__construct($message,$code,$previous);
35
-        $this->returnArray = $retarray;
34
+        parent::__construct($message, $code, $previous);
35
+        $this->returnArray=$retarray;
36 36
     }
37 37
     
38 38
     /**
@@ -56,7 +56,7 @@  discard block
 block discarded – undo
56 56
  */
57 57
 class UIDatabase //extends TrapDBQuery
58 58
 {
59
-    use TrapDBQuery,IdoDBQuery;
59
+    use TrapDBQuery, IdoDBQuery;
60 60
     
61 61
     /** @var TrapsController $trapController TrapController 'parent' class */
62 62
     protected  $trapController=null;
@@ -94,19 +94,19 @@  discard block
 block discarded – undo
94 94
      * @return bool true if OK, false if version < min version
95 95
      * @throws Exception if error and test = true
96 96
      */
97
-    protected function testDbVersion($dbAdapter,int $min,bool $test, string $DBname)
97
+    protected function testDbVersion($dbAdapter, int $min, bool $test, string $DBname)
98 98
     {
99 99
         try
100 100
         {
101
-            $query = $dbAdapter->select()
102
-            ->from($this->trapController->getModuleConfig()->getDbConfigTableName(),'value')
101
+            $query=$dbAdapter->select()
102
+            ->from($this->trapController->getModuleConfig()->getDbConfigTableName(), 'value')
103 103
             ->where('name=\'db_version\'');
104 104
             $version=$dbAdapter->fetchRow($query);
105
-            if ( ($version == null) || ! property_exists($version,'value') )
105
+            if (($version == null) || !property_exists($version, 'value'))
106 106
             {
107 107
                 if ($test === true) 
108 108
                 {
109
-                    $this->testResult = array(4,$DBname);
109
+                    $this->testResult=array(4, $DBname);
110 110
                     return false;
111 111
                 }
112 112
                 $this->trapController->redirectNow('trapdirector/settings?dberror=4');
@@ -116,7 +116,7 @@  discard block
 block discarded – undo
116 116
             {
117 117
                 if ($test === true) 
118 118
                 {
119
-                    $this->testResult = array(5,$version->value,$min);
119
+                    $this->testResult=array(5, $version->value, $min);
120 120
                     return false;
121 121
                 }
122 122
                 $this->trapController->redirectNow('trapdirector/settings?dberror=5');
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
         {
128 128
             if ($test === true) 
129 129
             {
130
-                $this->testResult = array(3,$DBname,$e->getMessage());
130
+                $this->testResult=array(3, $DBname, $e->getMessage());
131 131
                 return false;
132 132
             }
133 133
             $this->trapController->redirectNow('trapdirector/settings?dberror=4');
@@ -143,17 +143,17 @@  discard block
 block discarded – undo
143 143
      *  @throws DBException if test = true and error
144 144
      *	@return Selectable|null : if test=false, returns DB connexion, else array(error_num,message) or null on error.
145 145
      */
146
-    protected function getDbByName($DBname , $test = false , $test_version = true)
146
+    protected function getDbByName($DBname, $test=false, $test_version=true)
147 147
     {
148 148
         try
149 149
         {
150
-            $dbconn = IcingaDbConnection::fromResourceName($DBname);
150
+            $dbconn=IcingaDbConnection::fromResourceName($DBname);
151 151
         }
152 152
         catch (Exception $e)
153 153
         {
154 154
             if ($test === true) 
155 155
             {
156
-                throw new DBException(array(2,$DBname));
156
+                throw new DBException(array(2, $DBname));
157 157
             }
158 158
             $this->trapController->redirectNow('trapdirector/settings?dberror=2');
159 159
             return null;
@@ -168,7 +168,7 @@  discard block
 block discarded – undo
168 168
         {
169 169
             if ($test === true)
170 170
             {
171
-                throw new DBException(array(3,$DBname,$e->getMessage()));
171
+                throw new DBException(array(3, $DBname, $e->getMessage()));
172 172
             }
173 173
             $this->trapController->redirectNow('trapdirector/settings?dberror=3');
174 174
             return null;
@@ -191,19 +191,19 @@  discard block
 block discarded – undo
191 191
      */
192 192
     public function getDb()
193 193
     {
194
-        if ( $this->trapDB != null ) return $this->trapDB;
194
+        if ($this->trapDB != null) return $this->trapDB;
195 195
         
196 196
         
197 197
         $dbresource=$this->trapController->Config()->get('config', 'database');
198 198
         
199
-        if ( ! $dbresource )
199
+        if (!$dbresource)
200 200
         {
201 201
             $this->trapController->redirectNow('trapdirector/settings?dberror=1');
202 202
             return null;
203 203
         }
204 204
 
205 205
         try {
206
-            $this->trapDB = $this->getDbByName($dbresource,false,true);
206
+            $this->trapDB=$this->getDbByName($dbresource, false, true);
207 207
         } catch (DBException $e) {
208 208
             return null; // Should not happen as test = false
209 209
         }
@@ -233,12 +233,12 @@  discard block
 block discarded – undo
233 233
     {       
234 234
         $dbresource=$this->trapController->Config()->get('config', 'database');
235 235
         
236
-        if ( ! $dbresource )
236
+        if (!$dbresource)
237 237
         {
238
-                throw new DBException(array(1,''));
238
+                throw new DBException(array(1, ''));
239 239
         }
240 240
         
241
-        $this->trapDB = $this->getDbByName($dbresource,true,true);       
241
+        $this->trapDB=$this->getDbByName($dbresource, true, true);       
242 242
         return;
243 243
     }
244 244
     
@@ -249,11 +249,11 @@  discard block
 block discarded – undo
249 249
      */
250 250
     public function getIdoDb()
251 251
     {
252
-        if ( $this->idoDB != null ) return $this->idoDB;
252
+        if ($this->idoDB != null) return $this->idoDB;
253 253
         // TODO : get ido database directly from icingaweb2 config -> (or not if using only API)
254
-        $dbresource=$this->trapController->Config()->get('config', 'IDOdatabase');;
254
+        $dbresource=$this->trapController->Config()->get('config', 'IDOdatabase'); ;
255 255
         
256
-        if ( ! $dbresource )
256
+        if (!$dbresource)
257 257
         {
258 258
             $this->trapController->redirectNow('trapdirector/settings?idodberror=1');
259 259
             return null;
@@ -261,7 +261,7 @@  discard block
 block discarded – undo
261 261
         
262 262
         try
263 263
         {
264
-            $dbconn = IcingaDbConnection::fromResourceName($dbresource);
264
+            $dbconn=IcingaDbConnection::fromResourceName($dbresource);
265 265
         }
266 266
         catch (Exception $e)
267 267
         {
@@ -269,7 +269,7 @@  discard block
 block discarded – undo
269 269
             return null;
270 270
         }
271 271
 
272
-        $this->idoDB = $dbconn;
272
+        $this->idoDB=$dbconn;
273 273
         return $this->idoDB;
274 274
     }
275 275
 
@@ -292,35 +292,35 @@  discard block
 block discarded – undo
292 292
     public function testGetIdoDb()
293 293
     {
294 294
         // TODO : get ido database directly from icingaweb2 config -> (or not if using only API)
295
-        $dbresource=$this->trapController->Config()->get('config', 'IDOdatabase');;
295
+        $dbresource=$this->trapController->Config()->get('config', 'IDOdatabase'); ;
296 296
         
297
-        if ( ! $dbresource )
297
+        if (!$dbresource)
298 298
         {
299
-            throw new DBException(array(1,'No database in config.ini'));
299
+            throw new DBException(array(1, 'No database in config.ini'));
300 300
         }
301 301
         
302 302
         try
303 303
         {
304
-            $dbconn = IcingaDbConnection::fromResourceName($dbresource);
304
+            $dbconn=IcingaDbConnection::fromResourceName($dbresource);
305 305
         }
306 306
         catch (Exception $e)
307 307
         {
308
-            throw new DBException( array(2,"Database $dbresource does not exists in IcingaWeb2") );
308
+            throw new DBException(array(2, "Database $dbresource does not exists in IcingaWeb2"));
309 309
         }
310 310
                
311 311
         try
312 312
         {
313
-            $query = $dbconn->select()
314
-            ->from('icinga_dbversion',array('version'));
313
+            $query=$dbconn->select()
314
+            ->from('icinga_dbversion', array('version'));
315 315
             $version=$dbconn->fetchRow($query);
316
-            if ( ($version == null) || ! property_exists($version,'version') )
316
+            if (($version == null) || !property_exists($version, 'version'))
317 317
             {
318
-                throw new DBException( array(4,"$dbresource does not look like an IDO database"));
318
+                throw new DBException(array(4, "$dbresource does not look like an IDO database"));
319 319
             }
320 320
         }
321 321
         catch (Exception $e)
322 322
         {
323
-            throw new DBException( array(3,"Error connecting to $dbresource : " . $e->getMessage()));
323
+            throw new DBException(array(3, "Error connecting to $dbresource : ".$e->getMessage()));
324 324
         }
325 325
         
326 326
         return;
Please login to merge, or discard this patch.
application/controllers/HandlerController.php 3 patches
Indentation   +248 added lines, -249 removed lines patch added patch discarded remove patch
@@ -11,13 +11,12 @@  discard block
 block discarded – undo
11 11
 
12 12
 //use Icinga\Web\Form as Form;
13 13
 /** Rules management
14
-
15
-*/
14
+ */
16 15
 class HandlerController extends TrapsController
17 16
 {
18 17
 
19 18
 	/** index : list existing rules 
20
-	*/
19
+	 */
21 20
 	public function indexAction()
22 21
 	{	
23 22
 		$this->checkReadPermission();
@@ -41,22 +40,22 @@  discard block
 block discarded – undo
41 40
 	 */
42 41
 	public function testruleAction()
43 42
 	{
44
-	    $this->checkReadPermission();
45
-	    $this->getTabs()->add('get',array(
46
-	        'active'	=> true,
47
-	        'label'		=> $this->translate('Test Rule'),
48
-	        'url'		=> Url::fromRequest()
49
-	    ));
43
+		$this->checkReadPermission();
44
+		$this->getTabs()->add('get',array(
45
+			'active'	=> true,
46
+			'label'		=> $this->translate('Test Rule'),
47
+			'url'		=> Url::fromRequest()
48
+		));
50 49
 	    
51 50
 
52
-	    if ($this->params->get('rule') !== null) 
53
-	    {
54
-	        $this->view->rule= $this->params->get('rule');
55
-	    }
56
-	    else
57
-	    {
58
-	        $this->view->rule='';
59
-	    }
51
+		if ($this->params->get('rule') !== null) 
52
+		{
53
+			$this->view->rule= $this->params->get('rule');
54
+		}
55
+		else
56
+		{
57
+			$this->view->rule='';
58
+		}
60 59
 	}
61 60
 	
62 61
 	/**
@@ -64,31 +63,31 @@  discard block
 block discarded – undo
64 63
 	 */
65 64
 	private function add_setup_vars()
66 65
 	{
67
-	    // variables to send to view
68
-	    $this->view->hostlist=array(); // host list to input datalist
69
-	    $this->view->hostname=''; // Host name in input text
70
-	    $this->view->serviceGet=false; // Set to true to get list of service if only one host set
71
-	    $this->view->serviceSet=null; // Select service in services select (must have serviceGet=true).
72
-	    $this->view->mainoid=''; // Trap OID
73
-	    $this->view->mib=''; // Trap mib
74
-	    $this->view->name=''; // Trap name
75
-	    $this->view->trapListForMIB=array(); // Trap list if mib exists for trap
76
-	    $this->view->objectList=array(); // objects sent with trap
77
-	    $this->view->display=''; // Initial display
78
-	    $this->view->rule=''; // rule display
79
-	    $this->view->revertOK=''; // revert OK in seconds
80
-	    $this->view->hostid=-1; // normally set by javascript serviceGet()
81
-	    $this->view->ruleid=-1; // Rule id in DB for update & delete
82
-	    $this->view->setToUpdate=false; // set form as update form
83
-	    $this->view->setRuleMatch=-1; // set action on rule match (default nothing)
84
-	    $this->view->setRuleNoMatch=-1; // set action on rule no match (default nothing)
66
+		// variables to send to view
67
+		$this->view->hostlist=array(); // host list to input datalist
68
+		$this->view->hostname=''; // Host name in input text
69
+		$this->view->serviceGet=false; // Set to true to get list of service if only one host set
70
+		$this->view->serviceSet=null; // Select service in services select (must have serviceGet=true).
71
+		$this->view->mainoid=''; // Trap OID
72
+		$this->view->mib=''; // Trap mib
73
+		$this->view->name=''; // Trap name
74
+		$this->view->trapListForMIB=array(); // Trap list if mib exists for trap
75
+		$this->view->objectList=array(); // objects sent with trap
76
+		$this->view->display=''; // Initial display
77
+		$this->view->rule=''; // rule display
78
+		$this->view->revertOK=''; // revert OK in seconds
79
+		$this->view->hostid=-1; // normally set by javascript serviceGet()
80
+		$this->view->ruleid=-1; // Rule id in DB for update & delete
81
+		$this->view->setToUpdate=false; // set form as update form
82
+		$this->view->setRuleMatch=-1; // set action on rule match (default nothing)
83
+		$this->view->setRuleNoMatch=-1; // set action on rule no match (default nothing)
85 84
 	    
86
-	    $this->view->selectGroup=false; // Select by group if true
87
-	    $this->view->hostgroupid=-1; // host group id
88
-	    $this->view->serviceGroupGet=false; // Get list of service for group (set serviceSet to select one)
85
+		$this->view->selectGroup=false; // Select by group if true
86
+		$this->view->hostgroupid=-1; // host group id
87
+		$this->view->serviceGroupGet=false; // Get list of service for group (set serviceSet to select one)
89 88
 	    
90
-	    $this->view->modifier=null;
91
-	    $this->view->modified=null;
89
+		$this->view->modifier=null;
90
+		$this->view->modified=null;
92 91
 	}
93 92
 	
94 93
 	/**
@@ -97,102 +96,102 @@  discard block
 block discarded – undo
97 96
 	 */
98 97
 	private function add_from_existing($trapid)
99 98
 	{
100
-	    /********** Setup from existing trap ***************/
101
-	    // Get the full trap info
102
-	    $trapDetail=$this->getTrapDetail($trapid);
99
+		/********** Setup from existing trap ***************/
100
+		// Get the full trap info
101
+		$trapDetail=$this->getTrapDetail($trapid);
103 102
 	    
104
-	    $hostfilter=$trapDetail->source_ip;
103
+		$hostfilter=$trapDetail->source_ip;
105 104
 	    
106
-	    // Get host
107
-	    try
108
-	    {
109
-	        $hosts=$this->getUIDatabase()->getHostByIP($hostfilter);
110
-	    }
111
-	    catch (Exception $e)
112
-	    {
113
-	        $this->displayExitError('Add handler : get host by IP/Name ',$e->getMessage());
114
-	    }
105
+		// Get host
106
+		try
107
+		{
108
+			$hosts=$this->getUIDatabase()->getHostByIP($hostfilter);
109
+		}
110
+		catch (Exception $e)
111
+		{
112
+			$this->displayExitError('Add handler : get host by IP/Name ',$e->getMessage());
113
+		}
115 114
 	    
116 115
 	    
117
-	    // if one unique host found -> put id text input
118
-	    if (count($hosts)==1) {
119
-	        $this->view->hostname=$hosts[0]->name;
120
-	        //$hostid=$hosts[0]->id;
121
-	        // Tell JS to get services when page is loaded
122
-	        $this->view->serviceGet=true;
116
+		// if one unique host found -> put id text input
117
+		if (count($hosts)==1) {
118
+			$this->view->hostname=$hosts[0]->name;
119
+			//$hostid=$hosts[0]->id;
120
+			// Tell JS to get services when page is loaded
121
+			$this->view->serviceGet=true;
123 122
 	        
124
-	    }
125
-	    else
126
-	    {
127
-	        foreach($hosts as $key=>$val)
128
-	        {
129
-	            array_push($this->view->hostlist,$hosts[$key]->name);
130
-	        }
131
-	    }
123
+		}
124
+		else
125
+		{
126
+			foreach($hosts as $key=>$val)
127
+			{
128
+				array_push($this->view->hostlist,$hosts[$key]->name);
129
+			}
130
+		}
132 131
 	    
133
-	    // set up trap oid and objects received by the trap
132
+		// set up trap oid and objects received by the trap
134 133
 	    
135
-	    $this->view->mainoid=$trapDetail->trap_oid;
136
-	    if ($trapDetail->trap_name_mib != null)
137
-	    {
138
-	        $this->view->mib=$trapDetail->trap_name_mib;
139
-	        $this->view->name=$trapDetail->trap_name;
140
-	        $this->view->trapListForMIB=$this->getMIB()
141
-	        ->getTrapList($trapDetail->trap_name_mib);
142
-	    }
134
+		$this->view->mainoid=$trapDetail->trap_oid;
135
+		if ($trapDetail->trap_name_mib != null)
136
+		{
137
+			$this->view->mib=$trapDetail->trap_name_mib;
138
+			$this->view->name=$trapDetail->trap_name;
139
+			$this->view->trapListForMIB=$this->getMIB()
140
+			->getTrapList($trapDetail->trap_name_mib);
141
+		}
143 142
 	    
144
-	    // Get all objects that can be in trap from MIB
145
-	    $allObjects=$this->getMIB()->getObjectList($trapDetail->trap_oid);
146
-	    // Get all objects in current Trap
147
-	    $currentTrapObjects=$this->getTrapobjects($trapid);
148
-	    $oid_index=1;
149
-	    foreach ($currentTrapObjects as $key => $val)
150
-	    {
151
-	        $currentObjectType='Unknown';
152
-	        $currentObjectTypeEnum='Unknown';
153
-	        if (isset($allObjects[$val->oid]['type']))
154
-	        {
155
-	            $currentObjectType=$allObjects[$val->oid]['type'];
156
-	            $currentObjectTypeEnum=$allObjects[$val->oid]['type_enum'];
157
-	        }
158
-	        $currentObject=array(
159
-	            $oid_index,
160
-	            $val->oid,
161
-	            $val->oid_name_mib,
162
-	            $val->oid_name,
163
-	            $val->value,
164
-	            $currentObjectType,
165
-	            $currentObjectTypeEnum
166
-	        );
167
-	        $oid_index++;
168
-	        array_push($this->view->objectList,$currentObject);
169
-	        // set currrent object to null in allObjects
170
-	        if (isset($allObjects[$val->oid]))
171
-	        {
172
-	            $allObjects[$val->oid]=null;
173
-	        }
174
-	    }
175
-	    if ($allObjects!=null) // in case trap doesn't have objects or is not resolved
176
-	    {
177
-	        foreach ($allObjects as $key => $val)
178
-	        {
179
-	            if ($val==null) { continue; }
180
-	            array_push($this->view->objectList, array(
181
-	                $oid_index,
182
-	                $key,
183
-	                $allObjects[$key]['mib'],
184
-	                $allObjects[$key]['name'],
185
-	                '',
186
-	                $allObjects[$key]['type'],
187
-	                $allObjects[$key]['type_enum']
188
-	            ));
189
-	            $oid_index++;
190
-	        }
191
-	    }
143
+		// Get all objects that can be in trap from MIB
144
+		$allObjects=$this->getMIB()->getObjectList($trapDetail->trap_oid);
145
+		// Get all objects in current Trap
146
+		$currentTrapObjects=$this->getTrapobjects($trapid);
147
+		$oid_index=1;
148
+		foreach ($currentTrapObjects as $key => $val)
149
+		{
150
+			$currentObjectType='Unknown';
151
+			$currentObjectTypeEnum='Unknown';
152
+			if (isset($allObjects[$val->oid]['type']))
153
+			{
154
+				$currentObjectType=$allObjects[$val->oid]['type'];
155
+				$currentObjectTypeEnum=$allObjects[$val->oid]['type_enum'];
156
+			}
157
+			$currentObject=array(
158
+				$oid_index,
159
+				$val->oid,
160
+				$val->oid_name_mib,
161
+				$val->oid_name,
162
+				$val->value,
163
+				$currentObjectType,
164
+				$currentObjectTypeEnum
165
+			);
166
+			$oid_index++;
167
+			array_push($this->view->objectList,$currentObject);
168
+			// set currrent object to null in allObjects
169
+			if (isset($allObjects[$val->oid]))
170
+			{
171
+				$allObjects[$val->oid]=null;
172
+			}
173
+		}
174
+		if ($allObjects!=null) // in case trap doesn't have objects or is not resolved
175
+		{
176
+			foreach ($allObjects as $key => $val)
177
+			{
178
+				if ($val==null) { continue; }
179
+				array_push($this->view->objectList, array(
180
+					$oid_index,
181
+					$key,
182
+					$allObjects[$key]['mib'],
183
+					$allObjects[$key]['name'],
184
+					'',
185
+					$allObjects[$key]['type'],
186
+					$allObjects[$key]['type_enum']
187
+				));
188
+				$oid_index++;
189
+			}
190
+		}
192 191
 	    
193
-	    // Add a simple display
194
-	    $this->view->display='Trap '.$trapDetail->trap_name.' received';
195
-	    $this->view->create_basic_rule=true;
192
+		// Add a simple display
193
+		$this->view->display='Trap '.$trapDetail->trap_name.' received';
194
+		$this->view->create_basic_rule=true;
196 195
 	}
197 196
 
198 197
 	/**
@@ -201,29 +200,29 @@  discard block
 block discarded – undo
201 200
 	 */
202 201
 	private function add_check_host_exists($ruleDetail)
203 202
 	{
204
-	    // Check if hostname still exists
205
-	    $host_get=$this->getUIDatabase()->getHostByName($this->view->hostname);
203
+		// Check if hostname still exists
204
+		$host_get=$this->getUIDatabase()->getHostByName($this->view->hostname);
206 205
 	    
207
-	    if (count($host_get)==0)
208
-	    {
209
-	        $this->view->warning_message='Host '.$this->view->hostname. ' doesn\'t exists anymore';
210
-	        $this->view->serviceGet=false;
211
-	    }
212
-	    else
213
-	    {
214
-	        // Tell JS to get services when page is loaded
215
-	        $this->view->serviceGet=true;
216
-	        // get service id for form to set :
217
-	        $serviceID=$this->getUIDatabase()->getServiceIDByName($this->view->hostname,$ruleDetail->service_name);
218
-	        if (count($serviceID) ==0)
219
-	        {
220
-	            $this->view->warning_message=' Service '.$ruleDetail->service_name. ' doesn\'t exists anymore';
221
-	        }
222
-	        else
223
-	        {
224
-	            $this->view->serviceSet=$serviceID[0]->id;
225
-	        }
226
-	    }
206
+		if (count($host_get)==0)
207
+		{
208
+			$this->view->warning_message='Host '.$this->view->hostname. ' doesn\'t exists anymore';
209
+			$this->view->serviceGet=false;
210
+		}
211
+		else
212
+		{
213
+			// Tell JS to get services when page is loaded
214
+			$this->view->serviceGet=true;
215
+			// get service id for form to set :
216
+			$serviceID=$this->getUIDatabase()->getServiceIDByName($this->view->hostname,$ruleDetail->service_name);
217
+			if (count($serviceID) ==0)
218
+			{
219
+				$this->view->warning_message=' Service '.$ruleDetail->service_name. ' doesn\'t exists anymore';
220
+			}
221
+			else
222
+			{
223
+				$this->view->serviceSet=$serviceID[0]->id;
224
+			}
225
+		}
227 226
 	}
228 227
 
229 228
 	/**
@@ -232,33 +231,33 @@  discard block
 block discarded – undo
232 231
 	 */
233 232
 	private function add_check_hostgroup_exists($ruleDetail)
234 233
 	{
235
-	    // Check if groupe exists
236
-	    $group_get=$this->getUIDatabase()->getHostGroupByName($this->view->hostgroupname);
237
-	    if (count($group_get)==0)
238
-	    {
239
-	        $this->view->warning_message='HostGroup '.$this->view->hostgroupname. ' doesn\'t exists anymore';
240
-	        $this->view->serviceGroupGet=false;
241
-	    }
242
-	    else
243
-	    {
244
-	        $grpServices=$this->getUIDatabase()->getServicesByHostGroupid($group_get[0]->id);
245
-	        $foundGrpService=0;
246
-	        foreach ($grpServices as $grpService)
247
-	        {
248
-	            if ($grpService[0] == $ruleDetail->service_name)
249
-	            {
250
-	                $foundGrpService=1;
251
-	                $this->view->serviceSet=$ruleDetail->service_name;
252
-	            }
253
-	        }
234
+		// Check if groupe exists
235
+		$group_get=$this->getUIDatabase()->getHostGroupByName($this->view->hostgroupname);
236
+		if (count($group_get)==0)
237
+		{
238
+			$this->view->warning_message='HostGroup '.$this->view->hostgroupname. ' doesn\'t exists anymore';
239
+			$this->view->serviceGroupGet=false;
240
+		}
241
+		else
242
+		{
243
+			$grpServices=$this->getUIDatabase()->getServicesByHostGroupid($group_get[0]->id);
244
+			$foundGrpService=0;
245
+			foreach ($grpServices as $grpService)
246
+			{
247
+				if ($grpService[0] == $ruleDetail->service_name)
248
+				{
249
+					$foundGrpService=1;
250
+					$this->view->serviceSet=$ruleDetail->service_name;
251
+				}
252
+			}
254 253
 	        
255
-	        // Tell JS to get services when page is loaded
256
-	        $this->view->serviceGroupGet=true;
257
-	        if ($foundGrpService==0)
258
-	        {
259
-	            $this->view->warning_message.=' Service '.$ruleDetail->service_name. ' doesn\'t exists anymore';
260
-	        }
261
-	    }
254
+			// Tell JS to get services when page is loaded
255
+			$this->view->serviceGroupGet=true;
256
+			if ($foundGrpService==0)
257
+			{
258
+				$this->view->warning_message.=' Service '.$ruleDetail->service_name. ' doesn\'t exists anymore';
259
+			}
260
+		}
262 261
 	}
263 262
 	
264 263
 	/**
@@ -270,52 +269,52 @@  discard block
 block discarded – undo
270 269
 	 */
271 270
 	private function add_create_trap_object_list(&$display, &$rule)
272 271
 	{
273
-	    $curObjectList=array();
274
-	    $index=1;
275
-	    // check in display & rule for : OID(<oid>)
276
-	    $matches=array();
277
-	    while ( preg_match('/_OID\(([\.0-9\*]+)\)/',$display,$matches) ||
278
-	        preg_match('/_OID\(([\.0-9\*]+)\)/',$rule,$matches))
279
-	    {
280
-	        $curOid=$matches[1];
272
+		$curObjectList=array();
273
+		$index=1;
274
+		// check in display & rule for : OID(<oid>)
275
+		$matches=array();
276
+		while ( preg_match('/_OID\(([\.0-9\*]+)\)/',$display,$matches) ||
277
+			preg_match('/_OID\(([\.0-9\*]+)\)/',$rule,$matches))
278
+		{
279
+			$curOid=$matches[1];
281 280
 	        
282
-	        if ( (preg_match('/\*/',$curOid) == 0 ) 
283
-	            && ($object=$this->getMIB()->translateOID($curOid)) != null)
284
-	        {
285
-	            array_push($curObjectList, array(
286
-	                $index,
287
-	                $curOid,
288
-	                $object['mib'],
289
-	                $object['name'],
290
-	                '',
291
-	                $object['type'],
292
-	                $object['type_enum']
293
-	            ));
294
-	        }
295
-	        else
296
-	        {
297
-	            array_push($curObjectList, array(
298
-	                $index,
299
-	                $curOid,
300
-	                'not found',
301
-	                'not found',
302
-	                '',
303
-	                'not found',
304
-	                'not found'
305
-	            ));
306
-	        }
307
-	        $curOid = preg_replace('/\*/','\*',$curOid);
308
-	        $display=preg_replace('/_OID\('.$curOid.'\)/','\$'.$index.'\$',$display);
309
-	        $rule=preg_replace('/_OID\('.$curOid.'\)/','\$'.$index.'\$',$rule);
310
-	        $index++;
311
-	    }
312
-	    return $curObjectList;
281
+			if ( (preg_match('/\*/',$curOid) == 0 ) 
282
+				&& ($object=$this->getMIB()->translateOID($curOid)) != null)
283
+			{
284
+				array_push($curObjectList, array(
285
+					$index,
286
+					$curOid,
287
+					$object['mib'],
288
+					$object['name'],
289
+					'',
290
+					$object['type'],
291
+					$object['type_enum']
292
+				));
293
+			}
294
+			else
295
+			{
296
+				array_push($curObjectList, array(
297
+					$index,
298
+					$curOid,
299
+					'not found',
300
+					'not found',
301
+					'',
302
+					'not found',
303
+					'not found'
304
+				));
305
+			}
306
+			$curOid = preg_replace('/\*/','\*',$curOid);
307
+			$display=preg_replace('/_OID\('.$curOid.'\)/','\$'.$index.'\$',$display);
308
+			$rule=preg_replace('/_OID\('.$curOid.'\)/','\$'.$index.'\$',$rule);
309
+			$index++;
310
+		}
311
+		return $curObjectList;
313 312
 	}
314 313
 	
315 314
 	/** Add a handler  
316
-	*	Get params fromid : setup from existing trap (id of trap table)
317
-	*	Get param ruleid : edit from existing handler (id of rule table)
318
-	*/
315
+	 *	Get params fromid : setup from existing trap (id of trap table)
316
+	 *	Get param ruleid : edit from existing handler (id of rule table)
317
+	 */
319 318
 	public function addAction()
320 319
 	{
321 320
 		$this->checkConfigPermission();
@@ -334,8 +333,8 @@  discard block
 block discarded – undo
334 333
 		//$this->view->trapvalues=false; // Set to true to display 'value' colum in objects
335 334
 		
336 335
 		if (($trapid = $this->params->get('fromid')) !== null) {
337
-		    /********** Setup from existing trap ***************/
338
-            $this->add_from_existing($trapid);
336
+			/********** Setup from existing trap ***************/
337
+			$this->add_from_existing($trapid);
339 338
 			return;
340 339
 		}
341 340
 		
@@ -360,14 +359,14 @@  discard block
 block discarded – undo
360 359
 			$this->view->warning_message='';
361 360
 			if ($this->view->hostname != null)
362 361
 			{
363
-			    $this->view->selectGroup=false;
364
-			    // Check if hostname still exists
365
-			    $this->add_check_host_exists($ruleDetail);
362
+				$this->view->selectGroup=false;
363
+				// Check if hostname still exists
364
+				$this->add_check_host_exists($ruleDetail);
366 365
 			}
367 366
 			else
368 367
 			{
369
-			    $this->view->selectGroup=true;
370
-			    $this->add_check_hostgroup_exists($ruleDetail); //  Check if groupe exists				
368
+				$this->view->selectGroup=true;
369
+				$this->add_check_hostgroup_exists($ruleDetail); //  Check if groupe exists				
371 370
 			}
372 371
 			
373 372
 			$this->view->mainoid=$ruleDetail->trap_oid;
@@ -395,9 +394,9 @@  discard block
 block discarded – undo
395 394
 	}
396 395
 	
397 396
 	/** Validate form and output message to user  
398
-	*	@param in postdata 
399
-	* 	@return string status : OK / <Message>
400
-	**/
397
+	 *	@param in postdata 
398
+	 * 	@return string status : OK / <Message>
399
+	 **/
401 400
 	protected function handlerformAction()
402 401
 	{
403 402
 		$postData=$this->getRequest()->getPost();
@@ -428,7 +427,7 @@  discard block
 block discarded – undo
428 427
 		{
429 428
 			try
430 429
 			{
431
-			    $this->getUIDatabase()->deleteRule($postData[$params['db_rule']['post']]);
430
+				$this->getUIDatabase()->deleteRule($postData[$params['db_rule']['post']]);
432 431
 			}
433 432
 			catch (Exception $e)
434 433
 			{
@@ -438,7 +437,7 @@  discard block
 block discarded – undo
438 437
 			//$this->Module()->
439 438
 			$this->_helper->json(array(
440 439
 				'status'=>'OK',
441
-			    'redirect'=>'trapdirector/handler'
440
+				'redirect'=>'trapdirector/handler'
442 441
 			      
443 442
 			));
444 443
 		}		
@@ -465,7 +464,7 @@  discard block
 block discarded – undo
465 464
 			$isHostGroup=($params['hostgroup']['val'] == 1)?true:false;
466 465
 			if (! $isHostGroup ) 
467 466
 			{  // checks if selection by host 
468
-			    $hostAddr=$this->getUIDatabase()->getHostInfoByID($params['hostid']['val']);
467
+				$hostAddr=$this->getUIDatabase()->getHostInfoByID($params['hostid']['val']);
469 468
 				$params['ip4']['val']=$hostAddr->ip4;
470 469
 				$params['ip6']['val']=$hostAddr->ip6;
471 470
 				$checkHostName=$hostAddr->name;
@@ -483,7 +482,7 @@  discard block
 block discarded – undo
483 482
 			}
484 483
 			else
485 484
 			{
486
-			    $object=$this->getUIDatabase()->getObjectNameByid($params['hostid']['val']);
485
+				$object=$this->getUIDatabase()->getObjectNameByid($params['hostid']['val']);
487 486
 				if ($params['host_name']['val'] != $object->name1)
488 487
 				{
489 488
 					$this->_helper->json(array('status'=>"Invalid object group id : Please re enter service"));
@@ -504,11 +503,11 @@  discard block
 block discarded – undo
504 503
 			// echo '<br>';	print_r($dbparams);echo '<br>';
505 504
 			if ($params['db_rule']['val'] == -1 ) 
506 505
 			{
507
-			    $ruleID=$this->getUIDatabase()->addHandlerRule($dbparams);
506
+				$ruleID=$this->getUIDatabase()->addHandlerRule($dbparams);
508 507
 			}
509 508
 			else
510 509
 			{
511
-			    $this->getUIDatabase()->updateHandlerRule($dbparams,$params['db_rule']['val']);
510
+				$this->getUIDatabase()->updateHandlerRule($dbparams,$params['db_rule']['val']);
512 511
 				$ruleID=$params['db_rule']['val'];
513 512
 			}
514 513
 		}
@@ -522,9 +521,9 @@  discard block
 block discarded – undo
522 521
 	}
523 522
 
524 523
 	/** Get trap detail by trapid. 
525
-	*	@param integer $trapid : id of trap in received table
526
-	*	@return array (objects)
527
-	*/
524
+	 *	@param integer $trapid : id of trap in received table
525
+	 *	@return array (objects)
526
+	 */
528 527
 	protected function getTrapDetail($trapid) 
529 528
 	{
530 529
 		if (!preg_match('/^[0-9]+$/',$trapid)) { throw new Exception('Invalid id');  }
@@ -540,14 +539,14 @@  discard block
 block discarded – undo
540 539
 		}
541 540
 		try
542 541
 		{		
543
-		    $query = $dbConn->select()
542
+			$query = $dbConn->select()
544 543
 				->from($this->getModuleConfig()->getTrapTableName(),$elmts)
545 544
 				->where('id=?',$trapid);
546 545
 				$trapDetail=$dbConn->fetchRow($query);
547 546
 			if ( $trapDetail == null ) 
548 547
 			{
549
-			    $trapDetail = 'NULL';
550
-			    throw new Exception('No traps was found with id = '.$trapid);
548
+				$trapDetail = 'NULL';
549
+				throw new Exception('No traps was found with id = '.$trapid);
551 550
 			}
552 551
 		}
553 552
 		catch (Exception $e)
@@ -561,9 +560,9 @@  discard block
 block discarded – undo
561 560
 	}
562 561
 
563 562
 	/** Get trap objects
564
-	*	@param integer $trapid : trap id
565
-	* 	@return array : full column in db of trap id
566
-	*/
563
+	 *	@param integer $trapid : trap id
564
+	 * 	@return array : full column in db of trap id
565
+	 */
567 566
 	protected function getTrapobjects($trapid)
568 567
 	{	
569 568
 		if (!preg_match('/^[0-9]+$/',$trapid)) { throw new Exception('Invalid id');  }
@@ -579,7 +578,7 @@  discard block
 block discarded – undo
579 578
 		}
580 579
 		try
581 580
 		{		
582
-		    $query = $dbConn->select()
581
+			$query = $dbConn->select()
583 582
 				->from($this->moduleConfig->getTrapDataTableName(),$data_elmts)
584 583
 				->where('trap_id=?',$trapid);
585 584
 				$trapDetail=$dbConn->fetchAll($query);
@@ -595,10 +594,10 @@  discard block
 block discarded – undo
595 594
 	}
596 595
 
597 596
 	/** Get rule detail by ruleid.
598
-	*	@param integer $ruleid int id of rule in rule table
599
-	*	@return object : column objects in db 
600
-	*
601
-	*/
597
+	 *	@param integer $ruleid int id of rule in rule table
598
+	 *	@return object : column objects in db 
599
+	 *
600
+	 */
602 601
 	protected function getRuleDetail($ruleid) 
603 602
 	{
604 603
 		if (!preg_match('/^[0-9]+$/',$ruleid)) { throw new Exception('Invalid id');  }
@@ -609,7 +608,7 @@  discard block
 block discarded – undo
609 608
 		// ***************  Get main data
610 609
 		try
611 610
 		{		
612
-		    $query = $dbConn->select()
611
+			$query = $dbConn->select()
613 612
 				->from($this->getModuleConfig()->getTrapRuleName(),$queryArray)
614 613
 				->where('id=?',$ruleid);
615 614
 			$ruleDetail=$dbConn->fetchRow($query);
@@ -626,7 +625,7 @@  discard block
 block discarded – undo
626 625
 	}
627 626
 
628 627
 	/** Setup tabs for rules 
629
-	*/
628
+	 */
630 629
 	protected function prepareTabs()
631 630
 	{
632 631
 		return $this->getTabs()->add('status', array(
Please login to merge, or discard this patch.
Spacing   +81 added lines, -81 removed lines patch added patch discarded remove patch
@@ -23,16 +23,16 @@  discard block
 block discarded – undo
23 23
 		$this->checkReadPermission();
24 24
 		$this->prepareTabs()->activate('status');
25 25
 
26
-		$dbConn = $this->getUIDatabase()->getDb();
26
+		$dbConn=$this->getUIDatabase()->getDb();
27 27
 		if ($dbConn === null) throw new \ErrorException('uncatched db error');
28 28
 		
29 29
 		$this->getHandlerListTable()->setConnection($dbConn);
30 30
 		$this->getHandlerListTable()->setMibloader($this->getMIB());
31 31
 		// Apply pagination limits 
32
-		$this->view->table=$this->applyPaginationLimits($this->getHandlerListTable(),$this->getModuleConfig()->itemListDisplay());		
32
+		$this->view->table=$this->applyPaginationLimits($this->getHandlerListTable(), $this->getModuleConfig()->itemListDisplay());		
33 33
 		
34 34
 		// Set Filter
35
-		$this->view->filterEditor = $this->getHandlerListTable()->getFilterEditor($this->getRequest());		
35
+		$this->view->filterEditor=$this->getHandlerListTable()->getFilterEditor($this->getRequest());		
36 36
 	
37 37
 		//$this->displayExitError('Handler/indexAction','Not implemented');
38 38
 	}
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
 	public function testruleAction()
43 43
 	{
44 44
 	    $this->checkReadPermission();
45
-	    $this->getTabs()->add('get',array(
45
+	    $this->getTabs()->add('get', array(
46 46
 	        'active'	=> true,
47 47
 	        'label'		=> $this->translate('Test Rule'),
48 48
 	        'url'		=> Url::fromRequest()
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
 
52 52
 	    if ($this->params->get('rule') !== null) 
53 53
 	    {
54
-	        $this->view->rule= $this->params->get('rule');
54
+	        $this->view->rule=$this->params->get('rule');
55 55
 	    }
56 56
 	    else
57 57
 	    {
@@ -110,12 +110,12 @@  discard block
 block discarded – undo
110 110
 	    }
111 111
 	    catch (Exception $e)
112 112
 	    {
113
-	        $this->displayExitError('Add handler : get host by IP/Name ',$e->getMessage());
113
+	        $this->displayExitError('Add handler : get host by IP/Name ', $e->getMessage());
114 114
 	    }
115 115
 	    
116 116
 	    
117 117
 	    // if one unique host found -> put id text input
118
-	    if (count($hosts)==1) {
118
+	    if (count($hosts) == 1) {
119 119
 	        $this->view->hostname=$hosts[0]->name;
120 120
 	        //$hostid=$hosts[0]->id;
121 121
 	        // Tell JS to get services when page is loaded
@@ -124,9 +124,9 @@  discard block
 block discarded – undo
124 124
 	    }
125 125
 	    else
126 126
 	    {
127
-	        foreach($hosts as $key=>$val)
127
+	        foreach ($hosts as $key=>$val)
128 128
 	        {
129
-	            array_push($this->view->hostlist,$hosts[$key]->name);
129
+	            array_push($this->view->hostlist, $hosts[$key]->name);
130 130
 	        }
131 131
 	    }
132 132
 	    
@@ -165,18 +165,18 @@  discard block
 block discarded – undo
165 165
 	            $currentObjectTypeEnum
166 166
 	        );
167 167
 	        $oid_index++;
168
-	        array_push($this->view->objectList,$currentObject);
168
+	        array_push($this->view->objectList, $currentObject);
169 169
 	        // set currrent object to null in allObjects
170 170
 	        if (isset($allObjects[$val->oid]))
171 171
 	        {
172 172
 	            $allObjects[$val->oid]=null;
173 173
 	        }
174 174
 	    }
175
-	    if ($allObjects!=null) // in case trap doesn't have objects or is not resolved
175
+	    if ($allObjects != null) // in case trap doesn't have objects or is not resolved
176 176
 	    {
177 177
 	        foreach ($allObjects as $key => $val)
178 178
 	        {
179
-	            if ($val==null) { continue; }
179
+	            if ($val == null) { continue; }
180 180
 	            array_push($this->view->objectList, array(
181 181
 	                $oid_index,
182 182
 	                $key,
@@ -204,9 +204,9 @@  discard block
 block discarded – undo
204 204
 	    // Check if hostname still exists
205 205
 	    $host_get=$this->getUIDatabase()->getHostByName($this->view->hostname);
206 206
 	    
207
-	    if (count($host_get)==0)
207
+	    if (count($host_get) == 0)
208 208
 	    {
209
-	        $this->view->warning_message='Host '.$this->view->hostname. ' doesn\'t exists anymore';
209
+	        $this->view->warning_message='Host '.$this->view->hostname.' doesn\'t exists anymore';
210 210
 	        $this->view->serviceGet=false;
211 211
 	    }
212 212
 	    else
@@ -214,10 +214,10 @@  discard block
 block discarded – undo
214 214
 	        // Tell JS to get services when page is loaded
215 215
 	        $this->view->serviceGet=true;
216 216
 	        // get service id for form to set :
217
-	        $serviceID=$this->getUIDatabase()->getServiceIDByName($this->view->hostname,$ruleDetail->service_name);
218
-	        if (count($serviceID) ==0)
217
+	        $serviceID=$this->getUIDatabase()->getServiceIDByName($this->view->hostname, $ruleDetail->service_name);
218
+	        if (count($serviceID) == 0)
219 219
 	        {
220
-	            $this->view->warning_message=' Service '.$ruleDetail->service_name. ' doesn\'t exists anymore';
220
+	            $this->view->warning_message=' Service '.$ruleDetail->service_name.' doesn\'t exists anymore';
221 221
 	        }
222 222
 	        else
223 223
 	        {
@@ -234,9 +234,9 @@  discard block
 block discarded – undo
234 234
 	{
235 235
 	    // Check if groupe exists
236 236
 	    $group_get=$this->getUIDatabase()->getHostGroupByName($this->view->hostgroupname);
237
-	    if (count($group_get)==0)
237
+	    if (count($group_get) == 0)
238 238
 	    {
239
-	        $this->view->warning_message='HostGroup '.$this->view->hostgroupname. ' doesn\'t exists anymore';
239
+	        $this->view->warning_message='HostGroup '.$this->view->hostgroupname.' doesn\'t exists anymore';
240 240
 	        $this->view->serviceGroupGet=false;
241 241
 	    }
242 242
 	    else
@@ -254,9 +254,9 @@  discard block
 block discarded – undo
254 254
 	        
255 255
 	        // Tell JS to get services when page is loaded
256 256
 	        $this->view->serviceGroupGet=true;
257
-	        if ($foundGrpService==0)
257
+	        if ($foundGrpService == 0)
258 258
 	        {
259
-	            $this->view->warning_message.=' Service '.$ruleDetail->service_name. ' doesn\'t exists anymore';
259
+	            $this->view->warning_message.=' Service '.$ruleDetail->service_name.' doesn\'t exists anymore';
260 260
 	        }
261 261
 	    }
262 262
 	}
@@ -274,12 +274,12 @@  discard block
 block discarded – undo
274 274
 	    $index=1;
275 275
 	    // check in display & rule for : OID(<oid>)
276 276
 	    $matches=array();
277
-	    while ( preg_match('/_OID\(([\.0-9\*]+)\)/',$display,$matches) ||
278
-	        preg_match('/_OID\(([\.0-9\*]+)\)/',$rule,$matches))
277
+	    while (preg_match('/_OID\(([\.0-9\*]+)\)/', $display, $matches) ||
278
+	        preg_match('/_OID\(([\.0-9\*]+)\)/', $rule, $matches))
279 279
 	    {
280 280
 	        $curOid=$matches[1];
281 281
 	        
282
-	        if ( (preg_match('/\*/',$curOid) == 0 ) 
282
+	        if ((preg_match('/\*/', $curOid) == 0) 
283 283
 	            && ($object=$this->getMIB()->translateOID($curOid)) != null)
284 284
 	        {
285 285
 	            array_push($curObjectList, array(
@@ -304,9 +304,9 @@  discard block
 block discarded – undo
304 304
 	                'not found'
305 305
 	            ));
306 306
 	        }
307
-	        $curOid = preg_replace('/\*/','\*',$curOid);
308
-	        $display=preg_replace('/_OID\('.$curOid.'\)/','\$'.$index.'\$',$display);
309
-	        $rule=preg_replace('/_OID\('.$curOid.'\)/','\$'.$index.'\$',$rule);
307
+	        $curOid=preg_replace('/\*/', '\*', $curOid);
308
+	        $display=preg_replace('/_OID\('.$curOid.'\)/', '\$'.$index.'\$', $display);
309
+	        $rule=preg_replace('/_OID\('.$curOid.'\)/', '\$'.$index.'\$', $rule);
310 310
 	        $index++;
311 311
 	    }
312 312
 	    return $curObjectList;
@@ -320,7 +320,7 @@  discard block
 block discarded – undo
320 320
 	{
321 321
 		$this->checkConfigPermission();
322 322
 		// set up tab
323
-		$this->getTabs()->add('get',array(
323
+		$this->getTabs()->add('get', array(
324 324
 			'active'	=> true,
325 325
 			'label'		=> $this->translate('Add handler'),
326 326
 			'url'		=> Url::fromRequest()
@@ -333,7 +333,7 @@  discard block
 block discarded – undo
333 333
 		
334 334
 		//$this->view->trapvalues=false; // Set to true to display 'value' colum in objects
335 335
 		
336
-		if (($trapid = $this->params->get('fromid')) !== null) {
336
+		if (($trapid=$this->params->get('fromid')) !== null) {
337 337
 		    /********** Setup from existing trap ***************/
338 338
             $this->add_from_existing($trapid);
339 339
 			return;
@@ -353,7 +353,7 @@  discard block
 block discarded – undo
353 353
 			$this->view->setRuleMatch=$ruleDetail->action_match;
354 354
 			$this->view->setRuleNoMatch=$ruleDetail->action_nomatch;
355 355
 			$this->view->hostgroupname=$ruleDetail->host_group_name;
356
-			$this->view->modified=gmdate("Y-m-d\TH:i:s\Z",$ruleDetail->modified);
356
+			$this->view->modified=gmdate("Y-m-d\TH:i:s\Z", $ruleDetail->modified);
357 357
 			$this->view->modifier=$ruleDetail->modifier;
358 358
 			
359 359
 			// Warning message if host/service don't exists anymore
@@ -405,26 +405,26 @@  discard block
 block discarded – undo
405 405
 	
406 406
 		$params=array(
407 407
 			// id (also db) => 	array('post' => post id, 'val' => default val, 'db' => send to table)
408
-			'hostgroup'		=>	array('post' => 'hostgroup','db'=>false),
409
-			'db_rule'		=>	array('post' => 'db_rule','db'=>false),
410
-			'hostid'		=>	array('post' => 'hostid','db'=>false),
411
-			'host_name'		=>	array('post' => 'hostname','val' => null,'db'=>true),
412
-			'host_group_name'=>	array('post' => null,'val' => null,'db'=>true),
413
-			'serviceid'		=>	array('post' => 'serviceid','db'=>false),
414
-			'service_name'	=>	array('post' => 'serviceName','db'=>true),
415
-			'trap_oid'		=>	array('post' => 'oid','db'=>true),
416
-			'revert_ok'		=>	array('post' => 'revertOK','val' => 0,'db'=>true),
417
-			'display'		=>	array('post' => 'display','val' => '','db'=>true),
418
-			'rule'			=>	array('post' => 'rule','val' => '','db'=>true),			
419
-			'action_match'	=>	array('post' => 'ruleMatch','val' => -1,'db'=>true),
420
-			'action_nomatch'=>	array('post' => 'ruleNoMatch','val' => -1,'db'=>true),					
421
-			'ip4'			=>	array('post' => null,'val' => null,'db'=>true),
422
-			'ip6'			=>	array('post' => null,'val' => null,'db'=>true),
423
-			'action_form'	=>	array('post' => 'action_form','db'=>false)
408
+			'hostgroup'		=>	array('post' => 'hostgroup', 'db'=>false),
409
+			'db_rule'		=>	array('post' => 'db_rule', 'db'=>false),
410
+			'hostid'		=>	array('post' => 'hostid', 'db'=>false),
411
+			'host_name'		=>	array('post' => 'hostname', 'val' => null, 'db'=>true),
412
+			'host_group_name'=>	array('post' => null, 'val' => null, 'db'=>true),
413
+			'serviceid'		=>	array('post' => 'serviceid', 'db'=>false),
414
+			'service_name'	=>	array('post' => 'serviceName', 'db'=>true),
415
+			'trap_oid'		=>	array('post' => 'oid', 'db'=>true),
416
+			'revert_ok'		=>	array('post' => 'revertOK', 'val' => 0, 'db'=>true),
417
+			'display'		=>	array('post' => 'display', 'val' => '', 'db'=>true),
418
+			'rule'			=>	array('post' => 'rule', 'val' => '', 'db'=>true),			
419
+			'action_match'	=>	array('post' => 'ruleMatch', 'val' => -1, 'db'=>true),
420
+			'action_nomatch'=>	array('post' => 'ruleNoMatch', 'val' => -1, 'db'=>true),					
421
+			'ip4'			=>	array('post' => null, 'val' => null, 'db'=>true),
422
+			'ip6'			=>	array('post' => null, 'val' => null, 'db'=>true),
423
+			'action_form'	=>	array('post' => 'action_form', 'db'=>false)
424 424
 		);
425 425
 		
426 426
 		if (isset($postData[$params['action_form']['post']]) 
427
-			&& $postData[$params['action_form']['post']] == 'delete' )
427
+			&& $postData[$params['action_form']['post']] == 'delete')
428 428
 		{
429 429
 			try
430 430
 			{
@@ -444,16 +444,16 @@  discard block
 block discarded – undo
444 444
 		}		
445 445
 		foreach (array_keys($params) as $key)
446 446
 		{
447
-			if ($params[$key]['post']==null) continue; // data not sent in post vars
448
-			if (! isset($postData[$params[$key]['post']]))
447
+			if ($params[$key]['post'] == null) continue; // data not sent in post vars
448
+			if (!isset($postData[$params[$key]['post']]))
449 449
 			{
450 450
 				// should not happen as the js checks data
451
-				$this->_helper->json(array('status'=>'No ' . $key));
451
+				$this->_helper->json(array('status'=>'No '.$key));
452 452
 			}
453 453
 			else
454 454
 			{
455 455
 				$data=$postData[$params[$key]['post']];
456
-				if ($data!=null && $data !="")
456
+				if ($data != null && $data != "")
457 457
 				{
458 458
 					$params[$key]['val']=$postData[$params[$key]['post']];
459 459
 				}
@@ -462,8 +462,8 @@  discard block
 block discarded – undo
462 462
 
463 463
 		try 
464 464
 		{
465
-			$isHostGroup=($params['hostgroup']['val'] == 1)?true:false;
466
-			if (! $isHostGroup ) 
465
+			$isHostGroup=($params['hostgroup']['val'] == 1) ?true:false;
466
+			if (!$isHostGroup) 
467 467
 			{  // checks if selection by host 
468 468
 			    $hostAddr=$this->getUIDatabase()->getHostInfoByID($params['hostid']['val']);
469 469
 				$params['ip4']['val']=$hostAddr->ip4;
@@ -490,25 +490,25 @@  discard block
 block discarded – undo
490 490
 					return;					
491 491
 				}
492 492
 				// Put param in correct column (group_name)
493
-				$params['host_group_name']['val'] = $params['host_name']['val'];
493
+				$params['host_group_name']['val']=$params['host_name']['val'];
494 494
 				$params['host_name']['val']=null;
495 495
 			}
496 496
 			$dbparams=array();
497 497
 			foreach ($params as $key=>$val)
498 498
 			{
499
-				if ($val['db']==true )
499
+				if ($val['db'] == true)
500 500
 				{
501
-					$dbparams[$key] = $val['val'];
501
+					$dbparams[$key]=$val['val'];
502 502
 				}
503 503
 			}
504 504
 			// echo '<br>';	print_r($dbparams);echo '<br>';
505
-			if ($params['db_rule']['val'] == -1 ) 
505
+			if ($params['db_rule']['val'] == -1) 
506 506
 			{
507 507
 			    $ruleID=$this->getUIDatabase()->addHandlerRule($dbparams);
508 508
 			}
509 509
 			else
510 510
 			{
511
-			    $this->getUIDatabase()->updateHandlerRule($dbparams,$params['db_rule']['val']);
511
+			    $this->getUIDatabase()->updateHandlerRule($dbparams, $params['db_rule']['val']);
512 512
 				$ruleID=$params['db_rule']['val'];
513 513
 			}
514 514
 		}
@@ -527,10 +527,10 @@  discard block
 block discarded – undo
527 527
 	*/
528 528
 	protected function getTrapDetail($trapid) 
529 529
 	{
530
-		if (!preg_match('/^[0-9]+$/',$trapid)) { throw new Exception('Invalid id');  }
530
+		if (!preg_match('/^[0-9]+$/', $trapid)) { throw new Exception('Invalid id'); }
531 531
 		$queryArray=$this->getModuleConfig()->trapDetailQuery();
532 532
 		
533
-		$dbConn = $this->getUIDatabase()->getDbConn();
533
+		$dbConn=$this->getUIDatabase()->getDbConn();
534 534
 		if ($dbConn === null) throw new \ErrorException('uncatched db error');
535 535
 		// ***************  Get main data
536 536
 		// extract columns and titles;
@@ -540,19 +540,19 @@  discard block
 block discarded – undo
540 540
 		}
541 541
 		try
542 542
 		{		
543
-		    $query = $dbConn->select()
544
-				->from($this->getModuleConfig()->getTrapTableName(),$elmts)
545
-				->where('id=?',$trapid);
543
+		    $query=$dbConn->select()
544
+				->from($this->getModuleConfig()->getTrapTableName(), $elmts)
545
+				->where('id=?', $trapid);
546 546
 				$trapDetail=$dbConn->fetchRow($query);
547
-			if ( $trapDetail == null ) 
547
+			if ($trapDetail == null) 
548 548
 			{
549
-			    $trapDetail = 'NULL';
549
+			    $trapDetail='NULL';
550 550
 			    throw new Exception('No traps was found with id = '.$trapid);
551 551
 			}
552 552
 		}
553 553
 		catch (Exception $e)
554 554
 		{
555
-			$this->displayExitError('Add handler : get trap detail returning : '.print_r($trapDetail,true),$e->getMessage());
555
+			$this->displayExitError('Add handler : get trap detail returning : '.print_r($trapDetail, true), $e->getMessage());
556 556
 			return;
557 557
 		}
558 558
 
@@ -566,10 +566,10 @@  discard block
 block discarded – undo
566 566
 	*/
567 567
 	protected function getTrapobjects($trapid)
568 568
 	{	
569
-		if (!preg_match('/^[0-9]+$/',$trapid)) { throw new Exception('Invalid id');  }
569
+		if (!preg_match('/^[0-9]+$/', $trapid)) { throw new Exception('Invalid id'); }
570 570
 		$queryArrayData=$this->getModuleConfig()->trapDataDetailQuery();
571 571
 		
572
-		$dbConn = $this->getUIDatabase()->getDbConn();
572
+		$dbConn=$this->getUIDatabase()->getDbConn();
573 573
 		if ($dbConn === null) throw new \ErrorException('uncatched db error');
574 574
 		// ***************  Get object data
575 575
 		// extract columns and titles;
@@ -579,15 +579,15 @@  discard block
 block discarded – undo
579 579
 		}
580 580
 		try
581 581
 		{		
582
-		    $query = $dbConn->select()
583
-				->from($this->moduleConfig->getTrapDataTableName(),$data_elmts)
584
-				->where('trap_id=?',$trapid);
582
+		    $query=$dbConn->select()
583
+				->from($this->moduleConfig->getTrapDataTableName(), $data_elmts)
584
+				->where('trap_id=?', $trapid);
585 585
 				$trapDetail=$dbConn->fetchAll($query);
586 586
 			// if ( $trapDetail == null ) throw new Exception('No traps was found with id = '.$trapid);
587 587
 		}
588 588
 		catch (Exception $e)
589 589
 		{
590
-			$this->displayExitError('Add handler : get trap data detail : ',$e->getMessage());
590
+			$this->displayExitError('Add handler : get trap data detail : ', $e->getMessage());
591 591
 			return array();
592 592
 		}
593 593
 
@@ -601,24 +601,24 @@  discard block
 block discarded – undo
601 601
 	*/
602 602
 	protected function getRuleDetail($ruleid) 
603 603
 	{
604
-		if (!preg_match('/^[0-9]+$/',$ruleid)) { throw new Exception('Invalid id');  }
604
+		if (!preg_match('/^[0-9]+$/', $ruleid)) { throw new Exception('Invalid id'); }
605 605
 		$queryArray=$this->getModuleConfig()->ruleDetailQuery();
606 606
 		
607
-		$dbConn = $this->getUIDatabase()->getDbConn();
607
+		$dbConn=$this->getUIDatabase()->getDbConn();
608 608
 		if ($dbConn === null) throw new \ErrorException('uncatched db error');
609 609
 		// ***************  Get main data
610 610
 		try
611 611
 		{		
612
-		    $query = $dbConn->select()
613
-				->from($this->getModuleConfig()->getTrapRuleName(),$queryArray)
614
-				->where('id=?',$ruleid);
612
+		    $query=$dbConn->select()
613
+				->from($this->getModuleConfig()->getTrapRuleName(), $queryArray)
614
+				->where('id=?', $ruleid);
615 615
 			$ruleDetail=$dbConn->fetchRow($query);
616
-			if ( $ruleDetail == null ) throw new Exception('No rule was found with id = '.$ruleid);
616
+			if ($ruleDetail == null) throw new Exception('No rule was found with id = '.$ruleid);
617 617
 		}
618 618
 		catch (Exception $e)
619 619
 		{
620
-			$this->displayExitError('Update handler : get rule detail',$e->getMessage());
621
-			throw new Exception('Error : ',$e->getMessage());
620
+			$this->displayExitError('Update handler : get rule detail', $e->getMessage());
621
+			throw new Exception('Error : ', $e->getMessage());
622 622
 		}
623 623
 
624 624
 		return $ruleDetail;
@@ -631,7 +631,7 @@  discard block
 block discarded – undo
631 631
 	{
632 632
 		return $this->getTabs()->add('status', array(
633 633
 			'label' => $this->translate('Traps'),
634
-			'url'   => $this->getModuleConfig()->urlPath() . '/handler')
634
+			'url'   => $this->getModuleConfig()->urlPath().'/handler')
635 635
 		);
636 636
 	} 
637 637
 	
Please login to merge, or discard this patch.
Braces   +44 added lines, -42 removed lines patch added patch discarded remove patch
@@ -24,7 +24,9 @@  discard block
 block discarded – undo
24 24
 		$this->prepareTabs()->activate('status');
25 25
 
26 26
 		$dbConn = $this->getUIDatabase()->getDb();
27
-		if ($dbConn === null) throw new \ErrorException('uncatched db error');
27
+		if ($dbConn === null) {
28
+			throw new \ErrorException('uncatched db error');
29
+		}
28 30
 		
29 31
 		$this->getHandlerListTable()->setConnection($dbConn);
30 32
 		$this->getHandlerListTable()->setMibloader($this->getMIB());
@@ -52,8 +54,7 @@  discard block
 block discarded – undo
52 54
 	    if ($this->params->get('rule') !== null) 
53 55
 	    {
54 56
 	        $this->view->rule= $this->params->get('rule');
55
-	    }
56
-	    else
57
+	    } else
57 58
 	    {
58 59
 	        $this->view->rule='';
59 60
 	    }
@@ -107,8 +108,7 @@  discard block
 block discarded – undo
107 108
 	    try
108 109
 	    {
109 110
 	        $hosts=$this->getUIDatabase()->getHostByIP($hostfilter);
110
-	    }
111
-	    catch (Exception $e)
111
+	    } catch (Exception $e)
112 112
 	    {
113 113
 	        $this->displayExitError('Add handler : get host by IP/Name ',$e->getMessage());
114 114
 	    }
@@ -121,8 +121,7 @@  discard block
 block discarded – undo
121 121
 	        // Tell JS to get services when page is loaded
122 122
 	        $this->view->serviceGet=true;
123 123
 	        
124
-	    }
125
-	    else
124
+	    } else
126 125
 	    {
127 126
 	        foreach($hosts as $key=>$val)
128 127
 	        {
@@ -172,11 +171,14 @@  discard block
 block discarded – undo
172 171
 	            $allObjects[$val->oid]=null;
173 172
 	        }
174 173
 	    }
175
-	    if ($allObjects!=null) // in case trap doesn't have objects or is not resolved
174
+	    if ($allObjects!=null) {
175
+	    	// in case trap doesn't have objects or is not resolved
176 176
 	    {
177 177
 	        foreach ($allObjects as $key => $val)
178 178
 	        {
179
-	            if ($val==null) { continue; }
179
+	            if ($val==null) { continue;
180
+	    }
181
+	    }
180 182
 	            array_push($this->view->objectList, array(
181 183
 	                $oid_index,
182 184
 	                $key,
@@ -208,8 +210,7 @@  discard block
 block discarded – undo
208 210
 	    {
209 211
 	        $this->view->warning_message='Host '.$this->view->hostname. ' doesn\'t exists anymore';
210 212
 	        $this->view->serviceGet=false;
211
-	    }
212
-	    else
213
+	    } else
213 214
 	    {
214 215
 	        // Tell JS to get services when page is loaded
215 216
 	        $this->view->serviceGet=true;
@@ -218,8 +219,7 @@  discard block
 block discarded – undo
218 219
 	        if (count($serviceID) ==0)
219 220
 	        {
220 221
 	            $this->view->warning_message=' Service '.$ruleDetail->service_name. ' doesn\'t exists anymore';
221
-	        }
222
-	        else
222
+	        } else
223 223
 	        {
224 224
 	            $this->view->serviceSet=$serviceID[0]->id;
225 225
 	        }
@@ -238,8 +238,7 @@  discard block
 block discarded – undo
238 238
 	    {
239 239
 	        $this->view->warning_message='HostGroup '.$this->view->hostgroupname. ' doesn\'t exists anymore';
240 240
 	        $this->view->serviceGroupGet=false;
241
-	    }
242
-	    else
241
+	    } else
243 242
 	    {
244 243
 	        $grpServices=$this->getUIDatabase()->getServicesByHostGroupid($group_get[0]->id);
245 244
 	        $foundGrpService=0;
@@ -291,8 +290,7 @@  discard block
 block discarded – undo
291 290
 	                $object['type'],
292 291
 	                $object['type_enum']
293 292
 	            ));
294
-	        }
295
-	        else
293
+	        } else
296 294
 	        {
297 295
 	            array_push($curObjectList, array(
298 296
 	                $index,
@@ -363,8 +361,7 @@  discard block
 block discarded – undo
363 361
 			    $this->view->selectGroup=false;
364 362
 			    // Check if hostname still exists
365 363
 			    $this->add_check_host_exists($ruleDetail);
366
-			}
367
-			else
364
+			} else
368 365
 			{
369 366
 			    $this->view->selectGroup=true;
370 367
 			    $this->add_check_hostgroup_exists($ruleDetail); //  Check if groupe exists				
@@ -372,9 +369,11 @@  discard block
 block discarded – undo
372 369
 			
373 370
 			$this->view->mainoid=$ruleDetail->trap_oid;
374 371
 			$oidName=$this->getMIB()->translateOID($ruleDetail->trap_oid);
375
-			if ($oidName != null)  // oid is found in mibs
372
+			if ($oidName != null) {
373
+				// oid is found in mibs
376 374
 			{
377
-				$this->view->mib=$oidName['mib']; 
375
+				$this->view->mib=$oidName['mib'];
376
+			}
378 377
 				$this->view->name=$oidName['name'];
379 378
 				$this->view->trapListForMIB=$this->getMIB()
380 379
 					->getTrapList($oidName['mib']);				
@@ -429,8 +428,7 @@  discard block
 block discarded – undo
429 428
 			try
430 429
 			{
431 430
 			    $this->getUIDatabase()->deleteRule($postData[$params['db_rule']['post']]);
432
-			}
433
-			catch (Exception $e)
431
+			} catch (Exception $e)
434 432
 			{
435 433
 				$this->_helper->json(array('status'=>$e->getMessage()));
436 434
 				return;
@@ -444,13 +442,15 @@  discard block
 block discarded – undo
444 442
 		}		
445 443
 		foreach (array_keys($params) as $key)
446 444
 		{
447
-			if ($params[$key]['post']==null) continue; // data not sent in post vars
445
+			if ($params[$key]['post']==null) {
446
+				continue;
447
+			}
448
+			// data not sent in post vars
448 449
 			if (! isset($postData[$params[$key]['post']]))
449 450
 			{
450 451
 				// should not happen as the js checks data
451 452
 				$this->_helper->json(array('status'=>'No ' . $key));
452
-			}
453
-			else
453
+			} else
454 454
 			{
455 455
 				$data=$postData[$params[$key]['post']];
456 456
 				if ($data!=null && $data !="")
@@ -480,8 +480,7 @@  discard block
 block discarded – undo
480 480
 					$this->_helper->json(array('status'=>"Invalid service id : Please re enter service"));
481 481
 					return;
482 482
 				}
483
-			}
484
-			else
483
+			} else
485 484
 			{
486 485
 			    $object=$this->getUIDatabase()->getObjectNameByid($params['hostid']['val']);
487 486
 				if ($params['host_name']['val'] != $object->name1)
@@ -505,14 +504,12 @@  discard block
 block discarded – undo
505 504
 			if ($params['db_rule']['val'] == -1 ) 
506 505
 			{
507 506
 			    $ruleID=$this->getUIDatabase()->addHandlerRule($dbparams);
508
-			}
509
-			else
507
+			} else
510 508
 			{
511 509
 			    $this->getUIDatabase()->updateHandlerRule($dbparams,$params['db_rule']['val']);
512 510
 				$ruleID=$params['db_rule']['val'];
513 511
 			}
514
-		}
515
-		catch (Exception $e)
512
+		} catch (Exception $e)
516 513
 		{
517 514
 			$this->_helper->json(array('status'=>$e->getMessage()));
518 515
 			return;
@@ -531,7 +528,9 @@  discard block
 block discarded – undo
531 528
 		$queryArray=$this->getModuleConfig()->trapDetailQuery();
532 529
 		
533 530
 		$dbConn = $this->getUIDatabase()->getDbConn();
534
-		if ($dbConn === null) throw new \ErrorException('uncatched db error');
531
+		if ($dbConn === null) {
532
+			throw new \ErrorException('uncatched db error');
533
+		}
535 534
 		// ***************  Get main data
536 535
 		// extract columns and titles;
537 536
 		$elmts=NULL;
@@ -549,8 +548,7 @@  discard block
 block discarded – undo
549 548
 			    $trapDetail = 'NULL';
550 549
 			    throw new Exception('No traps was found with id = '.$trapid);
551 550
 			}
552
-		}
553
-		catch (Exception $e)
551
+		} catch (Exception $e)
554 552
 		{
555 553
 			$this->displayExitError('Add handler : get trap detail returning : '.print_r($trapDetail,true),$e->getMessage());
556 554
 			return;
@@ -570,7 +568,9 @@  discard block
 block discarded – undo
570 568
 		$queryArrayData=$this->getModuleConfig()->trapDataDetailQuery();
571 569
 		
572 570
 		$dbConn = $this->getUIDatabase()->getDbConn();
573
-		if ($dbConn === null) throw new \ErrorException('uncatched db error');
571
+		if ($dbConn === null) {
572
+			throw new \ErrorException('uncatched db error');
573
+		}
574 574
 		// ***************  Get object data
575 575
 		// extract columns and titles;
576 576
 		$data_elmts=NULL;
@@ -584,8 +584,7 @@  discard block
 block discarded – undo
584 584
 				->where('trap_id=?',$trapid);
585 585
 				$trapDetail=$dbConn->fetchAll($query);
586 586
 			// if ( $trapDetail == null ) throw new Exception('No traps was found with id = '.$trapid);
587
-		}
588
-		catch (Exception $e)
587
+		} catch (Exception $e)
589 588
 		{
590 589
 			$this->displayExitError('Add handler : get trap data detail : ',$e->getMessage());
591 590
 			return array();
@@ -605,7 +604,9 @@  discard block
 block discarded – undo
605 604
 		$queryArray=$this->getModuleConfig()->ruleDetailQuery();
606 605
 		
607 606
 		$dbConn = $this->getUIDatabase()->getDbConn();
608
-		if ($dbConn === null) throw new \ErrorException('uncatched db error');
607
+		if ($dbConn === null) {
608
+			throw new \ErrorException('uncatched db error');
609
+		}
609 610
 		// ***************  Get main data
610 611
 		try
611 612
 		{		
@@ -613,9 +614,10 @@  discard block
 block discarded – undo
613 614
 				->from($this->getModuleConfig()->getTrapRuleName(),$queryArray)
614 615
 				->where('id=?',$ruleid);
615 616
 			$ruleDetail=$dbConn->fetchRow($query);
616
-			if ( $ruleDetail == null ) throw new Exception('No rule was found with id = '.$ruleid);
617
-		}
618
-		catch (Exception $e)
617
+			if ( $ruleDetail == null ) {
618
+				throw new Exception('No rule was found with id = '.$ruleid);
619
+			}
620
+		} catch (Exception $e)
619 621
 		{
620 622
 			$this->displayExitError('Update handler : get rule detail',$e->getMessage());
621 623
 			throw new Exception('Error : ',$e->getMessage());
Please login to merge, or discard this patch.
application/controllers/HelperController.php 1 patch
Spacing   +60 added lines, -60 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,19 +235,19 @@  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
 
240
-		$action = $this->checkPostVar($postData, 'action', 'save|execute');
240
+		$action=$this->checkPostVar($postData, 'action', 'save|execute');
241 241
 		
242 242
 		if ($action == 'save')
243 243
 		{
244 244
 			try
245 245
 			{
246
-			    $this->getUIDatabase()->setDBConfigValue('db_remove_days',$days);
246
+			    $this->getUIDatabase()->setDBConfigValue('db_remove_days', $days);
247 247
 			}
248 248
 			catch (Exception $e)
249 249
 			{
250
-				$this->_helper->json(array('status'=>'Save error : '.$e->getMessage() ));
250
+				$this->_helper->json(array('status'=>'Save error : '.$e->getMessage()));
251 251
 				return;
252 252
 			}
253 253
 			$this->_helper->json(array('status'=>'OK'));
@@ -257,16 +257,16 @@  discard block
 block discarded – undo
257 257
 		{
258 258
 			try
259 259
 			{
260
-				require_once($this->Module()->getBaseDir() .'/bin/trap_class.php');
260
+				require_once($this->Module()->getBaseDir().'/bin/trap_class.php');
261 261
 				$icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc');
262 262
 				$debug_level=4;
263
-				$trap = new Trap($icingaweb2_etc);
264
-				$trap->setLogging($debug_level,'syslog');
263
+				$trap=new Trap($icingaweb2_etc);
264
+				$trap->setLogging($debug_level, 'syslog');
265 265
 				$trap->eraseOldTraps($days);
266 266
 			}
267 267
 			catch (Exception $e)
268 268
 			{
269
-				$this->_helper->json(array('status'=>'execute error : '.$e->getMessage() ));
269
+				$this->_helper->json(array('status'=>'execute error : '.$e->getMessage()));
270 270
 				return;
271 271
 			}			
272 272
 			$this->_helper->json(array('status'=>'OK'));
@@ -284,7 +284,7 @@  discard block
 block discarded – undo
284 284
 	{
285 285
 		$postData=$this->getRequest()->getPost();
286 286
 		
287
-		$destination = $this->checkPostVar($postData, 'destination', '.*');
287
+		$destination=$this->checkPostVar($postData, 'destination', '.*');
288 288
 		$logDest=$this->getModuleConfig()->getLogDestinations();
289 289
 		if (!isset($logDest[$destination]))
290 290
 		{
@@ -295,7 +295,7 @@  discard block
 block discarded – undo
295 295
 		if (isset($postData['file']))
296 296
 		{ 
297 297
 			$file=$postData['file'];
298
-			$fileHandler=@fopen($file,'w');
298
+			$fileHandler=@fopen($file, 'w');
299 299
 			if ($fileHandler == false)
300 300
 			{   // File os note writabe / cannot create
301 301
 			    $this->_helper->json(array('status'=>'File not writable :  '.$file));
@@ -315,17 +315,17 @@  discard block
 block discarded – undo
315 315
 			}
316 316
 		}
317 317
 
318
-		$level = $this->checkPostVar($postData, 'level', '[0-9]');
318
+		$level=$this->checkPostVar($postData, 'level', '[0-9]');
319 319
 				
320 320
 		try
321 321
 		{
322
-		    $this->getUIDatabase()->setDBConfigValue('log_destination',$destination);
323
-		    $this->getUIDatabase()->setDBConfigValue('log_file',$file);
324
-		    $this->getUIDatabase()->setDBConfigValue('log_level',$level);
322
+		    $this->getUIDatabase()->setDBConfigValue('log_destination', $destination);
323
+		    $this->getUIDatabase()->setDBConfigValue('log_file', $file);
324
+		    $this->getUIDatabase()->setDBConfigValue('log_level', $level);
325 325
 		}
326 326
 		catch (Exception $e)
327 327
 		{
328
-			$this->_helper->json(array('status'=>'Save error : '.$e->getMessage() ));
328
+			$this->_helper->json(array('status'=>'Save error : '.$e->getMessage()));
329 329
 			return;
330 330
 		}
331 331
 		$this->_helper->json(array('status'=>'OK'));
@@ -343,29 +343,29 @@  discard block
 block discarded – undo
343 343
 	    
344 344
 	    $postData=$this->getRequest()->getPost();
345 345
 	   
346
-	    $rule = $this->checkPostVar($postData, 'rule', '.*');
346
+	    $rule=$this->checkPostVar($postData, 'rule', '.*');
347 347
 
348
-	    $action = $this->checkPostVar($postData, 'action', 'evaluate');
348
+	    $action=$this->checkPostVar($postData, 'action', 'evaluate');
349 349
 
350 350
 	    if ($action == 'evaluate')
351 351
 	    {
352 352
 	        try
353 353
 	        {
354
-	            require_once($this->Module()->getBaseDir() .'/bin/trap_class.php');
354
+	            require_once($this->Module()->getBaseDir().'/bin/trap_class.php');
355 355
 	            $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc');
356
-	            $trap = new Trap($icingaweb2_etc);
356
+	            $trap=new Trap($icingaweb2_etc);
357 357
 	            // Cleanup spaces before eval
358 358
 	            $rule=$trap->ruleClass->eval_cleanup($rule);
359 359
 	            // Eval
360 360
 	            $item=0;
361
-	            $rule=$trap->ruleClass->evaluation($rule,$item);
361
+	            $rule=$trap->ruleClass->evaluation($rule, $item);
362 362
 	        }
363 363
 	        catch (Exception $e)
364 364
 	        {
365
-	            $this->_helper->json(array('status'=>'Evaluation error : '.$e->getMessage() ));
365
+	            $this->_helper->json(array('status'=>'Evaluation error : '.$e->getMessage()));
366 366
 	            return;
367 367
 	        }
368
-	        $return=($rule==true)?'true':'false';
368
+	        $return=($rule == true) ? 'true' : 'false';
369 369
 	        $this->_helper->json(array('status'=>'OK', 'message' => $return));
370 370
 	    }
371 371
 	    
@@ -380,15 +380,15 @@  discard block
 block discarded – undo
380 380
 	{
381 381
 	    $postData=$this->getRequest()->getPost();
382 382
 	    
383
-	    $pluginName = $this->checkPostVar($postData, 'name', '.*');
383
+	    $pluginName=$this->checkPostVar($postData, 'name', '.*');
384 384
 	    
385
-	    $action = $this->checkPostVar($postData, 'action', 'enable|disable');
385
+	    $action=$this->checkPostVar($postData, 'action', 'enable|disable');
386 386
 	    
387 387
         try
388 388
         {
389
-            require_once($this->Module()->getBaseDir() .'/bin/trap_class.php');
389
+            require_once($this->Module()->getBaseDir().'/bin/trap_class.php');
390 390
             $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc');
391
-            $trap = new Trap($icingaweb2_etc);
391
+            $trap=new Trap($icingaweb2_etc);
392 392
             // Enable plugin.
393 393
             $action=($action == 'enable') ? true : false;
394 394
             $retVal=$trap->pluginClass->enablePlugin($pluginName, $action);
@@ -396,7 +396,7 @@  discard block
 block discarded – undo
396 396
         }
397 397
         catch (Exception $e)
398 398
         {
399
-            $this->_helper->json(array('status'=>'Action error : '.$e->getMessage() ));
399
+            $this->_helper->json(array('status'=>'Action error : '.$e->getMessage()));
400 400
             return;
401 401
         }
402 402
         if ($retVal === true)
@@ -418,45 +418,45 @@  discard block
 block discarded – undo
418 418
 	{
419 419
 	    $postData=$this->getRequest()->getPost();
420 420
 	    
421
-	    $functionString = $this->checkPostVar($postData, 'function', '.*');
421
+	    $functionString=$this->checkPostVar($postData, 'function', '.*');
422 422
 	    
423 423
 	    $this->checkPostVar($postData, 'action', 'evaluate');
424 424
 	    
425 425
 	    // Only one action possible for now, no tests on action.
426 426
 	    try
427 427
 	    {
428
-	        require_once($this->Module()->getBaseDir() .'/bin/trap_class.php');
428
+	        require_once($this->Module()->getBaseDir().'/bin/trap_class.php');
429 429
 	        $icingaweb2Etc=$this->Config()->get('config', 'icingaweb2_etc');
430
-	        $trap = new Trap($icingaweb2Etc);
430
+	        $trap=new Trap($icingaweb2Etc);
431 431
 	        // load all plugins in case tested function is not enabled.
432 432
 	        $trap->pluginClass->registerAllPlugins(false);
433 433
 	        // Clean all spaces
434
-	        $functionString = $trap->ruleClass->eval_cleanup($functionString);
434
+	        $functionString=$trap->ruleClass->eval_cleanup($functionString);
435 435
 	        // Eval functions
436
-	        $result = $trap->pluginClass->evaluateFunctionString($functionString);	        
436
+	        $result=$trap->pluginClass->evaluateFunctionString($functionString);	        
437 437
 	    }
438 438
 	    catch (Exception $e)
439 439
 	    {
440
-	        $this->_helper->json(array('status'=>'Action error : '.$e->getMessage() ));
440
+	        $this->_helper->json(array('status'=>'Action error : '.$e->getMessage()));
441 441
 	        return;
442 442
 	    }
443 443
 	    
444
-        $result = ($result === true)?'True':'False';
445
-        $this->_helper->json(array('status'=>'OK','message' => $result));
444
+        $result=($result === true) ? 'True' : 'False';
445
+        $this->_helper->json(array('status'=>'OK', 'message' => $result));
446 446
 	}
447 447
 
448 448
     /**************   Utilities **********************/
449 449
 
450
-	private function checkPostVar(array $postData,string $postVar, string $validRegexp) : string
450
+	private function checkPostVar(array $postData, string $postVar, string $validRegexp) : string
451 451
 	{
452 452
 	    if (!isset ($postData[$postVar]))
453 453
 	    {
454
-	        $this->_helper->json(array('status'=>'No ' . $postVar));
454
+	        $this->_helper->json(array('status'=>'No '.$postVar));
455 455
 	        return '';
456 456
 	    }
457 457
 	    if (preg_match('/'.$validRegexp.'/', $postData[$postVar]) != 1)
458 458
 	    {
459
-	        $this->_helper->json(array('status'=>'Unknown ' . $postVar . ' value '.$postData[$postVar]));
459
+	        $this->_helper->json(array('status'=>'Unknown '.$postVar.' value '.$postData[$postVar]));
460 460
 	        return '';
461 461
 	    }
462 462
 	    return $postData[$postVar];
Please login to merge, or discard this patch.