Passed
Branch master (9f9a4d)
by Patrick
02:33
created
configuration.php 2 patches
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -6,8 +6,8 @@
 block discarded – undo
6 6
 $this->providePermission('trapdirector/config', $this->translate('Allow to create and modify traps services'));
7 7
 
8 8
 $this->provideConfigTab('config', array(
9
-    'title' => 'Configuration',
10
-    'url'   => 'settings'
9
+	'title' => 'Configuration',
10
+	'url'   => 'settings'
11 11
 ));
12 12
 
13 13
 $section = $this->menuSection(N_('Traps'),array (
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -10,22 +10,22 @@
 block discarded – undo
10 10
     'url'   => 'settings'
11 11
 ));
12 12
 
13
-$section = $this->menuSection(N_('Traps'),array (
13
+$section=$this->menuSection(N_('Traps'), array(
14 14
 	'icon'	=> 'filter',
15 15
 	'url'	=> 'trapdirector'
16 16
 ));
17 17
 
18
-$section->add(N_('Status & Mibs'),array(
18
+$section->add(N_('Status & Mibs'), array(
19 19
 	'url'			=> 'trapdirector/status/',
20 20
 	'permission' 	=> 'trapdirector/view'
21 21
 ));
22 22
 
23
-$section->add(N_('Received'),array(
23
+$section->add(N_('Received'), array(
24 24
 	'url'			=> 'trapdirector/received/',
25 25
 	'permission' 	=> 'trapdirector/view'
26 26
 ));
27 27
 
28
-$section->add(N_('Handlers'),array(
28
+$section->add(N_('Handlers'), array(
29 29
 	'url'			=> 'trapdirector/handler/',
30 30
 	'permission' 	=> 'trapdirector/config'
31 31
 ));
Please login to merge, or discard this patch.
application/clicommands/StatusCommand.php 3 patches
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -17,10 +17,10 @@
 block discarded – undo
17 17
 class StatusCommand extends Command
18 18
 {
19 19
 	/**
20
-	* Get database counts
21
-	*
22
-	* Get number of traps, rules
23
-	*/
20
+	 * Get database counts
21
+	 *
22
+	 * Get number of traps, rules
23
+	 */
24 24
 	public function dbAction()
25 25
 	{
26 26
 		$db_prefix=$this->Config()->get('config', 'database_prefix');
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -24,21 +24,21 @@
 block discarded – undo
24 24
 	public function dbAction()
25 25
 	{
26 26
 		$db_prefix=$this->Config()->get('config', 'database_prefix');
27
-		$Config = new TrapModuleConfig($db_prefix);
27
+		$Config=new TrapModuleConfig($db_prefix);
28 28
 		
29 29
 		try
30 30
 		{
31 31
 			
32 32
 			$dbresource=$this->Config()->get('config', 'database');
33
-			printf("DB name : %s\n",$dbresource);
34
-			$dataBase = IcingaDbConnection::fromResourceName($dbresource)->getConnection();
33
+			printf("DB name : %s\n", $dbresource);
34
+			$dataBase=IcingaDbConnection::fromResourceName($dbresource)->getConnection();
35 35
 			
36
-			$query = $dataBase->select()->from($Config->getTrapTableName(),array('COUNT(*)'));			
37
-			printf("Number of traps : %s\n", $dataBase->fetchOne($query) );
38
-			$query = $dataBase->select()->from($Config->getTrapDataTableName(),array('COUNT(*)'));			
39
-			printf("Number of trap objects : %s\n", $dataBase->fetchOne($query) );
40
-			$query = $dataBase->select()->from($Config->getTrapRuleName(),array('COUNT(*)'));			
41
-			printf("Number of rules : %s\n", $dataBase->fetchOne($query) );
36
+			$query=$dataBase->select()->from($Config->getTrapTableName(), array('COUNT(*)'));			
37
+			printf("Number of traps : %s\n", $dataBase->fetchOne($query));
38
+			$query=$dataBase->select()->from($Config->getTrapDataTableName(), array('COUNT(*)'));			
39
+			printf("Number of trap objects : %s\n", $dataBase->fetchOne($query));
40
+			$query=$dataBase->select()->from($Config->getTrapRuleName(), array('COUNT(*)'));			
41
+			printf("Number of rules : %s\n", $dataBase->fetchOne($query));
42 42
 			
43 43
 		}
44 44
 		catch (Exception $e)
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -40,8 +40,7 @@
 block discarded – undo
40 40
 			$query = $dataBase->select()->from($Config->getTrapRuleName(),array('COUNT(*)'));			
41 41
 			printf("Number of rules : %s\n", $dataBase->fetchOne($query) );
42 42
 			
43
-		}
44
-		catch (Exception $e)
43
+		} catch (Exception $e)
45 44
 		{
46 45
 			printf('Error in DB : %s\n', $e->getMessage());
47 46
 		}	   
Please login to merge, or discard this patch.
application/clicommands/TrapsCommand.php 3 patches
Indentation   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -17,16 +17,16 @@  discard block
 block discarded – undo
17 17
 class TrapsCommand extends Command
18 18
 {
19 19
 	/**
20
-	*	Delete old traps
21
-	*
22
-	*	USAGE 
23
-	*
24
-	*	icingali trapdirector traps rotate [options]
25
-	*	
26
-	*	OPTIONS
27
-	*	
28
-	*	--days	remove traps older than <n> days
29
-	*/
20
+	 *	Delete old traps
21
+	 *
22
+	 *	USAGE 
23
+	 *
24
+	 *	icingali trapdirector traps rotate [options]
25
+	 *	
26
+	 *	OPTIONS
27
+	 *	
28
+	 *	--days	remove traps older than <n> days
29
+	 */
30 30
 	public function rotateAction()
31 31
 	{
32 32
 		$module=Icinga::app()->getModuleManager()->getModule($this->getModuleName());
@@ -56,13 +56,13 @@  discard block
 block discarded – undo
56 56
 	}  	
57 57
 	
58 58
 	/**
59
-	*	Reset services to OK state if timeout is passed
60
-	*
61
-	*	USAGE
62
-	*
63
-	*	icingali trapdirector traps reset_services
64
-	*
65
-	*/
59
+	 *	Reset services to OK state if timeout is passed
60
+	 *
61
+	 *	USAGE
62
+	 *
63
+	 *	icingali trapdirector traps reset_services
64
+	 *
65
+	 */
66 66
 	public function resetOKAction()
67 67
 	{
68 68
 		$module=Icinga::app()->getModuleManager()->getModule($this->getModuleName());
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -30,16 +30,16 @@  discard block
 block discarded – undo
30 30
 	public function rotateAction()
31 31
 	{
32 32
 		$module=Icinga::app()->getModuleManager()->getModule($this->getModuleName());
33
-		require_once($module->getBaseDir() .'/bin/trap_class.php');
33
+		require_once($module->getBaseDir().'/bin/trap_class.php');
34 34
 		$icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc');
35 35
 		$debug_level=2;
36
-		$trap = new Trap($icingaweb2_etc);
37
-		$trap->setLogging($debug_level,'display');
36
+		$trap=new Trap($icingaweb2_etc);
37
+		$trap->setLogging($debug_level, 'display');
38 38
 		try
39 39
 		{
40
-			$days = $this->params->get('days', '<default>');
40
+			$days=$this->params->get('days', '<default>');
41 41
 			echo $this->screen->colorize("Deleting traps older than $days days\n", 'lightblue');
42
-			if ($days=='<default>')
42
+			if ($days == '<default>')
43 43
 			{
44 44
 				$trap->eraseOldTraps();
45 45
 			}
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
 		}
52 52
 		catch (Exception $e)
53 53
 		{
54
-			echo 'Error in updating : ' . $e->getMessage();
54
+			echo 'Error in updating : '.$e->getMessage();
55 55
 		}	   
56 56
 	}  	
57 57
 	
@@ -66,18 +66,18 @@  discard block
 block discarded – undo
66 66
 	public function resetOKAction()
67 67
 	{
68 68
 		$module=Icinga::app()->getModuleManager()->getModule($this->getModuleName());
69
-		require_once($module->getBaseDir() .'/bin/trap_class.php');
69
+		require_once($module->getBaseDir().'/bin/trap_class.php');
70 70
 		$icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc');
71 71
 		$debug_level=2;
72
-		$trap = new Trap($icingaweb2_etc);
73
-		$trap->setLogging($debug_level,'display');
72
+		$trap=new Trap($icingaweb2_etc);
73
+		$trap->setLogging($debug_level, 'display');
74 74
 		try 
75 75
 		{
76 76
 			$trap->reset_services();
77 77
 		} 
78 78
 		catch (Exception $e) 
79 79
 		{
80
-			echo 'ERROR : '. $e->getMessage();
80
+			echo 'ERROR : '.$e->getMessage();
81 81
 		}
82 82
 	} 	
83 83
 	
Please login to merge, or discard this patch.
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -42,14 +42,12 @@  discard block
 block discarded – undo
42 42
 			if ($days=='<default>')
43 43
 			{
44 44
 				$trap->eraseOldTraps();
45
-			}
46
-			else
45
+			} else
47 46
 			{
48 47
 				$trap->eraseOldTraps($days);
49 48
 			}
50 49
 			
51
-		}
52
-		catch (Exception $e)
50
+		} catch (Exception $e)
53 51
 		{
54 52
 			echo 'Error in updating : ' . $e->getMessage();
55 53
 		}	   
@@ -74,8 +72,7 @@  discard block
 block discarded – undo
74 72
 		try 
75 73
 		{
76 74
 			$trap->reset_services();
77
-		} 
78
-		catch (Exception $e) 
75
+		} catch (Exception $e) 
79 76
 		{
80 77
 			echo 'ERROR : '. $e->getMessage();
81 78
 		}
Please login to merge, or discard this patch.
application/clicommands/MibCommand.php 3 patches
Braces   +5 added lines, -10 removed lines patch added patch discarded remove patch
@@ -62,8 +62,7 @@  discard block
 block discarded – undo
62 62
 		if ($pid == 1)
63 63
 		{
64 64
 		    $trap->setLogging($logLevel,'display');
65
-		}
66
-		else
65
+		} else
67 66
 		{  // use default display TODO : if default is 'display' son process will be killed at first output....
68 67
 		    if ($pid != 0)
69 68
 		    {
@@ -72,8 +71,7 @@  discard block
 block discarded – undo
72 71
 		        fclose($file);
73 72
 		        echo "OK : process $pid in bckground";
74 73
 		        return 0;
75
-		    }
76
-		    else
74
+		    } else
77 75
 		    {  // son process : close all file descriptors and go to a new session
78 76
 		        fclose($file);		        
79 77
 // 		        $sid = posix_setsid();
@@ -83,8 +81,7 @@  discard block
 block discarded – undo
83 81
                 try
84 82
                 {
85 83
                     $trap->update_mib_database(false,$forceCheck);
86
-                }
87
-                catch (Exception $e)
84
+                } catch (Exception $e)
88 85
                 {
89 86
                     $trap->trapLog('Error in updating : ' . $e->getMessage(),2);
90 87
                 }
@@ -101,8 +98,7 @@  discard block
 block discarded – undo
101 98
 			$trap->update_mib_database(true,$forceCheck);
102 99
 			echo "Done\n";
103 100
 			
104
-		}
105
-		catch (Exception $e)
101
+		} catch (Exception $e)
106 102
 		{
107 103
 			echo 'Error in updating : ' . $e->getMessage();
108 104
 		}
@@ -144,8 +140,7 @@  discard block
 block discarded – undo
144 140
 			$query = $db->select()->from($Config->getTrapRuleName(),array('COUNT(*)'));			
145 141
 			echo "Number of rules : " . $db->fetchOne($query) ."\n";		
146 142
 			
147
-		}
148
-		catch (Exception $e)
143
+		} catch (Exception $e)
149 144
 		{
150 145
 			echo 'Error in DB : ' . $e->getMessage();
151 146
 		}	   
Please login to merge, or discard this patch.
Indentation   +71 added lines, -71 removed lines patch added patch discarded remove patch
@@ -20,77 +20,77 @@  discard block
 block discarded – undo
20 20
 class MibCommand extends Command
21 21
 {
22 22
 	/**
23
-	*	Update mib database
24
-	*
25
-	*	USAGE 
26
-	*
27
-	*	icingli trapdirector mib update
28
-	*	
29
-	*	OPTIONS
30
-	*	
31
-	*	--pid <file> : run in background with pid in <file>
32
-	*
33
-	*	--verb    : Set output log to verbose
34
-	*
35
-	*   --force-check : force check of all traps & objects for change. (NOT IMPLEMENTED)
36
-	*/
23
+	 *	Update mib database
24
+	 *
25
+	 *	USAGE 
26
+	 *
27
+	 *	icingli trapdirector mib update
28
+	 *	
29
+	 *	OPTIONS
30
+	 *	
31
+	 *	--pid <file> : run in background with pid in <file>
32
+	 *
33
+	 *	--verb    : Set output log to verbose
34
+	 *
35
+	 *   --force-check : force check of all traps & objects for change. (NOT IMPLEMENTED)
36
+	 */
37 37
 	public function updateAction()
38 38
 	{
39
-	    $background = $this->params->get('pid', null);
40
-	    $logLevel= $this->params->has('verb') ? 4 : 2;
41
-	    if ($this->params->has('force-check')) { echo "Not implemented"; return;}
42
-	    $forceCheck=$this->params->has('force-check')?True:False;
43
-	    $pid=1;
44
-	    if ($background != null)
45
-	    {
46
-	        $file=@fopen($background,'w');
47
-	        if ($file == false)
48
-	        {
49
-	            echo 'Error : cannot open pid file '.$background;
50
-	            return 1;
51
-	        }
52
-	        $pid = pcntl_fork();
53
-	        if ($pid == -1) {
54
-	            echo 'Error : Cannot fork process';
55
-	            return 1;
56
-	        }
57
-	    }
58
-	    $module=Icinga::app()->getModuleManager()->getModule($this->getModuleName());
39
+		$background = $this->params->get('pid', null);
40
+		$logLevel= $this->params->has('verb') ? 4 : 2;
41
+		if ($this->params->has('force-check')) { echo "Not implemented"; return;}
42
+		$forceCheck=$this->params->has('force-check')?True:False;
43
+		$pid=1;
44
+		if ($background != null)
45
+		{
46
+			$file=@fopen($background,'w');
47
+			if ($file == false)
48
+			{
49
+				echo 'Error : cannot open pid file '.$background;
50
+				return 1;
51
+			}
52
+			$pid = pcntl_fork();
53
+			if ($pid == -1) {
54
+				echo 'Error : Cannot fork process';
55
+				return 1;
56
+			}
57
+		}
58
+		$module=Icinga::app()->getModuleManager()->getModule($this->getModuleName());
59 59
 		require_once($module->getBaseDir() .'/bin/trap_class.php');
60 60
 		$icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc');
61 61
 		$trap = new Trap($icingaweb2_etc);
62 62
 		if ($pid == 1)
63 63
 		{
64
-		    $trap->setLogging($logLevel,'display');
64
+			$trap->setLogging($logLevel,'display');
65 65
 		}
66 66
 		else
67 67
 		{  // use default display TODO : if default is 'display' son process will be killed at first output....
68
-		    if ($pid != 0)
69
-		    {
70
-		        // father process
71
-		        fwrite($file,$pid);
72
-		        fclose($file);
73
-		        echo "OK : process $pid in bckground";
74
-		        return 0;
75
-		    }
76
-		    else
77
-		    {  // son process : close all file descriptors and go to a new session
78
-		        fclose($file);		        
68
+			if ($pid != 0)
69
+			{
70
+				// father process
71
+				fwrite($file,$pid);
72
+				fclose($file);
73
+				echo "OK : process $pid in bckground";
74
+				return 0;
75
+			}
76
+			else
77
+			{  // son process : close all file descriptors and go to a new session
78
+				fclose($file);		        
79 79
 // 		        $sid = posix_setsid();
80
-                fclose(STDIN);
81
-                fclose(STDOUT);
82
-                fclose(STDERR);
83
-                try
84
-                {
85
-                    $trap->update_mib_database(false,$forceCheck);
86
-                }
87
-                catch (Exception $e)
88
-                {
89
-                    $trap->trapLog('Error in updating : ' . $e->getMessage(),2);
90
-                }
91
-                unlink($background);
92
-                return 0;
93
-		    }
80
+				fclose(STDIN);
81
+				fclose(STDOUT);
82
+				fclose(STDERR);
83
+				try
84
+				{
85
+					$trap->update_mib_database(false,$forceCheck);
86
+				}
87
+				catch (Exception $e)
88
+				{
89
+					$trap->trapLog('Error in updating : ' . $e->getMessage(),2);
90
+				}
91
+				unlink($background);
92
+				return 0;
93
+			}
94 94
 		    
95 95
 		}
96 96
 		
@@ -108,20 +108,20 @@  discard block
 block discarded – undo
108 108
 		}
109 109
 		if ($pid != 1)
110 110
 		{
111
-		    unlink($background);
111
+			unlink($background);
112 112
 		}
113 113
 	}
114 114
 	/**
115
-	*	purge all mib database NOT IMPLEMENTED
116
-	*
117
-	*	USAGE 
118
-	*
119
-	*	icingli trapdirector mib purge --confirm yes
120
-	*	
121
-	*	OPTIONS
122
-	*	
123
-	*	--confirm yes : needed to execute purge
124
-	*/
115
+	 *	purge all mib database NOT IMPLEMENTED
116
+	 *
117
+	 *	USAGE 
118
+	 *
119
+	 *	icingli trapdirector mib purge --confirm yes
120
+	 *	
121
+	 *	OPTIONS
122
+	 *	
123
+	 *	--confirm yes : needed to execute purge
124
+	 */
125 125
 	public function purgeAction()
126 126
 	{
127 127
 		$db_prefix=$this->Config()->get('config', 'database_prefix');
Please login to merge, or discard this patch.
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -36,39 +36,39 @@  discard block
 block discarded – undo
36 36
 	*/
37 37
 	public function updateAction()
38 38
 	{
39
-	    $background = $this->params->get('pid', null);
40
-	    $logLevel= $this->params->has('verb') ? 4 : 2;
41
-	    if ($this->params->has('force-check')) { echo "Not implemented"; return;}
42
-	    $forceCheck=$this->params->has('force-check')?True:False;
39
+	    $background=$this->params->get('pid', null);
40
+	    $logLevel=$this->params->has('verb') ? 4 : 2;
41
+	    if ($this->params->has('force-check')) { echo "Not implemented"; return; }
42
+	    $forceCheck=$this->params->has('force-check') ?True:False;
43 43
 	    $pid=1;
44 44
 	    if ($background != null)
45 45
 	    {
46
-	        $file=@fopen($background,'w');
46
+	        $file=@fopen($background, 'w');
47 47
 	        if ($file == false)
48 48
 	        {
49 49
 	            echo 'Error : cannot open pid file '.$background;
50 50
 	            return 1;
51 51
 	        }
52
-	        $pid = pcntl_fork();
52
+	        $pid=pcntl_fork();
53 53
 	        if ($pid == -1) {
54 54
 	            echo 'Error : Cannot fork process';
55 55
 	            return 1;
56 56
 	        }
57 57
 	    }
58 58
 	    $module=Icinga::app()->getModuleManager()->getModule($this->getModuleName());
59
-		require_once($module->getBaseDir() .'/bin/trap_class.php');
59
+		require_once($module->getBaseDir().'/bin/trap_class.php');
60 60
 		$icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc');
61
-		$trap = new Trap($icingaweb2_etc);
61
+		$trap=new Trap($icingaweb2_etc);
62 62
 		if ($pid == 1)
63 63
 		{
64
-		    $trap->setLogging($logLevel,'display');
64
+		    $trap->setLogging($logLevel, 'display');
65 65
 		}
66 66
 		else
67 67
 		{  // use default display TODO : if default is 'display' son process will be killed at first output....
68 68
 		    if ($pid != 0)
69 69
 		    {
70 70
 		        // father process
71
-		        fwrite($file,$pid);
71
+		        fwrite($file, $pid);
72 72
 		        fclose($file);
73 73
 		        echo "OK : process $pid in bckground";
74 74
 		        return 0;
@@ -82,11 +82,11 @@  discard block
 block discarded – undo
82 82
                 fclose(STDERR);
83 83
                 try
84 84
                 {
85
-                    $trap->update_mib_database(false,$forceCheck);
85
+                    $trap->update_mib_database(false, $forceCheck);
86 86
                 }
87 87
                 catch (Exception $e)
88 88
                 {
89
-                    $trap->trapLog('Error in updating : ' . $e->getMessage(),2);
89
+                    $trap->trapLog('Error in updating : '.$e->getMessage(), 2);
90 90
                 }
91 91
                 unlink($background);
92 92
                 return 0;
@@ -98,13 +98,13 @@  discard block
 block discarded – undo
98 98
 		{
99 99
 			echo "Update main mib database : \n";
100 100
 			echo "# (trap found) C (trap already processed) . (every 2 seconds) : \n";
101
-			$trap->update_mib_database(true,$forceCheck);
101
+			$trap->update_mib_database(true, $forceCheck);
102 102
 			echo "Done\n";
103 103
 			
104 104
 		}
105 105
 		catch (Exception $e)
106 106
 		{
107
-			echo 'Error in updating : ' . $e->getMessage();
107
+			echo 'Error in updating : '.$e->getMessage();
108 108
 		}
109 109
 		if ($pid != 1)
110 110
 		{
@@ -128,26 +128,26 @@  discard block
 block discarded – undo
128 128
 		echo "Not implemented";
129 129
 		// TODO : implement
130 130
 		return;
131
-		$Config = new TrapModuleConfig($db_prefix);
131
+		$Config=new TrapModuleConfig($db_prefix);
132 132
 		
133 133
 		try
134 134
 		{
135 135
 			
136 136
 			$dbresource=$this->Config()->get('config', 'database');
137 137
 			echo "DB name : $dbresource\n";
138
-			$db = IcingaDbConnection::fromResourceName($dbresource)->getConnection();
138
+			$db=IcingaDbConnection::fromResourceName($dbresource)->getConnection();
139 139
 			
140
-			$query = $db->select()->from($Config->getTrapTableName(),array('COUNT(*)'));			
141
-			echo "Number of traps : " . $db->fetchOne($query) ."\n";
142
-			$query = $db->select()->from($Config->getTrapDataTableName(),array('COUNT(*)'));			
143
-			echo "Number of trap objects : " . $db->fetchOne($query) ."\n";
144
-			$query = $db->select()->from($Config->getTrapRuleName(),array('COUNT(*)'));			
145
-			echo "Number of rules : " . $db->fetchOne($query) ."\n";		
140
+			$query=$db->select()->from($Config->getTrapTableName(), array('COUNT(*)'));			
141
+			echo "Number of traps : ".$db->fetchOne($query)."\n";
142
+			$query=$db->select()->from($Config->getTrapDataTableName(), array('COUNT(*)'));			
143
+			echo "Number of trap objects : ".$db->fetchOne($query)."\n";
144
+			$query=$db->select()->from($Config->getTrapRuleName(), array('COUNT(*)'));			
145
+			echo "Number of rules : ".$db->fetchOne($query)."\n";		
146 146
 			
147 147
 		}
148 148
 		catch (Exception $e)
149 149
 		{
150
-			echo 'Error in DB : ' . $e->getMessage();
150
+			echo 'Error in DB : '.$e->getMessage();
151 151
 		}	   
152 152
 	}  	 	
153 153
 
Please login to merge, or discard this patch.
application/forms/TrapsConfigForm.php 2 patches
Indentation   +82 added lines, -82 removed lines patch added patch discarded remove patch
@@ -32,13 +32,13 @@  discard block
 block discarded – undo
32 32
 	
33 33
 	public function setDefaultIDODB($idoDbName)
34 34
 	{
35
-	    $this->idoDbName=$idoDbName;
36
-	    return $this;
35
+		$this->idoDbName=$idoDbName;
36
+		return $this;
37 37
 	}
38 38
 	
39
-    public function createElements(array $formData)
40
-    {
41
-        $this->addElement(
39
+	public function createElements(array $formData)
40
+	{
41
+		$this->addElement(
42 42
 			'select',
43 43
 			'config_database',
44 44
 			array(
@@ -72,14 +72,14 @@  discard block
 block discarded – undo
72 72
 			 )
73 73
 		);		
74 74
 		$this->addElement(
75
-            'text',
76
-            'config_icingaweb2_etc',
77
-            array(
78
-                    'required'      => true,
79
-                    'label'             => $this->translate('icingaweb2 config dir'),
75
+			'text',
76
+			'config_icingaweb2_etc',
77
+			array(
78
+					'required'      => true,
79
+					'label'             => $this->translate('icingaweb2 config dir'),
80 80
 					'value'			=> $this->icinga_base_path,
81
-             )
82
-        );
81
+			 )
82
+		);
83 83
 		$retval=0;
84 84
 		$output=array();
85 85
 		$snmptranslate=exec('which snmptranslate',$output,$retval);
@@ -88,68 +88,68 @@  discard block
 block discarded – undo
88 88
 			$snmptranslate='/usr/bin/snmptranslate';
89 89
 		}
90 90
 		$this->addElement(
91
-            'text',
92
-            'config_snmptranslate',
93
-            array(
94
-                    'required'      => true,
95
-                    'label'             => $this->translate('snmptranslate binary with path'),
91
+			'text',
92
+			'config_snmptranslate',
93
+			array(
94
+					'required'      => true,
95
+					'label'             => $this->translate('snmptranslate binary with path'),
96 96
 					'value'			=> $snmptranslate,
97
-             )
98
-        );
97
+			 )
98
+		);
99 99
 		$this->addElement(
100
-            'text',
101
-            'config_snmptranslate_dirs',
102
-            array(
103
-                    'required'      => true,
104
-                    'label'         => $this->translate('Path for mibs'),
100
+			'text',
101
+			'config_snmptranslate_dirs',
102
+			array(
103
+					'required'      => true,
104
+					'label'         => $this->translate('Path for mibs'),
105 105
 					'value'			=> $this->module_base_path.'/mibs',
106
-             )
107
-        );		
106
+			 )
107
+		);		
108 108
 		$this->addElement(
109
-            'text',
110
-            'config_icingacmd',
111
-            array(
112
-                    'required'      => true,
113
-                    'label'         => $this->translate('icingacmd with path'),
109
+			'text',
110
+			'config_icingacmd',
111
+			array(
112
+					'required'      => true,
113
+					'label'         => $this->translate('icingacmd with path'),
114 114
 					'value'			=> '/var/run/icinga2/cmd/icinga2.cmd',
115
-             )
116
-        );
115
+			 )
116
+		);
117 117
 		$this->addElement(
118
-		    'text',
119
-		    'config_icingaAPI_host',
120
-		    array(
121
-		        'required'      => false,
122
-		        'label'         => $this->translate('icinga2 API Host IP'),
123
-		        'value'			=> '',
124
-		    )
118
+			'text',
119
+			'config_icingaAPI_host',
120
+			array(
121
+				'required'      => false,
122
+				'label'         => $this->translate('icinga2 API Host IP'),
123
+				'value'			=> '',
124
+			)
125 125
 		);
126 126
 		$this->addElement(
127
-		    'text',
128
-		    'config_icingaAPI_port',
129
-		    array(
130
-		        'required'      => false,
131
-		        'label'         => $this->translate('icinga2 API TCP Port'),
132
-		        'value'			=> '5665',
133
-		    )
134
-		    );
127
+			'text',
128
+			'config_icingaAPI_port',
129
+			array(
130
+				'required'      => false,
131
+				'label'         => $this->translate('icinga2 API TCP Port'),
132
+				'value'			=> '5665',
133
+			)
134
+			);
135 135
 		$this->addElement(
136
-		    'text',
137
-		    'config_icingaAPI_user',
138
-		    array(
139
-		        'required'      => false,
140
-		        'label'         => $this->translate('icinga2 API username'),
141
-		        'value'			=> '',
142
-		    )
143
-        );
136
+			'text',
137
+			'config_icingaAPI_user',
138
+			array(
139
+				'required'      => false,
140
+				'label'         => $this->translate('icinga2 API username'),
141
+				'value'			=> '',
142
+			)
143
+		);
144 144
 		$this->addElement(
145
-		    'text',
146
-		    'config_icingaAPI_password',
147
-		    array(
148
-		        'required'      => false,
149
-		        'label'         => $this->translate('icinga2 API password'),
150
-		        'value'			=> '',
151
-		    )
152
-	    );
145
+			'text',
146
+			'config_icingaAPI_password',
147
+			array(
148
+				'required'      => false,
149
+				'label'         => $this->translate('icinga2 API password'),
150
+				'value'			=> '',
151
+			)
152
+		);
153 153
 		/*$this->addElement(
154 154
 		    'radio',
155 155
 		    'config_icinga2api_use',
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
 		        'value'			=> array('Yes', 'No'),//array('1' => 'Yes', '0' => 'No'),
160 160
 		    )
161 161
 		);*/  
162
-		    // For Icinga2 API connexion
162
+			// For Icinga2 API connexion
163 163
 	//	$icinga2API=new Fieldset('Icinga2 API connection');
164 164
 	/* 	$icinga2API_select=new radioBtn('icinga2API_use');
165 165
 		$icinga2API_select->setLabel('Use icinga2 API instead of cmd file?');
@@ -169,30 +169,30 @@  discard block
 block discarded – undo
169 169
 		]);
170 170
 		$icinga2API->add($icinga2API_select);
171 171
 		$this->add($icinga2API); */
172
-    }	
172
+	}	
173 173
 
