Class: uci

LuCI.uci

The LuCI.uci class utilizes LuCI.rpc to declare low level remote UCI ubus procedures and implements a local caching and data manipulation layer on top to allow for synchroneous operations on UCI configuration data.

Source:

Methods

add(config, type, nameopt) → {string}

Adds a new section of the given type to the given configuration, optionally named according to the given name.

Parameters:
Name Type Attributes Description
config 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.

Source:
Returns:

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.

Parameters:
Name Type Attributes Default Description
timeout number <optional>
10

Override the confirmation timeout after which a rollback is triggered.

Source:
Returns:

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.

Source:
Returns:

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>>>

createSID(config) → {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.

Parameters:
Name Type Description
config string

The configuration to generate the new section ID for.

Source:
Returns:

A newly generated, unique section ID in the form newXXXXXX where X denotes a hexadecimal digit.

Type
string

get(config, sid, optionopt) → {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.

Parameters:
Name Type Attributes Description
config string

The name of the configuration to read the value from.

sid string

The name or ID of the section to read.

option string <optional>

The option name to read the value from. If the option name is omitted or null, the entire section is returned instead.

Source:
Returns:
  • 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 option pointing to an UCI list.
  • Returns a section object if the option argument has been omitted or is null.
  • Returns null if 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_first(config, typeopt, optionopt) → {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 specfied.

Parameters:
Name Type Attributes Description
config 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 null, the first section of the entire config is read, otherwise the first section matching the given type.

option string <optional>

The option name to read the value from. If the option name is omitted or null, the entire section is returned instead.

Source:
Returns:
  • 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 option pointing to an UCI list.
  • Returns a section object if the option argument has been omitted or is null.
  • Returns null if 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(config) → {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.

Parameters:
Name Type Description
config string | Array.<string>

The name of the configuration or an array of configuration names to load.

Source:
Returns:

Returns a promise resolving to the names of the configurations that have been successfully loaded.

Type
Promise.<Array.<string>>

move(config, sid1, sid2opt, afteropt) → {boolean}

Move the first specified section within the given configuration before or after the second specified section.

Parameters:
Name Type Attributes Default Description
config 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 after argument is false or not specified, the section named by sid1 will be moved before this target section, if the after argument is true, the sid1 section will be moved after this section.

When the sid2 argument is null, the section specified by sid1 is moved to the end of the configuration.

after boolean <optional>
false

When true, the section sid1 is moved after the section sid2, when false, the section sid1 is moved before sid2.

If sid2 is null, then this parameter has no effect and the section sid1 is moved to the end of the configuration instead.

Source:
Returns:

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(config, sid)

Removes the section with the given ID from the given configuration.

Parameters:
Name Type Description
config string

The name of the configuration to remove the section from.

sid string

The ID of the section to remove.

Source:

resolveSID(config, sid) → {string|null}

Resolves a given section ID in extended notation to the internal section ID value.

Parameters:
Name Type Description
config string

The configuration to resolve the section ID for.

sid string

The section ID to resolve. If the ID is in the form @typename[#], it will get resolved to an internal anonymous ID in the forms cfgXXXXXX/newXXXXXX or to the name of a section in case it points to a named section. When the given ID is not in extended notation, it will be returned as-is.

Source:
Returns:

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.

Source:
Returns:

Returns a promise resolving to an array of configuration names which have been reloaded by the save operation.

Type
Array.<string>

sections(config, typeopt, cbopt) → {Array.<LuCI.uci.SectionObject>}

Enumerates the sections of the given configuration, optionally filtered by type.

Parameters:
Name Type Attributes Description
config 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.uci~sectionsFn <optional>

An optional callback to invoke for each enumerated section.

Source:
Returns:

Returns a sorted array of the section objects within the given configuration, filtered by type of a type has been specified.

Type
Array.<LuCI.uci.SectionObject>

set(config, sid, option, value)

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.

Parameters:
Name Type Description
config 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.

option string

The option name to set the value for.

value null | string | Array.<string>

The option value to set. If the value is null or an empty string, the option will be removed, otherwise it will be set or overwritten with the given value.

Source:

set_first(config, typeopt, option, value)

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.

Parameters:
Name Type Attributes Description
config 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 null, the first section of the entire config is written to, otherwise the first section matching the given type is used.

option string

The option name to set the value for.

value null | string | Array.<string>

The option value to set. If the value is null or an empty string, the option will be removed, otherwise it will be set or overwritten with the given value.

Source:

unload(config)

Unloads the given UCI configurations from the local cache.

Parameters:
Name Type Description
config string | Array.<string>

The name of the configuration or an array of configuration names to unload.

Source:

unset(config, sid, option)

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).

Parameters:
Name Type Description
config 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.

option string

The name of the option to remove.

Source:

unset_first(config, typeopt, option)

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).

Parameters:
Name Type Attributes Description
config 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 null, the first section of the entire config is written to, otherwise the first section matching the given type is used.

option string

The option name to set the value for.

Source:

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.

Type:
  • Array.<string>
Properties:
Name Type Description
0 string

The operation name - may be one of add, set, remove, order, list-add, list-del or rename.

1 string

The section ID targeted by the operation.

2 string

The meaning of the third element depends on the operation.

  • For add it is type of the section that has been added
  • For set it either is the option name if a fourth element exists, or the type of a named section which has been added when the change entry only contains three elements.
  • For remove it contains the name of the option that has been removed.
  • For order it specifies the new sort index of the section.
  • For list-add it contains the name of the list option a new value has been added to.
  • For list-del it contains the name of the list option a value has been removed from.
  • For rename it contains the name of the option that has been renamed if a fourth element exists, else it contains the new name a section has been renamed to if the change entry only contains three elements.
4 string

The meaning of the fourth element depends on the operation.

  • For set it is the value an option has been set to.
  • For list-add it is the new value that has been added to a list option.
  • For rename it is the new name of an option that has been renamed.
Source:

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 is isn't an allowed character for normal option names.

Type:
  • Object.<string, (boolean|number|string|Array.<string>)>
Properties:
Name Type Description
.anonymous boolean

The .anonymous property specifies whether the configuration is anonymous (true) or named (false).

.index number

The .index property specifes the sort order of the section.

.name string

The .name property holds the name of the section object. It may be either an anonymous ID in the form cfgXXXXXX or newXXXXXX with X being a hexadecimal digit or a string holding the name of the section.

.type string

The .type property contains the type of the corresponding uci section.

* string | Array.<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 [A-Za-z0-9_]+ and either contain a string value or an array of strings, in case the underlying option is an UCI list.

Source:

sectionsFn(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.

Parameters:
Name Type Description
section LuCI.uci.SectionObject

The section object.

sid string

The name or ID of the section.

Source: