@warren-bank/hls-proxy 3.6.5 → 3.6.7
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 +10 -3
- package/hls-proxy/bin/hlsd.js +1 -0
- package/hls-proxy/bin/lib/help.js +1 -0
- package/hls-proxy/bin/lib/process_argv.js +5 -0
- package/hls-proxy/proxy.js +15 -8
- package/hls-proxy/timers.js +17 -3
- package/hls-proxy/utils.js +19 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -159,6 +159,7 @@ options:
|
|
|
159
159
|
-v <number>
|
|
160
160
|
--acl-ip <ip_address_list>
|
|
161
161
|
--acl-pass <password_list>
|
|
162
|
+
--block-req-hostname <hostname_list>
|
|
162
163
|
--http-proxy <http[s]://[user:pass@]hostname:port>
|
|
163
164
|
--tls-cert <filepath>
|
|
164
165
|
--tls-key <filepath>
|
|
@@ -311,10 +312,14 @@ options:
|
|
|
311
312
|
)
|
|
312
313
|
|
|
313
314
|
add_request_interval(
|
|
314
|
-
(1000 * 60 * 5), // run timer at 5 minute
|
|
315
|
-
(request) => {
|
|
315
|
+
(1000 * 60 * 5), // run timer at 5 minute intervals to refresh cookies
|
|
316
|
+
(request, timer_id) => {
|
|
316
317
|
request('https://example.com/heart-beat')
|
|
317
|
-
|
|
318
|
+
|
|
319
|
+
if (globalThis.someCondition)
|
|
320
|
+
clearInterval(timer_id)
|
|
321
|
+
},
|
|
322
|
+
(1000 * 60 * 60 * 1) // automatically stop after a max duration of 1 hour
|
|
318
323
|
)
|
|
319
324
|
|
|
320
325
|
}
|
|
@@ -394,6 +399,8 @@ options:
|
|
|
394
399
|
* ex: `"192.168.1.100,192.168.1.101,192.168.1.102"`
|
|
395
400
|
* _--acl-pass_ restricts proxy server access to requests that include a `password` querystring parameter having a value in whitelist
|
|
396
401
|
* ex: `"1111,2222,3333,4444,5555"`
|
|
402
|
+
* _--block-req-hostname_ blocks proxy server requests to hostnames in blacklist
|
|
403
|
+
* ex: `"localhost,127.0.0.1"`
|
|
397
404
|
* --http-proxy enables all outbound HTTP and HTTPS requests from HLS-Proxy to be tunnelled through an additional external web proxy server
|
|
398
405
|
* SOCKS proxies are not supported
|
|
399
406
|
* ex: `http://myusername:mypassword@myproxy.example.com:1234`
|
package/hls-proxy/bin/hlsd.js
CHANGED
|
@@ -47,6 +47,7 @@ const middleware = require('../proxy')({
|
|
|
47
47
|
debug_level: argv_vals["-v"],
|
|
48
48
|
acl_ip: argv_vals["--acl-ip"],
|
|
49
49
|
acl_pass: argv_vals["--acl-pass"],
|
|
50
|
+
block_req_hostname: argv_vals["--block-req-hostname"],
|
|
50
51
|
http_proxy: argv_vals["--http-proxy"],
|
|
51
52
|
manifest_extension: argv_vals["--manifest-extension"],
|
|
52
53
|
segment_extension: argv_vals["--segment-extension"]
|
|
@@ -38,6 +38,7 @@ const argv_flags = {
|
|
|
38
38
|
"-v": {num: "int"},
|
|
39
39
|
"--acl-ip": {},
|
|
40
40
|
"--acl-pass": {},
|
|
41
|
+
"--block-req-hostname": {},
|
|
41
42
|
"--http-proxy": {},
|
|
42
43
|
|
|
43
44
|
"--tls-cert": {file: "path-exists"},
|
|
@@ -177,6 +178,10 @@ if (argv_vals["--acl-pass"]) {
|
|
|
177
178
|
argv_vals["--acl-pass"] = argv_vals["--acl-pass"].trim().split(/\s*,\s*/g)
|
|
178
179
|
}
|
|
179
180
|
|
|
181
|
+
if (argv_vals["--block-req-hostname"]) {
|
|
182
|
+
argv_vals["--block-req-hostname"] = argv_vals["--block-req-hostname"].trim().toLowerCase().split(/\s*,\s*/g)
|
|
183
|
+
}
|
|
184
|
+
|
|
180
185
|
if (argv_vals["--http-proxy"]) {
|
|
181
186
|
const proxy_options = {
|
|
182
187
|
keepAlive: true,
|
package/hls-proxy/proxy.js
CHANGED
|
@@ -6,17 +6,17 @@ const timers = require('./timers')
|
|
|
6
6
|
const utils = require('./utils')
|
|
7
7
|
|
|
8
8
|
const get_middleware = function(params) {
|
|
9
|
-
const {cache_segments} = params
|
|
10
|
-
let {acl_ip} = params
|
|
9
|
+
const {acl_ip, cache_segments} = params
|
|
11
10
|
|
|
12
11
|
const segment_cache = require('./segment_cache')(params)
|
|
13
12
|
const {get_segment, add_listener} = segment_cache
|
|
14
13
|
|
|
15
|
-
const is_acl_pass_allowed
|
|
16
|
-
const debug
|
|
17
|
-
const parse_req_url
|
|
18
|
-
const get_request_options
|
|
19
|
-
const
|
|
14
|
+
const is_acl_pass_allowed = acl_pass.is_allowed.bind(null, params)
|
|
15
|
+
const debug = utils.debug.bind(null, params)
|
|
16
|
+
const parse_req_url = utils.parse_req_url.bind(null, params)
|
|
17
|
+
const get_request_options = utils.get_request_options.bind(null, params)
|
|
18
|
+
const block_request_options = utils.block_request_options.bind(null, params)
|
|
19
|
+
const modify_m3u8_content = parser.modify_m3u8_content.bind(null, params, segment_cache)
|
|
20
20
|
|
|
21
21
|
const middleware = {}
|
|
22
22
|
|
|
@@ -57,6 +57,14 @@ const get_middleware = function(params) {
|
|
|
57
57
|
|
|
58
58
|
const qs_password = acl_pass.get_decoded_qs_password(req)
|
|
59
59
|
const is_m3u8 = (url_type === 'm3u8')
|
|
60
|
+
const options = get_request_options(url, is_m3u8, referer_url, querystring_req_headers, req.headers)
|
|
61
|
+
|
|
62
|
+
if (block_request_options(options)) {
|
|
63
|
+
res.writeHead(401)
|
|
64
|
+
res.end()
|
|
65
|
+
debug(2, 'request blocked by hostname blacklist:', url)
|
|
66
|
+
return
|
|
67
|
+
}
|
|
60
68
|
|
|
61
69
|
const send_cache_segment = function(segment, type) {
|
|
62
70
|
if (!type)
|
|
@@ -79,7 +87,6 @@ const get_middleware = function(params) {
|
|
|
79
87
|
}
|
|
80
88
|
}
|
|
81
89
|
|
|
82
|
-
const options = get_request_options(url, is_m3u8, referer_url, querystring_req_headers, req.headers)
|
|
83
90
|
debug(1, 'proxying:', url)
|
|
84
91
|
debug(3, 'm3u8:', (is_m3u8 ? 'true' : 'false'))
|
|
85
92
|
|
package/hls-proxy/timers.js
CHANGED
|
@@ -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
|
-
|
|
32
|
-
|
|
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
|
}
|
package/hls-proxy/utils.js
CHANGED
|
@@ -197,6 +197,24 @@ const get_request_options = function(params, url, is_m3u8, referer_url, querystr
|
|
|
197
197
|
return request_options
|
|
198
198
|
}
|
|
199
199
|
|
|
200
|
+
const block_request_options = function(params, request_options) {
|
|
201
|
+
const {block_req_hostname} = params
|
|
202
|
+
|
|
203
|
+
// short circuit
|
|
204
|
+
if (!block_req_hostname || !Array.isArray(block_req_hostname) || !block_req_hostname.length || !request_options)
|
|
205
|
+
return false
|
|
206
|
+
|
|
207
|
+
// special case: url
|
|
208
|
+
if (typeof request_options === 'string')
|
|
209
|
+
request_options = parse_url(request_options)
|
|
210
|
+
|
|
211
|
+
// sanity check
|
|
212
|
+
if (!request_options.hostname || (typeof request_options.hostname !== 'string'))
|
|
213
|
+
return false
|
|
214
|
+
|
|
215
|
+
return (block_req_hostname.indexOf(request_options.hostname.toLowerCase()) >= 0)
|
|
216
|
+
}
|
|
217
|
+
|
|
200
218
|
const should_prefetch_url = function(params, url, url_type) {
|
|
201
219
|
const {hooks, cache_segments} = params
|
|
202
220
|
|
|
@@ -226,5 +244,6 @@ module.exports = {
|
|
|
226
244
|
debug,
|
|
227
245
|
normalize_req_headers,
|
|
228
246
|
get_request_options,
|
|
247
|
+
block_request_options,
|
|
229
248
|
should_prefetch_url
|
|
230
249
|
}
|
package/package.json
CHANGED