Passed
Pull Request — master (#78)
by
unknown
04:15
created
library/Trapdirector/Tables/TrapDirectorTablePaging.php 3 patches
Braces   +14 added lines, -8 removed lines patch added patch discarded remove patch
@@ -46,7 +46,9 @@  discard block
 block discarded – undo
46 46
 
47 47
     protected function curPagingQuery()
48 48
     {
49
-        if ($this->currentPage == '') return '';
49
+        if ($this->currentPage == '') {
50
+        	return '';
51
+        }
50 52
         return 'page='.$this->currentPage;
51 53
     }
52 54
     
@@ -58,10 +60,14 @@  discard block
 block discarded – undo
58 60
             return  'count : ' . $this->count() . '<br>';
59 61
         }
60 62
         
61
-        if ($this->currentPage == 0) $this->currentPage = 1;
63
+        if ($this->currentPage == 0) {
64
+        	$this->currentPage = 1;
65
+        }
62 66
         
63 67
         $numPages = intdiv($count , $this->maxPerPage);
64
-        if ($count % $this->maxPerPage != 0 ) $numPages++;
68
+        if ($count % $this->maxPerPage != 0 ) {
69
+        	$numPages++;
70
+        }
65 71
         
66 72
         $html = '<div class="pagination-control" role="navigation">';
67 73
         $html .= '<ul class="nav tab-nav">';
@@ -75,8 +81,7 @@  discard block
 block discarded – undo
75 81
                      </span>
76 82
                 </li>
77 83
                ';