174 174
     
175
-    public function render(Zend_View_Interface $view = NULL)
176
-    {
175
+	public function render(Zend_View_Interface $view = NULL)
176
+	{
177 177
         
178 178
 
179
-        //return $html;
180
-        return parent::render($view);
181
-    }
179
+		//return $html;
180
+		return parent::render($view);
181
+	}
182 182
     
183
-    /**
184
-     * {@inheritdoc}
185
-     */
186
-    public function onSuccess()
187
-    {
188
-        parent::onSuccess();
189
-    }
183
+	/**
184
+	 * {@inheritdoc}
185
+	 */
186
+	public function onSuccess()
187
+	{
188
+		parent::onSuccess();
189
+	}
190 190
     
191
-    /**
192
-     * {@inheritdoc}
193
-     */
191
+	/**
192
+	 * {@inheritdoc}
193
+	 */
194 194
 	public function save()
195
-    {
195
+	{
196 196
 		parent::save();
197 197
 	}
198 198
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
18 18
 		$this->setName('form_config_traps');
19 19
 		$this->setSubmitLabel($this->translate('Save Changes'));
20 20
 	}
21
-	public function setPaths($module_base_path,$icinga_base_path)
21
+	public function setPaths($module_base_path, $icinga_base_path)
22 22
 	{
23 23
 		$this->module_base_path=$module_base_path;
24 24
 		$this->icinga_base_path=$icinga_base_path;
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
         );
