Community discussions

MikroTik App
 
alissonx
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 63
Joined: Tue Oct 06, 2009 4:12 pm

[SOLVED] PHP API to disconnect a user

Tue Oct 06, 2009 4:16 pm

Hi,

i'm trying to disconnect some users with the command remove

follow the code
<?php
$host="192.168.3.10";
$usuario="admin";
$senha="admin";
require_once('classes/routeros_api.class.php');
$API = new routeros_api();
$API->debug = true;
echo"<br>
";
if ($API->connect("192.168.3.10", "admin", "admin" )) {
$API->write('/ppp/active/print');
$READ = $API->read(false);
$ARRAY = $API->parse_response($READ);
print_r($ARRAY);
$API->write('/ppp/active/remove/0');
$READ = $API->read(false);
$ARRAY = $API->parse_response($READ);
//$API->disconnect();
} 
?>

the first command ppp/active/print is working

but the ppp/active/remove isn't working

can somebody help me?
Last edited by alissonx on Mon Oct 10, 2011 3:14 pm, edited 1 time in total.
 
fewi
Forum Guru
Forum Guru
Posts: 7717
Joined: Tue Aug 11, 2009 3:19 am

Re: PHP API to disconnect a user

Tue Oct 06, 2009 6:59 pm

"/ppp/active/remove/0" is not a valid API command. Refer to http://wiki.mikrotik.com/wiki/API for the syntax.
 
alissonx
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 63
Joined: Tue Oct 06, 2009 4:12 pm

Re: PHP API to disconnect a user

Tue Oct 06, 2009 9:28 pm

but... i used this commands

on the terminal and telnet

and they are working
 
fewi
Forum Guru
Forum Guru
Posts: 7717
Joined: Tue Aug 11, 2009 3:19 am

Re: PHP API to disconnect a user

Tue Oct 06, 2009 10:07 pm

The API has a different syntax than the CLI. The wiki outlines the syntax to use.
 
alissonx
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 63
Joined: Tue Oct 06, 2009 4:12 pm

Re: PHP API to disconnect a user

Tue Oct 06, 2009 10:16 pm

ok thank you,

i'll use shell + php to do this..

the php API is so good.. but need more commands
 
fewi
Forum Guru
Forum Guru
Posts: 7717
Joined: Tue Aug 11, 2009 3:19 am

Re: PHP API to disconnect a user

Tue Oct 06, 2009 10:27 pm

What commands are you missing? You can remove entries via the API, just not with the syntax you're using.
 
alissonx
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 63
Joined: Tue Oct 06, 2009 4:12 pm

Re: PHP API to disconnect a user

Tue Oct 06, 2009 10:37 pm

i need to do this command

ppp active remove $i

in API
 
fewi
Forum Guru
Forum Guru
Posts: 7717
Joined: Tue Aug 11, 2009 3:19 am

Re: PHP API to disconnect a user

Tue Oct 06, 2009 10:41 pm

So follow the link to the wiki above to find out how to do that.
 
alissonx
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 63
Joined: Tue Oct 06, 2009 4:12 pm

Re: PHP API to disconnect a user

Tue Oct 06, 2009 10:48 pm

I do this oon terminal > /ppp active remove 0

on API $API->write('/ppp/active/remove/0');
 
alissonx
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 63
Joined: Tue Oct 06, 2009 4:12 pm

Re: PHP API to disconnect a user

Tue Oct 06, 2009 11:30 pm

how i do this command /ppp active remove 0 on the API?
 
User avatar
Chupaka
Forum Guru
Forum Guru
Posts: 8709
Joined: Mon Jun 19, 2006 11:15 pm
Location: Minsk, Belarus
Contact:

Re: PHP API to disconnect a user

Wed Oct 07, 2009 2:16 am

first, you do
/ppp/active/print
=.proplist=.id
?name=something
then
/ppp/active/remove
=.id=*here_is_id_from_previous_command_result
 
alissonx
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 63
Joined: Tue Oct 06, 2009 4:12 pm

Re: PHP API to disconnect a user

Wed Oct 07, 2009 3:04 pm

but on the API PHP

$API->write('/ppp/active/remove/');
$API->write('=.id=0');


that's right?
 
User avatar
janisk
MikroTik Support
MikroTik Support
Posts: 6263
Joined: Tue Feb 14, 2006 9:46 am
Location: Riga, Latvia

Re: PHP API to disconnect a user

