source: trunk/Modules/NetworkConfigRouterOS/Routerboard2.php

Last change on this file was 888, checked in by chronos, 4 years ago
  • Modified: More static types added.
File size: 2.0 KB
Line 
1<?php
2
3include_once('SSH.php');
4
5class Routerboard extends SSH
6{
7 public array $Methods = array(
8 'kex' => 'diffie-hellman-group1-sha1',
9 'client_to_server' => array('crypt' => '3des-cbc', 'comp' => 'none'),
10 'server_to_client' => array('crypt' => 'aes256-cbc,aes192-cbc,aes128-cbc', 'comp' => 'none')
11 );
12
13 function Execute(array $Commands): array
14 {
15 if (is_array($Commands)) $Commands = implode(';', $Commands);
16 return parent::Execute($Commands);
17 }
18
19 function GetItem($Command): array
20 {
21 $Result = $this->Execute($Command);
22 array_pop($Result);
23 $List = array();
24 foreach ($Result as $ResultLine)
25 {
26 $ResultLineParts = explode(' ', trim($ResultLine));
27 if ($ResultLineParts[1][0] == '"') $ResultLineParts[1] = substr($ResultLineParts[1], 1, -1); // Remove quotes
28 $List[substr($ResultLineParts[0], 0, -1)] = $ResultLineParts[1];
29 }
30 return $List;
31 }
32
33 function GetList($Command, $Properties): array
34 {
35 $PropertyList = '"';
36 foreach ($Properties as $Property)
37 {
38 $PropertyList .= $Property.'=".[get $i '.$Property.']." ';
39 }
40 $PropertyList = substr($PropertyList, 0, -3);
41 $Result = $this->Execute($Command.' {:foreach i in=[find] do={:put ('.$PropertyList.')}}');
42 $List = array();
43 foreach ($Result as $ResultLine)
44 {
45 $ResultLineParts = explode(' ', $ResultLine);
46 $ListItem = array();
47 foreach ($ResultLineParts as $ResultLinePart)
48 {
49 $Value = explode('=', $ResultLinePart);
50 $ListItem[$Value[0]] = $Value[1];
51 }
52 $List[] = $ListItem;
53 }
54 return $List;
55 }
56
57 function GetSystemResource(): array
58 {
59 return $this->GetItem('/system resource print');
60 }
61
62 function GetFirewallFilterList(): array
63 {
64 return $this->GetList('/ip firewall nat', array('src-address', 'dst-address', 'bytes'));
65 }
66
67 function GetDHCPServerLeasesList(): array
68 {
69 return $this->GetList('/ip dhcp-server lease', array('address', 'active-address', 'comment', 'lease-time', 'status', 'host-name'));
70 }
71}
Note: See TracBrowser for help on using the repository browser.