Skip to content

Commit

Permalink
* (home): minor refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
ameshkov committed Oct 6, 2020
1 parent e1d1025 commit 5d0d6c5
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 108 deletions.
94 changes: 2 additions & 92 deletions AGHTechDoc.md
Original file line number Diff line number Diff line change
Expand Up @@ -1988,52 +1988,7 @@ Response:

200 OK

<?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>DNSSettings</key>
<dict>
<key>DNSProtocol</key>
<string>HTTPS</string>
<key>ServerURL</key>
<string>https://exmaple.com</string>
</dict>
<key>Name</key>
<string>exmaple.com DNS over HTTPS</string>
<key>PayloadDescription</key>
<string>Configures device to use AdGuard Home</string>
<key>PayloadDisplayName</key>
<string>AdGuard Home</string>
<key>PayloadIdentifier</key>
<string>com.apple.dnsSettings.managed.b53e1681-be7c-4c23-b350-6610545e884c</string>
<key>PayloadType</key>
<string>com.apple.dnsSettings.managed</string>
<key>PayloadUUID</key>
<string>b53e1681-be7c-4c23-b350-6610545e884c</string>
<key>PayloadVersion</key>
<integer>1</integer>
</dict>
</array>
<key>PayloadDescription</key>
<string>Adds AdGuard Home to Big Sur and iOS 14 or newer systems</string>
<key>PayloadDisplayName</key>
<string>AdGuard Home</string>
<key>PayloadIdentifier</key>
<string>9e2f3aff-b255-4179-bc16-caeca10396d1</string>
<key>PayloadRemovalDisallowed</key>
<false/>
<key>PayloadType</key>
<string>Configuration</string>
<key>PayloadUUID</key>
<string>b67ecfe3-e8e4-46d6-8cd8-400dbf74b501</string>
<key>PayloadVersion</key>
<integer>1</integer>
</dict>
</plist>
DOH plist file

## API: Get DNS over TLS .mobileconfig

Expand All @@ -2045,52 +2000,7 @@ Response:

200 OK

<?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>DNSSettings</key>
<dict>
<key>DNSProtocol</key>
<string>TLS</string>
<key>ServerName</key>
<string>exmaple.com</string>
</dict>
<key>Name</key>
<string>exmaple.com DNS over TLS</string>
<key>PayloadDescription</key>
<string>Configures device to use AdGuard Home</string>
<key>PayloadDisplayName</key>
<string>AdGuard Home</string>
<key>PayloadIdentifier</key>
<string>com.apple.dnsSettings.managed.70b41a0b-316d-4c4a-83c0-ef73b9ece4f6</string>
<key>PayloadType</key>
<string>com.apple.dnsSettings.managed</string>
<key>PayloadUUID</key>
<string>70b41a0b-316d-4c4a-83c0-ef73b9ece4f6</string>
<key>PayloadVersion</key>
<integer>1</integer>
</dict>
</array>
<key>PayloadDescription</key>
<string>Adds AdGuard Home to Big Sur and iOS 14 or newer systems</string>
<key>PayloadDisplayName</key>
<string>AdGuard Home</string>
<key>PayloadIdentifier</key>
<string>629466b3-b787-4645-9eb6-34382980398f</string>
<key>PayloadRemovalDisallowed</key>
<false/>
<key>PayloadType</key>
<string>Configuration</string>
<key>PayloadUUID</key>
<string>7fa3f167-e0da-4e45-9463-d07db8af3657</string>
<key>PayloadVersion</key>
<integer>1</integer>
</dict>
</plist>
DOT plist file

## ipset

Expand Down
1 change: 1 addition & 0 deletions home/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ func registerControlHandlers() {
httpRegister(http.MethodPost, "/control/update", handleUpdate)
httpRegister(http.MethodGet, "/control/profile", handleGetProfile)

// No auth is necessary for DOH/DOT configurations
http.HandleFunc("/apple/doh.mobileconfig", postInstall(handleMobileConfigDoh))
http.HandleFunc("/apple/dot.mobileconfig", postInstall(handleMobileConfigDot))
RegisterAuthHandlers()
Expand Down
24 changes: 12 additions & 12 deletions home/mobileconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,41 +40,41 @@ func genUUIDv4() string {
return uuid.NewV4().String()
}

func getMobileConfig(w http.ResponseWriter, r *http.Request, d DNSSettings) []byte {
func getMobileConfig(r *http.Request, d DNSSettings) ([]byte, error) {
name := fmt.Sprintf("%s DNS over %s", r.Host, d.DNSProtocol)

data := MobileConfig{
PayloadContent: []PayloadContent{{
Name: fmt.Sprintf("%s DNS over %s", r.Host, d.DNSProtocol),
Name: name,
PayloadDescription: "Configures device to use AdGuard Home",
PayloadDisplayName: "AdGuard Home",
PayloadDisplayName: name,
PayloadIdentifier: fmt.Sprintf("com.apple.dnsSettings.managed.%s", genUUIDv4()),
PayloadType: "com.apple.dnsSettings.managed",
PayloadUUID: genUUIDv4(),
PayloadVersion: 1,
DNSSettings: d,
}},
PayloadDescription: "Adds AdGuard Home to Big Sur and iOS 14 or newer systems",
PayloadDisplayName: "AdGuard Home",
PayloadDisplayName: name,
PayloadIdentifier: genUUIDv4(),
PayloadRemovalDisallowed: false,
PayloadType: "Configuration",
PayloadUUID: genUUIDv4(),
PayloadVersion: 1,
}

mobileconfig, err := plist.MarshalIndent(data, plist.XMLFormat, "\t")
return plist.MarshalIndent(data, plist.XMLFormat, "\t")
}

func handleMobileConfig(w http.ResponseWriter, r *http.Request, d DNSSettings) {
mobileconfig, err := getMobileConfig(r, d)

if err != nil {
httpError(w, http.StatusInternalServerError, "plist.MarshalIndent: %s", err)
}

return mobileconfig
}

func handleMobileConfig(w http.ResponseWriter, r *http.Request, d DNSSettings) {
mobileconfig := getMobileConfig(w, r, d)

w.Header().Set("Content-Type", "application/xml")
w.Write(mobileconfig)
_, _ = w.Write(mobileconfig)
}

func handleMobileConfigDoh(w http.ResponseWriter, r *http.Request) {
Expand Down
8 changes: 4 additions & 4 deletions openapi/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -922,22 +922,22 @@ paths:
tags:
- mobileconfig
- global
operationId: DoHMobileconfig
operationId: mobileConfigDoH
summary: Get DNS over HTTPS .mobileconfig
responses:
"200":
description: dot.mobileconfig
description: DNS over HTTPS plist file

/apple/dot.mobileconfig:
get:
tags:
- mobileconfig
- global
operationId: DoTMobileconfig
operationId: mobileConfigDoT
summary: Get TLS over TLS .mobileconfig
responses:
"200":
description: doh.mobileconfig
description: DNS over TLS plist file

components:
requestBodies:
Expand Down

0 comments on commit 5d0d6c5

Please sign in to comment.