78
-        }
79
-        else 
84
+        } else 
80 85
         {
81 86
             $html .= '
82 87
                 <li class="nav-item">
@@ -92,7 +97,9 @@  discard block
 block discarded – undo
92 97
             $active = ($this->currentPage == $i) ? 'active' : '';
93 98
             $first = ($i-1)*$this->maxPerPage+1;
94 99
             $last = $i * $this->maxPerPage;
95
-            if ($last > $count) $last = $count;
100
+            if ($last > $count) {
101
+            	$last = $count;
102
+            }
96 103
             $display = 'Show rows '. $first . ' to '. $last .' of '. $count;
97 104
             $html .= '<li class="' . $active . ' nav-item">
98 105
                     <a href="'. $this->getCurrentURLAndQS('paging') .'&page='. $i .'" title="' . $display . '" aria-label="' . $display . '">
@@ -111,8 +118,7 @@  discard block
 block discarded – undo
111 118
                      </span>
112 119
                 </li>
113 120
                ';
114
-        }
115
-        else
121
+        } else
116 122
         {
117 123
             $html .= '
118 124
                 <li class="nav-item">
Please login to merge, or discard this patch.
Indentation   +84 added lines, -84 removed lines patch added patch discarded remove patch
@@ -6,72 +6,72 @@  discard block
 block discarded – undo
6 6
 trait TrapDirectorTablePaging
7 7
 {
8 8
    
9
-    /*************** Paging *************/
10
-    protected $maxPerPage = 25;
9
+	/*************** Paging *************/
10
+	protected $maxPerPage = 25;
11 11
     
12
-    protected $currentPage = 0;
12
+	protected $currentPage = 0;
13 13
         
14
-    /**** var & func of TrapDirectorTable used ***/
15
-    protected $query;
16
-    abstract protected function getCurrentURLAndQS(string $caller);
17
-    abstract public function applyFilter();
14
+	/**** var & func of TrapDirectorTable used ***/
15
+	protected $query;
16
+	abstract protected function getCurrentURLAndQS(string $caller);
17
+	abstract public function applyFilter();
18 18
     
19
-    /*****************  Paging and counting *********/
19
+	/*****************  Paging and counting *********/
20 20
     
21
-    public function countQuery()
22
-    {
23
-        $this->query = $this->dbConn->select();
24
-        $this->query = $this->query
25
-            ->from(
26
-                $this->table,
27
-                array('COUNT(*)')
28
-                );
29
-        $this->applyFilter();                   
30
-    }
21
+	public function countQuery()
22
+	{
23
+		$this->query = $this->dbConn->select();
24
+		$this->query = $this->query
25
+			->from(
26
+				$this->table,
27
+				array('COUNT(*)')
28
+				);
29
+		$this->applyFilter();                   
30
+	}
31 31
     
32
-    public function count()
33
-    {
34
-        $this->countQuery();
35
-        return $this->dbConn->fetchOne($this->query);
36
-    }
32
+	public function count()
33
+	{
34
+		$this->countQuery();
35
+		return $this->dbConn->fetchOne($this->query);
36
+	}
37 37
     
38
-    public function setMaxPerPage(int $max)
39
-    {
40
-        $this->maxPerPage = $max;
41
-    }
38
+	public function setMaxPerPage(int $max)
39
+	{
40
+		$this->maxPerPage = $max;
41
+	}
42 42
     
43
-    protected function getPagingQuery(array $getVars)
44
-    {
45
-        if (isset($getVars['page']))
46
-        {
47
-            $this->currentPage = $getVars['page'];
48
-        }
49
-    }
43
+	protected function getPagingQuery(array $getVars)
44
+	{
45
+		if (isset($getVars['page']))
46
+		{
47
+			$this->currentPage = $getVars['page'];
48
+		}
49
+	}
50 50
 
51
-    protected function curPagingQuery()
52
-    {
53
-        if ($this->currentPage == '') return '';
54
-        return 'page='.$this->currentPage;
55
-    }
51
+	protected function curPagingQuery()
52
+	{
53
+		if ($this->currentPage == '') return '';
54
+		return 'page='.$this->currentPage;
55
+	}
56 56
     
57
-    public function renderPagingHeader()
58
-    {
59
-        $count = $this->count();
60
-        if ($count <= $this->maxPerPage )
61
-        {
62
-            return  'count : ' . $this->count() . '<br>';
63
-        }
57
+	public function renderPagingHeader()
58
+	{
59
+		$count = $this->count();
60
+		if ($count <= $this->maxPerPage )
61
+		{
62
+			return  'count : ' . $this->count() . '<br>';
63
+		}
64 64
         
65
-        if ($this->currentPage == 0) $this->currentPage = 1;
65
+		if ($this->currentPage == 0) $this->currentPage = 1;
66 66
         
67
-        $numPages = intdiv($count , $this->maxPerPage);
68
-        if ($count % $this->maxPerPage != 0 ) $numPages++;
67
+		$numPages = intdiv($count , $this->maxPerPage);
68
+		if ($count % $this->maxPerPage != 0 ) $numPages++;
69 69
         
70
-        $html = '<div class="pagination-control" role="navigation">';
71
-        $html .= '<ul class="nav tab-nav">';
72
-        if ($this->currentPage <=1)
73
-        {
74
-            $html .= '
70
+		$html = '<div class="pagination-control" role="navigation">';
71
+		$html .= '<ul class="nav tab-nav">';
72
+		if ($this->currentPage <=1)
73
+		{
74
+			$html .= '
75 75
                 <li class="nav-item disabled" aria-hidden="true">
76 76
                     <span class="previous-page">
77 77
                             <span class="sr-only">Previous page</span>
@@ -79,35 +79,35 @@  discard block
 block discarded – undo
79 79
                      </span>
80 80
                 </li>
81 81
                ';
82
-        }
83
-        else 
84
-        {
85
-            $html .= '
82
+		}
83
+		else 
84
+		{
85
+			$html .= '
86 86
                 <li class="nav-item">
87 87
                     <a href="'. $this->getCurrentURLAndQS('paging') .'&page='. ($this->currentPage - 1 ).'" class="previous-page" >
88 88
                             <i aria-hidden="true" class="icon-angle-double-left"></i>            
89 89
                      </a>
90 90
                 </li>
91 91
             ';
92
-        }
92
+		}
93 93
         
94
-        for ($i=1; $i <= $numPages ; $i++)
95
-        {
96
-            $active = ($this->currentPage == $i) ? 'active' : '';
97
-            $first = ($i-1)*$this->maxPerPage+1;
98
-            $last = $i * $this->maxPerPage;
99
-            if ($last > $count) $last = $count;
100
-            $display = 'Show rows '. $first . ' to '. $last .' of '. $count;
101
-            $html .= '<li class="' . $active . ' nav-item">
94
+		for ($i=1; $i <= $numPages ; $i++)
95
+		{
96
+			$active = ($this->currentPage == $i) ? 'active' : '';
97
+			$first = ($i-1)*$this->maxPerPage+1;
98
+			$last = $i * $this->maxPerPage;
99
+			if ($last > $count) $last = $count;
100
+			$display = 'Show rows '. $first . ' to '. $last .' of '. $count;
101
+			$html .= '<li class="' . $active . ' nav-item">
102 102
                     <a href="'. $this->getCurrentURLAndQS('paging') .'&page='. $i .'" title="' . $display . '" aria-label="' . $display . '">
103 103
                     '.$i.'                
104 104
                     </a>
105 105
                 </li>';
106
-        }
106
+		}
107 107
         
108
-        if ($this->currentPage == $numPages)
109
-        {
110
-            $html .= '
108
+		if ($this->currentPage == $numPages)
109
+		{
110
+			$html .= '
111 111
                 <li class="nav-item disabled" aria-hidden="true">
112 112
                     <span class="previous-page">
113 113
                             <span class="sr-only">Previous page</span>
@@ -115,28 +115,28 @@  discard block
 block discarded – undo
115 115
                      </span>
116 116
                 </li>
117 117
                ';
118
-        }
119
-        else
120
-        {
121
-            $html .= '
118
+		}
119
+		else
120
+		{
121
+			$html .= '
122 122
                 <li class="nav-item">
123 123
                     <a href="'. $this->getCurrentURLAndQS('paging') .'&page='. ($this->currentPage + 1 ).'" class="next-page">
124 124
                             <i aria-hidden="true" class="icon-angle-double-right"></i>
125 125
                      </a>
126 126
                 </li>
127 127
             ';
128
-        }
128
+		}
129 129
         
130
-        $html .= '</ul> </div>';
130
+		$html .= '</ul> </div>';
131 131
         
132
-        return $html;
133
-    }
132
+		return $html;
133
+	}
134 134
     
135
-    public function applyPaging()
136
-    {
137
-        $this->query->limitPage($this->currentPage,$this->maxPerPage);
138
-        return $this;
139
-    }
135
+	public function applyPaging()
136
+	{
137
+		$this->query->limitPage($this->currentPage,$this->maxPerPage);
138
+		return $this;
139
+	}
140 140
     
141 141
     
142 142
 }
143 143
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -7,9 +7,9 @@  discard block
 block discarded – undo
7 7
 {
8 8
    
9 9
     /*************** Paging *************/
10
-    protected $maxPerPage = 25;
10
+    protected $maxPerPage=25;
11 11
     
12
-    protected $currentPage = 0;
12
+    protected $currentPage=0;
13 13
         
14 14
     /**** var & func of TrapDirectorTable used ***/
15 15
     protected $query;
@@ -20,8 +20,8 @@  discard block
 block discarded – undo
20 20
     
21 21
     public function countQuery()
22 22
     {
23
-        $this->query = $this->dbConn->select();
24
-        $this->query = $this->query
23
+        $this->query=$this->dbConn->select();
24
+        $this->query=$this->query
25 25
             ->from(
26 26
                 $this->table,
27 27
                 array('COUNT(*)')
@@ -37,14 +37,14 @@  discard block
 block discarded – undo
37 37
     
38 38
     public function setMaxPerPage(int $max)
39 39
     {
40
-        $this->maxPerPage = $max;
40
+        $this->maxPerPage=$max;
41 41
     }
42 42
     
43 43
     protected function getPagingQuery(array $getVars)
44 44
     {
45 45
         if (isset($getVars['page']))
46 46
         {
47
-            $this->currentPage = $getVars['page'];
47
+            $this->currentPage=$getVars['page'];
48 48
         }
49 49
     }
50 50
 
@@ -56,22 +56,22 @@  discard block
 block discarded – undo
56 56
     
57 57
     public function renderPagingHeader()
58 58
     {
59
-        $count = $this->count();
60
-        if ($count <= $this->maxPerPage )
59
+        $count=$this->count();
60
+        if ($count <= $this->maxPerPage)
61 61
         {
62
-            return  'count : ' . $this->count() . '<br>';
62
+            return  'count : '.$this->count().'<br>';
63 63
         }
64 64
         
65
-        if ($this->currentPage == 0) $this->currentPage = 1;
65
+        if ($this->currentPage == 0) $this->currentPage=1;
66 66
         
67
-        $numPages = intdiv($count , $this->maxPerPage);
68
-        if ($count % $this->maxPerPage != 0 ) $numPages++;
67
+        $numPages=intdiv($count, $this->maxPerPage);
68
+        if ($count % $this->maxPerPage != 0) $numPages++;
69 69
         
70
-        $html = '<div class="pagination-control" role="navigation">';
71
-        $html .= '<ul class="nav tab-nav">';
72
-        if ($this->currentPage <=1)
70
+        $html='<div class="pagination-control" role="navigation">';
71
+        $html.='<ul class="nav tab-nav">';
72
+        if ($this->currentPage <= 1)
73 73
         {
74
-            $html .= '
74
+            $html.='
75 75
                 <li class="nav-item disabled" aria-hidden="true">
76 76
                     <span class="previous-page">
77 77
                             <span class="sr-only">Previous page</span>
@@ -82,24 +82,24 @@  discard block
 block discarded – undo
82 82
         }
83 83
         else 
84 84
         {
85
-            $html .= '
85
+            $html.='
86 86
                 <li class="nav-item">
87
-                    <a href="'. $this->getCurrentURLAndQS('paging') .'&page='. ($this->currentPage - 1 ).'" class="previous-page" >
87
+                    <a href="'. $this->getCurrentURLAndQS('paging').'&page='.($this->currentPage - 1).'" class="previous-page" >
88 88
                             <i aria-hidden="true" class="icon-angle-double-left"></i>            
89 89
                      </a>
90 90
                 </li>
91 91
             ';
92 92
         }
93 93
         
94
-        for ($i=1; $i <= $numPages ; $i++)
94
+        for ($i=1; $i <= $numPages; $i++)
95 95
         {
96
-            $active = ($this->currentPage == $i) ? 'active' : '';
97
-            $first = ($i-1)*$this->maxPerPage+1;
98
-            $last = $i * $this->maxPerPage;
99
-            if ($last > $count) $last = $count;
100
-            $display = 'Show rows '. $first . ' to '. $last .' of '. $count;
101
-            $html .= '<li class="' . $active . ' nav-item">
102
-                    <a href="'. $this->getCurrentURLAndQS('paging') .'&page='. $i .'" title="' . $display . '" aria-label="' . $display . '">
96
+            $active=($this->currentPage == $i) ? 'active' : '';
97
+            $first=($i - 1) * $this->maxPerPage + 1;
98
+            $last=$i * $this->maxPerPage;
99
+            if ($last > $count) $last=$count;
100
+            $display='Show rows '.$first.' to '.$last.' of '.$count;
101
+            $html.='<li class="'.$active.' nav-item">
102
+                    <a href="'. $this->getCurrentURLAndQS('paging').'&page='.$i.'" title="'.$display.'" aria-label="'.$display.'">
103 103
                     '.$i.'                
104 104
                     </a>
105 105
                 </li>';
@@ -107,7 +107,7 @@  discard block
 block discarded – undo
107 107
         
108 108
         if ($this->currentPage == $numPages)
109 109
         {
110
-            $html .= '
110
+            $html.='
111 111
                 <li class="nav-item disabled" aria-hidden="true">
112 112
                     <span class="previous-page">
113 113
                             <span class="sr-only">Previous page</span>
@@ -118,23 +118,23 @@  discard block
 block discarded – undo
118 118
         }
119 119
         else
120 120
         {
121
-            $html .= '
121
+            $html.='
122 122
                 <li class="nav-item">
123
-                    <a href="'. $this->getCurrentURLAndQS('paging') .'&page='. ($this->currentPage + 1 ).'" class="next-page">
123
+                    <a href="'. $this->getCurrentURLAndQS('paging').'&page='.($this->currentPage + 1).'" class="next-page">
124 124
                             <i aria-hidden="true" class="icon-angle-double-right"></i>
125 125
                      </a>
126 126
                 </li>
127 127
             ';
128 128
         }
129 129
         
130
-        $html .= '</ul> </div>';
130
+        $html.='</ul> </div>';
131 131
         
132 132
         return $html;
133 133
     }
134 134
     
135 135
     public function applyPaging()
136 136
     {
137
-        $this->query->limitPage($this->currentPage,$this->maxPerPage);
137
+        $this->query->limitPage($this->currentPage, $this->maxPerPage);
138 138
         return $this;
139 139
     }
140 140
     
Please login to merge, or discard this patch.
library/Trapdirector/Tables/TrapDirectorTableOrder.php 3 patches
Braces   +9 added lines, -3 removed lines patch added patch discarded remove patch
@@ -20,7 +20,9 @@  discard block
 block discarded – undo
20 20
         $orderSQL='';
21 21
         foreach ($this->order as $column => $direction)
22 22
         {
23
-            if ($orderSQL != "") $orderSQL.=',';
23
+            if ($orderSQL != "") {
24
+            	$orderSQL.=',';
25
+            }
24 26
             
25 27
             $orderSQL .= $column . ' ' . $direction;
26 28
         }
@@ -37,7 +39,9 @@  discard block
 block discarded – undo
37 39
 
38 40
     public function isOrderSet()
39 41
     {
40
-        if (count($this->order) == 0) return FALSE;
42
+        if (count($this->order) == 0) {
43
+        	return FALSE;
44
+        }
41 45
         return TRUE;
42 46
     }
43 47
     
@@ -58,7 +62,9 @@  discard block
 block discarded – undo
58 62
     
59 63
     protected function curOrderQuery()
60 64
     {
61
-        if ($this->orderQuery == '') return '';
65
+        if ($this->orderQuery == '') {
66
+        	return '';
67
+        }
62 68
         return 'o='.$this->orderQuery;
63 69
     }
64 70
         
Please login to merge, or discard this patch.
Indentation   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -5,65 +5,65 @@
 block discarded – undo
5 5
 
6 6
 trait TrapDirectorTableOrder
7 7
 { 
8
-    /** @var array $order : (db column, 'ASC' | 'DESC') */
9
-    protected $order = array();
10
-    /** @var string $orderQuery passed by GET */
11
-    protected $orderQuery = '';   
8
+	/** @var array $order : (db column, 'ASC' | 'DESC') */
9
+	protected $order = array();
10
+	/** @var string $orderQuery passed by GET */
11
+	protected $orderQuery = '';   
12 12
     
13
-    /** used var & functions of trapDirectorTable **/
14
-    protected $query;
13
+	/** used var & functions of trapDirectorTable **/
14
+	protected $query;
15 15
     
16 16
    /***************** Ordering ********************/
17 17
     
18
-    public function applyOrder()
19
-    {
20
-        if (count($this->order) == 0)
21
-        {
22
-            return $this;
23
-        }
24
-        $orderSQL='';
25
-        foreach ($this->order as $column => $direction)
26
-        {
27
-            if ($orderSQL != "") $orderSQL.=',';
18
+	public function applyOrder()
19
+	{
20
+		if (count($this->order) == 0)
21
+		{
22
+			return $this;
23
+		}
24
+		$orderSQL='';
25
+		foreach ($this->order as $column => $direction)
26
+		{
27
+			if ($orderSQL != "") $orderSQL.=',';
28 28
             
29
-            $orderSQL .= $column . ' ' . $direction;
30
-        }
31
-        $this->query = $this->query->order($orderSQL);
29
+			$orderSQL .= $column . ' ' . $direction;
30
+		}
31
+		$this->query = $this->query->order($orderSQL);
32 32
         
33
-        return $this;
34
-    }
33
+		return $this;
34
+	}
35 35
     
36
-    public function setOrder(array $order)
37
-    {
38
-        $this->order = $order;
39
-        return $this;
40
-    }
36
+	public function setOrder(array $order)
37
+	{
38
+		$this->order = $order;
39
+		return $this;
40
+	}
41 41
 
42
-    public function isOrderSet()
43
-    {
44
-        if (count($this->order) == 0) return FALSE;
45
-        return TRUE;
46
-    }
42
+	public function isOrderSet()
43
+	{
44
+		if (count($this->order) == 0) return FALSE;
45
+		return TRUE;
46
+	}
47 47
     
48
-    public function getOrderQuery(array $getVars)
49
-    {
50
-        if (isset($getVars['o']))
51
-        {
52
-            $this->orderQuery = $getVars['o'];
53
-            $match = array();
54
-            if (preg_match('/(.*)(ASC|DESC)$/', $this->orderQuery , $match))
55
-            {
56
-                $orderArray=array($match[1] => $match[2]);
57
-                echo "$match[1] => $match[2]";
58
-                $this->setOrder($orderArray);
59
-            }
60
-        }
61
-    }
48
+	public function getOrderQuery(array $getVars)
49
+	{
50
+		if (isset($getVars['o']))
51
+		{
52
+			$this->orderQuery = $getVars['o'];
53
+			$match = array();
54
+			if (preg_match('/(.*)(ASC|DESC)$/', $this->orderQuery , $match))
55
+			{
56
+				$orderArray=array($match[1] => $match[2]);
57
+				echo "$match[1] => $match[2]";
58
+				$this->setOrder($orderArray);
59
+			}
60
+		}
61
+	}
62 62
     
63
-    protected function curOrderQuery()
64
-    {
65
-        if ($this->orderQuery == '') return '';
66
-        return 'o='.$this->orderQuery;
67
-    }
63
+	protected function curOrderQuery()
64
+	{
65
+		if ($this->orderQuery == '') return '';
66
+		return 'o='.$this->orderQuery;
67
+	}
68 68
         
69 69
 }
70 70
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -6,9 +6,9 @@  discard block
 block discarded – undo
6 6
 trait TrapDirectorTableOrder
7 7
 { 
8 8
     /** @var array $order : (db column, 'ASC' | 'DESC') */
9
-    protected $order = array();
9
+    protected $order=array();
10 10
     /** @var string $orderQuery passed by GET */
11
-    protected $orderQuery = '';   
11
+    protected $orderQuery='';   
12 12
     
13 13
     /** used var & functions of trapDirectorTable **/
14 14
     protected $query;
@@ -26,16 +26,16 @@  discard block
 block discarded – undo
26 26
         {
27 27
             if ($orderSQL != "") $orderSQL.=',';
28 28
             
29
-            $orderSQL .= $column . ' ' . $direction;
29
+            $orderSQL.=$column.' '.$direction;
30 30
         }
31
-        $this->query = $this->query->order($orderSQL);
31
+        $this->query=$this->query->order($orderSQL);
32 32
         
33 33
         return $this;
34 34
     }
35 35
     
36 36
     public function setOrder(array $order)
37 37
     {
38
-        $this->order = $order;
38
+        $this->order=$order;
39 39
         return $this;
40 40
     }
41 41
 
@@ -49,9 +49,9 @@  discard block
 block discarded – undo
49 49
     {
50 50
         if (isset($getVars['o']))
51 51
         {
52
-            $this->orderQuery = $getVars['o'];
53
-            $match = array();
54
-            if (preg_match('/(.*)(ASC|DESC)$/', $this->orderQuery , $match))
52
+            $this->orderQuery=$getVars['o'];
53
+            $match=array();
54
+            if (preg_match('/(.*)(ASC|DESC)$/', $this->orderQuery, $match))
55 55
             {
56 56
                 $orderArray=array($match[1] => $match[2]);
57 57
                 echo "$match[1] => $match[2]";
Please login to merge, or discard this patch.
library/Trapdirector/Config/TrapModuleConfig.php 2 patches
Indentation   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -4,18 +4,18 @@  discard block
 block discarded – undo
4 4
 
5 5
 class TrapModuleConfig
6 6
 {
7
-    /********** Database configuration ***********************/
7
+	/********** Database configuration ***********************/
8 8
 	// Database prefix for tables 
9
-    protected $table_prefix; //< Database prefix for tables 	
9
+	protected $table_prefix; //< Database prefix for tables 	
10 10
 	protected $DBConfigDefaults=array(
11 11
 		'db_remove_days' => 60, // number of days before removing traps
12 12
 		'log_destination' => 'syslog', // Log destination for trap handler
13 13
 		'log_file' => '/tmp/trapdirector.log', // Log file
14 14
 		'log_level' => 2, // log level
15 15
 		'use_SnmpTrapAddess' => 1, // use SnmpTrapAddress by default
16
-	    'SnmpTrapAddess_oid' => '.1.3.6.1.6.3.18.1.3', // default snmpTrapAdress OID
17
-	    'max_rows_in_list' => 25, // Max rows displayed in table before paging
18
-	    'handler_categories' => '0:Not categorized' // handlers categories : <index>:<name>!<index>:<name> ....
16
+		'SnmpTrapAddess_oid' => '.1.3.6.1.6.3.18.1.3', // default snmpTrapAdress OID
17
+		'max_rows_in_list' => 25, // Max rows displayed in table before paging
18
+		'handler_categories' => '0:Not categorized' // handlers categories : <index>:<name>!<index>:<name> ....
19 19
 	);
20 20
 	// get default values for dbconfig
21 21
 	public function getDBConfigDefaults() { return $this->DBConfigDefaults;}
@@ -122,27 +122,27 @@  discard block
 block discarded – undo
122 122
 	// Note : must have 'source_ip' and 'last_sent'
123 123
 	public function getTrapHostListDisplayColumns()
124 124
 	{
125
-	    return array(
126
-	        'source_name'  =>  't.source_name',
127
-	        'source_ip'    =>  't.source_ip',
128
-	        'trap_oid'     =>  't.trap_oid',
129
-	        'count'        =>  'count(*)',
130
-	        'last_sent'    =>  'UNIX_TIMESTAMP(max(t.date_received))'
131
-	    );
125
+		return array(
126
+			'source_name'  =>  't.source_name',
127
+			'source_ip'    =>  't.source_ip',
128
+			'trap_oid'     =>  't.trap_oid',
129
+			'count'        =>  'count(*)',
130
+			'last_sent'    =>  'UNIX_TIMESTAMP(max(t.date_received))'
131
+		);
132 132
 	}
133 133
 
134 134
 	public function getTrapHostListSearchColumns()
135 135
 	{
136
-	    return array(); // No search needed on this table
136
+		return array(); // No search needed on this table
137 137
 	}
138 138
 	// Titles display in Trap List table
139 139
 	public function getTrapHostListTitles()
140 140
 	{
141
-	    return array(
142
-	        'trap_oid'		=> 'Trap OID',
143
-	        'count'		    => 'Number of traps received',
144
-	        'last_sent'     => 'Last trap received'
145
-	    );
141
+		return array(
142
+			'trap_oid'		=> 'Trap OID',
143
+			'count'		    => 'Number of traps received',
144
+			'last_sent'     => 'Last trap received'
145
+		);
146 146
 	}
147 147
 	
148 148
 	
@@ -157,13 +157,13 @@  discard block
 block discarded – undo
157 157
 			'source_ip'		=> "CASE WHEN r.ip4 IS NULL THEN r.ip6 ELSE r.ip4 END",
158 158
 			'trap_oid'		=> 'r.trap_oid',
159 159
 			'rule'			=> 'r.rule',
160
-		    'comment'	    => 'r.comment',
161
-		    'category'	    => 'r.rule_type',
160
+			'comment'	    => 'r.comment',
161
+			'category'	    => 'r.rule_type',
162 162
 			'action_match'	=> 'r.action_match',
163 163
 			'action_nomatch'=> 'r.action_nomatch',
164 164
 			'service_name'	=> 'r.service_name',
165 165
 			'num_match'		=> 'r.num_match',
166
-		    'rule_type'     => 'r.rule_type',
166
+			'rule_type'     => 'r.rule_type',
167 167
 			'id'           	=> 'r.id'
168 168
 		);
169 169
 	}
@@ -184,17 +184,17 @@  discard block
 block discarded – undo
184 184
 	}
185 185
 	public function getHandlerColumns()
186 186
 	{
187
-	    return array(
188
-	        'r.host_name', 'r.host_group_name',
189
-	        'r.ip4', 'r.ip6',
190
-	        'r.trap_oid',
191
-	        'r.rule',
192
-	        'r.action_match',
193
-	        'r.action_nomatch',
194
-	        'r.service_name',
195
-	        'r.num_match',
196
-	        'r.id'
197
-	    );
187
+		return array(
188
+			'r.host_name', 'r.host_group_name',
189
+			'r.ip4', 'r.ip6',
190
+			'r.trap_oid',
191
+			'r.rule',
192
+			'r.action_match',
193
+			'r.action_nomatch',
194
+			'r.service_name',
195
+			'r.num_match',
196
+			'r.id'
197
+		);
198 198
 	}
199 199
 
200 200
 	// handler update (<key> => <sql select>)
@@ -214,9 +214,9 @@  discard block
 block discarded – undo
214 214
 			'revert_ok'		=> 'r.revert_ok',
215 215
 			'display'		=> 'r.display',
216 216
 			'modified'		=> 'UNIX_TIMESTAMP(r.modified)',
217
-            'modifier'		=> 'r.modifier',
218
-		    'comment'       => 'r.comment',
219
-		    'category'      => 'r.rule_type'
217
+			'modifier'		=> 'r.modifier',
218
+			'comment'       => 'r.comment',
219
+			'category'      => 'r.rule_type'
220 220
 		);
221 221
 	}	
222 222
 		
Please login to merge, or discard this patch.
Spacing   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -18,27 +18,27 @@  discard block
 block discarded – undo
18 18
 	    'handler_categories' => '0:Not categorized' // handlers categories : <index>:<name>!<index>:<name> ....
19 19
 	);
20 20
 	// get default values for dbconfig
21
-	public function getDBConfigDefaults() { return $this->DBConfigDefaults;}
21
+	public function getDBConfigDefaults() { return $this->DBConfigDefaults; }
22 22
 	/** Minimum DB version
23 23
 	 * @return number
24 24
 	 */
25
-	static public function getDbMinVersion() { return 2;}	
25
+	static public function getDbMinVersion() { return 2; }	
26 26
 	/** Current DB version
27 27
 	 * @return number
28 28
 	 */
29
-	static public function getDbCurVersion() { return 2;}
29
+	static public function getDbCurVersion() { return 2; }
30 30
 
31 31
 	/************ Module configuration **********************/
32 32
 	// Module base path
33 33
 	static public function urlPath() { return 'trapdirector'; }
34
-	static public function getapiUserPermissions() { return array("status", "objects/query/Host", "objects/query/hostgroup", "objects/query/Service" , "actions/process-check-result"); } //< api user permissions required
34
+	static public function getapiUserPermissions() { return array("status", "objects/query/Host", "objects/query/hostgroup", "objects/query/Service", "actions/process-check-result"); } //< api user permissions required
35 35
 	
36 36
 	
37 37
 	/*********** Log configuration *************************/
38 38
 	protected $logLevels=array(0=>'No output', 1=>'critical', 2=>'warning', 3=>'trace', 4=>'ALL');
39
-	public function getlogLevels() { return $this->logLevels;}
40
-	protected $logDestinations=array('syslog'=>'syslog','file'=>'file','display'=>'display');
41
-	public function getLogDestinations() { return $this->logDestinations;}
39
+	public function getlogLevels() { return $this->logLevels; }
40
+	protected $logDestinations=array('syslog'=>'syslog', 'file'=>'file', 'display'=>'display');
41
+	public function getLogDestinations() { return $this->logDestinations; }
42 42
 	
43 43
 	function __construct($prefix)
44 44
 	{
@@ -49,29 +49,29 @@  discard block
 block discarded – undo
49 49
 	// DB table name of trap received list : prefix 't'
50 50
 	public function getTrapTableName() 
51 51
 	{ 
52
-		return array('t' => $this->table_prefix . 'received'); 
52
+		return array('t' => $this->table_prefix.'received'); 
53 53
 	}
54 54
 	// DB table name of trap data  list : prefix 'd'
55 55
 	public function getTrapDataTableName() 
56 56
 	{ 
57
-		return array('d' => $this->table_prefix . 'received_data'); 
57
+		return array('d' => $this->table_prefix.'received_data'); 
58 58
 	}	
59 59
 
60 60
 	// DB table name of rules : prefix 'r'
61 61
 	public function getTrapRuleName() 
62 62
 	{ 
63
-		return array('r' => $this->table_prefix . 'rules'); 
63
+		return array('r' => $this->table_prefix.'rules'); 
64 64
 	}		
65 65
 	
66 66
 	// DB table name of db config : prefix 'c'
67 67
 	public function getDbConfigTableName() 
68 68
 	{ 
69
-		return array('c' => $this->table_prefix . 'db_config');
69
+		return array('c' => $this->table_prefix.'db_config');
70 70
 	}
71 71
 	
72 72
 	// Mib cache tables
73
-	public function getMIBCacheTableName() { return $this->table_prefix . 'mib_cache'; }
74
-	public function getMIBCacheTableTrapObjName() { return $this->table_prefix . 'mib_cache_trap_object'; }
73
+	public function getMIBCacheTableName() { return $this->table_prefix.'mib_cache'; }
74
+	public function getMIBCacheTableTrapObjName() { return $this->table_prefix.'mib_cache_trap_object'; }
75 75
 	
76 76
 	
77 77
 	/****************** Database queries *******************/
@@ -152,7 +152,7 @@  discard block
 block discarded – undo
152 152
 	public function getHandlerListDisplayColumns()
153 153
 	{
154 154
 		return array(
155
-			'host_name'		=> 'r.host_name',//'UNIX_TIMESTAMP(t.date_received)',
155
+			'host_name'		=> 'r.host_name', //'UNIX_TIMESTAMP(t.date_received)',
156 156
 			'host_group_name'=> 'r.host_group_name',
157 157
 			'source_ip'		=> "CASE WHEN r.ip4 IS NULL THEN r.ip6 ELSE r.ip4 END",
158 158
 			'trap_oid'		=> 'r.trap_oid',
@@ -224,32 +224,32 @@  discard block
 block discarded – undo
224 224
 	public function trapDetailQuery()
225 225
 	{
226 226
 		return array(
227
-			'timestamp'			=> array('Date','UNIX_TIMESTAMP(t.date_received)'),
228
-			'source_ip'			=> array('Source IP','t.source_ip'),
229
-			'source_name'		=> array('Source name','t.source_name'),
230
-			'source_port'		=> array('Source port','t.source_port'),
231
-			'destination_ip'	=> array('Destination IP','t.destination_ip'),
232
-			'destination_port'	=> array('Destination port','t.destination_port'),			
233
-			'trap_oid'			=> array('Numeric OID','t.trap_oid'),
234
-			'trap_name'			=> array('Trap name','t.trap_name'),
235
-			'trap_name_mib'		=> array('Trap MIB','t.trap_name_mib'),
236
-			'status'			=> array('Processing status','t.status'),
237
-			'status_detail'		=> array('Status details','t.status_detail'),
238
-			'process_time'		=> array('Trap processing time','t.process_time'),			
227
+			'timestamp'			=> array('Date', 'UNIX_TIMESTAMP(t.date_received)'),
228
+			'source_ip'			=> array('Source IP', 't.source_ip'),
229
+			'source_name'		=> array('Source name', 't.source_name'),
230
+			'source_port'		=> array('Source port', 't.source_port'),
231
+			'destination_ip'	=> array('Destination IP', 't.destination_ip'),
232
+			'destination_port'	=> array('Destination port', 't.destination_port'),			
233
+			'trap_oid'			=> array('Numeric OID', 't.trap_oid'),
234
+			'trap_name'			=> array('Trap name', 't.trap_name'),
235
+			'trap_name_mib'		=> array('Trap MIB', 't.trap_name_mib'),
236
+			'status'			=> array('Processing status', 't.status'),
237
+			'status_detail'		=> array('Status details', 't.status_detail'),
238
+			'process_time'		=> array('Trap processing time', 't.process_time'),			
239 239
 		);
240 240
 	}
241 241
 	// Trap detail : additional data (<key> => <title> <sql select>)
242 242
 	public function trapDataDetailQuery()
243 243
 	{
244 244
 		return array(
245
-			'oid'				=> array('Numeric OID','d.oid'),
246
-			'oid_name'			=> array('Text OID','d.oid_name'),
247
-			'oid_name_mib'		=> array('MIB','d.oid_name_mib'),
248
-			'value'				=> array('Value','d.value'),
245
+			'oid'				=> array('Numeric OID', 'd.oid'),
246
+			'oid_name'			=> array('Text OID', 'd.oid_name'),
247
+			'oid_name_mib'		=> array('MIB', 'd.oid_name_mib'),
248
+			'value'				=> array('Value', 'd.value'),
249 249
 		);
250 250
 	}
251 251
 	// foreign key of trap data table
252
-	public function trapDataFK() { return 'trap_id';}
252
+	public function trapDataFK() { return 'trap_id'; }
253 253
 	
254 254
 	// Max items in a list OBSOLETE TODO : remove after all tables moved to trapdirectorTable
255 255
 	public function itemListDisplay() { return 25; }
Please login to merge, or discard this patch.
library/Trapdirector/Tables/TrapDirectorTableGrouping.php 3 patches
Indentation   +69 added lines, -69 removed lines patch added patch discarded remove patch
@@ -7,86 +7,86 @@
 block discarded – undo
7 7
 {
8 8
     
9 9
   
10
-    /*************** Grouping ************/
10
+	/*************** Grouping ************/
11 11
     
12
-    /** @var boolean $grouppingActive set to true if grouping is active by query or function call */
13
-    protected $grouppingActive=false;
12
+	/** @var boolean $grouppingActive set to true if grouping is active by query or function call */
13
+	protected $grouppingActive=false;
14 14
     
15
-    /** @var string $groupingColumn Name of column (can be hidden) for grouping */
16
-    protected $groupingColumn='';
15
+	/** @var string $groupingColumn Name of column (can be hidden) for grouping */
16
+	protected $groupingColumn='';
17 17
     
18
-    /**@var string $groupingVal Current value of grouping column in row (used while rendering) */
19
-    protected $groupingVal='';
18
+	/**@var string $groupingVal Current value of grouping column in row (used while rendering) */
19
+	protected $groupingVal='';
20 20
     
21
-    /** @var integer $groupingColSpan colspan of grouping line : set to table titles in init */
22
-    protected $groupingColSpan=1;
21
+	/** @var integer $groupingColSpan colspan of grouping line : set to table titles in init */
22
+	protected $groupingColSpan=1;
23 23
       
24
-    /*****************  Grouping ****************/
24
+	/*****************  Grouping ****************/
25 25
     
26
-    /**
27
-     * Set grouping. column must be DB name
28
-     * @param string $columnDBName
29
-     */
30
-    public function setGrouping(string $columnDBName)
31
-    {
32
-        $this->groupingColumn = $columnDBName;
33
-        $this->grouppingActive = TRUE;
34
-    }
26
+	/**
27
+	 * Set grouping. column must be DB name
28
+	 * @param string $columnDBName
29
+	 */
30
+	public function setGrouping(string $columnDBName)
31
+	{
32
+		$this->groupingColumn = $columnDBName;
33
+		$this->grouppingActive = TRUE;
34
+	}
35 35
     
36
-    /**
37
-     * Init of grouping before rendering
38
-     */
39
-    public function initGrouping()
40
-    {
41
-        $this->groupingVal = '';
42
-        $this->groupingColSpan = count($this->titles);
43
-    }
36
+	/**
37
+	 * Init of grouping before rendering
38
+	 */
39
+	public function initGrouping()
40
+	{
41
+		$this->groupingVal = '';
42
+		$this->groupingColSpan = count($this->titles);
43
+	}
44 44
     
45
-    /**
46
-     * Function to print grouping value (for ovveride in specific tables)
47
-     * @param string $value
48
-     * @return string
49
-     */
50
-    public function groupingPrintData( string $value )
51
-    {
52
-        $html = "$value";
53
-        return $html;
54
-    }
45
+	/**
46
+	 * Function to print grouping value (for ovveride in specific tables)
47
+	 * @param string $value
48
+	 * @return string
49
+	 */
50
+	public function groupingPrintData( string $value )
51
+	{
52
+		$html = "$value";
53
+		return $html;
54
+	}
55 55
     
56
-    /**
57
-     * When to display new grouping line  (for ovveride in specific tables)
58
-     * @param string $val1 Current value in grouping
59
-     * @param string $val2 Value of current line
60
-     * @return boolean TRUE if a new grouping line is needed.
61
-     */
62
-    public function groupingEvalNext(string $val1, string $val2)
63
-    {
64
-        if ($val1 != $val2)
65
-            return TRUE;
66
-        else
67
-            return FALSE;
68
-    }
56
+	/**
57
+	 * When to display new grouping line  (for ovveride in specific tables)
58
+	 * @param string $val1 Current value in grouping
59
+	 * @param string $val2 Value of current line
60
+	 * @return boolean TRUE if a new grouping line is needed.
61
+	 */
62
+	public function groupingEvalNext(string $val1, string $val2)
63
+	{
64
+		if ($val1 != $val2)
65
+			return TRUE;
66
+		else
67
+			return FALSE;
68
+	}
69 69
     
70
-    /**
71
-     * Called before each line to check if grouping line is needed.
72
-     * @param mixed $values
73
-     * @return string with line or empty.
74
-     */
75
-    public function groupingNextLine( $values)
76
-    {
77
-        if ($this->grouppingActive === FALSE) return '';
70
+	/**
71
+	 * Called before each line to check if grouping line is needed.
72
+	 * @param mixed $values
73
+	 * @return string with line or empty.
74
+	 */
75
+	public function groupingNextLine( $values)
76
+	{
77
+		if ($this->grouppingActive === FALSE) return '';
78 78
 
79
-        $dbcol = $this->groupingColumn;
80
-        $dbVal = $values->$dbcol;
81
-        if ( $dbVal === NULL ) $dbVal = '0'; // Set default to 0
82
-        if ($this->groupingVal == '' || $this->groupingEvalNext($this->groupingVal ,$dbVal) === TRUE )
83
-        {
84
-            $this->groupingVal = $dbVal;
85
-            $html = '<tr><th colspan="'. $this->groupingColSpan .'">'. $this->groupingPrintData($this->groupingVal) .'</th></tr>';
86
-            return $html;
87
-        }
88
-        return '';
79
+		$dbcol = $this->groupingColumn;
80
+		$dbVal = $values->$dbcol;
81
+		if ( $dbVal === NULL ) $dbVal = '0'; // Set default to 0
82
+		if ($this->groupingVal == '' || $this->groupingEvalNext($this->groupingVal ,$dbVal) === TRUE )
83
+		{
84
+			$this->groupingVal = $dbVal;
85
+			$html = '<tr><th colspan="'. $this->groupingColSpan .'">'. $this->groupingPrintData($this->groupingVal) .'</th></tr>';
86
+			return $html;
87
+		}
88
+		return '';
89 89
 
90
-    }
90
+	}
91 91
  
92 92
 }
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -29,8 +29,8 @@  discard block
 block discarded – undo
29 29
      */
30 30
     public function setGrouping(string $columnDBName)
31 31
     {
32
-        $this->groupingColumn = $columnDBName;
33
-        $this->grouppingActive = TRUE;
32
+        $this->groupingColumn=$columnDBName;
33
+        $this->grouppingActive=TRUE;
34 34
     }
35 35
     
36 36
     /**
@@ -38,8 +38,8 @@  discard block
 block discarded – undo
38 38
      */
39 39
     public function initGrouping()
40 40
     {
41
-        $this->groupingVal = '';
42
-        $this->groupingColSpan = count($this->titles);
41
+        $this->groupingVal='';
42
+        $this->groupingColSpan=count($this->titles);
43 43
     }
44 44
     
45 45
     /**
@@ -47,9 +47,9 @@  discard block
 block discarded – undo
47 47
      * @param string $value
48 48
      * @return string
49 49
      */
50
-    public function groupingPrintData( string $value )
50
+    public function groupingPrintData(string $value)
51 51
     {
52
-        $html = "$value";
52
+        $html="$value";
53 53
         return $html;
54 54
     }
55 55
     
@@ -72,17 +72,17 @@  discard block
 block discarded – undo
72 72
      * @param mixed $values
73 73
      * @return string with line or empty.
74 74
      */
75
-    public function groupingNextLine( $values)
75
+    public function groupingNextLine($values)
76 76
     {
77 77
         if ($this->grouppingActive === FALSE) return '';
78 78
 
79
-        $dbcol = $this->groupingColumn;
80
-        $dbVal = $values->$dbcol;
81
-        if ( $dbVal === NULL ) $dbVal = '0'; // Set default to 0
82
-        if ($this->groupingVal == '' || $this->groupingEvalNext($this->groupingVal ,$dbVal) === TRUE )
79
+        $dbcol=$this->groupingColumn;
80
+        $dbVal=$values->$dbcol;
81
+        if ($dbVal === NULL) $dbVal='0'; // Set default to 0
82
+        if ($this->groupingVal == '' || $this->groupingEvalNext($this->groupingVal, $dbVal) === TRUE)
83 83
         {
84
-            $this->groupingVal = $dbVal;
85
-            $html = '<tr><th colspan="'. $this->groupingColSpan .'">'. $this->groupingPrintData($this->groupingVal) .'</th></tr>';
84
+            $this->groupingVal=$dbVal;
85
+            $html='<tr><th colspan="'.$this->groupingColSpan.'">'.$this->groupingPrintData($this->groupingVal).'</th></tr>';
86 86
             return $html;
87 87
         }
88 88
         return '';
Please login to merge, or discard this patch.
Braces   +12 added lines, -6 removed lines patch added patch discarded remove patch
@@ -61,10 +61,11 @@  discard block
 block discarded – undo
61 61
      */
62 62
     public function groupingEvalNext(string $val1, string $val2)
63 63
     {
64
-        if ($val1 != $val2)
65
-            return TRUE;
66
-        else
67
-            return FALSE;
64
+        if ($val1 != $val2) {
65
+                    return TRUE;
66
+        } else {
67
+                    return FALSE;
68
+        }
68 69
     }
69 70
     
70 71
     /**
@@ -74,11 +75,16 @@  discard block
 block discarded – undo
74 75
      */
75 76
     public function groupingNextLine( $values)
76 77
     {
77
-        if ($this->grouppingActive === FALSE) return '';
78
+        if ($this->grouppingActive === FALSE) {
79
+        	return '';
80
+        }
78 81
 
79 82
         $dbcol = $this->groupingColumn;
80 83
         $dbVal = $values->$dbcol;
81
-        if ( $dbVal === NULL ) $dbVal = '0'; // Set default to 0
84
+        if ( $dbVal === NULL ) {
85
+        	$dbVal = '0';
86
+        }
87
+        // Set default to 0
82 88
         if ($this->groupingVal == '' || $this->groupingEvalNext($this->groupingVal ,$dbVal) === TRUE )
83 89
         {
84 90
             $this->groupingVal = $dbVal;
Please login to merge, or discard this patch.
library/Trapdirector/IcingaApi/IcingaApiBase.php 3 patches
Braces   +7 added lines, -9 removed lines patch added patch discarded remove patch
@@ -80,18 +80,19 @@  discard block
 block discarded – undo
80 80
        try
81 81
         {
82 82
             $result=$this->request('GET', "", NULL, NULL);
83
-        } 
84
-        catch (Exception $e)
83
+        } catch (Exception $e)
85 84
         {
86 85
             return array(true, 'Error with API : '.$e->getMessage());
87 86
         }
88 87
         //var_dump($result);
89 88
         $permOk=1;
90 89
         $permMissing='';
91
-        if ($permissions === NULL || count($permissions) == 0) // If no permission check return OK after connexion
90
+        if ($permissions === NULL || count($permissions) == 0) {
91
+        	// If no permission check return OK after connexion
92 92
         {
93 93
             return array(false,'OK');
94 94
         }
95
+        }
95 96
         if (property_exists($result, 'results') && property_exists($result->results[0], 'permissions'))
96 97
         {
97 98
             
@@ -177,8 +178,7 @@  discard block
 block discarded – undo
177 178
             if (property_exists($result,'status'))
178 179
             {
179 180
                 $message=$result->status;
180
-            }
181
-            else 
181
+            } else 
182 182
             {
183 183
                 $message="Unkown status";
184 184
             }
@@ -189,8 +189,7 @@  discard block
 block discarded – undo
189 189
             if (isset($result->results[0]))
190 190
             {
191 191
                 return array(true,'code '.$result->results[0]->code.' : '.$result->results[0]->status);
192
-            }
193
-            else
192
+            } else
194 193
             {
195 194
                 return array(false,'Service not found');
196 195
             }
@@ -211,8 +210,7 @@  discard block
 block discarded – undo
211 210
             if (property_exists($result,'status'))
212 211
             {
213 212
                 throw new Exception('Ret code ' .$result->error.' : ' . $result->status);
214
-            }
215
-            else
213
+            } else
216 214
             {
217 215
                 throw new Exception('Ret code ' .$result->error.' : Unkown status');
218 216
             }
Please login to merge, or discard this patch.
Indentation   +313 added lines, -313 removed lines patch added patch discarded remove patch
@@ -8,347 +8,347 @@
 block discarded – undo
8 8
 
9 9
 class IcingaApiBase
10 10
 {
11
-    protected $version = 'v1';      //< icinga2 api version
11
+	protected $version = 'v1';      //< icinga2 api version
12 12
     
13
-    protected $host;                //< icinga2 host name or IP
14
-    protected $port;                //< icinga2 api port
13
+	protected $host;                //< icinga2 host name or IP
14
+	protected $port;                //< icinga2 api port
15 15
     
16
-    protected $user;                //< user name
17
-    protected $pass;                //< user password
18
-    protected $usercert;            //< user key for certificate auth (NOT IMPLEMENTED)
19
-    protected $authmethod='pass';   //< Authentication : 'pass' or 'cert'
16
+	protected $user;                //< user name
17
+	protected $pass;                //< user password
18
+	protected $usercert;            //< user key for certificate auth (NOT IMPLEMENTED)
19
+	protected $authmethod='pass';   //< Authentication : 'pass' or 'cert'
20 20
 
21
-    protected $queryURL=array(
22
-        'host'  => 'objects/hosts',
23
-        'hostgroup' => 'objects/hostgroups',
24
-        'service' => 'objects/services'
25
-    );
21
+	protected $queryURL=array(
22
+		'host'  => 'objects/hosts',
23
+		'hostgroup' => 'objects/hostgroups',
24
+		'service' => 'objects/services'
25
+	);
26 26
     
27
-    protected $curl;
28
-    // http://php.net/manual/de/function.json-last-error.php#119985
29
-    protected $errorReference = [
30
-        JSON_ERROR_NONE => 'No error has occurred.',
31
-        JSON_ERROR_DEPTH => 'The maximum stack depth has been exceeded.',
32
-        JSON_ERROR_STATE_MISMATCH => 'Invalid or malformed JSON.',
33
-        JSON_ERROR_CTRL_CHAR => 'Control character error, possibly incorrectly encoded.',
34
-        JSON_ERROR_SYNTAX => 'Syntax error.',
35
-        JSON_ERROR_UTF8 => 'Malformed UTF-8 characters, possibly incorrectly encoded.',
36
-        JSON_ERROR_RECURSION => 'One or more recursive references in the value to be encoded.',
37
-        JSON_ERROR_INF_OR_NAN => 'One or more NAN or INF values in the value to be encoded.',
38
-        JSON_ERROR_UNSUPPORTED_TYPE => 'A value of a type that cannot be encoded was given.',
39
-    ];
40
-    const JSON_UNKNOWN_ERROR = 'Unknown error.';
27
+	protected $curl;
28
+	// http://php.net/manual/de/function.json-last-error.php#119985
29
+	protected $errorReference = [
30
+		JSON_ERROR_NONE => 'No error has occurred.',
31
+		JSON_ERROR_DEPTH => 'The maximum stack depth has been exceeded.',
32
+		JSON_ERROR_STATE_MISMATCH => 'Invalid or malformed JSON.',
33
+		JSON_ERROR_CTRL_CHAR => 'Control character error, possibly incorrectly encoded.',
34
+		JSON_ERROR_SYNTAX => 'Syntax error.',
35
+		JSON_ERROR_UTF8 => 'Malformed UTF-8 characters, possibly incorrectly encoded.',
36
+		JSON_ERROR_RECURSION => 'One or more recursive references in the value to be encoded.',
37
+		JSON_ERROR_INF_OR_NAN => 'One or more NAN or INF values in the value to be encoded.',
38
+		JSON_ERROR_UNSUPPORTED_TYPE => 'A value of a type that cannot be encoded was given.',
39
+	];
40
+	const JSON_UNKNOWN_ERROR = 'Unknown error.';
41 41
     
42
-    /**
43
-     * Creates Icinga2API object
44
-     * 
45
-     * @param string $host host name or IP
46
-     * @param number $port API port
47
-     */
48
-    public function __construct($host, $port = 5665)
49
-    {
50
-        $this->host=$host;
51
-        $this->port=$port;
52
-    }
53
-    /**
54
-     * Set user & pass
55
-     * @param string $user
56
-     * @param string $pass
57
-     */
58
-    public function setCredentials($user,$pass)
59
-    {
60
-        $this->user=$user;
61
-        $this->pass=$pass;
62
-        $this->authmethod='pass';
63
-    }
42
+	/**
43
+	 * Creates Icinga2API object
44
+	 * 
45
+	 * @param string $host host name or IP
46
+	 * @param number $port API port
47
+	 */
48
+	public function __construct($host, $port = 5665)
49
+	{
50
+		$this->host=$host;
51
+		$this->port=$port;
52
+	}
53
+	/**
54
+	 * Set user & pass
55
+	 * @param string $user
56
+	 * @param string $pass
57
+	 */
58
+	public function setCredentials($user,$pass)
59
+	{
60
+		$this->user=$user;
61
+		$this->pass=$pass;
62
+		$this->authmethod='pass';
63
+	}
64 64
     
65
-    /**
66
-     * Set user & certificate (NOT IMPLEMENTED @throws RuntimeException)
67
-     * @param string $user
68
-     * @param string $usercert
69
-     */
70
-    public function setCredentialskey($user,$usercert)
71
-    {
72
-        $this->user=$user;
73
-        $this->usercert=$usercert;
74
-        $this->authmethod='cert';
75
-        throw new RuntimeException('Certificate auth not implemented');
76
-    }
65
+	/**
66
+	 * Set user & certificate (NOT IMPLEMENTED @throws RuntimeException)
67
+	 * @param string $user
68
+	 * @param string $usercert
69
+	 */
70
+	public function setCredentialskey($user,$usercert)
71
+	{
72
+		$this->user=$user;
73
+		$this->usercert=$usercert;
74
+		$this->authmethod='cert';
75
+		throw new RuntimeException('Certificate auth not implemented');
76
+	}
77 77
 
78
-    /**
79
-     * Test API connection
80
-     * @param array $permissions : check permissions if not null or empty
81
-     * @return array (bool,string) : bool = false is all OK, else true with message
82
-     * */
83
-    public function test(array $permissions)
84
-    {
85
-       try
86
-        {
87
-            $result=$this->request('GET', "", NULL, NULL);
88
-        } 
89
-        catch (Exception $e)
90
-        {
91
-            return array(true, 'Error with API : '.$e->getMessage());
92
-        }
93
-        //var_dump($result);
94
-        $permOk=1;
95
-        $permMissing='';
96
-        if ($permissions === NULL || count($permissions) == 0) // If no permission check return OK after connexion
97
-        {
98
-            return array(false,'OK');
99
-        }
100
-        if (property_exists($result, 'results') && property_exists($result->results[0], 'permissions'))
101
-        {
78
+	/**
79
+	 * Test API connection
80
+	 * @param array $permissions : check permissions if not null or empty
81
+	 * @return array (bool,string) : bool = false is all OK, else true with message
82
+	 * */
83
+	public function test(array $permissions)
84
+	{
85
+	   try
86
+		{
87
+			$result=$this->request('GET', "", NULL, NULL);
88
+		} 
89
+		catch (Exception $e)
90
+		{
91
+			return array(true, 'Error with API : '.$e->getMessage());
92
+		}
93
+		//var_dump($result);
94
+		$permOk=1;
95
+		$permMissing='';
96
+		if ($permissions === NULL || count($permissions) == 0) // If no permission check return OK after connexion
97
+		{
98
+			return array(false,'OK');
99
+		}
100
+		if (property_exists($result, 'results') && property_exists($result->results[0], 'permissions'))
101
+		{
102 102
             
103
-            foreach ( $permissions as $mustPermission)
104
-            {
105
-                $curPermOK=0;
106
-                foreach ( $result->results[0]->permissions as $curPermission)
107
-                {
108
-                    $curPermission=preg_replace('/\*/','.*',$curPermission); // put * as .* to created a regexp
109
-                    if (preg_match('#'.$curPermission.'#',$mustPermission))
110
-                    {
111
-                        $curPermOK=1;
112
-                        break;
113
-                    }
114
-                }
115
-                if ($curPermOK == 0)
116
-                {
117
-                    $permOk=0;
118
-                    $permMissing=$mustPermission;
119
-                    break;
120
-                }
121
-            }
122
-            if ($permOk == 0)
123
-            {
124
-                return array(true,'API connection OK, but missing permission : '.$permMissing);
125
-            }
126
-            return array(false,'API connection OK');
103
+			foreach ( $permissions as $mustPermission)
104
+			{
105
+				$curPermOK=0;
106
+				foreach ( $result->results[0]->permissions as $curPermission)
107
+				{
108
+					$curPermission=preg_replace('/\*/','.*',$curPermission); // put * as .* to created a regexp
109
+					if (preg_match('#'.$curPermission.'#',$mustPermission))
110
+					{
111
+						$curPermOK=1;
112
+						break;
113
+					}
114
+				}
115
+				if ($curPermOK == 0)
116
+				{
117
+					$permOk=0;
118
+					$permMissing=$mustPermission;
119
+					break;
120
+				}
121
+			}
122
+			if ($permOk == 0)
123
+			{
124
+				return array(true,'API connection OK, but missing permission : '.$permMissing);
125
+			}
126
+			return array(false,'API connection OK');
127 127
             
128
-        }
129
-        return array(true,'API connection OK, but cannot get permissions');
130
-    }
128
+		}
129
+		return array(true,'API connection OK, but cannot get permissions');
130
+	}
131 131
     
132 132
     
133
-    protected function url($url) {
134
-        return sprintf('https://%s:%d/%s/%s', $this->host, $this->port, $this->version, $url);
135
-    }
133
+	protected function url($url) {
134
+		return sprintf('https://%s:%d/%s/%s', $this->host, $this->port, $this->version, $url);
135
+	}
136 136
     
137
-    /**
138
-     * Create or return curl ressource
139
-     * @throws Exception
140
-     * @return resource
141
-     */
142
-    protected function curl() {
143
-        if ($this->curl === null) {
144
-            $this->curl = curl_init(sprintf('https://%s:%d', $this->host, $this->port));
145
-            if ($this->curl === false) {
146
-                throw new Exception('CURL INIT ERROR');
147
-            }
148
-        }
149
-        return $this->curl;
150
-    }
137
+	/**
138
+	 * Create or return curl ressource
139
+	 * @throws Exception
140
+	 * @return resource
141
+	 */
142
+	protected function curl() {
143
+		if ($this->curl === null) {
144
+			$this->curl = curl_init(sprintf('https://%s:%d', $this->host, $this->port));
145
+			if ($this->curl === false) {
146
+				throw new Exception('CURL INIT ERROR');
147
+			}
148
+		}
149
+		return $this->curl;
150
+	}
151 151
 
152
-    /**
153
-     * Send a passive service check
154
-     * @param string $host : host name 
155
-     * @param string $service : service name
156
-     * @param int $state : state of service
157
-     * @param string $display : service passive check output
158
-     * @param string $perfdata : performance data as string
159
-     * @return array (status = true (oK) or false (nok), string message)
160
-     */
161
-    public function serviceCheckResult($host,$service,$state,$display,$perfdata='')
162
-    {
163
-        //Send a POST request to the URL endpoint /v1/actions/process-check-result
164
-        //actions/process-check-result?service=example.localdomain!passive-ping6
165
-        $url='actions/process-check-result';
166
-        $body=array(
167
-            "filter"        => 'service.name=="'.$service.'" && service.host_name=="'.$host.'"',
168
-            'type'          => 'Service',
169
-            "exit_status"   => $state,
170
-            "plugin_output" => $display,
171
-            "performance_data" => $perfdata
172
-        );
173
-        try 
174
-        {
175
-            $result=$this->request('POST', $url, null, $body);
176
-        } catch (Exception $e) 
177
-        {
178
-            return array(false, $e->getMessage());
179
-        }
180
-        if (property_exists($result,'error') )
181
-        {
182
-            if (property_exists($result,'status'))
183
-            {
184
-                $message=$result->status;
185
-            }
186
-            else 
187
-            {
188
-                $message="Unkown status";
189
-            }
190
-            return array(false , 'Ret code ' .$result->error.' : '.$message);
191
-        }
192
-        if (property_exists($result, 'results'))
193
-        {
194
-            if (isset($result->results[0]))
195
-            {
196
-                return array(true,'code '.$result->results[0]->code.' : '.$result->results[0]->status);
197
-            }
198
-            else
199
-            {
200
-                return array(false,'Service not found');
201
-            }
152
+	/**
153
+	 * Send a passive service check
154
+	 * @param string $host : host name 
155
+	 * @param string $service : service name
156
+	 * @param int $state : state of service
157
+	 * @param string $display : service passive check output
158
+	 * @param string $perfdata : performance data as string
159
+	 * @return array (status = true (oK) or false (nok), string message)
160
+	 */
161
+	public function serviceCheckResult($host,$service,$state,$display,$perfdata='')
162
+	{
163
+		//Send a POST request to the URL endpoint /v1/actions/process-check-result
164
+		//actions/process-check-result?service=example.localdomain!passive-ping6
165
+		$url='actions/process-check-result';
166
+		$body=array(
167
+			"filter"        => 'service.name=="'.$service.'" && service.host_name=="'.$host.'"',
168
+			'type'          => 'Service',
169
+			"exit_status"   => $state,
170
+			"plugin_output" => $display,
171
+			"performance_data" => $perfdata
172
+		);
173
+		try 
174
+		{
175
+			$result=$this->request('POST', $url, null, $body);
176
+		} catch (Exception $e) 
177
+		{
178
+			return array(false, $e->getMessage());
179
+		}
180
+		if (property_exists($result,'error') )
181
+		{
182
+			if (property_exists($result,'status'))
183
+			{
184
+				$message=$result->status;
185
+			}
186
+			else 
187
+			{
188
+				$message="Unkown status";
189
+			}
190
+			return array(false , 'Ret code ' .$result->error.' : '.$message);
191
+		}
192
+		if (property_exists($result, 'results'))
193
+		{
194
+			if (isset($result->results[0]))
195
+			{
196
+				return array(true,'code '.$result->results[0]->code.' : '.$result->results[0]->status);
197
+			}
198
+			else
199
+			{
200
+				return array(false,'Service not found');
201
+			}
202 202
             
203
-        }
204
-        return array(false,'Unkown result, open issue with this : '.print_r($result,true));
205
-    }
203
+		}
204
+		return array(false,'Unkown result, open issue with this : '.print_r($result,true));
205
+	}
206 206
   
207
-    /**
208
-     * Check 'result' exists and check for errors/status
209
-     * @param \stdClass $result
210
-     * @throws Exception 
211
-     */
212
-    public function checkResultStatus(\stdClass $result) 
213
-    {
214
-        if (property_exists($result,'error') )
215
-        {
216
-            if (property_exists($result,'status'))
217
-            {
218
-                throw new Exception('Ret code ' .$result->error.' : ' . $result->status);
219
-            }
220
-            else
221
-            {
222
-                throw new Exception('Ret code ' .$result->error.' : Unkown status');
223
-            }
224
-        }
225
-        if ( ! property_exists($result, 'results'))
226
-        {
227
-            throw new Exception('Unkown result');
228
-        }
229
-    }
207
+	/**
208
+	 * Check 'result' exists and check for errors/status
209
+	 * @param \stdClass $result
210
+	 * @throws Exception 
211
+	 */
212
+	public function checkResultStatus(\stdClass $result) 
213
+	{
214
+		if (property_exists($result,'error') )
215
+		{
216
+			if (property_exists($result,'status'))
217
+			{
218
+				throw new Exception('Ret code ' .$result->error.' : ' . $result->status);
219
+			}
220
+			else
221
+			{
222
+				throw new Exception('Ret code ' .$result->error.' : Unkown status');
223
+			}
224
+		}
225
+		if ( ! property_exists($result, 'results'))
226
+		{
227
+			throw new Exception('Unkown result');
228
+		}
229
+	}
230 230
     
231
-    /**
232
-     * Send request to API
233
-     * @param string $method get/post/...
234
-     * @param string $url (after /v1/ )
235
-     * @param array $headers
236
-     * @param array $body 
237
-     * @throws Exception
238
-     * @return array
239
-     */
240
-    public function request($method, $url, $headers, $body) {
241
-        $auth = sprintf('%s:%s', $this->user, $this->pass);
242
-        $curlHeaders = array("Accept: application/json");
243
-        if ($body !== null) {
244
-            $body = json_encode($body);
245
-            array_push($curlHeaders, 'Content-Type: application/json');
246
-            //array_push($curlHeaders, 'X-HTTP-Method-Override: GET');
247
-        }
248
-        //var_dump($body);
249
-        //var_dump($this->url($url));
250
-        if ($headers !== null) {
251
-            $curlFinalHeaders = array_merge($curlHeaders, $headers);
252
-        } else 
253
-        {
254
-            $curlFinalHeaders=$curlHeaders;
255
-        }
256
-        $curl = $this->curl();
257
-        $opts = array(
258
-            CURLOPT_URL		=> $this->url($url),
259
-            CURLOPT_HTTPHEADER 	=> $curlFinalHeaders,
260
-            CURLOPT_USERPWD		=> $auth,
261
-            CURLOPT_CUSTOMREQUEST	=> strtoupper($method),
262
-            CURLOPT_RETURNTRANSFER 	=> true,
263
-            CURLOPT_CONNECTTIMEOUT 	=> 10,
264
-            CURLOPT_SSL_VERIFYHOST 	=> false,
265
-            CURLOPT_SSL_VERIFYPEER 	=> false,
266
-        );
267
-        if ($body !== null) {
268
-            $opts[CURLOPT_POSTFIELDS] = $body;
269
-        }
270
-        curl_setopt_array($curl, $opts);
271
-        $res = curl_exec($curl);
272
-        if ($res === false) {
273
-            throw new Exception('CURL ERROR: ' . curl_error($curl));
274
-        }
275
-        $statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
276
-        if ($statusCode === 401) {
277
-            throw new Exception('Unable to authenticate, please check your API credentials');
278
-        }
279
-        return $this->fromJsonResult($res);
280
-    }
231
+	/**
232
+	 * Send request to API
233
+	 * @param string $method get/post/...
234
+	 * @param string $url (after /v1/ )
235
+	 * @param array $headers
236
+	 * @param array $body 
237
+	 * @throws Exception
238
+	 * @return array
239
+	 */
240
+	public function request($method, $url, $headers, $body) {
241
+		$auth = sprintf('%s:%s', $this->user, $this->pass);
242
+		$curlHeaders = array("Accept: application/json");
243
+		if ($body !== null) {
244
+			$body = json_encode($body);
245
+			array_push($curlHeaders, 'Content-Type: application/json');
246
+			//array_push($curlHeaders, 'X-HTTP-Method-Override: GET');
247
+		}
248
+		//var_dump($body);
249
+		//var_dump($this->url($url));
250
+		if ($headers !== null) {
251
+			$curlFinalHeaders = array_merge($curlHeaders, $headers);
252
+		} else 
253
+		{
254
+			$curlFinalHeaders=$curlHeaders;
255
+		}
256
+		$curl = $this->curl();
257
+		$opts = array(
258
+			CURLOPT_URL		=> $this->url($url),
259
+			CURLOPT_HTTPHEADER 	=> $curlFinalHeaders,
260
+			CURLOPT_USERPWD		=> $auth,
261
+			CURLOPT_CUSTOMREQUEST	=> strtoupper($method),
262
+			CURLOPT_RETURNTRANSFER 	=> true,
263
+			CURLOPT_CONNECTTIMEOUT 	=> 10,
264
+			CURLOPT_SSL_VERIFYHOST 	=> false,
265
+			CURLOPT_SSL_VERIFYPEER 	=> false,
266
+		);
267
+		if ($body !== null) {
268
+			$opts[CURLOPT_POSTFIELDS] = $body;
269
+		}
270
+		curl_setopt_array($curl, $opts);
271
+		$res = curl_exec($curl);
272
+		if ($res === false) {
273
+			throw new Exception('CURL ERROR: ' . curl_error($curl));
274
+		}
275
+		$statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
276
+		if ($statusCode === 401) {
277
+			throw new Exception('Unable to authenticate, please check your API credentials');
278
+		}
279
+		return $this->fromJsonResult($res);
280
+	}
281 281
     
282
-    /**
283
-     * 
284
-     * @param string $json json encoded 
285
-     * @throws Exception
286
-     * @return array json decoded
287
-     */
288
-    protected function fromJsonResult($json) {
289
-        $result = @json_decode($json);
290
-        //var_dump($json);
291
-        if ($result === null) {
292
-            throw new Exception('Parsing JSON failed: '.$this->getLastJsonErrorMessage(json_last_error()));
293
-        }
294
-        return $result;
295
-    }
282
+	/**
283
+	 * 
284
+	 * @param string $json json encoded 
285
+	 * @throws Exception
286
+	 * @return array json decoded
287
+	 */
288
+	protected function fromJsonResult($json) {
289
+		$result = @json_decode($json);
290
+		//var_dump($json);
291
+		if ($result === null) {
292
+			throw new Exception('Parsing JSON failed: '.$this->getLastJsonErrorMessage(json_last_error()));
293
+		}
294
+		return $result;
295
+	}
296 296
     
297
-    /**
298
-     * Return text error no json error
299
-     * @param string $errorCode
300
-     * @return string
301
-     */
302
-    protected function getLastJsonErrorMessage($errorCode) {
303
-        if (!array_key_exists($errorCode, $this->errorReference)) {
304
-            return self::JSON_UNKNOWN_ERROR;
305
-        }
306
-        return $this->errorReference[$errorCode];
307
-    }
297
+	/**
298
+	 * Return text error no json error
299
+	 * @param string $errorCode
300
+	 * @return string
301
+	 */
302
+	protected function getLastJsonErrorMessage($errorCode) {
303
+		if (!array_key_exists($errorCode, $this->errorReference)) {
304
+			return self::JSON_UNKNOWN_ERROR;
305
+		}
306
+		return $this->errorReference[$errorCode];
307
+	}
308 308
 
309
-    public function standardQuery(string $urlType , string $filter, array $attributes)
310
-    {
311
-        /*
309
+	public function standardQuery(string $urlType , string $filter, array $attributes)
310
+	{
311
+		/*
312 312
          *  curl -k -s -u  trapdirector:trapdirector -H 'X-HTTP-Method-Override: GET' -X POST 'https://localhost:5665/v1/objects/hosts' 
313 313
          *  -d '{"filter":"\"test_trap\" in host.groups","attrs": ["address" ,"address6"],"pretty": true}'
314 314
          
315 315
          {"results":[{"attrs":{"__name":"Icinga host","address":"127.0.0.1","display_name":"Icinga host","name":"Icinga host"},"joins":{},"meta":{},"name":"Icinga host","type":"Host"}]}
316 316
          */
317 317
         
318
-        if (! isset($this->queryURL[$urlType] ))
319
-        {
320
-            throw new Exception("Unkown object type");
321
-        }
322
-        $url=$this->queryURL[$urlType];
323
-        $body=array();
324
-        if ($filter !== NULL)
325
-        {
326
-            $body['filter'] = $filter;
327
-        }
328
-        if (count($attributes) != 0)
329
-        {
330
-            $body['attrs'] = $attributes;
331
-        }
318
+		if (! isset($this->queryURL[$urlType] ))
319
+		{
320
+			throw new Exception("Unkown object type");
321
+		}
322
+		$url=$this->queryURL[$urlType];
323
+		$body=array();
324
+		if ($filter !== NULL)
325
+		{
326
+			$body['filter'] = $filter;
327
+		}
328
+		if (count($attributes) != 0)
329
+		{
330
+			$body['attrs'] = $attributes;
331
+		}
332 332
 
333
-        try
334
-        {
335
-            $result=$this->request('POST', $url, array('X-HTTP-Method-Override: GET'), $body);
336
-        } catch (Exception $e)
337
-        {
338
-            throw new Exception($e->getMessage());
339
-        }
333
+		try
334
+		{
335
+			$result=$this->request('POST', $url, array('X-HTTP-Method-Override: GET'), $body);
336
+		} catch (Exception $e)
337
+		{
338
+			throw new Exception($e->getMessage());
339
+		}
340 340
         
341
-        $this->checkResultStatus($result);
341
+		$this->checkResultStatus($result);
342 342
         
343
-        $numHost=0;
344
-        $hostArray=array();
345
-        while (isset($result->results[$numHost]) && property_exists ($result->results[$numHost],'attrs'))
346
-        {
347
-            $hostArray[$numHost] = $result->results[$numHost]->attrs;
348
-            $numHost++;
349
-        }
350
-        return $hostArray;
351
-    }
343
+		$numHost=0;
344
+		$hostArray=array();
345
+		while (isset($result->results[$numHost]) && property_exists ($result->results[$numHost],'attrs'))
346
+		{
347
+			$hostArray[$numHost] = $result->results[$numHost]->attrs;
348
+			$numHost++;
349
+		}
350
+		return $hostArray;
351
+	}
352 352
     
353 353
 }
354 354
 
Please login to merge, or discard this patch.
Spacing   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -8,15 +8,15 @@  discard block
 block discarded – undo
8 8
 
9 9
 class IcingaApiBase
10 10
 {
11
-    protected $version = 'v1';      //< icinga2 api version
11
+    protected $version='v1'; //< icinga2 api version
12 12
     
13
-    protected $host;                //< icinga2 host name or IP
14
-    protected $port;                //< icinga2 api port
13
+    protected $host; //< icinga2 host name or IP
14
+    protected $port; //< icinga2 api port
15 15
     
16
-    protected $user;                //< user name
17
-    protected $pass;                //< user password
18
-    protected $usercert;            //< user key for certificate auth (NOT IMPLEMENTED)
19
-    protected $authmethod='pass';   //< Authentication : 'pass' or 'cert'
16
+    protected $user; //< user name
17
+    protected $pass; //< user password
18
+    protected $usercert; //< user key for certificate auth (NOT IMPLEMENTED)
19
+    protected $authmethod='pass'; //< Authentication : 'pass' or 'cert'
20 20
 
21 21
     protected $queryURL=array(
22 22
         'host'  => 'objects/hosts',
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
     
27 27
     protected $curl;
28 28
     // http://php.net/manual/de/function.json-last-error.php#119985
29
-    protected $errorReference = [
29
+    protected $errorReference=[
30 30
         JSON_ERROR_NONE => 'No error has occurred.',
31 31
         JSON_ERROR_DEPTH => 'The maximum stack depth has been exceeded.',
32 32
         JSON_ERROR_STATE_MISMATCH => 'Invalid or malformed JSON.',
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
         JSON_ERROR_INF_OR_NAN => 'One or more NAN or INF values in the value to be encoded.',
38 38
         JSON_ERROR_UNSUPPORTED_TYPE => 'A value of a type that cannot be encoded was given.',
39 39
     ];
40
-    const JSON_UNKNOWN_ERROR = 'Unknown error.';
40
+    const JSON_UNKNOWN_ERROR='Unknown error.';
41 41
     
42 42
     /**
43 43
      * Creates Icinga2API object
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
      * @param string $host host name or IP
46 46
      * @param number $port API port
47 47
      */
48
-    public function __construct($host, $port = 5665)
48
+    public function __construct($host, $port=5665)
49 49
     {
50 50
         $this->host=$host;
51 51
         $this->port=$port;
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
      * @param string $user
56 56
      * @param string $pass
57 57
      */
58
-    public function setCredentials($user,$pass)
58
+    public function setCredentials($user, $pass)
59 59
     {
60 60
         $this->user=$user;
61 61
         $this->pass=$pass;
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
      * @param string $user
68 68
      * @param string $usercert
69 69
      */
70
-    public function setCredentialskey($user,$usercert)
70
+    public function setCredentialskey($user, $usercert)
71 71
     {
72 72
         $this->user=$user;
73 73
         $this->usercert=$usercert;
@@ -95,18 +95,18 @@  discard block
 block discarded – undo
95 95
         $permMissing='';
96 96
         if ($permissions === NULL || count($permissions) == 0) // If no permission check return OK after connexion
97 97
         {
98
-            return array(false,'OK');
98
+            return array(false, 'OK');
99 99
         }
100 100
         if (property_exists($result, 'results') && property_exists($result->results[0], 'permissions'))
101 101
         {
102 102
             
103
-            foreach ( $permissions as $mustPermission)
103
+            foreach ($permissions as $mustPermission)
104 104
             {
105 105
                 $curPermOK=0;
106
-                foreach ( $result->results[0]->permissions as $curPermission)
106
+                foreach ($result->results[0]->permissions as $curPermission)
107 107
                 {
108
-                    $curPermission=preg_replace('/\*/','.*',$curPermission); // put * as .* to created a regexp
109
-                    if (preg_match('#'.$curPermission.'#',$mustPermission))
108
+                    $curPermission=preg_replace('/\*/', '.*', $curPermission); // put * as .* to created a regexp
109
+                    if (preg_match('#'.$curPermission.'#', $mustPermission))
110 110
                     {
111 111
                         $curPermOK=1;
112 112
                         break;
@@ -121,12 +121,12 @@  discard block
 block discarded – undo
121 121
             }
122 122
             if ($permOk == 0)
123 123
             {
124
-                return array(true,'API connection OK, but missing permission : '.$permMissing);
124
+                return array(true, 'API connection OK, but missing permission : '.$permMissing);
125 125
             }
126
-            return array(false,'API connection OK');
126
+            return array(false, 'API connection OK');
127 127
             
128 128
         }
129
-        return array(true,'API connection OK, but cannot get permissions');
129
+        return array(true, 'API connection OK, but cannot get permissions');
130 130
     }
131 131
     
132 132
     
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
      */
142 142
     protected function curl() {
143 143
         if ($this->curl === null) {
144
-            $this->curl = curl_init(sprintf('https://%s:%d', $this->host, $this->port));
144
+            $this->curl=curl_init(sprintf('https://%s:%d', $this->host, $this->port));
145 145
             if ($this->curl === false) {
146 146
                 throw new Exception('CURL INIT ERROR');
147 147
             }
@@ -158,7 +158,7 @@  discard block
 block discarded – undo
158 158
      * @param string $perfdata : performance data as string
159 159
      * @return array (status = true (oK) or false (nok), string message)
160 160
      */
161
-    public function serviceCheckResult($host,$service,$state,$display,$perfdata='')
161
+    public function serviceCheckResult($host, $service, $state, $display, $perfdata='')
162 162
     {
163 163
         //Send a POST request to the URL endpoint /v1/actions/process-check-result
164 164
         //actions/process-check-result?service=example.localdomain!passive-ping6
@@ -177,9 +177,9 @@  discard block
 block discarded – undo
177 177
         {
178 178
             return array(false, $e->getMessage());
179 179
         }
180
-        if (property_exists($result,'error') )
180
+        if (property_exists($result, 'error'))
181 181
         {
182
-            if (property_exists($result,'status'))
182
+            if (property_exists($result, 'status'))
183 183
             {
184 184
                 $message=$result->status;
185 185
             }
@@ -187,21 +187,21 @@  discard block
 block discarded – undo
187 187
             {
188 188
                 $message="Unkown status";
189 189
             }
190
-            return array(false , 'Ret code ' .$result->error.' : '.$message);
190
+            return array(false, 'Ret code '.$result->error.' : '.$message);
191 191
         }
192 192
         if (property_exists($result, 'results'))
193 193
         {
194 194
             if (isset($result->results[0]))
195 195
             {
196
-                return array(true,'code '.$result->results[0]->code.' : '.$result->results[0]->status);
196
+                return array(true, 'code '.$result->results[0]->code.' : '.$result->results[0]->status);
197 197
             }
198 198
             else
199 199
             {
200
-                return array(false,'Service not found');
200
+                return array(false, 'Service not found');
201 201
             }
202 202
             
203 203
         }
204
-        return array(false,'Unkown result, open issue with this : '.print_r($result,true));
204
+        return array(false, 'Unkown result, open issue with this : '.print_r($result, true));
205 205
     }
206 206
   
207 207
     /**
@@ -211,18 +211,18 @@  discard block
 block discarded – undo
211 211
      */
212 212
     public function checkResultStatus(\stdClass $result) 
213 213
     {
214
-        if (property_exists($result,'error') )
214
+        if (property_exists($result, 'error'))
215 215
         {
216
-            if (property_exists($result,'status'))
216
+            if (property_exists($result, 'status'))
217 217
             {
218
-                throw new Exception('Ret code ' .$result->error.' : ' . $result->status);
218
+                throw new Exception('Ret code '.$result->error.' : '.$result->status);
219 219
             }
220 220
             else
221 221
             {
222
-                throw new Exception('Ret code ' .$result->error.' : Unkown status');
222
+                throw new Exception('Ret code '.$result->error.' : Unkown status');
223 223
             }
224 224
         }
225
-        if ( ! property_exists($result, 'results'))
225
+        if (!property_exists($result, 'results'))
226 226
         {
227 227
             throw new Exception('Unkown result');
228 228
         }
@@ -238,23 +238,23 @@  discard block
 block discarded – undo
238 238
      * @return array
239 239
      */
240 240
     public function request($method, $url, $headers, $body) {
241
-        $auth = sprintf('%s:%s', $this->user, $this->pass);
242
-        $curlHeaders = array("Accept: application/json");
241
+        $auth=sprintf('%s:%s', $this->user, $this->pass);
242
+        $curlHeaders=array("Accept: application/json");
243 243
         if ($body !== null) {
244
-            $body = json_encode($body);
244
+            $body=json_encode($body);
245 245
             array_push($curlHeaders, 'Content-Type: application/json');
246 246
             //array_push($curlHeaders, 'X-HTTP-Method-Override: GET');
247 247
         }
248 248
         //var_dump($body);
249 249
         //var_dump($this->url($url));
250 250
         if ($headers !== null) {
251
-            $curlFinalHeaders = array_merge($curlHeaders, $headers);
251
+            $curlFinalHeaders=array_merge($curlHeaders, $headers);
252 252
         } else 
253 253
         {
254 254
             $curlFinalHeaders=$curlHeaders;
255 255
         }
256
-        $curl = $this->curl();
257
-        $opts = array(
256
+        $curl=$this->curl();
257
+        $opts=array(
258 258
             CURLOPT_URL		=> $this->url($url),
259 259
             CURLOPT_HTTPHEADER 	=> $curlFinalHeaders,
260 260
             CURLOPT_USERPWD		=> $auth,
@@ -265,14 +265,14 @@  discard block
 block discarded – undo
265 265
             CURLOPT_SSL_VERIFYPEER 	=> false,
266 266
         );
267 267
         if ($body !== null) {
268
-            $opts[CURLOPT_POSTFIELDS] = $body;
268
+            $opts[CURLOPT_POSTFIELDS]=$body;
269 269
         }
270 270
         curl_setopt_array($curl, $opts);
271
-        $res = curl_exec($curl);
271
+        $res=curl_exec($curl);
272 272
         if ($res === false) {
273
-            throw new Exception('CURL ERROR: ' . curl_error($curl));
273
+            throw new Exception('CURL ERROR: '.curl_error($curl));
274 274
         }
275
-        $statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
275
+        $statusCode=curl_getinfo($curl, CURLINFO_HTTP_CODE);
276 276
         if ($statusCode === 401) {
277 277
             throw new Exception('Unable to authenticate, please check your API credentials');
278 278
         }
@@ -286,7 +286,7 @@  discard block
 block discarded – undo
286 286
      * @return array json decoded
287 287
      */
288 288
     protected function fromJsonResult($json) {
289
-        $result = @json_decode($json);
289
+        $result=@json_decode($json);
290 290
         //var_dump($json);
291 291
         if ($result === null) {
292 292
             throw new Exception('Parsing JSON failed: '.$this->getLastJsonErrorMessage(json_last_error()));
@@ -306,7 +306,7 @@  discard block
 block discarded – undo
306 306
         return $this->errorReference[$errorCode];
307 307
     }
308 308
 
309
-    public function standardQuery(string $urlType , string $filter, array $attributes)
309
+    public function standardQuery(string $urlType, string $filter, array $attributes)
310 310
     {
311 311
         /*
312 312
          *  curl -k -s -u  trapdirector:trapdirector -H 'X-HTTP-Method-Override: GET' -X POST 'https://localhost:5665/v1/objects/hosts' 
@@ -315,7 +315,7 @@  discard block
 block discarded – undo
315 315
          {"results":[{"attrs":{"__name":"Icinga host","address":"127.0.0.1","display_name":"Icinga host","name":"Icinga host"},"joins":{},"meta":{},"name":"Icinga host","type":"Host"}]}
316 316
          */
317 317
         
318
-        if (! isset($this->queryURL[$urlType] ))
318
+        if (!isset($this->queryURL[$urlType]))
319 319
         {
320 320
             throw new Exception("Unkown object type");
321 321
         }
@@ -323,11 +323,11 @@  discard block
 block discarded – undo
323 323
         $body=array();
324 324
         if ($filter !== NULL)
325 325
         {
326
-            $body['filter'] = $filter;
326
+            $body['filter']=$filter;
327 327
         }
328 328
         if (count($attributes) != 0)
329 329
         {
330
-            $body['attrs'] = $attributes;
330
+            $body['attrs']=$attributes;
331 331
         }
332 332
 
333 333
         try
@@ -342,9 +342,9 @@  discard block
 block discarded – undo
342 342
         
343 343
         $numHost=0;
344 344
         $hostArray=array();
345
-        while (isset($result->results[$numHost]) && property_exists ($result->results[$numHost],'attrs'))
345
+        while (isset($result->results[$numHost]) && property_exists($result->results[$numHost], 'attrs'))
346 346
         {
347
-            $hostArray[$numHost] = $result->results[$numHost]->attrs;
347
+            $hostArray[$numHost]=$result->results[$numHost]->attrs;
348 348
             $numHost++;
349 349
         }
350 350
         return $hostArray;
Please login to merge, or discard this patch.
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
 /**
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -17,22 +17,22 @@
 block discarded – undo
17 17
 ));
18 18
 **/
19 19
 
20
-$section = $this->menuSection(N_('Traps'),array (
20
+$section=$this->menuSection(N_('Traps'), array(
21 21
 	'icon'	=> 'filter',
22 22
 	'url'	=> 'trapdirector'
23 23
 ));
24 24
 
25
-$section->add(N_('Status & Mibs'),array(
25
+$section->add(N_('Status & Mibs'), array(
26 26
 	'url'			=> 'trapdirector/status/',
27 27
 	'permission' 	=> 'trapdirector/view'
28 28
 ));
29 29
 
30
-$section->add(N_('Received'),array(
30
+$section->add(N_('Received'), array(
31 31
 	'url'			=> 'trapdirector/received/',
32 32
 	'permission' 	=> 'trapdirector/view'
33 33
 ));
34 34
 
35
-$section->add(N_('Handlers'),array(
35
+$section->add(N_('Handlers'), array(
36 36
 	'url'			=> 'trapdirector/handler/',
37 37
 	'permission' 	=> 'trapdirector/config'
38 38
 ));
Please login to merge, or discard this patch.
library/Trapdirector/TrapsController.php 3 patches
Braces   +15 added lines, -5 removed lines patch added patch discarded remove patch
@@ -131,9 +131,11 @@  discard block
 block discarded – undo
131 131
     	    $this->icingaAPI = new Icinga2API($host,$port);
132 132
     	    $this->icingaAPI->setCredentials($user, $pass);
133 133
     	    list($ret,$message) = $this->icingaAPI->test($this->getModuleConfig()->getapiUserPermissions());
134
-    	    if ($ret === TRUE) // On error, switch to ido DB
134
+    	    if ($ret === TRUE) {
135
+    	    	// On error, switch to ido DB
135 136
     	    {
136 137
     	        $this->apiMode = FALSE;
138
+    	    }
137 139
     	        return $this->getUIDatabase();
138 140
     	    }
139 141
     	    $this->apiMode = TRUE;
@@ -213,7 +215,9 @@  discard block
 block discarded – undo
213 215
 		if ($this->MIBData == null)
214 216
 		{
215 217
 		    $dbConn = $this->getUIDatabase()->getDbConn();
216
-		    if ($dbConn === null) throw new \ErrorException('uncatched db error');
218
+		    if ($dbConn === null) {
219
+		    	throw new \ErrorException('uncatched db error');
220
+		    }
217 221
 			$this->MIBData=new MIBLoader(
218 222
 				$this->Config()->get('config', 'snmptranslate'),
219 223
 				$this->Config()->get('config', 'snmptranslate_dirs'),
@@ -283,7 +287,9 @@  discard block
 block discarded – undo
283 287
 	    $catString='';
284 288
 	    foreach ($catArray as $index => $value)
285 289
 	    {
286
-	        if ($catString != '' ) $catString .= '!';
290
+	        if ($catString != '' ) {
291
+	        	$catString .= '!';
292
+	        }
287 293
 	        $catString .= $index . ':' . $value;
288 294
 	    }
289 295
 	    $this->getUIDatabase()->setDBConfigValue('handler_categories', $catString);
@@ -293,8 +299,12 @@  discard block
 block discarded – undo
293 299
 	{
294 300
 	    $catArray = $this->getHandlersCategory();
295 301
 	    $i=1;
296
-	    while (isset($catArray[$i]) && $i < 100) $i++;
297
-	    if ($i == 100) throw new ProgrammingError('Category array error');
302
+	    while (isset($catArray[$i]) && $i < 100) {
303
+	    	$i++;
304
+	    }
305
+	    if ($i == 100) {
306
+	    	throw new ProgrammingError('Category array error');
307
+	    }
298 308
 	    $catArray[$i] = $catName;
299 309
 	    $this->setHandlerCategory($catArray);
300 310
 	}
Please login to merge, or discard this patch.
Indentation   +110 added lines, -110 removed lines patch added patch discarded remove patch
@@ -49,8 +49,8 @@  discard block
 block discarded – undo
49 49
 	
50 50
 	
51 51
 	/** Get instance of TrapModuleConfig class
52
-	*	@return TrapModuleConfig
53
-	*/
52
+	 *	@return TrapModuleConfig
53
+	 */
54 54
 	public function getModuleConfig() 
55 55
 	{
56 56
 		if ($this->moduleConfig == Null) 
@@ -82,12 +82,12 @@  discard block
 block discarded – undo
82 82
 	 */
83 83
 	public function getTrapHostListTable()
84 84
 	{
85
-	    if ($this->trapTableHostList == Null) 
85
+		if ($this->trapTableHostList == Null) 
86 86
 		{
87
-	        $this->trapTableHostList = new TrapTableHostList();
88
-	        $this->trapTableHostList->setConfig($this->getModuleConfig());
89
-	    }
90
-	    return $this->trapTableHostList;
87
+			$this->trapTableHostList = new TrapTableHostList();
88
+			$this->trapTableHostList->setConfig($this->getModuleConfig());
89
+		}
90
+		return $this->trapTableHostList;
91 91
 	}
92 92
 	
93 93
 	/**
@@ -108,12 +108,12 @@  discard block
 block discarded – undo
108 108
 	 */
109 109
 	public function getUIDatabase()
110 110
 	{
111
-	    if ($this->UIDatabase == Null)
112
-	    {
113
-	        $this->UIDatabase = new UIDatabase($this);
111
+		if ($this->UIDatabase == Null)
112
+		{
113
+			$this->UIDatabase = new UIDatabase($this);
114 114
 	       
115
-	    }
116
-	    return $this->UIDatabase;
115
+		}
116
+		return $this->UIDatabase;
117 117
 	}
118 118
 
119 119
 	/**
@@ -122,41 +122,41 @@  discard block
 block discarded – undo
122 122
 	 */
123 123
 	public function getIdoConn()
124 124
 	{
125
-	    if ($this->icingaAPI === NULL)
126
-	    {
127
-    	    $host = $this->Config()->get('config', 'icingaAPI_host');
128
-    	    if ($host == '')
129
-    	    {
130
-    	        $this->apiMode = FALSE;
131
-    	        return $this->getUIDatabase();
132
-    	    }
133
-    	    $port = $this->Config()->get('config', 'icingaAPI_port');
134
-    	    $user = $this->Config()->get('config', 'icingaAPI_user');
135
-    	    $pass = $this->Config()->get('config', 'icingaAPI_password');
136
-    	    $this->icingaAPI = new Icinga2API($host,$port);
137
-    	    $this->icingaAPI->setCredentials($user, $pass);
138
-    	    list($ret,$message) = $this->icingaAPI->test($this->getModuleConfig()->getapiUserPermissions());
139
-    	    if ($ret === TRUE) // On error, switch to ido DB
140
-    	    {
141
-    	        $this->apiMode = FALSE;
142
-    	        return $this->getUIDatabase();
143
-    	    }
144
-    	    $this->apiMode = TRUE;
125
+		if ($this->icingaAPI === NULL)
126
+		{
127
+			$host = $this->Config()->get('config', 'icingaAPI_host');
128
+			if ($host == '')
129
+			{
130
+				$this->apiMode = FALSE;
131
+				return $this->getUIDatabase();
132
+			}
133
+			$port = $this->Config()->get('config', 'icingaAPI_port');
134
+			$user = $this->Config()->get('config', 'icingaAPI_user');
135
+			$pass = $this->Config()->get('config', 'icingaAPI_password');
136
+			$this->icingaAPI = new Icinga2API($host,$port);
137
+			$this->icingaAPI->setCredentials($user, $pass);
138
+			list($ret,$message) = $this->icingaAPI->test($this->getModuleConfig()->getapiUserPermissions());
139
+			if ($ret === TRUE) // On error, switch to ido DB
140
+			{
141
+				$this->apiMode = FALSE;
142
+				return $this->getUIDatabase();
143
+			}
144
+			$this->apiMode = TRUE;
145 145
     	    
146
-	    }
147
-	    return $this->icingaAPI;
146
+		}
147
+		return $this->icingaAPI;
148 148
 	    
149 149
 	}
150 150
 	
151
-    protected function applyPaginationLimits(Paginatable $paginatable, $limit = 25, $offset = null)
152
-    {
153
-        $limit = $this->params->get('limit', $limit);
154
-        $page = $this->params->get('page', $offset);
151
+	protected function applyPaginationLimits(Paginatable $paginatable, $limit = 25, $offset = null)
152
+	{
153
+		$limit = $this->params->get('limit', $limit);
154
+		$page = $this->params->get('page', $offset);
155 155
 
156
-        $paginatable->limit($limit, $page > 0 ? ($page - 1) * $limit : 0);
156
+		$paginatable->limit($limit, $page > 0 ? ($page - 1) * $limit : 0);
157 157
 
158
-        return $paginatable;
159
-    }	
158
+		return $paginatable;
159
+	}	
160 160
 	
161 161
 	public function displayExitError($source,$message)
162 162
 	{	// TODO : check better ways to transmit data (with POST ?)
@@ -165,33 +165,33 @@  discard block
 block discarded – undo
165 165
 	
166 166
 	protected function checkReadPermission()
167 167
 	{
168
-        if (! $this->Auth()->hasPermission('trapdirector/view')) {
169
-            $this->displayExitError('Permissions','No permission fo view content');
170
-        }		
168
+		if (! $this->Auth()->hasPermission('trapdirector/view')) {
169
+			$this->displayExitError('Permissions','No permission fo view content');
170
+		}		
171 171
 	}
172 172
 
173 173
 	protected function checkConfigPermission()
174 174
 	{
175
-        if (! $this->Auth()->hasPermission('trapdirector/config')) {
176
-            $this->displayExitError('Permissions','No permission fo configure');
177
-        }		
175
+		if (! $this->Auth()->hasPermission('trapdirector/config')) {
176
+			$this->displayExitError('Permissions','No permission fo configure');
177
+		}		
178 178
 	}
179 179
 	
180
-    /**
181
-     * Check if user has write permission
182
-     * @param number $check optional : if set to 1, return true (user has permission) or false instead of displaying error page
183
-     * @return boolean : user has permission
184
-     */
180
+	/**
181
+	 * Check if user has write permission
182
+	 * @param number $check optional : if set to 1, return true (user has permission) or false instead of displaying error page
183
+	 * @return boolean : user has permission
184
+	 */
185 185
 	protected function checkModuleConfigPermission($check=0)
186 186
 	{
187
-        if (! $this->Auth()->hasPermission('trapdirector/module_config')) {
188
-            if ($check == 0)
189
-            {
190
-                $this->displayExitError('Permissions','No permission fo configure module');
191
-            }
192
-            return false;
193
-        }
194
-        return true;
187
+		if (! $this->Auth()->hasPermission('trapdirector/module_config')) {
188
+			if ($check == 0)
189
+			{
190
+				$this->displayExitError('Permissions','No permission fo configure module');
191
+			}
192
+			return false;
193
+		}
194
+		return true;
195 195
 	}
196 196
 
197 197
 	/*************************  Trap class get **********************/
@@ -211,18 +211,18 @@  discard block
 block discarded – undo
211 211
 	/************************** MIB related **************************/
212 212
 	
213 213
 	/** Get MIBLoader class
214
-	*	@return MIBLoader class
215
-	*/
214
+	 *	@return MIBLoader class
215
+	 */
216 216
 	protected function getMIB()
217 217
 	{
218 218
 		if ($this->MIBData == null)
219 219
 		{
220
-		    $dbConn = $this->getUIDatabase()->getDbConn();
221
-		    if ($dbConn === null) throw new \ErrorException('uncatched db error');
220
+			$dbConn = $this->getUIDatabase()->getDbConn();
221
+			if ($dbConn === null) throw new \ErrorException('uncatched db error');
222 222
 			$this->MIBData=new MIBLoader(
223 223
 				$this->Config()->get('config', 'snmptranslate'),
224 224
 				$this->Config()->get('config', 'snmptranslate_dirs'),
225
-			    $dbConn,
225
+				$dbConn,
226 226
 				$this->getModuleConfig()
227 227
 			);
228 228
 		}
@@ -232,13 +232,13 @@  discard block
 block discarded – undo
232 232
 	/**************************  Database queries *******************/		
233 233
 	
234 234
 	/** Check if director is installed
235
-	*	@return bool true/false
236
-	*/
235
+	 *	@return bool true/false
236
+	 */
237 237
 	protected function isDirectorInstalled()
238 238
 	{
239
-	    $output=array();
240
-	    exec('icingacli module list',$output);
241
-	    foreach ($output as $line)
239
+		$output=array();
240
+		exec('icingacli module list',$output);
241
+		foreach ($output as $line)
242 242
 		{
243 243
 			if (preg_match('/^director .*enabled/',$line))
244 244
 			{
@@ -251,72 +251,72 @@  discard block
 block discarded – undo
251 251
 
252 252
 	/************************ UI elements **************************/
253 253
 	
254
-    /**
255
-     * get max rows to display before paging.
256
-     * @return number
257
-     */
254
+	/**
255
+	 * get max rows to display before paging.
256
+	 * @return number
257
+	 */
258 258
 	public function itemListDisplay()
259 259
 	{
260
-	    return $this->getUIDatabase()->getDBConfigValue('max_rows_in_list');
260
+		return $this->getUIDatabase()->getDBConfigValue('max_rows_in_list');
261 261
 	}
262 262
 
263 263
 	public function setitemListDisplay(int $maxRows)
264 264
 	{
265
-	    return $this->getUIDatabase()->setDBConfigValue('max_rows_in_list',$maxRows);
265
+		return $this->getUIDatabase()->setDBConfigValue('max_rows_in_list',$maxRows);
266 266
 	}
267 267
 	
268
-    /**
269
-     * get Handlers categories list (index => textvalue).
270
-     * @return array
271
-     */	
268
+	/**
269
+	 * get Handlers categories list (index => textvalue).
270
+	 * @return array
271
+	 */	
272 272
 	public function getHandlersCategory()
273 273
 	{
274
-	    //<index>:<name>!<index>:<name>
275
-	    $catList = $this->getUIDatabase()->getDBConfigValue('handler_categories');
276
-	    $catListArray=explode('!',$catList);
277
-	    $retArray=array();
278
-	    foreach ($catListArray as $category)
279
-	    {
280
-	        $catArray=explode(':',$category);
281
-	        $retArray[$catArray[0]] = $catArray[1];
282
-	    }
283
-	    return $retArray; 
274
+		//<index>:<name>!<index>:<name>
275
+		$catList = $this->getUIDatabase()->getDBConfigValue('handler_categories');
276
+		$catListArray=explode('!',$catList);
277
+		$retArray=array();
278
+		foreach ($catListArray as $category)
279
+		{
280
+			$catArray=explode(':',$category);
281
+			$retArray[$catArray[0]] = $catArray[1];
282
+		}
283
+		return $retArray; 
284 284
 	}
285 285
 
286 286
 	public function setHandlerCategory(array $catArray)
287 287
 	{
288
-	    $catString='';
289
-	    foreach ($catArray as $index => $value)
290
-	    {
291
-	        if ($catString != '' ) $catString .= '!';
292
-	        $catString .= $index . ':' . $value;
293
-	    }
294
-	    $this->getUIDatabase()->setDBConfigValue('handler_categories', $catString);
288
+		$catString='';
289
+		foreach ($catArray as $index => $value)
290
+		{
291
+			if ($catString != '' ) $catString .= '!';
292
+			$catString .= $index . ':' . $value;
293
+		}
294
+		$this->getUIDatabase()->setDBConfigValue('handler_categories', $catString);
295 295
 	}
296 296
 	
297 297
 	public function addHandlersCategory(string $catName)
298 298
 	{
299
-	    $catArray = $this->getHandlersCategory();
300
-	    $i=1;
301
-	    while (isset($catArray[$i]) && $i < 100) $i++;
302
-	    if ($i == 100) throw new ProgrammingError('Category array error');
303
-	    $catArray[$i] = $catName;
304
-	    $this->setHandlerCategory($catArray);
299
+		$catArray = $this->getHandlersCategory();
300
+		$i=1;
301
+		while (isset($catArray[$i]) && $i < 100) $i++;
302
+		if ($i == 100) throw new ProgrammingError('Category array error');
303
+		$catArray[$i] = $catName;
304
+		$this->setHandlerCategory($catArray);
305 305
 	}
306 306
 	
307 307
 	public function delHandlersCategory(int $catIndex)
308 308
 	{
309
-	    $catArray = $this->getHandlersCategory();
310
-	    unset($catArray[$catIndex]);
311
-	    $this->setHandlerCategory($catArray);
312
-	    $this->getUIDatabase()->updateHandlersOnCategoryDelete($catIndex);
309
+		$catArray = $this->getHandlersCategory();
310
+		unset($catArray[$catIndex]);
311
+		$this->setHandlerCategory($catArray);
312
+		$this->getUIDatabase()->updateHandlersOnCategoryDelete($catIndex);
313 313
 	}
314 314
 	
315 315
 	public function renameHandlersCategory(int $catIndex, string $catName)
316 316
 	{
317
-	    $catArray = $this->getHandlersCategory();
318
-	    $catArray[$catIndex] = $catName;
319
-	    $this->setHandlerCategory($catArray);
317
+		$catArray = $this->getHandlersCategory();
318
+		$catArray[$catIndex] = $catName;
319
+		$this->setHandlerCategory($catArray);
320 320
 	}
321 321
 	
322 322
 }
Please login to merge, or discard this patch.
Spacing   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -39,11 +39,11 @@  discard block
 block discarded – undo
39 39
 	/** @var Trap $trapClass Trap class for bin/trap_class.php */
40 40
 	protected $trapClass;
41 41
 	/** @var UIDatabase $UIDatabase */
42
-	protected $UIDatabase = NULL;
42
+	protected $UIDatabase=NULL;
43 43
 	/** @var Icinga2API $IcingaAPI */
44
-	protected $icingaAPI = NULL;
44
+	protected $icingaAPI=NULL;
45 45
 	/** @var bool $apiMode connection to icinngaDB is by api (true) od ido DB (false) */
46
-	protected $apiMode = FALSE;
46
+	protected $apiMode=FALSE;
47 47
 	
48 48
 	
49 49
 	
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
 			{
61 61
 				$this->redirectNow('trapdirector/settings?message=No database prefix');
62 62
 			}
63
-			$this->moduleConfig = new TrapModuleConfig($db_prefix);
63
+			$this->moduleConfig=new TrapModuleConfig($db_prefix);
64 64
 		}
65 65
 		return $this->moduleConfig;
66 66
 	}
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
 	 */
72 72
 	public function getTrapListTable() {
73 73
 		if ($this->trapTableList == Null) {
74
-			$this->trapTableList = new TrapTableList();
74
+			$this->trapTableList=new TrapTableList();
75 75
 			$this->trapTableList->setConfig($this->getModuleConfig());
76 76
 		}
77 77
 		return $this->trapTableList;
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
 	{
85 85
 	    if ($this->trapTableHostList == Null) 
86 86
 		{
87
-	        $this->trapTableHostList = new TrapTableHostList();
87
+	        $this->trapTableHostList=new TrapTableHostList();
88 88
 	        $this->trapTableHostList->setConfig($this->getModuleConfig());
89 89
 	    }
90 90
 	    return $this->trapTableHostList;
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
 	{
98 98
 		if ($this->handlerTableList == Null) 
99 99
 		{
100
-			$this->handlerTableList = new HandlerTableList();
100
+			$this->handlerTableList=new HandlerTableList();
101 101
 			$this->handlerTableList->setConfig($this->getModuleConfig());
102 102
 		}
103 103
 		return $this->handlerTableList;
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
 	{
111 111
 	    if ($this->UIDatabase == Null)
112 112
 	    {
113
-	        $this->UIDatabase = new UIDatabase($this);
113
+	        $this->UIDatabase=new UIDatabase($this);
114 114
 	       
115 115
 	    }
116 116
 	    return $this->UIDatabase;
@@ -124,56 +124,56 @@  discard block
 block discarded – undo
124 124
 	{
125 125
 	    if ($this->icingaAPI === NULL)
126 126
 	    {
127
-    	    $host = $this->Config()->get('config', 'icingaAPI_host');
127
+    	    $host=$this->Config()->get('config', 'icingaAPI_host');
128 128
     	    if ($host == '')
129 129
     	    {
130
-    	        $this->apiMode = FALSE;
130
+    	        $this->apiMode=FALSE;
131 131
     	        return $this->getUIDatabase();
132 132
     	    }
133
-    	    $port = $this->Config()->get('config', 'icingaAPI_port');
134
-    	    $user = $this->Config()->get('config', 'icingaAPI_user');
135
-    	    $pass = $this->Config()->get('config', 'icingaAPI_password');
136
-    	    $this->icingaAPI = new Icinga2API($host,$port);
133
+    	    $port=$this->Config()->get('config', 'icingaAPI_port');
134
+    	    $user=$this->Config()->get('config', 'icingaAPI_user');
135
+    	    $pass=$this->Config()->get('config', 'icingaAPI_password');
136
+    	    $this->icingaAPI=new Icinga2API($host, $port);
137 137
     	    $this->icingaAPI->setCredentials($user, $pass);
138
-    	    list($ret,$message) = $this->icingaAPI->test($this->getModuleConfig()->getapiUserPermissions());
138
+    	    list($ret, $message)=$this->icingaAPI->test($this->getModuleConfig()->getapiUserPermissions());
139 139
     	    if ($ret === TRUE) // On error, switch to ido DB
140 140
     	    {
141
-    	        $this->apiMode = FALSE;
141
+    	        $this->apiMode=FALSE;
142 142
     	        return $this->getUIDatabase();
143 143
     	    }
144
-    	    $this->apiMode = TRUE;
144
+    	    $this->apiMode=TRUE;
145 145
     	    
146 146
 	    }
147 147
 	    return $this->icingaAPI;
148 148
 	    
149 149
 	}
150 150
 	
151
-    protected function applyPaginationLimits(Paginatable $paginatable, $limit = 25, $offset = null)
151
+    protected function applyPaginationLimits(Paginatable $paginatable, $limit=25, $offset=null)
152 152
     {
153
-        $limit = $this->params->get('limit', $limit);
154
-        $page = $this->params->get('page', $offset);
153
+        $limit=$this->params->get('limit', $limit);
154
+        $page=$this->params->get('page', $offset);
155 155
 
156 156
         $paginatable->limit($limit, $page > 0 ? ($page - 1) * $limit : 0);
157 157
 
158 158
         return $paginatable;
159 159
     }	
160 160
 	
161
-	public function displayExitError($source,$message)
161
+	public function displayExitError($source, $message)
162 162
 	{	// TODO : check better ways to transmit data (with POST ?)
163 163
 		$this->redirectNow('trapdirector/error?source='.$source.'&message='.$message);
164 164
 	}
165 165
 	
166 166
 	protected function checkReadPermission()
167 167
 	{
168
-        if (! $this->Auth()->hasPermission('trapdirector/view')) {
169
-            $this->displayExitError('Permissions','No permission fo view content');
168
+        if (!$this->Auth()->hasPermission('trapdirector/view')) {
169
+            $this->displayExitError('Permissions', 'No permission fo view content');
170 170
         }		
171 171
 	}
172 172
 
173 173
 	protected function checkConfigPermission()
174 174
 	{
175
-        if (! $this->Auth()->hasPermission('trapdirector/config')) {
176
-            $this->displayExitError('Permissions','No permission fo configure');
175
+        if (!$this->Auth()->hasPermission('trapdirector/config')) {
176
+            $this->displayExitError('Permissions', 'No permission fo configure');
177 177
         }		
178 178
 	}
179 179
 	
@@ -184,10 +184,10 @@  discard block
 block discarded – undo
184 184
      */
185 185
 	protected function checkModuleConfigPermission($check=0)
186 186
 	{
187
-        if (! $this->Auth()->hasPermission('trapdirector/module_config')) {
187
+        if (!$this->Auth()->hasPermission('trapdirector/module_config')) {
188 188
             if ($check == 0)
189 189
             {
190
-                $this->displayExitError('Permissions','No permission fo configure module');
190
+                $this->displayExitError('Permissions', 'No permission fo configure module');
191 191
             }
192 192
             return false;
193 193
         }
@@ -199,10 +199,10 @@  discard block
 block discarded – undo
199 199
 	{ // TODO : try/catch here ? or within caller
200 200
 		if ($this->trapClass == null)
201 201
 		{
202
-			require_once($this->Module()->getBaseDir() .'/bin/trap_class.php');
202
+			require_once($this->Module()->getBaseDir().'/bin/trap_class.php');
203 203
 			$icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc');
204 204
 			//$debug_level=4;
205
-			$this->trapClass = new Trap($icingaweb2_etc);
205
+			$this->trapClass=new Trap($icingaweb2_etc);
206 206
 			//$Trap->setLogging($debug_level,'syslog');
207 207
 		}
208 208
 		return $this->trapClass;
@@ -217,7 +217,7 @@  discard block
 block discarded – undo
217 217
 	{
218 218
 		if ($this->MIBData == null)
219 219
 		{
220
-		    $dbConn = $this->getUIDatabase()->getDbConn();
220
+		    $dbConn=$this->getUIDatabase()->getDbConn();
221 221
 		    if ($dbConn === null) throw new \ErrorException('uncatched db error');
222 222
 			$this->MIBData=new MIBLoader(
223 223
 				$this->Config()->get('config', 'snmptranslate'),
@@ -237,10 +237,10 @@  discard block
 block discarded – undo
237 237
 	protected function isDirectorInstalled()
238 238
 	{
239 239
 	    $output=array();
240
-	    exec('icingacli module list',$output);
240
+	    exec('icingacli module list', $output);
241 241
 	    foreach ($output as $line)
242 242
 		{
243
-			if (preg_match('/^director .*enabled/',$line))
243
+			if (preg_match('/^director .*enabled/', $line))
244 244
 			{
245 245
 				return true;
246 246
 			}
@@ -262,7 +262,7 @@  discard block
 block discarded – undo
262 262
 
263 263
 	public function setitemListDisplay(int $maxRows)
264 264
 	{
265
-	    return $this->getUIDatabase()->setDBConfigValue('max_rows_in_list',$maxRows);
265
+	    return $this->getUIDatabase()->setDBConfigValue('max_rows_in_list', $maxRows);
266 266
 	}
267 267
 	
268 268
     /**
@@ -272,13 +272,13 @@  discard block
 block discarded – undo
272 272
 	public function getHandlersCategory()
273 273
 	{
274 274
 	    //<index>:<name>!<index>:<name>
275
-	    $catList = $this->getUIDatabase()->getDBConfigValue('handler_categories');
276
-	    $catListArray=explode('!',$catList);
275
+	    $catList=$this->getUIDatabase()->getDBConfigValue('handler_categories');
276
+	    $catListArray=explode('!', $catList);
277 277
 	    $retArray=array();
278 278
 	    foreach ($catListArray as $category)
279 279
 	    {
280
-	        $catArray=explode(':',$category);
281
-	        $retArray[$catArray[0]] = $catArray[1];
280
+	        $catArray=explode(':', $category);
281
+	        $retArray[$catArray[0]]=$catArray[1];
282 282
 	    }
283 283
 	    return $retArray; 
284 284
 	}
@@ -288,25 +288,25 @@  discard block
 block discarded – undo
288 288
 	    $catString='';
289 289
 	    foreach ($catArray as $index => $value)
290 290
 	    {
291
-	        if ($catString != '' ) $catString .= '!';
292
-	        $catString .= $index . ':' . $value;
291
+	        if ($catString != '') $catString.='!';
292
+	        $catString.=$index.':'.$value;
293 293
 	    }
294 294
 	    $this->getUIDatabase()->setDBConfigValue('handler_categories', $catString);
295 295
 	}
296 296
 	
297 297
 	public function addHandlersCategory(string $catName)
298 298
 	{
299
-	    $catArray = $this->getHandlersCategory();
299
+	    $catArray=$this->getHandlersCategory();
300 300
 	    $i=1;
301 301
 	    while (isset($catArray[$i]) && $i < 100) $i++;
302 302
 	    if ($i == 100) throw new ProgrammingError('Category array error');
303
-	    $catArray[$i] = $catName;
303
+	    $catArray[$i]=$catName;
304 304
 	    $this->setHandlerCategory($catArray);
305 305
 	}
306 306
 	
307 307
 	public function delHandlersCategory(int $catIndex)
308 308
 	{
309
-	    $catArray = $this->getHandlersCategory();
309
+	    $catArray=$this->getHandlersCategory();
310 310
 	    unset($catArray[$catIndex]);
311 311
 	    $this->setHandlerCategory($catArray);
312 312
 	    $this->getUIDatabase()->updateHandlersOnCategoryDelete($catIndex);
@@ -314,8 +314,8 @@  discard block
 block discarded – undo
314 314
 	
315 315
 	public function renameHandlersCategory(int $catIndex, string $catName)
316 316
 	{
317
-	    $catArray = $this->getHandlersCategory();
318
-	    $catArray[$catIndex] = $catName;
317
+	    $catArray=$this->getHandlersCategory();
318
+	    $catArray[$catIndex]=$catName;
319 319
 	    $this->setHandlerCategory($catArray);
320 320
 	}
321 321
 	
Please login to merge, or discard this patch.
application/controllers/HandlerController.php 3 patches
Spacing   +91 added lines, -91 removed lines patch added patch discarded remove patch
@@ -24,10 +24,10 @@  discard block
 block discarded – undo
24 24
 		$this->checkReadPermission();
25 25
 		$this->prepareTabs()->activate('status');
26 26
 
27
-		$dbConn = $this->getUIDatabase()->getDb();
27
+		$dbConn=$this->getUIDatabase()->getDb();
28 28
 		if ($dbConn === null) throw new \ErrorException('uncatched db error');
29 29
 		
30
-		$handlerTable = new HandlerTable(
30
+		$handlerTable=new HandlerTable(
31 31
 		      $this->moduleConfig->getTrapRuleName(),
32 32
 		      $this->moduleConfig->getHandlerListTitles(),
33 33
 		      $this->moduleConfig->getHandlerListDisplayColumns(),
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
 		
41 41
 		$handlerTable->setMibloader($this->getMIB());
42 42
 		
43
-		$getVars = $this->getRequest()->getParams();
43
+		$getVars=$this->getRequest()->getParams();
44 44
 		$handlerTable->getParams($getVars);
45 45
 		
46 46
 		if ($handlerTable->isOrderSet() == FALSE)
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
 		
52 52
 		}
53 53
 		
54
-		$this->view->handlerTable = $handlerTable;
54
+		$this->view->handlerTable=$handlerTable;
55 55
 		
56 56
 		
57 57
 		// TODO : Obsolete remove after new table validation.
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
 	public function testruleAction()
75 75
 	{
76 76
 	    $this->checkReadPermission();
77
-	    $this->getTabs()->add('get',array(
77
+	    $this->getTabs()->add('get', array(
78 78
 	        'active'	=> true,
79 79
 	        'label'		=> $this->translate('Test Rule'),
80 80
 	        'url'		=> Url::fromRequest()
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
 
84 84
 	    if ($this->params->get('rule') !== null) 
85 85
 	    {
86
-	        $this->view->rule= $this->params->get('rule');
86
+	        $this->view->rule=$this->params->get('rule');
87 87
 	    }
88 88
 	    else
89 89
 	    {
@@ -142,12 +142,12 @@  discard block
 block discarded – undo
142 142
 	    }
143 143
 	    catch (Exception $e)
144 144
 	    {
145
-	        $this->displayExitError('Add handler : get host by IP/Name ',$e->getMessage());
145
+	        $this->displayExitError('Add handler : get host by IP/Name ', $e->getMessage());
146 146
 	    }
147 147
 	    
148 148
 	    
149 149
 	    // if one unique host found -> put id text input
150
-	    if (count($hosts)==1) {
150
+	    if (count($hosts) == 1) {
151 151
 	        $this->view->hostname=$hosts[0]->name;
152 152
 	        //$hostid=$hosts[0]->id;
153 153
 	        // Tell JS to get services when page is loaded
@@ -156,9 +156,9 @@  discard block
 block discarded – undo
156 156
 	    }
157 157
 	    else
158 158
 	    {
159
-	        foreach($hosts as $key=>$val)
159
+	        foreach ($hosts as $key=>$val)
160 160
 	        {
161
-	            array_push($this->view->hostlist,$hosts[$key]->name);
161
+	            array_push($this->view->hostlist, $hosts[$key]->name);
162 162
 	        }
163 163
 	    }
164 164
 	    
@@ -197,18 +197,18 @@  discard block
 block discarded – undo
197 197
 	            $currentObjectTypeEnum
198 198
 	        );
199 199
 	        $oid_index++;
200
-	        array_push($this->view->objectList,$currentObject);
200
+	        array_push($this->view->objectList, $currentObject);
201 201
 	        // set currrent object to null in allObjects
202 202
 	        if (isset($allObjects[$val->oid]))
203 203
 	        {
204 204
 	            $allObjects[$val->oid]=null;
205 205
 	        }
206 206
 	    }
207
-	    if ($allObjects!=null) // in case trap doesn't have objects or is not resolved
207
+	    if ($allObjects != null) // in case trap doesn't have objects or is not resolved
208 208
 	    {
209 209
 	        foreach ($allObjects as $key => $val)
210 210
 	        {
211
-	            if ($val==null) { continue; }
211
+	            if ($val == null) { continue; }
212 212
 	            array_push($this->view->objectList, array(
213 213
 	                $oid_index,
214 214
 	                $key,
@@ -236,9 +236,9 @@  discard block
 block discarded – undo
236 236
 	    // Check if hostname still exists
237 237
 	    $host_get=$this->getIdoConn()->getHostByName($this->view->hostname);
238 238
 	    
239
-	    if (count($host_get)==0)
239
+	    if (count($host_get) == 0)
240 240
 	    {
241
-	        $this->view->warning_message='Host '.$this->view->hostname. ' doesn\'t exists anymore';
241
+	        $this->view->warning_message='Host '.$this->view->hostname.' doesn\'t exists anymore';
242 242
 	        $this->view->serviceGet=false;
243 243
 	    }
244 244
 	    else
@@ -246,10 +246,10 @@  discard block
 block discarded – undo
246 246
 	        // Tell JS to get services when page is loaded
247 247
 	        $this->view->serviceGet=true;
248 248
 	        // get service id for form to set :
249
-	        $serviceID=$this->getIdoConn()->getServiceIDByName($this->view->hostname,$ruleDetail->service_name);
250
-	        if (count($serviceID) ==0)
249
+	        $serviceID=$this->getIdoConn()->getServiceIDByName($this->view->hostname, $ruleDetail->service_name);
250
+	        if (count($serviceID) == 0)
251 251
 	        {
252
-	            $this->view->warning_message=' Service '.$ruleDetail->service_name. ' doesn\'t exists anymore';
252
+	            $this->view->warning_message=' Service '.$ruleDetail->service_name.' doesn\'t exists anymore';
253 253
 	        }
254 254
 	        else
255 255
 	        {
@@ -266,9 +266,9 @@  discard block
 block discarded – undo
266 266
 	{
267 267
 	    // Check if groupe exists
268 268
 	    $group_get=$this->getIdoConn()->getHostGroupByName($this->view->hostgroupname);
269
-	    if (count($group_get)==0)
269
+	    if (count($group_get) == 0)
270 270
 	    {
271
-	        $this->view->warning_message='HostGroup '.$this->view->hostgroupname. ' doesn\'t exists anymore';
271
+	        $this->view->warning_message='HostGroup '.$this->view->hostgroupname.' doesn\'t exists anymore';
272 272
 	        $this->view->serviceGroupGet=false;
273 273
 	    }
274 274
 	    else
@@ -286,9 +286,9 @@  discard block
 block discarded – undo
286 286
 	        
287 287
 	        // Tell JS to get services when page is loaded
288 288
 	        $this->view->serviceGroupGet=true;
289
-	        if ($foundGrpService==0)
289
+	        if ($foundGrpService == 0)
290 290
 	        {
291
-	            $this->view->warning_message.=' Service '.$ruleDetail->service_name. ' doesn\'t exists anymore';
291
+	            $this->view->warning_message.=' Service '.$ruleDetail->service_name.' doesn\'t exists anymore';
292 292
 	        }
293 293
 	    }
294 294
 	}
@@ -306,12 +306,12 @@  discard block
 block discarded – undo
306 306
 	    $index=1;
307 307
 	    // check in display & rule for : OID(<oid>)
308 308
 	    $matches=array();
309
-	    while ( preg_match('/_OID\(([\.0-9\*]+)\)/',$display,$matches) ||
310
-	        preg_match('/_OID\(([\.0-9\*]+)\)/',$rule,$matches))
309
+	    while (preg_match('/_OID\(([\.0-9\*]+)\)/', $display, $matches) ||
310
+	        preg_match('/_OID\(([\.0-9\*]+)\)/', $rule, $matches))
311 311
 	    {
312 312
 	        $curOid=$matches[1];
313 313
 	        
314
-	        if ( (preg_match('/\*/',$curOid) == 0 ) 
314
+	        if ((preg_match('/\*/', $curOid) == 0) 
315 315
 	            && ($object=$this->getMIB()->translateOID($curOid)) != null)
316 316
 	        {
317 317
 	            array_push($curObjectList, array(
@@ -336,9 +336,9 @@  discard block
 block discarded – undo
336 336
 	                'not found'
337 337
 	            ));
338 338
 	        }
339
-	        $curOid = preg_replace('/\*/','\*',$curOid);
340
-	        $display=preg_replace('/_OID\('.$curOid.'\)/','\$'.$index.'\$',$display);
341
-	        $rule=preg_replace('/_OID\('.$curOid.'\)/','\$'.$index.'\$',$rule);
339
+	        $curOid=preg_replace('/\*/', '\*', $curOid);
340
+	        $display=preg_replace('/_OID\('.$curOid.'\)/', '\$'.$index.'\$', $display);
341
+	        $rule=preg_replace('/_OID\('.$curOid.'\)/', '\$'.$index.'\$', $rule);
342 342
 	        $index++;
343 343
 	    }
344 344
 	    return $curObjectList;
@@ -353,7 +353,7 @@  discard block
 block discarded – undo
353 353
 		$this->checkConfigPermission();
354 354
 		// set up tab
355 355
 		$this->prepareTabs();
356
-		$this->getTabs()->add('get',array(
356
+		$this->getTabs()->add('get', array(
357 357
 			'active'	=> true,
358 358
 			'label'		=> $this->translate('Add handler'),
359 359
 			'url'		=> Url::fromRequest()
@@ -365,11 +365,11 @@  discard block
 block discarded – undo
365 365
 		$this->view->mibList=$this->getMIB()->getMIBList();
366 366
 		
367 367
 		// Get categories
368
-		$this->view->categoryList = $this->getHandlersCategory();
368
+		$this->view->categoryList=$this->getHandlersCategory();
369 369
 		
370 370
 		//$this->view->trapvalues=false; // Set to true to display 'value' colum in objects
371 371
 		
372
-		if (($trapid = $this->params->get('fromid')) !== null) {
372
+		if (($trapid=$this->params->get('fromid')) !== null) {
373 373
 		    /********** Setup from existing trap ***************/
374 374
             $this->add_from_existing($trapid);
375 375
 			return;
@@ -389,11 +389,11 @@  discard block
 block discarded – undo
389 389
 			$this->view->setRuleMatch=$ruleDetail->action_match;
390 390
 			$this->view->setRuleNoMatch=$ruleDetail->action_nomatch;
391 391
 			$this->view->hostgroupname=$ruleDetail->host_group_name;
392
-			$this->view->modified=gmdate("Y-m-d\TH:i:s\Z",$ruleDetail->modified);
392
+			$this->view->modified=gmdate("Y-m-d\TH:i:s\Z", $ruleDetail->modified);
393 393
 			$this->view->modifier=$ruleDetail->modifier;
394 394
 			
395
-			$this->view->comment = $ruleDetail->comment;
396
-			$this->view->category = $ruleDetail->category;
395
+			$this->view->comment=$ruleDetail->comment;
396
+			$this->view->category=$ruleDetail->category;
397 397
 			
398 398
 			// Warning message if host/service don't exists anymore
399 399
 			$this->view->warning_message='';
@@ -444,28 +444,28 @@  discard block
 block discarded – undo
444 444
 	
445 445
 		$params=array(
446 446
 			// id (also db) => 	array('post' => post id, 'val' => default val, 'db' => send to table)
447
-			'hostgroup'		=>	array('post' => 'hostgroup',                    'db'=>false),
448
-			'db_rule'		=>	array('post' => 'db_rule',                      'db'=>false),
449
-			'hostid'		=>	array('post' => 'hostid',                       'db'=>false),
450
-			'host_name'		=>	array('post' => 'hostname',      'val' => null,  'db'=>true),
451
-			'host_group_name'=>	array('post' => null,            'val' => null,  'db'=>true),
452
-			'serviceid'		=>	array('post' => 'serviceid',                     'db'=>false),
453
-			'service_name'	=>	array('post' => 'serviceName',                    'db'=>true),
454
-		    'comment'       =>  array('post' => 'comment',       'val' => '',    'db'=>true),
455
-		    'rule_type'     =>  array('post' => 'category',       'val' => 0,    'db'=>true),
456
-			'trap_oid'		=>	array('post' => 'oid',                            'db'=>true),
457
-			'revert_ok'		=>	array('post' => 'revertOK',      'val' => 0,      'db'=>true),
458
-			'display'		=>	array('post' => 'display',        'val' => '',     'db'=>true),
459
-			'rule'			=>	array('post' => 'rule',          'val' => '',        'db'=>true),			
460
-			'action_match'	=>	array('post' => 'ruleMatch',       'val' => -1,    'db'=>true),
461
-			'action_nomatch'=>	array('post' => 'ruleNoMatch',    'val' => -1,    'db'=>true),					
462
-			'ip4'			=>	array('post' => null,             'val' => null,  'db'=>true),
463
-			'ip6'			=>	array('post' => null,             'val' => null,  'db'=>true),
464
-		    'action_form'	=>	array('post' => 'action_form',    'val' => null, 'db'=>false)
447
+			'hostgroup'		=>	array('post' => 'hostgroup', 'db'=>false),
448
+			'db_rule'		=>	array('post' => 'db_rule', 'db'=>false),
449
+			'hostid'		=>	array('post' => 'hostid', 'db'=>false),
450
+			'host_name'		=>	array('post' => 'hostname', 'val' => null, 'db'=>true),
451
+			'host_group_name'=>	array('post' => null, 'val' => null, 'db'=>true),
452
+			'serviceid'		=>	array('post' => 'serviceid', 'db'=>false),
453
+			'service_name'	=>	array('post' => 'serviceName', 'db'=>true),
454
+		    'comment'       =>  array('post' => 'comment', 'val' => '', 'db'=>true),
455
+		    'rule_type'     =>  array('post' => 'category', 'val' => 0, 'db'=>true),
456
+			'trap_oid'		=>	array('post' => 'oid', 'db'=>true),
457
+			'revert_ok'		=>	array('post' => 'revertOK', 'val' => 0, 'db'=>true),
458
+			'display'		=>	array('post' => 'display', 'val' => '', 'db'=>true),
459
+			'rule'			=>	array('post' => 'rule', 'val' => '', 'db'=>true),			
460
+			'action_match'	=>	array('post' => 'ruleMatch', 'val' => -1, 'db'=>true),
461
+			'action_nomatch'=>	array('post' => 'ruleNoMatch', 'val' => -1, 'db'=>true),					
462
+			'ip4'			=>	array('post' => null, 'val' => null, 'db'=>true),
463
+			'ip6'			=>	array('post' => null, 'val' => null, 'db'=>true),
464
+		    'action_form'	=>	array('post' => 'action_form', 'val' => null, 'db'=>false)
465 465
 		);
466 466
 		
467 467
 		if (isset($postData[$params['action_form']['post']]) 
468
-			&& $postData[$params['action_form']['post']] == 'delete' )
468
+			&& $postData[$params['action_form']['post']] == 'delete')
469 469
 		{
470 470
 			try
471 471
 			{
@@ -473,7 +473,7 @@  discard block
 block discarded – undo
473 473
 			}
474 474
 			catch (Exception $e)
475 475
 			{
476
-				$this->_helper->json(array('status'=>$e->getMessage(),'location'=>'Deleting Rule'));
476
+				$this->_helper->json(array('status'=>$e->getMessage(), 'location'=>'Deleting Rule'));
477 477
 				return;
478 478
 			}
479 479
 			//$this->Module()->
@@ -485,16 +485,16 @@  discard block
 block discarded – undo
485 485
 		}		
486 486
 		foreach (array_keys($params) as $key)
487 487
 		{
488
-			if ($params[$key]['post']==null) continue; // data not sent in post vars
489
-			if (! isset($postData[$params[$key]['post']]))
488
+			if ($params[$key]['post'] == null) continue; // data not sent in post vars
489
+			if (!isset($postData[$params[$key]['post']]))
490 490
 			{
491 491
 				// should not happen as the js checks data
492
-				$this->_helper->json(array('status'=>'No ' . $key));
492
+				$this->_helper->json(array('status'=>'No '.$key));
493 493
 			}
494 494
 			else
495 495
 			{
496 496
 				$data=$postData[$params[$key]['post']];
497
-				if ($data!=null && $data !="")
497
+				if ($data != null && $data != "")
498 498
 				{
499 499
 					$params[$key]['val']=$postData[$params[$key]['post']];
500 500
 				}
@@ -503,8 +503,8 @@  discard block
 block discarded – undo
503 503
 		$this->getIdoConn(); //Set apiMode
504 504
 		try 
505 505
 		{
506
-			$isHostGroup=($params['hostgroup']['val'] == 1)?true:false;
507
-			if (! $isHostGroup ) 
506
+			$isHostGroup=($params['hostgroup']['val'] == 1) ?true:false;
507
+			if (!$isHostGroup) 
508 508
 			{  // checks if selection by host 
509 509
 			    $hostAddr=$this->getIdoConn()->getHostInfoByID($params['hostid']['val']);
510 510
 			    if ($hostAddr === NULL) throw new \Exception("No object found");
@@ -519,9 +519,9 @@  discard block
 block discarded – undo
519 519
 				if ($this->apiMode == TRUE)
520 520
 				{
521 521
 				    $serviceName=$this->getIdoConn()->getServiceById($params['serviceid']['val']);
522
-				    if (count($serviceName) == 0 )
522
+				    if (count($serviceName) == 0)
523 523
 				    {
524
-				        $this->_helper->json(array('status'=>"Invalid service id : Please re enter service",'sent'=>$params['serviceid']['val'],'found'=>$serviceName[0]->__name));
524
+				        $this->_helper->json(array('status'=>"Invalid service id : Please re enter service", 'sent'=>$params['serviceid']['val'], 'found'=>$serviceName[0]->__name));
525 525
 				        return;
526 526
 				    }
527 527
 				}
@@ -529,7 +529,7 @@  discard block
 block discarded – undo
529 529
 				{
530 530
     				if (!is_numeric($params['serviceid']['val']))
531 531
     				{
532
-    				    $this->_helper->json(array('status'=>"Invalid service id ". $params['serviceid']['val']));
532
+    				    $this->_helper->json(array('status'=>"Invalid service id ".$params['serviceid']['val']));
533 533
     				    return;
534 534
     				}
535 535
     				
@@ -562,15 +562,15 @@  discard block
 block discarded – undo
562 562
     				}
563 563
 			    }
564 564
 				// Put param in correct column (group_name)
565
-				$params['host_group_name']['val'] = $params['host_name']['val'];
565
+				$params['host_group_name']['val']=$params['host_name']['val'];
566 566
 				$params['host_name']['val']=null;
567 567
 			}
568 568
 			$dbparams=array();
569 569
 			foreach ($params as $key=>$val)
570 570
 			{
571
-				if ($val['db']==true )
571
+				if ($val['db'] == true)
572 572
 				{
573
-					$dbparams[$key] = $val['val'];
573
+					$dbparams[$key]=$val['val'];
574 574
 				}
575 575
 			}
576 576
 			// echo '<br>';	print_r($dbparams);echo '<br>';
@@ -581,13 +581,13 @@  discard block
 block discarded – undo
581 581
 			}
582 582
 			else
583 583
 			{
584
-			    $this->getUIDatabase()->updateHandlerRule($dbparams,$params['db_rule']['val']);
584
+			    $this->getUIDatabase()->updateHandlerRule($dbparams, $params['db_rule']['val']);
585 585
 				$ruleID=$params['db_rule']['val'];
586 586
 			}
587 587
 		}
588 588
 		catch (Exception $e)
589 589
 		{
590
-		    $this->_helper->json(array('status'=>$e->getMessage(),'location'=>'Add/update Rule','line'=>$e->getLine(),'file'=>$e->getFile()));
590
+		    $this->_helper->json(array('status'=>$e->getMessage(), 'location'=>'Add/update Rule', 'line'=>$e->getLine(), 'file'=>$e->getFile()));
591 591
 			return;
592 592
 		}
593 593
 		$this->_helper->json(array('status'=>'OK', 'id' => $ruleID));
@@ -600,10 +600,10 @@  discard block
 block discarded – undo
600 600
 	*/
601 601
 	protected function getTrapDetail($trapid) 
602 602
 	{
603
-		if (!preg_match('/^[0-9]+$/',$trapid)) { throw new Exception('Invalid id');  }
603
+		if (!preg_match('/^[0-9]+$/', $trapid)) { throw new Exception('Invalid id'); }
604 604
 		$queryArray=$this->getModuleConfig()->trapDetailQuery();
605 605
 		
606
-		$dbConn = $this->getUIDatabase()->getDbConn();
606
+		$dbConn=$this->getUIDatabase()->getDbConn();
607 607
 		if ($dbConn === null) throw new \ErrorException('uncatched db error');
608 608
 		// ***************  Get main data
609 609
 		// extract columns and titles;
@@ -613,19 +613,19 @@  discard block
 block discarded – undo
613 613
 		}
614 614
 		try
615 615
 		{		
616
-		    $query = $dbConn->select()
617
-				->from($this->getModuleConfig()->getTrapTableName(),$elmts)
618
-				->where('id=?',$trapid);
616
+		    $query=$dbConn->select()
617
+				->from($this->getModuleConfig()->getTrapTableName(), $elmts)
618
+				->where('id=?', $trapid);
619 619
 				$trapDetail=$dbConn->fetchRow($query);
620
-			if ( $trapDetail == null ) 
620
+			if ($trapDetail == null) 
621 621
 			{
622
-			    $trapDetail = 'NULL';
622
+			    $trapDetail='NULL';
623 623
 			    throw new Exception('No traps was found with id = '.$trapid);
624 624
 			}
625 625
 		}
626 626
 		catch (Exception $e)
627 627
 		{
628
-			$this->displayExitError('Add handler : get trap detail returning : '.print_r($trapDetail,true),$e->getMessage());
628
+			$this->displayExitError('Add handler : get trap detail returning : '.print_r($trapDetail, true), $e->getMessage());
629 629
 			return;
630 630
 		}
631 631
 
@@ -639,10 +639,10 @@  discard block
 block discarded – undo
639 639
 	*/
640 640
 	protected function getTrapobjects($trapid)
641 641
 	{	
642
-		if (!preg_match('/^[0-9]+$/',$trapid)) { throw new Exception('Invalid id');  }
642
+		if (!preg_match('/^[0-9]+$/', $trapid)) { throw new Exception('Invalid id'); }
643 643
 		$queryArrayData=$this->getModuleConfig()->trapDataDetailQuery();
644 644
 		
645
-		$dbConn = $this->getUIDatabase()->getDbConn();
645
+		$dbConn=$this->getUIDatabase()->getDbConn();
646 646
 		if ($dbConn === null) throw new \ErrorException('uncatched db error');
647 647
 		// ***************  Get object data
648 648
 		// extract columns and titles;
@@ -652,15 +652,15 @@  discard block
 block discarded – undo
652 652
 		}
653 653
 		try
654 654
 		{		
655
-		    $query = $dbConn->select()
656
-				->from($this->moduleConfig->getTrapDataTableName(),$data_elmts)
657
-				->where('trap_id=?',$trapid);
655
+		    $query=$dbConn->select()
656
+				->from($this->moduleConfig->getTrapDataTableName(), $data_elmts)
657
+				->where('trap_id=?', $trapid);
658 658
 				$trapDetail=$dbConn->fetchAll($query);
659 659
 			// if ( $trapDetail == null ) throw new Exception('No traps was found with id = '.$trapid);
660 660
 		}
661 661
 		catch (Exception $e)
662 662
 		{
663
-			$this->displayExitError('Add handler : get trap data detail : ',$e->getMessage());
663
+			$this->displayExitError('Add handler : get trap data detail : ', $e->getMessage());
664 664
 			return array();
665 665
 		}
666 666
 
@@ -674,24 +674,24 @@  discard block
 block discarded – undo
674 674
 	*/
675 675
 	protected function getRuleDetail($ruleid) 
676 676
 	{
677
-		if (!preg_match('/^[0-9]+$/',$ruleid)) { throw new Exception('Invalid id');  }
677
+		if (!preg_match('/^[0-9]+$/', $ruleid)) { throw new Exception('Invalid id'); }
678 678
 		$queryArray=$this->getModuleConfig()->ruleDetailQuery();
679 679
 		
680
-		$dbConn = $this->getUIDatabase()->getDbConn();
680
+		$dbConn=$this->getUIDatabase()->getDbConn();
681 681
 		if ($dbConn === null) throw new \ErrorException('uncatched db error');
682 682
 		// ***************  Get main data
683 683
 		try
684 684
 		{		
685
-		    $query = $dbConn->select()
686
-				->from($this->getModuleConfig()->getTrapRuleName(),$queryArray)
687
-				->where('id=?',$ruleid);
685
+		    $query=$dbConn->select()
686
+				->from($this->getModuleConfig()->getTrapRuleName(), $queryArray)
687
+				->where('id=?', $ruleid);
688 688
 			$ruleDetail=$dbConn->fetchRow($query);
689
-			if ( $ruleDetail == null ) throw new Exception('No rule was found with id = '.$ruleid);
689
+			if ($ruleDetail == null) throw new Exception('No rule was found with id = '.$ruleid);
690 690
 		}
691 691
 		catch (Exception $e)
692 692
 		{
693
-			$this->displayExitError('Update handler : get rule detail',$e->getMessage());
694
-			throw new Exception('Error : ' . $e->getMessage());
693
+			$this->displayExitError('Update handler : get rule detail', $e->getMessage());
694
+			throw new Exception('Error : '.$e->getMessage());
695 695
 		}
696 696
 
697 697
 		return $ruleDetail;
@@ -704,7 +704,7 @@  discard block
 block discarded – undo
704 704
 	{
705 705
 		return $this->getTabs()->add('status', array(
706 706
 			'label' => $this->translate('Trap handlers'),
707
-			'url'   => $this->getModuleConfig()->urlPath() . '/handler')
707
+			'url'   => $this->getModuleConfig()->urlPath().'/handler')
708 708
 		);
709 709
 	} 
710 710
 	
Please login to merge, or discard this patch.
Braces   +49 added lines, -47 removed lines patch added patch discarded remove patch
@@ -25,7 +25,9 @@  discard block
 block discarded – undo
25 25
 		$this->prepareTabs()->activate('status');
26 26
 
27 27
 		$dbConn = $this->getUIDatabase()->getDb();
28
-		if ($dbConn === null) throw new \ErrorException('uncatched db error');
28
+		if ($dbConn === null) {
29
+			throw new \ErrorException('uncatched db error');
30
+		}
29 31
 		
30 32
 		$handlerTable = new HandlerTable(
31 33
 		      $this->moduleConfig->getTrapRuleName(),
@@ -84,8 +86,7 @@  discard block
 block discarded – undo
84 86
 	    if ($this->params->get('rule') !== null) 
85 87
 	    {
86 88
 	        $this->view->rule= $this->params->get('rule');
87
-	    }
88
-	    else
89
+	    } else
89 90
 	    {
90 91
 	        $this->view->rule='';
91 92
 	    }
@@ -139,8 +140,7 @@  discard block
 block discarded – undo
139 140
 	    try
140 141
 	    {
141 142
 	        $hosts=$this->getIdoConn()->getHostByIP($hostfilter);
142
-	    }
143
-	    catch (Exception $e)
143
+	    } catch (Exception $e)
144 144
 	    {
145 145
 	        $this->displayExitError('Add handler : get host by IP/Name ',$e->getMessage());
146 146
 	    }
@@ -153,8 +153,7 @@  discard block
 block discarded – undo
153 153
 	        // Tell JS to get services when page is loaded
154 154
 	        $this->view->serviceGet=true;
155 155
 	        
156
-	    }
157
-	    else
156
+	    } else
158 157
 	    {
159 158
 	        foreach($hosts as $key=>$val)
160 159
 	        {
@@ -204,11 +203,14 @@  discard block
 block discarded – undo
204 203
 	            $allObjects[$val->oid]=null;
205 204
 	        }
206 205
 	    }
207
-	    if ($allObjects!=null) // in case trap doesn't have objects or is not resolved
206
+	    if ($allObjects!=null) {
207
+	    	// in case trap doesn't have objects or is not resolved
208 208
 	    {
209 209
 	        foreach ($allObjects as $key => $val)
210 210
 	        {
211
-	            if ($val==null) { continue; }
211
+	            if ($val==null) { continue;
212
+	    }
213
+	    }
212 214
 	            array_push($this->view->objectList, array(
213 215
 	                $oid_index,
214 216
 	                $key,
@@ -240,8 +242,7 @@  discard block
 block discarded – undo
240 242
 	    {
241 243
 	        $this->view->warning_message='Host '.$this->view->hostname. ' doesn\'t exists anymore';
242 244
 	        $this->view->serviceGet=false;
243
-	    }
244
-	    else
245
+	    } else
245 246
 	    {
246 247
 	        // Tell JS to get services when page is loaded
247 248
 	        $this->view->serviceGet=true;
@@ -250,8 +251,7 @@  discard block
 block discarded – undo
250 251
 	        if (count($serviceID) ==0)
251 252
 	        {
252 253
 	            $this->view->warning_message=' Service '.$ruleDetail->service_name. ' doesn\'t exists anymore';
253
-	        }
254
-	        else
254
+	        } else
255 255
 	        {
256 256
 	            $this->view->serviceSet=$serviceID[0]->id;
257 257
 	        }
@@ -270,8 +270,7 @@  discard block
 block discarded – undo
270 270
 	    {
271 271
 	        $this->view->warning_message='HostGroup '.$this->view->hostgroupname. ' doesn\'t exists anymore';
272 272
 	        $this->view->serviceGroupGet=false;
273
-	    }
274
-	    else
273
+	    } else
275 274
 	    {
276 275
 	        $grpServices=$this->getIdoConn()->getServicesByHostGroupid($group_get[0]->id);
277 276
 	        $foundGrpService=0;
@@ -323,8 +322,7 @@  discard block
 block discarded – undo
323 322
 	                $object['type'],
324 323
 	                $object['type_enum']
325 324
 	            ));
326
-	        }
327
-	        else
325
+	        } else
328 326
 	        {
329 327
 	            array_push($curObjectList, array(
330 328
 	                $index,
@@ -402,8 +400,7 @@  discard block
 block discarded – undo
402 400
 			    $this->view->selectGroup=false;
403 401
 			    // Check if hostname still exists
404 402
 			    $this->add_check_host_exists($ruleDetail);
405
-			}
406
-			else
403
+			} else
407 404
 			{
408 405
 			    $this->view->selectGroup=true;
409 406
 			    $this->add_check_hostgroup_exists($ruleDetail); //  Check if groupe exists				
@@ -411,9 +408,11 @@  discard block
 block discarded – undo
411 408
 			
412 409
 			$this->view->mainoid=$ruleDetail->trap_oid;
413 410
 			$oidName=$this->getMIB()->translateOID($ruleDetail->trap_oid);
414
-			if ($oidName != null)  // oid is found in mibs
411
+			if ($oidName != null) {
412
+				// oid is found in mibs
415 413
 			{
416
-				$this->view->mib=$oidName['mib']; 
414
+				$this->view->mib=$oidName['mib'];
415
+			}
417 416
 				$this->view->name=$oidName['name'];
418 417
 				$this->view->trapListForMIB=$this->getMIB()
419 418
 					->getTrapList($oidName['mib']);				
@@ -470,8 +469,7 @@  discard block
 block discarded – undo
470 469
 			try
471 470
 			{
472 471
 			    $this->getUIDatabase()->deleteRule($postData[$params['db_rule']['post']]);
473
-			}
474
-			catch (Exception $e)
472
+			} catch (Exception $e)
475 473
 			{
476 474
 				$this->_helper->json(array('status'=>$e->getMessage(),'location'=>'Deleting Rule'));
477 475
 				return;
@@ -485,13 +483,15 @@  discard block
 block discarded – undo
485 483
 		}		
486 484
 		foreach (array_keys($params) as $key)
487 485
 		{
488
-			if ($params[$key]['post']==null) continue; // data not sent in post vars
486
+			if ($params[$key]['post']==null) {
487
+				continue;
488
+			}
489
+			// data not sent in post vars
489 490
 			if (! isset($postData[$params[$key]['post']]))
490 491
 			{
491 492
 				// should not happen as the js checks data
492 493
 				$this->_helper->json(array('status'=>'No ' . $key));
493
-			}
494
-			else
494
+			} else
495 495
 			{
496 496
 				$data=$postData[$params[$key]['post']];
497 497
 				if ($data!=null && $data !="")
@@ -507,7 +507,9 @@  discard block
 block discarded – undo
507 507
 			if (! $isHostGroup ) 
508 508
 			{  // checks if selection by host 
509 509
 			    $hostAddr=$this->getIdoConn()->getHostInfoByID($params['hostid']['val']);
510
-			    if ($hostAddr === NULL) throw new \Exception("No object found");
510
+			    if ($hostAddr === NULL) {
511
+			    	throw new \Exception("No object found");
512
+			    }
511 513
 				$params['ip4']['val']=$hostAddr->ip4;
512 514
 				$params['ip6']['val']=$hostAddr->ip6;
513 515
 				$checkHostName=$hostAddr->name;
@@ -524,8 +526,7 @@  discard block
 block discarded – undo
524 526
 				        $this->_helper->json(array('status'=>"Invalid service id : Please re enter service",'sent'=>$params['serviceid']['val'],'found'=>$serviceName[0]->__name));
525 527
 				        return;
526 528
 				    }
527
-				}
528
-				else
529
+				} else
529 530
 				{
530 531
     				if (!is_numeric($params['serviceid']['val']))
531 532
     				{
@@ -540,8 +541,7 @@  discard block
 block discarded – undo
540 541
     					return;
541 542
     				}
542 543
 				}
543
-			}
544
-			else
544
+			} else
545 545
 			{
546 546
 			    if ($this->apiMode == TRUE)
547 547
 			    {
@@ -551,8 +551,7 @@  discard block
 block discarded – undo
551 551
 			            $this->_helper->json(array('status'=>"Invalid object group id : Please re enter service"));
552 552
 			            return;
553 553
 			        }
554
-			    }
555
-			    else 
554
+			    } else 
556 555
 			    {
557 556
     			    $object=$this->getUIDatabase()->getObjectNameByid($params['hostid']['val']);
558 557
     				if ($params['host_name']['val'] != $object->name1)
@@ -578,14 +577,12 @@  discard block
 block discarded – undo
578 577
 			if ($params['db_rule']['val'] == -1 || $params['action_form']['val'] == 'clone') 
579 578
 			{  // If no rule number or action is clone, add the handler
580 579
 			    $ruleID=$this->getUIDatabase()->addHandlerRule($dbparams);
581
-			}
582
-			else
580
+			} else
583 581
 			{
584 582
 			    $this->getUIDatabase()->updateHandlerRule($dbparams,$params['db_rule']['val']);
585 583
 				$ruleID=$params['db_rule']['val'];
586 584
 			}
587
-		}
588
-		catch (Exception $e)
585
+		} catch (Exception $e)
589 586
 		{
590 587
 		    $this->_helper->json(array('status'=>$e->getMessage(),'location'=>'Add/update Rule','line'=>$e->getLine(),'file'=>$e->getFile()));
591 588
 			return;
@@ -604,7 +601,9 @@  discard block
 block discarded – undo
604 601
 		$queryArray=$this->getModuleConfig()->trapDetailQuery();
605 602
 		
606 603
 		$dbConn = $this->getUIDatabase()->getDbConn();
607
-		if ($dbConn === null) throw new \ErrorException('uncatched db error');
604
+		if ($dbConn === null) {
605
+			throw new \ErrorException('uncatched db error');
606
+		}
608 607
 		// ***************  Get main data
609 608
 		// extract columns and titles;
610 609
 		$elmts=NULL;
@@ -622,8 +621,7 @@  discard block
 block discarded – undo
622 621
 			    $trapDetail = 'NULL';
623 622
 			    throw new Exception('No traps was found with id = '.$trapid);
624 623
 			}
625
-		}
626
-		catch (Exception $e)
624
+		} catch (Exception $e)
627 625
 		{
628 626
 			$this->displayExitError('Add handler : get trap detail returning : '.print_r($trapDetail,true),$e->getMessage());
629 627
 			return;
@@ -643,7 +641,9 @@  discard block
 block discarded – undo
643 641
 		$queryArrayData=$this->getModuleConfig()->trapDataDetailQuery();
644 642
 		
645 643
 		$dbConn = $this->getUIDatabase()->getDbConn();
646
-		if ($dbConn === null) throw new \ErrorException('uncatched db error');
644
+		if ($dbConn === null) {
645
+			throw new \ErrorException('uncatched db error');
646
+		}
647 647
 		// ***************  Get object data
648 648
 		// extract columns and titles;
649 649
 		$data_elmts=NULL;
@@ -657,8 +657,7 @@  discard block
 block discarded – undo
657 657
 				->where('trap_id=?',$trapid);
658 658
 				$trapDetail=$dbConn->fetchAll($query);
659 659
 			// if ( $trapDetail == null ) throw new Exception('No traps was found with id = '.$trapid);
660
-		}
661
-		catch (Exception $e)
660
+		} catch (Exception $e)
662 661
 		{
663 662
 			$this->displayExitError('Add handler : get trap data detail : ',$e->getMessage());
664 663
 			return array();
@@ -678,7 +677,9 @@  discard block
 block discarded – undo
678 677
 		$queryArray=$this->getModuleConfig()->ruleDetailQuery();
679 678
 		
680 679
 		$dbConn = $this->getUIDatabase()->getDbConn();
681
-		if ($dbConn === null) throw new \ErrorException('uncatched db error');
680
+		if ($dbConn === null) {
681
+			throw new \ErrorException('uncatched db error');
682
+		}
682 683
 		// ***************  Get main data
683 684
 		try
684 685
 		{		
@@ -686,9 +687,10 @@  discard block
 block discarded – undo
686 687
 				->from($this->getModuleConfig()->getTrapRuleName(),$queryArray)
687 688
 				->where('id=?',$ruleid);
688 689
 			$ruleDetail=$dbConn->fetchRow($query);
689
-			if ( $ruleDetail == null ) throw new Exception('No rule was found with id = '.$ruleid);
690
-		}
691
-		catch (Exception $e)
690
+			if ( $ruleDetail == null ) {
691
+				throw new Exception('No rule was found with id = '.$ruleid);
692
+			}
693
+		} catch (Exception $e)
692 694
 		{
693 695
 			$this->displayExitError('Update handler : get rule detail',$e->getMessage());
694 696
 			throw new Exception('Error : ' . $e->getMessage());
Please login to merge, or discard this patch.
Indentation   +294 added lines, -295 removed lines patch added patch discarded remove patch
@@ -12,13 +12,12 @@  discard block
 block discarded – undo
12 12
 
13 13
 //use Icinga\Web\Form as Form;
14 14
 /** Rules management
15
-
16
-*/
15
+ */
17 16
 class HandlerController extends TrapsController
18 17
 {
19 18
 
20 19
 	/** index : list existing rules 
21
-	*/
20
+	 */
22 21
 	public function indexAction()
23 22
 	{	
24 23
 		$this->checkReadPermission();
@@ -28,14 +27,14 @@  discard block
 block discarded – undo
28 27
 		if ($dbConn === null) throw new \ErrorException('uncatched db error');
29 28
 		
30 29
 		$handlerTable = new HandlerTable(
31
-		      $this->moduleConfig->getTrapRuleName(),
32
-		      $this->moduleConfig->getHandlerListTitles(),
33
-		      $this->moduleConfig->getHandlerListDisplayColumns(),
34
-		      $this->moduleConfig->getHandlerColumns(),
35
-		      $dbConn->getDbAdapter(),
30
+			  $this->moduleConfig->getTrapRuleName(),
31
+			  $this->moduleConfig->getHandlerListTitles(),
32
+			  $this->moduleConfig->getHandlerListDisplayColumns(),
33
+			  $this->moduleConfig->getHandlerColumns(),
34
+			  $dbConn->getDbAdapter(),
36 35
 //		      $dbConn->getConnection(),
37
-		      $this->view,
38
-		      $this->moduleConfig->urlPath());
36
+			  $this->view,
37
+			  $this->moduleConfig->urlPath());
39 38
 		
40 39
 		$handlerTable->setMaxPerPage($this->itemListDisplay());
41 40
 		
@@ -57,7 +56,7 @@  discard block
 block discarded – undo
57 56
 		
58 57
 		// TODO : Obsolete remove after new table validation.
59 58
 		
60
-	    /**
59
+		/**
61 60
 		$this->getHandlerListTable()->setConnection($dbConn);
62 61
 		$this->getHandlerListTable()->setMibloader($this->getMIB());
63 62
 		// Apply pagination limits 
@@ -74,22 +73,22 @@  discard block
 block discarded – undo
74 73
 	 */
75 74
 	public function testruleAction()
76 75
 	{
77
-	    $this->checkReadPermission();
78
-	    $this->getTabs()->add('get',array(
79
-	        'active'	=> true,
80
-	        'label'		=> $this->translate('Test Rule'),
81
-	        'url'		=> Url::fromRequest()
82
-	    ));
76
+		$this->checkReadPermission();
77
+		$this->getTabs()->add('get',array(
78
+			'active'	=> true,
79
+			'label'		=> $this->translate('Test Rule'),
80
+			'url'		=> Url::fromRequest()
81
+		));
83 82
 	    
84 83
 
85
-	    if ($this->params->get('rule') !== null) 
86
-	    {
87
-	        $this->view->rule= $this->params->get('rule');
88
-	    }
89
-	    else
90
-	    {
91
-	        $this->view->rule='';
92
-	    }
84
+		if ($this->params->get('rule') !== null) 
85
+		{
86
+			$this->view->rule= $this->params->get('rule');
87
+		}
88
+		else
89
+		{
90
+			$this->view->rule='';
91
+		}
93 92
 	}
94 93
 	
95 94
 	/**
@@ -97,31 +96,31 @@  discard block
 block discarded – undo
97 96
 	 */
98 97
 	private function add_setup_vars()
99 98
 	{
100
-	    // variables to send to view
101
-	    $this->view->hostlist=array(); // host list to input datalist
102
-	    $this->view->hostname=''; // Host name in input text
103
-	    $this->view->serviceGet=false; // Set to true to get list of service if only one host set
104
-	    $this->view->serviceSet=null; // Select service in services select (must have serviceGet=true).
105
-	    $this->view->mainoid=''; // Trap OID
106
-	    $this->view->mib=''; // Trap mib
107
-	    $this->view->name=''; // Trap name
108
-	    $this->view->trapListForMIB=array(); // Trap list if mib exists for trap
109
-	    $this->view->objectList=array(); // objects sent with trap
110
-	    $this->view->display=''; // Initial display
111
-	    $this->view->rule=''; // rule display
112
-	    $this->view->revertOK=''; // revert OK in seconds
113
-	    $this->view->hostid=-1; // normally set by javascript serviceGet()
114
-	    $this->view->ruleid=-1; // Rule id in DB for update & delete
115
-	    $this->view->setToUpdate=false; // set form as update form
116
-	    $this->view->setRuleMatch=-1; // set action on rule match (default nothing)
117
-	    $this->view->setRuleNoMatch=-1; // set action on rule no match (default nothing)
99
+		// variables to send to view
100
+		$this->view->hostlist=array(); // host list to input datalist
101
+		$this->view->hostname=''; // Host name in input text
102
+		$this->view->serviceGet=false; // Set to true to get list of service if only one host set
103
+		$this->view->serviceSet=null; // Select service in services select (must have serviceGet=true).
104
+		$this->view->mainoid=''; // Trap OID
105
+		$this->view->mib=''; // Trap mib
106
+		$this->view->name=''; // Trap name
107
+		$this->view->trapListForMIB=array(); // Trap list if mib exists for trap
108
+		$this->view->objectList=array(); // objects sent with trap
109
+		$this->view->display=''; // Initial display
110
+		$this->view->rule=''; // rule display
111
+		$this->view->revertOK=''; // revert OK in seconds
112
+		$this->view->hostid=-1; // normally set by javascript serviceGet()
113
+		$this->view->ruleid=-1; // Rule id in DB for update & delete
114
+		$this->view->setToUpdate=false; // set form as update form
115
+		$this->view->setRuleMatch=-1; // set action on rule match (default nothing)
116
+		$this->view->setRuleNoMatch=-1; // set action on rule no match (default nothing)
118 117
 	    
119
-	    $this->view->selectGroup=false; // Select by group if true
120
-	    $this->view->hostgroupid=-1; // host group id
121
-	    $this->view->serviceGroupGet=false; // Get list of service for group (set serviceSet to select one)
118
+		$this->view->selectGroup=false; // Select by group if true
119
+		$this->view->hostgroupid=-1; // host group id
120
+		$this->view->serviceGroupGet=false; // Get list of service for group (set serviceSet to select one)
122 121
 	    
123
-	    $this->view->modifier=null;
124
-	    $this->view->modified=null;
122
+		$this->view->modifier=null;
123
+		$this->view->modified=null;
125 124
 	}
126 125
 	
127 126
 	/**
@@ -130,102 +129,102 @@  discard block
 block discarded – undo
130 129
 	 */
131 130
 	private function add_from_existing($trapid)
132 131
 	{
133
-	    /********** Setup from existing trap ***************/
134
-	    // Get the full trap info
135
-	    $trapDetail=$this->getTrapDetail($trapid);
132
+		/********** Setup from existing trap ***************/
133
+		// Get the full trap info
134
+		$trapDetail=$this->getTrapDetail($trapid);
136 135
 	    
137
-	    $hostfilter=$trapDetail->source_ip;
136
+		$hostfilter=$trapDetail->source_ip;
138 137
 	    
139
-	    // Get host
140
-	    try
141
-	    {
142
-	        $hosts=$this->getIdoConn()->getHostByIP($hostfilter);
143
-	    }
144
-	    catch (Exception $e)
145
-	    {
146
-	        $this->displayExitError('Add handler : get host by IP/Name ',$e->getMessage());
147
-	    }
138
+		// Get host
139
+		try
140
+		{
141
+			$hosts=$this->getIdoConn()->getHostByIP($hostfilter);
142
+		}
143
+		catch (Exception $e)
144
+		{
145
+			$this->displayExitError('Add handler : get host by IP/Name ',$e->getMessage());
146
+		}
148 147
 	    
149 148
 	    
150
-	    // if one unique host found -> put id text input
151
-	    if (count($hosts)==1) {
152
-	        $this->view->hostname=$hosts[0]->name;
153
-	        //$hostid=$hosts[0]->id;
154
-	        // Tell JS to get services when page is loaded
155
-	        $this->view->serviceGet=true;
149
+		// if one unique host found -> put id text input
150
+		if (count($hosts)==1) {
151
+			$this->view->hostname=$hosts[0]->name;
152
+			//$hostid=$hosts[0]->id;
153
+			// Tell JS to get services when page is loaded
154
+			$this->view->serviceGet=true;
156 155
 	        
157
-	    }
158
-	    else
159
-	    {
160
-	        foreach($hosts as $key=>$val)
161
-	        {
162
-	            array_push($this->view->hostlist,$hosts[$key]->name);
163
-	        }
164
-	    }
156
+		}
157
+		else
158
+		{
159
+			foreach($hosts as $key=>$val)
160
+			{
161
+				array_push($this->view->hostlist,$hosts[$key]->name);
162
+			}
163
+		}
165 164
 	    
166
-	    // set up trap oid and objects received by the trap
165
+		// set up trap oid and objects received by the trap
167 166
 	    
168
-	    $this->view->mainoid=$trapDetail->trap_oid;
169
-	    if ($trapDetail->trap_name_mib != null)
170
-	    {
171
-	        $this->view->mib=$trapDetail->trap_name_mib;
172
-	        $this->view->name=$trapDetail->trap_name;
173
-	        $this->view->trapListForMIB=$this->getMIB()
174
-	        ->getTrapList($trapDetail->trap_name_mib);
175
-	    }
167
+		$this->view->mainoid=$trapDetail->trap_oid;
168
+		if ($trapDetail->trap_name_mib != null)
169
+		{
170
+			$this->view->mib=$trapDetail->trap_name_mib;
171
+			$this->view->name=$trapDetail->trap_name;
172
+			$this->view->trapListForMIB=$this->getMIB()
173
+			->getTrapList($trapDetail->trap_name_mib);
174
+		}
176 175
 	    
177
-	    // Get all objects that can be in trap from MIB
178
-	    $allObjects=$this->getMIB()->getObjectList($trapDetail->trap_oid);
179
-	    // Get all objects in current Trap
180
-	    $currentTrapObjects=$this->getTrapobjects($trapid);
181
-	    $oid_index=1;
182
-	    foreach ($currentTrapObjects as $key => $val)
183
-	    {
184
-	        $currentObjectType='Unknown';
185
-	        $currentObjectTypeEnum='Unknown';
186
-	        if (isset($allObjects[$val->oid]['type']))
187
-	        {
188
-	            $currentObjectType=$allObjects[$val->oid]['type'];
189
-	            $currentObjectTypeEnum=$allObjects[$val->oid]['type_enum'];
190
-	        }
191
-	        $currentObject=array(
192
-	            $oid_index,
193
-	            $val->oid,
194
-	            $val->oid_name_mib,
195
-	            $val->oid_name,
196
-	            $val->value,
197
-	            $currentObjectType,
198
-	            $currentObjectTypeEnum
199
-	        );
200
-	        $oid_index++;
201
-	        array_push($this->view->objectList,$currentObject);
202
-	        // set currrent object to null in allObjects
203
-	        if (isset($allObjects[$val->oid]))
204
-	        {
205
-	            $allObjects[$val->oid]=null;
206
-	        }
207
-	    }
208
-	    if ($allObjects!=null) // in case trap doesn't have objects or is not resolved
209
-	    {
210
-	        foreach ($allObjects as $key => $val)
211
-	        {
212
-	            if ($val==null) { continue; }
213
-	            array_push($this->view->objectList, array(
214
-	                $oid_index,
215
-	                $key,
216
-	                $allObjects[$key]['mib'],
217
-	                $allObjects[$key]['name'],
218
-	                '',
219
-	                $allObjects[$key]['type'],
220
-	                $allObjects[$key]['type_enum']
221
-	            ));
222
-	            $oid_index++;
223
-	        }
224
-	    }
176
+		// Get all objects that can be in trap from MIB
177
+		$allObjects=$this->getMIB()->getObjectList($trapDetail->trap_oid);
178
+		// Get all objects in current Trap
179
+		$currentTrapObjects=$this->getTrapobjects($trapid);
180
+		$oid_index=1;
181
+		foreach ($currentTrapObjects as $key => $val)
182
+		{
183
+			$currentObjectType='Unknown';
184
+			$currentObjectTypeEnum='Unknown';
185
+			if (isset($allObjects[$val->oid]['type']))
186
+			{
187
+				$currentObjectType=$allObjects[$val->oid]['type'];
188
+				$currentObjectTypeEnum=$allObjects[$val->oid]['type_enum'];
189
+			}
190
+			$currentObject=array(
191
+				$oid_index,
192
+				$val->oid,
193
+				$val->oid_name_mib,
194
+				$val->oid_name,
195
+				$val->value,
196
+				$currentObjectType,
197
+				$currentObjectTypeEnum
198
+			);
199
+			$oid_index++;
200
+			array_push($this->view->objectList,$currentObject);
201
+			// set currrent object to null in allObjects
202
+			if (isset($allObjects[$val->oid]))
203
+			{
204
+				$allObjects[$val->oid]=null;
205
+			}
206
+		}
207
+		if ($allObjects!=null) // in case trap doesn't have objects or is not resolved
208
+		{
209
+			foreach ($allObjects as $key => $val)
210
+			{
211
+				if ($val==null) { continue; }
212
+				array_push($this->view->objectList, array(
213
+					$oid_index,
214
+					$key,
215
+					$allObjects[$key]['mib'],
216
+					$allObjects[$key]['name'],
217
+					'',
218
+					$allObjects[$key]['type'],
219
+					$allObjects[$key]['type_enum']
220
+				));
221
+				$oid_index++;
222
+			}
223
+		}
225 224
 	    
226
-	    // Add a simple display
227
-	    $this->view->display='Trap '.$trapDetail->trap_name.' received';
228
-	    $this->view->create_basic_rule=true;
225
+		// Add a simple display
226
+		$this->view->display='Trap '.$trapDetail->trap_name.' received';
227
+		$this->view->create_basic_rule=true;
229 228
 	}
230 229
 
231 230
 	/**
@@ -234,29 +233,29 @@  discard block
 block discarded – undo
234 233
 	 */
235 234
 	private function add_check_host_exists($ruleDetail)
236 235
 	{
237
-	    // Check if hostname still exists
238
-	    $host_get=$this->getIdoConn()->getHostByName($this->view->hostname);
236
+		// Check if hostname still exists
237
+		$host_get=$this->getIdoConn()->getHostByName($this->view->hostname);
239 238
 	    
240
-	    if (count($host_get)==0)
241
-	    {
242
-	        $this->view->warning_message='Host '.$this->view->hostname. ' doesn\'t exists anymore';
243
-	        $this->view->serviceGet=false;
244
-	    }
245
-	    else
246
-	    {
247
-	        // Tell JS to get services when page is loaded
248
-	        $this->view->serviceGet=true;
249
-	        // get service id for form to set :
250
-	        $serviceID=$this->getIdoConn()->getServiceIDByName($this->view->hostname,$ruleDetail->service_name);
251
-	        if (count($serviceID) ==0)
252
-	        {
253
-	            $this->view->warning_message=' Service '.$ruleDetail->service_name. ' doesn\'t exists anymore';
254
-	        }
255
-	        else
256
-	        {
257
-	            $this->view->serviceSet=$serviceID[0]->id;
258
-	        }
259
-	    }
239
+		if (count($host_get)==0)
240
+		{
241
+			$this->view->warning_message='Host '.$this->view->hostname. ' doesn\'t exists anymore';
242
+			$this->view->serviceGet=false;
243
+		}
244
+		else
245
+		{
246
+			// Tell JS to get services when page is loaded
247
+			$this->view->serviceGet=true;
248
+			// get service id for form to set :
249
+			$serviceID=$this->getIdoConn()->getServiceIDByName($this->view->hostname,$ruleDetail->service_name);
250
+			if (count($serviceID) ==0)
251
+			{
252
+				$this->view->warning_message=' Service '.$ruleDetail->service_name. ' doesn\'t exists anymore';
253
+			}
254
+			else
255
+			{
256
+				$this->view->serviceSet=$serviceID[0]->id;
257
+			}
258
+		}
260 259
 	}
261 260
 
262 261
 	/**
@@ -265,33 +264,33 @@  discard block
 block discarded – undo
265 264
 	 */
266 265
 	private function add_check_hostgroup_exists($ruleDetail)
267 266
 	{
268
-	    // Check if groupe exists
269
-	    $group_get=$this->getIdoConn()->getHostGroupByName($this->view->hostgroupname);
270
-	    if (count($group_get)==0)
271
-	    {
272
-	        $this->view->warning_message='HostGroup '.$this->view->hostgroupname. ' doesn\'t exists anymore';
273
-	        $this->view->serviceGroupGet=false;
274
-	    }
275
-	    else
276
-	    {
277
-	        $grpServices=$this->getIdoConn()->getServicesByHostGroupid($group_get[0]->id);
278
-	        $foundGrpService=0;
279
-	        foreach ($grpServices as $grpService)
280
-	        {
281
-	            if ($grpService[0] == $ruleDetail->service_name)
282
-	            {
283
-	                $foundGrpService=1;
284
-	                $this->view->serviceSet=$ruleDetail->service_name;
285
-	            }
286
-	        }
267
+		// Check if groupe exists
268
+		$group_get=$this->getIdoConn()->getHostGroupByName($this->view->hostgroupname);
269
+		if (count($group_get)==0)
270
+		{
271
+			$this->view->warning_message='HostGroup '.$this->view->hostgroupname. ' doesn\'t exists anymore';
272
+			$this->view->serviceGroupGet=false;
273
+		}
274
+		else
275
+		{
276
+			$grpServices=$this->getIdoConn()->getServicesByHostGroupid($group_get[0]->id);
277
+			$foundGrpService=0;
278
+			foreach ($grpServices as $grpService)
279
+			{
280
+				if ($grpService[0] == $ruleDetail->service_name)
281
+				{
282
+					$foundGrpService=1;
283
+					$this->view->serviceSet=$ruleDetail->service_name;
284
+				}
285
+			}
287 286
 	        
288
-	        // Tell JS to get services when page is loaded
289
-	        $this->view->serviceGroupGet=true;
290
-	        if ($foundGrpService==0)
291
-	        {
292
-	            $this->view->warning_message.=' Service '.$ruleDetail->service_name. ' doesn\'t exists anymore';
293
-	        }
294
-	    }
287
+			// Tell JS to get services when page is loaded
288
+			$this->view->serviceGroupGet=true;
289
+			if ($foundGrpService==0)
290
+			{
291
+				$this->view->warning_message.=' Service '.$ruleDetail->service_name. ' doesn\'t exists anymore';
292
+			}
293
+		}
295 294
 	}
296 295
 	
297 296
 	/**
@@ -303,52 +302,52 @@  discard block
 block discarded – undo
303 302
 	 */
304 303
 	private function add_create_trap_object_list(&$display, &$rule)
305 304
 	{
306
-	    $curObjectList=array();
307
-	    $index=1;
308
-	    // check in display & rule for : OID(<oid>)
309
-	    $matches=array();
310
-	    while ( preg_match('/_OID\(([\.0-9\*]+)\)/',$display,$matches) ||
311
-	        preg_match('/_OID\(([\.0-9\*]+)\)/',$rule,$matches))
312
-	    {
313
-	        $curOid=$matches[1];
305
+		$curObjectList=array();
306
+		$index=1;
307
+		// check in display & rule for : OID(<oid>)
308
+		$matches=array();
309
+		while ( preg_match('/_OID\(([\.0-9\*]+)\)/',$display,$matches) ||
310
+			preg_match('/_OID\(([\.0-9\*]+)\)/',$rule,$matches))
311
+		{
312
+			$curOid=$matches[1];
314 313
 	        
315
-	        if ( (preg_match('/\*/',$curOid) == 0 ) 
316
-	            && ($object=$this->getMIB()->translateOID($curOid)) != null)
317
-	        {
318
-	            array_push($curObjectList, array(
319
-	                $index,
320
-	                $curOid,
321
-	                $object['mib'],
322
-	                $object['name'],
323
-	                '',
324
-	                $object['type'],
325
-	                $object['type_enum']
326
-	            ));
327
-	        }
328
-	        else
329
-	        {
330
-	            array_push($curObjectList, array(
331
-	                $index,
332
-	                $curOid,
333
-	                'not found',
334
-	                'not found',
335
-	                '',
336
-	                'not found',
337
-	                'not found'
338
-	            ));
339
-	        }
340
-	        $curOid = preg_replace('/\*/','\*',$curOid);
341
-	        $display=preg_replace('/_OID\('.$curOid.'\)/','\$'.$index.'\$',$display);
342
-	        $rule=preg_replace('/_OID\('.$curOid.'\)/','\$'.$index.'\$',$rule);
343
-	        $index++;
344
-	    }
345
-	    return $curObjectList;
314
+			if ( (preg_match('/\*/',$curOid) == 0 ) 
315
+				&& ($object=$this->getMIB()->translateOID($curOid)) != null)
316
+			{
317
+				array_push($curObjectList, array(
318
+					$index,
319
+					$curOid,
320
+					$object['mib'],
321
+					$object['name'],
322
+					'',
323
+					$object['type'],
324
+					$object['type_enum']
325
+				));
326
+			}
327
+			else
328
+			{
329
+				array_push($curObjectList, array(
330
+					$index,
331
+					$curOid,
332
+					'not found',
333
+					'not found',
334
+					'',
335
+					'not found',
336
+					'not found'
337
+				));
338
+			}
339
+			$curOid = preg_replace('/\*/','\*',$curOid);
340
+			$display=preg_replace('/_OID\('.$curOid.'\)/','\$'.$index.'\$',$display);
341
+			$rule=preg_replace('/_OID\('.$curOid.'\)/','\$'.$index.'\$',$rule);
342
+			$index++;
343
+		}
344
+		return $curObjectList;
346 345
 	}
347 346
 	
348 347
 	/** Add a handler  
349
-	*	Get params fromid : setup from existing trap (id of trap table)
350
-	*	Get param ruleid : edit from existing handler (id of rule table)
351
-	*/
348
+	 *	Get params fromid : setup from existing trap (id of trap table)
349
+	 *	Get param ruleid : edit from existing handler (id of rule table)
350
+	 */
352 351
 	public function addAction()
353 352
 	{
354 353
 		$this->checkConfigPermission();
@@ -371,8 +370,8 @@  discard block
 block discarded – undo
371 370
 		//$this->view->trapvalues=false; // Set to true to display 'value' colum in objects
372 371
 		
373 372
 		if (($trapid = $this->params->get('fromid')) !== null) {
374
-		    /********** Setup from existing trap ***************/
375
-            $this->add_from_existing($trapid);
373
+			/********** Setup from existing trap ***************/
374
+			$this->add_from_existing($trapid);
376 375
 			return;
377 376
 		}
378 377
 		
@@ -400,14 +399,14 @@  discard block
 block discarded – undo
400 399
 			$this->view->warning_message='';
401 400
 			if ($this->view->hostname != null)
402 401
 			{
403
-			    $this->view->selectGroup=false;
404
-			    // Check if hostname still exists
405
-			    $this->add_check_host_exists($ruleDetail);
402
+				$this->view->selectGroup=false;
403
+				// Check if hostname still exists
404
+				$this->add_check_host_exists($ruleDetail);
406 405
 			}
407 406
 			else
408 407
 			{
409
-			    $this->view->selectGroup=true;
410
-			    $this->add_check_hostgroup_exists($ruleDetail); //  Check if groupe exists				
408
+				$this->view->selectGroup=true;
409
+				$this->add_check_hostgroup_exists($ruleDetail); //  Check if groupe exists				
411 410
 			}
412 411
 			
413 412
 			$this->view->mainoid=$ruleDetail->trap_oid;
@@ -435,9 +434,9 @@  discard block
 block discarded – undo
435 434
 	}
436 435
 	
437 436
 	/** Validate form and output message to user  
438
-	*	@param in postdata 
439
-	* 	@return string status : OK / <Message>
440
-	**/
437
+	 *	@param in postdata 
438
+	 * 	@return string status : OK / <Message>
439
+	 **/
441 440
 	protected function handlerformAction()
442 441
 	{
443 442
 		$postData=$this->getRequest()->getPost();
@@ -452,8 +451,8 @@  discard block
 block discarded – undo
452 451
 			'host_group_name'=>	array('post' => null,            'val' => null,  'db'=>true),
453 452
 			'serviceid'		=>	array('post' => 'serviceid',                     'db'=>false),
454 453
 			'service_name'	=>	array('post' => 'serviceName',                    'db'=>true),
455
-		    'comment'       =>  array('post' => 'comment',       'val' => '',    'db'=>true),
456
-		    'rule_type'     =>  array('post' => 'category',       'val' => 0,    'db'=>true),
454
+			'comment'       =>  array('post' => 'comment',       'val' => '',    'db'=>true),
455
+			'rule_type'     =>  array('post' => 'category',       'val' => 0,    'db'=>true),
457 456
 			'trap_oid'		=>	array('post' => 'oid',                            'db'=>true),
458 457
 			'revert_ok'		=>	array('post' => 'revertOK',      'val' => 0,      'db'=>true),
459 458
 			'display'		=>	array('post' => 'display',        'val' => '',     'db'=>true),
@@ -462,7 +461,7 @@  discard block
 block discarded – undo
462 461
 			'action_nomatch'=>	array('post' => 'ruleNoMatch',    'val' => -1,    'db'=>true),					
463 462
 			'ip4'			=>	array('post' => null,             'val' => null,  'db'=>true),
464 463
 			'ip6'			=>	array('post' => null,             'val' => null,  'db'=>true),
465
-		    'action_form'	=>	array('post' => 'action_form',    'val' => null, 'db'=>false)
464
+			'action_form'	=>	array('post' => 'action_form',    'val' => null, 'db'=>false)
466 465
 		);
467 466
 		
468 467
 		if (isset($postData[$params['action_form']['post']]) 
@@ -470,7 +469,7 @@  discard block
 block discarded – undo
470 469
 		{
471 470
 			try
472 471
 			{
473
-			    $this->getUIDatabase()->deleteRule($postData[$params['db_rule']['post']]);
472
+				$this->getUIDatabase()->deleteRule($postData[$params['db_rule']['post']]);
474 473
 			}
475 474
 			catch (Exception $e)
476 475
 			{
@@ -480,7 +479,7 @@  discard block
 block discarded – undo
480 479
 			//$this->Module()->
481 480
 			$this->_helper->json(array(
482 481
 				'status'=>'OK',
483
-			    'redirect'=>'trapdirector/handler'
482
+				'redirect'=>'trapdirector/handler'
484 483
 			      
485 484
 			));
486 485
 		}		
@@ -507,8 +506,8 @@  discard block
 block discarded – undo
507 506
 			$isHostGroup=($params['hostgroup']['val'] == 1)?true:false;
508 507
 			if (! $isHostGroup ) 
509 508
 			{  // checks if selection by host 
510
-			    $hostAddr=$this->getIdoConn()->getHostInfoByID($params['hostid']['val']);
511
-			    if ($hostAddr === NULL) throw new \Exception("No object found");
509
+				$hostAddr=$this->getIdoConn()->getHostInfoByID($params['hostid']['val']);
510
+				if ($hostAddr === NULL) throw new \Exception("No object found");
512 511
 				$params['ip4']['val']=$hostAddr->ip4;
513 512
 				$params['ip6']['val']=$hostAddr->ip6;
514 513
 				$checkHostName=$hostAddr->name;
@@ -519,49 +518,49 @@  discard block
 block discarded – undo
519 518
 				}
520 519
 				if ($this->apiMode == TRUE)
521 520
 				{
522
-				    $serviceName=$this->getIdoConn()->getServiceById($params['serviceid']['val']);
523
-				    if (count($serviceName) == 0 )
524
-				    {
525
-				        $this->_helper->json(array('status'=>"Invalid service id : Please re enter service",'sent'=>$params['serviceid']['val'],'found'=>$serviceName[0]->__name));
526
-				        return;
527
-				    }
521
+					$serviceName=$this->getIdoConn()->getServiceById($params['serviceid']['val']);
522
+					if (count($serviceName) == 0 )
523
+					{
524
+						$this->_helper->json(array('status'=>"Invalid service id : Please re enter service",'sent'=>$params['serviceid']['val'],'found'=>$serviceName[0]->__name));
525
+						return;
526
+					}
528 527
 				}
529 528
 				else
530 529
 				{
531
-    				if (!is_numeric($params['serviceid']['val']))
532
-    				{
533
-    				    $this->_helper->json(array('status'=>"Invalid service id ". $params['serviceid']['val']));
534
-    				    return;
535
-    				}
530
+					if (!is_numeric($params['serviceid']['val']))
531
+					{
532
+						$this->_helper->json(array('status'=>"Invalid service id ". $params['serviceid']['val']));
533
+						return;
534
+					}
536 535
     				
537
-    				$serviceName=$this->getUIDatabase()->getObjectNameByid($params['serviceid']['val']);
538
-    				if ($params['service_name']['val'] != $serviceName->name2)
539
-    				{
540
-    					$this->_helper->json(array('status'=>"Invalid service id : Please re enter service"));
541
-    					return;
542
-    				}
536
+					$serviceName=$this->getUIDatabase()->getObjectNameByid($params['serviceid']['val']);
537
+					if ($params['service_name']['val'] != $serviceName->name2)
538
+					{
539
+						$this->_helper->json(array('status'=>"Invalid service id : Please re enter service"));
540
+						return;
541
+					}
543 542
 				}
544 543
 			}
545 544
 			else
546 545
 			{
547
-			    if ($this->apiMode == TRUE)
548
-			    {
549
-			        $object=$this->getIdoConn()->getHostGroupById($params['hostid']['val']);
546
+				if ($this->apiMode == TRUE)
547
+				{
548
+					$object=$this->getIdoConn()->getHostGroupById($params['hostid']['val']);
550 549
 				if (empty($object) || $params['host_name']['val'] != $object->__name)
551
-			        {
552
-			            $this->_helper->json(array('status'=>"Invalid object group id : Please re enter service"));
553
-			            return;
554
-			        }
555
-			    }
556
-			    else 
557
-			    {
558
-    			    $object=$this->getUIDatabase()->getObjectNameByid($params['hostid']['val']);
559
-    				if ($params['host_name']['val'] != $object->name1)
560
-    				{
561
-    					$this->_helper->json(array('status'=>"Invalid object group id : Please re enter service"));
562
-    					return;					
563
-    				}
564
-			    }
550
+					{
551
+						$this->_helper->json(array('status'=>"Invalid object group id : Please re enter service"));
552
+						return;
553
+					}
554
+				}
555
+				else 
556
+				{
557
+					$object=$this->getUIDatabase()->getObjectNameByid($params['hostid']['val']);
558
+					if ($params['host_name']['val'] != $object->name1)
559
+					{
560
+						$this->_helper->json(array('status'=>"Invalid object group id : Please re enter service"));
561
+						return;					
562
+					}
563
+				}
565 564
 				// Put param in correct column (group_name)
566 565
 				$params['host_group_name']['val'] = $params['host_name']['val'];
567 566
 				$params['host_name']['val']=null;
@@ -578,17 +577,17 @@  discard block
 block discarded – undo
578 577
 			
579 578
 			if ($params['db_rule']['val'] == -1 || $params['action_form']['val'] == 'clone') 
580 579
 			{  // If no rule number or action is clone, add the handler
581
-			    $ruleID=$this->getUIDatabase()->addHandlerRule($dbparams);
580
+				$ruleID=$this->getUIDatabase()->addHandlerRule($dbparams);
582 581
 			}
583 582
 			else
584 583
 			{
585
-			    $this->getUIDatabase()->updateHandlerRule($dbparams,$params['db_rule']['val']);
584
+				$this->getUIDatabase()->updateHandlerRule($dbparams,$params['db_rule']['val']);
586 585
 				$ruleID=$params['db_rule']['val'];
587 586
 			}
588 587
 		}
589 588
 		catch (Exception $e)
590 589
 		{
591
-		    $this->_helper->json(array('status'=>$e->getMessage(),'location'=>'Add/update Rule','line'=>$e->getLine(),'file'=>$e->getFile()));
590
+			$this->_helper->json(array('status'=>$e->getMessage(),'location'=>'Add/update Rule','line'=>$e->getLine(),'file'=>$e->getFile()));
592 591
 			return;
593 592
 		}
594 593
 		$this->_helper->json(array('status'=>'OK', 'id' => $ruleID));
@@ -596,9 +595,9 @@  discard block
 block discarded – undo
596 595
 	}
597 596
 
598 597
 	/** Get trap detail by trapid. 
599
-	*	@param integer $trapid : id of trap in received table
600
-	*	@return array (objects)
601
-	*/
598
+	 *	@param integer $trapid : id of trap in received table
599
+	 *	@return array (objects)
600
+	 */
602 601
 	protected function getTrapDetail($trapid) 
603 602
 	{
604 603
 		if (!preg_match('/^[0-9]+$/',$trapid)) { throw new Exception('Invalid id');  }
@@ -614,14 +613,14 @@  discard block
 block discarded – undo
614 613
 		}
615 614
 		try
616 615
 		{		
617
-		    $query = $dbConn->select()
616
+			$query = $dbConn->select()
618 617
 				->from($this->getModuleConfig()->getTrapTableName(),$elmts)
619 618
 				->where('id=?',$trapid);
620 619
 				$trapDetail=$dbConn->fetchRow($query);
621 620
 			if ( $trapDetail == null ) 
622 621
 			{
623
-			    $trapDetail = 'NULL';
624
-			    throw new Exception('No traps was found with id = '.$trapid);
622
+				$trapDetail = 'NULL';
623
+				throw new Exception('No traps was found with id = '.$trapid);
625 624
 			}
626 625
 		}
627 626
 		catch (Exception $e)
@@ -635,9 +634,9 @@  discard block
 block discarded – undo
635 634
 	}
636 635
 
637 636
 	/** Get trap objects
638
-	*	@param integer $trapid : trap id
639
-	* 	@return array : full column in db of trap id
640
-	*/
637
+	 *	@param integer $trapid : trap id
638
+	 * 	@return array : full column in db of trap id
639
+	 */
641 640
 	protected function getTrapobjects($trapid)
642 641
 	{	
643 642
 		if (!preg_match('/^[0-9]+$/',$trapid)) { throw new Exception('Invalid id');  }
@@ -653,7 +652,7 @@  discard block
 block discarded – undo
653 652
 		}
654 653
 		try
655 654
 		{		
656
-		    $query = $dbConn->select()
655
+			$query = $dbConn->select()
657 656
 				->from($this->moduleConfig->getTrapDataTableName(),$data_elmts)
658 657
 				->where('trap_id=?',$trapid);
659 658
 				$trapDetail=$dbConn->fetchAll($query);
@@ -669,10 +668,10 @@  discard block
 block discarded – undo
669 668
 	}
670 669
 
671 670
 	/** Get rule detail by ruleid.
672
-	*	@param integer $ruleid int id of rule in rule table
673
-	*	@return object|array : column objects in db 
674
-	*
675
-	*/
671
+	 *	@param integer $ruleid int id of rule in rule table
672
+	 *	@return object|array : column objects in db 
673
+	 *
674
+	 */
676 675
 	protected function getRuleDetail($ruleid) 
677 676
 	{
678 677
 		if (!preg_match('/^[0-9]+$/',$ruleid)) { throw new Exception('Invalid id');  }
@@ -683,7 +682,7 @@  discard block
 block discarded – undo
683 682
 		// ***************  Get main data
684 683
 		try
685 684
 		{		
686
-		    $query = $dbConn->select()
685
+			$query = $dbConn->select()
687 686
 				->from($this->getModuleConfig()->getTrapRuleName(),$queryArray)
688 687
 				->where('id=?',$ruleid);
689 688
 			$ruleDetail=$dbConn->fetchRow($query);
@@ -700,7 +699,7 @@  discard block
 block discarded – undo
700 699
 	}
701 700
 
702 701
 	/** Setup tabs for rules 
703
-	*/
702
+	 */
704 703
 	protected function prepareTabs()
705 704
 	{
706 705
 		return $this->getTabs()->add('status', array(
Please login to merge, or discard this patch.
application/controllers/HelperController.php 3 patches
Indentation   +151 added lines, -151 removed lines patch added patch discarded remove patch
@@ -12,8 +12,8 @@  discard block
 block discarded – undo
12 12
 {
13 13
 	
14 14
 	/** Get host list with filter (IP or name) : host=<filter>
15
-	*	returns in JSON : status=>OK/NOK  hosts=>array of hosts
16
-	*/
15
+	 *	returns in JSON : status=>OK/NOK  hosts=>array of hosts
16
+	 */
17 17
 	public function gethostsAction()
18 18
 	{
19 19
 		$postData=$this->getRequest()->getPost();
@@ -22,15 +22,15 @@  discard block
 block discarded – undo
22 22
 		
23 23
 		$retHosts=array('status'=>'OK','hosts' => array());
24 24
 		$this->getIdoConn(); // set apiMode to correct val
25
-        if ($this->apiMode === TRUE)
26
-        {
27
-          $hosts=$this->getIdoConn()->getHostByNameOrIP($hostFilter);
28
-          $retHosts['test']=count($hosts);
29
-        }
30
-        else 
31
-        {
25
+		if ($this->apiMode === TRUE)
26
+		{
27
+		  $hosts=$this->getIdoConn()->getHostByNameOrIP($hostFilter);
28
+		  $retHosts['test']=count($hosts);
29
+		}
30
+		else 
31
+		{
32 32
 		  $hosts=$this->getIdoConn()->getHostByIP($hostFilter);
33
-        }
33
+		}
34 34
 		foreach ($hosts as $val)
35 35
 		{
36 36
 			array_push($retHosts['hosts'],$val->name);
@@ -40,8 +40,8 @@  discard block
 block discarded – undo
40 40
 	}
41 41
 	
42 42
 	/** Get hostgroup list with filter (name) : hostgroup=<hostFilter>
43
-	*	returns in JSON : status=>OK/NOK  hosts=>array of hosts
44
-	*/
43
+	 *	returns in JSON : status=>OK/NOK  hosts=>array of hosts
44
+	 */
45 45
 	public function gethostgroupsAction()
46 46
 	{
47 47
 		$postData=$this->getRequest()->getPost();
@@ -60,11 +60,11 @@  discard block
 block discarded – undo
60 60
 	}
61 61
 	
62 62
 	/** Get service list by host name ( host=<host> )
63
-	*	returns in JSON : 
64
-	*		status=>OK/No services found/More than one host matches
65
-	*		services=>array of services (name)
66
-	*		hostid = host object id or -1 if not found.
67
-	*/
63
+	 *	returns in JSON : 
64
+	 *		status=>OK/No services found/More than one host matches
65
+	 *		services=>array of services (name)
66
+	 *		hostid = host object id or -1 if not found.
67
+	 */
68 68
 	public function getservicesAction()
69 69
 	{
70 70
 		$postData=$this->getRequest()->getPost();
@@ -106,11 +106,11 @@  discard block
 block discarded – undo
106 106
 	}
107 107
 	
108 108
 	/** Get service list by host group ( name=<host> )
109
-	*	returns in JSON : 
110
-	*		status=>OK/No services found/More than one host matches
111
-	*		services=>array of services (name)
112
-	*		groupid = group object id or -1 if not found.
113
-	*/
109
+	 *	returns in JSON : 
110
+	 *		status=>OK/No services found/More than one host matches
111
+	 *		services=>array of services (name)
112
+	 *		groupid = group object id or -1 if not found.
113
+	 */
114 114
 	public function gethostgroupservicesAction()
115 115
 	{
116 116
 		$postData=$this->getRequest()->getPost();
@@ -140,10 +140,10 @@  discard block
 block discarded – undo
140 140
 	}
141 141
 
142 142
 	/** Get traps from mib  : entry : mib=<mib>
143
-	*	returns in JSON : 
144
-	*		status=>OK/No mib/Error getting mibs
145
-	*		traps=>array of array( oid -> name)
146
-	*/
143
+	 *	returns in JSON : 
144
+	 *		status=>OK/No mib/Error getting mibs
145
+	 *		traps=>array of array( oid -> name)
146
+	 */
147 147
 	public function gettrapsAction()
148 148
 	{
149 149
 		$postData=$this->getRequest()->getPost();
@@ -163,10 +163,10 @@  discard block
 block discarded – undo
163 163
 	}	
164 164
 
165 165
 	/** Get trap objects from mib  : entry : trap=<oid>
166
-	*	returns in JSON : 
167
-	*		status=>OK/no trap/not found
168
-	*		objects=>array of array( oid -> name, oid->mib)
169
-	*/
166
+	 *	returns in JSON : 
167
+	 *		status=>OK/no trap/not found
168
+	 *		objects=>array of array( oid -> name, oid->mib)
169
+	 */
170 170
 	public function gettrapobjectsAction()
171 171
 	{
172 172
 		$postData=$this->getRequest()->getPost();
@@ -186,8 +186,8 @@  discard block
 block discarded – undo
186 186
 	}	
187 187
 	
188 188
 	/** Get list of all loaded mibs : entry : none
189
-	*	return : array of strings.
190
-	*/
189
+	 *	return : array of strings.
190
+	 */
191 191
 	public function getmiblistAction()
192 192
 	{
193 193
 		try
@@ -202,10 +202,10 @@  discard block
 block discarded – undo
202 202
 	}
203 203
 	
204 204
 	/** Get MIB::Name from OID : entry : oid
205
-	*		status=>OK/No oid/not found
206
-	*		mib=>string
207
-	*		name=>string
208
-	*/	
205
+	 *		status=>OK/No oid/not found
206
+	 *		mib=>string
207
+	 *		name=>string
208
+	 */	
209 209
 	public function translateoidAction()
210 210
 	{
211 211
 		$postData=$this->getRequest()->getPost();
@@ -226,7 +226,7 @@  discard block
 block discarded – undo
226 226
 					'name' => $object['name'],
227 227
 					'type' => $object['type'],
228 228
 					'type_enum' => $object['type_enum'],
229
-				    'description' => $object['description']
229
+					'description' => $object['description']
230 230
 				)
231 231
 			);
232 232
 		}
@@ -234,10 +234,10 @@  discard block
 block discarded – undo
234 234
 	}
235 235
 	
236 236
 	/** Save or execute database purge of <n> days
237
-	*	days=>int 
238
-	*	action=>save/execute
239
-	*	return : status=>OK/Message error
240
-	*/
237
+	 *	days=>int 
238
+	 *	action=>save/execute
239
+	 *	return : status=>OK/Message error
240
+	 */
241 241
 	public function dbmaintenanceAction()
242 242
 	{
243 243
 		
@@ -252,7 +252,7 @@  discard block
 block discarded – undo
252 252
 		{
253 253
 			try
254 254
 			{
255
-			    $this->getUIDatabase()->setDBConfigValue('db_remove_days',$days);
255
+				$this->getUIDatabase()->setDBConfigValue('db_remove_days',$days);
256 256
 			}
257 257
 			catch (Exception $e)
258 258
 			{
@@ -290,33 +290,33 @@  discard block
 block discarded – undo
290 290
 	 */
291 291
 	public function snmpconfigAction()
292 292
 	{
293
-	    $postData=$this->getRequest()->getPost();
293
+		$postData=$this->getRequest()->getPost();
294 294
 	    
295
-	    $snmpUse = $this->checkPostVar($postData, 'useTrapAddr', '0|1');
295
+		$snmpUse = $this->checkPostVar($postData, 'useTrapAddr', '0|1');
296 296
 	    
297
-	    $snmpOID = $this->checkPostVar($postData, 'trapAddrOID', '^[\.0-9]+$');
297
+		$snmpOID = $this->checkPostVar($postData, 'trapAddrOID', '^[\.0-9]+$');
298 298
 	    	    
299
-	    try
300
-	    {
301
-	        $this->getUIDatabase()->setDBConfigValue('use_SnmpTrapAddess',$snmpUse);
302
-	        $this->getUIDatabase()->setDBConfigValue('SnmpTrapAddess_oid',$snmpOID);
303
-	    }
304
-	    catch (Exception $e)
305
-	    {
306
-	        $this->_helper->json(array('status'=>'Save error : '.$e->getMessage() ));
307
-	        return;
308
-	    }
309
-	    $this->_helper->json(array('status'=>'OK'));
310
-	    return;
299
+		try
300
+		{
301
+			$this->getUIDatabase()->setDBConfigValue('use_SnmpTrapAddess',$snmpUse);
302
+			$this->getUIDatabase()->setDBConfigValue('SnmpTrapAddess_oid',$snmpOID);
303
+		}
304
+		catch (Exception $e)
305
+		{
306
+			$this->_helper->json(array('status'=>'Save error : '.$e->getMessage() ));
307
+			return;
308
+		}
309
+		$this->_helper->json(array('status'=>'OK'));
310
+		return;
311 311
 	    
312 312
 	}
313 313
 	
314 314
 	/** Save log output to db
315
-	*	destination=>log destination 
316
-	*	file=>file name
317
-	*	level => int 
318
-	*	return : status=>OK/Message error
319
-	*/
315
+	 *	destination=>log destination 
316
+	 *	file=>file name
317
+	 *	level => int 
318
+	 *	return : status=>OK/Message error
319
+	 */
320 320
 	public function logdestinationAction()
321 321
 	{
322 322
 		$postData=$this->getRequest()->getPost();
@@ -335,8 +335,8 @@  discard block
 block discarded – undo
335 335
 			$fileHandler=@fopen($file,'w');
336 336
 			if ($fileHandler == false)
337 337
 			{   // File os note writabe / cannot create
338
-			    $this->_helper->json(array('status'=>'File not writable :  '.$file));
339
-			    return;
338
+				$this->_helper->json(array('status'=>'File not writable :  '.$file));
339
+				return;
340 340
 			}
341 341
 		}
342 342
 		else
@@ -356,9 +356,9 @@  discard block
 block discarded – undo
356 356
 				
357 357
 		try
358 358
 		{
359
-		    $this->getUIDatabase()->setDBConfigValue('log_destination',$destination);
360
-		    $this->getUIDatabase()->setDBConfigValue('log_file',$file);
361
-		    $this->getUIDatabase()->setDBConfigValue('log_level',$level);
359
+			$this->getUIDatabase()->setDBConfigValue('log_destination',$destination);
360
+			$this->getUIDatabase()->setDBConfigValue('log_file',$file);
361
+			$this->getUIDatabase()->setDBConfigValue('log_level',$level);
362 362
 		}
363 363
 		catch (Exception $e)
364 364
 		{
@@ -378,33 +378,33 @@  discard block
 block discarded – undo
378 378
 	public function testruleAction()
379 379
 	{
380 380
 	    
381
-	    $postData=$this->getRequest()->getPost();
381
+		$postData=$this->getRequest()->getPost();
382 382
 	   
383
-	    $rule = $this->checkPostVar($postData, 'rule', '.*');
383
+		$rule = $this->checkPostVar($postData, 'rule', '.*');
384 384
 
385
-	    $action = $this->checkPostVar($postData, 'action', 'evaluate');
385
+		$action = $this->checkPostVar($postData, 'action', 'evaluate');
386 386
 
387
-	    if ($action == 'evaluate')
388
-	    {
389
-	        try
390
-	        {
391
-	            require_once($this->Module()->getBaseDir() .'/bin/trap_class.php');
392
-	            $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc');
393
-	            $trap = new Trap($icingaweb2_etc);
394
-	            // Cleanup spaces before eval
395
-	            $rule=$trap->ruleClass->eval_cleanup($rule);
396
-	            // Eval
397
-	            $item=0;
398
-	            $rule=$trap->ruleClass->evaluation($rule,$item);
399
-	        }
400
-	        catch (Exception $e)
401
-	        {
402
-	            $this->_helper->json(array('status'=>'Evaluation error : '.$e->getMessage() ));
403
-	            return;
404
-	        }
405
-	        $return=($rule==true)?'true':'false';
406
-	        $this->_helper->json(array('status'=>'OK', 'message' => $return));
407
-	    }
387
+		if ($action == 'evaluate')
388
+		{
389
+			try
390
+			{
391
+				require_once($this->Module()->getBaseDir() .'/bin/trap_class.php');
392
+				$icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc');
393
+				$trap = new Trap($icingaweb2_etc);
394
+				// Cleanup spaces before eval
395
+				$rule=$trap->ruleClass->eval_cleanup($rule);
396
+				// Eval
397
+				$item=0;
398
+				$rule=$trap->ruleClass->evaluation($rule,$item);
399
+			}
400
+			catch (Exception $e)
401
+			{
402
+				$this->_helper->json(array('status'=>'Evaluation error : '.$e->getMessage() ));
403
+				return;
404
+			}
405
+			$return=($rule==true)?'true':'false';
406
+			$this->_helper->json(array('status'=>'OK', 'message' => $return));
407
+		}
408 408
 	    
409 409
 	}	
410 410
 
@@ -415,35 +415,35 @@  discard block
 block discarded – undo
415 415
 	 */
416 416
 	public function pluginAction()
417 417
 	{
418
-	    $postData=$this->getRequest()->getPost();
418
+		$postData=$this->getRequest()->getPost();
419 419
 	    
420
-	    $pluginName = $this->checkPostVar($postData, 'name', '.*');
420
+		$pluginName = $this->checkPostVar($postData, 'name', '.*');
421 421
 	    
422
-	    $action = $this->checkPostVar($postData, 'action', 'enable|disable');
422
+		$action = $this->checkPostVar($postData, 'action', 'enable|disable');
423 423
 	    
424
-        try
425
-        {
426
-            require_once($this->Module()->getBaseDir() .'/bin/trap_class.php');
427
-            $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc');
428
-            $trap = new Trap($icingaweb2_etc);
429
-            // Enable plugin.
430
-            $action=($action == 'enable') ? true : false;
431
-            $retVal=$trap->pluginClass->enablePlugin($pluginName, $action);
424
+		try
425
+		{
426
+			require_once($this->Module()->getBaseDir() .'/bin/trap_class.php');
427
+			$icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc');
428
+			$trap = new Trap($icingaweb2_etc);
429
+			// Enable plugin.
430
+			$action=($action == 'enable') ? true : false;
431
+			$retVal=$trap->pluginClass->enablePlugin($pluginName, $action);
432 432
             
433
-        }
434
-        catch (Exception $e)
435
-        {
436
-            $this->_helper->json(array('status'=>'Action error : '.$e->getMessage() ));
437
-            return;
438
-        }
439
-        if ($retVal === true)
440
-        {
441
-            $this->_helper->json(array('status'=>'OK'));
442
-        }
443
-        else
444
-        {
445
-            $this->_helper->json(array('status'=>'Error, see logs'));
446
-        }
433
+		}
434
+		catch (Exception $e)
435
+		{
436
+			$this->_helper->json(array('status'=>'Action error : '.$e->getMessage() ));
437
+			return;
438
+		}
439
+		if ($retVal === true)
440
+		{
441
+			$this->_helper->json(array('status'=>'OK'));
442
+		}
443
+		else
444
+		{
445
+			$this->_helper->json(array('status'=>'Error, see logs'));
446
+		}
447 447
 	}
448 448
 	
449 449
 	/** Function evaluation
@@ -453,49 +453,49 @@  discard block
 block discarded – undo
453 453
 	 */
454 454
 	public function functionAction()
455 455
 	{
456
-	    $postData=$this->getRequest()->getPost();
456
+		$postData=$this->getRequest()->getPost();
457 457
 	    
458
-	    $functionString = $this->checkPostVar($postData, 'function', '.*');
458
+		$functionString = $this->checkPostVar($postData, 'function', '.*');
459 459
 	    
460
-	    $this->checkPostVar($postData, 'action', 'evaluate');
460
+		$this->checkPostVar($postData, 'action', 'evaluate');
461 461
 	    
462
-	    // Only one action possible for now, no tests on action.
463
-	    try
464
-	    {
465
-	        require_once($this->Module()->getBaseDir() .'/bin/trap_class.php');
466
-	        $icingaweb2Etc=$this->Config()->get('config', 'icingaweb2_etc');
467
-	        $trap = new Trap($icingaweb2Etc);
468
-	        // load all plugins in case tested function is not enabled.
469
-	        $trap->pluginClass->registerAllPlugins(false);
470
-	        // Clean all spaces
471
-	        $functionString = $trap->ruleClass->eval_cleanup($functionString);
472
-	        // Eval functions
473
-	        $result = $trap->pluginClass->evaluateFunctionString($functionString);	        
474
-	    }
475
-	    catch (Exception $e)
476
-	    {
477
-	        $this->_helper->json(array('status'=>'Action error : '.$e->getMessage() ));
478
-	        return;
479
-	    }
462
+		// Only one action possible for now, no tests on action.
463
+		try
464
+		{
465
+			require_once($this->Module()->getBaseDir() .'/bin/trap_class.php');
466
+			$icingaweb2Etc=$this->Config()->get('config', 'icingaweb2_etc');
467
+			$trap = new Trap($icingaweb2Etc);
468
+			// load all plugins in case tested function is not enabled.
469
+			$trap->pluginClass->registerAllPlugins(false);
470
+			// Clean all spaces
471
+			$functionString = $trap->ruleClass->eval_cleanup($functionString);
472
+			// Eval functions
473
+			$result = $trap->pluginClass->evaluateFunctionString($functionString);	        
474
+		}
475
+		catch (Exception $e)
476
+		{
477
+			$this->_helper->json(array('status'=>'Action error : '.$e->getMessage() ));
478
+			return;
479
+		}
480 480
 	    
481
-        $result = ($result === true)?'True':'False';
482
-        $this->_helper->json(array('status'=>'OK','message' => $result));
481
+		$result = ($result === true)?'True':'False';
482
+		$this->_helper->json(array('status'=>'OK','message' => $result));
483 483
 	}
484 484
 
485
-    /**************   Utilities **********************/
485
+	/**************   Utilities **********************/
486 486
 
487 487
 	private function checkPostVar(array $postData,string $postVar, string $validRegexp) : string
488 488
 	{
489
-	    if (!isset ($postData[$postVar]))
490
-	    {
491
-	        $this->_helper->json(array('status'=>'No ' . $postVar));
492
-	        return '';
493
-	    }
494
-	    if (preg_match('/'.$validRegexp.'/', $postData[$postVar]) != 1)
495
-	    {
496
-	        $this->_helper->json(array('status'=>'Unknown ' . $postVar . ' value '.$postData[$postVar]));
497
-	        return '';
498
-	    }
499
-	    return $postData[$postVar];
489
+		if (!isset ($postData[$postVar]))
490
+		{
491
+			$this->_helper->json(array('status'=>'No ' . $postVar));
492
+			return '';
493
+		}
494
+		if (preg_match('/'.$validRegexp.'/', $postData[$postVar]) != 1)
495
+		{
496
+			$this->_helper->json(array('status'=>'Unknown ' . $postVar . ' value '.$postData[$postVar]));
497
+			return '';
498
+		}
499
+		return $postData[$postVar];
500 500
 	}
501 501
 }
Please login to merge, or discard this patch.
Spacing   +65 added lines, -65 removed lines patch added patch discarded remove patch
@@ -18,9 +18,9 @@  discard block
 block discarded – undo
18 18
 	{
19 19
 		$postData=$this->getRequest()->getPost();
20 20
 		
21
-		$hostFilter = $this->checkPostVar($postData, 'hostFilter', '.*');
21
+		$hostFilter=$this->checkPostVar($postData, 'hostFilter', '.*');
22 22
 		
23
-		$retHosts=array('status'=>'OK','hosts' => array());
23
+		$retHosts=array('status'=>'OK', 'hosts' => array());
24 24
 		$this->getIdoConn(); // set apiMode to correct val
25 25
         if ($this->apiMode === TRUE)
26 26
         {
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
         }
34 34
 		foreach ($hosts as $val)
35 35
 		{
36
-			array_push($retHosts['hosts'],$val->name);
36
+			array_push($retHosts['hosts'], $val->name);
37 37
 		}
38 38
 		
39 39
 		$this->_helper->json($retHosts);
@@ -46,14 +46,14 @@  discard block
 block discarded – undo
46 46
 	{
47 47
 		$postData=$this->getRequest()->getPost();
48 48
 		
49
-		$hostFilter = $this->checkPostVar($postData, 'hostFilter', '.*');
49
+		$hostFilter=$this->checkPostVar($postData, 'hostFilter', '.*');
50 50
 		
51
-		$retHosts=array('status'=>'OK','hosts' => array());
51
+		$retHosts=array('status'=>'OK', 'hosts' => array());
52 52
 
53 53
 		$hosts=$this->getIdoConn()->getHostGroupByName($hostFilter);
54 54
 		foreach ($hosts as $val)
55 55
 		{
56
-			array_push($retHosts['hosts'],$val->name);
56
+			array_push($retHosts['hosts'], $val->name);
57 57
 		}
58 58
 		
59 59
 		$this->_helper->json($retHosts);
@@ -76,31 +76,31 @@  discard block
 block discarded – undo
76 76
 		}
77 77
 		else
78 78
 		{
79
-			$this->_helper->json(array('status'=>'No Hosts','hostid' => -1));
79
+			$this->_helper->json(array('status'=>'No Hosts', 'hostid' => -1));
80 80
 			return;
81 81
 		}
82 82
 		
83 83
 		$hostArray=$this->getIdoConn()->getHostByName($host);
84 84
 		if (count($hostArray) > 1)
85 85
 		{	
86
-			$this->_helper->json(array('status'=>'More than one host matches','hostid' => -1));
86
+			$this->_helper->json(array('status'=>'More than one host matches', 'hostid' => -1));
87 87
 			return;
88 88
 		}
89 89
 		else if (count($hostArray) == 0)
90 90
 		{
91
-			$this->_helper->json(array('status'=>'No host matches','hostid' => -1));
91
+			$this->_helper->json(array('status'=>'No host matches', 'hostid' => -1));
92 92
 			return;
93 93
 		}
94 94
 		$services=$this->getIdoConn()->getServicesByHostid($hostArray[0]->id);
95 95
 		if (count($services) < 1)
96 96
 		{
97
-			$this->_helper->json(array('status'=>'No services found for host','hostid' => $hostArray[0]->id));
97
+			$this->_helper->json(array('status'=>'No services found for host', 'hostid' => $hostArray[0]->id));
98 98
 			return;
99 99
 		}
100
-		$retServices=array('status'=>'OK','services' => array(),'hostid' => $hostArray[0]->id);
100
+		$retServices=array('status'=>'OK', 'services' => array(), 'hostid' => $hostArray[0]->id);
101 101
 		foreach ($services as $val)
102 102
 		{
103
-			array_push($retServices['services'],array($val->id , $val->name));
103
+			array_push($retServices['services'], array($val->id, $val->name));
104 104
 		}
105 105
 		$this->_helper->json($retServices);
106 106
 	}
@@ -115,26 +115,26 @@  discard block
 block discarded – undo
115 115
 	{
116 116
 		$postData=$this->getRequest()->getPost();
117 117
 		
118
-		$host = $this->checkPostVar($postData, 'host', '.+');
118
+		$host=$this->checkPostVar($postData, 'host', '.+');
119 119
 		
120 120
 		$hostArray=$this->getIdoConn()->getHostGroupByName($host);
121 121
 		if (count($hostArray) > 1)
122 122
 		{	
123
-			$this->_helper->json(array('status'=>'More than one hostgroup matches','hostid' => -1));
123
+			$this->_helper->json(array('status'=>'More than one hostgroup matches', 'hostid' => -1));
124 124
 			return;
125 125
 		}
126 126
 		else if (count($hostArray) == 0)
127 127
 		{
128
-			$this->_helper->json(array('status'=>'No hostgroup matches','hostid' => -1));
128
+			$this->_helper->json(array('status'=>'No hostgroup matches', 'hostid' => -1));
129 129
 			return;
130 130
 		}
131 131
 		$services=$this->getIdoConn()->getServicesByHostGroupid($hostArray[0]->id);
132 132
 		if (count($services) < 1)
133 133
 		{
134
-			$this->_helper->json(array('status'=>'No services found for hostgroup','hostid' => $hostArray[0]->id));
134
+			$this->_helper->json(array('status'=>'No services found for hostgroup', 'hostid' => $hostArray[0]->id));
135 135
 			return;
136 136
 		}
137
-		$retServices=array('status'=>'OK','services' => $services,'hostid' => $hostArray[0]->id);
137
+		$retServices=array('status'=>'OK', 'services' => $services, 'hostid' => $hostArray[0]->id);
138 138
 		
139 139
 		$this->_helper->json($retServices);
140 140
 	}
@@ -148,12 +148,12 @@  discard block
 block discarded – undo
148 148
 	{
149 149
 		$postData=$this->getRequest()->getPost();
150 150
 		
151
-		$mib = $this->checkPostVar($postData, 'mib', '.*');
151
+		$mib=$this->checkPostVar($postData, 'mib', '.*');
152 152
 
153 153
 		try
154 154
 		{
155 155
 			$traplist=$this->getMIB()->getTrapList($mib);
156
-			$retTraps=array('status'=>'OK','traps' => $traplist);
156
+			$retTraps=array('status'=>'OK', 'traps' => $traplist);
157 157
 		} 
158 158
 		catch (Exception $e) 
159 159
 		{ 
@@ -171,12 +171,12 @@  discard block
 block discarded – undo
171 171
 	{
172 172
 		$postData=$this->getRequest()->getPost();
173 173
 		
174
-		$trap = $this->checkPostVar($postData, 'trap', '.*');
174
+		$trap=$this->checkPostVar($postData, 'trap', '.*');
175 175
 		
176 176
 		try
177 177
 		{
178 178
 			$objectlist=$this->getMIB()->getObjectList($trap);
179
-			$retObjects=array('status'=>'OK','objects' => $objectlist);
179
+			$retObjects=array('status'=>'OK', 'objects' => $objectlist);
180 180
 		} 
181 181
 		catch (Exception $e) 
182 182
 		{ 
@@ -210,7 +210,7 @@  discard block
 block discarded – undo
210 210
 	{
211 211
 		$postData=$this->getRequest()->getPost();
212 212
 		
213
-		$oid = $this->checkPostVar($postData, 'oid', '.*');
213
+		$oid=$this->checkPostVar($postData, 'oid', '.*');
214 214
 		
215 215
 		// Try to get oid name from snmptranslate
216 216
 		if (($object=$this->getMIB()->translateOID($oid)) == null)
@@ -243,20 +243,20 @@  discard block
 block discarded – undo
243 243
 		
244 244
 		$postData=$this->getRequest()->getPost();
245 245
 		
246
-		$days = $this->checkPostVar($postData, 'days', '^[0-9]+$');
246
+		$days=$this->checkPostVar($postData, 'days', '^[0-9]+$');
247 247
 		$days=intval($days);
248 248
 
249
-		$action = $this->checkPostVar($postData, 'action', 'save|execute');
249
+		$action=$this->checkPostVar($postData, 'action', 'save|execute');
250 250
 		
251 251
 		if ($action == 'save')
252 252
 		{
253 253
 			try
254 254
 			{
255
-			    $this->getUIDatabase()->setDBConfigValue('db_remove_days',$days);
255
+			    $this->getUIDatabase()->setDBConfigValue('db_remove_days', $days);
256 256
 			}
257 257
 			catch (Exception $e)
258 258
 			{
259
-				$this->_helper->json(array('status'=>'Save error : '.$e->getMessage() ));
259
+				$this->_helper->json(array('status'=>'Save error : '.$e->getMessage()));
260 260
 				return;
261 261
 			}
262 262
 			$this->_helper->json(array('status'=>'OK'));
@@ -266,16 +266,16 @@  discard block
 block discarded – undo
266 266
 		{
267 267
 			try
268 268
 			{
269
-				require_once($this->Module()->getBaseDir() .'/bin/trap_class.php');
269
+				require_once($this->Module()->getBaseDir().'/bin/trap_class.php');
270 270
 				$icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc');
271 271
 				$debug_level=4;
272
-				$trap = new Trap($icingaweb2_etc);
273
-				$trap->setLogging($debug_level,'syslog');
272
+				$trap=new Trap($icingaweb2_etc);
273
+				$trap->setLogging($debug_level, 'syslog');
274 274
 				$trap->eraseOldTraps($days);
275 275
 			}
276 276
 			catch (Exception $e)
277 277
 			{
278
-				$this->_helper->json(array('status'=>'execute error : '.$e->getMessage() ));
278
+				$this->_helper->json(array('status'=>'execute error : '.$e->getMessage()));
279 279
 				return;
280 280
 			}			
281 281
 			$this->_helper->json(array('status'=>'OK'));
@@ -292,18 +292,18 @@  discard block
 block discarded – undo
292 292
 	{
293 293
 	    $postData=$this->getRequest()->getPost();
294 294
 	    
295
-	    $snmpUse = $this->checkPostVar($postData, 'useTrapAddr', '0|1');
295
+	    $snmpUse=$this->checkPostVar($postData, 'useTrapAddr', '0|1');
296 296
 	    
297
-	    $snmpOID = $this->checkPostVar($postData, 'trapAddrOID', '^[\.0-9]+$');
297
+	    $snmpOID=$this->checkPostVar($postData, 'trapAddrOID', '^[\.0-9]+$');
298 298
 	    	    
299 299
 	    try
300 300
 	    {
301
-	        $this->getUIDatabase()->setDBConfigValue('use_SnmpTrapAddess',$snmpUse);
302
-	        $this->getUIDatabase()->setDBConfigValue('SnmpTrapAddess_oid',$snmpOID);
301
+	        $this->getUIDatabase()->setDBConfigValue('use_SnmpTrapAddess', $snmpUse);
302
+	        $this->getUIDatabase()->setDBConfigValue('SnmpTrapAddess_oid', $snmpOID);
303 303
 	    }
304 304
 	    catch (Exception $e)
305 305
 	    {
306
-	        $this->_helper->json(array('status'=>'Save error : '.$e->getMessage() ));
306
+	        $this->_helper->json(array('status'=>'Save error : '.$e->getMessage()));
307 307
 	        return;
308 308
 	    }
309 309
 	    $this->_helper->json(array('status'=>'OK'));
@@ -321,7 +321,7 @@  discard block
 block discarded – undo
321 321
 	{
322 322
 		$postData=$this->getRequest()->getPost();
323 323
 		
324
-		$destination = $this->checkPostVar($postData, 'destination', '.*');
324
+		$destination=$this->checkPostVar($postData, 'destination', '.*');
325 325
 		$logDest=$this->getModuleConfig()->getLogDestinations();
326 326
 		if (!isset($logDest[$destination]))
327 327
 		{
@@ -332,7 +332,7 @@  discard block
 block discarded – undo
332 332
 		if (isset($postData['file']))
333 333
 		{ 
334 334
 			$file=$postData['file'];
335
-			$fileHandler=@fopen($file,'w');
335
+			$fileHandler=@fopen($file, 'w');
336 336
 			if ($fileHandler == false)
337 337
 			{   // File os note writabe / cannot create
338 338
 			    $this->_helper->json(array('status'=>'File not writable :  '.$file));
@@ -352,17 +352,17 @@  discard block
 block discarded – undo
352 352
 			}
353 353
 		}
354 354
 
355
-		$level = $this->checkPostVar($postData, 'level', '[0-9]');
355
+		$level=$this->checkPostVar($postData, 'level', '[0-9]');
356 356
 				
357 357
 		try
358 358
 		{
359
-		    $this->getUIDatabase()->setDBConfigValue('log_destination',$destination);
360
-		    $this->getUIDatabase()->setDBConfigValue('log_file',$file);
361
-		    $this->getUIDatabase()->setDBConfigValue('log_level',$level);
359
+		    $this->getUIDatabase()->setDBConfigValue('log_destination', $destination);
360
+		    $this->getUIDatabase()->setDBConfigValue('log_file', $file);
361
+		    $this->getUIDatabase()->setDBConfigValue('log_level', $level);
362 362
 		}
363 363
 		catch (Exception $e)
364 364
 		{
365
-			$this->_helper->json(array('status'=>'Save error : '.$e->getMessage() ));
365
+			$this->_helper->json(array('status'=>'Save error : '.$e->getMessage()));
366 366
 			return;
367 367
 		}
368 368
 		$this->_helper->json(array('status'=>'OK'));
@@ -380,29 +380,29 @@  discard block
 block discarded – undo
380 380
 	    
381 381
 	    $postData=$this->getRequest()->getPost();
382 382
 	   
383
-	    $rule = $this->checkPostVar($postData, 'rule', '.*');
383
+	    $rule=$this->checkPostVar($postData, 'rule', '.*');
384 384
 
385
-	    $action = $this->checkPostVar($postData, 'action', 'evaluate');
385
+	    $action=$this->checkPostVar($postData, 'action', 'evaluate');
386 386
 
387 387
 	    if ($action == 'evaluate')
388 388
 	    {
389 389
 	        try
390 390
 	        {
391
-	            require_once($this->Module()->getBaseDir() .'/bin/trap_class.php');
391
+	            require_once($this->Module()->getBaseDir().'/bin/trap_class.php');
392 392
 	            $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc');
393
-	            $trap = new Trap($icingaweb2_etc);
393
+	            $trap=new Trap($icingaweb2_etc);
394 394
 	            // Cleanup spaces before eval
395 395
 	            $rule=$trap->ruleClass->eval_cleanup($rule);
396 396
 	            // Eval
397 397
 	            $item=0;
398
-	            $rule=$trap->ruleClass->evaluation($rule,$item);
398
+	            $rule=$trap->ruleClass->evaluation($rule, $item);
399 399
 	        }
400 400
 	        catch (Exception $e)
401 401
 	        {
402
-	            $this->_helper->json(array('status'=>'Evaluation error : '.$e->getMessage() ));
402
+	            $this->_helper->json(array('status'=>'Evaluation error : '.$e->getMessage()));
403 403
 	            return;
404 404
 	        }
405
-	        $return=($rule==true)?'true':'false';
405
+	        $return=($rule == true) ? 'true' : 'false';
406 406
 	        $this->_helper->json(array('status'=>'OK', 'message' => $return));
407 407
 	    }
408 408
 	    
@@ -417,15 +417,15 @@  discard block
 block discarded – undo
417 417
 	{
418 418
 	    $postData=$this->getRequest()->getPost();
419 419
 	    
420
-	    $pluginName = $this->checkPostVar($postData, 'name', '.*');
420
+	    $pluginName=$this->checkPostVar($postData, 'name', '.*');
421 421
 	    
422
-	    $action = $this->checkPostVar($postData, 'action', 'enable|disable');
422
+	    $action=$this->checkPostVar($postData, 'action', 'enable|disable');
423 423
 	    
424 424
         try
425 425
         {
426
-            require_once($this->Module()->getBaseDir() .'/bin/trap_class.php');
426
+            require_once($this->Module()->getBaseDir().'/bin/trap_class.php');
427 427
             $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc');
428
-            $trap = new Trap($icingaweb2_etc);
428
+            $trap=new Trap($icingaweb2_etc);
429 429
             // Enable plugin.
430 430
             $action=($action == 'enable') ? true : false;
431 431
             $retVal=$trap->pluginClass->enablePlugin($pluginName, $action);
@@ -433,7 +433,7 @@  discard block
 block discarded – undo
433 433
         }
434 434
         catch (Exception $e)
435 435
         {
436
-            $this->_helper->json(array('status'=>'Action error : '.$e->getMessage() ));
436
+            $this->_helper->json(array('status'=>'Action error : '.$e->getMessage()));
437 437
             return;
438 438
         }
439 439
         if ($retVal === true)
@@ -455,45 +455,45 @@  discard block
 block discarded – undo
455 455
 	{
456 456
 	    $postData=$this->getRequest()->getPost();
457 457
 	    
458
-	    $functionString = $this->checkPostVar($postData, 'function', '.*');
458
+	    $functionString=$this->checkPostVar($postData, 'function', '.*');
459 459
 	    
460 460
 	    $this->checkPostVar($postData, 'action', 'evaluate');
461 461
 	    
462 462
 	    // Only one action possible for now, no tests on action.
463 463
 	    try
464 464
 	    {
465
-	        require_once($this->Module()->getBaseDir() .'/bin/trap_class.php');
465
+	        require_once($this->Module()->getBaseDir().'/bin/trap_class.php');
466 466
 	        $icingaweb2Etc=$this->Config()->get('config', 'icingaweb2_etc');
467
-	        $trap = new Trap($icingaweb2Etc);
467
+	        $trap=new Trap($icingaweb2Etc);
468 468
 	        // load all plugins in case tested function is not enabled.
469 469
 	        $trap->pluginClass->registerAllPlugins(false);
470 470
 	        // Clean all spaces
471
-	        $functionString = $trap->ruleClass->eval_cleanup($functionString);
471
+	        $functionString=$trap->ruleClass->eval_cleanup($functionString);
472 472
 	        // Eval functions
473
-	        $result = $trap->pluginClass->evaluateFunctionString($functionString);	        
473
+	        $result=$trap->pluginClass->evaluateFunctionString($functionString);	        
474 474
 	    }
475 475
 	    catch (Exception $e)
476 476
 	    {
477
-	        $this->_helper->json(array('status'=>'Action error : '.$e->getMessage() ));
477
+	        $this->_helper->json(array('status'=>'Action error : '.$e->getMessage()));
478 478
 	        return;
479 479
 	    }
480 480
 	    
481
-        $result = ($result === true)?'True':'False';
482
-        $this->_helper->json(array('status'=>'OK','message' => $result));
481
+        $result=($result === true) ? 'True' : 'False';
482
+        $this->_helper->json(array('status'=>'OK', 'message' => $result));
483 483
 	}
484 484
 
485 485
     /**************   Utilities **********************/
486 486
 
487
-	private function checkPostVar(array $postData,string $postVar, string $validRegexp) : string
487
+	private function checkPostVar(array $postData, string $postVar, string $validRegexp) : string
488 488
 	{
489 489
 	    if (!isset ($postData[$postVar]))
490 490
 	    {
491
-	        $this->_helper->json(array('status'=>'No ' . $postVar));
491
+	        $this->_helper->json(array('status'=>'No '.$postVar));
492 492
 	        return '';
493 493
 	    }
494 494
 	    if (preg_match('/'.$validRegexp.'/', $postData[$postVar]) != 1)
495 495
 	    {
496
-	        $this->_helper->json(array('status'=>'Unknown ' . $postVar . ' value '.$postData[$postVar]));
496
+	        $this->_helper->json(array('status'=>'Unknown '.$postVar.' value '.$postData[$postVar]));
497 497
 	        return '';
498 498
 	    }
499 499
 	    return $postData[$postVar];
Please login to merge, or discard this patch.
Braces   +18 added lines, -36 removed lines patch added patch discarded remove patch
@@ -26,8 +26,7 @@  discard block
 block discarded – undo
26 26
         {
27 27
           $hosts=$this->getIdoConn()->getHostByNameOrIP($hostFilter);
28 28
           $retHosts['test']=count($hosts);
29
-        }
30
-        else 
29
+        } else 
31 30
         {
32 31
 		  $hosts=$this->getIdoConn()->getHostByIP($hostFilter);
33 32
         }
@@ -73,8 +72,7 @@  discard block
 block discarded – undo
73 72
 		if (isset($postData['host']))
74 73
 		{
75 74
 			$host=$postData['host'];
76
-		}
77
-		else
75
+		} else
78 76
 		{
79 77
 			$this->_helper->json(array('status'=>'No Hosts','hostid' => -1));
80 78
 			return;
@@ -85,8 +83,7 @@  discard block
 block discarded – undo
85 83
 		{	
86 84
 			$this->_helper->json(array('status'=>'More than one host matches','hostid' => -1));
87 85
 			return;
88
-		}
89
-		else if (count($hostArray) == 0)
86
+		} else if (count($hostArray) == 0)
90 87
 		{
91 88
 			$this->_helper->json(array('status'=>'No host matches','hostid' => -1));
92 89
 			return;
@@ -122,8 +119,7 @@  discard block
 block discarded – undo
122 119
 		{	
123 120
 			$this->_helper->json(array('status'=>'More than one hostgroup matches','hostid' => -1));
124 121
 			return;
125
-		}
126
-		else if (count($hostArray) == 0)
122
+		} else if (count($hostArray) == 0)
127 123
 		{
128 124
 			$this->_helper->json(array('status'=>'No hostgroup matches','hostid' => -1));
129 125
 			return;
@@ -154,8 +150,7 @@  discard block
 block discarded – undo
154 150
 		{
155 151
 			$traplist=$this->getMIB()->getTrapList($mib);
156 152
 			$retTraps=array('status'=>'OK','traps' => $traplist);
157
-		} 
158
-		catch (Exception $e) 
153
+		} catch (Exception $e) 
159 154
 		{ 
160 155
 			$retTraps=array('status' => 'Error getting mibs');
161 156
 		}
@@ -177,8 +172,7 @@  discard block
 block discarded – undo
177 172
 		{
178 173
 			$objectlist=$this->getMIB()->getObjectList($trap);
179 174
 			$retObjects=array('status'=>'OK','objects' => $objectlist);
180
-		} 
181
-		catch (Exception $e) 
175
+		} catch (Exception $e) 
182 176
 		{ 
183 177
 			$retObjects=array('status' => 'not found');
184 178
 		}
@@ -193,8 +187,7 @@  discard block
 block discarded – undo
193 187
 		try
194 188
 		{
195 189
 			$miblist=$this->getMIB()->getMIBList();
196
-		} 
197
-		catch (Exception $e) 
190
+		} catch (Exception $e) 
198 191
 		{ 
199 192
 			$miblist=array('Error getting mibs');
200 193
 		}
@@ -217,8 +210,7 @@  discard block
 block discarded – undo
217 210
 		{
218 211
 			$this->_helper->json(array('status'=>'Not found'));
219 212
 			return;
220
-		}
221
-		else
213
+		} else
222 214
 		{
223 215
 			$this->_helper->json(
224 216
 				array('status'=>'OK',
@@ -253,8 +245,7 @@  discard block
 block discarded – undo
253 245
 			try
254 246
 			{
255 247
 			    $this->getUIDatabase()->setDBConfigValue('db_remove_days',$days);
256
-			}
257
-			catch (Exception $e)
248
+			} catch (Exception $e)
258 249
 			{
259 250
 				$this->_helper->json(array('status'=>'Save error : '.$e->getMessage() ));
260 251
 				return;
@@ -272,8 +263,7 @@  discard block
 block discarded – undo
272 263
 				$trap = new Trap($icingaweb2_etc);
273 264
 				$trap->setLogging($debug_level,'syslog');
274 265
 				$trap->eraseOldTraps($days);
275
-			}
276
-			catch (Exception $e)
266
+			} catch (Exception $e)
277 267
 			{
278 268
 				$this->_helper->json(array('status'=>'execute error : '.$e->getMessage() ));
279 269
 				return;
@@ -300,8 +290,7 @@  discard block
 block discarded – undo
300 290
 	    {
301 291
 	        $this->getUIDatabase()->setDBConfigValue('use_SnmpTrapAddess',$snmpUse);
302 292
 	        $this->getUIDatabase()->setDBConfigValue('SnmpTrapAddess_oid',$snmpOID);
303
-	    }
304
-	    catch (Exception $e)
293
+	    } catch (Exception $e)
305 294
 	    {
306 295
 	        $this->_helper->json(array('status'=>'Save error : '.$e->getMessage() ));
307 296
 	        return;
@@ -338,14 +327,12 @@  discard block
 block discarded – undo
338 327
 			    $this->_helper->json(array('status'=>'File not writable :  '.$file));
339 328
 			    return;
340 329
 			}
341
-		}
342
-		else
330
+		} else
343 331
 		{
344 332
 			if ($destination != 'file')
345 333
 			{
346 334
 				$file=null;
347
-			}
348
-			else
335
+			} else
349 336
 			{
350 337
 				$this->_helper->json(array('status'=>'No file'));
351 338
 				return;
@@ -359,8 +346,7 @@  discard block
 block discarded – undo
359 346
 		    $this->getUIDatabase()->setDBConfigValue('log_destination',$destination);
360 347
 		    $this->getUIDatabase()->setDBConfigValue('log_file',$file);
361 348
 		    $this->getUIDatabase()->setDBConfigValue('log_level',$level);
362
-		}
363
-		catch (Exception $e)
349
+		} catch (Exception $e)
364 350
 		{
365 351
 			$this->_helper->json(array('status'=>'Save error : '.$e->getMessage() ));
366 352
 			return;
@@ -396,8 +382,7 @@  discard block
 block discarded – undo
396 382
 	            // Eval
397 383
 	            $item=0;
398 384
 	            $rule=$trap->ruleClass->evaluation($rule,$item);
399
-	        }
400
-	        catch (Exception $e)
385
+	        } catch (Exception $e)
401 386
 	        {
402 387
 	            $this->_helper->json(array('status'=>'Evaluation error : '.$e->getMessage() ));
403 388
 	            return;
@@ -430,8 +415,7 @@  discard block
 block discarded – undo
430 415
             $action=($action == 'enable') ? true : false;
431 416
             $retVal=$trap->pluginClass->enablePlugin($pluginName, $action);
432 417
             
433
-        }
434
-        catch (Exception $e)
418
+        } catch (Exception $e)
435 419
         {
436 420
             $this->_helper->json(array('status'=>'Action error : '.$e->getMessage() ));
437 421
             return;
@@ -439,8 +423,7 @@  discard block
 block discarded – undo
439 423
         if ($retVal === true)
440 424
         {
441 425
             $this->_helper->json(array('status'=>'OK'));
442
-        }
443
-        else
426
+        } else
444 427
         {
445 428
             $this->_helper->json(array('status'=>'Error, see logs'));
446 429
         }
@@ -471,8 +454,7 @@  discard block
 block discarded – undo
471 454
 	        $functionString = $trap->ruleClass->eval_cleanup($functionString);
472 455
 	        // Eval functions
473 456
 	        $result = $trap->pluginClass->evaluateFunctionString($functionString);	        
474
-	    }
475
-	    catch (Exception $e)
457
+	    } catch (Exception $e)
476 458
 	    {
477 459
 	        $this->_helper->json(array('status'=>'Action error : '.$e->getMessage() ));
478 460
 	        return;
Please login to merge, or discard this patch.