Wed Oct 07, 2009 3:33 pm

yes, something like that, just use correct id numbers.

id numbers look something like this:
!re
=.id=*9
!re
=.id=*4402E70B
!re
=.id=*44038805
!re
=.id=*4403AC69
!re
=.id=*4403A3DB
!re
=.id=*30000003
!re
=.id=*440395C1
!re
=.id=*4403A083
!re
=.id=*44038CC1

!done
 
alissonx
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 63
Joined: Tue Oct 06, 2009 4:12 pm

Re: PHP API to disconnect a user

Wed Oct 07, 2009 4:08 pm

Hi,

isn't working... the user is connected and the id = *6

the code above is not workin

$API->write('/ppp/active/remove');
$API->write('=.id=*6');
$READ = $API->read(false);
$ARRAY = $API->parse_response($READ);


what's wrong?
 
User avatar
Chupaka
Forum Guru
Forum Guru
Posts: 8709
Joined: Mon Jun 19, 2006 11:15 pm
Location: Minsk, Belarus
Contact:

Re: PHP API to disconnect a user

Wed Oct 07, 2009 4:45 pm

$API->write('/ppp/active/remove', false);

only last line of command should not contain second parameter
 
alissonx
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 63
Joined: Tue Oct 06, 2009 4:12 pm

Re: PHP API to disconnect a user

Wed Oct 07, 2009 6:52 pm

thank you so much

now its working :D
 
ecosysonidos2
just joined
Posts: 24
Joined: Fri Dec 07, 2012 12:10 am

Re: PHP API to disconnect a user

Wed Dec 12, 2012 4:05 am

first, you do
/ppp/active/print
=.proplist=.id
?name=something
then
/ppp/active/remove
=.id=*here_is_id_from_previous_command_result
I need your help with this I tried to delete my hotspot users when they are active but I couldn't
I tried with this in php
$var='someuser'
$BRIDGEINFO = $API->comm('/ip/hotspot/user/active/print', array(
            ".proplist" => ".id",
            "?name" => "$var"
            ));
			
       $API->comm('/ip/hotspot/active/remove', false, array(
            ".id"=>$BRIDGEINFO[0]['.id'],
		
             ));

maybe my code doesn't work can you tell me which is my mistakes
		 
 
User avatar
Chupaka
Forum Guru
Forum Guru
Posts: 8709
Joined: Mon Jun 19, 2006 11:15 pm
Location: Minsk, Belarus
Contact:

Re: [SOLVED] PHP API to disconnect a user

Wed Dec 12, 2012 12:30 pm

have you checked whether you get correct result in $BRIDGEINFO[0]['.id'], for example?..
 
ecosysonidos2
just joined
Posts: 24
Joined: Fri Dec 07, 2012 12:10 am

Re: [SOLVED] PHP API to disconnect a user

Wed Dec 12, 2012 11:32 pm

have you checked whether you get correct result in $BRIDGEINFO[0]['.id'], for example?..
I tried to do this like when I have an Hotspot user and instead to disable an user I delete them and it works because when I put it, it catches me the id from user
something like that
$var="someuser";
$BRIDGEINFO = $API->comm('/ip/hotspot/user/print', array(
            ".proplist" => ".id",
            "?name" => "$var"
            ));
        $API->comm('/ip/hotspot/user/remove', array(
            ".id"=>$BRIDGEINFO[0]['.id'],
             ));
and it works
but it is only with my users from hotspot
it doesn't work with my users that I have active and I want to delete them

and I tried also like this
$BRIDGEINFO = $API->comm('/ip/hotspot/user/print', array(
            ".proplist" => ".id",
            "?name" => "$var"
            ));
mm('/ip/hotspot/user/active/remove', array(
            ".id"=>$BRIDGEINFO[0]['.id'],
             ));
but it doesn't work, I could removed only my users from hotspot but I can't do the same from my hotspot users when they are active and that is my big problem any idea? thanks anyway
 
User avatar
boen_robot
Forum Guru
Forum Guru
Posts: 2400
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: [SOLVED] PHP API to disconnect a user

Thu Dec 13, 2012 2:10 pm

In this code:
$BRIDGEINFO = $API->comm('/ip/hotspot/user/print', array(
            ".proplist" => ".id",
            "?name" => "$var"
            ));
mm('/ip/hotspot/user/active/remove', array(
            ".id"=>$BRIDGEINFO[0]['.id'],
             ));
