forked from pear2/Net_RouterOS
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added unit tests for Util::comment();
Marked the test for Util::count()'s mode be incomplete, due to it being absent in the final PHP 5.6 builds; Altered Client examples according to the Wiki; Added Util example files, matching those in the Wiki; Fixed the suggested firewall rule in Roscon's connection error message.
- Loading branch information
Showing
26 changed files
with
262 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
use PEAR2\Net\RouterOS; | ||
require_once 'PEAR2/Autoload.php'; | ||
|
||
$util = new RouterOS\Util($client = new RouterOS\Client('192.168.88.1', 'admin', 'password')); | ||
$util->setMenu('/ip arp'); | ||
$util->add( | ||
array( | ||
'address' => '192.168.88.100', | ||
'mac-address' => '00:00:00:00:00:01' | ||
), | ||
array( | ||
'address' => '192.168.88.101', | ||
'mac-address' => '00:00:00:00:00:02' | ||
) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
use PEAR2\Net\RouterOS; | ||
require_once 'PEAR2/Autoload.php'; | ||
|
||
$util = new RouterOS\Util($client = new RouterOS\Client('192.168.88.1', 'admin', 'password')); | ||
$util->setMenu('/ip arp'); | ||
|
||
//With function | ||
echo count($util) . "\n"; | ||
|
||
//With method call | ||
echo $util->count() . "\n"; | ||
|
||
//Count only disabled ARP items | ||
echo $util->count(COUNT_NORMAL, RouterOS\Query::where('disabled', 'true')) . "\n"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
use PEAR2\Net\RouterOS; | ||
require_once 'PEAR2/Autoload.php'; | ||
|
||
$util = new RouterOS\Util($client = new RouterOS\Client('192.168.88.1', 'admin', 'password')); | ||
$util->setMenu('/ip arp'); | ||
$util->remove(0); | ||
$util->disable(Query::where('comment', 'DISABLE ME')); | ||
$util->enable(1); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
use PEAR2\Net\RouterOS; | ||
require_once 'PEAR2/Autoload.php'; | ||
|
||
$util = new RouterOS\Util($client = new RouterOS\Client('192.168.88.1', 'admin', 'password')); | ||
$util->setMenu('/ip arp'); | ||
|
||
$util->exec(' | ||
add address=192.168.88.100 mac-address=00:00:00:00:00:01 comment=customer_1 | ||
add address=192.168.88.101 mac-address=00:00:00:00:00:02 comment=customer_2 | ||
/tool | ||
fetch url="http://example.com/?name=customer_1" | ||
fetch url="http://example.com/?name=customer_2" | ||
'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
use PEAR2\Net\RouterOS; | ||
require_once 'PEAR2/Autoload.php'; | ||
|
||
$util = new RouterOS\Util($client = new RouterOS\Client('192.168.88.1', 'admin', 'password')); | ||
$util->setMenu('/ip arp'); | ||
|
||
$source = ' | ||
add address="192.168.88.$ip" mac-address="00:00:00:00:00:$mac" comment=$name | ||
/tool | ||
fetch url="http://example.com/?name=$name" | ||
'; | ||
$util->exec( | ||
$source, | ||
array( | ||
'ip' => 100, | ||
'mac' => '01', | ||
'name' => 'customer_1' | ||
) | ||
); | ||
$util->exec( | ||
$source, | ||
array( | ||
'ip' => 101, | ||
'mac' => '02', | ||
'name' => 'customer_2' | ||
) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
use PEAR2\Net\RouterOS; | ||
require_once 'PEAR2/Autoload.php'; | ||
|
||
$util = new RouterOS\Util($client = new RouterOS\Client('192.168.88.1', 'admin', 'password')); | ||
$util->setMenu('/tool'); | ||
|
||
$url = $_GET['url'];//assume $_GET['url'] equals something akin to "http://example.com/geoip.rsc?filter=all"... | ||
|
||
$source = ' | ||
fetch url=$db keep-result=yes dst-path=$filename | ||
# Give the script time to be written onto disk | ||
:delay 2 | ||
/import file=$filename | ||
'; | ||
$util->exec( | ||
$source, | ||
array( | ||
'db' => $url, | ||
'filename' => pathinfo(parse_url($url, PHP_URL_PATH), PATHINFO_FILENAME) //... then this would be equal to "geoip.rsc" | ||
), | ||
'read,write' | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
use PEAR2\Net\RouterOS; | ||
require_once 'PEAR2/Autoload.php'; | ||
|
||
$util = new RouterOS\Util($client = new RouterOS\Client('192.168.88.1', 'admin', 'password')); | ||
|
||
$filename = 'backup.rsc'; | ||
file_put_contents($filename, $util->fileGetContents($filename)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
use PEAR2\Net\RouterOS; | ||
require_once 'PEAR2/Autoload.php'; | ||
|
||
$util = new RouterOS\Util($client = new RouterOS\Client('192.168.88.1', 'admin', 'password')); | ||
|
||
$filename = 'backup.auto.rsc'; | ||
$util->filePutContents($filename, file_get_contents($filename)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
use PEAR2\Net\RouterOS; | ||
require_once 'PEAR2/Autoload.php'; | ||
|
||
$util = new RouterOS\Util($client = new RouterOS\Client('192.168.88.1', 'admin', 'password')); | ||
$util->changeMenu('/ip arp'); | ||
echo $util->find(function ($response) { | ||
return preg_match('/^\d\d/', $response->getArgument('comment'));//Matches any entry who's comment starts with two digits | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
use PEAR2\Net\RouterOS; | ||
require_once 'PEAR2/Autoload.php'; | ||
|
||
$util = new RouterOS\Util($client = new RouterOS\Client('192.168.88.1', 'admin', 'password')); | ||
$util->setMenu('/ip arp'); | ||
echo $util->find(0, 1);//Outputs something similar to "*4de,*16a", since we targeted two entries - the one in position 0 and position 1. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
use PEAR2\Net\RouterOS; | ||
require_once 'PEAR2/Autoload.php'; | ||
|
||
$util = new RouterOS\Util($client = new RouterOS\Client('192.168.88.1', 'admin', 'password')); | ||
$util->setMenu('/system identity'); | ||
echo $util->get(null, 'name');//echoes "MikroTik", assuming you've never altered your router's identity. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
use PEAR2\Net\RouterOS; | ||
require_once 'PEAR2/Autoload.php'; | ||
|
||
$util = new RouterOS\Util($client = new RouterOS\Client('192.168.88.1', 'admin', 'password')); | ||
$util->setMenu('/ip arp'); | ||
echo $util->get(0, 'address');//echoes "192.168.88.1", assuming we had the previous example executed under an empty ARP list |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
use PEAR2\Net\RouterOS; | ||
require_once 'PEAR2/Autoload.php'; | ||
|
||
$util = new RouterOS\Util($client = new RouterOS\Client('192.168.88.1', 'admin', 'password')); | ||
$util->setMenu('/ip arp'); | ||
|
||
foreach($util->getAll() as $item) { | ||
echo 'IP: ', $item->getProperty('address'), | ||
' MAC: ', $item->getProperty('mac-address'), | ||
"\n"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
use PEAR2\Net\RouterOS; | ||
require_once 'PEAR2/Autoload.php'; | ||
|
||
$util = new RouterOS\Util($client = new RouterOS\Client('192.168.88.1', 'admin', 'password')); | ||
$util->setMenu('/queue simple'); | ||
$util->move(2, 0);//Place the queue at position 2 above the queue at position 0 | ||
$util->move($util->find(3,4), 0);//Place the queues at positions 3 and 4 above the queue at position 0 (the same one that a line ago was at position 2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
use PEAR2\Net\RouterOS; | ||
require_once 'PEAR2/Autoload.php'; | ||
|
||
$util = new RouterOS\Util($client = new RouterOS\Client('192.168.88.1', 'admin', 'password')); | ||
|
||
$util->setMenu('/system resource'); | ||
$uptime = RouterOS\Util::parseValue($util->get(null, 'uptime')); | ||
|
||
$now = new DateTime; | ||
|
||
//Will output something akin to 'The router has been in operation since Sunday, 18 Aug 2013 14:03:01' | ||
echo 'The router has been in operation since ' . $now->sub($uptime)->format(DateTime::COOKIE); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
use PEAR2\Net\RouterOS; | ||
require_once 'PEAR2/Autoload.php'; | ||
|
||
$util = new RouterOS\Util($client = new RouterOS\Client('192.168.88.1', 'admin', 'password')); | ||
$util->setMenu('/ip arp'); | ||
$util->set( | ||
$util->find( | ||
function ($response) { | ||
return preg_match('/^\d\d/', $response->getArgument('comment'));//Matches any entry who's comment starts with two digits | ||
} | ||
), | ||
array( | ||
'address' => '192.168.88.103' | ||
) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
use PEAR2\Net\RouterOS; | ||
require_once 'PEAR2/Autoload.php'; | ||
|
||
$util = new RouterOS\Util($client = new RouterOS\Client('192.168.88.1', 'admin', 'password')); | ||
$util->setMenu('/ip arp'); | ||
$util->set(0, array( | ||
'address' => '192.168.88.103' | ||
)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters