From f65126391549ab7e3a67b74a65ea2e8c786eeb83 Mon Sep 17 00:00:00 2001 From: Alexandru Tudose Date: Fri, 27 Oct 2017 15:23:44 +0300 Subject: [PATCH 001/110] Added mac os x demo app. --- netfox.xcodeproj/project.pbxproj | 152 +++- netfox/Core/NFXHelper.swift | 7 +- netfox/OSX/NFXListCell_OSX.xib | 17 +- netfox/OSX/NFXListController_OSX.swift | 3 +- netfox/OSX/NFXSettingsController_OSX.swift | 3 +- netfox/OSX/NetfoxWindow.xib | 100 ++- netfox_mac/AppDelegate.swift | 33 + .../AppIcon.appiconset/Contents.json | 58 ++ netfox_mac/Base.lproj/MainMenu.xib | 678 ++++++++++++++++++ netfox_mac/Info.plist | 32 + netfox_mac/netfox_mac.entitlements | 10 + 11 files changed, 1023 insertions(+), 70 deletions(-) mode change 100644 => 100755 netfox.xcodeproj/project.pbxproj mode change 100644 => 100755 netfox/OSX/NFXListCell_OSX.xib mode change 100644 => 100755 netfox/OSX/NFXListController_OSX.swift mode change 100644 => 100755 netfox/OSX/NFXSettingsController_OSX.swift mode change 100644 => 100755 netfox/OSX/NetfoxWindow.xib create mode 100644 netfox_mac/AppDelegate.swift create mode 100644 netfox_mac/Assets.xcassets/AppIcon.appiconset/Contents.json create mode 100644 netfox_mac/Base.lproj/MainMenu.xib create mode 100644 netfox_mac/Info.plist create mode 100644 netfox_mac/netfox_mac.entitlements diff --git a/netfox.xcodeproj/project.pbxproj b/netfox.xcodeproj/project.pbxproj old mode 100644 new mode 100755 index eb6c4c26..03869d94 --- a/netfox.xcodeproj/project.pbxproj +++ b/netfox.xcodeproj/project.pbxproj @@ -7,6 +7,10 @@ objects = { /* Begin PBXBuildFile section */ + 234DBCD61FA33BD90086CB79 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 234DBCD51FA33BD90086CB79 /* AppDelegate.swift */; }; + 234DBCD81FA33BD90086CB79 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 234DBCD71FA33BD90086CB79 /* Assets.xcassets */; }; + 234DBCDB1FA33BD90086CB79 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 234DBCD91FA33BD90086CB79 /* MainMenu.xib */; }; + 234DBCE11FA33BFE0086CB79 /* netfox_osx.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E20FD2E91C6912D400DCFF61 /* netfox_osx.framework */; }; 8229AD651F8FB34300A9D613 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8229AD641F8FB34300A9D613 /* AppDelegate.swift */; }; 8229AD671F8FB34300A9D613 /* ImageViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8229AD661F8FB34300A9D613 /* ImageViewController.swift */; }; 8229AD6A1F8FB34300A9D613 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 8229AD681F8FB34300A9D613 /* Main.storyboard */; }; @@ -71,6 +75,13 @@ /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ + 234DBCE21FA33D980086CB79 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = B3BC02061C09CDA000C17F3A /* Project object */; + proxyType = 1; + remoteGlobalIDString = E20FD2E81C6912D400DCFF61; + remoteInfo = netfox_osx; + }; 8229AD741F8FB37000A9D613 /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = B3BC02061C09CDA000C17F3A /* Project object */; @@ -81,6 +92,12 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ + 234DBCD31FA33BD90086CB79 /* netfox_mac.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = netfox_mac.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 234DBCD51FA33BD90086CB79 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; + 234DBCD71FA33BD90086CB79 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; + 234DBCDA1FA33BD90086CB79 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/MainMenu.xib; sourceTree = ""; }; + 234DBCDC1FA33BD90086CB79 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 234DBCDD1FA33BD90086CB79 /* netfox_mac.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = netfox_mac.entitlements; sourceTree = ""; }; 8229AD621F8FB34300A9D613 /* netfox_ios_demo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = netfox_ios_demo.app; sourceTree = BUILT_PRODUCTS_DIR; }; 8229AD641F8FB34300A9D613 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 8229AD661F8FB34300A9D613 /* ImageViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageViewController.swift; sourceTree = ""; }; @@ -131,6 +148,14 @@ /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ + 234DBCD01FA33BD90086CB79 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 234DBCE11FA33BFE0086CB79 /* netfox_osx.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; 8229AD5F1F8FB34300A9D613 /* Frameworks */ = { isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; @@ -156,6 +181,18 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 234DBCD41FA33BD90086CB79 /* netfox_mac */ = { + isa = PBXGroup; + children = ( + 234DBCD51FA33BD90086CB79 /* AppDelegate.swift */, + 234DBCD71FA33BD90086CB79 /* Assets.xcassets */, + 234DBCD91FA33BD90086CB79 /* MainMenu.xib */, + 234DBCDC1FA33BD90086CB79 /* Info.plist */, + 234DBCDD1FA33BD90086CB79 /* netfox_mac.entitlements */, + ); + path = netfox_mac; + sourceTree = ""; + }; 8229AD631F8FB34300A9D613 /* netfox_ios_demo */ = { isa = PBXGroup; children = ( @@ -183,6 +220,7 @@ children = ( CEFE42B41C0DDBD8001A56E0 /* netfox */, 8229AD631F8FB34300A9D613 /* netfox_ios_demo */, + 234DBCD41FA33BD90086CB79 /* netfox_mac */, B3BC02101C09CDA000C17F3A /* Products */, 8229AD761F8FB4B500A9D613 /* Frameworks */, ); @@ -194,6 +232,7 @@ B3BC020F1C09CDA000C17F3A /* netfox_ios.framework */, E20FD2E91C6912D400DCFF61 /* netfox_osx.framework */, 8229AD621F8FB34300A9D613 /* netfox_ios_demo.app */, + 234DBCD31FA33BD90086CB79 /* netfox_mac.app */, ); name = Products; sourceTree = ""; @@ -286,6 +325,24 @@ /* End PBXHeadersBuildPhase section */ /* Begin PBXNativeTarget section */ + 234DBCD21FA33BD90086CB79 /* netfox_mac */ = { + isa = PBXNativeTarget; + buildConfigurationList = 234DBCE01FA33BD90086CB79 /* Build configuration list for PBXNativeTarget "netfox_mac" */; + buildPhases = ( + 234DBCCF1FA33BD90086CB79 /* Sources */, + 234DBCD01FA33BD90086CB79 /* Frameworks */, + 234DBCD11FA33BD90086CB79 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + 234DBCE31FA33D980086CB79 /* PBXTargetDependency */, + ); + name = netfox_mac; + productName = netfox_mac; + productReference = 234DBCD31FA33BD90086CB79 /* netfox_mac.app */; + productType = "com.apple.product-type.application"; + }; 8229AD611F8FB34300A9D613 /* netfox_ios_demo */ = { isa = PBXNativeTarget; buildConfigurationList = 8229AD711F8FB34300A9D613 /* Build configuration list for PBXNativeTarget "netfox_ios_demo" */; @@ -346,10 +403,14 @@ B3BC02061C09CDA000C17F3A /* Project object */ = { isa = PBXProject; attributes = { - LastSwiftUpdateCheck = 0720; + LastSwiftUpdateCheck = 0900; LastUpgradeCheck = 0900; ORGANIZATIONNAME = kasketis; TargetAttributes = { + 234DBCD21FA33BD90086CB79 = { + CreatedOnToolsVersion = 9.0.1; + ProvisioningStyle = Automatic; + }; 8229AD611F8FB34300A9D613 = { CreatedOnToolsVersion = 9.0; ProvisioningStyle = Automatic; @@ -380,11 +441,21 @@ B3BC020E1C09CDA000C17F3A /* netfox_ios */, E20FD2E81C6912D400DCFF61 /* netfox_osx */, 8229AD611F8FB34300A9D613 /* netfox_ios_demo */, + 234DBCD21FA33BD90086CB79 /* netfox_mac */, ); }; /* End PBXProject section */ /* Begin PBXResourcesBuildPhase section */ + 234DBCD11FA33BD90086CB79 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 234DBCD81FA33BD90086CB79 /* Assets.xcassets in Resources */, + 234DBCDB1FA33BD90086CB79 /* MainMenu.xib in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; 8229AD601F8FB34300A9D613 /* Resources */ = { isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; @@ -415,6 +486,14 @@ /* End PBXResourcesBuildPhase section */ /* Begin PBXSourcesBuildPhase section */ + 234DBCCF1FA33BD90086CB79 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 234DBCD61FA33BD90086CB79 /* AppDelegate.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; 8229AD5E1F8FB34300A9D613 /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; @@ -492,6 +571,11 @@ /* End PBXSourcesBuildPhase section */ /* Begin PBXTargetDependency section */ + 234DBCE31FA33D980086CB79 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = E20FD2E81C6912D400DCFF61 /* netfox_osx */; + targetProxy = 234DBCE21FA33D980086CB79 /* PBXContainerItemProxy */; + }; 8229AD751F8FB37000A9D613 /* PBXTargetDependency */ = { isa = PBXTargetDependency; target = B3BC020E1C09CDA000C17F3A /* netfox_ios */; @@ -500,6 +584,14 @@ /* End PBXTargetDependency section */ /* Begin PBXVariantGroup section */ + 234DBCD91FA33BD90086CB79 /* MainMenu.xib */ = { + isa = PBXVariantGroup; + children = ( + 234DBCDA1FA33BD90086CB79 /* Base */, + ); + name = MainMenu.xib; + sourceTree = ""; + }; 8229AD681F8FB34300A9D613 /* Main.storyboard */ = { isa = PBXVariantGroup; children = ( @@ -519,6 +611,55 @@ /* End PBXVariantGroup section */ /* Begin XCBuildConfiguration section */ + 234DBCDE1FA33BD90086CB79 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CODE_SIGN_ENTITLEMENTS = netfox_mac/netfox_mac.entitlements; + CODE_SIGN_IDENTITY = "-"; + CODE_SIGN_STYLE = Automatic; + COMBINE_HIDPI_IMAGES = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + INFOPLIST_FILE = netfox_mac/Info.plist; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; + MACOSX_DEPLOYMENT_TARGET = 10.13; + PRODUCT_BUNDLE_IDENTIFIER = "com.tapptitude.netfox-mac"; + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = macosx; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; + SWIFT_VERSION = 4.0; + }; + name = Debug; + }; + 234DBCDF1FA33BD90086CB79 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CODE_SIGN_ENTITLEMENTS = netfox_mac/netfox_mac.entitlements; + CODE_SIGN_IDENTITY = "-"; + CODE_SIGN_STYLE = Automatic; + COMBINE_HIDPI_IMAGES = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + INFOPLIST_FILE = netfox_mac/Info.plist; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; + MACOSX_DEPLOYMENT_TARGET = 10.13; + PRODUCT_BUNDLE_IDENTIFIER = "com.tapptitude.netfox-mac"; + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = macosx; + SWIFT_VERSION = 4.0; + }; + name = Release; + }; 8229AD721F8FB34300A9D613 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { @@ -779,6 +920,15 @@ /* End XCBuildConfiguration section */ /* Begin XCConfigurationList section */ + 234DBCE01FA33BD90086CB79 /* Build configuration list for PBXNativeTarget "netfox_mac" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 234DBCDE1FA33BD90086CB79 /* Debug */, + 234DBCDF1FA33BD90086CB79 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; 8229AD711F8FB34300A9D613 /* Build configuration list for PBXNativeTarget "netfox_ios_demo" */ = { isa = XCConfigurationList; buildConfigurations = ( diff --git a/netfox/Core/NFXHelper.swift b/netfox/Core/NFXHelper.swift index 6f2634dc..490e34f2 100644 --- a/netfox/Core/NFXHelper.swift +++ b/netfox/Core/NFXHelper.swift @@ -301,7 +301,12 @@ class NFXDebugInfo let session = URLSession.shared session.dataTask(with: req as URLRequest, completionHandler: { (data, response, error) in do { - let rawJsonData = try JSONSerialization.jsonObject(with: data!, options: [.allowFragments]) + guard let data = data else { + completion("-") + return + } + + let rawJsonData = try JSONSerialization.jsonObject(with: data, options: [.allowFragments]) if let ipAddress = (rawJsonData as AnyObject).value(forKey: "ip") { completion(ipAddress as! String) } else { diff --git a/netfox/OSX/NFXListCell_OSX.xib b/netfox/OSX/NFXListCell_OSX.xib old mode 100644 new mode 100755 index f124b830..e866dba4 --- a/netfox/OSX/NFXListCell_OSX.xib +++ b/netfox/OSX/NFXListCell_OSX.xib @@ -1,14 +1,15 @@ - - + + - + + - + @@ -18,7 +19,7 @@ - + @@ -26,7 +27,7 @@ - + @@ -65,7 +66,7 @@ - + @@ -73,7 +74,7 @@ - + diff --git a/netfox/OSX/NFXListController_OSX.swift b/netfox/OSX/NFXListController_OSX.swift old mode 100644 new mode 100755 index 8ca18088..c632484a --- a/netfox/OSX/NFXListController_OSX.swift +++ b/netfox/OSX/NFXListController_OSX.swift @@ -24,7 +24,8 @@ class NFXListController_OSX: NFXListController, NSTableViewDelegate, NSTableView // MARK: View Life Cycle override func awakeFromNib() { - tableView.register(NSNib(nibNamed: NSNib.Name(rawValue: cellIdentifier), bundle: nil), forIdentifier: NSUserInterfaceItemIdentifier(rawValue: cellIdentifier)) + let bundle = Bundle(for: type(of: self)) + tableView.register(NSNib(nibNamed: NSNib.Name(rawValue: cellIdentifier), bundle: bundle), forIdentifier: NSUserInterfaceItemIdentifier(rawValue: cellIdentifier)) searchField.delegate = self NotificationCenter.default.addObserver(self, selector: #selector(NFXListController.reloadTableViewData), name: NSNotification.Name(rawValue: "NFXReloadData"), object: nil) diff --git a/netfox/OSX/NFXSettingsController_OSX.swift b/netfox/OSX/NFXSettingsController_OSX.swift old mode 100644 new mode 100755 index f2926db2..625751af --- a/netfox/OSX/NFXSettingsController_OSX.swift +++ b/netfox/OSX/NFXSettingsController_OSX.swift @@ -25,7 +25,8 @@ class NFXSettingsController_OSX: NFXSettingsController, NSTableViewDataSource, N nfxVersionLabel.stringValue = nfxVersionString nfxURLButton.title = nfxURL - responseTypesTableView.register(NSNib(nibNamed: NSNib.Name(rawValue: cellIdentifier), bundle: nil), forIdentifier: NSUserInterfaceItemIdentifier(rawValue: cellIdentifier)) + let bundle = Bundle(for: type(of:self)) + responseTypesTableView.register(NSNib(nibNamed: NSNib.Name(rawValue: cellIdentifier), bundle: bundle), forIdentifier: NSUserInterfaceItemIdentifier(rawValue: cellIdentifier)) reloadTableData() } diff --git a/netfox/OSX/NetfoxWindow.xib b/netfox/OSX/NetfoxWindow.xib old mode 100644 new mode 100755 index 77305834..9afa3a3a --- a/netfox/OSX/NetfoxWindow.xib +++ b/netfox/OSX/NetfoxWindow.xib @@ -1,8 +1,9 @@ - - + + - + + @@ -31,7 +32,7 @@ - + @@ -97,11 +98,8 @@ - + - - - @@ -110,13 +108,13 @@ - + - + @@ -135,6 +133,7 @@ + @@ -155,7 +154,6 @@ - - + @@ -250,17 +246,15 @@ - + - + - + - - @@ -270,7 +264,7 @@ - + @@ -292,17 +286,15 @@ - + - + - + - - @@ -312,7 +304,7 @@ - + @@ -334,17 +326,15 @@ - + - + - + - - @@ -354,7 +344,7 @@ - + @@ -376,17 +366,15 @@ - + - + - + - - @@ -396,7 +384,7 @@ - + @@ -435,7 +423,7 @@ - + @@ -486,13 +474,13 @@ - + - + @@ -511,6 +499,7 @@ + @@ -531,7 +520,6 @@ - @@ -640,15 +628,13 @@ - + - + - - @@ -662,7 +648,7 @@ - + @@ -696,15 +682,13 @@ - + - + - - @@ -718,7 +702,7 @@ - + diff --git a/netfox_mac/AppDelegate.swift b/netfox_mac/AppDelegate.swift new file mode 100644 index 00000000..7cd28816 --- /dev/null +++ b/netfox_mac/AppDelegate.swift @@ -0,0 +1,33 @@ +// +// AppDelegate.swift +// netfox_mac +// +// Created by Alexandru Tudose on 27/10/2017. +// Copyright © 2017 kasketis. All rights reserved. +// + +import Cocoa +import netfox_osx + +@NSApplicationMain +class AppDelegate: NSObject, NSApplicationDelegate { + + @IBOutlet weak var window: NSWindow! + + func applicationWillFinishLaunching(_ aNotification: Notification) { + + } + + func applicationDidFinishLaunching(_ aNotification: Notification) { + // Insert code here to initialize your application + NFX.sharedInstance().start() + NFX.sharedInstance().show() + } + + func applicationWillTerminate(_ aNotification: Notification) { + // Insert code here to tear down your application + } + + +} + diff --git a/netfox_mac/Assets.xcassets/AppIcon.appiconset/Contents.json b/netfox_mac/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 00000000..2db2b1c7 --- /dev/null +++ b/netfox_mac/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,58 @@ +{ + "images" : [ + { + "idiom" : "mac", + "size" : "16x16", + "scale" : "1x" + }, + { + "idiom" : "mac", + "size" : "16x16", + "scale" : "2x" + }, + { + "idiom" : "mac", + "size" : "32x32", + "scale" : "1x" + }, + { + "idiom" : "mac", + "size" : "32x32", + "scale" : "2x" + }, + { + "idiom" : "mac", + "size" : "128x128", + "scale" : "1x" + }, + { + "idiom" : "mac", + "size" : "128x128", + "scale" : "2x" + }, + { + "idiom" : "mac", + "size" : "256x256", + "scale" : "1x" + }, + { + "idiom" : "mac", + "size" : "256x256", + "scale" : "2x" + }, + { + "idiom" : "mac", + "size" : "512x512", + "scale" : "1x" + }, + { + "idiom" : "mac", + "size" : "512x512", + "scale" : "2x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/netfox_mac/Base.lproj/MainMenu.xib b/netfox_mac/Base.lproj/MainMenu.xib new file mode 100644 index 00000000..d5b10970 --- /dev/null +++ b/netfox_mac/Base.lproj/MainMenu.xib @@ -0,0 +1,678 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Default + + + + + + + Left to Right + + + + + + + Right to Left + + + + + + + + + + + Default + + + + + + + Left to Right + + + + + + + Right to Left + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/netfox_mac/Info.plist b/netfox_mac/Info.plist new file mode 100644 index 00000000..269d04e8 --- /dev/null +++ b/netfox_mac/Info.plist @@ -0,0 +1,32 @@ + + + + + CFBundleDevelopmentRegion + $(DEVELOPMENT_LANGUAGE) + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIconFile + + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + APPL + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + LSMinimumSystemVersion + $(MACOSX_DEPLOYMENT_TARGET) + NSHumanReadableCopyright + Copyright © 2017 kasketis. All rights reserved. + NSMainNibFile + MainMenu + NSPrincipalClass + NSApplication + + diff --git a/netfox_mac/netfox_mac.entitlements b/netfox_mac/netfox_mac.entitlements new file mode 100644 index 00000000..f2ef3ae0 --- /dev/null +++ b/netfox_mac/netfox_mac.entitlements @@ -0,0 +1,10 @@ + + + + + com.apple.security.app-sandbox + + com.apple.security.files.user-selected.read-only + + + From 7d6ef56ddf06f49fc58bf00f20b8228f0e6292f5 Mon Sep 17 00:00:00 2001 From: Alexandru Tudose Date: Mon, 30 Oct 2017 17:01:50 +0200 Subject: [PATCH 002/110] Swift 4 fixes. --- netfox/Core/NFXWindowController.swift | 6 +++--- netfox/OSX/NFXListCell_OSX.xib | 17 +++++++++-------- netfox/OSX/NFXListController_OSX.swift | 2 +- netfox/OSX/NFXSettingsController_OSX.swift | 12 ++++++------ netfox/OSX/NetfoxWindow.xib | 20 ++++++++++---------- 5 files changed, 29 insertions(+), 28 deletions(-) diff --git a/netfox/Core/NFXWindowController.swift b/netfox/Core/NFXWindowController.swift index aa4788e4..16249862 100644 --- a/netfox/Core/NFXWindowController.swift +++ b/netfox/Core/NFXWindowController.swift @@ -71,15 +71,15 @@ class NFXWindowController: NSWindowController, NSWindowDelegate, NFXWindowContro // MARK: Actions - @IBAction func settingsClicked(sender: AnyObject?) { + @IBAction func settingsClicked(_ sender: AnyObject?) { settingsPopover.show(relativeTo: NSZeroRect, of: settingsButton, preferredEdge: NSRectEdge.maxY) } - @IBAction func infoClicked(sender: AnyObject?) { + @IBAction func infoClicked(_ sender: AnyObject?) { infoPopover.show(relativeTo: NSZeroRect, of: infoButton, preferredEdge: NSRectEdge.maxY) } - @IBAction func statisticsClicked(sender: AnyObject?) { + @IBAction func statisticsClicked(_ sender: AnyObject?) { statisticsPopover.show(relativeTo: NSZeroRect, of: statisticsButton, preferredEdge: NSRectEdge.maxY) } diff --git a/netfox/OSX/NFXListCell_OSX.xib b/netfox/OSX/NFXListCell_OSX.xib index e866dba4..66a9cae9 100755 --- a/netfox/OSX/NFXListCell_OSX.xib +++ b/netfox/OSX/NFXListCell_OSX.xib @@ -10,7 +10,7 @@ - + @@ -53,15 +53,16 @@ - + - + - + - + + Multiline Label Multiline Label Multiline Label Multiline Label Multiline Label Multiline Label Multiline Label Multiline Label Multiline Label Multiline Label @@ -83,7 +84,7 @@ - + @@ -95,7 +96,7 @@ - + @@ -121,7 +122,7 @@ - + diff --git a/netfox/OSX/NFXListController_OSX.swift b/netfox/OSX/NFXListController_OSX.swift index c632484a..6ed8a598 100755 --- a/netfox/OSX/NFXListController_OSX.swift +++ b/netfox/OSX/NFXListController_OSX.swift @@ -65,7 +65,7 @@ class NFXListController_OSX: NFXListController, NSTableViewDelegate, NSTableView // MARK: UITableViewDataSource - func numberOfRowsInTableView(tableView: NSTableView) -> Int { + func numberOfRows(in tableView: NSTableView) -> Int { if (self.isSearchControllerActive) { return self.filteredTableData.count } else { diff --git a/netfox/OSX/NFXSettingsController_OSX.swift b/netfox/OSX/NFXSettingsController_OSX.swift index 625751af..6608c121 100755 --- a/netfox/OSX/NFXSettingsController_OSX.swift +++ b/netfox/OSX/NFXSettingsController_OSX.swift @@ -38,7 +38,7 @@ class NFXSettingsController_OSX: NFXSettingsController, NSTableViewDataSource, N // MARK: Actions - @IBAction func loggingButtonClicked(sender: NSButton) { + @IBAction func loggingButtonClicked(_ sender: NSButton) { if sender.state == .on { NFX.sharedInstance().enable() } else { @@ -46,16 +46,16 @@ class NFXSettingsController_OSX: NFXSettingsController, NSTableViewDataSource, N } } - @IBAction func clearDataClicked(sender: AnyObject?) { + @IBAction func clearDataClicked(_ sender: AnyObject?) { NFX.sharedInstance().clearOldData() NotificationCenter.default.post(name: NSNotification.Name(rawValue: "NFXReloadData"), object: nil) } - @IBAction func nfxURLButtonClicked(sender: NSButton) { + @IBAction func nfxURLButtonClicked(_ sender: NSButton) { NSWorkspace.shared.open(NSURL(string: nfxURL)! as URL) } - @IBAction func toggleResponseTypeClicked(sender: NSButton) { + @IBAction func toggleResponseTypeClicked(_ sender: NSButton) { filters[sender.tag] = !filters[sender.tag] NFX.sharedInstance().cacheFilters(filters) NotificationCenter.default.post(name: NSNotification.Name(rawValue: "NFXReloadData"), object: nil) @@ -69,7 +69,7 @@ class NFXSettingsController_OSX: NFXSettingsController, NSTableViewDataSource, N // MARK: Table View Delegate and DataSource - func numberOfRowsInTableView(tableView: NSTableView) -> Int { + func numberOfRows(in tableView: NSTableView) -> Int { return tableData.count } @@ -83,7 +83,7 @@ class NFXSettingsController_OSX: NFXSettingsController, NSTableViewDataSource, N cell.activeCheckbox.state = filters[row] ? .on : .off cell.activeCheckbox.tag = row cell.activeCheckbox.target = self - cell.activeCheckbox.action = #selector(toggleResponseTypeClicked(sender:)) + cell.activeCheckbox.action = #selector(toggleResponseTypeClicked(_:)) return cell } diff --git a/netfox/OSX/NetfoxWindow.xib b/netfox/OSX/NetfoxWindow.xib index 9afa3a3a..011547d6 100755 --- a/netfox/OSX/NetfoxWindow.xib +++ b/netfox/OSX/NetfoxWindow.xib @@ -202,17 +202,17 @@ - - + + - + - + - + @@ -224,7 +224,7 @@ - + @@ -429,7 +429,7 @@ - + @@ -471,7 +471,7 @@ - + @@ -626,7 +626,7 @@ - + @@ -680,7 +680,7 @@ - + From 2c156004588f6d11d242fdea10583f93b6f30b81 Mon Sep 17 00:00:00 2001 From: Alexandru Tudose Date: Mon, 30 Oct 2017 17:34:33 +0200 Subject: [PATCH 003/110] Serve netfox models over http. --- .gitignore | 131 +++++++++++----------- Podfile | 14 +++ Podfile.lock | 12 +++ netfox.xcodeproj/project.pbxproj | 167 +++++++++++++++++++++++++++++ netfox/Core/NFX.swift | 55 ++++++++++ netfox/Core/NFXHTTPModel.swift | 56 ++++++++++ netfox_mac/AppDelegate.swift | 30 +++++- netfox_mac/Info.plist | 5 + netfox_mac/netfox_mac.entitlements | 10 +- 9 files changed, 410 insertions(+), 70 deletions(-) create mode 100644 Podfile create mode 100644 Podfile.lock diff --git a/.gitignore b/.gitignore index dcd8c16b..25daaa64 100644 --- a/.gitignore +++ b/.gitignore @@ -1,65 +1,68 @@ -.DS_Store -*.xcuserdatad - -# Created by https://www.gitignore.io/api/xcode,osx - -### OSX ### -*.DS_Store -.AppleDouble -.LSOverride - -# Icon must end with two \r +.DS_Store +*.xcuserdatad + +# Created by https://www.gitignore.io/api/xcode,osx + +### OSX ### +*.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r Icon - -# Thumbnails -._* - -# Files that might appear in the root of a volume -.DocumentRevisions-V100 -.fseventsd -.Spotlight-V100 -.TemporaryItems -.Trashes -.VolumeIcon.icns -.com.apple.timemachine.donotpresent - -# Directories potentially created on remote AFP share -.AppleDB -.AppleDesktop -Network Trash Folder -Temporary Items -.apdisk - -### Xcode ### -# Xcode -# -# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore - -## Build generated -build/ -DerivedData/ - -## Various settings -*.pbxuser -!default.pbxuser -*.mode1v3 -!default.mode1v3 -*.mode2v3 -!default.mode2v3 -*.perspectivev3 -!default.perspectivev3 -xcuserdata/ - -## Other -*.moved-aside -*.xccheckout -*.xcscmblueprint - -### Xcode Patch ### -*.xcodeproj/* -!*.xcodeproj/project.pbxproj -!*.xcodeproj/xcshareddata/ -!*.xcworkspace/contents.xcworkspacedata -/*.gcno - -# End of https://www.gitignore.io/api/xcode,osx + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +### Xcode ### +# Xcode +# +# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore + +## Build generated +build/ +DerivedData/ + +## Various settings +*.pbxuser +!default.pbxuser +*.mode1v3 +!default.mode1v3 +*.mode2v3 +!default.mode2v3 +*.perspectivev3 +!default.perspectivev3 +xcuserdata/ + +## Other +*.moved-aside +*.xccheckout +*.xcscmblueprint + +### Xcode Patch ### +*.xcodeproj/* +!*.xcodeproj/project.pbxproj +!*.xcodeproj/xcshareddata/ +!*.xcworkspace/contents.xcworkspacedata +/*.gcno + +# End of https://www.gitignore.io/api/xcode,osx + +Pods/ +*.xcworkspace/ diff --git a/Podfile b/Podfile new file mode 100644 index 00000000..ef10659b --- /dev/null +++ b/Podfile @@ -0,0 +1,14 @@ +#platform :ios, '9.0' +use_frameworks! + +target 'netfox_ios' do + pod 'Swifter' +end + +target 'netfox_osx' do + pod 'Swifter' +end + +target 'netfox_mac' do + pod 'Swifter' +end diff --git a/Podfile.lock b/Podfile.lock new file mode 100644 index 00000000..4403b5fa --- /dev/null +++ b/Podfile.lock @@ -0,0 +1,12 @@ +PODS: + - Swifter (1.3.3) + +DEPENDENCIES: + - Swifter + +SPEC CHECKSUMS: + Swifter: 3fef6ec31449a8e3a29cf8551a9fe23485f15bc0 + +PODFILE CHECKSUM: 51d173693e74cf214adabef6425763321956a510 + +COCOAPODS: 1.3.1 diff --git a/netfox.xcodeproj/project.pbxproj b/netfox.xcodeproj/project.pbxproj index 03869d94..e5780cd4 100755 --- a/netfox.xcodeproj/project.pbxproj +++ b/netfox.xcodeproj/project.pbxproj @@ -11,6 +11,7 @@ 234DBCD81FA33BD90086CB79 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 234DBCD71FA33BD90086CB79 /* Assets.xcassets */; }; 234DBCDB1FA33BD90086CB79 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 234DBCD91FA33BD90086CB79 /* MainMenu.xib */; }; 234DBCE11FA33BFE0086CB79 /* netfox_osx.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E20FD2E91C6912D400DCFF61 /* netfox_osx.framework */; }; + 4288238379D4FFCA79F56095 /* Pods_netfox_osx.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = ACA8CED056B483F580B24412 /* Pods_netfox_osx.framework */; }; 8229AD651F8FB34300A9D613 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8229AD641F8FB34300A9D613 /* AppDelegate.swift */; }; 8229AD671F8FB34300A9D613 /* ImageViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8229AD661F8FB34300A9D613 /* ImageViewController.swift */; }; 8229AD6A1F8FB34300A9D613 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 8229AD681F8FB34300A9D613 /* Main.storyboard */; }; @@ -72,6 +73,8 @@ B3F8D6821C833B1700F9FBEA /* NFXResponseTypeCell_OSX.xib in Resources */ = {isa = PBXBuildFile; fileRef = B3F8D6781C833B1700F9FBEA /* NFXResponseTypeCell_OSX.xib */; }; B3F8D6831C833B1700F9FBEA /* NFXSettingsController_OSX.swift in Sources */ = {isa = PBXBuildFile; fileRef = B3F8D6791C833B1700F9FBEA /* NFXSettingsController_OSX.swift */; }; B3F8D6841C833B1700F9FBEA /* NFXStatisticsController_OSX.swift in Sources */ = {isa = PBXBuildFile; fileRef = B3F8D67A1C833B1700F9FBEA /* NFXStatisticsController_OSX.swift */; }; + C3B0FD99F1A684633A894676 /* Pods_netfox_ios.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 88412B0FEC6E00FC9E7BCDD3 /* Pods_netfox_ios.framework */; }; + D754AA6BB46409F670E8CC9A /* Pods_netfox_mac.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0080FF2CD0DC986CA9C85B89 /* Pods_netfox_mac.framework */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -92,12 +95,16 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ + 0080FF2CD0DC986CA9C85B89 /* Pods_netfox_mac.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_netfox_mac.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 234DBCD31FA33BD90086CB79 /* netfox_mac.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = netfox_mac.app; sourceTree = BUILT_PRODUCTS_DIR; }; 234DBCD51FA33BD90086CB79 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 234DBCD71FA33BD90086CB79 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 234DBCDA1FA33BD90086CB79 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/MainMenu.xib; sourceTree = ""; }; 234DBCDC1FA33BD90086CB79 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 234DBCDD1FA33BD90086CB79 /* netfox_mac.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = netfox_mac.entitlements; sourceTree = ""; }; + 2D8AAD7477115D8912E89F18 /* Pods-netfox_osx.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-netfox_osx.release.xcconfig"; path = "Pods/Target Support Files/Pods-netfox_osx/Pods-netfox_osx.release.xcconfig"; sourceTree = ""; }; + 4A183CD7E468F6A02AA4C6A6 /* Pods-netfox_ios.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-netfox_ios.debug.xcconfig"; path = "Pods/Target Support Files/Pods-netfox_ios/Pods-netfox_ios.debug.xcconfig"; sourceTree = ""; }; + 4F6DEF31CB10FADD0E630C4E /* Pods-netfox_ios.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-netfox_ios.release.xcconfig"; path = "Pods/Target Support Files/Pods-netfox_ios/Pods-netfox_ios.release.xcconfig"; sourceTree = ""; }; 8229AD621F8FB34300A9D613 /* netfox_ios_demo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = netfox_ios_demo.app; sourceTree = BUILT_PRODUCTS_DIR; }; 8229AD641F8FB34300A9D613 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 8229AD661F8FB34300A9D613 /* ImageViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageViewController.swift; sourceTree = ""; }; @@ -109,6 +116,9 @@ 826C4E9D1F979AB3008B440C /* NFXLoader.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NFXLoader.m; sourceTree = ""; }; 82F6E1021F8FD81C002B31BD /* TextViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextViewController.swift; sourceTree = ""; }; 82F6E1041F8FF55D002B31BD /* WebViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WebViewController.swift; sourceTree = ""; }; + 88412B0FEC6E00FC9E7BCDD3 /* Pods_netfox_ios.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_netfox_ios.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 9D2DF391029580C261E7189B /* Pods-netfox_mac.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-netfox_mac.release.xcconfig"; path = "Pods/Target Support Files/Pods-netfox_mac/Pods-netfox_mac.release.xcconfig"; sourceTree = ""; }; + ACA8CED056B483F580B24412 /* Pods_netfox_osx.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_netfox_osx.framework; sourceTree = BUILT_PRODUCTS_DIR; }; B3BC020F1C09CDA000C17F3A /* netfox_ios.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = netfox_ios.framework; sourceTree = BUILT_PRODUCTS_DIR; }; B3F8BA711C833ABC00F9FBEA /* NFX.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NFX.swift; sourceTree = ""; }; B3F8BA721C833ABC00F9FBEA /* NFXAssets.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NFXAssets.swift; sourceTree = ""; }; @@ -144,6 +154,8 @@ B3F8D6781C833B1700F9FBEA /* NFXResponseTypeCell_OSX.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = NFXResponseTypeCell_OSX.xib; sourceTree = ""; }; B3F8D6791C833B1700F9FBEA /* NFXSettingsController_OSX.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NFXSettingsController_OSX.swift; sourceTree = ""; }; B3F8D67A1C833B1700F9FBEA /* NFXStatisticsController_OSX.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NFXStatisticsController_OSX.swift; sourceTree = ""; }; + B40729489A21C5008AD68710 /* Pods-netfox_mac.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-netfox_mac.debug.xcconfig"; path = "Pods/Target Support Files/Pods-netfox_mac/Pods-netfox_mac.debug.xcconfig"; sourceTree = ""; }; + D43B421C0A67AEC706F6DA00 /* Pods-netfox_osx.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-netfox_osx.debug.xcconfig"; path = "Pods/Target Support Files/Pods-netfox_osx/Pods-netfox_osx.debug.xcconfig"; sourceTree = ""; }; E20FD2E91C6912D400DCFF61 /* netfox_osx.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = netfox_osx.framework; sourceTree = BUILT_PRODUCTS_DIR; }; /* End PBXFileReference section */ @@ -153,6 +165,7 @@ buildActionMask = 2147483647; files = ( 234DBCE11FA33BFE0086CB79 /* netfox_osx.framework in Frameworks */, + D754AA6BB46409F670E8CC9A /* Pods_netfox_mac.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -168,6 +181,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + C3B0FD99F1A684633A894676 /* Pods_netfox_ios.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -175,6 +189,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 4288238379D4FFCA79F56095 /* Pods_netfox_osx.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -193,6 +208,19 @@ path = netfox_mac; sourceTree = ""; }; + 4F26BEEC5880CE0F5CE688F7 /* Pods */ = { + isa = PBXGroup; + children = ( + 4A183CD7E468F6A02AA4C6A6 /* Pods-netfox_ios.debug.xcconfig */, + 4F6DEF31CB10FADD0E630C4E /* Pods-netfox_ios.release.xcconfig */, + B40729489A21C5008AD68710 /* Pods-netfox_mac.debug.xcconfig */, + 9D2DF391029580C261E7189B /* Pods-netfox_mac.release.xcconfig */, + D43B421C0A67AEC706F6DA00 /* Pods-netfox_osx.debug.xcconfig */, + 2D8AAD7477115D8912E89F18 /* Pods-netfox_osx.release.xcconfig */, + ); + name = Pods; + sourceTree = ""; + }; 8229AD631F8FB34300A9D613 /* netfox_ios_demo */ = { isa = PBXGroup; children = ( @@ -211,6 +239,9 @@ 8229AD761F8FB4B500A9D613 /* Frameworks */ = { isa = PBXGroup; children = ( + 88412B0FEC6E00FC9E7BCDD3 /* Pods_netfox_ios.framework */, + 0080FF2CD0DC986CA9C85B89 /* Pods_netfox_mac.framework */, + ACA8CED056B483F580B24412 /* Pods_netfox_osx.framework */, ); name = Frameworks; sourceTree = ""; @@ -223,6 +254,7 @@ 234DBCD41FA33BD90086CB79 /* netfox_mac */, B3BC02101C09CDA000C17F3A /* Products */, 8229AD761F8FB4B500A9D613 /* Frameworks */, + 4F26BEEC5880CE0F5CE688F7 /* Pods */, ); sourceTree = ""; }; @@ -329,9 +361,12 @@ isa = PBXNativeTarget; buildConfigurationList = 234DBCE01FA33BD90086CB79 /* Build configuration list for PBXNativeTarget "netfox_mac" */; buildPhases = ( + D8B74BF3E42DA4570C20ADF8 /* [CP] Check Pods Manifest.lock */, 234DBCCF1FA33BD90086CB79 /* Sources */, 234DBCD01FA33BD90086CB79 /* Frameworks */, 234DBCD11FA33BD90086CB79 /* Resources */, + E60DBB29C0B223A4CD7FA321 /* [CP] Embed Pods Frameworks */, + 6F29FEC6D1E533905FE377B5 /* [CP] Copy Pods Resources */, ); buildRules = ( ); @@ -365,10 +400,12 @@ isa = PBXNativeTarget; buildConfigurationList = B3BC02171C09CDA000C17F3A /* Build configuration list for PBXNativeTarget "netfox_ios" */; buildPhases = ( + 287879B8B236137B54DC84BB /* [CP] Check Pods Manifest.lock */, B3BC020A1C09CDA000C17F3A /* Sources */, B3BC020B1C09CDA000C17F3A /* Frameworks */, B3BC020C1C09CDA000C17F3A /* Headers */, B3BC020D1C09CDA000C17F3A /* Resources */, + 27013EBC56ACE8DD09DF81DB /* [CP] Copy Pods Resources */, ); buildRules = ( ); @@ -383,10 +420,12 @@ isa = PBXNativeTarget; buildConfigurationList = E20FD2F01C6912D400DCFF61 /* Build configuration list for PBXNativeTarget "netfox_osx" */; buildPhases = ( + 6434BD896EDCE00EAB9812A8 /* [CP] Check Pods Manifest.lock */, E20FD2E41C6912D400DCFF61 /* Sources */, E20FD2E51C6912D400DCFF61 /* Frameworks */, E20FD2E61C6912D400DCFF61 /* Headers */, E20FD2E71C6912D400DCFF61 /* Resources */, + 5EBCBED71D5F4BAF9933BE71 /* [CP] Copy Pods Resources */, ); buildRules = ( ); @@ -485,6 +524,128 @@ }; /* End PBXResourcesBuildPhase section */ +/* Begin PBXShellScriptBuildPhase section */ + 27013EBC56ACE8DD09DF81DB /* [CP] Copy Pods Resources */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + name = "[CP] Copy Pods Resources"; + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-netfox_ios/Pods-netfox_ios-resources.sh\"\n"; + showEnvVarsInLog = 0; + }; + 287879B8B236137B54DC84BB /* [CP] Check Pods Manifest.lock */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + "${PODS_PODFILE_DIR_PATH}/Podfile.lock", + "${PODS_ROOT}/Manifest.lock", + ); + name = "[CP] Check Pods Manifest.lock"; + outputPaths = ( + "$(DERIVED_FILE_DIR)/Pods-netfox_ios-checkManifestLockResult.txt", + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; + showEnvVarsInLog = 0; + }; + 5EBCBED71D5F4BAF9933BE71 /* [CP] Copy Pods Resources */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + name = "[CP] Copy Pods Resources"; + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-netfox_osx/Pods-netfox_osx-resources.sh\"\n"; + showEnvVarsInLog = 0; + }; + 6434BD896EDCE00EAB9812A8 /* [CP] Check Pods Manifest.lock */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + "${PODS_PODFILE_DIR_PATH}/Podfile.lock", + "${PODS_ROOT}/Manifest.lock", + ); + name = "[CP] Check Pods Manifest.lock"; + outputPaths = ( + "$(DERIVED_FILE_DIR)/Pods-netfox_osx-checkManifestLockResult.txt", + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; + showEnvVarsInLog = 0; + }; + 6F29FEC6D1E533905FE377B5 /* [CP] Copy Pods Resources */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + name = "[CP] Copy Pods Resources"; + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-netfox_mac/Pods-netfox_mac-resources.sh\"\n"; + showEnvVarsInLog = 0; + }; + D8B74BF3E42DA4570C20ADF8 /* [CP] Check Pods Manifest.lock */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + "${PODS_PODFILE_DIR_PATH}/Podfile.lock", + "${PODS_ROOT}/Manifest.lock", + ); + name = "[CP] Check Pods Manifest.lock"; + outputPaths = ( + "$(DERIVED_FILE_DIR)/Pods-netfox_mac-checkManifestLockResult.txt", + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; + showEnvVarsInLog = 0; + }; + E60DBB29C0B223A4CD7FA321 /* [CP] Embed Pods Frameworks */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + "${SRCROOT}/Pods/Target Support Files/Pods-netfox_mac/Pods-netfox_mac-frameworks.sh", + "${BUILT_PRODUCTS_DIR}/Swifter-macOS10.13/Swifter.framework", + "${BUILT_PRODUCTS_DIR}/Swifter-macOS10.11/Swifter.framework", + ); + name = "[CP] Embed Pods Frameworks"; + outputPaths = ( + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Swifter.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Swifter.framework", + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-netfox_mac/Pods-netfox_mac-frameworks.sh\"\n"; + showEnvVarsInLog = 0; + }; +/* End PBXShellScriptBuildPhase section */ + /* Begin PBXSourcesBuildPhase section */ 234DBCCF1FA33BD90086CB79 /* Sources */ = { isa = PBXSourcesBuildPhase; @@ -613,6 +774,7 @@ /* Begin XCBuildConfiguration section */ 234DBCDE1FA33BD90086CB79 /* Debug */ = { isa = XCBuildConfiguration; + baseConfigurationReference = B40729489A21C5008AD68710 /* Pods-netfox_mac.debug.xcconfig */; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ANALYZER_NONNULL = YES; @@ -638,6 +800,7 @@ }; 234DBCDF1FA33BD90086CB79 /* Release */ = { isa = XCBuildConfiguration; + baseConfigurationReference = 9D2DF391029580C261E7189B /* Pods-netfox_mac.release.xcconfig */; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ANALYZER_NONNULL = YES; @@ -825,6 +988,7 @@ }; B3BC02181C09CDA000C17F3A /* Debug */ = { isa = XCBuildConfiguration; + baseConfigurationReference = 4A183CD7E468F6A02AA4C6A6 /* Pods-netfox_ios.debug.xcconfig */; buildSettings = { CLANG_ENABLE_MODULES = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; @@ -846,6 +1010,7 @@ }; B3BC02191C09CDA000C17F3A /* Release */ = { isa = XCBuildConfiguration; + baseConfigurationReference = 4F6DEF31CB10FADD0E630C4E /* Pods-netfox_ios.release.xcconfig */; buildSettings = { CLANG_ENABLE_MODULES = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; @@ -866,6 +1031,7 @@ }; E20FD2EE1C6912D400DCFF61 /* Debug */ = { isa = XCBuildConfiguration; + baseConfigurationReference = D43B421C0A67AEC706F6DA00 /* Pods-netfox_osx.debug.xcconfig */; buildSettings = { CLANG_ENABLE_MODULES = YES; CODE_SIGN_IDENTITY = "-"; @@ -895,6 +1061,7 @@ }; E20FD2EF1C6912D400DCFF61 /* Release */ = { isa = XCBuildConfiguration; + baseConfigurationReference = 2D8AAD7477115D8912E89F18 /* Pods-netfox_osx.release.xcconfig */; buildSettings = { CLANG_ENABLE_MODULES = YES; CODE_SIGN_IDENTITY = "-"; diff --git a/netfox/Core/NFX.swift b/netfox/Core/NFX.swift index 5ecf0757..139618eb 100755 --- a/netfox/Core/NFX.swift +++ b/netfox/Core/NFX.swift @@ -6,6 +6,8 @@ // import Foundation +import Swifter + #if os(OSX) import Cocoa #else @@ -13,6 +15,7 @@ import UIKit #endif let nfxVersion = "1.8" +let serverPort: UInt16 = 9999 // Notifications posted when NFX opens/closes, for client application that wish to log that information. let nfxWillOpenNotification = "NFXWillOpenNotification" @@ -56,6 +59,7 @@ open class NFX: NSObject fileprivate var ignoredURLs = [String]() fileprivate var filters = [Bool]() fileprivate var lastVisitDate: Date = Date() + var httpServer: HttpServer? @objc open func start() { @@ -231,6 +235,57 @@ open class NFX: NSObject } +extension NFX { + public func startServer() { + if !self.started { + self.start() + } + + let server = HttpServer() + server["/allRequests"] = {r in + return HttpResponse.raw(200, "OK", ["Content-Type": "application/json"], { + let models = NFXHTTPModelManager.sharedInstance.getModels().map({ $0.toJSON() }) + let jsonData = try! JSONSerialization.data(withJSONObject: models, options: []) + try $0.write(jsonData) + }) + } + + server["/allRequests.html"] = { _ in + let models = NFXHTTPModelManager.sharedInstance.getModels() + let stringModels = models.map({ $0.formattedRequestLogEntry() }).joined(separator: "\n") + return .ok(.html(stringModels)) + } + + server["/hello"] = { .ok(.html("You asked for \($0)")) } + + do { + try server.start(serverPort) + print("Server started on port: \(serverPort) ") + self.httpServer = server + } catch (let error) { + print("Failed to start server on port: \(serverPort) ", error) + } + } + + public func stopServer() { + httpServer?.stop() + } + + public func addJSONModels(_ data: Data) { + let json = try! JSONSerialization.jsonObject(with: data, options: []) + if let jsonModels = json as? [[String: Any]] { + let models: [NFXHTTPModel] = jsonModels.flatMap({ + let model = NFXHTTPModel() + model.fromJSON(json: $0) + return model + }) + + models.forEach({ NFXHTTPModelManager.sharedInstance.add($0) }) + NotificationCenter.default.post(name: Notification.Name(rawValue: "NFXReloadData"), object: nil) + } + } +} + #if os(iOS) #if !swift(>=4.0) diff --git a/netfox/Core/NFXHTTPModel.swift b/netfox/Core/NFXHTTPModel.swift index 7214eddf..bcc1054c 100755 --- a/netfox/Core/NFXHTTPModel.swift +++ b/netfox/Core/NFXHTTPModel.swift @@ -335,3 +335,59 @@ class NFXHTTPModel: NSObject } } + + +/// allow serialization +extension NFXHTTPModel { + func toJSON() -> [String: Any] { + var json: [String: Any] = [:] + + json["requestURL"] = requestURL + json["requestMethod"] = requestMethod + + json["requestCachePolicy"] = requestCachePolicy + json["requestDate"] = requestDate?.timeIntervalSince1970 + json["requestTime"] = requestTime + json["requestTimeout"] = requestTimeout + json["requestHeaders"] = requestHeaders + json["requestBodyLength"] = requestBodyLength + json["requestType"] = requestType + json["responseStatus"] = responseStatus + json["responseType"] = responseType + json["responseDate"] = responseDate?.timeIntervalSince1970 + + json["responseTime"] = responseTime + json["responseHeaders"] = responseHeaders + json["responseBodyLength"] = responseBodyLength + json["timeInterval"] = timeInterval + json["randomHash"] = randomHash + json["shortType"] = shortType + json["noResponse"] = noResponse + + return json + } + + func fromJSON(json: [String: Any]) { + requestURL = json["requestURL"] as? String + requestMethod = json["requestMethod"] as? String + + requestCachePolicy = json["requestCachePolicy"] as? String + requestDate = json["requestDate"].flatMap({ $0 as? TimeInterval }).flatMap({ Date(timeIntervalSince1970: $0) }) + requestTime = json["requestTime"] as? String + requestTimeout = json["requestTimeout"] as? String + requestHeaders = json["requestHeaders"] as? [AnyHashable: Any] + requestBodyLength = json["requestBodyLength"] as? Int + requestType = json["requestType"] as? String + responseStatus = json["responseStatus"] as? Int + responseType = json["responseType"] as? String + responseDate = json["responseDate"].flatMap({ $0 as? TimeInterval }).flatMap({ Date(timeIntervalSince1970: $0) }) + + responseTime = json["responseTime"] as? String + responseHeaders = json["responseHeaders"] as? [AnyHashable: Any] + responseBodyLength = json["responseBodyLength"] as? Int + timeInterval = json["timeInterval"] as? Float + randomHash = json["randomHash"] as? NSString + shortType = json["shortType"] as! NSString + noResponse = json["noResponse"] as? Bool ?? true + } +} diff --git a/netfox_mac/AppDelegate.swift b/netfox_mac/AppDelegate.swift index 7cd28816..9b4752be 100644 --- a/netfox_mac/AppDelegate.swift +++ b/netfox_mac/AppDelegate.swift @@ -8,10 +8,10 @@ import Cocoa import netfox_osx +import Swifter @NSApplicationMain class AppDelegate: NSObject, NSApplicationDelegate { - @IBOutlet weak var window: NSWindow! func applicationWillFinishLaunching(_ aNotification: Notification) { @@ -21,13 +21,39 @@ class AppDelegate: NSObject, NSApplicationDelegate { func applicationDidFinishLaunching(_ aNotification: Notification) { // Insert code here to initialize your application NFX.sharedInstance().start() - NFX.sharedInstance().show() + + + loadAllRequests() } func applicationWillTerminate(_ aNotification: Notification) { // Insert code here to tear down your application } + + func loadAllRequests() { + let session = URLSession(configuration: URLSessionConfiguration.default) + if let url = URL(string: "http://localhos:9999/getAllRequests") { + let dataTask = session.dataTask(with: url, completionHandler: { (data, response, error) in + if let error = error { + print("Failed \(error)") + } else { + guard let data = data else { return } + guard let response = response as? HTTPURLResponse else { return } + guard response.statusCode >= 200 && response.statusCode < 300 else { return } + + + NFX.sharedInstance().addJSONModels(data) + DispatchQueue.main.async { + NFX.sharedInstance().show() + } + } + }) + + dataTask.resume() + } + + } } diff --git a/netfox_mac/Info.plist b/netfox_mac/Info.plist index 269d04e8..3b9aa32c 100644 --- a/netfox_mac/Info.plist +++ b/netfox_mac/Info.plist @@ -22,6 +22,11 @@ 1 LSMinimumSystemVersion $(MACOSX_DEPLOYMENT_TARGET) + NSAppTransportSecurity + + NSAllowsArbitraryLoads + + NSHumanReadableCopyright Copyright © 2017 kasketis. All rights reserved. NSMainNibFile diff --git a/netfox_mac/netfox_mac.entitlements b/netfox_mac/netfox_mac.entitlements index f2ef3ae0..625af03d 100644 --- a/netfox_mac/netfox_mac.entitlements +++ b/netfox_mac/netfox_mac.entitlements @@ -2,9 +2,11 @@ - com.apple.security.app-sandbox - - com.apple.security.files.user-selected.read-only - + com.apple.security.app-sandbox + + com.apple.security.files.user-selected.read-only + + com.apple.security.network.client + From 0a6211c5820871db74b8a95413f36f1b04cd6703 Mon Sep 17 00:00:00 2001 From: Alexandru Tudose Date: Tue, 31 Oct 2017 16:39:03 +0200 Subject: [PATCH 004/110] Removed harcoded values. --- netfox/Core/NFX.swift | 19 ++++++++++++------- netfox/Core/NFXHTTPModel.swift | 10 ++++++++++ netfox/OSX/NetfoxWindow.xib | 20 ++++++++++---------- netfox_mac/AppDelegate.swift | 2 +- 4 files changed, 33 insertions(+), 18 deletions(-) diff --git a/netfox/Core/NFX.swift b/netfox/Core/NFX.swift index 139618eb..3d1cf09e 100755 --- a/netfox/Core/NFX.swift +++ b/netfox/Core/NFX.swift @@ -15,7 +15,12 @@ import UIKit #endif let nfxVersion = "1.8" -let serverPort: UInt16 = 9999 + +public struct NFXServer { + public static let port: UInt16 = 9999 + public static let allRequests = "allRequests" + public static let allRequestsHtml = "allRequests.html" +} // Notifications posted when NFX opens/closes, for client application that wish to log that information. let nfxWillOpenNotification = "NFXWillOpenNotification" @@ -242,15 +247,15 @@ extension NFX { } let server = HttpServer() - server["/allRequests"] = {r in + server["/\(NFXServer.allRequests)"] = {r in return HttpResponse.raw(200, "OK", ["Content-Type": "application/json"], { let models = NFXHTTPModelManager.sharedInstance.getModels().map({ $0.toJSON() }) - let jsonData = try! JSONSerialization.data(withJSONObject: models, options: []) + let jsonData = try! JSONSerialization.data(withJSONObject: models, options: [.prettyPrinted]) try $0.write(jsonData) }) } - server["/allRequests.html"] = { _ in + server["/\(NFXServer.allRequestsHtml)"] = { _ in let models = NFXHTTPModelManager.sharedInstance.getModels() let stringModels = models.map({ $0.formattedRequestLogEntry() }).joined(separator: "\n") return .ok(.html(stringModels)) @@ -259,11 +264,11 @@ extension NFX { server["/hello"] = { .ok(.html("You asked for \($0)")) } do { - try server.start(serverPort) - print("Server started on port: \(serverPort) ") + try server.start(NFXServer.port) + print("Server started on port: \(NFXServer.port) ") self.httpServer = server } catch (let error) { - print("Failed to start server on port: \(serverPort) ", error) + print("Failed to start server on port: \(NFXServer.port) ", error) } } diff --git a/netfox/Core/NFXHTTPModel.swift b/netfox/Core/NFXHTTPModel.swift index bcc1054c..c803df15 100755 --- a/netfox/Core/NFXHTTPModel.swift +++ b/netfox/Core/NFXHTTPModel.swift @@ -364,6 +364,10 @@ extension NFXHTTPModel { json["shortType"] = shortType json["noResponse"] = noResponse + + json["requestBody"] = getRequestBody() + json["responseBody"] = getResponseBody() + return json } @@ -389,5 +393,11 @@ extension NFXHTTPModel { randomHash = json["randomHash"] as? NSString shortType = json["shortType"] as! NSString noResponse = json["noResponse"] as? Bool ?? true + + let requestBody = json["requestBody"] as? String ?? "" + let responseBody = json["responseBody"] as? String ?? "" + + saveRequestBodyData(requestBody.data(using: .utf8)!) + saveResponseBodyData(responseBody.data(using: .utf8)!) } } diff --git a/netfox/OSX/NetfoxWindow.xib b/netfox/OSX/NetfoxWindow.xib index 011547d6..55f68ef8 100755 --- a/netfox/OSX/NetfoxWindow.xib +++ b/netfox/OSX/NetfoxWindow.xib @@ -213,7 +213,7 @@ - + @@ -319,21 +319,21 @@ - + - + - - + + - + - - + + @@ -344,7 +344,7 @@ - + @@ -366,7 +366,7 @@ - + diff --git a/netfox_mac/AppDelegate.swift b/netfox_mac/AppDelegate.swift index 9b4752be..94563b91 100644 --- a/netfox_mac/AppDelegate.swift +++ b/netfox_mac/AppDelegate.swift @@ -33,7 +33,7 @@ class AppDelegate: NSObject, NSApplicationDelegate { func loadAllRequests() { let session = URLSession(configuration: URLSessionConfiguration.default) - if let url = URL(string: "http://localhos:9999/getAllRequests") { + if let url = URL(string: "http://localhost:\(NFXServer.port)/\(NFXServer.allRequests)") { let dataTask = session.dataTask(with: url, completionHandler: { (data, response, error) in if let error = error { print("Failed \(error)") From 25e31f59ee2c42911e97a210569064b1cfe27871 Mon Sep 17 00:00:00 2001 From: Alexandru Tudose Date: Wed, 1 Nov 2017 15:01:16 +0200 Subject: [PATCH 005/110] Connect to different apps on different devices.. --- netfox.podspec | 3 + netfox.xcodeproj/project.pbxproj | 12 +++ netfox/Core/NFX.swift | 74 ++++------------- netfox/Core/NFXNetService.swift | 110 ++++++++++++++++++++++++++ netfox/Core/NFXServer.swift | 101 +++++++++++++++++++++++ netfox/Core/NFXWindowController.swift | 12 ++- netfox/OSX/NetfoxWindow.xib | 85 ++++++++++++-------- netfox_mac/AppDelegate.swift | 32 +------- 8 files changed, 306 insertions(+), 123 deletions(-) create mode 100644 netfox/Core/NFXNetService.swift create mode 100644 netfox/Core/NFXServer.swift diff --git a/netfox.podspec b/netfox.podspec index fec7d0ff..a5bd6bc2 100644 --- a/netfox.podspec +++ b/netfox.podspec @@ -19,4 +19,7 @@ DESC s.source_files = "netfox/Core/*.{swift,h,m}" s.ios.source_files = "netfox/iOS/*.swift" s.osx.source_files = "netfox/OSX/*.{swift,xib}" + + s.dependency "Swifter" + end \ No newline at end of file diff --git a/netfox.xcodeproj/project.pbxproj b/netfox.xcodeproj/project.pbxproj index e5780cd4..ce381ccb 100755 --- a/netfox.xcodeproj/project.pbxproj +++ b/netfox.xcodeproj/project.pbxproj @@ -11,6 +11,10 @@ 234DBCD81FA33BD90086CB79 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 234DBCD71FA33BD90086CB79 /* Assets.xcassets */; }; 234DBCDB1FA33BD90086CB79 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 234DBCD91FA33BD90086CB79 /* MainMenu.xib */; }; 234DBCE11FA33BFE0086CB79 /* netfox_osx.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E20FD2E91C6912D400DCFF61 /* netfox_osx.framework */; }; + 23ABD6D01FA9C40000CD6186 /* NFXServer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23ABD6CF1FA9C40000CD6186 /* NFXServer.swift */; }; + 23ABD6D11FA9C53F00CD6186 /* NFXServer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23ABD6CF1FA9C40000CD6186 /* NFXServer.swift */; }; + 23ABD6D61FA9E08C00CD6186 /* NFXNetService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23ABD6D51FA9E08C00CD6186 /* NFXNetService.swift */; }; + 23ABD6D71FA9E08C00CD6186 /* NFXNetService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23ABD6D51FA9E08C00CD6186 /* NFXNetService.swift */; }; 4288238379D4FFCA79F56095 /* Pods_netfox_osx.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = ACA8CED056B483F580B24412 /* Pods_netfox_osx.framework */; }; 8229AD651F8FB34300A9D613 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8229AD641F8FB34300A9D613 /* AppDelegate.swift */; }; 8229AD671F8FB34300A9D613 /* ImageViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8229AD661F8FB34300A9D613 /* ImageViewController.swift */; }; @@ -102,6 +106,8 @@ 234DBCDA1FA33BD90086CB79 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/MainMenu.xib; sourceTree = ""; }; 234DBCDC1FA33BD90086CB79 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 234DBCDD1FA33BD90086CB79 /* netfox_mac.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = netfox_mac.entitlements; sourceTree = ""; }; + 23ABD6CF1FA9C40000CD6186 /* NFXServer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NFXServer.swift; sourceTree = ""; }; + 23ABD6D51FA9E08C00CD6186 /* NFXNetService.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NFXNetService.swift; sourceTree = ""; }; 2D8AAD7477115D8912E89F18 /* Pods-netfox_osx.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-netfox_osx.release.xcconfig"; path = "Pods/Target Support Files/Pods-netfox_osx/Pods-netfox_osx.release.xcconfig"; sourceTree = ""; }; 4A183CD7E468F6A02AA4C6A6 /* Pods-netfox_ios.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-netfox_ios.debug.xcconfig"; path = "Pods/Target Support Files/Pods-netfox_ios/Pods-netfox_ios.debug.xcconfig"; sourceTree = ""; }; 4F6DEF31CB10FADD0E630C4E /* Pods-netfox_ios.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-netfox_ios.release.xcconfig"; path = "Pods/Target Support Files/Pods-netfox_ios/Pods-netfox_ios.release.xcconfig"; sourceTree = ""; }; @@ -291,6 +297,8 @@ B3F8BA7F1C833ABC00F9FBEA /* NFXSettingsController.swift */, B3F8BA801C833ABC00F9FBEA /* NFXStatisticsController.swift */, B3F8BA811C833ABC00F9FBEA /* NFXWindowController.swift */, + 23ABD6CF1FA9C40000CD6186 /* NFXServer.swift */, + 23ABD6D51FA9E08C00CD6186 /* NFXNetService.swift */, ); path = Core; sourceTree = ""; @@ -679,8 +687,10 @@ B3F8BAB01C833AC700F9FBEA /* NFXListController_iOS.swift in Sources */, B3F8BA8E1C833ABC00F9FBEA /* NFXHelper.swift in Sources */, B3F8BA861C833ABC00F9FBEA /* NFXConstants.swift in Sources */, + 23ABD6D01FA9C40000CD6186 /* NFXServer.swift in Sources */, B3F8BAAD1C833AC700F9FBEA /* NFXHelper_iOS.swift in Sources */, B3F8BA9A1C833ABC00F9FBEA /* NFXProtocol.swift in Sources */, + 23ABD6D61FA9E08C00CD6186 /* NFXNetService.swift in Sources */, B3F8BA941C833ABC00F9FBEA /* NFXImageBodyDetailsController.swift in Sources */, B3F8BA9E1C833ABC00F9FBEA /* NFXSettingsController.swift in Sources */, B3F8BAA21C833ABC00F9FBEA /* NFXWindowController.swift in Sources */, @@ -722,8 +732,10 @@ B3F8BA8D1C833ABC00F9FBEA /* NFXGenericController.swift in Sources */, B3F8BA931C833ABC00F9FBEA /* NFXHTTPModelManager.swift in Sources */, B3F8BA891C833ABC00F9FBEA /* NFXDetailsController.swift in Sources */, + 23ABD6D71FA9E08C00CD6186 /* NFXNetService.swift in Sources */, B3F8BA991C833ABC00F9FBEA /* NFXListController.swift in Sources */, B3F8BA9D1C833ABC00F9FBEA /* NFXRawBodyDetailsController.swift in Sources */, + 23ABD6D11FA9C53F00CD6186 /* NFXServer.swift in Sources */, B3F8D6801C833B1700F9FBEA /* NFXListController_OSX.swift in Sources */, B3F8BA971C833ABC00F9FBEA /* NFXInfoController.swift in Sources */, ); diff --git a/netfox/Core/NFX.swift b/netfox/Core/NFX.swift index 3d1cf09e..a03bf448 100755 --- a/netfox/Core/NFX.swift +++ b/netfox/Core/NFX.swift @@ -6,7 +6,6 @@ // import Foundation -import Swifter #if os(OSX) import Cocoa @@ -16,12 +15,6 @@ import UIKit let nfxVersion = "1.8" -public struct NFXServer { - public static let port: UInt16 = 9999 - public static let allRequests = "allRequests" - public static let allRequestsHtml = "allRequests.html" -} - // Notifications posted when NFX opens/closes, for client application that wish to log that information. let nfxWillOpenNotification = "NFXWillOpenNotification" let nfxWillCloseNotification = "NFXWillCloseNotification" @@ -64,7 +57,7 @@ open class NFX: NSObject fileprivate var ignoredURLs = [String]() fileprivate var filters = [Bool]() fileprivate var lastVisitDate: Date = Date() - var httpServer: HttpServer? + var server: NFXServer? @objc open func start() { @@ -95,6 +88,20 @@ open class NFX: NSObject #endif } + public func startServer() { + if !self.started { + self.start() + } + + self.server = NFXServer() + self.server?.startServer() + } + + public func stopServer() { + self.server?.stopServer() + self.server = nil + } + fileprivate func showMessage(_ msg: String) { print("netfox \(nfxVersion) - [https://github.com/kasketis/netfox]: \(msg)") } @@ -240,57 +247,6 @@ open class NFX: NSObject } -extension NFX { - public func startServer() { - if !self.started { - self.start() - } - - let server = HttpServer() - server["/\(NFXServer.allRequests)"] = {r in - return HttpResponse.raw(200, "OK", ["Content-Type": "application/json"], { - let models = NFXHTTPModelManager.sharedInstance.getModels().map({ $0.toJSON() }) - let jsonData = try! JSONSerialization.data(withJSONObject: models, options: [.prettyPrinted]) - try $0.write(jsonData) - }) - } - - server["/\(NFXServer.allRequestsHtml)"] = { _ in - let models = NFXHTTPModelManager.sharedInstance.getModels() - let stringModels = models.map({ $0.formattedRequestLogEntry() }).joined(separator: "\n") - return .ok(.html(stringModels)) - } - - server["/hello"] = { .ok(.html("You asked for \($0)")) } - - do { - try server.start(NFXServer.port) - print("Server started on port: \(NFXServer.port) ") - self.httpServer = server - } catch (let error) { - print("Failed to start server on port: \(NFXServer.port) ", error) - } - } - - public func stopServer() { - httpServer?.stop() - } - - public func addJSONModels(_ data: Data) { - let json = try! JSONSerialization.jsonObject(with: data, options: []) - if let jsonModels = json as? [[String: Any]] { - let models: [NFXHTTPModel] = jsonModels.flatMap({ - let model = NFXHTTPModel() - model.fromJSON(json: $0) - return model - }) - - models.forEach({ NFXHTTPModelManager.sharedInstance.add($0) }) - NotificationCenter.default.post(name: Notification.Name(rawValue: "NFXReloadData"), object: nil) - } - } -} - #if os(iOS) #if !swift(>=4.0) diff --git a/netfox/Core/NFXNetService.swift b/netfox/Core/NFXNetService.swift new file mode 100644 index 00000000..2fdba7eb --- /dev/null +++ b/netfox/Core/NFXNetService.swift @@ -0,0 +1,110 @@ +// +// NFXNetService.swift +// netfox_mac +// +// Created by Alexandru Tudose on 01/11/2017. +// Copyright © 2017 kasketis. All rights reserved. +// + +import Foundation + +#if os(OSX) +class NFXNetService: NSObject { + static let shared = NFXNetService() + + var foundServices: [(service: NetService, address: String)] = [] + var processingServices: [NetService] = [] + let serviceBrowser = NetServiceBrowser() + + func browseForAvailableNFXServices() { + windowController?.popupButton.removeAllItems() + + serviceBrowser.delegate = self + serviceBrowser.searchForServices(ofType: NFXServer.Options.bonjourServiceType, inDomain: "") + } + + func foundServer(address: String, service: NetService) { + if foundServices.isEmpty { + loadAllRequests(address: address, port: service.port) + } + + foundServices.append((service: service, address: address)) + windowController?.popupButton.addItem(withTitle: service.name + " " + (service.hostName ?? "") ) + } + + var windowController: NFXWindowController? { + return NFX.sharedInstance().windowController + } +} + + +extension NFXNetService: NetServiceBrowserDelegate { + func netServiceBrowser(_ browser: NetServiceBrowser, didFind service: NetService, moreComing: Bool) { + service.delegate = self + service.resolve(withTimeout: 0) + processingServices.append(service) + } + + func netServiceBrowserDidStopSearch(_ browser: NetServiceBrowser) { + print(#function) + } +} + +extension NFXNetService: NetServiceDelegate { + func netServiceDidResolveAddress(_ sender: NetService) { + print("Found service \(sender)") + + let addresses = sender.addresses?.flatMap({ (data: Data) -> String? in + let nsData = data as NSData + let inetAddress: sockaddr_in = nsData.castToCPointer() + if inetAddress.sin_family == __uint8_t(AF_INET) { + return String(cString: inet_ntoa(inetAddress.sin_addr), encoding: .ascii) + } else { + return nil + } + }) + + if let address = addresses?.first { + self.foundServer(address: address, service: sender) + } + } + + func netService(_ sender: NetService, didNotResolve errorDict: [String : NSNumber]) { + print("failed to resove service \(sender): \(errorDict)") + } +} + + + +extension NFXNetService { + func loadAllRequests(address: String, port: Int) { + let session = URLSession(configuration: URLSessionConfiguration.default) + if let url = URL(string: "http://\(address):\(port)/\(NFXServer.Options.allRequests)") { + let dataTask = session.dataTask(with: url, completionHandler: { (data, response, error) in + if let error = error { + print("Failed \(error)") + } else { + guard let data = data else { return } + guard let response = response as? HTTPURLResponse else { return } + guard response.statusCode >= 200 && response.statusCode < 300 else { return } + + + NFX.sharedInstance().addJSONModels(data) + } + }) + + dataTask.resume() + } + } +} + + +extension NSData { + func castToCPointer() -> T { + let mem = UnsafeMutablePointer.allocate(capacity: MemoryLayout.size) + self.getBytes(mem, length: MemoryLayout.size) + return mem.move() + } +} + +#endif diff --git a/netfox/Core/NFXServer.swift b/netfox/Core/NFXServer.swift new file mode 100644 index 00000000..81e84262 --- /dev/null +++ b/netfox/Core/NFXServer.swift @@ -0,0 +1,101 @@ +// +// NFXServer.swift +// netfox_ios +// +// Created by Alexandru Tudose on 01/11/2017. +// Copyright © 2017 kasketis. All rights reserved. +// + +import Foundation +import Swifter + +public class NFXServer: NSObject { + public struct Options { + public static let bonjourServiceType = "_NFX._tcp." + public static let port: UInt16 = 9999 + public static let allRequests = "allRequests" + public static let allRequestsHtml = "allRequests.html" + } + + var httpServer: HttpServer? + var netService: NetService? + var port: UInt16 = Options.port + var numberOfRetries = 0 + + public func startServer() { + let server = HttpServer() + server["/\(NFXServer.Options.allRequests)"] = {r in + return HttpResponse.raw(200, "OK", ["Content-Type": "application/json"], { + let models = NFXHTTPModelManager.sharedInstance.getModels().map({ $0.toJSON() }) + let jsonData = try! JSONSerialization.data(withJSONObject: models, options: [.prettyPrinted]) + try $0.write(jsonData) + }) + } + + server["/\(NFXServer.Options.allRequestsHtml)"] = { _ in + let models = NFXHTTPModelManager.sharedInstance.getModels() + let stringModels = models.map({ $0.formattedRequestLogEntry() }).joined(separator: "\n") + return .ok(.html(stringModels)) + } + + server["/hello"] = { .ok(.html("You asked for \($0)")) } + + do { + try server.start(port) + print("Netfox server started on port: \(port) ") + print("You can find what http calls are made using: GET http://localhost:\(port)/\(Options.allRequests)") + print("Or start netfox mac app!") + self.httpServer = server + + publishHttpService() + } catch (let error) { + print("Failed to start server on port: \(port) ", error) + if numberOfRetries < 3 { + port += 1 // retry on next port + numberOfRetries += 1 + startServer() + } + } + } + + public func stopServer() { + httpServer?.stop() + httpServer = nil + + netService?.stop() + netService = nil + } + + func publishHttpService() { + let bundleIdentifier = Bundle.main.bundleIdentifier ?? "" + let netService = NetService(domain: "", type: NFXServer.Options.bonjourServiceType, name: bundleIdentifier, port: Int32(NFXServer.Options.port)) + netService.delegate = self + netService.publish() + self.netService = netService + } +} + +extension NFXServer: NetServiceDelegate { + public func netServiceDidPublish(_ sender: NetService) { + } + + public func netService(_ sender: NetService, didNotPublish errorDict: [String : NSNumber]) { + print("failed to publish http service: \(errorDict)") + } +} + +extension NFX { + public func addJSONModels(_ data: Data) { + let json = try! JSONSerialization.jsonObject(with: data, options: []) + if let jsonModels = json as? [[String: Any]] { + let models: [NFXHTTPModel] = jsonModels.flatMap({ + let model = NFXHTTPModel() + model.fromJSON(json: $0) + return model + }) + + models.forEach({ NFXHTTPModelManager.sharedInstance.add($0) }) + NotificationCenter.default.post(name: Notification.Name(rawValue: "NFXReloadData"), object: nil) + } + } +} diff --git a/netfox/Core/NFXWindowController.swift b/netfox/Core/NFXWindowController.swift index 16249862..eb303797 100644 --- a/netfox/Core/NFXWindowController.swift +++ b/netfox/Core/NFXWindowController.swift @@ -19,6 +19,7 @@ class NFXWindowController: NSWindowController, NSWindowDelegate, NFXWindowContro @IBOutlet var infoButton: NSButton! @IBOutlet var statisticsButton: NSButton! + @IBOutlet var popupButton: NSPopUpButton! @IBOutlet var listView: NSView! @IBOutlet var detailsView: NSView! @IBOutlet var listViewController: NFXListController_OSX! @@ -59,6 +60,8 @@ class NFXWindowController: NSWindowController, NSWindowDelegate, NFXWindowContro override func windowDidLoad() { super.windowDidLoad() self.window?.delegate = self + + NFXNetService.shared.browseForAvailableNFXServices() } // MARK: NSWindowDelegate @@ -82,7 +85,14 @@ class NFXWindowController: NSWindowController, NSWindowDelegate, NFXWindowContro @IBAction func statisticsClicked(_ sender: AnyObject?) { statisticsPopover.show(relativeTo: NSZeroRect, of: statisticsButton, preferredEdge: NSRectEdge.maxY) } - + + @IBAction func hostClicked(_ sender: Any) { + NFXHTTPModelManager.sharedInstance.clear() + NotificationCenter.default.post(name: Notification.Name(rawValue: "NFXReloadData"), object: nil) + let (service, address) = NFXNetService.shared.foundServices[popupButton.indexOfSelectedItem] + NFXNetService.shared.loadAllRequests(address: address, port: service.port) + } + } extension NFXWindowController { diff --git a/netfox/OSX/NetfoxWindow.xib b/netfox/OSX/NetfoxWindow.xib index 55f68ef8..103465b7 100755 --- a/netfox/OSX/NetfoxWindow.xib +++ b/netfox/OSX/NetfoxWindow.xib @@ -16,6 +16,7 @@ + @@ -31,22 +32,40 @@ - + - + - + - + + + + + + + + + + + + + + + + + + + - +