83 83
 		$retval=0;
84 84
 		$output=array();
85
-		$snmptranslate=exec('which snmptranslate',$output,$retval);
85
+		$snmptranslate=exec('which snmptranslate', $output, $retval);
86 86
 		if ($retval != 0) 
87 87
 		{
88 88
 			$snmptranslate='/usr/bin/snmptranslate';
@@ -172,7 +172,7 @@  discard block
 block discarded – undo
172 172
     }	
173 173
 
174 174
     
175
-    public function render(Zend_View_Interface $view = NULL)
175
+    public function render(Zend_View_Interface $view=NULL)
176 176
     {
177 177
         
178 178
 
Please login to merge, or discard this patch.
application/controllers/ReceivedController.php 3 patches
Indentation   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -39,8 +39,8 @@  discard block
 block discarded – undo
39 39
 	}
40 40
 
41 41
 	/** 
42
-	*	Trap detail page
43
-	*/	
42
+	 *	Trap detail page
43
+	 */	
44 44
 	public function trapdetailAction() 
45 45
 	{
46 46
 		
@@ -141,22 +141,22 @@  discard block
 block discarded – undo
141 141
 	 */
142 142
 	public function hostsAction()
143 143
 	{
144
-	    $this->checkReadPermission();
145
-	    $this->prepareTabs()->activate('hosts');
144
+		$this->checkReadPermission();
145
+		$this->prepareTabs()->activate('hosts');
146 146
 	    
147
-	    $db = $this->getDb();
148
-	    $this->getTrapHostListTable()->setConnection($db);
147
+		$db = $this->getDb();
148
+		$this->getTrapHostListTable()->setConnection($db);
149 149
 	    
150
-	    // Apply pagination limits
151
-	    $this->view->table=$this->applyPaginationLimits($this->getTrapHostListTable(),$this->getModuleConfig()->itemListDisplay());
150
+		// Apply pagination limits
151
+		$this->view->table=$this->applyPaginationLimits($this->getTrapHostListTable(),$this->getModuleConfig()->itemListDisplay());
152 152
 	    
153
-	    // Set Filter
154
-	    //$postData=$this->getRequest()->getPost();
155
-	    $filter=array();
156
-	    $filter['q']=$this->params->get('q');//(isset($postData['q']))?$postData['q']:'';
157
-	    $filter['done']=$this->params->get('done');
158
-	    $this->view->filter=$filter;
159
-	    $this->view->table->updateFilter(Url::fromRequest(),$filter);
153
+		// Set Filter
154
+		//$postData=$this->getRequest()->getPost();
155
+		$filter=array();
156
+		$filter['q']=$this->params->get('q');//(isset($postData['q']))?$postData['q']:'';
157
+		$filter['done']=$this->params->get('done');
158
+		$this->view->filter=$filter;
159
+		$this->view->table->updateFilter(Url::fromRequest(),$filter);
160 160
 	}
161 161
 	
162 162
 	public function deleteAction()
@@ -176,12 +176,12 @@  discard block
 block discarded – undo
176 176
 		return $this->getTabs()->add('traps', array(
177 177
 			'label'	=> $this->translate('Traps'),
178 178
 			'url'   => $this->getModuleConfig()->urlPath() . '/received')
179
-		    )
180
-		    ->add('hosts', array(
181
-		        'label' => $this->translate('Hosts'),
182
-		        'url'   => $this->getModuleConfig()->urlPath() . '/received/hosts')
183
-		    )
184
-		    ->add('delete', array(
179
+			)
180
+			->add('hosts', array(
181
+				'label' => $this->translate('Hosts'),
182
+				'url'   => $this->getModuleConfig()->urlPath() . '/received/hosts')
183
+			)
184
+			->add('delete', array(
185 185
 			'label' => $this->translate('Delete'),
186 186
 			'url'   => $this->getModuleConfig()->urlPath() . '/received/delete')
187 187
 		  );
Please login to merge, or discard this patch.
Spacing   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -20,19 +20,19 @@  discard block
 block discarded – undo
20 20
 		$this->checkReadPermission();
21 21
 		$this->prepareTabs()->activate('traps');
22 22
 
23
-		$db = $this->getDb();
23
+		$db=$this->getDb();
24 24
 		$this->getTrapListTable()->setConnection($db);
25 25
 		
26 26
 		// Apply pagination limits
27
-		$this->view->table=$this->applyPaginationLimits($this->getTrapListTable(),$this->getModuleConfig()->itemListDisplay());		
27
+		$this->view->table=$this->applyPaginationLimits($this->getTrapListTable(), $this->getModuleConfig()->itemListDisplay());		
28 28
 		
29 29
 		// Set Filter
30 30
 		//$postData=$this->getRequest()->getPost();
31 31
 		$filter=array();
32
-		$filter['q']=$this->params->get('q');//(isset($postData['q']))?$postData['q']:'';
32
+		$filter['q']=$this->params->get('q'); //(isset($postData['q']))?$postData['q']:'';
33 33
 		$filter['done']=$this->params->get('done');
34 34
 		$this->view->filter=$filter;
35
-		$this->view->table->updateFilter(Url::fromRequest(),$filter);
35
+		$this->view->table->updateFilter(Url::fromRequest(), $filter);
36 36
 		
37 37
 		//$this->view->filterEditor = $this->getTrapListTable()->getFilterEditor($this->getRequest());
38 38
 
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
 		
47 47
 		$this->checkReadPermission();
48 48
 		// set up tab
49
-		$this->getTabs()->add('get',array(
49
+		$this->getTabs()->add('get', array(
50 50
 			'active'	=> true,
51 51
 			'label'		=> $this->translate('Detailed status'),
52 52
 			'url'		=> Url::fromRequest()
@@ -56,11 +56,11 @@  discard block
 block discarded – undo
56 56
 		$this->view->trapid=$trapid;
57 57
 		$queryArray=$this->getModuleConfig()->trapDetailQuery();
58 58
 		
59
-		$db = $this->getDb()->getConnection();
59
+		$db=$this->getDb()->getConnection();
60 60
 		
61 61
 		// URL to add a handler
62 62
 		$this->view->addHandlerUrl=Url::fromPath(
63
-			$this->getModuleConfig()->urlPath() . '/handler/add',
63
+			$this->getModuleConfig()->urlPath().'/handler/add',
64 64
 			array('fromid' => $trapid));
65 65
 		// ***************  Get main data
66 66
 		// extract columns and titles;
@@ -72,27 +72,27 @@  discard block
 block discarded – undo
72 72
 		// Do DB query for trap. 
73 73
 		try
74 74
 		{
75
-			$query = $db->select()
76
-				->from($this->moduleConfig->getTrapTableName(),$elmts)
77
-				->where('id=?',$trapid);
75
+			$query=$db->select()
76
+				->from($this->moduleConfig->getTrapTableName(), $elmts)
77
+				->where('id=?', $trapid);
78 78
 			$trapDetail=$db->fetchRow($query);
79
-			if ( $trapDetail == null) throw new Exception('No traps was found with id = '.$trapid);
79
+			if ($trapDetail == null) throw new Exception('No traps was found with id = '.$trapid);
80 80
 		}
81 81
 		catch (Exception $e)
82 82
 		{
83
-			$this->displayExitError('Trap detail',$e->getMessage());
83
+			$this->displayExitError('Trap detail', $e->getMessage());
84 84
 		}
85 85
 
86 86
 		// Store result in array (with Titles).
87 87
 		foreach ($queryArray as $key => $val) {
88 88
 			if ($key == 'timestamp') {
89
-				$cval=strftime('%c',$trapDetail->$key);
89
+				$cval=strftime('%c', $trapDetail->$key);
90 90
 			} else {
91 91
 				$cval=$trapDetail->$key;
92 92
 			}
93
-			array_push($queryArray[$key],$cval);
93
+			array_push($queryArray[$key], $cval);
94 94
 		}
95
-		$this->view->rowset = $queryArray;
95
+		$this->view->rowset=$queryArray;
96 96
 
97 97
 		// **************   Check for additionnal data
98 98
 		
@@ -104,17 +104,17 @@  discard block
 block discarded – undo
104 104
 		}
105 105
 		try
106 106
 		{		
107
-			$query = $db->select()
108
-				->from($this->moduleConfig->getTrapDataTableName(),$data_elmts)
109
-				->where('trap_id=?',$trapid);
107
+			$query=$db->select()
108
+				->from($this->moduleConfig->getTrapDataTableName(), $data_elmts)
109
+				->where('trap_id=?', $trapid);
110 110
 			$trapDetail=$db->fetchAll($query);
111 111
 		}
112 112
 		catch (Exception $e)
113 113
 		{
114
-			$this->displayExitError('Trap detail',$e->getMessage());
114
+			$this->displayExitError('Trap detail', $e->getMessage());
115 115
 		}
116 116
 		// TODO : code this in a better & simpler way
117
-		if ($trapDetail == null ) 
117
+		if ($trapDetail == null) 
118 118
 		{
119 119
 			$this->view->data=false;
120 120
 		}
@@ -126,9 +126,9 @@  discard block
 block discarded – undo
126 126
 			foreach ($trapDetail as $key => $val) 
127 127
 			{	
128 128
 				$trapval[$key]=array();
129
-				foreach (array_keys($queryArrayData) as $vkey ) 
129
+				foreach (array_keys($queryArrayData) as $vkey) 
130 130
 				{
131
-					array_push($trapval[$key],$val->$vkey);
131
+					array_push($trapval[$key], $val->$vkey);
132 132
 				}
133 133
 			}
134 134
 			$this->view->data_val=$trapval;
@@ -144,19 +144,19 @@  discard block
 block discarded – undo
144 144
 	    $this->checkReadPermission();
145 145
 	    $this->prepareTabs()->activate('hosts');
146 146
 	    
147
-	    $db = $this->getDb();
147
+	    $db=$this->getDb();
148 148
 	    $this->getTrapHostListTable()->setConnection($db);
149 149
 	    
150 150
 	    // Apply pagination limits
151
-	    $this->view->table=$this->applyPaginationLimits($this->getTrapHostListTable(),$this->getModuleConfig()->itemListDisplay());
151
+	    $this->view->table=$this->applyPaginationLimits($this->getTrapHostListTable(), $this->getModuleConfig()->itemListDisplay());
152 152
 	    
153 153
 	    // Set Filter
154 154
 	    //$postData=$this->getRequest()->getPost();
155 155
 	    $filter=array();
156
-	    $filter['q']=$this->params->get('q');//(isset($postData['q']))?$postData['q']:'';
156
+	    $filter['q']=$this->params->get('q'); //(isset($postData['q']))?$postData['q']:'';
157 157
 	    $filter['done']=$this->params->get('done');
158 158
 	    $this->view->filter=$filter;
159
-	    $this->view->table->updateFilter(Url::fromRequest(),$filter);
159
+	    $this->view->table->updateFilter(Url::fromRequest(), $filter);
160 160
 	}
161 161
 	
162 162
 	public function deleteAction()
@@ -175,15 +175,15 @@  discard block
 block discarded – undo
175 175
 	{
176 176
 		return $this->getTabs()->add('traps', array(
177 177
 			'label'	=> $this->translate('Traps'),
178
-			'url'   => $this->getModuleConfig()->urlPath() . '/received')
178
+			'url'   => $this->getModuleConfig()->urlPath().'/received')
179 179
 		    )
180 180
 		    ->add('hosts', array(
181 181
 		        'label' => $this->translate('Hosts'),
182
-		        'url'   => $this->getModuleConfig()->urlPath() . '/received/hosts')
182
+		        'url'   => $this->getModuleConfig()->urlPath().'/received/hosts')
183 183
 		    )
184 184
 		    ->add('delete', array(
185 185
 			'label' => $this->translate('Delete'),
186
-			'url'   => $this->getModuleConfig()->urlPath() . '/received/delete')
186
+			'url'   => $this->getModuleConfig()->urlPath().'/received/delete')
187 187
 		  );
188 188
 	} 
189 189
 
@@ -209,13 +209,13 @@  discard block
 block discarded – undo
209 209
 		{
210 210
 			$this->_helper->json(array('status'=>'Missing variables'));
211 211
 		}
212
-		if ($action =="count")
212
+		if ($action == "count")
213 213
 		{
214
-			$this->_helper->json(array('status'=>'OK','count'=>$this->countTrap($ip,$oid)));
214
+			$this->_helper->json(array('status'=>'OK', 'count'=>$this->countTrap($ip, $oid)));
215 215
 		}
216
-		if ($action =="delete")
216
+		if ($action == "delete")
217 217
 		{
218
-			$this->_helper->json(array('status'=>'OK','count'=>$this->deleteTrap($ip,$oid)));
218
+			$this->_helper->json(array('status'=>'OK', 'count'=>$this->deleteTrap($ip, $oid)));
219 219
 		}		
220 220
 		$this->_helper->json(array('status'=>'unknown action'));
221 221
 	}
Please login to merge, or discard this patch.
Braces   +7 added lines, -9 removed lines patch added patch discarded remove patch
@@ -76,9 +76,10 @@  discard block
 block discarded – undo
76 76
 				->from($this->moduleConfig->getTrapTableName(),$elmts)
77 77
 				->where('id=?',$trapid);
78 78
 			$trapDetail=$db->fetchRow($query);
79
-			if ( $trapDetail == null) throw new Exception('No traps was found with id = '.$trapid);
80
-		}
81
-		catch (Exception $e)
79
+			if ( $trapDetail == null) {
80
+				throw new Exception('No traps was found with id = '.$trapid);
81
+			}
82
+		} catch (Exception $e)
82 83
 		{
83 84
 			$this->displayExitError('Trap detail',$e->getMessage());
84 85
 		}
@@ -108,8 +109,7 @@  discard block
 block discarded – undo
108 109
 				->from($this->moduleConfig->getTrapDataTableName(),$data_elmts)
109 110
 				->where('trap_id=?',$trapid);
110 111
 			$trapDetail=$db->fetchAll($query);
111
-		}
112
-		catch (Exception $e)
112
+		} catch (Exception $e)
113 113
 		{
114 114
 			$this->displayExitError('Trap detail',$e->getMessage());
115 115
 		}
@@ -117,8 +117,7 @@  discard block
 block discarded – undo
117 117
 		if ($trapDetail == null ) 
