Community discussions

MikroTik App
 
MBAGA
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 53
Joined: Fri Oct 03, 2014 1:07 pm

remove entry in walled garden [PHP]

Wed Nov 12, 2014 6:55 pm

I added "www.example.com" in walled garden with
$addRequest = new RouterOS\Request('/ip hotspot walled-garden add dst-host=www.example.com');
$client($addRequest);
 
now how can i remove it in php ?
Thanks
 
User avatar
boen_robot
Forum Guru
Forum Guru
Posts: 2400
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: remove entry in walled garden [PHP]

Wed Nov 12, 2014 7:51 pm

How would you remove it from CLI?

My guess is with a "find" subcommand on "remove", so...
$util = new RouterOS\Util($client);
$util
    ->setMenu('/ip hotspot walled-garden')
    ->remove(
        RouterOS\Query::where('dst-host', 'www.example.com')
    );
(this is with 1.0.0b5; Last time we talked, you used b4, where it's "changeMenu" instead of "setMenu"; I recommend that you upgrade to b5)
 
MBAGA
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 53
Joined: Fri Oct 03, 2014 1:07 pm

Re: remove entry in walled garden [PHP]

Wed Nov 12, 2014 8:15 pm

I tried this
$util = new RouterOS\Util($client);
$util
    ->changeMenu('/ip hotspot walled-garden')
    ->remove(RouterOS\Query::where('dst-host', 'www.example.com')
    );
$client($util);
but i get

Fatal error: Call to a member function remove() on string
 
User avatar
boen_robot
Forum Guru
Forum Guru
Posts: 2400
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: remove entry in walled garden [PHP]

Thu Nov 13, 2014 1:16 pm

Oh... In b4, changeMenu() returned the last menu... I forgot.

Change it to:
$util->changeMenu('/ip hotspot walled-garden');
$util->remove(RouterOS\Query::where('dst-host', 'www.example.com')); 
 
MBAGA
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 53
Joined: Fri Oct 03, 2014 1:07 pm

Re: remove entry in walled garden [PHP]

Sat Nov 15, 2014 10:30 pm

Thanks aand if i want to print entries where comment="something" ?

I tried
$printRequest = new RouterOS\Request(
'/ip hotspot walled-garden getall .proplist=dst-host',
RouterOS\Query::where('comment', 'something')
);
echo $client->sendSync($printRequest)->getArgument('dst-host');
 
but Prints only th first result

i guess i need a for / foreach , Right?
 
User avatar
boen_robot
Forum Guru
Forum Guru
Posts: 2400
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: remove entry in walled garden [PHP]

Sat Nov 15, 2014 10:45 pm

i guess i need a for / foreach , Right?
Yep.
 
MBAGA
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 53
Joined: Fri Oct 03, 2014 1:07 pm

Re: remove entry in walled garden [PHP]

Sat Nov 15, 2014 10:48 pm

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

Re: remove entry in walled garden [PHP]

Sat Nov 15, 2014 11:38 pm

Like?
Damn it! You had me so hopeful there, that you finally get the overall flow and didn't need further instructions. :D
foreach ($client->sendSync($printRequest)->getAllOfType(Routeros\Response::TYPE_DATA) as $response) {
    echo $response('dst-host');
} 
 
MBAGA
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 53
Joined: Fri Oct 03, 2014 1:07 pm

Re: remove entry in walled garden [PHP]

Sat Nov 15, 2014 11:50 pm

I'm twenty & I'm Italian : have patience :roll:

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

Re: remove entry in walled garden [PHP]

Sun Nov 16, 2014 12:02 am

I'm twenty & I'm Italian
That doesn't mean anything... Usually, older people have harder time learning, and you're younger than me (and I'm in my 20's right now), and I think I still learn stuff OK.
have patience :roll:
Oh, I have. You have no idea :lol: .
 
MBAGA
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 53
Joined: Fri Oct 03, 2014 1:07 pm

Re: remove entry in walled garden [PHP]

Sun Nov 16, 2014 12:11 am

:D yes are apologies but a month ago I did not know what mikrtik was
Oh, I have. You have no idea :lol: .
Respect! :')
 
User avatar
Stillhard
Frequent Visitor
Frequent Visitor
Posts: 82
Joined: Sun Jun 10, 2012 11:18 am
Location: Banten, Indonesia
Contact:

Re: remove entry in walled garden [PHP]

Sun Nov 16, 2014 2:40 pm

:D yes are apologies but a month ago I did not know what mikrtik was
what's mikritik? :lol:
 
MBAGA
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 53
Joined: Fri Oct 03, 2014 1:07 pm

Re: remove entry in walled garden [PHP]

Sun Nov 16, 2014 9:00 pm

indeed XD
last 2 questions (hope) :
1 ) i tried to concatenate Query parameters like e.g.
$util = new RouterOS\Util($client);
$util->changeMenu('/ip hotspot walled-garden');
$util->remove(RouterOS\Query::where('dst-host', 'something') && ('comment', 'something')); 
unsuccessfully
how you Doing?

2 ) is it possible to modify session timeout ofa hotspot user profile (php) ?
 
User avatar
boen_robot
Forum Guru
Forum Guru
Posts: 2400
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: remove entry in walled garden [PHP]

Sun Nov 16, 2014 9:44 pm

how you Doing?
What?

jk. :lol:

Yeah, creating more complicated queries is unfortunately a little more complicated currently.

The Query object (the thing that's returned from Query::where()) collects all the different conditions you want, and you can chain more by invoking either orWhere() or andWhere(), depending on whether you want the next condition to be OR-ed or AND-ed with everything up to this point.

So, in your case:
$util->remove(RouterOS\Query::where('dst-host', 'something')->andWhere('comment', 'something')); 
There's no brackets - you have to artificially arrange your conditions so that the conditions can be correctly evaluated from left to right. That's not important for your current scenario, but if you go any more complicated than two conditions, you may start seeing what looks like "anomalies", created due to this tricky part.
2 ) is it possible to modify session timeout ofa hotspot user profile (php) ?
In general, ask yourself how would you do it from a console.

I'd also recommend you get yourself a nice PHP editor like Eclipse PDT for example - it would tell you those things while you're typing the code, in the form of list of methods you can invoke, and with docs, from which point you should be able to intuitively guess which one you need.

In this case, since you're modifying, you need set(), e.g.
$util->changeMenu('/ip hotspot user profile');
$util->set(
    'default',
    array(
        'session-timeout' => '20m'
    )
); 
 
MBAGA
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 53
Joined: Fri Oct 03, 2014 1:07 pm

Re: remove entry in walled garden [PHP]

Sun Nov 16, 2014 10:00 pm

fantastic