luci/applications/luci-app-example
Hosted Weblate 9068c65ca1 Translated using Weblate (Swedish)
Currently translated at 93.2% (55 of 59 strings)

Translation: OpenWrt/LuCI/applications/nft-qos
Translate-URL: https://hosted.weblate.org/projects/openwrt/luciapplicationsnft-qos/sv/

Translated using Weblate (Swedish)

Currently translated at 100.0% (38 of 38 strings)

Translation: OpenWrt/LuCI/applications/advanced-reboot
Translate-URL: https://hosted.weblate.org/projects/openwrt/luciapplicationsadvanced-reboot/sv/

Translated using Weblate (Swedish)

Currently translated at 5.0% (2 of 40 strings)

Translation: OpenWrt/LuCI/applications/cloudflared
Translate-URL: https://hosted.weblate.org/projects/openwrt/luciapplicationscloudflared/sv/

Translated using Weblate (Swedish)

Currently translated at 21.2% (7 of 33 strings)

Translation: OpenWrt/LuCI/applications/v2raya
Translate-URL: https://hosted.weblate.org/projects/openwrt/luciapplicationsv2raya/sv/

Translated using Weblate (Swedish)

Currently translated at 2.0% (1 of 48 strings)

Translation: OpenWrt/LuCI/applications/openwisp
Translate-URL: https://hosted.weblate.org/projects/openwrt/luciapplicationsopenwisp/sv/

Translated using Weblate (Swedish)

Currently translated at 4.3% (2 of 46 strings)

Translation: OpenWrt/LuCI/applications/xfrpc
Translate-URL: https://hosted.weblate.org/projects/openwrt/luciapplicationsxfrpc/sv/

Translated using Weblate (Swedish)

Currently translated at 5.8% (1 of 17 strings)

Translation: OpenWrt/LuCI/applications/eoip
Translate-URL: https://hosted.weblate.org/projects/openwrt/luciapplicationseoip/sv/

Translated using Weblate (Swedish)

Currently translated at 27.5% (11 of 40 strings)

Translation: OpenWrt/LuCI/applications/example
Translate-URL: https://hosted.weblate.org/projects/openwrt/luciapplicationsexample/sv/

Translated using Weblate (Swedish)

Currently translated at 3.0% (2 of 66 strings)

Translation: OpenWrt/LuCI/applications/sshtunnel
Translate-URL: https://hosted.weblate.org/projects/openwrt/luciapplicationssshtunnel/sv/

Translated using Weblate (Swedish)

Currently translated at 3.4% (3 of 88 strings)

Translation: OpenWrt/LuCI/applications/mosquitto
Translate-URL: https://hosted.weblate.org/projects/openwrt/luciapplicationsmosquitto/sv/

Translated using Weblate (Swedish)

Currently translated at 21.0% (4 of 19 strings)

Translation: OpenWrt/LuCI/applications/irqbalance
Translate-URL: https://hosted.weblate.org/projects/openwrt/luciapplicationsirqbalance/sv/

Translated using Weblate (Swedish)

Currently translated at 3.0% (6 of 198 strings)

Translation: OpenWrt/LuCI/applications/smartdns
Translate-URL: https://hosted.weblate.org/projects/openwrt/luciapplicationssmartdns/sv/

Translated using Weblate (Swedish)

Currently translated at 51.5% (17 of 33 strings)

Translation: OpenWrt/LuCI/applications/alist
Translate-URL: https://hosted.weblate.org/projects/openwrt/luciapplicationsalist/sv/

Translated using Weblate (Swedish)

Currently translated at 95.0% (19 of 20 strings)

Translated using Weblate (Swedish)

Currently translated at 52.9% (54 of 102 strings)

Translated using Weblate (Swedish)

Currently translated at 32.4% (764 of 2353 strings)

Translation: OpenWrt/LuCI/modules/luci-base
Translate-URL: https://hosted.weblate.org/projects/openwrt/luci/sv/

Translated using Weblate (Portuguese)

Currently translated at 60.0% (24 of 40 strings)

