dsh-aupdate 0.4.0 → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -0
- package/client.js +1 -1
- package/index.js +62 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -130,6 +130,11 @@ mtime 为准:那是磁盘事实。会话目录整个读不到时返回「不
|
|
|
130
130
|
日志只经由 `GET /api/dsh-aupdate/logs?lines=N` 读,参数夹在 1 到 1000 之间,
|
|
131
131
|
不提供写入口——面板能看,但改不了日志。
|
|
132
132
|
|
|
133
|
+
四个接口都要先过宿主的连接准入(`connection.admit` / 旧宿主的
|
|
134
|
+
`requestRejection`),没通过就回 401/403,拿不到 `connection` 服务或它抛错时
|
|
135
|
+
一律 503。不用「只认回环地址」这种判据:浏览器里任何网页都能向 127.0.0.1 发请求。
|
|
136
|
+
`/state` 和 `/logs` 也照样要过,因为它们分别会吐全量设置和读磁盘上的日志文件。
|
|
137
|
+
|
|
133
138
|
## 效率
|
|
134
139
|
|
|
135
140
|
- 只取 dist-tags:24 个包从 2.88 MB 降到 655 B
|
|
@@ -162,6 +167,13 @@ queue is flushed before reading, so lines from the check you just triggered are
|
|
|
162
167
|
already there. Timestamps render in local time, rotation past 1 MB is called out,
|
|
163
168
|
and the total line count is shown.
|
|
164
169
|
|
|
170
|
+
All four routes go through the host's connection admission (`connection.admit`, or
|
|
171
|
+
`requestRejection` on older hosts) first: a rejection answers 401/403, and a missing
|
|
172
|
+
or throwing `connection` service answers 503. Checking only the loopback address is
|
|
173
|
+
not an admission decision — any web page in the browser can reach 127.0.0.1.
|
|
174
|
+
`/state` and `/logs` are gated too; they expose the whole settings object and read
|
|
175
|
+
the log file off disk.
|
|
176
|
+
|
|
165
177
|
The log is read through `GET /api/dsh-aupdate/logs?lines=N` only, with the count
|
|
166
178
|
clamped between 1 and 1000. There is no write path: the page can look, not edit.
|
|
167
179
|
|
package/client.js
CHANGED
|
@@ -751,7 +751,7 @@ window.__ModuleLoader__.load({
|
|
|
751
751
|
? h('span', { style: S.status }, T.logsEmpty)
|
|
752
752
|
: h('pre', { style: S.logBox, title: data?.path || '' },
|
|
753
753
|
rows.map((row, index) => h('div', { key: index },
|
|
754
|
-
row.at ? h('span', { style: S.logTime }, row.at
|
|
754
|
+
row.at ? h('span', { style: S.logTime }, formatWhen(row.at) + ' ') : null,
|
|
755
755
|
h('span', { style: S.logText }, row.text),
|
|
756
756
|
)),
|
|
757
757
|
),
|
package/index.js
CHANGED
|
@@ -158,6 +158,16 @@ function propOf(target, key) {
|
|
|
158
158
|
}
|
|
159
159
|
|
|
160
160
|
function serviceOf(ctx, key) {
|
|
161
|
+
// 有 reflect 就先走 reflect.get:cordis 4 的 ctx 是 Proxy,裸读(以及 ctx.get)
|
|
162
|
+
// 碰未在 inject 里声明的服务会抛 "cannot get property without inject",而不是
|
|
163
|
+
// 返回 undefined。connection 正是那种没声明的服务,用 ctx.get 会被我们自己的
|
|
164
|
+
// catch 吞成 null,于是每个请求都判成 503。
|
|
165
|
+
try {
|
|
166
|
+
const reflect = propOf(ctx, 'reflect')
|
|
167
|
+
if (reflect !== undefined && reflect !== null && typeof reflect.get === 'function') {
|
|
168
|
+
return reflect.get(key) ?? null
|
|
169
|
+
}
|
|
170
|
+
} catch {}
|
|
161
171
|
try {
|
|
162
172
|
return (typeof ctx?.get === 'function' ? ctx.get(key) : undefined) ?? null
|
|
163
173
|
} catch {
|
|
@@ -1218,7 +1228,9 @@ async function runCycle(mode, ctxRef) {
|
|
|
1218
1228
|
name: dep.name,
|
|
1219
1229
|
current,
|
|
1220
1230
|
target,
|
|
1221
|
-
|
|
1231
|
+
// 这里是服务端拼的纯文本,拿不到浏览器时区,所以显式写 UTC,
|
|
1232
|
+
// 免得把一个 UTC 时刻当成本地时间读。
|
|
1233
|
+
why: '上次安装失败,' + until.toISOString().slice(0, 16).replace('T', ' ') + ' UTC 前不再重试',
|
|
1222
1234
|
}
|
|
1223
1235
|
}
|
|
1224
1236
|
return { name: dep.name, current, target, tag }
|
|
@@ -1534,6 +1546,52 @@ function sendJson(res, status, value) {
|
|
|
1534
1546
|
} catch {}
|
|
1535
1547
|
}
|
|
1536
1548
|
|
|
1549
|
+
/**
|
|
1550
|
+
* 谁能调这些路由。
|
|
1551
|
+
*
|
|
1552
|
+
* 浏览器里任何一个网页都能向 127.0.0.1 发请求,所以「只看 Host/Origin/回环地址」
|
|
1553
|
+
* 不算准入。宿主把这件事交给 connection 服务,这里只做转发:
|
|
1554
|
+
*
|
|
1555
|
+
* - 新宿主是 admit(req),返回 { rejection: status } 信封;旧宿主是
|
|
1556
|
+
* requestRejection(req),直接返回状态码。两种拼写都要认,认错一种就会把
|
|
1557
|
+
* 鉴权整个关掉。
|
|
1558
|
+
* - 返回 undefined 才是放行。
|
|
1559
|
+
* - 服务不在、或调用抛错,一律当拒绝(503)。这里不能「降级成放行」——
|
|
1560
|
+
* 那等于宿主一抖动,设置页对全世界的网页开放。
|
|
1561
|
+
*
|
|
1562
|
+
* connection 故意不写进 inject:cordis 的注入是全或无的,多声明一个依赖会让
|
|
1563
|
+
* 整个作用域等一个可能永远不来的服务。改成每次请求惰性读一次。
|
|
1564
|
+
*/
|
|
1565
|
+
function admitRequest(scope, req, res) {
|
|
1566
|
+
const connection = serviceOf(scope, 'connection')
|
|
1567
|
+
// 必须回 true:调用点写的是 if (admitRequest(...)) return,回 undefined 的话
|
|
1568
|
+
// 请求照旧往下走,鉴权就形同虚设(写的时候真踩过一次)。
|
|
1569
|
+
const write = (status) => {
|
|
1570
|
+
try {
|
|
1571
|
+
res.writeHead(status, { 'content-type': 'application/json; charset=utf-8', 'cache-control': 'no-store' })
|
|
1572
|
+
res.end(JSON.stringify({ error: 'unauthorized' }))
|
|
1573
|
+
} catch {}
|
|
1574
|
+
return true
|
|
1575
|
+
}
|
|
1576
|
+
if (connection === null) return write(503)
|
|
1577
|
+
let status
|
|
1578
|
+
try {
|
|
1579
|
+
const admit = propOf(connection, 'admit')
|
|
1580
|
+
if (typeof admit === 'function') {
|
|
1581
|
+
const verdict = admit.call(connection, req)
|
|
1582
|
+
status = verdict && typeof verdict === 'object' ? verdict.rejection : undefined
|
|
1583
|
+
} else {
|
|
1584
|
+
const reject = propOf(connection, 'requestRejection')
|
|
1585
|
+
if (typeof reject !== 'function') return write(503)
|
|
1586
|
+
status = reject.call(connection, req)
|
|
1587
|
+
}
|
|
1588
|
+
} catch {
|
|
1589
|
+
return write(503)
|
|
1590
|
+
}
|
|
1591
|
+
if (status === undefined || status === null) return false
|
|
1592
|
+
return write(typeof status === 'number' ? status : 403)
|
|
1593
|
+
}
|
|
1594
|
+
|
|
1537
1595
|
function readBody(req) {
|
|
1538
1596
|
return new Promise((settle) => {
|
|
1539
1597
|
let size = 0
|
|
@@ -1633,6 +1691,9 @@ function registerRoutes(scope, ctxRef) {
|
|
|
1633
1691
|
if (webServer === null || typeof webServer.register !== 'function') return false
|
|
1634
1692
|
const handler = async (req, res) => {
|
|
1635
1693
|
try {
|
|
1694
|
+
// 先过宿主准入,再碰任何设置或文件。读接口也过:/state 里有全量设置,
|
|
1695
|
+
// /logs 会读磁盘上的日志文件,都不该由任意网页拿到。
|
|
1696
|
+
if (admitRequest(scope, req, res)) return
|
|
1636
1697
|
const url = new URL(req.url ?? '/', 'http://localhost')
|
|
1637
1698
|
const suffix = url.pathname.slice(ROUTE_PREFIX.length)
|
|
1638
1699
|
const method = req.method ?? 'GET'
|