@@ -340,13 +340,30 @@ def _create_firefox_profile(
340
340
"datareporting.policy.dataSubmissionPolicyAccepted" , False )
341
341
profile .set_preference ("toolkit.telemetry.unified" , False )
342
342
if proxy_string :
343
- proxy_server = proxy_string .split (':' )[0 ]
344
- proxy_port = proxy_string .split (':' )[1 ]
343
+ socks_proxy = False
344
+ socks_ver = 0
345
+ chunks = proxy_string .split (':' )
346
+ if len (chunks ) == 3 and (
347
+ chunks [0 ] == "socks4" or chunks [0 ] == "socks5" ):
348
+ socks_proxy = True
349
+ socks_ver = int (chunks [0 ][5 ])
350
+ if chunks [1 ].startswith ("//" ) and len (chunks [1 ]) > 2 :
351
+ chunks [1 ] = chunks [1 ][2 :]
352
+ proxy_server = chunks [1 ]
353
+ proxy_port = chunks [2 ]
354
+ else :
355
+ proxy_server = proxy_string .split (':' )[0 ]
356
+ proxy_port = proxy_string .split (':' )[1 ]
345
357
profile .set_preference ("network.proxy.type" , 1 )
346
- profile .set_preference ("network.proxy.http" , proxy_server )
347
- profile .set_preference ("network.proxy.http_port" , int (proxy_port ))
348
- profile .set_preference ("network.proxy.ssl" , proxy_server )
349
- profile .set_preference ("network.proxy.ssl_port" , int (proxy_port ))
358
+ if socks_proxy :
359
+ profile .set_preference ('network.proxy.socks' , proxy_server )
360
+ profile .set_preference ('network.proxy.socks_port' , int (proxy_port ))
361
+ profile .set_preference ('network.proxy.socks_version' , socks_ver )
362
+ else :
363
+ profile .set_preference ("network.proxy.http" , proxy_server )
364
+ profile .set_preference ("network.proxy.http_port" , int (proxy_port ))
365
+ profile .set_preference ("network.proxy.ssl" , proxy_server )
366
+ profile .set_preference ("network.proxy.ssl_port" , int (proxy_port ))
350
367
if user_agent :
351
368
profile .set_preference ("general.useragent.override" , user_agent )
352
369
profile .set_preference (
@@ -406,12 +423,25 @@ def validate_proxy_string(proxy_string):
406
423
elif proxy_string .startswith ('https://' ):
407
424
proxy_string = proxy_string .split ('https://' )[1 ]
408
425
elif '://' in proxy_string :
409
- proxy_string = proxy_string .split ('://' )[1 ]
426
+ if not proxy_string .startswith ('socks4://' ) and not (
427
+ proxy_string .startswith ('socks5://' )):
428
+ proxy_string = proxy_string .split ('://' )[1 ]
410
429
chunks = proxy_string .split (':' )
411
430
if len (chunks ) == 2 :
412
431
if re .match (r'^\d+$' , chunks [1 ]):
413
432
if page_utils .is_valid_url ('http://' + proxy_string ):
414
433
valid = True
434
+ elif len (chunks ) == 3 :
435
+ if re .match (r'^\d+$' , chunks [2 ]):
436
+ if page_utils .is_valid_url ('http:' + ':' .join (chunks [1 :])):
437
+ if chunks [0 ] == "http" :
438
+ valid = True
439
+ elif chunks [0 ] == "https" :
440
+ valid = True
441
+ elif chunks [0 ] == "socks4" :
442
+ valid = True
443
+ elif chunks [0 ] == "socks5" :
444
+ valid = True
415
445
else :
416
446
proxy_string = val_ip .group ()
417
447
valid = True
0 commit comments