@@ -17,10 +17,10 @@ |
||
17 | 17 | class StatusCommand extends Command |
18 | 18 | { |
19 | 19 | /** |
20 | - * Get database counts |
|
21 | - * |
|
22 | - * Get number of traps, rules |
|
23 | - */ |
|
20 | + * Get database counts |
|
21 | + * |
|
22 | + * Get number of traps, rules |
|
23 | + */ |
|
24 | 24 | public function dbAction() |
25 | 25 | { |
26 | 26 | $db_prefix=$this->Config()->get('config', 'database_prefix'); |
@@ -40,8 +40,7 @@ |
||
40 | 40 | $query = $dataBase->select()->from($Config->getTrapRuleName(),array('COUNT(*)')); |
41 | 41 | printf("Number of rules : %s\n", $dataBase->fetchOne($query) ); |
42 | 42 | |
43 | - } |
|
44 | - catch (Exception $e) |
|
43 | + } catch (Exception $e) |
|
45 | 44 | { |
46 | 45 | printf('Error in DB : %s\n', $e->getMessage()); |
47 | 46 | } |
@@ -24,22 +24,22 @@ |
||
24 | 24 | public function dbAction() |
25 | 25 | { |
26 | 26 | $db_prefix=$this->Config()->get('config', 'database_prefix'); |
27 | - $Config = new TrapModuleConfig($db_prefix); |
|
27 | + $Config=new TrapModuleConfig($db_prefix); |
|
28 | 28 | |
29 | 29 | try |
30 | 30 | { |
31 | 31 | |
32 | 32 | $dbresource=$this->Config()->get('config', 'database'); |
33 | - printf("DB name : %s\n",$dbresource); |
|
33 | + printf("DB name : %s\n", $dbresource); |
|
34 | 34 | // $dataBase = IcingaDbConnection::fromResourceName($dbresource)->getConnection(); |
35 | - $dataBase = IcingaDbConnection::fromResourceName($dbresource)->getDbAdapter(); |
|
35 | + $dataBase=IcingaDbConnection::fromResourceName($dbresource)->getDbAdapter(); |
|
36 | 36 | |
37 | - $query = $dataBase->select()->from($Config->getTrapTableName(),array('COUNT(*)')); |
|
38 | - printf("Number of traps : %s\n", $dataBase->fetchOne($query) ); |
|
39 | - $query = $dataBase->select()->from($Config->getTrapDataTableName(),array('COUNT(*)')); |
|
40 | - printf("Number of trap objects : %s\n", $dataBase->fetchOne($query) ); |
|
41 | - $query = $dataBase->select()->from($Config->getTrapRuleName(),array('COUNT(*)')); |
|
42 | - printf("Number of rules : %s\n", $dataBase->fetchOne($query) ); |
|
37 | + $query=$dataBase->select()->from($Config->getTrapTableName(), array('COUNT(*)')); |
|
38 | + printf("Number of traps : %s\n", $dataBase->fetchOne($query)); |
|
39 | + $query=$dataBase->select()->from($Config->getTrapDataTableName(), array('COUNT(*)')); |
|
40 | + printf("Number of trap objects : %s\n", $dataBase->fetchOne($query)); |
|
41 | + $query=$dataBase->select()->from($Config->getTrapRuleName(), array('COUNT(*)')); |
|
42 | + printf("Number of rules : %s\n", $dataBase->fetchOne($query)); |
|
43 | 43 | |
44 | 44 | } |
45 | 45 | catch (Exception $e) |
@@ -17,16 +17,16 @@ discard block |
||
17 | 17 | class TrapsCommand extends Command |
18 | 18 | { |
19 | 19 | /** |
20 | - * Delete old traps |
|
21 | - * |
|
22 | - * USAGE |
|
23 | - * |
|
24 | - * icingali trapdirector traps rotate [options] |
|
25 | - * |
|
26 | - * OPTIONS |
|
27 | - * |
|
28 | - * --days remove traps older than <n> days |
|
29 | - */ |
|
20 | + * Delete old traps |
|
21 | + * |
|
22 | + * USAGE |
|
23 | + * |
|
24 | + * icingali trapdirector traps rotate [options] |
|
25 | + * |
|
26 | + * OPTIONS |
|
27 | + * |
|
28 | + * --days remove traps older than <n> days |
|
29 | + */ |
|
30 | 30 | public function rotateAction() |
31 | 31 | { |
32 | 32 | $module=Icinga::app()->getModuleManager()->getModule($this->getModuleName()); |
@@ -56,13 +56,13 @@ discard block |
||
56 | 56 | } |
57 | 57 | |
58 | 58 | /** |
59 | - * Reset services to OK state if timeout is passed |
|
60 | - * |
|
61 | - * USAGE |
|
62 | - * |
|
63 | - * icingali trapdirector traps reset_services |
|
64 | - * |
|
65 | - */ |
|
59 | + * Reset services to OK state if timeout is passed |
|
60 | + * |
|
61 | + * USAGE |
|
62 | + * |
|
63 | + * icingali trapdirector traps reset_services |
|
64 | + * |
|
65 | + */ |
|
66 | 66 | public function resetOKAction() |
67 | 67 | { |
68 | 68 | $module=Icinga::app()->getModuleManager()->getModule($this->getModuleName()); |
@@ -30,16 +30,16 @@ discard block |
||
30 | 30 | public function rotateAction() |
31 | 31 | { |
32 | 32 | $module=Icinga::app()->getModuleManager()->getModule($this->getModuleName()); |
33 | - require_once($module->getBaseDir() .'/bin/trap_class.php'); |
|
33 | + require_once($module->getBaseDir().'/bin/trap_class.php'); |
|
34 | 34 | $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
35 | 35 | $debug_level=2; |
36 | - $trap = new Trap($icingaweb2_etc); |
|
37 | - $trap->setLogging($debug_level,'display'); |
|
36 | + $trap=new Trap($icingaweb2_etc); |
|
37 | + $trap->setLogging($debug_level, 'display'); |
|
38 | 38 | try |
39 | 39 | { |
40 | - $days = $this->params->get('days', '<default>'); |
|
40 | + $days=$this->params->get('days', '<default>'); |
|
41 | 41 | echo $this->screen->colorize("Deleting traps older than $days days\n", 'lightblue'); |
42 | - if ($days=='<default>') |
|
42 | + if ($days == '<default>') |
|
43 | 43 | { |
44 | 44 | $trap->eraseOldTraps(); |
45 | 45 | } |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | } |
52 | 52 | catch (Exception $e) |
53 | 53 | { |
54 | - echo 'Error in updating : ' . $e->getMessage(); |
|
54 | + echo 'Error in updating : '.$e->getMessage(); |
|
55 | 55 | } |
56 | 56 | } |
57 | 57 | |
@@ -66,18 +66,18 @@ discard block |
||
66 | 66 | public function resetOKAction() |
67 | 67 | { |
68 | 68 | $module=Icinga::app()->getModuleManager()->getModule($this->getModuleName()); |
69 | - require_once($module->getBaseDir() .'/bin/trap_class.php'); |
|
69 | + require_once($module->getBaseDir().'/bin/trap_class.php'); |
|
70 | 70 | $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
71 | 71 | $debug_level=2; |
72 | - $trap = new Trap($icingaweb2_etc); |
|
73 | - $trap->setLogging($debug_level,'display'); |
|
72 | + $trap=new Trap($icingaweb2_etc); |
|
73 | + $trap->setLogging($debug_level, 'display'); |
|
74 | 74 | try |
75 | 75 | { |
76 | 76 | $trap->reset_services(); |
77 | 77 | } |
78 | 78 | catch (Exception $e) |
79 | 79 | { |
80 | - echo 'ERROR : '. $e->getMessage(); |
|
80 | + echo 'ERROR : '.$e->getMessage(); |
|
81 | 81 | } |
82 | 82 | } |
83 | 83 |
@@ -42,14 +42,12 @@ discard block |
||
42 | 42 | if ($days=='<default>') |
43 | 43 | { |
44 | 44 | $trap->eraseOldTraps(); |
45 | - } |
|
46 | - else |
|
45 | + } else |
|
47 | 46 | { |
48 | 47 | $trap->eraseOldTraps($days); |
49 | 48 | } |
50 | 49 | |
51 | - } |
|
52 | - catch (Exception $e) |
|
50 | + } catch (Exception $e) |
|
53 | 51 | { |
54 | 52 | echo 'Error in updating : ' . $e->getMessage(); |
55 | 53 | } |
@@ -74,8 +72,7 @@ discard block |
||
74 | 72 | try |
75 | 73 | { |
76 | 74 | $trap->reset_services(); |
77 | - } |
|
78 | - catch (Exception $e) |
|
75 | + } catch (Exception $e) |
|
79 | 76 | { |
80 | 77 | echo 'ERROR : '. $e->getMessage(); |
81 | 78 | } |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | $this->setName('form_config_traps'); |
19 | 19 | $this->setSubmitLabel($this->translate('Save Changes')); |
20 | 20 | } |
21 | - public function setPaths($module_base_path,$icinga_base_path) |
|
21 | + public function setPaths($module_base_path, $icinga_base_path) |
|
22 | 22 | { |
23 | 23 | $this->module_base_path=$module_base_path; |
24 | 24 | $this->icinga_base_path=$icinga_base_path; |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | ); |
83 | 83 | $retval=0; |
84 | 84 | $output=array(); |
85 | - $snmptranslate=exec('which snmptranslate',$output,$retval); |
|
85 | + $snmptranslate=exec('which snmptranslate', $output, $retval); |
|
86 | 86 | if ($retval != 0) |
87 | 87 | { |
88 | 88 | $snmptranslate='/usr/bin/snmptranslate'; |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | } |
173 | 173 | |
174 | 174 | |
175 | - public function render(Zend_View_Interface $view = NULL) |
|
175 | + public function render(Zend_View_Interface $view=NULL) |
|
176 | 176 | { |
177 | 177 | |
178 | 178 |
@@ -32,13 +32,13 @@ discard block |
||
32 | 32 | |
33 | 33 | public function setDefaultIDODB($idoDbName) |
34 | 34 | { |
35 | - $this->idoDbName=$idoDbName; |
|
36 | - return $this; |
|
35 | + $this->idoDbName=$idoDbName; |
|
36 | + return $this; |
|
37 | 37 | } |
38 | 38 | |
39 | - public function createElements(array $formData) |
|
40 | - { |
|
41 | - $this->addElement( |
|
39 | + public function createElements(array $formData) |
|
40 | + { |
|
41 | + $this->addElement( |
|
42 | 42 | 'select', |
43 | 43 | 'config_database', |
44 | 44 | array( |
@@ -72,14 +72,14 @@ discard block |
||
72 | 72 | ) |
73 | 73 | ); |
74 | 74 | $this->addElement( |
75 | - 'text', |
|
76 | - 'config_icingaweb2_etc', |
|
77 | - array( |
|
78 | - 'required' => true, |
|
79 | - 'label' => $this->translate('icingaweb2 config dir'), |
|
75 | + 'text', |
|
76 | + 'config_icingaweb2_etc', |
|
77 | + array( |
|
78 | + 'required' => true, |
|
79 | + 'label' => $this->translate('icingaweb2 config dir'), |
|
80 | 80 | 'value' => $this->icinga_base_path, |
81 | - ) |
|
82 | - ); |
|
81 | + ) |
|
82 | + ); |
|
83 | 83 | $retval=0; |
84 | 84 | $output=array(); |
85 | 85 | $snmptranslate=exec('which snmptranslate',$output,$retval); |
@@ -88,69 +88,69 @@ discard block |
||
88 | 88 | $snmptranslate='/usr/bin/snmptranslate'; |
89 | 89 | } |
90 | 90 | $this->addElement( |
91 | - 'text', |
|
92 | - 'config_snmptranslate', |
|
93 | - array( |
|
94 | - 'required' => true, |
|
95 | - 'label' => $this->translate('snmptranslate binary with path'), |
|
91 | + 'text', |
|
92 | + 'config_snmptranslate', |
|
93 | + array( |
|
94 | + 'required' => true, |
|
95 | + 'label' => $this->translate('snmptranslate binary with path'), |
|
96 | 96 | 'value' => $snmptranslate, |
97 | - ) |
|
98 | - ); |
|
97 | + ) |
|
98 | + ); |
|
99 | 99 | $this->addElement( |
100 | - 'text', |
|
101 | - 'config_snmptranslate_dirs', |
|
102 | - array( |
|
103 | - 'required' => true, |
|
104 | - 'label' => $this->translate('Path for mibs'), |
|
100 | + 'text', |
|
101 | + 'config_snmptranslate_dirs', |
|
102 | + array( |
|
103 | + 'required' => true, |
|
104 | + 'label' => $this->translate('Path for mibs'), |
|
105 | 105 | 'value' => $this->module_base_path.'/mibs', |
106 | - ) |
|
107 | - ); |
|
106 | + ) |
|
107 | + ); |
|
108 | 108 | $this->addElement( |
109 | - 'text', |
|
110 | - 'config_icingacmd', |
|
111 | - array( |
|
112 | - 'required' => true, |
|
113 | - 'label' => $this->translate('icingacmd with path'), |
|
109 | + 'text', |
|
110 | + 'config_icingacmd', |
|
111 | + array( |
|
112 | + 'required' => true, |
|
113 | + 'label' => $this->translate('icingacmd with path'), |
|
114 | 114 | 'value' => '/var/run/icinga2/cmd/icinga2.cmd', |
115 | - ) |
|
116 | - ); |
|
115 | + ) |
|
116 | + ); |
|
117 | 117 | $this->addElement( |
118 | - 'text', |
|
119 | - 'config_icingaAPI_host', |
|
120 | - array( |
|
121 | - 'required' => false, |
|
122 | - 'label' => $this->translate('icinga2 API Host IP'), |
|
123 | - 'value' => '', |
|
124 | - ) |
|
118 | + 'text', |
|
119 | + 'config_icingaAPI_host', |
|
120 | + array( |
|
121 | + 'required' => false, |
|
122 | + 'label' => $this->translate('icinga2 API Host IP'), |
|
123 | + 'value' => '', |
|
124 | + ) |
|
125 | 125 | ); |
126 | 126 | $this->addElement( |
127 | - 'text', |
|
128 | - 'config_icingaAPI_port', |
|
129 | - array( |
|
130 | - 'required' => false, |
|
131 | - 'label' => $this->translate('icinga2 API TCP Port'), |
|
132 | - 'value' => '5665', |
|
133 | - ) |
|
134 | - ); |
|
127 | + 'text', |
|
128 | + 'config_icingaAPI_port', |
|
129 | + array( |
|
130 | + 'required' => false, |
|
131 | + 'label' => $this->translate('icinga2 API TCP Port'), |
|
132 | + 'value' => '5665', |
|
133 | + ) |
|
134 | + ); |
|
135 | 135 | $this->addElement( |
136 | - 'text', |
|
137 | - 'config_icingaAPI_user', |
|
138 | - array( |
|
139 | - 'required' => false, |
|
140 | - 'label' => $this->translate('icinga2 API username'), |
|
141 | - 'value' => '', |
|
142 | - ) |
|
143 | - ); |
|
136 | + 'text', |
|
137 | + 'config_icingaAPI_user', |
|
138 | + array( |
|
139 | + 'required' => false, |
|
140 | + 'label' => $this->translate('icinga2 API username'), |
|
141 | + 'value' => '', |
|
142 | + ) |
|
143 | + ); |
|
144 | 144 | $this->addElement( |
145 | - 'password', |
|
146 | - 'config_icingaAPI_password', |
|
147 | - array( |
|
148 | - 'required' => false, |
|
149 | - 'label' => $this->translate('icinga2 API password'), |
|
150 | - 'renderPassword'=> true, |
|
151 | - 'value' => '', |
|
152 | - ) |
|
153 | - ); |
|
145 | + 'password', |
|
146 | + 'config_icingaAPI_password', |
|
147 | + array( |
|
148 | + 'required' => false, |
|
149 | + 'label' => $this->translate('icinga2 API password'), |
|
150 | + 'renderPassword'=> true, |
|
151 | + 'value' => '', |
|
152 | + ) |
|
153 | + ); |
|
154 | 154 | /*$this->addElement( |
155 | 155 | 'radio', |
156 | 156 | 'config_icinga2api_use', |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | 'value' => array('Yes', 'No'),//array('1' => 'Yes', '0' => 'No'), |
161 | 161 | ) |
162 | 162 | );*/ |
163 | - // For Icinga2 API connexion |
|
163 | + // For Icinga2 API connexion |
|
164 | 164 | // $icinga2API=new Fieldset('Icinga2 API connection'); |
165 | 165 | /* $icinga2API_select=new radioBtn('icinga2API_use'); |
166 | 166 | $icinga2API_select->setLabel('Use icinga2 API instead of cmd file?'); |
@@ -170,30 +170,30 @@ discard block |
||
170 | 170 | ]); |
171 | 171 | $icinga2API->add($icinga2API_select); |
172 | 172 | $this->add($icinga2API); */ |
173 | - } |
|
173 | + } |
|
174 | 174 | |
175 | 175 | |
176 | - public function render(Zend_View_Interface $view = NULL) |
|
177 | - { |
|
176 | + public function render(Zend_View_Interface $view = NULL) |
|
177 | + { |
|
178 | 178 | |
179 | 179 | |
180 | - //return $html; |
|
181 | - return parent::render($view); |
|
182 | - } |
|
180 | + //return $html; |
|
181 | + return parent::render($view); |
|
182 | + } |
|
183 | 183 | |
184 | - /** |
|
185 | - * {@inheritdoc} |
|
186 | - */ |
|
187 | - public function onSuccess() |
|
188 | - { |
|
189 | - parent::onSuccess(); |
|
190 | - } |
|
184 | + /** |
|
185 | + * {@inheritdoc} |
|
186 | + */ |
|
187 | + public function onSuccess() |
|
188 | + { |
|
189 | + parent::onSuccess(); |
|
190 | + } |
|
191 | 191 | |
192 | - /** |
|
193 | - * {@inheritdoc} |
|
194 | - */ |
|
192 | + /** |
|
193 | + * {@inheritdoc} |
|
194 | + */ |
|
195 | 195 | public function save() |
196 | - { |
|
196 | + { |
|
197 | 197 | parent::save(); |
198 | 198 | } |
199 | 199 | } |
@@ -12,7 +12,7 @@ |
||
12 | 12 | |
13 | 13 | public function indexAction() |
14 | 14 | { |
15 | - $this->getTabs()->add('get',array( |
|
15 | + $this->getTabs()->add('get', array( |
|
16 | 16 | 'active' => true, |
17 | 17 | 'label' => $this->translate('Error'), |
18 | 18 | 'url' => Url::fromRequest() |
@@ -21,13 +21,13 @@ discard block |
||
21 | 21 | protected $lastHost; |
22 | 22 | // Filters |
23 | 23 | |
24 | - protected $filter; |
|
25 | - protected $enforcedFilters = array(); |
|
26 | - protected $searchColumns = array(); |
|
24 | + protected $filter; |
|
25 | + protected $enforcedFilters = array(); |
|
26 | + protected $searchColumns = array(); |
|
27 | 27 | |
28 | 28 | protected function getTitles() { |
29 | 29 | // TODO : check moduleconfig is set |
30 | - return $this->moduleConfig->getTrapHostListTitles(); |
|
30 | + return $this->moduleConfig->getTrapHostListTitles(); |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | // ****************** Render table in html |
@@ -35,45 +35,45 @@ discard block |
||
35 | 35 | // Host grouping |
36 | 36 | protected function renderHostIfNew($IP,$hostname) |
37 | 37 | { |
38 | - $view = $this->getView(); |
|
38 | + $view = $this->getView(); |
|
39 | 39 | |
40 | - if ($this->lastHost === $IP) { |
|
41 | - return; |
|
42 | - } |
|
40 | + if ($this->lastHost === $IP) { |
|
41 | + return; |
|
42 | + } |
|
43 | 43 | |
44 | - if ($this->lastHost === null) |
|
45 | - { |
|
46 | - $htm = "<thead>\n <tr>\n"; |
|
47 | - } else { |
|
48 | - $htm = "</tbody>\n<thead>\n <tr>\n"; |
|
49 | - } |
|
44 | + if ($this->lastHost === null) |
|
45 | + { |
|
46 | + $htm = "<thead>\n <tr>\n"; |
|
47 | + } else { |
|
48 | + $htm = "</tbody>\n<thead>\n <tr>\n"; |
|
49 | + } |
|
50 | 50 | |
51 | - if ($this->columnCount === null) |
|
52 | - { |
|
53 | - $this->columnCount = count($this->getTitles()); |
|
54 | - } |
|
51 | + if ($this->columnCount === null) |
|
52 | + { |
|
53 | + $this->columnCount = count($this->getTitles()); |
|
54 | + } |
|
55 | 55 | |
56 | - $htm .= '<th colspan="' . $this->columnCount . '">' . $view->escape($IP); |
|
57 | - if ($hostname != null) |
|
58 | - { |
|
59 | - $htm .= ' ('.$hostname.')'; |
|
60 | - } |
|
61 | - $htm .= '</th>' . "\n"; |
|
62 | - if ($this->lastHost === null) { |
|
63 | - $htm .= " </tr>\n"; |
|
64 | - } else { |
|
65 | - $htm .= " </tr>\n</thead>\n"; |
|
66 | - } |
|
56 | + $htm .= '<th colspan="' . $this->columnCount . '">' . $view->escape($IP); |
|
57 | + if ($hostname != null) |
|
58 | + { |
|
59 | + $htm .= ' ('.$hostname.')'; |
|
60 | + } |
|
61 | + $htm .= '</th>' . "\n"; |
|
62 | + if ($this->lastHost === null) { |
|
63 | + $htm .= " </tr>\n"; |
|
64 | + } else { |
|
65 | + $htm .= " </tr>\n</thead>\n"; |
|
66 | + } |
|
67 | 67 | |
68 | - $this->lastHost = $IP; |
|
68 | + $this->lastHost = $IP; |
|
69 | 69 | |
70 | - return $htm . "<tbody>\n"; |
|
70 | + return $htm . "<tbody>\n"; |
|
71 | 71 | } |
72 | 72 | |
73 | - public function __toString() |
|
74 | - { |
|
75 | - return $this->render(); |
|
76 | - } |
|
73 | + public function __toString() |
|
74 | + { |
|
75 | + return $this->render(); |
|
76 | + } |
|
77 | 77 | |
78 | 78 | public function render() |
79 | 79 | { |
@@ -139,9 +139,9 @@ discard block |
||
139 | 139 | |
140 | 140 | } |
141 | 141 | |
142 | - public function count() |
|
143 | - { |
|
144 | - $db=$this->db(); |
|
142 | + public function count() |
|
143 | + { |
|
144 | + $db=$this->db(); |
|
145 | 145 | |
146 | 146 | $query = $this->getBaseQuery(); |
147 | 147 | $this->applyFiltersToQuery($query); |
@@ -149,16 +149,16 @@ discard block |
||
149 | 149 | |
150 | 150 | return count($values); |
151 | 151 | |
152 | - //return $db->fetchOne($query); |
|
153 | - } |
|
152 | + //return $db->fetchOne($query); |
|
153 | + } |
|
154 | 154 | |
155 | - public function getPaginator() |
|
156 | - { |
|
157 | - $paginator = new Paginator(); |
|
158 | - $paginator->setQuery($this); |
|
155 | + public function getPaginator() |
|
156 | + { |
|
157 | + $paginator = new Paginator(); |
|
158 | + $paginator->setQuery($this); |
|
159 | 159 | |
160 | - return $paginator; |
|
161 | - } |
|
160 | + return $paginator; |
|
161 | + } |
|
162 | 162 | |
163 | 163 | // ****************** DB connection and query |
164 | 164 | |
@@ -168,24 +168,24 @@ discard block |
||
168 | 168 | |
169 | 169 | $query = $this->getBaseQuery(); |
170 | 170 | $this->applyFiltersToQuery($query); |
171 | - if ($this->hasLimit() || $this->hasOffset()) { |
|
172 | - $query->limit($this->getLimit(), $this->getOffset()); |
|
173 | - } |
|
171 | + if ($this->hasLimit() || $this->hasOffset()) { |
|
172 | + $query->limit($this->getLimit(), $this->getOffset()); |
|
173 | + } |
|
174 | 174 | |
175 | 175 | return $db->fetchAll($query); |
176 | 176 | } |
177 | 177 | |
178 | - public function getBaseQuery() |
|
179 | - { |
|
178 | + public function getBaseQuery() |
|
179 | + { |
|
180 | 180 | $db=$this->db(); |
181 | 181 | $query = $db->select()->from( |
182 | - $this->moduleConfig->getTrapTableName(), |
|
183 | - $this->moduleConfig->getTrapHostListDisplayColumns() |
|
184 | - )->group(array('t.source_ip','t.source_name','t.trap_oid')) |
|
185 | - ->order('t.source_ip'); |
|
182 | + $this->moduleConfig->getTrapTableName(), |
|
183 | + $this->moduleConfig->getTrapHostListDisplayColumns() |
|
184 | + )->group(array('t.source_ip','t.source_name','t.trap_oid')) |
|
185 | + ->order('t.source_ip'); |
|
186 | 186 | |
187 | - return $query; |
|
188 | - } |
|
187 | + return $query; |
|
188 | + } |
|
189 | 189 | |
190 | 190 | // ****************** Filters |
191 | 191 | |
@@ -215,39 +215,39 @@ discard block |
||
215 | 215 | $this->filter_done=(isset($filter['done']))?$this->filter_done=$filter['done']:0; |
216 | 216 | } |
217 | 217 | |
218 | - protected function getSearchColumns() |
|
219 | - { |
|
220 | - return $this->getColumns(); |
|
221 | - } |
|
218 | + protected function getSearchColumns() |
|
219 | + { |
|
220 | + return $this->getColumns(); |
|
221 | + } |
|
222 | 222 | |
223 | 223 | public function getColumns() |
224 | 224 | { |
225 | 225 | return $this->moduleConfig->getTrapListDisplayColumns(); |
226 | 226 | } |
227 | 227 | |
228 | - public function setFilter($filter) |
|
229 | - { |
|
230 | - $this->filter = $filter; |
|
231 | - return $this; |
|
232 | - } |
|
228 | + public function setFilter($filter) |
|
229 | + { |
|
230 | + $this->filter = $filter; |
|
231 | + return $this; |
|
232 | + } |
|
233 | 233 | |
234 | 234 | public function getFilterEditor(Request $request) |
235 | - { |
|
236 | - $filterEditor = Widget::create('filterEditor') |
|
237 | - ->setColumns(array_keys($this->getColumns())) |
|
238 | - ->setSearchColumns(array_keys($this->getSearchColumns())) |
|
239 | - ->preserveParams('limit', 'sort', 'dir', 'view', 'backend') |
|
240 | - ->ignoreParams('page') |
|
241 | - ->handleRequest($request); |
|
235 | + { |
|
236 | + $filterEditor = Widget::create('filterEditor') |
|
237 | + ->setColumns(array_keys($this->getColumns())) |
|
238 | + ->setSearchColumns(array_keys($this->getSearchColumns())) |
|
239 | + ->preserveParams('limit', 'sort', 'dir', 'view', 'backend') |
|
240 | + ->ignoreParams('page') |
|
241 | + ->handleRequest($request); |
|
242 | 242 | |
243 | - $filter = $filterEditor->getFilter(); |
|
244 | - $this->setFilter($filter); |
|
243 | + $filter = $filterEditor->getFilter(); |
|
244 | + $this->setFilter($filter); |
|
245 | 245 | |
246 | - return $filterEditor; |
|
247 | - } |
|
246 | + return $filterEditor; |
|
247 | + } |
|
248 | 248 | |
249 | - protected function applyFiltersToQuery($query) |
|
250 | - { |
|
249 | + protected function applyFiltersToQuery($query) |
|
250 | + { |
|
251 | 251 | |
252 | 252 | $sql=''; |
253 | 253 | if ($this->filter_query != '') |
@@ -268,8 +268,8 @@ discard block |
||
268 | 268 | $sql.="(status != 'done')"; |
269 | 269 | } |
270 | 270 | if ($sql != '') $query->where($sql); |
271 | - return $query; |
|
272 | - } |
|
271 | + return $query; |
|
272 | + } |
|
273 | 273 | |
274 | 274 | } |
275 | 275 |
@@ -256,7 +256,9 @@ discard block |
||
256 | 256 | $first=1; |
257 | 257 | foreach($this->moduleConfig->getTrapListSearchColumns() as $column) |
258 | 258 | { |
259 | - if ($first==0) $sql.=' OR '; |
|
259 | + if ($first==0) { |
|
260 | + $sql.=' OR '; |
|
261 | + } |
|
260 | 262 | $first=0; |
261 | 263 | $sql.=" ".$column." LIKE '%".$this->filter_query."%' "; |
262 | 264 | } |
@@ -264,10 +266,14 @@ discard block |
||
264 | 266 | } |
265 | 267 | if ($this->filter_done == 1) |
266 | 268 | { |
267 | - if ($sql != '') $sql.=' AND '; |
|
269 | + if ($sql != '') { |
|
270 | + $sql.=' AND '; |
|
271 | + } |
|
268 | 272 | $sql.="(status != 'done')"; |
269 | 273 | } |
270 | - if ($sql != '') $query->where($sql); |
|
274 | + if ($sql != '') { |
|
275 | + $query->where($sql); |
|
276 | + } |
|
271 | 277 | return $query; |
272 | 278 | } |
273 | 279 |
@@ -23,8 +23,8 @@ discard block |
||
23 | 23 | // Filters |
24 | 24 | |
25 | 25 | protected $filter; |
26 | - protected $enforcedFilters = array(); |
|
27 | - protected $searchColumns = array(); |
|
26 | + protected $enforcedFilters=array(); |
|
27 | + protected $searchColumns=array(); |
|
28 | 28 | |
29 | 29 | protected function getTitles() { |
30 | 30 | // TODO : check moduleconfig is set |
@@ -34,9 +34,9 @@ discard block |
||
34 | 34 | // ****************** Render table in html |
35 | 35 | |
36 | 36 | // Host grouping |
37 | - protected function renderHostIfNew($IP,$hostname) |
|
37 | + protected function renderHostIfNew($IP, $hostname) |
|
38 | 38 | { |
39 | - $view = $this->getView(); |
|
39 | + $view=$this->getView(); |
|
40 | 40 | |
41 | 41 | if ($this->lastHost === $IP) { |
42 | 42 | return; |
@@ -44,31 +44,31 @@ discard block |
||
44 | 44 | |
45 | 45 | if ($this->lastHost === null) |
46 | 46 | { |
47 | - $htm = "<thead>\n <tr>\n"; |
|
47 | + $htm="<thead>\n <tr>\n"; |
|
48 | 48 | } else { |
49 | - $htm = "</tbody>\n<thead>\n <tr>\n"; |
|
49 | + $htm="</tbody>\n<thead>\n <tr>\n"; |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | if ($this->columnCount === null) |
53 | 53 | { |
54 | - $this->columnCount = count($this->getTitles()); |
|
54 | + $this->columnCount=count($this->getTitles()); |
|
55 | 55 | } |
56 | 56 | |
57 | - $htm .= '<th colspan="' . $this->columnCount . '">' . $view->escape($IP); |
|
57 | + $htm.='<th colspan="'.$this->columnCount.'">'.$view->escape($IP); |
|
58 | 58 | if ($hostname != null) |
59 | 59 | { |
60 | - $htm .= ' ('.$hostname.')'; |
|
60 | + $htm.=' ('.$hostname.')'; |
|
61 | 61 | } |
62 | - $htm .= '</th>' . "\n"; |
|
62 | + $htm.='</th>'."\n"; |
|
63 | 63 | if ($this->lastHost === null) { |
64 | - $htm .= " </tr>\n"; |
|
64 | + $htm.=" </tr>\n"; |
|
65 | 65 | } else { |
66 | - $htm .= " </tr>\n</thead>\n"; |
|
66 | + $htm.=" </tr>\n</thead>\n"; |
|
67 | 67 | } |
68 | 68 | |
69 | - $this->lastHost = $IP; |
|
69 | + $this->lastHost=$IP; |
|
70 | 70 | |
71 | - return $htm . "<tbody>\n"; |
|
71 | + return $htm."<tbody>\n"; |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | public function __toString() |
@@ -79,62 +79,62 @@ discard block |
||
79 | 79 | public function render() |
80 | 80 | { |
81 | 81 | $data=$this->getTable(); |
82 | - $view = $this->getView(); |
|
83 | - $this->columnCount = count($this->getTitles()); |
|
82 | + $view=$this->getView(); |
|
83 | + $this->columnCount=count($this->getTitles()); |
|
84 | 84 | $this->lastHost=null; |
85 | 85 | // Table start |
86 | - $htm = '<table class="simple common-table table-row-selectable">'; |
|
86 | + $htm='<table class="simple common-table table-row-selectable">'; |
|
87 | 87 | |
88 | 88 | // Titles |
89 | - $htm .= "<thead>\n <tr>\n"; |
|
90 | - $titles = $this->getTitles(); |
|
89 | + $htm.="<thead>\n <tr>\n"; |
|
90 | + $titles=$this->getTitles(); |
|
91 | 91 | foreach ($titles as $title) |
92 | 92 | { |
93 | - $htm .= ' <th>' . $view->escape($view->translate($title)) . "</th>\n"; |
|
93 | + $htm.=' <th>'.$view->escape($view->translate($title))."</th>\n"; |
|
94 | 94 | } |
95 | - $htm .= " </tr>\n</thead>\n"; |
|
95 | + $htm.=" </tr>\n</thead>\n"; |
|
96 | 96 | |
97 | 97 | // Rows |
98 | - $htm .= "<tbody>\n"; |
|
98 | + $htm.="<tbody>\n"; |
|
99 | 99 | |
100 | 100 | foreach ($data as $row) |
101 | 101 | { |
102 | 102 | |
103 | - $firstCol = true; |
|
103 | + $firstCol=true; |
|
104 | 104 | // Put host header |
105 | - $source_name=(property_exists($row,'source_name'))?$row->source_name:null; |
|
106 | - $htm .= $this->renderHostIfNew($row->source_ip,$source_name); |
|
105 | + $source_name=(property_exists($row, 'source_name')) ? $row->source_name : null; |
|
106 | + $htm.=$this->renderHostIfNew($row->source_ip, $source_name); |
|
107 | 107 | |
108 | 108 | |
109 | 109 | // Render row |
110 | - $htm .= '<tr '.' >'; |
|
111 | - foreach ( $titles as $rowkey => $title) |
|
110 | + $htm.='<tr '.' >'; |
|
111 | + foreach ($titles as $rowkey => $title) |
|
112 | 112 | { |
113 | 113 | // Check missing value |
114 | 114 | if (property_exists($row, $rowkey)) |
115 | 115 | { |
116 | - $val = ($rowkey=='last_sent') ? DateFormatter::formatDateTime($row->$rowkey) : $row->$rowkey; |
|
116 | + $val=($rowkey == 'last_sent') ? DateFormatter::formatDateTime($row->$rowkey) : $row->$rowkey; |
|
117 | 117 | } else { |
118 | - $val = '-'; |
|
118 | + $val='-'; |
|
119 | 119 | } |
120 | 120 | if ($firstCol === true) { // Put link in first column for trap detail. |
121 | - $htm .= '<td>' |
|
121 | + $htm.='<td>' |
|
122 | 122 | . $view->qlink( |
123 | 123 | $view->escape($val), |
124 | 124 | Url::fromPath( |
125 | - $this->moduleConfig->urlPath() . '/received', |
|
125 | + $this->moduleConfig->urlPath().'/received', |
|
126 | 126 | array('q' => $row->trap_oid) |
127 | 127 | ) |
128 | 128 | ) |
129 | 129 | . '</td>'; |
130 | 130 | } else { |
131 | - $htm .= '<td>' . $view->escape($val) . '</td>'; |
|
131 | + $htm.='<td>'.$view->escape($val).'</td>'; |
|
132 | 132 | } |
133 | 133 | $firstCol=false; |
134 | 134 | } |
135 | - $htm .= "<tr>\n"; |
|
135 | + $htm.="<tr>\n"; |
|
136 | 136 | } |
137 | - $htm .= "</tbody></table>\n"; |
|
137 | + $htm.="</tbody></table>\n"; |
|
138 | 138 | //$htm .= "Filter : " . $this->filter."<br>\n"; |
139 | 139 | return $htm; |
140 | 140 | |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | { |
145 | 145 | $db=$this->db(); |
146 | 146 | |
147 | - $query = $this->getBaseQuery(); |
|
147 | + $query=$this->getBaseQuery(); |
|
148 | 148 | $this->applyFiltersToQuery($query); |
149 | 149 | $values=$db->fetchAll($query); |
150 | 150 | |
@@ -155,7 +155,7 @@ discard block |
||
155 | 155 | |
156 | 156 | public function getPaginator() |
157 | 157 | { |
158 | - $paginator = new Paginator(); |
|
158 | + $paginator=new Paginator(); |
|
159 | 159 | $paginator->setQuery($this); |
160 | 160 | |
161 | 161 | return $paginator; |
@@ -167,7 +167,7 @@ discard block |
||
167 | 167 | { |
168 | 168 | $db=$this->db(); |
169 | 169 | |
170 | - $query = $this->getBaseQuery(); |
|
170 | + $query=$this->getBaseQuery(); |
|
171 | 171 | $this->applyFiltersToQuery($query); |
172 | 172 | if ($this->hasLimit() || $this->hasOffset()) { |
173 | 173 | $query->limit($this->getLimit(), $this->getOffset()); |
@@ -179,10 +179,10 @@ discard block |
||
179 | 179 | public function getBaseQuery() |
180 | 180 | { |
181 | 181 | $db=$this->db(); |
182 | - $query = $db->select()->from( |
|
182 | + $query=$db->select()->from( |
|
183 | 183 | $this->moduleConfig->getTrapTableName(), |
184 | 184 | $this->moduleConfig->getTrapHostListDisplayColumns() |
185 | - )->group(array('t.source_ip','t.source_name','t.trap_oid')) |
|
185 | + )->group(array('t.source_ip', 't.source_name', 't.trap_oid')) |
|
186 | 186 | ->order('t.source_ip'); |
187 | 187 | |
188 | 188 | return $query; |
@@ -193,7 +193,7 @@ discard block |
||
193 | 193 | protected $filter_Handler; |
194 | 194 | protected $filter_query=''; |
195 | 195 | protected $filter_done=''; |
196 | - protected $filter_query_list=array('q','done'); |
|
196 | + protected $filter_query_list=array('q', 'done'); |
|
197 | 197 | public function renderFilterHTML() |
198 | 198 | { |
199 | 199 | $htm=' <form id="filter" name="mainFilter" |
@@ -203,17 +203,17 @@ discard block |
||
203 | 203 | $htm.='<input type="text" name="q" title="Search is simple! Try to combine multiple words" |
204 | 204 | placeholder="Search..." class="search" value="'.$this->filter_query.'">'; |
205 | 205 | $htm.='<input type="checkbox" id="checkbox_done" name="done" value="1" class="autosubmit" '; |
206 | - if ($this->filter_done == 1) { $htm.=' checked ';} |
|
206 | + if ($this->filter_done == 1) { $htm.=' checked '; } |
|
207 | 207 | $htm.='> <label for="checkbox_done">Hide processed traps</label>'; |
208 | 208 | $htm.='</form>'; |
209 | 209 | return $htm; |
210 | 210 | } |
211 | 211 | |
212 | - public function updateFilter($handler,$filter) |
|
212 | + public function updateFilter($handler, $filter) |
|
213 | 213 | { |
214 | 214 | $this->filter_Handler=$handler->remove($this->filter_query_list)->__toString(); |
215 | - $this->filter_query=(isset($filter['q']))?$this->filter_query=$filter['q']:''; |
|
216 | - $this->filter_done=(isset($filter['done']))?$this->filter_done=$filter['done']:0; |
|
215 | + $this->filter_query=(isset($filter['q'])) ? $this->filter_query=$filter['q'] : ''; |
|
216 | + $this->filter_done=(isset($filter['done'])) ? $this->filter_done=$filter['done'] : 0; |
|
217 | 217 | } |
218 | 218 | |
219 | 219 | protected function getSearchColumns() |
@@ -228,20 +228,20 @@ discard block |
||
228 | 228 | |
229 | 229 | public function setFilter($filter) |
230 | 230 | { |
231 | - $this->filter = $filter; |
|
231 | + $this->filter=$filter; |
|
232 | 232 | return $this; |
233 | 233 | } |
234 | 234 | |
235 | 235 | public function getFilterEditor(Request $request) |
236 | 236 | { |
237 | - $filterEditor = Widget::create('filterEditor') |
|
237 | + $filterEditor=Widget::create('filterEditor') |
|
238 | 238 | ->setColumns(array_keys($this->getColumns())) |
239 | 239 | ->setSearchColumns(array_keys($this->getSearchColumns())) |
240 | 240 | ->preserveParams('limit', 'sort', 'dir', 'view', 'backend') |
241 | 241 | ->ignoreParams('page') |
242 | 242 | ->handleRequest($request); |
243 | 243 | |
244 | - $filter = $filterEditor->getFilter(); |
|
244 | + $filter=$filterEditor->getFilter(); |
|
245 | 245 | $this->setFilter($filter); |
246 | 246 | |
247 | 247 | return $filterEditor; |
@@ -255,9 +255,9 @@ discard block |
||
255 | 255 | { |
256 | 256 | $sql.='('; |
257 | 257 | $first=1; |
258 | - foreach($this->moduleConfig->getTrapListSearchColumns() as $column) |
|
258 | + foreach ($this->moduleConfig->getTrapListSearchColumns() as $column) |
|
259 | 259 | { |
260 | - if ($first==0) $sql.=' OR '; |
|
260 | + if ($first == 0) $sql.=' OR '; |
|
261 | 261 | $first=0; |
262 | 262 | $sql.=" ".$column." LIKE '%".$this->filter_query."%' "; |
263 | 263 | } |
@@ -99,13 +99,11 @@ discard block |
||
99 | 99 | if (isset($oidName['name'])) |
100 | 100 | { |
101 | 101 | $val=$oidName['name']; |
102 | - } |
|
103 | - else |
|
102 | + } else |
|
104 | 103 | { |
105 | 104 | $val = $row->$rowkey; |
106 | 105 | } |
107 | - } |
|
108 | - else |
|
106 | + } else |
|
109 | 107 | { |
110 | 108 | $val = $row->$rowkey; |
111 | 109 | } |
@@ -114,8 +112,7 @@ discard block |
||
114 | 112 | if ($row->$rowkey == null) |
115 | 113 | { |
116 | 114 | $val = $row->host_group_name; |
117 | - } |
|
118 | - else |
|
115 | + } else |
|
119 | 116 | { |
120 | 117 | $val = $row->$rowkey; |
121 | 118 | } |
@@ -31,9 +31,9 @@ discard block |
||
31 | 31 | |
32 | 32 | // Filters |
33 | 33 | |
34 | - protected $filter; |
|
35 | - protected $enforcedFilters = array(); |
|
36 | - protected $searchColumns = array(); |
|
34 | + protected $filter; |
|
35 | + protected $enforcedFilters = array(); |
|
36 | + protected $searchColumns = array(); |
|
37 | 37 | |
38 | 38 | protected function getTitles() { |
39 | 39 | return $this->moduleConfig->getHandlerListTitles(); |
@@ -45,10 +45,10 @@ discard block |
||
45 | 45 | $this->doTranslate=true; |
46 | 46 | } |
47 | 47 | // ****************** Render table in html |
48 | - public function __toString() |
|
49 | - { |
|
50 | - return $this->render(); |
|
51 | - } |
|
48 | + public function __toString() |
|
49 | + { |
|
50 | + return $this->render(); |
|
51 | + } |
|
52 | 52 | |
53 | 53 | public function render() |
54 | 54 | { |
@@ -153,30 +153,30 @@ discard block |
||
153 | 153 | |
154 | 154 | } |
155 | 155 | |
156 | - public function count() |
|
157 | - { |
|
158 | - //$db = $this->connection()->getConnection(); |
|
159 | - $query = clone($this->getBaseQuery()); |
|
160 | - $query->reset('order')->columns(array('COUNT(*)')); |
|
161 | - $this->applyFiltersToQuery($query); |
|
156 | + public function count() |
|
157 | + { |
|
158 | + //$db = $this->connection()->getConnection(); |
|
159 | + $query = clone($this->getBaseQuery()); |
|
160 | + $query->reset('order')->columns(array('COUNT(*)')); |
|
161 | + $this->applyFiltersToQuery($query); |
|
162 | 162 | |
163 | 163 | $db=$this->db(); |
164 | 164 | |
165 | 165 | $query = $db->select()->from( |
166 | - $this->moduleConfig->getTrapRuleName(), |
|
167 | - array('COUNT(*)') |
|
168 | - ); |
|
166 | + $this->moduleConfig->getTrapRuleName(), |
|
167 | + array('COUNT(*)') |
|
168 | + ); |
|
169 | 169 | |
170 | - return $db->fetchOne($query); |
|
171 | - } |
|
170 | + return $db->fetchOne($query); |
|
171 | + } |
|
172 | 172 | |
173 | - public function getPaginator() |
|
174 | - { |
|
175 | - $paginator = new Paginator(); |
|
176 | - $paginator->setQuery($this); |
|
173 | + public function getPaginator() |
|
174 | + { |
|
175 | + $paginator = new Paginator(); |
|
176 | + $paginator->setQuery($this); |
|
177 | 177 | |
178 | - return $paginator; |
|
179 | - } |
|
178 | + return $paginator; |
|
179 | + } |
|
180 | 180 | |
181 | 181 | // ****************** DB connection and query |
182 | 182 | |
@@ -186,63 +186,63 @@ discard block |
||
186 | 186 | |
187 | 187 | $query = $this->getBaseQuery(); |
188 | 188 | |
189 | - if ($this->hasLimit() || $this->hasOffset()) { |
|
190 | - $query->limit($this->getLimit(), $this->getOffset()); |
|
191 | - } |
|
189 | + if ($this->hasLimit() || $this->hasOffset()) { |
|
190 | + $query->limit($this->getLimit(), $this->getOffset()); |
|
191 | + } |
|
192 | 192 | |
193 | 193 | return $db->fetchAll($query); |
194 | 194 | } |
195 | 195 | |
196 | - public function getBaseQuery() |
|
197 | - { |
|
196 | + public function getBaseQuery() |
|
197 | + { |
|
198 | 198 | $db=$this->db(); |
199 | 199 | |
200 | 200 | $query = $db->select()->from( |
201 | - $this->moduleConfig->getTrapRuleName(), |
|
202 | - $this->moduleConfig->getHandlerListDisplayColumns() |
|
203 | - )->order('host_name DESC,trap_oid DESC'); |
|
201 | + $this->moduleConfig->getTrapRuleName(), |
|
202 | + $this->moduleConfig->getHandlerListDisplayColumns() |
|
203 | + )->order('host_name DESC,trap_oid DESC'); |
|
204 | 204 | |
205 | - return $query; |
|
206 | - } |
|
205 | + return $query; |
|
206 | + } |
|
207 | 207 | |
208 | 208 | // ****************** Filters |
209 | 209 | |
210 | - protected function getSearchColumns() |
|
211 | - { |
|
212 | - return $this->getColumns(); |
|
213 | - } |
|
210 | + protected function getSearchColumns() |
|
211 | + { |
|
212 | + return $this->getColumns(); |
|
213 | + } |
|
214 | 214 | |
215 | 215 | public function getColumns() |
216 | 216 | { |
217 | 217 | return $this->moduleConfig->getHandlerListDisplayColumns(); |
218 | 218 | } |
219 | 219 | |
220 | - public function setFilter($filter) |
|
221 | - { |
|
222 | - $this->filter = $filter; |
|
223 | - return $this; |
|
224 | - } |
|
220 | + public function setFilter($filter) |
|
221 | + { |
|
222 | + $this->filter = $filter; |
|
223 | + return $this; |
|
224 | + } |
|
225 | 225 | |
226 | 226 | public function getFilterEditor(Request $request) |
227 | - { |
|
228 | - $filterEditor = Widget::create('filterEditor') |
|
229 | - ->setColumns(array_keys($this->getColumns())) |
|
230 | - ->setSearchColumns(array_keys($this->getSearchColumns())) |
|
231 | - ->preserveParams('limit', 'sort', 'dir', 'view', 'backend') |
|
232 | - ->ignoreParams('page') |
|
233 | - ->handleRequest($request); |
|
227 | + { |
|
228 | + $filterEditor = Widget::create('filterEditor') |
|
229 | + ->setColumns(array_keys($this->getColumns())) |
|
230 | + ->setSearchColumns(array_keys($this->getSearchColumns())) |
|
231 | + ->preserveParams('limit', 'sort', 'dir', 'view', 'backend') |
|
232 | + ->ignoreParams('page') |
|
233 | + ->handleRequest($request); |
|
234 | 234 | |
235 | - $filter = $filterEditor->getFilter(); |
|
236 | - $this->setFilter($filter); |
|
235 | + $filter = $filterEditor->getFilter(); |
|
236 | + $this->setFilter($filter); |
|
237 | 237 | |
238 | - return $filterEditor; |
|
239 | - } |
|
238 | + return $filterEditor; |
|
239 | + } |
|
240 | 240 | |
241 | - protected function applyFiltersToQuery($query) |
|
242 | - { |
|
241 | + protected function applyFiltersToQuery($query) |
|
242 | + { |
|
243 | 243 | // TODO : implement |
244 | 244 | |
245 | - /*$filter = null; |
|
245 | + /*$filter = null; |
|
246 | 246 | $enforced = $this->enforcedFilters; |
247 | 247 | if ($this->filter && ! $this->filter->isEmpty()) { |
248 | 248 | $filter = $this->filter; |
@@ -257,7 +257,7 @@ discard block |
||
257 | 257 | } |
258 | 258 | */ |
259 | 259 | |
260 | - return $query; |
|
261 | - } |
|
260 | + return $query; |
|
261 | + } |
|
262 | 262 | |
263 | 263 | } |
@@ -32,8 +32,8 @@ discard block |
||
32 | 32 | // Filters |
33 | 33 | |
34 | 34 | protected $filter; |
35 | - protected $enforcedFilters = array(); |
|
36 | - protected $searchColumns = array(); |
|
35 | + protected $enforcedFilters=array(); |
|
36 | + protected $searchColumns=array(); |
|
37 | 37 | |
38 | 38 | protected function getTitles() { |
39 | 39 | return $this->moduleConfig->getHandlerListTitles(); |
@@ -53,34 +53,34 @@ discard block |
||
53 | 53 | public function render() |
54 | 54 | { |
55 | 55 | $data=$this->getTable(); |
56 | - $view = $this->getView(); |
|
57 | - $this->columnCount = count($this->getTitles()); |
|
56 | + $view=$this->getView(); |
|
57 | + $this->columnCount=count($this->getTitles()); |
|
58 | 58 | $this->lastDay=null; |
59 | 59 | // Table start |
60 | - $htm = '<table class="simple common-table table-row-selectable">'; |
|
60 | + $htm='<table class="simple common-table table-row-selectable">'; |
|
61 | 61 | |
62 | 62 | // Titles |
63 | - $htm .= "<thead>\n <tr>\n"; |
|
64 | - $titles = $this->getTitles(); |
|
63 | + $htm.="<thead>\n <tr>\n"; |
|
64 | + $titles=$this->getTitles(); |
|
65 | 65 | foreach ($titles as $title) |
66 | 66 | { |
67 | - $htm .= ' <th>' . $view->escape($view->translate($title)) . "</th>\n"; |
|
67 | + $htm.=' <th>'.$view->escape($view->translate($title))."</th>\n"; |
|
68 | 68 | } |
69 | - $htm .= " </tr>\n</thead>\n"; |
|
69 | + $htm.=" </tr>\n</thead>\n"; |
|
70 | 70 | |
71 | 71 | // Rows |
72 | - $htm .= "<tbody>\n"; |
|
72 | + $htm.="<tbody>\n"; |
|
73 | 73 | |
74 | 74 | foreach ($data as $row) |
75 | 75 | { |
76 | - $firstCol = true; |
|
76 | + $firstCol=true; |
|
77 | 77 | // Put date header |
78 | 78 | //$htm .= $this->renderDayIfNew($row->timestamp); |
79 | 79 | |
80 | 80 | |
81 | 81 | // Render row |
82 | - $htm .= '<tr '.' >'; |
|
83 | - foreach ( $titles as $rowkey => $title) |
|
82 | + $htm.='<tr '.' >'; |
|
83 | + foreach ($titles as $rowkey => $title) |
|
84 | 84 | { |
85 | 85 | // Check missing value |
86 | 86 | if (property_exists($row, $rowkey)) |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | break; |
94 | 94 | case 'trap_oid': // try to traslate oids. |
95 | 95 | |
96 | - if ($this->doTranslate===true) |
|
96 | + if ($this->doTranslate === true) |
|
97 | 97 | { |
98 | 98 | $oidName=$this->MIB->translateOID($row->$rowkey); |
99 | 99 | if (isset($oidName['name'])) |
@@ -102,52 +102,52 @@ discard block |
||
102 | 102 | } |
103 | 103 | else |
104 | 104 | { |
105 | - $val = $row->$rowkey; |
|
105 | + $val=$row->$rowkey; |
|
106 | 106 | } |
107 | 107 | } |
108 | 108 | else |
109 | 109 | { |
110 | - $val = $row->$rowkey; |
|
110 | + $val=$row->$rowkey; |
|
111 | 111 | } |
112 | 112 | break; |
113 | 113 | case 'host_name': // switch to hostgroup if name is null |
114 | 114 | if ($row->$rowkey == null) |
115 | 115 | { |
116 | - $val = $row->host_group_name; |
|
116 | + $val=$row->host_group_name; |
|
117 | 117 | } |
118 | 118 | else |
119 | 119 | { |
120 | - $val = $row->$rowkey; |
|
120 | + $val=$row->$rowkey; |
|
121 | 121 | } |
122 | 122 | break; |
123 | 123 | default: |
124 | - $val = $row->$rowkey; |
|
124 | + $val=$row->$rowkey; |
|
125 | 125 | } |
126 | - if ($rowkey == 'trap_oid' && $this->doTranslate===true) |
|
126 | + if ($rowkey == 'trap_oid' && $this->doTranslate === true) |
|
127 | 127 | { |
128 | 128 | |
129 | 129 | } |
130 | 130 | } else { |
131 | - $val = '-'; |
|
131 | + $val='-'; |
|
132 | 132 | } |
133 | 133 | if ($firstCol === true) { // Put link in first column for trap detail. |
134 | - $htm .= '<td>' |
|
134 | + $htm.='<td>' |
|
135 | 135 | . $view->qlink( |
136 | 136 | $view->escape($val), |
137 | 137 | Url::fromPath( |
138 | - $this->moduleConfig->urlPath() . '/handler/add', |
|
138 | + $this->moduleConfig->urlPath().'/handler/add', |
|
139 | 139 | array('ruleid' => $row->id) |
140 | 140 | ) |
141 | 141 | ) |
142 | 142 | . '</td>'; |
143 | 143 | } else { |
144 | - $htm .= '<td>' . $view->escape($val) . '</td>'; |
|
144 | + $htm.='<td>'.$view->escape($val).'</td>'; |
|
145 | 145 | } |
146 | 146 | $firstCol=false; |
147 | 147 | } |
148 | - $htm .= "<tr>\n"; |
|
148 | + $htm.="<tr>\n"; |
|
149 | 149 | } |
150 | - $htm .= "</tbody></table>\n"; |
|
150 | + $htm.="</tbody></table>\n"; |
|
151 | 151 | //$htm .= "Filter : " . $this->filter."<br>\n"; |
152 | 152 | return $htm; |
153 | 153 | |
@@ -156,13 +156,13 @@ discard block |
||
156 | 156 | public function count() |
157 | 157 | { |
158 | 158 | //$db = $this->connection()->getConnection(); |
159 | - $query = clone($this->getBaseQuery()); |
|
159 | + $query=clone($this->getBaseQuery()); |
|
160 | 160 | $query->reset('order')->columns(array('COUNT(*)')); |
161 | 161 | $this->applyFiltersToQuery($query); |
162 | 162 | |
163 | 163 | $db=$this->db(); |
164 | 164 | |
165 | - $query = $db->select()->from( |
|
165 | + $query=$db->select()->from( |
|
166 | 166 | $this->moduleConfig->getTrapRuleName(), |
167 | 167 | array('COUNT(*)') |
168 | 168 | ); |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | |
173 | 173 | public function getPaginator() |
174 | 174 | { |
175 | - $paginator = new Paginator(); |
|
175 | + $paginator=new Paginator(); |
|
176 | 176 | $paginator->setQuery($this); |
177 | 177 | |
178 | 178 | return $paginator; |
@@ -184,7 +184,7 @@ discard block |
||
184 | 184 | { |
185 | 185 | $db=$this->db(); |
186 | 186 | |
187 | - $query = $this->getBaseQuery(); |
|
187 | + $query=$this->getBaseQuery(); |
|
188 | 188 | |
189 | 189 | if ($this->hasLimit() || $this->hasOffset()) { |
190 | 190 | $query->limit($this->getLimit(), $this->getOffset()); |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | { |
198 | 198 | $db=$this->db(); |
199 | 199 | |
200 | - $query = $db->select()->from( |
|
200 | + $query=$db->select()->from( |
|
201 | 201 | $this->moduleConfig->getTrapRuleName(), |
202 | 202 | $this->moduleConfig->getHandlerListDisplayColumns() |
203 | 203 | )->order('host_name DESC,trap_oid DESC'); |
@@ -219,20 +219,20 @@ discard block |
||
219 | 219 | |
220 | 220 | public function setFilter($filter) |
221 | 221 | { |
222 | - $this->filter = $filter; |
|
222 | + $this->filter=$filter; |
|
223 | 223 | return $this; |
224 | 224 | } |
225 | 225 | |
226 | 226 | public function getFilterEditor(Request $request) |
227 | 227 | { |
228 | - $filterEditor = Widget::create('filterEditor') |
|
228 | + $filterEditor=Widget::create('filterEditor') |
|
229 | 229 | ->setColumns(array_keys($this->getColumns())) |
230 | 230 | ->setSearchColumns(array_keys($this->getSearchColumns())) |
231 | 231 | ->preserveParams('limit', 'sort', 'dir', 'view', 'backend') |
232 | 232 | ->ignoreParams('page') |
233 | 233 | ->handleRequest($request); |
234 | 234 | |
235 | - $filter = $filterEditor->getFilter(); |
|
235 | + $filter=$filterEditor->getFilter(); |
|
236 | 236 | $this->setFilter($filter); |
237 | 237 | |
238 | 238 | return $filterEditor; |
@@ -68,7 +68,9 @@ |
||
68 | 68 | switch ($outputType) |
69 | 69 | { |
70 | 70 | case 'file': |
71 | - if ($outputFile == null) throw new Exception("File logging without file !"); |
|
71 | + if ($outputFile == null) { |
|
72 | + throw new Exception("File logging without file !"); |
|
73 | + } |
|
72 | 74 | $this->setFile($outputFile); |
73 | 75 | $this->setDestination('file'); |
74 | 76 | break; |
@@ -9,113 +9,113 @@ |
||
9 | 9 | class Logging |
10 | 10 | { |
11 | 11 | |
12 | - //**** Options from config database |
|
13 | - // Default values |
|
14 | - public $debugLevel=2; // 0=No output 1=critical 2=warning 3=trace 4=ALL |
|
15 | - public $outputMode='syslog'; // alert type : file, syslog, display |
|
16 | - public $outputFile="/tmp/trapdebug.txt"; |
|
17 | - protected $logLevels=array("","Error","Warning","Info","Debug"); |
|
18 | - protected $outputList=array('file', 'syslog', 'display'); |
|
12 | + //**** Options from config database |
|
13 | + // Default values |
|
14 | + public $debugLevel=2; // 0=No output 1=critical 2=warning 3=trace 4=ALL |
|
15 | + public $outputMode='syslog'; // alert type : file, syslog, display |
|
16 | + public $outputFile="/tmp/trapdebug.txt"; |
|
17 | + protected $logLevels=array("","Error","Warning","Info","Debug"); |
|
18 | + protected $outputList=array('file', 'syslog', 'display'); |
|
19 | 19 | |
20 | - /** Send log. Throws exception on critical error |
|
21 | - * @param string $message Message to log |
|
22 | - * @param int $level 1=critical 2=warning 3=trace 4=debug |
|
23 | - * @param string $destination file/syslog/display |
|
24 | - * @return void |
|
25 | - * @throws Exception |
|
26 | - **/ |
|
27 | - public function log( $message, $level, $destination ='') |
|
28 | - { |
|
29 | - if ($this->debugLevel >= $level) |
|
30 | - { |
|
31 | - $date = '['. date("Y/m/d H:i:s") . '] '; // no date in syslog as already there |
|
32 | - $message = '[TrapDirector] ['.$this->logLevels[$level].']: ' .$message . "\n"; |
|
20 | + /** Send log. Throws exception on critical error |
|
21 | + * @param string $message Message to log |
|
22 | + * @param int $level 1=critical 2=warning 3=trace 4=debug |
|
23 | + * @param string $destination file/syslog/display |
|
24 | + * @return void |
|
25 | + * @throws Exception |
|
26 | + **/ |
|
27 | + public function log( $message, $level, $destination ='') |
|
28 | + { |
|
29 | + if ($this->debugLevel >= $level) |
|
30 | + { |
|
31 | + $date = '['. date("Y/m/d H:i:s") . '] '; // no date in syslog as already there |
|
32 | + $message = '[TrapDirector] ['.$this->logLevels[$level].']: ' .$message . "\n"; |
|
33 | 33 | |
34 | - $output = ( $destination != '' ) ? $destination : $this->outputMode; |
|
35 | - switch ($output) |
|
36 | - { |
|
37 | - case 'file': |
|
38 | - file_put_contents ($this->outputFile, $date.$message , FILE_APPEND); |
|
39 | - break; |
|
40 | - case 'syslog': |
|
41 | - switch($level) |
|
42 | - { |
|
43 | - case 1 : $prio = LOG_ERR;break; |
|
44 | - case 2 : $prio = LOG_WARNING;break; |
|
45 | - case 3 : $prio = LOG_INFO;break; |
|
46 | - case 4 : $prio = LOG_INFO;break; // LOG_DEBUG isn't always displayed in syslog |
|
47 | - default: $prio = LOG_ERR; |
|
48 | - } |
|
49 | - syslog($prio,$message); |
|
50 | - break; |
|
51 | - case 'display': |
|
52 | - echo $date.$message; |
|
53 | - break; |
|
54 | - default : // nothing we can do at this point |
|
55 | - throw new Exception($date.$message); |
|
56 | - } |
|
57 | - } |
|
58 | - if ($level == 1) |
|
59 | - { |
|
60 | - throw new Exception($message); |
|
61 | - } |
|
62 | - } |
|
34 | + $output = ( $destination != '' ) ? $destination : $this->outputMode; |
|
35 | + switch ($output) |
|
36 | + { |
|
37 | + case 'file': |
|
38 | + file_put_contents ($this->outputFile, $date.$message , FILE_APPEND); |
|
39 | + break; |
|
40 | + case 'syslog': |
|
41 | + switch($level) |
|
42 | + { |
|
43 | + case 1 : $prio = LOG_ERR;break; |
|
44 | + case 2 : $prio = LOG_WARNING;break; |
|
45 | + case 3 : $prio = LOG_INFO;break; |
|
46 | + case 4 : $prio = LOG_INFO;break; // LOG_DEBUG isn't always displayed in syslog |
|
47 | + default: $prio = LOG_ERR; |
|
48 | + } |
|
49 | + syslog($prio,$message); |
|
50 | + break; |
|
51 | + case 'display': |
|
52 | + echo $date.$message; |
|
53 | + break; |
|
54 | + default : // nothing we can do at this point |
|
55 | + throw new Exception($date.$message); |
|
56 | + } |
|
57 | + } |
|
58 | + if ($level == 1) |
|
59 | + { |
|
60 | + throw new Exception($message); |
|
61 | + } |
|
62 | + } |
|
63 | 63 | |
64 | 64 | |
65 | - public function setLogging($debugLvl,$outputType,$outputFile=null) |
|
66 | - { |
|
67 | - $this->setLevel($debugLvl); |
|
68 | - switch ($outputType) |
|
69 | - { |
|
70 | - case 'file': |
|
71 | - if ($outputFile == null) throw new Exception("File logging without file !"); |
|
72 | - $this->setFile($outputFile); |
|
73 | - $this->setDestination('file'); |
|
74 | - break; |
|
75 | - default: |
|
76 | - $this->setDestination($outputType); |
|
77 | - } |
|
78 | - } |
|
65 | + public function setLogging($debugLvl,$outputType,$outputFile=null) |
|
66 | + { |
|
67 | + $this->setLevel($debugLvl); |
|
68 | + switch ($outputType) |
|
69 | + { |
|
70 | + case 'file': |
|
71 | + if ($outputFile == null) throw new Exception("File logging without file !"); |
|
72 | + $this->setFile($outputFile); |
|
73 | + $this->setDestination('file'); |
|
74 | + break; |
|
75 | + default: |
|
76 | + $this->setDestination($outputType); |
|
77 | + } |
|
78 | + } |
|
79 | 79 | |
80 | - /** |
|
81 | - * Set logging level |
|
82 | - * @param integer $level |
|
83 | - * @throws Exception |
|
84 | - */ |
|
85 | - public function setLevel($level) |
|
86 | - { |
|
87 | - if (!is_integer($level) || $level < 0 || $level > 10) |
|
88 | - { |
|
89 | - throw new Exception('Invalid log level'); |
|
90 | - } |
|
91 | - $this->debugLevel=$level; |
|
92 | - } |
|
80 | + /** |
|
81 | + * Set logging level |
|
82 | + * @param integer $level |
|
83 | + * @throws Exception |
|
84 | + */ |
|
85 | + public function setLevel($level) |
|
86 | + { |
|
87 | + if (!is_integer($level) || $level < 0 || $level > 10) |
|
88 | + { |
|
89 | + throw new Exception('Invalid log level'); |
|
90 | + } |
|
91 | + $this->debugLevel=$level; |
|
92 | + } |
|
93 | 93 | |
94 | - /** |
|
95 | - * Set logging destination |
|
96 | - * @param string $destination |
|
97 | - * @throws Exception |
|
98 | - */ |
|
99 | - public function setDestination($destination) |
|
100 | - { |
|
101 | - if (!is_string($destination) || ! in_array($destination, $this->outputList)) |
|
102 | - { |
|
103 | - throw new Exception('Invalid log destination'); |
|
104 | - } |
|
105 | - $this->outputMode=$destination; |
|
106 | - } |
|
107 | - /** |
|
108 | - * Set file destination |
|
109 | - * @param string $file |
|
110 | - * @throws Exception |
|
111 | - */ |
|
112 | - public function setFile($file) |
|
113 | - { |
|
114 | - if (!is_string($file)) |
|
115 | - { |
|
116 | - throw new Exception('Invalid log file'); |
|
117 | - } |
|
118 | - $this->outputFile=$file; |
|
119 | - } |
|
94 | + /** |
|
95 | + * Set logging destination |
|
96 | + * @param string $destination |
|
97 | + * @throws Exception |
|
98 | + */ |
|
99 | + public function setDestination($destination) |
|
100 | + { |
|
101 | + if (!is_string($destination) || ! in_array($destination, $this->outputList)) |
|
102 | + { |
|
103 | + throw new Exception('Invalid log destination'); |
|
104 | + } |
|
105 | + $this->outputMode=$destination; |
|
106 | + } |
|
107 | + /** |
|
108 | + * Set file destination |
|
109 | + * @param string $file |
|
110 | + * @throws Exception |
|
111 | + */ |
|
112 | + public function setFile($file) |
|
113 | + { |
|
114 | + if (!is_string($file)) |
|
115 | + { |
|
116 | + throw new Exception('Invalid log file'); |
|
117 | + } |
|
118 | + $this->outputFile=$file; |
|
119 | + } |
|
120 | 120 | |
121 | 121 | } |
122 | 122 | \ No newline at end of file |
@@ -4,17 +4,17 @@ discard block |
||
4 | 4 | |
5 | 5 | use Exception; |
6 | 6 | |
7 | -define("ERROR", 1);define("WARN", 2);define("INFO", 3);define("DEBUG", 4); |
|
7 | +define("ERROR", 1); define("WARN", 2); define("INFO", 3); define("DEBUG", 4); |
|
8 | 8 | |
9 | 9 | class Logging |
10 | 10 | { |
11 | 11 | |
12 | 12 | //**** Options from config database |
13 | 13 | // Default values |
14 | - public $debugLevel=2; // 0=No output 1=critical 2=warning 3=trace 4=ALL |
|
14 | + public $debugLevel=2; // 0=No output 1=critical 2=warning 3=trace 4=ALL |
|
15 | 15 | public $outputMode='syslog'; // alert type : file, syslog, display |
16 | 16 | public $outputFile="/tmp/trapdebug.txt"; |
17 | - protected $logLevels=array("","Error","Warning","Info","Debug"); |
|
17 | + protected $logLevels=array("", "Error", "Warning", "Info", "Debug"); |
|
18 | 18 | protected $outputList=array('file', 'syslog', 'display'); |
19 | 19 | |
20 | 20 | /** Send log. Throws exception on critical error |
@@ -24,29 +24,29 @@ discard block |
||
24 | 24 | * @return void |
25 | 25 | * @throws Exception |
26 | 26 | **/ |
27 | - public function log( $message, $level, $destination ='') |
|
27 | + public function log($message, $level, $destination='') |
|
28 | 28 | { |
29 | 29 | if ($this->debugLevel >= $level) |
30 | 30 | { |
31 | - $date = '['. date("Y/m/d H:i:s") . '] '; // no date in syslog as already there |
|
32 | - $message = '[TrapDirector] ['.$this->logLevels[$level].']: ' .$message . "\n"; |
|
31 | + $date='['.date("Y/m/d H:i:s").'] '; // no date in syslog as already there |
|
32 | + $message='[TrapDirector] ['.$this->logLevels[$level].']: '.$message."\n"; |
|
33 | 33 | |
34 | - $output = ( $destination != '' ) ? $destination : $this->outputMode; |
|
34 | + $output=($destination != '') ? $destination : $this->outputMode; |
|
35 | 35 | switch ($output) |
36 | 36 | { |
37 | 37 | case 'file': |
38 | - file_put_contents ($this->outputFile, $date.$message , FILE_APPEND); |
|
38 | + file_put_contents($this->outputFile, $date.$message, FILE_APPEND); |
|
39 | 39 | break; |
40 | 40 | case 'syslog': |
41 | - switch($level) |
|
41 | + switch ($level) |
|
42 | 42 | { |
43 | - case 1 : $prio = LOG_ERR;break; |
|
44 | - case 2 : $prio = LOG_WARNING;break; |
|
45 | - case 3 : $prio = LOG_INFO;break; |
|
46 | - case 4 : $prio = LOG_INFO;break; // LOG_DEBUG isn't always displayed in syslog |
|
47 | - default: $prio = LOG_ERR; |
|
43 | + case 1 : $prio=LOG_ERR; break; |
|
44 | + case 2 : $prio=LOG_WARNING; break; |
|
45 | + case 3 : $prio=LOG_INFO; break; |
|
46 | + case 4 : $prio=LOG_INFO; break; // LOG_DEBUG isn't always displayed in syslog |
|
47 | + default: $prio=LOG_ERR; |
|
48 | 48 | } |
49 | - syslog($prio,$message); |
|
49 | + syslog($prio, $message); |
|
50 | 50 | break; |
51 | 51 | case 'display': |
52 | 52 | echo $date.$message; |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | } |
63 | 63 | |
64 | 64 | |
65 | - public function setLogging($debugLvl,$outputType,$outputFile=null) |
|
65 | + public function setLogging($debugLvl, $outputType, $outputFile=null) |
|
66 | 66 | { |
67 | 67 | $this->setLevel($debugLvl); |
68 | 68 | switch ($outputType) |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | */ |
99 | 99 | public function setDestination($destination) |
100 | 100 | { |
101 | - if (!is_string($destination) || ! in_array($destination, $this->outputList)) |
|
101 | + if (!is_string($destination) || !in_array($destination, $this->outputList)) |
|
102 | 102 | { |
103 | 103 | throw new Exception('Invalid log destination'); |
104 | 104 | } |
@@ -14,40 +14,40 @@ |
||
14 | 14 | |
15 | 15 | if (!array_key_exists('v',$options) || !array_key_exists('c',$options) || !array_key_exists('b',$options)|| !array_key_exists('a',$options)) |
16 | 16 | { |
17 | - printf("Need version -v, path -a, database -b (mysql,pgsql) command -c (create/update)\n"); |
|
18 | - exit(1); |
|
17 | + printf("Need version -v, path -a, database -b (mysql,pgsql) command -c (create/update)\n"); |
|
18 | + exit(1); |
|
19 | 19 | } |
20 | 20 | $command=$options['c']; |
21 | 21 | $path=$options['a']; |
22 | 22 | try { |
23 | - switch($command) |
|
24 | - { |
|
25 | - case 'create': |
|
26 | - $schema=($options['b']=='mysql')?'schema_v'.$options['v'].'.sql':'schema_v'.$options['v'].'.pgsql'; |
|
27 | - $schema=$path.'/SQL/'.$schema; |
|
28 | - $trap->trapsDB->create_schema($schema, 'traps_'); |
|
29 | - break; |
|
30 | - case 'update': |
|
31 | - $message=$trap->trapsDB->update_schema($path."/SQL/",$options['v'], 'traps_',true); |
|
32 | - printf("Update message : %s\n",$message); |
|
33 | - if ($message == 'ERROR') |
|
34 | - { |
|
35 | - exit(1); |
|
36 | - } |
|
37 | - printf("Messages DONE, updating : \n"); |
|
38 | - $message=$trap->trapsDB->update_schema($path."/SQL/",$options['v'], 'traps_'); |
|
39 | - if ($message == 'ERROR') |
|
40 | - { |
|
41 | - exit(1); |
|
42 | - } |
|
43 | - break; |
|
44 | - default: |
|
45 | - printf("Unknown command\n"); |
|
46 | - exit(1); |
|
47 | - } |
|
23 | + switch($command) |
|
24 | + { |
|
25 | + case 'create': |
|
26 | + $schema=($options['b']=='mysql')?'schema_v'.$options['v'].'.sql':'schema_v'.$options['v'].'.pgsql'; |
|
27 | + $schema=$path.'/SQL/'.$schema; |
|
28 | + $trap->trapsDB->create_schema($schema, 'traps_'); |
|
29 | + break; |
|
30 | + case 'update': |
|
31 | + $message=$trap->trapsDB->update_schema($path."/SQL/",$options['v'], 'traps_',true); |
|
32 | + printf("Update message : %s\n",$message); |
|
33 | + if ($message == 'ERROR') |
|
34 | + { |
|
35 | + exit(1); |
|
36 | + } |
|
37 | + printf("Messages DONE, updating : \n"); |
|
38 | + $message=$trap->trapsDB->update_schema($path."/SQL/",$options['v'], 'traps_'); |
|
39 | + if ($message == 'ERROR') |
|
40 | + { |
|
41 | + exit(1); |
|
42 | + } |
|
43 | + break; |
|
44 | + default: |
|
45 | + printf("Unknown command\n"); |
|
46 | + exit(1); |
|
47 | + } |
|
48 | 48 | } catch (Exception $e) { |
49 | - printf("Caught Exception %s\n",$e->getMessage()); |
|
50 | - exit (1); |
|
49 | + printf("Caught Exception %s\n",$e->getMessage()); |
|
50 | + exit (1); |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | exit(0); |
@@ -3,16 +3,16 @@ discard block |
||
3 | 3 | |
4 | 4 | require_once 'bin/trap_class.php'; |
5 | 5 | |
6 | -$options = getopt("c:v:d:b:a:"); |
|
6 | +$options=getopt("c:v:d:b:a:"); |
|
7 | 7 | |
8 | -$icingaweb2Etc=(array_key_exists('d',$options))?$options['d']:"/etc/icingaweb2"; |
|
8 | +$icingaweb2Etc=(array_key_exists('d', $options)) ? $options['d'] : "/etc/icingaweb2"; |
|
9 | 9 | |
10 | -$debugLevel=4;// 0=No output 1=critical 2=warning 3=trace 4=ALL |
|
10 | +$debugLevel=4; // 0=No output 1=critical 2=warning 3=trace 4=ALL |
|
11 | 11 | |
12 | -$trap = new trap($icingaweb2Etc,$debugLevel,'display'); |
|
13 | -$trap->setLogging($debugLevel,'display'); |
|
12 | +$trap=new trap($icingaweb2Etc, $debugLevel, 'display'); |
|
13 | +$trap->setLogging($debugLevel, 'display'); |
|
14 | 14 | |
15 | -if (!array_key_exists('v',$options) || !array_key_exists('c',$options) || !array_key_exists('b',$options)|| !array_key_exists('a',$options)) |
|
15 | +if (!array_key_exists('v', $options) || !array_key_exists('c', $options) || !array_key_exists('b', $options) || !array_key_exists('a', $options)) |
|
16 | 16 | { |
17 | 17 | printf("Need version -v, path -a, database -b (mysql,pgsql) command -c (create/update)\n"); |
18 | 18 | exit(1); |
@@ -20,22 +20,22 @@ discard block |
||
20 | 20 | $command=$options['c']; |
21 | 21 | $path=$options['a']; |
22 | 22 | try { |
23 | - switch($command) |
|
23 | + switch ($command) |
|
24 | 24 | { |
25 | 25 | case 'create': |
26 | - $schema=($options['b']=='mysql')?'schema_v'.$options['v'].'.sql':'schema_v'.$options['v'].'.pgsql'; |
|
26 | + $schema=($options['b'] == 'mysql') ? 'schema_v'.$options['v'].'.sql' : 'schema_v'.$options['v'].'.pgsql'; |
|
27 | 27 | $schema=$path.'/SQL/'.$schema; |
28 | 28 | $trap->trapsDB->create_schema($schema, 'traps_'); |
29 | 29 | break; |
30 | 30 | case 'update': |
31 | - $message=$trap->trapsDB->update_schema($path."/SQL/",$options['v'], 'traps_',true); |
|
32 | - printf("Update message : %s\n",$message); |
|
31 | + $message=$trap->trapsDB->update_schema($path."/SQL/", $options['v'], 'traps_', true); |
|
32 | + printf("Update message : %s\n", $message); |
|
33 | 33 | if ($message == 'ERROR') |
34 | 34 | { |
35 | 35 | exit(1); |
36 | 36 | } |
37 | 37 | printf("Messages DONE, updating : \n"); |
38 | - $message=$trap->trapsDB->update_schema($path."/SQL/",$options['v'], 'traps_'); |
|
38 | + $message=$trap->trapsDB->update_schema($path."/SQL/", $options['v'], 'traps_'); |
|
39 | 39 | if ($message == 'ERROR') |
40 | 40 | { |
41 | 41 | exit(1); |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | exit(1); |
47 | 47 | } |
48 | 48 | } catch (Exception $e) { |
49 | - printf("Caught Exception %s\n",$e->getMessage()); |
|
49 | + printf("Caught Exception %s\n", $e->getMessage()); |
|
50 | 50 | exit (1); |
51 | 51 | } |
52 | 52 |
@@ -56,8 +56,7 @@ discard block |
||
56 | 56 | if ($pluginDir == '') |
57 | 57 | { |
58 | 58 | $this->pluginDir=dirname(__DIR__).'/Plugins'; |
59 | - } |
|
60 | - else |
|
59 | + } else |
|
61 | 60 | { |
62 | 61 | $this->pluginDir=$pluginDir; |
63 | 62 | } |
@@ -94,8 +93,7 @@ discard block |
||
94 | 93 | { |
95 | 94 | $this->logClass->log('No enabled plugins',DEBUG); |
96 | 95 | return; |
97 | - } |
|
98 | - else |
|
96 | + } else |
|
99 | 97 | { // Saved config : <plugin name>;<Catch all OID ? 1|0>;<Trap target ? 1|0>;<func 1 name>|<func 2 name>... ,<plugin2 name>.... |
100 | 98 | $this->logClass->log('Enabled plugins = '.$PluginList,DEBUG); |
101 | 99 | |
@@ -233,9 +231,11 @@ discard block |
||
233 | 231 | */ |
234 | 232 | public function registerPlugin(string $pluginName) |
235 | 233 | { |
236 | - if ( ! isset($this->pluginsList[$pluginName]) ) // Plugin isn't enable, create entry |
|
234 | + if ( ! isset($this->pluginsList[$pluginName]) ) { |
|
235 | + // Plugin isn't enable, create entry |
|
237 | 236 | { |
238 | 237 | $pluginListElmt = array(); |
238 | + } |
|
239 | 239 | $pluginListElmt['object'] = null; // class not loaded |
240 | 240 | $pluginListElmt['enabled'] = false; |
241 | 241 | $this->pluginsList[$pluginName] = $pluginListElmt; |
@@ -282,8 +282,7 @@ discard block |
||
282 | 282 | . $pluginName . ' and ' . $this->functionList[$fname]['plugin']); |
283 | 283 | } |
284 | 284 | |
285 | - } |
|
286 | - else |
|
285 | + } else |
|
287 | 286 | { |
288 | 287 | $this->functionList[$fname]=array(); |
289 | 288 | $this->functionList[$fname]['plugin'] = $pluginName; |
@@ -326,11 +325,13 @@ discard block |
||
326 | 325 | $retDisplay .= $e->getMessage() . ' / '; |
327 | 326 | } |
328 | 327 | } |
329 | - if ($checkEnabled === false) // Load all php files in plugin dir |
|
328 | + if ($checkEnabled === false) { |
|
329 | + // Load all php files in plugin dir |
|
330 | 330 | { |
331 | 331 | foreach (glob($this->pluginDir."/*.php") as $filename) |
332 | 332 | { |
333 | 333 | $pluginName=basename($filename,'.php'); |
334 | + } |
|
334 | 335 | if (!preg_match('/^[a-zA-Z0-9]+$/',$pluginName)) |
335 | 336 | { |
336 | 337 | $this->logClass->log("Invalid plugin name : ".$pluginName, WARN); |
@@ -348,8 +349,7 @@ discard block |
||
348 | 349 | if ($retDisplay == '') |
349 | 350 | { |
350 | 351 | return 'All plugins loaded OK'; |
351 | - } |
|
352 | - else |
|
352 | + } else |
|
353 | 353 | { |
354 | 354 | return $retDisplay; |
355 | 355 | } |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | * $pluginsList[plugin name]['target'] : bool true if plugin can be trap processing target |
25 | 25 | * $pluginsList[plugin name]['enabled'] : bool true if plugin is in enabled list |
26 | 26 | **/ |
27 | - protected $pluginsList = array(); |
|
27 | + protected $pluginsList=array(); |
|
28 | 28 | |
29 | 29 | /** Array of functions names |
30 | 30 | * @var array $functionList |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | * @param string $plugin_dir optional plugin directory |
52 | 52 | * @throws \Exception |
53 | 53 | */ |
54 | - function __construct(Trap $trapClass,string $pluginDir='') |
|
54 | + function __construct(Trap $trapClass, string $pluginDir='') |
|
55 | 55 | { |
56 | 56 | if ($pluginDir == '') |
57 | 57 | { |
@@ -88,42 +88,42 @@ discard block |
||
88 | 88 | */ |
89 | 89 | private function loadEnabledPlugins() |
90 | 90 | { |
91 | - $PluginList = $this->trapClass->trapsDB->getDBConfig('enabled_plugins'); |
|
91 | + $PluginList=$this->trapClass->trapsDB->getDBConfig('enabled_plugins'); |
|
92 | 92 | |
93 | 93 | if ($PluginList === null || $PluginList == '') |
94 | 94 | { |
95 | - $this->logClass->log('No enabled plugins',DEBUG); |
|
95 | + $this->logClass->log('No enabled plugins', DEBUG); |
|
96 | 96 | return; |
97 | 97 | } |
98 | 98 | else |
99 | 99 | { // Saved config : <plugin name>;<Catch all OID ? 1|0>;<Trap target ? 1|0>;<func 1 name>|<func 2 name>... ,<plugin2 name>.... |
100 | - $this->logClass->log('Enabled plugins = '.$PluginList,DEBUG); |
|
100 | + $this->logClass->log('Enabled plugins = '.$PluginList, DEBUG); |
|
101 | 101 | |
102 | - $pluginArray = explode(',', $PluginList); |
|
102 | + $pluginArray=explode(',', $PluginList); |
|
103 | 103 | foreach ($pluginArray as $pluginElmt) |
104 | 104 | { |
105 | - $pluginElmt = explode(';',$pluginElmt); |
|
105 | + $pluginElmt=explode(';', $pluginElmt); |
|
106 | 106 | if ($pluginElmt === false || count($pluginElmt) != 4) |
107 | 107 | { |
108 | - throw new \Exception('Invalid plugin configuration : '. $PluginList ); |
|
108 | + throw new \Exception('Invalid plugin configuration : '.$PluginList); |
|
109 | 109 | } |
110 | 110 | $pluginName=$pluginElmt[0]; |
111 | 111 | |
112 | - $pluginListElmt = array(); |
|
113 | - $pluginListElmt['object'] = null; // class not loaded |
|
114 | - $pluginListElmt['allOID'] = ($pluginElmt[1]=='1') ? true : false; |
|
115 | - $pluginListElmt['target'] = ($pluginElmt[2]=='1') ? true : false; |
|
116 | - $pluginListElmt['enabled'] = true; |
|
112 | + $pluginListElmt=array(); |
|
113 | + $pluginListElmt['object']=null; // class not loaded |
|
114 | + $pluginListElmt['allOID']=($pluginElmt[1] == '1') ? true : false; |
|
115 | + $pluginListElmt['target']=($pluginElmt[2] == '1') ? true : false; |
|
116 | + $pluginListElmt['enabled']=true; |
|
117 | 117 | |
118 | - $this->pluginsList[$pluginName] = $pluginListElmt; |
|
118 | + $this->pluginsList[$pluginName]=$pluginListElmt; |
|
119 | 119 | |
120 | 120 | // deal with plugin functions |
121 | - $pluginFunctions = explode('|',$pluginElmt[3]); |
|
121 | + $pluginFunctions=explode('|', $pluginElmt[3]); |
|
122 | 122 | if ($pluginFunctions !== false) |
123 | 123 | { |
124 | 124 | foreach ($pluginFunctions as $function) |
125 | 125 | { |
126 | - $this->functionList[$function] = array( |
|
126 | + $this->functionList[$function]=array( |
|
127 | 127 | 'plugin' => $pluginName, |
128 | 128 | 'function' => null |
129 | 129 | ); |
@@ -155,16 +155,16 @@ discard block |
||
155 | 155 | { |
156 | 156 | continue; |
157 | 157 | } |
158 | - $functionString .= ($functionString == '') ? '' : '|'; // add separator if not empty |
|
159 | - $functionString .= $fName; |
|
158 | + $functionString.=($functionString == '') ? '' : '|'; // add separator if not empty |
|
159 | + $functionString.=$fName; |
|
160 | 160 | } |
161 | - $saveString .= ($saveString == '')?'':',' ; |
|
161 | + $saveString.=($saveString == '') ? '' : ','; |
|
162 | 162 | |
163 | - $allOID = ($value['allOID'] === true) ? 1 : 0; |
|
164 | - $target = ($value['target'] === true) ? 1 : 0; |
|
165 | - $saveString .= $name . ';' . $allOID . ';' . $target . ';' . $functionString ; |
|
163 | + $allOID=($value['allOID'] === true) ? 1 : 0; |
|
164 | + $target=($value['target'] === true) ? 1 : 0; |
|
165 | + $saveString.=$name.';'.$allOID.';'.$target.';'.$functionString; |
|
166 | 166 | } |
167 | - $this->logClass->log('Saving : ' . $saveString,DEBUG); |
|
167 | + $this->logClass->log('Saving : '.$saveString, DEBUG); |
|
168 | 168 | return $this->trapClass->trapsDB->setDBConfig('enabled_plugins', $saveString); |
169 | 169 | } |
170 | 170 | |
@@ -178,7 +178,7 @@ discard block |
||
178 | 178 | { |
179 | 179 | if ($value['enabled'] == true) |
180 | 180 | { |
181 | - array_push($retArray,$name); |
|
181 | + array_push($retArray, $name); |
|
182 | 182 | } |
183 | 183 | } |
184 | 184 | return $retArray; |
@@ -190,29 +190,29 @@ discard block |
||
190 | 190 | * @param bool $enabled true to enable, false to disable |
191 | 191 | * @return bool true if OK, or false (error logged) |
192 | 192 | */ |
193 | - public function enablePlugin(string $pluginName,bool $enabled) |
|
193 | + public function enablePlugin(string $pluginName, bool $enabled) |
|
194 | 194 | { |
195 | 195 | if ($enabled === false) |
196 | 196 | { |
197 | 197 | // If plugin is defined set to disable |
198 | - if ( isset($this->pluginsList[$pluginName])) |
|
198 | + if (isset($this->pluginsList[$pluginName])) |
|
199 | 199 | { |
200 | - $this->pluginsList[$pluginName]['enabled'] = false; |
|
200 | + $this->pluginsList[$pluginName]['enabled']=false; |
|
201 | 201 | } |
202 | 202 | return $this->saveEnabledPlugins(); |
203 | 203 | } |
204 | 204 | // Check if plugin is loaded / exists |
205 | - if ( ! isset($this->pluginsList[$pluginName]) || |
|
205 | + if (!isset($this->pluginsList[$pluginName]) || |
|
206 | 206 | $this->pluginsList[$pluginName]['object'] === null) |
207 | 207 | { |
208 | 208 | try { |
209 | 209 | $this->registerPlugin($pluginName); |
210 | 210 | } catch (Exception $e) { |
211 | - $this->logClass->log('Cannot enable plugin : ' . $e->getMessage(),WARN); |
|
211 | + $this->logClass->log('Cannot enable plugin : '.$e->getMessage(), WARN); |
|
212 | 212 | return false; |
213 | 213 | } |
214 | 214 | } |
215 | - $this->pluginsList[$pluginName]['enabled'] = true; |
|
215 | + $this->pluginsList[$pluginName]['enabled']=true; |
|
216 | 216 | // save in DB and return |
217 | 217 | return $this->saveEnabledPlugins(); |
218 | 218 | } |
@@ -233,12 +233,12 @@ discard block |
||
233 | 233 | */ |
234 | 234 | public function registerPlugin(string $pluginName) |
235 | 235 | { |
236 | - if ( ! isset($this->pluginsList[$pluginName]) ) // Plugin isn't enable, create entry |
|
236 | + if (!isset($this->pluginsList[$pluginName])) // Plugin isn't enable, create entry |
|
237 | 237 | { |
238 | - $pluginListElmt = array(); |
|
239 | - $pluginListElmt['object'] = null; // class not loaded |
|
240 | - $pluginListElmt['enabled'] = false; |
|
241 | - $this->pluginsList[$pluginName] = $pluginListElmt; |
|
238 | + $pluginListElmt=array(); |
|
239 | + $pluginListElmt['object']=null; // class not loaded |
|
240 | + $pluginListElmt['enabled']=false; |
|
241 | + $this->pluginsList[$pluginName]=$pluginListElmt; |
|
242 | 242 | } |
243 | 243 | |
244 | 244 | if ($this->pluginsList[$pluginName]['object'] !== null) |
@@ -247,13 +247,13 @@ discard block |
||
247 | 247 | } |
248 | 248 | try { |
249 | 249 | // Include plugin file |
250 | - include_once($this->pluginDir.'/' . $pluginName . '.php'); |
|
250 | + include_once($this->pluginDir.'/'.$pluginName.'.php'); |
|
251 | 251 | |
252 | 252 | // Create full class name with namespace |
253 | - $pluginClassName = __NAMESPACE__ . '\\Plugins\\' . $pluginName; |
|
253 | + $pluginClassName=__NAMESPACE__.'\\Plugins\\'.$pluginName; |
|
254 | 254 | |
255 | 255 | // Create class |
256 | - $newClass = new $pluginClassName(); |
|
256 | + $newClass=new $pluginClassName(); |
|
257 | 257 | |
258 | 258 | // Set logging |
259 | 259 | $newClass->setLoggingClass($this->logClass); |
@@ -276,33 +276,33 @@ discard block |
||
276 | 276 | { |
277 | 277 | if (isset($this->functionList[$fname])) |
278 | 278 | { |
279 | - if ($this->functionList[$fname]['plugin'] != $pluginName ) |
|
279 | + if ($this->functionList[$fname]['plugin'] != $pluginName) |
|
280 | 280 | { |
281 | - throw new Exception('Duplicate function name '.$fname . ' in ' |
|
282 | - . $pluginName . ' and ' . $this->functionList[$fname]['plugin']); |
|
281 | + throw new Exception('Duplicate function name '.$fname.' in ' |
|
282 | + . $pluginName.' and '.$this->functionList[$fname]['plugin']); |
|
283 | 283 | } |
284 | 284 | |
285 | 285 | } |
286 | 286 | else |
287 | 287 | { |
288 | 288 | $this->functionList[$fname]=array(); |
289 | - $this->functionList[$fname]['plugin'] = $pluginName; |
|
289 | + $this->functionList[$fname]['plugin']=$pluginName; |
|
290 | 290 | } |
291 | 291 | $this->functionList[$fname]['function']=$function['function']; |
292 | 292 | } |
293 | - $this->logClass->log('Registered plugin '.$pluginName,DEBUG); |
|
293 | + $this->logClass->log('Registered plugin '.$pluginName, DEBUG); |
|
294 | 294 | |
295 | 295 | } catch (Exception $e) { |
296 | 296 | unset($this->pluginsList[$pluginName]); |
297 | - $errorMessage = "Error registering plugin $pluginName : ".$e->getMessage(); |
|
298 | - $this->logClass->log($errorMessage,WARN); |
|
297 | + $errorMessage="Error registering plugin $pluginName : ".$e->getMessage(); |
|
298 | + $this->logClass->log($errorMessage, WARN); |
|
299 | 299 | // Disable the plugin |
300 | 300 | $this->enablePlugin($pluginName, false); |
301 | 301 | throw new \Exception($errorMessage); |
302 | 302 | } catch (Throwable $t) { |
303 | 303 | unset($this->pluginsList[$pluginName]); |
304 | - $errorMessage = $t->getMessage() . ' in file ' . $t->getFile() . ' line ' . $t->getLine(); |
|
305 | - $this->logClass->log($errorMessage,WARN); |
|
304 | + $errorMessage=$t->getMessage().' in file '.$t->getFile().' line '.$t->getLine(); |
|
305 | + $this->logClass->log($errorMessage, WARN); |
|
306 | 306 | // Disable the plugin |
307 | 307 | $this->enablePlugin($pluginName, false); |
308 | 308 | throw new \Exception($errorMessage); |
@@ -323,24 +323,24 @@ discard block |
||
323 | 323 | try { |
324 | 324 | $this->registerPlugin($pluginName); |
325 | 325 | } catch (Exception $e) { |
326 | - $retDisplay .= $e->getMessage() . ' / '; |
|
326 | + $retDisplay.=$e->getMessage().' / '; |
|
327 | 327 | } |
328 | 328 | } |
329 | 329 | if ($checkEnabled === false) // Load all php files in plugin dir |
330 | 330 | { |
331 | 331 | foreach (glob($this->pluginDir."/*.php") as $filename) |
332 | 332 | { |
333 | - $pluginName=basename($filename,'.php'); |
|
334 | - if (!preg_match('/^[a-zA-Z0-9]+$/',$pluginName)) |
|
333 | + $pluginName=basename($filename, '.php'); |
|
334 | + if (!preg_match('/^[a-zA-Z0-9]+$/', $pluginName)) |
|
335 | 335 | { |
336 | 336 | $this->logClass->log("Invalid plugin name : ".$pluginName, WARN); |
337 | - $retDisplay .= "Invalid plugin name : ".$pluginName . " / "; |
|
337 | + $retDisplay.="Invalid plugin name : ".$pluginName." / "; |
|
338 | 338 | break; |
339 | 339 | } |
340 | 340 | try { // Already registerd plugin will simply return false |
341 | 341 | $this->registerPlugin($pluginName); |
342 | 342 | } catch (Exception $e) { |
343 | - $retDisplay .= $e->getMessage() . ' / '; |
|
343 | + $retDisplay.=$e->getMessage().' / '; |
|
344 | 344 | } |
345 | 345 | } |
346 | 346 | } |
@@ -380,17 +380,17 @@ discard block |
||
380 | 380 | { |
381 | 381 | $this->registerPlugin($name); // can throw exception handled by caller |
382 | 382 | } |
383 | - $retObj = new stdClass(); |
|
384 | - $retObj->name = $name; |
|
385 | - $retObj->catchAllTraps = $this->pluginsList[$name]['allOID']; |
|
386 | - $retObj->processTraps = $this->pluginsList[$name]['target']; |
|
387 | - $retObj->description = $this->pluginsList[$name]['object']->description; |
|
383 | + $retObj=new stdClass(); |
|
384 | + $retObj->name=$name; |
|
385 | + $retObj->catchAllTraps=$this->pluginsList[$name]['allOID']; |
|
386 | + $retObj->processTraps=$this->pluginsList[$name]['target']; |
|
387 | + $retObj->description=$this->pluginsList[$name]['object']->description; |
|
388 | 388 | $functions=array(); |
389 | 389 | foreach ($this->functionList as $fName => $func) |
390 | 390 | { |
391 | 391 | if ($func['plugin'] == $name) |
392 | 392 | { |
393 | - array_push($functions,$fName); |
|
393 | + array_push($functions, $fName); |
|
394 | 394 | } |
395 | 395 | } |
396 | 396 | $retObj->funcArray=$functions; |
@@ -403,13 +403,13 @@ discard block |
||
403 | 403 | * @param string $pluginName |
404 | 404 | * @return boolean returns plugin object of false; |
405 | 405 | */ |
406 | - public function getFunction($funcName,&$pluginName) |
|
406 | + public function getFunction($funcName, &$pluginName) |
|
407 | 407 | { |
408 | - if (! isset($this->functionList[$funcName]) ) |
|
408 | + if (!isset($this->functionList[$funcName])) |
|
409 | 409 | { |
410 | 410 | return false; |
411 | 411 | } |
412 | - $pluginName = $this->functionList[$funcName]['plugin']; |
|
412 | + $pluginName=$this->functionList[$funcName]['plugin']; |
|
413 | 413 | return true; |
414 | 414 | } |
415 | 415 | |
@@ -421,21 +421,21 @@ discard block |
||
421 | 421 | */ |
422 | 422 | public function getFunctionDetails($funcName) |
423 | 423 | { |
424 | - if (! isset($this->functionList[$funcName]) ) |
|
424 | + if (!isset($this->functionList[$funcName])) |
|
425 | 425 | { |
426 | 426 | return false; |
427 | 427 | } |
428 | - $pluginName = $this->functionList[$funcName]['plugin']; // plugin name |
|
429 | - $plugin = $this->pluginsList[$pluginName]['object']; // plugin object |
|
428 | + $pluginName=$this->functionList[$funcName]['plugin']; // plugin name |
|
429 | + $plugin=$this->pluginsList[$pluginName]['object']; // plugin object |
|
430 | 430 | if ($plugin === null) |
431 | 431 | { |
432 | 432 | $this->registerPlugin($pluginName); // can throw exception handled by caller |
433 | 433 | } |
434 | - $retObj = new stdClass(); |
|
435 | - $retObj->name = $funcName; |
|
436 | - $retObj->plugin = $pluginName; |
|
437 | - $retObj->params = $plugin->functions[$funcName]['params']; |
|
438 | - $retObj->description = $plugin->functions[$funcName]['description']; |
|
434 | + $retObj=new stdClass(); |
|
435 | + $retObj->name=$funcName; |
|
436 | + $retObj->plugin=$pluginName; |
|
437 | + $retObj->params=$plugin->functions[$funcName]['params']; |
|
438 | + $retObj->description=$plugin->functions[$funcName]['description']; |
|
439 | 439 | return $retObj; |
440 | 440 | } |
441 | 441 | |
@@ -446,23 +446,23 @@ discard block |
||
446 | 446 | * @throws Exception |
447 | 447 | * @return bool |
448 | 448 | */ |
449 | - public function getFunctionEval(string $funcName,$params) : bool |
|
449 | + public function getFunctionEval(string $funcName, $params) : bool |
|
450 | 450 | { |
451 | - if (! isset($this->functionList[$funcName]) ) |
|
451 | + if (!isset($this->functionList[$funcName])) |
|
452 | 452 | { |
453 | - throw new Exception($funcName . ' not found.'); |
|
453 | + throw new Exception($funcName.' not found.'); |
|
454 | 454 | } |
455 | - $pluginName = $this->functionList[$funcName]['plugin']; // plugin name |
|
456 | - $plugin = $this->pluginsList[$pluginName]['object']; // plugin object |
|
455 | + $pluginName=$this->functionList[$funcName]['plugin']; // plugin name |
|
456 | + $plugin=$this->pluginsList[$pluginName]['object']; // plugin object |
|
457 | 457 | |
458 | 458 | if ($plugin === null) |
459 | 459 | { |
460 | 460 | $this->registerPlugin($pluginName); // can throw exception handled by caller |
461 | - $plugin = $this->pluginsList[$pluginName]['object']; |
|
461 | + $plugin=$this->pluginsList[$pluginName]['object']; |
|
462 | 462 | } |
463 | 463 | |
464 | - $propertyName = $this->functionList[$funcName]['function']; |
|
465 | - $this->logClass->log('Using property '. $propertyName . ' of class : '.$pluginName,DEBUG); |
|
464 | + $propertyName=$this->functionList[$funcName]['function']; |
|
465 | + $this->logClass->log('Using property '.$propertyName.' of class : '.$pluginName, DEBUG); |
|
466 | 466 | |
467 | 467 | return $plugin->{$propertyName}($params); |
468 | 468 | } |
@@ -475,17 +475,17 @@ discard block |
||
475 | 475 | //$this->logClass->log('eval cleanup : '.$functionString,DEBUG); |
476 | 476 | |
477 | 477 | // Match function call |
478 | - $num=preg_match('/^__([a-zA-Z0-9]+)\((.+)\)$/', $functionString , $matches); |
|
479 | - if ($num !=1) |
|
478 | + $num=preg_match('/^__([a-zA-Z0-9]+)\((.+)\)$/', $functionString, $matches); |
|
479 | + if ($num != 1) |
|
480 | 480 | { |
481 | - throw new \ErrorException('Function syntax error : ' . $functionString ); |
|
481 | + throw new \ErrorException('Function syntax error : '.$functionString); |
|
482 | 482 | } |
483 | - $this->logClass->log('Got function : '. $matches[1] . ', params : '.$matches[2],DEBUG); |
|
483 | + $this->logClass->log('Got function : '.$matches[1].', params : '.$matches[2], DEBUG); |
|
484 | 484 | $funcName=$matches[1]; |
485 | 485 | |
486 | 486 | // Get parameters comma separated |
487 | - $funcParams=str_getcsv($matches[2],',','"',"\\"); |
|
488 | - $this->logClass->log('Function params : ' . print_r($funcParams,true),DEBUG); |
|
487 | + $funcParams=str_getcsv($matches[2], ',', '"', "\\"); |
|
488 | + $this->logClass->log('Function params : '.print_r($funcParams, true), DEBUG); |
|
489 | 489 | |
490 | 490 | // return evaluation |
491 | 491 | return $this->getFunctionEval($funcName, $funcParams); |
@@ -520,7 +520,7 @@ discard block |
||
520 | 520 | */ |
521 | 521 | public function setLoggingClass($loggingClass) |
522 | 522 | { |
523 | - $this->loggingClass = $loggingClass; |
|
523 | + $this->loggingClass=$loggingClass; |
|
524 | 524 | } |
525 | 525 | |
526 | 526 | /** |
@@ -528,8 +528,8 @@ discard block |
||
528 | 528 | * @param string $message |
529 | 529 | * @param int $level DEBUG/INFO/WARN/CRIT |
530 | 530 | */ |
531 | - public function log($message,$level) |
|
531 | + public function log($message, $level) |
|
532 | 532 | { |
533 | - $this->loggingClass->log('[ '.get_class($this).'] '. $message, $level); |
|
533 | + $this->loggingClass->log('[ '.get_class($this).'] '.$message, $level); |
|
534 | 534 | } |
535 | 535 | } |
536 | 536 | \ No newline at end of file |
@@ -17,519 +17,519 @@ |
||
17 | 17 | */ |
18 | 18 | class Plugins |
19 | 19 | { |
20 | - /** Array of plugin objects. Keys ar plugin name |
|
21 | - * @var PluginTemplate[] $pluginsList Plugins array with name as index |
|
22 | - * $pluginsList[plugin name]['object'] : plugin object (NULL of not loaded) |
|
23 | - * $pluginsList[plugin name]['allOID'] : bool true if plugin catches all oid |
|
24 | - * $pluginsList[plugin name]['target'] : bool true if plugin can be trap processing target |
|
25 | - * $pluginsList[plugin name]['enabled'] : bool true if plugin is in enabled list |
|
26 | - **/ |
|
27 | - protected $pluginsList = array(); |
|
20 | + /** Array of plugin objects. Keys ar plugin name |
|
21 | + * @var PluginTemplate[] $pluginsList Plugins array with name as index |
|
22 | + * $pluginsList[plugin name]['object'] : plugin object (NULL of not loaded) |
|
23 | + * $pluginsList[plugin name]['allOID'] : bool true if plugin catches all oid |
|
24 | + * $pluginsList[plugin name]['target'] : bool true if plugin can be trap processing target |
|
25 | + * $pluginsList[plugin name]['enabled'] : bool true if plugin is in enabled list |
|
26 | + **/ |
|
27 | + protected $pluginsList = array(); |
|
28 | 28 | |
29 | - /** Array of functions names |
|
30 | - * @var array $functionList |
|
31 | - * $functionList[name]['plugin'] : Plugin name |
|
32 | - * $functionList[name]['function'] : Plugin function to call (null if plugin not loaded) |
|
33 | - */ |
|
34 | - protected $functionList=array(); |
|
29 | + /** Array of functions names |
|
30 | + * @var array $functionList |
|
31 | + * $functionList[name]['plugin'] : Plugin name |
|
32 | + * $functionList[name]['function'] : Plugin function to call (null if plugin not loaded) |
|
33 | + */ |
|
34 | + protected $functionList=array(); |
|
35 | 35 | |
36 | - /** @var string[] $enabledPlugins list of enabled plugins */ |
|
37 | - //public $enabledPlugins = array(); |
|
36 | + /** @var string[] $enabledPlugins list of enabled plugins */ |
|
37 | + //public $enabledPlugins = array(); |
|
38 | 38 | |
39 | 39 | |
40 | - /** @var Logging $logClass */ |
|
41 | - protected $logClass; |
|
40 | + /** @var Logging $logClass */ |
|
41 | + protected $logClass; |
|
42 | 42 | |
43 | - /** @var Trap $trapClass */ |
|
44 | - protected $trapClass; |
|
43 | + /** @var Trap $trapClass */ |
|
44 | + protected $trapClass; |
|
45 | 45 | |
46 | - /** @var string $pluginDir */ |
|
47 | - protected $pluginDir; |
|
46 | + /** @var string $pluginDir */ |
|
47 | + protected $pluginDir; |
|
48 | 48 | |
49 | - /** Setup class |
|
50 | - * @param Trap $logClass the top trap class |
|
51 | - * @param string $plugin_dir optional plugin directory |
|
52 | - * @throws \Exception |
|
53 | - */ |
|
54 | - function __construct(Trap $trapClass,string $pluginDir='') |
|
55 | - { |
|
56 | - if ($pluginDir == '') |
|
57 | - { |
|
58 | - $this->pluginDir=dirname(__DIR__).'/Plugins'; |
|
59 | - } |
|
60 | - else |
|
61 | - { |
|
62 | - $this->pluginDir=$pluginDir; |
|
63 | - } |
|
64 | - // Set and check Logging class |
|
65 | - $this->trapClass=$trapClass; |
|
66 | - if ($this->trapClass === null) |
|
67 | - { |
|
68 | - throw new Exception('Log class not loaded into trap class'); |
|
69 | - } |
|
70 | - $this->logClass=$trapClass->logging; |
|
71 | - if ($this->logClass === null) |
|
72 | - { |
|
73 | - throw new Exception('Log class not loaded into trap class'); |
|
74 | - } |
|
75 | - // check DB class and get plugins list. |
|
76 | - if ($this->trapClass->trapsDB === null) |
|
77 | - { |
|
78 | - throw new Exception('Database class not loaded into trap class'); |
|
79 | - } |
|
80 | - $this->loadEnabledPlugins(); |
|
81 | - } |
|
49 | + /** Setup class |
|
50 | + * @param Trap $logClass the top trap class |
|
51 | + * @param string $plugin_dir optional plugin directory |
|
52 | + * @throws \Exception |
|
53 | + */ |
|
54 | + function __construct(Trap $trapClass,string $pluginDir='') |
|
55 | + { |
|
56 | + if ($pluginDir == '') |
|
57 | + { |
|
58 | + $this->pluginDir=dirname(__DIR__).'/Plugins'; |
|
59 | + } |
|
60 | + else |
|
61 | + { |
|
62 | + $this->pluginDir=$pluginDir; |
|
63 | + } |
|
64 | + // Set and check Logging class |
|
65 | + $this->trapClass=$trapClass; |
|
66 | + if ($this->trapClass === null) |
|
67 | + { |
|
68 | + throw new Exception('Log class not loaded into trap class'); |
|
69 | + } |
|
70 | + $this->logClass=$trapClass->logging; |
|
71 | + if ($this->logClass === null) |
|
72 | + { |
|
73 | + throw new Exception('Log class not loaded into trap class'); |
|
74 | + } |
|
75 | + // check DB class and get plugins list. |
|
76 | + if ($this->trapClass->trapsDB === null) |
|
77 | + { |
|
78 | + throw new Exception('Database class not loaded into trap class'); |
|
79 | + } |
|
80 | + $this->loadEnabledPlugins(); |
|
81 | + } |
|
82 | 82 | |
83 | 83 | |
84 | - /** |
|
85 | - * Load enabled plugins from database config table. |
|
86 | - * Fills enabledPlugins and functionList properties |
|
87 | - * @throws \Exception |
|
88 | - */ |
|
89 | - private function loadEnabledPlugins() |
|
90 | - { |
|
91 | - $PluginList = $this->trapClass->trapsDB->getDBConfig('enabled_plugins'); |
|
84 | + /** |
|
85 | + * Load enabled plugins from database config table. |
|
86 | + * Fills enabledPlugins and functionList properties |
|
87 | + * @throws \Exception |
|
88 | + */ |
|
89 | + private function loadEnabledPlugins() |
|
90 | + { |
|
91 | + $PluginList = $this->trapClass->trapsDB->getDBConfig('enabled_plugins'); |
|
92 | 92 | |
93 | - if ($PluginList === null || $PluginList == '') |
|
94 | - { |
|
95 | - $this->logClass->log('No enabled plugins',DEBUG); |
|
96 | - return; |
|
97 | - } |
|
98 | - else |
|
99 | - { // Saved config : <plugin name>;<Catch all OID ? 1|0>;<Trap target ? 1|0>;<func 1 name>|<func 2 name>... ,<plugin2 name>.... |
|
100 | - $this->logClass->log('Enabled plugins = '.$PluginList,DEBUG); |
|
93 | + if ($PluginList === null || $PluginList == '') |
|
94 | + { |
|
95 | + $this->logClass->log('No enabled plugins',DEBUG); |
|
96 | + return; |
|
97 | + } |
|
98 | + else |
|
99 | + { // Saved config : <plugin name>;<Catch all OID ? 1|0>;<Trap target ? 1|0>;<func 1 name>|<func 2 name>... ,<plugin2 name>.... |
|
100 | + $this->logClass->log('Enabled plugins = '.$PluginList,DEBUG); |
|
101 | 101 | |
102 | - $pluginArray = explode(',', $PluginList); |
|
103 | - foreach ($pluginArray as $pluginElmt) |
|
104 | - { |
|
105 | - $pluginElmt = explode(';',$pluginElmt); |
|
106 | - if ($pluginElmt === false || count($pluginElmt) != 4) |
|
107 | - { |
|
108 | - throw new \Exception('Invalid plugin configuration : '. $PluginList ); |
|
109 | - } |
|
110 | - $pluginName=$pluginElmt[0]; |
|
102 | + $pluginArray = explode(',', $PluginList); |
|
103 | + foreach ($pluginArray as $pluginElmt) |
|
104 | + { |
|
105 | + $pluginElmt = explode(';',$pluginElmt); |
|
106 | + if ($pluginElmt === false || count($pluginElmt) != 4) |
|
107 | + { |
|
108 | + throw new \Exception('Invalid plugin configuration : '. $PluginList ); |
|
109 | + } |
|
110 | + $pluginName=$pluginElmt[0]; |
|
111 | 111 | |
112 | - $pluginListElmt = array(); |
|
113 | - $pluginListElmt['object'] = null; // class not loaded |
|
114 | - $pluginListElmt['allOID'] = ($pluginElmt[1]=='1') ? true : false; |
|
115 | - $pluginListElmt['target'] = ($pluginElmt[2]=='1') ? true : false; |
|
116 | - $pluginListElmt['enabled'] = true; |
|
112 | + $pluginListElmt = array(); |
|
113 | + $pluginListElmt['object'] = null; // class not loaded |
|
114 | + $pluginListElmt['allOID'] = ($pluginElmt[1]=='1') ? true : false; |
|
115 | + $pluginListElmt['target'] = ($pluginElmt[2]=='1') ? true : false; |
|
116 | + $pluginListElmt['enabled'] = true; |
|
117 | 117 | |
118 | - $this->pluginsList[$pluginName] = $pluginListElmt; |
|
118 | + $this->pluginsList[$pluginName] = $pluginListElmt; |
|
119 | 119 | |
120 | - // deal with plugin functions |
|
121 | - $pluginFunctions = explode('|',$pluginElmt[3]); |
|
122 | - if ($pluginFunctions !== false) |
|
123 | - { |
|
124 | - foreach ($pluginFunctions as $function) |
|
125 | - { |
|
126 | - $this->functionList[$function] = array( |
|
127 | - 'plugin' => $pluginName, |
|
128 | - 'function' => null |
|
129 | - ); |
|
130 | - } |
|
131 | - } |
|
132 | - } |
|
120 | + // deal with plugin functions |
|
121 | + $pluginFunctions = explode('|',$pluginElmt[3]); |
|
122 | + if ($pluginFunctions !== false) |
|
123 | + { |
|
124 | + foreach ($pluginFunctions as $function) |
|
125 | + { |
|
126 | + $this->functionList[$function] = array( |
|
127 | + 'plugin' => $pluginName, |
|
128 | + 'function' => null |
|
129 | + ); |
|
130 | + } |
|
131 | + } |
|
132 | + } |
|
133 | 133 | |
134 | - } |
|
134 | + } |
|
135 | 135 | |
136 | - } |
|
136 | + } |
|
137 | 137 | |
138 | - /** |
|
139 | - * Save enabled plugin array in DB config |
|
140 | - * @return bool true if OK, or false (error logged by DB Class) |
|
141 | - */ |
|
142 | - private function saveEnabledPlugins() |
|
143 | - { |
|
144 | - $saveString=''; |
|
145 | - foreach ($this->pluginsList as $name => $value) |
|
146 | - { |
|
147 | - if ($value['enabled'] == false) |
|
148 | - { |
|
149 | - continue; |
|
150 | - } |
|
151 | - $functionString=''; |
|
152 | - foreach ($this->functionList as $fName => $fvalue) |
|
153 | - { |
|
154 | - if ($fvalue['plugin'] != $name) |
|
155 | - { |
|
156 | - continue; |
|
157 | - } |
|
158 | - $functionString .= ($functionString == '') ? '' : '|'; // add separator if not empty |
|
159 | - $functionString .= $fName; |
|
160 | - } |
|
161 | - $saveString .= ($saveString == '')?'':',' ; |
|
138 | + /** |
|
139 | + * Save enabled plugin array in DB config |
|
140 | + * @return bool true if OK, or false (error logged by DB Class) |
|
141 | + */ |
|
142 | + private function saveEnabledPlugins() |
|
143 | + { |
|
144 | + $saveString=''; |
|
145 | + foreach ($this->pluginsList as $name => $value) |
|
146 | + { |
|
147 | + if ($value['enabled'] == false) |
|
148 | + { |
|
149 | + continue; |
|
150 | + } |
|
151 | + $functionString=''; |
|
152 | + foreach ($this->functionList as $fName => $fvalue) |
|
153 | + { |
|
154 | + if ($fvalue['plugin'] != $name) |
|
155 | + { |
|
156 | + continue; |
|
157 | + } |
|
158 | + $functionString .= ($functionString == '') ? '' : '|'; // add separator if not empty |
|
159 | + $functionString .= $fName; |
|
160 | + } |
|
161 | + $saveString .= ($saveString == '')?'':',' ; |
|
162 | 162 | |
163 | - $allOID = ($value['allOID'] === true) ? 1 : 0; |
|
164 | - $target = ($value['target'] === true) ? 1 : 0; |
|
165 | - $saveString .= $name . ';' . $allOID . ';' . $target . ';' . $functionString ; |
|
166 | - } |
|
167 | - $this->logClass->log('Saving : ' . $saveString,DEBUG); |
|
168 | - return $this->trapClass->trapsDB->setDBConfig('enabled_plugins', $saveString); |
|
169 | - } |
|
163 | + $allOID = ($value['allOID'] === true) ? 1 : 0; |
|
164 | + $target = ($value['target'] === true) ? 1 : 0; |
|
165 | + $saveString .= $name . ';' . $allOID . ';' . $target . ';' . $functionString ; |
|
166 | + } |
|
167 | + $this->logClass->log('Saving : ' . $saveString,DEBUG); |
|
168 | + return $this->trapClass->trapsDB->setDBConfig('enabled_plugins', $saveString); |
|
169 | + } |
|
170 | 170 | |
171 | - /** Get enabled plugin list by name |
|
172 | - * @return array |
|
173 | - */ |
|
174 | - public function getEnabledPlugins() : array |
|
175 | - { |
|
176 | - $retArray=array(); |
|
177 | - foreach ($this->pluginsList as $name => $value) |
|
178 | - { |
|
179 | - if ($value['enabled'] == true) |
|
180 | - { |
|
181 | - array_push($retArray,$name); |
|
182 | - } |
|
183 | - } |
|
184 | - return $retArray; |
|
185 | - } |
|
171 | + /** Get enabled plugin list by name |
|
172 | + * @return array |
|
173 | + */ |
|
174 | + public function getEnabledPlugins() : array |
|
175 | + { |
|
176 | + $retArray=array(); |
|
177 | + foreach ($this->pluginsList as $name => $value) |
|
178 | + { |
|
179 | + if ($value['enabled'] == true) |
|
180 | + { |
|
181 | + array_push($retArray,$name); |
|
182 | + } |
|
183 | + } |
|
184 | + return $retArray; |
|
185 | + } |
|
186 | 186 | |
187 | - /** Enable plugin (enabling an enabled plugin is OK, same for disabled). |
|
188 | - * and save in DB config |
|
189 | - * @param string $pluginName |
|
190 | - * @param bool $enabled true to enable, false to disable |
|
191 | - * @return bool true if OK, or false (error logged) |
|
192 | - */ |
|
193 | - public function enablePlugin(string $pluginName,bool $enabled) |
|
194 | - { |
|
195 | - if ($enabled === false) |
|
196 | - { |
|
197 | - // If plugin is defined set to disable |
|
198 | - if ( isset($this->pluginsList[$pluginName])) |
|
199 | - { |
|
200 | - $this->pluginsList[$pluginName]['enabled'] = false; |
|
201 | - } |
|
202 | - return $this->saveEnabledPlugins(); |
|
203 | - } |
|
204 | - // Check if plugin is loaded / exists |
|
205 | - if ( ! isset($this->pluginsList[$pluginName]) || |
|
206 | - $this->pluginsList[$pluginName]['object'] === null) |
|
207 | - { |
|
208 | - try { |
|
209 | - $this->registerPlugin($pluginName); |
|
210 | - } catch (Exception $e) { |
|
211 | - $this->logClass->log('Cannot enable plugin : ' . $e->getMessage(),WARN); |
|
212 | - return false; |
|
213 | - } |
|
214 | - } |
|
215 | - $this->pluginsList[$pluginName]['enabled'] = true; |
|
216 | - // save in DB and return |
|
217 | - return $this->saveEnabledPlugins(); |
|
218 | - } |
|
187 | + /** Enable plugin (enabling an enabled plugin is OK, same for disabled). |
|
188 | + * and save in DB config |
|
189 | + * @param string $pluginName |
|
190 | + * @param bool $enabled true to enable, false to disable |
|
191 | + * @return bool true if OK, or false (error logged) |
|
192 | + */ |
|
193 | + public function enablePlugin(string $pluginName,bool $enabled) |
|
194 | + { |
|
195 | + if ($enabled === false) |
|
196 | + { |
|
197 | + // If plugin is defined set to disable |
|
198 | + if ( isset($this->pluginsList[$pluginName])) |
|
199 | + { |
|
200 | + $this->pluginsList[$pluginName]['enabled'] = false; |
|
201 | + } |
|
202 | + return $this->saveEnabledPlugins(); |
|
203 | + } |
|
204 | + // Check if plugin is loaded / exists |
|
205 | + if ( ! isset($this->pluginsList[$pluginName]) || |
|
206 | + $this->pluginsList[$pluginName]['object'] === null) |
|
207 | + { |
|
208 | + try { |
|
209 | + $this->registerPlugin($pluginName); |
|
210 | + } catch (Exception $e) { |
|
211 | + $this->logClass->log('Cannot enable plugin : ' . $e->getMessage(),WARN); |
|
212 | + return false; |
|
213 | + } |
|
214 | + } |
|
215 | + $this->pluginsList[$pluginName]['enabled'] = true; |
|
216 | + // save in DB and return |
|
217 | + return $this->saveEnabledPlugins(); |
|
218 | + } |
|
219 | 219 | |
220 | - /** |
|
221 | - * Destroy plugin objects and reload them with new enabled list. |
|
222 | - * TODO : Code this function (ref DAEMON_MODE) |
|
223 | - */ |
|
224 | - public function reloadAllPlugins() |
|
225 | - { |
|
226 | - return; |
|
227 | - } |
|
220 | + /** |
|
221 | + * Destroy plugin objects and reload them with new enabled list. |
|
222 | + * TODO : Code this function (ref DAEMON_MODE) |
|
223 | + */ |
|
224 | + public function reloadAllPlugins() |
|
225 | + { |
|
226 | + return; |
|
227 | + } |
|
228 | 228 | |
229 | - /** Load plugin by name. Create entry if not in $pluginsList |
|
230 | - * @param string $pluginName Plugin name to load |
|
231 | - * @return bool true if created, false if already loaded |
|
232 | - * @throws Exception on error loading plugin |
|
233 | - */ |
|
234 | - public function registerPlugin(string $pluginName) |
|
235 | - { |
|
236 | - if ( ! isset($this->pluginsList[$pluginName]) ) // Plugin isn't enable, create entry |
|
237 | - { |
|
238 | - $pluginListElmt = array(); |
|
239 | - $pluginListElmt['object'] = null; // class not loaded |
|
240 | - $pluginListElmt['enabled'] = false; |
|
241 | - $this->pluginsList[$pluginName] = $pluginListElmt; |
|
242 | - } |
|
229 | + /** Load plugin by name. Create entry if not in $pluginsList |
|
230 | + * @param string $pluginName Plugin name to load |
|
231 | + * @return bool true if created, false if already loaded |
|
232 | + * @throws Exception on error loading plugin |
|
233 | + */ |
|
234 | + public function registerPlugin(string $pluginName) |
|
235 | + { |
|
236 | + if ( ! isset($this->pluginsList[$pluginName]) ) // Plugin isn't enable, create entry |
|
237 | + { |
|
238 | + $pluginListElmt = array(); |
|
239 | + $pluginListElmt['object'] = null; // class not loaded |
|
240 | + $pluginListElmt['enabled'] = false; |
|
241 | + $this->pluginsList[$pluginName] = $pluginListElmt; |
|
242 | + } |
|
243 | 243 | |
244 | - if ($this->pluginsList[$pluginName]['object'] !== null) |
|
245 | - { |
|
246 | - return false; |
|
247 | - } |
|
248 | - try { |
|
249 | - // Include plugin file |
|
250 | - include_once($this->pluginDir.'/' . $pluginName . '.php'); |
|
244 | + if ($this->pluginsList[$pluginName]['object'] !== null) |
|
245 | + { |
|
246 | + return false; |
|
247 | + } |
|
248 | + try { |
|
249 | + // Include plugin file |
|
250 | + include_once($this->pluginDir.'/' . $pluginName . '.php'); |
|
251 | 251 | |
252 | - // Create full class name with namespace |
|
253 | - $pluginClassName = __NAMESPACE__ . '\\Plugins\\' . $pluginName; |
|
252 | + // Create full class name with namespace |
|
253 | + $pluginClassName = __NAMESPACE__ . '\\Plugins\\' . $pluginName; |
|
254 | 254 | |
255 | - // Create class |
|
256 | - $newClass = new $pluginClassName(); |
|
255 | + // Create class |
|
256 | + $newClass = new $pluginClassName(); |
|
257 | 257 | |
258 | - // Set logging |
|
259 | - $newClass->setLoggingClass($this->logClass); |
|
258 | + // Set logging |
|
259 | + $newClass->setLoggingClass($this->logClass); |
|
260 | 260 | |
261 | - // Add in plugin array |
|
262 | - $this->pluginsList[$pluginName]['object']=$newClass; |
|
263 | - $this->pluginsList[$pluginName]['allOID']=$newClass->catchAllTraps; |
|
264 | - $this->pluginsList[$pluginName]['target']=$newClass->processTraps; |
|
261 | + // Add in plugin array |
|
262 | + $this->pluginsList[$pluginName]['object']=$newClass; |
|
263 | + $this->pluginsList[$pluginName]['allOID']=$newClass->catchAllTraps; |
|
264 | + $this->pluginsList[$pluginName]['target']=$newClass->processTraps; |
|
265 | 265 | |
266 | - // Delete old functions |
|
267 | - foreach ($this->functionList as $fname => $fvalue) |
|
268 | - { |
|
269 | - if ($fvalue['plugin'] == $pluginName) |
|
270 | - { |
|
271 | - unset($this->functionList[$fname]); |
|
272 | - } |
|
273 | - } |
|
274 | - // Add functions |
|
275 | - foreach ($newClass->functions as $fname => $function) |
|
276 | - { |
|
277 | - if (isset($this->functionList[$fname])) |
|
278 | - { |
|
279 | - if ($this->functionList[$fname]['plugin'] != $pluginName ) |
|
280 | - { |
|
281 | - throw new Exception('Duplicate function name '.$fname . ' in ' |
|
282 | - . $pluginName . ' and ' . $this->functionList[$fname]['plugin']); |
|
283 | - } |
|
266 | + // Delete old functions |
|
267 | + foreach ($this->functionList as $fname => $fvalue) |
|
268 | + { |
|
269 | + if ($fvalue['plugin'] == $pluginName) |
|
270 | + { |
|
271 | + unset($this->functionList[$fname]); |
|
272 | + } |
|
273 | + } |
|
274 | + // Add functions |
|
275 | + foreach ($newClass->functions as $fname => $function) |
|
276 | + { |
|
277 | + if (isset($this->functionList[$fname])) |
|
278 | + { |
|
279 | + if ($this->functionList[$fname]['plugin'] != $pluginName ) |
|
280 | + { |
|
281 | + throw new Exception('Duplicate function name '.$fname . ' in ' |
|
282 | + . $pluginName . ' and ' . $this->functionList[$fname]['plugin']); |
|
283 | + } |
|
284 | 284 | |
285 | - } |
|
286 | - else |
|
287 | - { |
|
288 | - $this->functionList[$fname]=array(); |
|
289 | - $this->functionList[$fname]['plugin'] = $pluginName; |
|
290 | - } |
|
291 | - $this->functionList[$fname]['function']=$function['function']; |
|
292 | - } |
|
293 | - $this->logClass->log('Registered plugin '.$pluginName,DEBUG); |
|
285 | + } |
|
286 | + else |
|
287 | + { |
|
288 | + $this->functionList[$fname]=array(); |
|
289 | + $this->functionList[$fname]['plugin'] = $pluginName; |
|
290 | + } |
|
291 | + $this->functionList[$fname]['function']=$function['function']; |
|
292 | + } |
|
293 | + $this->logClass->log('Registered plugin '.$pluginName,DEBUG); |
|
294 | 294 | |
295 | - } catch (Exception $e) { |
|
296 | - unset($this->pluginsList[$pluginName]); |
|
297 | - $errorMessage = "Error registering plugin $pluginName : ".$e->getMessage(); |
|
298 | - $this->logClass->log($errorMessage,WARN); |
|
299 | - // Disable the plugin |
|
300 | - $this->enablePlugin($pluginName, false); |
|
301 | - throw new \Exception($errorMessage); |
|
302 | - } catch (Throwable $t) { |
|
303 | - unset($this->pluginsList[$pluginName]); |
|
304 | - $errorMessage = $t->getMessage() . ' in file ' . $t->getFile() . ' line ' . $t->getLine(); |
|
305 | - $this->logClass->log($errorMessage,WARN); |
|
306 | - // Disable the plugin |
|
307 | - $this->enablePlugin($pluginName, false); |
|
308 | - throw new \Exception($errorMessage); |
|
309 | - } |
|
310 | - return true; |
|
311 | - } |
|
295 | + } catch (Exception $e) { |
|
296 | + unset($this->pluginsList[$pluginName]); |
|
297 | + $errorMessage = "Error registering plugin $pluginName : ".$e->getMessage(); |
|
298 | + $this->logClass->log($errorMessage,WARN); |
|
299 | + // Disable the plugin |
|
300 | + $this->enablePlugin($pluginName, false); |
|
301 | + throw new \Exception($errorMessage); |
|
302 | + } catch (Throwable $t) { |
|
303 | + unset($this->pluginsList[$pluginName]); |
|
304 | + $errorMessage = $t->getMessage() . ' in file ' . $t->getFile() . ' line ' . $t->getLine(); |
|
305 | + $this->logClass->log($errorMessage,WARN); |
|
306 | + // Disable the plugin |
|
307 | + $this->enablePlugin($pluginName, false); |
|
308 | + throw new \Exception($errorMessage); |
|
309 | + } |
|
310 | + return true; |
|
311 | + } |
|
312 | 312 | |
313 | - /** Registers all plugins (check=false) or only those with name present in array (check=true) |
|
314 | - * @param bool $checkEnabled Check if plugin is enabled before loading it |
|
315 | - * @return string Errors encountered while registering plugins |
|
316 | - */ |
|
317 | - public function registerAllPlugins(bool $checkEnabled=true) |
|
318 | - { |
|
319 | - $retDisplay=''; |
|
320 | - // First load enabled plugins |
|
321 | - foreach (array_keys($this->pluginsList) as $pluginName) |
|
322 | - { |
|
323 | - try { |
|
324 | - $this->registerPlugin($pluginName); |
|
325 | - } catch (Exception $e) { |
|
326 | - $retDisplay .= $e->getMessage() . ' / '; |
|
327 | - } |
|
328 | - } |
|
329 | - if ($checkEnabled === false) // Load all php files in plugin dir |
|
330 | - { |
|
331 | - foreach (glob($this->pluginDir."/*.php") as $filename) |
|
332 | - { |
|
333 | - $pluginName=basename($filename,'.php'); |
|
334 | - if (!preg_match('/^[a-zA-Z0-9]+$/',$pluginName)) |
|
335 | - { |
|
336 | - $this->logClass->log("Invalid plugin name : ".$pluginName, WARN); |
|
337 | - $retDisplay .= "Invalid plugin name : ".$pluginName . " / "; |
|
338 | - break; |
|
339 | - } |
|
340 | - try { // Already registerd plugin will simply return false |
|
341 | - $this->registerPlugin($pluginName); |
|
342 | - } catch (Exception $e) { |
|
343 | - $retDisplay .= $e->getMessage() . ' / '; |
|
344 | - } |
|
345 | - } |
|
346 | - } |
|
313 | + /** Registers all plugins (check=false) or only those with name present in array (check=true) |
|
314 | + * @param bool $checkEnabled Check if plugin is enabled before loading it |
|
315 | + * @return string Errors encountered while registering plugins |
|
316 | + */ |
|
317 | + public function registerAllPlugins(bool $checkEnabled=true) |
|
318 | + { |
|
319 | + $retDisplay=''; |
|
320 | + // First load enabled plugins |
|
321 | + foreach (array_keys($this->pluginsList) as $pluginName) |
|
322 | + { |
|
323 | + try { |
|
324 | + $this->registerPlugin($pluginName); |
|
325 | + } catch (Exception $e) { |
|
326 | + $retDisplay .= $e->getMessage() . ' / '; |
|
327 | + } |
|
328 | + } |
|
329 | + if ($checkEnabled === false) // Load all php files in plugin dir |
|
330 | + { |
|
331 | + foreach (glob($this->pluginDir."/*.php") as $filename) |
|
332 | + { |
|
333 | + $pluginName=basename($filename,'.php'); |
|
334 | + if (!preg_match('/^[a-zA-Z0-9]+$/',$pluginName)) |
|
335 | + { |
|
336 | + $this->logClass->log("Invalid plugin name : ".$pluginName, WARN); |
|
337 | + $retDisplay .= "Invalid plugin name : ".$pluginName . " / "; |
|
338 | + break; |
|
339 | + } |
|
340 | + try { // Already registerd plugin will simply return false |
|
341 | + $this->registerPlugin($pluginName); |
|
342 | + } catch (Exception $e) { |
|
343 | + $retDisplay .= $e->getMessage() . ' / '; |
|
344 | + } |
|
345 | + } |
|
346 | + } |
|
347 | 347 | |
348 | - if ($retDisplay == '') |
|
349 | - { |
|
350 | - return 'All plugins loaded OK'; |
|
351 | - } |
|
352 | - else |
|
353 | - { |
|
354 | - return $retDisplay; |
|
355 | - } |
|
356 | - } |
|
348 | + if ($retDisplay == '') |
|
349 | + { |
|
350 | + return 'All plugins loaded OK'; |
|
351 | + } |
|
352 | + else |
|
353 | + { |
|
354 | + return $retDisplay; |
|
355 | + } |
|
356 | + } |
|
357 | 357 | |
358 | - /** |
|
359 | - * Returns array of name of loaded plugins |
|
360 | - * @return array |
|
361 | - */ |
|
362 | - public function pluginList() : array |
|
363 | - { |
|
364 | - return array_keys($this->pluginsList); |
|
365 | - } |
|
358 | + /** |
|
359 | + * Returns array of name of loaded plugins |
|
360 | + * @return array |
|
361 | + */ |
|
362 | + public function pluginList() : array |
|
363 | + { |
|
364 | + return array_keys($this->pluginsList); |
|
365 | + } |
|
366 | 366 | |
367 | - /** |
|
368 | - * Get plugin details |
|
369 | - * @param string $name name of plugins |
|
370 | - * @return boolean|stdClass result as stdClass or false if plugin not found. |
|
371 | - * @throws \Exception if registering is not possible |
|
372 | - */ |
|
373 | - public function pluginDetails(string $name) |
|
374 | - { |
|
375 | - if (!array_key_exists($name, $this->pluginsList)) |
|
376 | - { |
|
377 | - return false; |
|
378 | - } |
|
379 | - if ($this->pluginsList[$name]['object'] === null) |
|
380 | - { |
|
381 | - $this->registerPlugin($name); // can throw exception handled by caller |
|
382 | - } |
|
383 | - $retObj = new stdClass(); |
|
384 | - $retObj->name = $name; |
|
385 | - $retObj->catchAllTraps = $this->pluginsList[$name]['allOID']; |
|
386 | - $retObj->processTraps = $this->pluginsList[$name]['target']; |
|
387 | - $retObj->description = $this->pluginsList[$name]['object']->description; |
|
388 | - $functions=array(); |
|
389 | - foreach ($this->functionList as $fName => $func) |
|
390 | - { |
|
391 | - if ($func['plugin'] == $name) |
|
392 | - { |
|
393 | - array_push($functions,$fName); |
|
394 | - } |
|
395 | - } |
|
396 | - $retObj->funcArray=$functions; |
|
397 | - return $retObj; |
|
398 | - } |
|
367 | + /** |
|
368 | + * Get plugin details |
|
369 | + * @param string $name name of plugins |
|
370 | + * @return boolean|stdClass result as stdClass or false if plugin not found. |
|
371 | + * @throws \Exception if registering is not possible |
|
372 | + */ |
|
373 | + public function pluginDetails(string $name) |
|
374 | + { |
|
375 | + if (!array_key_exists($name, $this->pluginsList)) |
|
376 | + { |
|
377 | + return false; |
|
378 | + } |
|
379 | + if ($this->pluginsList[$name]['object'] === null) |
|
380 | + { |
|
381 | + $this->registerPlugin($name); // can throw exception handled by caller |
|
382 | + } |
|
383 | + $retObj = new stdClass(); |
|
384 | + $retObj->name = $name; |
|
385 | + $retObj->catchAllTraps = $this->pluginsList[$name]['allOID']; |
|
386 | + $retObj->processTraps = $this->pluginsList[$name]['target']; |
|
387 | + $retObj->description = $this->pluginsList[$name]['object']->description; |
|
388 | + $functions=array(); |
|
389 | + foreach ($this->functionList as $fName => $func) |
|
390 | + { |
|
391 | + if ($func['plugin'] == $name) |
|
392 | + { |
|
393 | + array_push($functions,$fName); |
|
394 | + } |
|
395 | + } |
|
396 | + $retObj->funcArray=$functions; |
|
397 | + return $retObj; |
|
398 | + } |
|
399 | 399 | |
400 | - /** |
|
401 | - * Get plugin name from function name |
|
402 | - * @param string $funcName |
|
403 | - * @param string $pluginName |
|
404 | - * @return boolean returns plugin object of false; |
|
405 | - */ |
|
406 | - public function getFunction($funcName,&$pluginName) |
|
407 | - { |
|
408 | - if (! isset($this->functionList[$funcName]) ) |
|
409 | - { |
|
410 | - return false; |
|
411 | - } |
|
412 | - $pluginName = $this->functionList[$funcName]['plugin']; |
|
413 | - return true; |
|
414 | - } |
|
400 | + /** |
|
401 | + * Get plugin name from function name |
|
402 | + * @param string $funcName |
|
403 | + * @param string $pluginName |
|
404 | + * @return boolean returns plugin object of false; |
|
405 | + */ |
|
406 | + public function getFunction($funcName,&$pluginName) |
|
407 | + { |
|
408 | + if (! isset($this->functionList[$funcName]) ) |
|
409 | + { |
|
410 | + return false; |
|
411 | + } |
|
412 | + $pluginName = $this->functionList[$funcName]['plugin']; |
|
413 | + return true; |
|
414 | + } |
|
415 | 415 | |
416 | - /** |
|
417 | - * Get functions params and description |
|
418 | - * @param string $funcName |
|
419 | - * @return boolean|stdClass false if not found or object (name,params,description) |
|
420 | - * @throws \Exception if registering is not possible |
|
421 | - */ |
|
422 | - public function getFunctionDetails($funcName) |
|
423 | - { |
|
424 | - if (! isset($this->functionList[$funcName]) ) |
|
425 | - { |
|
426 | - return false; |
|
427 | - } |
|
428 | - $pluginName = $this->functionList[$funcName]['plugin']; // plugin name |
|
429 | - $plugin = $this->pluginsList[$pluginName]['object']; // plugin object |
|
430 | - if ($plugin === null) |
|
431 | - { |
|
432 | - $this->registerPlugin($pluginName); // can throw exception handled by caller |
|
433 | - } |
|
434 | - $retObj = new stdClass(); |
|
435 | - $retObj->name = $funcName; |
|
436 | - $retObj->plugin = $pluginName; |
|
437 | - $retObj->params = $plugin->functions[$funcName]['params']; |
|
438 | - $retObj->description = $plugin->functions[$funcName]['description']; |
|
439 | - return $retObj; |
|
440 | - } |
|
416 | + /** |
|
417 | + * Get functions params and description |
|
418 | + * @param string $funcName |
|
419 | + * @return boolean|stdClass false if not found or object (name,params,description) |
|
420 | + * @throws \Exception if registering is not possible |
|
421 | + */ |
|
422 | + public function getFunctionDetails($funcName) |
|
423 | + { |
|
424 | + if (! isset($this->functionList[$funcName]) ) |
|
425 | + { |
|
426 | + return false; |
|
427 | + } |
|
428 | + $pluginName = $this->functionList[$funcName]['plugin']; // plugin name |
|
429 | + $plugin = $this->pluginsList[$pluginName]['object']; // plugin object |
|
430 | + if ($plugin === null) |
|
431 | + { |
|
432 | + $this->registerPlugin($pluginName); // can throw exception handled by caller |
|
433 | + } |
|
434 | + $retObj = new stdClass(); |
|
435 | + $retObj->name = $funcName; |
|
436 | + $retObj->plugin = $pluginName; |
|
437 | + $retObj->params = $plugin->functions[$funcName]['params']; |
|
438 | + $retObj->description = $plugin->functions[$funcName]['description']; |
|
439 | + return $retObj; |
|
440 | + } |
|
441 | 441 | |
442 | - /** |
|
443 | - * Evaluate function with parameters |
|
444 | - * @param string $funcName |
|
445 | - * @param mixed $params |
|
446 | - * @throws Exception |
|
447 | - * @return bool |
|
448 | - */ |
|
449 | - public function getFunctionEval(string $funcName,$params) : bool |
|
450 | - { |
|
451 | - if (! isset($this->functionList[$funcName]) ) |
|
452 | - { |
|
453 | - throw new Exception($funcName . ' not found.'); |
|
454 | - } |
|
455 | - $pluginName = $this->functionList[$funcName]['plugin']; // plugin name |
|
456 | - $plugin = $this->pluginsList[$pluginName]['object']; // plugin object |
|
442 | + /** |
|
443 | + * Evaluate function with parameters |
|
444 | + * @param string $funcName |
|
445 | + * @param mixed $params |
|
446 | + * @throws Exception |
|
447 | + * @return bool |
|
448 | + */ |
|
449 | + public function getFunctionEval(string $funcName,$params) : bool |
|
450 | + { |
|
451 | + if (! isset($this->functionList[$funcName]) ) |
|
452 | + { |
|
453 | + throw new Exception($funcName . ' not found.'); |
|
454 | + } |
|
455 | + $pluginName = $this->functionList[$funcName]['plugin']; // plugin name |
|
456 | + $plugin = $this->pluginsList[$pluginName]['object']; // plugin object |
|
457 | 457 | |
458 | - if ($plugin === null) |
|
459 | - { |
|
460 | - $this->registerPlugin($pluginName); // can throw exception handled by caller |
|
461 | - $plugin = $this->pluginsList[$pluginName]['object']; |
|
462 | - } |
|
458 | + if ($plugin === null) |
|
459 | + { |
|
460 | + $this->registerPlugin($pluginName); // can throw exception handled by caller |
|
461 | + $plugin = $this->pluginsList[$pluginName]['object']; |
|
462 | + } |
|
463 | 463 | |
464 | - $propertyName = $this->functionList[$funcName]['function']; |
|
465 | - $this->logClass->log('Using property '. $propertyName . ' of class : '.$pluginName,DEBUG); |
|
464 | + $propertyName = $this->functionList[$funcName]['function']; |
|
465 | + $this->logClass->log('Using property '. $propertyName . ' of class : '.$pluginName,DEBUG); |
|
466 | 466 | |
467 | - return $plugin->{$propertyName}($params); |
|
468 | - } |
|
467 | + return $plugin->{$propertyName}($params); |
|
468 | + } |
|
469 | 469 | |
470 | - public function evaluateFunctionString(string $functionString) : bool |
|
471 | - { |
|
472 | - $matches=array(); |
|
473 | - // Cleanup spaces |
|
474 | - //$functionString = $this->trapClass->ruleClass->eval_cleanup($functionString); |
|
475 | - //$this->logClass->log('eval cleanup : '.$functionString,DEBUG); |
|
470 | + public function evaluateFunctionString(string $functionString) : bool |
|
471 | + { |
|
472 | + $matches=array(); |
|
473 | + // Cleanup spaces |
|
474 | + //$functionString = $this->trapClass->ruleClass->eval_cleanup($functionString); |
|
475 | + //$this->logClass->log('eval cleanup : '.$functionString,DEBUG); |
|
476 | 476 | |
477 | - // Match function call |
|
478 | - $num=preg_match('/^__([a-zA-Z0-9]+)\((.+)\)$/', $functionString , $matches); |
|
479 | - if ($num !=1) |
|
480 | - { |
|
481 | - throw new \ErrorException('Function syntax error : ' . $functionString ); |
|
482 | - } |
|
483 | - $this->logClass->log('Got function : '. $matches[1] . ', params : '.$matches[2],DEBUG); |
|
484 | - $funcName=$matches[1]; |
|
477 | + // Match function call |
|
478 | + $num=preg_match('/^__([a-zA-Z0-9]+)\((.+)\)$/', $functionString , $matches); |
|
479 | + if ($num !=1) |
|
480 | + { |
|
481 | + throw new \ErrorException('Function syntax error : ' . $functionString ); |
|
482 | + } |
|
483 | + $this->logClass->log('Got function : '. $matches[1] . ', params : '.$matches[2],DEBUG); |
|
484 | + $funcName=$matches[1]; |
|
485 | 485 | |
486 | - // Get parameters comma separated |
|
487 | - $funcParams=str_getcsv($matches[2],',','"',"\\"); |
|
488 | - $this->logClass->log('Function params : ' . print_r($funcParams,true),DEBUG); |
|
486 | + // Get parameters comma separated |
|
487 | + $funcParams=str_getcsv($matches[2],',','"',"\\"); |
|
488 | + $this->logClass->log('Function params : ' . print_r($funcParams,true),DEBUG); |
|
489 | 489 | |
490 | - // return evaluation |
|
491 | - return $this->getFunctionEval($funcName, $funcParams); |
|
490 | + // return evaluation |
|
491 | + return $this->getFunctionEval($funcName, $funcParams); |
|
492 | 492 | |
493 | - } |
|
493 | + } |
|
494 | 494 | |
495 | 495 | } |
496 | 496 | |
497 | 497 | abstract class PluginTemplate |
498 | 498 | { |
499 | 499 | |
500 | - /** @var Logging $loggingClass */ |
|
501 | - private $loggingClass; |
|
500 | + /** @var Logging $loggingClass */ |
|
501 | + private $loggingClass; |
|
502 | 502 | |
503 | - /** @var string $name Name of plugin */ |
|
504 | - public $name; |
|
503 | + /** @var string $name Name of plugin */ |
|
504 | + public $name; |
|
505 | 505 | |
506 | - /** @var string $description Description of plugin */ |
|
507 | - public $description='Default plugin description'; |
|
506 | + /** @var string $description Description of plugin */ |
|
507 | + public $description='Default plugin description'; |
|
508 | 508 | |
509 | - /** @var array $functions Functions of this plugin for rule eval*/ |
|
510 | - public $functions=array(); |
|
509 | + /** @var array $functions Functions of this plugin for rule eval*/ |
|
510 | + public $functions=array(); |
|
511 | 511 | |
512 | - /** @var boolean $catchAllTraps Set to true if all traps will be sent to the plugin */ |
|
513 | - public $catchAllTraps=false; |
|
512 | + /** @var boolean $catchAllTraps Set to true if all traps will be sent to the plugin */ |
|
513 | + public $catchAllTraps=false; |
|
514 | 514 | |
515 | - /** @var boolean $processTraps Set to true if plugins can handle traps */ |
|
516 | - public $processTraps=false; |
|
515 | + /** @var boolean $processTraps Set to true if plugins can handle traps */ |
|
516 | + public $processTraps=false; |
|
517 | 517 | |
518 | - /** |
|
519 | - * @param \Trapdirector\Logging $loggingClass |
|
520 | - */ |
|
521 | - public function setLoggingClass($loggingClass) |
|
522 | - { |
|
523 | - $this->loggingClass = $loggingClass; |
|
524 | - } |
|
518 | + /** |
|
519 | + * @param \Trapdirector\Logging $loggingClass |
|
520 | + */ |
|
521 | + public function setLoggingClass($loggingClass) |
|
522 | + { |
|
523 | + $this->loggingClass = $loggingClass; |
|
524 | + } |
|
525 | 525 | |
526 | - /** |
|
527 | - * |
|
528 | - * @param string $message |
|
529 | - * @param int $level DEBUG/INFO/WARN/CRIT |
|
530 | - */ |
|
531 | - public function log($message,$level) |
|
532 | - { |
|
533 | - $this->loggingClass->log('[ '.get_class($this).'] '. $message, $level); |
|
534 | - } |
|
526 | + /** |
|
527 | + * |
|
528 | + * @param string $message |
|
529 | + * @param int $level DEBUG/INFO/WARN/CRIT |
|
530 | + */ |
|
531 | + public function log($message,$level) |
|
532 | + { |
|
533 | + $this->loggingClass->log('[ '.get_class($this).'] '. $message, $level); |
|
534 | + } |
|
535 | 535 | } |
536 | 536 | \ No newline at end of file |