0

I am using a simple php script to add user in Mikrotik Hostspot.

Here is the code :

<?php
$connection = ssh2_connect('192.168.3.201', 22);
ssh2_auth_password($connection, 'root', 'vonlinux');
$stream = ssh2_exec($connection, 'ssh admin@192.168.3.202 /ip hotspot user add disabled=no name='.$MOBILE.' password='.$VAR.' profile=default');
stream_set_blocking($stream, true);
$stream_out = ssh2_fetch_stream($stream, SSH2_STREAM_STDIO);
echo stream_get_contents($stream_out);
?>

Now what i want ? Actually with the above code i am able to create a new user in Mikrotik hotspot Now, if the user is already exit this code should update the password of that user.

Hope its clear, Any help would be Appreciated.

Thanks in Advance...!

schnaader
  • 49,103
  • 10
  • 104
  • 136
user2129513
  • 9
  • 1
  • 2

1 Answers1

2

Using the CLI its as easy as this:

ip hotspot user set User_Name password=New_Password

You should check in your code if the user exist to update the password or if it's a new user create it.

You could use /ip hotspot user print command to check if the user exists or not.

NetVicious
  • 3,848
  • 1
  • 33
  • 47