Hello, I have a RB493AH, and I’m trying to add a ppp user using the Mikrotik API with php..
My code is…
require_once ("api/api.php"); //aqui incluimos la clase API para trabajar con ella
$ipRB="xx.xx.xx.xx"; //IP de tu RB.
$Username="user"; //Nombre de usuario con privilegios para acceder al RB
$clave="password"; //Clave del usuario con privilegios
$api_puerto=8728; //Puerto que definimos el API en IP
$API = new routeros_api(); //Creamos un objeto de la clase API
$API->debug = false; //Desactivamos el debug
$API->connect($ipRB , $Username , $clave, $api_puerto);
$nombre = $_POST['nombre'];
$password = $_POST['password'];
$service="pppoe";
$profile="PPPoE";
$API->comm("/ppp/secret/add", array(
"name" => '.$nombre',
"password" => '.$password',
"profile" => '.$profile',
"service" => '.$service',
));
?>
What I’m doing wrong?
I’m missing something?
Regards..
Carina
When you surround a value with single quotes in PHP, you’re getting a literal value, without any variable interpolation. You need to use double quotes if you want variable interpolation, or no quotes at all if you want the variable itself, i.e. replace
"name" => '.$nombre',
"password" => '.$password',
"profile" => '.$profile',
"service" => '.$service',
with
"name" => $nombre,
"password" => $password,
"profile" => $profile,
"service" => $service,
It’s working finally..
Thanks boen_robot!!
And how did you disable an user?
I’m guessing you’d use the “disable” command, and supply the username in the “numbers” argument. This should work if that menu requires the username to be unique.
If not, you must make a “print” request, get the “.id”, and put that in the “numbers” argument.
boen_robot, thanks for your answer, I did that and It worked.
I have just the last question, when I get all my /ppp/secret/getall users is posible to get the state? enable or disable?and if the user is connected?
There should be a “disabled” property for every user retrieved. If “true”, the user is disabled.
I don’t know about checking whether they’re currently connected, as I don’t use PPP… How would you check that from CLI? If you know that, it should be analogous in the API too.
That’s ok!
I was trying disable instead disabled.
Thanks a lot.
Best regards