Community discussions

 
myke1124
just joined
Topic Author
Posts: 18
Joined: Fri Mar 28, 2014 2:15 am

automating access list oddity

Thu May 14, 2015 5:53 pm

I created a script that adds mac address to the access list. My installers set the wireless mac to specific mac address. The AP then grabs the the radio name, which is the original mac, and adds that to the access list. This part works great. The installer will then reset the mac address and update the radio name to the customer name. The second part of the script then sets the comment in the access list to the radio name. The second part does work if I run the script from winbox or the scheduler. The script works from the terminal ( /system script run Auth ). This has been tested with RouterOS v6.? - 6.27.
/interface wireless access-list add mac-address=314159265358  interface=all comment=”AUTH”
/system scheduler add interval=5m name=AutoAuth on-event=Auth start-time=startup policy=ftp,password,policy,read,reboot,sensitive,sniff,test,write
/system script
add name=Auth policy=ftp,password,policy,read,reboot,sensitive,sniff,test,write \
  source=":if ([:len [/interface wireless registration-table find where mac-address=31:41:59:26:53:58]]=1 and [:len [/interface wireless access-list find where comment=[/interface wireless registration-table get [find mac-address=31:41:59:26:53:58] value-name=radio-name ]]] =0 ) do={/interface wireless access-list add forwarding=no interface=all mac-address=[/interface wireless registration-table get [find mac-address=31:41:59:26:53:58] value-name=radio-name ] comment=[/interface wireless registration-table get [find mac-address=31:41:59:26:53:58] value-name=radio-name ]}\r\
\n:for i from=0 to=([/interface wireless registration-table print count-only ] -1 ) do={:if ([/interface wireless registration-table get \$i value-name=comment] != [/interface wireless registration-table get \$i value-name=radio-name ] and [/interface wireless registration-table get \$i value-name=mac-address] != \"31:41:59:26:53:58\"  ) do={/interface wireless access-list set [find mac-address=[/interface wireless registration-table get \$i value-name=mac-address ]] comment=[/interface wireless registration-table get \$i value-name=radio-name  ] }}"
 
psamsig
Member Candidate
Member Candidate
Posts: 161
Joined: Sun Dec 06, 2009 1:36 pm
Location: Denmark

Re: automating access list oddity

Thu May 14, 2015 7:27 pm

I am pretty sure the problem lies with the :for i from=0 to=( go with :foreach i in= instead. Item indexing in script/scheduler works different than in console.

Not sure what the script tries to accomplish, but here is my shot on a slightly more readable version:
/interface wireless registration-table {
    :local idxRadioMacAddress [find mac-address=31:41:59:26:53:58]
    :if ([:len $idxRadioMacAddress] = 1) do={
        :local radioName [get $idxRadioMacAddress radio-name]
        /interface wireless access-list {
            :if ([:len [find where comment=$radioName]] = 0) do={
                add forwarding=no interface=all mac-address=$radioName comment=$radioName
            }
        }
    }
    :foreach i in=[find] do={
        :local macAddress [get $i mac-address]
        :if ([get $i comment] != [get $i radio-name] and $macAddress != "31:41:59:26:53:58") do={
            /interface wireless access-list {
                set [find mac-address=$macAddress] comment=[get $i radio-name] 
        }
    }
}
 
myke1124
just joined
Topic Author
Posts: 18
Joined: Fri Mar 28, 2014 2:15 am

Re: automating access list oddity

Thu May 14, 2015 7:54 pm

Thanks. Changing the for loop to foreach fixed the issue.

Who is online

Users browsing this forum: No registered users and 15 guests