@famir/reverse-app 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/modules/authorize/authorize.controller.d.ts +23 -0
- package/dist/modules/authorize/authorize.controller.js +331 -0
- package/dist/modules/authorize/authorize.controller.js.map +1 -0
- package/dist/modules/authorize/authorize.d.ts +32 -0
- package/dist/modules/authorize/authorize.js +3 -0
- package/dist/modules/authorize/authorize.js.map +1 -0
- package/dist/modules/authorize/authorize.schemas.d.ts +2 -0
- package/dist/modules/authorize/authorize.schemas.js +8 -0
- package/dist/modules/authorize/authorize.schemas.js.map +1 -0
- package/dist/modules/authorize/authorize.service.d.ts +17 -0
- package/dist/modules/authorize/authorize.service.js +116 -0
- package/dist/modules/authorize/authorize.service.js.map +1 -0
- package/dist/modules/authorize/index.d.ts +4 -0
- package/dist/modules/authorize/index.js +5 -0
- package/dist/modules/authorize/index.js.map +1 -0
- package/dist/modules/base/base.controller.d.ts +29 -0
- package/dist/modules/base/base.controller.js +237 -0
- package/dist/modules/base/base.controller.js.map +1 -0
- package/dist/modules/base/base.d.ts +11 -0
- package/dist/modules/base/base.js +2 -0
- package/dist/modules/base/base.js.map +1 -0
- package/dist/modules/base/index.d.ts +2 -0
- package/dist/modules/base/index.js +3 -0
- package/dist/modules/base/index.js.map +1 -0
- package/dist/modules/complete/complete.controller.d.ts +14 -0
- package/dist/modules/complete/complete.controller.js +57 -0
- package/dist/modules/complete/complete.controller.js.map +1 -0
- package/dist/modules/complete/complete.d.ts +24 -0
- package/dist/modules/complete/complete.js +3 -0
- package/dist/modules/complete/complete.js.map +1 -0
- package/dist/modules/complete/complete.service.d.ts +11 -0
- package/dist/modules/complete/complete.service.js +44 -0
- package/dist/modules/complete/complete.service.js.map +1 -0
- package/dist/modules/complete/index.d.ts +3 -0
- package/dist/modules/complete/index.js +4 -0
- package/dist/modules/complete/index.js.map +1 -0
- package/dist/modules/forward/forward.controller.d.ts +15 -0
- package/dist/modules/forward/forward.controller.js +175 -0
- package/dist/modules/forward/forward.controller.js.map +1 -0
- package/dist/modules/forward/forward.d.ts +41 -0
- package/dist/modules/forward/forward.js +3 -0
- package/dist/modules/forward/forward.js.map +1 -0
- package/dist/modules/forward/forward.service.d.ts +11 -0
- package/dist/modules/forward/forward.service.js +21 -0
- package/dist/modules/forward/forward.service.js.map +1 -0
- package/dist/modules/forward/index.d.ts +3 -0
- package/dist/modules/forward/index.js +4 -0
- package/dist/modules/forward/index.js.map +1 -0
- package/dist/modules/index.d.ts +7 -0
- package/dist/modules/index.js +8 -0
- package/dist/modules/index.js.map +1 -0
- package/dist/modules/setup-mirror/index.d.ts +3 -0
- package/dist/modules/setup-mirror/index.js +4 -0
- package/dist/modules/setup-mirror/index.js.map +1 -0
- package/dist/modules/setup-mirror/setup-mirror.controller.d.ts +16 -0
- package/dist/modules/setup-mirror/setup-mirror.controller.js +76 -0
- package/dist/modules/setup-mirror/setup-mirror.controller.js.map +1 -0
- package/dist/modules/setup-mirror/setup-mirror.d.ts +16 -0
- package/dist/modules/setup-mirror/setup-mirror.js +3 -0
- package/dist/modules/setup-mirror/setup-mirror.js.map +1 -0
- package/dist/modules/setup-mirror/setup-mirror.service.d.ts +12 -0
- package/dist/modules/setup-mirror/setup-mirror.service.js +54 -0
- package/dist/modules/setup-mirror/setup-mirror.service.js.map +1 -0
- package/dist/modules/transform/index.d.ts +2 -0
- package/dist/modules/transform/index.js +3 -0
- package/dist/modules/transform/index.js.map +1 -0
- package/dist/modules/transform/transform.controller.d.ts +12 -0
- package/dist/modules/transform/transform.controller.js +126 -0
- package/dist/modules/transform/transform.controller.js.map +1 -0
- package/dist/modules/transform/transform.d.ts +1 -0
- package/dist/modules/transform/transform.js +2 -0
- package/dist/modules/transform/transform.js.map +1 -0
- package/dist/modules/well-known-urls/index.d.ts +2 -0
- package/dist/modules/well-known-urls/index.js +3 -0
- package/dist/modules/well-known-urls/index.js.map +1 -0
- package/dist/modules/well-known-urls/well-known-urls.controller.d.ts +13 -0
- package/dist/modules/well-known-urls/well-known-urls.controller.js +47 -0
- package/dist/modules/well-known-urls/well-known-urls.controller.js.map +1 -0
- package/dist/modules/well-known-urls/well-known-urls.d.ts +5 -0
- package/dist/modules/well-known-urls/well-known-urls.js +2 -0
- package/dist/modules/well-known-urls/well-known-urls.js.map +1 -0
- package/dist/reverse-app.d.ts +19 -0
- package/dist/reverse-app.js +59 -0
- package/dist/reverse-app.js.map +1 -0
- package/package.json +52 -0
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
export class BaseController {
|
|
2
|
+
validator;
|
|
3
|
+
logger;
|
|
4
|
+
templater;
|
|
5
|
+
router;
|
|
6
|
+
constructor(validator, logger, templater, router) {
|
|
7
|
+
this.validator = validator;
|
|
8
|
+
this.logger = logger;
|
|
9
|
+
this.templater = templater;
|
|
10
|
+
this.router = router;
|
|
11
|
+
}
|
|
12
|
+
getState(ctx, key) {
|
|
13
|
+
const state = ctx.state;
|
|
14
|
+
if (state[key] == null) {
|
|
15
|
+
throw new Error(`State '${String(key)}' missing`);
|
|
16
|
+
}
|
|
17
|
+
return state[key];
|
|
18
|
+
}
|
|
19
|
+
setState(ctx, key, value) {
|
|
20
|
+
const state = ctx.state;
|
|
21
|
+
if (state[key]) {
|
|
22
|
+
throw new Error(`State '${String(key)}' exists`);
|
|
23
|
+
}
|
|
24
|
+
state[key] = value;
|
|
25
|
+
}
|
|
26
|
+
async sendNoContent(ctx, status = 204) {
|
|
27
|
+
if (ctx.type !== 'normal') {
|
|
28
|
+
throw new Error(`Only 'normal' context type allowed`);
|
|
29
|
+
}
|
|
30
|
+
ctx.status.set(status);
|
|
31
|
+
ctx.responseBody.reset();
|
|
32
|
+
ctx.responseHeaders.merge({
|
|
33
|
+
'Content-Type': 'text/plain',
|
|
34
|
+
'Content-Length': ctx.responseBody.length.toString(),
|
|
35
|
+
'Access-Control-Allow-Origin': '*',
|
|
36
|
+
'Access-Control-Allow-Methods': '*',
|
|
37
|
+
'Access-Control-Allow-Headers': '*',
|
|
38
|
+
'Access-Control-Expose-Headers': '*',
|
|
39
|
+
'Access-Control-Allow-Credentials': 'true',
|
|
40
|
+
'Access-Control-Max-Age': '86400',
|
|
41
|
+
});
|
|
42
|
+
await ctx.sendResponse();
|
|
43
|
+
}
|
|
44
|
+
async sendPreflightCors(ctx, status = 204) {
|
|
45
|
+
if (ctx.type !== 'normal') {
|
|
46
|
+
throw new Error(`Only 'normal' context type allowed`);
|
|
47
|
+
}
|
|
48
|
+
ctx.status.set(status);
|
|
49
|
+
ctx.responseBody.reset();
|
|
50
|
+
ctx.responseHeaders.merge({
|
|
51
|
+
'Content-Type': 'text/plain',
|
|
52
|
+
'Content-Length': ctx.responseBody.length.toString(),
|
|
53
|
+
'Access-Control-Allow-Origin': '*',
|
|
54
|
+
'Access-Control-Allow-Methods': '*',
|
|
55
|
+
'Access-Control-Allow-Headers': '*',
|
|
56
|
+
'Access-Control-Expose-Headers': '*',
|
|
57
|
+
'Access-Control-Allow-Credentials': 'true',
|
|
58
|
+
'Access-Control-Max-Age': '86400',
|
|
59
|
+
});
|
|
60
|
+
await ctx.sendResponse();
|
|
61
|
+
}
|
|
62
|
+
async sendRedirectTo(ctx, url, status = 302) {
|
|
63
|
+
if (ctx.type !== 'normal') {
|
|
64
|
+
throw new Error(`Only 'normal' context type allowed`);
|
|
65
|
+
}
|
|
66
|
+
ctx.status.set(status);
|
|
67
|
+
ctx.responseHeaders.merge({
|
|
68
|
+
'Location': url,
|
|
69
|
+
'Referrer-Policy': 'no-referrer',
|
|
70
|
+
});
|
|
71
|
+
await ctx.sendResponse();
|
|
72
|
+
}
|
|
73
|
+
async sendOriginRedirect(ctx) {
|
|
74
|
+
await this.sendRedirectTo(ctx, ctx.url.toRelative());
|
|
75
|
+
}
|
|
76
|
+
async sendMainRedirect(ctx) {
|
|
77
|
+
await this.sendRedirectTo(ctx, '/');
|
|
78
|
+
}
|
|
79
|
+
async sendMainPage(ctx, target) {
|
|
80
|
+
if (ctx.type !== 'normal') {
|
|
81
|
+
throw new Error(`Only 'normal' context type allowed`);
|
|
82
|
+
}
|
|
83
|
+
if (ctx.method.is(['GET', 'HEAD']) && target.mainPage) {
|
|
84
|
+
ctx.status.set(200);
|
|
85
|
+
ctx.responseBody.setText(target.mainPage);
|
|
86
|
+
ctx.responseHeaders.merge({
|
|
87
|
+
'Content-Type': 'text/html',
|
|
88
|
+
'Content-Length': ctx.responseBody.length.toString(),
|
|
89
|
+
'Last-Modified': target.createdAt.toUTCString(),
|
|
90
|
+
'Cache-Control': 'public, max-age=86400',
|
|
91
|
+
});
|
|
92
|
+
if (ctx.method.is('HEAD')) {
|
|
93
|
+
ctx.responseBody.reset();
|
|
94
|
+
}
|
|
95
|
+
await ctx.sendResponse();
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
await this.sendNotFoundPage(ctx, target);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
async sendNotFoundPage(ctx, target) {
|
|
102
|
+
if (ctx.type !== 'normal') {
|
|
103
|
+
throw new Error(`Only 'normal' context type allowed`);
|
|
104
|
+
}
|
|
105
|
+
ctx.status.set(404);
|
|
106
|
+
if (target.notFoundPage) {
|
|
107
|
+
ctx.responseBody.setText(target.notFoundPage);
|
|
108
|
+
ctx.responseHeaders.merge({
|
|
109
|
+
'Content-Type': 'text/html',
|
|
110
|
+
'Content-Length': ctx.responseBody.length.toString(),
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
ctx.responseBody.setText(`Not found`);
|
|
115
|
+
ctx.responseHeaders.merge({
|
|
116
|
+
'Content-Type': 'text/plain',
|
|
117
|
+
'Content-Length': ctx.responseBody.length.toString(),
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
await ctx.sendResponse();
|
|
121
|
+
}
|
|
122
|
+
async sendErrorPage(ctx, error, isHtml) {
|
|
123
|
+
if (ctx.type !== 'normal') {
|
|
124
|
+
throw new Error(`Only 'normal' context type allowed`);
|
|
125
|
+
}
|
|
126
|
+
ctx.status.set(error.status);
|
|
127
|
+
if (isHtml) {
|
|
128
|
+
const errorPage = this.templater.render(ctx.state.errorPage, {
|
|
129
|
+
status: error.status,
|
|
130
|
+
message: error.message,
|
|
131
|
+
});
|
|
132
|
+
ctx.responseHeaders.set('Content-Type', 'text/html');
|
|
133
|
+
ctx.responseBody.setText(errorPage);
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
ctx.responseHeaders.set('Content-Type', 'text/plain');
|
|
137
|
+
ctx.responseBody.setText(error.message);
|
|
138
|
+
}
|
|
139
|
+
ctx.responseHeaders.set('Content-Length', ctx.responseBody.length.toString());
|
|
140
|
+
await ctx.sendResponse();
|
|
141
|
+
}
|
|
142
|
+
async sendFaviconIco(ctx, target) {
|
|
143
|
+
if (ctx.type !== 'normal') {
|
|
144
|
+
throw new Error(`Only 'normal' context type allowed`);
|
|
145
|
+
}
|
|
146
|
+
if (ctx.method.is(['GET', 'HEAD']) && target.faviconIco) {
|
|
147
|
+
ctx.status.set(200);
|
|
148
|
+
ctx.responseBody.setBase64(target.faviconIco);
|
|
149
|
+
ctx.responseHeaders.merge({
|
|
150
|
+
'Content-Type': 'image/x-icon',
|
|
151
|
+
'Content-Length': ctx.responseBody.length.toString(),
|
|
152
|
+
'Last-Modified': target.createdAt.toUTCString(),
|
|
153
|
+
'Cache-Control': 'public, max-age=86400',
|
|
154
|
+
});
|
|
155
|
+
if (ctx.method.is('HEAD')) {
|
|
156
|
+
ctx.responseBody.reset();
|
|
157
|
+
}
|
|
158
|
+
await ctx.sendResponse();
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
await this.sendNotFoundPage(ctx, target);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
async sendRobotsTxt(ctx, target) {
|
|
165
|
+
if (ctx.type !== 'normal') {
|
|
166
|
+
throw new Error(`Only 'normal' context type allowed`);
|
|
167
|
+
}
|
|
168
|
+
if (ctx.method.is(['GET', 'HEAD']) && target.robotsTxt) {
|
|
169
|
+
ctx.status.set(200);
|
|
170
|
+
ctx.responseBody.setText(target.robotsTxt);
|
|
171
|
+
ctx.responseHeaders.merge({
|
|
172
|
+
'Content-Type': 'text/plain',
|
|
173
|
+
'Content-Length': ctx.responseBody.length.toString(),
|
|
174
|
+
'Last-Modified': target.createdAt.toUTCString(),
|
|
175
|
+
'Cache-Control': 'public, max-age=86400',
|
|
176
|
+
});
|
|
177
|
+
if (ctx.method.is('HEAD')) {
|
|
178
|
+
ctx.responseBody.reset();
|
|
179
|
+
}
|
|
180
|
+
await ctx.sendResponse();
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
await this.sendNotFoundPage(ctx, target);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
async sendSitemapXml(ctx, target) {
|
|
187
|
+
if (ctx.type !== 'normal') {
|
|
188
|
+
throw new Error(`Only 'normal' context type allowed`);
|
|
189
|
+
}
|
|
190
|
+
if (ctx.method.is(['GET', 'HEAD']) && target.sitemapXml) {
|
|
191
|
+
ctx.status.set(200);
|
|
192
|
+
ctx.responseBody.setText(target.sitemapXml);
|
|
193
|
+
ctx.responseHeaders.merge({
|
|
194
|
+
'Content-Type': 'application/xml',
|
|
195
|
+
'Content-Length': ctx.responseBody.length.toString(),
|
|
196
|
+
'Last-Modified': target.createdAt.toUTCString(),
|
|
197
|
+
'Cache-Control': 'public, max-age=86400',
|
|
198
|
+
});
|
|
199
|
+
if (ctx.method.is('HEAD')) {
|
|
200
|
+
ctx.responseBody.reset();
|
|
201
|
+
}
|
|
202
|
+
await ctx.sendResponse();
|
|
203
|
+
}
|
|
204
|
+
else {
|
|
205
|
+
await this.sendNotFoundPage(ctx, target);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
async sendRedirectorPage(ctx, target, redirector, data) {
|
|
209
|
+
if (ctx.method.is(['GET', 'HEAD'])) {
|
|
210
|
+
ctx.status.set(200);
|
|
211
|
+
const redirectorPage = this.templater.render(redirector.page, data);
|
|
212
|
+
ctx.responseBody.setText(redirectorPage);
|
|
213
|
+
ctx.responseHeaders.merge({
|
|
214
|
+
'Content-Type': 'text/html',
|
|
215
|
+
'Content-Length': ctx.responseBody.length.toString(),
|
|
216
|
+
'Last-Modified': redirector.createdAt.toUTCString(),
|
|
217
|
+
'Cache-Control': 'public, max-age=86400',
|
|
218
|
+
});
|
|
219
|
+
if (ctx.method.is('HEAD')) {
|
|
220
|
+
ctx.responseBody.reset();
|
|
221
|
+
}
|
|
222
|
+
await ctx.sendResponse();
|
|
223
|
+
}
|
|
224
|
+
else {
|
|
225
|
+
await this.sendNotFoundPage(ctx, target);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
async sendCloakingSite(ctx, target) {
|
|
229
|
+
if (ctx.url.isPath('/')) {
|
|
230
|
+
await this.sendMainPage(ctx, target);
|
|
231
|
+
}
|
|
232
|
+
else {
|
|
233
|
+
await this.sendNotFoundPage(ctx, target);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
//# sourceMappingURL=base.controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.controller.js","sourceRoot":"","sources":["../../../src/modules/base/base.controller.ts"],"names":[],"mappings":"AAaA,MAAM,OAAgB,cAAc;IAEb;IACA;IACA;IACA;IAJrB,YACqB,SAAoB,EACpB,MAAc,EACd,SAAoB,EACpB,MAAwB;QAHxB,cAAS,GAAT,SAAS,CAAW;QACpB,WAAM,GAAN,MAAM,CAAQ;QACd,cAAS,GAAT,SAAS,CAAW;QACpB,WAAM,GAAN,MAAM,CAAkB;IAC1C,CAAC;IAEM,QAAQ,CAChB,GAAsB,EACtB,GAAM;QAEN,MAAM,KAAK,GAAG,GAAG,CAAC,KAAU,CAAA;QAE5B,IAAI,KAAK,CAAC,GAAG,CAAC,IAAI,I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AE,UAAU,CAAC,SAAS,CAAC,WAAW,EAAE;gBACnD,eAAe,EAAE,uBAAuB;aACzC,CAAC,CAAA;YAEF,IAAI,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC;gBAC1B,GAAG,CAAC,YAAY,CAAC,KAAK,EAAE,CAAA;YAC1B,CAAC;YAED,MAAM,GAAG,CAAC,YAAY,EAAE,CAAA;QAC1B,CAAC;aAAM,CAAC;YACN,MAAM,IAAI,CAAC,gBAAgB,CAAC,GAAG,EAAE,MAAM,CAAC,CAAA;QAC1C,CAAC;IACH,CAAC;IAES,KAAK,CAAC,gBAAgB,CAC9B,GAAsB,EACtB,MAA8B;QAE9B,IAAI,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC;YACxB,MAAM,IAAI,CAAC,YAAY,CAAC,GAAG,EAAE,MAAM,CAAC,CAAA;QACtC,CAAC;aAAM,CAAC;YACN,MAAM,IAAI,CAAC,gBAAgB,CAAC,GAAG,EAAE,MAAM,CAAC,CAAA;QAC1C,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { EnabledFullTargetModel, EnabledProxyModel, FullCampaignModel, SessionModel, TargetModel } from '@famir/database';
|
|
2
|
+
import { HttpServerContextState } from '@famir/http-server';
|
|
3
|
+
import { HttpMessage } from '@famir/http-tools';
|
|
4
|
+
export interface ReverseContextState extends HttpServerContextState {
|
|
5
|
+
campaign?: FullCampaignModel;
|
|
6
|
+
proxy?: EnabledProxyModel;
|
|
7
|
+
target?: EnabledFullTargetModel;
|
|
8
|
+
targets?: TargetModel[];
|
|
9
|
+
session?: SessionModel;
|
|
10
|
+
message?: HttpMessage;
|
|
11
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.js","sourceRoot":"","sources":["../../../src/modules/base/base.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/modules/base/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAA;AACpC,cAAc,WAAW,CAAA"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { DIContainer } from '@famir/common';
|
|
2
|
+
import { HttpServerRouter } from '@famir/http-server';
|
|
3
|
+
import { Logger } from '@famir/logger';
|
|
4
|
+
import { Templater } from '@famir/templater';
|
|
5
|
+
import { Validator } from '@famir/validator';
|
|
6
|
+
import { BaseController } from '../base/index.js';
|
|
7
|
+
import { type CompleteService } from './complete.service.js';
|
|
8
|
+
export declare class CompleteController extends BaseController {
|
|
9
|
+
protected readonly completeService: CompleteService;
|
|
10
|
+
static register(container: DIContainer): void;
|
|
11
|
+
static resolve(container: DIContainer): CompleteController;
|
|
12
|
+
constructor(validator: Validator, logger: Logger, templater: Templater, router: HttpServerRouter, completeService: CompleteService);
|
|
13
|
+
use(): void;
|
|
14
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { HTTP_SERVER_ROUTER } from '@famir/http-server';
|
|
2
|
+
import { LOGGER } from '@famir/logger';
|
|
3
|
+
import { TEMPLATER } from '@famir/templater';
|
|
4
|
+
import { VALIDATOR } from '@famir/validator';
|
|
5
|
+
import { BaseController } from '../base/index.js';
|
|
6
|
+
import { COMPLETE_CONTROLLER, COMPLETE_SERVICE } from './complete.js';
|
|
7
|
+
export class CompleteController extends BaseController {
|
|
8
|
+
completeService;
|
|
9
|
+
static register(container) {
|
|
10
|
+
container.registerSingleton(COMPLETE_CONTROLLER, (c) => new CompleteController(c.resolve(VALIDATOR), c.resolve(LOGGER), c.resolve(TEMPLATER), c.resolve(HTTP_SERVER_ROUTER), c.resolve(COMPLETE_SERVICE)));
|
|
11
|
+
}
|
|
12
|
+
static resolve(container) {
|
|
13
|
+
return container.resolve(COMPLETE_CONTROLLER);
|
|
14
|
+
}
|
|
15
|
+
constructor(validator, logger, templater, router, completeService) {
|
|
16
|
+
super(validator, logger, templater, router);
|
|
17
|
+
this.completeService = completeService;
|
|
18
|
+
this.logger.debug(`CompleteController initialized`);
|
|
19
|
+
}
|
|
20
|
+
use() {
|
|
21
|
+
this.router.addMiddleware('complete', async (ctx, next) => {
|
|
22
|
+
const campaign = this.getState(ctx, 'campaign');
|
|
23
|
+
const proxy = this.getState(ctx, 'proxy');
|
|
24
|
+
const target = this.getState(ctx, 'target');
|
|
25
|
+
const session = this.getState(ctx, 'session');
|
|
26
|
+
const message = this.getState(ctx, 'message');
|
|
27
|
+
message.payload['user-agent'] = ctx.userAgent;
|
|
28
|
+
message.payload['request-content-type'] = message.requestHeaders.getContentType();
|
|
29
|
+
message.payload['request-cookies'] = message.requestHeaders.getCookies();
|
|
30
|
+
message.payload['response-cookies'] = message.responseHeaders.getSetCookies();
|
|
31
|
+
message.payload['response-content-type'] = message.responseHeaders.getContentType();
|
|
32
|
+
await this.completeService.createMessage({
|
|
33
|
+
campaignId: campaign.campaignId,
|
|
34
|
+
messageId: message.id,
|
|
35
|
+
proxyId: proxy.proxyId,
|
|
36
|
+
targetId: target.targetId,
|
|
37
|
+
sessionId: session.sessionId,
|
|
38
|
+
type: message.type,
|
|
39
|
+
method: message.method.get(),
|
|
40
|
+
url: message.url.toRelative(),
|
|
41
|
+
requestHeaders: message.requestHeaders.toObject(),
|
|
42
|
+
requestBody: message.requestBody.get(),
|
|
43
|
+
status: message.status.get(),
|
|
44
|
+
responseHeaders: message.responseHeaders.toObject(),
|
|
45
|
+
responseBody: message.responseBody.get(),
|
|
46
|
+
connection: message.connection,
|
|
47
|
+
payload: message.payload,
|
|
48
|
+
errors: message.errors,
|
|
49
|
+
analyze: message.analyze,
|
|
50
|
+
startTime: ctx.startTime,
|
|
51
|
+
finishTime: ctx.finishTime,
|
|
52
|
+
});
|
|
53
|
+
await next();
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=complete.controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"complete.controller.js","sourceRoot":"","sources":["../../../src/modules/complete/complete.controller.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAoB,MAAM,oBAAoB,CAAA;AACzE,OAAO,EAAU,MAAM,EAAE,MAAM,eAAe,CAAA;AAC9C,OAAO,EAAE,SAAS,EAAa,MAAM,kBAAkB,CAAA;AACvD,OAAO,EAAa,SAAS,EAAE,MAAM,kBAAkB,CAAA;AACvD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AACjD,OAAO,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAA;AAQrE,MAAM,OAAO,kBAAmB,SAAQ,cAAc;IA8B/B;IA1BrB,MAAM,CAAC,QAAQ,CAAC,SAAsB;QACpC,SAAS,CAAC,iBAAiB,CACzB,mBAAmB,EACnB,CAAC,CAAC,EAAE,EAAE,CACJ,IAAI,kBAAkB,CACpB,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,EACpB,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,EACjB,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,EACpB,CAAC,CAAC,OAAO,CAAC,kBAAkB,CAAC,EAC7B,CAAC,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAC5B,CACJ,CAAA;IACH,CAAC;IAKD,MAAM,CAAC,OAAO,CAAC,SAAsB;QACnC,OAAO,SAAS,CAAC,OAAO,CAAC,mBAAmB,CAAC,CAAA;IAC/C,CAAC;IAED,YACE,SAAoB,EACpB,MAAc,EACd,SAAoB,EACpB,MAAwB,EACL,eAAgC;QAEnD,KAAK,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,CAAC,CAAA;QAFxB,oBAAe,GAAf,eAAe,CAAiB;QAInD,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,gCAAgC,CAAC,CAAA;IACrD,CAAC;IAED,GAAG;QACD,IAAI,CAAC,M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AAC,MAAM,CAAC,GAAG,EAAE;gBAC5B,GAAG,EAAE,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE;gBAC7B,cAAc,EAAE,OAAO,CAAC,cAAc,CAAC,QAAQ,EAAE;gBACjD,WAAW,EAAE,OAAO,CAAC,WAAW,CAAC,GAAG,EAAE;gBACtC,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,GAAG,EAAE;gBAC5B,eAAe,EAAE,OAAO,CAAC,eAAe,CAAC,QAAQ,EAAE;gBACnD,YAAY,EAAE,OAAO,CAAC,YAAY,CAAC,GAAG,EAAE;gBACxC,UAAU,EAAE,OAAO,CAAC,UAAU;gBAC9B,OAAO,EAAE,OAAO,CAAC,OAAO;gBACxB,MAAM,EAAE,OAAO,CAAC,MAAM;gBACtB,OAAO,EAAE,OAAO,CAAC,OAAO;gBACxB,SAAS,EAAE,GAAG,CAAC,SAAS;gBACxB,UAAU,EAAE,GAAG,CAAC,UAAU;aAC3B,CAAC,CAAA;YAEF,MAAM,IAAI,EAAE,CAAA;QACd,CAAC,CAAC,CAAA;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { HttpBody, HttpConnection, HttpError, HttpHeaders, HttpMethod, HttpPayload, HttpType } from '@famir/http-proto';
|
|
2
|
+
export declare const COMPLETE_CONTROLLER: unique symbol;
|
|
3
|
+
export declare const COMPLETE_SERVICE: unique symbol;
|
|
4
|
+
export interface CreateMessageData {
|
|
5
|
+
campaignId: string;
|
|
6
|
+
messageId: string;
|
|
7
|
+
proxyId: string;
|
|
8
|
+
targetId: string;
|
|
9
|
+
sessionId: string;
|
|
10
|
+
type: HttpType;
|
|
11
|
+
method: HttpMethod;
|
|
12
|
+
url: string;
|
|
13
|
+
requestHeaders: HttpHeaders;
|
|
14
|
+
requestBody: HttpBody;
|
|
15
|
+
status: number;
|
|
16
|
+
responseHeaders: HttpHeaders;
|
|
17
|
+
responseBody: HttpBody;
|
|
18
|
+
connection: HttpConnection;
|
|
19
|
+
payload: HttpPayload;
|
|
20
|
+
errors: HttpError[];
|
|
21
|
+
analyze: string | null;
|
|
22
|
+
startTime: number;
|
|
23
|
+
finishTime: number;
|
|
24
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"complete.js","sourceRoot":"","sources":["../../../src/modules/complete/complete.ts"],"names":[],"mappings":"AAcA,MAAM,CAAC,MAAM,mBAAmB,GAAG,MAAM,CAAC,oBAAoB,CAAC,CAAA;AAM/D,MAAM,CAAC,MAAM,gBAAgB,GAAG,MAAM,CAAC,iBAAiB,CAAC,CAAA"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { DIContainer } from '@famir/common';
|
|
2
|
+
import { MessageRepository } from '@famir/database';
|
|
3
|
+
import { AnalyzeQueue } from '@famir/produce';
|
|
4
|
+
import { CreateMessageData } from './complete.js';
|
|
5
|
+
export declare class CompleteService {
|
|
6
|
+
protected readonly messageRepository: MessageRepository;
|
|
7
|
+
protected readonly analyzeQueue: AnalyzeQueue;
|
|
8
|
+
static register(container: DIContainer): void;
|
|
9
|
+
constructor(messageRepository: MessageRepository, analyzeQueue: AnalyzeQueue);
|
|
10
|
+
createMessage(data: CreateMessageData): Promise<void>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { DatabaseError, MESSAGE_REPOSITORY } from '@famir/database';
|
|
2
|
+
import { HttpServerError } from '@famir/http-server';
|
|
3
|
+
import { ANALYZE_QUEUE } from '@famir/produce';
|
|
4
|
+
import { COMPLETE_SERVICE } from './complete.js';
|
|
5
|
+
export class CompleteService {
|
|
6
|
+
messageRepository;
|
|
7
|
+
analyzeQueue;
|
|
8
|
+
static register(container) {
|
|
9
|
+
container.registerSingleton(COMPLETE_SERVICE, (c) => new CompleteService(c.resolve(MESSAGE_REPOSITORY), c.resolve(ANALYZE_QUEUE)));
|
|
10
|
+
}
|
|
11
|
+
constructor(messageRepository, analyzeQueue) {
|
|
12
|
+
this.messageRepository = messageRepository;
|
|
13
|
+
this.analyzeQueue = analyzeQueue;
|
|
14
|
+
}
|
|
15
|
+
async createMessage(data) {
|
|
16
|
+
try {
|
|
17
|
+
if (data.analyze) {
|
|
18
|
+
await this.messageRepository.create(data.campaignId, data.messageId, data.proxyId, data.targetId, data.sessionId, data.type, data.method, data.url, data.requestHeaders, data.requestBody, data.status, data.responseHeaders, data.responseBody, data.connection, data.payload, data.errors, data.analyze, data.startTime, data.finishTime);
|
|
19
|
+
await this.analyzeQueue.addJob(data.analyze, {
|
|
20
|
+
campaignId: data.campaignId,
|
|
21
|
+
messageId: data.messageId,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
await this.messageRepository.createDummy(data.campaignId, data.messageId, data.proxyId, data.targetId, data.sessionId);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
if (error instanceof DatabaseError) {
|
|
30
|
+
if (error.code === 'NOT_FOUND') {
|
|
31
|
+
throw new HttpServerError(`Service unavailable`, {
|
|
32
|
+
cause: error,
|
|
33
|
+
context: {
|
|
34
|
+
reason: `Create message failed`,
|
|
35
|
+
},
|
|
36
|
+
code: 'SERVICE_UNAVAILABLE',
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
throw error;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=complete.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"complete.service.js","sourceRoot":"","sources":["../../../src/modules/complete/complete.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAqB,MAAM,iBAAiB,CAAA;AACtF,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AACpD,OAAO,EAAE,aAAa,EAAgB,MAAM,gBAAgB,CAAA;AAC5D,OAAO,EAAE,gBAAgB,EAAqB,MAAM,eAAe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AAC,WAAW,CACtC,IAAI,CAAC,UAAU,EACf,IAAI,CAAC,SAAS,EACd,IAAI,CAAC,OAAO,EACZ,IAAI,CAAC,QAAQ,EACb,IAAI,CAAC,SAAS,CACf,CAAA;YACH,CAAC;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,KAAK,YAAY,aAAa,EAAE,CAAC;gBACnC,IAAI,KAAK,CAAC,IAAI,KAAK,WAAW,EAAE,CAAC;oBAC/B,MAAM,IAAI,eAAe,CAAC,qBAAqB,EAAE;wBAC/C,KAAK,EAAE,KAAK;wBACZ,OAAO,EAAE;4BACP,MAAM,EAAE,uBAAuB;yBAChC;wBACD,IAAI,EAAE,qBAAqB;qBAC5B,CAAC,CAAA;gBACJ,CAAC;YACH,CAAC;YAED,MAAM,KAAK,CAAA;QACb,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/modules/complete/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAA;AACxC,cAAc,eAAe,CAAA;AAC7B,cAAc,uBAAuB,CAAA"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { DIContainer } from '@famir/common';
|
|
2
|
+
import { HttpServerRouter } from '@famir/http-server';
|
|
3
|
+
import { Logger } from '@famir/logger';
|
|
4
|
+
import { Templater } from '@famir/templater';
|
|
5
|
+
import { Validator } from '@famir/validator';
|
|
6
|
+
import { BaseController } from '../base/index.js';
|
|
7
|
+
import { type ForwardService } from './forward.service.js';
|
|
8
|
+
export declare class ForwardController extends BaseController {
|
|
9
|
+
protected readonly forwardService: ForwardService;
|
|
10
|
+
static register(container: DIContainer): void;
|
|
11
|
+
static resolve(container: DIContainer): ForwardController;
|
|
12
|
+
constructor(validator: Validator, logger: Logger, templater: Templater, router: HttpServerRouter, forwardService: ForwardService);
|
|
13
|
+
use(): void;
|
|
14
|
+
private dispatchRoot;
|
|
15
|
+
}
|