@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | /** |
25 | 25 | * @var bool |
26 | 26 | */ |
27 | - public $autoconnect = TRUE; // Sets whether or not exec() will automatically connect() if needed |
|
27 | + public $autoconnect = true; // Sets whether or not exec() will automatically connect() if needed |
|
28 | 28 | /** |
29 | 29 | * @var int |
30 | 30 | */ |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | /** |
33 | 33 | * @var bool |
34 | 34 | */ |
35 | - public $connected = FALSE; // True/False Whether or not you are currently connected |
|
35 | + public $connected = false; // True/False Whether or not you are currently connected |
|
36 | 36 | /** |
37 | 37 | * @var |
38 | 38 | */ |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | * @return String |
111 | 111 | * @access public |
112 | 112 | */ |
113 | - public function read($pattern = '', $regex = FALSE) { |
|
113 | + public function read($pattern = '', $regex = false) { |
|
114 | 114 | //usleep(1000); |
115 | 115 | $this->_response = ''; |
116 | 116 | $match = $pattern; |
@@ -121,9 +121,9 @@ discard block |
||
121 | 121 | //echo 'M:'.print_r($matches, TRUE).'<br>'; |
122 | 122 | $match = isset($matches[0]) ? $matches[0] : []; |
123 | 123 | } |
124 | - $pos = !empty($match) ? mb_strpos($this->_response, $match) : FALSE; |
|
124 | + $pos = !empty($match) ? mb_strpos($this->_response, $match) : false; |
|
125 | 125 | //echo ++$i . "POS:".var_export($pos, TRUE).'<br>'; |
126 | - if ($pos !== FALSE) { |
|
126 | + if ($pos !== false) { |
|
127 | 127 | //echo "$match Matching $pattern @ $pos <br>"; |
128 | 128 | return $this->_string_shift($this->_response, $pos + mb_strlen($match)); |
129 | 129 | } |
@@ -153,28 +153,28 @@ discard block |
||
153 | 153 | public function connect() { |
154 | 154 | //echo "Connecting to " . $this->_hostname . "<br>"; |
155 | 155 | $this->_ssh = ssh2_connect($this->_hostname, $this->_port); |
156 | - if ($this->_ssh === FALSE) |
|
157 | - return FALSE; |
|
156 | + if ($this->_ssh === false) |
|
157 | + return false; |
|
158 | 158 | ssh2_auth_password($this->_ssh, $this->_username, $this->_password); |
159 | 159 | $this->_stream = ssh2_shell($this->_ssh); |
160 | - $this->connected = TRUE; |
|
160 | + $this->connected = true; |
|
161 | 161 | $this->parse_motd_and_prompt(); |
162 | - return TRUE; |
|
162 | + return true; |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | /** |
166 | 166 | * |
167 | 167 | */ |
168 | 168 | public function parse_motd_and_prompt() { |
169 | - $this->_motd = trim($this->read('/.*[>|#]/', TRUE)); |
|
169 | + $this->_motd = trim($this->read('/.*[>|#]/', true)); |
|
170 | 170 | $this->write("\n"); |
171 | - $this->_prompt = trim($this->read('/.*[>|#]/', TRUE)); |
|
171 | + $this->_prompt = trim($this->read('/.*[>|#]/', true)); |
|
172 | 172 | $length = mb_strlen($this->_prompt); |
173 | 173 | if (mb_substr($this->_motd, -$length) == $this->_prompt) |
174 | 174 | $this->_motd = mb_substr($this->_motd, 0, -$length); |
175 | 175 | //echo "MOTD:".$this->_motd."<br>"; |
176 | 176 | //echo "Prompt:".$this->_prompt.'<br>'; |
177 | - return TRUE; |
|
177 | + return true; |
|
178 | 178 | sleep(1); |
179 | 179 | $this->_motd = ''; |
180 | 180 | while ($this->_response = fgets($this->_stream)) |
@@ -211,13 +211,13 @@ discard block |
||
211 | 211 | * @return string |
212 | 212 | */ |
213 | 213 | public function exec($cmd) { |
214 | - if ($this->autoconnect === TRUE && $this->connected === FALSE) |
|
214 | + if ($this->autoconnect === true && $this->connected === false) |
|
215 | 215 | $this->connect(); |
216 | 216 | if (mb_substr($cmd, -1) != "\n") { |
217 | 217 | //error_log("Adding NEWLINE Character To SSH2 Command $cmd", __LINE__, __FILE__); |
218 | 218 | $cmd .= "\n"; |
219 | 219 | } |
220 | - $this->_data = FALSE; |
|
220 | + $this->_data = false; |
|
221 | 221 | fwrite($this->_stream, $cmd); |
222 | 222 | $this->_response = trim($this->read($this->_prompt)); |
223 | 223 | $length = mb_strlen($this->_prompt); |
@@ -243,14 +243,14 @@ discard block |
||
243 | 243 | */ |
244 | 244 | public function disconnect() { |
245 | 245 | //ssh2_exec($this->_ssh, 'quit'); |
246 | - $this->connected = FALSE; |
|
246 | + $this->connected = false; |
|
247 | 247 | } |
248 | 248 | |
249 | 249 | /** |
250 | 250 | * |
251 | 251 | */ |
252 | 252 | public function __destruct() { |
253 | - if ($this->connected === TRUE) |
|
253 | + if ($this->connected === true) |
|
254 | 254 | $this->disconnect(); |
255 | 255 | } |
256 | 256 | |
@@ -316,7 +316,7 @@ discard block |
||
316 | 316 | */ |
317 | 317 | public function show_log() { |
318 | 318 | // Enabled Only |
319 | - if (mb_strpos($this->_prompt, '#') === FALSE) |
|
319 | + if (mb_strpos($this->_prompt, '#') === false) |
|
320 | 320 | die('Error: User must be enabled to use show_log()'.PHP_EOL); |
321 | 321 | $result = []; |
322 | 322 | $this->exec('sh log | inc %'); |
@@ -349,19 +349,19 @@ discard block |
||
349 | 349 | $this->_data = explode("\r\n", $this->_data); |
350 | 350 | foreach ($this->_data as $entry) { |
351 | 351 | $entry = trim($entry); |
352 | - if (mb_strpos($entry, 'line protocol') !== FALSE) { |
|
352 | + if (mb_strpos($entry, 'line protocol') !== false) { |
|
353 | 353 | $result['interface'] = mb_substr($entry, 0, mb_strpos($entry, ' ')); |
354 | - if (mb_strpos($entry, 'administratively') !== FALSE) { |
|
354 | + if (mb_strpos($entry, 'administratively') !== false) { |
|
355 | 355 | $result['status'] = 'disabled'; |
356 | 356 | } elseif (mb_substr($entry, mb_strpos($entry, 'line protocol') + 17, 2) == 'up') { |
357 | 357 | $result['status'] = 'connected'; |
358 | 358 | } else { |
359 | 359 | $result['status'] = 'notconnect'; |
360 | 360 | } // if .. else |
361 | - } elseif (mb_strpos($entry, 'Description: ') !== FALSE) { |
|
361 | + } elseif (mb_strpos($entry, 'Description: ') !== false) { |
|
362 | 362 | $entry = explode(':', $entry); |
363 | 363 | $result['description'] = trim($entry[1]); |
364 | - } elseif (mb_strpos($entry, 'MTU') !== FALSE) { |
|
364 | + } elseif (mb_strpos($entry, 'MTU') !== false) { |
|
365 | 365 | $entry = explode(',', $entry); |
366 | 366 | $entry[0] = trim($entry[0]); |
367 | 367 | $entry[0] = explode(' ', $entry[0]); |
@@ -372,33 +372,33 @@ discard block |
||
372 | 372 | $entry[2] = trim($entry[2]); |
373 | 373 | $entry[2] = explode(' ', $entry[2]); |
374 | 374 | $result['dly'] = $entry[2][1]; |
375 | - } elseif (mb_strpos($entry, 'duplex') !== FALSE) { |
|
375 | + } elseif (mb_strpos($entry, 'duplex') !== false) { |
|
376 | 376 | $entry = explode(',', $entry); |
377 | 377 | $entry[0] = trim($entry[0]); |
378 | 378 | $entry[0] = explode(' ', $entry[0]); |
379 | 379 | $entry[0][0] = explode('-', $entry[0][0]); |
380 | 380 | $result['duplex'] = strtolower($entry[0][0][0]); |
381 | 381 | $entry[1] = trim($entry[1]); |
382 | - if (mb_strpos($entry[1], 'Auto') !== FALSE) { |
|
382 | + if (mb_strpos($entry[1], 'Auto') !== false) { |
|
383 | 383 | $result['speed'] = 'auto'; |
384 | 384 | } else { |
385 | 385 | $result['speed'] = (int) $entry[1]; |
386 | 386 | } // if .. else |
387 | 387 | $entry[2] = rtrim($entry[2]); |
388 | 388 | $result['type'] = mb_substr($entry[2], mb_strrpos($entry[2], ' ') + 1); |
389 | - } elseif (mb_strpos($entry, 'input rate') !== FALSE) { |
|
389 | + } elseif (mb_strpos($entry, 'input rate') !== false) { |
|
390 | 390 | $entry = explode(',', $entry); |
391 | 391 | $result['in_rate'] = mb_substr($entry[0], mb_strpos($entry[0], 'rate') + 5, mb_strrpos($entry[0], ' ') - (mb_strpos($entry[0], 'rate') + 5)); |
392 | 392 | $entry = trim($entry[1]); |
393 | 393 | $entry = explode(' ', $entry); |
394 | 394 | $result['in_packet_rate'] = $entry[0]; |
395 | - } elseif (mb_strpos($entry, 'output rate') !== FALSE) { |
|
395 | + } elseif (mb_strpos($entry, 'output rate') !== false) { |
|
396 | 396 | $entry = explode(',', $entry); |
397 | 397 | $result['out_rate'] = mb_substr($entry[0], mb_strpos($entry[0], 'rate') + 5, mb_strrpos($entry[0], ' ') - (mb_strpos($entry[0], 'rate') + 5)); |
398 | 398 | $entry = trim($entry[1]); |
399 | 399 | $entry = explode(' ', $entry); |
400 | 400 | $result['out_packet_rate'] = $entry[0]; |
401 | - } elseif (mb_strpos($entry, 'packets input') !== FALSE) { |
|
401 | + } elseif (mb_strpos($entry, 'packets input') !== false) { |
|
402 | 402 | $entry = explode(',', $entry); |
403 | 403 | $entry[0] = trim($entry[0]); |
404 | 404 | $entry[0] = explode(' ', $entry[0]); |
@@ -411,7 +411,7 @@ discard block |
||
411 | 411 | $entry[2] = explode(' ', $entry[2]); |
412 | 412 | $result['no_buffer'] = $entry[2][0]; |
413 | 413 | } // if |
414 | - } elseif (mb_strpos($entry, 'Received') !== FALSE) { |
|
414 | + } elseif (mb_strpos($entry, 'Received') !== false) { |
|
415 | 415 | $entry = explode(',', $entry); |
416 | 416 | $entry[0] = trim($entry[0]); |
417 | 417 | $entry[0] = explode(' ', $entry[0]); |
@@ -427,7 +427,7 @@ discard block |
||
427 | 427 | $entry[3] = explode(' ', $entry[3]); |
428 | 428 | $result['throttle'] = $entry[3][0]; |
429 | 429 | } // if |
430 | - } elseif (mb_strpos($entry, 'CRC') !== FALSE) { |
|
430 | + } elseif (mb_strpos($entry, 'CRC') !== false) { |
|
431 | 431 | $entry = explode(',', $entry); |
432 | 432 | $entry[0] = trim($entry[0]); |
433 | 433 | $entry[0] = explode(' ', $entry[0]); |
@@ -444,7 +444,7 @@ discard block |
||
444 | 444 | $entry[4] = trim($entry[4]); |
445 | 445 | $entry[4] = explode(' ', $entry[4]); |
446 | 446 | $result['ignored'] = $entry[4][0]; |
447 | - } elseif (mb_strpos($entry, 'watchdog') !== FALSE) { |
|
447 | + } elseif (mb_strpos($entry, 'watchdog') !== false) { |
|
448 | 448 | $entry = explode(',', $entry); |
449 | 449 | $entry[0] = trim($entry[0]); |
450 | 450 | $entry[0] = explode(' ', $entry[0]); |
@@ -457,11 +457,11 @@ discard block |
||
457 | 457 | $entry[2] = explode(' ', $entry[2]); |
458 | 458 | $result['pause_in'] = $entry[2][0]; |
459 | 459 | } // if |
460 | - } elseif (mb_strpos($entry, 'dribble') !== FALSE) { |
|
460 | + } elseif (mb_strpos($entry, 'dribble') !== false) { |
|
461 | 461 | $entry = trim($entry); |
462 | 462 | $entry = explode(' ', $entry); |
463 | 463 | $result['in_dribble'] = $entry[0]; |
464 | - } elseif (mb_strpos($entry, 'packets output') !== FALSE) { |
|
464 | + } elseif (mb_strpos($entry, 'packets output') !== false) { |
|
465 | 465 | $entry = explode(',', $entry); |
466 | 466 | $entry[0] = trim($entry[0]); |
467 | 467 | $entry[0] = explode(' ', $entry[0]); |
@@ -472,7 +472,7 @@ discard block |
||
472 | 472 | $entry[2] = trim($entry[2]); |
473 | 473 | $entry[2] = explode(' ', $entry[2]); |
474 | 474 | $result['underrun'] = $entry[2][0]; |
475 | - } elseif (mb_strpos($entry, 'output errors') !== FALSE) { |
|
475 | + } elseif (mb_strpos($entry, 'output errors') !== false) { |
|
476 | 476 | $entry = explode(',', $entry); |
477 | 477 | $entry[0] = trim($entry[0]); |
478 | 478 | $entry[0] = explode(' ', $entry[0]); |
@@ -489,7 +489,7 @@ discard block |
||
489 | 489 | $entry[1] = explode(' ', $entry[1]); |
490 | 490 | $result['reset'] = $entry[1][0]; |
491 | 491 | } // if .. else |
492 | - } elseif (mb_strpos($entry, 'babbles') !== FALSE) { |
|
492 | + } elseif (mb_strpos($entry, 'babbles') !== false) { |
|
493 | 493 | $entry = explode(',', $entry); |
494 | 494 | $entry[0] = trim($entry[0]); |
495 | 495 | $entry[0] = explode(' ', $entry[0]); |
@@ -500,7 +500,7 @@ discard block |
||
500 | 500 | $entry[2] = trim($entry[2]); |
501 | 501 | $entry[2] = explode(' ', $entry[2]); |
502 | 502 | $result['deferred'] = $entry[2][0]; |
503 | - } elseif (mb_strpos($entry, 'lost carrier') !== FALSE) { |
|
503 | + } elseif (mb_strpos($entry, 'lost carrier') !== false) { |
|
504 | 504 | $entry = explode(',', $entry); |
505 | 505 | $entry[0] = trim($entry[0]); |
506 | 506 | $entry[0] = explode(' ', $entry[0]); |
@@ -513,7 +513,7 @@ discard block |
||
513 | 513 | $entry[2] = explode(' ', $entry[2]); |
514 | 514 | $result['pause_out'] = $entry[2][0]; |
515 | 515 | } // if |
516 | - } elseif (mb_strpos($entry, 'output buffer failures') !== FALSE) { |
|
516 | + } elseif (mb_strpos($entry, 'output buffer failures') !== false) { |
|
517 | 517 | $entry = explode(',', $entry); |
518 | 518 | $entry[0] = trim($entry[0]); |
519 | 519 | $entry[0] = explode(' ', $entry[0]); |
@@ -640,7 +640,7 @@ discard block |
||
640 | 640 | $entry = []; |
641 | 641 | $entry['mac_address'] = $temp[1]; |
642 | 642 | $entry['interface'] = $temp[3]; |
643 | - if (in_array($entry['interface'], $omit) == FALSE) { |
|
643 | + if (in_array($entry['interface'], $omit) == false) { |
|
644 | 644 | $result[] = $entry; |
645 | 645 | } // if |
646 | 646 | } // foreach |
@@ -736,13 +736,13 @@ discard block |
||
736 | 736 | public function configure($config) { |
737 | 737 | // USE AT OWN RISK: This function will apply configuration statements to a device. |
738 | 738 | // Enabled Only |
739 | - if (mb_strpos($this->_prompt, '#') === FALSE) |
|
739 | + if (mb_strpos($this->_prompt, '#') === false) |
|
740 | 740 | die('Error: User must be enabled to use configure()'.PHP_EOL); |
741 | 741 | $this->_data = explode("\n", $config); |
742 | 742 | $this->_ssh->write("config t\n"); |
743 | 743 | $config_prompt = $this->_ssh->read('/.*[>|#]/', NET_SSH2_READ_REGEX); |
744 | 744 | $config_prompt = str_replace("\r\n", '', trim($config_prompt)); |
745 | - if (mb_strpos($config_prompt, 'config)#') !== FALSE) { |
|
745 | + if (mb_strpos($config_prompt, 'config)#') !== false) { |
|
746 | 746 | foreach ($this->_data as $c) |
747 | 747 | $this->_ssh->write($c."\n"); |
748 | 748 | $this->_ssh->write("end\n"); |
@@ -750,7 +750,7 @@ discard block |
||
750 | 750 | $result = $this->_ssh->read($this->_prompt); |
751 | 751 | $result = explode("\r\n", $result); |
752 | 752 | if (count($this->_data) == (count($result) - 2)) |
753 | - return TRUE; |
|
753 | + return true; |
|
754 | 754 | else |
755 | 755 | die('Error: Switch rejected configuration: '.PHP_EOL.$config."\n"); |
756 | 756 | } |
@@ -760,10 +760,10 @@ discard block |
||
760 | 760 | */ |
761 | 761 | public function write_config() { |
762 | 762 | $this->exec('write'); |
763 | - if (mb_strpos($this->_data, '[OK]') !== FALSE) |
|
764 | - return TRUE; |
|
763 | + if (mb_strpos($this->_data, '[OK]') !== false) |
|
764 | + return true; |
|
765 | 765 | else |
766 | - return FALSE; |
|
766 | + return false; |
|
767 | 767 | } |
768 | 768 | } |
769 | 769 | |
@@ -794,13 +794,13 @@ discard block |
||
794 | 794 | public function parse_cisco_children($lines, $x = 0, $depth = 0) { |
795 | 795 | //global $x; |
796 | 796 | $data = []; |
797 | - $last_command = FALSE; |
|
797 | + $last_command = false; |
|
798 | 798 | for ($xMax = count($lines); $x < $xMax; $x++) { |
799 | 799 | $cdepth = $this->get_space_depth($lines, $x); |
800 | 800 | $command = ltrim($lines[$x]); |
801 | 801 | $arguments = ''; |
802 | 802 | $spacepos = mb_strpos($command, ' '); |
803 | - if ($spacepos !== FALSE) { |
|
803 | + if ($spacepos !== false) { |
|
804 | 804 | $arguments = mb_substr($command, $spacepos + 1); |
805 | 805 | $command = mb_substr($command, 0, $spacepos); |
806 | 806 | //echo "Got C|$command|A|$arguments|<br>"; |