luaopenwrtluciuci

UCI. Lua script. How to edit firewall rule


I have redirect rules for one host in my config, but sometimes I need to change the ip.

firewall.@redirect[0]=redirect
firewall.@redirect[0].name='zd_ssh'
firewall.@redirect[0].src='wan'
firewall.@redirect[0].proto='tcp'
firewall.@redirect[0].src_dport='8422'
firewall.@redirect[0].dest='lan'
firewall.@redirect[0].dest_port='22'
firewall.@redirect[0].target='DNAT'
firewall.@redirect[0].dest_ip='192.168.1.200'
firewall.@redirect[1]=redirect
firewall.@redirect[1].name='zd_https'
firewall.@redirect[1].src='wan'
firewall.@redirect[1].proto='tcp'
firewall.@redirect[1].src_dport='8443'
firewall.@redirect[1].dest='lan'
firewall.@redirect[1].dest_port='443'
firewall.@redirect[1].target='DNAT'
firewall.@redirect[1].dest_ip='192.168.1.200'

Now I am experiencing issues adding the rule in my script

uci_cursor:set("firewall", "firewall.@redirect[0]", "dest_ip", "192.168.1.200")
uci_cursor:set("firewall", "firewall.@redirect[1]", "dest_ip", "192.168.1.200")

it doesnt work. I found in openwrt wiki that "firewall" "is a type, not a section". Section should be looking like cfg02f02f

Now question is: how to find this cfg02f02f?

uci_cursor:get_all("system") doesnt show me anything.


Solution

  • Finally found solution:

    require "uci"
    x = uci.cursor()
    
    x:foreach("firewall", "redirect", function(s)
         print('------------------')
         for key, value in pairs(s) do
             print(key .. ': ' .. tostring(value))
         end
    end)