This commit is contained in:
Ian VanSchooten 2024-10-15 15:05:41 -04:00 committed by GitHub
commit 9a27db2a25
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 16 additions and 11 deletions

View File

@ -7,7 +7,7 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
private var networkMonitor: NWPathMonitor? private var networkMonitor: NWPathMonitor?
private var site: Site? private var site: Site?
private var log = Logger(subsystem: "net.defined.mobileNebula", category: "PacketTunnelProvider") static let log = Logger(subsystem: "net.defined.mobileNebula", category: "PacketTunnelProvider")
private var nebula: MobileNebulaNebula? private var nebula: MobileNebulaNebula?
private var dnUpdater = DNUpdater() private var dnUpdater = DNUpdater()
private var didSleep = false private var didSleep = false
@ -37,7 +37,7 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
config = try site!.getConfig() config = try site!.getConfig()
} catch { } catch {
//TODO: need a way to notify the app //TODO: need a way to notify the app
log.error("Failed to render config from vpn object") Self.log.error("Failed to render config from vpn object")
return completionHandler(error) return completionHandler(error)
} }
@ -89,7 +89,7 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
self.startNetworkMonitor() self.startNetworkMonitor()
if err != nil { if err != nil {
self.log.error("We had an error starting up: \(err, privacy: .public)") Self.log.error("We had an error starting up: \(err, privacy: .public)")
return completionHandler(err!) return completionHandler(err!)
} }
@ -106,7 +106,7 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
try self.nebula?.reload(String(data: newSite.getConfig(), encoding: .utf8), key: newSite.getKey()) try self.nebula?.reload(String(data: newSite.getConfig(), encoding: .utf8), key: newSite.getKey())
} catch { } catch {
self.log.error("Got an error while updating nebula \(error.localizedDescription, privacy: .public)") Self.log.error("Got an error while updating nebula \(error.localizedDescription, privacy: .public)")
} }
} }
@ -162,7 +162,7 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
override func handleAppMessage(_ data: Data, completionHandler: ((Data?) -> Void)? = nil) { override func handleAppMessage(_ data: Data, completionHandler: ((Data?) -> Void)? = nil) {
guard let call = try? JSONDecoder().decode(IPCRequest.self, from: data) else { guard let call = try? JSONDecoder().decode(IPCRequest.self, from: data) else {
log.error("Failed to decode IPCRequest from network extension") Self.log.error("Failed to decode IPCRequest from network extension")
return return
} }
@ -190,7 +190,7 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
if nebula == nil { if nebula == nil {
// Respond with an empty success message in the event a command comes in before we've truly started // Respond with an empty success message in the event a command comes in before we've truly started
log.warning("Received command but do not have a nebula instance") Self.log.warning("Received command but do not have a nebula instance")
return completionHandler!(try? JSONEncoder().encode(IPCResponse.init(type: .success, message: nil))) return completionHandler!(try? JSONEncoder().encode(IPCResponse.init(type: .success, message: nil)))
} }

View File

@ -1,6 +1,9 @@
import NetworkExtension import NetworkExtension
import MobileNebula import MobileNebula
import SwiftyJSON import SwiftyJSON
import os.log
var log = Logger(subsystem: "net.defined.mobileNebula", category: "Site")
extension String: Error {} extension String: Error {}
@ -430,7 +433,7 @@ struct IncomingSite: Codable {
return return
} }
print("Saving to \(configPath)") log.notice("Saving to \(configPath, privacy: .public)")
do { do {
if (self.key != nil) { if (self.key != nil) {
let data = self.key!.data(using: .utf8) let data = self.key!.data(using: .utf8)

View File

@ -1,8 +1,10 @@
import Foundation import Foundation
import os.log
class DNUpdater { class DNUpdater {
private let apiClient = APIClient() private let apiClient = APIClient()
private let timer = RepeatingTimer(timeInterval: 15 * 60) // 15 * 60 is 15 minutes private let timer = RepeatingTimer(timeInterval: 15 * 60) // 15 * 60 is 15 minutes
static let log = Logger(subsystem: "net.defined.mobileNebula", category: "DNUpdater")
func updateAll(onUpdate: @escaping (Site) -> ()) { func updateAll(onUpdate: @escaping (Site) -> ()) {
_ = SiteList{ (sites, _) -> () in _ = SiteList{ (sites, _) -> () in
@ -55,7 +57,7 @@ class DNUpdater {
} catch (APIClientError.invalidCredentials) { } catch (APIClientError.invalidCredentials) {
if (!credentials.invalid) { if (!credentials.invalid) {
try site.invalidateDNCredentials() try site.invalidateDNCredentials()
print("Invalidated credentials in site \(site.name)") Self.log.notice("Invalidated credentials in site: \(site.name, privacy: .public)")
} }
return return
@ -63,7 +65,7 @@ class DNUpdater {
newSite?.save(manager: nil) { error in newSite?.save(manager: nil) { error in
if (error != nil) { if (error != nil) {
print("failed to save update: \(error!.localizedDescription)") Self.log.error("failed to save update: \(error!.localizedDescription, privacy: .public)")
} else { } else {
onUpdate(Site(incoming: newSite!)) onUpdate(Site(incoming: newSite!))
} }
@ -71,11 +73,11 @@ class DNUpdater {
if (credentials.invalid) { if (credentials.invalid) {
try site.validateDNCredentials() try site.validateDNCredentials()
print("Revalidated credentials in site \(site.name)") Self.log.notice("Revalidated credentials in site \(site.name, privacy: .public)")
} }
} catch { } catch {
print("Error while updating \(site.name): \(error.localizedDescription)") Self.log.error("Error while updating \(site.name, privacy: .public): \(error.localizedDescription, privacy: .public)")
} }
} }
} }