File tree 6 files changed +66
-17
lines changed
6 files changed +66
-17
lines changed Original file line number Diff line number Diff line change 1
1
import time
2
-
2
+ import yaml
3
3
import re
4
4
import requests
5
5
6
6
7
7
class BlocksitesUpdater (object ):
8
8
9
- regex_rules = r'http.?://([0-9A-Za-z.]*)/'
9
+ regex_rules = r'http.?://\*? ([0-9A-Za-z.\- ]*)/'
10
10
def __init__ (self ,url ):
11
- self .url = url
12
- pass
11
+ self .url = url .format (time = int (time .time ()* 100 ))
12
+ self .get ()
13
+ self .parse_domain_list ()
13
14
14
15
def get (self ):
15
16
resp = requests .get (self .url )
16
17
self .data = [i .strip ('"' ) for i in resp .text .split (',' )]
18
+ return self .data
17
19
18
20
19
21
20
22
def parse_domain_list (self ):
21
23
domain = set ()
22
24
for data in self .data :
23
25
result = re .search (self .regex_rules , data )
24
- domain .add (result .group (1 ))
25
- return domain
26
+ try :
27
+ domain .add (result .group (1 ).strip ("." ))
28
+ except :
29
+ pass
30
+ self .domain = domain
31
+
26
32
27
33
28
34
Original file line number Diff line number Diff line change 4
4
from jinja2 import FileSystemLoader
5
5
import os
6
6
7
+ from components .blocksites_updater import BlocksitesUpdater
8
+
9
+
7
10
class PacGenerator (object ):
8
- def __init__ (self ,config ):
11
+ def __init__ (self ,config , block_list = None ):
9
12
self .env = Environment (loader = FileSystemLoader ('template' ))
10
13
def yaml_loader (file ):
11
14
with open (file ) as f :
12
15
return yaml .load (f )
13
16
self .config = yaml_loader (config )
17
+ self .block_list = block_list
14
18
15
19
16
20
def get_ip (self ):
@@ -25,15 +29,20 @@ def get_ip(self):
25
29
26
30
def build_pac (self ):
27
31
info = {}
28
- info ['proxy_domain' ]= self .config ['dns_domain' ]
32
+ if self .block_list :
33
+ info ['block_urls' ]= self .block_list
34
+ else :
35
+ info ['block_urls' ]= self .config ['dns_domain' ]
36
+ info ['direct_urls' ]= self .config ['direct_urls' ]
29
37
try :
30
38
info ['proxy_ip' ]= os .environ ["IPADDR" ]
31
39
except :
32
40
info ['proxy_ip' ]= self .get_ip ()
33
41
info ['proxy_port' ]= self .config .get ("proxy_port" )
34
- template = self .env .get_template ("proxy .pac" )
42
+ template = self .env .get_template ("new_proxy .pac" )
35
43
self .file_writer (template .render (info = info ))
36
44
37
45
def file_writer (self ,data ):
38
46
with open ("pac/proxy.pac" ,'w+' ) as file :
39
- file .write (data )
47
+ file .write (data )
48
+
Original file line number Diff line number Diff line change @@ -28,7 +28,11 @@ def yaml_loader(file):
28
28
else :
29
29
config = yaml_loader ('config.yaml' )
30
30
check_url = config .get ('validate_url' )
31
- speedtest_url = config .get ('speedtest_url' )
31
+ https_enabled = config .get ('https_enabled' )
32
+ if https_enabled :
33
+ speedtest_url = config .get ('speedtest_url_https' )
34
+ else :
35
+ speedtest_url = config .get ('speedtest_url' )
32
36
timeout = config .get ('timeout' )
33
37
checker_timeout = config .get ('checker_timeout' )
34
38
speedtest_times = config .get ("speedtest_times" )
Original file line number Diff line number Diff line change @@ -40,10 +40,18 @@ validate_url: "http://ipservice.163.com/isFromMainland"
40
40
speedtest_url : " http://music.163.com/test"
41
41
speedtest_url_https : " https://music.163.com"
42
42
43
- https_enabled : true,
43
+ https_enabled : true
44
44
45
45
# HTTPS Related options
46
46
47
+
48
+ # Blocksites updater
49
+
50
+ enable_blocksites_updater : true
51
+ updater_url : " "
52
+
53
+ # Blocksites updater
54
+
47
55
speedtest_times : 3
48
56
timeout : 5
49
57
checker_timeout : 3
@@ -64,4 +72,14 @@ upstream_dns : "8.8.8.8"
64
72
65
73
# Disable normal HTTP Proxy
66
74
# this is useful if u make a public server on the internet and avoid them to use it as a public HTTP Proxy. (Need to use with PAC or DNS)
67
- disable_proxy : false
75
+ disable_proxy : false
76
+
77
+
78
+ # Auto Generate Infos.
79
+
80
+ direct_urls :
81
+ - " *inter.iqiyi.com*"
82
+ - " *file.xiami.com*"
83
+ - " *pcvideoaliyun.titan.mgtv.com*"
84
+ - " *vhotlx.video.qq.com*"
85
+ - " *newflv.sohu.ccgslb.net*"
Original file line number Diff line number Diff line change 11
11
import yaml
12
12
13
13
from async_proxy import handle_client
14
+ from components .blocksites_updater import BlocksitesUpdater
14
15
from components .pac_generator import PacGenerator
15
16
from components .proxy_checker import ProxyChecker
16
17
from components .proxy_helper import ProxyHelper
@@ -26,8 +27,16 @@ def yaml_loader(file):
26
27
27
28
if __name__ == '__main__' :
28
29
logging .basicConfig (level = logging .INFO )
29
- PacGenerator ( "config.yaml" ). build_pac ()
30
+
30
31
config = yaml_loader ("config.yaml" )
32
+ if config .get ('enable_blocksites_updater' ):
33
+ block_generator = BlocksitesUpdater (config .get ("updater_url" ))
34
+ else :
35
+ block_generator = None
36
+
37
+ PacGenerator ("config.yaml" ,block_generator .data if block_generator else None ).build_pac ()
38
+
39
+
31
40
32
41
# pid = os.fork()
33
42
# if pid == 0:
@@ -65,6 +74,10 @@ def yaml_loader(file):
65
74
sys .exit (1 )
66
75
67
76
proxy_helper = ProxyHelper .get_instance ()
77
+
78
+ if block_generator :
79
+ proxy_helper .black_list = list (block_generator .domain )
80
+
68
81
helper = Helper ("Helper" ,proxy_helper )
69
82
helper .start ()
70
83
Original file line number Diff line number Diff line change 1
1
var block_urls = { { info . block_urls} }
2
2
var direct_urls = { { info . direct_urls} }
3
- var proxies_str = '{%- for item in info.proxies %}PROXY {{item}};{%- endfor %}' ;
4
3
function FindProxyForURL ( url , host ) {
5
4
if ( shExpMatch ( url , 'http://cache.video.qiyi.com/vms*' ) ) return proxies_str ;
6
5
for ( var i in direct_urls ) {
7
6
var direct_url = direct_urls [ i ] ;
8
7
if ( shExpMatch ( url , direct_url ) ) return 'DIRECT' ;
9
8
}
10
9
for ( var i in block_urls ) {
11
- var block_url = block_urls [ i ]
10
+ var block_url = block_urls [ i ] ;
12
11
if ( shExpMatch ( url , block_url ) ) {
13
- return proxies_str ;
12
+ return "PROXY {{info.proxy_ip}}:{{info.proxy_port}};" ;
14
13
}
15
14
}
16
15
return 'DIRECT' ;
You can’t perform that action at this time.
0 commit comments