Translation: OpenWrt/LuCI/applications/cloudflared
Translate-URL: https://hosted.weblate.org/projects/openwrt/luciapplicationscloudflared/pt/

Translated using Weblate (Portuguese)

Currently translated at 27.2% (9 of 33 strings)

Translation: OpenWrt/LuCI/applications/v2raya
Translate-URL: https://hosted.weblate.org/projects/openwrt/luciapplicationsv2raya/pt/

Translated using Weblate (Portuguese)

Currently translated at 2.0% (1 of 48 strings)

Translation: OpenWrt/LuCI/applications/openwisp
Translate-URL: https://hosted.weblate.org/projects/openwrt/luciapplicationsopenwisp/pt/

Translated using Weblate (Portuguese)

Currently translated at 10.8% (5 of 46 strings)

Translation: OpenWrt/LuCI/applications/xfrpc
Translate-URL: https://hosted.weblate.org/projects/openwrt/luciapplicationsxfrpc/pt/

Translated using Weblate (Portuguese)

Currently translated at 100.0% (19 of 19 strings)

Translation: OpenWrt/LuCI/applications/irqbalance
Translate-URL: https://hosted.weblate.org/projects/openwrt/luciapplicationsirqbalance/pt/

Translated using Weblate (Portuguese)

Currently translated at 2.0% (4 of 198 strings)

Translation: OpenWrt/LuCI/applications/smartdns
Translate-URL: https://hosted.weblate.org/projects/openwrt/luciapplicationssmartdns/pt/

Translated using Weblate (Portuguese)

Currently translated at 93.9% (31 of 33 strings)

Translation: OpenWrt/LuCI/applications/alist
Translate-URL: https://hosted.weblate.org/projects/openwrt/luciapplicationsalist/pt/

Translated using Weblate (Portuguese)

Currently translated at 100.0% (164 of 164 strings)

Translation: OpenWrt/LuCI/applications/adblock-fast
Translate-URL: https://hosted.weblate.org/projects/openwrt/luciapplicationsadblock-fast/pt/

Translated using Weblate (Portuguese)

Currently translated at 100.0% (16 of 16 strings)

Translation: OpenWrt/LuCI/applications/hd-idle
Translate-URL: https://hosted.weblate.org/projects/openwrt/luciapplicationshd-idle/pt/

Translated using Weblate (Portuguese)

Currently translated at 98.3% (240 of 244 strings)

Translation: OpenWrt/LuCI/applications/banip
Translate-URL: https://hosted.weblate.org/projects/openwrt/luciapplicationsbanip/pt/

Translated using Weblate (Portuguese)

Currently translated at 100.0% (197 of 197 strings)

Translation: OpenWrt/LuCI/applications/ddns
Translate-URL: https://hosted.weblate.org/projects/openwrt/luciapplicationsddns/pt/

Translated using Weblate (Portuguese)

Currently translated at 100.0% (102 of 102 strings)

Translated using Weblate (Portuguese)

Currently translated at 100.0% (46 of 46 strings)

Translated using Weblate (Portuguese)

Currently translated at 100.0% (183 of 183 strings)

Translated using Weblate (Portuguese)

Currently translated at 99.6% (279 of 280 strings)

Translated using Weblate (Portuguese)

Currently translated at 100.0% (376 of 376 strings)

Translated using Weblate (Portuguese)

Currently translated at 100.0% (25 of 25 strings)

Translated using Weblate (Chinese (Simplified))

Currently translated at 100.0% (21 of 21 strings)

Translation: OpenWrt/LuCI/applications/tor
Translate-URL: https://hosted.weblate.org/projects/openwrt/luciapplicationstor/zh_Hans/

Translated using Weblate (Polish)

Currently translated at 100.0% (21 of 21 strings)

Translation: OpenWrt/LuCI/applications/tor
Translate-URL: https://hosted.weblate.org/projects/openwrt/luciapplicationstor/pl/

Translated using Weblate (Chinese (Simplified))

Currently translated at 100.0% (164 of 164 strings)

