OpenWrt Forum Archive

Topic: How to interface list type in UCI with LuCi

The content of this topic has been archived on 31 Mar 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

Hello,

I'm making an interface for "NoDogSplash" (https://github.com/nodogsplash/nodogsplash) and I'm stuck with the "list" type of UCI. For example there is a section in /etc/config/nodogsplash:

  list authenticated_users 'allow tcp port 22'
  list authenticated_users 'allow tcp port 53'
  list authenticated_users 'allow udp port 53'
  list authenticated_users 'allow tcp port 80'
  list authenticated_users 'allow tcp port 443'

I want to create a table in the UI to be able to add/remove entries and change the values (allow/block, tcp/udp, port number)
Also, when I change from "allow" to "block" I want to change some fields in the table because the "block" syntax is a bit different. Example:

  list authenticated_users 'block to 192.168.0.0/16'
  list authenticated_users 'block to 10.0.0.0/8'

I'm more concerned about the first question, as I can not find any documentation apart from the "get_list" command.
Thank you.

the problem is that the config file is not in conventional uci format.  If you format the "/etc/config/nodogsplash" file correctly you can use the uci.lua model. I have provided the config file in proper format ( i get it off the net so I am not sure if it is current ??) and a fully working code snippet the demonstrate


-- /usr/lib/lua/luci/model/uci_list_demo.lua
--[[ uci_list example ]]--

local uci = require "luci.model.uci"
local _uci_real, _uci_state


local function print_uci_list(config, section, option)
  _uci_real  = uci.cursor()
  _uci_state = _uci_real:substate()
  local tbl = {}
  tbl = _uci_real:get_list(config, section, option)
  print("\nsize of "..option.." ["..section.."] ".."list: "..#tbl)
  for i,v in pairs(tbl) do
   print(i,v)
  end
 return
end

print_uci_list("nodogsplash", "block", "authenticated_users")
print_uci_list("nodogsplash", "allow", "authenticated_users")
print_uci_list("nodogsplash", "allow", "preauthenticated_users")
print_uci_list("nodogsplash", "allow", "users_to_router")

and the config in the proper format ...

"/etc/config/nodogsplash"

config instance
  # Set to 1 to enable nodogsplash
  option enabled 1

  # Use plain configuration file as well
  option config '/etc/nodogsplash/nodogsplash.conf'
  option network 'wlan'
  option gatewayname 'OpenWrt Nodogsplash'
  option maxclients '250'
  option idletimeout '1200'

  # Your router may have several interfaces, and you
  # probably want to keep them private from the network/gatewayinterface.
  # If so, you should block the entire subnets on those interfaces, e.g.:
config users_to_router 'block'
  list authenticated_users 'block to 192.168.0.0/16'
  list authenticated_users 'block to 10.0.0.0/8'

  # Typical ports you will probably want to open up.
config users_to_router 'allow'
  list authenticated_users 'allow tcp port 22'
  list authenticated_users 'allow tcp port 53'
  list authenticated_users 'allow udp port 53'
  list authenticated_users 'allow tcp port 80'
  list authenticated_users 'allow tcp port 443'

  # For preauthenticated users to resolve IP addresses in their
  # initial request not using the router itself as a DNS server,
config list preauthenticated_users 'allow'
  list preauthenticated_users 'allow tcp port 53'
  list preauthenticated_users 'allow udp port 53'

  # Allow ports for SSH/Telnet/DNS/DHCP/HTTP/HTTPS
config users_to_router 'allow'
  list users_to_router 'allow tcp port 22'
  list users_to_router 'allow tcp port 23'
  list users_to_router 'allow tcp port 53'
  list users_to_router 'allow udp port 53'
  list users_to_router 'allow udp port 67'
  list users_to_router 'allow tcp port 80'
  list users_to_router 'allow tcp port 443'

  # See https://github.com/nodogsplash for a full list of available options.

if you save the code snippet from above to "/usr/lib/lua/luci/mode/uci_list_demo.lua" and update you config file with the one above or just add the sections as i did above ("config <section>) then you can execute it from cmd line like ...

lua /usr/lib/lua/luci/model/uci_list_demo.lua

that should give you the idea wink

(Last edited by hostle19 on 10 Jan 2016, 01:06)

Are you still interested in completing this project ? I would be willing to help out with the interface if you are ...

Nah. I ended the project. I don't remember if I solved the problem or if I worked around it.

The discussion might have continued from here.