Conditions | 17 |
Paths | 921 |
Total Lines | 146 |
Code Lines | 74 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
85 | public function mibAction() |
||
86 | { |
||
87 | $this->prepareTabs()->activate('mib'); |
||
88 | |||
89 | $this->view->uploadStatus=null; |
||
90 | // check if it is an ajax query |
||
91 | if ($this->getRequest()->isPost()) |
||
92 | { |
||
93 | $postData=$this->getRequest()->getPost(); |
||
94 | /** Check for action update or check update */ |
||
95 | if (isset($postData['action'])) |
||
96 | { |
||
97 | $action=$postData['action']; |
||
98 | if ($action == 'update_mib_db') |
||
99 | { // Do the update in background |
||
100 | $return=exec('icingacli trapdirector mib update --pid /tmp/trapdirector_update.pid'); |
||
101 | if (preg_match('/OK/',$return)) |
||
102 | { |
||
103 | $this->_helper->json(array('status'=>'OK')); |
||
104 | } |
||
105 | // Error |
||
106 | $this->_helper->json(array('status'=>$return)); |
||
107 | } |
||
108 | if ($action == 'check_update') |
||
109 | { |
||
110 | $file=@fopen('/tmp/trapdirector_update.pid','r'); |
||
111 | if ($file == false) |
||
112 | { // process is dead |
||
113 | $this->_helper->json(array('status'=>'tu quoque fili','err'=>'Cannot open file')); |
||
114 | return; |
||
115 | } |
||
116 | $pid=fgets($file); |
||
117 | $output=array(); |
||
118 | $retVal=0; |
||
119 | exec('ps '.$pid,$output,$retVal); |
||
120 | if ($retVal == 0) |
||
121 | { // process is alive |
||
122 | $this->_helper->json(array('status'=>'Alive and kicking')); |
||
123 | } |
||
124 | else |
||
125 | { // process is dead |
||
126 | $this->_helper->json(array('status'=>'tu quoque fili','err'=>'no proc'.$pid)); |
||
127 | } |
||
128 | } |
||
129 | $this->_helper->json(array('status'=>'ERR : no '.$action.' action possible' )); |
||
130 | } |
||
131 | /** Check for mib file UPLOAD */ |
||
132 | if (isset($_FILES['mibfile'])) |
||
133 | { |
||
134 | $name=filter_var($_FILES['mibfile']['name'],FILTER_SANITIZE_STRING); |
||
135 | $DirConf=explode(':',$this->Config()->get('config', 'snmptranslate_dirs')); |
||
136 | $destDir=array_shift($DirConf); |
||
137 | if (!is_dir($destDir)) |
||
138 | { |
||
139 | $this->view->uploadStatus="ERROR : no $destDir directory, check module configuration"; |
||
140 | } |
||
141 | else |
||
142 | { |
||
143 | if (!is_writable($destDir)) |
||
144 | { |
||
145 | $this->view->uploadStatus="ERROR : $destDir directory is not writable"; |
||
146 | } |
||
147 | else |
||
148 | { |
||
149 | $destination = $destDir .'/'.$name; //$this->Module()->getBaseDir() . "/mibs/$name"; |
||
150 | $sourceTmpNam=filter_var($_FILES['mibfile']['tmp_name'],FILTER_SANITIZE_STRING); |
||
151 | if (move_uploaded_file($sourceTmpNam,$destination)===false) |
||
152 | { |
||
153 | $this->view->uploadStatus="ERROR, file $destination not loaded. Check file and path name or selinux violations"; |
||
154 | } |
||
155 | else |
||
156 | { |
||
157 | $this->view->uploadStatus="File $name uploaded in $destDir"; |
||
158 | } |
||
159 | } |
||
160 | } |
||
161 | |||
162 | } |
||
163 | |||
164 | } |
||
165 | |||
166 | // snmptranslate tests |
||
167 | $snmptranslate = $this->Config()->get('config', 'snmptranslate'); |
||
168 | $this->view->snmptranslate_bin=$snmptranslate; |
||
169 | $this->view->snmptranslate_state='warn'; |
||
170 | if (is_executable ( $snmptranslate )) |
||
171 | { |
||
172 | $translate=exec($snmptranslate . ' 1'); |
||
173 | if (preg_match('/iso/',$translate)) |
||
174 | { |
||
175 | $this->view->snmptranslate='works fine'; |
||
176 | $this->view->snmptranslate_state='ok'; |
||
177 | } |
||
178 | else |
||
179 | { |
||
180 | $this->view->snmptranslate='can execute but no resolution'; |
||
181 | } |
||
182 | } |
||
183 | else |
||
184 | { |
||
185 | $this->view->snmptranslate='cannot execute'; |
||
186 | } |
||
187 | |||
188 | // mib database |
||
189 | |||
190 | $this->view->mibDbCount=$this->getMIB()->countObjects(); |
||
191 | $this->view->mibDbCountTrap=$this->getMIB()->countObjects(null,21); |
||
192 | |||
193 | // mib dirs |
||
194 | $DirConf=$this->Config()->get('config', 'snmptranslate_dirs'); |
||
195 | $dirArray=explode(':',$DirConf); |
||
196 | |||
197 | // Get base directories from net-snmp-config |
||
198 | $output=$matches=array(); |
||
199 | $retVal=0; |
||
200 | $sysDirs=exec('net-snmp-config --default-mibdirs',$output,$retVal); |
||
201 | if ($retVal==0) |
||
202 | { |
||
203 | $dirArray=array_merge($dirArray,explode(':',$sysDirs)); |
||
204 | } |
||
205 | else |
||
206 | { |
||
207 | $translateOut=exec($this->Config()->get('config', 'snmptranslate') . ' -Dinit_mib .1.3 2>&1 | grep MIBDIRS'); |
||
208 | if (preg_match('/MIBDIRS.*\'([^\']+)\'/',$translateOut,$matches)) |
||
209 | { |
||
210 | $dirArray=array_merge($dirArray,explode(':',$matches[1])); |
||
211 | } |
||
212 | else |
||
213 | { |
||
214 | array_push($dirArray,'Install net-snmp-config to see system directories'); |
||
215 | } |
||
216 | } |
||
217 | |||
218 | $this->view->dirArray=$dirArray; |
||
219 | |||
220 | $output=null; |
||
221 | foreach (explode(':',$DirConf) as $mibdir) |
||
222 | { |
||
223 | exec('ls '.$mibdir.' | grep -v traplist.txt',$output); |
||
224 | } |
||
225 | //$i=0;$listFiles='';while (isset($output[$i])) $listFiles.=$output[$i++]; |
||
226 | //$this->view->fileList=explode(' ',$listFiles); |
||
227 | $this->view->fileList=$output; |
||
228 | |||
229 | // Zend form |
||
230 | $this->view->form= new UploadForm(); |
||
231 | //$this->view->form= new Form('upload-form'); |
||
429 |
The
break
statement is not necessary if it is preceded for example by areturn
statement:If you would like to keep this construct to be consistent with other
case
statements, you can safely mark this issue as a false-positive.