-
Notifications
You must be signed in to change notification settings - Fork 85
/
Copy pathWhitelistUtilities.swift
101 lines (84 loc) · 3.33 KB
/
WhitelistUtilities.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
//
// WhitelistUtilities.swift
// LockdowniOS
//
// Created by Johnny Lin on 8/7/19.
// Copyright © 2019 Confirmed Inc. All rights reserved.
//
import Foundation
import NetworkExtension
// MARK: - Constants
let kLockdownWhitelistedDomains = "whitelisted_domains"
let kUserWhitelistedDomains = "whitelisted_domains_user"
func getAllWhitelistedDomains() -> Array<String> {
let lockdownWhitelistedDomains = getLockdownWhitelistedDomains()
let userWhitelistedDomains = getUserWhitelistedDomains()
var allWhitelistedDomains = Array<String>()
for (key, value) in lockdownWhitelistedDomains {
if (value as AnyObject).boolValue {
allWhitelistedDomains.append(key)
}
}
for (key, value) in userWhitelistedDomains {
if (value as AnyObject).boolValue {
allWhitelistedDomains.append(key)
}
}
return allWhitelistedDomains
}
// MARK: - User blocked domains
func getUserWhitelistedDomains() -> Dictionary<String, Any> {
if let domains = defaults.dictionary(forKey: kUserWhitelistedDomains) {
return domains
}
return Dictionary()
}
func addUserWhitelistedDomain(domain: String) {
var domains = getUserWhitelistedDomains()
domains[domain] = NSNumber(value: true)
defaults.set(domains, forKey: kUserWhitelistedDomains)
}
func setUserWhitelistedDomain(domain: String, enabled: Bool) {
var domains = getUserWhitelistedDomains()
domains[domain] = NSNumber(value: enabled)
defaults.set(domains, forKey: kUserWhitelistedDomains)
}
func deleteUserWhitelistedDomain(domain: String) {
var domains = getUserWhitelistedDomains()
domains[domain] = nil
defaults.set(domains, forKey: kUserWhitelistedDomains)
}
// MARK: - Lockdown whitelisted domains
func setupLockdownWhitelistedDomains() {
addLockdownWhitelistedDomainIfNotExists(domain: "creditkarma.com")
addLockdownWhitelistedDomainIfNotExists(domain: "hulu.com")
addLockdownWhitelistedDomainIfNotExists(domain: "netflix.com")
addLockdownWhitelistedDomainIfNotExists(domain: "api.twitter.com")
addLockdownWhitelistedDomainIfNotExists(domain: "m.twitter.com")
addLockdownWhitelistedDomainIfNotExists(domain: "mobile.twitter.com")
addLockdownWhitelistedDomainIfNotExists(domain: "houzz.com")
addLockdownWhitelistedDomainIfNotExists(domain: "apple.com")
addLockdownWhitelistedDomainIfNotExists(domain: "icloud.com")
addLockdownWhitelistedDomainIfNotExists(domain: "skype.com")
addLockdownWhitelistedDomainIfNotExists(domain: "slickdeals.net")
addLockdownWhitelistedDomainIfNotExists(domain: "confirmedvpn.com")
}
func addLockdownWhitelistedDomainIfNotExists(domain: String) {
// only add it if it doesn't exist, and add it as true
var domains = getLockdownWhitelistedDomains()
if domains[domain] == nil {
domains[domain] = NSNumber(value: true)
}
defaults.set(domains, forKey: kLockdownWhitelistedDomains)
}
func getLockdownWhitelistedDomains() -> Dictionary<String, Any> {
if let domains = defaults.dictionary(forKey: kLockdownWhitelistedDomains) {
return domains;
}
return Dictionary()
}
func setLockdownWhitelistedDomain(domain: String, enabled: Bool) {
var domains = getLockdownWhitelistedDomains()
domains[domain] = NSNumber(value: enabled)
defaults.set(domains, forKey: kLockdownWhitelistedDomains)
}