you're getting the "user" ID, not the "user/active" ID, which is why the remove fails.

Try it as
$BRIDGEINFO = $API->comm('/ip/hotspot/user/active/print', array(
            ".proplist" => ".id",
            "?name" => "$var"
            ));
mm('/ip/hotspot/user/active/remove', array(
            ".id"=>$BRIDGEINFO[0]['.id'],
             ));
 
ecosysonidos2
just joined
Posts: 24
Joined: Fri Dec 07, 2012 12:10 am

Re: [SOLVED] PHP API to disconnect a user

Sun Dec 16, 2012 10:10 pm

In this code:
mm = $API->comm('/ip/hotspot/user/print', array(
            ".proplist" => ".id",
            "?name" => "$var"
            ));
mm('/ip/hotspot/user/remove', array(
            ".id"=>$BRIDGEINFO[0]['.id'],
             ));
you're getting the "user" ID, not the "user/active" ID, which is why the remove fails.

Try it as
$BRIDGEINFO = $API->comm('/ip/hotspot/user/active/print', array(
            ".proplist" => ".id",
            "?name" => "$var"
            ));

mm('/ip/hotspot/user/active/remove', array(
            ".id"=>$BRIDGEINFO[0]['.id'],
             ));



I tried like this too
$var="someuser";
$BRIDGEINFO = $API->comm('/ip/hotspot/user/active/print', array(
            ".proplist" => ".id",
            "?name" => "$var"
            ));
 $API->comm('/ip/hotspot/user/active/remove', array(
            ".id"=>$BRIDGEINFO[0]['.id'],
             ));

$API->disconnect();
and it gives me this resut
Connection attempt #1 to 192.168.x.x:xxxx... <<< [6] /login >>> [5/5] bytes read. >>> [5, 39]!done >>> [37/37] bytes read. >>> [37, 1]=ret=eaaf47c3a811cc80f0304e21067abbc9 <<< [6] /login <<< [11] =name=admin <<< [44] =response=00c8e509faa8f3f9d11b621eddaaa0cc9e >>> [5/5] bytes read. >>> [5, 1]!done Connected... <<< [29] /ip/hotspot/user/active/print <<< [14] =.proplist=.id <<< [14] ?name=myuser >>> [5/5] bytes read. >>> [5, 40]!trap >>> [31/31] bytes read. >>> [31, 8]=message=no such command prefix >>> [5/5] bytes read. >>> [5, 1]!done <<< [30] /ip/hotspot/user/active/remove <<< [5] =.id= >>> [5/5] bytes read. >>> [5, 40]!trap >>> [31/31] bytes read. >>> [31, 8]=message=no such command prefix >>> [5/5] bytes read. >>> [5, 1]!done Disconnected... .id
but still remains active, some Idea why doesn't work thanks anyway
Last edited by ecosysonidos2 on Sun Jan 20, 2013 9:30 pm, edited 1 time in total.
 
User avatar
boen_robot
Forum Guru
Forum Guru
Posts: 2400
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: [SOLVED] PHP API to disconnect a user

Sun Dec 16, 2012 11:21 pm

From the portion
[29] /ip/hotspot/user/active/print <<< [14] =.proplist=.id <<< [14] ?name=myuser >>> [5/5] bytes read. >>> [5, 40]!trap >>> [31/31] bytes read. >>> [31, 8]=message=no such command prefix
we can see the print failed, hence the removal.

What RouterOS version are you using? Try this with 5.22.
 
User avatar
Chupaka
Forum Guru
Forum Guru
Posts: 8709
Joined: Mon Jun 19, 2006 11:15 pm
Location: Minsk, Belarus
Contact:

Re: [SOLVED] PHP API to disconnect a user

Mon Dec 17, 2012 5:30 pm

as far as I can see in CLI, there's no "/ip hotspot user active print" command. but there's "/ip hotspot active print" one ;)
 
ecosysonidos2
just joined
Posts: 24
Joined: Fri Dec 07, 2012 12:10 am

Re: [SOLVED] PHP API to disconnect a user

Tue Jan 15, 2013 11:06 pm

From the portion
[29] /ip/hotspot/user/active/print <<< [14] =.proplist=.id <<< [14] ?name=myuser >>> [5/5] bytes read. >>> [5, 40]!trap >>> [31/31] bytes read. >>> [31, 8]=message=no such command prefix
we can see the print failed, hence the removal.

