Commit Graph

52 Commits

Author SHA1 Message Date
Paul Donald df90c60a72 luci-base: dispatcher; improve wildcard routing
When a menu JSON describes an endpoint like

 "admin/app/edit/*" : { ...

and the user navigates to

 admin/app/edit/

instead of the URI which supplies an ID to edit, like

 admin/app/edit/myfoobarthing

we now can use 'alias' and 'rewrite' to redirect
transparently for more generic endpoints.
Without this, it's possible to navigate to

 admin/app/edit/

and the corresponding view does not receive a suitable
path/ID to derive data from, when views use anything
derived via L.env.requestpath.

This menu JSON

  "admin/app/entry/*": {
    "action": {
      "type": "view",
      "path": "app/entry"
    }
  },

  "admin/app/entries": {
    "title": "entries",
    "order": 5,
    "action": {
      "type": "view",
      "path": "app/entries"
    }
  },

  "admin/app/entry": {
    "action": {
      "type": "alias",
      "path": "admin/app/entries"
    }
  },

Produces JSON with a wildcardaction element

  "entry":
  {
    "satisfied": true,
    "wildcard": true,
    "action":
    {
      "type": "alias",
      "path": "admin/app/entries"
    },
    "wildcardaction":
    {
      "type": "view",
      "path": "app/entry"
    }
  },
  "entries":
  {
    "satisfied": true,
    "action":
    {
      "type": "view",
      "path": "app/entries"
    },
    "order": 5,
    "title": "entries"
  },

Signed-off-by: Paul Donald <newtwen+github@gmail.com>
2026-01-23 04:27:52 +01:00
Stan Grishin 91b3950112 luci-base: remove reset button from sysauth
Signed-off-by: Stan Grishin <stangri@melmac.ca>
2025-11-18 04:01:16 +01:00
Paul Donald d9a087e48c luci-base: use zone names without spaces
See build: stop zoneinfo builder scripts changing '_' -> ' '
f36f014229

Signed-off-by: Paul Donald <newtwen+github@gmail.com>
2025-10-20 14:41:08 +02:00
Paul Donald a30c8d8872 luci-base: update sys.uc conntrack_list to use /usr/sbin/conntrack
Update sys.uc so that ubus luci->getConntrackList method is optionally
populated by /usr/sbin/conntrack application if /proc/net/nf_conntrack
is not available.

Signed-off-by: James <jpfox156@yahoo.com.au>
2025-10-02 15:43:30 +02:00
Paul Donald 81692c6c38 luci-base: tweak dispatcher logging to post under correct facility
Previously we might see:

... daemon.err uhttpd[5153]: [info] luci: accepted login on / for root from x.x.x.x

Now:

... authpriv.info dispatcher.uc: luci: accepted login on / for root from x.x.x.x

Signed-off-by: Paul Donald <newtwen+github@gmail.com>
2025-07-09 18:18:00 +02:00
Paul Donald ae5d91da90 treewide: vectorise iconography
Clear, crisp, resolution independent vector graphics replace the trusty
microscopic PNG. Some minor CSS changes were needed to constrain images
in some locations to make sure they don't consume too much space.

Iconography taken from Mate desktop theme with minor adjustments:

https://github.com/mate-desktop/mate-icon-theme/

Signed-off-by: Paul Donald <newtwen+github@gmail.com>
2025-06-12 18:55:53 +02:00
Oleg S f6f82b52eb luci-base: package update based cache-busting string
Problem:
After updating the JS-part of any package, the user is forced to clear
the browser cache.

Fix:
Each time a package is removed or installed, the contents of the
"/lib/apk/db/installed" file are changed.
This fix add the modification time of the "/lib/apk/db/installed" file
to the version of the main LuCI package (for each js-file).

Signed-off-by: Oleg S <remittor@gmail.com>
2025-04-14 15:16:54 +02:00
Hannu Nyman 05c7844389 luci-base: update timezone data to 2025b
Update timezone data to 2025b.

https://lists.iana.org/hyperkitty/list/tz-announce@iana.org/thread/6JVHNHLB6I2WAYTQ75L6KEPEQHFXAJK3/

* New zone for Aysén Region in Chile which moves from -04/-03 to -03.

Also:
* Europe/Dublin corrected syntax
* Morocco string format change

Signed-off-by: Hannu Nyman <hannu.nyman@iki.fi>
2025-03-27 21:06:03 +02:00
Hannu Nyman edc352e110 luci-base: update timezone data to 2025a
Update timezone data to 2025a.

https://lists.iana.org/hyperkitty/list/tz-announce@iana.org/thread/MWII7R3HMCEDNUCIYQKSSTYYR7UWK4OQ/

* Paraguay adopts permanent -03 starting spring 2024.
* Asia/Choibalsan is removed from selection list. It is now
  an alias for Asia/Ulaanbaatar rather than being a separate
  Zone (changed in 2024b).

Signed-off-by: Hannu Nyman <hannu.nyman@iki.fi>
2025-02-06 20:54:34 +02:00
Paul Donald f92e07253f luci-base: drop promise polyfill
Subsequent commits will modernize LuCI JavaScript code to use ES6 features,
so drop the Promise polyfill as we're dropping support for non-ES6 browsers.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2024-12-20 00:09:47 +00:00
Mustafa Can Elmacı ae8bbb814f treewide: HTML Cleanup
* HTML Cleanup: Meta tags.
* Converted charset to shorthand.
* Removed meta tags with `Content-Script-Type` attribute. (Invalid in HTML5 spec.)

* HTML Cleanup: CSS tags.
* Removed `type` attribute with CSS files from link tags. (HTML5 spec recommends omitting it.)
* Removed `type` attribute from style tags. (Deprecated in HTML5 spec.)
https://html.spec.whatwg.org/#attr-link-type
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/style

* HTML Cleanup: Convert from XHTML to HTML5
* Removed XML declaration.
* Removed XML namespace.
* Changed doctype to HTML5.

* HTML Cleanup: CDATA tags.
* CDATA sections should not be used within HTML they are considered as comments and not displayed.
https://developer.mozilla.org/en-US/docs/Web/API/CDATASection

* HTML Cleanup: Script tags.
* Removed `language` attribute from script tags. (No longer valid in HTML5)
* Removed `type` attribute with JavaScript MIME type from script tags. (HTML5 spec recommends omitting it.)
https://html.spec.whatwg.org/multipage/scripting.html#attr-script-type
https://mimesniff.spec.whatwg.org/#javascript-mime-type

Signed-off-by: Mustafa Can Elmacı <mustafacan@elmaci.net>
2024-11-22 22:39:46 +01:00
Paul Donald 8449716ceb luci-base: expunge correct transport cookies on logout
Closes #7269

Thanks to @mikma

Signed-off-by: Paul Donald <newtwen+github@gmail.com>
2024-09-20 17:39:58 +02:00
Jo-Philipp Wich 65b8002adb luci-base: dispatcher.uc: skip login nodes when resolving w/ active session
When resolving eligible child nodes during evaluation of the "firstchild"
dispatch action, do not consider nodes allowing a login as allowed when
there already is an established session.

This fixes cases where restricted sessions are redirected to nodes they
have insufficent ACLs for, just because those nodes allow logins.

Fixes: #7218
Ref: https://forum.openwrt.org/t/x/174687
Suggested-by: @mikma
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2024-07-31 00:01:22 +02:00
Hannu Nyman f2a49104c4 Revert "luci-base: force menu to regenerate after uci change"
This reverts commit 97ebdcbddb.

The commit seems to cause errors already before the login screen.
Discussion in https://github.com/openwrt/luci/commit/97ebdcbddb9cad76dc551086fcb887e55886a069#commitcomment-139871175

Errors like:

 In error(), file [C]
 called from function [anonymous function] (/usr/lib/lua/luci/ucodebridge.lua:23)
 called from function ((tail call))
 In [anonymous function](), file /usr/share/ucode/luci/runtime.uc, line 148, byte 45:
   called from function build_pagetree (/usr/share/ucode/luci/dispatcher.uc:382:73)
   called from function menu_json (/usr/share/ucode/luci/dispatcher.uc:439:26)
   called from function [anonymous function] (/usr/share/ucode/luci/dispatcher.uc:898:24)
   called from anonymous function (/www/cgi-bin/luci:39:13)

  `        return lcall.call(modname, method, ...args);`
   Near here ----------------------------------------^

Signed-off-by: Hannu Nyman <hannu.nyman@iki.fi>
2024-03-17 09:17:20 +02:00
James Haggerty 97ebdcbddb luci-base: force menu to regenerate after uci change
Because the menu JSON can have 'depends' in them, uci changes
should force the menu to regenerate.

Closes #6423

Signed-off-by: James Haggerty <james.haggerty@morsemicro.com>
Signed-off-by: Paul Donald <newtwen@gmail.com>
2024-03-17 00:23:45 +01:00
Hannu Nyman 23ebdb3bf9 luci-base: update timezone data to 2024a
Update timezone data to 2024a.

https://mm.icann.org/pipermail/tz-announce/2024-February/000081.html

Briefly:
* Kazakhstan unifies on UTC+5 beginning 2024-03-01.

Signed-off-by: Hannu Nyman <hannu.nyman@iki.fi>
2024-02-09 21:34:37 +02:00
Hannu Nyman 8debeeb438 timezone data: update to 2023d
Update timezone data to 2023d.

https://mm.icann.org/pipermail/tz-announce/2023-December/000080.html

Summary:
* Ittoqqortoormiit, Greenland changes time zones on 2024-03-31.
* Vostok, Antarctica changed time zones on 2023-12-18.
* Casey, Antarctica changed time zones five times since 2020.

Signed-off-by: Hannu Nyman <hannu.nyman@iki.fi>
2024-01-06 21:02:56 +02:00
Jo-Philipp Wich b4594b3d11 luci-base: http.uc: fix eof detection in temporary upload files
Binary string comparisons in ucode are currently unsafe, so use the
`length()` function to determine the just read data chunk size in
order to test for end of file.

Fixes: #6530
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2023-08-21 16:37:11 +02:00
Jo-Philipp Wich 86f04d85fc luci-base: dispatcher.uc: improve error reporting for actionless nodes
In case a - potentially auto-created, intermediate - node is requested, reply
with a clean HTTP 404 error instead of an internal assertion about an unknown
action type.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2023-08-21 09:48:29 +02:00
Jo-Philipp Wich ec8cf9e83c luci-base: dispatcher.uc: satisfy auto-created intermediate nodes
When we auto-create intermediate parent nodes, make sure that those nodes
are marked as satisfied, so that it is possible to dispatch their actual
child nodes.

This aligns the behavior with the old Lua based dispatcher implementation.

Fixes: #6529
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2023-08-21 09:48:29 +02:00
Paul Dee 2c3018d426 luci-base: grammar fixes
Login (n) -> Log (v) in

Logout (n) -> Log (v) out

Signed-off-by: Paul Dee <itsascambutmailmeanyway@gmail.com>
2023-08-11 13:17:04 +02:00
Jo-Philipp Wich 9763e3e9d3 luci-base: runtime.uc: fix error500() invocation on theme failure
In case no single theme could be loaded successfully, the runtime class
failed to properly invoke the `error500()` method, which is only available
through the passed environment at this point.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2023-08-07 23:36:36 +02:00
Jo-Philipp Wich 107ed061a8 luci-base: dispatcher.uc: fix N_() fallback implementation
The fallback implementation of `N_()` accessed the wrong variable, a
global `n` instead of the local `args`. Adjust the expression to reference
the correct variable.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2023-08-07 23:33:56 +02:00
Jo-Philipp Wich a435d4e11a luci-base: dispatcher.uc: fix error500() reporting in fallback case
Fix the `error500()` fallback code path to properly output the given error
message in case rendering the error template failed.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2023-08-07 23:29:50 +02:00
Tianling Shen 588c6a1e4b luci-base: http.uc: fix reference error of undeclared variable err
The variable `err` was used without initialized.

Signed-off-by: Tianling Shen <cnsztl@immortalwrt.org>
2023-04-14 10:50:02 +03:00
Hannu Nyman 2145121d4c timezone data: update to 2023c
Update timezone data to 2023a, 2023b, 2023c.
(2023c reverts 2023b.)

https://mm.icann.org/pipermail/tz-announce/2023-March/000077.html
https://mm.icann.org/pipermail/tz-announce/2023-March/000078.html
https://mm.icann.org/pipermail/tz-announce/2023-March/000079.html

Summary:
* Egypt now uses DST again, from April through October.
* Much of Greenland still uses DST from 2024 on.
* America/Yellowknife now links to America/Edmonton. (removed here)
* Europe/Kirov and Europe/Volgograd now use the abbreviations MSK/MSD

Signed-off-by: Hannu Nyman <hannu.nyman@iki.fi>
2023-04-03 18:49:17 +03:00
Jo-Philipp Wich 24d7da2416 luci-base: dispatcher.uc: prevent XSS through 404 error template
Make sure to escape the user controlled URL passed as part of the error
message into the error404 template in order to avoid XSS.

Reported-by: 40826d <40826d@posteo.de>
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2023-03-10 15:36:09 +01:00
Jo-Philipp Wich 9634086efc luci-base: dispatcher.uc: urldecode URL components
In order to maintain compatibility with the old Lua runtime, ensure to URL
decode the request path segments since they might end up as arguments to
invoked action functions.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2023-01-13 21:18:09 +01:00
Hannu Nyman 5f14c47d0d timezone data: update to 2022g
Update timezone data to 2022g.

* https://mm.icann.org/pipermail/tz-announce/2022-November/000076.html

- In the Mexican state of Chihuahua, the border strip near the US
  will change to agree with nearby US locations on 2022-11-30.
  The strip's western part, represented by Ciudad Juárez, switches
  from -06 all year to -07/-06 with US DST rules, like El Paso, TX.
  The eastern part, represented by Ojinaga, will observe US DST next
  year, like Presidio, TX.
- A new Zone America/Ciudad_Juarez splits from America/Ojinaga.

- Much of Greenland, represented by America/Nuuk, stops observing
  winter time after March 2023, so its daylight saving time becomes
  standard time.

Signed-off-by: Hannu Nyman <hannu.nyman@iki.fi>
2022-12-01 21:50:43 +02:00
Jo-Philipp Wich bed67dc000 luci-base: only render theme specific sysauth template when it exists
Avoid displaying non-fatal "File not found" exceptions when a theme is not
shipping an own sysauth template.

Fixes: #6118
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-11-25 15:30:20 +01:00
Jo-Philipp Wich d8e3b35c88 luci-base: fix passing dispatched node details to templates
Fixes: #6111
Fixes: 08ae8d40a9 ("luci-base, luci-lua-runtime: fix "dispatched" and "requested" properties")
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-11-22 17:31:37 +01:00
Jo-Philipp Wich 9d10c2e671 luci-base: fix (again) rendering ucode templates in template target
Fixes: #6111
Fixes: a5d21dadbd ("luci-base: fix rendering ucode templates from `template` target")
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-11-22 15:01:32 +01:00
Jo-Philipp Wich a5d21dadbd luci-base: fix rendering ucode templates from template target
A previous commit inadvertently broke support for rendering ucode templates
from the `template` dispatcher target.

Fixes: #6111
Fixes: fa17c1573f ("luci-base, luci-lua-runtime: adjust Lua template environment")
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-11-22 09:41:31 +01:00
Jo-Philipp Wich fa17c1573f luci-base, luci-lua-runtime: adjust Lua template environment
To maintain full compatibility with the old Lua runtime, templates
rendered from a menu `template()` action must implicitly inherit the
`luci.dispatcher` namespace as scope while other indirectly included
templates must not.

Fixes: #6105
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-11-21 12:27:28 +01:00
Jo-Philipp Wich 08ae8d40a9 luci-base, luci-lua-runtime: fix "dispatched" and "requested" properties
Ensure to properly emulate the "dispatched" and "requested" properties
which refer to the executed and initially resolved menu node respectivey.

Also stop exposing a `node` property in Lua context to maintain full
compatibility with the old Lua runtime.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-11-21 12:24:31 +01:00
Jo-Philipp Wich c4d86c9f67 luci-base: expose sysauth rendering errors
In case a theme shipped sysauth.htm failed to render/execute, expose the
exception error details in the ui theme fallback indicator.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-11-21 12:20:58 +01:00
Jo-Philipp Wich 0dd0114a9d luci-base: fix empty reply format in ubus gateway fallback code
The ubus gateway fallback code incorrectly formatted ubus replies
containing no payload data when forwarding them via HTTP, leading
to `TypeError: Unexpected reply data format` errors in at least
the `luci.fs` class when receiving replies without payload.

Fix this issue by ensuring that the result array never contains
a `null` value for the payload, send an one-element array containing
just the status code in this case instead.

Fixes: #6074
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-11-03 11:27:52 +01:00
Jo-Philipp Wich 4b1a074c95 luci-base: dispatcher.uc: only flush HTTP headers after rendering output
Ensure to first completely render the action function before flushing HTTP
headers since the invoked action logic might modify the HTTP headers itself.

Fixes: e7afd0d327 ("luci-base: fix luci.http.close()")
Ref: https://github.com/openwrt/luci/commit/e7afd0d327bb35c502ca41a3c5e3ea098898fbd7#commitcomment-88736854
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-11-03 11:17:55 +01:00
Jo-Philipp Wich e7afd0d327 luci-base: fix luci.http.close()
Ensure that `http.write()` or template rendering operations after a call
to `http.close()` do not produce additional output. This is required for
certain legacy Lua apps which invoke write and close operations in the
middle of a server side cbi rendering process.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-11-03 00:38:00 +01:00
Jo-Philipp Wich 815028ef93 luci-base: runtime.uc: avoid Lua not installed exeption from trycompile()
Make sure to request loading the Lua bridge as optional when initializing
the Lua VM context from trycompile() in order to not raise a fatal exception
in case the Lua runtime support is not present.

Ref: https://forum.openwrt.org/t/x/141426
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-11-02 10:21:05 +01:00
Jo-Philipp Wich c99602e4ac luci-base: dispatcher.uc: apply ACLs to menu tree JSON
Add menu tree annotations for node readonly and dependency satisfied state
in order to ensure that unreachable menu nodes are hidden from view.

Fixes: ded8ccf93e ("luci-base-ucode: add initial ucode based LuCI runtime")
Ref: https://forum.openwrt.org/t/x/141426/10
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-11-02 10:13:41 +01:00
Jo-Philipp Wich d967bbaa92 luci-base: http.uc: fix invoking Lua file upload callbacks
In case a callback is installed from Lua code, the received callback
argument is not a callable function but a resource object with a call
method. Attempts to call it will leading to a `Type error: left-hand
side is not a function` error.

To solve this issue, invoke the internally set filehandler instead
which wraps the resource if needed.

Fixes: #6067
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-11-02 09:08:16 +01:00
Hannu Nyman da41c11971 timezone data: update to 2022f
Update timezone data to 2022f.
* http://mm.icann.org/pipermail/tz-announce/2022-October/000075.html

 -   Mexico will no longer observe DST after 2022, except for areas
     near the US border that continue to observe US DST rules.
     On 2022-10-30 at 02:00 the Mexican state of Chihuahua moves
     from -07 (-06 with DST) to year-round -06.
 -   Fiji will not observe DST in 2022/3.
     For now, assume DST is suspended indefinitely.
 -   Simplify four Ontario zones.

Signed-off-by: Hannu Nyman <hannu.nyman@iki.fi>
2022-10-31 20:04:10 +02:00
Jo-Philipp Wich 1eea6c0ce8 luci-base: add ui indicator when fallback theme is used
Add a ui indicator displaying error details when the configured theme
failed to load and the next available one is being used instead.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-10-27 11:14:52 +02:00
Jo-Philipp Wich 767acf32d4 luci-base: dispatcher.uc: update uci session ID in Lua context
Make sure that the uci session ID of the `luci.model.uci` module within
the Lua context is updated once we acquire the login session information.

In case legacy themes are used, the probing of the theme header template
might indirectly load the Lua runtime and the Lua side `luci.dispatcher`
module which in turn will load the `luci.model.uci` and set the session
ID there which is not yet initialized at this point in time.

This results in broken uci change handling within legacy Lua applications
when a legacy theme is loaded.

Fixes: #6060
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-10-27 11:14:52 +02:00
Jo-Philipp Wich 70e32f0cb1 luci-base: dispatcher.uc: ensure usage of dashes in language tags
The LuCI uci configuration requires language tags with underscores due
limitations of uci option names but the language catalogs themselves
are designated with dash separated language tags.

Make sure to substitute underscores with dashes when determining the
desired request language in order to fix loading of languages such as
`pt-br` or `zh-cn`.

Ref: https://github.com/openwrt/luci/pull/5976#issuecomment-1290352951
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-10-25 13:01:31 +02:00
Jo-Philipp Wich adc4ca65bc luci-base: dispatcher.uc: reintroduce support for 'absent' fs depends
The ability to require certain paths to be absent for a menu entry to show
up was lost during the ucode conversion.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-10-25 12:50:37 +02:00
Jo-Philipp Wich 21dacf2db7 luci-base: sys.uc: reliably skip TIME_WAIT connections in conntrack list
The TIME_WAIT indicator might not appear at the beginning of the tuple
string in some cases, so match it anywhere.

Signed-off-by: Kevin Darbyshire-Bryant <ldir@darbyshire-bryant.me.uk>
[add commit message]
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-10-25 01:03:37 +02:00
Jo-Philipp Wich 791a71d225 luci-base: sys.uc: fix parsing conntrack list
Ensure that the extracted tuple string starts with a space to fully match
all contained key-value pairs.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-10-25 01:03:37 +02:00
Jo-Philipp Wich 60a9f01978 luci-base: sys.uc: increase init script START/STOP search space
Some init scripts, such as the sysfsutils one, declare their START or
STOP variables very late in the file. Duplicate the search buffer to
2048 byte in order to catch these cases.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-10-25 01:03:37 +02:00