|
1 |
| -using Shadowsocks.Model; |
2 |
| -using System; |
3 |
| -using System.Collections; |
4 |
| -using System.Collections.Generic; |
5 |
| -using System.Net; |
6 |
| -using System.Reflection; |
7 |
| -using System.Text; |
8 |
| -using System.Text.RegularExpressions; |
9 |
| -using System.Xml; |
10 |
| -using System.Windows.Forms; |
11 |
| - |
12 |
| -namespace Shadowsocks.Controller |
13 |
| -{ |
14 |
| - public class UpdateFreeNode |
15 |
| - { |
16 |
| - private const string UpdateURL = "https://raw.githubusercontent.com/shadowsocksrr/breakwa11.github.io/master/free/freenodeplain.txt"; |
17 |
| - |
18 |
| - public event EventHandler NewFreeNodeFound; |
19 |
| - public string FreeNodeResult; |
20 |
| - public ServerSubscribe subscribeTask; |
| 1 | +using Shadowsocks.Model; |
| 2 | +using System; |
| 3 | +using System.Collections; |
| 4 | +using System.Collections.Generic; |
| 5 | +using System.Net; |
| 6 | +using System.Reflection; |
| 7 | +using System.Text; |
| 8 | +using System.Text.RegularExpressions; |
| 9 | +using System.Xml; |
| 10 | +using System.Windows.Forms; |
| 11 | + |
| 12 | +namespace Shadowsocks.Controller |
| 13 | +{ |
| 14 | + public class UpdateFreeNode |
| 15 | + { |
| 16 | + private const string UpdateURL = "https://raw.githubusercontent.com/shadowsocksrr/breakwa11.github.io/master/free/freenodeplain.txt"; |
| 17 | + |
| 18 | + public event EventHandler NewFreeNodeFound; |
| 19 | + public string FreeNodeResult; |
| 20 | + public ServerSubscribe subscribeTask; |
21 | 21 | public bool noitify;
|
22 |
| - |
23 |
| - public const string Name = "ShadowsocksR"; |
24 |
| - |
25 |
| - public void CheckUpdate(Configuration config, ServerSubscribe subscribeTask, bool use_proxy, bool noitify) |
26 |
| - { |
27 |
| - FreeNodeResult = null; |
28 |
| - this.noitify = noitify; |
29 |
| - try |
30 |
| - { |
31 |
| - WebClient http = new WebClient(); |
| 22 | + |
| 23 | + public const string Name = "ShadowsocksR"; |
| 24 | + |
| 25 | + public void CheckUpdate(Configuration config, ServerSubscribe subscribeTask, bool use_proxy, bool noitify) |
| 26 | + { |
| 27 | + FreeNodeResult = null; |
| 28 | + this.noitify = noitify; |
| 29 | + try |
| 30 | + { |
| 31 | + WebClient http = new WebClient(); |
32 | 32 | http.Headers.Add("User-Agent",
|
33 | 33 | String.IsNullOrEmpty(config.proxyUserAgent) ?
|
34 | 34 | "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.3319.102 Safari/537.36"
|
35 |
| - : config.proxyUserAgent); |
36 |
| - http.QueryString["rnd"] = Util.Utils.RandUInt32().ToString(); |
37 |
| - if (use_proxy) |
38 |
| - { |
39 |
| - WebProxy proxy = new WebProxy(IPAddress.Loopback.ToString(), config.localPort); |
40 |
| - if (!string.IsNullOrEmpty(config.authPass)) |
41 |
| - { |
42 |
| - proxy.Credentials = new NetworkCredential(config.authUser, config.authPass); |
43 |
| - } |
44 |
| - http.Proxy = proxy; |
45 |
| - } |
46 |
| - else |
47 |
| - { |
48 |
| - http.Proxy = null; |
49 |
| - } |
50 |
| - //UseProxy = !UseProxy; |
51 |
| - this.subscribeTask = subscribeTask; |
52 |
| - string URL = subscribeTask.URL; |
53 |
| - http.DownloadStringCompleted += http_DownloadStringCompleted; |
54 |
| - http.DownloadStringAsync(new Uri(URL != null ? URL : UpdateURL)); |
55 |
| - } |
56 |
| - catch (Exception e) |
57 |
| - { |
58 |
| - Logging.LogUsefulException(e); |
59 |
| - } |
60 |
| - } |
61 |
| - |
62 |
| - private void http_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e) |
63 |
| - { |
64 |
| - try |
65 |
| - { |
66 |
| - string response = e.Result; |
67 |
| - FreeNodeResult = response; |
68 |
| - |
69 |
| - if (NewFreeNodeFound != null) |
70 |
| - { |
71 |
| - NewFreeNodeFound(this, new EventArgs()); |
72 |
| - } |
73 |
| - } |
74 |
| - catch (Exception ex) |
75 |
| - { |
76 |
| - if (e.Error != null) |
77 |
| - { |
78 |
| - Logging.Debug(e.Error.ToString()); |
79 |
| - } |
80 |
| - Logging.Debug(ex.ToString()); |
81 |
| - if (NewFreeNodeFound != null) |
82 |
| - { |
83 |
| - NewFreeNodeFound(this, new EventArgs()); |
84 |
| - } |
85 |
| - return; |
86 |
| - } |
87 |
| - } |
88 |
| - } |
89 |
| - |
90 |
| - public class UpdateSubscribeManager |
91 |
| - { |
92 |
| - private Configuration _config; |
93 |
| - private List<ServerSubscribe> _serverSubscribes; |
94 |
| - private UpdateFreeNode _updater; |
95 |
| - private string _URL; |
96 |
| - private bool _use_proxy; |
| 35 | + : config.proxyUserAgent); |
| 36 | + http.QueryString["rnd"] = Util.Utils.RandUInt32().ToString(); |
| 37 | + if (use_proxy) |
| 38 | + { |
| 39 | + WebProxy proxy = new WebProxy(IPAddress.Loopback.ToString(), config.localPort); |
| 40 | + if (!string.IsNullOrEmpty(config.authPass)) |
| 41 | + { |
| 42 | + proxy.Credentials = new NetworkCredential(config.authUser, config.authPass); |
| 43 | + } |
| 44 | + http.Proxy = proxy; |
| 45 | + } |
| 46 | + else |
| 47 | + { |
| 48 | + http.Proxy = null; |
| 49 | + } |
| 50 | + //UseProxy = !UseProxy; |
| 51 | + this.subscribeTask = subscribeTask; |
| 52 | + string URL = subscribeTask.URL; |
| 53 | + |
| 54 | + //add support for tls1.2+ |
| 55 | + if (URL.StartsWith("https", StringComparison.OrdinalIgnoreCase)) |
| 56 | + { |
| 57 | + ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | (SecurityProtocolType)3072 | SecurityProtocolType.Tls; |
| 58 | + } |
| 59 | + |
| 60 | + http.DownloadStringCompleted += http_DownloadStringCompleted; |
| 61 | + http.DownloadStringAsync(new Uri(URL != null ? URL : UpdateURL)); |
| 62 | + } |
| 63 | + catch (Exception e) |
| 64 | + { |
| 65 | + Logging.LogUsefulException(e); |
| 66 | + } |
| 67 | + } |
| 68 | + |
| 69 | + private void http_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e) |
| 70 | + { |
| 71 | + try |
| 72 | + { |
| 73 | + string response = e.Result; |
| 74 | + FreeNodeResult = response; |
| 75 | + |
| 76 | + if (NewFreeNodeFound != null) |
| 77 | + { |
| 78 | + NewFreeNodeFound(this, new EventArgs()); |
| 79 | + } |
| 80 | + } |
| 81 | + catch (Exception ex) |
| 82 | + { |
| 83 | + if (e.Error != null) |
| 84 | + { |
| 85 | + Logging.Debug(e.Error.ToString()); |
| 86 | + } |
| 87 | + Logging.Debug(ex.ToString()); |
| 88 | + if (NewFreeNodeFound != null) |
| 89 | + { |
| 90 | + NewFreeNodeFound(this, new EventArgs()); |
| 91 | + } |
| 92 | + return; |
| 93 | + } |
| 94 | + } |
| 95 | + } |
| 96 | + |
| 97 | + public class UpdateSubscribeManager |
| 98 | + { |
| 99 | + private Configuration _config; |
| 100 | + private List<ServerSubscribe> _serverSubscribes; |
| 101 | + private UpdateFreeNode _updater; |
| 102 | + private string _URL; |
| 103 | + private bool _use_proxy; |
97 | 104 | public bool _noitify;
|
98 |
| - |
99 |
| - public void CreateTask(Configuration config, UpdateFreeNode updater, int index, bool use_proxy, bool noitify) |
100 |
| - { |
101 |
| - if (_config == null) |
102 |
| - { |
103 |
| - _config = config; |
104 |
| - _updater = updater; |
105 |
| - _use_proxy = use_proxy; |
106 |
| - _noitify = noitify; |
107 |
| - if (index < 0) |
108 |
| - { |
109 |
| - _serverSubscribes = new List<ServerSubscribe>(); |
110 |
| - for (int i = 0; i < config.serverSubscribes.Count; ++i) |
111 |
| - { |
112 |
| - _serverSubscribes.Add(config.serverSubscribes[i]); |
113 |
| - } |
114 |
| - } |
115 |
| - else if (index < _config.serverSubscribes.Count) |
116 |
| - { |
117 |
| - _serverSubscribes = new List<ServerSubscribe>(); |
118 |
| - _serverSubscribes.Add(config.serverSubscribes[index]); |
119 |
| - } |
120 |
| - Next(); |
121 |
| - } |
122 |
| - } |
123 |
| - |
124 |
| - public bool Next() |
125 |
| - { |
126 |
| - if (_serverSubscribes.Count == 0) |
127 |
| - { |
128 |
| - _config = null; |
129 |
| - return false; |
130 |
| - } |
131 |
| - else |
132 |
| - { |
133 |
| - _URL = _serverSubscribes[0].URL; |
134 |
| - _updater.CheckUpdate(_config, _serverSubscribes[0], _use_proxy, _noitify); |
135 |
| - _serverSubscribes.RemoveAt(0); |
136 |
| - return true; |
137 |
| - } |
138 |
| - } |
139 |
| - |
140 |
| - public string URL |
141 |
| - { |
142 |
| - get |
143 |
| - { |
144 |
| - return _URL; |
145 |
| - } |
146 |
| - } |
147 |
| - } |
148 |
| -} |
| 105 | + |
| 106 | + public void CreateTask(Configuration config, UpdateFreeNode updater, int index, bool use_proxy, bool noitify) |
| 107 | + { |
| 108 | + if (_config == null) |
| 109 | + { |
| 110 | + _config = config; |
| 111 | + _updater = updater; |
| 112 | + _use_proxy = use_proxy; |
| 113 | + _noitify = noitify; |
| 114 | + if (index < 0) |
| 115 | + { |
| 116 | + _serverSubscribes = new List<ServerSubscribe>(); |
| 117 | + for (int i = 0; i < config.serverSubscribes.Count; ++i) |
| 118 | + { |
| 119 | + _serverSubscribes.Add(config.serverSubscribes[i]); |
| 120 | + } |
| 121 | + } |
| 122 | + else if (index < _config.serverSubscribes.Count) |
| 123 | + { |
| 124 | + _serverSubscribes = new List<ServerSubscribe>(); |
| 125 | + _serverSubscribes.Add(config.serverSubscribes[index]); |
| 126 | + } |
| 127 | + Next(); |
| 128 | + } |
| 129 | + } |
| 130 | + |
| 131 | + public bool Next() |
| 132 | + { |
| 133 | + if (_serverSubscribes.Count == 0) |
| 134 | + { |
| 135 | + _config = null; |
| 136 | + return false; |
| 137 | + } |
| 138 | + else |
| 139 | + { |
| 140 | + _URL = _serverSubscribes[0].URL; |
| 141 | + _updater.CheckUpdate(_config, _serverSubscribes[0], _use_proxy, _noitify); |
| 142 | + _serverSubscribes.RemoveAt(0); |
| 143 | + return true; |
| 144 | + } |
| 145 | + } |
| 146 | + |
| 147 | + public string URL |
| 148 | + { |
| 149 | + get |
| 150 | + { |
| 151 | + return _URL; |
| 152 | + } |
| 153 | + } |
| 154 | + } |
| 155 | +} |
0 commit comments