Community discussions

MUM Europe 2020
 
mudasir
Member Candidate
Member Candidate
Topic Author
Posts: 278
Joined: Tue Apr 29, 2008 3:38 am
Location: Karachi, Pakistan
Contact:

Change hotspot password with PHP API

Thu Jan 21, 2010 9:19 pm

Hi,

I am working on a simple PHP script to change password of a hotspot user.
A simple example would be great.

Right now i am doing this with a BASH script from a Linux Server. I get a STD Timeout error almost all the time while changing password, i dont understand why i get this.
Also if someone can brief me about this STD Timeout error.

Looking forward for a positive reply.
Regards
Mudasir Mirza
http://www.diglinux.com
 
User avatar
normis
MikroTik Support
MikroTik Support
Posts: 24422
Joined: Fri May 28, 2004 11:04 am
Location: Riga, Latvia

Re: Change hotspot password with PHP API

Fri Jan 22, 2010 10:28 am

it would be easier to help if you posted some code example of what you are doing
No answer to your question? How to write posts
 
mudasir
Member Candidate
Member Candidate
Topic Author
Posts: 278
Joined: Tue Apr 29, 2008 3:38 am
Location: Karachi, Pakistan
Contact:

Re: Change hotspot password with PHP API

Sat Jan 23, 2010 3:05 am

HI,

uptill now i have only made login system, and a simple html form with required fields.
form has following fields
1. userid
2. old password
3. new password
4. confirm password.

i have made a function to check new password and confirm password. after that the password should go through the php.api syntax to mikrotik to change the password for the userid.

a simple example would be much more helpfull. I only want to know the correct sytax to be used with php.api to change password for hotspot user.
Regards
Mudasir Mirza
http://www.diglinux.com
 
User avatar
Chupaka
Forum Guru
Forum Guru
Posts: 8345
Joined: Mon Jun 19, 2006 11:15 pm
Location: Minsk, Belarus
Contact:

Re: Change hotspot password with PHP API

Sat Jan 23, 2010 2:21 pm

again, please post CLI command to do that =) and it will be easy to translate it into API command
Russian-speaking forum: https://forum.mikrotik.by/. Welcome!

For every complex problem, there is a solution that is simple, neat, and wrong.

MikroTik. Your life. Your routing.
 
mudasir
Member Candidate
Member Candidate
Topic Author
Posts: 278
Joined: Tue Apr 29, 2008 3:38 am
Location: Karachi, Pakistan
Contact:

Re: Change hotspot password with PHP API

Sat Jan 23, 2010 10:12 pm

Hi,

Thanks for th reply.

the CLI command is simple.
"ip hotspot user set User_Name password=New_Password"

i want this to do through the PHP API, a working example would be great.

Thanks in advance.
Regards
Mudasir Mirza
http://www.diglinux.com
 
User avatar
Chupaka
Forum Guru
Forum Guru
Posts: 8345
Joined: Mon Jun 19, 2006 11:15 pm
Location: Minsk, Belarus
Contact:

Re: Change hotspot password with PHP API

Mon Jan 25, 2010 2:00 pm

as far as I understand, in canonical form it's
/ip hotspot user set [find name="User_Name"] password=New_Password
so, look at http://forum.mikrotik.com/viewtopic.php?f=9&t=32825
Russian-speaking forum: https://forum.mikrotik.by/. Welcome!

For every complex problem, there is a solution that is simple, neat, and wrong.

MikroTik. Your life. Your routing.
 
User avatar
desertadmin
Member Candidate
Member Candidate
Posts: 232
Joined: Tue Jul 26, 2005 6:09 pm
Location: Las Vegas, New Mexico
Contact:

Re: Change hotspot password with PHP API

Fri Feb 26, 2010 11:15 pm

Can you post your PHP that you have so far on this? Do you think it would be easier to do in PERL?

-Sincerely,
DesertAdmin
 
User avatar
desertadmin
Member Candidate
Member Candidate
Posts: 232
Joined: Tue Jul 26, 2005 6:09 pm
Location: Las Vegas, New Mexico
Contact:

Re: Change hotspot password with PHP API

Mon Mar 01, 2010 11:25 am

My code is like this and is not changing the password please help. I am able to connect and to pull up the array of information but I can n ot do a set /change for a password. any ideas?

I am trying to locate the username ilfeld and then change it to the following test password of yoyo. The username appears to be listed as id *5. What am I doing wrong? This is with the PHP API.
        $API->write('/ip/hotspot/user/getall');
	$API->write('=.proplist=name');
	$API->write('?name=ilfeld');
	$API->write('/ip/hotspot/user/set');
	$API->write('=.id=*5');	
	$API->write('=password=yoyo');

	$READ = $API->read(false);
	$ARRAY = $API->parse_response($READ);
	print_r($ARRAY);
Thanks in advance

-Sincerely,
DesertAdmin
 
dog
Member Candidate
Member Candidate
Posts: 186
Joined: Wed Aug 12, 2009 3:37 pm
Location: Germany

Re: Change hotspot password with PHP API

Mon Mar 01, 2010 5:20 pm

You forgot to end the sentence.
Call $API->finish_sentence(); before trying to read anything.

...forget that comment, I have a modified version of the API :)

With the "official" API you would have to write:
   $API->write('/ip/hotspot/user/getall',false);
   $API->write('=.proplist=name',false);
   $API->write('?name=ilfeld');
#you have to read out something at this point
   $API->write('/ip/hotspot/user/set',false);
   $API->write('=.id=*5',false);   
   $API->write('=password=yoyo');
 
User avatar
desertadmin
Member Candidate
Member Candidate
Posts: 232
Joined: Tue Jul 26, 2005 6:09 pm
Location: Las Vegas, New Mexico
Contact:

Re: Change hotspot password with PHP API

Mon Mar 01, 2010 9:25 pm

Awesome that worked!!

Here is what my hotspot password page looks like. I have two files that I made but I also use the routeros_api.class.php (of course) on my secure https server.
Files:
hotspot.php
hspot1.php
routeros_api.class.php


Here is the code for my basic login page for the hotel managers to use: https://server.address.com/hman/hotspot.php
<html>
<body>
<table width="300" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<form name="form1" method="post" action="hspot1.php">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td colspan="3"><strong>HotSpot Admin Login </strong></td>
</tr>
<tr>
<td width="78">Username</td>
<td width="6">:</td>
<td width="294"><input name="myusername" type="text" id="myusername"></td>
</tr>
<tr>
<td>Password</td>
<td>:</td>
<td><input name="mypassword" type="password" id="mypassword"></td>
</tr>

<tr>
<td width="78">Hotel Username</td>
<td width="6">:</td>
<td width="294"><strong>ilfeld</strong></td>
</tr>
<tr>
<td>New Password</td>
<td>:</td>
<td><input name="guestpassword" type="password" id="guestpassword"></td>
</tr>

<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td><input type="submit" name="Submit" value="Login"></td>
</tr>
</table>
</td>
</form>
</tr>
</table>
 <script language="JavaScript">
<!--
document.hotspot.myusername.focus();
//-->

</script>
</body>
</html>

My code calls hspot1.php Please change the IP address of the server and use a username and password that is only able to change hotspot usernames and passwords. For instance I made a login user that can only write as the username of manager with a simple to remember password. This will only allow that username to change the passwords. Do not forget to enable the API service port and set it to your address range accordingly. Or you can create a rule set that would allow only your IP address ranges. Once you have that setup find the username that you want always to change and get its ID if the hotspot user is the number 4 on the list that call your .id=*5 because it is counting the number 0.
<?php

require('routeros_api.class.php');

$API = new routeros_api();

$API->debug = false;
$myusername = $_POST["myusername"];
$mypassword = $_POST["mypassword"];
$guestpassword = $_POST["guestpassword"];
$cmmnd ="=password=";
$cmmnd .=$guestpassword;
$ipofsvr="111.111.111.111";

if ($API->connect($ipofsvr, $myusername, $mypassword)) {

	echo "Password Changed successfully!";

	$API->write('/ip/hotspot/user/getall',false);
	$API->write('=.proplist=name',false);
	$API->write('?name=ilfeld');
	$API->write('/ip/hotspot/user/set',false);
	$API->write('=.id=*5',false);
	$API->write($cmmnd);

	$READ = $API->read(false);
	$ARRAY = $API->parse_response($READ);
	
	$API->disconnect();

}
else 
{
  echo "Incorrect Username or Password! Please try again!";
  $API->disconnect();
} 
?>


If you all have any questions or comments please post it back. Thanks for everyones help.

-Sincerely,
DesertAdmin
 
User avatar
desertadmin
Member Candidate
Member Candidate
Posts: 232
Joined: Tue Jul 26, 2005 6:09 pm
Location: Las Vegas, New Mexico
Contact:

Re: Change hotspot password with PHP API

Tue Mar 02, 2010 3:25 am

Here is my newest modification to the page for our hotel managers to change their basic guest account password for their hotspot. All other customers who need greater then 128k will then purchase bandwidth from us.
hotelmanagerpage.JPG
I have this nicely secured on our https site that is only accessible on our networks.

Let me know what you think!

Thanks

-Sincerely,
DesertAdmin
You do not have the required permissions to view the files attached to this post.
 
crusoe
just joined
Posts: 8
Joined: Sun May 16, 2010 9:59 am
Location: Ghana
Contact:

Re: Change hotspot password with PHP API

Sun May 16, 2010 10:27 am

Hi Everyone,I am trying to build a system similar to what is being discussed on this page,using some info on this page
I want hotspot users to change their passwords after they have logged in.
The login.html and status.html are from the default mikrotik hotspot folder

The sequence:
login.html (usual login page)>>>>>status.html (generated after successful login)>>>>changepass.php (forwaded from a link on status.html)>>>>>hspot1.php

but i am having difficulty after the hspot1.php is called,i only see the code being displayed on the web page and that is it.no password is changed!!!!
i need help


NB
i have no experience in php,html,java..this is my first time..i have come this far courtesy of this forum and google.


here is the status page code

<html>
<head>
<title> hotspot > status</title>
<style type="text/css">
<!--
.style1 {
	color: #660000;
	font-weight: bold;
}
-->
</style>
$(if refresh-timeout)
<meta http-equiv="refresh" content="$(refresh-timeout-secs)">
$(endif)
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="expires" content="-1">
<style type="text/css">
<!--
textarea,input,select {
	background-color: #FDFBFB;
	border: 1px #BBBBBB solid;
	padding: 2px;
	margin: 1px;
	font-size: 14px;
	color: #808080;
}

