Community discussions

MikroTik App
 
gacopl
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 63
Joined: Sun Jul 29, 2007 5:11 pm
Location: Poland

PPPoE interface up and down scripts

Wed Oct 24, 2007 7:01 pm

Hello

Got one problem:

Is there any way to trigger a defined script when pppoe connection starts and pppoe connection ends?
Because i need that for some advanced QOS, which in order to do it i have to operate mangle rules, since people get dynamic addresses all i can do is to match rules against pppoe interfaces but when pppoe interface goes down the rule becomes invalid :/

If could use some kind of trigger i would create and remove rules dynamically when connection starts and ends.
I use radius authentication.
Router OS 2.9

Thanks in advance
Michal
 
gacopl
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 63
Joined: Sun Jul 29, 2007 5:11 pm
Location: Poland

Re: PPPoE interface up and down scripts

Fri Oct 26, 2007 10:40 am

Hello

Like i thought i couldn't count on noone so i Made a script myself. it is tested. And it's unexpectedsystemrebootproof.
So there shouldn't be any problem with it ( itested it for 2 days).

Hope someone could have use of it

1. Code of main program that triggers subprograms pppup pppdown:
:foreach i in $pppup do {#here you put a command that will be triggered when mikrotik shutdowns unexpectedly - for egz. clean up some firewall rules;};:set pppup       ;:set pppdown;:local x 1; :do {/system script run pppdown; :delay 2s;/system script run pppup;} while ($x = 1);:set x;


2. Code of pppup:
:foreach i in=[/ppp active find service=pppoe] do={:local exclude [:pick [/ppp active get $i name] 0 ([:len[/ppp active get $i name]]-14)];:put $exclude; :if ([:find [:toarray $pppup] $exclude] >= 0) do={:put "its there already"} else={:put added;:#here you place commands that will be triggered when ppp connection starts);:global pppup ([:toarray $pppup] . $exclude);}};
3. Code of pppdown
:global pppdown $pppup; :foreach i in=[/ppp active find service=pppoe] do={:local exclude [/ppp active get $i name];:if ([:find [:toarray $pppup] $exclude] >= 0) do={ :global pppdown ([:pick [:toarray $pppdown] 0 ([:find [:toarray $pppdown] $exclude])] . [:pick [:toarray $pppdown] ([:find [:toarray $pppdown] $exclude]+1) [:len [:toarray $pppdown]]] ); }};:foreach i in=$pppdown do={:global pppup ([:pick [:toarray $pppup] 0 ([:find [:toarray $pppup] $i])] . [:pick [:toarray $pppup] ([:find [:toarray $pppup] $i]+1) [:len [:toarray $pppup]]] );#HERE you put commands you want to trigger when ppp connection goes down]};
The script takes out name from active connections so you can use it in creating commands, you can also take some other info like ip. But it's up to you.

Hopefully someone will find it usefull.
This was tested with 2.9

Best Regards
Michal
 
User avatar
111111
Member Candidate
Member Candidate
Posts: 195
Joined: Thu Oct 05, 2006 1:39 am
Location: BG,SOFIA

Re: PPPoE interface up and down scripts

Mon Jul 28, 2014 5:14 pm

Is any one test this on latest versions 5.x or 6.x,
idea is to put upnp rule with interface when private addresses used.

Who is online

Users browsing this forum: No registered users and 18 guests