Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 070c936a69 | |||
| 3f15cbda80 | |||
| 4b48f0056e | |||
| d91fda084b | |||
| a86d83f835 | |||
| 05235ec284 |
@@ -3,6 +3,41 @@
|
|||||||
## Pending
|
## Pending
|
||||||
|
|
||||||
|
|
||||||
|
## 2026-05-24 - 1.30.1
|
||||||
|
|
||||||
|
### Fixes
|
||||||
|
|
||||||
|
- align Onebox settings gateway cards with the dees-tile footer action pattern
|
||||||
|
- align settings gateway cards with dees-tile footer actions (settings-ui)
|
||||||
|
- Replaces custom gateway card wrappers with dees-tile header and footer slots.
|
||||||
|
- Uses tile-styled action buttons for Admin UI and dcrouter settings saves.
|
||||||
|
|
||||||
|
## 2026-05-24 - 1.30.0
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
- add configurable Onebox Admin UI domain
|
||||||
|
- expose Admin UI domain in settings
|
||||||
|
- sync the Admin UI route as a first-class dcrouter gateway route
|
||||||
|
- keep Admin UI routing separate from app service routes
|
||||||
|
- add configurable Admin UI domain routing (admin-ui)
|
||||||
|
- Expose and validate the Admin UI domain in settings
|
||||||
|
- Sync the Admin UI as a dedicated dcrouter gateway route and SmartProxy route
|
||||||
|
- Preserve configured and legacy Admin UI routes during stale-route reconciliation
|
||||||
|
|
||||||
|
### Fixes
|
||||||
|
|
||||||
|
- preserve Onebox Admin UI routes during external gateway stale-route reconciliation
|
||||||
|
|
||||||
|
## 2026-05-24 - 1.29.0
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
- add Onebox runtime update prompts and admin-triggered self-upgrades
|
||||||
|
- expose Onebox update status through system status
|
||||||
|
- reuse the CLI upgrade logic for web-triggered detached upgrades
|
||||||
|
- show an update banner and guided DeesUpdater flow in the dashboard
|
||||||
|
|
||||||
## 2026-05-24 - 1.28.0
|
## 2026-05-24 - 1.28.0
|
||||||
|
|
||||||
### Features
|
### Features
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@serve.zone/onebox",
|
"name": "@serve.zone/onebox",
|
||||||
"version": "1.28.0",
|
"version": "1.30.1",
|
||||||
"exports": "./mod.ts",
|
"exports": "./mod.ts",
|
||||||
"tasks": {
|
"tasks": {
|
||||||
"test": "deno test --allow-all test/",
|
"test": "deno test --allow-all test/",
|
||||||
|
|||||||
+3
-6
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@serve.zone/onebox",
|
"name": "@serve.zone/onebox",
|
||||||
"version": "1.28.0",
|
"version": "1.30.1",
|
||||||
"description": "Self-hosted container platform with automatic SSL and DNS - a mini Heroku for single servers",
|
"description": "Self-hosted container platform with automatic SSL and DNS - a mini Heroku for single servers",
|
||||||
"main": "mod.ts",
|
"main": "mod.ts",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
@@ -52,7 +52,7 @@
|
|||||||
"x64",
|
"x64",
|
||||||
"arm64"
|
"arm64"
|
||||||
],
|
],
|
||||||
"packageManager": "pnpm@10.18.1+sha512.77a884a165cbba2d8d1c19e3b4880eee6d2fcabd0d879121e282196b80042351d5eb3ca0935fa599da1dc51265cc68816ad2bddd2a2de5ea9fdf92adbec7cd34",
|
"packageManager": "pnpm@11.1.2",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@api.global/typedrequest-interfaces": "^3.0.19",
|
"@api.global/typedrequest-interfaces": "^3.0.19",
|
||||||
"@api.global/typedsocket": "^4.1.3",
|
"@api.global/typedsocket": "^4.1.3",
|
||||||
@@ -65,8 +65,5 @@
|
|||||||
"@git.zone/tsdeno": "^1.3.2",
|
"@git.zone/tsdeno": "^1.3.2",
|
||||||
"@git.zone/tswatch": "^3.3.5"
|
"@git.zone/tswatch": "^3.3.5"
|
||||||
},
|
},
|
||||||
"private": true,
|
"private": true
|
||||||
"pnpm": {
|
|
||||||
"overrides": {}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -173,6 +173,47 @@ Deno.test('ExternalGatewayManager syncs service routes to dcrouter gatewayClient
|
|||||||
assertEquals(syncRequest.requestData.enabled, true);
|
assertEquals(syncRequest.requestData.enabled, true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Deno.test('ExternalGatewayManager syncs Admin UI route to dcrouter gatewayClient API', async () => {
|
||||||
|
const oneboxRef = makeOneboxRef();
|
||||||
|
oneboxRef.database.settings.set('adminUiDomain', 'Onebox.Example.com');
|
||||||
|
oneboxRef.database.settings.set('serverIP', '203.0.113.10');
|
||||||
|
oneboxRef.database.settings.set('httpPort', '8080');
|
||||||
|
|
||||||
|
const requests: Array<{ method: string; requestData: Record<string, unknown> }> = [];
|
||||||
|
const manager = new ExternalGatewayManager(oneboxRef as any);
|
||||||
|
(manager as any).fireDcRouterRequest = async (
|
||||||
|
method: string,
|
||||||
|
requestData: Record<string, unknown>,
|
||||||
|
) => {
|
||||||
|
if (method === 'getGatewayClientContext') {
|
||||||
|
return {
|
||||||
|
context: { role: 'gatewayClient', gatewayClient: { type: 'onebox', id: 'onebox-token' } },
|
||||||
|
};
|
||||||
|
}
|
||||||
|
requests.push({ method, requestData });
|
||||||
|
if (method === 'exportCertificate') {
|
||||||
|
return { success: false };
|
||||||
|
}
|
||||||
|
return { success: true, action: 'created', routeId: 'admin-route' };
|
||||||
|
};
|
||||||
|
|
||||||
|
await manager.syncAdminUiRoute();
|
||||||
|
|
||||||
|
const syncRequest = requests.find((request) => request.method === 'syncGatewayClientRoute')!;
|
||||||
|
const route = syncRequest.requestData.route as any;
|
||||||
|
const ownership = syncRequest.requestData.ownership as any;
|
||||||
|
|
||||||
|
assertEquals(ownership, {
|
||||||
|
gatewayClientType: 'onebox',
|
||||||
|
gatewayClientId: 'onebox-token',
|
||||||
|
appId: 'onebox-admin-ui',
|
||||||
|
hostname: 'onebox.example.com',
|
||||||
|
});
|
||||||
|
assertEquals(route.match, { ports: [443], domains: ['onebox.example.com'] });
|
||||||
|
assertEquals(route.action.targets, [{ host: '203.0.113.10', port: 8080 }]);
|
||||||
|
assertEquals(syncRequest.requestData.enabled, true);
|
||||||
|
});
|
||||||
|
|
||||||
Deno.test('ExternalGatewayManager uses managed dcrouter local target in managed mode', async () => {
|
Deno.test('ExternalGatewayManager uses managed dcrouter local target in managed mode', async () => {
|
||||||
const oneboxRef = makeOneboxRef();
|
const oneboxRef = makeOneboxRef();
|
||||||
(oneboxRef as any).managedDcRouter = {
|
(oneboxRef as any).managedDcRouter = {
|
||||||
@@ -322,6 +363,206 @@ Deno.test('ExternalGatewayManager removes stale gateway routes during reconcilia
|
|||||||
assertEquals((deletes[0].ownership as any).hostname, 'stale.example.com');
|
assertEquals((deletes[0].ownership as any).hostname, 'stale.example.com');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Deno.test('ExternalGatewayManager preserves configured Admin UI route during reconciliation', async () => {
|
||||||
|
const oneboxRef = makeOneboxRef();
|
||||||
|
oneboxRef.database.settings.set('adminUiDomain', 'onebox.example.com');
|
||||||
|
oneboxRef.database.settings.set('serverIP', '203.0.113.10');
|
||||||
|
oneboxRef.database.services.push({
|
||||||
|
id: 1,
|
||||||
|
name: 'active',
|
||||||
|
image: 'nginx:latest',
|
||||||
|
envVars: {},
|
||||||
|
port: 3000,
|
||||||
|
domain: 'active.example.com',
|
||||||
|
status: 'running',
|
||||||
|
createdAt: 1,
|
||||||
|
updatedAt: 1,
|
||||||
|
});
|
||||||
|
|
||||||
|
const deletes: Record<string, unknown>[] = [];
|
||||||
|
const manager = new ExternalGatewayManager(oneboxRef as any);
|
||||||
|
(manager as any).fireDcRouterRequest = async (method: string, requestData: Record<string, unknown>) => {
|
||||||
|
if (method === 'getGatewayClientContext') {
|
||||||
|
return { context: { role: 'gatewayClient', gatewayClient: { type: 'onebox', id: 'onebox-token' } } };
|
||||||
|
}
|
||||||
|
if (method === 'syncGatewayClientRoute') {
|
||||||
|
if (requestData.delete) {
|
||||||
|
deletes.push(requestData);
|
||||||
|
return { success: true, action: 'deleted' };
|
||||||
|
}
|
||||||
|
return { success: true, action: 'updated' };
|
||||||
|
}
|
||||||
|
if (method === 'exportCertificate') {
|
||||||
|
return { success: false };
|
||||||
|
}
|
||||||
|
if (method === 'getGatewayClientDnsRecords') {
|
||||||
|
return {
|
||||||
|
records: [
|
||||||
|
{
|
||||||
|
id: 'admin-record',
|
||||||
|
domainId: 'domain-1',
|
||||||
|
name: 'onebox',
|
||||||
|
type: 'A',
|
||||||
|
value: '203.0.113.10',
|
||||||
|
ttl: 300,
|
||||||
|
source: 'route',
|
||||||
|
status: 'active',
|
||||||
|
gatewayClientType: 'onebox',
|
||||||
|
gatewayClientId: 'onebox-token',
|
||||||
|
appId: 'onebox-admin-ui',
|
||||||
|
hostname: 'onebox.example.com',
|
||||||
|
routeId: 'admin-route',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'stale-record',
|
||||||
|
domainId: 'domain-1',
|
||||||
|
name: 'stale',
|
||||||
|
type: 'A',
|
||||||
|
value: '203.0.113.10',
|
||||||
|
ttl: 300,
|
||||||
|
source: 'route',
|
||||||
|
status: 'active',
|
||||||
|
gatewayClientType: 'onebox',
|
||||||
|
gatewayClientId: 'onebox-token',
|
||||||
|
appId: 'stale',
|
||||||
|
hostname: 'stale.example.com',
|
||||||
|
routeId: 'stale-route',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
throw new Error(`Unexpected method: ${method}`);
|
||||||
|
};
|
||||||
|
|
||||||
|
await manager.syncServiceRoutes();
|
||||||
|
|
||||||
|
assertEquals(deletes.length, 1);
|
||||||
|
assertEquals((deletes[0].ownership as any).hostname, 'stale.example.com');
|
||||||
|
});
|
||||||
|
|
||||||
|
Deno.test('ExternalGatewayManager preserves legacy Admin UI route when setting is absent', async () => {
|
||||||
|
const oneboxRef = makeOneboxRef();
|
||||||
|
oneboxRef.database.settings.set('serverIP', '203.0.113.10');
|
||||||
|
|
||||||
|
const deletes: Record<string, unknown>[] = [];
|
||||||
|
const manager = new ExternalGatewayManager(oneboxRef as any);
|
||||||
|
(manager as any).fireDcRouterRequest = async (
|
||||||
|
method: string,
|
||||||
|
requestData: Record<string, unknown>,
|
||||||
|
) => {
|
||||||
|
if (method === 'getGatewayClientContext') {
|
||||||
|
return {
|
||||||
|
context: { role: 'gatewayClient', gatewayClient: { type: 'onebox', id: 'onebox-token' } },
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if (method === 'syncGatewayClientRoute') {
|
||||||
|
if (requestData.delete) {
|
||||||
|
deletes.push(requestData);
|
||||||
|
return { success: true, action: 'deleted' };
|
||||||
|
}
|
||||||
|
return { success: true, action: 'updated' };
|
||||||
|
}
|
||||||
|
if (method === 'getGatewayClientDnsRecords') {
|
||||||
|
return {
|
||||||
|
records: [
|
||||||
|
{
|
||||||
|
id: 'legacy-admin-record',
|
||||||
|
domainId: 'domain-1',
|
||||||
|
name: 'onebox',
|
||||||
|
type: 'A',
|
||||||
|
value: '203.0.113.10',
|
||||||
|
ttl: 300,
|
||||||
|
source: 'route',
|
||||||
|
status: 'active',
|
||||||
|
gatewayClientType: 'onebox',
|
||||||
|
gatewayClientId: 'onebox-token',
|
||||||
|
appId: 'onebox',
|
||||||
|
hostname: 'onebox.example.com',
|
||||||
|
routeId: 'legacy-admin-route',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'stale-record',
|
||||||
|
domainId: 'domain-1',
|
||||||
|
name: 'stale',
|
||||||
|
type: 'A',
|
||||||
|
value: '203.0.113.10',
|
||||||
|
ttl: 300,
|
||||||
|
source: 'route',
|
||||||
|
status: 'active',
|
||||||
|
gatewayClientType: 'onebox',
|
||||||
|
gatewayClientId: 'onebox-token',
|
||||||
|
appId: 'stale',
|
||||||
|
hostname: 'stale.example.com',
|
||||||
|
routeId: 'stale-route',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
throw new Error(`Unexpected method: ${method}`);
|
||||||
|
};
|
||||||
|
|
||||||
|
await manager.syncServiceRoutes();
|
||||||
|
|
||||||
|
assertEquals(deletes.length, 1);
|
||||||
|
assertEquals((deletes[0].ownership as any).hostname, 'stale.example.com');
|
||||||
|
});
|
||||||
|
|
||||||
|
Deno.test('ExternalGatewayManager deletes old Admin UI route after domain change', async () => {
|
||||||
|
const oneboxRef = makeOneboxRef();
|
||||||
|
oneboxRef.database.settings.set('adminUiDomain', 'new.example.com');
|
||||||
|
oneboxRef.database.settings.set('serverIP', '203.0.113.10');
|
||||||
|
|
||||||
|
const deletes: Record<string, unknown>[] = [];
|
||||||
|
const manager = new ExternalGatewayManager(oneboxRef as any);
|
||||||
|
(manager as any).fireDcRouterRequest = async (
|
||||||
|
method: string,
|
||||||
|
requestData: Record<string, unknown>,
|
||||||
|
) => {
|
||||||
|
if (method === 'getGatewayClientContext') {
|
||||||
|
return {
|
||||||
|
context: { role: 'gatewayClient', gatewayClient: { type: 'onebox', id: 'onebox-token' } },
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if (method === 'syncGatewayClientRoute') {
|
||||||
|
if (requestData.delete) {
|
||||||
|
deletes.push(requestData);
|
||||||
|
return { success: true, action: 'deleted' };
|
||||||
|
}
|
||||||
|
return { success: true, action: 'updated' };
|
||||||
|
}
|
||||||
|
if (method === 'exportCertificate') {
|
||||||
|
return { success: false };
|
||||||
|
}
|
||||||
|
if (method === 'getGatewayClientDnsRecords') {
|
||||||
|
return {
|
||||||
|
records: [
|
||||||
|
{
|
||||||
|
id: 'old-admin-record',
|
||||||
|
domainId: 'domain-1',
|
||||||
|
name: 'onebox',
|
||||||
|
type: 'A',
|
||||||
|
value: '203.0.113.10',
|
||||||
|
ttl: 300,
|
||||||
|
source: 'route',
|
||||||
|
status: 'active',
|
||||||
|
gatewayClientType: 'onebox',
|
||||||
|
gatewayClientId: 'onebox-token',
|
||||||
|
appId: 'onebox-admin-ui',
|
||||||
|
hostname: 'old.example.com',
|
||||||
|
routeId: 'old-admin-route',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
throw new Error(`Unexpected method: ${method}`);
|
||||||
|
};
|
||||||
|
|
||||||
|
await manager.syncServiceRoutes();
|
||||||
|
|
||||||
|
assertEquals(deletes.length, 1);
|
||||||
|
assertEquals((deletes[0].ownership as any).hostname, 'old.example.com');
|
||||||
|
});
|
||||||
|
|
||||||
Deno.test('ExternalGatewayManager imports exported dcrouter certificates into Onebox', async () => {
|
Deno.test('ExternalGatewayManager imports exported dcrouter certificates into Onebox', async () => {
|
||||||
const oneboxRef = makeOneboxRef();
|
const oneboxRef = makeOneboxRef();
|
||||||
const manager = new ExternalGatewayManager(oneboxRef as any);
|
const manager = new ExternalGatewayManager(oneboxRef as any);
|
||||||
|
|||||||
@@ -0,0 +1,50 @@
|
|||||||
|
import { assertEquals } from '@std/assert';
|
||||||
|
|
||||||
|
import { OneboxReverseProxy } from '../ts/classes/reverseproxy.ts';
|
||||||
|
import type { IService } from '../ts/types.ts';
|
||||||
|
|
||||||
|
class FakeDatabase {
|
||||||
|
public settings = new Map<string, string>();
|
||||||
|
public services: IService[] = [];
|
||||||
|
|
||||||
|
getSetting(key: string): string | null {
|
||||||
|
return this.settings.get(key) ?? null;
|
||||||
|
}
|
||||||
|
|
||||||
|
getAllServices(): IService[] {
|
||||||
|
return this.services;
|
||||||
|
}
|
||||||
|
|
||||||
|
getServiceByID(id: number): IService | null {
|
||||||
|
return this.services.find((service) => service.id === id) ?? null;
|
||||||
|
}
|
||||||
|
|
||||||
|
getAllSSLCertificates(): [] {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Deno.test('OneboxReverseProxy loads Admin UI domain as local SmartProxy route', async () => {
|
||||||
|
const database = new FakeDatabase();
|
||||||
|
database.settings.set('adminUiDomain', 'onebox.example.com');
|
||||||
|
database.settings.set('serverIP', '203.0.113.10');
|
||||||
|
|
||||||
|
const reverseProxy = new OneboxReverseProxy({ database } as any);
|
||||||
|
const routes: Array<{ domain: string; upstream: string }> = [];
|
||||||
|
(reverseProxy as any).smartProxy = {
|
||||||
|
clear: () => routes.splice(0, routes.length),
|
||||||
|
addRoute: async (domain: string, upstream: string) => {
|
||||||
|
routes.push({ domain, upstream });
|
||||||
|
},
|
||||||
|
getCertificates: () => [],
|
||||||
|
};
|
||||||
|
|
||||||
|
await reverseProxy.reloadRoutes();
|
||||||
|
|
||||||
|
assertEquals(routes, [
|
||||||
|
{
|
||||||
|
domain: 'onebox.example.com',
|
||||||
|
upstream: '203.0.113.10:3000',
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
});
|
||||||
@@ -3,6 +3,6 @@
|
|||||||
*/
|
*/
|
||||||
export const commitinfo = {
|
export const commitinfo = {
|
||||||
name: '@serve.zone/onebox',
|
name: '@serve.zone/onebox',
|
||||||
version: '1.28.0',
|
version: '1.30.1',
|
||||||
description: 'Self-hosted container platform with automatic SSL and DNS - a mini Heroku for single servers'
|
description: 'Self-hosted container platform with automatic SSL and DNS - a mini Heroku for single servers'
|
||||||
}
|
}
|
||||||
|
|||||||
+102
-17
@@ -1,11 +1,17 @@
|
|||||||
import * as plugins from '../plugins.ts';
|
import * as plugins from '../plugins.ts';
|
||||||
import { logger } from '../logging.ts';
|
import { logger } from '../logging.ts';
|
||||||
import { getErrorMessage } from '../utils/error.ts';
|
import { getErrorMessage } from '../utils/error.ts';
|
||||||
|
import { normalizeHostname } from '../utils/domain.ts';
|
||||||
import { OneboxDatabase } from './database.ts';
|
import { OneboxDatabase } from './database.ts';
|
||||||
import type { IDomain, IService } from '../types.ts';
|
import type { IDomain, IService } from '../types.ts';
|
||||||
import type { TDcRouterMode } from './managed-dcrouter.ts';
|
import type { TDcRouterMode } from './managed-dcrouter.ts';
|
||||||
|
|
||||||
|
const adminUiRouteName = 'onebox-admin-ui';
|
||||||
|
|
||||||
type TWorkHosterType = 'onebox';
|
type TWorkHosterType = 'onebox';
|
||||||
|
type TExternalGatewayRoute = Pick<IService, 'id' | 'name' | 'domain' | 'status'> & {
|
||||||
|
domain: string;
|
||||||
|
};
|
||||||
|
|
||||||
interface IExternalGatewayConfig {
|
interface IExternalGatewayConfig {
|
||||||
url: string;
|
url: string;
|
||||||
@@ -137,15 +143,34 @@ export class ExternalGatewayManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async syncServiceRoutes(): Promise<void> {
|
public async syncServiceRoutes(): Promise<void> {
|
||||||
|
const adminUiRoute = this.getAdminUiRoute();
|
||||||
|
const adminUiDomain = adminUiRoute?.domain;
|
||||||
const services = this.database.getAllServices()
|
const services = this.database.getAllServices()
|
||||||
.filter((service) => service.domain && service.status === 'running');
|
.filter((service) =>
|
||||||
|
service.domain && service.status === 'running' && service.domain !== adminUiDomain
|
||||||
|
);
|
||||||
const activeHostnames = new Set(services.map((service) => service.domain!));
|
const activeHostnames = new Set(services.map((service) => service.domain!));
|
||||||
|
|
||||||
|
if (adminUiRoute) {
|
||||||
|
activeHostnames.add(adminUiRoute.domain);
|
||||||
|
try {
|
||||||
|
await this.syncGatewayRoute(adminUiRoute);
|
||||||
|
} catch (error) {
|
||||||
|
logger.warn(
|
||||||
|
`Failed to sync external gateway route for ${adminUiRoute.domain}: ${
|
||||||
|
getErrorMessage(error)
|
||||||
|
}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (const service of services) {
|
for (const service of services) {
|
||||||
try {
|
try {
|
||||||
await this.syncServiceRoute(service);
|
await this.syncServiceRoute(service);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.warn(`Failed to sync external gateway route for ${service.domain}: ${getErrorMessage(error)}`);
|
logger.warn(
|
||||||
|
`Failed to sync external gateway route for ${service.domain}: ${getErrorMessage(error)}`,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -158,6 +183,7 @@ export class ExternalGatewayManager {
|
|||||||
|
|
||||||
for (const record of records) {
|
for (const record of records) {
|
||||||
if (!record.hostname || activeHostnamesArg.has(record.hostname)) continue;
|
if (!record.hostname || activeHostnamesArg.has(record.hostname)) continue;
|
||||||
|
if (this.shouldPreserveUnconfiguredAdminUiRecord(record)) continue;
|
||||||
if (!record.routeId && !record.appId && !record.serviceName) continue;
|
if (!record.routeId && !record.appId && !record.serviceName) continue;
|
||||||
staleRecordsByHostname.set(record.hostname, record);
|
staleRecordsByHostname.set(record.hostname, record);
|
||||||
}
|
}
|
||||||
@@ -169,7 +195,11 @@ export class ExternalGatewayManager {
|
|||||||
domain: record.hostname,
|
domain: record.hostname,
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.warn(`Failed to delete stale external gateway route for ${record.hostname}: ${getErrorMessage(error)}`);
|
logger.warn(
|
||||||
|
`Failed to delete stale external gateway route for ${record.hostname}: ${
|
||||||
|
getErrorMessage(error)
|
||||||
|
}`,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -289,40 +319,72 @@ export class ExternalGatewayManager {
|
|||||||
public async syncServiceRoute(service: IService): Promise<void> {
|
public async syncServiceRoute(service: IService): Promise<void> {
|
||||||
if (!service.domain) return;
|
if (!service.domain) return;
|
||||||
|
|
||||||
|
await this.syncGatewayRoute({
|
||||||
|
id: service.id,
|
||||||
|
name: service.name,
|
||||||
|
domain: service.domain,
|
||||||
|
status: service.status,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public async syncAdminUiRoute(): Promise<void> {
|
||||||
|
const route = this.getAdminUiRoute();
|
||||||
|
if (!route) return;
|
||||||
|
await this.syncGatewayRoute(route);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async deleteAdminUiRoute(domain: string): Promise<void> {
|
||||||
|
const normalizedDomain = normalizeHostname(domain);
|
||||||
|
if (!normalizedDomain) return;
|
||||||
|
await this.deleteServiceRoute({
|
||||||
|
name: adminUiRouteName,
|
||||||
|
domain: normalizedDomain,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private async syncGatewayRoute(route: TExternalGatewayRoute): Promise<void> {
|
||||||
|
if (!route.domain) return;
|
||||||
|
|
||||||
const config = await this.getConfig({ requireTarget: true });
|
const config = await this.getConfig({ requireTarget: true });
|
||||||
if (!config) return;
|
if (!config) return;
|
||||||
|
|
||||||
const result = await this.fireDcRouterRequest<IWorkAppRouteSyncResult>(
|
const result = await this.fireDcRouterRequest<IWorkAppRouteSyncResult>(
|
||||||
'syncGatewayClientRoute',
|
'syncGatewayClientRoute',
|
||||||
{
|
{
|
||||||
ownership: this.buildGatewayClientOwnership(service, service.domain, config),
|
ownership: this.buildGatewayClientOwnership(route, route.domain, config),
|
||||||
route: this.buildRoute(service, config),
|
route: this.buildRoute(route, config),
|
||||||
enabled: service.status === 'running',
|
enabled: route.status === 'running',
|
||||||
},
|
},
|
||||||
config,
|
config,
|
||||||
).catch(async () => {
|
).catch(async () => {
|
||||||
return await this.fireDcRouterRequest<IWorkAppRouteSyncResult>(
|
return await this.fireDcRouterRequest<IWorkAppRouteSyncResult>(
|
||||||
'syncWorkAppRoute',
|
'syncWorkAppRoute',
|
||||||
{
|
{
|
||||||
ownership: this.buildOwnership(service, service.domain!, config),
|
ownership: this.buildOwnership(route, route.domain, config),
|
||||||
route: this.buildRoute(service, config),
|
route: this.buildRoute(route, config),
|
||||||
enabled: service.status === 'running',
|
enabled: route.status === 'running',
|
||||||
},
|
},
|
||||||
config,
|
config,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!result.success) {
|
if (!result.success) {
|
||||||
throw new Error(result.message || `dcrouter route sync failed for ${service.domain}`);
|
throw new Error(result.message || `dcrouter route sync failed for ${route.domain}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.success(`External gateway route ${result.action || 'synced'} for ${service.domain}`);
|
logger.success(`External gateway route ${result.action || 'synced'} for ${route.domain}`);
|
||||||
await this.importCertificateForDomain(service.domain).catch((error) => {
|
await this.importCertificateForDomain(route.domain).catch((error) => {
|
||||||
logger.debug(`External gateway certificate import skipped for ${service.domain}: ${getErrorMessage(error)}`);
|
logger.debug(
|
||||||
|
`External gateway certificate import skipped for ${route.domain}: ${
|
||||||
|
getErrorMessage(error)
|
||||||
|
}`,
|
||||||
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public async deleteServiceRoute(service: Pick<IService, 'id' | 'name' | 'domain'>): Promise<void> {
|
public async deleteServiceRoute(
|
||||||
|
service: Pick<IService, 'id' | 'name' | 'domain'>,
|
||||||
|
): Promise<void> {
|
||||||
if (!service.domain) return;
|
if (!service.domain) return;
|
||||||
|
|
||||||
const config = await this.getConfig({ requireTarget: false });
|
const config = await this.getConfig({ requireTarget: false });
|
||||||
@@ -536,12 +598,35 @@ export class ExternalGatewayManager {
|
|||||||
return ownership;
|
return ownership;
|
||||||
}
|
}
|
||||||
|
|
||||||
private buildRoute(service: IService, config: IExternalGatewayConfig): IDcRouterRouteConfig {
|
private getAdminUiRoute(): TExternalGatewayRoute | null {
|
||||||
|
const domain = normalizeHostname(this.database.getSetting('adminUiDomain') || '');
|
||||||
|
if (!domain) return null;
|
||||||
return {
|
return {
|
||||||
name: this.routeName(service.domain!),
|
id: 0,
|
||||||
|
name: adminUiRouteName,
|
||||||
|
domain,
|
||||||
|
status: 'running',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private isAdminUiRecord(record: IGatewayDnsRecord): boolean {
|
||||||
|
const ownerName = record.serviceName || record.appId;
|
||||||
|
return ownerName === adminUiRouteName || ownerName === 'onebox';
|
||||||
|
}
|
||||||
|
|
||||||
|
private shouldPreserveUnconfiguredAdminUiRecord(record: IGatewayDnsRecord): boolean {
|
||||||
|
return this.database.getSetting('adminUiDomain') === null && this.isAdminUiRecord(record);
|
||||||
|
}
|
||||||
|
|
||||||
|
private buildRoute(
|
||||||
|
route: TExternalGatewayRoute,
|
||||||
|
config: IExternalGatewayConfig,
|
||||||
|
): IDcRouterRouteConfig {
|
||||||
|
return {
|
||||||
|
name: this.routeName(route.domain),
|
||||||
match: {
|
match: {
|
||||||
ports: [443],
|
ports: [443],
|
||||||
domains: [service.domain!],
|
domains: [route.domain],
|
||||||
},
|
},
|
||||||
action: {
|
action: {
|
||||||
type: 'forward',
|
type: 'forward',
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { logger } from '../logging.ts';
|
import { logger } from '../logging.ts';
|
||||||
|
import { projectInfo } from '../info.ts';
|
||||||
import { getErrorMessage } from '../utils/error.ts';
|
import { getErrorMessage } from '../utils/error.ts';
|
||||||
import { hashPassword } from '../utils/auth.ts';
|
import { hashPassword } from '../utils/auth.ts';
|
||||||
import { OneboxDatabase } from './database.ts';
|
import { OneboxDatabase } from './database.ts';
|
||||||
@@ -26,6 +27,7 @@ import { BackupManager } from './backup-manager.ts';
|
|||||||
import { BackupScheduler } from './backup-scheduler.ts';
|
import { BackupScheduler } from './backup-scheduler.ts';
|
||||||
import { ExternalGatewayManager } from './external-gateway.ts';
|
import { ExternalGatewayManager } from './external-gateway.ts';
|
||||||
import { ManagedDcRouterManager } from './managed-dcrouter.ts';
|
import { ManagedDcRouterManager } from './managed-dcrouter.ts';
|
||||||
|
import { OneboxUpdateManager } from './update-manager.ts';
|
||||||
import { OpsServer } from '../opsserver/index.ts';
|
import { OpsServer } from '../opsserver/index.ts';
|
||||||
|
|
||||||
export class Onebox {
|
export class Onebox {
|
||||||
@@ -48,6 +50,7 @@ export class Onebox {
|
|||||||
public backupScheduler: BackupScheduler;
|
public backupScheduler: BackupScheduler;
|
||||||
public managedDcRouter: ManagedDcRouterManager;
|
public managedDcRouter: ManagedDcRouterManager;
|
||||||
public externalGateway: ExternalGatewayManager;
|
public externalGateway: ExternalGatewayManager;
|
||||||
|
public updateManager: OneboxUpdateManager;
|
||||||
public opsServer: OpsServer;
|
public opsServer: OpsServer;
|
||||||
|
|
||||||
private initialized = false;
|
private initialized = false;
|
||||||
@@ -93,6 +96,7 @@ export class Onebox {
|
|||||||
// Initialize optional dcrouter gateway integration
|
// Initialize optional dcrouter gateway integration
|
||||||
this.managedDcRouter = new ManagedDcRouterManager(this);
|
this.managedDcRouter = new ManagedDcRouterManager(this);
|
||||||
this.externalGateway = new ExternalGatewayManager(this);
|
this.externalGateway = new ExternalGatewayManager(this);
|
||||||
|
this.updateManager = new OneboxUpdateManager();
|
||||||
|
|
||||||
// Initialize OpsServer (TypedRequest-based server)
|
// Initialize OpsServer (TypedRequest-based server)
|
||||||
this.opsServer = new OpsServer(this);
|
this.opsServer = new OpsServer(this);
|
||||||
@@ -305,6 +309,7 @@ export class Onebox {
|
|||||||
const proxyStatus = this.reverseProxy.getStatus();
|
const proxyStatus = this.reverseProxy.getStatus();
|
||||||
const dnsConfigured = this.dns.isConfigured();
|
const dnsConfigured = this.dns.isConfigured();
|
||||||
const sslConfigured = this.ssl.isConfigured();
|
const sslConfigured = this.ssl.isConfigured();
|
||||||
|
const oneboxUpdate = await this.updateManager.getUpdateStatus();
|
||||||
|
|
||||||
const services = this.services.listServices();
|
const services = this.services.listServices();
|
||||||
const runningServices = services.filter((s) => s.status === 'running').length;
|
const runningServices = services.filter((s) => s.status === 'running').length;
|
||||||
@@ -407,6 +412,10 @@ export class Onebox {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
onebox: {
|
||||||
|
version: projectInfo.version,
|
||||||
|
update: oneboxUpdate,
|
||||||
|
},
|
||||||
docker: {
|
docker: {
|
||||||
running: dockerRunning,
|
running: dockerRunning,
|
||||||
version: dockerRunning ? await this.docker.getDockerVersion() : null,
|
version: dockerRunning ? await this.docker.getDockerVersion() : null,
|
||||||
|
|||||||
@@ -10,15 +10,20 @@
|
|||||||
|
|
||||||
import { logger } from '../logging.ts';
|
import { logger } from '../logging.ts';
|
||||||
import { getErrorMessage } from '../utils/error.ts';
|
import { getErrorMessage } from '../utils/error.ts';
|
||||||
|
import { normalizeHostname } from '../utils/domain.ts';
|
||||||
import { OneboxDatabase } from './database.ts';
|
import { OneboxDatabase } from './database.ts';
|
||||||
import { SmartProxyManager } from './smartproxy.ts';
|
import { SmartProxyManager } from './smartproxy.ts';
|
||||||
|
|
||||||
|
const adminUiRouteName = 'onebox-admin-ui';
|
||||||
|
const adminUiPort = 3000;
|
||||||
|
|
||||||
interface IProxyRoute {
|
interface IProxyRoute {
|
||||||
domain: string;
|
domain: string;
|
||||||
targetHost: string;
|
targetHost: string;
|
||||||
targetPort: number;
|
targetPort: number;
|
||||||
serviceId: number;
|
serviceId?: number;
|
||||||
serviceName?: string;
|
serviceName?: string;
|
||||||
|
routeType: 'service' | 'admin-ui';
|
||||||
}
|
}
|
||||||
|
|
||||||
export class OneboxReverseProxy {
|
export class OneboxReverseProxy {
|
||||||
@@ -112,6 +117,7 @@ export class OneboxReverseProxy {
|
|||||||
targetPort,
|
targetPort,
|
||||||
serviceId,
|
serviceId,
|
||||||
serviceName,
|
serviceName,
|
||||||
|
routeType: 'service',
|
||||||
};
|
};
|
||||||
|
|
||||||
this.routes.set(domain, route);
|
this.routes.set(domain, route);
|
||||||
@@ -127,6 +133,25 @@ export class OneboxReverseProxy {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async addAdminUiRoute(domain: string): Promise<void> {
|
||||||
|
const normalizedDomain = normalizeHostname(domain);
|
||||||
|
if (!normalizedDomain) return;
|
||||||
|
|
||||||
|
const targetHost = this.getAdminUiTargetHost();
|
||||||
|
const route: IProxyRoute = {
|
||||||
|
domain: normalizedDomain,
|
||||||
|
targetHost,
|
||||||
|
targetPort: adminUiPort,
|
||||||
|
serviceName: adminUiRouteName,
|
||||||
|
routeType: 'admin-ui',
|
||||||
|
};
|
||||||
|
|
||||||
|
this.routes.set(normalizedDomain, route);
|
||||||
|
const upstream = `${targetHost}:${adminUiPort}`;
|
||||||
|
await this.smartProxy.addRoute(normalizedDomain, upstream);
|
||||||
|
logger.success(`Added Admin UI proxy route: ${normalizedDomain} -> ${upstream}`);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove a route
|
* Remove a route
|
||||||
*/
|
*/
|
||||||
@@ -166,6 +191,11 @@ export class OneboxReverseProxy {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const adminUiDomain = this.getAdminUiDomain();
|
||||||
|
if (adminUiDomain) {
|
||||||
|
await this.addAdminUiRoute(adminUiDomain);
|
||||||
|
}
|
||||||
|
|
||||||
logger.success(`Loaded ${this.routes.size} proxy routes`);
|
logger.success(`Loaded ${this.routes.size} proxy routes`);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(`Failed to reload routes: ${getErrorMessage(error)}`);
|
logger.error(`Failed to reload routes: ${getErrorMessage(error)}`);
|
||||||
@@ -173,6 +203,18 @@ export class OneboxReverseProxy {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private getAdminUiDomain(): string {
|
||||||
|
return normalizeHostname(this.database.getSetting('adminUiDomain') || '');
|
||||||
|
}
|
||||||
|
|
||||||
|
private getAdminUiTargetHost(): string {
|
||||||
|
const serverIP = this.database.getSetting('serverIP');
|
||||||
|
if (!serverIP) {
|
||||||
|
logger.warn('serverIP is not configured; Admin UI proxy route will use host.docker.internal');
|
||||||
|
}
|
||||||
|
return serverIP || 'host.docker.internal';
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add TLS certificate for a domain
|
* Add TLS certificate for a domain
|
||||||
* Sends PEM content to SmartProxy via Admin API
|
* Sends PEM content to SmartProxy via Admin API
|
||||||
|
|||||||
@@ -0,0 +1,214 @@
|
|||||||
|
import { logger } from '../logging.ts';
|
||||||
|
import { projectInfo } from '../info.ts';
|
||||||
|
import { getErrorMessage } from '../utils/error.ts';
|
||||||
|
import * as interfaces from '../../ts_interfaces/index.ts';
|
||||||
|
|
||||||
|
const ONEBOX_REPOSITORY_URL = 'https://code.foss.global/serve.zone/onebox';
|
||||||
|
const ONEBOX_LATEST_RELEASE_API_URL =
|
||||||
|
'https://code.foss.global/api/v1/repos/serve.zone/onebox/releases/latest';
|
||||||
|
const ONEBOX_INSTALL_SCRIPT_URL = `${ONEBOX_REPOSITORY_URL}/raw/branch/main/install.sh`;
|
||||||
|
const ONEBOX_CHANGELOG_URL = `${ONEBOX_REPOSITORY_URL}/src/branch/main/changelog.md`;
|
||||||
|
const UPGRADE_LOG_PATH = '/var/log/onebox-upgrade.log';
|
||||||
|
|
||||||
|
interface IGiteaReleaseResponse {
|
||||||
|
tag_name?: unknown;
|
||||||
|
html_url?: unknown;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface IParsedRelease {
|
||||||
|
tagName: string;
|
||||||
|
releaseUrl: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class OneboxUpdateManager {
|
||||||
|
private cachedStatus: interfaces.data.IOneboxUpdateStatus | null = null;
|
||||||
|
private cachedStatusExpiresAt = 0;
|
||||||
|
private upgradeStartedAt = 0;
|
||||||
|
private readonly statusCacheTtlMs = 5 * 60 * 1000;
|
||||||
|
|
||||||
|
public async getUpdateStatus(
|
||||||
|
optionsArg: { force?: boolean } = {},
|
||||||
|
): Promise<interfaces.data.IOneboxUpdateStatus> {
|
||||||
|
const now = Date.now();
|
||||||
|
if (!optionsArg.force && this.cachedStatus && this.cachedStatusExpiresAt > now) {
|
||||||
|
return this.cachedStatus;
|
||||||
|
}
|
||||||
|
|
||||||
|
const status = await this.fetchUpdateStatus();
|
||||||
|
this.cachedStatus = status;
|
||||||
|
this.cachedStatusExpiresAt = now + this.statusCacheTtlMs;
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async startDetachedUpgrade(): Promise<interfaces.data.IOneboxUpgradeStartResult> {
|
||||||
|
this.assertRoot();
|
||||||
|
|
||||||
|
const status = await this.getUpdateStatus({ force: true });
|
||||||
|
this.assertUpdateCheckSucceeded(status);
|
||||||
|
|
||||||
|
const targetVersion = status.latestVersion || status.currentVersion;
|
||||||
|
if (!status.updateAvailable) {
|
||||||
|
return {
|
||||||
|
accepted: false,
|
||||||
|
currentVersion: status.currentVersion,
|
||||||
|
targetVersion,
|
||||||
|
message: 'Onebox is already up to date.',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.upgradeStartedAt && Date.now() - this.upgradeStartedAt < 10 * 60 * 1000) {
|
||||||
|
return {
|
||||||
|
accepted: false,
|
||||||
|
currentVersion: status.currentVersion,
|
||||||
|
targetVersion,
|
||||||
|
message: 'A Onebox upgrade has already been started.',
|
||||||
|
logPath: UPGRADE_LOG_PATH,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const command = new Deno.Command('bash', {
|
||||||
|
args: ['-c', this.createDetachedUpgradeScript()],
|
||||||
|
stdin: 'null',
|
||||||
|
stdout: 'null',
|
||||||
|
stderr: 'null',
|
||||||
|
detached: true,
|
||||||
|
});
|
||||||
|
const child = command.spawn();
|
||||||
|
child.unref();
|
||||||
|
this.upgradeStartedAt = Date.now();
|
||||||
|
|
||||||
|
logger.info(`Started detached Onebox upgrade process ${child.pid}`);
|
||||||
|
return {
|
||||||
|
accepted: true,
|
||||||
|
currentVersion: status.currentVersion,
|
||||||
|
targetVersion,
|
||||||
|
message: 'Onebox upgrade started. The service will restart automatically.',
|
||||||
|
pid: child.pid,
|
||||||
|
logPath: UPGRADE_LOG_PATH,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public async runUpgradeForeground(
|
||||||
|
statusArg?: interfaces.data.IOneboxUpdateStatus,
|
||||||
|
): Promise<interfaces.data.IOneboxUpgradeStartResult> {
|
||||||
|
this.assertRoot();
|
||||||
|
|
||||||
|
const status = statusArg || (await this.getUpdateStatus({ force: true }));
|
||||||
|
this.assertUpdateCheckSucceeded(status);
|
||||||
|
|
||||||
|
const targetVersion = status.latestVersion || status.currentVersion;
|
||||||
|
if (!status.updateAvailable) {
|
||||||
|
return {
|
||||||
|
accepted: false,
|
||||||
|
currentVersion: status.currentVersion,
|
||||||
|
targetVersion,
|
||||||
|
message: 'Onebox is already up to date.',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const installCommand = new Deno.Command('bash', {
|
||||||
|
args: ['-c', `curl -sSL ${ONEBOX_INSTALL_SCRIPT_URL} | bash`],
|
||||||
|
stdin: 'inherit',
|
||||||
|
stdout: 'inherit',
|
||||||
|
stderr: 'inherit',
|
||||||
|
});
|
||||||
|
const installResult = await installCommand.output();
|
||||||
|
if (!installResult.success) {
|
||||||
|
throw new Error('Upgrade failed');
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
accepted: true,
|
||||||
|
currentVersion: status.currentVersion,
|
||||||
|
targetVersion,
|
||||||
|
message: `Upgraded to ${targetVersion}`,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private async fetchUpdateStatus(): Promise<interfaces.data.IOneboxUpdateStatus> {
|
||||||
|
const currentVersion = this.normalizeVersion(projectInfo.version);
|
||||||
|
const checkedAt = Date.now();
|
||||||
|
|
||||||
|
try {
|
||||||
|
const release = await this.fetchLatestRelease();
|
||||||
|
const latestVersion = this.normalizeVersion(release.tagName);
|
||||||
|
return {
|
||||||
|
currentVersion,
|
||||||
|
latestVersion,
|
||||||
|
updateAvailable: currentVersion !== latestVersion,
|
||||||
|
checkedAt,
|
||||||
|
releaseUrl: release.releaseUrl,
|
||||||
|
changelogUrl: ONEBOX_CHANGELOG_URL,
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
return {
|
||||||
|
currentVersion,
|
||||||
|
latestVersion: null,
|
||||||
|
updateAvailable: false,
|
||||||
|
checkedAt,
|
||||||
|
releaseUrl: `${ONEBOX_REPOSITORY_URL}/releases`,
|
||||||
|
changelogUrl: ONEBOX_CHANGELOG_URL,
|
||||||
|
error: getErrorMessage(error),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async fetchLatestRelease(): Promise<IParsedRelease> {
|
||||||
|
const abortController = new AbortController();
|
||||||
|
const timeoutId = setTimeout(() => abortController.abort(), 5000);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await fetch(ONEBOX_LATEST_RELEASE_API_URL, {
|
||||||
|
headers: { accept: 'application/json' },
|
||||||
|
signal: abortController.signal,
|
||||||
|
});
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(`Failed to fetch latest release: HTTP ${response.status}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const release = await response.json() as IGiteaReleaseResponse;
|
||||||
|
if (typeof release.tag_name !== 'string' || !release.tag_name) {
|
||||||
|
throw new Error('Latest release response does not include a tag name');
|
||||||
|
}
|
||||||
|
|
||||||
|
const tagName = release.tag_name;
|
||||||
|
const releaseUrl = typeof release.html_url === 'string' && release.html_url
|
||||||
|
? release.html_url
|
||||||
|
: `${ONEBOX_REPOSITORY_URL}/releases/tag/${this.normalizeVersion(tagName)}`;
|
||||||
|
|
||||||
|
return { tagName, releaseUrl };
|
||||||
|
} finally {
|
||||||
|
clearTimeout(timeoutId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private assertRoot(): void {
|
||||||
|
if (Deno.uid() !== 0) {
|
||||||
|
throw new Error('Onebox upgrades must be started as root. Try: sudo onebox upgrade');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private assertUpdateCheckSucceeded(statusArg: interfaces.data.IOneboxUpdateStatus): void {
|
||||||
|
if (statusArg.error) {
|
||||||
|
throw new Error(`Cannot determine latest Onebox release: ${statusArg.error}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private normalizeVersion(versionArg: string): string {
|
||||||
|
const trimmedVersion = versionArg.trim();
|
||||||
|
return trimmedVersion.startsWith('v') ? trimmedVersion : `v${trimmedVersion}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
private createDetachedUpgradeScript(): string {
|
||||||
|
return `
|
||||||
|
set -e
|
||||||
|
mkdir -p /var/log
|
||||||
|
{
|
||||||
|
echo "==== Onebox upgrade started $(date -Is) ===="
|
||||||
|
sleep 2
|
||||||
|
curl -sSL ${ONEBOX_INSTALL_SCRIPT_URL} | bash
|
||||||
|
echo "==== Onebox upgrade finished $(date -Is) ===="
|
||||||
|
} >> ${UPGRADE_LOG_PATH} 2>&1
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,6 +8,7 @@ import { getErrorMessage } from './utils/error.ts';
|
|||||||
import { Onebox } from './classes/onebox.ts';
|
import { Onebox } from './classes/onebox.ts';
|
||||||
import { OneboxDaemon } from './classes/daemon.ts';
|
import { OneboxDaemon } from './classes/daemon.ts';
|
||||||
import { OneboxSystemd } from './classes/systemd.ts';
|
import { OneboxSystemd } from './classes/systemd.ts';
|
||||||
|
import { OneboxUpdateManager } from './classes/update-manager.ts';
|
||||||
import type { IAppVersionConfig } from './classes/appstore-types.ts';
|
import type { IAppVersionConfig } from './classes/appstore-types.ts';
|
||||||
|
|
||||||
export async function runCli(): Promise<void> {
|
export async function runCli(): Promise<void> {
|
||||||
@@ -500,60 +501,29 @@ async function handleUpgradeCommand(): Promise<void> {
|
|||||||
logger.info('Checking for updates...');
|
logger.info('Checking for updates...');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Get current version
|
const updateManager = new OneboxUpdateManager();
|
||||||
const currentVersion = projectInfo.version;
|
const status = await updateManager.getUpdateStatus({ force: true });
|
||||||
|
if (status.error) {
|
||||||
|
throw new Error(status.error);
|
||||||
|
}
|
||||||
|
|
||||||
// Fetch latest version from Gitea API
|
console.log(` Current version: ${status.currentVersion}`);
|
||||||
const apiUrl = 'https://code.foss.global/api/v1/repos/serve.zone/onebox/releases/latest';
|
console.log(` Latest version: ${status.latestVersion}`);
|
||||||
const curlCmd = new Deno.Command('curl', {
|
|
||||||
args: ['-sSL', apiUrl],
|
|
||||||
stdout: 'piped',
|
|
||||||
stderr: 'piped',
|
|
||||||
});
|
|
||||||
const curlResult = await curlCmd.output();
|
|
||||||
const response = new TextDecoder().decode(curlResult.stdout);
|
|
||||||
const release = JSON.parse(response);
|
|
||||||
const latestVersion = release.tag_name as string; // e.g., "v1.11.0"
|
|
||||||
|
|
||||||
// Normalize versions for comparison (ensure both have "v" prefix)
|
|
||||||
const normalizedCurrent = currentVersion.startsWith('v')
|
|
||||||
? currentVersion
|
|
||||||
: `v${currentVersion}`;
|
|
||||||
const normalizedLatest = latestVersion.startsWith('v')
|
|
||||||
? latestVersion
|
|
||||||
: `v${latestVersion}`;
|
|
||||||
|
|
||||||
console.log(` Current version: ${normalizedCurrent}`);
|
|
||||||
console.log(` Latest version: ${normalizedLatest}`);
|
|
||||||
console.log('');
|
console.log('');
|
||||||
|
|
||||||
// Compare normalized versions
|
if (!status.updateAvailable) {
|
||||||
if (normalizedCurrent === normalizedLatest) {
|
|
||||||
logger.success('Already up to date!');
|
logger.success('Already up to date!');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.info(`New version available: ${latestVersion}`);
|
logger.info(`New version available: ${status.latestVersion}`);
|
||||||
logger.info('Downloading and installing...');
|
logger.info('Downloading and installing...');
|
||||||
console.log('');
|
console.log('');
|
||||||
|
|
||||||
// Download and run the install script
|
const upgrade = await updateManager.runUpgradeForeground(status);
|
||||||
const installUrl = 'https://code.foss.global/serve.zone/onebox/raw/branch/main/install.sh';
|
|
||||||
const installCmd = new Deno.Command('bash', {
|
|
||||||
args: ['-c', `curl -sSL ${installUrl} | bash`],
|
|
||||||
stdin: 'inherit',
|
|
||||||
stdout: 'inherit',
|
|
||||||
stderr: 'inherit',
|
|
||||||
});
|
|
||||||
const installResult = await installCmd.output();
|
|
||||||
|
|
||||||
if (!installResult.success) {
|
|
||||||
logger.error('Upgrade failed');
|
|
||||||
Deno.exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log('');
|
console.log('');
|
||||||
logger.success(`Upgraded to ${latestVersion}`);
|
logger.success(upgrade.message);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(`Upgrade failed: ${getErrorMessage(error)}`);
|
logger.error(`Upgrade failed: ${getErrorMessage(error)}`);
|
||||||
Deno.exit(1);
|
Deno.exit(1);
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import * as interfaces from '../../../ts_interfaces/index.ts';
|
|||||||
import { requireAdminIdentity } from '../helpers/guards.ts';
|
import { requireAdminIdentity } from '../helpers/guards.ts';
|
||||||
import { logger } from '../../logging.ts';
|
import { logger } from '../../logging.ts';
|
||||||
import { getErrorMessage } from '../../utils/error.ts';
|
import { getErrorMessage } from '../../utils/error.ts';
|
||||||
|
import { isValidHostname, normalizeHostname } from '../../utils/domain.ts';
|
||||||
|
|
||||||
export class SettingsHandler {
|
export class SettingsHandler {
|
||||||
public typedrouter = new plugins.typedrequest.TypedRouter();
|
public typedrouter = new plugins.typedrequest.TypedRouter();
|
||||||
@@ -23,6 +24,7 @@ export class SettingsHandler {
|
|||||||
return {
|
return {
|
||||||
cloudflareToken: cloudflareToken || '',
|
cloudflareToken: cloudflareToken || '',
|
||||||
cloudflareZoneId: settingsMap['cloudflareZoneId'] || '',
|
cloudflareZoneId: settingsMap['cloudflareZoneId'] || '',
|
||||||
|
adminUiDomain: settingsMap['adminUiDomain'] || '',
|
||||||
dcrouterMode: managedDcRouter.getMode(),
|
dcrouterMode: managedDcRouter.getMode(),
|
||||||
dcrouterManagedImage: managedDcRouter.getImage(),
|
dcrouterManagedImage: managedDcRouter.getImage(),
|
||||||
dcrouterManagedOpsPort: managedDcRouter.getOpsPort(),
|
dcrouterManagedOpsPort: managedDcRouter.getOpsPort(),
|
||||||
@@ -64,8 +66,10 @@ export class SettingsHandler {
|
|||||||
const db = this.opsServerRef.oneboxRef.database;
|
const db = this.opsServerRef.oneboxRef.database;
|
||||||
const updates = dataArg.settings;
|
const updates = dataArg.settings;
|
||||||
|
|
||||||
|
const normalizedUpdates = this.normalizeUpdates(updates);
|
||||||
|
|
||||||
// Store each setting as key-value pair
|
// Store each setting as key-value pair
|
||||||
for (const [key, value] of Object.entries(updates)) {
|
for (const [key, value] of Object.entries(normalizedUpdates)) {
|
||||||
if (value !== undefined) {
|
if (value !== undefined) {
|
||||||
if (db.isSecretSettingKey(key)) {
|
if (db.isSecretSettingKey(key)) {
|
||||||
await db.setSecretSetting(key, String(value));
|
await db.setSecretSetting(key, String(value));
|
||||||
@@ -75,8 +79,8 @@ export class SettingsHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.hasExternalGatewaySetting(updates)) {
|
if (this.hasRouteSyncSetting(normalizedUpdates)) {
|
||||||
this.refreshDcRouterGateway().catch((error) => {
|
this.refreshGatewayRoutes(normalizedUpdates).catch((error) => {
|
||||||
logger.warn(`dcrouter gateway settings refresh failed: ${getErrorMessage(error)}`);
|
logger.warn(`dcrouter gateway settings refresh failed: ${getErrorMessage(error)}`);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -110,8 +114,23 @@ export class SettingsHandler {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private hasExternalGatewaySetting(settings: Partial<interfaces.data.ISettings>): boolean {
|
private normalizeUpdates(
|
||||||
|
settings: Partial<interfaces.data.ISettings>,
|
||||||
|
): Partial<interfaces.data.ISettings> {
|
||||||
|
const normalizedUpdates = { ...settings };
|
||||||
|
if (Object.prototype.hasOwnProperty.call(normalizedUpdates, 'adminUiDomain')) {
|
||||||
|
const normalizedDomain = normalizeHostname(String(normalizedUpdates.adminUiDomain || ''));
|
||||||
|
if (!isValidHostname(normalizedDomain)) {
|
||||||
|
throw new plugins.typedrequest.TypedResponseError('Invalid Admin UI domain');
|
||||||
|
}
|
||||||
|
normalizedUpdates.adminUiDomain = normalizedDomain;
|
||||||
|
}
|
||||||
|
return normalizedUpdates;
|
||||||
|
}
|
||||||
|
|
||||||
|
private hasRouteSyncSetting(settings: Partial<interfaces.data.ISettings>): boolean {
|
||||||
return [
|
return [
|
||||||
|
'adminUiDomain',
|
||||||
'dcrouterMode',
|
'dcrouterMode',
|
||||||
'dcrouterManagedImage',
|
'dcrouterManagedImage',
|
||||||
'dcrouterManagedOpsPort',
|
'dcrouterManagedOpsPort',
|
||||||
@@ -127,23 +146,29 @@ export class SettingsHandler {
|
|||||||
].some((key) => Object.prototype.hasOwnProperty.call(settings, key));
|
].some((key) => Object.prototype.hasOwnProperty.call(settings, key));
|
||||||
}
|
}
|
||||||
|
|
||||||
private async refreshDcRouterGateway(): Promise<void> {
|
private hasManagedDcRouterRuntimeSetting(settings: Partial<interfaces.data.ISettings>): boolean {
|
||||||
|
return [
|
||||||
|
'dcrouterMode',
|
||||||
|
'dcrouterManagedImage',
|
||||||
|
'dcrouterManagedOpsPort',
|
||||||
|
'dcrouterManagedHttpPort',
|
||||||
|
'dcrouterManagedHttpsPort',
|
||||||
|
'dcrouterManagedDataDir',
|
||||||
|
].some((key) => Object.prototype.hasOwnProperty.call(settings, key));
|
||||||
|
}
|
||||||
|
|
||||||
|
private async refreshGatewayRoutes(settings: Partial<interfaces.data.ISettings>): Promise<void> {
|
||||||
const onebox = this.opsServerRef.oneboxRef;
|
const onebox = this.opsServerRef.oneboxRef;
|
||||||
|
if (this.hasManagedDcRouterRuntimeSetting(settings)) {
|
||||||
if (onebox.managedDcRouter.getMode() === 'managed') {
|
if (onebox.managedDcRouter.getMode() === 'managed') {
|
||||||
await onebox.managedDcRouter.restart();
|
await onebox.managedDcRouter.restart();
|
||||||
} else {
|
} else {
|
||||||
await onebox.managedDcRouter.stop();
|
await onebox.managedDcRouter.stop();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
await onebox.reverseProxy.reloadRoutes();
|
||||||
await onebox.externalGateway.syncDomains();
|
await onebox.externalGateway.syncDomains();
|
||||||
|
await onebox.externalGateway.syncServiceRoutes();
|
||||||
const services = onebox.database.getAllServices().filter((service) => service.domain);
|
|
||||||
await Promise.all(services.map(async (service) => {
|
|
||||||
try {
|
|
||||||
await onebox.externalGateway.syncServiceRoute(service);
|
|
||||||
} catch (error) {
|
|
||||||
logger.warn(`Failed to sync external gateway route for ${service.domain}: ${getErrorMessage(error)}`);
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import * as plugins from '../../plugins.ts';
|
|||||||
import type { OpsServer } from '../classes.opsserver.ts';
|
import type { OpsServer } from '../classes.opsserver.ts';
|
||||||
import * as interfaces from '../../../ts_interfaces/index.ts';
|
import * as interfaces from '../../../ts_interfaces/index.ts';
|
||||||
import { requireAdminIdentity } from '../helpers/guards.ts';
|
import { requireAdminIdentity } from '../helpers/guards.ts';
|
||||||
|
import { getErrorMessage } from '../../utils/error.ts';
|
||||||
|
|
||||||
export class StatusHandler {
|
export class StatusHandler {
|
||||||
public typedrouter = new plugins.typedrequest.TypedRouter();
|
public typedrouter = new plugins.typedrequest.TypedRouter();
|
||||||
@@ -22,5 +23,20 @@ export class StatusHandler {
|
|||||||
},
|
},
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
this.typedrouter.addTypedHandler(
|
||||||
|
new plugins.typedrequest.TypedHandler<interfaces.requests.IReq_StartOneboxUpgrade>(
|
||||||
|
'startOneboxUpgrade',
|
||||||
|
async (dataArg) => {
|
||||||
|
await requireAdminIdentity(this.opsServerRef.adminHandler, dataArg);
|
||||||
|
try {
|
||||||
|
const upgrade = await this.opsServerRef.oneboxRef.updateManager.startDetachedUpgrade();
|
||||||
|
return { upgrade };
|
||||||
|
} catch (error) {
|
||||||
|
throw new plugins.typedrequest.TypedResponseError(getErrorMessage(error));
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -280,6 +280,7 @@ export interface ISetting {
|
|||||||
// Application settings
|
// Application settings
|
||||||
export interface IAppSettings {
|
export interface IAppSettings {
|
||||||
serverIP?: string;
|
serverIP?: string;
|
||||||
|
adminUiDomain?: string;
|
||||||
cloudflareToken?: string;
|
cloudflareToken?: string;
|
||||||
cloudflareZoneId?: string;
|
cloudflareZoneId?: string;
|
||||||
dcrouterMode?: 'managed' | 'external' | 'disabled';
|
dcrouterMode?: 'managed' | 'external' | 'disabled';
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
export function normalizeHostname(valueArg: string): string {
|
||||||
|
const trimmedValue = valueArg.trim().toLowerCase();
|
||||||
|
if (!trimmedValue) return '';
|
||||||
|
|
||||||
|
const withoutProtocol = trimmedValue.replace(/^[a-z][a-z0-9+.-]*:\/\//, '');
|
||||||
|
const withoutPath = withoutProtocol.split('/')[0].split('?')[0].split('#')[0];
|
||||||
|
return withoutPath.replace(/:\d+$/, '').replace(/\.$/, '');
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isValidHostname(hostnameArg: string): boolean {
|
||||||
|
if (!hostnameArg) return true;
|
||||||
|
if (hostnameArg.length > 253) return false;
|
||||||
|
return hostnameArg.split('.').every((label) => {
|
||||||
|
if (!label || label.length > 63) return false;
|
||||||
|
return /^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/.test(label);
|
||||||
|
});
|
||||||
|
}
|
||||||
File diff suppressed because one or more lines are too long
@@ -21,6 +21,7 @@ export interface IManagedDcRouterStatus {
|
|||||||
export interface ISettings {
|
export interface ISettings {
|
||||||
cloudflareToken: string;
|
cloudflareToken: string;
|
||||||
cloudflareZoneId: string;
|
cloudflareZoneId: string;
|
||||||
|
adminUiDomain: string;
|
||||||
dcrouterMode: TDcRouterMode;
|
dcrouterMode: TDcRouterMode;
|
||||||
dcrouterManagedImage: string;
|
dcrouterManagedImage: string;
|
||||||
dcrouterManagedOpsPort: number;
|
dcrouterManagedOpsPort: number;
|
||||||
|
|||||||
@@ -4,7 +4,30 @@
|
|||||||
|
|
||||||
import type { TPlatformServiceType, TPlatformServiceStatus } from './platform.ts';
|
import type { TPlatformServiceType, TPlatformServiceStatus } from './platform.ts';
|
||||||
|
|
||||||
|
export interface IOneboxUpdateStatus {
|
||||||
|
currentVersion: string;
|
||||||
|
latestVersion: string | null;
|
||||||
|
updateAvailable: boolean;
|
||||||
|
checkedAt: number;
|
||||||
|
releaseUrl: string;
|
||||||
|
changelogUrl: string;
|
||||||
|
error?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface IOneboxUpgradeStartResult {
|
||||||
|
accepted: boolean;
|
||||||
|
currentVersion: string;
|
||||||
|
targetVersion: string;
|
||||||
|
message: string;
|
||||||
|
pid?: number;
|
||||||
|
logPath?: string;
|
||||||
|
}
|
||||||
|
|
||||||
export interface ISystemStatus {
|
export interface ISystemStatus {
|
||||||
|
onebox: {
|
||||||
|
version: string;
|
||||||
|
update: IOneboxUpdateStatus;
|
||||||
|
};
|
||||||
docker: {
|
docker: {
|
||||||
running: boolean;
|
running: boolean;
|
||||||
version: unknown;
|
version: unknown;
|
||||||
|
|||||||
@@ -13,3 +13,16 @@ export interface IReq_GetSystemStatus extends plugins.typedrequestInterfaces.imp
|
|||||||
status: data.ISystemStatus;
|
status: data.ISystemStatus;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface IReq_StartOneboxUpgrade extends plugins.typedrequestInterfaces.implementsTR<
|
||||||
|
plugins.typedrequestInterfaces.ITypedRequest,
|
||||||
|
IReq_StartOneboxUpgrade
|
||||||
|
> {
|
||||||
|
method: 'startOneboxUpgrade';
|
||||||
|
request: {
|
||||||
|
identity: data.IIdentity;
|
||||||
|
};
|
||||||
|
response: {
|
||||||
|
upgrade: data.IOneboxUpgradeStartResult;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,6 +3,6 @@
|
|||||||
*/
|
*/
|
||||||
export const commitinfo = {
|
export const commitinfo = {
|
||||||
name: '@serve.zone/onebox',
|
name: '@serve.zone/onebox',
|
||||||
version: '1.28.0',
|
version: '1.30.1',
|
||||||
description: 'Self-hosted container platform with automatic SSL and DNS - a mini Heroku for single servers'
|
description: 'Self-hosted container platform with automatic SSL and DNS - a mini Heroku for single servers'
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,6 +41,14 @@ export class ObAppShell extends DeesElement {
|
|||||||
refreshInterval: 30000,
|
refreshInterval: 30000,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@state()
|
||||||
|
accessor systemState: appstate.ISystemState = {
|
||||||
|
status: null,
|
||||||
|
};
|
||||||
|
|
||||||
|
@state()
|
||||||
|
accessor globalMessages: plugins.deesCatalog.IGlobalMessage[] = [];
|
||||||
|
|
||||||
@state()
|
@state()
|
||||||
accessor loginLoading: boolean = false;
|
accessor loginLoading: boolean = false;
|
||||||
|
|
||||||
@@ -126,6 +134,8 @@ export class ObAppShell extends DeesElement {
|
|||||||
];
|
];
|
||||||
|
|
||||||
private resolvedViewTabs: IResolvedView[] = [];
|
private resolvedViewTabs: IResolvedView[] = [];
|
||||||
|
private suppressedUpdateVersion = '';
|
||||||
|
private upgradeFlowRunning = false;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
@@ -135,12 +145,21 @@ export class ObAppShell extends DeesElement {
|
|||||||
.select((stateArg: appstate.ILoginState) => stateArg)
|
.select((stateArg: appstate.ILoginState) => stateArg)
|
||||||
.subscribe((loginState: appstate.ILoginState) => {
|
.subscribe((loginState: appstate.ILoginState) => {
|
||||||
this.loginState = loginState;
|
this.loginState = loginState;
|
||||||
|
this.updateGlobalMessages();
|
||||||
if (loginState.isLoggedIn) {
|
if (loginState.isLoggedIn) {
|
||||||
appstate.systemStatePart.dispatchAction(appstate.fetchSystemStatusAction, null);
|
appstate.systemStatePart.dispatchAction(appstate.fetchSystemStatusAction, null);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.rxSubscriptions.push(loginSubscription);
|
this.rxSubscriptions.push(loginSubscription);
|
||||||
|
|
||||||
|
const systemSubscription = appstate.systemStatePart
|
||||||
|
.select((stateArg: appstate.ISystemState) => stateArg)
|
||||||
|
.subscribe((systemState: appstate.ISystemState) => {
|
||||||
|
this.systemState = systemState;
|
||||||
|
this.updateGlobalMessages();
|
||||||
|
});
|
||||||
|
this.rxSubscriptions.push(systemSubscription);
|
||||||
|
|
||||||
const uiSubscription = appstate.uiStatePart
|
const uiSubscription = appstate.uiStatePart
|
||||||
.select((stateArg: appstate.IUiState) => stateArg)
|
.select((stateArg: appstate.IUiState) => stateArg)
|
||||||
.subscribe((uiState: appstate.IUiState) => {
|
.subscribe((uiState: appstate.IUiState) => {
|
||||||
@@ -214,6 +233,7 @@ export class ObAppShell extends DeesElement {
|
|||||||
name="Onebox"
|
name="Onebox"
|
||||||
.viewTabs=${this.resolvedViewTabs}
|
.viewTabs=${this.resolvedViewTabs}
|
||||||
.selectedView=${this.currentViewTab}
|
.selectedView=${this.currentViewTab}
|
||||||
|
.globalMessages=${this.globalMessages}
|
||||||
>
|
>
|
||||||
</dees-simple-appdash>
|
</dees-simple-appdash>
|
||||||
</dees-simple-login>
|
</dees-simple-login>
|
||||||
@@ -324,6 +344,177 @@ export class ObAppShell extends DeesElement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private updateGlobalMessages(): void {
|
||||||
|
const updateStatus = this.systemState.status?.onebox.update;
|
||||||
|
if (
|
||||||
|
!this.loginState.isLoggedIn ||
|
||||||
|
!updateStatus?.updateAvailable ||
|
||||||
|
!updateStatus.latestVersion ||
|
||||||
|
updateStatus.latestVersion === this.suppressedUpdateVersion
|
||||||
|
) {
|
||||||
|
this.globalMessages = [];
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.globalMessages = [
|
||||||
|
{
|
||||||
|
id: `onebox-update-${updateStatus.latestVersion}`,
|
||||||
|
type: 'info',
|
||||||
|
icon: 'lucide:download',
|
||||||
|
message: `Onebox ${updateStatus.latestVersion} is available. Current version: ${updateStatus.currentVersion}.`,
|
||||||
|
dismissible: false,
|
||||||
|
actions: [
|
||||||
|
{
|
||||||
|
name: 'Update Now',
|
||||||
|
iconName: 'lucide:download',
|
||||||
|
action: () => this.startOneboxUpgradeFlow(),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Release Notes',
|
||||||
|
iconName: 'lucide:fileText',
|
||||||
|
action: () => this.openUpdateUrl(updateStatus.changelogUrl || updateStatus.releaseUrl),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Later',
|
||||||
|
iconName: 'lucide:clock',
|
||||||
|
action: () => {
|
||||||
|
this.suppressedUpdateVersion = updateStatus.latestVersion || '';
|
||||||
|
this.updateGlobalMessages();
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
private async startOneboxUpgradeFlow(): Promise<void> {
|
||||||
|
if (this.upgradeFlowRunning) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const identity = appstate.loginStatePart.getState().identity;
|
||||||
|
const updateStatus = this.systemState.status?.onebox.update;
|
||||||
|
if (!identity || !updateStatus?.latestVersion) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.upgradeFlowRunning = true;
|
||||||
|
const updater = await plugins.deesCatalog.DeesUpdater.createAndShow({
|
||||||
|
currentVersion: updateStatus.currentVersion,
|
||||||
|
updatedVersion: updateStatus.latestVersion,
|
||||||
|
moreInfoUrl: updateStatus.releaseUrl,
|
||||||
|
changelogUrl: updateStatus.changelogUrl,
|
||||||
|
successAction: 'reload',
|
||||||
|
successDelayMs: 30000,
|
||||||
|
successActionLabel: 'Reloading Onebox UI',
|
||||||
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
|
updater.updateProgress({
|
||||||
|
percentage: 10,
|
||||||
|
indeterminate: true,
|
||||||
|
statusText: 'Requesting upgrade...',
|
||||||
|
terminalLines: ['Requesting Onebox upgrade'],
|
||||||
|
});
|
||||||
|
|
||||||
|
const typedRequest = new plugins.domtools.plugins.typedrequest.TypedRequest<
|
||||||
|
interfaces.requests.IReq_StartOneboxUpgrade
|
||||||
|
>('/typedrequest', 'startOneboxUpgrade');
|
||||||
|
const response = await typedRequest.fire({ identity });
|
||||||
|
|
||||||
|
if (!response.upgrade.accepted) {
|
||||||
|
updater.markUpdateError(response.upgrade.message);
|
||||||
|
await this.delay(5000);
|
||||||
|
await updater.destroy();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
updater.appendProgressLine(response.upgrade.message);
|
||||||
|
if (response.upgrade.pid) {
|
||||||
|
updater.appendProgressLine(`Upgrade process PID: ${response.upgrade.pid}`);
|
||||||
|
}
|
||||||
|
if (response.upgrade.logPath) {
|
||||||
|
updater.appendProgressLine(`Upgrade log: ${response.upgrade.logPath}`);
|
||||||
|
}
|
||||||
|
updater.updateProgress({
|
||||||
|
percentage: 45,
|
||||||
|
indeterminate: true,
|
||||||
|
statusText: 'Installer started...',
|
||||||
|
});
|
||||||
|
|
||||||
|
await this.waitForOneboxUpgrade(updater, response.upgrade.targetVersion, identity);
|
||||||
|
await updater.markUpdateReady();
|
||||||
|
} catch (error) {
|
||||||
|
updater.markUpdateError(this.getErrorMessage(error));
|
||||||
|
await this.delay(5000);
|
||||||
|
await updater.destroy();
|
||||||
|
} finally {
|
||||||
|
this.upgradeFlowRunning = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async waitForOneboxUpgrade(
|
||||||
|
updaterArg: plugins.deesCatalog.DeesUpdater,
|
||||||
|
targetVersionArg: string,
|
||||||
|
identityArg: interfaces.data.IIdentity,
|
||||||
|
): Promise<void> {
|
||||||
|
const normalizedTargetVersion = this.normalizeVersion(targetVersionArg);
|
||||||
|
const timeoutAt = Date.now() + 90000;
|
||||||
|
let attempt = 0;
|
||||||
|
|
||||||
|
updaterArg.appendProgressLine('Waiting for Onebox to restart with the new version');
|
||||||
|
while (Date.now() < timeoutAt) {
|
||||||
|
await this.delay(5000);
|
||||||
|
attempt++;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const typedRequest = new plugins.domtools.plugins.typedrequest.TypedRequest<
|
||||||
|
interfaces.requests.IReq_GetSystemStatus
|
||||||
|
>('/typedrequest', 'getSystemStatus');
|
||||||
|
const response = await typedRequest.fire({ identity: identityArg });
|
||||||
|
const onlineVersion = this.normalizeVersion(response.status.onebox.version);
|
||||||
|
updaterArg.appendProgressLine(`Onebox API answered with ${onlineVersion}`);
|
||||||
|
|
||||||
|
if (onlineVersion === normalizedTargetVersion) {
|
||||||
|
updaterArg.updateProgress({
|
||||||
|
percentage: 100,
|
||||||
|
indeterminate: false,
|
||||||
|
statusText: `Onebox ${normalizedTargetVersion} is online.`,
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
updaterArg.appendProgressLine('Onebox API is restarting...');
|
||||||
|
}
|
||||||
|
|
||||||
|
updaterArg.updateProgress({
|
||||||
|
percentage: Math.min(95, 45 + attempt * 5),
|
||||||
|
indeterminate: true,
|
||||||
|
statusText: `Waiting for Onebox ${normalizedTargetVersion}...`,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
updaterArg.appendProgressLine('Timed out waiting for the version check; reloading the UI anyway');
|
||||||
|
}
|
||||||
|
|
||||||
|
private openUpdateUrl(urlArg: string): void {
|
||||||
|
window.open(urlArg, '_blank', 'noopener,noreferrer');
|
||||||
|
}
|
||||||
|
|
||||||
|
private async delay(millisecondsArg: number): Promise<void> {
|
||||||
|
const domtools = await this.domtoolsPromise;
|
||||||
|
await domtools.convenience.smartdelay.delayFor(millisecondsArg);
|
||||||
|
}
|
||||||
|
|
||||||
|
private getErrorMessage(errorArg: unknown): string {
|
||||||
|
return errorArg instanceof Error ? errorArg.message : String(errorArg);
|
||||||
|
}
|
||||||
|
|
||||||
|
private normalizeVersion(versionArg: string): string {
|
||||||
|
const trimmedVersion = versionArg.trim();
|
||||||
|
return trimmedVersion.startsWith('v') ? trimmedVersion : `v${trimmedVersion}`;
|
||||||
|
}
|
||||||
|
|
||||||
private syncAppdashView(viewName: string, subviewName: string | null): void {
|
private syncAppdashView(viewName: string, subviewName: string | null): void {
|
||||||
const appDash = this.shadowRoot?.querySelector('dees-simple-appdash') as any;
|
const appDash = this.shadowRoot?.querySelector('dees-simple-appdash') as any;
|
||||||
if (!appDash || this.resolvedViewTabs.length === 0) return;
|
if (!appDash || this.resolvedViewTabs.length === 0) return;
|
||||||
|
|||||||
@@ -48,31 +48,45 @@ export class ObViewSettings extends DeesElement {
|
|||||||
cssManager.defaultStyles,
|
cssManager.defaultStyles,
|
||||||
shared.viewHostCss,
|
shared.viewHostCss,
|
||||||
css`
|
css`
|
||||||
.gateway-card {
|
dees-tile {
|
||||||
|
display: block;
|
||||||
margin-bottom: 24px;
|
margin-bottom: 24px;
|
||||||
border: 1px solid ${cssManager.bdTheme('#e4e4e7', '#27272a')};
|
|
||||||
border-radius: 12px;
|
|
||||||
background: ${cssManager.bdTheme('#ffffff', '#09090b')};
|
|
||||||
overflow: hidden;
|
|
||||||
box-shadow: 0 1px 2px ${cssManager.bdTheme('rgba(0,0,0,0.04)', 'rgba(0,0,0,0.2)')};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.gateway-header {
|
.gateway-header {
|
||||||
padding: 16px 20px;
|
height: 36px;
|
||||||
border-bottom: 1px solid ${cssManager.bdTheme('#f4f4f5', '#27272a')};
|
display: flex;
|
||||||
background: ${cssManager.bdTheme('#fafafa', '#101013')};
|
align-items: center;
|
||||||
|
padding: 0 16px;
|
||||||
|
width: 100%;
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
.gateway-heading {
|
||||||
|
flex: 1;
|
||||||
|
display: flex;
|
||||||
|
align-items: baseline;
|
||||||
|
gap: 8px;
|
||||||
|
min-width: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.gateway-title {
|
.gateway-title {
|
||||||
font-size: 15px;
|
font-size: 13px;
|
||||||
font-weight: 600;
|
font-weight: 500;
|
||||||
color: ${cssManager.bdTheme('#18181b', '#fafafa')};
|
letter-spacing: -0.01em;
|
||||||
|
color: var(--dees-color-text-secondary);
|
||||||
|
white-space: nowrap;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
}
|
}
|
||||||
|
|
||||||
.gateway-subtitle {
|
.gateway-subtitle {
|
||||||
margin-top: 4px;
|
font-size: 12px;
|
||||||
font-size: 13px;
|
color: var(--dees-color-text-muted);
|
||||||
color: ${cssManager.bdTheme('#71717a', '#a1a1aa')};
|
letter-spacing: -0.01em;
|
||||||
|
white-space: nowrap;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
}
|
}
|
||||||
|
|
||||||
.gateway-content {
|
.gateway-content {
|
||||||
@@ -176,8 +190,51 @@ export class ObViewSettings extends DeesElement {
|
|||||||
|
|
||||||
.gateway-footer {
|
.gateway-footer {
|
||||||
display: flex;
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
justify-content: flex-end;
|
justify-content: flex-end;
|
||||||
padding: 0 20px 20px;
|
align-items: center;
|
||||||
|
gap: 0;
|
||||||
|
height: 36px;
|
||||||
|
width: 100%;
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tile-button {
|
||||||
|
padding: 0 16px;
|
||||||
|
height: 100%;
|
||||||
|
text-align: center;
|
||||||
|
font-size: 12px;
|
||||||
|
font-weight: 500;
|
||||||
|
cursor: pointer;
|
||||||
|
user-select: none;
|
||||||
|
transition: all 0.15s ease;
|
||||||
|
background: transparent;
|
||||||
|
border: none;
|
||||||
|
border-left: 1px solid var(--dees-color-border-subtle);
|
||||||
|
color: var(--dees-color-text-muted);
|
||||||
|
white-space: nowrap;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tile-button:first-child {
|
||||||
|
border-left: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tile-button:hover {
|
||||||
|
background: var(--dees-color-hover);
|
||||||
|
color: var(--dees-color-text-primary);
|
||||||
|
}
|
||||||
|
|
||||||
|
.tile-button.primary {
|
||||||
|
color: ${cssManager.bdTheme('hsl(217.2 91.2% 59.8%)', 'hsl(213.1 93.9% 67.8%)')};
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tile-button.primary:hover {
|
||||||
|
background: ${cssManager.bdTheme('hsl(217.2 91.2% 59.8% / 0.08)', 'hsl(213.1 93.9% 67.8% / 0.08)')};
|
||||||
|
color: ${cssManager.bdTheme('hsl(217.2 91.2% 50%)', 'hsl(213.1 93.9% 75%)')};
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (max-width: 700px) {
|
@media (max-width: 700px) {
|
||||||
@@ -201,12 +258,14 @@ export class ObViewSettings extends DeesElement {
|
|||||||
public render(): TemplateResult {
|
public render(): TemplateResult {
|
||||||
return html`
|
return html`
|
||||||
<ob-sectionheading>Settings</ob-sectionheading>
|
<ob-sectionheading>Settings</ob-sectionheading>
|
||||||
|
${this.renderAdminUiSettings()}
|
||||||
${this.renderExternalGatewaySettings()}
|
${this.renderExternalGatewaySettings()}
|
||||||
<sz-settings-view
|
<sz-settings-view
|
||||||
.settings=${this.settingsState.settings || {
|
.settings=${this.settingsState.settings || {
|
||||||
darkMode: true,
|
darkMode: true,
|
||||||
cloudflareToken: '',
|
cloudflareToken: '',
|
||||||
cloudflareZoneId: '',
|
cloudflareZoneId: '',
|
||||||
|
adminUiDomain: '',
|
||||||
dcrouterMode: 'managed',
|
dcrouterMode: 'managed',
|
||||||
dcrouterManagedImage: 'code.foss.global/serve.zone/dcrouter:latest',
|
dcrouterManagedImage: 'code.foss.global/serve.zone/dcrouter:latest',
|
||||||
dcrouterManagedOpsPort: 3300,
|
dcrouterManagedOpsPort: 3300,
|
||||||
@@ -244,14 +303,39 @@ export class ObViewSettings extends DeesElement {
|
|||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private renderAdminUiSettings(): TemplateResult {
|
||||||
|
const settings = this.settingsState.settings;
|
||||||
|
return html`
|
||||||
|
<dees-tile>
|
||||||
|
<div slot="header" class="gateway-header">
|
||||||
|
<div class="gateway-heading">
|
||||||
|
<span class="gateway-title">Onebox Admin UI</span>
|
||||||
|
<span class="gateway-subtitle">Configure the public hostname for this Onebox dashboard</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="gateway-content">
|
||||||
|
${this.renderGatewayInput('adminUiDomain', 'Admin UI Domain', settings?.adminUiDomain || '', 'Example: onebox.example.com. Leave empty to disable the public Admin UI route.')}
|
||||||
|
${this.renderGatewayReadonly('Local Target', 'Onebox OpsServer on port 3000', 'The external gateway forwards to SmartProxy, which forwards this hostname to the Onebox Admin UI.')}
|
||||||
|
</div>
|
||||||
|
<div slot="footer" class="gateway-footer">
|
||||||
|
<button class="tile-button primary" type="button" @click=${() => this.saveAdminUiSettings()}>
|
||||||
|
Save Admin UI Domain
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</dees-tile>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
private renderExternalGatewaySettings(): TemplateResult {
|
private renderExternalGatewaySettings(): TemplateResult {
|
||||||
const settings = this.settingsState.settings;
|
const settings = this.settingsState.settings;
|
||||||
const mode = settings?.dcrouterMode || 'managed';
|
const mode = settings?.dcrouterMode || 'managed';
|
||||||
return html`
|
return html`
|
||||||
<section class="gateway-card">
|
<dees-tile>
|
||||||
<div class="gateway-header">
|
<div slot="header" class="gateway-header">
|
||||||
<div class="gateway-title">dcrouter Gateway</div>
|
<div class="gateway-heading">
|
||||||
<div class="gateway-subtitle">Run a local managed dcrouter or delegate routing, DNS, and certificates to an external dcrouter.</div>
|
<span class="gateway-title">dcrouter Gateway</span>
|
||||||
|
<span class="gateway-subtitle">Run a local managed dcrouter or delegate routing to an external dcrouter</span>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="gateway-mode-row">
|
<div class="gateway-mode-row">
|
||||||
${this.renderModeButton('managed', 'Managed Local', mode)}
|
${this.renderModeButton('managed', 'Managed Local', mode)}
|
||||||
@@ -277,15 +361,12 @@ export class ObViewSettings extends DeesElement {
|
|||||||
<div class="gateway-disabled">dcrouter route delegation is disabled. Onebox will keep using its local SmartProxy directly.</div>
|
<div class="gateway-disabled">dcrouter route delegation is disabled. Onebox will keep using its local SmartProxy directly.</div>
|
||||||
`}
|
`}
|
||||||
</div>
|
</div>
|
||||||
<div class="gateway-footer">
|
<div slot="footer" class="gateway-footer">
|
||||||
<dees-button
|
<button class="tile-button primary" type="button" @click=${() => this.saveExternalGatewaySettings()}>
|
||||||
.text=${'Save dcrouter Settings'}
|
Save dcrouter Settings
|
||||||
.type=${'default'}
|
</button>
|
||||||
.icon=${'lucide:Save'}
|
|
||||||
@click=${() => this.saveExternalGatewaySettings()}
|
|
||||||
></dees-button>
|
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</dees-tile>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -329,7 +410,7 @@ export class ObViewSettings extends DeesElement {
|
|||||||
isPassword = false,
|
isPassword = false,
|
||||||
): TemplateResult {
|
): TemplateResult {
|
||||||
return html`
|
return html`
|
||||||
<div class="gateway-field ${key === 'dcrouterGatewayUrl' ? 'full' : ''}">
|
<div class="gateway-field ${key === 'dcrouterGatewayUrl' || key === 'adminUiDomain' ? 'full' : ''}">
|
||||||
<dees-input-text
|
<dees-input-text
|
||||||
.key=${key}
|
.key=${key}
|
||||||
.label=${label}
|
.label=${label}
|
||||||
@@ -393,4 +474,15 @@ export class ObViewSettings extends DeesElement {
|
|||||||
});
|
});
|
||||||
await appstate.settingsStatePart.dispatchAction(appstate.fetchManagedDcRouterStatusAction, null);
|
await appstate.settingsStatePart.dispatchAction(appstate.fetchManagedDcRouterStatusAction, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async saveAdminUiSettings(): Promise<void> {
|
||||||
|
const settings = this.settingsState.settings;
|
||||||
|
if (!settings) return;
|
||||||
|
|
||||||
|
await appstate.settingsStatePart.dispatchAction(appstate.updateSettingsAction, {
|
||||||
|
settings: {
|
||||||
|
adminUiDomain: settings.adminUiDomain || '',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user