Translation: OpenWrt/LuCI/applications/adblock-fast
Translate-URL: https://hosted.weblate.org/projects/openwrt/luciapplicationsadblock-fast/zh_Hans/

Translated using Weblate (Polish)

Currently translated at 100.0% (164 of 164 strings)

Translation: OpenWrt/LuCI/applications/adblock-fast
Translate-URL: https://hosted.weblate.org/projects/openwrt/luciapplicationsadblock-fast/pl/

Translated using Weblate (Chinese (Simplified))

Currently translated at 100.0% (194 of 194 strings)

Translated using Weblate (Polish)

Currently translated at 100.0% (194 of 194 strings)

Translated using Weblate (Chinese (Simplified))

Currently translated at 100.0% (83 of 83 strings)

Translated using Weblate (Polish)

Currently translated at 100.0% (83 of 83 strings)

Translated using Weblate (Russian)

Currently translated at 100.0% (21 of 21 strings)

Translation: OpenWrt/LuCI/applications/tor
Translate-URL: https://hosted.weblate.org/projects/openwrt/luciapplicationstor/ru/

Translated using Weblate (Russian)

Currently translated at 100.0% (164 of 164 strings)

Translation: OpenWrt/LuCI/applications/adblock-fast
Translate-URL: https://hosted.weblate.org/projects/openwrt/luciapplicationsadblock-fast/ru/

Translated using Weblate (Lithuanian)

Currently translated at 100.0% (83 of 83 strings)

Translated using Weblate (Lithuanian)

Currently translated at 50.5% (45 of 89 strings)

Translation: OpenWrt/LuCI/applications/frpc
Translate-URL: https://hosted.weblate.org/projects/openwrt/luciapplicationsfrpc/lt/

Translated using Weblate (Lithuanian)

Currently translated at 48.4% (32 of 66 strings)

Translation: OpenWrt/LuCI/applications/frps
Translate-URL: https://hosted.weblate.org/projects/openwrt/luciapplicationsfrps/lt/

Translated using Weblate (Lithuanian)

Currently translated at 98.5% (2320 of 2355 strings)

Translation: OpenWrt/LuCI/modules/luci-base
Translate-URL: https://hosted.weblate.org/projects/openwrt/luci/lt/

Translated using Weblate (Russian)

Currently translated at 100.0% (194 of 194 strings)

Translated using Weblate (Russian)

Currently translated at 100.0% (83 of 83 strings)

Translated using Weblate (Lithuanian)

Currently translated at 60.3% (117 of 194 strings)

Translated using Weblate (Lithuanian)

Currently translated at 61.1% (118 of 193 strings)

Translated using Weblate (Swedish)

Currently translated at 1.1% (1 of 88 strings)

Translation: OpenWrt/LuCI/applications/mosquitto
Translate-URL: https://hosted.weblate.org/projects/openwrt/luciapplicationsmosquitto/sv/

Translated using Weblate (Italian)

Currently translated at 88.2% (143 of 162 strings)

Translation: OpenWrt/LuCI/applications/adblock-fast
Translate-URL: https://hosted.weblate.org/projects/openwrt/luciapplicationsadblock-fast/it/

Translated using Weblate (Lithuanian)

Currently translated at 58.0% (112 of 193 strings)

Translated using Weblate (Italian)

Currently translated at 21.5% (31 of 144 strings)

Translation: OpenWrt/LuCI/applications/https-dns-proxy
Translate-URL: https://hosted.weblate.org/projects/openwrt/luciapplicationshttps-dns-proxy/it/

Translated using Weblate (Italian)

Currently translated at 83.3% (20 of 24 strings)

Translation: OpenWrt/LuCI/applications/lxc
Translate-URL: https://hosted.weblate.org/projects/openwrt/luciapplicationslxc/it/

Translated using Weblate (Italian)

Currently translated at 73.0% (19 of 26 strings)

Translation: OpenWrt/LuCI/applications/dcwapd
Translate-URL: https://hosted.weblate.org/projects/openwrt/luciapplicationsdcwapd/it/

