Force Proxy to any Windows/MacOS/Linux Application TCP and UDP traffic
C ccybersecurityhttp3httpproxylinuxlinux-proxymacosmacos-appmacos-proxyproxifierproxifier-alternativeproxyclienttcpthick-clientudpwindivertwindows
added update checker - Pending test
Sourav Kalal92716392074d
diff --git a/MacOS/ProxyBridge/ProxyBridge/ProxyBridgeGUI.swift b/MacOS/ProxyBridge/ProxyBridge/ProxyBridgeGUI.swiftindex 47470d5..0e2a1fe 100644--- a/MacOS/ProxyBridge/ProxyBridge/ProxyBridgeGUI.swift+++ b/MacOS/ProxyBridge/ProxyBridge/ProxyBridgeGUI.swift@@ -10,6 +10,7 @@ struct ProxyBridgeGUIApp: App {ContentView(viewModel: viewModel).onAppear {AppDelegate.viewModel = viewModel+ checkForUpdatesOnStartup()}}.windowStyle(.hiddenTitleBar)@@ -29,6 +30,12 @@ struct ProxyBridgeGUIApp: App {}CommandGroup(replacing: .help) {+ Button("Check for Updates...") {+ openUpdateCheckWindow()+ }++ Divider()+Button("About ProxyBridge") {openAboutWindow()}@@ -53,6 +60,12 @@ struct ProxyBridgeGUIApp: App {}.windowResizability(.contentSize).defaultPosition(.center)++ Window("Check for Updates", id: "update-check") {+ UpdateCheckView()+ }+ .windowResizability(.contentSize)+ .defaultPosition(.center)}private func openProxySettingsWindow() {@@ -66,10 +79,33 @@ struct ProxyBridgeGUIApp: App {private func openAboutWindow() {NSApp.sendAction(#selector(AppDelegate.openAbout), to: nil, from: nil)}++ private func openUpdateCheckWindow() {+ NSApp.sendAction(#selector(AppDelegate.openUpdateCheck), to: nil, from: nil)+ }++ private func checkForUpdatesOnStartup() {+ let shouldCheck = UserDefaults.standard.object(forKey: "checkForUpdatesOnStartup") as? Bool ?? true++ if shouldCheck {+ Task {+ let updateService = UpdateService()+ let versionInfo = await updateService.checkForUpdates()++ if versionInfo.isUpdateAvailable {+ await MainActor.run {+ AppDelegate.pendingUpdateInfo = versionInfo+ NSApp.sendAction(#selector(AppDelegate.showUpdateNotification(_:)), to: nil, from: nil)+ }+ }+ }+ }+ }}class AppDelegate: NSObject, NSApplicationDelegate {static var viewModel: ProxyBridgeViewModel?+ static var pendingUpdateInfo: VersionInfo?func applicationWillTerminate(_ notification: Notification) {AppDelegate.viewModel?.stopProxy()@@ -93,6 +129,21 @@ class AppDelegate: NSObject, NSApplicationDelegate {}}+ @objc func openUpdateCheck() {+ openWindow(title: "Check for Updates", size: NSSize(width: 450, height: 300)) {+ UpdateCheckView()+ }+ }++ @objc func showUpdateNotification(_ sender: Any?) {+ if let versionInfo = AppDelegate.pendingUpdateInfo {+ openWindow(title: "Update Available", size: NSSize(width: 450, height: 350)) {+ UpdateNotificationView(versionInfo: versionInfo)+ }+ AppDelegate.pendingUpdateInfo = nil+ }+ }+private func openWindow<Content: View>(title: String,size: NSSize,diff --git a/MacOS/ProxyBridge/ProxyBridge/UpdateCheckView.swift b/MacOS/ProxyBridge/ProxyBridge/UpdateCheckView.swiftnew file mode 100644index 0000000..37d945b--- /dev/null+++ b/MacOS/ProxyBridge/ProxyBridge/UpdateCheckView.swift@@ -0,0 +1,196 @@+import SwiftUI+import Combine++struct UpdateCheckView: View {+ @Environment(\.dismiss) private var dismiss+ @StateObject private var viewModel = UpdateCheckViewModel()++ var body: some View {+ VStack(spacing: 20) {+ // Header+ Text("Check for Updates")+ .font(.title2)+ .fontWeight(.semibold)++ Divider()++ // Version Info+ VStack(spacing: 12) {+ HStack {+ Text("Current Version:")+ .fontWeight(.medium)+ Spacer()+ Text(viewModel.currentVersion)+ .foregroundColor(.secondary)+ }++ HStack {+ Text("Latest Version:")+ .fontWeight(.medium)+ Spacer()+ Text(viewModel.latestVersion)+ .foregroundColor(viewModel.latestVersionColor)+ }+ }+ .padding(.horizontal)++ // Status Message+ if !viewModel.statusMessage.isEmpty {+ HStack {+ Image(systemName: viewModel.isUpdateAvailable ? "arrow.down.circle.fill" : "checkmark.circle.fill")+ .foregroundColor(viewModel.statusColor)+ Text(viewModel.statusMessage)+ .foregroundColor(viewModel.statusColor)+ .fontWeight(.medium)+ }+ .padding(.horizontal)+ }++ // Error Message+ if viewModel.hasError {+ Text(viewModel.errorMessage)+ .foregroundColor(.red)+ .font(.caption)+ .multilineTextAlignment(.center)+ .padding(.horizontal)+ }++ // Progress+ if viewModel.isChecking {+ ProgressView("Checking for updates...")+ .padding()+ } else if viewModel.isDownloading {+ VStack(spacing: 8) {+ ProgressView(value: viewModel.downloadProgress, total: 1.0)+ .progressViewStyle(.linear)+ Text(viewModel.downloadStatus)+ .font(.caption)+ .foregroundColor(.secondary)+ }+ .padding(.horizontal)+ }++ Spacer()++ // Buttons+ HStack(spacing: 12) {+ if viewModel.isUpdateAvailable && !viewModel.isDownloading {+ Button("Download Now") {+ Task {+ await viewModel.downloadAndInstall()+ }+ }+ .controlSize(.large)+ }++ if !viewModel.isChecking && !viewModel.isDownloading {+ Button("Check Again") {+ Task {+ await viewModel.checkForUpdates()+ }+ }+ }++ Button(viewModel.isDownloading ? "Cancel" : "Close") {+ dismiss()+ }+ .keyboardShortcut(.cancelAction)+ .disabled(viewModel.isDownloading)+ }+ }+ .padding()+ .frame(width: 450, height: 300)+ .task {+ await viewModel.checkForUpdates()+ }+ }+}++@MainActor+class UpdateCheckViewModel: ObservableObject {+ @Published var currentVersion = ""+ @Published var latestVersion = ""+ @Published var statusMessage = ""+ @Published var statusColor = Color.secondary+ @Published var latestVersionColor = Color.secondary+ @Published var errorMessage = ""+ @Published var isChecking = false+ @Published var hasError = false+ @Published var isUpdateAvailable = false+ @Published var isDownloading = false+ @Published var downloadProgress: Double = 0+ @Published var downloadStatus = ""++ private let updateService = UpdateService()+ private var versionInfo: VersionInfo?++ func checkForUpdates() async {+ isChecking = true+ hasError = false+ statusMessage = ""+ errorMessage = ""++ let info = await updateService.checkForUpdates()+ versionInfo = info++ currentVersion = info.currentVersion+ latestVersion = info.latestVersion+ isUpdateAvailable = info.isUpdateAvailable++ if let error = info.error {+ hasError = true+ errorMessage = error+ statusMessage = "Unable to check for updates"+ statusColor = .red+ latestVersionColor = .red+ } else if info.isUpdateAvailable {+ statusMessage = "New version available!"+ statusColor = .green+ latestVersionColor = .green+ } else {+ statusMessage = "You have the latest version"+ statusColor = .green+ latestVersionColor = .blue+ }++ isChecking = false+ }++ func downloadAndInstall() async {+ guard let info = versionInfo,+ let downloadUrl = info.downloadUrl,+ let fileName = info.fileName else {+ errorMessage = "Download URL not available"+ hasError = true+ return+ }++ isDownloading = true+ downloadProgress = 0+ downloadStatus = "Starting download..."+ hasError = false+ errorMessage = ""++ do {+ let installerPath = try await updateService.downloadUpdate(+ from: downloadUrl,+ fileName: fileName+ ) { progress in+ Task { @MainActor in+ self.downloadProgress = progress+ self.downloadStatus = String(format: "Downloading... %.0f%%", progress * 100)+ }+ }++ downloadStatus = "Download complete. Starting installer..."+ try await Task.sleep(nanoseconds: 1_000_000_000) // 1 second delay++ updateService.installUpdateAndQuit(installerPath: installerPath)+ } catch {+ hasError = true+ errorMessage = "Download error: \(error.localizedDescription)"+ downloadStatus = "Download failed"+ isDownloading = false+ }+ }+}diff --git a/MacOS/ProxyBridge/ProxyBridge/UpdateNotificationView.swift b/MacOS/ProxyBridge/ProxyBridge/UpdateNotificationView.swiftnew file mode 100644index 0000000..d2a20ad--- /dev/null+++ b/MacOS/ProxyBridge/ProxyBridge/UpdateNotificationView.swift@@ -0,0 +1,165 @@+import SwiftUI+import Combine++struct UpdateNotificationView: View {+ @Environment(\.dismiss) private var dismiss+ let versionInfo: VersionInfo+ @StateObject private var viewModel: UpdateNotificationViewModel++ init(versionInfo: VersionInfo) {+ self.versionInfo = versionInfo+ _viewModel = StateObject(wrappedValue: UpdateNotificationViewModel(versionInfo: versionInfo))+ }++ var body: some View {+ VStack(spacing: 20) {+ // Icon and Title+ VStack(spacing: 12) {+ Image(systemName: "arrow.down.circle.fill")+ .font(.system(size: 50))+ .foregroundColor(.blue)++ Text("Update Available")+ .font(.title2)+ .fontWeight(.bold)+ }++ Divider()++ // Version Information+ VStack(spacing: 10) {+ HStack {+ Text("Current Version:")+ .fontWeight(.medium)+ Spacer()+ Text(versionInfo.currentVersion)+ .foregroundColor(.secondary)+ }++ HStack {+ Text("New Version:")+ .fontWeight(.medium)+ Spacer()+ Text(versionInfo.latestVersion)+ .foregroundColor(.green)+ .fontWeight(.semibold)+ }+ }+ .padding(.horizontal)++ Text("A new version of ProxyBridge is available!")+ .multilineTextAlignment(.center)+ .foregroundColor(.secondary)++ // Download Progress+ if viewModel.isDownloading {+ VStack(spacing: 8) {+ ProgressView(value: viewModel.downloadProgress, total: 1.0)+ .progressViewStyle(.linear)+ Text(viewModel.downloadStatus)+ .font(.caption)+ .foregroundColor(.secondary)+ }+ .padding(.horizontal)+ }++ // Error Message+ if viewModel.hasError {+ Text(viewModel.errorMessage)+ .foregroundColor(.red)+ .font(.caption)+ .multilineTextAlignment(.center)+ .padding(.horizontal)+ }++ Spacer()++ // Action Buttons+ if !viewModel.isDownloading {+ HStack(spacing: 12) {+ Button("Don't Ask Again") {+ viewModel.dontAskAgain()+ dismiss()+ }++ Button("Later") {+ dismiss()+ }+ .keyboardShortcut(.cancelAction)++ Button("Update Now") {+ Task {+ await viewModel.downloadAndInstall()+ }+ }+ .keyboardShortcut(.defaultAction)+ .controlSize(.large)+ }+ } else {+ Button("Cancel") {+ dismiss()+ }+ .disabled(true)+ }+ }+ .padding()+ .frame(width: 450, height: 350)+ }+}++@MainActor+class UpdateNotificationViewModel: ObservableObject {+ @Published var downloadStatus = ""+ @Published var errorMessage = ""+ @Published var downloadProgress: Double = 0+ @Published var isDownloading = false+ @Published var hasError = false++ private let updateService = UpdateService()+ private let versionInfo: VersionInfo++ init(versionInfo: VersionInfo) {+ self.versionInfo = versionInfo+ }++ func downloadAndInstall() async {+ guard let downloadUrl = versionInfo.downloadUrl,+ let fileName = versionInfo.fileName else {+ hasError = true+ errorMessage = "Download URL not available"+ return+ }++ isDownloading = true+ downloadProgress = 0+ downloadStatus = "Starting download..."+ hasError = false+ errorMessage = ""++ do {+ let installerPath = try await updateService.downloadUpdate(+ from: downloadUrl,+ fileName: fileName+ ) { progress in+ Task { @MainActor in+ self.downloadProgress = progress+ self.downloadStatus = String(format: "Downloading... %.0f%%", progress * 100)+ }+ }++ downloadStatus = "Download complete. Starting installer..."+ try await Task.sleep(nanoseconds: 1_000_000_000)++ updateService.installUpdateAndQuit(installerPath: installerPath)+ } catch {+ hasError = true+ errorMessage = "Error downloading update: \(error.localizedDescription)"+ downloadStatus = "Download failed"+ isDownloading = false+ }+ }++ func dontAskAgain() {+ UserDefaults.standard.set(false, forKey: "checkForUpdatesOnStartup")+ }+}diff --git a/MacOS/ProxyBridge/ProxyBridge/UpdateService.swift b/MacOS/ProxyBridge/ProxyBridge/UpdateService.swiftnew file mode 100644index 0000000..caba7bb--- /dev/null+++ b/MacOS/ProxyBridge/ProxyBridge/UpdateService.swift@@ -0,0 +1,165 @@+import Foundation+import AppKit++struct GitHubRelease: Codable {+ let tagName: String+ let name: String+ let prerelease: Bool+ let publishedAt: String+ let assets: [GitHubAsset]++ enum CodingKeys: String, CodingKey {+ case tagName = "tag_name"+ case name+ case prerelease+ case publishedAt = "published_at"+ case assets+ }+}++struct GitHubAsset: Codable {+ let name: String+ let browserDownloadUrl: String+ let size: Int64++ enum CodingKeys: String, CodingKey {+ case name+ case browserDownloadUrl = "browser_download_url"+ case size+ }+}++struct VersionInfo {+ let currentVersion: String+ let latestVersion: String+ let isUpdateAvailable: Bool+ let downloadUrl: String?+ let fileName: String?+ let error: String?+}++class UpdateService {+ private let githubApiUrl = "https://api.github.com/repos/InterceptSuite/ProxyBridge/releases/latest"++ func checkForUpdates() async -> VersionInfo {+ do {+ guard let url = URL(string: githubApiUrl) else {+ return errorVersion("Invalid API URL")+ }++ var request = URLRequest(url: url)+ request.setValue("ProxyBridge-UpdateChecker", forHTTPHeaderField: "User-Agent")++ let (data, _) = try await URLSession.shared.data(for: request)+ let release = try JSONDecoder().decode(GitHubRelease.self, from: data)++ let currentVersion = getCurrentVersion()+ let latestVersion = parseVersion(release.tagName)++ // Find the PKG installer in assets+ let pkgAsset = release.assets.first { asset in+ asset.name.lowercased().hasSuffix(".pkg") &&+ (asset.name.lowercased().contains("proxybridge") ||+ asset.name.lowercased().contains("installer"))+ }++ return VersionInfo(+ currentVersion: currentVersion,+ latestVersion: release.tagName,+ isUpdateAvailable: isNewerVersion(latestVersion, currentVersion),+ downloadUrl: pkgAsset?.browserDownloadUrl,+ fileName: pkgAsset?.name,+ error: nil+ )+ } catch {+ return errorVersion("Failed to check for updates: \(error.localizedDescription)")+ }+ }++ func downloadUpdate(from urlString: String, fileName: String, progress: @escaping (Double) -> Void) async throws -> URL {+ guard let url = URL(string: urlString) else {+ throw NSError(domain: "UpdateService", code: -1, userInfo: [NSLocalizedDescriptionKey: "Invalid download URL"])+ }++ let (asyncBytes, response) = try await URLSession.shared.bytes(from: url)++ guard let httpResponse = response as? HTTPURLResponse,+ httpResponse.statusCode == 200 else {+ throw NSError(domain: "UpdateService", code: -1, userInfo: [NSLocalizedDescriptionKey: "Download failed"])+ }++ let totalBytes = response.expectedContentLength+ let tempDir = FileManager.default.temporaryDirectory+ let fileURL = tempDir.appendingPathComponent(fileName)++ // Remove existing file if any+ try? FileManager.default.removeItem(at: fileURL)++ var downloadedBytes: Int64 = 0+ let data = NSMutableData()++ for try await byte in asyncBytes {+ var byteValue = byte+ data.append(&byteValue, length: 1)+ downloadedBytes += 1++ if totalBytes > 0 {+ let progressValue = Double(downloadedBytes) / Double(totalBytes)+ await MainActor.run {+ progress(progressValue)+ }+ }+ }++ try data.write(to: fileURL)+ return fileURL+ }++ func installUpdateAndQuit(installerPath: URL) {+ // Open the PKG installer+ NSWorkspace.shared.open(installerPath)++ // Give the installer a moment to start, then quit+ DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {+ NSApplication.shared.terminate(nil)+ }+ }++ private func getCurrentVersion() -> String {+ if let version = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String {+ return "v\(version)"+ }+ return "v3.0"+ }++ private func parseVersion(_ tagName: String) -> String {+ return tagName.hasPrefix("v") ? String(tagName.dropFirst()) : tagName+ }++ private func isNewerVersion(_ latest: String, _ current: String) -> Bool {+ let latestComponents = latest.split(separator: ".").compactMap { Int($0) }+ let currentVersionString = current.hasPrefix("v") ? String(current.dropFirst()) : current+ let currentComponents = currentVersionString.split(separator: ".").compactMap { Int($0) }++ for i in 0..<min(latestComponents.count, currentComponents.count) {+ if latestComponents[i] > currentComponents[i] {+ return true+ } else if latestComponents[i] < currentComponents[i] {+ return false+ }+ }++ return latestComponents.count > currentComponents.count+ }++ private func errorVersion(_ message: String) -> VersionInfo {+ return VersionInfo(+ currentVersion: getCurrentVersion(),+ latestVersion: "Error",+ isUpdateAvailable: false,+ downloadUrl: nil,+ fileName: nil,+ error: message+ )+ }+}