-
-
Notifications
You must be signed in to change notification settings - Fork 162
/
setproxy.go
146 lines (139 loc) · 4.39 KB
/
setproxy.go
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
package mcinstall
import (
"fmt"
"github.com/danielpaulus/go-ios/ios"
)
//RemoveProxy unsets the global HTTP proxy config again by deleting the global config profile
//installed by go-ios using the identifier
//I hardcoded 'Go-iOS.CD15976B-E205-4213-9B8E-FDAA5FAB1C22'
func RemoveProxy(device ios.DeviceEntry) error {
profileService, err := New(device)
if err != nil {
return err
}
defer profileService.Close()
return profileService.RemoveProfile("Go-iOS.CD15976B-E205-4213-9B8E-FDAA5FAB1C22")
}
//SetHttpProxy generates the config profile "Go-iOS.CD15976B-E205-4213-9B8E-FDAA5FAB1C22" that will set a global
//http proxy on supervised devices.
func SetHttpProxy(device ios.DeviceEntry, host string, port string, user string, pass string, p12file []byte, p12password string) error {
profileBytes, err := setUpProfile(host, port, user, pass)
if err != nil {
return err
}
return InstallProfileSilent(device, p12file, p12password, profileBytes)
}
func setUpProfile(host string, port string, user string, pass string) ([]byte, error) {
if host == "" || port == "" {
return []byte{}, fmt.Errorf("host and port must not be empty")
}
if user != "" {
profile := fmt.Sprintf(profileTemplateAuth, host, port, user, pass)
return []byte(profile), nil
}
profile := fmt.Sprintf(profileTemplate, host, port)
return []byte(profile), nil
}
//InstallProfileSilent install a configuration profile silently.
func InstallProfileSilent(device ios.DeviceEntry, p12file []byte, p12password string, profileBytes []byte) error {
profileService, err := New(device)
if err != nil {
return err
}
defer profileService.Close()
return profileService.AddProfileSupervised(profileBytes, p12file, p12password)
}
const profileTemplate = `
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>PayloadContent</key>
<array>
<dict>
<key>PayloadDescription</key>
<string>Global HTTP Proxy</string>
<key>PayloadDisplayName</key>
<string>Global HTTP Proxy</string>
<key>PayloadIdentifier</key>
<string>com.apple.proxy.http.global.20A1B29D-7945-4C7C-9A49-649D3751F85D</string>
<key>PayloadType</key>
<string>com.apple.proxy.http.global</string>
<key>PayloadUUID</key>
<string>20A1B29D-7945-4C7C-9A49-649D3751F85D</string>
<key>PayloadVersion</key>
<integer>1</integer>
<key>ProxyCaptiveLoginAllowed</key>
<true/>
<key>ProxyServer</key>
<string>%s</string>
<key>ProxyServerPort</key>
<integer>%s</integer>
<key>ProxyType</key>
<string>Manual</string>
</dict>
</array>
<key>PayloadDisplayName</key>
<string>Untitled</string>
<key>PayloadIdentifier</key>
<string>Go-iOS.CD15976B-E205-4213-9B8E-FDAA5FAB1C22</string>
<key>PayloadRemovalDisallowed</key>
<false/>
<key>PayloadType</key>
<string>Configuration</string>
<key>PayloadUUID</key>
<string>20A1B29D-7945-4C7C-9A49-649D3751F85D</string>
<key>PayloadVersion</key>
<integer>1</integer>
</dict>
</plist>
`
const profileTemplateAuth = `
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>PayloadContent</key>
<array>
<dict>
<key>PayloadDescription</key>
<string>Global HTTP Proxy</string>
<key>PayloadDisplayName</key>
<string>Global HTTP Proxy</string>
<key>PayloadIdentifier</key>
<string>com.apple.proxy.http.global.20A1B29D-7945-4C7C-9A49-649D3751F85D</string>
<key>PayloadType</key>
<string>com.apple.proxy.http.global</string>
<key>PayloadUUID</key>
<string>20A1B29D-7945-4C7C-9A49-649D3751F85D</string>
<key>PayloadVersion</key>
<integer>1</integer>
<key>ProxyCaptiveLoginAllowed</key>
<true/>
<key>ProxyServer</key>
<string>%s</string>
<key>ProxyServerPort</key>
<integer>%s</integer>
<key>ProxyType</key>
<string>Manual</string>
<key>ProxyUsername</key>
<string>%s</string>
<key>ProxyPassword</key>
<string>%s</string>
</dict>
</array>
<key>PayloadDisplayName</key>
<string>Untitled</string>
<key>PayloadIdentifier</key>
<string>Go-iOS.CD15976B-E205-4213-9B8E-FDAA5FAB1C22</string>
<key>PayloadRemovalDisallowed</key>
<false/>
<key>PayloadType</key>
<string>Configuration</string>
<key>PayloadUUID</key>
<string>20A1B29D-7945-4C7C-9A49-649D3751F85D</string>
<key>PayloadVersion</key>
<integer>1</integer>
</dict>
</plist>
`