Translated using Weblate (Italian)

Currently translated at 99.5% (243 of 244 strings)

Translation: OpenWrt/LuCI/applications/banip
Translate-URL: https://hosted.weblate.org/projects/openwrt/luciapplicationsbanip/it/

Translated using Weblate (Italian)

Currently translated at 100.0% (51 of 51 strings)

Translated using Weblate (Italian)

Currently translated at 83.7% (31 of 37 strings)

Translated using Weblate (Italian)

Currently translated at 68.9% (40 of 58 strings)

Translated using Weblate (Lithuanian)

Currently translated at 64.7% (11 of 17 strings)

Translation: OpenWrt/LuCI/applications/omcproxy
Translate-URL: https://hosted.weblate.org/projects/openwrt/luciapplicationsomcproxy/lt/

Translated using Weblate (Lithuanian)

Currently translated at 62.8% (71 of 113 strings)

Translated using Weblate (Lithuanian)

Currently translated at 93.2% (55 of 59 strings)

Translation: OpenWrt/LuCI/applications/nft-qos
Translate-URL: https://hosted.weblate.org/projects/openwrt/luciapplicationsnft-qos/lt/

Translated using Weblate (Lithuanian)

Currently translated at 100.0% (20 of 20 strings)

Translation: OpenWrt/LuCI/applications/ltqtapi
Translate-URL: https://hosted.weblate.org/projects/openwrt/luciapplicationsltqtapi/lt/

Translated using Weblate (Lithuanian)

Currently translated at 53.5% (98 of 183 strings)

Translated using Weblate (Lithuanian)

Currently translated at 100.0% (28 of 28 strings)

Translation: OpenWrt/LuCI/applications/acl
Translate-URL: https://hosted.weblate.org/projects/openwrt/luciapplicationsacl/lt/

Translated using Weblate (Polish)

Currently translated at 100.0% (2355 of 2355 strings)

Translation: OpenWrt/LuCI/modules/luci-base
Translate-URL: https://hosted.weblate.org/projects/openwrt/luci/pl/

Translated using Weblate (Russian)

Currently translated at 100.0% (2355 of 2355 strings)

Translation: OpenWrt/LuCI/modules/luci-base
Translate-URL: https://hosted.weblate.org/projects/openwrt/luci/ru/

Translated using Weblate (Chinese (Simplified))

Currently translated at 100.0% (2355 of 2355 strings)

Translation: OpenWrt/LuCI/modules/luci-base
Translate-URL: https://hosted.weblate.org/projects/openwrt/luci/zh_Hans/

Translated using Weblate (Italian)

Currently translated at 99.8% (2352 of 2355 strings)

Translation: OpenWrt/LuCI/modules/luci-base
Translate-URL: https://hosted.weblate.org/projects/openwrt/luci/it/