What RouterOS version are you using? Try this with 5.22.
Why did you tell me that the print failed?, in the result I can see the correct name from my user and user id

but I can't remove it :?

the version is v5.6 on RB493AH
 
User avatar
Chupaka
Forum Guru
Forum Guru
Posts: 8709
Joined: Mon Jun 19, 2006 11:15 pm
Location: Minsk, Belarus
Contact:

Re: [SOLVED] PHP API to disconnect a user

Wed Jan 16, 2013 12:16 pm

it's not the result, it's request :) result is "no such command prefix" trap :)
 
ecosysonidos2
just joined
Posts: 24
Joined: Fri Dec 07, 2012 12:10 am

Re: [SOLVED] PHP API to disconnect a user

Thu Jan 17, 2013 3:08 am

it's not the result, it's request :) result is "no such command prefix" trap :)
ok help me with this, when I put on mk's terminal the instruction,
/ip hotspot active print
it's gave me the list of my active users like this

Flags: R - radius, B - blocked                                                    
 #    USER            ADDRESS         UPTIME       SESSION-TIME-LEFT IDLE-TIMEOUT
 0    migue        192.168.x.x       5h51m12s            4w1d18h8m48s     
 1    kai              192.168.x.x     7h51m6s               6d16h8m54s       
 2    se12a       192.168.x.x       6h26m36s              4w1d17h33m24s    
but on this list every user has a number then I wrote this on the terminal
/ip hotspot active remove numbers=0
this in order to delete the user 0=migue

and with this I can delete the user that I want only with number of flag, I tried to delete with these instructions from php but I couldn't :shock: because with php I can't obtain the list from my active users
 
User avatar
boen_robot
Forum Guru
Forum Guru
Posts: 2400
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: [SOLVED] PHP API to disconnect a user

Thu Jan 17, 2013 2:29 pm

The PHP codes you've shown above use "/hotspot/user/active/print" or "/hotspot/user/print". Neither is correct.

Change that to "/hotspot/active/print". And the ".../remove" too.
 
User avatar
Chupaka
Forum Guru
Forum Guru
Posts: 8709
Joined: Mon Jun 19, 2006 11:15 pm
Location: Minsk, Belarus
Contact:

Re: [SOLVED] PHP API to disconnect a user

Thu Jan 17, 2013 3:37 pm

I said that exactly a month ago xD
 
ecosysonidos2
just joined
Posts: 24
Joined: Fri Dec 07, 2012 12:10 am

Re: [SOLVED] PHP API to disconnect a user

Thu Jan 17, 2013 9:06 pm

The PHP codes you've shown above use "/hotspot/user/active/print" or "/hotspot/user/print". Neither is correct.

Change that to "/hotspot/active/print". And the ".../remove" too.
I did it but It didn't work :shock: then I try to find other way from the terminal and after that prove the same syntax with php :( :o
 
User avatar
boen_robot
Forum Guru
Forum Guru
Posts: 2400
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: [SOLVED] PHP API to disconnect a user

Fri Jan 18, 2013 3:32 pm

Can you please show us ALL of your involved PHP code then? The one after these changes (the ones above are all without them).
 
User avatar
Chupaka
Forum Guru
Forum Guru
Posts: 8709
Joined: Mon Jun 19, 2006 11:15 pm
Location: Minsk, Belarus
Contact:

Re: [SOLVED] PHP API to disconnect a user

Fri Jan 18, 2013 4:58 pm

the best is the output after your changes :)
 
ecosysonidos2
just joined
Posts: 24
Joined: Fri Dec 07, 2012 12:10 am

Re: [SOLVED] PHP API to disconnect a user

Sat Jan 19, 2013 8:28 pm

Can you please show us ALL of your involved PHP code then? The one after these changes (the ones above are all without them).
this is my result
Connection attempt #1 to 192.168.x.x:xx... <<< [6] /login >>> [5/5] bytes read. >>> [5, 39]!done >>> [37/37] bytes read. >>> [37, 1]=ret=cfe976394cc6a955a584319c924dcf79 <<< [6] /login <<< [11] =name=admin <<< [44] =response=002ffcaa2c3e7a971062be5b7f4edbbda6 >>> [5/5] bytes read. >>> [5, 1]!done Connected... <<< [24] /ip/hotspot/active/print <<< [14] =.proplist=.id <<< [10] ?name=demo >>> [5/5] bytes read. >>> [5, 1]!done <<< [25] /ip/hotspot/active/remove <<< [5] =.id= >>> [5/5] bytes read. >>> [5, 1]!done Disconnected...

