Community discussions

 
begreat
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 85
Joined: Sun Mar 01, 2009 1:35 am
Location: Lajes do Pico, Azores - Portugal
Contact:

Centralize Mikrotik Scripts

Wed Jan 29, 2014 1:54 am

Hi, i have 5 Hotspots right now, and i'm planning on installing about 45 more during this year.

I have Walled Garden Pages and IP Bindings that i really need to have centralized.

Is there any possibility to have all sincronized between all the hotspot devices?

It can be a .rsc file to be stored in a ftp server and then downloaded by all the hotspot devices.

The initial idea would be to use my central's hotspot to program the Walled Garden and the IP Bindings, and have it exporting the .rsc file, and then have all the other hotspots downloading and executing the .rsc file.

If the export wouldn't be possible, i can have the .rsc file stored in the ftp server and edit it manually, and have all the hotspots downloading and executing the .rsc file.
Don't be good, begreat :P
Paulo Brinca
http://www.picomatica.com/
 
efaden
Forum Guru
Forum Guru
Posts: 1711
Joined: Sat Mar 30, 2013 1:55 am
Location: New York, USA

Re: Centralize Mikrotik Scripts

Wed Jan 29, 2014 4:17 am

Hi, i have 5 Hotspots right now, and i'm planning on installing about 45 more during this year.

I have Walled Garden Pages and IP Bindings that i really need to have centralized.

Is there any possibility to have all sincronized between all the hotspot devices?

It can be a .rsc file to be stored in a ftp server and then downloaded by all the hotspot devices.

The initial idea would be to use my central's hotspot to program the Walled Garden and the IP Bindings, and have it exporting the .rsc file, and then have all the other hotspots downloading and executing the .rsc file.

If the export wouldn't be possible, i can have the .rsc file stored in the ftp server and edit it manually, and have all the hotspots downloading and executing the .rsc file.
You really could do either. It just depends. You could even have a linux box download it... process it with perl and re-upload it. I did some custom scripting a while back to move static DNS entries from one box to another.

-Eric
 
begreat
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 85
Joined: Sun Mar 01, 2009 1:35 am
Location: Lajes do Pico, Azores - Portugal
Contact:

Re: Centralize Mikrotik Scripts

Wed Jan 29, 2014 5:19 am

That is awsome news.

Are you willing to share a working script so i could accomplish that task, i would really appreciate it.

I've been trying to import, export and download files using mikrotik script's, but i'm not getting the job done.

I belive that it would be easier to have a central manual file that i can edit, and then the devices can get that file a run the script to apply the changes.

But it would be really awsome to get my central system to export the necessary content and upload it to my ftp server, and the procede with the rest of the process.

Best regards,
Paulo Brinca.
Don't be good, begreat :P
Paulo Brinca
http://www.picomatica.com/
 
User avatar
aacable
Member
Member
Posts: 422
Joined: Wed Sep 17, 2008 11:58 am
Location: ISLAMIC Republic of PAKISTAN
Contact:

Re: Centralize Mikrotik Scripts

Wed Jan 29, 2014 11:11 am

You can make a script for this purpose and schedule it to all of your routers to run it daily at specific timings. via this script, all routers will pull the walled garden list from central FTP server (you can update it as you required) and then it will remove old entries, and update new one according to newly downloaded list.

Is this what you want ?
_____________
Regard's

Syed Jahanzaib
Web: http://aacable.wordpress.com
Email: aacable [at] hotmail.com
 
efaden
Forum Guru
Forum Guru
Posts: 1711
Joined: Sat Mar 30, 2013 1:55 am
Location: New York, USA

Re: Centralize Mikrotik Scripts

Wed Jan 29, 2014 3:29 pm

That is awsome news.

Are you willing to share a working script so i could accomplish that task, i would really appreciate it.

I've been trying to import, export and download files using mikrotik script's, but i'm not getting the job done.

I belive that it would be easier to have a central manual file that i can edit, and then the devices can get that file a run the script to apply the changes.