Co-authored-by: Džiugas J <dziugas1959@hotmail.com>
Co-authored-by: Hosted Weblate <hosted@weblate.org>
Co-authored-by: Kristoffer Grundström <swedishsailfishosuser@tutanota.com>
Co-authored-by: Matthaiks <kitynska@gmail.com>
Co-authored-by: Paul Dee <itsascambutmailmeanyway@gmail.com>
Co-authored-by: Random <random-r@users.noreply.hosted.weblate.org>
Co-authored-by: SKAL <sir_kalot@yahoo.it>
Co-authored-by: ssantos <ssantos@web.de>
Co-authored-by: st7105 <st7105@gmail.com>
Co-authored-by: 大王叫我来巡山 <hamburger2048@users.noreply.hosted.weblate.org>
Signed-off-by: Džiugas J <dziugas1959@hotmail.com>
Signed-off-by: Kristoffer Grundström <swedishsailfishosuser@tutanota.com>
Signed-off-by: Matthaiks <kitynska@gmail.com>
Signed-off-by: Paul Dee <itsascambutmailmeanyway@gmail.com>
Signed-off-by: Random <random-r@users.noreply.hosted.weblate.org>
Signed-off-by: SKAL <sir_kalot@yahoo.it>
Signed-off-by: ssantos <ssantos@web.de>
Signed-off-by: st7105 <st7105@gmail.com>
Signed-off-by: 大王叫我来巡山 <hamburger2048@users.noreply.hosted.weblate.org>
Translate-URL: https://hosted.weblate.org/projects/openwrt/luciapplicationsfirewall/pt/
Translate-URL: https://hosted.weblate.org/projects/openwrt/luciapplicationsminidlna/pt/
Translate-URL: https://hosted.weblate.org/projects/openwrt/luciapplicationsnatmap/sv/
Translate-URL: https://hosted.weblate.org/projects/openwrt/luciapplicationsolsr/lt/
Translate-URL: https://hosted.weblate.org/projects/openwrt/luciapplicationsolsr/pt/
Translate-URL: https://hosted.weblate.org/projects/openwrt/luciapplicationsopenvpn/lt/
Translate-URL: https://hosted.weblate.org/projects/openwrt/luciapplicationsopenvpn/pl/
Translate-URL: https://hosted.weblate.org/projects/openwrt/luciapplicationsopenvpn/ru/
Translate-URL: https://hosted.weblate.org/projects/openwrt/luciapplicationsopenvpn/zh_Hans/
Translate-URL: https://hosted.weblate.org/projects/openwrt/luciapplicationsopkg/lt/
Translate-URL: https://hosted.weblate.org/projects/openwrt/luciapplicationsopkg/pl/
Translate-URL: https://hosted.weblate.org/projects/openwrt/luciapplicationsopkg/ru/
Translate-URL: https://hosted.weblate.org/projects/openwrt/luciapplicationsopkg/zh_Hans/
Translate-URL: https://hosted.weblate.org/projects/openwrt/luciapplicationspolipo/it/
Translate-URL: https://hosted.weblate.org/projects/openwrt/luciapplicationsqos/pt/
Translate-URL: https://hosted.weblate.org/projects/openwrt/luciapplicationsradicale2/lt/
Translate-URL: https://hosted.weblate.org/projects/openwrt/luciapplicationsstatistics/pt/
Translate-URL: https://hosted.weblate.org/projects/openwrt/luciapplicationstransmission/pt/
Translate-URL: https://hosted.weblate.org/projects/openwrt/luciapplicationstransmission/sv/
Translate-URL: https://hosted.weblate.org/projects/openwrt/luciapplicationsupnp/it/
Translate-URL: https://hosted.weblate.org/projects/openwrt/luciapplicationswatchcat/it/
Translation: OpenWrt/LuCI/applications/firewall
Translation: OpenWrt/LuCI/applications/minidlna
Translation: OpenWrt/LuCI/applications/natmap
Translation: OpenWrt/LuCI/applications/olsr
Translation: OpenWrt/LuCI/applications/openvpn
Translation: OpenWrt/LuCI/applications/opkg
Translation: OpenWrt/LuCI/applications/polipo
Translation: OpenWrt/LuCI/applications/qos
Translation: OpenWrt/LuCI/applications/radicale2
Translation: OpenWrt/LuCI/applications/statistics
Translation: OpenWrt/LuCI/applications/transmission
Translation: OpenWrt/LuCI/applications/upnp
Translation: OpenWrt/LuCI/applications/watchcat
2024-02-16 21:52:28 +02:00
..
htdocs/luci-static/resources/view/example luci-app-example: Update with more documentation, more examples (#6503) 2023-12-04 22:12:28 +01:00
po Translated using Weblate (Swedish) 2024-02-16 21:52:28 +02:00
root luci-app-example: Update with more documentation, more examples (#6503) 2023-12-04 22:12:28 +01:00
BUILDING.md luci-app-example: improve docs formatting 2024-01-23 09:29:12 +02:00
Makefile luci-app-example: Update with more documentation, more examples (#6503) 2023-12-04 22:12:28 +01:00
README.md luci-app-example: improve docs formatting 2024-01-23 09:29:12 +02:00
structure.md luci-app-example: replace NBSP with a space 2024-01-23 09:29:12 +02:00
YAML.md luci-app-example: improve docs formatting 2024-01-23 09:29:12 +02:00

Example app for js based Luci

This app is meant to be a starting point for developing new LuCI apps using the modern JavaScript client-rendered approach. Previously the LuCI used a Lua server-side render approach which id deprecated now.

Installation

In all cases, you'll want to log out of the web interface and back in to force a cache refresh after installing the new package.

From git

To install the luci-app-example to your OpenWrt instance (assuming your OpenWRT instance is on 192.168.1.1):

scp -r root/* root@192.168.1.1:/
scp -r htdocs/* root@192.168.1.1:/www/
# execute the UCI defaults script to create the /etc/config/example
ssh root@192.168.1.1 "sh /etc/uci-defaults/80_example"

From packages

Install the app on your OpenWrt installation. This can be an actual router/device, or something like a QEMU virtual machine.

opkg install luci-app-example

Visit the web UI for the device/virtual machine where the package was installed. Log in to OpenWrt, and Example should be present in the navigation menu.

Application structure

See structure.md for details on how to lay out a LuCI application.

Code format

The LuCI Javascript code should be indented with tabs. js-beautify/jsbeautifier can help with this. The examples in this application were formatted with:

js-beautify -t -a -j -w 110 -r <filename>

Editing the code

You can either do direct editing on the device/virtual machine, or use something like sshfs to have remote access from your development computer.

By default, the code is minified by the build process, which makes editing it non-trivial. You can either change the build process, or just copy the file content from the git repository and replace the content on disk.

Javascript code can be found on the device/virtual machine in /www/luci-static/resources/view/example/.

form.js

This is a JS view that uses the form.Map approach to providing a form that can change the configuration. It relies on UCI access, and the relevant ACL declarations are in root/usr/share/rpcd/acl.d/luci-app-example.json.

The declarations are luci-app-example > read > uci and luci-app-example > write > uci. Note that for both permissions, the node name "example" is provided as a list argument to the interface type (uci); this maps to /etc/config/example.

Since form.Map and form.JSONMap create Promises, you cannot embed them inside a E()-built structure.

htmlview.js

This is a read-only view that uses E() to create DOM nodes.

Data is fetched via the function defined in load() - these loads are done as Promises, with the promise results stored in an array. Multiple load functions results are available in the array, and can be accessed via a single argument passed to the render() function.

This code relies on the same ACL grants as form.js.

The signature for E() is E(node_type, {node attributes}, [child nodes]).

rpc.js

The RPC JS page is read-only, and demonstrates using RPC calls to get data. It also demonstrates using the JSONMap form object for mapping a configuration to a form, but makes the form read-only for display purposes.

The configuration is stored in /etc/config/example. The file must exist and created on device boot by UCI defaults script in /root/etc/uci-defaults/80_example. The developer guide has more details about UCI defaults.

The RPCd script is stored as /usr/libexec/rpcd/luci.example, and can be called via ubus.

It relies on RPC access, and the relevant ACL declarations are in root/usr/share/rpcd/acl.d/luci-app-example.json.

The declaration is luci-app-example > read > ubus > luci.example; the list of names under this key is the list of APIs that can be called.

ACLs

ACLs are global for the entire web UI - the declaration of luci-app-example in a file called acl.d/luci-app-example is just a naming convention. Nothing enforces that only the code in luci-app-example is mutating /etc/config/example. Once the ACL is defined to allow reads/writes to a UCI node, any code running from the web UI can make changes to that node.

YAML

You may wish to work with YAML data. See YAML.md for details on how to integrate YAML read support.

Translations

For a real world application (or changes to this example one that you wish to submit upstream), translations should be kept up to date.

To rebuild the translations file, from the root of the repository execute ./build/i18n-scan.pl applications/luci-app-example > applications/luci-app-example/po/templates/example.pot

If the scan command fails with an error about being unable to open/find msguniq, install the GNU gettext package for your operating system.