Enable/Disabled Queue Simple PHP

Hello,
I’m trying to develop a page in PHP to manage my Mikrotik and need some help.

I’m able to list the single file and register a new user in single file.
I wanted to know how do I disable and enable a simple queue of User in PHP.

Thanks, and sorry for the English, I’m using google translator, I am Brazilian.

Similarly to how you would do it using CLI.

How do you do it CLI depends on what kind of users do you have. Hotspot, PPPoE, User Manager, etc.

I’m using this code to add a Client in single file PPPoE, I wanted to know how do I delete / Disable / Enable.

    $API = new routeros_api();
    $API->debug = false;
    if ($API->connect($ServerList, $Username, $Pass, $Port)) {
      
$API-> comm('/queue/simple/add', array (
"name" => $name,
"target-addresses" => $ip,
"max-limit" => $maxlimit,
"limit-at" => $maxlimit,
//"comment" => $comentario
));
$API->comm('/ip/arp/add', array(
"address" => $ip, 
"interface" => $interface,
"mac-address" => $mac,
"comment" => $comentario,

));
echo 'Cadastrado com Sucesso';
}
        
        $API->disconnect();

I’m using this code to add a Client in single file PPPoE, I wanted to know how do I delete / Disable / Enable.

You use the “remove”, “disable” and “enable” commands.

In the case of the queue, you can specify the queue name at the “numbers” argument.

In the case of ARP, you need to first find the ARP item by doing a “print” with a query. The query should contain enough conditions to uniquely identity the ARP item… Like maybe the comment alone, or if that’s not sufficient - the combination of an IP and MAC address. Once you know the ID, you use it at the “numbers” argument.

With my API client, the code is as simple as:

$util = new RouterOS\Util($client = new RouterOS\Client($ServerList, $Username, $Pass, $Port));

//When adding
$util->setMenu('/queue simple')->add(
    array (
        "name" => $name,
        "target-addresses" => $ip,
        "max-limit" => $maxlimit,
        "limit-at" => $maxlimit
    )
);
$util->setMenu('/ip arp')->add(
    array(
        "address" => $ip, 
        "interface" => $interface,
        "mac-address" => $mac,
        "comment" => $comentario
    )
);

//When removing
$util->setMenu('/queue simple')->remove($name);
$util->setMenu('/ip arp')->remove($util->find(RouterOS\Query::where('comment', $comentario)));

//Same deal with "enable" and "disable"; Replace "remove" with "enable" or "disable" for that effect.     

(it’s a similar in principle with your current API client…)

please, you could rewrite with clase “routeros_api.class.php” ??
I do not use “PEAR2_Net_RouterOS (1.0.0b5).”

with this I have a Call of error to a member function SetMenu () on a non-object.

I am developing the system and need only believe in that class that I use would be so remove.

    $API = new routeros_api();
    $API->debug = false;
    if ($API->connect($ServerList, $Username, $Pass, $Port)) {
      
$API-> comm('/queue/simple/add')->remove($name);

Saying.. Fatal error: Call to a member function remove() on a non-object

Not have that removes my php class.

I do not use “PEAR2_Net_RouterOS (1.0.0b5).”

Why not try it?

please, you could rewrite with clase “routeros_api.class.php” ??

Eww. No.

I would prefer to rewrite your entire app to PEAR2_Net_RouterOS. Seriously. Send me your app (as an archive, or as a link to a Git repository), and I’ll rewrite it for you (for free).

with this I have a Call of error to a member function SetMenu () on a non-object.

I am developing the system and need only believe in that class that I use would be so remove.

I said similar in principle. Not similar in code.

The code is different, but the principle is the same: you call the remove/disable/enable command at the particular menu, with a “numbers” argument that has the ID or name of the item(s) you want to remove/disable/enable. And you find the ID with a separate “print” command with a query.

Hi boy,

May be you must read this: http://www.tech-nico.com/blog/api-mikrotik-crear-queues-simples-verificando-no-duplicar-regla/

Saludos amigo.

Thanks to all the helpers, I managed to solve the problem.

follows the code below if someone needs!

<?php
switch (isset($_POST["tipo"]) ? $_POST["tipo"] : 0
) {
  case "enable":
include ("conexao.php");
$API = new routeros_api();
$API->debug = false;

if ($API->connect($ServerList, $Username, $Pass, $Port)) { 
//Busca ID por Nome
$API->write('/queue/simple/print
?name='.(isset($_POST["name"]) ? $_POST["name"] : 0)
);
$find = $API->read();
//Remove ID encontrado de Acordo com o Nome.
foreach ($find as $find){
$API->write('/queue/simple/enable', false); // remove, enable, disable
$API->write('=.id='.$find['.id']);
$API->read();
}
$API->disconnect();
}

    break;
  case "disable":
include ("conexao.php");
$API = new routeros_api();
$API->debug = false;

if ($API->connect($ServerList, $Username, $Pass, $Port)) { 
//Busca ID por Nome
$API->write('/queue/simple/print
?name='.(isset($_POST["name"]) ? $_POST["name"] : 0)
);
$find = $API->read();
//Remove ID encontrado de Acordo com o Nome.
foreach ($find as $find){
$API->write('/queue/simple/disable', false); // remove, enable, disable
$API->write('=.id='.$find['.id']);
$API->read();
}
$API->disconnect();
}
    break;
  case "remove":
include ("conexao.php");
$API = new routeros_api();
$API->debug = false;

if ($API->connect($ServerList, $Username, $Pass, $Port)) { 
//Busca ID por Nome
$API->write('/queue/simple/print
?name='.(isset($_POST["name"]) ? $_POST["name"] : 0)
);
$find = $API->read();
//Remove ID encontrado de Acordo com o Nome.
foreach ($find as $find){
$API->write('/queue/simple/remove', false); // remove, enable, disable
$API->write('=.id='.$find['.id']);
$API->read();
}
$API->disconnect();
}
  break;
  default:
    echo "Nada Selecionado";
  break;

}

?>