.tabula{
 
border-width: 1px; 
border-collapse: collapse; 
border-color: #c1c1c1; 
background-color: transparent;
font-family: verdana;
font-size: 11px;
}

body{ color: #737373; font-size: 12px; font-family: verdana; }

a, a:link, a:visited, a:active { color: #AAAAAA; text-decoration: none; font-size: 12px; }
a:hover { border-bottom: 1px dotted #c1c1c1; color: #AAAAAA; }
img {border: none;}
td { font-size: 12px; padding: 4px;}
.style2 {color: #660000}

-->
</style>
<script language="JavaScript">
<!--
$(if advert-pending == 'yes')
    var popup = '';
    function focusAdvert() {
	if (window.focus) popup.focus();
    }
    function openAdvert() {
	popup = open('$(link-advert)', 'hotspot_advert', '');
	setTimeout("focusAdvert()", 1000);
    }
$(endif)
    function openLogout() {
	if (window.name != 'hotspot_status') return true;
        open('$(link-logout)', 'hotspot_logout', 'toolbar=0,location=0,directories=0,status=0,menubars=0,resizable=1,width=280,height=250');
	window.close();
	return false;
    }
//-->
</script>
</head>
<body bottommargin="0" topmargin="0" leftmargin="0" rightmargin="0"
$(if advert-pending == 'yes')
	onLoad="openAdvert()"
$(endif)
>
<table width="100%" height="100%">

<tr>
<td align="center" valign="middle">
<form action="$(link-logout)" name="logout" onSubmit="return openLogout()">
<table border="1" class="tabula">
$(if login-by == 'trial')
	<br><div style="text-align: center;">Welcome trial user!</div><br>
$(elif login-by != 'mac')
	<br><div style="text-align: center;">Welcome $(username)!</div><br>
$(endif)
	<tr><td align="right">IP address:</td><td>$(ip)</td></tr>
	<tr><td align="right">bytes up/down:</td><td>$(bytes-in-nice) / $(bytes-out-nice)</td></tr>
$(if session-time-left)
	<tr><td align="right">connected / left:</td><td>$(uptime) / $(session-time-left)</td></tr>
$(else)

	<tr><td align="right">connected:</td><td>$(uptime)</td></tr>
$(endif)
$(if blocked == 'yes')
	<tr><td align="right">status:</td><td><div style="color: #FF8080">
<a href="$(link-advert)" target="hotspot_advert">advertisement</a> required</div></td>
$(elif refresh-timeout)
	<tr><td align="right">status refresh:</td><td>$(refresh-timeout)</td>
$(endif)
</table>
$(if login-by-mac != 'yes')
<br>
<!-- user manager link
<button onclick="document.location='http://$(hostname)/user?subs='">status</button>
<!-- end of user manager link -->
<input type="submit" value="log off">
<label>
/</label>
<p>$(endif)</p>
<p class="style1"><a href="changepass.php">CHANGE PASSWORD</a></p>
</form>


</td>
</table>
</body>
</html>


code for changepass.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<table width="300" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<form name="form1" method="post" action="hspot1.php">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td colspan="3"><strong>HotSpot User Password change</strong></td>
</tr>
<tr>
<td width="78">Username</td>
<td width="6">:</td>
<td width="294"><input name="myusername" type="text" id="myusername"></td>
</tr>
<tr>
<td>Old Password</td>
<td>:</td>
<td><input name="mypassword" type="password" id="mypassword"></td>
</tr>

<tr>
<td width="78">&nbsp;</td>
<td width="6">&nbsp;</td>
<td width="294">


</td>
</tr>
<tr>
<td>New Password</td>
<td>:</td>
<td><input name="newpassword" type="password" id="newpassword"></td>
</tr>

<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td><input type="submit" name="Submit" value="submit"></td>
</tr>
</table>
</td>
</form>
</tr>
</table>
<script language="JavaScript">
<!--
document.hotspot.myusername.focus();
//-->

</script>
</body>
</html>




then code for hotspot1.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>


<?php

require('routeros_api.class.php');

$API = new routeros_api();

$API->debug = false;
$myusername = $_POST["myusername"];
$mypassword = $_POST["mypassword"];
$newpassword= $_POST["newpassword"]
$cmmnd ="=password=";
$cmmnd .=$newpassword;
$ipofsvr="172.16.1.1";

if ($API->connect($ipofsvr, $myusername, $mypassword)) {

   echo "Password Changed successfully!";

   $API->write('/ip/hotspot/user/getall',false);
   $API->write('=.proplist=name',false);
   $API->write('?name=$myusername');
   $API->write('/ip/hotspot/user/set',false);
   $API->write('=name=$myusername',false);
   $API->write($cmmnd);

   $READ = $API->read(false);
   $ARRAY = $API->parse_response($READ);
   
   $API->disconnect();

}
else
{
  echo "Incorrect Username or Password! Please try again!";
  $API->disconnect();
}
?>


<body>
</body>
</html>
 
User avatar
janisk
MikroTik Support
MikroTik Support
Posts: 6283
Joined: Tue Feb 14, 2006 9:46 am
Location: Riga, Latvia

Re: Change hotspot password with PHP API

Mon May 17, 2010 11:00 am

are you trying to put these pages on Router? If yes, then it will not work. You will have to place these pages on php capable http server, that RouterOS is not.
 
crusoe
just joined
Posts: 8
Joined: Sun May 16, 2010 9:59 am
Location: Ghana
Contact:

Re: Change hotspot password with PHP API

Mon May 17, 2010 2:18 pm

ok.thanks for that info,i have realised my mistake.

Now what i have done is to maintain the login.html and status.html on the router ,then i have created a link on status .html to change password which links to changepass.html which then redirects the user to changepass.php and hspot1.php on an external server running wampserver 2i
The router's ip address is 172.16.1.1,user admin and no password


i have logged in to the system with a user named "admin" password "admin",and i want to change password to test,when i run the code

hspot.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>


<?php

require('routeros_api.class.php');

$API = new routeros_api();

$API->debug = true;
$myusername = $_POST["myusername"];
$mypassword = $_POST["mypassword"];
$newpassword= $_POST["newpassword"];
$ipofsvr="172.16.1.1";

if ($API->connect($ipofsvr,'admin',"")) {


   $API->write('/ip/hotspot/user/getall',false);
   $API->write('/ip/hotspot/user/set/',false);
   $API->write('=.id='.$myusername,false);
   $API->write('=password='.$newpassword);

   $READ = $API->read(false);
   $ARRAY = $API->parse_response($READ);
   
   $API->disconnect();
   
   echo "Password Changed successfully!";

}
else
{
  echo "Incorrect Username or Password! Please try again!";
  $API->disconnect();
}
?>


<body>
</body>
</html>
i get this output with debugging on
Connection attempt #1 to 172.16.1.1:8728... <<< [6] /login >>> [5, 39] !done >>> [37, 1] =ret=42aa9f5618bbc947415e1a680ee3b2b7 <<< [6] /login <<< [11] =name=admin <<< [44] =response=00b9325a654b8954ac191945f299c4c093 >>> [5, 1] !done Connected... <<< [23] /ip/hotspot/user/getall <<< [21] /ip/hotspot/user/set/ <<< [10] =.id=admin <<< [14] =password=test >>> [3, 189] !re >>> [7, 181] =.id=*1 >>> [11, 169] =name=admin >>> [15, 153] =password=admin >>> [16, 136] =profile=default >>> [16, 119] =uptime=1h30m12s >>> [18, 100] =bytes-in=21293900 >>> [19, 80] =bytes-out=22015929 >>> [17, 62] =packets-in=26375 >>> [18, 43] =packets-out=21254 >>> [11, 31] =dynamic=no >>> [9, 21] =comment= >>> [12, 8] =disabled=no >>> [5, 1] !done Disconnected... Password Changed successfully! 

but the password is not changed whatsoever.
i have api enabled to allow address range of 172.16.1.0/24



code for changepass.php


<?php
$username = $_POST['user'];
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<table width="300" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<form name="form1" method="post" action="hspot1.php">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td colspan="3"><strong>HotSpot User Password change</strong></td>
</tr>
<tr>


<td width="78">Username</td>
<td width="6">:</td>
<td width="294"><?php echo $username; ?><input name="myusername" type="hidden" id="myusername" value="<?php echo $username; ?>"></td>
</tr>
<tr>
<td>Old Password</td>
<td>:</td>
<td><input name="mypassword" type="password" id="mypassword" ></td>
</tr>

<tr>
<td width="78">&nbsp;</td>
<td width="6">&nbsp;</td>
<td width="294">


</td>
</tr>
<tr>
<td>New Password</td>
<td>:</td>
<td><input name="newpassword" type="password" id="newpassword"></td>
</tr>

<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td><input type="submit" name="Submit" value="submit"></td>
</tr>
</table>
</td>
</form>
</tr>
</table>
<script language="JavaScript">
<!--
document.hotspot.myusername.focus();
//-->

</script>
</body>
</html>






now i'm stuck,dont know wat to do
 
User avatar
desertadmin
Member Candidate
Member Candidate
Posts: 232
Joined: Tue Jul 26, 2005 6:09 pm
Location: Las Vegas, New Mexico
Contact:

Re: Change hotspot password with PHP API

Mon May 17, 2010 7:55 pm

Well the API is meant to change a username at place ".id=*1" I do believe. So you may need to modify the .id value to the corresponding username. You may need to do a find to get the correct id position and +1 ( I may be incorrect.)

I think that is the whole problem. Of course this does appear that you are using a routerboard with the hotspot code on it.

-Sincerely,
DesertAdmin
 
crusoe
just joined
Posts: 8
Joined: Sun May 16, 2010 9:59 am
Location: Ghana
Contact:

Re: Change hotspot password with PHP API

Tue May 18, 2010 12:36 am

ok.
so i want ahead and changed the line
$API->write('=.id='.$myusername,false);

to
$API->write('=.id=*1,false);

b'cos from the output i clearly see .id has a value of *1
it still behaved as if the password has been changed,but logging into the router shows otherwise.
i'm currently running v3.13 routeros
but i was suspecting maybe there is a bug so i upgraded to 3.22 and when i run the same code i get
Connection attempt #1 to 172.16.1.1:8728... <<< [6] /login >>> [5, 39] !done >>> [37, 1] =ret=3c459371715010e0476c6d91d2995876 <<< [6] /login <<< [11] =name=admin <<< [44] =response=00393c8c29e1e089dbbf83a720fc58bcc8 >>> [5, 1] !done Connected... <<< [23] /ip/hotspot/user/getall <<< [21] /ip/hotspot/user/set/ <<< [10] =.id=admin <<< [14] =password=test >>> [5, 35] !trap >>> [26, 8] =message=unknown parameter >>> [5, 1] !done Disconnected... Password Changed successfully! 
what unknown parameter is it talking about?how can i identify it
i'm so confused now,but i never give up

back to your suggestion about the find,i came up with this code
<?php

require('routeros_api.class.php');

$API = new routeros_api();

$API->debug = true;
$myusername = $_POST["myusername"];
$mypassword = $_POST["mypassword"];
$newpassword= $_POST["newpassword"];
$ipofsvr="172.16.1.1";

if ($API->connect($ipofsvr,'admin',"")) {


   $API->write('/ip/hotspot/user/getall');
   $API->write('=.proplist=.id',false);
   $API->write('?name='.$myusername);
   
   $A = $API->read();
   $A = $A[0];
   
   echo "list  .id value" .$A;
   
   
   $READ = $API->read(false);
   $ARRAY = $API->parse_response($READ);
   
   $API->write('/ip/hotspot/user/set/',false);
   $API->write('=.id='.$A['.id'],false);
   $API->write('=password='.$newpassword);
   $API->read();

   
   
   $API->disconnect();
   
   echo "Password Changed successfully!";

}
else
{
  echo "Incorrect Username or Password! Please try again!";
  $API->disconnect();
}
?>
when i run i get this output
Connection attempt #1 to 172.16.1.1:8728... <<< [6] /login >>> [5, 39] !done >>> [37, 1] =ret=c8e0d23ebe4ba26d3143df7ad2ba87a4 <<< [6] /login <<< [11] =name=admin <<< [44] =response=00e6d723bf535a6070e54f046d0acd1f26 >>> [5, 1] !done Connected... <<< [23] /ip/hotspot/user/getall <<< [14] =.proplist=.id <<< [11] ?name=admin >>> [5, 223] !trap >>> [31, 191] =message=no such command prefix >>> [5, 184] !done >>> [3, 179] !re >>> [7, 171] =.id=*1 >>> [9, 161] =comment= >>> [11, 149] =name=admin >>> [15, 133] =password=admin >>> [16, 116] =profile=default >>> [16, 99] =uptime=06:34:31 >>> [18, 80] =bytes-in=67384966 >>> [19, 60] =bytes-out=22911619 >>> [17, 42] =packets-in=63280 >>> [18, 23] =packets-out=29152 >>> [14, 8] =dynamic=false >>> [5, 1] !done list .id valueArray
Notice: Undefined variable: _ in C:\wamp\www\hotspot\routeros_api.class.php on line 217

Notice: Undefined variable: _ in C:\wamp\www\hotspot\routeros_api.class.php on line 217

Notice: Undefined variable: _ in C:\wamp\www\hotspot\routeros_api.class.php on line 217

Notice: Undefined variable: _ in C:\wamp\www\hotspot\routeros_api.class.php on line 217

people i need help with these codes,like i said this is my 1st time with php and api

this is line 217 of the routeros_api.class.php,i
if ((!$this->connected && !$STATUS['unread_bytes']) || ($this->connected && $_ == '!done' && !$STATUS['unread_bytes']))
does any1 have an updated version of routeros_api.class.php cos anyway i twist my code now i seem to get a an error on the above line,and elsewhere
 
User avatar
janisk
MikroTik Support
MikroTik Support
Posts: 6283
Joined: Tue Feb 14, 2006 9:46 am
Location: Riga, Latvia

Re: Change hotspot password with PHP API

Tue May 18, 2010 7:39 am

try:

/ip/hotspot/user/set

instead of:

/ip/hotspot/user/set/

remember API sentence contains of command and arguments:

/this/is/the/command
=these=arguments
 
crusoe
just joined
Posts: 8
Joined: Sun May 16, 2010 9:59 am
Location: Ghana
Contact:

Re: Change hotspot password with PHP API

Tue May 18, 2010 11:32 am

output remains the same after using

/ip/hotspot/user/set

does not work
 
User avatar
desertadmin
Member Candidate
Member Candidate
Posts: 232
Joined: Tue Jul 26, 2005 6:09 pm
Location: Las Vegas, New Mexico
Contact:

Re: Change hotspot password with PHP API

Tue May 18, 2010 6:30 pm

The .id number is the user in its sequential order listed in the hotspot username area. For instance I have the following under my:

[username@Plazahotelilfeld] /ip hotspot user> pri
Flags: X - disabled, D - dynamic
# SERVER NAME ADDRESS PROFILE UPTIME
0 ilfeld guest 1w2d2h20m40s
1 admin default 22m15s
2 staff iphone 3m28s

Which would make the place +1 equal '=.id=*1' for the username of ilfeld and '=.id=*2' for the username of admin and so fourth.

Do you have the routeros_api.class.php in the same folder on the off site server?
If not you need to get it from the http://wiki.mikrotik.com/wiki/API_PHP_class

Let me know if that helped.

-Sincerely,
DesertAdmin
 
User avatar
janisk
MikroTik Support
MikroTik Support
Posts: 6283
Joined: Tue Feb 14, 2006 9:46 am
Location: Riga, Latvia

Re: Change hotspot password with PHP API

Wed May 19, 2010 7:34 am

do not assume things.here is simple example:
[admin@test-B] /ip hotspot user> add name=one 
[admin@test-B] /ip hotspot user> add name=two 
[admin@test-B] /ip hotspot user> add name=three
[admin@test-B] /ip hotspot user> print 
Flags: X - disabled, D - dynamic 
 #   SERVER                   NAME              ADDRESS              PROFILE                     UPTIME      
 0                            one                                     default                        0s          
 1                            two                                     default                        0s          
 2                            three                                   default                        0s          
[admin@test-B] /ip hotspot user> :put [find]
*1;*2;*3
[admin@test-B] /ip hotspot user> add name=four 
[admin@test-B] /ip hotspot user> remove [find where name="two"]
[admin@test-B] /ip hotspot user> add name=two                  
[admin@test-B] /ip hotspot user> :put [find]                   
*1;*3;*4;*5
look at those .ID fields and values. .ID values for item does not change over time.
 
crusoe
just joined
Posts: 8
Joined: Sun May 16, 2010 9:59 am
Location: Ghana
Contact:

Re: Change hotspot password with PHP API

Wed May 19, 2010 9:22 am

ok. ppl will do as suggested,thanks for all the help
will keep u posted
 
crusoe
just joined
Posts: 8
Joined: Sun May 16, 2010 9:59 am
Location: Ghana
Contact:

Re: Change hotspot password with PHP API

Wed May 19, 2010 9:26 am

routeros_api.class.php is in the same folder
 
User avatar
desertadmin
Member Candidate
Member Candidate
Posts: 232
Joined: Tue Jul 26, 2005 6:09 pm
Location: Las Vegas, New Mexico
Contact:

Re: Change hotspot password with PHP API

Thu May 20, 2010 7:10 pm

Good Luck let me know if I can help you any further.

Please also make sure you are running at the better 3.30 ROS, I think 3.22 had some really odd issues. I have a lot of my main backhauls and core routers running on 3.30 with a few APs and remote test sites running on ROS 4.6( I like 4.6 it seems very stable.) I do not recommend using 4.9 that killed one of my 433AH's after I upgraded from 4.6; any ways 3.30 works really well with the PHP API so do make sure you are running on that ROS version. I think some of the language changed as well from 3.22 to 3.30. So that might just be the whole problem. I could be wrong, please chime in "someone" if you know something different.

-Sincerely,
DesertAdmin
 
User avatar
janisk
MikroTik Support
MikroTik Support
Posts: 6283
Joined: Tue Feb 14, 2006 9:46 am
Location: Riga, Latvia

Re: Change hotspot password with PHP API

Fri May 21, 2010 9:02 am

as i remember there where added requirement, that API commands always have to be complete. In older API you could write something like /sy/reso/pri that was problematic because when you add new feature and commands like this could become indeterministic, so now you have to use long form for everything in API - /system/resource/print - so it will always resolve to same command, no matter how menu changes.
 
mudasir
Member Candidate
Member Candidate
Topic Author
Posts: 278
Joined: Tue Apr 29, 2008 3:38 am
Location: Karachi, Pakistan
Contact:

Re: Change hotspot password with PHP API

Fri May 21, 2010 6:32 pm

Dear,

i have done all the scripts in bash and have created a complete user management panel in Webmin. Its working great and have solved all my problems. I will very soon be publishing all my bash scripts to mikrotik wiki.
Regards
Mudasir Mirza
http://www.diglinux.com
 
crusoe
just joined
Posts: 8
Joined: Sun May 16, 2010 9:59 am
Location: Ghana
Contact:

Re: Change hotspot password with PHP API

Fri May 21, 2010 6:47 pm

OK.ppl thanx 4 all ur help,my system is working smoothly now.i will post all my scripts in a bit.
Mikrotik is Great....
Anyway,wat do u get for publishing an article on wiki...i read somewhere u get some kind of license?
 
User avatar
desertadmin
Member Candidate
Member Candidate
Posts: 232
Joined: Tue Jul 26, 2005 6:09 pm
Location: Las Vegas, New Mexico
Contact:

Re: Change hotspot password with PHP API

Fri May 21, 2010 9:44 pm

Fame and that comes with fast cars and fast women. :^)

I think that was in the beginning of the wiki launch. I wish there was more incentive for the wiki posts via license levels. I try to post when I discover some thing new to help other fellow Mikrotik'ers out. There is a lot of great examples on the wiki. It is just a great thing to do to help and show everyone what people are doing around the world to better their businesses and their infrastructure.


-Sincerely,
DesertAdmin
 
crusoe
just joined
Posts: 8
Joined: Sun May 16, 2010 9:59 am
Location: Ghana
Contact:

Re: Change hotspot password with PHP API

Sat May 22, 2010 5:30 pm

i agree with u man,i think its a great thing
 
User avatar
desertadmin
Member Candidate
Member Candidate
Posts: 232
Joined: Tue Jul 26, 2005 6:09 pm
Location: Las Vegas, New Mexico
Contact:

Re: Change hotspot password with PHP API

Sat Jun 19, 2010 11:17 pm

Very odd.. It seems like the API has changed a slight bit from 4.6 to 4.10 does any one know how to make the following work. It will up date on of my RB that is running on 3.30 while the other one is running on 4.10 it doe snot work. I think the syntax has changed once more. Please suggest where the code is broken. Thanks.
<?php

require('routeros_api.class.php');

$API = new routeros_api();

$API->debug = false;
$myusername = $_POST["myusername"];
$mypassword = $_POST["mypassword"];
$guestpassword = $_POST["guestpassword"];
$cmmnd ="=password=";
$cmmnd .=$guestpassword;
$ipofsvr1="111.111.111.156";
$ipofsvr2="111.111.111.158";

if ($API->connect($ipofsvr1, $myusername, $mypassword)) {

	echo "Password Changed Successfully Site1!<br>";

	$API->write('/ip/hotspot/user/getall',false);
	$API->write('=.proplist=name',false);
	$API->write('?name=rvguest');
	$API->write('/ip/hotspot/user/set',false);
	$API->write('=.id=*2',false);
	$API->write($cmmnd);

	$READ = $API->read(false);
	$ARRAY = $API->parse_response($READ);
	
	$API->disconnect();

}
else 
{
  echo "Incorrect Username or Password! Please try again!<br><br>";
  $API->disconnect();
} 


if ($API->connect($ipofsvr2, $myusername, $mypassword)) {

	echo "Password Changed Successfully Site 2!<br>";

	$API->write('/ip/hotspot/user/getall',false);
	$API->write('=.proplist=name',false);
	$API->write('?name=rvguest');
	$API->write('/ip/hotspot/user/set',false);
	$API->write('=.id=*2',false);
	$API->write($cmmnd);

	$READ = $API->read(false);
	$ARRAY = $API->parse_response($READ);
	
	$API->disconnect();

}
else 
{
  echo "Incorrect Username or Password! Please try again!<BR><BR>";
  $API->disconnect();
} 

?>
-Sincerely,
DesertAdmin
 
User avatar
Chupaka
Forum Guru
Forum Guru
Posts: 8345
Joined: Mon Jun 19, 2006 11:15 pm
Location: Minsk, Belarus
Contact:

Re: Change hotspot password with PHP API

Mon Jun 21, 2010 11:28 pm

so, what's problem?.. what do you see when you execute that?
Russian-speaking forum: https://forum.mikrotik.by/. Welcome!

For every complex problem, there is a solution that is simple, neat, and wrong.

MikroTik. Your life. Your routing.
 
Christiano
Frequent Visitor
Frequent Visitor
Posts: 52
Joined: Fri Aug 13, 2010 8:53 pm

Re: Change hotspot password with PHP API

Fri Aug 13, 2010 9:32 pm

Hi,

I´m from Brazil and my english is poor. I need help to translate command CLI to API PHP.

Anybody know?

I intent do this:

require('routeros_api.class.php');

$API = new routeros_api();

$API->debug = true;


$ip = 'xxx.xxx.xxx.xxx';
$usuario = 'admin';
$senha = '';


if ($API->connect($ip, $usuario, $senha))
{
$API->write('/user/set',false);
$API->write('=name=teste3',false);
}



But it doesn´t work:

I look in winBox in 'use list' panel and the name is the same. I try connect with new user e can´t login.

I don´t know what happening. I read API PHP, API mikrotik, looking in google and now i´m so tired.

Thank you for any help.
 
User avatar
Chupaka
Forum Guru
Forum Guru
Posts: 8345
Joined: Mon Jun 19, 2006 11:15 pm
Location: Minsk, Belarus
Contact:

Re: Change hotspot password with PHP API

Mon Aug 16, 2010 4:30 pm

what CLI command? =)
Russian-speaking forum: https://forum.mikrotik.by/. Welcome!

For every complex problem, there is a solution that is simple, neat, and wrong.

MikroTik. Your life. Your routing.
 
Christiano
Frequent Visitor
Frequent Visitor
Posts: 52
Joined: Fri Aug 13, 2010 8:53 pm

Re: Change hotspot password with PHP API

Mon Aug 16, 2010 4:50 pm

In the terminal i use (winBox):

/user set teste4 name=teste3

I want to do the same with api php but don´t work. I create one user with winBox called teste4. And now i try to use api php to set the name or password, for example, disconnect and connect again. But the set command in api php don´t work in the script above.

Thank you for help.

Now i have a post in the first page called 'how to set use with api php' (mikrotik). Is not my intent duplicate the efforts. So the link: http://forum.mikrotik.com/viewtopic.php?f=9&t=44240

Thank anybody for help
 
User avatar
Chupaka
Forum Guru
Forum Guru
Posts: 8345
Joined: Mon Jun 19, 2006 11:15 pm
Location: Minsk, Belarus
Contact:

Re: Change hotspot password with PHP API

Mon Aug 16, 2010 6:51 pm

try this:
if ($API->connect($ip, $usuario, $senha)) 
{
  $API->write('/user/set',false);
  $API->write('=name=teste3',false); 
  $API->write('=.id=teste4'); 
}
Russian-speaking forum: https://forum.mikrotik.by/. Welcome!

For every complex problem, there is a solution that is simple, neat, and wrong.

MikroTik. Your life. Your routing.
 
Christiano
Frequent Visitor
Frequent Visitor
Posts: 52
Joined: Fri Aug 13, 2010 8:53 pm

Re: Change hotspot password with PHP API

Mon Aug 16, 2010 8:38 pm

I need to replace the 'id', right?

In terminal of winBox i use "/user active print" and the answer:

# WHEN NAME ADDRESS VIA
0 jan/02/1970 00:00:34 teste4 0.0.0.0 winbox
1 jan/02/1970 00:00:34 teste4 0.0.0.0 console

With this in hand I tried:
Script:

require('routeros_api.class.php');

$API = new routeros_api();
$API->debug = true;

$ip = 'xxx.xxx.xxx.xxx';
$usuario = 'teste4'; // full same admin
$senha = '123456';


if ($API->connect($ip, $usuario, $senha))
{
$API->write('/user/set',false);
$API->write('=name=teste3',false);
$API->write('=.0=teste4'); // Here a tried id, 0 and 1.

$API->disconnect();

$ip = 'xxx.xxx.xxx.xxx';
$usuario = 'teste3';
$senha = '123456';

if ($API->connect($ip, $usuario, $senha))
{
$API->write('/interface/getall');

$ARRAY = $API->read();

print_r($ARRAY);

$API->disconnect();
}
}
response received:

Connection attempt #1 to 192.168.200.221:8728...
<<< [6] /login
>>> [5/5 bytes read.
>>> [5, 39] !done
>>> [37/37 bytes read.
>>> [37, 1] =ret=8441030695fedd9c963c770d925460cd
<<< [6] /login
<<< [12] =name=teste4
<<< [44] =response=000294eb58ca98ef53e55dd28b2ef0acf8
>>> [5/5 bytes read.
>>> [5, 1] !done
Connected...
<<< [9] /user/set
<<< [12] =name=teste3

<<< [10] =.1=teste4
Disconnected...
Connection attempt #1 to 192.168.200.221:8728...
<<< [6] /login
>>> [5/5 bytes read.
>>> [5, 39] !done
>>> [37/37 bytes read.
>>> [37, 1] =ret=9444b11262d1f06b1a62c81b2ddac860
<<< [6] /login
<<< [12] =name=teste3
<<< [44] =response=007ed1d4468149966ca2196c4b82af1f16
>>> [5/5 bytes read.
>>> [5, 31] !trap
>>> [22/22 bytes read.
>>> [22, 8] =message=cannot log in
>>> [5/5 bytes read.
>>> [5, 1] !done
Connection attempt #2 to 192.168.200.221:8728...
<<< [6] /login
>>> [5/5 bytes read.
>>> [5, 39] !done
>>> [37/37 bytes read.
>>> [37, 1] =ret=2226666ebea49c0e354d4d766aa652c4

<<< [6] /login
<<< [12] =name=teste3
<<< [44] =response=004f8ae6db35b745b8436120bbc8fd18cc
>>> [5/5 bytes read.
>>> [5, 31] !trap
>>> [22/22 bytes read.
>>> [22, 8] =message=cannot log in
>>> [5/5 bytes read.
>>> [5, 1] !done
Connection attempt #3 to 192.168.200.221:8728...
<<< [6] /login
>>> [5/5 bytes read.
>>> [5, 39] !done
>>> [37/37 bytes read.
>>> [37, 1] =ret=2c232466e70099e1c4d341aae933b386
<<< [6] /login
<<< [12] =name=teste3

<<< [44] =response=00f4461510173f8eae21702d2e626941ad
>>> [5/5 bytes read.
>>> [5, 31] !trap
>>> [22/22 bytes read.
>>> [22, 8] =message=cannot log in
>>> [5/5 bytes read.
>>> [5, 1] !done
Connection attempt #4 to 192.168.200.221:8728...
<<< [6] /login
>>> [5/5 bytes read.
>>> [5, 39] !done
>>> [37/37 bytes read.
>>> [37, 1] =ret=2128256d5a45199bb248d13db5e7f409
<<< [6] /login
<<< [12] =name=teste3
<<< [44] =response=00d747bd404d71a75980164f245806e96a
>>> [5/5 bytes read.
>>> [5, 31] !trap
>>> [22/22 bytes read.
>>> [22, 8] =message=cannot log in
>>> [5/5 bytes read.
>>> [5, 1] !done
Connection attempt #5 to 192.168.200.221:8728...
<<< [6] /login
>>> [5/5 bytes read.
>>> [5, 39] !done
>>> [37/37 bytes read.
>>> [37, 1] =ret=1e69034240d80270ae9564a517eba75a

<<< [6] /login
<<< [12] =name=teste3
<<< [44] =response=00b7e4073087bc37edd4d33ace5edb1a38
>>> [5/5 bytes read.
>>> [5, 31] !trap
>>> [22/22 bytes read.
>>> [22, 8] =message=cannot log in
>>> [5/5 bytes read.
>>> [5, 1] !done
Error...
A can´t login after command. The mikrotik try and try but Error...

I do not understand what I'm doing wrong. I figured that worked like this:

$API->write('/user/set teste4
=name=teste3');

But it did not work too.
 
SurferTim
Forum Guru
Forum Guru
Posts: 4637
Joined: Mon Jan 07, 2008 10:31 pm
Location: Miramar Beach, Florida

Re: Change hotspot password with PHP API

Mon Aug 16, 2010 8:48 pm

I think this is the challenge:
Connected...
<<< [9] /user/set
<<< [12] =name=teste3

You need something like this:
Connected...
<<< [9] /user/set
<<< [10] =.id=teste4
<<< [12] =name=teste3

Now teste3 will be the user name. But teste4 will no longer work for the id.

Next time, start a new thread. You will get more responses that way!
 
Christiano
Frequent Visitor
Frequent Visitor
Posts: 52
Joined: Fri Aug 13, 2010 8:53 pm

Re: Change hotspot password with PHP API

Mon Aug 16, 2010 9:26 pm

I changed the position of command and got an answer after you have indicated.
But it did not work.

Look:

$API->write('/user/set',false);
$API->write('=.1=teste4'); // Here a tried id, 0 and 1.
$API->write('=name=teste3',false);

That was it? This is the way it should write the code?
the result:

Connection attempt #1 to 192.168.200.221:8728...
<<< [6] /login
>>> [5/5 bytes read.
>>> [5, 39] !done
>>> [37/37 bytes read.
>>> [37, 1] =ret=4e210569c6f7eff5da86de598e944cc6
<<< [6] /login
<<< [12] =name=teste4
<<< [44] =response=00faa4671994be671fee69ff191c309311
>>> [5/5 bytes read.
>>> [5, 1] !done
Connected...
<<< [9] /user/set
<<< [10] =.1=teste4

<<< [12] =name=teste3
Disconnected...

Connection attempt #1 to 192.168.200.221:8728...
<<< [6] /login
>>> [5/5 bytes read.
>>> [5, 39] !done
>>> [37/37 bytes read.
>>> [37, 1] =ret=733e098726650cf35bfb42f6b84e411f
<<< [6] /login
<<< [12] =name=teste3
<<< [44] =response=0053928d217e06c9d47e45144c7b000adb
>>> [5/5 bytes read.
>>> [5, 31] !trap
>>> [22/22 bytes read.
>>> [22, 8] =message=cannot log in
>>> [5/5 bytes read.
>>> [5, 1] !done
(...)
the same
(...)
Error!
Thank you for support Chupaka!

Glad that you exist. There are so many people exchanging information through the internet, but I confess I was beginning to feel completely alone with this problem.
 
User avatar
Chupaka
Forum Guru
Forum Guru
Posts: 8345
Joined: Mon Jun 19, 2006 11:15 pm
Location: Minsk, Belarus
Contact:

Re: Change hotspot password with PHP API

Mon Aug 16, 2010 9:38 pm

omg %)
$API->write('=.id='.$old_name, false);
and about ', false' - it means that command will have additional parameters. if it's 'true' or absent - then the command is executed. so the full form:
$API->write('/user/set', false);
$API->write('=.id='.$old_name, false);
$API->write('=name='.$new_name);
Russian-speaking forum: https://forum.mikrotik.by/. Welcome!

For every complex problem, there is a solution that is simple, neat, and wrong.

MikroTik. Your life. Your routing.
 
Christiano
Frequent Visitor
Frequent Visitor
Posts: 52
Joined: Fri Aug 13, 2010 8:53 pm

Re: Change hotspot password with PHP API

Mon Aug 16, 2010 10:05 pm

I do not understand exactly what you want. Sorry! What should I do to run the script? Should I remove the false parameter?

What I'm trying to do:

-> I'm trying to connect the card using a mikrotik user manager;
-> Then want to change the name of the user;
-> Disconnect;
-> I want to reconnect with the new name;

teste4 is the actual and the old name.
teste3 is the new name.

If I get it, I can make a web-based access control for the plates mikrotiks.

I´m from Brazil. I don´t understand this omg %).

Thank you for your atention!
 
User avatar
Chupaka
Forum Guru
Forum Guru
Posts: 8345
Joined: Mon Jun 19, 2006 11:15 pm
Location: Minsk, Belarus
Contact:

Re: Change hotspot password with PHP API

Mon Aug 16, 2010 10:15 pm

omg = oh, my god!..

in your code, replace
if ($API->connect($ip, $usuario, $senha))
{
$API->write('/user/set',false);
$API->write('=name=teste3',false);
}
with
if ($API->connect($ip, $usuario, $senha))
{
$API->write('/user/set', false);
$API->write('=.id='.$old_name, false);
$API->write('=name='.$new_name);
}
or something
Russian-speaking forum: https://forum.mikrotik.by/. Welcome!

For every complex problem, there is a solution that is simple, neat, and wrong.

MikroTik. Your life. Your routing.
 
Christiano
Frequent Visitor
Frequent Visitor
Posts: 52
Joined: Fri Aug 13, 2010 8:53 pm

Re: Change hotspot password with PHP API

Mon Aug 16, 2010 11:27 pm

I'm going to abuse a little more of your patience ...

I think I've done that in the previous code above. But I tried again. Look:

[b]CODE:[/b]

<?php
require('routeros_api.class.php');

$API = new routeros_api();
$API->debug = true;


$old_name = 'teste4';
$new_name = 'teste3';

if ($API->connect('xxx.xxx.xxx.xxx', $old_name, '123456'))
{
	$API->write('/user/set', false);
	$API->write('=.1='.$old_name, false);
	$API->write('=name='.$new_name);
	
	$API->disconnect();
	
	if ($API->connect('xxx.xxx.xxx.xxx', $new_name, '123456')) 
	{
		$API->write('/interface/getall');
		$ARRAY = $API->read();
		print_r($ARRAY);
		$API->disconnect();
	}

}
?>
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
[b]Result:[/b]

Connection attempt #1 to 192.168.200.221:8728...
<<< [6] /login
>>> [5/5 bytes read.
>>> [5, 39] !done
>>> [37/37 bytes read.
>>> [37, 1] =ret=1fea1cbb243777b91c39e2619af7a197
<<< [6] /login
<<< [12] =name=teste4
<<< [44] =response=00f629fe98712aa6707d7b2c006ceafa07
>>> [5/5 bytes read.
>>> [5, 1] !done
Connected...
<<< [9] /user/set
<<< [10] =.1=teste4

<<< [12] =name=teste3
Disconnected...
Connection attempt #1 to 192.168.200.221:8728...
<<< [6] /login
>>> [5/5 bytes read.
>>> [5, 39] !done
>>> [37/37 bytes read.
>>> [37, 1] =ret=5da30379fe51f6c93686570473ab5706
<<< [6] /login
<<< [12] =name=teste3
<<< [44] =response=00a82eb97d3d594bcbe4120bf409f054c3
>>> [5/5 bytes read.
>>> [5, 31] !trap
>>> [22/22 bytes read.
>>> [22, 8] =message=cannot log in
>>> [5/5 bytes read.
>>> [5, 1] !done
Connection attempt #2 to 192.168.200.221:8728...
<<< [6] /login
>>> [5/5 bytes read.
>>> [5, 39] !done
>>> [37/37 bytes read.
>>> [37, 1] =ret=ea0fe30f2945afd024430890a82df8f5

<<< [6] /login
<<< [12] =name=teste3
<<< [44] =response=00c2d2fa3cdc9ac1697f298523f78f85cb
>>> [5/5 bytes read.
>>> [5, 31] !trap
>>> [22/22 bytes read.
>>> [22, 8] =message=cannot log in
>>> [5/5 bytes read.
>>> [5, 1] !done
Connection attempt #3 to 192.168.200.221:8728...
<<< [6] /login
>>> [5/5 bytes read.
>>> [5, 39] !done
>>> [37/37 bytes read.
>>> [37, 1] =ret=e8b4fcb738e821b9264db018e6275547
<<< [6] /login
<<< [12] =name=teste3

<<< [44] =response=00b857fba7e1673f062262a541a491442e
>>> [5/5 bytes read.
>>> [5, 31] !trap
>>> [22/22 bytes read.
>>> [22, 8] =message=cannot log in
>>> [5/5 bytes read.
>>> [5, 1] !done
Connection attempt #4 to 192.168.200.221:8728...
<<< [6] /login
>>> [5/5 bytes read.
>>> [5, 39] !done
>>> [37/37 bytes read.
>>> [37, 1] =ret=6373efc42eeb4c17be9224e3e4b2aeaa
<<< [6] /login
<<< [12] =name=teste3
<<< [44] =response=001ee80de2577e3cf8942ac56d77c4bbb0
>>> [5/5 bytes read.
>>> [5, 31] !trap
>>> [22/22 bytes read.
>>> [22, 8] =message=cannot log in
>>> [5/5 bytes read.
>>> [5, 1] !done
Connection attempt #5 to 192.168.200.221:8728...
<<< [6] /login
>>> [5/5 bytes read.
>>> [5, 39] !done
>>> [37/37 bytes read.
>>> [37, 1] =ret=fc80bb852dc8357285bd0feb91471627

<<< [6] /login
<<< [12] =name=teste3
<<< [44] =response=0096428d9e2f21031d6b264b78e98eaa9b
>>> [5/5 bytes read.
>>> [5, 31] !trap
>>> [22/22 bytes read.
>>> [22, 8] =message=cannot log in
>>> [5/5 bytes read.
>>> [5, 1] !done
Error...
Doubt:
But if I'm not using Winbox (in the real case), how will I know the old user id? Since the script will know what to put in place of 'id'?
 
fewi
Forum Guru
Forum Guru
Posts: 7734
Joined: Tue Aug 11, 2009 3:19 am

Re: Change hotspot password with PHP API

Mon Aug 16, 2010 11:31 pm

   $API->write('/user/set', false);
   $API->write('=.1='.$old_name, false);
   $API->write('=name='.$new_name);
Stop replacing the word 'id' with the number 1.
   $API->write('/user/set', false);
   $API->write('=.id='.$old_name, false);
   $API->write('=name='.$new_name);
 
User avatar
Chupaka
Forum Guru
Forum Guru
Posts: 8345
Joined: Mon Jun 19, 2006 11:15 pm
Location: Minsk, Belarus
Contact:

Re: Change hotspot password with PHP API

Mon Aug 16, 2010 11:40 pm

oh, those little green men eat my brain %)

as a friend of mine says, "Never say 'copied' until you did Ctrl+C, Ctrl+V" :)

p.s. if it works, you own me karma points :D
Russian-speaking forum: https://forum.mikrotik.by/. Welcome!

For every complex problem, there is a solution that is simple, neat, and wrong.

MikroTik. Your life. Your routing.
 
Christiano
Frequent Visitor
Frequent Visitor
Posts: 52
Joined: Fri Aug 13, 2010 8:53 pm

Re: Change hotspot password with PHP API

Mon Aug 16, 2010 11:50 pm

I replace 1 for id:

$API->write('/user/set', false);
$API->write('=.id='.$old_name, false);
$API->write('=name='.$new_name);

But didn´t work:
Connection attempt #1 to 192.168.200.221:8728...
<<< [6] /login
>>> [5/5 bytes read.
>>> [5, 39] !done
>>> [37/37 bytes read.
>>> [37, 1] =ret=1fb26a805b6554171b758e2e4ebd29dc
<<< [6] /login
<<< [12] =name=teste4
<<< [44] =response=00dc50211d69169a8c5a7efb66df7409e5
>>> [5/5 bytes read.
>>> [5, 1] !done
Connected...
<<< [9] /user/set
<<< [11] =.id=teste4

<<< [12] =name=teste3
Disconnected...
Connection attempt #1 to 192.168.200.221:8728...
<<< [6] /login
>>> [5/5 bytes read.
>>> [5, 39] !done
>>> [37/37 bytes read.
>>> [37, 1] =ret=a611026006b72b6b16089e0bfd1548a6
<<< [6] /login
<<< [12] =name=teste3
<<< [44] =response=00533eacaa8714ecff1cc266c3b7e9249d
>>> [5/5 bytes read.
>>> [5, 31] !trap
>>> [22/22 bytes read.
>>> [22, 8] =message=cannot log in
>>> [5/5 bytes read.
>>> [5, 1] !done
Connection attempt #2 to 192.168.200.221:8728...
<<< [6] /login
>>> [5/5 bytes read.
>>> [5, 39] !done
>>> [37/37 bytes read.
>>> [37, 1] =ret=cc8e149aad11f779aa7c60277b4ceca7

<<< [6] /login
<<< [12] =name=teste3
<<< [44] =response=00bc40244f4fa1748c02bf4a5dbd27d25d
>>> [5/5 bytes read.
>>> [5, 31] !trap
>>> [22/22 bytes read.
>>> [22, 8] =message=cannot log in
>>> [5/5 bytes read.
>>> [5, 1] !done
Connection attempt #3 to 192.168.200.221:8728...
<<< [6] /login
>>> [5/5 bytes read.
>>> [5, 39] !done
>>> [37/37 bytes read.
>>> [37, 1] =ret=ca026c0bf26b706a94959ff95b0fee55
<<< [6] /login
<<< [12] =name=teste3

<<< [44] =response=00066086e924161a180279de2d3b5c7a7f
>>> [5/5 bytes read.
>>> [5, 31] !trap
>>> [22/22 bytes read.
>>> [22, 8] =message=cannot log in
>>> [5/5 bytes read.
>>> [5, 1] !done
Connection attempt #4 to 192.168.200.221:8728...
<<< [6] /login
>>> [5/5 bytes read.
>>> [5, 39] !done
>>> [37/37 bytes read.
>>> [37, 1] =ret=c598dd21f695386cf18de9ae655032c5
<<< [6] /login
<<< [12] =name=teste3
<<< [44] =response=006b0b49629aea59dae657b575dfb85d74
>>> [5/5 bytes read.
>>> [5, 31] !trap
>>> [22/22 bytes read.
>>> [22, 8] =message=cannot log in
>>> [5/5 bytes read.
>>> [5, 1] !done
Connection attempt #5 to 192.168.200.221:8728...
<<< [6] /login
>>> [5/5 bytes read.
>>> [5, 39] !done
>>> [37/37 bytes read.
>>> [37, 1] =ret=b833b02cc8f5344dcc3a30cea283991b

<<< [6] /login
<<< [12] =name=teste3
<<< [44] =response=00fc0290d1fea1f6487cc25171acd7cec1
>>> [5/5 bytes read.
>>> [5, 31] !trap
>>> [22/22 bytes read.
>>> [22, 8] =message=cannot log in
>>> [5/5 bytes read.
>>> [5, 1] !done
Error...

I do not know what to do. A friend told me to forget this API and try to use Shell(. Sh). I think I'll follow the suggestion...
 
User avatar
Chupaka
Forum Guru
Forum Guru
Posts: 8345
Joined: Mon Jun 19, 2006 11:15 pm
Location: Minsk, Belarus
Contact:

Re: Change hotspot password with PHP API

Mon Aug 16, 2010 11:55 pm

before disconnecting, you MUST read the response. try "$ARRAY = $API->read(); print_r($ARRAY);" before "$API->disconnect();"
Russian-speaking forum: https://forum.mikrotik.by/. Welcome!

For every complex problem, there is a solution that is simple, neat, and wrong.

MikroTik. Your life. Your routing.
 
SurferTim
Forum Guru
Forum Guru
Posts: 4637
Joined: Mon Jan 07, 2008 10:31 pm
Location: Miramar Beach, Florida

Re: Change hotspot password with PHP API

Tue Aug 17, 2010 12:31 am

What group is the user teste4? Does that user have permission to do that change?
Why is there a blank line between the id and the name lines?
Connected...
<<< [9] /user/set
<<< [11] =.id=teste4

<<< [12] =name=teste3
Disconnected...
 
Christiano
Frequent Visitor
Frequent Visitor
Posts: 52
Joined: Fri Aug 13, 2010 8:53 pm

Re: Change hotspot password with PHP API

Tue Aug 17, 2010 3:29 pm

I'm afraid to celebrate at the wrong time but I think now you are right on target. :)

Chupak you're the man! :D

Now is working !!!!!

Look:

SCRIPT:
<?php
require('routeros_api.class.php');

$API = new routeros_api();
$API->debug = true;


$ip = 'xxx.xxx.xxx.xxx';
$old_password = '123456';
$old_name = 'testeb';
$new_password = '123456';
$new_name = 'testea';

if ($API->connect($ip, $old_name, $old_password))
{
	$API->write('/user/set', false);
	$API->write('=.id='.$old_name, false);
	$API->write('=name='.$new_name);
	
	$ARRAY = $API->read();
	print_r($ARRAY);
	
	$API->disconnect();
	
	if ($API->connect($ip, $new_name, $new_password)) 
	{
		$API->write('/interface/getall');
		$ARRAY = $API->read();
		print_r($ARRAY);
		$API->disconnect();
	}
}
?>

RESULT:
Connection attempt #1 to xxx.xxx.xxx.xxx:8728...
<<< [6] /login
>>> [5/5 bytes read.
>>> [5, 39] !done
>>> [37/37 bytes read.
>>> [37, 1] =ret=cfc3bb0305947b63aa5cc3c4b068685b
<<< [6] /login
<<< [12] =name=testeb
<<< [44] =response=00ad387bab4a4f1e0e36fecf63a588f7be
>>> [5/5 bytes read.
>>> [5, 1] !done
Connected...
<<< [9] /user/set
<<< [11] =.id=testeb

<<< [12] =name=testea
>>> [5/5 bytes read.
>>> [5, 1] !done
Array
(
)
Disconnected...
Connection attempt #1 to xxx.xxx.xxx.xxx:8728...
<<< [6] /login
>>> [5/5 bytes read.
>>> [5, 39] !done
>>> [37/37 bytes read.
>>> [37, 1] =ret=feac54a9279e6b5fc2db16886d3504ff
<<< [6] /login
<<< [12] =name=testea
<<< [44] =response=00f565dbddd9a335bb8559b4c48c32c16c
>>> [5/5 bytes read.
>>> [5, 1] !done
Connected...
<<< [17] /interface/getall
>>> [3/3 bytes read.
>>> [3, 437] !re
>>> [7/7 bytes read.
>>> [7, 429] =.id=*1
>>> [12/12 bytes read.
>>> [12, 416] =name=ether1
>>> [11/11 bytes read.
>>> [11, 404] =type=ether
>>> [9/9 bytes read.
>>> [9, 394] =mtu=1500
>>> [11/11 bytes read.
>>> [11, 382] =l2mtu=1526
>>> [20/20 bytes read.
>>> [20, 361] =bytes=277611/136422
>>> [17/17 bytes read.
>>> [17, 343] =packets=2544/637
>>> [14/14 bytes read.
>>> [14, 328] =dynamic=false
>>> [13/13 bytes read.
>>> [13, 314] =running=true
>>> [15/15 bytes read.
>>> [15, 298] =disabled=false
>>> [9/9 bytes read.
>>> [9, 288] =comment=
>>> [3/3 bytes read.
>>> [3, 283] !re
>>> [7/7 bytes read.
>>> [7, 275] =.id=*2
>>> [12/12 bytes read.
>>> [12, 262] =name=ether2
>>> [11/11 bytes read.
>>> [11, 250] =type=ether
>>> [9/9 bytes read.
>>> [9, 240] =mtu=1500
>>> [11/11 bytes read.
>>> [11, 228] =l2mtu=1522
>>> [10/10 bytes read.
>>> [10, 217] =bytes=0/0
>>> [12/12 bytes read.
>>> [12, 204] =packets=0/0
>>> [14/14 bytes read.
>>> [14, 189] =dynamic=false
>>> [14/14 bytes read.
>>> [14, 174] =running=false
>>> [15/15 bytes read.
>>> [15, 158] =disabled=false
>>> [9/9 bytes read.
>>> [9, 148] =comment=
>>> [3/3 bytes read.
>>> [3, 143] !re
>>> [7/7 bytes read.
>>> [7, 135] =.id=*3
>>> [12/12 bytes read.
>>> [12, 122] =name=ether3
>>> [11/11 bytes read.
>>> [11, 110] =type=ether
>>> [9/9 bytes read.
>>> [9, 100] =mtu=1500
>>> [11/11 bytes read.
>>> [11, 88] =l2mtu=1522
>>> [10/10 bytes read.
>>> [10, 77] =bytes=0/0
>>> [12/12 bytes read.
>>> [12, 64] =packets=0/0
>>> [14/14 bytes read.
>>> [14, 49] =dynamic=false
>>> [14/14 bytes read.
>>> [14, 34] =running=false
>>> [15/15 bytes read.
>>> [15, 18] =disabled=false
>>> [9/9 bytes read.
>>> [9, 8] =comment=
>>> [5/5 bytes read.
>>> [5, 1] !done
Array
(
    [0] => Array
        (
            [.id] => *1
            [name] => ether1
            [type] => ether
            [mtu] => 1500
            [l2mtu] => 1526
            [bytes] => 277611/136422
            [packets] => 2544/637
            [dynamic] => false
            [running] => true
            [disabled] => false
            [comment] => 
        )

    [1] => Array
        (
            [.id] => *2
            [name] => ether2
            [type] => ether
            [mtu] => 1500
            [l2mtu] => 1522
            [bytes] => 0/0
            [packets] => 0/0
            [dynamic] => false
            [running] => false
            [disabled] => false
            [comment] => 
        )

    [2] => Array
        (
            [.id] => *3
            [name] => ether3
            [type] => ether
            [mtu] => 1500
            [l2mtu] => 1522
            [bytes] => 0/0
            [packets] => 0/0
            [dynamic] => false
            [running] => false
            [disabled] => false
            [comment] => 
        )

)
Disconnected...


Are you listening?

Clap, clap, clap, clap, clap. Heeeeeeee!!! Great Job!!! Huuuuuu!!!!!

In the middle of the stadium we have a winnerrrr.

Thank you very much chupaka!

How does the karma system you mentioned? Just click on how I want?

---------------------------------------------------------------

Hi fewi. Hi SurferTim. Thank You for your attention and help too.

Answers to your questions SurferTim:

What group is the user teste4?
R: full
Does that user have permission to do that change?
R: Yes. Same admin.
Why is there a blank line between the id and the name lines?
R: I don´t know. The code I present here in the forum is the same as I am testing here at my computer. I do not know why it jumps the line. You have idea?

-------

The array is blank in the first time because the command don´t have result to appear. I think...

Everybody help, thank you!!!! And may God reward all of you with Happiness. I will pray that the world people can help each other as you exemplified here.
:D
 
User avatar
Chupaka
Forum Guru
Forum Guru
Posts: 8345
Joined: Mon Jun 19, 2006 11:15 pm
Location: Minsk, Belarus
Contact:

Re: Change hotspot password with PHP API

Tue Aug 17, 2010 3:43 pm

How does the karma system you mentioned? Just click on how I want?
yep, simply click HERE :)

I'm glad I can help :D
Russian-speaking forum: https://forum.mikrotik.by/. Welcome!

For every complex problem, there is a solution that is simple, neat, and wrong.

MikroTik. Your life. Your routing.
 
Christiano
Frequent Visitor
Frequent Visitor
Posts: 52
Joined: Fri Aug 13, 2010 8:53 pm

Re: Change hotspot password with PHP API

Tue Aug 17, 2010 4:16 pm

Adapting the test above to add user:
<?php
require('routeros_api.class.php');

$API = new routeros_api();
$API->debug = true;


$ip = 'xxx.xxx.xxx.xxx';
$old_password = '123456';
$old_name = 'testea';
$new_password = '123456';
$new_name = 'testeb';

if ($API->connect($ip, $old_name, $old_password))
{
	$API->write('/user/add', false);
	$API->write('=group=full', false);
	$API->write('=name=zuca', false);
	$API->write('=password=123456');
		
	$new_name = 'zuca';
	$ARRAY = $API->read();
	print_r($ARRAY);
	
	$API->disconnect();
	
	if ($API->connect($ip, $new_name, $new_password)) 
	{
		$API->write('/interface/getall');
		$ARRAY = $API->read();
		print_r($ARRAY);
		$API->disconnect();
	}
}
?>


It´s working:
Connection attempt #1 to xxx.xxx.xxx.xxx:8728...
<<< [6] /login
>>> [5/5 bytes read.
>>> [5, 39] !done
>>> [37/37 bytes read.
>>> [37, 1] =ret=7b4519f9cce802b64a4181386154b012
<<< [6] /login
<<< [12] =name=testea
<<< [44] =response=002db108e8acd3b2e230e3b94be5a245ee
>>> [5/5 bytes read.
>>> [5, 1] !done
Connected...
<<< [9] /user/add
<<< [11] =group=full

<<< [10] =name=zuca
<<< [16] =password=123456
>>> [5/5 bytes read.
>>> [5, 9] !done
>>> [7/7 bytes read.
>>> [7, 1] =ret=*6
Array
(
)
Disconnected...
Connection attempt #1 to xxx.xxx.xxx.xxx:8728...
<<< [6] /login
>>> [5/5 bytes read.
>>> [5, 39] !done
>>> [37/37 bytes read.
>>> [37, 1] =ret=17779f55f1437de64473ea814fe411b9
<<< [6] /login
<<< [10] =name=zuca
<<< [44] =response=00ce3d55b646aa538e6b1ebd110900b910
>>> [5/5 bytes read.
>>> [5, 1] !done
Connected...

<<< [17] /interface/getall
>>> [3/3 bytes read.
>>> [3, 438] !re
>>> [7/7 bytes read.
>>> [7, 430] =.id=*1
>>> [12/12 bytes read.
>>> [12, 417] =name=ether1
>>> [11/11 bytes read.
>>> [11, 405] =type=ether
>>> [9/9 bytes read.
>>> [9, 395] =mtu=1500
>>> [11/11 bytes read.
>>> [11, 383] =l2mtu=1526
>>> [20/20 bytes read.
>>> [20, 362] =bytes=898078/202207
>>> [18/18 bytes read.
>>> [18, 343] =packets=7061/1064
>>> [14/14 bytes read.
>>> [14, 328] =dynamic=false
>>> [13/13 bytes read.
>>> [13, 314] =running=true
>>> [15/15 bytes read.
>>> [15, 298] =disabled=false
>>> [9/9 bytes read.
>>> [9, 288] =comment=
>>> [3/3 bytes read.
>>> [3, 283] !re
>>> [7/7 bytes read.
>>> [7, 275] =.id=*2
>>> [12/12 bytes read.
>>> [12, 262] =name=ether2
>>> [11/11 bytes read.
>>> [11, 250] =type=ether
>>> [9/9 bytes read.
>>> [9, 240] =mtu=1500
>>> [11/11 bytes read.
>>> [11, 228] =l2mtu=1522
>>> [10/10 bytes read.
>>> [10, 217] =bytes=0/0
>>> [12/12 bytes read.
>>> [12, 204] =packets=0/0
>>> [14/14 bytes read.
>>> [14, 189] =dynamic=false
>>> [14/14 bytes read.
>>> [14, 174] =running=false
>>> [15/15 bytes read.
>>> [15, 158] =disabled=false
>>> [9/9 bytes read.
>>> [9, 148] =comment=
>>> [3/3 bytes read.
>>> [3, 143] !re
>>> [7/7 bytes read.
>>> [7, 135] =.id=*3
>>> [12/12 bytes read.
>>> [12, 122] =name=ether3
>>> [11/11 bytes read.
>>> [11, 110] =type=ether
>>> [9/9 bytes read.
>>> [9, 100] =mtu=1500
>>> [11/11 bytes read.
>>> [11, 88] =l2mtu=1522
>>> [10/10 bytes read.
>>> [10, 77] =bytes=0/0
>>> [12/12 bytes read.
>>> [12, 64] =packets=0/0
>>> [14/14 bytes read.
>>> [14, 49] =dynamic=false
>>> [14/14 bytes read.
>>> [14, 34] =running=false
>>> [15/15 bytes read.
>>> [15, 18] =disabled=false
>>> [9/9 bytes read.
>>> [9, 8] =comment=
>>> [5/5 bytes read.
>>> [5, 1] !done
Array
(
    [0] => Array
        (
            [.id] => *1
            [name] => ether1
            [type] => ether
            [mtu] => 1500
            [l2mtu] => 1526
            [bytes] => 898078/202207
            [packets] => 7061/1064
            [dynamic] => false
            [running] => true
            [disabled] => false
            [comment] => 
        )

    [1] => Array
        (
            [.id] => *2
            [name] => ether2
            [type] => ether
            [mtu] => 1500
            [l2mtu] => 1522
            [bytes] => 0/0
            [packets] => 0/0
            [dynamic] => false
            [running] => false
            [disabled] => false
            [comment] => 
        )

    [2] => Array
        (
            [.id] => *3
            [name] => ether3
            [type] => ether
            [mtu] => 1500
            [l2mtu] => 1522
            [bytes] => 0/0
            [packets] => 0/0
            [dynamic] => false
            [running] => false
            [disabled] => false
            [comment] => 
        )

)
Disconnected...
Upward and onward!

:D


Without charity there is no salvation.
 
Krco
just joined
Posts: 18
Joined: Tue Aug 24, 2010 12:58 am

Re: Change hotspot password with PHP API

Tue Aug 24, 2010 4:29 pm

Pls can somebody give to me in one post all theat things theat works pls :( I really need it

I really wish that my hotspot users can change their own passwords
Last edited by Krco on Tue Aug 24, 2010 6:05 pm, edited 1 time in total.
 
User avatar
Chupaka
Forum Guru
Forum Guru
Posts: 8345
Joined: Mon Jun 19, 2006 11:15 pm
Location: Minsk, Belarus
Contact:

Re: Change hotspot password with PHP API

Tue Aug 24, 2010 5:58 pm

what exactly do you need?
Russian-speaking forum: https://forum.mikrotik.by/. Welcome!

For every complex problem, there is a solution that is simple, neat, and wrong.

MikroTik. Your life. Your routing.
 
Krco
just joined
Posts: 18
Joined: Tue Aug 24, 2010 12:58 am

Re: Change hotspot password with PHP API

Tue Aug 24, 2010 6:07 pm

all scripts and pages for changing password from the user i want theat work (my English is bad and I cant connect all those posts, I am lost in PHP, HTML and JavaScript :P can you write me how to do all. pls in steps :( just how to write i know how to place it on router tnq :)
 
User avatar
Chupaka
Forum Guru
Forum Guru
Posts: 8345
Joined: Mon Jun 19, 2006 11:15 pm
Location: Minsk, Belarus
Contact:

Re: Change hotspot password with PHP API

Tue Aug 24, 2010 6:27 pm

you cannot place it in RouterOS - you should use additional webserver with PHP support
Russian-speaking forum: https://forum.mikrotik.by/. Welcome!

For every complex problem, there is a solution that is simple, neat, and wrong.

MikroTik. Your life. Your routing.
 
Krco
just joined
Posts: 18
Joined: Tue Aug 24, 2010 12:58 am

Re: Change hotspot password with PHP API

Tue Aug 24, 2010 6:35 pm

But I just need theat i will have it ;)
 
Krco
just joined
Posts: 18
Joined: Tue Aug 24, 2010 12:58 am

Re: Change hotspot password with PHP API

Tue Aug 24, 2010 7:08 pm

Pls can you give it to me :(
 
Krco
just joined
Posts: 18
Joined: Tue Aug 24, 2010 12:58 am

Re: Change hotspot password with PHP API

Tue Aug 24, 2010 7:40 pm

you cannot place it in RouterOS - you should use additional webserver with PHP support
Please :(
 
fewi
Forum Guru
Forum Guru
Posts: 7734
Joined: Tue Aug 11, 2009 3:19 am

Re: Change hotspot password with PHP API

Tue Aug 24, 2010 7:49 pm

Do you have an external web server with a PHP stack installed?

Also, posting the same request three times in a row less than 90 minutes apart is kind of rude.
 
Krco
just joined
Posts: 18
Joined: Tue Aug 24, 2010 12:58 am

Re: Change hotspot password with PHP API

Tue Aug 24, 2010 8:00 pm

Yes I have :) server with PHP instaled
 
Christiano
Frequent Visitor
Frequent Visitor
Posts: 52
Joined: Fri Aug 13, 2010 8:53 pm

Re: Change hotspot password with PHP API

Fri Sep 03, 2010 3:31 pm

You need see this first:

http://wiki.mikrotik.com/wiki/Manual:API
http://wiki.mikrotik.com/wiki/API_PHP_class
http://under-linux.org/f215/mikrotik-ap ... ql-134691/
http://under-linux.org/f143/ajuda-api-php-122996/

After go back here and read more in the fórum. Beleave, you can.


Without charity there is no salvation.
 
User avatar
neandero
Member Candidate
Member Candidate
Posts: 243
Joined: Fri Jul 17, 2009 11:43 am
Location: Inside Mind

Re: Change hotspot password with PHP API

Sat Sep 04, 2010 4:00 pm

i don't know to much about php, could it be possible to change user's pass through basic html.
for example: modifying the hotspot/status.html file.
not using anything but the routerboardos itself as a server?
 
fewi
Forum Guru
Forum Guru
Posts: 7734
Joined: Tue Aug 11, 2009 3:19 am

Re: Change hotspot password with PHP API

Sat Sep 04, 2010 4:22 pm

No, it is not.
 
User avatar
winet
Member Candidate
Member Candidate
Posts: 272
Joined: Fri Mar 16, 2007 4:49 pm
Location: Indonesia

Re: Change hotspot password with PHP API

Thu Nov 03, 2011 2:50 pm

i managed to create "set" and "add" script, but failed on "remove" script

for example: /ip/hotspot/user/remove

dunno which function to use, comm / write

any idea?

EDIT: i got it. i use write, just switch the boolean from false to true, dunno what it means, but it works. it would be better if anyone could explain it anyway.
$API->write(command,boolean)
what exactly true or false do to this function?
 
User avatar
Chupaka
Forum Guru
Forum Guru
Posts: 8345
Joined: Mon Jun 19, 2006 11:15 pm
Location: Minsk, Belarus
Contact:

Re: Change hotspot password with PHP API

Thu Nov 03, 2011 4:00 pm

'true' means 'send the command, no more parameters will be added'
'false' means 'there will be additional words (parameters) in the command, send the command when the next call with "true" will be'

AFAIR :)
Russian-speaking forum: https://forum.mikrotik.by/. Welcome!

For every complex problem, there is a solution that is simple, neat, and wrong.

MikroTik. Your life. Your routing.
 
User avatar
winet
Member Candidate
Member Candidate
Posts: 272
Joined: Fri Mar 16, 2007 4:49 pm
Location: Indonesia

Re: Change hotspot password with PHP API

Thu Nov 03, 2011 5:56 pm

'true' means 'send the command, no more parameters will be added'
'false' means 'there will be additional words (parameters) in the command, send the command when the next call with "true" will be'

AFAIR :)
i see :) thanks for it

btw, while making this script. i've just found a bug on winbox, on /ip hotspot user profile outgoing-filter= and incoming-filter=, u can't disable/remove it on GUI once activated(only through terminal command line). i'm running v5.7 ROS.
 
User avatar
Chupaka
Forum Guru
Forum Guru
Posts: 8345
Joined: Mon Jun 19, 2006 11:15 pm
Location: Minsk, Belarus
Contact:

Re: Change hotspot password with PHP API

Thu Nov 03, 2011 11:06 pm

a bug on winbox, on /ip hotspot user profile outgoing-filter= and incoming-filter=, u can't disable/remove it on GUI once activated(only through terminal command line). i'm running v5.7 ROS.
can't see anything unusual in v5.8... what's with 5.7? there's no 'up' arrow at the right, or something else?..
Russian-speaking forum: https://forum.mikrotik.by/. Welcome!

For every complex problem, there is a solution that is simple, neat, and wrong.

MikroTik. Your life. Your routing.
 
User avatar
winet
Member Candidate
Member Candidate
Posts: 272
Joined: Fri Mar 16, 2007 4:49 pm
Location: Indonesia

Re: Change hotspot password with PHP API

Fri Nov 04, 2011 4:44 am

a bug on winbox, on /ip hotspot user profile outgoing-filter= and incoming-filter=, u can't disable/remove it on GUI once activated(only through terminal command line). i'm running v5.7 ROS.
can't see anything unusual in v5.8... what's with 5.7? there's no 'up' arrow at the right, or something else?..
the GUI showing it is cleared(outgoing filter/incoming filter) but it is actually not, since when a hotspot user login with the profile, the dynamic still created. so i checked the configuration with terminal, and i see the filter still there. i had to clear the incoming/outgoing filter with command line.
 
User avatar
Chupaka
Forum Guru
Forum Guru
Posts: 8345
Joined: Mon Jun 19, 2006 11:15 pm
Location: Minsk, Belarus
Contact:

Re: Change hotspot password with PHP API

Fri Nov 04, 2011 8:45 am

the GUI showing it is cleared(outgoing filter/incoming filter) but it is actually not, since when a hotspot user login with the profile, the dynamic still created. so i checked the configuration with terminal, and i see the filter still there. i had to clear the incoming/outgoing filter with command line.
then, the same bug is in v5.8. have you reported it to support@?
Russian-speaking forum: https://forum.mikrotik.by/. Welcome!

For every complex problem, there is a solution that is simple, neat, and wrong.

MikroTik. Your life. Your routing.
 
User avatar
winet
Member Candidate
Member Candidate
Posts: 272
Joined: Fri Mar 16, 2007 4:49 pm
Location: Indonesia

Re: Change hotspot password with PHP API

Fri Nov 04, 2011 6:24 pm

the GUI showing it is cleared(outgoing filter/incoming filter) but it is actually not, since when a hotspot user login with the profile, the dynamic still created. so i checked the configuration with terminal, and i see the filter still there. i had to clear the incoming/outgoing filter with command line.
then, the same bug is in v5.8. have you reported it to support@?
not yet, i think it will be better if it is u report it than me :lol:
 
User avatar
Chupaka
Forum Guru
Forum Guru
Posts: 8345
Joined: Mon Jun 19, 2006 11:15 pm
Location: Minsk, Belarus
Contact:

Re: Change hotspot password with PHP API

Fri Nov 04, 2011 6:42 pm

not yet, i think it will be better if it is u report it than me :lol:
write to support@! I already have a few open tickets with bugs... errr, features :)
Russian-speaking forum: https://forum.mikrotik.by/. Welcome!

For every complex problem, there is a solution that is simple, neat, and wrong.

MikroTik. Your life. Your routing.
 
User avatar
winet
Member Candidate
Member Candidate
Posts: 272
Joined: Fri Mar 16, 2007 4:49 pm
Location: Indonesia

Re: Change hotspot password with PHP API

Sat Nov 05, 2011 1:22 pm

not yet, i think it will be better if it is u report it than me :lol:
write to support@! I already have a few open tickets with bugs... errr, features :)
found similiar bug. still on hotspot user profile, this one is on "Address Pool" field. still haven't written to support :p
 
solution
just joined
Posts: 5
Joined: Sun Oct 30, 2011 8:21 pm

Re: Change hotspot password with PHP API

Mon Dec 12, 2011 2:01 am

good night,
able to run the password change with this script in php.
but how to validate the old password?
because this way anyone can change the password, since it is not necessary to know the old password.

I'm from Brazil, sorry my English is not so good.
 
User avatar
janisk
MikroTik Support
MikroTik Support
Posts: 6283
Joined: Tue Feb 14, 2006 9:46 am
Location: Riga, Latvia

Re: Change hotspot password with PHP API

Mon Dec 12, 2011 9:12 am

do not mix up password change using /password command (that is interactive and does not work in API and /user menu has to be used instead) with password of hotspot user password
 
User avatar
Chupaka
Forum Guru
Forum Guru
Posts: 8345
Joined: Mon Jun 19, 2006 11:15 pm
Location: Minsk, Belarus
Contact:

Re: Change hotspot password with PHP API

Tue Dec 13, 2011 1:26 am

but how to validate the old password?
print all your hotspot users - 'password' field should be here
Russian-speaking forum: https://forum.mikrotik.by/. Welcome!

For every complex problem, there is a solution that is simple, neat, and wrong.

MikroTik. Your life. Your routing.
 
solution
just joined
Posts: 5
Joined: Sun Oct 30, 2011 8:21 pm

Re: Change hotspot password with PHP API

Tue Dec 13, 2011 2:02 pm

ok

I'll check how to treat and make the data verification/comparison data.

Who is online

Users browsing this forum: No registered users and 11 guests