You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

ShadowsocksController.cs 24 kB

6 years ago
10 years ago
6 years ago
10 years ago
10 years ago
10 years ago
6 years ago
10 years ago
10 years ago
10 years ago
6 years ago
6 years ago
6 years ago
10 years ago
6 years ago
10 years ago
6 years ago
6 years ago
10 years ago
10 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
9 years ago
9 years ago
6 years ago
9 years ago
6 years ago
10 years ago
6 years ago
6 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731
  1. using System;
  2. using System.Collections.Concurrent;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Net;
  7. using System.Net.Http;
  8. using System.Net.Sockets;
  9. using System.Text;
  10. using System.Threading;
  11. using System.Threading.Tasks;
  12. using System.Web;
  13. using System.Windows.Forms;
  14. using NLog;
  15. using Shadowsocks.Controller.Service;
  16. using Shadowsocks.Controller.Strategy;
  17. using Shadowsocks.Model;
  18. using Shadowsocks.Util;
  19. using WPFLocalizeExtension.Engine;
  20. namespace Shadowsocks.Controller
  21. {
  22. public class ShadowsocksController
  23. {
  24. private readonly Logger logger;
  25. private readonly HttpClient httpClient;
  26. // controller:
  27. // handle user actions
  28. // manipulates UI
  29. // interacts with low level logic
  30. #region Members definition
  31. private Thread _trafficThread;
  32. private Listener _listener;
  33. private PACDaemon _pacDaemon;
  34. private PACServer _pacServer;
  35. private Configuration _config;
  36. private StrategyManager _strategyManager;
  37. private PrivoxyRunner privoxyRunner;
  38. private readonly ConcurrentDictionary<Server, Sip003Plugin> _pluginsByServer;
  39. private long _inboundCounter = 0;
  40. private long _outboundCounter = 0;
  41. public long InboundCounter => Interlocked.Read(ref _inboundCounter);
  42. public long OutboundCounter => Interlocked.Read(ref _outboundCounter);
  43. public Queue<TrafficPerSecond> trafficPerSecondQueue;
  44. private bool stopped = false;
  45. public class PathEventArgs : EventArgs
  46. {
  47. public string Path;
  48. }
  49. public class UpdatedEventArgs : EventArgs
  50. {
  51. public string OldVersion;
  52. public string NewVersion;
  53. }
  54. public class TrafficPerSecond
  55. {
  56. public long inboundCounter;
  57. public long outboundCounter;
  58. public long inboundIncreasement;
  59. public long outboundIncreasement;
  60. }
  61. public event EventHandler ConfigChanged;
  62. public event EventHandler EnableStatusChanged;
  63. public event EventHandler EnableGlobalChanged;
  64. public event EventHandler ShareOverLANStatusChanged;
  65. public event EventHandler VerboseLoggingStatusChanged;
  66. public event EventHandler ShowPluginOutputChanged;
  67. public event EventHandler TrafficChanged;
  68. // when user clicked Edit PAC, and PAC file has already created
  69. public event EventHandler<PathEventArgs> PACFileReadyToOpen;
  70. public event EventHandler<PathEventArgs> UserRuleFileReadyToOpen;
  71. public event EventHandler<GeositeResultEventArgs> UpdatePACFromGeositeCompleted;
  72. public event ErrorEventHandler UpdatePACFromGeositeError;
  73. public event ErrorEventHandler Errored;
  74. // Invoked when controller.Start();
  75. public event EventHandler<UpdatedEventArgs> ProgramUpdated;
  76. #endregion
  77. public ShadowsocksController()
  78. {
  79. logger = LogManager.GetCurrentClassLogger();
  80. httpClient = new HttpClient();
  81. _config = Configuration.Load();
  82. Configuration.Process(ref _config);
  83. _strategyManager = new StrategyManager(this);
  84. _pluginsByServer = new ConcurrentDictionary<Server, Sip003Plugin>();
  85. StartTrafficStatistics(61);
  86. ProgramUpdated += (o, e) =>
  87. {
  88. // version update precedures
  89. if (e.OldVersion == "4.3.0.0" || e.OldVersion == "4.3.1.0")
  90. _config.geositeDirectGroups.Add("private");
  91. logger.Info($"Updated from {e.OldVersion} to {e.NewVersion}");
  92. };
  93. }
  94. #region Basic
  95. public void Start(bool systemWakeUp = false)
  96. {
  97. if (_config.firstRunOnNewVersion && !systemWakeUp)
  98. {
  99. ProgramUpdated.Invoke(this, new UpdatedEventArgs()
  100. {
  101. OldVersion = _config.version,
  102. NewVersion = UpdateChecker.Version,
  103. });
  104. // delete pac.txt when regeneratePacOnUpdate is true
  105. if (_config.regeneratePacOnUpdate)
  106. try
  107. {
  108. File.Delete(PACDaemon.PAC_FILE);
  109. logger.Info("Deleted pac.txt from previous version.");
  110. }
  111. catch (Exception e)
  112. {
  113. logger.LogUsefulException(e);
  114. }
  115. // finish up first run of new version
  116. _config.firstRunOnNewVersion = false;
  117. _config.version = UpdateChecker.Version;
  118. Configuration.Save(_config);
  119. }
  120. Reload();
  121. if (!systemWakeUp)
  122. HotkeyReg.RegAllHotkeys();
  123. }
  124. public void Stop()
  125. {
  126. if (stopped)
  127. {
  128. return;
  129. }
  130. stopped = true;
  131. if (_listener != null)
  132. {
  133. _listener.Stop();
  134. }
  135. StopPlugins();
  136. if (privoxyRunner != null)
  137. {
  138. privoxyRunner.Stop();
  139. }
  140. if (_config.enabled)
  141. {
  142. SystemProxy.Update(_config, true, null);
  143. }
  144. Encryption.RNG.Close();
  145. }
  146. protected void Reload()
  147. {
  148. Encryption.RNG.Reload();
  149. // some logic in configuration updated the config when saving, we need to read it again
  150. _config = Configuration.Load();
  151. Configuration.Process(ref _config);
  152. NLogConfig.LoadConfiguration();
  153. logger.Info($"WPF Localization Extension|Current culture: {LocalizeDictionary.CurrentCulture}");
  154. // set User-Agent for httpClient
  155. try
  156. {
  157. if (!string.IsNullOrWhiteSpace(_config.userAgentString))
  158. httpClient.DefaultRequestHeaders.Add("User-Agent", _config.userAgentString);
  159. }
  160. catch
  161. {
  162. // reset userAgent to default and reapply
  163. Configuration.ResetUserAgent(_config);
  164. httpClient.DefaultRequestHeaders.Add("User-Agent", _config.userAgentString);
  165. }
  166. privoxyRunner = privoxyRunner ?? new PrivoxyRunner();
  167. _pacDaemon = _pacDaemon ?? new PACDaemon(_config);
  168. _pacDaemon.PACFileChanged += PacDaemon_PACFileChanged;
  169. _pacDaemon.UserRuleFileChanged += PacDaemon_UserRuleFileChanged;
  170. _pacServer = _pacServer ?? new PACServer(_pacDaemon);
  171. _pacServer.UpdatePACURL(_config); // So PACServer works when system proxy disabled.
  172. GeositeUpdater.ResetEvent();
  173. GeositeUpdater.UpdateCompleted += PacServer_PACUpdateCompleted;
  174. GeositeUpdater.Error += PacServer_PACUpdateError;
  175. _listener?.Stop();
  176. StopPlugins();
  177. // don't put PrivoxyRunner.Start() before pacServer.Stop()
  178. // or bind will fail when switching bind address from 0.0.0.0 to 127.0.0.1
  179. // though UseShellExecute is set to true now
  180. // http://stackoverflow.com/questions/10235093/socket-doesnt-close-after-application-exits-if-a-launched-process-is-open
  181. privoxyRunner.Stop();
  182. try
  183. {
  184. var strategy = GetCurrentStrategy();
  185. strategy?.ReloadServers();
  186. StartPlugin();
  187. privoxyRunner.Start(_config);
  188. TCPRelay tcpRelay = new TCPRelay(this, _config);
  189. tcpRelay.OnInbound += UpdateInboundCounter;
  190. tcpRelay.OnOutbound += UpdateOutboundCounter;
  191. tcpRelay.OnFailed += (o, e) => GetCurrentStrategy()?.SetFailure(e.server);
  192. UDPRelay udpRelay = new UDPRelay(this);
  193. List<Listener.IService> services = new List<Listener.IService>
  194. {
  195. tcpRelay,
  196. udpRelay,
  197. _pacServer,
  198. new PortForwarder(privoxyRunner.RunningPort)
  199. };
  200. _listener = new Listener(services);
  201. _listener.Start(_config);
  202. }
  203. catch (Exception e)
  204. {
  205. // translate Microsoft language into human language
  206. // i.e. An attempt was made to access a socket in a way forbidden by its access permissions => Port already in use
  207. if (e is SocketException se)
  208. {
  209. if (se.SocketErrorCode == SocketError.AddressAlreadyInUse)
  210. {
  211. e = new Exception(I18N.GetString("Port {0} already in use", _config.localPort), e);
  212. }
  213. else if (se.SocketErrorCode == SocketError.AccessDenied)
  214. {
  215. e = new Exception(I18N.GetString("Port {0} is reserved by system", _config.localPort), e);
  216. }
  217. }
  218. logger.LogUsefulException(e);
  219. ReportError(e);
  220. }
  221. ConfigChanged?.Invoke(this, new EventArgs());
  222. UpdateSystemProxy();
  223. }
  224. protected void SaveConfig(Configuration newConfig)
  225. {
  226. Configuration.Save(newConfig);
  227. Reload();
  228. }
  229. protected void ReportError(Exception e)
  230. {
  231. Errored?.Invoke(this, new ErrorEventArgs(e));
  232. }
  233. public HttpClient GetHttpClient() => httpClient;
  234. public Server GetCurrentServer() => _config.GetCurrentServer();
  235. public Configuration GetCurrentConfiguration() => _config;
  236. public Server GetAServer(IStrategyCallerType type, IPEndPoint localIPEndPoint, EndPoint destEndPoint)
  237. {
  238. IStrategy strategy = GetCurrentStrategy();
  239. if (strategy != null)
  240. {
  241. return strategy.GetAServer(type, localIPEndPoint, destEndPoint);
  242. }
  243. if (_config.index < 0)
  244. {
  245. _config.index = 0;
  246. }
  247. return GetCurrentServer();
  248. }
  249. public void SaveServers(List<Server> servers, int localPort, bool portableMode)
  250. {
  251. _config.configs = servers;
  252. _config.localPort = localPort;
  253. _config.portableMode = portableMode;
  254. Configuration.Save(_config);
  255. }
  256. public void SelectServerIndex(int index)
  257. {
  258. _config.index = index;
  259. _config.strategy = null;
  260. SaveConfig(_config);
  261. }
  262. public void ToggleShareOverLAN(bool enabled)
  263. {
  264. _config.shareOverLan = enabled;
  265. SaveConfig(_config);
  266. ShareOverLANStatusChanged?.Invoke(this, new EventArgs());
  267. }
  268. #endregion
  269. #region OS Proxy
  270. public void ToggleEnable(bool enabled)
  271. {
  272. _config.enabled = enabled;
  273. SaveConfig(_config);
  274. EnableStatusChanged?.Invoke(this, new EventArgs());
  275. }
  276. public void ToggleGlobal(bool global)
  277. {
  278. _config.global = global;
  279. SaveConfig(_config);
  280. EnableGlobalChanged?.Invoke(this, new EventArgs());
  281. }
  282. public void SaveProxy(ForwardProxyConfig proxyConfig)
  283. {
  284. _config.proxy = proxyConfig;
  285. SaveConfig(_config);
  286. }
  287. private void UpdateSystemProxy()
  288. {
  289. SystemProxy.Update(_config, false, _pacServer);
  290. }
  291. #endregion
  292. #region PAC
  293. private void PacDaemon_PACFileChanged(object sender, EventArgs e)
  294. {
  295. UpdateSystemProxy();
  296. }
  297. private void PacServer_PACUpdateCompleted(object sender, GeositeResultEventArgs e)
  298. {
  299. UpdatePACFromGeositeCompleted?.Invoke(this, e);
  300. }
  301. private void PacServer_PACUpdateError(object sender, ErrorEventArgs e)
  302. {
  303. UpdatePACFromGeositeError?.Invoke(this, e);
  304. }
  305. private static readonly IEnumerable<char> IgnoredLineBegins = new[] { '!', '[' };
  306. private void PacDaemon_UserRuleFileChanged(object sender, EventArgs e)
  307. {
  308. GeositeUpdater.MergeAndWritePACFile(_config.geositeDirectGroups, _config.geositeProxiedGroups, _config.geositePreferDirect);
  309. UpdateSystemProxy();
  310. }
  311. public void CopyPacUrl()
  312. {
  313. Clipboard.SetDataObject(_pacServer.PacUrl);
  314. }
  315. public void SavePACUrl(string pacUrl)
  316. {
  317. _config.pacUrl = pacUrl;
  318. SaveConfig(_config);
  319. ConfigChanged?.Invoke(this, new EventArgs());
  320. }
  321. public void UseOnlinePAC(bool useOnlinePac)
  322. {
  323. _config.useOnlinePac = useOnlinePac;
  324. SaveConfig(_config);
  325. ConfigChanged?.Invoke(this, new EventArgs());
  326. }
  327. public void TouchPACFile()
  328. {
  329. string pacFilename = _pacDaemon.TouchPACFile();
  330. PACFileReadyToOpen?.Invoke(this, new PathEventArgs() { Path = pacFilename });
  331. }
  332. public void TouchUserRuleFile()
  333. {
  334. string userRuleFilename = _pacDaemon.TouchUserRuleFile();
  335. UserRuleFileReadyToOpen?.Invoke(this, new PathEventArgs() { Path = userRuleFilename });
  336. }
  337. public void ToggleSecureLocalPac(bool enabled)
  338. {
  339. _config.secureLocalPac = enabled;
  340. SaveConfig(_config);
  341. ConfigChanged?.Invoke(this, new EventArgs());
  342. }
  343. public void ToggleRegeneratePacOnUpdate(bool enabled)
  344. {
  345. _config.regeneratePacOnUpdate = enabled;
  346. SaveConfig(_config);
  347. ConfigChanged?.Invoke(this, new EventArgs());
  348. }
  349. #endregion
  350. #region SIP002
  351. public bool AskAddServerBySSURL(string ssURL)
  352. {
  353. var dr = MessageBox.Show(I18N.GetString("Import from URL: {0} ?", ssURL), I18N.GetString("Shadowsocks"), MessageBoxButtons.YesNo);
  354. if (dr == DialogResult.Yes)
  355. {
  356. if (AddServerBySSURL(ssURL))
  357. {
  358. MessageBox.Show(I18N.GetString("Successfully imported from {0}", ssURL));
  359. return true;
  360. }
  361. else
  362. {
  363. MessageBox.Show(I18N.GetString("Failed to import. Please check if the link is valid."));
  364. }
  365. }
  366. return false;
  367. }
  368. public bool AddServerBySSURL(string ssURL)
  369. {
  370. try
  371. {
  372. if (string.IsNullOrWhiteSpace(ssURL))
  373. return false;
  374. var servers = Server.GetServers(ssURL);
  375. if (servers == null || servers.Count == 0)
  376. return false;
  377. foreach (var server in servers)
  378. {
  379. _config.configs.Add(server);
  380. }
  381. _config.index = _config.configs.Count - 1;
  382. SaveConfig(_config);
  383. return true;
  384. }
  385. catch (Exception e)
  386. {
  387. logger.LogUsefulException(e);
  388. return false;
  389. }
  390. }
  391. public string GetServerURLForCurrentServer()
  392. {
  393. return GetCurrentServer().GetURL(_config.generateLegacyUrl);
  394. }
  395. #endregion
  396. #region Misc
  397. public void ToggleVerboseLogging(bool enabled)
  398. {
  399. _config.isVerboseLogging = enabled;
  400. SaveConfig(_config);
  401. NLogConfig.LoadConfiguration(); // reload nlog
  402. VerboseLoggingStatusChanged?.Invoke(this, new EventArgs());
  403. }
  404. public void ToggleCheckingUpdate(bool enabled)
  405. {
  406. _config.autoCheckUpdate = enabled;
  407. Configuration.Save(_config);
  408. ConfigChanged?.Invoke(this, new EventArgs());
  409. }
  410. public void ToggleCheckingPreRelease(bool enabled)
  411. {
  412. _config.checkPreRelease = enabled;
  413. Configuration.Save(_config);
  414. ConfigChanged?.Invoke(this, new EventArgs());
  415. }
  416. public void SaveSkippedUpdateVerion(string version)
  417. {
  418. _config.skippedUpdateVersion = version;
  419. Configuration.Save(_config);
  420. }
  421. public void SaveLogViewerConfig(LogViewerConfig newConfig)
  422. {
  423. _config.logViewer = newConfig;
  424. newConfig.SaveSize();
  425. Configuration.Save(_config);
  426. ConfigChanged?.Invoke(this, new EventArgs());
  427. }
  428. public void SaveHotkeyConfig(HotkeyConfig newConfig)
  429. {
  430. _config.hotkey = newConfig;
  431. SaveConfig(_config);
  432. ConfigChanged?.Invoke(this, new EventArgs());
  433. }
  434. #endregion
  435. #region Strategy
  436. public void SelectStrategy(string strategyID)
  437. {
  438. _config.index = -1;
  439. _config.strategy = strategyID;
  440. SaveConfig(_config);
  441. }
  442. public IList<IStrategy> GetStrategies()
  443. {
  444. return _strategyManager.GetStrategies();
  445. }
  446. public IStrategy GetCurrentStrategy()
  447. {
  448. foreach (var strategy in _strategyManager.GetStrategies())
  449. {
  450. if (strategy.ID == _config.strategy)
  451. {
  452. return strategy;
  453. }
  454. }
  455. return null;
  456. }
  457. public void UpdateInboundCounter(object sender, SSTransmitEventArgs args)
  458. {
  459. GetCurrentStrategy()?.UpdateLastRead(args.server);
  460. Interlocked.Add(ref _inboundCounter, args.length);
  461. }
  462. public void UpdateOutboundCounter(object sender, SSTransmitEventArgs args)
  463. {
  464. GetCurrentStrategy()?.UpdateLastWrite(args.server);
  465. Interlocked.Add(ref _outboundCounter, args.length);
  466. }
  467. #endregion
  468. #region SIP003
  469. private void StartPlugin()
  470. {
  471. var server = _config.GetCurrentServer();
  472. GetPluginLocalEndPointIfConfigured(server);
  473. }
  474. private void StopPlugins()
  475. {
  476. foreach (var serverAndPlugin in _pluginsByServer)
  477. {
  478. serverAndPlugin.Value?.Dispose();
  479. }
  480. _pluginsByServer.Clear();
  481. }
  482. public EndPoint GetPluginLocalEndPointIfConfigured(Server server)
  483. {
  484. var plugin = _pluginsByServer.GetOrAdd(
  485. server,
  486. x => Sip003Plugin.CreateIfConfigured(x, _config.showPluginOutput));
  487. if (plugin == null)
  488. {
  489. return null;
  490. }
  491. try
  492. {
  493. if (plugin.StartIfNeeded())
  494. {
  495. logger.Info(
  496. $"Started SIP003 plugin for {server.Identifier()} on {plugin.LocalEndPoint} - PID: {plugin.ProcessId}");
  497. }
  498. }
  499. catch (Exception ex)
  500. {
  501. logger.Error("Failed to start SIP003 plugin: " + ex.Message);
  502. throw;
  503. }
  504. return plugin.LocalEndPoint;
  505. }
  506. public void ToggleShowPluginOutput(bool enabled)
  507. {
  508. _config.showPluginOutput = enabled;
  509. SaveConfig(_config);
  510. ShowPluginOutputChanged?.Invoke(this, new EventArgs());
  511. }
  512. #endregion
  513. #region Traffic Statistics
  514. private void StartTrafficStatistics(int queueMaxSize)
  515. {
  516. trafficPerSecondQueue = new Queue<TrafficPerSecond>();
  517. for (int i = 0; i < queueMaxSize; i++)
  518. {
  519. trafficPerSecondQueue.Enqueue(new TrafficPerSecond());
  520. }
  521. _trafficThread = new Thread(new ThreadStart(() => TrafficStatistics(queueMaxSize)))
  522. {
  523. IsBackground = true
  524. };
  525. _trafficThread.Start();
  526. }
  527. private void TrafficStatistics(int queueMaxSize)
  528. {
  529. TrafficPerSecond previous, current;
  530. while (true)
  531. {
  532. previous = trafficPerSecondQueue.Last();
  533. current = new TrafficPerSecond
  534. {
  535. inboundCounter = InboundCounter,
  536. outboundCounter = OutboundCounter
  537. };
  538. current.inboundIncreasement = current.inboundCounter - previous.inboundCounter;
  539. current.outboundIncreasement = current.outboundCounter - previous.outboundCounter;
  540. trafficPerSecondQueue.Enqueue(current);
  541. if (trafficPerSecondQueue.Count > queueMaxSize)
  542. trafficPerSecondQueue.Dequeue();
  543. TrafficChanged?.Invoke(this, new EventArgs());
  544. Thread.Sleep(1000);
  545. }
  546. }
  547. #endregion
  548. #region SIP008
  549. public async Task<int> UpdateOnlineConfigInternal(string url)
  550. {
  551. var onlineServer = await OnlineConfigResolver.GetOnline(url);
  552. _config.configs = Configuration.SortByOnlineConfig(
  553. _config.configs
  554. .Where(c => c.group != url)
  555. .Concat(onlineServer)
  556. );
  557. logger.Info($"updated {onlineServer.Count} server from {url}");
  558. return onlineServer.Count;
  559. }
  560. public async Task<bool> UpdateOnlineConfig(string url)
  561. {
  562. var selected = GetCurrentServer();
  563. try
  564. {
  565. int count = await UpdateOnlineConfigInternal(url);
  566. }
  567. catch (Exception e)
  568. {
  569. logger.LogUsefulException(e);
  570. return false;
  571. }
  572. _config.index = _config.configs.IndexOf(selected);
  573. SaveConfig(_config);
  574. return true;
  575. }
  576. public async Task<List<string>> UpdateAllOnlineConfig()
  577. {
  578. var selected = GetCurrentServer();
  579. var failedUrls = new List<string>();
  580. foreach (var url in _config.onlineConfigSource)
  581. {
  582. try
  583. {
  584. await UpdateOnlineConfigInternal(url);
  585. }
  586. catch (Exception e)
  587. {
  588. logger.LogUsefulException(e);
  589. failedUrls.Add(url);
  590. }
  591. }
  592. _config.index = _config.configs.IndexOf(selected);
  593. SaveConfig(_config);
  594. return failedUrls;
  595. }
  596. public void SaveOnlineConfigSource(List<string> sources)
  597. {
  598. _config.onlineConfigSource = sources;
  599. SaveConfig(_config);
  600. }
  601. public void RemoveOnlineConfig(string url)
  602. {
  603. _config.onlineConfigSource.RemoveAll(v => v == url);
  604. _config.configs = Configuration.SortByOnlineConfig(
  605. _config.configs.Where(c => c.group != url)
  606. );
  607. SaveConfig(_config);
  608. }
  609. #endregion
  610. }
  611. }