### LuCI Theme Media Link Example (HTML) Source: https://openwrt.github.io/luci/jsapi/tutorial-ThemesHowTo.html Demonstrates how to reference media files (like icons) within LuCI theme templates using the `{{ media }}` variable. This variable points to the theme's static resource directory. ```html | ---|--- ``` -------------------------------- ### LuCI Module Makefile for C/C++ Code Source: https://openwrt.github.io/luci/jsapi/tutorial-Modules.html This snippet shows how to handle C/C++ code within a LuCI module. It requires a 'src/' subdirectory with its own Makefile and demonstrates the installation process using the DESTDIR variable. ```makefile | mkdir -p $(DESTDIR)/usr/bin; cp myexecutable $(DESTDIR)/usr/bin/myexecutable --- ``` -------------------------------- ### LuCI Form Map Creation and Rendering Example (JavaScript) Source: https://openwrt.github.io/luci/jsapi/form.js.html Demonstrates how to create a LuCI form using the `form.Map` class. This example shows adding a named section with different option types (Flag and ListValue) and then rendering the form into the DOM. ```javascript 'use strict'; 'require form'; let m, s, o; m = new form.Map('example', _('Example form'), _('This is an example form mapping the contents of /etc/config/example')); s = m.section(form.NamedSection, 'first_section', 'example', _('The first section'), _('This sections maps "config example first_section" of /etc/config/example')); o = s.option(form.Flag, 'some_bool', _('A checkbox option')); o = s.option(form.ListValue, 'some_choice', _('A select element')); o.value('choice1', _('The first choice')); o.value('choice2', _('The second choice')); m.render().then((node) => { document.body.appendChild(node); }); ``` -------------------------------- ### LuCI Theme Post-Installation Script (ipkg) Source: https://openwrt.github.io/luci/jsapi/tutorial-ThemesHowTo.html A post-installation script for LuCI themes using ipkg. It ensures that the theme's default settings are applied and cleans up the temporary configuration file upon installation. ```sh | #!/bin/sh ---|--- | [ -n "${IPKG_INSTROOT}" ] || { | ( . /etc/uci-defaults/luci-theme-mytheme ) && rm -f /etc/uci-defaults/luci-theme-mytheme | } ``` -------------------------------- ### LuCI Network API - Get Device Source: https://openwrt.github.io/luci/jsapi/LuCI.network.html Retrieves a Device instance that describes the specified network device. ```APIDOC ## GET /api/luci/network/getDevice ### Description Get a `Device` instance describing the given network device. ### Method GET ### Endpoint /api/luci/network/getDevice ### Parameters #### Path Parameters None #### Query Parameters - **name** (string) - Required - The name of the network device to get, e.g. `eth0` or `br-lan`. ### Request Example ``` GET /api/luci/network/getDevice?name=eth0 ``` ### Response #### Success Response (200) - **device** (LuCI.network.Device) - The `Device` instance describing the network device or `null` if the given device name could not be found. #### Response Example ```json { "__instance": "LuCI.network.Device", "name": "eth0" } ``` ``` -------------------------------- ### All Network Interfaces Source: https://openwrt.github.io/luci/jsapi/network.js.html Gets all logical interfaces this device is assigned to. ```APIDOC ## GET /device/networks ### Description Gets all logical interfaces this device is assigned to. ### Method GET ### Endpoint /device/networks ### Parameters None ### Request Example None ### Response #### Success Response (200) - **networks** (Array|null) - An array of `Network.Protocol` instances representing the logical interfaces. #### Response Example ```json { "networks": [ { "id": "lan", "proto": "static", "ifname": "br-lan" }, { "id": "guest", "proto": "static", "ifname": "br-guest" } ] } ``` ``` -------------------------------- ### instantiateView Source: https://openwrt.github.io/luci/jsapi/LuCI.ui.html Loads a specified view class path, sets it up, renders its contents, and includes them in the view area. Handles runtime errors. ```APIDOC ## instantiateView(path) → {Promise.} ### Description Load specified view class path and set it up. Transforms the given view path into a class name, requires it using `LuCI.require()` and asserts that the resulting class instance is a descendant of `LuCI.view`. By instantiating the view class, its corresponding contents are rendered and included into the view area. Any runtime errors are caught and rendered using `LuCI.error()`. ### Method N/A (This appears to be a client-side JavaScript function, not a typical HTTP API endpoint) ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```javascript instantiateView('admin/status/overview').then(view => { console.log('View instantiated:', view); }).catch(error => { console.error('Failed to instantiate view:', error); }); ``` ### Response #### Success Response (N/A) Returns a promise resolving to the loaded view instance. #### Response Example ```javascript // Example of a resolved LuCI.view instance { // ... view properties and methods } ``` ``` -------------------------------- ### OpenWRT Feed Integration: Package Installation Source: https://openwrt.github.io/luci/jsapi/tutorial-Modules.html Specifies the installation target for a LuCI Web UI application package in the OpenWRT feed. It uses a LuCI template to handle the installation process. ```makefile define Package/luci-app-YOURMODULE/install $(call Package/luci/install/template,$(1),applications/YOURMODULE) endef ``` -------------------------------- ### LuCI.form.JSONMap Constructor Source: https://openwrt.github.io/luci/jsapi/LuCI.form.JSONMap.html Initializes a new JSONMap instance with provided data, title, and description. ```APIDOC ## new JSONMap(data, titleopt, descriptionopt) ### Description Initializes a new JSONMap instance. This class functions similarly to `LuCI.form.Map` but uses a multidimensional JavaScript object as its data source instead of UCI configuration. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body * **data** (Object.|Array.>)>) - Required - The JavaScript object to use as a data source. Top-level keys are treated as UCI section types, and their values (objects or arrays of objects) are treated as section contents. * **title** (string) - Optional - The title caption for the form, rendered as a headline element before the form content. * **description** (string) - Optional - The description text for the form, rendered as a paragraph below the title and before the form content. ### Request Example ```json { "data": { "network": { "lan": { "proto": "static", "ipaddr": "192.168.1.1" } } }, "title": "Network Configuration", "description": "Configure your network settings." } ``` ### Response #### Success Response (200) This constructor does not return a value directly, but initializes the JSONMap object. #### Response Example N/A ``` -------------------------------- ### LuCI.network.WifiNetwork Methods Source: https://openwrt.github.io/luci/jsapi/LuCI.network.WifiNetwork.html This section details the various methods available for interacting with a WifiNetwork instance. ```APIDOC ## POST /luci/network/disconnectClient ### Description Forcibly disconnect the given client from the wireless network. ### Method POST ### Endpoint `/luci/network/disconnectClient` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **mac** (string) - Required - The MAC address of the client to disconnect. - **deauth** (boolean) - Optional - Specifies whether to de-authenticate (`true`) or disassociate (`false`) the client. Defaults to `false`. - **reason** (number) - Optional - Specifies the IEEE 802.11 reason code to disassoc/deauth the client with. Defaults to `1`. - **ban_time** (number) - Optional - Specifies the number of milliseconds to ban the client from reconnecting. Defaults to `0`. ### Request Example ```json { "mac": "00:11:22:33:44:55", "deauth": true, "reason": 1, "ban_time": 30000 } ``` ### Response #### Success Response (200) - **result_code** (number) - The underlying ubus call result code, typically `0`. #### Response Example ```json { "result_code": 0 } ``` ``` ```APIDOC ## GET /luci/network/get ### Description Read the given UCI option value of this wireless network. ### Method GET ### Endpoint `/luci/network/get` ### Parameters #### Path Parameters None #### Query Parameters - **opt** (string) - Required - The UCI option name to read. ### Request Example ```json { "opt": "ssid" } ``` ### Response #### Success Response (200) - **value** (null|string|Array.) - The UCI option value or `null` if the requested option is not found. #### Response Example ```json { "value": "MyWiFiNetwork" } ``` ``` ```APIDOC ## GET /luci/network/getActiveBSSID ### Description Query the current BSSID from runtime information. ### Method GET ### Endpoint `/luci/network/getActiveBSSID` ### Parameters #### Path Parameters None #### Query Parameters None ### Request Example ```json {} ``` ### Response #### Success Response (200) - **bssid** (string) - The current BSSID or Mesh ID as reported by `ubus` runtime information. #### Response Example ```json { "bssid": "AA:BB:CC:DD:EE:FF" } ``` ``` ```APIDOC ## GET /luci/network/getActiveEncryption ### Description Query the current encryption settings from runtime information. ### Method GET ### Endpoint `/luci/network/getActiveEncryption` ### Parameters #### Path Parameters None #### Query Parameters None ### Request Example ```json {} ``` ### Response #### Success Response (200) - **encryption** (string) - A string describing the current encryption or `-` if the encryption state could not be found in `ubus` runtime information. #### Response Example ```json { "encryption": "WPA2-PSK" } ``` ``` ```APIDOC ## GET /luci/network/getActiveMode ### Description Query the current operation mode from runtime information. ### Method GET ### Endpoint `/luci/network/getActiveMode` ### Parameters #### Path Parameters None #### Query Parameters None ### Request Example ```json {} ``` ### Response #### Success Response (200) - **mode** (string) - The human readable mode name as reported by iwinfo or uci mode. Possible values include: `Master`, `Ad-Hoc`, `Client`, `Monitor`, `Master (VLAN)`, `WDS`, `Mesh Point`, `P2P Client`, `P2P Go`, `Unknown`. #### Response Example ```json { "mode": "Master" } ``` ``` ```APIDOC ## GET /luci/network/getActiveModeI18n ### Description Query the current operation mode from runtime information as a translated string. ### Method GET ### Endpoint `/luci/network/getActiveModeI18n` ### Parameters #### Path Parameters None #### Query Parameters None ### Request Example ```json {} ``` ### Response #### Success Response (200) - **mode_i18n** (string) - The translated, human readable mode name as reported by `ubus` runtime state. #### Response Example ```json { "mode_i18n": "Master" } ``` ``` ```APIDOC ## GET /luci/network/getActiveSSID ### Description Query the current SSID from runtime information. ### Method GET ### Endpoint `/luci/network/getActiveSSID` ### Parameters #### Path Parameters None #### Query Parameters None ### Request Example ```json {} ``` ### Response #### Success Response (200) - **ssid** (string) - The current SSID or Mesh ID as reported by `ubus` runtime information. #### Response Example ```json { "ssid": "MyWiFiNetwork" } ``` ``` ```APIDOC ## GET /luci/network/getAssocList ### Description Fetch the list of associated peers. ### Method GET ### Endpoint `/luci/network/getAssocList` ### Parameters #### Path Parameters None #### Query Parameters None ### Request Example ```json {} ``` ### Response #### Success Response (200) - **peers** (Array.) - An array of objects, where each object represents a wireless peer associated with this network. Each peer object may contain properties like `mac`, `rssi`, `tx_rate`, etc. #### Response Example ```json { "peers": [ { "mac": "00:11:22:33:44:55", "rssi": -50, "tx_rate": 54000000 }, { "mac": "AA:BB:CC:DD:EE:FF", "rssi": -65, "tx_rate": 130000000 } ] } ``` ``` ```APIDOC ## GET /luci/network/getBSSID ### Description Get the configured BSSID of the wireless network. ### Method GET ### Endpoint `/luci/network/getBSSID` ### Parameters #### Path Parameters None #### Query Parameters None ### Request Example ```json {} ``` ### Response #### Success Response (200) - **bssid** (null|string) - The configured BSSID value or `null` if none has been specified. #### Response Example ```json { "bssid": "AA:BB:CC:DD:EE:FF" } ``` ``` ```APIDOC ## GET /luci/network/getBitRate ### Description Query the current average bit-rate of all peers associated with this wireless network. ### Method GET ### Endpoint `/luci/network/getBitRate` ### Parameters #### Path Parameters None #### Query Parameters None ### Request Example ```json {} ``` ### Response #### Success Response (200) - **bitrate** (null|number) - The average bit rate among all peers associated with the network as reported by `ubus` runtime information or `null` if the information is not available. #### Response Example ```json { "bitrate": 54000000 } ``` ``` ```APIDOC ## GET /luci/network/getChannel ### Description Query the current wireless channel. ### Method GET ### Endpoint `/luci/network/getChannel` ### Parameters #### Path Parameters None #### Query Parameters None ### Request Example ```json {} ``` ### Response #### Success Response (200) - **channel** (null|number) - The wireless channel as reported by `ubus` runtime information or `null` if it cannot be determined. #### Response Example ```json { "channel": 6 } ``` ``` ```APIDOC ## GET /luci/network/getCountryCode ### Description Query the current country code. ### Method GET ### Endpoint `/luci/network/getCountryCode` ### Parameters #### Path Parameters None #### Query Parameters None ### Request Example ```json {} ``` ### Response #### Success Response (200) - **country_code** (string) - The wireless country code as reported by `ubus` runtime information or `00` if it cannot be determined. #### Response Example ```json { "country_code": "US" } ``` ``` ```APIDOC ## GET /luci/network/getDevice ### Description Get the associated Linux network device. ### Method GET ### Endpoint `/luci/network/getDevice` ### Parameters #### Path Parameters None #### Query Parameters None ### Request Example ```json {} ``` ### Response #### Success Response (200) - **device** (object) - A `Network.Device` instance representing the Linux network device associated with this wireless network. #### Response Example ```json { "device": { "name": "wlan0", "type": "wifi" } } ``` ``` -------------------------------- ### Cursor:load Source: https://openwrt.github.io/luci/api/modules/luci.model.uci.html Manually loads a UCI configuration. ```APIDOC ## Cursor:load ### Description Manually load a config. ### Method N/A (Function Call) ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **config** (string) - Required - UCI config ### Return value Boolean whether operation succeeded ### See also - Cursor:save - Cursor:unload ``` -------------------------------- ### Get Protocol Handler Package Name (JavaScript) Source: https://openwrt.github.io/luci/jsapi/network.js.html Retrieves the name of the package that provides the protocol functionality. This is used when a configuration refers to a protocol handler that is not yet installed. This method is intended to be overridden by protocol-specific subclasses. It returns null by default. ```javascript getPackageName() { return null; } ``` -------------------------------- ### Get Linux Network Interface Name Source: https://openwrt.github.io/luci/jsapi/network.js.html Fetches the Linux network device name associated with the wireless network. It queries ubus for 'ifname' and 'iwinfo', falling back to the network ID if the resolved name is null or starts with 'wifi' or 'radio'. This is crucial for interacting with the network interface at the OS level. ```javascript getIfname() { let ifname = this.ubus('net', 'ifname') || this.ubus('net', 'iwinfo', 'ifname'); if (ifname == null || ifname.match(/^(wifi|radio)\d/)) ifname = this.netid; return ifname; } ``` -------------------------------- ### LuCI UI - View Instantiation Source: https://openwrt.github.io/luci/jsapi/ui.js.html Demonstrates how to load and instantiate a view class, ensuring it's a descendant of LuCI.view. Handles rendering and error catching. ```APIDOC ## instantiateView(path) ### Description Loads a specified view class path, transforms it into a class name, requires it using `LuCI.require()`, and asserts that the resulting class instance is a descendant of `LuCI.view`. Instantiates the view class to render its contents into the view area. Catches and renders any runtime errors using `LuCI.error()`. ### Method `instantiateView(path) ### Endpoint N/A (Client-side JavaScript function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```javascript // Example usage: LuCI.instantiateView('status/overview').then(view => { // View loaded and instantiated successfully }).catch(err => { // Handle errors during view loading or instantiation }); ``` ### Response #### Success Response (Promise) - **view** (LuCI.view) - The loaded and instantiated view instance. #### Response Example ```json // A LuCI.view instance is returned upon successful loading. // The exact structure depends on the specific view being loaded. ``` ``` -------------------------------- ### Get UCI Configuration using JSON RPC Source: https://openwrt.github.io/luci/jsapi/tutorial-JsonRpcHowTo.html This example shows how to retrieve all configuration settings for a specific section (e.g., 'network') from the Universal Configuration Interface (UCI) using LuCI's JSON-RPC API. It requires an authentication token obtained from the 'auth' library and sends a 'get_all' method request to the 'uci' RPC endpoint. ```shell curl http:///cgi-bin/luci/rpc/uci?auth=yourtoken --data ' \ { \ "method": "get_all", \ "params": [ "network" ] \ }' ``` -------------------------------- ### Start Polling Loop (JavaScript) Source: https://openwrt.github.io/luci/jsapi/luci.js.html Starts the polling loop, setting an interval timer and executing the step function. Dispatches a 'poll-start' event on the document. Returns true if started or if no functions are registered, false if already running. ```javascript start() { if (this.active()) return false; this.tick = 0; if (this.queue.length) { this.timer = window.setInterval(this.step, 1000); this.step(); document.dispatchEvent(new CustomEvent('poll-start')); } return true; } ``` -------------------------------- ### LuCI.network.WifiDevice Methods Source: https://openwrt.github.io/luci/jsapi/LuCI.network.WifiDevice.html This section details the methods available for interacting with a WifiDevice instance. ```APIDOC ## LuCI.network.WifiDevice Class A `Network.WifiDevice` class instance represents a wireless radio device present on the system and provides wireless capability information as well as methods for enumerating related wireless networks. ### Methods #### addWifiNetwork(options) Adds a new wireless network associated with this radio device to the configuration and sets its options to the provided values. **Parameters:** - `options` (Object.)>) - Optional: The options to set for the newly added wireless network. **Returns:** A promise resolving to a `WifiNetwork` instance describing the newly added wireless network or `null` if the given options were invalid. **Type:** Promise.<(null|LuCI.network.WifiNetwork)> #### deleteWifiNetwork(network) Deletes the wireless network with the given name associated with this radio device. **Parameters:** - `network` (string) - The name of the wireless network to look up. This may be either an uci configuration section ID, a network ID in the form `radio#.network#` or a Linux network device name like `wlan0` which is resolved to the corresponding configuration section through `ubus` runtime information. **Returns:** A promise resolving to `true` when the wireless network was successfully deleted from the configuration or `false` when the given network could not be found or if the found network was not associated with this wireless radio device. **Type:** Promise. #### get(opt) Read the given UCI option value of this wireless device. **Parameters:** - `opt` (string) - The UCI option name to read. **Returns:** The UCI option value or `null` if the requested option is not found. **Type:** null | string | Array. #### getHTModes() Gets a list of supported htmodes. The htmode values describe the wide-frequency options supported by the wireless phy. **Returns:** An array of valid htmode values for this radio. Currently known mode values are: * `HT20` - applicable to IEEE 802.11n, 20 MHz wide channels * `HT40` - applicable to IEEE 802.11n, 40 MHz wide channels * `VHT20` - applicable to IEEE 802.11ac, 20 MHz wide channels * `VHT40` - applicable to IEEE 802.11ac, 40 MHz wide channels * `VHT80` - applicable to IEEE 802.11ac, 80 MHz wide channels * `VHT160` - applicable to IEEE 802.11ac, 160 MHz wide channels * `HE20` - applicable to IEEE 802.11ax, 20 MHz wide channels * `HE40` - applicable to IEEE 802.11ax, 40 MHz wide channels * `HE80` - applicable to IEEE 802.11ax, 80 MHz wide channels * `HE160` - applicable to IEEE 802.11ax, 160 MHz wide channels * `EHT20` - applicable to IEEE 802.11be, 20 MHz wide channels * `EHT40` - applicable to IEEE 802.11be, 40 MHz wide channels * `EHT80` - applicable to IEEE 802.11be, 80 MHz wide channels * `EHT160` - applicable to IEEE 802.11be, 160 MHz wide channels * `EHT320` - applicable to IEEE 802.11be, 320 MHz wide channels **Type:** Array. #### getHWModes() Gets a list of supported hwmodes. The hwmode values describe the frequency band and wireless standard versions supported by the wireless phy. **Returns:** An array of valid hwmode values for this radio. Currently known mode values are: * `a` - Legacy 802.11a mode, 5 GHz, up to 54 Mbit/s * `b` - Legacy 802.11b mode, 2.4 GHz, up to 11 Mbit/s * `g` - Legacy 802.11g mode, 2.4 GHz, up to 54 Mbit/s * `n` - IEEE 802.11n mode, 2.4 or 5 GHz, up to 600 Mbit/s * `ac` - IEEE 802.11ac mode, 5 GHz, up to 6770 Mbit/s * `ax` - IEEE 802.11ax mode, 2.4 or 5 GHz * 'be' - IEEE 802.11be mode, 2.4, 5 or 6 GHz **Type:** Array. #### getI18n() Get a string describing the wireless radio hardware. **Returns:** The description string. **Type:** string #### getName() Get the configuration name of this wireless radio. **Returns:** The UCI section name (e.g. `radio0`) of the corresponding radio configuration, which also serves as a unique logical identifier for the wireless phy. **Type:** string #### getScanList() Trigger a wireless scan on this radio device and obtain a list of nearby networks. **Returns:** A promise resolving to an array of scan result objects describing the networks found in the vicinity. **Type:** Promise.> ``` -------------------------------- ### Issue HTTP GET Request with LuCI Wrapper Source: https://openwrt.github.io/luci/jsapi/luci.js.html The `get` function is a deprecated wrapper for issuing HTTP GET requests. It takes a URL, optional arguments, and a callback function. It internally uses the `poll` function to handle the request and returns a promise that resolves to `null` upon completion. ```javascript get(url, args, cb) { return this.poll(null, url, args, cb, false); } ``` -------------------------------- ### Initialize LuCI with System Feature Probing Source: https://openwrt.github.io/luci/jsapi/luci.js.html This snippet shows the initialization process for LuCI, which involves probing system features and preloading classes. It uses `Promise.all` to concurrently execute `probeSystemFeatures` and `probePreloadClasses`. The `finally` block ensures that preloaded classes are required and then `initDOM` is called. ```javascript return Promise.all([ this.probeSystemFeatures(), this.probePreloadClasses() ]).finally(LuCI.prototype.bind(function() { const tasks = []; if (Array.isArray(preloadClasses)) for (let i = 0; i < preloadClasses.length; i++) tasks.push(this.require(preloadClasses[i])); return Promise.all(tasks); }, this)).finally(this.initDOM); ``` -------------------------------- ### LuCI HTTP GET Request Method Source: https://openwrt.github.io/luci/jsapi/luci.js.html Initiates an HTTP GET request to a specified URL with optional configuration options. It returns a Promise that resolves with the HTTP response. ```javascript get(url, options) { return this.request(url, Object.assign({ method: 'GET' }, options)); } ``` -------------------------------- ### LuCI.form.JSONMap Methods Source: https://openwrt.github.io/luci/jsapi/LuCI.form.JSONMap.html Documentation for append, chain, and findElement methods. ```APIDOC ## append(obj) ### Description Adds another form element as a child to this element. ### Method `append` ### Endpoint N/A (Method of a class instance) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body * **obj** (LuCI.form.AbstractElement) - Required - The form element to add as a child. ### Request Example ```javascript // Assuming 'map' is an instance of JSONMap and 'element' is a form element map.append(element); ``` ### Response #### Success Response (200) This method does not return a value. #### Response Example N/A --- ## chain(config) ### Description Ties another UCI configuration file to the map. This is useful when the map needs to access values from configuration files beyond the one specified in the constructor. ### Method `chain` ### Endpoint N/A (Method of a class instance) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body * **config** (string) - Required - The name of the additional UCI configuration file to tie to the map. If the file is already in the list of required files, it will be ignored. ### Request Example ```javascript // Assuming 'map' is an instance of JSONMap map.chain('wireless'); // Ties the 'wireless' UCI configuration file ``` ### Response #### Success Response (200) This method does not return a value. #### Response Example N/A --- ## findElement(…args, selector_or_attrname, attrvalueopt) → {Node|null} ### Description Returns the first DOM node within this Map that matches the given search parameters. It acts as a wrapper for `findElements()`, returning only the first match. The behavior depends on the number of arguments provided: one argument is treated as a `querySelector` selector, while two arguments treat the first as an attribute name and the second as its value. ### Method `findElement` ### Endpoint N/A (Method of a class instance) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body * **args** (*) - Repeatable - Argument array. * **selector_or_attrname** (string) - Required - If one argument is provided, this is a `querySelector()` compatible selector expression. If two arguments are provided, this is the attribute name to filter by. * **attrvalue** (string) - Optional - If two arguments are provided, this specifies the attribute value to match. ### Request Example ```javascript // Find the first input element let inputElement = map.findElement('input'); // Find the first element with type="text" let textInputElement = map.findElement('type', 'text'); ``` ### Response #### Success Response (200) * **Node | null** - Returns the first found DOM node or `null` if no element matched the criteria. #### Response Example ```javascript // Example of a returned Node object (structure may vary) // ``` ### Throws * **InternalError** - Thrown if more than two function parameters are passed. ``` -------------------------------- ### Get Validation Error Message (JavaScript) Source: https://openwrt.github.io/luci/jsapi/form.js.html Retrieves the current validation error message for an input. It gets the UI element and calls its `getValidationError` method. If no UI element is found, it returns an empty string, indicating no error. ```javascript getValidationError(section_id) { const elem = this.getUIElement(section_id); return elem ? elem.getValidationError() : ''; } ``` -------------------------------- ### Cursor:section Source: https://openwrt.github.io/luci/api/modules/luci.model.uci.html Creates a new UCI section and initializes it with provided data. ```APIDOC ## Cursor:section ### Description Create a new section and initialize it with data. ### Method N/A (Function Call) ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **config** (string) - Required - UCI config - **type** (string) - Required - UCI section type - **name** (string) - Optional - UCI section name - **values** (table) - Required - Table of key - value pairs to initialize the section with ### Return value Name of created section ``` -------------------------------- ### LuCI GET Request Wrapper (JavaScript) Source: https://openwrt.github.io/luci/jsapi/LuCI.html Issues an HTTP GET request to a specified URL, optionally appending query arguments, and invokes a callback upon completion. This is a wrapper around `Request.request()` and returns a promise. ```javascript L.get('/status', { iface: 'lan' }, (err, data) => { /* handle response */ }); ``` -------------------------------- ### LuCI Network Hosts Class Initialization and MAC Address Lookups (JavaScript) Source: https://openwrt.github.io/luci/jsapi/network.js.html Initializes the network state and creates a Hosts instance. Provides methods to get hostnames, IPv4, and IPv6 addresses by MAC address. It handles cases where host information might be missing. ```javascript getHostHints() { return initNetworkState().then(function() { return new Hosts(_state.hosts); }); } }); Hosts = baseclass.extend({ __init__(hosts) { this.hosts = hosts; }, getHostnameByMACAddr(mac) { return this.hosts[mac] ? (this.hosts[mac].name || null) : null; }, getIPAddrByMACAddr(mac) { return this.hosts[mac] ? (L.toArray(this.hosts[mac].ipaddrs || this.hosts[mac].ipv4)[0] || null) : null; }, getIP6AddrByMACAddr(mac) { return this.hosts[mac] ? (L.toArray(this.hosts[mac].ip6addrs || this.hosts[mac].ipv6)[0] || null) : null; } }); ``` -------------------------------- ### Instantiate Network Device (JavaScript) Source: https://openwrt.github.io/luci/jsapi/network.js.html Instantiates a network device, optionally extending it with provided properties. If 'extend' is provided, it creates a new class that inherits from Device and then instantiates it; otherwise, it creates a standard Device instance. ```javascript instantiateDevice(name, network, extend) { if (extend != null) return new (Device.extend(extend))(name, network); return new Device(name, network); } ``` -------------------------------- ### Check if Protocol Handler is Installed (JavaScript) Source: https://openwrt.github.io/luci/jsapi/network.js.html Checks if the protocol functionality is installed. This method is for compatibility with older code and always returns true. It is marked as deprecated and abstract, suggesting subclasses might have provided specific implementations in the past. ```javascript isInstalled() { return true; } ``` -------------------------------- ### LuCI RPC API - List Objects and Methods Source: https://openwrt.github.io/luci/jsapi/rpc.js.html This endpoint allows you to list available ubus objects or retrieve method signatures for specific objects. It can be called with no arguments to get a list of all objects, or with object names to get their method signatures. ```APIDOC ## GET /rpc/list ### Description Lists available remote ubus objects or the method signatures of specific objects. ### Method GET ### Endpoint /rpc/list ### Parameters #### Query Parameters - **objectNames** (string) - Optional - Comma-separated list of ubus object names to get method signatures for. ### Request Example ``` GET /rpc/list ``` ### Response #### Success Response (200) - **Array** - If no arguments are provided, returns a promise resolving to an array of ubus object names. - **Object>>** - If object names are provided, returns a promise resolving to an object describing the method signatures of each requested ubus object name. #### Response Example (no arguments) ```json [ "session", "uci", "system" ] ``` #### Response Example (with arguments) ```json { "session": { "get_session": [ { "name": "sessionid", "type": "string" } ], "kill": [ { "name": "uid", "type": "string" } ] } } ``` ``` -------------------------------- ### Instantiate Protocol Back-end Source: https://openwrt.github.io/luci/jsapi/network.js.html Instantiates a specified LuCI network protocol back-end. It takes the protocol name and an optional network name as arguments. If the protocol is not known, it returns null. The network name defaults to '__dummy__' if not provided. ```javascript /** * Instantiates the given {@link LuCI.network.Protocol Protocol} back-end, * optionally using the given network name. * * @param {string} protoname * The protocol back-end to use, e.g. `static` or `dhcp`. * * @param {string} [netname=__dummy__] * The network name to use for the instantiated protocol. This should be * usually set to one of the interfaces described in /etc/config/network * but it is allowed to omit it, e.g. to query protocol capabilities * without the need for an existing interface. * * @returns {null|LuCI.network.Protocol} * Returns the instantiated protocol back-end class or `null` if the given * protocol isn't known. */ getProtocol(protoname, netname) { const v = _protocols[protoname]; if (v != null) return new v(netname || '__dummy__'); return null; }, ``` -------------------------------- ### Get All Wireless Device Instances (JavaScript) Source: https://openwrt.github.io/luci/jsapi/network.js.html Obtains a list of all configured wireless radio devices on the system. It initializes the network state and then iterates through all 'wifi-device' sections in the UCI wireless configuration. For each section, it creates and collects a `WifiDevice` instance, returning them in an array. ```javascript /** * Obtain a list of all configured radio devices. * * @returns {Promise>} * Returns a promise resolving to an array of `WifiDevice` instances * describing the wireless radios configured in the system. * The order of the array corresponds to the order of the radios in * the configuration. */ getWifiDevices() { return initNetworkState().then(L.bind(function() { const uciWifiDevices = uci.sections('wireless', 'wifi-device'); const rv = []; for (let wfd of uciWifiDevices) { const devname = wfd['.name']; rv.push(this.instantiateWifiDevice(devname, _state.radios[devname] || {})); } return rv; }, this)); } ``` -------------------------------- ### Get Wi-Fi SSID from Runtime Information Source: https://openwrt.github.io/luci/jsapi/network.js.html Retrieves the current Wi-Fi SSID or Mesh ID by querying 'ubus' runtime information. It attempts to get the SSID from 'iwinfo', then 'config', and finally a local 'ssid' property. Returns an empty string if not found. ```javascript getActiveSSID() { return this.ubus('net', 'iwinfo', 'ssid') || this.ubus('net', 'config', 'ssid') || this.get('ssid'); } ``` -------------------------------- ### Get Textual Input Representation (JavaScript) Source: https://openwrt.github.io/luci/jsapi/form.js.html Obtains a string representation of the input value, HTML-escaped. It first attempts to get the configuration value, falls back to a default if none exists, joins array values with spaces, and then formats the result. This can be overridden for custom text representations. ```javascript textvalue(section_id) { let cval = this.cfgvalue(section_id); if (cval == null) cval = this.default; if (Array.isArray(cval)) cval = cval.join(' '); return (cval != null) ? '%h'.format(cval) : null; } ``` -------------------------------- ### InitOptions for LuCI UI Elements Source: https://openwrt.github.io/luci/jsapi/LuCI.ui.FileUpload.html This section describes the specific initialization options recognized by LuCI UI elements, extending the base AbstractElement.InitOptions. These options control various aspects of the element's behavior, such as file browser modes, upload capabilities, and directory selection. ```APIDOC ## InitOptions for LuCI UI Elements ### Description This section describes the specific initialization options recognized by LuCI UI elements, extending the base `AbstractElement.InitOptions`. These options control various aspects of the element's behavior, such as file browser modes, upload capabilities, and directory selection. ### Type LuCI.ui.AbstractElement.InitOptions ### Properties #### `browser` (boolean) - **Type:** boolean - **Attributes:** - **Default:** `false` - **Description:** Use a file browser mode. #### `show_hidden` (boolean) - **Type:** boolean - **Attributes:** - **Default:** `false` - **Description:** Specifies whether hidden files should be displayed when browsing remote files. Note that this is not a security feature, hidden files are always present in the remote file listings received, this option merely controls whether they're displayed or not. #### `enable_upload` (boolean) - **Type:** boolean - **Attributes:** - **Default:** `true` - **Description:** Specifies whether the widget allows the user to upload files. If set to `false`, only existing files may be selected. Note that this is not a security feature. Whether file upload requests are accepted remotely depends on the ACL setup for the current session. This option merely controls whether the upload controls are rendered or not. #### `enable_remove` (boolean) - **Type:** boolean - **Attributes:** - **Default:** `true` - **Description:** Specifies whether the widget allows the user to delete remove files. If set to `false`, existing files may not be removed. Note that this is not a security feature. Whether file delete requests are accepted remotely depends on the ACL setup for the current session. This option merely controls whether the file remove controls are rendered or not. #### `directory_create` (boolean) - **Type:** boolean - **Attributes:** - **Default:** `false` - **Description:** Specifies whether the widget allows the user to create directories. #### `directory_select` (boolean) - **Type:** boolean - **Attributes:** - **Default:** `false` - **Description:** Specifies whether the widget shall select directories only instead of files. #### `enable_download` (boolean) - **Type:** boolean - **Attributes:** - **Default:** `false` - **Description:** Specifies whether the widget allows the user to download files. #### `root_directory` (string) - **Type:** string - **Attributes:** - **Default:** `/etc/luci-uploads` - **Description:** Specifies the remote directory the upload and file browsing actions take place in. Browsing to directories outside the root directory is prevented by the widget. Note that this is not a security feature. Whether remote directories are browsable or not solely depends on the ACL setup for the current session. ``` -------------------------------- ### get(opt) Source: https://openwrt.github.io/luci/jsapi/LuCI.network.Protocol.html Reads a specific UCI option value for this network interface. ```APIDOC ## get(opt) ### Description Read the given UCI option value of this network. ### Method `get(opt)` ### Parameters #### Path Parameters - **opt** (string) - Required - The UCI option name to read. ### Returns Returns the UCI option value or `null` if the requested option is not found. ### Type `null | string | Array.` ### Source `network.js`, line 2027 ``` -------------------------------- ### Instantiate Wi-Fi Device (JavaScript) Source: https://openwrt.github.io/luci/jsapi/network.js.html Creates a new Wi-Fi device instance using the provided radio name and state. This function is responsible for initializing a WifiDevice object based on the given parameters. ```javascript instantiateWifiDevice(radioname, radiostate) { return new WifiDevice(radioname, radiostate); } ``` -------------------------------- ### LuCI.form.Map Constructor Source: https://openwrt.github.io/luci/jsapi/LuCI.form.Map.html Initializes a new Map instance, representing a form that maps a UCI configuration file. It can optionally take a title and description. ```APIDOC ## new Map(config, titleopt, descriptionopt) ### Description Initializes a new Map instance, representing a form that maps a UCI configuration file. It can optionally take a title and description. ### Parameters #### Path Parameters - None #### Query Parameters - None #### Request Body - **config** (string) - Required - The UCI configuration to map. It is automatically loaded along with the resulting map instance. - **title** (string) - Optional - The title caption of the form. A form title is usually rendered as a separate headline element before the actual form contents. If omitted, the corresponding headline element will not be rendered. - **description** (string) - Optional - The description text of the form which is usually rendered as a text paragraph below the form title and before the actual form contents. If omitted, the corresponding paragraph element will not be rendered. ### Request Example ```json { "config": "system", "title": "System Settings", "description": "Configure system-wide settings." } ``` ### Response #### Success Response (200) - **Map Instance** (object) - A new instance of the LuCI.form.Map class. #### Response Example ```json { "message": "Map instance created successfully." } ``` ``` -------------------------------- ### Get File Stat Source: https://openwrt.github.io/luci/jsapi/LuCI.fs.html Retrieves file status information for the specified path. ```APIDOC ## GET /websites/openwrt_github_io_luci/stat ### Description Returns file stat information on the specified path. ### Method GET ### Endpoint `/websites/openwrt_github_io_luci/stat` ### Parameters #### Query Parameters - **path** (string) - Required - The filesystem path to stat. ### Response #### Success Response (200) - ***LuCI.fs.FileStatEntry*** (Promise.) - A stat detail object. #### Response Example ```json { "example": { "size": 1024, "mtime": 1678886400, "mode": "0644", "type": "file" } } ``` ``` -------------------------------- ### Cursor:get Source: https://openwrt.github.io/luci/api/modules/luci.model.uci.html Retrieves a specific UCI section type or option value. ```APIDOC ## Cursor:get ### Description Get a section type or an option. ### Method N/A (Function Call) ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **config** (string) - Required - UCI config - **section** (string) - Required - UCI section name - **option** (string) - Optional - UCI option ### Return value UCI value ```