@warren-bank/hls-proxy 3.6.6 → 3.6.8

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 CHANGED
@@ -160,6 +160,7 @@ options:
160
160
  --acl-ip <ip_address_list>
161
161
  --acl-pass <password_list>
162
162
  --block-req-hostname <hostname_list>
163
+ --allow-private-req-hostnames
163
164
  --http-proxy <http[s]://[user:pass@]hostname:port>
164
165
  --tls-cert <filepath>
165
166
  --tls-key <filepath>
@@ -312,10 +313,14 @@ options:
312
313
  )
313
314
 
314
315
  add_request_interval(
315
- (1000 * 60 * 5), // run timer at 5 minute interval to refresh cookies
316
- (request) => {
316
+ (1000 * 60 * 5), // run timer at 5 minute intervals to refresh cookies
317
+ (request, timer_id) => {
317
318
  request('https://example.com/heart-beat')
318
- }
319
+
320
+ if (globalThis.someCondition)
321
+ clearInterval(timer_id)
322
+ },
323
+ (1000 * 60 * 60 * 1) // automatically stop after a max duration of 1 hour
319
324
  )
320
325
 
321
326
  }
@@ -396,7 +401,30 @@ options:
396
401
  * _--acl-pass_ restricts proxy server access to requests that include a `password` querystring parameter having a value in whitelist
397
402
  * ex: `"1111,2222,3333,4444,5555"`
398
403
  * _--block-req-hostname_ blocks proxy server requests to hostnames in blacklist
399
- * ex: `"localhost,127.0.0.1"`
404
+ * the value is a comma-separated list that is normalized to lowercase
405
+ * the value of each item in the list can use any of the following formats:
406
+ - includes substring
407
+ * value begins and ends with `*` character
408
+ * ex: `"*foo*"`<br>blacklists all hostnames that include the substring: `foo`
409
+ - starts with substring
410
+ * value ends with `*` character
411
+ * ex: `"www.*"`<br>blacklists all hostnames that start with the substring: `www.`
412
+ - ends with substring
413
+ * value starts with `*` character
414
+ * ex: `"*.foo.com"`<br>blacklists all hostnames that end with the substring: `.foo.com`
415
+ - matches regex pattern
416
+ * value begins and ends with `/` character
417
+ * ex: `"/^www\..+\.com$/"`<br>blacklists all hostnames that both start with the substring: `www.`, and end with the substring: `.com`
418
+ - equals exact string
419
+ * all other values
420
+ * ex: `"localhost,127.0.0.1"`
421
+ * _--allow-private-req-hostnames_ is a flag to prevent the automatic addition of the following values to the _--block-req-hostname_ blacklist:
422
+ ```text
423
+ localhost,
424
+ ::1,
425
+ /^(0\.|10\.|127\.|169\.254\.|192\.168\.|172\.(1[6-9]|2\d|3[01])\.)/,
426
+ /^(fe80:|fc|fd|::ffff:(0\.|10\.|127\.|169\.254\.|192\.168\.|172\.(1[6-9]|2\d|3[01])\.))/
427
+ ```
400
428
  * --http-proxy enables all outbound HTTP and HTTPS requests from HLS-Proxy to be tunnelled through an additional external web proxy server
401
429
  * SOCKS proxies are not supported
402
430
  * ex: `http://myusername:mypassword@myproxy.example.com:1234`
@@ -31,6 +31,7 @@ options:
31
31
  --acl-ip <ip_address_list>
32
32
  --acl-pass <password_list>
33
33
  --block-req-hostname <hostname_list>
34
+ --allow-private-req-hostnames
34
35
  --http-proxy <http[s]://[user:pass@]hostname:port>
35
36
  --tls-cert <filepath>
36
37
  --tls-key <filepath>