which are my mistakes here :shock:



whit this I can delete the user if I know de user id
first print my users
 $API->comm('/ip/hotspot/active/print);
then I know the correct id for each one an after that with this
	$API->write("/ip/hotspot/active/remove", false);
$API->write("=.id=*C0A80FF9");
$API->read();	
and It works :o 'cause delete my active user

but my idea is only give the name user with this catch the user id and after that delete
Last edited by ecosysonidos2 on Sun Jan 20, 2013 9:27 pm, edited 1 time in total.
 
User avatar
boen_robot
Forum Guru
Forum Guru
Posts: 2400
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: [SOLVED] PHP API to disconnect a user

Sun Jan 20, 2013 3:25 pm

Looking at the log, you can see there's no entries matching your query.
<<< [24] /ip/hotspot/active/print
<<< [14] =.proplist=.id
<<< [10] ?name=demo
>>> [5/5] bytes read.
>>> [5, 1]!done 
If you execute the print command from terminal, you can see there's no "name" property on active users, but only "user" instead, which also explains why your query doesn't match.

So, replace
$BRIDGEINFO = $API->comm('/ip/hotspot/active/print', array(
            ".proplist" => ".id",
            "?name" => "$var"
            )); 
with
$BRIDGEINFO = $API->comm('/ip/hotspot/active/print', array(
            ".proplist" => ".id",
            "?user" => $var
            )); 
 
ecosysonidos2
just joined
Posts: 24
Joined: Fri Dec 07, 2012 12:10 am

Re: [SOLVED] PHP API to disconnect a user

Sun Jan 20, 2013 9:19 pm

thanks it works :)
 
ecosysonidos2
just joined
Posts: 24
Joined: Fri Dec 07, 2012 12:10 am

Re: [SOLVED] PHP API to disconnect a user

Mon Jun 03, 2013 7:25 pm

as far as I can see in CLI, there's no "/ip hotspot user active print" command. but there's "/ip hotspot active print" one ;)
can you help me?
I need this, I have my wifi and my users can access with hotspot
but now I need to send the username and password to other page in my external server, how can I do it with javascript?

My idea is send them from my redirect page, just when my user has been logged correctly

my hotspot use md5.js
 
User avatar
boen_robot
Forum Guru
Forum Guru
Posts: 2400
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: [SOLVED] PHP API to disconnect a user

Mon Jun 03, 2013 9:02 pm

You can't do that with JavaScript due to the same origin policy.

The best way is to make the external server available from a subdomain of the router's domain name (e.g. portal.example.com being the external server for the login page, available from example.com). When you have that, you'll be able to read the cookie the router set, and then use the API to figure out the user this cookie is supposed to belong to (by using "/ip hotspot cookie print" with an according query).

A slightly less secure way, available when the server is within your network, is to redirect to it with its local IP. The server can then figure out if the user has logged in, and who they are, by connecting to the router with the API and looking up their IP address.
 
ecosysonidos2
just joined
Posts: 24
Joined: Fri Dec 07, 2012 12:10 am

Re: [SOLVED] PHP API to disconnect a user

Mon Jun 03, 2013 11:15 pm

You can't do that with JavaScript due to the same origin policy.

The best way is to make the external server available from a subdomain of the router's domain name (e.g. portal.example.com being the external server for the login page, available from example.com). When you have that, you'll be able to read the cookie the router set, and then use the API to figure out the user this cookie is supposed to belong to (by using "/ip hotspot cookie print" with an according query).

A slightly less secure way, available when the server is within your network, is to redirect to it with its local IP. The server can then figure out if the user has logged in, and who they are, by connecting to the router with the API and looking up their IP address.

ok :shock:
exist a hotspot with php?

I just need the information from my form1 it will be sending to my other page that I have in my server online
how can I do in order to integrate php to my hotspot in html? 'cause I can't integrate a mysql server in mikrotik my server has to be online or not?

:?
 
User avatar
boen_robot
Forum Guru
Forum Guru
Posts: 2400
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: [SOLVED] PHP API to disconnect a user

Mon Jun 03, 2013 11:30 pm

exist a hotspot with php?
No.

It sounds to me like you're misunderstanding how DNS works... a subdomain doesn't need to point to the same IP as the main domain.

