Files
dawnline/package/luci-app-dawnline/root/usr/share/ucode/dawnline/rpc/common.uc
T
Aemeath 2f2aaf6c34
Build packages / CI (push) Blocked by required conditions
Build packages / Version (push) Waiting to run
CI / Web (format, types, tests, bundles) (push) Blocked by required conditions
CI / ShellCheck (push) Blocked by required conditions
CI / ucode static checks (push) Blocked by required conditions
CI / ucode compiles and tests pass (OpenWrt 24.10) (push) Blocked by required conditions
CI / ucode compiles and tests pass (OpenWrt 25.12) (push) Blocked by required conditions
Dawnline 0.11.0
- Russian translation. The admin pages, the LuCI menu and the router's
  messages (errors, Health checks, update steps, the service log) come in
  Russian with the new luci-i18n-dawnline-ru package, released beside the
  app. LuCI shows it when its language is Russian, or "auto" with a Russian
  browser
- The translation installs with install.sh when LuCI is in Russian (or with
  --lang ru), follows every Dawnline update and rollback, and can be added
  or removed in Components → Dawnline → Translation
- The portal speaks the visitor's language: it opens in the system's
  language and switches between English and Russian in place, from the
  language pill beside its QR code. It carries its own translation and needs
  no package
- Set-up steps quote the apps' own menus word for word, in Russian too:
  AmneziaVPN is "+ → Insert → Continue" (it has no "Add server"), and the
  Mac and Windows menus of WireGuard and AmneziaWG have their real names
- Questions in the portal (Reconnect, Remove) read from the left edge and
  close with Cancel, without ×
- Numbers, sizes and dates follow the page's language. A server that can't
  start says why in one sentence; event details and service log lines read
  as whole sentences
- README in Russian (README_ru.md). rules/i18n.md: how strings are written
  and translated; CI checks the catalogs (npm run i18n:check)
2026-10-20 19:33:52 +03:00

135 lines
4.8 KiB
Ucode
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Dawnline — what the rpcd method modules (dawnline.rpc.*) share: the call
// wrapper, argument helpers, the disguise check and the portal port check.
import * as core from 'dawnline.core';
import * as awg from 'dawnline.awg';
import * as health from 'dawnline.health';
import * as schema from 'dawnline.schema';
import { uniq } from 'dawnline.util';
import { _ } from 'dawnline.i18n';
/**
* An rpcd handler from fn(args): an object result is passed on, anything else
* is wrapped as { result }, and a failure becomes { error } (the UI shows it).
*/
export function wrap(fn) {
return function(req) {
try {
let r = fn(req.args ?? {});
return type(r) == 'object' ? r : { result: r };
}
catch (e) {
return { error: e.message ?? `${e}` };
}
};
};
/** An argument as a trimmed string ('' for null). */
export function str(v) {
return v == null ? '' : trim(`${v}`);
};
/** Days of history a caller may ask for: 1–400, default 30. */
export function clamp_days(v) {
let n = +(v ?? 30);
return n >= 1 ? (n > 400 ? 400 : int(n)) : 30;
};
export const METHODS = [ 'off', 'balanced', 'max' ];
/** The disguise a new server gets: the strongest this router can run. */
export function default_method() {
let c = awg.caps();
return c.v3 ? 'max' : c.v2 ? 'balanced' : 'off';
};
/** A disguise method the installed AmneziaWG can run. */
export function check_method(name) {
if (index(METHODS, name) < 0)
die(_('Unknown disguise method.'));
let c = awg.caps();
if (name == 'max' && !c.v3)
die(awg.installed()
? _('Maximum needs AmneziaWG 3.1 on the router (kmod-amneziawg, amneziawg-tools 3.1): install a 3.1 build in Dawnline → Components.')
: _('AmneziaWG is not installed: install it in Dawnline → Components, then choose Maximum.'));
if (name == 'balanced' && !c.v2)
die(awg.installed()
? _('Balanced needs AmneziaWG 2.0 or newer on the router: install a current build in Dawnline → Components.')
: _('AmneziaWG is not installed: install it in Dawnline → Components, then choose Balanced.'));
return name;
};
/**
* The portal's ports in the final configuration `m` (compared with `was`,
* before the change) are acceptable: its HTTPS port and, when links on IP
* addresses use plain HTTP, the next port too — both get a WAN ACCEPT rule.
* Neither may be 22, 53, 80 or 443, beyond 65535, or taken by another program.
*/
/** TCP port forwards from the servers' WAN zones: [{ from, to, name }]. */
function tcp_forwards(m) {
let out = [];
for (let z in uniq([ 'wan', ...map(values(m.servers), (s) => s.wan_zone) ]))
push(out, ...core.wan_forwards(z, 'tcp'));
return out;
}
/**
* TCP ports the portal can't take, and who holds them: [{ from, to, who }].
* The router's own (22, 53, 80, 443), other programs and port forwards from WAN.
* `who` is shown in the admin's language ("Used by %s.").
*/
export function tcp_taken(m) {
let out = [];
let held = {};
let hold = (p, who) => {
if (!held[p]) {
held[p] = true;
push(out, { from: p, to: p, who });
}
};
for (let p in schema.RESERVED_PORTS)
hold(p, _('the router itself'));
for (let p, name in health.tcp_port_programs())
hold(+p, sprintf(_('%s on this router'), name));
for (let f in tcp_forwards(m))
push(out, { from: f.from, to: f.to, who: sprintf(_('port forward “%s”'), f.name) });
return out;
};
export function check_portal(m, was) {
let s = m.settings;
if (!s.portal_enabled)
return;
let port = s.portal_port;
if (!schema.valid_port(port) || index(schema.RESERVED_PORTS, port) >= 0)
die(_('Choose a free port between 1 and 65535 (not 22, 53, 80 or 443).'));
let ports = [ port ];
if (core.portal_http(m)) {
let hp = core.portal_http_port(m);
if (!schema.valid_port(hp) || index(schema.RESERVED_PORTS, hp) >= 0)
die(sprintf(_('Links on IP addresses use plain HTTP on the next port (%d), which the portal cannot take. Choose another portal port.'), hp));
push(ports, hp);
}
// Only ports the portal does not hold already: our own uhttpd is not an owner anyway.
let held = [];
if (was?.settings?.portal_enabled) {
push(held, was.settings.portal_port);
if (core.portal_http(was))
push(held, core.portal_http_port(was));
}
for (let p in ports) {
if (index(held, p) >= 0)
continue;
let owners = health.tcp_port_owners(p);
if (length(owners))
die(sprintf(p != port
? _("TCP %d is already used by %s. Links on IP addresses use plain HTTP on the port after the portal's. Choose another portal port.")
: _('TCP %d is already used by %s. Choose another portal port.'), p, join(', ', owners)));
}
// A forwarded port never reaches the router: the portal would be unreachable.
for (let p in ports)
for (let f in tcp_forwards(m))
if (f.from <= p && p <= f.to)
die(sprintf(_('TCP %d is sent on by port forward “%s”. Choose another portal port.'), p, f.name));
};