118 118
 		{
119 119
 			$this->view->data=false;
120
-		}
121
-		else
120
+		} else
122 121
 		{
123 122
 			$this->view->data=true;
124 123
 			// Store result in array.
@@ -204,8 +203,7 @@  discard block
 block discarded – undo
204 203
 			$ip=$postData['IP'];
205 204
 			$oid=$postData['OID'];
206 205
 			$action=$postData['action'];
207
-		}
208
-		else
206
+		} else
209 207
 		{
210 208
 			$this->_helper->json(array('status'=>'Missing variables'));
211 209
 		}
Please login to merge, or discard this patch.
application/controllers/SettingsController.php 3 patches
Indentation   +100 added lines, -100 removed lines patch added patch discarded remove patch
@@ -22,37 +22,37 @@  discard block
 block discarded – undo
22 22
   public function indexAction()
23 23
   {
24 24
       
25
-    // CHeck permissions : display tests in any case, but no configuration.
25
+	// CHeck permissions : display tests in any case, but no configuration.
26 26
 	$this->view->configPermission=$this->checkModuleConfigPermission(1);
27 27
 	// But check read permission
28 28
 	$this->checkReadPermission();
29 29
 	// Get message : sent on configuration problems detected by controllers
30 30
 	$dberrorMsg=$this->params->get('dberror');
31 31
 	if ($dberrorMsg != '')
32
-	    $this->view->errorDetected=$dberrorMsg;
33
-    $dberrorMsg=$this->params->get('idodberror');
34
-    if ($dberrorMsg != '')
35
-        $this->view->errorDetected=$dberrorMsg;
32
+		$this->view->errorDetected=$dberrorMsg;
33
+	$dberrorMsg=$this->params->get('idodberror');
34
+	if ($dberrorMsg != '')
35
+		$this->view->errorDetected=$dberrorMsg;
36 36
     
37
-    $this->view->configErrorDetected == NULL; // Displayed error on various conifugration errors.
37
+	$this->view->configErrorDetected == NULL; // Displayed error on various conifugration errors.
38 38
     
39
-    // Test if configuration exists, if not create for installer script
39
+	// Test if configuration exists, if not create for installer script
40 40
 	$emptyConfig=0;
41
-    if ($this->Config()->isEmpty() == true)
42
-    {
43
-        $this->Config()->setSection('config'); // Set base config section.
44
-        try 
45
-        { 
46
-            $this->Config()->saveIni();
47
-            $this->view->configErrorDetected='Configuration is empty : you can run install script with parameters (see Automatic installation below)';
41
+	if ($this->Config()->isEmpty() == true)
42
+	{
43
+		$this->Config()->setSection('config'); // Set base config section.
44
+		try 
45
+		{ 
46
+			$this->Config()->saveIni();
47
+			$this->view->configErrorDetected='Configuration is empty : you can run install script with parameters (see Automatic installation below)';
48 48
 			$emptyConfig=1;
49
-        }
50
-        catch (Exception $e)
51
-        {
52
-            $this->view->configErrorDetected=$e->getMessage();
53
-        }
49
+		}
50
+		catch (Exception $e)
51
+		{
52
+			$this->view->configErrorDetected=$e->getMessage();
53
+		}
54 54
         
55
-    }
55
+	}
56 56
 	// Test Database
57 57
 	$db_message=array( // index => ( message OK, message NOK, optional link if NOK ) 
58 58
 		0	=>	array('Database configuration OK','',''),
@@ -97,20 +97,20 @@  discard block
 block discarded – undo
97 97
 	//********* Test API
98 98
 	if ($this->Config()->get('config', 'icingaAPI_host') != '')
99 99
 	{
100
-	    $apitest=new Icinga2Api($this->Config()->get('config', 'icingaAPI_host'),$this->Config()->get('config', 'icingaAPI_port'));
101
-    	$apitest->setCredentials($this->Config()->get('config', 'icingaAPI_user'), $this->Config()->get('config', 'icingaAPI_password'));
102
-    	try {
103
-    	    list($this->view->apimessageError,$this->view->apimessage)=$apitest->test($this->getModuleConfig()::getapiUserPermissions());
104
-    	    //$this->view->apimessageError=false;
105
-    	} catch (RuntimeException $e) {
106
-    	    $this->view->apimessage='API config : ' . $e->getMessage();
107
-    	    $this->view->apimessageError=true;
108
-    	} 
100
+		$apitest=new Icinga2Api($this->Config()->get('config', 'icingaAPI_host'),$this->Config()->get('config', 'icingaAPI_port'));
101
+		$apitest->setCredentials($this->Config()->get('config', 'icingaAPI_user'), $this->Config()->get('config', 'icingaAPI_password'));
102
+		try {
103
+			list($this->view->apimessageError,$this->view->apimessage)=$apitest->test($this->getModuleConfig()::getapiUserPermissions());
104
+			//$this->view->apimessageError=false;
105
+		} catch (RuntimeException $e) {
106
+			$this->view->apimessage='API config : ' . $e->getMessage();
107
+			$this->view->apimessageError=true;
108
+		} 
109 109
 	}
110 110
 	else
111 111
 	{
112
-	    $this->view->apimessage='API parameters not configured';
113
-	    $this->view->apimessageError=true;
112
+		$this->view->apimessage='API parameters not configured';
113
+		$this->view->apimessageError=true;
114 114
 	}
115 115
 	
116 116
 	//*********** Test snmptrapd alive and options
@@ -125,33 +125,33 @@  discard block
 block discarded – undo
125 125
 		}
126 126
 	}
127 127
 
128
-    $this->view->tabs = $this->Module()->getConfigTabs()->activate('config');
128
+	$this->view->tabs = $this->Module()->getConfigTabs()->activate('config');
129 129
 
130 130
 	// Check standard Icingaweb2 path
131 131
 	$this->view->icingaEtcWarn=0;
132 132
 	$icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc');
133 133
 	if ($icingaweb2_etc != "/etc/icingaweb2/" && $icingaweb2_etc != '')
134 134
 	{
135
-	    $output=array();
135
+		$output=array();
136 136
 	    
137
-	    exec('cat ' . $this->module->getBaseDir() .'/bin/trap_in.php | grep "\$icingaweb2_etc=" ',$output);
137
+		exec('cat ' . $this->module->getBaseDir() .'/bin/trap_in.php | grep "\$icingaweb2_etc=" ',$output);
138 138
 	    
139
-	    if (! preg_match('#"'. $icingaweb2_etc .'"#',$output[0]))
140
-	    {
141
-    	    $this->view->icingaEtcWarn=1;
142
-	        $this->view->icingaweb2_etc=$icingaweb2_etc;
143
-	    }
139
+		if (! preg_match('#"'. $icingaweb2_etc .'"#',$output[0]))
140
+		{
141
+			$this->view->icingaEtcWarn=1;
142
+			$this->view->icingaweb2_etc=$icingaweb2_etc;
143
+		}
144 144
 	}
145 145
 
146 146
 	// Setup path for mini documentation
147 147
 	$this->view->traps_in_config= PHP_BINARY . ' ' . $this->Module()->getBaseDir() . '/bin/trap_in.php';
148 148
 	
149 149
 	$this->view->installer= $this->Module()->getBaseDir() . '/bin/installer.sh '
150
-	    . ' -c all ' 
151
-	    . ' -d ' . $this->Module()->getBaseDir()
152
-	    . ' -p ' . PHP_BINARY
153
-	    . ' -a ' . exec('whoami')
154
-	    . ' -w ' . Icinga::app()->getConfigDir();
150
+		. ' -c all ' 
151
+		. ' -d ' . $this->Module()->getBaseDir()
152
+		. ' -p ' . PHP_BINARY
153
+		. ' -a ' . exec('whoami')
154
+		. ' -w ' . Icinga::app()->getConfigDir();
155 155
 	        
156 156
 	// ******************* configuration form setup*******************
157 157
 	$this->view->form = $form = new TrapsConfigForm();
@@ -196,19 +196,19 @@  discard block
 block discarded – undo
196 196
 		  $dbResource = ResourceFactory::getResourceConfig($dbName);
197 197
 		  $dbType=$dbResource->get('db');
198 198
 		  switch ($dbType) {
199
-		      case 'mysql':
200
-		          $dbFileExt='sql';
201
-		          break;
202
-		      case 'pgsql':
203
-		          $dbFileExt='pgsql';
204
-		          break;
205
-		      default:
206
-		          throw new ConfigurationError('Unsuported database : '.$dbType);
199
+			  case 'mysql':
200
+				  $dbFileExt='sql';
201
+				  break;
202
+			  case 'pgsql':
203
+				  $dbFileExt='pgsql';
204
+				  break;
205
+			  default:
206
+				  throw new ConfigurationError('Unsuported database : '.$dbType);
207 207
 		  }
208 208
 		} catch (ConfigurationError $e )
209 209
 		{
210
-		    printf("Database configuration error : %s",$e->getMessage());
211
-		    return;
210
+			printf("Database configuration error : %s",$e->getMessage());
211
+			return;
212 212
 		}
213 213
 		printf('<pre>');
214 214
 		require_once $this->Module()->getBaseDir() .'/bin/trap_class.php';
@@ -232,11 +232,11 @@  discard block
 block discarded – undo
232 232
   public function updateschemaAction()
233 233
   {
234 234
 	  $this->checkModuleConfigPermission();
235
-    	$this->getTabs()->add('get',array(
236
-    		'active'	=> true,
237
-    		'label'		=> $this->translate('Update Schema'),
238
-    		'url'		=> Url::fromRequest()
239
-    	));
235
+		$this->getTabs()->add('get',array(
236
+			'active'	=> true,
237
+			'label'		=> $this->translate('Update Schema'),
238
+			'url'		=> Url::fromRequest()
239
+		));
240 240
 	  // check if needed
241 241
 	  
242 242
 	  $dberror=$this->getDb(true); // Get DB in test mode
@@ -245,15 +245,15 @@  discard block
 block discarded – undo
245 245
 	  
246 246
 	  if ($dberror[0] == 0)
247 247
 	  {
248
-	      echo 'Schema already exists and is up to date<br>';
249
-	      return;
248
+		  echo 'Schema already exists and is up to date<br>';
249
+		  return;
250 250
 	  }
251 251
 	  if ($dberror[0] != 5)
252 252
 	  {
253
-	      echo 'Database does not exists or is not setup correctly<br>';
254
-	      return;
253
+		  echo 'Database does not exists or is not setup correctly<br>';
254
+		  return;
255 255
 	  }
256
-      // setup
256
+	  // setup
257 257
 	  require_once($this->Module()->getBaseDir() .'/bin/trap_class.php');
258 258
 	  $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc');
259 259
 	  $debug_level=4;
@@ -266,20 +266,20 @@  discard block
 block discarded – undo
266 266
 	  $target_version=$dberror[2];
267 267
 	  
268 268
 	  if ($this->params->get('msgok') == null) {
269
-	      // Check for messages and display if any
270
-              echo "Upgrade databse is going to start.<br>Don't forget to backup your database before update<br>";
271
-	      $Trap->setLogging(2,'syslog');
272
-	      $message = $Trap->update_schema($updateSchema,$target_version,$prefix,true);
273
-	      if ($message != '')
274
-	      {
275
-	          echo 'Note :<br><pre>';
276
-	          echo $message;
277
-	          echo '</pre>';
278
-	          echo '<br>';
279
-	          echo '<a  class="link-button" style="font-size:large;font-weight:bold" href="' . Url::fromPath('trapdirector/settings/updateschema') .'?msgok=1">Click here to update</a>';
280
-	          echo '<br>';
281
-	          return;
282
-	      }
269
+		  // Check for messages and display if any
270
+			  echo "Upgrade databse is going to start.<br>Don't forget to backup your database before update<br>";
271
+		  $Trap->setLogging(2,'syslog');
272
+		  $message = $Trap->update_schema($updateSchema,$target_version,$prefix,true);
273
+		  if ($message != '')
274
+		  {
275
+			  echo 'Note :<br><pre>';
276
+			  echo $message;
277
+			  echo '</pre>';
278
+			  echo '<br>';
279
+			  echo '<a  class="link-button" style="font-size:large;font-weight:bold" href="' . Url::fromPath('trapdirector/settings/updateschema') .'?msgok=1">Click here to update</a>';
280
+			  echo '<br>';
281
+			  return;
282
+		  }
283 283
 	  }
284 284
 	  
285 285
 	  $Trap->setLogging($debug_level,'display');
@@ -293,28 +293,28 @@  discard block
 block discarded – undo
293 293
 
294 294
   private function checkSnmpTrapd()
295 295
   {
296
-      $psOutput=array();
297
-      // First check is someone is listening to port 162. As not root, we can't have pid... 
298
-      exec('netstat -an |grep -E "udp.*:162"',$psOutput);
299
-      if (count($psOutput) == 0)
300
-      {
301
-          return array(1,'Port UDP/162 is not open : snmptrapd must not be started');
302
-      }
303
-      $psOutput=array();
304
-      exec('ps fax |grep snmptrapd |grep -v grep',$psOutput);
305
-      if (count($psOutput) == 0)
306
-      {
307
-          return array(1,"UDP/162 : OK, but no snmptrapd process (?)");
308
-      }
309
-      // Assume there is only one line... TODO : see if there is a better way to do this
310
-      $line = preg_replace('/^.*snmptrapd /','',$psOutput[0]);
311
-      if (!preg_match('/-n/',$line))
312
-          return array(1,'snmptrapd has no -n option : '.$line);
313
-      if (!preg_match('/-O[^ ]*n/',$line))
314
-          return array(1,'snmptrapd has no -On option : '.$line);
315
-      if (!preg_match('/-O[^ ]*e/',$line))
316
-          return array(1,'snmptrapd has no -Oe option : '.$line);
296
+	  $psOutput=array();
297
+	  // First check is someone is listening to port 162. As not root, we can't have pid... 
298
+	  exec('netstat -an |grep -E "udp.*:162"',$psOutput);
299
+	  if (count($psOutput) == 0)
300
+	  {
301
+		  return array(1,'Port UDP/162 is not open : snmptrapd must not be started');
302
+	  }
303
+	  $psOutput=array();
304
+	  exec('ps fax |grep snmptrapd |grep -v grep',$psOutput);
305
+	  if (count($psOutput) == 0)
306
+	  {
307
+		  return array(1,"UDP/162 : OK, but no snmptrapd process (?)");
308
+	  }
309
+	  // Assume there is only one line... TODO : see if there is a better way to do this
310
+	  $line = preg_replace('/^.*snmptrapd /','',$psOutput[0]);
311
+	  if (!preg_match('/-n/',$line))
312
+		  return array(1,'snmptrapd has no -n option : '.$line);
313
+	  if (!preg_match('/-O[^ ]*n/',$line))
314
+		  return array(1,'snmptrapd has no -On option : '.$line);
315
+	  if (!preg_match('/-O[^ ]*e/',$line))
316
+		  return array(1,'snmptrapd has no -Oe option : '.$line);
317 317
       
318
-      return array(0,'snmptrapd listening to UDP/162, options : '.$line);
318
+	  return array(0,'snmptrapd listening to UDP/162, options : '.$line);
319 319
   }
320 320
 }
Please login to merge, or discard this patch.
Spacing   +63 added lines, -63 removed lines patch added patch discarded remove patch
@@ -55,15 +55,15 @@  discard block
 block discarded – undo
55 55
     }
56 56
 	// Test Database
