UCI Config and exports CSV, PDF, others

Hi there, is there any tool or any hack to export a part or the full config of a OpenWRT/LEDE BOX to a flat .CSV file ?

It will be great and usefull to have the hostnames, dhcps, networks, firewalls, being usable externally and also synchronized to a enduser usable access.

Hope this is not a bad request, and sure if this tool do not exist it will be a great stuff to have.

Look at "uci export" and "uci show" commands in wiki.
There are also other useful examples that you can utilise
https://wiki.openwrt.org/doc/uci#export_an_entire_configuration

But you need to handle all config files / packages, and note that you can't reuse quite all settings, as some values like MACs are device-specific

Thanks hnyman, great to know the export full or part command line.
But no way to get it as a .CSV, or .PDF format, like for adding into a documentation or to create images ?

It is plain text output
just output to a file
uci export > /tmp/uci_export.txt
then use a text to pdf conveter after you copy it to your pc ( or just cut and paste)
You could also just use your favourite word-processor and save as pdf

Thanks mbo2o, again I have to explain that I may have being incomplete in my first question.

I have seing the export in text file, but I want to reformat into a external way.
Like a csv, format where columns and rows are all in one topic way.

The UCI format is a one line way format.
Topic, parameter(s)...
Topic.subtopic, parameter(s)

I search a manner to get all in this format; columns titles, then lines of parameters...
Topic, subtopic, subtopic2...
parameter(s) of topic, parameter(s) of subtopic, ...

Then anyone can get the UCI from config files to a calc (csv) way, and then reformat it in image(s), and publish it (pdf)...

I am in search of a tool that can make a visualisation of the parameters, for documentations, tutorials, or magazine articles, of the UCI configs.

Hope I explain better my need, but thanks to get in the topic, anyway... :wink:

Can you make a quick mock example of the CSV output you would like to see? I am sure the uci values can be easily formatted in your desired target format with a little bit of Lua or shell scripting.

1 Like

Ok, PDF probably isn't a good description of what you need.
You might have to write your own script to do conversion into tabulated data.

If you look at the export data format it is well structured so that would be easiest to work with.

1 Like

This is a small piece from the flat format (UCI)
dhcp.@host[0]=host
dhcp.@host[0].name='BREL'
dhcp.@host[0].dns='1'
dhcp.@host[0].mac='00:04:20:17:D9:FA'
dhcp.@host[0].ip='10.3.2.101'
dhcp.@host[1]=host
dhcp.@host[1].name='BRASSENS'
dhcp.@host[1].dns='1'
dhcp.@host[1].mac='00:04:20:1B:B0:A9'
dhcp.@host[1].ip='10.3.2.104'

with the hoped tables format needed :

dhcp.@host[#] dhcp.@host[#].name dhcp.@host[#].dns dhcp.@host[#].mac dhcp.@host[#].ip
host BREL 1 00:04:20:17:D9:FA 10.3.2.101
host BRASSENS 1 00:04:20:1B:B0:A9 10.3.2.104

Yes, it's what I need.

I have seen export and show, but I do not know how to do a such script.

UCI is a tree format with hashes and arrays, and it doesn't lend itself well to CSV. For instance, how does these keys fit into your example?
dhcp.lan=dhcp
dhcp.lan.interface='lan'
dhcp.wan.ignore='1'

I think you would need hundreds of columns, and most rows would only contain one or a few values, or the data in the rows would not be connected. It would not be a good way to explain them.

like this;
dhcp.lan;dhcp.lan.interface;dhcp.wan.ignore
dhcp;'lan';'1'

dhcp.lan dhcp.lan.interface dhcp.wan.ignore
dhcp 'lan' '1'

Not if all the same types is grouped by number, like, for dhcp, where a value [##] is grouped into the same colums, then the rows takes the each values of the options

dhcp.@host[0] dhcp.@host[0].name dhcp.@host[0].dns dhcp.@host[0].mac dhcp.@host[0].ip
dhcp.@host[1] dhcp.@host[1].name dhcp.@host[1].dns dhcp.@host[1].mac dhcp.@host[1].ip
dhcp.@host[2] dhcp.@host[2].name dhcp.@host[2].dns dhcp.@host[2].mac dhcp.@host[2].ip
dhcp.@host[3] dhcp.@host[3].name dhcp.@host[3].dns dhcp.@host[3].mac dhcp.@host[3].ip

There is a particularly large number of array based values in dhcp, so it gives a false impression of how useful your system is. Arrays aren't used at all in for instance Adblock, so you will just get a header line and a single data line with 164 columns. Making a special case for arrays is also a bit of a hack, and the code for encoding and decoding it wouldn't be very nice. I actually thought about writing it just to prove my point, but it's too messy and not very useful. Sorry.

While CSV is a common interchange format for spreadsheets, I don't know that it can represent hierarchical data in a reasonable way. As @per has noted, there are very few flat "arrays" in a typical configuration. Pretty much everything is going to require its own "special" table, making readability and parsability poor, in my opinion.

If you're looking for a good way to communicate the configuration, the configuration files themselves are well suited for that, especially as that is what drives the run-time configuration.

If you're looking for an interchange format to convert between various renderings, something that represents hierarchical data would be much more appropriate than CSV. JSON is one example of such a format, as would be XML.

You'are both right, but what I need in the first is only the DHCP and hosts lists, like in the luci web app, but in a printable way...
Because the luci web app do not show the all information in a browser, and because they are not copy/pastable...

This may be of interest to you

You may export to json and then convert with jshn/jsonfilter tools. Export to JSON can be made via ubus call to uci service e.g. to get all zones from /etc/config/firewall:

# ubus call uci get '{"config":"firewall","type":"zone"}'
{
	"values": {
		"cfg02dc81": {
			".anonymous": true,
			".type": "zone",
			".name": "cfg02dc81",
			".index": 1,
			"name": "lan",
			"network": [
				"lan"
			],
			"input": "ACCEPT",
			"output": "ACCEPT",
			"forward": "ACCEPT"
		},
		"cfg03dc81": {
			".anonymous": true,
			".type": "zone",
			".name": "cfg03dc81",
			".index": 2,
			"name": "wan",
			"network": [
				"wan",
				"wan6",
				"pppoe"
			],
			"input": "REJECT",
			"output": "ACCEPT",
			"forward": "REJECT",
			"masq": "1",
			"mtu_fix": "1"
		}
	}
}