public virtual bool OnRouteDefaultRemoveDo() { Json jRoutes = Engine.Instance.JsonRouteList(); foreach (Json jRoute in jRoutes.GetArray()) { IpAddress address = new IpAddress(jRoute["address"].Value as string); if (address.IsInAddrAny) { if (RouteRemove(jRoute)) { m_routesDefaultGateway.Add(jRoute); } } } return(true); }
public static void Init() { string iso3166data = Engine.Instance.LocateResource("iso-3166.json"); if (iso3166data != "") { Json jData = null; if (Json.TryParse(Platform.Instance.FileContentsReadText(iso3166data), out jData)) { foreach (Json jCountry in jData.GetArray()) { string code = jCountry["alpha-2"].Value as string; string name = jCountry["name"].Value as string; Add(code, name); } } } }
private static bool AllowPath(string path) { string sha256 = ""; string signId = ""; if (Platform.Instance.FileExists(path) == false) { return(false); } List <string> trustedPaths = Platform.Instance.GetTrustedPaths(); foreach (string trustedPath in trustedPaths) { if (path.StartsWith(trustedPath, StringComparison.InvariantCulture)) { return(true); } } // Avoid if possible any shell before the storage init. if (Engine.Instance.Storage == null) { return(false); } Json rulesCustom = Engine.Instance.Storage.GetJson("external.rules"); for (int r = 0; r < 2; r++) { Json rules = null; if (r == 0) { if (Engine.Instance.Storage.GetBool("external.rules.recommended")) { rules = Engine.Instance.Manifest["external-rules-recommended"].Value as Json; } else { continue; } } else if (r == 1) { rules = rulesCustom; } foreach (Json rule in rules.GetArray()) { string type = rule["type"].Value as string; if (type == "all") { return(true); } if (type == "sign") { if (signId == "") { signId = Platform.Instance.FileGetSignedId(path); } if (rule["id"].Value as string == signId) { return(true); } } if (type == "sha256") { if (sha256 == "") { sha256 = UtilsCore.HashSHA256File(path); } if (rule["hash"].Value as string == sha256) { return(true); } } if (type == "path") { if (rule["path"].Value as string == path) { return(true); } } } } // Ensure compute, Report and result if (signId == "") { signId = Platform.Instance.FileGetSignedId(path); } if (sha256 == "") { sha256 = UtilsCore.HashSHA256File(path); } Json askToUi = new Json(); askToUi["sha256"].Value = sha256; askToUi["sign-id"].Value = signId; askToUi["path"].Value = path; // Propose to add rule to UI Json replyUi = Engine.Instance.OnAskShellExternalPermission(askToUi); if (replyUi.HasKey("allow")) { if (Convert.ToBoolean(replyUi["allow"].Value) == false) { return(false); } } if (replyUi.HasKey("type")) { replyUi.RemoveKey("allow"); rulesCustom.Append(replyUi); Engine.Instance.Storage.SetJson("external.rules", rulesCustom); return(AllowPath(path)); } if (replyUi.HasKey("allow")) { if (Convert.ToBoolean(replyUi["allow"].Value) == true) { return(true); } } //Engine.Instance.Storage.SetJson("external.rules", rules); return(false); }