57 57
 	$db_message=array( // index => ( message OK, message NOK, optional link if NOK ) 
58
-		0	=>	array('Database configuration OK','',''),
59
-		1	=>	array('Database set in config.ini','No database in config.ini',''),
60
-		2	=>	array('Database exists in Icingaweb2 config','Database does not exist in Icingaweb2 : ',
58
+		0	=>	array('Database configuration OK', '', ''),
59
+		1	=>	array('Database set in config.ini', 'No database in config.ini', ''),
60
+		2	=>	array('Database exists in Icingaweb2 config', 'Database does not exist in Icingaweb2 : ',
61 61
 					Url::fromPath('config/resource')),
62
-		3	=>	array('Database credentials OK','Database does not exist/invalid credentials/no schema : ',
62
+		3	=>	array('Database credentials OK', 'Database does not exist/invalid credentials/no schema : ',
63 63
 					Url::fromPath('trapdirector/settings/createschema')),
64
-		4	=>	array('Schema is set','Schema is not set for ',
64
+		4	=>	array('Schema is set', 'Schema is not set for ',
65 65
 					Url::fromPath('trapdirector/settings/createschema')),					
66
-		5	=>	array('Schema is up to date','Schema is outdated :',
66
+		5	=>	array('Schema is up to date', 'Schema is outdated :',
67 67
 					Url::fromPath('trapdirector/settings/updateschema')),
68 68
 	);
69 69
 		
@@ -74,13 +74,13 @@  discard block
 block discarded – undo
74 74
 	{
75 75
 		case 2:
76 76
 		case 4:
77
-			$db_message[$dberror[0]][1] .= $dberror[1];
77
+			$db_message[$dberror[0]][1].=$dberror[1];
78 78
 			break;
79 79
 		case 3:
80
-			$db_message[$dberror[0]][1] .= $dberror[1] . ', Message : ' . $dberror[2];
80
+			$db_message[$dberror[0]][1].=$dberror[1].', Message : '.$dberror[2];
81 81
 			break;
82 82
 		case 5:
83
-			$db_message[$dberror[0]][1] .= ' version '. $dberror[1] . ', version needed : ' .$dberror[2];
83
+			$db_message[$dberror[0]][1].=' version '.$dberror[1].', version needed : '.$dberror[2];
84 84
 			break;
85 85
 		case 0:
86 86
 		case 1:
@@ -92,18 +92,18 @@  discard block
 block discarded – undo
92 92
 	
93 93
 	$dberror=$this->getIdoDb(true); // Get IDO DB in test mode
94 94
 	$this->view->ido_db_error=$dberror[0];
95
-	$this->view->ido_message='IDO Database : ' . $dberror[1];
95
+	$this->view->ido_message='IDO Database : '.$dberror[1];
96 96
 	
97 97
 	//********* Test API
98 98
 	if ($this->Config()->get('config', 'icingaAPI_host') != '')
99 99
 	{
100
-	    $apitest=new Icinga2Api($this->Config()->get('config', 'icingaAPI_host'),$this->Config()->get('config', 'icingaAPI_port'));
100
+	    $apitest=new Icinga2Api($this->Config()->get('config', 'icingaAPI_host'), $this->Config()->get('config', 'icingaAPI_port'));
101 101
     	$apitest->setCredentials($this->Config()->get('config', 'icingaAPI_user'), $this->Config()->get('config', 'icingaAPI_password'));
102 102
     	try {
103
-    	    list($this->view->apimessageError,$this->view->apimessage)=$apitest->test($this->getModuleConfig()::getapiUserPermissions());
103
+    	    list($this->view->apimessageError, $this->view->apimessage)=$apitest->test($this->getModuleConfig()::getapiUserPermissions());
104 104
     	    //$this->view->apimessageError=false;
105 105
     	} catch (RuntimeException $e) {
106
-    	    $this->view->apimessage='API config : ' . $e->getMessage();
106
+    	    $this->view->apimessage='API config : '.$e->getMessage();
107 107
     	    $this->view->apimessageError=true;
108 108
     	} 
109 109
 	}
@@ -114,18 +114,18 @@  discard block
 block discarded – undo
114 114
 	}
115 115
 	
116 116
 	//*********** Test snmptrapd alive and options
117
-	list ($this->view->snmptrapdError, $this->view->snmptrapdMessage) = $this->checkSnmpTrapd();
117
+	list ($this->view->snmptrapdError, $this->view->snmptrapdMessage)=$this->checkSnmpTrapd();
118 118
 
119 119
 	// List DB in $ressources
120
-	$resources = array();
121
-	$allowed = array('mysql', 'pgsql');
120
+	$resources=array();
121
+	$allowed=array('mysql', 'pgsql');
122 122
 	foreach (ResourceFactory::getResourceConfigs() as $name => $resource) {
123 123
 		if ($resource->get('type') === 'db' && in_array($resource->get('db'), $allowed)) {
124
-			$resources[$name] = $name;
124
+			$resources[$name]=$name;
125 125
 		}
126 126
 	}
127 127
 
128
-    $this->view->tabs = $this->Module()->getConfigTabs()->activate('config');
128
+    $this->view->tabs=$this->Module()->getConfigTabs()->activate('config');
129 129
 
130 130
 	// Check standard Icingaweb2 path
131 131
 	$this->view->icingaEtcWarn=0;
@@ -134,9 +134,9 @@  discard block
 block discarded – undo
134 134
 	{
135 135
 	    $output=array();
136 136
 	    
137
-	    exec('cat ' . $this->module->getBaseDir() .'/bin/trap_in.php | grep "\$icingaweb2_etc=" ',$output);
137
+	    exec('cat '.$this->module->getBaseDir().'/bin/trap_in.php | grep "\$icingaweb2_etc=" ', $output);
138 138
 	    
139
-	    if (! preg_match('#"'. $icingaweb2_etc .'"#',$output[0]))
139
+	    if (!preg_match('#"'.$icingaweb2_etc.'"#', $output[0]))
140 140
 	    {
141 141
     	    $this->view->icingaEtcWarn=1;
142 142
 	        $this->view->icingaweb2_etc=$icingaweb2_etc;
@@ -144,23 +144,23 @@  discard block
 block discarded – undo
144 144
 	}
145 145
 
146 146
 	// Setup path for mini documentation
147
-	$this->view->traps_in_config= PHP_BINARY . ' ' . $this->Module()->getBaseDir() . '/bin/trap_in.php';
147
+	$this->view->traps_in_config=PHP_BINARY.' '.$this->Module()->getBaseDir().'/bin/trap_in.php';
148 148
 	
149
-	$this->view->installer= $this->Module()->getBaseDir() . '/bin/installer.sh '
149
+	$this->view->installer=$this->Module()->getBaseDir().'/bin/installer.sh '
150 150
 	    . ' -c all ' 
151
-	    . ' -d ' . $this->Module()->getBaseDir()
152
-	    . ' -p ' . PHP_BINARY
153
-	    . ' -a ' . exec('whoami')
154
-	    . ' -w ' . Icinga::app()->getConfigDir();
151
+	    . ' -d '.$this->Module()->getBaseDir()
152
+	    . ' -p '.PHP_BINARY
153
+	    . ' -a '.exec('whoami')
154
+	    . ' -w '.Icinga::app()->getConfigDir();
155 155
 	        
156 156
 	// ******************* configuration form setup*******************
157
-	$this->view->form = $form = new TrapsConfigForm();
157
+	$this->view->form=$form=new TrapsConfigForm();
158 158
 	
159 159
 	// set default paths;
160
-	$this->view->form->setPaths($this->Module()->getBaseDir(),Icinga::app()->getConfigDir());
160
+	$this->view->form->setPaths($this->Module()->getBaseDir(), Icinga::app()->getConfigDir());
161 161
 	
162 162
 	// set default ido database
163
-	$this->view->form->setDefaultIDODB($this->Config()->module('monitoring','backends')->get('icinga','resource'));
163
+	$this->view->form->setDefaultIDODB($this->Config()->module('monitoring', 'backends')->get('icinga', 'resource'));
164 164
 	
165 165
 	// Make form handle request.
166 166
 	$form->setIniConfig($this->Config())
@@ -172,7 +172,7 @@  discard block
 block discarded – undo
172 172
   public function createschemaAction()
173 173
   {
174 174
 	$this->checkModuleConfigPermission();
175
-	$this->getTabs()->add('create_schema',array(
175
+	$this->getTabs()->add('create_schema', array(
176 176
 		'active'	=> true,
177 177
 		'label'		=> $this->translate('Create Schema'),
178 178
 		'url'		=> Url::fromRequest()
@@ -193,7 +193,7 @@  discard block
 block discarded – undo
193 193
 		$dbName=$this->Config()->get('config', 'database');
194 194
 
195 195
 		try {
196
-		  $dbResource = ResourceFactory::getResourceConfig($dbName);
196
+		  $dbResource=ResourceFactory::getResourceConfig($dbName);
197 197
 		  $dbType=$dbResource->get('db');
198 198
 		  switch ($dbType) {
199 199
 		      case 'mysql':
@@ -205,34 +205,34 @@  discard block
 block discarded – undo
205 205
 		      default:
206 206
 		          throw new ConfigurationError('Unsuported database : '.$dbType);
207 207
 		  }
208
-		} catch (ConfigurationError $e )
208
+		} catch (ConfigurationError $e)
209 209
 		{
210
-		    printf("Database configuration error : %s",$e->getMessage());
210
+		    printf("Database configuration error : %s", $e->getMessage());
211 211
 		    return;
212 212
 		}
213 213
 		printf('<pre>');
214
-		require_once $this->Module()->getBaseDir() .'/bin/trap_class.php';
214
+		require_once $this->Module()->getBaseDir().'/bin/trap_class.php';
215 215
 		
216 216
 		$icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc');
217 217
 		$debug_level=4;
218
-		$Trap = new Trap($icingaweb2_etc);
219
-		$Trap->setLogging($debug_level,'display');
218
+		$Trap=new Trap($icingaweb2_etc);
219
+		$Trap->setLogging($debug_level, 'display');
220 220
 		
221 221
 		$prefix=$this->Config()->get('config', 'database_prefix');
222 222
 		// schema file : <path>/SQL/schema_v<verion>.<dbtype>
223
-		$schema=$this->Module()->getBaseDir() . 
224
-		'/SQL/schema_v'. $this->getModuleConfig()->getDbCurVersion() . '.' . $dbFileExt;
223
+		$schema=$this->Module()->getBaseDir(). 
224
+		'/SQL/schema_v'.$this->getModuleConfig()->getDbCurVersion().'.'.$dbFileExt;
225 225
 		
226
-		$Trap->create_schema($schema,$prefix);
226
+		$Trap->create_schema($schema, $prefix);
227 227
 		echo '</pre>';
228 228
 	}
229
-	echo '<br><br>Return to <a href="' . Url::fromPath('trapdirector/settings') .'" class="link-button icon-wrench"> settings page </a>';
229
+	echo '<br><br>Return to <a href="'.Url::fromPath('trapdirector/settings').'" class="link-button icon-wrench"> settings page </a>';
230 230
   }
231 231
 
232 232
   public function updateschemaAction()
233 233
   {
234 234
 	  $this->checkModuleConfigPermission();
235
-    	$this->getTabs()->add('get',array(
235
+    	$this->getTabs()->add('get', array(
236 236
     		'active'	=> true,
237 237
     		'label'		=> $this->translate('Update Schema'),
238 238
     		'url'		=> Url::fromRequest()
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
 	  
242 242
 	  $dberror=$this->getDb(true); // Get DB in test mode
243 243
 	  
244
-	  echo 'Return to <a href="' . Url::fromPath('trapdirector/settings') .'" class="link-button icon-wrench"> settings page </a><br><br>';
244
+	  echo 'Return to <a href="'.Url::fromPath('trapdirector/settings').'" class="link-button icon-wrench"> settings page </a><br><br>';
245 245
 	  
246 246
 	  if ($dberror[0] == 0)
247 247
 	  {
@@ -254,40 +254,40 @@  discard block
 block discarded – undo
254 254
 	      return;
255 255
 	  }
256 256
       // setup
257
-	  require_once($this->Module()->getBaseDir() .'/bin/trap_class.php');
257
+	  require_once($this->Module()->getBaseDir().'/bin/trap_class.php');
258 258
 	  $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc');
259 259
 	  $debug_level=4;
260
-	  $Trap = new Trap($icingaweb2_etc);
260
+	  $Trap=new Trap($icingaweb2_etc);
261 261
 	  
262 262
 	  
263 263
 	  $prefix=$this->Config()->get('config', 'database_prefix');
264
-	  $updateSchema=$this->Module()->getBaseDir() . '/SQL/';
264
+	  $updateSchema=$this->Module()->getBaseDir().'/SQL/';
265 265
 	  
266 266
 	  $target_version=$dberror[2];
267 267
 	  
268 268
 	  if ($this->params->get('msgok') == null) {
269 269
 	      // Check for messages and display if any
270 270
               echo "Upgrade databse is going to start.<br>Don't forget to backup your database before update<br>";
271
-	      $Trap->setLogging(2,'syslog');
272
-	      $message = $Trap->update_schema($updateSchema,$target_version,$prefix,true);
271
+	      $Trap->setLogging(2, 'syslog');
272
+	      $message=$Trap->update_schema($updateSchema, $target_version, $prefix, true);
273 273
 	      if ($message != '')
274 274
 	      {
275 275
 	          echo 'Note :<br><pre>';
276 276
 	          echo $message;
277 277
 	          echo '</pre>';
278 278
 	          echo '<br>';
279
-	          echo '<a  class="link-button" style="font-size:large;font-weight:bold" href="' . Url::fromPath('trapdirector/settings/updateschema') .'?msgok=1">Click here to update</a>';
279
+	          echo '<a  class="link-button" style="font-size:large;font-weight:bold" href="'.Url::fromPath('trapdirector/settings/updateschema').'?msgok=1">Click here to update</a>';
280 280
 	          echo '<br>';
281 281
 	          return;
282 282
 	      }
283 283
 	  }
284 284
 	  
285
-	  $Trap->setLogging($debug_level,'display');
285
+	  $Trap->setLogging($debug_level, 'display');
286 286
 	  
287
-	  echo 'Updating schema to '. $target_version . ': <br>';
287
+	  echo 'Updating schema to '.$target_version.': <br>';
288 288
 	  echo '<pre>';
289 289
 	  	  
290
-	  $Trap->update_schema($updateSchema,$target_version,$prefix);
290
+	  $Trap->update_schema($updateSchema, $target_version, $prefix);
291 291
 	  echo '</pre>';
292 292
   }  
293 293
 
@@ -295,26 +295,26 @@  discard block
 block discarded – undo
295 295
   {
296 296
       $psOutput=array();
297 297
       // First check is someone is listening to port 162. As not root, we can't have pid... 
298
-      exec('netstat -an |grep -E "udp.*:162"',$psOutput);
298
+      exec('netstat -an |grep -E "udp.*:162"', $psOutput);
299 299
       if (count($psOutput) == 0)
300 300
       {
301
-          return array(1,'Port UDP/162 is not open : snmptrapd must not be started');
301
+          return array(1, 'Port UDP/162 is not open : snmptrapd must not be started');
302 302
       }
303 303
       $psOutput=array();
304
-      exec('ps fax |grep snmptrapd |grep -v grep',$psOutput);
304
+      exec('ps fax |grep snmptrapd |grep -v grep', $psOutput);
305 305
       if (count($psOutput) == 0)
306 306
       {
307
-          return array(1,"UDP/162 : OK, but no snmptrapd process (?)");
307
+          return array(1, "UDP/162 : OK, but no snmptrapd process (?)");
308 308
       }
309 309
       // Assume there is only one line... TODO : see if there is a better way to do this
310
-      $line = preg_replace('/^.*snmptrapd /','',$psOutput[0]);
311
-      if (!preg_match('/-n/',$line))
312
-          return array(1,'snmptrapd has no -n option : '.$line);
313
-      if (!preg_match('/-O[^ ]*n/',$line))
314
-          return array(1,'snmptrapd has no -On option : '.$line);
315
-      if (!preg_match('/-O[^ ]*e/',$line))
316
-          return array(1,'snmptrapd has no -Oe option : '.$line);
310
+      $line=preg_replace('/^.*snmptrapd /', '', $psOutput[0]);
311
+      if (!preg_match('/-n/', $line))
312
+          return array(1, 'snmptrapd has no -n option : '.$line);
313
+      if (!preg_match('/-O[^ ]*n/', $line))
314
+          return array(1, 'snmptrapd has no -On option : '.$line);
315
+      if (!preg_match('/-O[^ ]*e/', $line))
316
+          return array(1, 'snmptrapd has no -Oe option : '.$line);
317 317
       
318
-      return array(0,'snmptrapd listening to UDP/162, options : '.$line);
318
+      return array(0, 'snmptrapd listening to UDP/162, options : '.$line);
319 319
   }
320 320
 }
Please login to merge, or discard this patch.
Braces   +18 added lines, -16 removed lines patch added patch discarded remove patch
@@ -28,11 +28,13 @@  discard block
 block discarded – undo
28 28
 	$this->checkReadPermission();
29 29
 	// Get message : sent on configuration problems detected by controllers
30 30
 	$dberrorMsg=$this->params->get('dberror');
31
-	if ($dberrorMsg != '')
32
-	    $this->view->errorDetected=$dberrorMsg;
31
+	if ($dberrorMsg != '') {
32
+		    $this->view->errorDetected=$dberrorMsg;
33
+	}
33 34
     $dberrorMsg=$this->params->get('idodberror');
34
-    if ($dberrorMsg != '')
35
-        $this->view->errorDetected=$dberrorMsg;
35
+    if ($dberrorMsg != '') {
36
+            $this->view->errorDetected=$dberrorMsg;
37
+    }
36 38
     
37 39
     $this->view->configErrorDetected == NULL; // Displayed error on various conifugration errors.
38 40
     
@@ -46,8 +48,7 @@  discard block
 block discarded – undo
46 48
             $this->Config()->saveIni();
47 49
             $this->view->configErrorDetected='Configuration is empty : you can run install script with parameters (see Automatic installation below)';
48 50
 			$emptyConfig=1;
49
-        }
50
-        catch (Exception $e)
51
+        } catch (Exception $e)
51 52
         {
52 53
             $this->view->configErrorDetected=$e->getMessage();
53 54
         }
@@ -106,8 +107,7 @@  discard block
 block discarded – undo
106 107
     	    $this->view->apimessage='API config : ' . $e->getMessage();
107 108
     	    $this->view->apimessageError=true;
108 109
     	} 
109
-	}
110
-	else
110
+	} else
111 111
 	{
112 112
 	    $this->view->apimessage='API parameters not configured';
113 113
 	    $this->view->apimessageError=true;
@@ -184,8 +184,7 @@  discard block
 block discarded – undo
184 184
 	if ($dberror[0] == 0)
185 185
 	{
186 186
 		printf('Schema already exists');
187
-	}
188
-	else
187
+	} else
189 188
 	{
190 189
 		printf('Creating schema : <br>');
191 190
 
@@ -308,12 +307,15 @@  discard block
 block discarded – undo
308 307
       }
309 308
       // Assume there is only one line... TODO : see if there is a better way to do this
310 309
       $line = preg_replace('/^.*snmptrapd /','',$psOutput[0]);
311
-      if (!preg_match('/-n/',$line))
312
-          return array(1,'snmptrapd has no -n option : '.$line);
313
-      if (!preg_match('/-O[^ ]*n/',$line))
314
-          return array(1,'snmptrapd has no -On option : '.$line);
315
-      if (!preg_match('/-O[^ ]*e/',$line))
316
-          return array(1,'snmptrapd has no -Oe option : '.$line);
310
+      if (!preg_match('/-n/',$line)) {
311
+                return array(1,'snmptrapd has no -n option : '.$line);
312
+      }
313
+      if (!preg_match('/-O[^ ]*n/',$line)) {
314
+                return array(1,'snmptrapd has no -On option : '.$line);
315
+      }
316
+      if (!preg_match('/-O[^ ]*e/',$line)) {
317
+                return array(1,'snmptrapd has no -Oe option : '.$line);
318
+      }
317 319
       
318 320
       return array(0,'snmptrapd listening to UDP/162, options : '.$line);
319 321
   }
Please login to merge, or discard this patch.
application/controllers/HandlerController.php 3 patches
Indentation   +88 added lines, -89 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();
@@ -39,29 +38,29 @@  discard block
 block discarded – undo
39 38
 	 */
40 39
 	public function testruleAction()
41 40
 	{
42
-	    $this->checkReadPermission();
43
-	    $this->getTabs()->add('get',array(
44
-	        'active'	=> true,
45
-	        'label'		=> $this->translate('Test Rule'),
46
-	        'url'		=> Url::fromRequest()
47
-	    ));
41
+		$this->checkReadPermission();
42
+		$this->getTabs()->add('get',array(
43
+			'active'	=> true,
44
+			'label'		=> $this->translate('Test Rule'),
45
+			'url'		=> Url::fromRequest()
46
+		));
48 47
 	    
49
-	    //$db = $this->getDb();
48
+		//$db = $this->getDb();
50 49
 
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
-	    }
50
+		if ($this->params->get('rule') !== null) 
51
+		{
52
+			$this->view->rule= $this->params->get('rule');
53
+		}
54
+		else
55
+		{
56
+			$this->view->rule='';
57
+		}
59 58
 	}
60 59
 	
61 60
 	/** Add a handler  
62
-	*	Get params fromid : setup from existing trap (id of trap table)
63
-	*	Get param ruleid : edit from existing handler (id of rule table)
64
-	*/
61
+	 *	Get params fromid : setup from existing trap (id of trap table)
62
+	 *	Get param ruleid : edit from existing handler (id of rule table)
63
+	 */
65 64
 	public function addAction()
66 65
 	{
67 66
 		$this->checkConfigPermission();
@@ -162,7 +161,7 @@  discard block
 block discarded – undo
162 161
 					$currentObjectTypeEnum=$allObjects[$val->oid]['type_enum'];
163 162
 				}
164 163
 				$currentObject=array(
165
-				    $oid_index,
164
+					$oid_index,
166 165
 					$val->oid,
167 166
 					$val->oid_name_mib,
168 167
 					$val->oid_name,
@@ -184,7 +183,7 @@  discard block
 block discarded – undo
184 183
 				{
185 184
 					if ($val==null) { continue; }
186 185
 					array_push($this->view->objectList, array(
187
-					    $oid_index,
186
+						$oid_index,
188 187
 						$key,
189 188
 						$allObjects[$key]['mib'],
190 189
 						$allObjects[$key]['name'],
@@ -223,61 +222,61 @@  discard block
 block discarded – undo
223 222
 			$this->view->warning_message='';
224 223
 			if ($this->view->hostname != null)
225 224
 			{
226
-			    $this->view->selectGroup=false;
227
-			    // Check if hostname still exists
228
-			    $host_get=$this->getHostByName($this->view->hostname);
225
+				$this->view->selectGroup=false;
226
+				// Check if hostname still exists
227
+				$host_get=$this->getHostByName($this->view->hostname);
229 228
 			    
230
-			    if (count($host_get)==0)
231
-			    {
232
-			        $this->view->warning_message='Host '.$this->view->hostname. ' doesn\'t exists anymore';
233
-			        $this->view->serviceGet=false;
234
-			    }
235
-			    else
236
-			    {
237
-    				// Tell JS to get services when page is loaded
238
-    				$this->view->serviceGet=true;
239
-    				// get service id for form to set :			
240
-    				$serviceID=$this->getServiceIDByName($this->view->hostname,$ruleDetail->service_name);
241
-    				if (count($serviceID) ==0)
242
-    				{
243
-    				    $this->view->warning_message=' Service '.$ruleDetail->service_name. ' doesn\'t exists anymore';
244
-    				} 
245
-    				else
246
-    				{
247
-    				    $this->view->serviceSet=$serviceID[0]->id;
248
-    				}
249
-			    }
229
+				if (count($host_get)==0)
230
+				{
231
+					$this->view->warning_message='Host '.$this->view->hostname. ' doesn\'t exists anymore';
232
+					$this->view->serviceGet=false;
233
+				}
234
+				else
235
+				{
236
+					// Tell JS to get services when page is loaded
237
+					$this->view->serviceGet=true;
238
+					// get service id for form to set :			
239
+					$serviceID=$this->getServiceIDByName($this->view->hostname,$ruleDetail->service_name);
240
+					if (count($serviceID) ==0)
241
+					{
242
+						$this->view->warning_message=' Service '.$ruleDetail->service_name. ' doesn\'t exists anymore';
243
+					} 
244
+					else
245
+					{
246
+						$this->view->serviceSet=$serviceID[0]->id;
247
+					}
248
+				}
250 249
 			}
251 250
 			else
252 251
 			{
253
-			    $this->view->selectGroup=true;
254
-			    // Check if groupe exists
255
-			    $group_get=$this->getHostGroupByName($this->view->hostgroupname);
256
-			    if (count($group_get)==0)
257
-			    {
258
-			        $this->view->warning_message='HostGroup '.$this->view->hostgroupname. ' doesn\'t exists anymore';
259
-			        $this->view->serviceGroupGet=false;
260
-			    }
261
-			    else
262
-			    {
263
-			        $grpServices=$this->getServicesByHostGroupid($group_get[0]->id);
264
-			        $foundGrpService=0;
265
-			        foreach ($grpServices as $grpService)
266
-			        {
267
-			            if ($grpService[0] == $ruleDetail->service_name)
268
-			            {
269
-			                $foundGrpService=1;
270
-			                $this->view->serviceSet=$ruleDetail->service_name;
271
-			            }
272
-			        }
252
+				$this->view->selectGroup=true;
253
+				// Check if groupe exists
254
+				$group_get=$this->getHostGroupByName($this->view->hostgroupname);
255
+				if (count($group_get)==0)
256
+				{
257
+					$this->view->warning_message='HostGroup '.$this->view->hostgroupname. ' doesn\'t exists anymore';
258
+					$this->view->serviceGroupGet=false;
259
+				}
260
+				else
261
+				{
262
+					$grpServices=$this->getServicesByHostGroupid($group_get[0]->id);
263
+					$foundGrpService=0;
264
+					foreach ($grpServices as $grpService)
265
+					{
266
+						if ($grpService[0] == $ruleDetail->service_name)
267
+						{
268
+							$foundGrpService=1;
269
+							$this->view->serviceSet=$ruleDetail->service_name;
270
+						}
271
+					}
273 272
 			        
274
-			        // Tell JS to get services when page is loaded
275
-			        $this->view->serviceGroupGet=true;
276
-			        if ($foundGrpService==0)
277
-			        {
278
-			            $this->view->warning_message.=' Service '.$ruleDetail->service_name. ' doesn\'t exists anymore';
279
-			        }
280
-			    }				
273
+					// Tell JS to get services when page is loaded
274
+					$this->view->serviceGroupGet=true;
275
+					if ($foundGrpService==0)
276
+					{
277
+						$this->view->warning_message.=' Service '.$ruleDetail->service_name. ' doesn\'t exists anymore';
278
+					}
279
+				}				
281 280
 			}
282 281
 			$this->view->mainoid=$ruleDetail->trap_oid;
283 282
 			$oidName=$this->getMIB()->translateOID($ruleDetail->trap_oid);
@@ -302,7 +301,7 @@  discard block
 block discarded – undo
302 301
 				if (($object=$this->getMIB()->translateOID($curOid)) != null)
303 302
 				{
304 303
 					array_push($curObjectList, array(
305
-					    $index,
304
+						$index,
306 305
 						$curOid,
307 306
 						$object['mib'],
308 307
 						$object['name'],
@@ -314,7 +313,7 @@  discard block
 block discarded – undo
314 313
 				else
315 314
 				{
316 315
 					array_push($curObjectList, array(
317
-					    $index,
316
+						$index,
318 317
 						$curOid,
319 318
 						'not found',
320 319
 						'not found',
@@ -335,9 +334,9 @@  discard block
 block discarded – undo
335 334
 	}
336 335
 	
337 336
 	/** Validate form and output message to user  
338
-	*	@param in postdata 
339
-	* 	@return string status : OK / <Message>
340
-	**/
337
+	 *	@param in postdata 
338
+	 * 	@return string status : OK / <Message>
339
+	 **/
341 340
 	protected function handlerformAction()
342 341
 	{
343 342
 		$postData=$this->getRequest()->getPost();
@@ -378,7 +377,7 @@  discard block
 block discarded – undo
378 377
 			//$this->Module()->
379 378
 			$this->_helper->json(array(
380 379
 				'status'=>'OK',
381
-			    'redirect'=>'trapdirector/handler'
380
+				'redirect'=>'trapdirector/handler'
382 381
 			      
383 382
 			));
384 383
 		}		
@@ -462,9 +461,9 @@  discard block
 block discarded – undo
462 461
 	}
463 462
 
464 463
 	/** Get trap detail by trapid. 
465
-	*	@param $trapid int id of trap in received table
466
-	*	@return array (objects)
467
-	*/
464
+	 *	@param $trapid int id of trap in received table
465
+	 *	@return array (objects)
466
+	 */
468 467
 	protected function getTrapDetail($trapid) 
469 468
 	{
470 469
 		if (!preg_match('/^[0-9]+$/',$trapid)) { throw new Exception('Invalid id');  }
@@ -495,9 +494,9 @@  discard block
 block discarded – undo
495 494
 	}
496 495
 
497 496
 	/** Get trap objects
498
-	*	@param : trap id
499
-	* 	@return array of objects
500
-	*/
497
+	 *	@param : trap id
498
+	 * 	@return array of objects
499
+	 */
501 500
 	protected function getTrapobjects($trapid)
502 501
 	{	
503 502
 		if (!preg_match('/^[0-9]+$/',$trapid)) { throw new Exception('Invalid id');  }
@@ -527,9 +526,9 @@  discard block
 block discarded – undo
527 526
 	}
528 527
 
529 528
 	/** Get rule detail by ruleid.
530
-	*	@param $ruleid int id of rule in rule table
531
-	*	@return array (objects)
532
-	*/
529
+	 *	@param $ruleid int id of rule in rule table
530
+	 *	@return array (objects)
531
+	 */
533 532
 	protected function getRuleDetail($ruleid) 
534 533
 	{
535 534
 		if (!preg_match('/^[0-9]+$/',$ruleid)) { throw new Exception('Invalid id');  }
@@ -555,7 +554,7 @@  discard block
 block discarded – undo
555 554
 	}
556 555
 
557 556
 	/** Setup tabs for rules 
558
-	*/
557
+	 */
559 558
 	protected function prepareTabs()
560 559
 	{
561 560
 		return $this->getTabs()->add('status', array(
Please login to merge, or discard this patch.
Spacing   +76 added lines, -76 removed lines patch added patch discarded remove patch
@@ -23,14 +23,14 @@  discard block
 block discarded – undo
23 23
 		$this->checkReadPermission();
24 24
 		$this->prepareTabs()->activate('status');
25 25
 
26
-		$db = $this->getDb();
26
+		$db=$this->getDb();
27 27
 		$this->getHandlerListTable()->setConnection($db);
28 28
 		$this->getHandlerListTable()->setMibloader($this->getMIB());
29 29
 		// Apply pagination limits 
30
-		$this->view->table=$this->applyPaginationLimits($this->getHandlerListTable(),$this->getModuleConfig()->itemListDisplay());		
30
+		$this->view->table=$this->applyPaginationLimits($this->getHandlerListTable(), $this->getModuleConfig()->itemListDisplay());		
31 31
 		
32 32
 		// Set Filter
33
-		$this->view->filterEditor = $this->getHandlerListTable()->getFilterEditor($this->getRequest());		
33
+		$this->view->filterEditor=$this->getHandlerListTable()->getFilterEditor($this->getRequest());		
34 34
 	
35 35
 		//$this->displayExitError('Handler/indexAction','Not implemented');
36 36
 	}
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
 	public function testruleAction()
41 41
 	{
42 42
 	    $this->checkReadPermission();
43
-	    $this->getTabs()->add('get',array(
43
+	    $this->getTabs()->add('get', array(
44 44
 	        'active'	=> true,
45 45
 	        'label'		=> $this->translate('Test Rule'),
46 46
 	        'url'		=> Url::fromRequest()
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
 
51 51
 	    if ($this->params->get('rule') !== null) 
52 52
 	    {
53
-	        $this->view->rule= $this->params->get('rule');
53
+	        $this->view->rule=$this->params->get('rule');
54 54
 	    }
55 55
 	    else
56 56
 	    {
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
 	{
67 67
 		$this->checkConfigPermission();
68 68
 		// set up tab
69
-		$this->getTabs()->add('get',array(
69
+		$this->getTabs()->add('get', array(
70 70
 			'active'	=> true,
71 71
 			'label'		=> $this->translate('Add handler'),
72 72
 			'url'		=> Url::fromRequest()
@@ -116,12 +116,12 @@  discard block
 block discarded – undo
116 116
 			}
117 117
 			catch (Exception $e)
118 118
 			{
119
-				$this->displayExitError('Add handler : get host by IP/Name ',$e->getMessage());
119
+				$this->displayExitError('Add handler : get host by IP/Name ', $e->getMessage());
120 120
 			}
121 121
 			
122 122
 			
123 123
 			// if one unique host found -> put id text input
124
-			if (count($hosts)==1) {
124
+			if (count($hosts) == 1) {
125 125
 				$this->view->hostname=$hosts[0]->name;
126 126
 				//$hostid=$hosts[0]->id;
127 127
 				// Tell JS to get services when page is loaded
@@ -130,9 +130,9 @@  discard block
 block discarded – undo
130 130
 			}
131 131
 			else
132 132
 			{
133
-				foreach($hosts as $key=>$val)
133
+				foreach ($hosts as $key=>$val)
134 134
 				{
135
-					array_push($this->view->hostlist,$hosts[$key]->name);
135
+					array_push($this->view->hostlist, $hosts[$key]->name);
136 136
 				}
137 137
 			}
138 138
 			
@@ -171,18 +171,18 @@  discard block
 block discarded – undo
171 171
 					$currentObjectTypeEnum
172 172
 				);
173 173
 				$oid_index++;
174
-				array_push($this->view->objectList,$currentObject);
174
+				array_push($this->view->objectList, $currentObject);
175 175
 				// set currrent object to null in allObjects
176 176
 				if (isset($allObjects[$val->oid]))
177 177
 				{
178 178
 					$allObjects[$val->oid]=null;
179 179
 				}
180 180
 			}
181
-			if ($allObjects!=null) // in case trap doesn't have objects or is not resolved
181
+			if ($allObjects != null) // in case trap doesn't have objects or is not resolved
182 182
 			{
183 183
 				foreach ($allObjects as $key => $val)
184 184
 				{
185
-					if ($val==null) { continue; }
185
+					if ($val == null) { continue; }
186 186
 					array_push($this->view->objectList, array(
187 187
 					    $oid_index,
188 188
 						$key,
@@ -216,7 +216,7 @@  discard block
 block discarded – undo
216 216
 			$this->view->setRuleMatch=$ruleDetail->action_match;
217 217
 			$this->view->setRuleNoMatch=$ruleDetail->action_nomatch;
218 218
 			$this->view->hostgroupname=$ruleDetail->host_group_name;
219
-			$this->view->modified=gmdate("Y-m-d\TH:i:s\Z",$ruleDetail->modified);
219
+			$this->view->modified=gmdate("Y-m-d\TH:i:s\Z", $ruleDetail->modified);
220 220
 			$this->view->modifier=$ruleDetail->modifier;
221 221
 			
222 222
 			// Warning message if host/service don't exists anymore
@@ -227,9 +227,9 @@  discard block
 block discarded – undo
227 227
 			    // Check if hostname still exists
228 228
 			    $host_get=$this->getHostByName($this->view->hostname);
229 229
 			    
230
-			    if (count($host_get)==0)
230
+			    if (count($host_get) == 0)
231 231
 			    {
232
-			        $this->view->warning_message='Host '.$this->view->hostname. ' doesn\'t exists anymore';
232
+			        $this->view->warning_message='Host '.$this->view->hostname.' doesn\'t exists anymore';
233 233
 			        $this->view->serviceGet=false;
234 234
 			    }
235 235
 			    else
@@ -237,10 +237,10 @@  discard block
 block discarded – undo
237 237
     				// Tell JS to get services when page is loaded
238 238
     				$this->view->serviceGet=true;
239 239
     				// get service id for form to set :			
240
-    				$serviceID=$this->getServiceIDByName($this->view->hostname,$ruleDetail->service_name);
241
-    				if (count($serviceID) ==0)
240
+    				$serviceID=$this->getServiceIDByName($this->view->hostname, $ruleDetail->service_name);
241
+    				if (count($serviceID) == 0)
242 242
     				{
243
-    				    $this->view->warning_message=' Service '.$ruleDetail->service_name. ' doesn\'t exists anymore';
243
+    				    $this->view->warning_message=' Service '.$ruleDetail->service_name.' doesn\'t exists anymore';
244 244
     				} 
245 245
     				else
246 246
     				{
@@ -253,9 +253,9 @@  discard block
 block discarded – undo
253 253
 			    $this->view->selectGroup=true;
254 254
 			    // Check if groupe exists
255 255
 			    $group_get=$this->getHostGroupByName($this->view->hostgroupname);
256
-			    if (count($group_get)==0)
256
+			    if (count($group_get) == 0)
257 257
 			    {
258
-			        $this->view->warning_message='HostGroup '.$this->view->hostgroupname. ' doesn\'t exists anymore';
258
+			        $this->view->warning_message='HostGroup '.$this->view->hostgroupname.' doesn\'t exists anymore';
259 259
 			        $this->view->serviceGroupGet=false;
260 260
 			    }
261 261
 			    else
@@ -273,9 +273,9 @@  discard block
 block discarded – undo
273 273
 			        
274 274
 			        // Tell JS to get services when page is loaded
275 275
 			        $this->view->serviceGroupGet=true;
276
-			        if ($foundGrpService==0)
276
+			        if ($foundGrpService == 0)
277 277
 			        {
278
-			            $this->view->warning_message.=' Service '.$ruleDetail->service_name. ' doesn\'t exists anymore';
278
+			            $this->view->warning_message.=' Service '.$ruleDetail->service_name.' doesn\'t exists anymore';
279 279
 			        }
280 280
 			    }				
281 281
 			}
@@ -295,8 +295,8 @@  discard block
 block discarded – undo
295 295
 			$index=1; 
296 296
 			// check in display & rule for : OID(<oid>)
297 297
 			$matches=array();
298
-			while ( preg_match('/_OID\(([\.0-9]+)\)/',$display,$matches) ||
299
-					preg_match('/_OID\(([\.0-9]+)\)/',$rule,$matches))
298
+			while (preg_match('/_OID\(([\.0-9]+)\)/', $display, $matches) ||
299
+					preg_match('/_OID\(([\.0-9]+)\)/', $rule, $matches))
300 300
 			{
301 301
 				$curOid=$matches[1];
302 302
 				if (($object=$this->getMIB()->translateOID($curOid)) != null)
@@ -322,8 +322,8 @@  discard block
 block discarded – undo
322 322
 						'not found'
323 323
 					));
324 324
 				}
325
-				$display=preg_replace('/_OID\('.$curOid.'\)/','\$'.$index.'\$',$display);
326
-				$rule=preg_replace('/_OID\('.$curOid.'\)/','\$'.$index.'\$',$rule);
325
+				$display=preg_replace('/_OID\('.$curOid.'\)/', '\$'.$index.'\$', $display);
326
+				$rule=preg_replace('/_OID\('.$curOid.'\)/', '\$'.$index.'\$', $rule);
327 327
 				$index++;
328 328
 			}
329 329
 			// set display
@@ -345,26 +345,26 @@  discard block
 block discarded – undo
345 345
 	
346 346
 		$params=array(
347 347
 			// id (also db) => 	array('post' => post id, 'val' => default val, 'db' => send to table)
348
-			'hostgroup'		=>	array('post' => 'hostgroup','db'=>false),
349
-			'db_rule'		=>	array('post' => 'db_rule','db'=>false),
350
-			'hostid'		=>	array('post' => 'hostid','db'=>false),
351
-			'host_name'		=>	array('post' => 'hostname','val' => null,'db'=>true),
352
-			'host_group_name'=>	array('post' => null,'val' => null,'db'=>true),
353
-			'serviceid'		=>	array('post' => 'serviceid','db'=>false),
354
-			'service_name'	=>	array('post' => 'serviceName','db'=>true),
355
-			'trap_oid'		=>	array('post' => 'oid','db'=>true),
356
-			'revert_ok'		=>	array('post' => 'revertOK','val' => 0,'db'=>true),
357
-			'display'		=>	array('post' => 'display','val' => '','db'=>true),
358
-			'rule'			=>	array('post' => 'rule','val' => '','db'=>true),			
359
-			'action_match'	=>	array('post' => 'ruleMatch','val' => -1,'db'=>true),
360
-			'action_nomatch'=>	array('post' => 'ruleNoMatch','val' => -1,'db'=>true),					
361
-			'ip4'			=>	array('post' => null,'val' => null,'db'=>true),
362
-			'ip6'			=>	array('post' => null,'val' => null,'db'=>true),
363
-			'action_form'	=>	array('post' => 'action_form','db'=>false)
348
+			'hostgroup'		=>	array('post' => 'hostgroup', 'db'=>false),
349
+			'db_rule'		=>	array('post' => 'db_rule', 'db'=>false),
350
+			'hostid'		=>	array('post' => 'hostid', 'db'=>false),
351
+			'host_name'		=>	array('post' => 'hostname', 'val' => null, 'db'=>true),
352
+			'host_group_name'=>	array('post' => null, 'val' => null, 'db'=>true),
353
+			'serviceid'		=>	array('post' => 'serviceid', 'db'=>false),
354
+			'service_name'	=>	array('post' => 'serviceName', 'db'=>true),
355
+			'trap_oid'		=>	array('post' => 'oid', 'db'=>true),
356
+			'revert_ok'		=>	array('post' => 'revertOK', 'val' => 0, 'db'=>true),
357
+			'display'		=>	array('post' => 'display', 'val' => '', 'db'=>true),
358
+			'rule'			=>	array('post' => 'rule', 'val' => '', 'db'=>true),			
359
+			'action_match'	=>	array('post' => 'ruleMatch', 'val' => -1, 'db'=>true),
360
+			'action_nomatch'=>	array('post' => 'ruleNoMatch', 'val' => -1, 'db'=>true),					
361
+			'ip4'			=>	array('post' => null, 'val' => null, 'db'=>true),
362
+			'ip6'			=>	array('post' => null, 'val' => null, 'db'=>true),
363
+			'action_form'	=>	array('post' => 'action_form', 'db'=>false)
364 364
 		);
365 365
 		
366 366
 		if (isset($postData[$params['action_form']['post']]) 
367
-			&& $postData[$params['action_form']['post']] == 'delete' )
367
+			&& $postData[$params['action_form']['post']] == 'delete')
368 368
 		{
369 369
 			try
370 370
 			{
@@ -384,16 +384,16 @@  discard block
 block discarded – undo
384 384
 		}		
385 385
 		foreach (array_keys($params) as $key)
386 386
 		{
387
-			if ($params[$key]['post']==null) continue; // data not sent in post vars
388
-			if (! isset($postData[$params[$key]['post']]))
387
+			if ($params[$key]['post'] == null) continue; // data not sent in post vars
388
+			if (!isset($postData[$params[$key]['post']]))
389 389
 			{
390 390
 				// should not happen as the js checks data
391
-				$this->_helper->json(array('status'=>'No ' . $key));
391
+				$this->_helper->json(array('status'=>'No '.$key));
392 392
 			}
393 393
 			else
394 394
 			{
395 395
 				$data=$postData[$params[$key]['post']];
396
-				if ($data!=null && $data !="")
396
+				if ($data != null && $data != "")
397 397
 				{
398 398
 					$params[$key]['val']=$postData[$params[$key]['post']];
399 399
 				}
@@ -402,8 +402,8 @@  discard block
 block discarded – undo
402 402
 
403 403
 		try 
404 404
 		{
405
-			$isHostGroup=($params['hostgroup']['val'] == 1)?true:false;
406
-			if (! $isHostGroup ) 
405
+			$isHostGroup=($params['hostgroup']['val'] == 1) ?true:false;
406
+			if (!$isHostGroup) 
407 407
 			{  // checks if selection by host 
408 408
 				$hostAddr=$this->getHostInfoByID($params['hostid']['val']);
409 409
 				$params['ip4']['val']=$hostAddr->ip4;
@@ -430,25 +430,25 @@  discard block
 block discarded – undo
430 430
 					return;					
431 431
 				}
432 432
 				// Put param in correct column (group_name)
433
-				$params['host_group_name']['val'] = $params['host_name']['val'];
433
+				$params['host_group_name']['val']=$params['host_name']['val'];
434 434
 				$params['host_name']['val']=null;
435 435
 			}
436 436
 			$dbparams=array();
437 437
 			foreach ($params as $key=>$val)
438 438
 			{
439
-				if ($val['db']==true )
439
+				if ($val['db'] == true)
440 440
 				{
441
-					$dbparams[$key] = $val['val'];
441
+					$dbparams[$key]=$val['val'];
442 442
 				}
443 443
 			}
444 444
 			// echo '<br>';	print_r($dbparams);echo '<br>';
445
-			if ($params['db_rule']['val'] == -1 ) 
445
+			if ($params['db_rule']['val'] == -1) 
446 446
 			{
447 447
 				$ruleID=$this->addHandlerRule($dbparams);
448 448
 			}
449 449
 			else
450 450
 			{
451
-				$this->updateHandlerRule($dbparams,$params['db_rule']['val']);
451
+				$this->updateHandlerRule($dbparams, $params['db_rule']['val']);
452 452
 				$ruleID=$params['db_rule']['val'];
453 453
 			}
454 454
 		}
@@ -467,10 +467,10 @@  discard block
 block discarded – undo
467 467
 	*/
468 468
 	protected function getTrapDetail($trapid) 
469 469
 	{
470
-		if (!preg_match('/^[0-9]+$/',$trapid)) { throw new Exception('Invalid id');  }
470
+		if (!preg_match('/^[0-9]+$/', $trapid)) { throw new Exception('Invalid id'); }
471 471
 		$queryArray=$this->getModuleConfig()->trapDetailQuery();
472 472
 		
473
-		$db = $this->getDb()->getConnection();
473
+		$db=$this->getDb()->getConnection();
474 474
 		// ***************  Get main data
475 475
 		// extract columns and titles;
476 476
 		$elmts=NULL;
@@ -479,15 +479,15 @@  discard block
 block discarded – undo
479 479
 		}
480 480
 		try
481 481
 		{		
482
-			$query = $db->select()
483
-				->from($this->getModuleConfig()->getTrapTableName(),$elmts)
484
-				->where('id=?',$trapid);
482
+			$query=$db->select()
483
+				->from($this->getModuleConfig()->getTrapTableName(), $elmts)
484
+				->where('id=?', $trapid);
485 485
 			$trapDetail=$db->fetchRow($query);
486
-			if ( $trapDetail == null ) throw new Exception('No traps was found with id = '.$trapid);
486
+			if ($trapDetail == null) throw new Exception('No traps was found with id = '.$trapid);
487 487
 		}
488 488
 		catch (Exception $e)
489 489
 		{
490
-			$this->displayExitError('Add handler : get trap detail returning : '.print_r($trapDetail,true),$e->getMessage());
490
+			$this->displayExitError('Add handler : get trap detail returning : '.print_r($trapDetail, true), $e->getMessage());
491 491
 		}
492 492
 
493 493
 		return $trapDetail;
@@ -500,10 +500,10 @@  discard block
 block discarded – undo
500 500
 	*/
501 501
 	protected function getTrapobjects($trapid)
502 502
 	{	
503
-		if (!preg_match('/^[0-9]+$/',$trapid)) { throw new Exception('Invalid id');  }
503
+		if (!preg_match('/^[0-9]+$/', $trapid)) { throw new Exception('Invalid id'); }
504 504
 		$queryArrayData=$this->getModuleConfig()->trapDataDetailQuery();
505 505
 		
506
-		$db = $this->getDb()->getConnection();
506
+		$db=$this->getDb()->getConnection();
507 507
 		// ***************  Get object data
508 508
 		// extract columns and titles;
509 509
 		$data_elmts=NULL;
@@ -512,15 +512,15 @@  discard block
 block discarded – undo
512 512
 		}
513 513
 		try
514 514
 		{		
515
-			$query = $db->select()
516
-				->from($this->moduleConfig->getTrapDataTableName(),$data_elmts)
517
-				->where('trap_id=?',$trapid);
515
+			$query=$db->select()
516
+				->from($this->moduleConfig->getTrapDataTableName(), $data_elmts)
517
+				->where('trap_id=?', $trapid);
518 518
 			$trapDetail=$db->fetchAll($query);
519 519
 			// if ( $trapDetail == null ) throw new Exception('No traps was found with id = '.$trapid);
520 520
 		}
521 521
 		catch (Exception $e)
522 522
 		{
523
-			$this->displayExitError('Add handler : get trap data detail',$e->getMessage());
523
+			$this->displayExitError('Add handler : get trap data detail', $e->getMessage());
524 524
 		}
525 525
 
526 526
 		return $trapDetail;
@@ -532,22 +532,22 @@  discard block
 block discarded – undo
532 532
 	*/
533 533
 	protected function getRuleDetail($ruleid) 
534 534
 	{
535
-		if (!preg_match('/^[0-9]+$/',$ruleid)) { throw new Exception('Invalid id');  }
535
+		if (!preg_match('/^[0-9]+$/', $ruleid)) { throw new Exception('Invalid id'); }
536 536
 		$queryArray=$this->getModuleConfig()->ruleDetailQuery();
537 537
 		
538
-		$db = $this->getDb()->getConnection();
538
+		$db=$this->getDb()->getConnection();
539 539
 		// ***************  Get main data
540 540
 		try
541 541
 		{		
542
-			$query = $db->select()
543
-				->from($this->getModuleConfig()->getTrapRuleName(),$queryArray)
544
-				->where('id=?',$ruleid);
542
+			$query=$db->select()
543
+				->from($this->getModuleConfig()->getTrapRuleName(), $queryArray)
544
+				->where('id=?', $ruleid);
545 545
 			$ruleDetail=$db->fetchRow($query);
546
-			if ( $ruleDetail == null ) throw new Exception('No rule was found with id = '.$ruleid);
546
+			if ($ruleDetail == null) throw new Exception('No rule was found with id = '.$ruleid);
547 547
 		}
548 548
 		catch (Exception $e)
549 549
 		{
550
-			$this->displayExitError('Update handler : get rule detail',$e->getMessage());
550
+			$this->displayExitError('Update handler : get rule detail', $e->getMessage());
551 551
 		}
552 552
 
553 553
 		return $ruleDetail;
@@ -560,7 +560,7 @@  discard block
 block discarded – undo
560 560
 	{
561 561
 		return $this->getTabs()->add('status', array(
562 562
 			'label' => $this->translate('Traps'),
563
-			'url'   => $this->getModuleConfig()->urlPath() . '/handler')
563
+			'url'   => $this->getModuleConfig()->urlPath().'/handler')
564 564
 		);
565 565
 	} 
566 566
 	
Please login to merge, or discard this patch.
Braces   +35 added lines, -39 removed lines patch added patch discarded remove patch
@@ -51,8 +51,7 @@  discard block
 block discarded – undo
51 51
 	    if ($this->params->get('rule') !== null) 
52 52
 	    {
53 53
 	        $this->view->rule= $this->params->get('rule');
54
-	    }
55
-	    else
54
+	    } else
56 55
 	    {
57 56
 	        $this->view->rule='';
58 57
 	    }
@@ -113,8 +112,7 @@  discard block
 block discarded – undo
113 112
 			try
114 113
 			{
115 114
 				$hosts=$this->getHostByIP($hostfilter);
116
-			}
117
-			catch (Exception $e)
115
+			} catch (Exception $e)
118 116
 			{
119 117
 				$this->displayExitError('Add handler : get host by IP/Name ',$e->getMessage());
120 118
 			}
@@ -127,8 +125,7 @@  discard block
 block discarded – undo
127 125
 				// Tell JS to get services when page is loaded
128 126
 				$this->view->serviceGet=true;
129 127
 				
130
-			}
131
-			else
128
+			} else
132 129
 			{
133 130
 				foreach($hosts as $key=>$val)
134 131
 				{
@@ -178,11 +175,14 @@  discard block
 block discarded – undo
178 175
 					$allObjects[$val->oid]=null;
179 176
 				}
180 177
 			}
181
-			if ($allObjects!=null) // in case trap doesn't have objects or is not resolved
178
+			if ($allObjects!=null) {
179
+				// in case trap doesn't have objects or is not resolved
182 180
 			{
183 181
 				foreach ($allObjects as $key => $val)
184 182
 				{
185
-					if ($val==null) { continue; }
183
+					if ($val==null) { continue;
184
+			}
185
+			}
186 186
 					array_push($this->view->objectList, array(
187 187
 					    $oid_index,
188 188
 						$key,
@@ -231,8 +231,7 @@  discard block
 block discarded – undo
231 231
 			    {
232 232
 			        $this->view->warning_message='Host '.$this->view->hostname. ' doesn\'t exists anymore';
233 233
 			        $this->view->serviceGet=false;
234
-			    }
235
-			    else
234
+			    } else
236 235
 			    {
237 236
     				// Tell JS to get services when page is loaded
238 237
     				$this->view->serviceGet=true;
@@ -241,14 +240,12 @@  discard block
 block discarded – undo
241 240
     				if (count($serviceID) ==0)
242 241
     				{
243 242
     				    $this->view->warning_message=' Service '.$ruleDetail->service_name. ' doesn\'t exists anymore';
244
-    				} 
245
-    				else
243
+    				} else
246 244
     				{
247 245
     				    $this->view->serviceSet=$serviceID[0]->id;
248 246
     				}
249 247
 			    }
250
-			}
251
-			else
248
+			} else
252 249
 			{
253 250
 			    $this->view->selectGroup=true;
254 251
 			    // Check if groupe exists
@@ -257,8 +254,7 @@  discard block
 block discarded – undo
257 254
 			    {
258 255
 			        $this->view->warning_message='HostGroup '.$this->view->hostgroupname. ' doesn\'t exists anymore';
259 256
 			        $this->view->serviceGroupGet=false;
260
-			    }
261
-			    else
257
+			    } else
262 258
 			    {
263 259
 			        $grpServices=$this->getServicesByHostGroupid($group_get[0]->id);
264 260
 			        $foundGrpService=0;
@@ -281,9 +277,11 @@  discard block
 block discarded – undo
281 277
 			}
282 278
 			$this->view->mainoid=$ruleDetail->trap_oid;
283 279
 			$oidName=$this->getMIB()->translateOID($ruleDetail->trap_oid);
284
-			if ($oidName != null)  // oid is found in mibs
280
+			if ($oidName != null) {
281
+				// oid is found in mibs
285 282
 			{
286
-				$this->view->mib=$oidName['mib']; 
283
+				$this->view->mib=$oidName['mib'];
284
+			}
287 285
 				$this->view->name=$oidName['name'];
288 286
 				$this->view->trapListForMIB=$this->getMIB()
289 287
 					->getTrapList($oidName['mib']);				
@@ -310,8 +308,7 @@  discard block
 block discarded – undo
310 308
 						$object['type'],
311 309
 						$object['type_enum']
312 310
 					));
313
-				}
314
-				else
311
+				} else
315 312
 				{
316 313
 					array_push($curObjectList, array(
317 314
 					    $index,
@@ -369,8 +366,7 @@  discard block
 block discarded – undo
369 366
 			try
370 367
 			{
371 368
 				$this->deleteRule($postData[$params['db_rule']['post']]);
372
-			}
373
-			catch (Exception $e)
369
+			} catch (Exception $e)
374 370
 			{
375 371
 				$this->_helper->json(array('status'=>$e->getMessage()));
376 372
 				return;
@@ -384,13 +380,15 @@  discard block
 block discarded – undo
384 380
 		}		
385 381
 		foreach (array_keys($params) as $key)
386 382
 		{
387
-			if ($params[$key]['post']==null) continue; // data not sent in post vars
383
+			if ($params[$key]['post']==null) {
384
+				continue;
385
+			}
386
+			// data not sent in post vars
388 387
 			if (! isset($postData[$params[$key]['post']]))
389 388
 			{
390 389
 				// should not happen as the js checks data
391 390
 				$this->_helper->json(array('status'=>'No ' . $key));
392
-			}
393
-			else
391
+			} else
394 392
 			{
395 393
 				$data=$postData[$params[$key]['post']];
396 394
 				if ($data!=null && $data !="")
@@ -420,8 +418,7 @@  discard block
 block discarded – undo
420 418
 					$this->_helper->json(array('status'=>"Invalid service id : Please re enter service"));
421 419
 					return;
422 420
 				}
423
-			}
424
-			else
421
+			} else
425 422
 			{
426 423
 				$object=$this->getObjectNameByid($params['hostid']['val']);
427 424
 				if ($params['host_name']['val'] != $object->name1)
@@ -445,14 +442,12 @@  discard block
 block discarded – undo
445 442
 			if ($params['db_rule']['val'] == -1 ) 
446 443
 			{
447 444
 				$ruleID=$this->addHandlerRule($dbparams);
448
-			}
449
-			else
445
+			} else
450 446
 			{
451 447
 				$this->updateHandlerRule($dbparams,$params['db_rule']['val']);
452 448
 				$ruleID=$params['db_rule']['val'];
453 449
 			}
454
-		}
455
-		catch (Exception $e)
450
+		} catch (Exception $e)
456 451
 		{
457 452
 			$this->_helper->json(array('status'=>$e->getMessage()));
458 453
 			return;
@@ -483,9 +478,10 @@  discard block
 block discarded – undo
483 478
 				->from($this->getModuleConfig()->getTrapTableName(),$elmts)
484 479
 				->where('id=?',$trapid);
485 480
 			$trapDetail=$db->fetchRow($query);
486
-			if ( $trapDetail == null ) throw new Exception('No traps was found with id = '.$trapid);
487
-		}
488
-		catch (Exception $e)
481
+			if ( $trapDetail == null ) {
482
+				throw new Exception('No traps was found with id = '.$trapid);
483
+			}
484
+		} catch (Exception $e)
489 485
 		{
490 486
 			$this->displayExitError('Add handler : get trap detail returning : '.print_r($trapDetail,true),$e->getMessage());
491 487
 		}
@@ -517,8 +513,7 @@  discard block
 block discarded – undo
517 513
 				->where('trap_id=?',$trapid);
518 514
 			$trapDetail=$db->fetchAll($query);
519 515
 			// if ( $trapDetail == null ) throw new Exception('No traps was found with id = '.$trapid);
520
-		}
521
-		catch (Exception $e)
516
+		} catch (Exception $e)
522 517
 		{
523 518
 			$this->displayExitError('Add handler : get trap data detail',$e->getMessage());
524 519
 		}
@@ -543,9 +538,10 @@  discard block
 block discarded – undo
543 538
 				->from($this->getModuleConfig()->getTrapRuleName(),$queryArray)
544 539
 				->where('id=?',$ruleid);
545 540
 			$ruleDetail=$db->fetchRow($query);
546
-			if ( $ruleDetail == null ) throw new Exception('No rule was found with id = '.$ruleid);
547
-		}
548
-		catch (Exception $e)
541
+			if ( $ruleDetail == null ) {
542
+				throw new Exception('No rule was found with id = '.$ruleid);
543
+			}
544
+		} catch (Exception $e)
549 545
 		{
550 546
 			$this->displayExitError('Update handler : get rule detail',$e->getMessage());
551 547
 		}
Please login to merge, or discard this patch.
application/controllers/ErrorController.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@
 block discarded – undo
12 12
 	
13 13
 	public function indexAction()
14 14
 	{	  
15
-		$this->getTabs()->add('get',array(
15
+		$this->getTabs()->add('get', array(
16 16
 			'active'	=> true,
17 17
 			'label'		=> $this->translate('Error'),
18 18
 			'url'		=> Url::fromRequest()
Please login to merge, or discard this patch.