@dominevo/series-scraper-core 0.0.90 → 0.0.92
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/dist/controllers/notifications.controller.d.ts +4 -11
- package/dist/controllers/notifications.controller.js +7 -5
- package/dist/controllers/settings.controller.d.ts +3 -3
- package/dist/controllers/settings.controller.js +6 -4
- package/dist/controllers/sites.controller.d.ts +5 -53
- package/dist/controllers/sites.controller.js +47 -14
- package/dist/controllers/table.controller.js +2 -1
- package/dist/controllers/vpn.controller.d.ts +5 -0
- package/dist/controllers/vpn.controller.js +35 -3
- package/dist/docker-layout/secret-layout.js +19 -7
- package/dist/ports/secret-store.d.ts +2 -0
- package/dist/ports/secret-store.js +2 -0
- package/dist/repositories/settings.repository.d.ts +5 -0
- package/dist/repositories/settings.repository.js +15 -1
- package/dist/repositories/sites.repository.d.ts +6 -1
- package/dist/repositories/sites.repository.js +34 -5
- package/dist/repositories/webhook.repository.d.ts +3 -0
- package/dist/repositories/webhook.repository.js +13 -4
- package/dist/scraper.module.js +2 -0
- package/dist/services/captcha.service.js +1 -1
- package/dist/services/download.service.js +1 -1
- package/dist/services/egress/egress-context.d.ts +4 -0
- package/dist/services/egress/egress-input.d.ts +15 -2
- package/dist/services/egress/egress-input.js +32 -3
- package/dist/services/egress/leak-guard.d.ts +5 -1
- package/dist/services/plugin-settings.service.d.ts +2 -0
- package/dist/services/plugin-settings.service.js +16 -3
- package/dist/services/secret-migration.service.d.ts +22 -0
- package/dist/services/secret-migration.service.js +48 -0
- package/dist/services/secret-views.d.ts +56 -0
- package/dist/services/secret-views.js +120 -0
- package/dist/services/vpn.service.d.ts +9 -2
- package/dist/services/vpn.service.js +38 -9
- package/dist/types.d.ts +7 -0
- package/package.json +1 -1
|
@@ -1,28 +1,21 @@
|
|
|
1
1
|
import { Observable } from 'rxjs';
|
|
2
2
|
import { NotificationService } from '../services/notification.service';
|
|
3
|
+
import { WebhookView } from '../services/secret-views';
|
|
3
4
|
import { WebhookRepository, WebhookConfig } from '../repositories/webhook.repository';
|
|
4
5
|
export declare class NotificationsController {
|
|
5
6
|
private readonly notifications;
|
|
6
7
|
private readonly webhookRepo;
|
|
7
8
|
constructor(notifications: NotificationService, webhookRepo: WebhookRepository);
|
|
8
9
|
stream(): Observable<MessageEvent>;
|
|
9
|
-
getWebhooks():
|
|
10
|
+
getWebhooks(): WebhookView[];
|
|
10
11
|
createWebhook(body: {
|
|
11
12
|
name: string;
|
|
12
13
|
url: string;
|
|
13
14
|
events?: string[];
|
|
14
15
|
headers?: Record<string, string>;
|
|
15
16
|
payloadTemplate?: any;
|
|
16
|
-
}):
|
|
17
|
-
updateWebhook(id: string, body: Partial<WebhookConfig>):
|
|
18
|
-
id: string;
|
|
19
|
-
name: string;
|
|
20
|
-
url: string;
|
|
21
|
-
enabled: boolean;
|
|
22
|
-
events: string[];
|
|
23
|
-
headers: Record<string, string>;
|
|
24
|
-
payloadTemplate?: any;
|
|
25
|
-
};
|
|
17
|
+
}): WebhookView;
|
|
18
|
+
updateWebhook(id: string, body: Partial<WebhookConfig>): WebhookView;
|
|
26
19
|
deleteWebhook(id: string): {
|
|
27
20
|
ok: boolean;
|
|
28
21
|
};
|
|
@@ -17,6 +17,7 @@ const common_1 = require("@nestjs/common");
|
|
|
17
17
|
const rxjs_1 = require("rxjs");
|
|
18
18
|
const uuid_1 = require("uuid");
|
|
19
19
|
const notification_service_1 = require("../services/notification.service");
|
|
20
|
+
const secret_views_1 = require("../services/secret-views");
|
|
20
21
|
const webhook_repository_1 = require("../repositories/webhook.repository");
|
|
21
22
|
let NotificationsController = class NotificationsController {
|
|
22
23
|
constructor(notifications, webhookRepo) {
|
|
@@ -30,7 +31,7 @@ let NotificationsController = class NotificationsController {
|
|
|
30
31
|
}
|
|
31
32
|
// --- Webhook CRUD ---
|
|
32
33
|
getWebhooks() {
|
|
33
|
-
return this.webhookRepo.getAll();
|
|
34
|
+
return this.webhookRepo.getAll().map(secret_views_1.toWebhookView);
|
|
34
35
|
}
|
|
35
36
|
createWebhook(body) {
|
|
36
37
|
const webhook = {
|
|
@@ -39,19 +40,20 @@ let NotificationsController = class NotificationsController {
|
|
|
39
40
|
url: body.url,
|
|
40
41
|
enabled: true,
|
|
41
42
|
events: body.events || [],
|
|
42
|
-
headers: body.headers
|
|
43
|
+
headers: (0, secret_views_1.mergeHeaders)({}, body.headers ?? {}),
|
|
43
44
|
payloadTemplate: body.payloadTemplate,
|
|
44
45
|
};
|
|
45
46
|
this.webhookRepo.save(webhook);
|
|
46
|
-
return webhook;
|
|
47
|
+
return (0, secret_views_1.toWebhookView)(webhook);
|
|
47
48
|
}
|
|
48
49
|
updateWebhook(id, body) {
|
|
49
50
|
const existing = this.webhookRepo.getById(id);
|
|
50
51
|
if (!existing)
|
|
51
52
|
throw new common_1.HttpException('Webhook not found', common_1.HttpStatus.NOT_FOUND);
|
|
52
|
-
const
|
|
53
|
+
const { headers, secretHeaders: _view, urlSecretSet: _set, ...rest } = body;
|
|
54
|
+
const updated = { ...existing, ...rest, id: existing.id, url: (0, secret_views_1.mergeWebhookUrl)(existing.url, rest.url), headers: headers === undefined ? existing.headers : (0, secret_views_1.mergeHeaders)(existing.headers, headers) };
|
|
53
55
|
this.webhookRepo.save(updated);
|
|
54
|
-
return updated;
|
|
56
|
+
return (0, secret_views_1.toWebhookView)(updated);
|
|
55
57
|
}
|
|
56
58
|
deleteWebhook(id) {
|
|
57
59
|
const ok = this.webhookRepo.delete(id);
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { AppSettings } from '../types';
|
|
2
1
|
import { SettingsService } from '../services/settings.service';
|
|
3
2
|
import { DownloadService } from '../services/download.service';
|
|
3
|
+
import { SettingsView } from '../services/secret-views';
|
|
4
4
|
import { SUPPORTED_LANGUAGES, LANGUAGE_TYPES } from '../constants/languages';
|
|
5
5
|
export declare class SettingsController {
|
|
6
6
|
private readonly settingsService;
|
|
7
7
|
private readonly downloadService;
|
|
8
8
|
constructor(settingsService: SettingsService, downloadService: DownloadService);
|
|
9
|
-
get():
|
|
9
|
+
get(): SettingsView;
|
|
10
10
|
/** Predefined choices exposed to the UI for the preferred-language dropdowns. */
|
|
11
11
|
getLanguages(): {
|
|
12
12
|
languages: typeof SUPPORTED_LANGUAGES;
|
|
13
13
|
types: typeof LANGUAGE_TYPES;
|
|
14
14
|
};
|
|
15
|
-
update(body:
|
|
15
|
+
update(body: unknown): SettingsView;
|
|
16
16
|
}
|
|
@@ -16,6 +16,7 @@ exports.SettingsController = void 0;
|
|
|
16
16
|
const common_1 = require("@nestjs/common");
|
|
17
17
|
const settings_service_1 = require("../services/settings.service");
|
|
18
18
|
const download_service_1 = require("../services/download.service");
|
|
19
|
+
const secret_views_1 = require("../services/secret-views");
|
|
19
20
|
const languages_1 = require("../constants/languages");
|
|
20
21
|
let SettingsController = class SettingsController {
|
|
21
22
|
constructor(settingsService, downloadService) {
|
|
@@ -23,18 +24,19 @@ let SettingsController = class SettingsController {
|
|
|
23
24
|
this.downloadService = downloadService;
|
|
24
25
|
}
|
|
25
26
|
get() {
|
|
26
|
-
return this.settingsService.get();
|
|
27
|
+
return (0, secret_views_1.toSettingsView)(this.settingsService.get());
|
|
27
28
|
}
|
|
28
29
|
/** Predefined choices exposed to the UI for the preferred-language dropdowns. */
|
|
29
30
|
getLanguages() {
|
|
30
31
|
return { languages: languages_1.SUPPORTED_LANGUAGES, types: languages_1.LANGUAGE_TYPES };
|
|
31
32
|
}
|
|
32
33
|
update(body) {
|
|
33
|
-
const
|
|
34
|
-
|
|
34
|
+
const patch = (0, secret_views_1.parseSettingsBody)(body);
|
|
35
|
+
const updated = this.settingsService.update(patch);
|
|
36
|
+
if (patch.concurrentDownloads !== undefined) {
|
|
35
37
|
this.downloadService.syncConcurrency();
|
|
36
38
|
}
|
|
37
|
-
return updated;
|
|
39
|
+
return (0, secret_views_1.toSettingsView)(updated);
|
|
38
40
|
}
|
|
39
41
|
};
|
|
40
42
|
exports.SettingsController = SettingsController;
|
|
@@ -7,70 +7,22 @@ export declare class SitesController {
|
|
|
7
7
|
private readonly adapterRegistry;
|
|
8
8
|
private readonly analyzer;
|
|
9
9
|
constructor(sitesRepo: SitesRepository, adapterRegistry: AdapterRegistryService, analyzer: SiteAnalyzerService);
|
|
10
|
-
getAll():
|
|
11
|
-
getById(id: string):
|
|
10
|
+
getAll(): import("../services/secret-views").SiteView[];
|
|
11
|
+
getById(id: string): import("../services/secret-views").SiteView;
|
|
12
12
|
analyze(body: {
|
|
13
13
|
url: string;
|
|
14
14
|
}): Promise<import("../services/site-analyzer.service").AnalysisResult>;
|
|
15
15
|
analyzeSearch(body: {
|
|
16
16
|
url: string;
|
|
17
17
|
}): Promise<Partial<import("../services/site-analyzer.service").AnalysisResult>>;
|
|
18
|
-
create(body: Omit<GenericSiteConfig, 'id'>):
|
|
19
|
-
update(id: string, body: Partial<GenericSiteConfig>):
|
|
20
|
-
id: string;
|
|
21
|
-
name: string;
|
|
22
|
-
baseUrl: string;
|
|
23
|
-
hosts: string[];
|
|
24
|
-
languages?: import("../types").AdapterLanguageInfo[];
|
|
25
|
-
search: {
|
|
26
|
-
urlPattern: string;
|
|
27
|
-
resultSelector: string;
|
|
28
|
-
titleSelector: string;
|
|
29
|
-
urlSelector: string;
|
|
30
|
-
imageSelector?: string;
|
|
31
|
-
imageAttr?: string;
|
|
32
|
-
};
|
|
33
|
-
seasons?: {
|
|
34
|
-
listSelector: string;
|
|
35
|
-
numberAttr?: string;
|
|
36
|
-
numberSelector?: string;
|
|
37
|
-
urlSelector?: string;
|
|
38
|
-
singlePage?: boolean;
|
|
39
|
-
};
|
|
40
|
-
episodes: {
|
|
41
|
-
listSelector: string;
|
|
42
|
-
numberAttr?: string;
|
|
43
|
-
numberSelector?: string;
|
|
44
|
-
titleSelector?: string;
|
|
45
|
-
urlSelector?: string;
|
|
46
|
-
seasonFilterAttr?: string;
|
|
47
|
-
seasonFilterSelector?: string;
|
|
48
|
-
episodeIdAttr?: string;
|
|
49
|
-
};
|
|
50
|
-
downloads: {
|
|
51
|
-
linkSelector?: string;
|
|
52
|
-
linkAttr?: string;
|
|
53
|
-
videoUrlPattern?: boolean;
|
|
54
|
-
iframeSelector?: string;
|
|
55
|
-
mirrorSelector?: string;
|
|
56
|
-
mirrorFilterSelector?: string;
|
|
57
|
-
mirrorLinkAttr?: string;
|
|
58
|
-
languageFromQuery?: string;
|
|
59
|
-
languageMap?: Record<string, string>;
|
|
60
|
-
defaultLanguage?: string;
|
|
61
|
-
grabberUrlPattern?: string;
|
|
62
|
-
playerIdSelector?: string;
|
|
63
|
-
playerIdAttr?: string;
|
|
64
|
-
};
|
|
65
|
-
headers?: Record<string, string>;
|
|
66
|
-
useHeadless?: boolean;
|
|
67
|
-
};
|
|
18
|
+
create(body: Omit<GenericSiteConfig, 'id'>): import("../services/secret-views").SiteView;
|
|
19
|
+
update(id: string, body: Partial<GenericSiteConfig>): import("../services/secret-views").SiteView;
|
|
68
20
|
delete(id: string): {
|
|
69
21
|
ok: boolean;
|
|
70
22
|
};
|
|
71
23
|
/** Export every site as a single JSON blob — suitable for backup / cross-instance copy. */
|
|
72
24
|
exportAll(): {
|
|
73
|
-
sites:
|
|
25
|
+
sites: import("../services/secret-views").SiteView[];
|
|
74
26
|
};
|
|
75
27
|
/**
|
|
76
28
|
* Bulk import site configs. Matches by `name`: existing sites are updated,
|
|
@@ -15,9 +15,27 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
15
|
exports.SitesController = void 0;
|
|
16
16
|
const common_1 = require("@nestjs/common");
|
|
17
17
|
const uuid_1 = require("uuid");
|
|
18
|
+
const secret_views_1 = require("../services/secret-views");
|
|
18
19
|
const sites_repository_1 = require("../repositories/sites.repository");
|
|
19
20
|
const adapter_registry_service_1 = require("../services/adapter-registry.service");
|
|
20
21
|
const site_analyzer_service_1 = require("../services/site-analyzer.service");
|
|
22
|
+
function hostOf(url) {
|
|
23
|
+
if (typeof url !== 'string')
|
|
24
|
+
return undefined;
|
|
25
|
+
try {
|
|
26
|
+
return new URL(url).host.toLowerCase();
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/** Whether an imported site stays on a host the stored one already served (its baseUrl host, or one of its hosts). */
|
|
33
|
+
function sameSiteHost(stored, incoming) {
|
|
34
|
+
const host = hostOf(incoming.baseUrl);
|
|
35
|
+
if (host === undefined)
|
|
36
|
+
return false;
|
|
37
|
+
return host === hostOf(stored.baseUrl) || stored.hosts.some((h) => h.toLowerCase() === host);
|
|
38
|
+
}
|
|
21
39
|
let SitesController = class SitesController {
|
|
22
40
|
constructor(sitesRepo, adapterRegistry, analyzer) {
|
|
23
41
|
this.sitesRepo = sitesRepo;
|
|
@@ -25,13 +43,13 @@ let SitesController = class SitesController {
|
|
|
25
43
|
this.analyzer = analyzer;
|
|
26
44
|
}
|
|
27
45
|
getAll() {
|
|
28
|
-
return this.sitesRepo.getAll();
|
|
46
|
+
return this.sitesRepo.getAll().map(secret_views_1.toSiteView);
|
|
29
47
|
}
|
|
30
48
|
getById(id) {
|
|
31
49
|
const site = this.sitesRepo.getById(id);
|
|
32
50
|
if (!site)
|
|
33
51
|
throw new common_1.HttpException('Site not found', common_1.HttpStatus.NOT_FOUND);
|
|
34
|
-
return site;
|
|
52
|
+
return (0, secret_views_1.toSiteView)(site);
|
|
35
53
|
}
|
|
36
54
|
async analyze(body) {
|
|
37
55
|
if (!body.url)
|
|
@@ -54,19 +72,19 @@ let SitesController = class SitesController {
|
|
|
54
72
|
}
|
|
55
73
|
}
|
|
56
74
|
create(body) {
|
|
57
|
-
const site = { ...body, id: (0, uuid_1.v4)() };
|
|
75
|
+
const site = { ...(0, secret_views_1.siteFromWrite)(body), id: (0, uuid_1.v4)() };
|
|
58
76
|
this.sitesRepo.save(site);
|
|
59
77
|
this.adapterRegistry.reloadGenericAdapters();
|
|
60
|
-
return site;
|
|
78
|
+
return (0, secret_views_1.toSiteView)(site);
|
|
61
79
|
}
|
|
62
80
|
update(id, body) {
|
|
63
81
|
const existing = this.sitesRepo.getById(id);
|
|
64
82
|
if (!existing)
|
|
65
83
|
throw new common_1.HttpException('Site not found', common_1.HttpStatus.NOT_FOUND);
|
|
66
|
-
const updated = { ...existing, ...body, id: existing.id };
|
|
84
|
+
const updated = { ...existing, ...(0, secret_views_1.siteFromWrite)(body, existing), id: existing.id };
|
|
67
85
|
this.sitesRepo.save(updated);
|
|
68
86
|
this.adapterRegistry.reloadGenericAdapters();
|
|
69
|
-
return updated;
|
|
87
|
+
return (0, secret_views_1.toSiteView)(updated);
|
|
70
88
|
}
|
|
71
89
|
delete(id) {
|
|
72
90
|
const ok = this.sitesRepo.delete(id);
|
|
@@ -77,7 +95,7 @@ let SitesController = class SitesController {
|
|
|
77
95
|
}
|
|
78
96
|
/** Export every site as a single JSON blob — suitable for backup / cross-instance copy. */
|
|
79
97
|
exportAll() {
|
|
80
|
-
return { sites: this.sitesRepo.getAll() };
|
|
98
|
+
return { sites: this.sitesRepo.getAll().map(secret_views_1.toSiteView) };
|
|
81
99
|
}
|
|
82
100
|
/**
|
|
83
101
|
* Bulk import site configs. Matches by `name`: existing sites are updated,
|
|
@@ -108,25 +126,40 @@ let SitesController = class SitesController {
|
|
|
108
126
|
}
|
|
109
127
|
let created = 0;
|
|
110
128
|
let updated = 0;
|
|
129
|
+
// Validate every entry before anything is deleted: a bad one must leave the stored sites untouched.
|
|
130
|
+
for (const raw of incoming) {
|
|
131
|
+
if (!raw || typeof raw !== 'object' || !raw.name) {
|
|
132
|
+
throw new common_1.HttpException('Each site must include a "name"', common_1.HttpStatus.BAD_REQUEST);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
// A replace wipes the sites, and their stored credentials with them: remember what a site that comes back held,
|
|
136
|
+
// so its credential headers (which an export never carries) survive the round trip.
|
|
137
|
+
const before = this.sitesRepo.getAll();
|
|
138
|
+
const priorById = new Map(before.map((s) => [s.id, s]));
|
|
139
|
+
const priorByName = new Map(before.map((s) => [s.name, s]));
|
|
111
140
|
if (mode === 'replace') {
|
|
112
|
-
for (const s of
|
|
141
|
+
for (const s of before)
|
|
113
142
|
this.sitesRepo.delete(s.id);
|
|
114
143
|
}
|
|
115
144
|
const existing = this.sitesRepo.getAll();
|
|
116
145
|
const byName = new Map(existing.map((s) => [s.name, s]));
|
|
117
146
|
for (const raw of incoming) {
|
|
118
|
-
|
|
119
|
-
throw new common_1.HttpException('Each site must include a "name"', common_1.HttpStatus.BAD_REQUEST);
|
|
120
|
-
}
|
|
121
|
-
const match = byName.get(raw.name);
|
|
147
|
+
const match = byName.get(String(raw.name));
|
|
122
148
|
if (match) {
|
|
123
|
-
|
|
149
|
+
// The stored headers (a cookie) follow the name only while the site stays on the same host.
|
|
150
|
+
const { headers: _stored, ...bare } = match;
|
|
151
|
+
const merged = sameSiteHost(match, raw)
|
|
152
|
+
? { ...match, ...(0, secret_views_1.siteFromWrite)(raw, match), id: match.id }
|
|
153
|
+
: { ...bare, ...(0, secret_views_1.siteFromWrite)(raw), id: match.id };
|
|
124
154
|
this.sitesRepo.save(merged);
|
|
125
155
|
updated++;
|
|
126
156
|
}
|
|
127
157
|
else {
|
|
128
158
|
const id = ('id' in raw && typeof raw.id === 'string') ? raw.id : (0, uuid_1.v4)();
|
|
129
|
-
|
|
159
|
+
const byId = priorById.get(id);
|
|
160
|
+
const byNameMatch = priorByName.get(String(raw.name));
|
|
161
|
+
const prior = byId ?? (byNameMatch && sameSiteHost(byNameMatch, raw) ? byNameMatch : undefined);
|
|
162
|
+
this.sitesRepo.save({ ...(0, secret_views_1.siteFromWrite)(raw, prior), id });
|
|
130
163
|
created++;
|
|
131
164
|
}
|
|
132
165
|
}
|
|
@@ -23,6 +23,7 @@ const sonarr_service_1 = require("../services/sonarr.service");
|
|
|
23
23
|
const radarr_service_1 = require("../services/radarr.service");
|
|
24
24
|
const details_service_1 = require("../services/details.service");
|
|
25
25
|
const vpn_providers_repository_1 = require("../repositories/vpn-providers.repository");
|
|
26
|
+
const vpn_service_1 = require("../services/vpn.service");
|
|
26
27
|
const egress_input_1 = require("../services/egress/egress-input");
|
|
27
28
|
let TableController = TableController_1 = class TableController {
|
|
28
29
|
constructor(tableService, downloadService, sonarr, radarr, details, vpnProviders) {
|
|
@@ -59,7 +60,7 @@ let TableController = TableController_1 = class TableController {
|
|
|
59
60
|
update(id, body) {
|
|
60
61
|
let patch = body;
|
|
61
62
|
try {
|
|
62
|
-
const egress = (0, egress_input_1.parseEntryEgressPatch)(body, new Set(this.vpnProviders.getAll().map((e) => e.id)));
|
|
63
|
+
const egress = (0, egress_input_1.parseEntryEgressPatch)(body, new Set(this.vpnProviders.getAll().map((e) => e.id)), new Set(this.vpnProviders.getAll().filter(vpn_service_1.isHomeByDesign).map((e) => e.id)));
|
|
63
64
|
// `egressId` is replaced by the validated value (or removed, which clears the override).
|
|
64
65
|
if (egress.change)
|
|
65
66
|
patch = { ...body, egressId: egress.egressId };
|
|
@@ -35,6 +35,11 @@ export declare class VpnController {
|
|
|
35
35
|
strictMode: boolean;
|
|
36
36
|
rules: import("../types").HostRule[];
|
|
37
37
|
}>;
|
|
38
|
+
/**
|
|
39
|
+
* The home-connection choice belongs to the captcha role: when that role moves off an exit, the exit loses
|
|
40
|
+
* the flag in the same request, so it never keeps an exemption it no longer has a reason for.
|
|
41
|
+
*/
|
|
42
|
+
private clearHomeFlagLeaving;
|
|
38
43
|
getStatus(): import("../services/vpn.service").VpnStatus;
|
|
39
44
|
/** Whether work may go out: open, or closed with the reason. Always answers, whatever the gate says. */
|
|
40
45
|
getGate(): import("..").GateStatus;
|
|
@@ -19,6 +19,7 @@ const vpn_settings_repository_1 = require("../repositories/vpn-settings.reposito
|
|
|
19
19
|
const vpn_preset_registry_service_1 = require("../services/vpn-preset-registry.service");
|
|
20
20
|
const table_service_1 = require("../services/table.service");
|
|
21
21
|
const vpn_service_1 = require("../services/vpn.service");
|
|
22
|
+
const vpn_service_2 = require("../services/vpn.service");
|
|
22
23
|
const egress_input_1 = require("../services/egress/egress-input");
|
|
23
24
|
const nord_lookup_1 = require("../services/egress/nord-lookup");
|
|
24
25
|
const egress_migration_1 = require("../services/egress/egress-migration");
|
|
@@ -62,7 +63,11 @@ let VpnController = class VpnController {
|
|
|
62
63
|
}
|
|
63
64
|
async createProvider(body) {
|
|
64
65
|
const resolved = await resolveNord(this.vpn, body);
|
|
65
|
-
const
|
|
66
|
+
const parsed = validated(() => (0, egress_input_1.parseNewEgress)(body, resolved));
|
|
67
|
+
if ('homeIpByDesign' in parsed && parsed.homeIpByDesign) {
|
|
68
|
+
throw new common_1.HttpException('Create the exit first, make it the captcha fallback exit, then mark it as using the home connection', common_1.HttpStatus.BAD_REQUEST);
|
|
69
|
+
}
|
|
70
|
+
const created = this.providersRepo.create(parsed);
|
|
66
71
|
await this.vpn.reload();
|
|
67
72
|
return (0, egress_migration_1.toEgressView)(created);
|
|
68
73
|
}
|
|
@@ -71,7 +76,17 @@ let VpnController = class VpnController {
|
|
|
71
76
|
if (!existing)
|
|
72
77
|
throw new common_1.HttpException('Exit not found', common_1.HttpStatus.NOT_FOUND);
|
|
73
78
|
const resolved = await resolveNord(this.vpn, body);
|
|
74
|
-
const
|
|
79
|
+
const patched = validated(() => (0, egress_input_1.applyEgressPatch)(existing, body, resolved));
|
|
80
|
+
if ('homeIpByDesign' in patched && patched.homeIpByDesign) {
|
|
81
|
+
const settings = this.settingsRepo.get();
|
|
82
|
+
validated(() => (0, egress_input_1.assertHomeIpAllowed)(id, patched.name, {
|
|
83
|
+
defaultEgressId: settings.defaultEgressId,
|
|
84
|
+
ruleExitIds: settings.rules.flatMap((r) => r.egressIds),
|
|
85
|
+
entryEgressIds: this.table.getAll().flatMap((e) => (e.egressId ? [e.egressId] : [])),
|
|
86
|
+
captchaFallbackEgressId: settings.captchaFallbackEgressId,
|
|
87
|
+
}));
|
|
88
|
+
}
|
|
89
|
+
const saved = this.providersRepo.update(id, patched);
|
|
75
90
|
if (!saved)
|
|
76
91
|
throw new common_1.HttpException('Exit not found', common_1.HttpStatus.NOT_FOUND);
|
|
77
92
|
await this.vpn.reload();
|
|
@@ -103,11 +118,28 @@ let VpnController = class VpnController {
|
|
|
103
118
|
}
|
|
104
119
|
async updateSettings(body) {
|
|
105
120
|
const known = new Set(this.providersRepo.getAll().map((e) => e.id));
|
|
106
|
-
const
|
|
121
|
+
const homeOnly = new Set(this.providersRepo.getAll().filter(vpn_service_2.isHomeByDesign).map((e) => e.id));
|
|
122
|
+
const next = validated(() => (0, egress_input_1.parseSettingsPatch)(body, this.settingsRepo.get(), known, homeOnly));
|
|
123
|
+
// Deliberate order: the flag goes first. If the settings write then fails, the old exit has lost its exemption
|
|
124
|
+
// (it fails closed, back under the VPN leak check); the reverse order could leave an exempt exit with no role.
|
|
125
|
+
this.clearHomeFlagLeaving(this.settingsRepo.get().captchaFallbackEgressId, next.captchaFallbackEgressId);
|
|
107
126
|
this.settingsRepo.update(next);
|
|
108
127
|
await this.vpn.reload();
|
|
109
128
|
return { ...next, captchaFallbackEgressId: next.captchaFallbackEgressId ?? null, status: this.vpn.getStatus() };
|
|
110
129
|
}
|
|
130
|
+
/**
|
|
131
|
+
* The home-connection choice belongs to the captcha role: when that role moves off an exit, the exit loses
|
|
132
|
+
* the flag in the same request, so it never keeps an exemption it no longer has a reason for.
|
|
133
|
+
*/
|
|
134
|
+
clearHomeFlagLeaving(previousId, nextId) {
|
|
135
|
+
if (!previousId || previousId === nextId)
|
|
136
|
+
return;
|
|
137
|
+
const old = this.providersRepo.getById(previousId);
|
|
138
|
+
if (!old || !(0, vpn_service_2.isHomeByDesign)(old) || old.type === 'direct' || old.type === 'wireguard')
|
|
139
|
+
return;
|
|
140
|
+
const { homeIpByDesign: _cleared, ...kept } = old;
|
|
141
|
+
this.providersRepo.update(previousId, kept);
|
|
142
|
+
}
|
|
111
143
|
getStatus() {
|
|
112
144
|
return this.vpn.getStatus();
|
|
113
145
|
}
|
|
@@ -100,12 +100,8 @@ const egressLayout = recordListLayout({
|
|
|
100
100
|
prefix: 'egress.',
|
|
101
101
|
fields: ['password', 'privateKey'],
|
|
102
102
|
});
|
|
103
|
-
/**
|
|
104
|
-
const
|
|
105
|
-
collection: 'webhooks',
|
|
106
|
-
prefix: 'webhook.',
|
|
107
|
-
fields: ['headers'],
|
|
108
|
-
listKey: 'webhooks',
|
|
103
|
+
/** An object in the file, one JSON text through the port. */
|
|
104
|
+
const headersCodec = {
|
|
109
105
|
encode: (_field, value) => {
|
|
110
106
|
try {
|
|
111
107
|
const parsed = JSON.parse(value);
|
|
@@ -116,5 +112,21 @@ const webhookLayout = recordListLayout({
|
|
|
116
112
|
}
|
|
117
113
|
},
|
|
118
114
|
decode: (_field, value) => (isObject(value) ? JSON.stringify(value) : undefined),
|
|
115
|
+
};
|
|
116
|
+
/** Webhook headers are an object in the file and one JSON text through the port. */
|
|
117
|
+
const webhookLayout = recordListLayout({
|
|
118
|
+
collection: 'webhooks',
|
|
119
|
+
prefix: 'webhook.',
|
|
120
|
+
fields: ['headers'],
|
|
121
|
+
listKey: 'webhooks',
|
|
122
|
+
...headersCodec,
|
|
123
|
+
});
|
|
124
|
+
/** A site's HTTP headers can carry a session cookie: same shape as a webhook's. */
|
|
125
|
+
const siteLayout = recordListLayout({
|
|
126
|
+
collection: 'sites',
|
|
127
|
+
prefix: 'site.',
|
|
128
|
+
fields: ['headers'],
|
|
129
|
+
listKey: 'sites',
|
|
130
|
+
...headersCodec,
|
|
119
131
|
});
|
|
120
|
-
exports.DOCKER_SECRET_LAYOUT = [settingsLayout, egressLayout, webhookLayout];
|
|
132
|
+
exports.DOCKER_SECRET_LAYOUT = [settingsLayout, egressLayout, webhookLayout, siteLayout];
|
|
@@ -22,4 +22,6 @@ export declare const secretNames: {
|
|
|
22
22
|
readonly egressPrivateKey: (egressId: string) => string;
|
|
23
23
|
/** The webhook's headers as one JSON object text. */
|
|
24
24
|
readonly webhookHeaders: (webhookId: string) => string;
|
|
25
|
+
/** A generic site's HTTP headers as one JSON object text (they can carry a session cookie). */
|
|
26
|
+
readonly siteHeaders: (siteId: string) => string;
|
|
25
27
|
};
|
|
@@ -10,4 +10,6 @@ exports.secretNames = {
|
|
|
10
10
|
egressPrivateKey: (egressId) => `egress.${egressId}.privateKey`,
|
|
11
11
|
/** The webhook's headers as one JSON object text. */
|
|
12
12
|
webhookHeaders: (webhookId) => `webhook.${webhookId}.headers`,
|
|
13
|
+
/** A generic site's HTTP headers as one JSON object text (they can carry a session cookie). */
|
|
14
|
+
siteHeaders: (siteId) => `site.${siteId}.headers`,
|
|
13
15
|
};
|
|
@@ -12,5 +12,10 @@ export declare class SettingsRepository {
|
|
|
12
12
|
get(): AppSettings;
|
|
13
13
|
save(settings: AppSettings): void;
|
|
14
14
|
update(partial: Partial<AppSettings>): AppSettings;
|
|
15
|
+
/**
|
|
16
|
+
* Moves a credential a state file from an older version still carries into the secret store, leaving none behind.
|
|
17
|
+
* Returns how many it moved; a second run finds none.
|
|
18
|
+
*/
|
|
19
|
+
migratePlaintext(): number;
|
|
15
20
|
private keepSecret;
|
|
16
21
|
}
|
|
@@ -70,10 +70,12 @@ let SettingsRepository = class SettingsRepository {
|
|
|
70
70
|
}
|
|
71
71
|
save(settings) {
|
|
72
72
|
const { sonarrApiKey, radarrApiKey, plexToken, ...rest } = settings;
|
|
73
|
-
this
|
|
73
|
+
// Secrets first, state after: a host that writes behind persists them in this order, so a crash between the two
|
|
74
|
+
// leaves a credential in both places (harmless) and never in neither.
|
|
74
75
|
this.keepSecret(secret_store_1.secretNames.sonarrApiKey, sonarrApiKey);
|
|
75
76
|
this.keepSecret(secret_store_1.secretNames.radarrApiKey, radarrApiKey);
|
|
76
77
|
this.keepSecret(secret_store_1.secretNames.plexToken, plexToken);
|
|
78
|
+
this.repo.write(rest);
|
|
77
79
|
}
|
|
78
80
|
update(partial) {
|
|
79
81
|
const current = this.get();
|
|
@@ -81,6 +83,18 @@ let SettingsRepository = class SettingsRepository {
|
|
|
81
83
|
this.save(updated);
|
|
82
84
|
return updated;
|
|
83
85
|
}
|
|
86
|
+
/**
|
|
87
|
+
* Moves a credential a state file from an older version still carries into the secret store, leaving none behind.
|
|
88
|
+
* Returns how many it moved; a second run finds none.
|
|
89
|
+
*/
|
|
90
|
+
migratePlaintext() {
|
|
91
|
+
const raw = { ...this.repo.read() };
|
|
92
|
+
const keys = ['sonarrApiKey', 'radarrApiKey', 'plexToken'];
|
|
93
|
+
const moved = keys.filter((k) => typeof raw[k] === 'string' && raw[k] !== '').length;
|
|
94
|
+
if (moved > 0)
|
|
95
|
+
this.save(this.get());
|
|
96
|
+
return moved;
|
|
97
|
+
}
|
|
84
98
|
keepSecret(name, value) {
|
|
85
99
|
if (this.secrets.get(name) !== value)
|
|
86
100
|
this.secrets.set(name, value);
|
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import { GenericSiteConfig } from '../types';
|
|
2
|
+
import { SecretStore } from '../ports/secret-store';
|
|
2
3
|
import { StateStore } from '../ports/state-store';
|
|
3
4
|
export declare class SitesRepository {
|
|
5
|
+
private readonly secrets;
|
|
4
6
|
private readonly repo;
|
|
5
|
-
constructor(state: StateStore);
|
|
7
|
+
constructor(state: StateStore, secrets: SecretStore);
|
|
6
8
|
getAll(): GenericSiteConfig[];
|
|
7
9
|
getById(id: string): GenericSiteConfig | undefined;
|
|
8
10
|
save(site: GenericSiteConfig): void;
|
|
9
11
|
delete(id: string): boolean;
|
|
12
|
+
/** Moves headers an older state file still holds into the secret store. Returns how many sites it moved; a second run finds none. */
|
|
13
|
+
migratePlaintext(): number;
|
|
14
|
+
private hydrate;
|
|
10
15
|
}
|
|
@@ -15,25 +15,39 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
15
|
exports.SitesRepository = void 0;
|
|
16
16
|
const common_1 = require("@nestjs/common");
|
|
17
17
|
const tokens_1 = require("../ports/tokens");
|
|
18
|
+
const secret_store_1 = require("../ports/secret-store");
|
|
19
|
+
const webhook_repository_1 = require("./webhook.repository");
|
|
18
20
|
const state_store_1 = require("../ports/state-store");
|
|
19
21
|
let SitesRepository = class SitesRepository {
|
|
20
|
-
constructor(state) {
|
|
22
|
+
constructor(state, secrets) {
|
|
23
|
+
this.secrets = secrets;
|
|
21
24
|
this.repo = new state_store_1.StoredCollection(state, 'sites', { sites: [] });
|
|
22
25
|
}
|
|
23
26
|
getAll() {
|
|
24
|
-
return this.repo.read().sites;
|
|
27
|
+
return this.repo.read().sites.map((s) => this.hydrate(s));
|
|
25
28
|
}
|
|
26
29
|
getById(id) {
|
|
27
30
|
return this.getAll().find((s) => s.id === id);
|
|
28
31
|
}
|
|
29
32
|
save(site) {
|
|
33
|
+
const { headers, ...stored } = site;
|
|
34
|
+
// Secret first, state after (see SettingsRepository.save): a crash between the two never loses the headers.
|
|
35
|
+
const name = secret_store_1.secretNames.siteHeaders(site.id);
|
|
36
|
+
if (headers && Object.keys(headers).length > 0) {
|
|
37
|
+
const text = JSON.stringify(headers);
|
|
38
|
+
if (this.secrets.get(name) !== text)
|
|
39
|
+
this.secrets.set(name, text);
|
|
40
|
+
}
|
|
41
|
+
else if (this.secrets.get(name) !== undefined) {
|
|
42
|
+
this.secrets.delete(name);
|
|
43
|
+
}
|
|
30
44
|
const store = this.repo.read();
|
|
31
45
|
const idx = store.sites.findIndex((s) => s.id === site.id);
|
|
32
46
|
if (idx >= 0) {
|
|
33
|
-
store.sites[idx] =
|
|
47
|
+
store.sites[idx] = stored;
|
|
34
48
|
}
|
|
35
49
|
else {
|
|
36
|
-
store.sites.push(
|
|
50
|
+
store.sites.push(stored);
|
|
37
51
|
}
|
|
38
52
|
this.repo.write(store);
|
|
39
53
|
}
|
|
@@ -43,14 +57,29 @@ let SitesRepository = class SitesRepository {
|
|
|
43
57
|
store.sites = store.sites.filter((s) => s.id !== id);
|
|
44
58
|
if (store.sites.length < before) {
|
|
45
59
|
this.repo.write(store);
|
|
60
|
+
this.secrets.delete(secret_store_1.secretNames.siteHeaders(id));
|
|
46
61
|
return true;
|
|
47
62
|
}
|
|
48
63
|
return false;
|
|
49
64
|
}
|
|
65
|
+
/** Moves headers an older state file still holds into the secret store. Returns how many sites it moved; a second run finds none. */
|
|
66
|
+
migratePlaintext() {
|
|
67
|
+
const legacy = this.repo.read().sites.filter((s) => s.headers !== undefined);
|
|
68
|
+
for (const stored of legacy)
|
|
69
|
+
this.save(this.hydrate(stored));
|
|
70
|
+
return legacy.filter((s) => Object.keys(s.headers ?? {}).length > 0).length;
|
|
71
|
+
}
|
|
72
|
+
hydrate(stored) {
|
|
73
|
+
const text = this.secrets.get(secret_store_1.secretNames.siteHeaders(stored.id));
|
|
74
|
+
const headers = text === undefined ? stored.headers : (0, webhook_repository_1.parseHeaders)(text);
|
|
75
|
+
const { headers: _own, ...rest } = stored;
|
|
76
|
+
return headers && Object.keys(headers).length > 0 ? { ...rest, headers } : rest;
|
|
77
|
+
}
|
|
50
78
|
};
|
|
51
79
|
exports.SitesRepository = SitesRepository;
|
|
52
80
|
exports.SitesRepository = SitesRepository = __decorate([
|
|
53
81
|
(0, common_1.Injectable)(),
|
|
54
82
|
__param(0, (0, common_1.Inject)(tokens_1.STATE_STORE)),
|
|
55
|
-
|
|
83
|
+
__param(1, (0, common_1.Inject)(tokens_1.SECRET_STORE)),
|
|
84
|
+
__metadata("design:paramtypes", [Object, Object])
|
|
56
85
|
], SitesRepository);
|
|
@@ -17,5 +17,8 @@ export declare class WebhookRepository {
|
|
|
17
17
|
getById(id: string): WebhookConfig | undefined;
|
|
18
18
|
save(webhook: WebhookConfig): void;
|
|
19
19
|
delete(id: string): boolean;
|
|
20
|
+
/** Moves headers an older state file still holds into the secret store. Returns how many webhooks it moved; a second run finds none. */
|
|
21
|
+
migratePlaintext(): number;
|
|
20
22
|
private hydrate;
|
|
21
23
|
}
|
|
24
|
+
export declare function parseHeaders(text: string): Record<string, string>;
|