Your hotspot login page can be located on the router, and let's say that it's the private IP 192.168.0.1. At the router, and the hotspot server profile in particular, you can adjust the hotspot to respond to the DNS name "example.com". You may have to also add the name and IP in "/ip dns", but still, the point is you can make it so that when users type (or are redirected to) "http://example.com", they get the login page from 192.168.0.1.

At the same time, you can have your web server, and let's say that it's at the public IP 10.10.10.1. In the "/ip dns" menu, you can add "portal.example.com" (or whatever name you like that ends with ".example.com") and make it point to that IP. That way, you're making it so that when users type (or are redirected to) "http://portal.example.com", they'll get content from 10.10.10.1.


And THAT is where it gets interesting... cookies do NOT care about the IP of the other end - they care of the domain name the other end is accessed with. So a cookie set by "example.com" is available to not only the server responding to "example.com" (i.e. the router), but they're also available to any server that responds to a domain name ending in ".example.com" (in this case, the server, responding to "portal.example.com".
my server has to be online or not?
Your server would have to always be online, yes. Just as your router. Without it, users can still login and access the internet, but they won't be able to access whatever you're trying to provide with PHP (and I'm only guessing you're making a way for them to edit their credentials and more, right?).
 
ecosysonidos2
just joined
Posts: 24
Joined: Fri Dec 07, 2012 12:10 am

Re: [SOLVED] PHP API to disconnect a user

Tue Jun 04, 2013 2:27 am

exist a hotspot with php?
No.

It sounds to me like you're misunderstanding how DNS works... a subdomain doesn't need to point to the same IP as the main domain.

Your hotspot login page can be located on the router, and let's say that it's the private IP 192.168.0.1. At the router, and the hotspot server profile in particular, you can adjust the hotspot to respond to the DNS name "example.com". You may have to also add the name and IP in "/ip dns", but still, the point is you can make it so that when users type (or are redirected to) "http://example.com", they get the login page from 192.168.0.1.

At the same time, you can have your web server, and let's say that it's at the public IP 10.10.10.1. In the "/ip dns" menu, you can add "portal.example.com" (or whatever name you like that ends with ".example.com") and make it point to that IP. That way, you're making it so that when users type (or are redirected to) "http://portal.example.com", they'll get content from 10.10.10.1.


And THAT is where it gets interesting... cookies do NOT care about the IP of the other end - they care of the domain name the other end is accessed with. So a cookie set by "example.com" is available to not only the server responding to "example.com" (i.e. the router), but they're also available to any server that responds to a domain name ending in ".example.com" (in this case, the server, responding to "portal.example.com".
my server has to be online or not?
Your server would have to always be online, yes. Just as your router. Without it, users can still login and access the internet, but they won't be able to access whatever you're trying to provide with PHP (and I'm only guessing you're making a way for them to edit their credentials and more, right?).


I think you don't understand me what I want to do or maybe I don't know to explain :? my problem is this
http://forum.mikrotik.com/viewtopic.php?f=2&t=73272

I just need only catch the username and password from the user that is logged in and send them to my page in php that I have in my online server

