using System; using System.Text.RegularExpressions; using System.Web; namespace Netch.Models.Server.Shadowsocks { public class Shadowsocks : Server { public Shadowsocks() { this.Type = ServerType.Shadowsocks; } /// /// 密码 /// [Newtonsoft.Json.JsonProperty("passwd")] public string Passwd; /// /// 加密 /// [Newtonsoft.Json.JsonProperty("method")] public string Method; /// /// 插件 /// [Newtonsoft.Json.JsonProperty("obfs")] public string OBFS; /// /// 插件参数 /// [Newtonsoft.Json.JsonProperty("obfsparam")] public string OBFSParam; /// /// 解析链接 /// /// 链接 /// 是否成功 public bool ParseLink(string link) { if (link.Contains("#")) { this.Remark = HttpUtility.UrlDecode(link.Split('#')[1]); link = link.Split('#')[0]; } if (link.Contains("?")) { var finder = new Regex(@"^(?.+?)\?(.+)$"); var matches = finder.Match(link); if (matches.Success) { var plugin = HttpUtility.UrlDecode(HttpUtility.ParseQueryString(new Uri(link).Query).Get("plugin")); if (plugin != null) { var obfs = plugin.Substring(0, plugin.IndexOf(";")); var opts = plugin.Substring(plugin.IndexOf(";") + 1); switch (obfs) { case "obfs-local": case "simple-obfs": case "simple-obfs-tls": obfs = "simple-obfs"; break; } this.OBFS = obfs; this.OBFSParam = opts; } link = matches.Groups["data"].Value; } else { return false; } } if (link.Contains("@")) { var finder = new Regex(@"^ss://(?.+?)@(?.+):(?\d+)"); var parser = new Regex(@"^(?.+?):(?.+)$"); var matches = finder.Match(link); if (!matches.Success) { return false; } this.Host = matches.Groups["server"].Value; if (ushort.TryParse(matches.Groups["port"].Value, out var result)) { this.Port = result; } else { return false; } matches = parser.Match(Utils.Base64.Decode.URLSafe(matches.Groups["base64"].Value)); if (!matches.Success) { return false; } this.Passwd = matches.Groups["password"].Value; this.Method = matches.Groups["method"].Value; } else { return false; } this.Method = this.Method.ToLower(); return Global.Methods.Contains(this.Method); } } }