Datasheet
RouterOS PHP class
173
$parser->parseFile(array("config line 1", "config line 2", "config line 3"));
•• function call($cmd, $args)
Execute defined function with specified args as array in current parser context. Returns function return value.
$parser->call("test_function", array("192.168.10.1", "1.2.3.4"));
•• function updateSection($conn, $alias)
Perform specified section $alias update for specified RouterOS $conn connection. All update logs are in
$parser->logs.
$parser->updateSection($conn, "firewall-filter");
•• function update($conn, $ret = FALSE)
Perform update of all sections for specified RouterOS $conn connection. All logs are either flushed on stdout or
returned if $ret is TRUE.
$parser->update($conn);
<?
require_once("routeros.class.php");
require_once("routerosparser.class.php");
header("Content-Type: text/plain");
// connect to device
$conn = RouterOS::connect("192.168.10.11", "admin", "adminpassword") or die("couldn't connect to 192.168.10.11");
$resource = $conn->getall(array("system", "resource")) or die("couldn't get resource;
// create class and define device information
$parser = new RouterOSParser();
$parser->variable("name", "MikroTik");
$parser->variable("version", $resource["version"]);
$parser->variable("arch", $resource["architecture-name"]);
// define function
function allowConnectivity($parser, $srcaddress, $dstaddress) {
if(!$srcaddress || !$dstaddress)
$parser->error("src or dst not specified");
$parser->config("firewall-filter", "chain=forward src-address=$srcaddress dst-address=$dstaddress action=accept");
$parser->config("firewall-filter", "chain=forward src-address=$dstaddress dst-address=$srcaddress action=accept");
}
$parser->cmd('allow-forward', allowConnectivity);
$parser->section("firewall-filter", "/ip/firewall/filter", "addset_order"); // add firewall-filter
$parser->pass("firewall-filter", "chain=forward"); // update ONLY forward chain
$parser->parseFile("example_config.cfg"); // load configuration










