Luci uses uhttpd to interpret cgi-bin requests made over http. The option cgi_prefix '/cgi-bin' setting in /etc/config/uhttpd defines the file location for the luci interpretation script.
The /www/cgi-bin/luci script is as follows:
#!/usr/bin/env ucode
'use strict';
import { stdin, stdout } from 'fs';
import dispatch from 'luci.dispatcher';
import request from 'luci.http';
const input_bufsize = 4096;
let input_available = +getenv('CONTENT_LENGTH') || 0;
function read(len) {
if (input_available == 0) {
stdin.close();
return null;
}
let chunk = stdin.read(min(input_available, len ?? input_bufsize, input_bufsize));
if (chunk == null) {
input_available = 0;
stdin.close();
}
else {
input_available -= length(chunk);
}
return chunk;
}
function write(data) {
return stdout.write(data);
}
let req = request(getenv(), read, write);
dispatch(req);
req.close();
Example http request:
GET /cgi-bin/luci/admin/menu?1709065406341 HTTP/1.1
Host: ip
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.5735.134 Safari/537.36
Accept: */*
Referer: http://ip/cgi-bin/luci/
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.9
Cookie: sysauth_http=2ab91d1f2672560abcdef0692ebexxxx
Connection: close
Example http response:
HTTP/1.1 200 OK
Connection: close
content-type: application/json; charset=UTF-8
cache-control: no-cache
expires: 0
x-frame-options: SAMEORIGIN
x-xss-protection: 1; mode=block
x-content-type-options: nosniff
Content-Length: 24047
{
"action": {
"type": "firstchild"
},
"children": {
"admin": {
"satisfied": true,
"children": {
"network": {
"satisfied": true,
"children": {
"firewall": {
"satisfied": true,
"action": {
"type": "alias",
"path": "admin/network/firewall/zones"
},
"depends": {
"acl": [
"luci-app-firewall"
],
"fs": {
"/sbin/fw3": "executable"
},
"uci": {
"firewall": true
}
},
"order": 60,
"title": "Firewall",
"children": {
"zones": {
"satisfied": true,
"action": {
"type": "view",
"path": "firewall/zones"
},
"order": 10,
"title": "General Settings"
},
"forwards": {
"satisfied": true,
"action": {
"type": "view",
"path": "firewall/forwards"
},
"order": 20,
"title": "Port Forwards"
},
"rules": {
"satisfied": true,
"action": {
"type": "view",
"path": "firewall/rules"
},
"order": 30,
"title": "Traffic Rules"
},
"snats": {
"satisfied": true,
"action": {
"type": "view",
"path": "firewall/snats"
},
"order": 40,
"title": "NAT Rules"
},
"ipsets": {
"satisfied": true,
"action": {
"type": "view",
"path": "firewall/ipsets"
},
"order": 45,
"title": "IP Sets"
},
"custom": {
"satisfied": false,
"action": {
"type": "view",
"path": "firewall/custom"
},
"depends": {
"fs": {
"/usr/share/fw3/helpers.conf": "file"
}
},
"order": 50,
"title": "Custom Rules"
}
}
},
"switch": {
"satisfied": false,
"action": {
"type": "view",
"path": "network/switch"
},
"depends": {
"acl": [
"luci-mod-network-config"
],
"fs": {
"/sbin/swconfig": "executable"
},
"uci": {
"network": {
"@switch": true
}
}
},
"order": 20,
"title": "Switch"
},
"wireless": {
"satisfied": false,
"action": {
"type": "view",
"path": "network/wireless"
},
"depends": {
"acl": [
"luci-mod-network-config"
],
"uci": {
"wireless": {
"@wifi-device": true
}
}
},
"order": 15,
"title": "Wireless"
},
"remote_addr": {
"satisfied": true,
"wildcard": true,
"action": {
"type": "call",
"module": "luci.controller.admin.network",
"function": "remote_addr"
}
},
"network": {
"satisfied": true,
"action": {
"type": "view",
"path": "network/interfaces"
},
"depends": {
"acl": [
"luci-mod-network-config"
]
},
"order": 10,
"title": "Interfaces"
},
"routes": {
"satisfied": true,
"action": {
"type": "view",
"path": "network/routes"
},
"depends": {
"acl": [
"luci-mod-network-config"
]
},
"order": 30,
"title": "Routing"
},
"dhcp": {
"satisfied": true,
"action": {
"type": "view",
"path": "network/dhcp"
},
"depends": {
"acl": [
"luci-mod-network-dhcp"
],
"fs": {
"/usr/sbin/dnsmasq": "executable"
},
"uci": {
"dhcp": true
}
},
"order": 40,
"title": "DHCP and DNS"
},
"diagnostics": {
"satisfied": true,
"action": {
"type": "view",
"path": "network/diagnostics"
},
"depends": {
"acl": [
"luci-mod-network-diagnostics"
]
},
"order": 50,
"title": "Diagnostics",
"readonly": true
}
},
"action": {
"type": "firstchild",
"recurse": true
},
"order": 50,
"title": "Network"
},
"system": {
"satisfied": true,
"children": {
"opkg": {
"satisfied": true,
"action": {
"type": "view",
"path": "opkg"
},
"depends": {
"acl": [
"luci-app-opkg"
]
},
"order": 30,
"title": "Software"
},
"system": {
"satisfied": true,
"action": {
"type": "view",
"path": "system/system"
},
"depends": {
"acl": [
"luci-mod-system-config"
]
},
"order": 1,
"title": "System"
},
"admin": {
"satisfied": true,
"action": {
"type": "firstchild"
},
"depends": {
"acl": [
"luci-mod-system-config",
"luci-mod-system-ssh"
]
},
"order": 2,
"title": "Administration",
"children": {
"password": {
"satisfied": true,
"action": {
"type": "view",
"path": "system/password"
},
"depends": {
"acl": [
"luci-mod-system-config"
]
},
"order": 1,
"title": "Router Password"
},
"dropbear": {
"satisfied": true,
"action": {
"type": "view",
"path": "system/dropbear"
},
"depends": {
"acl": [
"luci-mod-system-ssh"
],
"fs": {
"/usr/sbin/dropbear": "executable"
}
},
"order": 2,
"title": "SSH Access"
},
"sshkeys": {
"satisfied": true,
"action": {
"type": "view",
"path": "system/sshkeys"
},
"depends": {
"acl": [
"luci-mod-system-ssh"
],
"fs": {
"/usr/sbin/dropbear": "executable"
}
},
"order": 3,
"title": "SSH-Keys"
},
"uhttpd": {
"satisfied": true,
"action": {
"type": "view",
"path": "system/uhttpd"
},
"depends": {
"acl": [
"luci-mod-system-uhttpd"
],
"fs": {
"/usr/sbin/uhttpd": "executable"
}
},
"order": 4,
"title": "HTTP(S) Access"
}
}
},
"startup": {
"satisfied": true,
"action": {
"type": "view",
"path": "system/startup"
},
"depends": {
"acl": [
"luci-mod-system-init"
]
},
"order": 45,
"title": "Startup"
},
"crontab": {
"satisfied": true,
"action": {
"type": "view",
"path": "system/crontab"
},
"depends": {
"acl": [
"luci-mod-system-cron"
]
},
"order": 46,
"title": "Scheduled Tasks"
},
"mounts": {
"satisfied": true,
"action": {
"type": "view",
"path": "system/mounts"
},
"depends": {
"acl": [
"luci-mod-system-mounts"
],
"fs": {
"/sbin/block": "executable"
}
},
"order": 50,
"title": "Mount Points"
},
"leds": {
"satisfied": false,
"action": {
"type": "view",
"path": "system/leds"
},
"depends": {
"acl": [
"luci-mod-system-config"
],
"fs": {
"/sys/class/leds": "directory"
}
},
"order": 60,
"title": "LED Configuration"
},
"flash": {
"satisfied": true,
"action": {
"type": "view",
"path": "system/flash"
},
"depends": {
"acl": [
"luci-mod-system-flash"
]
},
"order": 70,
"title": "Backup / Flash Firmware"
},
"reboot": {
"satisfied": true,
"action": {
"type": "view",
"path": "system/reboot"
},
"depends": {
"acl": [
"luci-mod-system-reboot"
]
},
"order": 90,
"title": "Reboot"
}
},
"action": {
"type": "firstchild",
"preferred": "system",
"recurse": true
},
"order": 20,
"title": "System"
},
"status": {
"satisfied": true,
"action": {
"type": "firstchild",
"preferred": "overview",
"recurse": true
},
"order": 10,
"title": "Status",
"children": {
"overview": {
"satisfied": true,
"action": {
"type": "template",
"path": "admin_status/index"
},
"depends": {
"acl": [
"luci-mod-status-index"
]
},
"order": 1,
"title": "Overview"
},
"routes": {
"satisfied": true,
"action": {
"type": "view",
"path": "status/routes"
},
"depends": {
"acl": [
"luci-mod-status-routes"
]
},
"order": 2,
"title": "Routing",
"readonly": true
},
"iptables": {
"satisfied": false,
"action": {
"type": "view",
"path": "status/iptables"
},
"depends": {
"acl": [
"luci-mod-status-firewall"
],
"fs": [
{
"/usr/sbin/nft": "absent",
"/usr/sbin/iptables": "executable"
},
{
"/usr/sbin/nft": "absent",
"/usr/sbin/ip6tables": "executable"
}
]
},
"order": 3,
"title": "Firewall"
},
"nftables": {
"satisfied": true,
"action": {
"type": "view",
"path": "status/nftables"
},
"depends": {
"acl": [
"luci-mod-status-firewall"
],
"fs": {
"/usr/sbin/nft": "executable"
}
},
"order": 3,
"title": "Firewall",
"children": {
"iptables": {
"satisfied": true,
"action": {
"type": "view",
"path": "status/iptables"
}
}
}
},
"logs": {
"satisfied": true,
"action": {
"type": "alias",
"path": "admin/status/logs/syslog"
},
"depends": {
"acl": [
"luci-mod-status-logs"
]
},
"order": 4,
"title": "System Log",
"children": {
"syslog": {
"satisfied": true,
"action": {
"type": "view",
"path": "status/syslog"
},
"order": 1,
"title": "System Log"
},
"dmesg": {
"satisfied": true,
"action": {
"type": "view",
"path": "status/dmesg"
},
"order": 2,
"title": "Kernel Log"
}
},
"readonly": true
},
"processes": {
"satisfied": true,
"action": {
"type": "view",
"path": "status/processes"
},
"depends": {
"acl": [
"luci-mod-status-processes"
]
},
"order": 6,
"title": "Processes"
},
"channel_analysis": {
"satisfied": false,
"action": {
"type": "view",
"path": "status/channel_analysis"
},
"depends": {
"acl": [
"luci-mod-status-channel_analysis"
],
"uci": {
"wireless": {
"@wifi-device": true
}
}
},
"order": 7,
"title": "Channel Analysis",
"readonly": true
},
"realtime": {
"satisfied": true,
"action": {
"type": "alias",
"path": "admin/status/realtime/load"
},
"depends": {
"acl": [
"luci-mod-status-realtime"
]
},
"order": 7,
"title": "Realtime Graphs",
"children": {
"load": {
"satisfied": true,
"action": {
"type": "view",
"path": "status/load"
},
"order": 1,
"title": "Load"
},
"bandwidth": {
"satisfied": true,
"action": {
"type": "view",
"path": "status/bandwidth"
},
"order": 2,
"title": "Traffic"
},
"wireless": {
"satisfied": false,
"action": {
"type": "view",
"path": "status/wireless"
},
"depends": {
"uci": {
"wireless": {
"@wifi-device": true
}
}
},
"order": 3,
"title": "Wireless"
},
"connections": {
"satisfied": true,
"action": {
"type": "view",
"path": "status/connections"
},
"order": 4,
"title": "Connections"
}
},
"readonly": true
}
}
},
"services": {
"satisfied": true,
"action": {
"type": "firstchild",
"recurse": true
},
"order": 40,
"title": "Services"
},
"vpn": {
"satisfied": true,
"action": {
"type": "firstchild",
"recurse": true
},
"order": 70,
"title": "VPN",
"children": {
"openvpn": {
"satisfied": true,
"children": {
"advanced": {
"satisfied": true,
"action": {
"module": "luci.dispatcher",
"type": "call",
"post": {
"cbi.submit": true
},
"function": "invoke_cbi_action",
"parameters": [
"openvpn-advanced",
{
}
]
},
"wildcard": true
},
"file": {
"satisfied": true,
"action": {
"module": "luci.dispatcher",
"type": "call",
"post": {
"cbi.submit": true
},
"function": "invoke_form_action",
"parameters": [
"openvpn-file"
]
},
"wildcard": true
},
"basic": {
"satisfied": true,
"action": {
"module": "luci.dispatcher",
"type": "call",
"post": {
"cbi.submit": true
},
"function": "invoke_cbi_action",
"parameters": [
"openvpn-basic",
{
}
]
},
"wildcard": true
},
"upload": {
"satisfied": true,
"action": {
"module": "luci.controller.openvpn",
"type": "call",
"function": "ovpn_upload"
}
}
},
"action": {
"module": "luci.dispatcher",
"type": "call",
"post": {
"cbi.submit": true
},
"function": "invoke_cbi_action",
"parameters": [
"openvpn",
{
}
]
},
"depends": {
"acl": [
"luci-app-openvpn"
]
},
"title": "OpenVPN"
}
}
},
"translations": {
"satisfied": true,
"wildcard": true,
"action": {
"type": "function",
"module": "luci.controller.admin.index",
"function": "action_translations"
},
"auth": {
}
},
"ubus": {
"satisfied": true,
"wildcard": true,
"action": {
"type": "function",
"module": "luci.controller.admin.index",
"function": "action_ubus"
},
"auth": {
}
},
"logout": {
"satisfied": true,
"action": {
"type": "function",
"module": "luci.controller.admin.index",
"function": "action_logout"
},
"depends": {
"acl": [
"luci-base"
]
},
"order": 999,
"title": "Log out",
"firstchild_ineligible": true
},
"uci": {
"satisfied": true,
"action": {
"type": "firstchild"
},
"children": {
"revert": {
"satisfied": true,
"action": {
"type": "function",
"module": "luci.controller.admin.uci",
"function": "action_revert",
"post": true
}
},
"apply_rollback": {
"satisfied": true,
"action": {
"type": "function",
"module": "luci.controller.admin.uci",
"function": "action_apply_rollback",
"post": true
},
"auth": {
"methods": [
"cookie:sysauth_https",
"cookie:sysauth_http"
]
},
"cors": true
},
"apply_unchecked": {
"satisfied": true,
"action": {
"type": "function",
"module": "luci.controller.admin.uci",
"function": "action_apply_unchecked",
"post": true
},
"auth": {
"methods": [
"cookie:sysauth_https",
"cookie:sysauth_http"
]
},
"cors": true
},
"confirm": {
"satisfied": true,
"action": {
"type": "function",
"module": "luci.controller.admin.uci",
"function": "action_confirm"
},
"auth": {
},
"cors": true
}
}
},
"menu": {
"satisfied": true,
"action": {
"type": "function",
"module": "luci.controller.admin.index",
"function": "action_menu"
},
"auth": {
}
},
"docker": {
"satisfied": true,
"children": {
"images_tag": {
"satisfied": true,
"action": {
"module": "luci.controller.dockerman",
"type": "call",
"function": "tag_image"
},
"wildcard": true
},
"newnetwork": {
"satisfied": true,
"action": {
"module": "luci.dispatcher",
"type": "call",
"post": {
"cbi.submit": true
},
"function": "invoke_form_action",
"parameters": [
"dockerman/newnetwork"
]
},
"wildcard": true
},
"networks": {
"satisfied": true,
"action": {
"module": "luci.dispatcher",
"type": "call",
"post": {
"cbi.submit": true
},
"function": "invoke_form_action",
"parameters": [
"dockerman/networks"
]
},
"order": 5,
"title": "Networks",
"wildcard": true
},
"config": {
"satisfied": true,
"action": {
"module": "luci.dispatcher",
"type": "call",
"post": {
"cbi.submit": true
},
"function": "invoke_cbi_action",
"parameters": [
"dockerman/configuration",
{
}
]
},
"order": 1,
"title": "Configuration",
"wildcard": true
},
"containers": {
"satisfied": true,
"action": {
"module": "luci.dispatcher",
"type": "call",
"post": {
"cbi.submit": true
},
"function": "invoke_form_action",
"parameters": [
"dockerman/containers"
]
},
"order": 3,
"title": "Containers",
"wildcard": true
},
"volumes": {
"satisfied": true,
"action": {
"module": "luci.dispatcher",
"type": "call",
"post": {
"cbi.submit": true
},
"function": "invoke_form_action",
"parameters": [
"dockerman/volumes"
]
},
"order": 6,
"title": "Volumes",
"wildcard": true
},
"overview": {
"satisfied": true,
"action": {
"module": "luci.dispatcher",
"type": "call",
"post": {
"cbi.submit": true
},
"function": "invoke_form_action",
"parameters": [
"dockerman/overview"
]
},
"order": 2,
"title": "Overview",
"wildcard": true
},
"container_put_archive": {
"satisfied": true,
"action": {
"module": "luci.controller.dockerman",
"type": "call",
"function": "upload_archive"
},
"wildcard": true
},
"images_import": {
"satisfied": true,
"action": {
"module": "luci.controller.dockerman",
"type": "call",
"function": "import_images"
},
"wildcard": true
},
"confirm": {
"satisfied": true,
"action": {
"module": "luci.controller.dockerman",
"type": "call",
"function": "action_confirm"
},
"wildcard": true
},
"events": {
"satisfied": true,
"action": {
"module": "luci.controller.dockerman",
"type": "call",
"function": "action_events"
},
"order": 7,
"title": "Events"
},
"images_untag": {
"satisfied": true,
"action": {
"module": "luci.controller.dockerman",
"type": "call",
"function": "untag_image"
},
"wildcard": true
},
"container": {
"satisfied": true,
"action": {
"module": "luci.dispatcher",
"type": "call",
"post": {
"cbi.submit": true
},
"function": "invoke_form_action",
"parameters": [
"dockerman/container"
]
},
"wildcard": true
},
"images_load": {
"satisfied": true,
"action": {
"module": "luci.controller.dockerman",
"type": "call",
"function": "load_images"
},
"wildcard": true
},
"newcontainer": {
"satisfied": true,
"action": {
"module": "luci.dispatcher",
"type": "call",
"post": {
"cbi.submit": true
},
"function": "invoke_form_action",
"parameters": [
"dockerman/newcontainer"
]
},
"wildcard": true
},
"images_get_tags": {
"satisfied": true,
"action": {
"module": "luci.controller.dockerman",
"type": "call",
"function": "get_image_tags"
},
"wildcard": true
},
"container_stats": {
"satisfied": true,
"action": {
"module": "luci.controller.dockerman",
"type": "call",
"function": "action_get_container_stats"
},
"wildcard": true
},
"images": {
"satisfied": true,
"action": {
"module": "luci.dispatcher",
"type": "call",
"post": {
"cbi.submit": true
},
"function": "invoke_form_action",
"parameters": [
"dockerman/images"
]
},
"order": 4,
"title": "Images",
"wildcard": true
},
"container_get_archive": {
"satisfied": true,
"action": {
"module": "luci.controller.dockerman",
"type": "call",
"function": "download_archive"
},
"wildcard": true
},
"images_save": {
"satisfied": true,
"action": {
"module": "luci.controller.dockerman",
"type": "call",
"function": "save_images"
},
"wildcard": true
}
},
"action": {
"type": "firstchild"
},
"depends": {
"acl": [
"luci-app-dockerman"
]
},
"order": 40,
"title": "Docker"
}
},
"action": {
"type": "firstchild",
"recurse": true
},
"auth": {
"methods": [
"cookie:sysauth_https",
"cookie:sysauth_http"
],
"login": true
},
"order": 10,
"title": "Administration"
}
}
}
The luci.http package does not mention a request function.
Is there any ucode specific documentation that I've missed?