just that, why?, :o because I try to save the hour and date that someone is logged in and save that information in my data base are you gett it? :(
 
User avatar
boen_robot
Forum Guru
Forum Guru
Posts: 2400
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: [SOLVED] PHP API to disconnect a user

Tue Jun 04, 2013 2:10 pm

why?, :o because I try to save the hour and date that someone is logged in and save that information in my data base are you gett it? :(
You should've started with that.

There's a lot easier way to do it. At the user profile, add the following script to be executed "on-login":

ros code

/tool fetch url="http://example.com/tracker.php?user=$user"
(the variable $user is available to on-login scripts to tell you which user has just logged in)

Assuming your server is at example.com and a file dedicated to keeping track of logins is at tracker.php, in it, you can access the username there with $_GET['user']. To prevent arbitrary people from triggering this script, you may want to check $_SERVER['REMOTE_ADDR'] to ensure the IP is (one of?) your routers'.


This approach doesn't force users to go to your tracking web page, while at the same time allowing you to save them in the DB. I previously assumed you're making some kind of an editing utility, because that's pretty much the only reason (I can think of) why anyone would want to redirect users to (and show them!) a page on a server they control, while having their hotspot credentials carried.
 
ecosysonidos2
just joined
Posts: 24
Joined: Fri Dec 07, 2012 12:10 am

Re: [SOLVED] PHP API to disconnect a user

Tue Jun 04, 2013 11:26 pm

This approach doesn't force users to go to your tracking web page, while at the same time allowing you to save them in the DB. I previously assumed you're making some kind of an editing utility, because that's pretty much the only reason (I can think of) why anyone would want to redirect users to (and show them!) a page on a server they control, while having their hotspot credentials carried.
this is my idea
I have my hotspot if my users have their username and password then they can access to my wifi ok :shock:
my hostpot is in HTML and use md5 in order to logged in...
when somebody hires me my internet service I register them with php on my database with this I register how many days they want the service,

when somebody logged in if I can send the username and password to my page in my server then
I can know how many days somebody payed for the service and when their hires finish,
that's way I need to know when my users logged in hotspot...
(all of this I already did it with php and works perfectly my problem is how can integrate php to mikrotik and send my username and password)
for that I try to catch this information after they logged in just in the page redirect.html from mikrotik and send them to my external page in php in order to do everything that I want in my database

or how can I do it?, just the last way that you told me, didn't you?
but if I try to integrate php to my hotspot how can I work? if mikrotik doesn't integrate php that's way I think that I have to send my variables with ajax or something like that............... I wanna kill myself :shock:
 
User avatar
boen_robot
Forum Guru
Forum Guru
Posts: 2400
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: [SOLVED] PHP API to disconnect a user

Wed Jun 05, 2013 1:21 pm

or how can I do it?, just the last way that you told me, didn't you?
YES!!! That's the way!
but if I try to integrate php to my hotspot how can I work?
You can't. You can't install PHP, or anything else for that matter, on RouterOS.
if mikrotik doesn't integrate php that's way I think that I have to send my variables with ajax or something like that...
"/tool fetch" is exactly that "something like ajax" thing AND it doesn't leave any traces on the user's machine, which is what makes it so perfect - it's not the user telling your server "Hey, I just logged in!"; It's the router telling you server "Hey, one of my users called X just logged in!".
I wanna kill myself :shock:
You need to maintain an always on DB server anyway, with or without MikroTik supporting PHP internally, so I don't see why this makes such a huge deal.
 
ecosysonidos2
just joined
Posts: 24
Joined: Fri Dec 07, 2012 12:10 am

Re: [SOLVED] PHP API to disconnect a user

Wed Jun 05, 2013 8:00 pm

Ok, thanks for everything and your advices
I need to prove and after that I show you if I could do it, I am new with mikrotik maybe and sometimes I can understand so well thanks anyway
 
ecosysonidos2
just joined
Posts: 24
Joined: Fri Dec 07, 2012 12:10 am

Re: PHP API to disconnect a user

Mon Jun 10, 2013 4:55 am

first, you do
/ppp/active/print
=.proplist=.id
?name=something
then
/ppp/active/remove
=.id=*here_is_id_from_previous_command_result
hi can you help me with this
I need to access to my mk from web, this is my problem I am working with api class with php
when I try to connect whit mk and I am in the same range the comunication is possible and work fine
whit this
if ($API->connect("192.xx.xx.xx", "user", "pass"))
but now I have my server online and with the same line I can't to access to mikrotik how can I do it?
 
User avatar
boen_robot
Forum Guru
Forum Guru
Posts: 2400
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: [SOLVED] PHP API to disconnect a user

Mon Jun 10, 2013 11:00 am

Simply replace "192.xx.xx.xx" with your router's public IP.
 
User avatar
Chupaka
Forum Guru
Forum Guru
Posts: 8709
Joined: Mon Jun 19, 2006 11:15 pm
Location: Minsk, Belarus
Contact:

Re: [SOLVED] PHP API to disconnect a user

Mon Jun 10, 2013 5:03 pm

... and make sure that external API connections are allowed in Firewall Filter
 
ecosysonidos2
just joined
Posts: 24
Joined: Fri Dec 07, 2012 12:10 am

Re: [SOLVED] PHP API to disconnect a user

Mon Jun 10, 2013 6:38 pm

... and make sure that external API connections are allowed in Firewall Filter
Im not sure to understand you, you want to say that I have to add a rule inside Mk's firellaw, don't you?
 
User avatar
boen_robot
Forum Guru
Forum Guru
Posts: 2400
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: [SOLVED] PHP API to disconnect a user

Mon Jun 10, 2013 6:40 pm

... and make sure that external API connections are allowed in Firewall Filter
Im not sure to understand you, you want to say that I have to add a rule inside Mk's firellaw, don't you?
Not necessarily. You must NOT have a rule that denies connections to the API, either explicitly or implicitly.

If you don't have ANY filter, mangle or dst-nat rules, you have nothing to worry about.


Stop getting ahead of yourself, and just try connecting with the public IP already. We'll deal with any errors, if there are any to begin with.
 
ecosysonidos2
just joined
Posts: 24
Joined: Fri Dec 07, 2012 12:10 am

Re: [SOLVED] PHP API to disconnect a user

Mon Jun 10, 2013 7:19 pm

Simply replace "192.xx.xx.xx" with your router's public IP.
 
fadinehme
just joined
Posts: 4
Joined: Sun Jul 20, 2014 3:30 am

Re: [SOLVED] PHP API to disconnect a user

Sun Jul 20, 2014 3:47 am

can i have the code using vb.net
after some research i have found this but nothing works :(

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim mk = New mkAPI(tb_ip.Text)
If Not mk.Login(tb_user.Text, tb_pass.Text) Then
mk.Close()
tb_result.Text = "Error"
Me.Enabled = True
Exit Sub
End If
mk.Login(tb_user.Text, tb_pass.Text)
mk.Send("/ppp/active/remove/", False)
mk.Send("=.id=*8007DC0C")

End Sub

on the rb side i can see on the log page
user **** logged in from 192.168.**** via api
but no session end
any help please
 
User avatar
Chupaka
Forum Guru
Forum Guru
Posts: 8709
Joined: Mon Jun 19, 2006 11:15 pm
Location: Minsk, Belarus
Contact:

Re: [SOLVED] PHP API to disconnect a user

Mon Jul 21, 2014 10:08 am

where did you get '*8007DC0C'? it should change each time user reconnects
 
fadinehme
just joined
Posts: 4
Joined: Sun Jul 20, 2014 3:30 am

Re: [SOLVED] PHP API to disconnect a user

Mon Jul 21, 2014 1:22 pm

"*8007DC0C" this is the session id that i want it to be disconnected
i have take this id from my rb ppp/active/getall
 
User avatar
Chupaka
Forum Guru
Forum Guru
Posts: 8709
Joined: Mon Jun 19, 2006 11:15 pm
Location: Minsk, Belarus
Contact:

Re: [SOLVED] PHP API to disconnect a user

Mon Jul 21, 2014 4:41 pm

you don't wait for any response of the command (also, is '/ppp/active/remove/' a correct command? shouldn't it be '/ppp/active/remove'?), why?
 
fadinehme
just joined
Posts: 4
Joined: Sun Jul 20, 2014 3:30 am

Re: [SOLVED] PHP API to disconnect a user

Wed Jul 23, 2014 1:37 am

i have tried this

mk.Login(tb_user.Text, tb_pass.Text)
mk.Send("/ppp/active/remove", False)
mk.Send("=.id=*8007DC0C")
it did not work :(

do you have an operational example for vb.net how to disconnect a pppoe user from the rb using api?
i am searching also for changing queue limits using api nothing found :(
thank you
 
User avatar
Chupaka
Forum Guru
Forum Guru
Posts: 8709
Joined: Mon Jun 19, 2006 11:15 pm
Location: Minsk, Belarus
Contact:

Re: [SOLVED] PHP API to disconnect a user

Wed Jul 23, 2014 4:49 pm

it did not work :(
what's the response?
do you have an operational example for vb.net
nope
 
fadinehme
just joined
Posts: 4
Joined: Sun Jul 20, 2014 3:30 am

Re: [SOLVED] PHP API to disconnect a user

Wed Jul 23, 2014 5:02 pm

!trap=message=no such command
!done
 
User avatar
Chupaka
Forum Guru
Forum Guru
Posts: 8709
Joined: Mon Jun 19, 2006 11:15 pm
Location: Minsk, Belarus
Contact:

Re: [SOLVED] PHP API to disconnect a user

Wed Jul 23, 2014 11:44 pm

so, '/ppp/active/remove' seems like not valid command for some reason - recheck it...
 
Tiesto
newbie
Posts: 28
Joined: Fri Oct 14, 2011 1:18 pm
Contact:

Re: [SOLVED] PHP API to disconnect a user

Mon Jul 05, 2021 11:23 pm

You can disconnect user, from /ppp/interfaces/"username"

Who is online

Users browsing this forum: A9691 and 17 guests