Page 1 of 1

remove entry in walled garden [PHP]

Posted: Wed Nov 12, 2014 6:55 pm
by MBAGA
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

Re: remove entry in walled garden [PHP]

Posted: Wed Nov 12, 2014 7:51 pm
by boen_robot
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)

Re: remove entry in walled garden [PHP]

Posted: Wed Nov 12, 2014 8:15 pm
by MBAGA
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

Re: remove entry in walled garden [PHP]

Posted: Thu Nov 13, 2014 1:16 pm
by boen_robot
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')); 

Re: remove entry in walled garden [PHP]

Posted: Sat Nov 15, 2014 10:30 pm
by MBAGA
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?

Re: remove entry in walled garden [PHP]

Posted: Sat Nov 15, 2014 10:45 pm
by boen_robot
i guess i need a for / foreach , Right?
Yep.

Re: remove entry in walled garden [PHP]

Posted: Sat Nov 15, 2014 10:48 pm
by MBAGA
Like?

Re: remove entry in walled garden [PHP]

Posted: Sat Nov 15, 2014 11:38 pm
by boen_robot
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');
} 

Re: remove entry in walled garden [PHP]

Posted: Sat Nov 15, 2014 11:50 pm
by MBAGA
I'm twenty & I'm Italian : have patience :roll:

Thanks!

Re: remove entry in walled garden [PHP]

Posted: Sun Nov 16, 2014 12:02 am
by boen_robot
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: .

Re: remove entry in walled garden [PHP]

Posted: Sun Nov 16, 2014 12:11 am
by MBAGA
:D yes are apologies but a month ago I did not know what mikrtik was
Oh, I have. You have no idea :lol: .
Respect! :')

Re: remove entry in walled garden [PHP]

Posted: Sun Nov 16, 2014 2:40 pm
by Stillhard
:D yes are apologies but a month ago I did not know what mikrtik was
what's mikritik? :lol:

Re: remove entry in walled garden [PHP]

Posted: Sun Nov 16, 2014 9:00 pm
by MBAGA
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) ?

Re: remove entry in walled garden [PHP]

Posted: Sun Nov 16, 2014 9:44 pm
by boen_robot
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'
    )
); 

Re: remove entry in walled garden [PHP]

Posted: Sun Nov 16, 2014 10:00 pm
by MBAGA
fantastic