But it would be really awsome to get my central system to export the necessary content and upload it to my ftp server, and the procede with the rest of the process.

Best regards,
Paulo Brinca.
My script doesn't do what you want. It is specific for my task.

Sent from my SCH-I545 using Tapatalk
 
User avatar
aacable
Member
Member
Posts: 422
Joined: Wed Sep 17, 2008 11:58 am
Location: ISLAMIC Republic of PAKISTAN
Contact:

Re: Centralize Mikrotik Scripts

Thu Jan 30, 2014 8:08 am

That is awsome news.
Are you willing to share a working script so i could accomplish that task, i would really appreciate it.
I've been trying to import, export and download files using mikrotik script's, but i'm not getting the job done. I belive that it would be easier to have a central manual file that i can edit, and then the devices can get that file a run the script to apply the changes. But it would be really awesome to get my central system to export the necessary content and upload it to my ftp server, and the procede with the rest of the process. Best regards, Paulo Brinca.
Try this:
Create a file name data.txt, add entries you want something like this.
data.txt example contents ...
aacable.wordpress.com
yahoo.com
google.com
cnn.com
bbc.com
Make sure you don't add any space at the end of the line or any empty line.
Upload this data.txt to your central FTP server files section.

Now create a script on all your hotspot routers, the script will fetch a file name data.txt from your central FTP server and will parse it and add entries to your hotspot walled garden ip list. You can schedule the script to run on Daily basis.

Tested with ROS 5.20
# January 3rd, 2014
# Script Started .... Syed Jahanzaib / aacable @ hotmail . com

# Printing local time for Log purposes ...
:local CurrentTime [/system clock get time];
:log warning "Script Start to Update HOTSPOT WALLED ip garden at Current Time = $CurrentTime. . ."

# Downloading / Fetching the Walled Garden List from centgral FTP Server ...
/tool fetch url=http://yourdomain.com/files/data.txt

# Removing any Previous Entries to avoid duplication , using comments detection ...
:foreach entry in=[/ip hotspot walled-garden ip find comment=allowed-walled-garden-domains] do={
/ip hotspot walled-garden ip remove $entry
}
:if ( [/file get [/file find name=data.txt] size] > 0 ) do={

# Parsing data.txt for URLS to be added later in HS Walled Garden     
   :global content [/file get [/file find name=data.txt] contents] ;
   :global contentLen [ :len $content ] ; 
   :global lineEnd 0;
   :global line "";
   :global lastEnd 0;   
   :do {
         :set lineEnd [:find $content "\n" $lastEnd ] ;
         :set line [:pick $content $lastEnd $lineEnd] ;
         :set lastEnd ( $lineEnd + 1 ) ;   

# ignore lines which have hash sign in start of line , comment out.
         :if ( [:pick $line 0 1] != "#" ) do={   
        :local entry [:pick $line 0 ($lineEnd -1) ]
        :if ( [:len $entry ] > 0 ) do={

# Adding Entries in Walled Garden IP list from the parsed data
/ip hotspot walled-garden ip add action=accept disabled=no dst-host="$entry" comment=allowed-walled-garden-domains;
        }
      }
   } while ($lineEnd < $contentLen)
   }

:log warning "Script Completed ... at Current Time = $CurrentTime . . .  Jz"
# Script Completed ....
Last edited by aacable on Mon Feb 03, 2014 6:05 am, edited 2 times in total.
_____________
Regard's

Syed Jahanzaib
Web: http://aacable.wordpress.com
Email: aacable [at] hotmail.com
 
begreat
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 85
Joined: Sun Mar 01, 2009 1:35 am
Location: Lajes do Pico, Azores - Portugal
Contact:

Re: Centralize Mikrotik Scripts

Sat Feb 01, 2014 5:39 am

Thanks @aacable i'll test the script during this weekend and post the results.

Best regards,
Paulo Brinca.
Don't be good, begreat :P
Paulo Brinca
http://www.picomatica.com/
 
begreat
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 85
Joined: Sun Mar 01, 2009 1:35 am
Location: Lajes do Pico, Azores - Portugal
Contact:

Re: Centralize Mikrotik Scripts

Sat Feb 01, 2014 7:36 am

So, i've managed to get your script running, but with a few gliches.

With your script i need to have 1 "dummy" line above the first url and 1 "dummy" line bellow the last url on the .txt file, like this:
# DUMMY LINE
site1.com
site2.com
site3.com
site4.com
site5.com
# DUMMY LINE
If i don't place the "dummy" lines mentioned the urls won't be imported correctly:
  • If i don't place the "dummy" line above the url list, the last letter of the url will be ignored (url "site1.com" will be added as "site1.co");
  • If i don't place the "dummy" line bellow the url list, the last url line will be ignored (url "site5.com" will not be added).
Tested on multiple devices with OS v6.1, 6.2 and 6.3 (X86 and RouterBoard devices).

It's almost there, any help is welcome :) .

Best regards,
Paulo Brinca.
Don't be good, begreat :P
Paulo Brinca
http://www.picomatica.com/
 
User avatar
aacable
Member
Member
Posts: 422
Joined: Wed Sep 17, 2008 11:58 am
Location: ISLAMIC Republic of PAKISTAN
Contact:

Re: Centralize Mikrotik Scripts

Mon Feb 03, 2014 5:54 am

Make sure not to add any empty space or empty line. simple flat entries with no spaces.
I have tested with 5.20 several times, and working gr8.
[update: even i tested with empty spaces and it worked fine]
_____________
Regard's

Syed Jahanzaib
Web: http://aacable.wordpress.com
Email: aacable [at] hotmail.com
 
begreat
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 85
Joined: Sun Mar 01, 2009 1:35 am
Location: Lajes do Pico, Azores - Portugal
Contact:

Re: Centralize Mikrotik Scripts

Mon Feb 03, 2014 7:46 pm

The script is woorking perfectly as i stated before.

It may be a problem with RouterOS V6.x, as i tested it out in a couple of devices with different RouterOS V6 versions and in all of them i had to add the 2 mentioned lines.

I don't have any V5.x devices i can test on, but i would like to know if any other user has the chance to try it out.

As i said in the beggining, your script is already up and runnig, and it's wonderfull, does the job as i need, and i can even use it for many other applications, like IP Binding, and many more :)

Best regards,
Paulo Brinca.
Don't be good, begreat :P
Paulo Brinca
http://www.picomatica.com/
 
Gladiator2014
just joined
Posts: 1
Joined: Sat Feb 21, 2015 8:52 pm

Re: Centralize Mikrotik Scripts

Sat Feb 21, 2015 9:37 pm

Hi,
i have a problem whith script.
I have router os v 6.27 and when launching the script goes in loop generating ever more rows of walled garden.
how can I avoid this loop?
 
ggermes
just joined
Posts: 4
Joined: Thu Jan 12, 2012 5:29 am

Re: Centralize Mikrotik Scripts

Thu Nov 26, 2015 1:03 am

havign same problem, do you get to solve the loop problem?

or anyone now why is not working on latest version of routeros?

thanks in advance!
Hi,
i have a problem whith script.
I have router os v 6.27 and when launching the script goes in loop generating ever more rows of walled garden.
how can I avoid this loop?
 
noib
Member Candidate
Member Candidate
Posts: 285
Joined: Fri Jan 25, 2013 6:04 pm
Location: France
Contact:

Re: Centralize Mikrotik Scripts

Thu Nov 26, 2015 10:58 am

You can also use API to connect to your 50 hotspots and push configurations.. this is how i update my walled garden. PHP + API + loop = win !
 
cicserver
Member
Member
Posts: 300
Joined: Sun Jul 24, 2011 12:04 pm

Re: Centralize Mikrotik Scripts

Fri Nov 27, 2015 7:58 am

any solution for lopp issue? i am using this script and its working perfect in 5.x version, but with version 6.33 its LOOPING and keep adding same hosts again n again until i stop it :(

Who is online

Users browsing this forum: No registered users and 64 guests