lemonldap-ng-handler 0.5.3 → 0.6.0
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/CHANGELOG.md +23 -0
- package/LICENSE +622 -284
- package/lib/handlerDevOps.d.ts +22 -0
- package/lib/handlerDevOpsST.d.ts +10 -0
- package/lib/handlerMain.d.ts +30 -0
- package/lib/handlerServiceToken.d.ts +8 -0
- package/lib/index.d.ts +10 -0
- package/lib/index.js +2 -322
- package/lib/index.js.map +1 -0
- package/lib/index.mjs +726 -0
- package/lib/index.mjs.map +1 -0
- package/lib/init.d.ts +30 -0
- package/lib/tsv.d.ts +59 -0
- package/package.json +20 -47
- package/lib/conf.js +0 -340
- package/lib/handlerDevOps.js +0 -167
- package/lib/handlerDevOpsST.js +0 -23
- package/lib/handlerOAuth2.js +0 -55
- package/lib/handlerServiceToken.js +0 -59
- package/lib/safelib.js +0 -174
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { LLNG_Session } from '@lemonldap-ng/types';
|
|
3
|
+
import { Handler_Args } from './init';
|
|
4
|
+
import LemonldapNGHandler from './handlerMain';
|
|
5
|
+
import express from 'express';
|
|
6
|
+
import http from 'http';
|
|
7
|
+
declare type Vhost_Config = {
|
|
8
|
+
prot: string;
|
|
9
|
+
host: string;
|
|
10
|
+
path: string;
|
|
11
|
+
port: string;
|
|
12
|
+
headers?: {
|
|
13
|
+
[k: string]: string;
|
|
14
|
+
};
|
|
15
|
+
lb?: boolean;
|
|
16
|
+
};
|
|
17
|
+
declare class LemonldapNGHandlerDevOps extends LemonldapNGHandler {
|
|
18
|
+
constructor(args: Handler_Args);
|
|
19
|
+
grant(req: express.Request | http.IncomingMessage, uri: string, session: LLNG_Session): Promise<boolean>;
|
|
20
|
+
loadVhostConfig(req: express.Request | http.IncomingMessage, vhost: string, lvOpts: Vhost_Config): Promise<boolean>;
|
|
21
|
+
}
|
|
22
|
+
export default LemonldapNGHandlerDevOps;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Request } from 'express';
|
|
3
|
+
import { ParamsDictionary } from 'express-serve-static-core';
|
|
4
|
+
import { IncomingMessage } from 'http';
|
|
5
|
+
import { ParsedQs } from 'qs';
|
|
6
|
+
import LemonldapNGHandlerDevOps from './handlerDevOps';
|
|
7
|
+
declare class LemonldapNGHandlerDevOpsST extends LemonldapNGHandlerDevOps {
|
|
8
|
+
fetchId(req: Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>> | IncomingMessage): string;
|
|
9
|
+
}
|
|
10
|
+
export default LemonldapNGHandlerDevOpsST;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { LLNG_Session } from '@lemonldap-ng/types';
|
|
3
|
+
import HandlerInit from './init';
|
|
4
|
+
import express from 'express';
|
|
5
|
+
import http from 'http';
|
|
6
|
+
export declare type FastCGI_Opts = {
|
|
7
|
+
mode: string | undefined;
|
|
8
|
+
port: number | undefined;
|
|
9
|
+
ip: string | undefined;
|
|
10
|
+
};
|
|
11
|
+
declare class LemonldapNGHandler extends HandlerInit {
|
|
12
|
+
init(): Promise<boolean>;
|
|
13
|
+
/**
|
|
14
|
+
* run(), the access control function
|
|
15
|
+
*/
|
|
16
|
+
run(req: express.Request | http.IncomingMessage, res: http.ServerResponse, next: Function): any;
|
|
17
|
+
selfUri(vhost: string, uri: string): string;
|
|
18
|
+
nginxServer(fcgiOpt: FastCGI_Opts): void;
|
|
19
|
+
setError(res: http.ServerResponse, uri: string, code: number, txt: string): void;
|
|
20
|
+
isUnprotected(req: express.Request | http.IncomingMessage, uri: string): number | false;
|
|
21
|
+
resolveAlias(req: express.Request | http.IncomingMessage): string;
|
|
22
|
+
fetchId(req: express.Request | http.IncomingMessage): string;
|
|
23
|
+
retrieveSession(id: string): Promise<LLNG_Session>;
|
|
24
|
+
grant(req: express.Request | http.IncomingMessage, uri: string, session: LLNG_Session): Promise<boolean>;
|
|
25
|
+
sendHeaders(req: express.Request | http.IncomingMessage, session: LLNG_Session): void;
|
|
26
|
+
hideCookie(req: express.Request | http.IncomingMessage): void;
|
|
27
|
+
forbidden(req: express.Request | http.IncomingMessage, res: http.ServerResponse, session: LLNG_Session): void;
|
|
28
|
+
goToPortal(res: http.ServerResponse, uri: string, args?: string): void;
|
|
29
|
+
}
|
|
30
|
+
export default LemonldapNGHandler;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import express from 'express';
|
|
3
|
+
import http from 'http';
|
|
4
|
+
import LemonldapNGHandler from './handlerMain';
|
|
5
|
+
declare class LemonldapNGHandlerServiceToken extends LemonldapNGHandler {
|
|
6
|
+
fetchId(req: express.Request | http.IncomingMessage): string;
|
|
7
|
+
}
|
|
8
|
+
export default LemonldapNGHandlerServiceToken;
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import express from 'express';
|
|
2
|
+
import http from 'http';
|
|
3
|
+
import { Handler_Args } from './init';
|
|
4
|
+
import LemonldapNGHandler, { FastCGI_Opts } from './handlerMain';
|
|
5
|
+
import LemonldapNGHandlerDevOps from './handlerDevOps';
|
|
6
|
+
declare let currentClass: typeof LemonldapNGHandler | typeof LemonldapNGHandlerDevOps;
|
|
7
|
+
export declare const init: (args: Handler_Args) => Promise<LemonldapNGHandler>;
|
|
8
|
+
export declare const run: (req: express.Request | http.IncomingMessage, res: http.ServerResponse, next: Function) => any;
|
|
9
|
+
export declare const nginxServer: (args: FastCGI_Opts) => void;
|
|
10
|
+
export { currentClass as class };
|
package/lib/index.js
CHANGED
|
@@ -1,322 +1,2 @@
|
|
|
1
|
-
(function() {
|
|
2
|
-
|
|
3
|
-
* LemonLDAP::NG handler for Node.js/express
|
|
4
|
-
*
|
|
5
|
-
* See README.md for license and copyright
|
|
6
|
-
*/
|
|
7
|
-
var Handler, conf, h, normalizeUrl;
|
|
8
|
-
|
|
9
|
-
conf = null;
|
|
10
|
-
|
|
11
|
-
normalizeUrl = require('normalize-url');
|
|
12
|
-
|
|
13
|
-
Handler = class Handler {
|
|
14
|
-
constructor(args) {
|
|
15
|
-
var m;
|
|
16
|
-
m = require('./conf');
|
|
17
|
-
this.conf = new m(args);
|
|
18
|
-
this.logger = this.conf.logger;
|
|
19
|
-
this.userLogger = this.conf.userLogger;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
run(req, res, next) {
|
|
23
|
-
var id, protection, self, u, uri, vhost;
|
|
24
|
-
self = this;
|
|
25
|
-
vhost = req.headers.host;
|
|
26
|
-
uri = normalizeUrl(req.url);
|
|
27
|
-
if (this.conf.tsv.maintenance[vhost]) {
|
|
28
|
-
self.logger.info(`Go to portal with maintenance error code ${vhost}`);
|
|
29
|
-
return this.setError(res, '/', 503, 'Service Temporarily Unavailable');
|
|
30
|
-
}
|
|
31
|
-
protection = this.isUnprotected(req, uri);
|
|
32
|
-
// Skip value is 2
|
|
33
|
-
if (protection === 2) {
|
|
34
|
-
next();
|
|
35
|
-
return new Promise(function(resolve, reject) {
|
|
36
|
-
return resolve(true);
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
id = this.fetchId(req);
|
|
40
|
-
if (id) {
|
|
41
|
-
return self.retrieveSession(id).then(function(session) {
|
|
42
|
-
return self.grant(req, uri, session).then(function() {
|
|
43
|
-
// TODO: display uid
|
|
44
|
-
self.userLogger.info(`User ${session[self.conf.tsv.whatToTrace]} was granted to access to ${uri}`);
|
|
45
|
-
self.sendHeaders(req, session);
|
|
46
|
-
self.hideCookie(req);
|
|
47
|
-
return next();
|
|
48
|
-
}).catch(function(e) {
|
|
49
|
-
self.userLogger.warn(`${session[self.conf.tsv.whatToTrace]} rejected: ` + (e != null ? (e.message != null ? e.message : e) : ''));
|
|
50
|
-
return self.forbidden(req, res, session);
|
|
51
|
-
});
|
|
52
|
-
}).catch(function(e) {
|
|
53
|
-
self.logger.info(`Session error: ${e}`);
|
|
54
|
-
return self.goToPortal(res, 'http://' + vhost + uri);
|
|
55
|
-
});
|
|
56
|
-
} else {
|
|
57
|
-
self.logger.debug("No id");
|
|
58
|
-
u = `://${vhost}${uri}`;
|
|
59
|
-
if ((this.conf.tsv.https != null) && this.conf.tsv.https[vhost]) {
|
|
60
|
-
u = `https${u}`;
|
|
61
|
-
} else {
|
|
62
|
-
u = `http${u}`;
|
|
63
|
-
}
|
|
64
|
-
return this.goToPortal(res, u);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
nginxServer(options) {
|
|
69
|
-
var fcgiOpt, k, self, srv;
|
|
70
|
-
self = this;
|
|
71
|
-
fcgiOpt = {
|
|
72
|
-
mode: "fcgi",
|
|
73
|
-
port: 9090,
|
|
74
|
-
ip: 'localhost'
|
|
75
|
-
};
|
|
76
|
-
if (options != null) {
|
|
77
|
-
for (k in fcgiOpt) {
|
|
78
|
-
if (options[k] != null) {
|
|
79
|
-
fcgiOpt[k] = options[k];
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
// Define server
|
|
84
|
-
srv = fcgiOpt.mode === 'fcgi' ? require('node-fastcgi') : require('http');
|
|
85
|
-
srv.createServer(function(req, res) {
|
|
86
|
-
var next, resp;
|
|
87
|
-
next = function() {
|
|
88
|
-
return res.writeHead(200, req.headers);
|
|
89
|
-
};
|
|
90
|
-
resp = self.run(req, res, next);
|
|
91
|
-
if (resp.then) {
|
|
92
|
-
return resp.then(function() {
|
|
93
|
-
return res.end();
|
|
94
|
-
});
|
|
95
|
-
} else {
|
|
96
|
-
return res.end();
|
|
97
|
-
}
|
|
98
|
-
}).listen(fcgiOpt.port, fcgiOpt.ip);
|
|
99
|
-
return self.logger.info("Server started at " + fcgiOpt.ip + ":" + fcgiOpt.port);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
grant(req, uri, session) {
|
|
103
|
-
var d, self;
|
|
104
|
-
self = this;
|
|
105
|
-
d = new Promise(function(resolve, reject) {
|
|
106
|
-
var i, j, len, ref, rule, vhost;
|
|
107
|
-
vhost = self.resolveAlias(req);
|
|
108
|
-
if (self.conf.tsv.defaultCondition[vhost] == null) {
|
|
109
|
-
self.logger.error(`No configuration found for ${vhost} (or not listed in Node.js virtualHosts)`);
|
|
110
|
-
return reject();
|
|
111
|
-
}
|
|
112
|
-
if (self.conf.tsv.locationRegexp[vhost] == null) {
|
|
113
|
-
self.conf.tsv.locationRegexp[vhost] = [];
|
|
114
|
-
}
|
|
115
|
-
ref = self.conf.tsv.locationRegexp[vhost];
|
|
116
|
-
for (i = j = 0, len = ref.length; j < len; i = ++j) {
|
|
117
|
-
rule = ref[i];
|
|
118
|
-
if (uri.match(rule)) {
|
|
119
|
-
return resolve(self.conf.tsv.locationCondition[vhost][i](req, session));
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
if (self.conf.tsv.defaultCondition[vhost](req, session)) {
|
|
123
|
-
return resolve();
|
|
124
|
-
} else {
|
|
125
|
-
return reject();
|
|
126
|
-
}
|
|
127
|
-
});
|
|
128
|
-
return d;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
forbidden(req, res, session) {
|
|
132
|
-
var u, uri;
|
|
133
|
-
uri = req.uri;
|
|
134
|
-
u = session._logout;
|
|
135
|
-
if (u) {
|
|
136
|
-
return this.goToPortal(res, u, 'logout=1');
|
|
137
|
-
}
|
|
138
|
-
// req.redirect is defined when running under express. If not
|
|
139
|
-
// we are running as FastCGI server
|
|
140
|
-
return this.setError(res, '/', 403, 'Forbidden');
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
sendHeaders(req, session) {
|
|
144
|
-
var err, i, k, ref, v, vhost;
|
|
145
|
-
vhost = this.resolveAlias(req);
|
|
146
|
-
try {
|
|
147
|
-
i = 0;
|
|
148
|
-
req.headers['Lm-Remote-User'] = session[this.conf.tsv.whatToTrace];
|
|
149
|
-
ref = this.conf.tsv.forgeHeaders[vhost](session);
|
|
150
|
-
for (k in ref) {
|
|
151
|
-
v = ref[k];
|
|
152
|
-
i++;
|
|
153
|
-
req.headers[k] = v;
|
|
154
|
-
req.rawHeaders.push(k, v);
|
|
155
|
-
// req.redirect is defined when running under express. If not
|
|
156
|
-
// we are running as FastCGI server
|
|
157
|
-
if (req.redirect == null) {
|
|
158
|
-
req.headers[`Headername${i}`] = k;
|
|
159
|
-
req.headers[`Headervalue${i}`] = v;
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
} catch (error) {
|
|
163
|
-
err = error;
|
|
164
|
-
this.logger.warn(`No headers configuration found for ${vhost}: ${err}`);
|
|
165
|
-
}
|
|
166
|
-
return true;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
resolveAlias(req) {
|
|
170
|
-
var vhost;
|
|
171
|
-
vhost = req.headers.host.replace(/:.*$/, '');
|
|
172
|
-
return this.conf.tsv.vhostAlias[vhost] || vhost;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
// Get cookie value
|
|
176
|
-
fetchId(req) {
|
|
177
|
-
var cor;
|
|
178
|
-
if (req.headers.cookie) {
|
|
179
|
-
cor = this.conf.tsv.cookieDetect.exec(req.headers.cookie);
|
|
180
|
-
if (cor && cor[1] !== '0') {
|
|
181
|
-
return cor[1];
|
|
182
|
-
}
|
|
183
|
-
} else {
|
|
184
|
-
return false;
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
// Get session from store
|
|
189
|
-
retrieveSession(id) {
|
|
190
|
-
var d, self;
|
|
191
|
-
self = this;
|
|
192
|
-
d = new Promise(function(resolve, reject) {
|
|
193
|
-
return self.conf.sa.get(id).then(function(session) {
|
|
194
|
-
var now;
|
|
195
|
-
// Timestamp in seconds
|
|
196
|
-
now = Date.now() / 1000 | 0;
|
|
197
|
-
if (now - session._utime > self.conf.tsv.timeout || (self.conf.tsv.timeoutActivity && session._lastSeen && now - $session._lastSeen > self.conf.tsv.timeoutActivity)) {
|
|
198
|
-
self.userLogger.info(`Session ${id} expired`);
|
|
199
|
-
reject(false);
|
|
200
|
-
}
|
|
201
|
-
// Update the session to notify activity, if necessary
|
|
202
|
-
if (self.conf.tsv.timeoutActivity && now - session._lastSeen > 60) {
|
|
203
|
-
session._lastSeen = now;
|
|
204
|
-
self.conf.sa.update(id, session);
|
|
205
|
-
}
|
|
206
|
-
return resolve(session);
|
|
207
|
-
}).catch(function(e) {
|
|
208
|
-
self.userLogger.info(`Session ${id} can't be found in store: ${e}`);
|
|
209
|
-
return reject(false);
|
|
210
|
-
});
|
|
211
|
-
});
|
|
212
|
-
return d;
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
// Check if uri is protected
|
|
216
|
-
isUnprotected(req, uri) {
|
|
217
|
-
var i, j, len, ref, rule, vhost;
|
|
218
|
-
vhost = this.resolveAlias(req);
|
|
219
|
-
if (this.conf.tsv.defaultCondition[vhost] == null) {
|
|
220
|
-
return false;
|
|
221
|
-
}
|
|
222
|
-
ref = this.conf.tsv.locationRegexp[vhost];
|
|
223
|
-
for (i = j = 0, len = ref.length; j < len; i = ++j) {
|
|
224
|
-
rule = ref[i];
|
|
225
|
-
if (uri.match(rule)) {
|
|
226
|
-
return this.conf.tsv.locationProtection[vhost][i];
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
return this.conf.tsv.defaultProtection[vhost];
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
// Remove LLNG cookie from headers
|
|
233
|
-
hideCookie(req) {
|
|
234
|
-
return req.headers.cookie = req.headers.cookie.replace(this.conf.tsv.cookieDetect, '');
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
goToPortal(res, uri, args) {
|
|
238
|
-
var urlc;
|
|
239
|
-
if (typeof this.conf.tsv.portal !== 'function') {
|
|
240
|
-
console.error("Configuration is not ready");
|
|
241
|
-
if (res.redirect) {
|
|
242
|
-
res.status(503).send('Waiting for configuration');
|
|
243
|
-
} else {
|
|
244
|
-
res.writeHead(503);
|
|
245
|
-
res.end();
|
|
246
|
-
}
|
|
247
|
-
return res;
|
|
248
|
-
}
|
|
249
|
-
urlc = this.conf.tsv.portal();
|
|
250
|
-
if (uri) {
|
|
251
|
-
urlc += '?url=' + new Buffer.from(encodeURI(uri)).toString('base64');
|
|
252
|
-
}
|
|
253
|
-
if (args) {
|
|
254
|
-
urlc += uri ? '&' : '?';
|
|
255
|
-
urlc += args;
|
|
256
|
-
}
|
|
257
|
-
// req.redirect is defined when running under express. If not
|
|
258
|
-
// we are running as FastCGI server
|
|
259
|
-
this.logger.debug("Redirecting to " + urlc);
|
|
260
|
-
if (res.redirect) {
|
|
261
|
-
res.redirect(urlc);
|
|
262
|
-
} else {
|
|
263
|
-
// Nginx doesn't accept 302 from a auth request. LLNG Nginx configuration
|
|
264
|
-
// maps 401 to 302 when "Location" is set
|
|
265
|
-
res.writeHead(401, {
|
|
266
|
-
Location: urlc
|
|
267
|
-
});
|
|
268
|
-
}
|
|
269
|
-
return res;
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
setError(res, uri, code, txt) {
|
|
273
|
-
var u;
|
|
274
|
-
if (this.conf.tsv.useRedirectOnError) {
|
|
275
|
-
u = this.conf.tsv.portal() + `?lmError=${code}&url=` + new Buffer.from(encodeURI(uri)).toString('base64');
|
|
276
|
-
this.logger.debug(`Redirecting to ${u}`);
|
|
277
|
-
if (res.redirect != null) {
|
|
278
|
-
return res.redirect(u);
|
|
279
|
-
} else {
|
|
280
|
-
// Nginx doesn't accept 302 from a auth request. LLNG Nginx configuration
|
|
281
|
-
// maps 401 to 302 when "Location" is set
|
|
282
|
-
return res.writeHead(401, {
|
|
283
|
-
Location: u
|
|
284
|
-
});
|
|
285
|
-
}
|
|
286
|
-
} else {
|
|
287
|
-
if (res.redirect != null) {
|
|
288
|
-
return res.status(code).send(txt);
|
|
289
|
-
} else {
|
|
290
|
-
return res.writeHead(code, txt);
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
};
|
|
296
|
-
|
|
297
|
-
h = {};
|
|
298
|
-
|
|
299
|
-
module.exports = {
|
|
300
|
-
init: function(args) {
|
|
301
|
-
var err;
|
|
302
|
-
if (args.type) {
|
|
303
|
-
try {
|
|
304
|
-
h = require('./handler' + args.type);
|
|
305
|
-
return h = new h(args);
|
|
306
|
-
} catch (error) {
|
|
307
|
-
err = error;
|
|
308
|
-
console.error(`Unable to load ${args.type} handler: ${err}`);
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
return h = new Handler(args);
|
|
312
|
-
},
|
|
313
|
-
run: function(req, res, next) {
|
|
314
|
-
return h.run(req, res, next);
|
|
315
|
-
},
|
|
316
|
-
nginxServer: function(options) {
|
|
317
|
-
return h.nginxServer(options);
|
|
318
|
-
},
|
|
319
|
-
class: Handler
|
|
320
|
-
};
|
|
321
|
-
|
|
322
|
-
}).call(this);
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("@lemonldap-ng/conf"),e=require("@lemonldap-ng/session"),o=require("@lemonldap-ng/safelib"),s=require("@lemonldap-ng/logger"),r=require("vm"),i=require("re2"),n=require("http");function a(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}function c(t){if(t&&t.__esModule)return t;var e=Object.create(null);return t&&Object.keys(t).forEach((function(o){if("default"!==o){var s=Object.getOwnPropertyDescriptor(t,o);Object.defineProperty(e,o,s.get?s:{enumerable:!0,get:function(){return t[o]}})}})),e.default=t,Object.freeze(e)}var h=a(t),l=a(e),d=a(o),u=a(s),p=a(r),f=a(i),v=a(n);const g=new f.default("^logout(?:_sso|_app|_app_sso|)(?:s+(.*))?$","i");let m=0;const w=["cda","cookieExpiration","cipher","cookieName","customFunctions","httpOnly","securedCookie","timeout","timeoutActivity","useRedirectOnError","useRedirectOnForbidden","whatToTrace","loopBackUrl"];const y=(t,e)=>e.some((e=>e instanceof RegExp?e.test(t):e===t));function b(t,e){if(e={defaultProtocol:"http:",normalizeProtocol:!0,forceHttp:!1,forceHttps:!1,stripAuthentication:!0,stripHash:!1,stripTextFragment:!0,stripWWW:!0,removeQueryParameters:[/^utm_\w+/i],removeTrailingSlash:!0,removeSingleSlash:!0,removeDirectoryIndex:!1,sortQueryParameters:!0,...e},t=t.trim(),/^data:/i.test(t))return((t,{stripHash:e})=>{const o=/^data:(?<type>[^,]*?),(?<data>[^#]*?)(?:#(?<hash>.*))?$/.exec(t);if(!o)throw new Error(`Invalid URL: ${t}`);let{type:s,data:r,hash:i}=o.groups;const n=s.split(";");i=e?"":i;let a=!1;"base64"===n[n.length-1]&&(n.pop(),a=!0);const c=(n.shift()||"").toLowerCase(),h=[...n.map((t=>{let[e,o=""]=t.split("=").map((t=>t.trim()));return"charset"===e&&(o=o.toLowerCase(),"us-ascii"===o)?"":`${e}${o?`=${o}`:""}`})).filter(Boolean)];return a&&h.push("base64"),(h.length>0||c&&"text/plain"!==c)&&h.unshift(c),`data:${h.join(";")},${a?r.trim():r}${i?`#${i}`:""}`})(t,e);if(/^view-source:/i.test(t))throw new Error("`view-source:` is not supported as it is a non-standard protocol");const o=t.startsWith("//");!o&&/^\.*\//.test(t)||(t=t.replace(/^(?!(?:\w+:)?\/\/)|^\/\//,e.defaultProtocol));const s=new URL(t);if(e.forceHttp&&e.forceHttps)throw new Error("The `forceHttp` and `forceHttps` options cannot be used together");if(e.forceHttp&&"https:"===s.protocol&&(s.protocol="http:"),e.forceHttps&&"http:"===s.protocol&&(s.protocol="https:"),e.stripAuthentication&&(s.username="",s.password=""),e.stripHash?s.hash="":e.stripTextFragment&&(s.hash=s.hash.replace(/#?:~:text.*?$/i,"")),s.pathname){const t=/\b[a-z][a-z\d+\-.]{1,50}:\/\//g;let e=0,o="";for(;;){const r=t.exec(s.pathname);if(!r)break;const i=r[0],n=r.index;o+=s.pathname.slice(e,n).replace(/\/{2,}/g,"/"),o+=i,e=n+i.length}o+=s.pathname.slice(e,s.pathname.length).replace(/\/{2,}/g,"/"),s.pathname=o}if(s.pathname)try{s.pathname=decodeURI(s.pathname)}catch{}if(!0===e.removeDirectoryIndex&&(e.removeDirectoryIndex=[/^index\.[a-z]+$/]),Array.isArray(e.removeDirectoryIndex)&&e.removeDirectoryIndex.length>0){let t=s.pathname.split("/");const o=t[t.length-1];y(o,e.removeDirectoryIndex)&&(t=t.slice(0,-1),s.pathname=t.slice(1).join("/")+"/")}if(s.hostname&&(s.hostname=s.hostname.replace(/\.$/,""),e.stripWWW&&/^www\.(?!www\.)[a-z\-\d]{1,63}\.[a-z.\-\d]{2,63}$/.test(s.hostname)&&(s.hostname=s.hostname.replace(/^www\./,""))),Array.isArray(e.removeQueryParameters))for(const t of[...s.searchParams.keys()])y(t,e.removeQueryParameters)&&s.searchParams.delete(t);if(!0===e.removeQueryParameters&&(s.search=""),e.sortQueryParameters){s.searchParams.sort();try{s.search=decodeURIComponent(s.search)}catch{}}e.removeTrailingSlash&&(s.pathname=s.pathname.replace(/\/$/,""));const r=t;return t=s.toString(),e.removeSingleSlash||"/"!==s.pathname||r.endsWith("/")||""!==s.hash||(t=t.replace(/\/$/,"")),(e.removeTrailingSlash||"/"===s.pathname)&&""===s.hash&&e.removeSingleSlash&&(t=t.replace(/\/$/,"")),o&&!e.normalizeProtocol&&(t=t.replace(/^http:\/\//,"//")),e.stripProtocol&&(t=t.replace(/^(?:https?:)?\/\//,"")),t}class $ extends class{constructor(t){this.safe={},this.tsv={defaultCondition:{},defaultProtection:{},forgeHeaders:{},headerList:{},https:{},locationCondition:{},locationCount:{},locationProtection:{},locationRegexp:{},maintenance:{},port:{},portal:()=>"",vhostAlias:{}},this.localConf=t,t.configStorage||(t.configStorage={}),t.configStorage.localStorage||(t.configStorage.localStorage=t.localStorage),t.configStorage.localStorageOptions||(t.configStorage.localStorageOptions=t.localStorageOptions),this.confAcc=new h.default(t.configStorage);if([this.confAcc.getLocalConf("handler",!0),this.confAcc.getLocalConf("node-handler",!1)].forEach((t=>{Object.keys(t).forEach((e=>{if(!this.localConf)throw new Error("undef");void 0===this.localConf[e]&&(this.localConf[e]=t[e])}))})),void 0===this.localConf.nodeVhosts)throw new Error("No Virtualhosts configured for Node.js");this.vhostList=this.localConf.nodeVhosts.split(/[,\s]+/)}reload(){return new Promise(((t,e)=>{this.confAcc.ready.then((()=>{this.confAcc.getConf({}).then((e=>{if(w.forEach((t=>{this.tsv[t]=e[t]})),Object.keys(this.localConf).forEach((t=>{e[t]=this.localConf[t]})),["https","port","maintenance"].forEach((t=>{if(void 0!==e[t]&&(this.tsv[t]={_:e[t]},e.vhostOptions)){const s=`vhost${o=t,o.charAt(0).toUpperCase()+o.slice(1)}`;Object.keys(e.vhostOptions).forEach((o=>{const r=e.vhostOptions[o][s];r>0&&(this.tsv[t][o]=r)}))}var o})),!e.portal)throw new Error("portal should be defined");if(this.tsv.portal=()=>e.portal,!e.globalStorage||!e.globalStorageOptions)throw new Error("Bad session storage coniguration");try{this.sessionAcc=new l.default({storageModule:e.globalStorage,storageModuleOptions:e.globalStorageOptions})}catch(t){throw new Error(`Unable to load session module: ${t}`)}Object.keys(e.locationRules).forEach((t=>{if(-1==this.vhostList.indexOf(t))return;this.tsv.locationCount[t]=0,["locationRegexp","locationProtection","locationCondition"].forEach((e=>{void 0===this.tsv[e][t]&&(this.tsv[e][t]=[])})),this.safe[t]||(this.safe[t]=new d.default(e));const o=e.locationRules[t];Object.keys(o).forEach((e=>{const[s,r]=this.conditionSub(o[e],this.safe[t]);"default"===e?(this.tsv.defaultCondition[t]=s,this.tsv.defaultProtection[t]=r):(this.tsv.locationCondition[t].push(s),this.tsv.locationProtection[t].push(r),this.tsv.locationRegexp[t].push(new f.default(e.replace(/\(\?#.*?\)/,""))),this.tsv.locationCount[t]++)})),this.tsv.defaultCondition[t]||(this.tsv.defaultCondition[t]=()=>!0,this.tsv.defaultProtection[t]=0)})),void 0!==e.exportedHeaders&&Object.keys(e.exportedHeaders).forEach((t=>{const o=e.exportedHeaders[t];if(-1==this.vhostList.indexOf(t))return;this.tsv.headerList[t]||(this.tsv.headerList[t]=[]);let s="";Object.keys(o).forEach((e=>{this.tsv.headerList[t].push(e),s+=`'${e}': ${this.substitute(o[e])},`})),s=s.replace(/,$/,""),p.default.runInContext(`fg = function(session) {return {${s}};}`,this.safe[t]),this.tsv.forgeHeaders[t]=this.safe[t].fg})),void 0!==e.vhostOptions&&Object.keys(e.vhostOptions).forEach((t=>{e.vhostOptions[t].aliases&&e.vhostOptions[t].aliases.forEach((e=>{this.tsv.vhostAlias[e]=t}))})),this.tsv.cookieDetect=new f.default(`\\b${this.tsv.cookieName}=([^;]+)`),this.sessionAcc.ready.then((()=>{t(!0),u.default(e,!0).then((e=>{this.userLogger=e,t(!0)})).catch((t=>{throw console.error("Logger error",t),new Error(t)}))}))})).catch((t=>{e(`Unable to get configuration: ${t}`)}))}))}))}conditionSub(t,e){const o=()=>!0;if("accept"===t)return[o,0];if("deny"===t)return[()=>!1,0];if("unprotect"===t)return[o,1];if("skip"===t)return[o,2];const s=g.exec(t);if(s&&s[1]){const t=s[1];return t?[e=>(e._logout=t,!1),0]:[t=>(t._logout=this.tsv.portal(),!1),0]}if(t=this.substitute(t),e)return m++,p.default.runInContext(`sub${m.toString()} = function(req,session) {return (${t});}`,e),[e[`sub${m.toString()}`],0];throw new Error("Disabling safeJail is not supported")}substitute(t){return t.replace(/\$date\b/g,"this.date()").replace(/\$vhost\b/g,"this.hostname(req)").replace(/\$ip\b/g,"this.remote_ip(req)").replace(/\$(_*[a-zA-Z]\w*)/g,"session.$1")}}{init(){return this.reload()}run(t,e,o){const s=t.headers.host;if(void 0===s)return this.userLogger.error("Request without Host header"),void this.setError(e,"/",400,"Bad request");const r=new URL(b(s+t.url)).pathname||"/";if(this.tsv.maintenance[s])return this.setError(e,"/",503,"Service Temporarily Unavailable");if(2===this.isUnprotected(t,r))return o();const i=this.fetchId(t);""!==i?this.retrieveSession(i).then((i=>{const n=i[this.tsv.whatToTrace];this.userLogger.debug(`User ${n} identified`),this.grant(t,r,i).then((a=>{a?(this.sendHeaders(t,i),this.hideCookie(t),o(),this.userLogger.info(`${s}: user ${n} was granted access to ${r}`)):(this.forbidden(t,e,i),this.userLogger.notice(`${s}: user ${n} was denied access to ${r}`))})).catch((t=>{console.error(t),this.setError(e,"/",500,"Server error")}))})).catch((t=>{this.goToPortal(e,this.selfUri(s,r))})):this.goToPortal(e,this.selfUri(s,r))}selfUri(t,e){return(this.tsv.https&&this.tsv.https[t]?"https":"http")+"://"+t+e}nginxServer(t){t.mode||(t.mode="fcgi"),t.port||(t.port=9090),t.ip||(t.ip="localhost");("fcgi"===t.mode?require("node-fastcgi"):v.default).createServer(((t,e)=>{this.run(t,e,(()=>{e.writeHead(200,t.headers)}))})).listen(t.port,t.ip)}setError(t,e,o,s){if(this.tsv.useRedirectOnError){const e=this.tsv.portal()+`?lmError=${o.toString()}&url=`;t.redirect?t.redirect(e):t.writeHead(401,{Location:e})}else t.redirect?t.status(o).send(s):t.writeHead(o,s)}isUnprotected(t,e){const o=this.resolveAlias(t);if(!this.tsv.defaultCondition[o])return!1;for(let t=0;t<this.tsv.locationRegexp[o].length;t++)if(this.tsv.locationRegexp[o][t].test(e))return this.tsv.locationProtection[o][t];return this.tsv.defaultProtection[o]}resolveAlias(t){const e=t.headers.host.replace(/:.*$/,"");return this.tsv.vhostAlias[e]||e}fetchId(t){if(t.headers.cookie){const e=this.tsv.cookieDetect.exec(t.headers.cookie);if(e&&"0"!=e[1])return e[1]}return""}retrieveSession(t){return new Promise(((e,o)=>{if(void 0===this.sessionAcc)return o("Server not ready, please wait");this.sessionAcc.get(t).then((s=>{const r=Date.now()/1e3|0;r-s._utime>this.tsv.timeout||this.tsv.timeoutActivity&&s._lastSeen&&r-s._lastSeen>this.tsv.timeoutActivity?o(`Session ${t} expired`):(this.tsv.timeoutActivity&&r-s._lastSeen>60&&(s._lastSeen=r,this.sessionAcc.update(s)),e(s))})).catch((e=>{o(`Session ${t} can't be found in store: ${e}`)}))}))}grant(t,e,o){return new Promise(((s,r)=>{const i=this.resolveAlias(t);if(!this.tsv.defaultCondition[i])return r(`No configuration found for ${i} (or not listed in Node.js virtualHosts)`);if(this.tsv.locationRegexp[i]){let r=0;this.tsv.locationRegexp[i].forEach((n=>{if(n.test(e))return s(this.tsv.locationCondition[i][r](t,o));r++}))}this.tsv.defaultCondition[i](t,o)?s(!0):r("Unauthorized")}))}sendHeaders(t,e){const o=this.resolveAlias(t);try{let s=0;t.headers["Lm-Remote-User"]=e[this.tsv.whatToTrace];const r=this.tsv.forgeHeaders[o](e);Object.keys(r).forEach((e=>{s++,t.headers[e]=r[e],t.rawHeaders.push(e,r[e]),t.redirect||(t.headers[`Headername${s}`]=e,t.headers[`Headervalue${s}`]=r[e])}))}catch(t){return void console.error(`Headers maybe not sent: ${t}`)}}hideCookie(t){t.headers.cookie&&(t.headers.cookie=t.headers.cookie.replace(this.tsv.cookieDetect,""))}forbidden(t,e,o){o._logout?this.goToPortal(e,o._logout,"logout=1"):this.setError(e,"/",403,"Forbidden")}goToPortal(t,e,o=""){if("function"!=typeof this.tsv.portal)return void this.setError(t,e,503,"Waiting for configuration");const s=this.tsv.portal()+(e?"?url="+new Buffer.from(encodeURI(e)).toString("base64"):"")+(o?(e?"&":"?")+o:"");t.redirect?t.redirect(s):t.writeHead(401,{Location:s})}}class x extends ${constructor(t){super(t),this.tsv.lastVhostUpdate={}}grant(t,e,o){const s=this.resolveAlias(t);if(this.tsv.defaultCondition[s]&&Date.now()/1e3-this.tsv.lastVhostUpdate[s]<600)return super.grant(t,e,o);const r=t.cgiParams&&t.cgiParams.RULES_URL?t.cgiParams.RULES_URL:(this.tsv.loopBackUrl||"http://127.0.0.1")+"/rules.json";if(!/^(https?):\/\/([^/:]+)(?::(\d+))?(.*)$/.test(r))return new Promise(((t,e)=>e(`Bad loopBackUrl ${r}`)));const i={prot:RegExp.$1,host:RegExp.$2,path:RegExp.$4,port:RegExp.$3||("https"==RegExp.$1?"443":"80"),lb:!(t.cgiParams&&t.cgiParams.RULES_URL)};return new Promise(((r,n)=>{this.loadVhostConfig(t,s,i).then((()=>{this.grant(t,e,o).then((t=>{r(t)})).catch((t=>n(t)))})).catch((s=>{console.error(s),this.grant(t,e,o).then((t=>{r(t)})).catch((t=>n(t)))}))}))}loadVhostConfig(t,e,o){return new Promise(((t,s)=>{o.lb||(e=o.host),delete o.lb,o.headers={Host:e};const r=require(o.prot);delete o.prot;const i=r.request(o,(o=>{let r="";o.on("data",(t=>{r+=t})),o.on("end",(()=>{if(this.tsv.locationCondition[e]=[],this.tsv.locationProtection[e]=[],this.tsv.locationRegexp[e]=[],this.tsv.locationCount[e]=0,this.tsv.headerList[e]=[],""===r)return this.tsv.defaultCondition[e]=()=>!0,this.tsv.defaultProtection[e]=0,this.tsv.lastVhostUpdate[e]=Date.now()/1e3,t(!0);try{const o=JSON.parse(r);if(this.safe[e]=new d.default({cipher:this.tsv.cipher}),o.rules&&"object"==typeof o.rules&&(Object.keys(o.rules).forEach((t=>{const s=new String(o.rules[t]).valueOf();let r,i;[r,i]=this.conditionSub(s,this.safe[e]),"default"===t?(this.tsv.defaultCondition[e]=r,this.tsv.defaultProtection[e]=i):(this.tsv.locationCondition[e].push(r),this.tsv.locationProtection[e].push(i),this.tsv.locationRegexp[e].push(new f.default(t.replace(/\(\?#.*?\)/,""))),this.tsv.locationCount[e]++)})),this.tsv.defaultCondition[e]||(this.tsv.defaultCondition[e]=()=>!0,this.tsv.defaultProtection[e]=0)),o.headers&&"object"==typeof o.headers){const t=Object.keys(o.headers).map((t=>(this.tsv.headerList[e].push(t),`'${t}': ${this.substitute(o.headers[t])}`))).join(",");p.default.runInContext(`fg = function(session) {return {${t}}}`,this.safe[e]),this.tsv.forgeHeaders[e]=this.safe[e].fg}this.tsv.lastVhostUpdate[e]=Date.now()/1e3,t(!0)}catch(t){s("Unable to getremote config: "+t)}})),i.on("error",(t=>{s(t)})),i.end()}))}))}}class S extends ${fetchId(t){const e=t.cgiParams?t.cgiParams.HTTP_X_LLNG_TOKEN:t.headers["x-llng-token"];if(e){const o=this.tsv.cipher.decrypt(e).split(":");if(!o[2])return console.warn("Bad service token"),"";const s=Date.now()/1e3,r=parseInt(o[0]);if(r<s-30||r>s)return console.warn("Expired service token"),"";const i=this.resolveAlias(t);return o.indexOf(i)<2?(console.warn(`${i} not authorizated in token`),""):o[1]}return super.fetchId(t)}}let P;exports.class=void 0;const E={Main:$,DevOps:x,ServiceToken:S,ServiceTokenST:class extends x{fetchId(t){return S.prototype.fetchId.call(this,t)}}};exports.init=t=>new Promise(((e,o)=>{var s;t.type||(t.type="Main"),E[t.type]?(exports.class=E[t.type],P=new E[t.type](t),P.init().then((()=>e(P))).catch((t=>o(t)))):(s="@lemonldap-ng/handler-"+t.type.toLowerCase(),Promise.resolve().then((function(){return c(require(s))}))).then((o=>{exports.class=o.default,P=new exports.class(t),P.init().then((()=>e(P)))})).catch((t=>o(t)))})),exports.nginxServer=t=>{P.nginxServer(t)},exports.run=(t,e,o)=>P.run(t,e,o);
|
|
2
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/init.ts","../../../node_modules/normalize-url/index.js","../src/handlerMain.ts","../src/handlerDevOps.ts","../src/handlerServiceToken.ts","../src/index.ts","../src/handlerDevOpsST.ts"],"sourcesContent":[null,"// https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs\nconst DATA_URL_DEFAULT_MIME_TYPE = 'text/plain';\nconst DATA_URL_DEFAULT_CHARSET = 'us-ascii';\n\nconst testParameter = (name, filters) => filters.some(filter => filter instanceof RegExp ? filter.test(name) : filter === name);\n\nconst normalizeDataURL = (urlString, {stripHash}) => {\n\tconst match = /^data:(?<type>[^,]*?),(?<data>[^#]*?)(?:#(?<hash>.*))?$/.exec(urlString);\n\n\tif (!match) {\n\t\tthrow new Error(`Invalid URL: ${urlString}`);\n\t}\n\n\tlet {type, data, hash} = match.groups;\n\tconst mediaType = type.split(';');\n\thash = stripHash ? '' : hash;\n\n\tlet isBase64 = false;\n\tif (mediaType[mediaType.length - 1] === 'base64') {\n\t\tmediaType.pop();\n\t\tisBase64 = true;\n\t}\n\n\t// Lowercase MIME type\n\tconst mimeType = (mediaType.shift() || '').toLowerCase();\n\tconst attributes = mediaType\n\t\t.map(attribute => {\n\t\t\tlet [key, value = ''] = attribute.split('=').map(string => string.trim());\n\n\t\t\t// Lowercase `charset`\n\t\t\tif (key === 'charset') {\n\t\t\t\tvalue = value.toLowerCase();\n\n\t\t\t\tif (value === DATA_URL_DEFAULT_CHARSET) {\n\t\t\t\t\treturn '';\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn `${key}${value ? `=${value}` : ''}`;\n\t\t})\n\t\t.filter(Boolean);\n\n\tconst normalizedMediaType = [\n\t\t...attributes,\n\t];\n\n\tif (isBase64) {\n\t\tnormalizedMediaType.push('base64');\n\t}\n\n\tif (normalizedMediaType.length > 0 || (mimeType && mimeType !== DATA_URL_DEFAULT_MIME_TYPE)) {\n\t\tnormalizedMediaType.unshift(mimeType);\n\t}\n\n\treturn `data:${normalizedMediaType.join(';')},${isBase64 ? data.trim() : data}${hash ? `#${hash}` : ''}`;\n};\n\nexport default function normalizeUrl(urlString, options) {\n\toptions = {\n\t\tdefaultProtocol: 'http:',\n\t\tnormalizeProtocol: true,\n\t\tforceHttp: false,\n\t\tforceHttps: false,\n\t\tstripAuthentication: true,\n\t\tstripHash: false,\n\t\tstripTextFragment: true,\n\t\tstripWWW: true,\n\t\tremoveQueryParameters: [/^utm_\\w+/i],\n\t\tremoveTrailingSlash: true,\n\t\tremoveSingleSlash: true,\n\t\tremoveDirectoryIndex: false,\n\t\tsortQueryParameters: true,\n\t\t...options,\n\t};\n\n\turlString = urlString.trim();\n\n\t// Data URL\n\tif (/^data:/i.test(urlString)) {\n\t\treturn normalizeDataURL(urlString, options);\n\t}\n\n\tif (/^view-source:/i.test(urlString)) {\n\t\tthrow new Error('`view-source:` is not supported as it is a non-standard protocol');\n\t}\n\n\tconst hasRelativeProtocol = urlString.startsWith('//');\n\tconst isRelativeUrl = !hasRelativeProtocol && /^\\.*\\//.test(urlString);\n\n\t// Prepend protocol\n\tif (!isRelativeUrl) {\n\t\turlString = urlString.replace(/^(?!(?:\\w+:)?\\/\\/)|^\\/\\//, options.defaultProtocol);\n\t}\n\n\tconst urlObject = new URL(urlString);\n\n\tif (options.forceHttp && options.forceHttps) {\n\t\tthrow new Error('The `forceHttp` and `forceHttps` options cannot be used together');\n\t}\n\n\tif (options.forceHttp && urlObject.protocol === 'https:') {\n\t\turlObject.protocol = 'http:';\n\t}\n\n\tif (options.forceHttps && urlObject.protocol === 'http:') {\n\t\turlObject.protocol = 'https:';\n\t}\n\n\t// Remove auth\n\tif (options.stripAuthentication) {\n\t\turlObject.username = '';\n\t\turlObject.password = '';\n\t}\n\n\t// Remove hash\n\tif (options.stripHash) {\n\t\turlObject.hash = '';\n\t} else if (options.stripTextFragment) {\n\t\turlObject.hash = urlObject.hash.replace(/#?:~:text.*?$/i, '');\n\t}\n\n\t// Remove duplicate slashes if not preceded by a protocol\n\t// NOTE: This could be implemented using a single negative lookbehind\n\t// regex, but we avoid that to maintain compatibility with older js engines\n\t// which do not have support for that feature.\n\tif (urlObject.pathname) {\n\t\t// TODO: Replace everything below with `urlObject.pathname = urlObject.pathname.replace(/(?<!\\b[a-z][a-z\\d+\\-.]{1,50}:)\\/{2,}/g, '/');` when Safari supports negative lookbehind.\n\n\t\t// Split the string by occurrences of this protocol regex, and perform\n\t\t// duplicate-slash replacement on the strings between those occurrences\n\t\t// (if any).\n\t\tconst protocolRegex = /\\b[a-z][a-z\\d+\\-.]{1,50}:\\/\\//g;\n\n\t\tlet lastIndex = 0;\n\t\tlet result = '';\n\t\tfor (;;) {\n\t\t\tconst match = protocolRegex.exec(urlObject.pathname);\n\t\t\tif (!match) {\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tconst protocol = match[0];\n\t\t\tconst protocolAtIndex = match.index;\n\t\t\tconst intermediate = urlObject.pathname.slice(lastIndex, protocolAtIndex);\n\n\t\t\tresult += intermediate.replace(/\\/{2,}/g, '/');\n\t\t\tresult += protocol;\n\t\t\tlastIndex = protocolAtIndex + protocol.length;\n\t\t}\n\n\t\tconst remnant = urlObject.pathname.slice(lastIndex, urlObject.pathname.length);\n\t\tresult += remnant.replace(/\\/{2,}/g, '/');\n\n\t\turlObject.pathname = result;\n\t}\n\n\t// Decode URI octets\n\tif (urlObject.pathname) {\n\t\ttry {\n\t\t\turlObject.pathname = decodeURI(urlObject.pathname);\n\t\t} catch {}\n\t}\n\n\t// Remove directory index\n\tif (options.removeDirectoryIndex === true) {\n\t\toptions.removeDirectoryIndex = [/^index\\.[a-z]+$/];\n\t}\n\n\tif (Array.isArray(options.removeDirectoryIndex) && options.removeDirectoryIndex.length > 0) {\n\t\tlet pathComponents = urlObject.pathname.split('/');\n\t\tconst lastComponent = pathComponents[pathComponents.length - 1];\n\n\t\tif (testParameter(lastComponent, options.removeDirectoryIndex)) {\n\t\t\tpathComponents = pathComponents.slice(0, -1);\n\t\t\turlObject.pathname = pathComponents.slice(1).join('/') + '/';\n\t\t}\n\t}\n\n\tif (urlObject.hostname) {\n\t\t// Remove trailing dot\n\t\turlObject.hostname = urlObject.hostname.replace(/\\.$/, '');\n\n\t\t// Remove `www.`\n\t\tif (options.stripWWW && /^www\\.(?!www\\.)[a-z\\-\\d]{1,63}\\.[a-z.\\-\\d]{2,63}$/.test(urlObject.hostname)) {\n\t\t\t// Each label should be max 63 at length (min: 1).\n\t\t\t// Source: https://en.wikipedia.org/wiki/Hostname#Restrictions_on_valid_host_names\n\t\t\t// Each TLD should be up to 63 characters long (min: 2).\n\t\t\t// It is technically possible to have a single character TLD, but none currently exist.\n\t\t\turlObject.hostname = urlObject.hostname.replace(/^www\\./, '');\n\t\t}\n\t}\n\n\t// Remove query unwanted parameters\n\tif (Array.isArray(options.removeQueryParameters)) {\n\t\t// eslint-disable-next-line unicorn/no-useless-spread -- We are intentionally spreading to get a copy.\n\t\tfor (const key of [...urlObject.searchParams.keys()]) {\n\t\t\tif (testParameter(key, options.removeQueryParameters)) {\n\t\t\t\turlObject.searchParams.delete(key);\n\t\t\t}\n\t\t}\n\t}\n\n\tif (options.removeQueryParameters === true) {\n\t\turlObject.search = '';\n\t}\n\n\t// Sort query parameters\n\tif (options.sortQueryParameters) {\n\t\turlObject.searchParams.sort();\n\n\t\t// Calling `.sort()` encodes the search parameters, so we need to decode them again.\n\t\ttry {\n\t\t\turlObject.search = decodeURIComponent(urlObject.search);\n\t\t} catch {}\n\t}\n\n\tif (options.removeTrailingSlash) {\n\t\turlObject.pathname = urlObject.pathname.replace(/\\/$/, '');\n\t}\n\n\tconst oldUrlString = urlString;\n\n\t// Take advantage of many of the Node `url` normalizations\n\turlString = urlObject.toString();\n\n\tif (!options.removeSingleSlash && urlObject.pathname === '/' && !oldUrlString.endsWith('/') && urlObject.hash === '') {\n\t\turlString = urlString.replace(/\\/$/, '');\n\t}\n\n\t// Remove ending `/` unless removeSingleSlash is false\n\tif ((options.removeTrailingSlash || urlObject.pathname === '/') && urlObject.hash === '' && options.removeSingleSlash) {\n\t\turlString = urlString.replace(/\\/$/, '');\n\t}\n\n\t// Restore relative protocol, if applicable\n\tif (hasRelativeProtocol && !options.normalizeProtocol) {\n\t\turlString = urlString.replace(/^http:\\/\\//, '//');\n\t}\n\n\t// Remove http/https\n\tif (options.stripProtocol) {\n\t\turlString = urlString.replace(/^(?:https?:)?\\/\\//, '');\n\t}\n\n\treturn urlString;\n}\n",null,null,null,null,null],"names":["condMatch","RE2","sid","requiredFields","testParameter","name","filters","some","filter","RegExp","test","normalizeUrl","urlString","options","defaultProtocol","normalizeProtocol","forceHttp","forceHttps","stripAuthentication","stripHash","stripTextFragment","stripWWW","removeQueryParameters","removeTrailingSlash","removeSingleSlash","removeDirectoryIndex","sortQueryParameters","trim","match","exec","Error","type","data","hash","groups","mediaType","split","isBase64","length","pop","mimeType","shift","toLowerCase","normalizedMediaType","map","attribute","key","value","string","Boolean","push","unshift","join","normalizeDataURL","hasRelativeProtocol","startsWith","replace","urlObject","URL","protocol","username","password","pathname","protocolRegex","lastIndex","result","protocolAtIndex","index","slice","decodeURI","Array","isArray","pathComponents","lastComponent","hostname","searchParams","keys","delete","search","sort","decodeURIComponent","oldUrlString","toString","endsWith","stripProtocol","LemonldapNGHandler","constructor","args","this","safe","tsv","defaultCondition","defaultProtection","forgeHeaders","headerList","https","locationCondition","locationCount","locationProtection","locationRegexp","maintenance","port","portal","vhostAlias","localConf","configStorage","localStorage","localStorageOptions","confAcc","Conf","getLocalConf","forEach","iniSection","Object","k","undefined","nodeVhosts","vhostList","reload","Promise","resolve","reject","ready","then","getConf","conf","_","vhostOptions","s","charAt","toUpperCase","vhost","val","sessionAcc","Session","storageModule","storageModuleOptions","e","locationRules","indexOf","SafeLib","rules","url","cond","prot","conditionSub","exportedHeaders","headers","sub","substitute","vm","runInContext","fg","aliases","alias","cookieDetect","cookieName","Logger","logger","userLogger","catch","console","error","ctx","OK","res","session","_logout","expr","init","run","req","next","host","setError","uri","isUnprotected","id","fetchId","retrieveSession","user","whatToTrace","debug","grant","grantResult","sendHeaders","hideCookie","info","forbidden","notice","goToPortal","selfUri","nginxServer","fcgiOpt","mode","ip","require","http","createServer","writeHead","listen","code","txt","useRedirectOnError","redirect","Location","status","send","resolveAlias","i","cookie","get","now","Date","_utime","timeout","timeoutActivity","_lastSeen","update","regex","rawHeaders","urlc","Buffer","from","encodeURI","LemonldapNGHandlerDevOps","super","lastVhostUpdate","base","cgiParams","RULES_URL","loopBackUrl","lvOpts","$1","$2","path","$4","$3","lb","loadVhostConfig","err","Host","request","resp","str","on","chunk","vhostConfig","JSON","parse","cipher","rule","String","valueOf","end","LemonldapNGHandlerServiceToken","token","HTTP_X_LLNG_TOKEN","tokenElement","decrypt","warn","tokenTime","parseInt","currentHandler","currentClass","knownHandlers","Main","DevOps","ServiceToken","ServiceTokenST","prototype","call","t","_interopNamespace","mod","default"],"m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