Methods
-
Adds a new section of the given type to the given configuration, optionally named according to the given name.
Name Type Description confstring The name of the configuration to add the section to.
typestring The type of the section to add.
namestring optional The name of the section to add. If the name is omitted, an anonymous section will be added instead.
Returns:
Type Description string Returns the section ID of the newly added section which is equivalent to the given name for non-anonymous sections. -
Instructs the remote
ubusUCI api to commit all saved changes with rollback protection and attempts to confirm the pending commit operation to cancel the rollback timer.Name Type Default Description timeoutnumber 10 optional Override the confirmation timeout after which a rollback is triggered.
Returns:
Type Description Promise.<number> Returns a promise resolving/rejecting with the ubusRPC status code. -
changes(){Promise.<Object.<string, Array.<LuCI.uci.ChangeRecord>>>}
-
Fetches uncommitted UCI changes from the remote
ubusRPC api.Returns:
Type Description Promise.<Object.<string, Array.<LuCI.uci.ChangeRecord>>> Returns a promise resolving to an object containing the configuration names as keys and arrays of related change records as values. -
Clones an existing section of the given type to the given configuration, optionally named according to the given name.
Name Type Description confstring The name of the configuration into which to clone the section.
typestring The type of the section to clone.
srcsidstring The source section id to clone.
put_nextboolean optional Whether to put the cloned item next (true) or last (false: default).
namestring optional The name of the new cloned section. If the name is omitted, an anonymous section will be created instead.
Returns:
Type Description string Returns the section ID of the newly cloned section which is equivalent to the given name for non-anonymous sections. -
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
cfgXXXXXXonce the configuration is saved by the remoteubusUCI api.Name Type Description confstring The configuration to generate the new section ID for.
Returns:
Type Description string A newly generated, unique section ID in the form newXXXXXXwhereXdenotes a hexadecimal digit. -
get(conf, sid, opt){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 Description confstring The name of the configuration to read the value from.
sidstring The name or ID of the section to read.
optstring optional The option name to read the value from. If the option name is omitted or
null, the entire section is returned instead.Returns:
Type Description null | string | Array.<string> | LuCI.uci.SectionObject - 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.
-
A special case of
getthat always returns eithertrueorfalse.Many configuration files contain boolean settings, such as
enabledoradvanced_mode, where there is no consistent definition for the values. This function allows users to enter any of the values"yes","on","true"or1in 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
truevalue.Name Type Description confstring The name of the configuration to read.
sidstring The name or ID of the section to read.
optstring optional The option name from which to read the value. If the option name is omitted or
null, the valuefalseis returned.Returns:
Type Description boolean - Returns boolean
trueif the configuration value is defined and looks like a true value, otherwise returnsfalse.
- Returns boolean
-
get_first(conf, type, opt){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 Description confstring The name of the configuration to read the value from.
typestring 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.optstring optional The option name to read the value from. If the option name is omitted or
null, the entire section is returned instead.Returns:
Type Description null | string | Array.<string> | LuCI.uci.SectionObject - 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.
-
Loads the given UCI configurations from the remote
ubusapi.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 packagesstring | Array.<string> The name of the configuration or an array of configuration names to load.
Returns:
Type Description Promise.<Array.<string>> Returns a promise resolving to the names of the configurations that have been successfully loaded. -
Move the first specified section within the given configuration before or after the second specified section.
Name Type Default Description confstring The configuration to move the section within.
sid1string The ID of the section to move within the configuration.
sid2string optional The ID of the target section for the move operation. If the
afterargument isfalseor not specified, the section named bysid1will be moved before this target section, if theafterargument istrue, thesid1section will be moved after this section.When the
sid2argument isnull, the section specified bysid1is moved to the end of the configuration.afterboolean false optional When
true, the sectionsid1is moved after the sectionsid2, whenfalse, the sectionsid1is moved beforesid2.If
sid2is null, then this parameter has no effect and the sectionsid1is moved to the end of the configuration instead.Returns:
Type Description boolean Returns truewhen the section was successfully moved, orfalsewhen either the section specified bysid1or bysid2is not found. -
Removes the section with the given ID from the given configuration.
Name Type Description confstring The name of the configuration to remove the section from.
sidstring The ID of the section to remove.
-
Resolves a given section ID in extended notation to the internal section ID value.
Name Type Description confstring The configuration to resolve the section ID for.
sidstring The section ID to resolve. If the ID is in the form
@typename[#], it will get resolved to an internal anonymous ID in the formscfgXXXXXX/newXXXXXXor 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.Returns:
Type Description string | null Returns the resolved section ID or the original given ID if it was not in extended notation. Returns nullwhen an extended ID could not be resolved to existing section ID. -
Submits all local configuration changes to the remove
ubusapi, adds, removes and reorders remote sections as needed and reloads all loaded configurations to resynchronize the local state with the remote configuration values.Returns:
Type Description Array.<string> Returns a promise resolving to an array of configuration names which have been reloaded by the save operation. -
sections(conf, type, cb){Array.<LuCI.uci.SectionObject>}
-
Enumerates the sections of the given configuration, optionally filtered by type.
Name Type Description confstring The name of the configuration to enumerate the sections for.
typestring optional Enumerate only sections of the given type. If omitted, enumerate all sections.
cbLuCI.uci~sectionsFn optional An optional callback to invoke for each enumerated section.
Returns:
Type Description Array.<LuCI.uci.SectionObject> Returns a sorted array of the section objects within the given configuration, filtered by type, if a type has been specified. -
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
optionbegins with a dot, the function will do nothing.Name Type Description confstring The name of the configuration to set the option value in.
sidstring The name or ID of the section to set the option value in.
optstring The option name to set the value for.
valnull | string | Array.<string> The option value to set. If the value is
nullor an empty string, the option will be removed, otherwise it will be set or overwritten with the given 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
optionbegins with a dot, the function will do nothing.Name Type Description confstring The name of the configuration to set the option value in.
typestring 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.optstring The option name to set the value for.
valnull | string | Array.<string> The option value to set. If the value is
nullor an empty string, the option will be removed, otherwise it will be set or overwritten with the given value. -
Unloads the given UCI configurations from the local cache.
Name Type Description packagesstring | Array.<string> The name of the configuration or an array of configuration names to unload.
-
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 confstring The name of the configuration to remove the option from.
sidstring The name or ID of the section to remove the option from.
optstring The name of the option to remove.
-
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 Description confstring The name of the configuration to set the option value in.
typestring 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.optstring The option name to set the value for.
Type Definitions
-
LuCI.uci.ChangeRecordArray.<string>
-
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.
- For
addit is type of the section that has been added - For
setit 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
removeit contains the name of the option that has been removed. - For
orderit specifies the new sort index of the section. - For
list-addit contains the name of the list option a new value has been added to. - For
list-delit contains the name of the list option a value has been removed from. - For
renameit 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. - For
setit is the value an option has been set to. - For
list-addit is the new value that has been added to a list option. - For
renameit is the new name of an option that has been renamed.
Properties:
Name Type Description 0string The operation name - may be one of
add,set,remove,order,list-add,list-delorrename.1string The section ID targeted by the operation.
2string The meaning of the third element depends on the operation.
4string The meaning of the fourth element depends on the operation.
- For
-
LuCI.uci.SectionObjectObject.<string, (boolean|number|string|Array.<string>)>
-
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.
Properties:
Name Type Description .anonymousboolean The
.anonymousproperty specifies whether the configuration is anonymous (true) or named (false)..indexnumber The
.indexproperty specifies the sort order of the section..namestring The
.nameproperty holds the name of the section object. It may be either an anonymous ID in the formcfgXXXXXXornewXXXXXXwithXbeing a hexadecimal digit or a string holding the name of the section..typestring The
.typeproperty 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. -
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 sectionLuCI.uci.SectionObject The section object.
sidstring The name or ID of the section.