@@ -39,6 +39,7 @@ const argv_flags = {
39
39
  "--acl-ip": {},
40
40
  "--acl-pass": {},
41
41
  "--block-req-hostname": {},
42
+ "--allow-private-req-hostnames": {bool: true},
42
43
  "--http-proxy": {},
43
44
 
44
45
  "--tls-cert": {file: "path-exists"},
@@ -179,7 +180,99 @@ if (argv_vals["--acl-pass"]) {
179
180
  }
180
181
 
181
182
  if (argv_vals["--block-req-hostname"]) {
182
- argv_vals["--block-req-hostname"] = argv_vals["--block-req-hostname"].trim().toLowerCase().split(/\s*,\s*/g)
183
+ const blacklist = argv_vals["--block-req-hostname"].trim().toLowerCase().split(/\s*,\s*/g)
184
+
185
+ argv_vals["--block-req-hostname"] = {
186
+ includes: [],
187
+ startsWith: [],
188
+ endsWith: [],
189
+ match: [],
190
+ equals: []
191
+ }
192
+
193
+ for (const item of blacklist) {
194
+ if (!item) continue
195
+
196
+ const globStart = item.startsWith('*')
197
+ const globEnd = item.endsWith('*')
198
+ const regexStart = item.startsWith('/')
199
+ const regexEnd = item.endsWith('/')
200
+
201
+ if (globStart && globEnd) {
202
+ if (item.length > 2) {
203
+ argv_vals["--block-req-hostname"].includes.push(
204
+ item.substring(1, item.length - 1)
205
+ )
206
+ }
207
+ continue
208
+ }
209
+ if (globEnd) {
210
+ if (item.length > 1) {
211
+ argv_vals["--block-req-hostname"].startsWith.push(
212
+ item.substring(0, item.length - 1)
213
+ )
214
+ }
215
+ continue
216
+ }
217
+ if (globStart) {
218
+ if (item.length > 1) {
219
+ argv_vals["--block-req-hostname"].endsWith.push(
220
+ item.substring(1, item.length)
221
+ )
222
+ }
223
+ continue
224
+ }
225
+ if (regexStart && regexEnd) {
226
+ if (item.length > 2) {
227
+ try {
228
+ const regex = new RegExp(item.substring(1, item.length - 1))
229
+
230
+ argv_vals["--block-req-hostname"].match.push(
231
+ regex
232
+ )
233
+ }
234
+ catch(ignored) {}
235
+ }
236
+ continue
237
+ }
238
+ else {
239
+ argv_vals["--block-req-hostname"].equals.push(
240
+ item
241
+ )
242
+ }
243
+ }
244
+ }
245
+
246
+ if (!argv_vals["--allow-private-req-hostnames"]) {
247
+ if (!argv_vals["--block-req-hostname"]) {
248
+ argv_vals["--block-req-hostname"] = {
249
+ includes: [],
250
+ startsWith: [],
251
+ endsWith: [],
252
+ match: [],
253
+ equals: []
254
+ }
255
+ }
256
+ argv_vals["--block-req-hostname"].match.push(
257
+ /^(0\.|10\.|127\.|169\.254\.|192\.168\.|172\.(1[6-9]|2\d|3[01])\.)/,
258
+ /^(fe80:|fc|fd|::ffff:(0\.|10\.|127\.|169\.254\.|192\.168\.|172\.(1[6-9]|2\d|3[01])\.))/
259
+ )
260
+ argv_vals["--block-req-hostname"].equals.push(
261
+ 'localhost',
262
+ '::1'
263
+ )
264
+ }
265
+
266
+ if (argv_vals["--block-req-hostname"]) {
267
+ if (
268
+ !argv_vals["--block-req-hostname"].includes.length &&
269
+ !argv_vals["--block-req-hostname"].startsWith.length &&
270
+ !argv_vals["--block-req-hostname"].endsWith.length &&
271
+ !argv_vals["--block-req-hostname"].match.length &&
272
+ !argv_vals["--block-req-hostname"].equals.length
273
+ ) {
274
+ argv_vals["--block-req-hostname"] = null
275
+ }
183
276
  }
184
277
 
185
278
  if (argv_vals["--http-proxy"]) {
@@ -23,13 +23,27 @@ const initialize_timers = function(params) {
23
23
  return request(options, POST_data, config)
24
24
  }
25
25
 
26
- const add_request_interval = function(delay_ms, callback) {
26
+ const add_request_interval = function(delay_ms, callback, max_duration_ms) {
27
27
  if (!delay_ms || (typeof delay_ms !== 'number') || isNaN(delay_ms) || (delay_ms < 0)) {
28
28
  callback(request_wrapper)
29
29
  }
30
30
  else {
31
- setInterval(
32
- callback.bind(null, request_wrapper),
31
+ if (max_duration_ms && ((typeof max_duration_ms !== 'number') || (max_duration_ms < 0)))
32
+ max_duration_ms = 0
33
+
34
+ const start_time_ms = max_duration_ms
35
+ ? Date.now()
36
+ : null
37
+
38
+ const callback_wrapper = () => {
39
+ if (max_duration_ms && ((Date.now() - start_time_ms) > max_duration_ms))
40
+ clearInterval(timer_id)
41
+ else
42
+ callback(request_wrapper, timer_id)
43
+ }
44
+
45
+ const timer_id = setInterval(
46
+ callback_wrapper,
33
47
  delay_ms
34
48
  )
35
49
  }
@@ -201,7 +201,7 @@ const block_request_options = function(params, request_options) {
201
201
  const {block_req_hostname} = params
202
202
 
203
203
  // short circuit
204
- if (!block_req_hostname || !Array.isArray(block_req_hostname) || !block_req_hostname.length || !request_options)
204
+ if (!block_req_hostname || !request_options)
205
205
  return false
206
206
 
207
207
  // special case: url
@@ -212,7 +212,20 @@ const block_request_options = function(params, request_options) {
212
212
  if (!request_options.hostname || (typeof request_options.hostname !== 'string'))
213
213
  return false
214
214
 
215
- return (block_req_hostname.indexOf(request_options.hostname.toLowerCase()) >= 0)
215
+ const hostname = request_options.hostname.toLowerCase()
216
+ for (const blacklist_item of block_req_hostname.includes) {
217
+ if (hostname.includes(blacklist_item)) return true
218
+ }
219
+ for (const blacklist_item of block_req_hostname.startsWith) {
220
+ if (hostname.startsWith(blacklist_item)) return true
221
+ }
222
+ for (const blacklist_item of block_req_hostname.endsWith) {
223
+ if (hostname.endsWith(blacklist_item)) return true
224
+ }
225
+ for (const blacklist_item of block_req_hostname.match) {
226
+ if (blacklist_item.test(hostname)) return true
227
+ }
228
+ return (block_req_hostname.equals.indexOf(hostname) >= 0)
216
229
  }
217
230
 
218
231
  const should_prefetch_url = function(params, url, url_type) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@warren-bank/hls-proxy",
3
3
  "description": "Node.js server to proxy HLS video streams",
4
- "version": "3.6.6",
4
+ "version": "3.6.8",
5
5
  "scripts": {
6
6
  "start": "node hls-proxy/bin/hlsd.js",
7
7
  "sudo": "sudo node hls-proxy/bin/hlsd.js"