require('routeros_api.class.php');
function recorro($matriz)
{
foreach($matriz as $key=>$value)
{
if (is_array($value))
{
//echo $value["name"].'<br>';
//si es un array busco dentro
if ($value["name"] == $mac)
{
//si coincide con el valor deseado, lo devuelvo para usarlo
return $value['.id'];
break;
}
recorro($value);
}else{
//si es un elemento continuo
continue;
}
}
}
if ($API->connect('IP', 'USER', 'PASSWORD'))
{
echo '<br><br>';
echo 'Conecatado Ok';
echo '<br><br>';
$API->write('/ip/hotspot/user/print',true);
$READ = $API->read(true);
$id = recorro($READ);
$API->write('/ip/hotspot/user/disable',false);
$API->write('=.id=' . $id);
echo 'Buscado: '.$id;
echo '<br><br>';
//print_r($READ);
echo '<br><br>';
$API->write('/ip/hotspot/active/print',true);
$READ2 = $API->read(true);
foreach ($READ2 as $value2) {
//echo $value2['mac-address'].'<br>';
if ($value2['mac-address'] == $mac)
{
$API->write('/ip/hotspot/active/remove',false);
$API->write('=.id=' . $value2['.id']);
$KILL = $API->read();
echo 'Encontrado ';
echo $value2['.id'];
}
}
//print_r($READ2);
$API->disconnect();
}
The problem:
if i send the $mac value from other web, or form, ($_GET) the api seems dont get this value,
if i use $value[“name”] == “MAC ADDRESS”, the api works fine.
any idea why the api dont read the value of the var?
Are you sure that your usernames are the mac addresses? Perhaps you need to instead target the mac-address property in the user section too. It would be normal for the remove to fail if there’s no ID from the print being matched, which would happen if that’s the case.
BTW, I’m not even sure the removal in the “host” is necesary. It should be deleted automatically as a consequence of the user deletion.
Going slowly by starting with the more cumbersome and unintuitive API, towards the cleaner and easier one… fair enough… I think.
Hi again, my script was working fine till now (some years working perfect), something more that i saw change with any of last routerOS updates, and now i have a problem with the remove part from hotpost, the enable/disable part works fine, looks like the problem is in the read return from the router, apears to come back empty.