From b0fc409ead43b11fb3c5322a38695eb728d81a5c Mon Sep 17 00:00:00 2001 From: Paul Rock Date: Tue, 24 Sep 2019 21:11:06 +0300 Subject: [PATCH] yet another example added, about hotspot ip-binding logic, by #16 --- examples/hotspot.php | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 examples/hotspot.php diff --git a/examples/hotspot.php b/examples/hotspot.php new file mode 100644 index 0000000..f90f0fc --- /dev/null +++ b/examples/hotspot.php @@ -0,0 +1,57 @@ +set('host', '127.0.0.1') + ->set('port', 8728) + ->set('pass', 'admin') + ->set('user', 'admin'); + +// Initiate client with config object +$client = new Client($config); + +/* + * For the first we need to create new one user + */ + +// Build query +$query = + (new Query('/ip/hotspot/ip-binding/add')) + ->equal('mac-address', '00:00:00:00:40:29') + ->equal('type', 'bypassed') + ->equal('comment', 'testcomment'); + +// Add user +$out = $client->query($query)->read(); +print_r($out); + +/* + * Now try to remove created user from RouterOS + */ + +// Remove user +$query = + (new Query('/ip/hotspot/ip-binding/print')) + ->where('mac-address', '00:00:00:00:40:29'); + +// Get user from RouterOS by query +$user = $client->query($query)->read(); + +if (!empty($user[0]['.id'])) { + $userId = $user[0]['.id']; + + // Remove MACa address + $query = + (new Query('/ip/hotspot/ip-binding/remove')) + ->equal('.id', $userId); + + // Remove user from RouterOS + $removeUser = $client->query($query)->read(); + print_r($removeUser); +}