Methods
add(conf, type, nameopt) → {string}
Adds a new section of the given type to the given configuration, optionally named according to the given name.
| Name | Type | Attributes | Description |
|---|---|---|---|
conf | string | The name of the configuration to add the section to. | |
type | string | The type of the section to add. | |
name | string | <optional> | The name of the section to add. If the name is omitted, an anonymous section will be added instead. |
Returns the section ID of the newly added section which is equivalent to the given name for non-anonymous sections.
- Type:
- string
apply(timeoutopt) → {Promise.<number>}
Instructs the remote ubus UCI api to commit all saved changes with rollback protection and attempts to confirm the pending commit operation to cancel the rollback timer.
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
timeout | number | <optional> | 10 | Override the confirmation timeout after which a rollback is triggered. |
Returns a promise resolving/rejecting with the ubus RPC status code.
- Type:
- Promise.<number>
changes() → {Promise.<Object.<string, Array.<LuCI.uci.ChangeRecord>>>}
Fetches uncommitted UCI changes from the remote ubus RPC api.
Returns a promise resolving to an object containing the configuration names as keys and arrays of related change records as values.
- Type:
- Promise.<Object.<string, Array.<LuCI.uci.ChangeRecord>>>
clone(conf, type, srcsid, put_nextopt, nameopt) → {string}
Clones an existing section of the given type to the given configuration, optionally named according to the given name.
| Name | Type | Attributes | Description |
|---|---|---|---|
conf | string | The name of the configuration into which to clone the section. | |
type | string | The type of the section to clone. | |
srcsid | string | The source section id to clone. | |
put_next | boolean | <optional> | Whether to put the cloned item next (true) or last (false: default). |
name | string | <optional> | The name of the new cloned section. If the name is omitted, an anonymous section will be created instead. |
Returns the section ID of the newly cloned section which is equivalent to the given name for non-anonymous sections.
- Type:
- string
createSID(conf) → {string}
Generates a new, unique section ID for the given configuration.
Note that the generated ID is temporary, it will get replaced by an identifier in the form cfgXXXXXX once the configuration is saved by the remote ubus UCI api.
| Name | Type | Description |
|---|---|---|
conf | string | The configuration to generate the new section ID for. |
A newly generated, unique section ID in the form newXXXXXX where X denotes a hexadecimal digit.
- Type:
- string
get(conf, sid, optopt) → {null|string|Array.<string>|LuCI.uci.SectionObject}
Gets the value of the given option within the specified section of the given configuration or the entire section object if the option name is omitted.
| Name | Type | Attributes | Description |
|---|---|---|---|
conf | string | The name of the configuration to read the value from. | |
sid | string | The name or ID of the section to read. | |
opt | string | <optional> | The option name to read the value from. If the option name is omitted or |
- Returns a string containing the option value in case of a plain UCI option.
- Returns an array of strings containing the option values in case of
optionpointing to an UCI list. - Returns a
section objectif theoptionargument has been omitted or isnull. - Returns
nullif the config, section or option has not been found or if the corresponding configuration is not loaded.
- Type:
- null |
string | Array.<string> | LuCI. uci. SectionObject
get_bool(conf, type, optopt) → {boolean}
A special case of get that always returns either true or false.
Many configuration files contain boolean settings, such as enabled or advanced_mode, where there is no consistent definition for the values. This function allows users to enter any of the values "yes", "on", "true", "enabled" or 1 in their config files and we return the expected boolean result.
Character case is not significant, so for example, any of "YES", "Yes" or "yes" will be interpreted as a true value.
| Name | Type | Attributes | Description |
|---|---|---|---|
conf | string | The name of the configuration to read. | |
type | string | The section type to read. | |
opt | string | <optional> | The option name from which to read the value. If the option name is omitted or |
- Returns boolean
trueif the configuration value is defined and looks like a true value, otherwise returnsfalse.
See the Developers Guide for more.
- Type:
- boolean
get_first(conf, typeopt, optopt) → {null|string|Array.<string>|LuCI.uci.SectionObject}
Gets the value of the given option or the entire section object of the first found section of the specified type or the first found section of the entire configuration if no type is specified.
| Name | Type | Attributes | Description |
|---|---|---|---|
conf | string | The name of the configuration to read the value from. | |
type | string | <optional> | The type of the first section to find. If it is |
opt | string | <optional> | The option name to read the value from. If the option name is omitted or |
- Returns a string containing the option value in case of a plain UCI option.
- Returns an array of strings containing the option values in case of
optionpointing to an UCI list. - Returns a
section objectif theoptionargument has been omitted or isnull. - Returns
nullif the config, section or option has not been found or if the corresponding configuration is not loaded.
- Type:
- null |
string | Array.<string> | LuCI. uci. SectionObject
load(packages) → {Promise.<Array.<string>>}
Loads the given UCI configurations from the remote ubus api.
Loaded configurations are cached and only loaded once. Subsequent load operations of the same configurations will return the cached data.
To force reloading a configuration, it has to be unloaded with uci.unload() first.
| Name | Type | Description |
|---|---|---|
packages | string | | The name of the configuration or an array of configuration names to load. |
Returns a promise resolving to the names of the configurations that have been successfully loaded.
- Type:
- Promise.<Array.<string>>
move(conf, sid1, sid2opt, afteropt) → {boolean}
Move the first specified section within the given configuration before or after the second specified section.
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
conf | string | The configuration to move the section within. | ||
sid1 | string | The ID of the section to move within the configuration. | ||
sid2 | string | <optional> | The ID of the target section for the move operation. If the When the | |
after | boolean | <optional> | false | When If |
Returns true when the section was successfully moved, or false when either the section specified by sid1 or by sid2 is not found.
- Type:
- boolean
remove(conf, sid)
Removes the section with the given ID from the given configuration.
| Name | Type | Description |
|---|---|---|
conf | string | The name of the configuration to remove the section from. |
sid | string | The ID of the section to remove. |
resolveSID(conf, sid) → {string|null}
Resolves a given section ID in extended notation to the internal section ID value.
| Name | Type | Description |
|---|---|---|
conf | string | The configuration to resolve the section ID for. |
sid | string | The section ID to resolve. If the ID is in the form |
Returns the resolved section ID or the original given ID if it was not in extended notation. Returns null when an extended ID could not be resolved to existing section ID.
- Type:
- string |
null
save() → {Array.<string>}
Submits all local configuration changes to the remove ubus api, adds, removes and reorders remote sections as needed and reloads all loaded configurations to resynchronize the local state with the remote configuration values.
Returns a promise resolving to an array of configuration names which have been reloaded by the save operation.
- Type:
- Array.<string>
sections(conf, typeopt, cbopt) → {Array.<LuCI.uci.SectionObject>}
Enumerates the sections of the given configuration, optionally filtered by type.
| Name | Type | Attributes | Description |
|---|---|---|---|
conf | string | The name of the configuration to enumerate the sections for. | |
type | string | <optional> | Enumerate only sections of the given type. If omitted, enumerate all sections. |
cb | LuCI. | <optional> | An optional callback to invoke for each enumerated section. |
Returns a sorted array of the section objects within the given configuration, filtered by type, if a type has been specified.
- Type:
- Array.<LuCI.uci.SectionObject>
set(conf, sid, opt, val)
Sets the value of the given option within the specified section of the given configuration.
If either config, section or option is null, or if option begins with a dot, the function will do nothing.
| Name | Type | Description |
|---|---|---|
conf | string | The name of the configuration to set the option value in. |
sid | string | The name or ID of the section to set the option value in. |
opt | string | The option name to set the value for. |
val | null | | The option value to set. If the value is |
set_first(conf, typeopt, opt, val) → {null}
Sets the value of the given option within the first found section of the given configuration matching the specified type or within the first section of the entire config when no type has is specified.
If either config, type or option is null, or if option begins with a dot, the function will do nothing.
| Name | Type | Attributes | Description |
|---|---|---|---|
conf | string | The name of the configuration to set the option value in. | |
type | string | <optional> | The type of the first section to find. If it is |
opt | string | The option name to set the value for. | |
val | null | | The option value to set. If the value is |
- Type:
- null
unload(packages)
Unloads the given UCI configurations from the local cache.
| Name | Type | Description |
|---|---|---|
packages | string | | The name of the configuration or an array of configuration names to unload. |
unset(conf, sid, opt) → {null}
Remove the given option within the specified section of the given configuration.
This function is a convenience wrapper around uci.set(config, section, option, null).
| Name | Type | Description |
|---|---|---|
conf | string | The name of the configuration to remove the option from. |
sid | string | The name or ID of the section to remove the option from. |
opt | string | The name of the option to remove. |
- Type:
- null
unset_first(conf, typeopt, opt) → {null}
Removes the given option within the first found section of the given configuration matching the specified type or within the first section of the entire config when no type has is specified.
This function is a convenience wrapper around uci.set_first(config, type, option, null).
| Name | Type | Attributes | Description |
|---|---|---|---|
conf | string | The name of the configuration to set the option value in. | |
type | string | <optional> | The type of the first section to find. If it is |
opt | string | The option name to set the value for. |
- Type:
- null
Type Definitions
ChangeRecord
An UCI change record is a plain array containing the change operation name as first element, the affected section ID as second argument and an optional third and fourth argument whose meanings depend on the operation.
- Array.<string>
| Name | Type | Attributes | Description |
|---|---|---|---|
operation | string | The operation name - may be one of | |
section_id | string | The section ID targeted by the operation. | |
parameter | string | The meaning of the third element depends on the operation.
| |
value | string | <optional> | The meaning of the fourth element depends on the operation.
|
SectionObject
A section object represents the options and their corresponding values enclosed within a configuration section, as well as some additional meta data such as sort indexes and internal ID.
Any internal metadata fields are prefixed with a dot which isn't an allowed character for normal option names.
- Object.<string, (boolean|number|string|Array.<string>)>
| Name | Type | Description |
|---|---|---|
".anonymous" | boolean | The |
".index" | number | The |
".name" | string | The |
".type" | string | The |
* | string | | A section object may contain an arbitrary number of further properties representing the uci option enclosed in the section. All option property names will be in the form |
sections(section, sid)
The sections callback is invoked for each section found within the given configuration and receives the section object and its associated name as arguments.
| Name | Type | Description |
|---|---|---|
section | LuCI. | The section object. |
sid | string | The name or ID of the section. |