@@ -20,8 +20,7 @@ discard block |
||
| 20 | 20 | * |
| 21 | 21 | * @access public |
| 22 | 22 | */ |
| 23 | -class cisco |
|
| 24 | -{ |
|
| 23 | +class cisco { |
|
| 25 | 24 | /** |
| 26 | 25 | * @var bool |
| 27 | 26 | */ |
@@ -81,8 +80,7 @@ discard block |
||
| 81 | 80 | * @param $password |
| 82 | 81 | * @param int $port |
| 83 | 82 | */ |
| 84 | - public function __construct($hostname, $username, $password, $port = 22) |
|
| 85 | - { |
|
| 83 | + public function __construct($hostname, $username, $password, $port = 22) { |
|
| 86 | 84 | $this->_hostname = $hostname; |
| 87 | 85 | $this->_username = $username; |
| 88 | 86 | $this->_password = $password; |
@@ -97,8 +95,7 @@ discard block |
||
| 97 | 95 | * @param int $index |
| 98 | 96 | * @return string |
| 99 | 97 | */ |
| 100 | - public function _string_shift(&$string, $index = 1) |
|
| 101 | - { |
|
| 98 | + public function _string_shift(&$string, $index = 1) { |
|
| 102 | 99 | $substr = mb_substr($string, 0, $index); |
| 103 | 100 | $string = mb_substr($string, $index); |
| 104 | 101 | return $substr; |
@@ -114,8 +111,7 @@ discard block |
||
| 114 | 111 | * @return String |
| 115 | 112 | * @access public |
| 116 | 113 | */ |
| 117 | - public function read($pattern = '', $regex = false) |
|
| 118 | - { |
|
| 114 | + public function read($pattern = '', $regex = false) { |
|
| 119 | 115 | //usleep(1000); |
| 120 | 116 | $this->_response = ''; |
| 121 | 117 | $match = $pattern; |
@@ -148,16 +144,14 @@ discard block |
||
| 148 | 144 | /** |
| 149 | 145 | * @param string $cmd |
| 150 | 146 | */ |
| 151 | - public function write($cmd) |
|
| 152 | - { |
|
| 147 | + public function write($cmd) { |
|
| 153 | 148 | fwrite($this->_stream, $cmd); |
| 154 | 149 | } |
| 155 | 150 | |
| 156 | 151 | /** |
| 157 | 152 | * @return bool |
| 158 | 153 | */ |
| 159 | - public function connect() |
|
| 160 | - { |
|
| 154 | + public function connect() { |
|
| 161 | 155 | //echo "Connecting to " . $this->_hostname . "<br>"; |
| 162 | 156 | $this->_ssh = ssh2_connect($this->_hostname, $this->_port); |
| 163 | 157 | if ($this->_ssh === false) { |
@@ -173,8 +167,7 @@ discard block |
||
| 173 | 167 | /** |
| 174 | 168 | * |
| 175 | 169 | */ |
| 176 | - public function parse_motd_and_prompt() |
|
| 177 | - { |
|
| 170 | + public function parse_motd_and_prompt() { |
|
| 178 | 171 | $this->_motd = trim($this->read('/.*[>|#]/', true)); |
| 179 | 172 | $this->write("\n"); |
| 180 | 173 | $this->_prompt = trim($this->read('/.*[>|#]/', true)); |
@@ -221,8 +214,7 @@ discard block |
||
| 221 | 214 | * @param string $cmd |
| 222 | 215 | * @return string |
| 223 | 216 | */ |
| 224 | - public function exec($cmd) |
|
| 225 | - { |
|
| 217 | + public function exec($cmd) { |
|
| 226 | 218 | if ($this->autoconnect === true && $this->connected === false) { |
| 227 | 219 | $this->connect(); |
| 228 | 220 | } |
@@ -247,16 +239,14 @@ discard block |
||
| 247 | 239 | /** |
| 248 | 240 | * @return string |
| 249 | 241 | */ |
| 250 | - public function get_response() |
|
| 251 | - { |
|
| 242 | + public function get_response() { |
|
| 252 | 243 | return $this->_response; |
| 253 | 244 | } |
| 254 | 245 | |
| 255 | 246 | /** |
| 256 | 247 | * |
| 257 | 248 | */ |
| 258 | - public function disconnect() |
|
| 259 | - { |
|
| 249 | + public function disconnect() { |
|
| 260 | 250 | //ssh2_exec($this->_ssh, 'quit'); |
| 261 | 251 | $this->connected = false; |
| 262 | 252 | } |
@@ -264,8 +254,7 @@ discard block |
||
| 264 | 254 | /** |
| 265 | 255 | * |
| 266 | 256 | */ |
| 267 | - public function __destruct() |
|
| 268 | - { |
|
| 257 | + public function __destruct() { |
|
| 269 | 258 | if ($this->connected === true) { |
| 270 | 259 | $this->disconnect(); |
| 271 | 260 | } |
@@ -275,8 +264,7 @@ discard block |
||
| 275 | 264 | * @param $int |
| 276 | 265 | * @return string |
| 277 | 266 | */ |
| 278 | - public function show_int_config($int) |
|
| 279 | - { |
|
| 267 | + public function show_int_config($int) { |
|
| 280 | 268 | // Enabled Only |
| 281 | 269 | //if (mb_strpos($this->_prompt, '#') === FALSE) |
| 282 | 270 | // die('Error: User must be enabled to use show_int_config()'.PHP_EOL); |
@@ -287,8 +275,7 @@ discard block |
||
| 287 | 275 | /** |
| 288 | 276 | * @return string |
| 289 | 277 | */ |
| 290 | - public function show_int_config_parser() |
|
| 291 | - { |
|
| 278 | + public function show_int_config_parser() { |
|
| 292 | 279 | $this->_data = explode("\r\n", $this->_data); |
| 293 | 280 | for ($i = 0; $i < 5; $i++) { |
| 294 | 281 | array_shift($this->_data); |
@@ -303,8 +290,7 @@ discard block |
||
| 303 | 290 | /** |
| 304 | 291 | * @return array |
| 305 | 292 | */ |
| 306 | - public function show_int_status() |
|
| 307 | - { |
|
| 293 | + public function show_int_status() { |
|
| 308 | 294 | $result = []; |
| 309 | 295 | $this->exec('show int status'); |
| 310 | 296 | $this->_data = explode("\r\n", $this->_data); |
@@ -337,8 +323,7 @@ discard block |
||
| 337 | 323 | /** |
| 338 | 324 | * @return array |
| 339 | 325 | */ |
| 340 | - public function show_log() |
|
| 341 | - { |
|
| 326 | + public function show_log() { |
|
| 342 | 327 | // Enabled Only |
| 343 | 328 | if (mb_strpos($this->_prompt, '#') === false) { |
| 344 | 329 | die('Error: User must be enabled to use show_log()'.PHP_EOL); |
@@ -369,8 +354,7 @@ discard block |
||
| 369 | 354 | * @param $int |
| 370 | 355 | * @return array |
| 371 | 356 | */ |
| 372 | - public function show_int($int) |
|
| 373 | - { |
|
| 357 | + public function show_int($int) { |
|
| 374 | 358 | $result = []; |
| 375 | 359 | $this->exec('show int '.$int); |
| 376 | 360 | $this->_data = explode("\r\n", $this->_data); |
@@ -557,8 +541,7 @@ discard block |
||
| 557 | 541 | /** |
| 558 | 542 | * @return array |
| 559 | 543 | */ |
| 560 | - public function trunk_ports() |
|
| 561 | - { |
|
| 544 | + public function trunk_ports() { |
|
| 562 | 545 | $result = []; |
| 563 | 546 | $this->exec('show interface status | include trunk'); |
| 564 | 547 | $this->_data = explode("\r\n", $this->_data); |
@@ -577,8 +560,7 @@ discard block |
||
| 577 | 560 | /** |
| 578 | 561 | * @return array |
| 579 | 562 | */ |
| 580 | - public function vlans() |
|
| 581 | - { |
|
| 563 | + public function vlans() { |
|
| 582 | 564 | $result = []; |
| 583 | 565 | $this->exec('show spanning-tree summary | include ^VLAN'); |
| 584 | 566 | $this->_data = explode("\r\n", $this->_data); |
@@ -598,8 +580,7 @@ discard block |
||
| 598 | 580 | /** |
| 599 | 581 | * @return array |
| 600 | 582 | */ |
| 601 | - public function errdisabled() |
|
| 602 | - { |
|
| 583 | + public function errdisabled() { |
|
| 603 | 584 | $result = []; |
| 604 | 585 | $this->exec('show int status err'); |
| 605 | 586 | $this->_data = explode("\r\n", $this->_data); |
@@ -629,8 +610,7 @@ discard block |
||
| 629 | 610 | /** |
| 630 | 611 | * @return array |
| 631 | 612 | */ |
| 632 | - public function dhcpsnoop_bindings() |
|
| 633 | - { |
|
| 613 | + public function dhcpsnoop_bindings() { |
|
| 634 | 614 | $result = []; |
| 635 | 615 | $this->exec('sh ip dhcp snoop binding | inc dhcp-snooping'); |
| 636 | 616 | $this->_data = explode("\r\n", $this->_data); |
@@ -657,8 +637,7 @@ discard block |
||
| 657 | 637 | /** |
| 658 | 638 | * @return array |
| 659 | 639 | */ |
| 660 | - public function mac_address_table() |
|
| 661 | - { |
|
| 640 | + public function mac_address_table() { |
|
| 662 | 641 | $result = []; |
| 663 | 642 | $omit = $this->trunk_ports(); |
| 664 | 643 | $this->exec('show mac address-table | exclude CPU'); |
@@ -687,8 +666,7 @@ discard block |
||
| 687 | 666 | /** |
| 688 | 667 | * @return array |
| 689 | 668 | */ |
| 690 | - public function arp_table() |
|
| 691 | - { |
|
| 669 | + public function arp_table() { |
|
| 692 | 670 | $result = []; |
| 693 | 671 | $this->exec('show arp | exc Incomplete'); |
| 694 | 672 | $this->_data = explode("\r\n", $this->_data); |
@@ -718,8 +696,7 @@ discard block |
||
| 718 | 696 | /** |
| 719 | 697 | * @return array |
| 720 | 698 | */ |
| 721 | - public function ipv6_neighbor_table() |
|
| 722 | - { |
|
| 699 | + public function ipv6_neighbor_table() { |
|
| 723 | 700 | $result = []; |
| 724 | 701 | $this->exec('show ipv6 neighbors | exc INCMP'); |
| 725 | 702 | $this->_data = explode("\r\n", $this->_data); |
@@ -746,8 +723,7 @@ discard block |
||
| 746 | 723 | /** |
| 747 | 724 | * @return array |
| 748 | 725 | */ |
| 749 | - public function ipv6_routers() |
|
| 750 | - { |
|
| 726 | + public function ipv6_routers() { |
|
| 751 | 727 | $result = []; |
| 752 | 728 | $this->exec('show ipv6 routers'); |
| 753 | 729 | $this->_data = explode("\r\n", $this->_data); |
@@ -776,8 +752,7 @@ discard block |
||
| 776 | 752 | * @param $config |
| 777 | 753 | * @return null|boolean |
| 778 | 754 | */ |
| 779 | - public function configure($config) |
|
| 780 | - { |
|
| 755 | + public function configure($config) { |
|
| 781 | 756 | // USE AT OWN RISK: This function will apply configuration statements to a device. |
| 782 | 757 | // Enabled Only |
| 783 | 758 | if (mb_strpos($this->_prompt, '#') === false) { |
@@ -805,8 +780,7 @@ discard block |
||
| 805 | 780 | /** |
| 806 | 781 | * @return bool |
| 807 | 782 | */ |
| 808 | - public function write_config() |
|
| 809 | - { |
|
| 783 | + public function write_config() { |
|
| 810 | 784 | $this->exec('write'); |
| 811 | 785 | if (mb_strpos($this->_data, '[OK]') !== false) { |
| 812 | 786 | return true; |
@@ -819,15 +793,13 @@ discard block |
||
| 819 | 793 | /** |
| 820 | 794 | * Class cisco_parser |
| 821 | 795 | */ |
| 822 | -class cisco_parser |
|
| 823 | -{ |
|
| 796 | +class cisco_parser { |
|
| 824 | 797 | /** |
| 825 | 798 | * @param $lines |
| 826 | 799 | * @param integer $x |
| 827 | 800 | * @return int |
| 828 | 801 | */ |
| 829 | - public function get_space_depth($lines, $x) |
|
| 830 | - { |
|
| 802 | + public function get_space_depth($lines, $x) { |
|
| 831 | 803 | if (preg_match('/^(?P<spaces>\s+)*(?P<rest>\S.*)$/', $lines[$x], $matches)) { |
| 832 | 804 | $cdepth = mb_strlen($matches['spaces']); |
| 833 | 805 | } else { |
@@ -842,8 +814,7 @@ discard block |
||
| 842 | 814 | * @param int $depth |
| 843 | 815 | * @return array |
| 844 | 816 | */ |
| 845 | - public function parse_cisco_children($lines, $x = 0, $depth = 0) |
|
| 846 | - { |
|
| 817 | + public function parse_cisco_children($lines, $x = 0, $depth = 0) { |
|
| 847 | 818 | //global $x; |
| 848 | 819 | $data = []; |
| 849 | 820 | $last_command = false; |