Пример #1
0
 /**
  * Runs the test in a separate process for the sake of
  * peristent connections.
  * 
  * @runInSeparateProcess
  * 
  * @return void
  */
 public function testSystemReboot()
 {
     $this->object->sendSync(new Request('/system/reboot'));
     $this->object->close();
     $this->object = null;
     sleep(1);
     while (true) {
         try {
             $this->object = new Client(\HOSTNAME, USERNAME, PASSWORD, PORT);
             $this->assertTrue(true);
             return;
         } catch (SocketException $e) {
             //Connection is expected to fail several times before success.
         }
     }
 }
Пример #2
0
$query = RouterOS\Query::where("list", $list)->andWhere("comment", $dnshost);
$req->setQuery($query);
$resp = $c->sendSync($req);
$todelete = array();
$toadd = $dnsip;
foreach ($resp as $r) {
    if ($r->getType() === RouterOS\Response::TYPE_DATA) {
        $pos = array_search($r->getProperty("address"), $toadd);
        if ($pos === FALSE) {
            $todelete[] = $r->getProperty(".id");
        } else {
            unset($toadd[$pos]);
        }
    }
}
foreach ($toadd as $ip) {
    echo "Adding {$ip}...\n";
    $req = new RouterOS\Request("/ip/firewall/address-list/add");
    $req->setArgument("address", $ip);
    $req->setArgument("comment", $dnshost);
    $req->setArgument("list", $list);
    $c->sendSync($req);
}
foreach ($todelete as $id) {
    echo "Removing {$id}...\n";
    $req = new RouterOS\Request("/ip/firewall/address-list/remove");
    $req->setArgument("numbers", $id);
    $c->sendSync($req);
}
$c->close();