Skip to content

Commit

Permalink
Don't crash when config file read fails.
Browse files Browse the repository at this point in the history
  • Loading branch information
Johan Bloemberg committed Dec 5, 2018
1 parent d26e56e commit 5fc5e7f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 16 deletions.
43 changes: 29 additions & 14 deletions Wireguard Statusbar/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -166,22 +166,37 @@ class AppDelegate: NSObject, NSApplicationDelegate, SKQueueDelegate {
let files = enumerator?.allObjects as! [String]
let config_files = files.filter{$0.hasSuffix(".conf")}.sorted()
for config_file in config_files {
var config = parseConfig(config_path + "/" + config_file)
let interface = config_file.replacingOccurrences(of: ".conf", with: "")
// TODO: currently supports only one peer, need to pick a different method for parsing config
let peers = [Peer(
endpoint: config["Peer"]!["Endpoint"]!,
allowedIps: config["Peer"]!["AllowedIPs"]!.split(separator: ",").map { $0.trimmingCharacters(in: .whitespaces) }


// determine if config file can be read
if let _ = try? String(contentsOfFile: config_path + "/" + config_file) {
var config = parseConfig(config_path + "/" + config_file)

// TODO: currently supports only one peer, need to pick a different method for parsing config
let peers = [Peer(
endpoint: config["Peer"]!["Endpoint"]!,
allowedIps: config["Peer"]!["AllowedIPs"]!.split(separator: ",").map { $0.trimmingCharacters(in: .whitespaces) }
)
]
let tunnel = Tunnel(
name: "",
interface: interface,
connected: false,
address: config["Interface"]!["Address"]!,
peers: peers
)
]
let tunnel = Tunnel(
name: "",
interface: interface,
connected: false,
address: config["Interface"]!["Address"]!,
peers: peers
)
tunnels[interface] = tunnel
tunnels[interface] = tunnel
} else {
// could not read config, provide minimal details
tunnels[interface] = Tunnel(
name: "",
interface: interface,
connected: false,
address: "",
peers: []
)
}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions Wireguard Statusbar/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.6</string>
<string>1.7</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSApplicationCategoryType</key>
Expand All @@ -35,7 +35,7 @@
<key>SMPrivilegedExecutables</key>
<dict>
<key>nl.ijohan.WireguardStatusbarHelper</key>
<string>anchor apple generic and identifier "nl.ijohan.WireguardStatusbarHelper" </string>
<string>anchor apple generic and identifier &quot;nl.ijohan.WireguardStatusbarHelper&quot; </string>
</dict>
</dict>
</plist>

0 comments on commit 5fc5e7f

Please sign in to comment.