80 Commits

Author SHA1 Message Date
relikd
9ee094dc20 Version 1.0.0 (25) 2020-07-28 14:50:59 +02:00
relikd
b1d49c6765 Persist logs by renaming table (hopefully reduces lock time) 2020-07-27 21:16:14 +02:00
relikd
b774e2152c Don't perform notification open action if modal window is open 2020-07-27 19:23:16 +02:00
relikd
e398ac8bcd Let notification open domain 2020-07-27 19:06:44 +02:00
relikd
01523b250f Proper VPN simulator with notifications, etc. 2020-07-27 17:50:15 +02:00
relikd
a2b0f311d5 First version with app notifications 2020-07-26 22:32:11 +02:00
relikd
88a52fb92c Version 1.0.0 (24) 2020-07-02 14:12:26 +02:00
relikd
723f1665a7 fittingSize() 2020-07-02 12:26:34 +02:00
relikd
4f92d3d58d Co-Occurrence on domain level 2020-07-02 12:26:07 +02:00
relikd
05d06a4f31 Update readme 2020-07-01 13:31:29 +02:00
relikd
f9ab545e0f Version 1.0.0 (23) 2020-07-01 12:30:22 +02:00
relikd
b10d4c8b36 Show database file size in settings 2020-07-01 11:47:15 +02:00
relikd
5a3ca024f8 Vacuum before export 2020-07-01 10:57:50 +02:00
relikd
92216c0c03 CustomAlert refactoring. Using proper UIPresentationController with adaptive margins 2020-07-01 00:53:25 +02:00
relikd
9ece3474c6 Limit CustomAlert to screen size & cut padding in half if necessary 2020-06-29 00:34:15 +02:00
relikd
6dcc2086e6 Auto-delete logs finished + custom App-to-VPN messages 2020-06-28 23:55:08 +02:00
relikd
08483711e2 Remove two unimportant and verbose error logs 2020-06-28 21:17:37 +02:00
relikd
0e100006d3 Moving extensions around 2020-06-28 17:04:48 +02:00
relikd
710c617862 Move VPN manager logic into its own controller 2020-06-28 16:31:11 +02:00
relikd
3ed25c92cd Render assets as template image 2020-06-28 14:34:16 +02:00
relikd
f7644e6048 Rename Pref -> Prefs 2020-06-28 14:33:36 +02:00
relikd
80afa6aff1 Privacy: Auto-delete logs (no functionality yet) 2020-06-28 14:20:31 +02:00
relikd
43de81929f Alerts with custom views 2020-06-28 01:06:06 +02:00
relikd
e315e71d07 Storyboard constantly trying to replace floats with rounding error 2020-06-27 16:27:48 +02:00
relikd
416eb34799 Reverse context analysis sort order (oldest first) 2020-06-27 16:20:20 +02:00
relikd
b7b13f51b2 Recordings: Toggle between raw logs and summary 2020-06-27 16:13:58 +02:00
relikd
2312187670 DB readText -> col_text 2020-06-27 00:54:50 +02:00
relikd
c7d0dc7c5f UIColor.sysFg -> UIColor.sysLabel 2020-06-27 00:50:47 +02:00
relikd
895cabee80 Context analysis: +/-5min raw logs 2020-06-27 00:40:29 +02:00
relikd
d96ced48c9 Version 1.0.0 (22) 2020-06-26 21:36:51 +02:00
relikd
0b6dbfd888 Co-Occurrence tutorial sheet + small bugfixes 2020-06-26 20:26:30 +02:00
relikd
96656438c6 Context analysis: Co-Occurrence 2020-06-24 13:09:11 +02:00
relikd
4b32df5683 Fix layout constraint warning on iOS 10 2020-06-21 16:20:20 +02:00
relikd
0758bd7dec Fix iOS 9 finish editing of cell 2020-06-21 16:16:39 +02:00
relikd
171dabd83a Search integrated in table view header 2020-06-21 16:13:58 +02:00
relikd
6182a99ebd Exclude TLD when searching host 2020-06-20 13:56:11 +02:00
relikd
8bfedda3ab Version 1.0.0 (21) 2020-06-20 13:28:38 +02:00
relikd
26f6ea1a9a Fix crash when sort and filter change at the same time.
Fix edit table cell during reload
2020-06-20 12:56:56 +02:00
relikd
778f377e42 Disabling prepared statement for now 2020-06-20 01:03:51 +02:00
relikd
f284365469 Fix update of 'last modified' cell if removing latest entries 2020-06-19 17:01:10 +02:00
relikd
5dfb7d4ba4 Remove safeSetRange 2020-06-19 15:40:34 +02:00
relikd
bb9c3a3034 Use nil instead of 0 and -1 2020-06-19 14:24:03 +02:00
relikd
8cf872a4b0 Todos 2020-06-17 01:49:46 +02:00
relikd
e813230824 Fix: re-insert at same position if last row 2020-06-17 01:36:39 +02:00
relikd
e8bfde9243 Fix: Search bar animation table height 2020-06-17 01:26:49 +02:00
relikd
e947ad6d4d Refactoring II.
- Filter by date range
- SyncUpdate tasks run fully asynchronous in background
- Move tableView manipulations into FilterPipelineDelegate
- Move SyncUpdate notification into SyncUpdateDelegate
- Fix: sync cache before persisting a recording
- Restructuring GroupedDomainDataSource
- Performance: db logs queries use rowids instead of timestamps
- Add 'now' button to DatePickerAlert
2020-06-17 00:27:22 +02:00
relikd
0a53898797 DatePickerAlert + DateFormat 2020-06-11 01:32:50 +02:00
relikd
946acc2460 Sort order 2020-06-08 23:38:09 +02:00
relikd
e13b3df2c4 Swap filter and search button button 2020-06-07 12:02:18 +02:00
relikd
7df2fe421e Version 1.0.0 (19) 2020-06-05 18:23:12 +02:00
relikd
b4b89f8bb4 Persist cache with pull-to-refresh + Sync rate limiting 2020-06-05 18:12:31 +02:00
relikd
db41e68f35 Remove filter logic from PipelineSorting 2020-06-05 16:11:42 +02:00
relikd
5acd9bbcc6 Bugfix: sorted array difference 2020-06-05 16:08:17 +02:00
relikd
23eab2310f Search Hosts + search animations + reload table after filter manipulations 2020-06-05 14:27:41 +02:00
relikd
80829ad015 Version 1.0.0 (17) 2020-06-04 18:54:38 +02:00
relikd
661bf5d30a Fix data source update 2020-06-04 18:54:09 +02:00
relikd
38f4166503 Version 1.0.0 (16) 2020-06-04 18:36:36 +02:00
relikd
d96038c7e3 Bounce settings table view 2020-06-04 17:42:12 +02:00
relikd
7d6b071d8a Bugfixes
- Disable cell animations for huge changes
- Updating a cell keeps the old position whenever possible
- Async `didChangeDateFilter`
- Fixes bug where saving a recording would persist entries again
- Small changes to `TimeFormat`, `AlertDeleteLogs` and `binTreeIndex()`
2020-06-04 17:07:37 +02:00
relikd
b17fb3c354 Refactoring I.
- Revamp whole DB to Display flow
- Filter Pipeline, arbitrary filtering and sorting
- Binary tree arrays for faster lookup & manipulation
- DB: introducing custom functions
- DB scheme: split req into heap & cache
- cache written by GlassVPN only
- heap written by Main App only
- Introducing DB separation: DBCore, DBCommon, DBAppOnly
- Introducing DB data sources: TestDataSource, GroupedDomainDataSource, RecordingsDB, DomainFilter
- Background sync: Move entries from cache to heap and notify all observers
- GlassVPN: Binary tree filter lookup
- GlassVPN: Reusing prepared statement
2020-06-02 21:45:08 +02:00
relikd
10b43a0f67 Group multiple timestamps 2020-05-13 21:57:04 +02:00
relikd
4092a9ba55 Fix tableview access on main thread 2020-05-13 21:55:02 +02:00
relikd
2d35c863e4 Readme + 3rd party license 2020-05-13 15:32:38 +02:00
relikd
8424c161b9 Search + lastXMin Filter + dynamic text size 2020-05-13 01:37:50 +02:00
relikd
9485d7e9b5 Fix pull back animation for new recording 2020-04-22 22:30:19 +02:00
relikd
9f26bdfba1 DNS filter: URL text input 2020-04-18 18:57:17 +02:00
relikd
412d533275 Version 1.0.0 (15) 2020-04-18 18:56:37 +02:00
relikd
245bb46e4f DNS filters: proper sort + no cell selection + copy cell value 2020-04-18 00:39:59 +02:00
relikd
70508c1325 Tutorial Sheet (incl. Welcome message + Recordings introduction) 2020-04-17 23:37:03 +02:00
relikd
b44fd788b5 Fix iOS9 row edit issue 2020-04-08 22:34:44 +02:00
relikd
80f3503e16 Edit delete recordings 2020-04-08 21:34:45 +02:00
relikd
d0056c0275 Recording details duplicate and display 2020-04-08 18:53:00 +02:00
relikd
e7560479ee remove unused 2020-04-08 16:43:35 +02:00
relikd
ed5298f7a2 Storyboard logical sort 2020-04-06 23:46:38 +02:00
relikd
647eca310f Previous recordings detail view template 2020-04-06 23:37:46 +02:00
relikd
515c296b26 Keep title for expanded notes 2020-04-04 01:52:07 +02:00
relikd
61ae50cdfa Enlarge notes above keyboard 2020-04-04 00:06:16 +02:00
relikd
fcb6e9c5dd Stack view for recordings tab 2020-04-02 20:14:57 +02:00
relikd
79f836016a Recordings interface 2020-04-02 18:28:20 +02:00
relikd
144773ddaa Add (+) button to domain filter view 2020-03-26 19:28:03 +01:00
120 changed files with 8847 additions and 2652 deletions

View File

@@ -7,32 +7,83 @@
objects = {
/* Begin PBXBuildFile section */
540C6457240D929300E948F9 /* EditableRows.swift in Sources */ = {isa = PBXBuildFile; fileRef = 540C6456240D929300E948F9 /* EditableRows.swift */; };
5404AEEB24A90717003B2F54 /* PrefsShared.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54E67E4524A8B0FE0025D261 /* PrefsShared.swift */; };
5404AEED24A95F3F003B2F54 /* SlideInAnimation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5404AEEC24A95F3F003B2F54 /* SlideInAnimation.swift */; };
5404AEEF24ACC089003B2F54 /* VCAnalysisBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5404AEEE24ACC089003B2F54 /* VCAnalysisBar.swift */; };
540E6780242D2CF100871BBE /* VCRecordings.swift in Sources */ = {isa = PBXBuildFile; fileRef = 540E677F242D2CF100871BBE /* VCRecordings.swift */; };
540E67822433483D00871BBE /* VCEditRecording.swift in Sources */ = {isa = PBXBuildFile; fileRef = 540E67812433483D00871BBE /* VCEditRecording.swift */; };
540E67842433FAFE00871BBE /* TVCPreviousRecords.swift in Sources */ = {isa = PBXBuildFile; fileRef = 540E67832433FAFE00871BBE /* TVCPreviousRecords.swift */; };
541075CE24C9D43A00D6F1BF /* UNNotification.swift in Sources */ = {isa = PBXBuildFile; fileRef = 541075CD24C9D43A00D6F1BF /* UNNotification.swift */; };
541075CF24C9D43A00D6F1BF /* UNNotification.swift in Sources */ = {isa = PBXBuildFile; fileRef = 541075CD24C9D43A00D6F1BF /* UNNotification.swift */; };
541075D124CDBA0000D6F1BF /* ThrottledBatchQueue.swift in Sources */ = {isa = PBXBuildFile; fileRef = 541075D024CDBA0000D6F1BF /* ThrottledBatchQueue.swift */; };
541075D224CDBA0000D6F1BF /* ThrottledBatchQueue.swift in Sources */ = {isa = PBXBuildFile; fileRef = 541075D024CDBA0000D6F1BF /* ThrottledBatchQueue.swift */; };
541075D524CE286200D6F1BF /* CachedConnectionAlert.swift in Sources */ = {isa = PBXBuildFile; fileRef = 541075D424CE286200D6F1BF /* CachedConnectionAlert.swift */; };
541075D624CE286200D6F1BF /* CachedConnectionAlert.swift in Sources */ = {isa = PBXBuildFile; fileRef = 541075D424CE286200D6F1BF /* CachedConnectionAlert.swift */; };
541075D924CE2C7200D6F1BF /* GlassVPNHook.swift in Sources */ = {isa = PBXBuildFile; fileRef = 541075D824CE2C7200D6F1BF /* GlassVPNHook.swift */; };
541075DA24CE2C7200D6F1BF /* GlassVPNHook.swift in Sources */ = {isa = PBXBuildFile; fileRef = 541075D824CE2C7200D6F1BF /* GlassVPNHook.swift */; };
5412F8EE24571B8200A63D7A /* VCDateFilter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5412F8ED24571B8100A63D7A /* VCDateFilter.swift */; };
5412FCC224C628FA000DE429 /* TVCReminderAlerts.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5412FCBF24C628F9000DE429 /* TVCReminderAlerts.swift */; };
5412FCC324C628FA000DE429 /* TVCChooseAlertTone.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5412FCC024C628F9000DE429 /* TVCChooseAlertTone.swift */; };
5412FCC424C628FA000DE429 /* TVCConnectionAlerts.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5412FCC124C628FA000DE429 /* TVCConnectionAlerts.swift */; };
541A957623E602DF00C09C19 /* LaunchIcon.png in Resources */ = {isa = PBXBuildFile; fileRef = 541A957523E602DF00C09C19 /* LaunchIcon.png */; };
541AC5D82399498A00A769D7 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 541AC5D72399498A00A769D7 /* AppDelegate.swift */; };
541AC5DD2399498A00A769D7 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 541AC5DB2399498A00A769D7 /* Main.storyboard */; };
541AC5DF2399498B00A769D7 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 541AC5DE2399498B00A769D7 /* Assets.xcassets */; };
541AC5E22399498B00A769D7 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 541AC5E02399498B00A769D7 /* LaunchScreen.storyboard */; };
541DCA6124A6B0F6005F1A4B /* Color.swift in Sources */ = {isa = PBXBuildFile; fileRef = 541DCA6024A6B0F6005F1A4B /* Color.swift */; };
541FC47624A12D01009154D8 /* IBViews.swift in Sources */ = {isa = PBXBuildFile; fileRef = 541FC47524A12D01009154D8 /* IBViews.swift */; };
541FC47824A1453F009154D8 /* VCCoOccurrence.swift in Sources */ = {isa = PBXBuildFile; fileRef = 541FC47724A1453F009154D8 /* VCCoOccurrence.swift */; };
541FC9872497D81C00962623 /* TheGreatDestroyer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 541FC9862497D81C00962623 /* TheGreatDestroyer.swift */; };
542E2A982404973F001462DC /* TBCMain.swift in Sources */ = {isa = PBXBuildFile; fileRef = 542E2A972404973F001462DC /* TBCMain.swift */; };
542E2A9A24051556001462DC /* TVCSettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = 542E2A9924051556001462DC /* TVCSettings.swift */; };
543078AA24B5E12500278F2D /* snap2.caf in Resources */ = {isa = PBXBuildFile; fileRef = 5430789F24B5E12200278F2D /* snap2.caf */; };
543078AB24B5E12500278F2D /* snap2.caf in Resources */ = {isa = PBXBuildFile; fileRef = 5430789F24B5E12200278F2D /* snap2.caf */; };
543078AC24B5E12500278F2D /* typewriter2.caf in Resources */ = {isa = PBXBuildFile; fileRef = 543078A024B5E12200278F2D /* typewriter2.caf */; };
543078AD24B5E12500278F2D /* typewriter2.caf in Resources */ = {isa = PBXBuildFile; fileRef = 543078A024B5E12200278F2D /* typewriter2.caf */; };
543078AE24B5E12500278F2D /* wood1.caf in Resources */ = {isa = PBXBuildFile; fileRef = 543078A124B5E12300278F2D /* wood1.caf */; };
543078AF24B5E12500278F2D /* wood1.caf in Resources */ = {isa = PBXBuildFile; fileRef = 543078A124B5E12300278F2D /* wood1.caf */; };
543078B024B5E12500278F2D /* plop2.caf in Resources */ = {isa = PBXBuildFile; fileRef = 543078A224B5E12300278F2D /* plop2.caf */; };
543078B124B5E12500278F2D /* plop2.caf in Resources */ = {isa = PBXBuildFile; fileRef = 543078A224B5E12300278F2D /* plop2.caf */; };
543078B224B5E12500278F2D /* plop1.caf in Resources */ = {isa = PBXBuildFile; fileRef = 543078A324B5E12300278F2D /* plop1.caf */; };
543078B324B5E12500278F2D /* plop1.caf in Resources */ = {isa = PBXBuildFile; fileRef = 543078A324B5E12300278F2D /* plop1.caf */; };
543078B424B5E12500278F2D /* snap1.caf in Resources */ = {isa = PBXBuildFile; fileRef = 543078A424B5E12300278F2D /* snap1.caf */; };
543078B524B5E12500278F2D /* snap1.caf in Resources */ = {isa = PBXBuildFile; fileRef = 543078A424B5E12300278F2D /* snap1.caf */; };
543078B624B5E12500278F2D /* drum1.caf in Resources */ = {isa = PBXBuildFile; fileRef = 543078A524B5E12300278F2D /* drum1.caf */; };
543078B724B5E12500278F2D /* drum1.caf in Resources */ = {isa = PBXBuildFile; fileRef = 543078A524B5E12300278F2D /* drum1.caf */; };
543078B824B5E12500278F2D /* wood2.caf in Resources */ = {isa = PBXBuildFile; fileRef = 543078A624B5E12400278F2D /* wood2.caf */; };
543078B924B5E12500278F2D /* wood2.caf in Resources */ = {isa = PBXBuildFile; fileRef = 543078A624B5E12400278F2D /* wood2.caf */; };
543078BA24B5E12500278F2D /* typewriter1.caf in Resources */ = {isa = PBXBuildFile; fileRef = 543078A724B5E12400278F2D /* typewriter1.caf */; };
543078BB24B5E12500278F2D /* typewriter1.caf in Resources */ = {isa = PBXBuildFile; fileRef = 543078A724B5E12400278F2D /* typewriter1.caf */; };
543078BC24B5E12500278F2D /* clock.caf in Resources */ = {isa = PBXBuildFile; fileRef = 543078A824B5E12400278F2D /* clock.caf */; };
543078BD24B5E12500278F2D /* clock.caf in Resources */ = {isa = PBXBuildFile; fileRef = 543078A824B5E12400278F2D /* clock.caf */; };
543078BE24B5E12500278F2D /* drum2.caf in Resources */ = {isa = PBXBuildFile; fileRef = 543078A924B5E12500278F2D /* drum2.caf */; };
543078BF24B5E12500278F2D /* drum2.caf in Resources */ = {isa = PBXBuildFile; fileRef = 543078A924B5E12500278F2D /* drum2.caf */; };
543078C324B60F3B00278F2D /* Settings.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 543078C124B60F3B00278F2D /* Settings.storyboard */; };
543078C924B75CEA00278F2D /* PushNotificationAppOnly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 543078C824B75CD100278F2D /* PushNotificationAppOnly.swift */; };
543CDB2023EEE61900B7F323 /* PacketTunnelProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 543CDB1F23EEE61900B7F323 /* PacketTunnelProvider.swift */; };
543CDB2523EEE61900B7F323 /* GlassVPN.appex in Embed App Extensions */ = {isa = PBXBuildFile; fileRef = 543CDB1D23EEE61900B7F323 /* GlassVPN.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
544C95262407B1C700AB89D0 /* SharedState.swift in Sources */ = {isa = PBXBuildFile; fileRef = 544C95252407B1C700AB89D0 /* SharedState.swift */; };
546063E523FEFAFE008F505A /* SQDB.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54B7562223D7B2DC008F0C41 /* SQDB.swift */; };
54751E512423955100168273 /* FileManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54751E502423955000168273 /* FileManager.swift */; };
54751E522423955100168273 /* FileManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54751E502423955000168273 /* FileManager.swift */; };
54953E3323DC752E0054345C /* SQDB.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54B7562223D7B2DC008F0C41 /* SQDB.swift */; };
54448A2E2486464F00771C96 /* Array.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54448A2D2486464F00771C96 /* Array.swift */; };
54448A30248647D900771C96 /* Time.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54448A2F248647D900771C96 /* Time.swift */; };
54448A3224899A4000771C96 /* SearchBarManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54448A3124899A4000771C96 /* SearchBarManager.swift */; };
544F912024A67EC5001D4B00 /* TVCOccurrenceContext.swift in Sources */ = {isa = PBXBuildFile; fileRef = 544F911F24A67EC5001D4B00 /* TVCOccurrenceContext.swift */; };
5458EBC0243A3F2200CFEB15 /* TVCRecordingDetails.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5458EBBF243A3F2200CFEB15 /* TVCRecordingDetails.swift */; };
545DDDCF243E6267003B6544 /* TutorialSheet.swift in Sources */ = {isa = PBXBuildFile; fileRef = 545DDDCE243E6267003B6544 /* TutorialSheet.swift */; };
545DDDD124436983003B6544 /* QuickUI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 545DDDD024436983003B6544 /* QuickUI.swift */; };
545DDDD424466D37003B6544 /* AutoLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 545DDDD324466D37003B6544 /* AutoLayout.swift */; };
546063E523FEFAFE008F505A /* DBCore.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54B7562223D7B2DC008F0C41 /* DBCore.swift */; };
54751E512423955100168273 /* URL.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54751E502423955000168273 /* URL.swift */; };
54751E522423955100168273 /* URL.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54751E502423955000168273 /* URL.swift */; };
54953E3323DC752E0054345C /* DBCore.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54B7562223D7B2DC008F0C41 /* DBCore.swift */; };
54953E5F23DEBE840054345C /* TVCDomains.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54953E5E23DEBE840054345C /* TVCDomains.swift */; };
54953E6123E0D69A0054345C /* TVCHosts.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54953E6023E0D69A0054345C /* TVCHosts.swift */; };
54953E6F23E44CD00054345C /* TVCHostDetails.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54953E6E23E44CD00054345C /* TVCHostDetails.swift */; };
54953E7123E473F10054345C /* Settings.bundle in Resources */ = {isa = PBXBuildFile; fileRef = 54953E7023E473F10054345C /* Settings.bundle */; };
549ECD9D24A7AD550097571C /* CustomAlert.swift in Sources */ = {isa = PBXBuildFile; fileRef = 549ECD9C24A7AD550097571C /* CustomAlert.swift */; };
54B34594240E6343004C53CC /* TVCFilter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54B34593240E6343004C53CC /* TVCFilter.swift */; };
54B34596240F0513004C53CC /* TableView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54B34595240F0513004C53CC /* TableView.swift */; };
54B345992414F491004C53CC /* DBWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54B345982414F491004C53CC /* DBWrapper.swift */; };
54B345A6241BB982004C53CC /* Notifications.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54B345A5241BB982004C53CC /* Notifications.swift */; };
54B345A9241BBA0B004C53CC /* Generic.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54B345A8241BBA0B004C53CC /* Generic.swift */; };
54B345A9241BBA0B004C53CC /* Logging.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54B345A8241BBA0B004C53CC /* Logging.swift */; };
54B345AB241BBA5B004C53CC /* AlertSheet.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54B345AA241BBA5B004C53CC /* AlertSheet.swift */; };
54B345AD241BBB00004C53CC /* GroupedDomain.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54B345AC241BBB00004C53CC /* GroupedDomain.swift */; };
54B345AD241BBB00004C53CC /* DBExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54B345AC241BBB00004C53CC /* DBExtensions.swift */; };
54B345B0242264F8004C53CC /* third-level.txt in Resources */ = {isa = PBXBuildFile; fileRef = 54B345AF242264F8004C53CC /* third-level.txt */; };
54C056DB23E9E36E00214A3F /* AppInfoType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54C056DA23E9E36E00214A3F /* AppInfoType.swift */; };
54C056DD23E9EEF700214A3F /* BundleIcon.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54C056DC23E9EEF700214A3F /* BundleIcon.swift */; };
@@ -86,8 +137,6 @@
54CA02952426B2FD003A5E04 /* DNSEnums.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54CA02242426B2FC003A5E04 /* DNSEnums.swift */; };
54CA02962426B2FD003A5E04 /* PacketProtocolParser.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54CA02262426B2FC003A5E04 /* PacketProtocolParser.swift */; };
54CA02972426B2FD003A5E04 /* IPPacket.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54CA02272426B2FC003A5E04 /* IPPacket.swift */; };
54CA02982426B2FD003A5E04 /* IPMutablePacket.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54CA02282426B2FC003A5E04 /* IPMutablePacket.swift */; };
54CA02992426B2FD003A5E04 /* TCPMutablePacket.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54CA02292426B2FC003A5E04 /* TCPMutablePacket.swift */; };
54CA029A2426B2FD003A5E04 /* Observer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54CA022B2426B2FC003A5E04 /* Observer.swift */; };
54CA029C2426B2FD003A5E04 /* AdapterSocketEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54CA022E2426B2FC003A5E04 /* AdapterSocketEvent.swift */; };
54CA029D2426B2FD003A5E04 /* ProxyServerEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54CA022F2426B2FC003A5E04 /* ProxyServerEvent.swift */; };
@@ -102,8 +151,6 @@
54CA02A72426B2FD003A5E04 /* DirectAdapter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54CA023B2426B2FC003A5E04 /* DirectAdapter.swift */; };
54CA02A82426B2FD003A5E04 /* SOCKS5Adapter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54CA023C2426B2FC003A5E04 /* SOCKS5Adapter.swift */; };
54CA02A92426B2FD003A5E04 /* RejectAdapter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54CA023D2426B2FC003A5E04 /* RejectAdapter.swift */; };
54CA02AA2426B2FD003A5E04 /* SpeedAdapterFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54CA023F2426B2FC003A5E04 /* SpeedAdapterFactory.swift */; };
54CA02AB2426B2FD003A5E04 /* ShadowsocksAdapterFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54CA02402426B2FC003A5E04 /* ShadowsocksAdapterFactory.swift */; };
54CA02AC2426B2FD003A5E04 /* AuthenticationServerAdapterFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54CA02412426B2FC003A5E04 /* AuthenticationServerAdapterFactory.swift */; };
54CA02AD2426B2FD003A5E04 /* RejectAdapterFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54CA02422426B2FC003A5E04 /* RejectAdapterFactory.swift */; };
54CA02AE2426B2FD003A5E04 /* AdapterFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54CA02432426B2FD003A5E04 /* AdapterFactory.swift */; };
@@ -112,10 +159,6 @@
54CA02B12426B2FD003A5E04 /* ServerAdapterFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54CA02462426B2FD003A5E04 /* ServerAdapterFactory.swift */; };
54CA02B22426B2FD003A5E04 /* AdapterFactoryManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54CA02472426B2FD003A5E04 /* AdapterFactoryManager.swift */; };
54CA02B32426B2FD003A5E04 /* HTTPAdapterFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54CA02482426B2FD003A5E04 /* HTTPAdapterFactory.swift */; };
54CA02B42426B2FD003A5E04 /* StreamObfuscater.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54CA024A2426B2FD003A5E04 /* StreamObfuscater.swift */; };
54CA02B52426B2FD003A5E04 /* CryptoStreamProcessor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54CA024B2426B2FD003A5E04 /* CryptoStreamProcessor.swift */; };
54CA02B62426B2FD003A5E04 /* ProtocolObfuscater.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54CA024C2426B2FD003A5E04 /* ProtocolObfuscater.swift */; };
54CA02B72426B2FD003A5E04 /* ShadowsocksAdapter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54CA024D2426B2FD003A5E04 /* ShadowsocksAdapter.swift */; };
54CA02B82426B2FD003A5E04 /* HTTPProxySocket.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54CA024F2426B2FD003A5E04 /* HTTPProxySocket.swift */; };
54CA02B92426B2FD003A5E04 /* DirectProxySocket.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54CA02502426B2FD003A5E04 /* DirectProxySocket.swift */; };
54CA02BA2426B2FD003A5E04 /* ProxySocket.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54CA02512426B2FD003A5E04 /* ProxySocket.swift */; };
@@ -124,6 +167,25 @@
54CA02BE2426D4F3003A5E04 /* DDLog.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54CA02BD2426D4F3003A5E04 /* DDLog.swift */; };
54CA02C32426DCCD003A5E04 /* GCDAsyncSocket.m in Sources */ = {isa = PBXBuildFile; fileRef = 54CA02BF2426DCCC003A5E04 /* GCDAsyncSocket.m */; };
54CA02C42426DCCD003A5E04 /* GCDAsyncUdpSocket.m in Sources */ = {isa = PBXBuildFile; fileRef = 54CA02C02426DCCD003A5E04 /* GCDAsyncUdpSocket.m */; };
54CE8BC424B1ED2100CC1756 /* PushNotification.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54CE8BC324B1ED2100CC1756 /* PushNotification.swift */; };
54CE8BC524B1ED2100CC1756 /* PushNotification.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54CE8BC324B1ED2100CC1756 /* PushNotification.swift */; };
54D8B97A246C9F2000EB2414 /* FilterPipeline.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54D8B979246C9F2000EB2414 /* FilterPipeline.swift */; };
54D8B97C2471A7E000EB2414 /* String.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54D8B97B2471A7E000EB2414 /* String.swift */; };
54D8B97E2471B88900EB2414 /* DBCommon.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54D8B97D2471B88900EB2414 /* DBCommon.swift */; };
54D8B97F2471B89100EB2414 /* DBCommon.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54D8B97D2471B88900EB2414 /* DBCommon.swift */; };
54D8B9832471BD8100EB2414 /* DBAppOnly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54D8B9822471BD8100EB2414 /* DBAppOnly.swift */; };
54D8B98624796E9900EB2414 /* GroupedDomainDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54D8B98524796E9800EB2414 /* GroupedDomainDataSource.swift */; };
54E540F2247C423200F7C34A /* DomainFilter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54E540F1247C423200F7C34A /* DomainFilter.swift */; };
54E540F4247D3F2600F7C34A /* SimulatorVPN.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54E540F3247D3F2600F7C34A /* SimulatorVPN.swift */; };
54E540F8247DB90F00F7C34A /* RecordingsDB.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54E540F7247DB90F00F7C34A /* RecordingsDB.swift */; };
54E540FA2482414800F7C34A /* SyncUpdate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54E540F92482414800F7C34A /* SyncUpdate.swift */; };
54E67E4624A8B0FE0025D261 /* PrefsShared.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54E67E4524A8B0FE0025D261 /* PrefsShared.swift */; };
54E67E4924A8B1280025D261 /* Prefs.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54E67E4824A8B1280025D261 /* Prefs.swift */; };
54E67E4B24A8C6370025D261 /* GlassVPN.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54E67E4A24A8C6370025D261 /* GlassVPN.swift */; };
54E67E4D24A8E20D0025D261 /* TVCSettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = 542E2A9924051556001462DC /* TVCSettings.swift */; };
54E67E4F24A8E2910025D261 /* Equatable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54E67E4E24A8E2910025D261 /* Equatable.swift */; };
54E67E5124A8E8820025D261 /* View.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54E67E5024A8E8820025D261 /* View.swift */; };
54EFA4E82491A16A0022D618 /* Font.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54EFA4E72491A16A0022D618 /* Font.swift */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
@@ -151,7 +213,19 @@
/* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */
540C6456240D929300E948F9 /* EditableRows.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditableRows.swift; sourceTree = "<group>"; };
5404AEEC24A95F3F003B2F54 /* SlideInAnimation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SlideInAnimation.swift; sourceTree = "<group>"; };
5404AEEE24ACC089003B2F54 /* VCAnalysisBar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VCAnalysisBar.swift; sourceTree = "<group>"; };
540E677F242D2CF100871BBE /* VCRecordings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VCRecordings.swift; sourceTree = "<group>"; };
540E67812433483D00871BBE /* VCEditRecording.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VCEditRecording.swift; sourceTree = "<group>"; };
540E67832433FAFE00871BBE /* TVCPreviousRecords.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TVCPreviousRecords.swift; sourceTree = "<group>"; };
541075CD24C9D43A00D6F1BF /* UNNotification.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UNNotification.swift; sourceTree = "<group>"; };
541075D024CDBA0000D6F1BF /* ThrottledBatchQueue.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ThrottledBatchQueue.swift; sourceTree = "<group>"; };
541075D424CE286200D6F1BF /* CachedConnectionAlert.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CachedConnectionAlert.swift; sourceTree = "<group>"; };
541075D824CE2C7200D6F1BF /* GlassVPNHook.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GlassVPNHook.swift; sourceTree = "<group>"; };
5412F8ED24571B8100A63D7A /* VCDateFilter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VCDateFilter.swift; sourceTree = "<group>"; };
5412FCBF24C628F9000DE429 /* TVCReminderAlerts.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TVCReminderAlerts.swift; sourceTree = "<group>"; };
5412FCC024C628F9000DE429 /* TVCChooseAlertTone.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TVCChooseAlertTone.swift; sourceTree = "<group>"; };
5412FCC124C628FA000DE429 /* TVCConnectionAlerts.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TVCConnectionAlerts.swift; sourceTree = "<group>"; };
541A957523E602DF00C09C19 /* LaunchIcon.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = LaunchIcon.png; sourceTree = "<group>"; };
541AC5D42399498A00A769D7 /* AppCheck.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = AppCheck.app; sourceTree = BUILT_PRODUCTS_DIR; };
541AC5D72399498A00A769D7 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
@@ -159,28 +233,52 @@
541AC5DE2399498B00A769D7 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
541AC5E12399498B00A769D7 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
541AC5E32399498B00A769D7 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
541DCA6024A6B0F6005F1A4B /* Color.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Color.swift; sourceTree = "<group>"; };
541FC47524A12D01009154D8 /* IBViews.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IBViews.swift; sourceTree = "<group>"; };
541FC47724A1453F009154D8 /* VCCoOccurrence.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VCCoOccurrence.swift; sourceTree = "<group>"; };
541FC9862497D81C00962623 /* TheGreatDestroyer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TheGreatDestroyer.swift; sourceTree = "<group>"; };
542E2A972404973F001462DC /* TBCMain.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TBCMain.swift; sourceTree = "<group>"; };
542E2A9924051556001462DC /* TVCSettings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TVCSettings.swift; sourceTree = "<group>"; };
5430789F24B5E12200278F2D /* snap2.caf */ = {isa = PBXFileReference; lastKnownFileType = file; path = snap2.caf; sourceTree = "<group>"; };
543078A024B5E12200278F2D /* typewriter2.caf */ = {isa = PBXFileReference; lastKnownFileType = file; path = typewriter2.caf; sourceTree = "<group>"; };
543078A124B5E12300278F2D /* wood1.caf */ = {isa = PBXFileReference; lastKnownFileType = file; path = wood1.caf; sourceTree = "<group>"; };
543078A224B5E12300278F2D /* plop2.caf */ = {isa = PBXFileReference; lastKnownFileType = file; path = plop2.caf; sourceTree = "<group>"; };
543078A324B5E12300278F2D /* plop1.caf */ = {isa = PBXFileReference; lastKnownFileType = file; path = plop1.caf; sourceTree = "<group>"; };
543078A424B5E12300278F2D /* snap1.caf */ = {isa = PBXFileReference; lastKnownFileType = file; path = snap1.caf; sourceTree = "<group>"; };
543078A524B5E12300278F2D /* drum1.caf */ = {isa = PBXFileReference; lastKnownFileType = file; path = drum1.caf; sourceTree = "<group>"; };
543078A624B5E12400278F2D /* wood2.caf */ = {isa = PBXFileReference; lastKnownFileType = file; path = wood2.caf; sourceTree = "<group>"; };
543078A724B5E12400278F2D /* typewriter1.caf */ = {isa = PBXFileReference; lastKnownFileType = file; path = typewriter1.caf; sourceTree = "<group>"; };
543078A824B5E12400278F2D /* clock.caf */ = {isa = PBXFileReference; lastKnownFileType = file; path = clock.caf; sourceTree = "<group>"; };
543078A924B5E12500278F2D /* drum2.caf */ = {isa = PBXFileReference; lastKnownFileType = file; path = drum2.caf; sourceTree = "<group>"; };
543078C224B60F3B00278F2D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Settings.storyboard; sourceTree = "<group>"; };
543078C824B75CD100278F2D /* PushNotificationAppOnly.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PushNotificationAppOnly.swift; sourceTree = "<group>"; };
543CDB1D23EEE61900B7F323 /* GlassVPN.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = GlassVPN.appex; sourceTree = BUILT_PRODUCTS_DIR; };
543CDB1F23EEE61900B7F323 /* PacketTunnelProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PacketTunnelProvider.swift; sourceTree = "<group>"; };
543CDB2123EEE61900B7F323 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
543CDB2223EEE61900B7F323 /* GlassVPN.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = GlassVPN.entitlements; sourceTree = "<group>"; };
544C95252407B1C700AB89D0 /* SharedState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SharedState.swift; sourceTree = "<group>"; };
54751E502423955000168273 /* FileManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileManager.swift; sourceTree = "<group>"; };
54448A2D2486464F00771C96 /* Array.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Array.swift; sourceTree = "<group>"; };
54448A2F248647D900771C96 /* Time.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Time.swift; sourceTree = "<group>"; };
54448A3124899A4000771C96 /* SearchBarManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchBarManager.swift; sourceTree = "<group>"; };
544F911F24A67EC5001D4B00 /* TVCOccurrenceContext.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TVCOccurrenceContext.swift; sourceTree = "<group>"; };
5458EBBF243A3F2200CFEB15 /* TVCRecordingDetails.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TVCRecordingDetails.swift; sourceTree = "<group>"; };
545DDDCE243E6267003B6544 /* TutorialSheet.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TutorialSheet.swift; sourceTree = "<group>"; };
545DDDD024436983003B6544 /* QuickUI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QuickUI.swift; sourceTree = "<group>"; };
545DDDD324466D37003B6544 /* AutoLayout.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AutoLayout.swift; sourceTree = "<group>"; };
54751E502423955000168273 /* URL.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = URL.swift; sourceTree = "<group>"; };
548B1F9423D338EC005B047C /* main.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = main.entitlements; sourceTree = "<group>"; };
54953E5E23DEBE840054345C /* TVCDomains.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TVCDomains.swift; sourceTree = "<group>"; };
54953E6023E0D69A0054345C /* TVCHosts.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TVCHosts.swift; sourceTree = "<group>"; };
54953E6E23E44CD00054345C /* TVCHostDetails.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TVCHostDetails.swift; sourceTree = "<group>"; };
54953E7023E473F10054345C /* Settings.bundle */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.plug-in"; path = Settings.bundle; sourceTree = "<group>"; };
549ECD9C24A7AD550097571C /* CustomAlert.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomAlert.swift; sourceTree = "<group>"; };
54B34593240E6343004C53CC /* TVCFilter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TVCFilter.swift; sourceTree = "<group>"; };
54B34595240F0513004C53CC /* TableView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TableView.swift; sourceTree = "<group>"; };
54B345982414F491004C53CC /* DBWrapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DBWrapper.swift; sourceTree = "<group>"; };
54B345A5241BB982004C53CC /* Notifications.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Notifications.swift; sourceTree = "<group>"; };
54B345A8241BBA0B004C53CC /* Generic.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Generic.swift; sourceTree = "<group>"; };
54B345A8241BBA0B004C53CC /* Logging.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Logging.swift; sourceTree = "<group>"; };
54B345AA241BBA5B004C53CC /* AlertSheet.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AlertSheet.swift; sourceTree = "<group>"; };
54B345AC241BBB00004C53CC /* GroupedDomain.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GroupedDomain.swift; sourceTree = "<group>"; };
54B345AC241BBB00004C53CC /* DBExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DBExtensions.swift; sourceTree = "<group>"; };
54B345AF242264F8004C53CC /* third-level.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "third-level.txt"; sourceTree = "<group>"; };
54B7562223D7B2DC008F0C41 /* SQDB.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SQDB.swift; sourceTree = "<group>"; };
54B7562223D7B2DC008F0C41 /* DBCore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DBCore.swift; sourceTree = "<group>"; };
54C056DA23E9E36E00214A3F /* AppInfoType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppInfoType.swift; sourceTree = "<group>"; };
54C056DC23E9EEF700214A3F /* BundleIcon.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BundleIcon.swift; sourceTree = "<group>"; };
54CA00D62426A803003A5E04 /* CocoaAsyncSocket.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CocoaAsyncSocket.h; sourceTree = "<group>"; };
@@ -234,8 +332,6 @@
54CA02242426B2FC003A5E04 /* DNSEnums.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DNSEnums.swift; sourceTree = "<group>"; };
54CA02262426B2FC003A5E04 /* PacketProtocolParser.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PacketProtocolParser.swift; sourceTree = "<group>"; };
54CA02272426B2FC003A5E04 /* IPPacket.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IPPacket.swift; sourceTree = "<group>"; };
54CA02282426B2FC003A5E04 /* IPMutablePacket.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IPMutablePacket.swift; sourceTree = "<group>"; };
54CA02292426B2FC003A5E04 /* TCPMutablePacket.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TCPMutablePacket.swift; sourceTree = "<group>"; };
54CA022B2426B2FC003A5E04 /* Observer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Observer.swift; sourceTree = "<group>"; };
54CA022E2426B2FC003A5E04 /* AdapterSocketEvent.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AdapterSocketEvent.swift; sourceTree = "<group>"; };
54CA022F2426B2FC003A5E04 /* ProxyServerEvent.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ProxyServerEvent.swift; sourceTree = "<group>"; };
@@ -250,8 +346,6 @@
54CA023B2426B2FC003A5E04 /* DirectAdapter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DirectAdapter.swift; sourceTree = "<group>"; };
54CA023C2426B2FC003A5E04 /* SOCKS5Adapter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SOCKS5Adapter.swift; sourceTree = "<group>"; };
54CA023D2426B2FC003A5E04 /* RejectAdapter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RejectAdapter.swift; sourceTree = "<group>"; };
54CA023F2426B2FC003A5E04 /* SpeedAdapterFactory.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SpeedAdapterFactory.swift; sourceTree = "<group>"; };
54CA02402426B2FC003A5E04 /* ShadowsocksAdapterFactory.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ShadowsocksAdapterFactory.swift; sourceTree = "<group>"; };
54CA02412426B2FC003A5E04 /* AuthenticationServerAdapterFactory.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AuthenticationServerAdapterFactory.swift; sourceTree = "<group>"; };
54CA02422426B2FC003A5E04 /* RejectAdapterFactory.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RejectAdapterFactory.swift; sourceTree = "<group>"; };
54CA02432426B2FD003A5E04 /* AdapterFactory.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AdapterFactory.swift; sourceTree = "<group>"; };
@@ -260,10 +354,6 @@
54CA02462426B2FD003A5E04 /* ServerAdapterFactory.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ServerAdapterFactory.swift; sourceTree = "<group>"; };
54CA02472426B2FD003A5E04 /* AdapterFactoryManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AdapterFactoryManager.swift; sourceTree = "<group>"; };
54CA02482426B2FD003A5E04 /* HTTPAdapterFactory.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HTTPAdapterFactory.swift; sourceTree = "<group>"; };
54CA024A2426B2FD003A5E04 /* StreamObfuscater.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StreamObfuscater.swift; sourceTree = "<group>"; };
54CA024B2426B2FD003A5E04 /* CryptoStreamProcessor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CryptoStreamProcessor.swift; sourceTree = "<group>"; };
54CA024C2426B2FD003A5E04 /* ProtocolObfuscater.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ProtocolObfuscater.swift; sourceTree = "<group>"; };
54CA024D2426B2FD003A5E04 /* ShadowsocksAdapter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ShadowsocksAdapter.swift; sourceTree = "<group>"; };
54CA024F2426B2FD003A5E04 /* HTTPProxySocket.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HTTPProxySocket.swift; sourceTree = "<group>"; };
54CA02502426B2FD003A5E04 /* DirectProxySocket.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DirectProxySocket.swift; sourceTree = "<group>"; };
54CA02512426B2FD003A5E04 /* ProxySocket.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ProxySocket.swift; sourceTree = "<group>"; };
@@ -274,6 +364,22 @@
54CA02C02426DCCD003A5E04 /* GCDAsyncUdpSocket.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GCDAsyncUdpSocket.m; sourceTree = "<group>"; };
54CA02C12426DCCD003A5E04 /* GCDAsyncSocket.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GCDAsyncSocket.h; sourceTree = "<group>"; };
54CA02C22426DCCD003A5E04 /* GCDAsyncUdpSocket.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GCDAsyncUdpSocket.h; sourceTree = "<group>"; };
54CE8BC324B1ED2100CC1756 /* PushNotification.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PushNotification.swift; sourceTree = "<group>"; };
54D8B979246C9F2000EB2414 /* FilterPipeline.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FilterPipeline.swift; sourceTree = "<group>"; };
54D8B97B2471A7E000EB2414 /* String.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = String.swift; sourceTree = "<group>"; };
54D8B97D2471B88900EB2414 /* DBCommon.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DBCommon.swift; sourceTree = "<group>"; };
54D8B9822471BD8100EB2414 /* DBAppOnly.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DBAppOnly.swift; sourceTree = "<group>"; };
54D8B98524796E9800EB2414 /* GroupedDomainDataSource.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GroupedDomainDataSource.swift; sourceTree = "<group>"; };
54E540F1247C423200F7C34A /* DomainFilter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DomainFilter.swift; sourceTree = "<group>"; };
54E540F3247D3F2600F7C34A /* SimulatorVPN.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SimulatorVPN.swift; sourceTree = "<group>"; };
54E540F7247DB90F00F7C34A /* RecordingsDB.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RecordingsDB.swift; sourceTree = "<group>"; };
54E540F92482414800F7C34A /* SyncUpdate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SyncUpdate.swift; sourceTree = "<group>"; };
54E67E4524A8B0FE0025D261 /* PrefsShared.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PrefsShared.swift; sourceTree = "<group>"; };
54E67E4824A8B1280025D261 /* Prefs.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Prefs.swift; sourceTree = "<group>"; };
54E67E4A24A8C6370025D261 /* GlassVPN.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GlassVPN.swift; sourceTree = "<group>"; };
54E67E4E24A8E2910025D261 /* Equatable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Equatable.swift; sourceTree = "<group>"; };
54E67E5024A8E8820025D261 /* View.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = View.swift; sourceTree = "<group>"; };
54EFA4E72491A16A0022D618 /* Font.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Font.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -298,8 +404,11 @@
isa = PBXGroup;
children = (
54953E5E23DEBE840054345C /* TVCDomains.swift */,
5412F8ED24571B8100A63D7A /* VCDateFilter.swift */,
54953E6023E0D69A0054345C /* TVCHosts.swift */,
54953E6E23E44CD00054345C /* TVCHostDetails.swift */,
544F911F24A67EC5001D4B00 /* TVCOccurrenceContext.swift */,
541FC47424A12CE9009154D8 /* Analysis */,
);
path = Requests;
sourceTree = "<group>";
@@ -309,10 +418,35 @@
children = (
542E2A9924051556001462DC /* TVCSettings.swift */,
54B34593240E6343004C53CC /* TVCFilter.swift */,
5412FCBF24C628F9000DE429 /* TVCReminderAlerts.swift */,
5412FCC124C628FA000DE429 /* TVCConnectionAlerts.swift */,
5412FCC024C628F9000DE429 /* TVCChooseAlertTone.swift */,
);
path = Settings;
sourceTree = "<group>";
};
540E677E242D2CD200871BBE /* Recordings */ = {
isa = PBXGroup;
children = (
540E677F242D2CF100871BBE /* VCRecordings.swift */,
540E67832433FAFE00871BBE /* TVCPreviousRecords.swift */,
540E67812433483D00871BBE /* VCEditRecording.swift */,
5458EBBF243A3F2200CFEB15 /* TVCRecordingDetails.swift */,
);
path = Recordings;
sourceTree = "<group>";
};
541075D324CE284700D6F1BF /* Push Notifications */ = {
isa = PBXGroup;
children = (
541075CD24C9D43A00D6F1BF /* UNNotification.swift */,
54CE8BC324B1ED2100CC1756 /* PushNotification.swift */,
543078C824B75CD100278F2D /* PushNotificationAppOnly.swift */,
541075D424CE286200D6F1BF /* CachedConnectionAlert.swift */,
);
path = "Push Notifications";
sourceTree = "<group>";
};
541AC5CB2399498A00A769D7 = {
isa = PBXGroup;
children = (
@@ -336,16 +470,22 @@
isa = PBXGroup;
children = (
54B3459A2415651C004C53CC /* DB */,
54E540F0247C386500F7C34A /* Data Source */,
54B345A4241BB975004C53CC /* Extensions */,
545DDDD224436A03003B6544 /* Common Classes */,
541075D324CE284700D6F1BF /* Push Notifications */,
548B1F9423D338EC005B047C /* main.entitlements */,
541AC5D72399498A00A769D7 /* AppDelegate.swift */,
54E67E4A24A8C6370025D261 /* GlassVPN.swift */,
541075D824CE2C7200D6F1BF /* GlassVPNHook.swift */,
542E2A972404973F001462DC /* TBCMain.swift */,
54B34597240F18DD004C53CC /* TVC Extensions */,
540C6454240D5BAE00E948F9 /* Requests */,
540E677E242D2CD200871BBE /* Recordings */,
540C6455240D5BD200E948F9 /* Settings */,
54B345B12422E029004C53CC /* unused */,
541AC5DB2399498A00A769D7 /* Main.storyboard */,
541AC5E02399498B00A769D7 /* LaunchScreen.storyboard */,
541AC5DB2399498A00A769D7 /* Main.storyboard */,
543078C124B60F3B00278F2D /* Settings.storyboard */,
541AC5DE2399498B00A769D7 /* Assets.xcassets */,
541AC5E32399498B00A769D7 /* Info.plist */,
54953E7023E473F10054345C /* Settings.bundle */,
@@ -353,15 +493,43 @@
path = main;
sourceTree = "<group>";
};
541FC47424A12CE9009154D8 /* Analysis */ = {
isa = PBXGroup;
children = (
5404AEEE24ACC089003B2F54 /* VCAnalysisBar.swift */,
541FC47724A1453F009154D8 /* VCCoOccurrence.swift */,
);
path = Analysis;
sourceTree = "<group>";
};
542E2A9B24051F79001462DC /* media */ = {
isa = PBXGroup;
children = (
5430789E24B5E10E00278F2D /* sounds */,
541A957523E602DF00C09C19 /* LaunchIcon.png */,
54B345AF242264F8004C53CC /* third-level.txt */,
);
path = media;
sourceTree = "<group>";
};
5430789E24B5E10E00278F2D /* sounds */ = {
isa = PBXGroup;
children = (
543078A824B5E12400278F2D /* clock.caf */,
543078A524B5E12300278F2D /* drum1.caf */,
543078A924B5E12500278F2D /* drum2.caf */,
543078A324B5E12300278F2D /* plop1.caf */,
543078A224B5E12300278F2D /* plop2.caf */,
543078A424B5E12300278F2D /* snap1.caf */,
5430789F24B5E12200278F2D /* snap2.caf */,
543078A724B5E12400278F2D /* typewriter1.caf */,
543078A024B5E12200278F2D /* typewriter2.caf */,
543078A124B5E12300278F2D /* wood1.caf */,
543078A624B5E12400278F2D /* wood2.caf */,
);
path = sounds;
sourceTree = "<group>";
};
543CDB1E23EEE61900B7F323 /* GlassVPN */ = {
isa = PBXGroup;
children = (
@@ -376,19 +544,31 @@
path = GlassVPN;
sourceTree = "<group>";
};
54B34597240F18DD004C53CC /* TVC Extensions */ = {
545DDDD224436A03003B6544 /* Common Classes */ = {
isa = PBXGroup;
children = (
540C6456240D929300E948F9 /* EditableRows.swift */,
54E67E4824A8B1280025D261 /* Prefs.swift */,
54E67E4524A8B0FE0025D261 /* PrefsShared.swift */,
545DDDD024436983003B6544 /* QuickUI.swift */,
545DDDCE243E6267003B6544 /* TutorialSheet.swift */,
54D8B979246C9F2000EB2414 /* FilterPipeline.swift */,
54448A3124899A4000771C96 /* SearchBarManager.swift */,
549ECD9C24A7AD550097571C /* CustomAlert.swift */,
541FC47524A12D01009154D8 /* IBViews.swift */,
5404AEEC24A95F3F003B2F54 /* SlideInAnimation.swift */,
541075D024CDBA0000D6F1BF /* ThrottledBatchQueue.swift */,
);
path = "TVC Extensions";
path = "Common Classes";
sourceTree = "<group>";
};
54B3459A2415651C004C53CC /* DB */ = {
isa = PBXGroup;
children = (
54B7562223D7B2DC008F0C41 /* SQDB.swift */,
54B345982414F491004C53CC /* DBWrapper.swift */,
54B7562223D7B2DC008F0C41 /* DBCore.swift */,
54D8B97D2471B88900EB2414 /* DBCommon.swift */,
54D8B9822471BD8100EB2414 /* DBAppOnly.swift */,
54B345AC241BBB00004C53CC /* DBExtensions.swift */,
541FC9862497D81C00962623 /* TheGreatDestroyer.swift */,
);
path = DB;
sourceTree = "<group>";
@@ -396,13 +576,19 @@
54B345A4241BB975004C53CC /* Extensions */ = {
isa = PBXGroup;
children = (
544C95252407B1C700AB89D0 /* SharedState.swift */,
54B345A8241BBA0B004C53CC /* Generic.swift */,
54B345A8241BBA0B004C53CC /* Logging.swift */,
54E67E4E24A8E2910025D261 /* Equatable.swift */,
54B345A5241BB982004C53CC /* Notifications.swift */,
54B345AA241BBA5B004C53CC /* AlertSheet.swift */,
54B345AC241BBB00004C53CC /* GroupedDomain.swift */,
54E67E5024A8E8820025D261 /* View.swift */,
541DCA6024A6B0F6005F1A4B /* Color.swift */,
54448A2F248647D900771C96 /* Time.swift */,
54751E502423955000168273 /* URL.swift */,
54EFA4E72491A16A0022D618 /* Font.swift */,
54448A2D2486464F00771C96 /* Array.swift */,
54D8B97B2471A7E000EB2414 /* String.swift */,
54B34595240F0513004C53CC /* TableView.swift */,
54751E502423955000168273 /* FileManager.swift */,
545DDDD324466D37003B6544 /* AutoLayout.swift */,
);
path = Extensions;
sourceTree = "<group>";
@@ -562,8 +748,6 @@
children = (
54CA02262426B2FC003A5E04 /* PacketProtocolParser.swift */,
54CA02272426B2FC003A5E04 /* IPPacket.swift */,
54CA02282426B2FC003A5E04 /* IPMutablePacket.swift */,
54CA02292426B2FC003A5E04 /* TCPMutablePacket.swift */,
);
path = Packet;
sourceTree = "<group>";
@@ -611,7 +795,6 @@
54CA023C2426B2FC003A5E04 /* SOCKS5Adapter.swift */,
54CA023D2426B2FC003A5E04 /* RejectAdapter.swift */,
54CA023E2426B2FC003A5E04 /* Factory */,
54CA02492426B2FD003A5E04 /* Shadowsocks */,
);
path = AdapterSocket;
sourceTree = "<group>";
@@ -619,8 +802,6 @@
54CA023E2426B2FC003A5E04 /* Factory */ = {
isa = PBXGroup;
children = (
54CA023F2426B2FC003A5E04 /* SpeedAdapterFactory.swift */,
54CA02402426B2FC003A5E04 /* ShadowsocksAdapterFactory.swift */,
54CA02412426B2FC003A5E04 /* AuthenticationServerAdapterFactory.swift */,
54CA02422426B2FC003A5E04 /* RejectAdapterFactory.swift */,
54CA02432426B2FD003A5E04 /* AdapterFactory.swift */,
@@ -633,17 +814,6 @@
path = Factory;
sourceTree = "<group>";
};
54CA02492426B2FD003A5E04 /* Shadowsocks */ = {
isa = PBXGroup;
children = (
54CA024A2426B2FD003A5E04 /* StreamObfuscater.swift */,
54CA024B2426B2FD003A5E04 /* CryptoStreamProcessor.swift */,
54CA024C2426B2FD003A5E04 /* ProtocolObfuscater.swift */,
54CA024D2426B2FD003A5E04 /* ShadowsocksAdapter.swift */,
);
path = Shadowsocks;
sourceTree = "<group>";
};
54CA024E2426B2FD003A5E04 /* ProxySocket */ = {
isa = PBXGroup;
children = (
@@ -655,6 +825,18 @@
path = ProxySocket;
sourceTree = "<group>";
};
54E540F0247C386500F7C34A /* Data Source */ = {
isa = PBXGroup;
children = (
54E540F3247D3F2600F7C34A /* SimulatorVPN.swift */,
54E540F92482414800F7C34A /* SyncUpdate.swift */,
54D8B98524796E9800EB2414 /* GroupedDomainDataSource.swift */,
54E540F1247C423200F7C34A /* DomainFilter.swift */,
54E540F7247DB90F00F7C34A /* RecordingsDB.swift */,
);
path = "Data Source";
sourceTree = "<group>";
};
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
@@ -749,11 +931,23 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
543078AC24B5E12500278F2D /* typewriter2.caf in Resources */,
54953E7123E473F10054345C /* Settings.bundle in Resources */,
543078B024B5E12500278F2D /* plop2.caf in Resources */,
541AC5E22399498B00A769D7 /* LaunchScreen.storyboard in Resources */,
543078B824B5E12500278F2D /* wood2.caf in Resources */,
543078BE24B5E12500278F2D /* drum2.caf in Resources */,
543078B424B5E12500278F2D /* snap1.caf in Resources */,
541AC5DF2399498B00A769D7 /* Assets.xcassets in Resources */,
543078AE24B5E12500278F2D /* wood1.caf in Resources */,
541AC5DD2399498A00A769D7 /* Main.storyboard in Resources */,
54B345B0242264F8004C53CC /* third-level.txt in Resources */,
543078BA24B5E12500278F2D /* typewriter1.caf in Resources */,
543078B224B5E12500278F2D /* plop1.caf in Resources */,
543078B624B5E12500278F2D /* drum1.caf in Resources */,
543078BC24B5E12500278F2D /* clock.caf in Resources */,
543078C324B60F3B00278F2D /* Settings.storyboard in Resources */,
543078AA24B5E12500278F2D /* snap2.caf in Resources */,
541A957623E602DF00C09C19 /* LaunchIcon.png in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
@@ -762,6 +956,17 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
543078AD24B5E12500278F2D /* typewriter2.caf in Resources */,
543078BB24B5E12500278F2D /* typewriter1.caf in Resources */,
543078BF24B5E12500278F2D /* drum2.caf in Resources */,
543078AF24B5E12500278F2D /* wood1.caf in Resources */,
543078B124B5E12500278F2D /* plop2.caf in Resources */,
543078AB24B5E12500278F2D /* snap2.caf in Resources */,
543078B924B5E12500278F2D /* wood2.caf in Resources */,
543078B724B5E12500278F2D /* drum1.caf in Resources */,
543078B524B5E12500278F2D /* snap1.caf in Resources */,
543078B324B5E12500278F2D /* plop1.caf in Resources */,
543078BD24B5E12500278F2D /* clock.caf in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -772,25 +977,65 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
54B345AD241BBB00004C53CC /* GroupedDomain.swift in Sources */,
54E67E4924A8B1280025D261 /* Prefs.swift in Sources */,
54E540F8247DB90F00F7C34A /* RecordingsDB.swift in Sources */,
54E67E4F24A8E2910025D261 /* Equatable.swift in Sources */,
54E540F4247D3F2600F7C34A /* SimulatorVPN.swift in Sources */,
541075D924CE2C7200D6F1BF /* GlassVPNHook.swift in Sources */,
541075D524CE286200D6F1BF /* CachedConnectionAlert.swift in Sources */,
5404AEEF24ACC089003B2F54 /* VCAnalysisBar.swift in Sources */,
545DDDD424466D37003B6544 /* AutoLayout.swift in Sources */,
54B345AD241BBB00004C53CC /* DBExtensions.swift in Sources */,
54E540F2247C423200F7C34A /* DomainFilter.swift in Sources */,
54D8B97E2471B88900EB2414 /* DBCommon.swift in Sources */,
54D8B9832471BD8100EB2414 /* DBAppOnly.swift in Sources */,
5412FCC224C628FA000DE429 /* TVCReminderAlerts.swift in Sources */,
54E67E4D24A8E20D0025D261 /* TVCSettings.swift in Sources */,
540E67842433FAFE00871BBE /* TVCPreviousRecords.swift in Sources */,
54B345A6241BB982004C53CC /* Notifications.swift in Sources */,
54448A2E2486464F00771C96 /* Array.swift in Sources */,
54E67E4B24A8C6370025D261 /* GlassVPN.swift in Sources */,
541FC47824A1453F009154D8 /* VCCoOccurrence.swift in Sources */,
54B345AB241BBA5B004C53CC /* AlertSheet.swift in Sources */,
544C95262407B1C700AB89D0 /* SharedState.swift in Sources */,
54B345A9241BBA0B004C53CC /* Generic.swift in Sources */,
541DCA6124A6B0F6005F1A4B /* Color.swift in Sources */,
545DDDCF243E6267003B6544 /* TutorialSheet.swift in Sources */,
54B345A9241BBA0B004C53CC /* Logging.swift in Sources */,
54B34596240F0513004C53CC /* TableView.swift in Sources */,
54953E3323DC752E0054345C /* SQDB.swift in Sources */,
540E6780242D2CF100871BBE /* VCRecordings.swift in Sources */,
541075D124CDBA0000D6F1BF /* ThrottledBatchQueue.swift in Sources */,
54953E3323DC752E0054345C /* DBCore.swift in Sources */,
54E67E4624A8B0FE0025D261 /* PrefsShared.swift in Sources */,
5412FCC324C628FA000DE429 /* TVCChooseAlertTone.swift in Sources */,
544F912024A67EC5001D4B00 /* TVCOccurrenceContext.swift in Sources */,
54448A30248647D900771C96 /* Time.swift in Sources */,
54953E6123E0D69A0054345C /* TVCHosts.swift in Sources */,
540C6457240D929300E948F9 /* EditableRows.swift in Sources */,
54751E512423955100168273 /* FileManager.swift in Sources */,
542E2A9A24051556001462DC /* TVCSettings.swift in Sources */,
54751E512423955100168273 /* URL.swift in Sources */,
54953E5F23DEBE840054345C /* TVCDomains.swift in Sources */,
54C056DB23E9E36E00214A3F /* AppInfoType.swift in Sources */,
54D8B98624796E9900EB2414 /* GroupedDomainDataSource.swift in Sources */,
541075CE24C9D43A00D6F1BF /* UNNotification.swift in Sources */,
54953E6F23E44CD00054345C /* TVCHostDetails.swift in Sources */,
54D8B97C2471A7E000EB2414 /* String.swift in Sources */,
54E67E5124A8E8820025D261 /* View.swift in Sources */,
54C056DD23E9EEF700214A3F /* BundleIcon.swift in Sources */,
542E2A982404973F001462DC /* TBCMain.swift in Sources */,
54448A3224899A4000771C96 /* SearchBarManager.swift in Sources */,
5458EBC0243A3F2200CFEB15 /* TVCRecordingDetails.swift in Sources */,
541FC9872497D81C00962623 /* TheGreatDestroyer.swift in Sources */,
5412F8EE24571B8200A63D7A /* VCDateFilter.swift in Sources */,
5412FCC424C628FA000DE429 /* TVCConnectionAlerts.swift in Sources */,
543078C924B75CEA00278F2D /* PushNotificationAppOnly.swift in Sources */,
545DDDD124436983003B6544 /* QuickUI.swift in Sources */,
541AC5D82399498A00A769D7 /* AppDelegate.swift in Sources */,
54B345992414F491004C53CC /* DBWrapper.swift in Sources */,
541FC47624A12D01009154D8 /* IBViews.swift in Sources */,
540E67822433483D00871BBE /* VCEditRecording.swift in Sources */,
54EFA4E82491A16A0022D618 /* Font.swift in Sources */,
54D8B97A246C9F2000EB2414 /* FilterPipeline.swift in Sources */,
54B34594240E6343004C53CC /* TVCFilter.swift in Sources */,
549ECD9D24A7AD550097571C /* CustomAlert.swift in Sources */,
54CE8BC424B1ED2100CC1756 /* PushNotification.swift in Sources */,
54E540FA2482414800F7C34A /* SyncUpdate.swift in Sources */,
5404AEED24A95F3F003B2F54 /* SlideInAnimation.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -802,17 +1047,16 @@
54CA025D2426B2FD003A5E04 /* HTTPHeader.swift in Sources */,
54CA02832426B2FD003A5E04 /* DNSSessionMatchResult.swift in Sources */,
54CA02862426B2FD003A5E04 /* RuleManager.swift in Sources */,
54CA02B52426B2FD003A5E04 /* CryptoStreamProcessor.swift in Sources */,
54CA02B82426B2FD003A5E04 /* HTTPProxySocket.swift in Sources */,
54CA02C32426DCCD003A5E04 /* GCDAsyncSocket.m in Sources */,
54CA02752426B2FD003A5E04 /* IPRange.swift in Sources */,
54CA02722426B2FD003A5E04 /* IPInterval.swift in Sources */,
54CA029A2426B2FD003A5E04 /* Observer.swift in Sources */,
54CA025C2426B2FD003A5E04 /* ConnectSession.swift in Sources */,
5404AEEB24A90717003B2F54 /* PrefsShared.swift in Sources */,
54CA02C42426DCCD003A5E04 /* GCDAsyncUdpSocket.m in Sources */,
54CA02BA2426B2FD003A5E04 /* ProxySocket.swift in Sources */,
54CA025E2426B2FD003A5E04 /* ResponseGeneratorFactory.swift in Sources */,
54CA02982426B2FD003A5E04 /* IPMutablePacket.swift in Sources */,
54CA02892426B2FD003A5E04 /* Tunnel.swift in Sources */,
54CA029F2426B2FD003A5E04 /* ProxySocketEvent.swift in Sources */,
54CA027D2426B2FD003A5E04 /* GlobalIntializer.swift in Sources */,
@@ -823,10 +1067,8 @@
54CA029E2426B2FD003A5E04 /* EventType.swift in Sources */,
54CA02912426B2FD003A5E04 /* DNSMessage.swift in Sources */,
54CA02712426B2FD003A5E04 /* UInt128.swift in Sources */,
54CA02B62426B2FD003A5E04 /* ProtocolObfuscater.swift in Sources */,
54CA02882426B2FD003A5E04 /* QueueFactory.swift in Sources */,
54CA02A12426B2FD003A5E04 /* RuleMatchEvent.swift in Sources */,
54CA02AB2426B2FD003A5E04 /* ShadowsocksAdapterFactory.swift in Sources */,
54CA02BE2426D4F3003A5E04 /* DDLog.swift in Sources */,
54CA02962426B2FD003A5E04 /* PacketProtocolParser.swift in Sources */,
54CA02932426B2FD003A5E04 /* DNSServer.swift in Sources */,
@@ -835,31 +1077,33 @@
54CA02A82426B2FD003A5E04 /* SOCKS5Adapter.swift in Sources */,
54CA02792426B2FD003A5E04 /* Checksum.swift in Sources */,
54CA02AD2426B2FD003A5E04 /* RejectAdapterFactory.swift in Sources */,
541075D224CDBA0000D6F1BF /* ThrottledBatchQueue.swift in Sources */,
54CA02672426B2FD003A5E04 /* RawTCPSocketProtocol.swift in Sources */,
54CA02602426B2FD003A5E04 /* GCDProxyServer.swift in Sources */,
54CA026B2426B2FD003A5E04 /* GCDTCPSocket.swift in Sources */,
54CA028E2426B2FD003A5E04 /* IPStackProtocol.swift in Sources */,
54CA01D52426B252003A5E04 /* SafeDict.swift in Sources */,
54CA02992426B2FD003A5E04 /* TCPMutablePacket.swift in Sources */,
54CA027B2426B2FD003A5E04 /* HTTPAuthentication.swift in Sources */,
54CA02762426B2FD003A5E04 /* IPAddress.swift in Sources */,
54CA02B02426B2FD003A5E04 /* SecureHTTPAdapterFactory.swift in Sources */,
54CA02A62426B2FD003A5E04 /* AdapterSocket.swift in Sources */,
54CA02742426B2FD003A5E04 /* IPMask.swift in Sources */,
541075CF24C9D43A00D6F1BF /* UNNotification.swift in Sources */,
54CA02BB2426B2FD003A5E04 /* SOCKS5ProxySocket.swift in Sources */,
54D8B97F2471B89100EB2414 /* DBCommon.swift in Sources */,
54CA02A42426B2FD003A5E04 /* SecureHTTPAdapter.swift in Sources */,
54CA02942426B2FD003A5E04 /* DNSResolver.swift in Sources */,
54CA025F2426B2FD003A5E04 /* ProxyServer.swift in Sources */,
54CA02842426B2FD003A5E04 /* Rule.swift in Sources */,
54CE8BC524B1ED2100CC1756 /* PushNotification.swift in Sources */,
54CA02B92426B2FD003A5E04 /* DirectProxySocket.swift in Sources */,
54751E522423955100168273 /* FileManager.swift in Sources */,
54751E522423955100168273 /* URL.swift in Sources */,
54CA02A92426B2FD003A5E04 /* RejectAdapter.swift in Sources */,
54CA02732426B2FD003A5E04 /* IPPool.swift in Sources */,
541075D624CE286200D6F1BF /* CachedConnectionAlert.swift in Sources */,
54CA027E2426B2FD003A5E04 /* DomainListRule.swift in Sources */,
54CA02782426B2FD003A5E04 /* BinaryDataScanner.swift in Sources */,
54CA02B12426B2FD003A5E04 /* ServerAdapterFactory.swift in Sources */,
54CA02B42426B2FD003A5E04 /* StreamObfuscater.swift in Sources */,
54CA02AA2426B2FD003A5E04 /* SpeedAdapterFactory.swift in Sources */,
54CA02952426B2FD003A5E04 /* DNSEnums.swift in Sources */,
54CA02802426B2FD003A5E04 /* DNSSessionMatchType.swift in Sources */,
54CA02A22426B2FD003A5E04 /* ObserverFactory.swift in Sources */,
@@ -880,14 +1124,14 @@
54CA02972426B2FD003A5E04 /* IPPacket.swift in Sources */,
54CA026A2426B2FD003A5E04 /* RawSocketFactory.swift in Sources */,
54CA02A02426B2FD003A5E04 /* TunnelEvent.swift in Sources */,
546063E523FEFAFE008F505A /* SQDB.swift in Sources */,
546063E523FEFAFE008F505A /* DBCore.swift in Sources */,
54CA02872426B2FD003A5E04 /* IPRangeListRule.swift in Sources */,
54CA02922426B2FD003A5E04 /* DNSSession.swift in Sources */,
54CA02B72426B2FD003A5E04 /* ShadowsocksAdapter.swift in Sources */,
54CA026D2426B2FD003A5E04 /* Opt.swift in Sources */,
54CA02B32426B2FD003A5E04 /* HTTPAdapterFactory.swift in Sources */,
54CA02702426B2FD003A5E04 /* HTTPStreamScanner.swift in Sources */,
54CA02812426B2FD003A5E04 /* DNSFailRule.swift in Sources */,
541075DA24CE2C7200D6F1BF /* GlassVPNHook.swift in Sources */,
54CA02AC2426B2FD003A5E04 /* AuthenticationServerAdapterFactory.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
@@ -919,6 +1163,14 @@
name = LaunchScreen.storyboard;
sourceTree = "<group>";
};
543078C124B60F3B00278F2D /* Settings.storyboard */ = {
isa = PBXVariantGroup;
children = (
543078C224B60F3B00278F2D /* Base */,
);
name = Settings.storyboard;
sourceTree = "<group>";
};
/* End PBXVariantGroup section */
/* Begin XCBuildConfiguration section */
@@ -1049,7 +1301,7 @@
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_ENTITLEMENTS = main/main.entitlements;
CURRENT_PROJECT_VERSION = 12;
CURRENT_PROJECT_VERSION = 25;
INFOPLIST_FILE = main/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
@@ -1068,7 +1320,7 @@
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_ENTITLEMENTS = main/main.entitlements;
CURRENT_PROJECT_VERSION = 12;
CURRENT_PROJECT_VERSION = 25;
INFOPLIST_FILE = main/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
@@ -1087,7 +1339,7 @@
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = GlassVPN/GlassVPN.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 12;
CURRENT_PROJECT_VERSION = 25;
INFOPLIST_FILE = GlassVPN/Info.plist;
MARKETING_VERSION = 1.0.0;
PRODUCT_BUNDLE_IDENTIFIER = "de.uni-bamberg.psi.AppCheck.VPN";
@@ -1105,7 +1357,7 @@
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = GlassVPN/GlassVPN.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 12;
CURRENT_PROJECT_VERSION = 25;
INFOPLIST_FILE = GlassVPN/Info.plist;
MARKETING_VERSION = 1.0.0;
PRODUCT_BUNDLE_IDENTIFIER = "de.uni-bamberg.psi.AppCheck.VPN";

View File

@@ -1,13 +1,13 @@
import NetworkExtension
fileprivate var db: SQLiteDatabase?
fileprivate var domainFilters: [String : FilterOptions] = [:]
fileprivate var hook : GlassVPNHook!
// MARK: ObserverFactory
class LDObserverFactory: ObserverFactory {
override func getObserverForProxySocket(_ socket: ProxySocket) -> Observer<ProxySocketEvent>? {
// TODO: replace NEKit with custom proxy with minimal footprint
return LDProxySocketObserver()
}
@@ -15,103 +15,115 @@ class LDObserverFactory: ObserverFactory {
override func signal(_ event: ProxySocketEvent) {
switch event {
case .receivedRequest(let session, let socket):
DDLogDebug("DNS: \(session.host)")
let match = domainFilters.first { session.host == $0.key || session.host.hasSuffix("." + $0.key) }
let block = match?.value.contains(.blocked) ?? false
let ignore = match?.value.contains(.ignored) ?? false
if !ignore { try? db?.insertDNSQuery(session.host, blocked: block) }
else { DDLogDebug("ignored") }
if block { DDLogDebug("blocked"); socket.forceDisconnect() }
let kill = hook.processDNSRequest(session.host)
if kill { socket.forceDisconnect() }
default:
break
}
}
}
}
// MARK: NEPacketTunnelProvider
class PacketTunnelProvider: NEPacketTunnelProvider {
let proxyServerPort: UInt16 = 9090
let proxyServerAddress = "127.0.0.1"
var proxyServer: GCDHTTPProxyServer!
private let proxyServerPort: UInt16 = 9090
private let proxyServerAddress = "127.0.0.1"
private var proxyServer: GCDHTTPProxyServer!
func reloadDomainFilter() {
domainFilters = db?.loadFilters() ?? [:]
}
override func startTunnel(options: [String : NSObject]?, completionHandler: @escaping (Error?) -> Void) {
DDLogVerbose("startTunnel")
// MARK: Delegate
override func startTunnel(options: [String : NSObject]?, completionHandler: @escaping (Error?) -> Void) {
DDLogVerbose("startTunnel with with options: \(String(describing: options))")
PrefsShared.registerDefaults()
do {
db = try SQLiteDatabase.open()
db!.initScheme()
try SQLiteDatabase.open().initCommonScheme()
} catch {
completionHandler(error)
completionHandler(error) // if we cant open db, fail immediately
return
}
if proxyServer != nil {
proxyServer.stop()
}
proxyServer = nil
reloadDomainFilter()
// stop previous if any
if proxyServer != nil { proxyServer.stop() }
proxyServer = nil
// Create proxy
let settings = NEPacketTunnelNetworkSettings(tunnelRemoteAddress: proxyServerAddress)
settings.mtu = NSNumber(value: 1500)
let proxySettings = NEProxySettings()
proxySettings.httpEnabled = true;
proxySettings.httpServer = NEProxyServer(address: proxyServerAddress, port: Int(proxyServerPort))
proxySettings.httpsEnabled = true;
proxySettings.httpsServer = NEProxyServer(address: proxyServerAddress, port: Int(proxyServerPort))
proxySettings.excludeSimpleHostnames = false;
proxySettings.exceptionList = []
proxySettings.matchDomains = [""]
settings.dnsSettings = NEDNSSettings(servers: ["127.0.0.1"])
settings.proxySettings = proxySettings;
RawSocketFactory.TunnelProvider = self
ObserverFactory.currentFactory = LDObserverFactory()
willInitProxy()
self.setTunnelNetworkSettings(settings) { error in
self.setTunnelNetworkSettings(createProxy()) { error in
guard error == nil else {
DDLogError("setTunnelNetworkSettings error: \(String(describing: error))")
DDLogError("setTunnelNetworkSettings error: \(error!)")
completionHandler(error)
return
}
DDLogVerbose("setTunnelNetworkSettings success \(self.packetFlow)")
completionHandler(nil)
self.proxyServer = GCDHTTPProxyServer(address: IPAddress(fromString: self.proxyServerAddress), port: Port(port: self.proxyServerPort))
do {
try self.proxyServer.start()
completionHandler(nil)
}
catch let proxyError {
DDLogError("Error starting proxy server \(proxyError)")
completionHandler(proxyError)
}
do {
try self.proxyServer.start()
self.didInitProxy()
completionHandler(nil)
} catch let proxyError {
DDLogError("Error starting proxy server \(proxyError)")
completionHandler(proxyError)
}
}
}
}
override func stopTunnel(with reason: NEProviderStopReason, completionHandler: @escaping () -> Void) {
DDLogVerbose("stopTunnel with reason: \(reason)")
db = nil
shutdown()
completionHandler()
exit(EXIT_SUCCESS)
}
override func handleAppMessage(_ messageData: Data, completionHandler: ((Data?) -> Void)?) {
hook.handleAppMessage(messageData)
}
// MARK: Helper
private func willInitProxy() {
hook = GlassVPNHook()
}
private func createProxy() -> NEPacketTunnelNetworkSettings {
let settings = NEPacketTunnelNetworkSettings(tunnelRemoteAddress: proxyServerAddress)
settings.mtu = NSNumber(value: 1500)
let proxySettings = NEProxySettings()
proxySettings.httpEnabled = true;
proxySettings.httpServer = NEProxyServer(address: proxyServerAddress, port: Int(proxyServerPort))
proxySettings.httpsEnabled = true;
proxySettings.httpsServer = NEProxyServer(address: proxyServerAddress, port: Int(proxyServerPort))
proxySettings.excludeSimpleHostnames = false;
proxySettings.exceptionList = []
proxySettings.matchDomains = [""]
settings.dnsSettings = NEDNSSettings(servers: ["127.0.0.1"])
settings.proxySettings = proxySettings;
RawSocketFactory.TunnelProvider = self
ObserverFactory.currentFactory = LDObserverFactory()
return settings
}
private func didInitProxy() {
if PrefsShared.RestartReminder.Enabled {
PushNotification.scheduleRestartReminderBadge(on: false)
}
}
private func shutdown() {
// proxy
DNSServer.currentServer = nil
RawSocketFactory.TunnelProvider = nil
ObserverFactory.currentFactory = nil
proxyServer.stop()
proxyServer = nil
completionHandler()
exit(EXIT_SUCCESS)
}
override func handleAppMessage(_ messageData: Data, completionHandler: ((Data?) -> Void)?) {
DDLogVerbose("handleAppMessage")
reloadDomainFilter()
}
RawSocketFactory.TunnelProvider = nil
ObserverFactory.currentFactory = nil
proxyServer.stop()
proxyServer = nil
// custom
hook.cleanUp()
hook = nil
if PrefsShared.RestartReminder.Enabled {
PushNotification.scheduleRestartReminderBadge(on: true)
PushNotification.scheduleRestartReminderBanner()
}
}
}

View File

@@ -0,0 +1,35 @@
This library is in the public domain.
However, not all organizations are allowed to use such a license.
For example, Germany doesn't recognize the Public Domain and one is not allowed to use libraries under such license (or similar).
Thus, the library is now dual licensed,
and one is allowed to choose which license they would like to use.
##################################################
License Option #1 :
##################################################
Public Domain
##################################################
License Option #2 :
##################################################
Software License Agreement (BSD License)
Copyright (c) 2017, Deusty, LLC
All rights reserved.
Redistribution and use of this software in source and binary forms,
with or without modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above
copyright notice, this list of conditions and the
following disclaimer.
* Neither the name of Deusty LLC nor the names of its
contributors may be used to endorse or promote products
derived from this software without specific prior
written permission of Deusty LLC.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

View File

@@ -1,76 +0,0 @@
//import Foundation
//
//enum ChangeType {
// case Address, Port
//}
//
//public class IPMutablePacket {
// // Support only IPv4 for now
//
// let version: IPVersion
// let proto: TransportType
// let IPHeaderLength: Int
// var sourceAddress: IPv4Address {
// get {
// return IPv4Address(fromBytesInNetworkOrder: payload.bytes.advancedBy(12))
// }
// set {
// setIPv4Address(sourceAddress, newAddress: newValue, at: 12)
// }
// }
// var destinationAddress: IPv4Address {
// get {
// return IPv4Address(fromBytesInNetworkOrder: payload.bytes.advancedBy(16))
// }
// set {
// setIPv4Address(destinationAddress, newAddress: newValue, at: 16)
// }
// }
//
// let payload: NSMutableData
//
// public init(payload: NSData) {
// let vl = UnsafePointer<UInt8>(payload.bytes).memory
// version = IPVersion(rawValue: vl >> 4)!
// IPHeaderLength = Int(vl & 0x0F) * 4
// let p = UnsafePointer<UInt8>(payload.bytes.advancedBy(9)).memory
// proto = TransportType(rawValue: p)!
// self.payload = NSMutableData(data: payload)
// }
//
// func updateChecksum(oldValue: UInt16, newValue: UInt16, type: ChangeType) {
// if type == .Address {
// updateChecksum(oldValue, newValue: newValue, at: 10)
// }
// }
//
// // swiftlint:disable:next variable_name
// internal func updateChecksum(oldValue: UInt16, newValue: UInt16, at: Int) {
// let oldChecksum = UnsafePointer<UInt16>(payload.bytes.advancedBy(at)).memory
// let oc32 = UInt32(~oldChecksum)
// let ov32 = UInt32(~oldValue)
// let nv32 = UInt32(newValue)
// var newChecksum32 = oc32 &+ ov32 &+ nv32
// newChecksum32 = (newChecksum32 & 0xFFFF) + (newChecksum32 >> 16)
// newChecksum32 = (newChecksum32 & 0xFFFF) &+ (newChecksum32 >> 16)
// var newChecksum = ~UInt16(newChecksum32)
// payload.replaceBytesInRange(NSRange(location: at, length: 2), withBytes: &newChecksum, length: 2)
// }
//
// // swiftlint:disable:next variable_name
// private func foldChecksum(checksum: UInt32) -> UInt32 {
// var checksum = checksum
// while checksum > 0xFFFF {
// checksum = (checksum & 0xFFFF) + (checksum >> 16)
// }
// return checksum
// }
//
// // swiftlint:disable:next variable_name
// private func setIPv4Address(oldAddress: IPv4Address, newAddress: IPv4Address, at: Int) {
// payload.replaceBytesInRange(NSRange(location: at, length: 4), withBytes: newAddress.bytesInNetworkOrder, length: 4)
// updateChecksum(UnsafePointer<UInt16>(oldAddress.bytesInNetworkOrder).memory, newValue: UnsafePointer<UInt16>(newAddress.bytesInNetworkOrder).memory, type: .Address)
// updateChecksum(UnsafePointer<UInt16>(oldAddress.bytesInNetworkOrder).advancedBy(1).memory, newValue: UnsafePointer<UInt16>(newAddress.bytesInNetworkOrder).advancedBy(1).memory, type: .Address)
// }
//
//}

View File

@@ -1,32 +0,0 @@
//import Foundation
//
//class TCPMutablePacket: IPMutablePacket {
// var sourcePort: Port {
// get {
// return Port(bytesInNetworkOrder: payload.bytes.advancedBy(IPHeaderLength))
// }
// set {
// setPort(sourcePort, newPort: newValue, at: 0)
// }
// }
//
// var destinationPort: Port {
// get {
// return Port(bytesInNetworkOrder: payload.bytes.advancedBy(IPHeaderLength + 2))
// }
// set {
// setPort(destinationPort, newPort: newValue, at: 2)
// }
// }
//
// override func updateChecksum(oldValue: UInt16, newValue: UInt16, type: ChangeType) {
// super.updateChecksum(oldValue, newValue: newValue, type: type)
// updateChecksum(oldValue, newValue: newValue, at: IPHeaderLength + 16)
// }
//
// // swiftlint:disable:next variable_name
// private func setPort(oldPort: Port, newPort: Port, at: Int) {
// payload.replaceBytesInRange(NSRange(location: at + IPHeaderLength, length: 2), withBytes: newPort.bytesInNetworkOrder, length: 2)
// updateChecksum(oldPort.valueInNetworkOrder, newValue: newPort.valueInNetworkOrder, type: .Port)
// }
//}

View File

@@ -0,0 +1,27 @@
Copyright (c) 2016, Zhuhao Wang
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of NEKit nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

View File

@@ -141,7 +141,14 @@ public class NWTCPSocket: NSObject, RawTCPSocketProtocol {
connection!.readMinimumLength(1, maximumLength: Opt.MAXNWTCPSocketReadDataSize) { data, error in
guard error == nil else {
DDLogError("NWTCPSocket got an error when reading data: \(String(describing: error))")
let e = error! as NSError
let ignore = (
e.domain == "kNWErrorDomainPOSIX" && e.code == POSIXError.ECANCELED.rawValue // Operation canceled
|| e.domain == NSPOSIXErrorDomain && e.code == POSIXError.ENOTCONN.rawValue // Socket is not connected
)
if !ignore {
DDLogError("NWTCPSocket got an error when reading data: \(String(describing: error))")
}
self.queueCall {
self.disconnect()
}

View File

@@ -1,28 +0,0 @@
//import Foundation
//
///// Factory building Shadowsocks adapter.
//open class ShadowsocksAdapterFactory: ServerAdapterFactory {
// let protocolObfuscaterFactory: ShadowsocksAdapter.ProtocolObfuscater.Factory
// let cryptorFactory: ShadowsocksAdapter.CryptoStreamProcessor.Factory
// let streamObfuscaterFactory: ShadowsocksAdapter.StreamObfuscater.Factory
//
// public init(serverHost: String, serverPort: Int, protocolObfuscaterFactory: ShadowsocksAdapter.ProtocolObfuscater.Factory, cryptorFactory: ShadowsocksAdapter.CryptoStreamProcessor.Factory, streamObfuscaterFactory: ShadowsocksAdapter.StreamObfuscater.Factory) {
// self.protocolObfuscaterFactory = protocolObfuscaterFactory
// self.cryptorFactory = cryptorFactory
// self.streamObfuscaterFactory = streamObfuscaterFactory
// super.init(serverHost: serverHost, serverPort: serverPort)
// }
//
// /**
// Get a Shadowsocks adapter.
//
// - parameter session: The connect session.
//
// - returns: The built adapter.
// */
// override open func getAdapterFor(session: ConnectSession) -> AdapterSocket {
// let adapter = ShadowsocksAdapter(host: serverHost, port: serverPort, protocolObfuscater: protocolObfuscaterFactory.build(), cryptor: cryptorFactory.build(), streamObfuscator: streamObfuscaterFactory.build(for: session))
// adapter.socket = RawSocketFactory.getRawSocket()
// return adapter
// }
//}

View File

@@ -1,26 +0,0 @@
//import Foundation
//
///// Factory building speed adapter.
//open class SpeedAdapterFactory: AdapterFactory {
// open var adapterFactories: [(AdapterFactory, Int)]!
//
// public override init() {}
//
// /**
// Get a speed adapter.
//
// - parameter session: The connect session.
//
// - returns: The built adapter.
// */
// override open func getAdapterFor(session: ConnectSession) -> AdapterSocket {
// let adapters = adapterFactories.map { adapterFactory, delay -> (AdapterSocket, Int) in
// let adapter = adapterFactory.getAdapterFor(session: session)
// adapter.socket = RawSocketFactory.getRawSocket()
// return (adapter, delay)
// }
// let speedAdapter = SpeedAdapter()
// speedAdapter.adapters = adapters
// return speedAdapter
// }
//}

View File

@@ -14,7 +14,7 @@ public class SOCKS5Adapter: AdapterSocket {
var internalStatus: SOCKS5AdapterStatus = .invalid
let helloData = Data(bytes: UnsafePointer<UInt8>(([0x05, 0x01, 0x00] as [UInt8])), count: 3)
let helloData = Data([0x05, 0x01, 0x00])
public enum ReadTag: Int {
case methodResponse = -20000, connectResponseFirstPart, connectResponseSecondPart

View File

@@ -1,133 +0,0 @@
//import Foundation
//
//extension ShadowsocksAdapter {
// public class CryptoStreamProcessor {
// public class Factory {
// let password: String
// let algorithm: CryptoAlgorithm
// let key: Data
//
// public init(password: String, algorithm: CryptoAlgorithm) {
// self.password = password
// self.algorithm = algorithm
// key = CryptoHelper.getKey(password, methodType: algorithm)
// }
//
// public func build() -> CryptoStreamProcessor {
// return CryptoStreamProcessor(key: key, algorithm: algorithm)
// }
// }
//
// public weak var inputStreamProcessor: StreamObfuscater.StreamObfuscaterBase!
// public weak var outputStreamProcessor: ProtocolObfuscater.ProtocolObfuscaterBase!
//
// var readIV: Data!
// let key: Data
// let algorithm: CryptoAlgorithm
//
// var sendKey = false
//
// var buffer = Buffer(capacity: 0)
//
// lazy var writeIV: Data = {
// [unowned self] in
// CryptoHelper.getIV(self.algorithm)
// }()
// lazy var ivLength: Int = {
// [unowned self] in
// CryptoHelper.getIVLength(self.algorithm)
// }()
// lazy var encryptor: StreamCryptoProtocol = {
// [unowned self] in
// self.getCrypto(.encrypt)
// }()
// lazy var decryptor: StreamCryptoProtocol = {
// [unowned self] in
// self.getCrypto(.decrypt)
// }()
//
// init(key: Data, algorithm: CryptoAlgorithm) {
// self.key = key
// self.algorithm = algorithm
// }
//
// func encrypt(data: inout Data) {
// return encryptor.update(&data)
// }
//
// func decrypt(data: inout Data) {
// return decryptor.update(&data)
// }
//
// public func input(data: Data) throws {
// var data = data
//
// if readIV == nil {
// buffer.append(data: data)
// readIV = buffer.get(length: ivLength)
// guard readIV != nil else {
// try inputStreamProcessor!.input(data: Data())
// return
// }
//
// data = buffer.get() ?? Data()
// buffer.release()
// }
//
// decrypt(data: &data)
// try inputStreamProcessor!.input(data: data)
// }
//
// public func output(data: Data) {
// var data = data
// encrypt(data: &data)
// if sendKey {
// return outputStreamProcessor!.output(data: data)
// } else {
// sendKey = true
// var out = Data(capacity: data.count + writeIV.count)
// out.append(writeIV)
// out.append(data)
//
// return outputStreamProcessor!.output(data: out)
// }
// }
//
// private func getCrypto(_ operation: CryptoOperation) -> StreamCryptoProtocol {
// switch algorithm {
// case .AES128CFB, .AES192CFB, .AES256CFB:
// switch operation {
// case .decrypt:
// return CCCrypto(operation: .decrypt, mode: .cfb, algorithm: .aes, initialVector: readIV, key: key)
// case .encrypt:
// return CCCrypto(operation: .encrypt, mode: .cfb, algorithm: .aes, initialVector: writeIV, key: key)
// }
// case .CHACHA20:
// switch operation {
// case .decrypt:
// return SodiumStreamCrypto(key: key, iv: readIV, algorithm: .chacha20)
// case .encrypt:
// return SodiumStreamCrypto(key: key, iv: writeIV, algorithm: .chacha20)
// }
// case .SALSA20:
// switch operation {
// case .decrypt:
// return SodiumStreamCrypto(key: key, iv: readIV, algorithm: .salsa20)
// case .encrypt:
// return SodiumStreamCrypto(key: key, iv: writeIV, algorithm: .salsa20)
// }
// case .RC4MD5:
// var combinedKey = Data(capacity: key.count + ivLength)
// combinedKey.append(key)
// switch operation {
// case .decrypt:
// combinedKey.append(readIV)
// return CCCrypto(operation: .decrypt, mode: .rc4, algorithm: .rc4, initialVector: nil, key: MD5Hash.final(combinedKey))
// case .encrypt:
// combinedKey.append(writeIV)
// return CCCrypto(operation: .encrypt, mode: .rc4, algorithm: .rc4, initialVector: nil, key: MD5Hash.final(combinedKey))
// }
// }
// }
// }
//}

View File

@@ -1,371 +0,0 @@
//import Foundation
//
//extension ShadowsocksAdapter {
// public struct ProtocolObfuscater {
// public class Factory {
// public init() {}
//
// public func build() -> ProtocolObfuscaterBase {
// return ProtocolObfuscaterBase()
// }
// }
//
// public class ProtocolObfuscaterBase {
// public weak var inputStreamProcessor: CryptoStreamProcessor!
// public weak var outputStreamProcessor: ShadowsocksAdapter!
//
// public func start() {}
// public func input(data: Data) throws {}
// public func output(data: Data) {}
//
// public func didWrite() {}
// }
//
// public class OriginProtocolObfuscater: ProtocolObfuscaterBase {
//
// public class Factory: ProtocolObfuscater.Factory {
// public override init() {}
//
// public override func build() -> ShadowsocksAdapter.ProtocolObfuscater.ProtocolObfuscaterBase {
// return OriginProtocolObfuscater()
// }
// }
//
// public override func start() {
// outputStreamProcessor.becomeReadyToForward()
// }
//
// public override func input(data: Data) throws {
// try inputStreamProcessor.input(data: data)
// }
//
// public override func output(data: Data) {
// outputStreamProcessor.output(data: data)
// }
// }
//
// public class HTTPProtocolObfuscater: ProtocolObfuscaterBase {
//
// public class Factory: ProtocolObfuscater.Factory {
// let method: String
// let hosts: [String]
// let customHeader: String?
//
// public init(method: String = "GET", hosts: [String], customHeader: String?) {
// self.method = method
// self.hosts = hosts
// self.customHeader = customHeader
// }
//
// public override func build() -> ShadowsocksAdapter.ProtocolObfuscater.ProtocolObfuscaterBase {
// return HTTPProtocolObfuscater(method: method, hosts: hosts, customHeader: customHeader)
// }
// }
//
// static let headerLength = 30
// static let userAgent = ["Mozilla/5.0 (Windows NT 6.3; WOW64; rv:40.0) Gecko/20100101 Firefox/40.0",
// "Mozilla/5.0 (Windows NT 6.3; WOW64; rv:40.0) Gecko/20100101 Firefox/44.0",
// "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36",
// "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.11 (KHTML, like Gecko) Ubuntu/11.10 Chromium/27.0.1453.93 Chrome/27.0.1453.93 Safari/537.36",
// "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:35.0) Gecko/20100101 Firefox/35.0",
// "Mozilla/5.0 (compatible; WOW64; MSIE 10.0; Windows NT 6.2)",
// "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/533.20.25 (KHTML, like Gecko) Version/5.0.4 Safari/533.20.27",
// "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.3; Trident/7.0; .NET4.0E; .NET4.0C)",
// "Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko",
// "Mozilla/5.0 (Linux; Android 4.4; Nexus 5 Build/BuildID) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/30.0.0.0 Mobile Safari/537.36",
// "Mozilla/5.0 (iPad; CPU OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A334 Safari/7534.48.3",
// "Mozilla/5.0 (iPhone; CPU iPhone OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A334 Safari/7534.48.3"]
//
// let method: String
// let hosts: [String]
// let customHeader: String?
//
// var readingFakeHeader = false
// var sendHeader = false
// var remaining = false
//
// var buffer = Buffer(capacity: 8192)
//
// public init(method: String = "GET", hosts: [String], customHeader: String?) {
// self.method = method
// self.hosts = hosts
// self.customHeader = customHeader
// }
//
// private func generateHeader(encapsulating data: Data) -> String {
// let ind = Int(arc4random_uniform(UInt32(hosts.count)))
// let host = outputStreamProcessor.port == 80 ? hosts[ind] : "\(hosts[ind]):\(outputStreamProcessor.port)"
// var header = "\(method) /\(hexlify(data: data)) HTTP/1.1\r\nHost: \(host)\r\n"
// if let customHeader = customHeader {
// header += customHeader
// } else {
// let ind = Int(arc4random_uniform(UInt32(HTTPProtocolObfuscater.userAgent.count)))
// header += "User-Agent: \(HTTPProtocolObfuscater.userAgent[ind])\r\nAccept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\nAccept-Language: en-US,en;q=0.8\r\nAccept-Encoding: gzip, deflate\r\nDNT: 1\r\nConnection: keep-alive"
// }
// header += "\r\n\r\n"
// return header
// }
//
// private func hexlify(data: Data) -> String {
// var result = ""
// for i in data {
// result = result.appendingFormat("%%%02x", i)
// }
// return result
// }
//
// public override func start() {
// readingFakeHeader = true
// outputStreamProcessor.becomeReadyToForward()
// }
//
// public override func input(data: Data) throws {
// if readingFakeHeader {
// buffer.append(data: data)
// if buffer.get(to: Utils.HTTPData.DoubleCRLF) != nil {
// readingFakeHeader = false
// if let remainData = buffer.get() {
// try inputStreamProcessor.input(data: remainData)
// return
// }
// }
// try inputStreamProcessor.input(data: Data())
// return
// }
//
// try inputStreamProcessor.input(data: data)
// }
//
// public override func output(data: Data) {
// if sendHeader {
// outputStreamProcessor.output(data: data)
// } else {
// var fakeRequestDataLength = inputStreamProcessor.key.count + HTTPProtocolObfuscater.headerLength
// if data.count - fakeRequestDataLength > 64 {
// fakeRequestDataLength += Int(arc4random_uniform(64))
// } else {
// fakeRequestDataLength = data.count
// }
//
// var outputData = generateHeader(encapsulating: data.subdata(in: 0 ..< fakeRequestDataLength)).data(using: .utf8)!
// outputData.append(data.subdata(in: fakeRequestDataLength ..< data.count))
// sendHeader = true
// outputStreamProcessor.output(data: outputData)
// }
// }
// }
//
// public class TLSProtocolObfuscater: ProtocolObfuscaterBase {
//
// public class Factory: ProtocolObfuscater.Factory {
// let hosts: [String]
//
// public init(hosts: [String]) {
// self.hosts = hosts
// }
//
// public override func build() -> ShadowsocksAdapter.ProtocolObfuscater.ProtocolObfuscaterBase {
// return TLSProtocolObfuscater(hosts: hosts)
// }
// }
//
// let hosts: [String]
// let clientID: Data = {
// var id = Data(count: 32)
// Utils.Random.fill(data: &id)
// return id
// }()
//
// private var status = 0
//
// private var buffer = Buffer(capacity: 1024)
//
// init(hosts: [String]) {
// self.hosts = hosts
// }
//
// public override func start() {
// handleStatus0()
// outputStreamProcessor.socket.readDataTo(length: 129)
// }
//
// public override func input(data: Data) throws {
// switch status {
// case 8:
// try handleInput(data: data)
// case 1:
// outputStreamProcessor.becomeReadyToForward()
// default:
// break
// }
// }
//
// public override func output(data: Data) {
// switch status {
// case 8:
// handleStatus8(data: data)
// return
// case 1:
// handleStatus1(data: data)
// return
// default:
// break
// }
// }
//
// private func authData() -> Data {
// var time = UInt32(Date.init().timeIntervalSince1970).bigEndian
// var output = Data(count: 32)
// var key = inputStreamProcessor.key
// key.append(clientID)
//
// withUnsafeBytes(of: &time) {
// output.replaceSubrange(0 ..< 4, with: $0)
// }
//
// Utils.Random.fill(data: &output, from: 4, length: 18)
// output.withUnsafeBytes {
// output.replaceSubrange(22 ..< 32, with: HMAC.final(value: $0.baseAddress!, length: 22, algorithm: .SHA1, key: key).subdata(in: 0..<10))
// }
// return output
// }
//
// private func pack(data: Data) -> Data {
// var output = Data()
// var left = data.count
// while left > 0 {
// let blockSize = UInt16(min(Int(arc4random_uniform(UInt32(UInt16.max))) % 4096 + 100, left))
// var blockSizeBE = blockSize.bigEndian
// output.append(contentsOf: [0x17, 0x03, 0x03])
// withUnsafeBytes(of: &blockSizeBE) {
// output.append($0.baseAddress!.assumingMemoryBound(to: UInt8.self), count: $0.count)
// }
// output.append(data.subdata(in: data.count - left ..< data.count - left + Int(blockSize)))
// left -= Int(blockSize)
// }
// return output
// }
//
// private func handleStatus8(data: Data) {
// outputStreamProcessor.output(data: pack(data: data))
// }
//
// private func handleStatus0() {
// status = 1
//
// var outData = Data()
// outData.append(contentsOf: [0x03, 0x03])
// outData.append(authData())
// outData.append(0x20)
// outData.append(clientID)
// outData.append(contentsOf: [0x00, 0x1c, 0xc0, 0x2b, 0xc0, 0x2f, 0xcc, 0xa9, 0xcc, 0xa8, 0xcc, 0x14, 0xcc, 0x13, 0xc0, 0x0a, 0xc0, 0x14, 0xc0, 0x09, 0xc0, 0x13, 0x00, 0x9c, 0x00, 0x35, 0x00, 0x2f, 0x00, 0x0a])
// outData.append("0100".data(using: .utf8)!)
//
// var extData = Data()
// extData.append(contentsOf: [0xff, 0x01, 0x00, 0x01, 0x00])
// let hostData = hosts[Int(arc4random_uniform(UInt32(hosts.count)))].data(using: .utf8)!
//
// var sniData = Data(capacity: hosts.count + 2 + 1 + 2 + 2 + 2)
//
// sniData.append(contentsOf: [0x00, 0x00])
//
// var _lenBE = UInt16(hostData.count + 5).bigEndian
// withUnsafeBytes(of: &_lenBE) {
// sniData.append($0.baseAddress!.assumingMemoryBound(to: UInt8.self), count: $0.count)
// }
//
// _lenBE = UInt16(hostData.count + 3).bigEndian
// withUnsafeBytes(of: &_lenBE) {
// sniData.append($0.baseAddress!.assumingMemoryBound(to: UInt8.self), count: $0.count)
// }
//
// sniData.append(0x00)
//
// _lenBE = UInt16(hostData.count).bigEndian
// withUnsafeBytes(of: &_lenBE) {
// sniData.append($0.baseAddress!.assumingMemoryBound(to: UInt8.self), count: $0.count)
// }
//
// sniData.append(hostData)
//
// extData.append(sniData)
//
// extData.append(contentsOf: [0x00, 0x17, 0x00, 0x00, 0x00, 0x23, 0x00, 0xd0])
//
// var randomData = Data(count: 208)
// Utils.Random.fill(data: &randomData)
// extData.append(randomData)
//
// extData.append(contentsOf: [0x00, 0x0d, 0x00, 0x16, 0x00, 0x14, 0x06, 0x01, 0x06, 0x03, 0x05, 0x01, 0x05, 0x03, 0x04, 0x01, 0x04, 0x03, 0x03, 0x01, 0x03, 0x03, 0x02, 0x01, 0x02, 0x03])
// extData.append(contentsOf: [0x00, 0x05, 0x00, 0x05, 0x01, 0x00, 0x00, 0x00, 0x00])
// extData.append(contentsOf: [0x00, 0x12, 0x00, 0x00])
// extData.append(contentsOf: [0x75, 0x50, 0x00, 0x00])
// extData.append(contentsOf: [0x00, 0x0b, 0x00, 0x02, 0x01, 0x00])
// extData.append(contentsOf: [0x00, 0x0a, 0x00, 0x06, 0x00, 0x04, 0x00, 0x17, 0x00, 0x18])
//
// _lenBE = UInt16(extData.count).bigEndian
// withUnsafeBytes(of: &_lenBE) {
// outData.append($0.baseAddress!.assumingMemoryBound(to: UInt8.self), count: $0.count)
// }
// outData.append(extData)
//
// var outputData = Data(capacity: outData.count + 9)
// outputData.append(contentsOf: [0x16, 0x03, 0x01])
// _lenBE = UInt16(outData.count + 4).bigEndian
// withUnsafeBytes(of: &_lenBE) {
// outputData.append($0.baseAddress!.assumingMemoryBound(to: UInt8.self), count: $0.count)
// }
// outputData.append(contentsOf: [0x01, 0x00])
// _lenBE = UInt16(outData.count).bigEndian
// withUnsafeBytes(of: &_lenBE) {
// outputData.append($0.baseAddress!.assumingMemoryBound(to: UInt8.self), count: $0.count)
// }
// outputData.append(outData)
// outputStreamProcessor.output(data: outputData)
// }
//
// private func handleStatus1(data: Data) {
// status = 8
//
// var outputData = Data()
// outputData.append(contentsOf: [0x14, 0x03, 0x03, 0x00, 0x01, 0x01, 0x16, 0x03, 0x03, 0x00, 0x20])
// var random = Data(count: 22)
// Utils.Random.fill(data: &random)
// outputData.append(random)
//
// var key = inputStreamProcessor.key
// key.append(clientID)
// outputData.withUnsafeBytes {
// outputData.append(HMAC.final(value: $0.baseAddress!, length: outputData.count, algorithm: .SHA1, key: key).subdata(in: 0..<10))
// }
//
// outputData.append(pack(data: data))
//
// outputStreamProcessor.output(data: outputData)
// }
//
// private func handleInput(data: Data) throws {
// buffer.append(data: data)
// var unpackedData = Data()
// while buffer.left > 5 {
// buffer.skip(3)
// var length: Int = 0
// buffer.withUnsafeBytes { (ptr: UnsafePointer<UInt16>) in
// length = Int(ptr.pointee.byteSwapped)
// }
// buffer.skip(2)
// if buffer.left >= length {
// unpackedData.append(buffer.get(length: length)!)
// continue
// } else {
// buffer.setBack(length: 5)
// break
// }
// }
// buffer.squeeze()
// try inputStreamProcessor.input(data: unpackedData)
// }
// }
//
// }
//}

View File

@@ -1,112 +0,0 @@
//import Foundation
//import CommonCrypto
//
///// This adapter connects to remote through Shadowsocks proxy.
//public class ShadowsocksAdapter: AdapterSocket {
// enum ShadowsocksAdapterStatus {
// case invalid,
// connecting,
// connected,
// forwarding,
// stopped
// }
//
// enum EncryptMethod: String {
// case AES128CFB = "AES-128-CFB", AES192CFB = "AES-192-CFB", AES256CFB = "AES-256-CFB"
//
// static let allValues: [EncryptMethod] = [.AES128CFB, .AES192CFB, .AES256CFB]
// }
//
// public let host: String
// public let port: Int
//
// var internalStatus: ShadowsocksAdapterStatus = .invalid
//
// private let protocolObfuscater: ProtocolObfuscater.ProtocolObfuscaterBase
// private let cryptor: CryptoStreamProcessor
// private let streamObfuscator: StreamObfuscater.StreamObfuscaterBase
//
// public init(host: String, port: Int, protocolObfuscater: ProtocolObfuscater.ProtocolObfuscaterBase, cryptor: CryptoStreamProcessor, streamObfuscator: StreamObfuscater.StreamObfuscaterBase) {
// self.host = host
// self.port = port
// self.protocolObfuscater = protocolObfuscater
// self.cryptor = cryptor
// self.streamObfuscator = streamObfuscator
//
// super.init()
//
// protocolObfuscater.inputStreamProcessor = cryptor
// protocolObfuscater.outputStreamProcessor = self
//
// cryptor.inputStreamProcessor = streamObfuscator
// cryptor.outputStreamProcessor = protocolObfuscater
//
// streamObfuscator.inputStreamProcessor = self
// streamObfuscator.outputStreamProcessor = cryptor
// }
//
// override public func openSocketWith(session: ConnectSession) {
// super.openSocketWith(session: session)
//
// do {
// internalStatus = .connecting
// try socket.connectTo(host: host, port: port, enableTLS: false, tlsSettings: nil)
// } catch let error {
// observer?.signal(.errorOccured(error, on: self))
// disconnect()
// }
// }
//
// override public func didConnectWith(socket: RawTCPSocketProtocol) {
// super.didConnectWith(socket: socket)
//
// internalStatus = .connected
//
// protocolObfuscater.start()
// }
//
// override public func didRead(data: Data, from socket: RawTCPSocketProtocol) {
// super.didRead(data: data, from: socket)
//
// do {
// try protocolObfuscater.input(data: data)
// } catch {
// disconnect()
// }
// }
//
// public override func write(data: Data) {
// streamObfuscator.output(data: data)
// }
//
// public func write(rawData: Data) {
// super.write(data: rawData)
// }
//
// public func input(data: Data) {
// delegate?.didRead(data: data, from: self)
// }
//
// public func output(data: Data) {
// write(rawData: data)
// }
//
// override public func didWrite(data: Data?, by socket: RawTCPSocketProtocol) {
// super.didWrite(data: data, by: socket)
//
// protocolObfuscater.didWrite()
//
// switch internalStatus {
// case .forwarding:
// delegate?.didWrite(data: data, by: self)
// default:
// return
// }
// }
//
// func becomeReadyToForward() {
// internalStatus = .forwarding
// observer?.signal(.readyForForward(self))
// delegate?.didBecomeReadyToForwardWith(socket: self)
// }
//}

View File

@@ -1,167 +0,0 @@
//import Foundation
//
//extension ShadowsocksAdapter {
// public struct StreamObfuscater {
// public class Factory {
// public init() {}
//
// public func build(for session: ConnectSession) -> StreamObfuscaterBase {
// return StreamObfuscaterBase(for: session)
// }
// }
//
// public class StreamObfuscaterBase {
// public weak var inputStreamProcessor: ShadowsocksAdapter!
// private weak var _outputStreamProcessor: CryptoStreamProcessor!
// public var outputStreamProcessor: CryptoStreamProcessor! {
// get {
// return _outputStreamProcessor
// }
// set {
// _outputStreamProcessor = newValue
// key = _outputStreamProcessor?.key
// writeIV = _outputStreamProcessor?.writeIV
// }
// }
//
// public var key: Data?
// public var writeIV: Data?
//
// let session: ConnectSession
//
// init(for session: ConnectSession) {
// self.session = session
// }
//
// func output(data: Data) {}
// func input(data: Data) throws {}
// }
//
// public class OriginStreamObfuscater: StreamObfuscaterBase {
// public class Factory: StreamObfuscater.Factory {
// public override init() {}
//
// public override func build(for session: ConnectSession) -> ShadowsocksAdapter.StreamObfuscater.StreamObfuscaterBase {
// return OriginStreamObfuscater(for: session)
// }
// }
//
// private var requestSend = false
//
// private func requestData(withData data: Data) -> Data {
// let hostLength = session.host.utf8.count
// let length = 1 + 1 + hostLength + 2 + data.count
// var response = Data(count: length)
// response[0] = 3
// response[1] = UInt8(hostLength)
// response.replaceSubrange(2..<2+hostLength, with: session.host.utf8)
// var beport = UInt16(session.port).bigEndian
// withUnsafeBytes(of: &beport) {
// response.replaceSubrange(2+hostLength..<4+hostLength, with: $0)
// }
// response.replaceSubrange(4+hostLength..<length, with: data)
// return response
// }
//
// public override func input(data: Data) throws {
// inputStreamProcessor!.input(data: data)
// }
//
// public override func output(data: Data) {
// if requestSend {
// return outputStreamProcessor!.output(data: data)
// } else {
// requestSend = true
// return outputStreamProcessor!.output(data: requestData(withData: data))
// }
// }
// }
//
// public class OTAStreamObfuscater: StreamObfuscaterBase {
// public class Factory: StreamObfuscater.Factory {
// public override init() {}
//
// public override func build(for session: ConnectSession) -> ShadowsocksAdapter.StreamObfuscater.StreamObfuscaterBase {
// return OTAStreamObfuscater(for: session)
// }
// }
//
// private var count: UInt32 = 0
//
// private let DATA_BLOCK_SIZE = 0xFFFF - 12
//
// private var requestSend = false
//
// private func requestData() -> Data {
// var response: [UInt8] = [0x13]
// response.append(UInt8(session.host.utf8.count))
// response += [UInt8](session.host.utf8)
// response += [UInt8](Utils.toByteArray(UInt16(session.port)).reversed())
// var responseData = Data(bytes: UnsafePointer<UInt8>(response), count: response.count)
// var keyiv = Data(count: key!.count + writeIV!.count)
//
// keyiv.replaceSubrange(0..<writeIV!.count, with: writeIV!)
// keyiv.replaceSubrange(writeIV!.count..<writeIV!.count + key!.count, with: key!)
// responseData.append(HMAC.final(value: responseData, algorithm: .SHA1, key: keyiv).subdata(in: 0..<10))
// return responseData
// }
//
// public override func input(data: Data) throws {
// inputStreamProcessor!.input(data: data)
// }
//
// public override func output(data: Data) {
// let fullBlockCount = data.count / DATA_BLOCK_SIZE
// var outputSize = fullBlockCount * (DATA_BLOCK_SIZE + 10 + 2)
// if data.count > fullBlockCount * DATA_BLOCK_SIZE {
// outputSize += data.count - fullBlockCount * DATA_BLOCK_SIZE + 10 + 2
// }
//
// let _requestData: Data = requestData()
// if !requestSend {
// outputSize += _requestData.count
// }
//
// var outputData = Data(count: outputSize)
// var outputOffset = 0
// var dataOffset = 0
//
// if !requestSend {
// requestSend = true
// outputData.replaceSubrange(0..<_requestData.count, with: _requestData)
// outputOffset += _requestData.count
// }
//
// while outputOffset != outputSize {
// let blockLength = min(data.count - dataOffset, DATA_BLOCK_SIZE)
// var len = UInt16(blockLength).bigEndian
// withUnsafeBytes(of: &len) {
// outputData.replaceSubrange(outputOffset..<outputOffset+2, with: $0)
// }
//
// var kc = Data(count: writeIV!.count + MemoryLayout.size(ofValue: count))
// kc.replaceSubrange(0..<writeIV!.count, with: writeIV!)
// var c = count.bigEndian
// let ms = MemoryLayout.size(ofValue: c)
// withUnsafeBytes(of: &c) {
// kc.replaceSubrange(writeIV!.count..<writeIV!.count+ms, with: $0)
// }
//
// data.withUnsafeBytes {
// outputData.replaceSubrange(outputOffset+2..<outputOffset+12, with: HMAC.final(value: $0.baseAddress!.advanced(by: dataOffset), length: blockLength, algorithm: .SHA1, key: kc).subdata(in: 0..<10))
// }
//
// data.withUnsafeBytes {
// outputData.replaceSubrange(outputOffset+12..<outputOffset+12+blockLength, with: $0.baseAddress!.advanced(by: dataOffset), count: blockLength)
// }
//
// count += 1
// outputOffset += 12 + blockLength
// dataOffset += blockLength
// }
//
// return outputStreamProcessor!.output(data: outputData)
// }
// }
// }
//}

View File

@@ -0,0 +1,9 @@
The MIT License
Copyright 2018 Zhuhao Wang
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

55
README.md Normal file
View File

@@ -0,0 +1,55 @@
AppCheck Privacy Monitor
==========================
A pocket DNS monitor and network filter.
![screenshot](doc/screenshot.png)
## What is it?
AppCheck helps you identify which applications communicate with third parties.
It does so by logging network requests.
AppCheck learns only the destination addresses, not the actual data that is exchanged.
Your data belongs to you.
Therefore, monitoring and analysis take place on your device only.
The app does not share any data with us or any other third-party unless you choose to.
Join [Testflight beta](https://testflight.apple.com/join/9jjaFeHO)
### How does it work?
AppCheck creates a local VPN tunnel to intercept all network connections.
For each connection AppCheck looks into the DNS headers only, namely the domain names.
These domain names are logged in the background while the VPN is active.
That means, AppCheck does not have to be active in the foreground all the time.
## Features
- See outgoing (DNS) network requests in real-time
- See history of previous connections
- Block unwanted traffic based on domain names
- Record app specific activity<sup>1</sup>
- Apply logging filters (block or ignore) and display filters (specific range or last x minutes)
- Sort results by time, name, or occurrence count
- Context Analysis
- What other domains occur often at the same time?
- What happened immediately before or after the action?
- Export results for custom analysis
**… and soon:**
- Alert Monitor & reminder
- Participate in privacy research
<sup>1</sup> Due to technical limitations, recordings can not be restricted to a single application. Remember to force-quit all other applications before starting a recording.
## Research Project
*information will be added soon™*

BIN
doc/screenshot.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 158 KiB

View File

@@ -1,134 +1,35 @@
import UIKit
import NetworkExtension
let VPNConfigBundleIdentifier = "de.uni-bamberg.psi.AppCheck.VPN"
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
var managerVPN: NETunnelProviderManager?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
if UserDefaults.standard.bool(forKey: "kill_db") {
UserDefaults.standard.set(false, forKey: "kill_db")
SQLiteDatabase.destroyDatabase()
}
try? SQLiteDatabase.open().initScheme()
DBWrp.initContentOfDB()
loadVPN { mgr in
self.managerVPN = mgr
self.postVPNState()
if let db = AppDB {
db.initCommonScheme()
db.initAppOnlyScheme()
}
NSNotification.Name.NEVPNStatusDidChange.observe(call: #selector(vpnStatusChanged(_:)), on: self)
NotifyFilterChanged.observe(call: #selector(filterDidChange), on: self)
Prefs.registerDefaults()
PrefsShared.registerDefaults()
#if IOS_SIMULATOR
SimulatorVPN.load()
#endif
sync.start()
return true
}
@objc private func vpnStatusChanged(_ notification: Notification) {
postRawVPNState((notification.object as? NETunnelProviderSession)?.status ?? .invalid)
}
@objc private func filterDidChange() {
// Notify VPN extension about changes
if let session = self.managerVPN?.connection as? NETunnelProviderSession,
session.status == .connected {
try? session.sendProviderMessage("filter-update".data(using: .ascii)!, responseHandler: nil)
}
}
func setProxyEnabled(_ newState: Bool) {
guard let mgr = self.managerVPN else {
self.createNewVPN { manager in
self.managerVPN = manager
self.setProxyEnabled(newState)
}
return
}
let state = mgr.isEnabled && (mgr.connection.status == .connected)
if state != newState {
self.updateVPN({ mgr.isEnabled = true }) {
newState ? try? mgr.connection.startVPNTunnel() : mgr.connection.stopVPNTunnel()
}
}
}
// MARK: VPN
private func createNewVPN(_ success: @escaping (_ manager: NETunnelProviderManager) -> Void) {
let mgr = NETunnelProviderManager()
mgr.localizedDescription = "AppCheck Monitor"
let proto = NETunnelProviderProtocol()
proto.providerBundleIdentifier = VPNConfigBundleIdentifier
proto.serverAddress = "127.0.0.1"
mgr.protocolConfiguration = proto
mgr.isEnabled = true
mgr.saveToPreferences { error in
guard error == nil else {
self.postProcessedVPNState(.off)
//ErrorAlert(error!).presentIn(self.window?.rootViewController)
return
}
success(mgr)
}
}
private func loadVPN(_ finally: @escaping (_ manager: NETunnelProviderManager?) -> Void) {
NETunnelProviderManager.loadAllFromPreferences { managers, error in
guard let mgrs = managers, mgrs.count > 0 else {
finally(nil)
return
}
for mgr in mgrs {
if let proto = (mgr.protocolConfiguration as? NETunnelProviderProtocol) {
if proto.providerBundleIdentifier == VPNConfigBundleIdentifier {
finally(mgr)
return
}
}
}
finally(nil)
}
}
private func updateVPN(_ body: @escaping () -> Void, _ onSuccess: @escaping () -> Void) {
self.managerVPN?.loadFromPreferences { error in
guard error == nil else { return }
body()
self.managerVPN?.saveToPreferences { error in
guard error == nil else { return }
onSuccess()
}
}
}
private func postVPNState() {
guard let mgr = self.managerVPN else {
self.postRawVPNState(.invalid)
return
}
mgr.loadFromPreferences { _ in
self.postRawVPNState(mgr.connection.status)
}
}
// MARK: Notifications
private func postRawVPNState(_ origState: NEVPNStatus) {
let state: VPNState
switch origState {
case .connected: state = .on
case .connecting, .disconnecting, .reasserting: state = .inbetween
case .invalid, .disconnected: fallthrough
@unknown default: state = .off
}
postProcessedVPNState(state)
}
private func postProcessedVPNState(_ state: VPNState) {
currentVPNState = state
NotifyVPNStateChanged.post(state)
func applicationDidBecomeActive(_ application: UIApplication) {
TheGreatDestroyer.deleteLogs(olderThan: PrefsShared.AutoDeleteLogsDays)
// FIXME: Does not reflect changes performed by GlassVPN auto-delete while app is open.
// It will update whenever app restarts or becomes active again (only if deleteLogs has something to delete!)
// This is a known issue and tolerated.
}
}

BIN
main/Assets.xcassets/.DS_Store vendored Normal file

Binary file not shown.

View File

@@ -0,0 +1,26 @@
{
"images" : [
{
"filename" : "img.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "img@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "img@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"template-rendering-intent" : "template"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 187 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 289 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 395 B

View File

@@ -0,0 +1,26 @@
{
"images" : [
{
"filename" : "img.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "img@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "img@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"template-rendering-intent" : "template"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 155 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 226 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 302 B

View File

@@ -0,0 +1,26 @@
{
"images" : [
{
"filename" : "img.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "img@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "img@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"template-rendering-intent" : "template"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 385 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 695 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

View File

@@ -0,0 +1,26 @@
{
"images" : [
{
"filename" : "img.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "img@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "img@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"template-rendering-intent" : "template"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 230 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 409 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 544 B

View File

@@ -0,0 +1,26 @@
{
"images" : [
{
"filename" : "img.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "img@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "img@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"template-rendering-intent" : "template"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 150 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 216 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 283 B

View File

@@ -0,0 +1,26 @@
{
"images" : [
{
"filename" : "img.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "img@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "img@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"template-rendering-intent" : "template"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 156 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 224 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 282 B

View File

@@ -27,7 +27,7 @@
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="52.173913043478265" y="375"/>
<point key="canvasLocation" x="120" y="100"/>
</scene>
</scenes>
<resources>

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,837 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="16097" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="qdB-ZO-LHY">
<device id="retina4_0" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="16087"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--Settings-->
<scene sceneID="gEe-ny-NaU">
<objects>
<tableViewController id="qdB-ZO-LHY" customClass="TVCSettings" customModule="AppCheck" customModuleProvider="target" sceneMemberID="viewController">
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="static" style="grouped" separatorStyle="default" rowHeight="44" estimatedRowHeight="-1" sectionHeaderHeight="18" sectionFooterHeight="18" id="8kq-PY-wp7">
<rect key="frame" x="0.0" y="0.0" width="320" height="568"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
<sections>
<tableViewSection headerTitle="VPN Proxy Settings" id="w58-6X-Jea">
<cells>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="none" indentationWidth="10" textLabel="3y8-eK-09n" style="IBUITableViewCellStyleDefault" id="ghM-ze-fvp">
<rect key="frame" x="0.0" y="55.5" width="320" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="ghM-ze-fvp" id="d2v-vz-QIB">
<rect key="frame" x="0.0" y="0.0" width="320" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="VPN Proxy Enabled" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="3y8-eK-09n">
<rect key="frame" x="16" y="0.0" width="288" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleBody"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" contentHorizontalAlignment="center" contentVerticalAlignment="center" on="YES" translatesAutoresizingMaskIntoConstraints="NO" id="ZAz-WT-FDb">
<rect key="frame" x="257" y="6" width="49" height="31"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxY="YES"/>
<connections>
<action selector="toggleVPNProxy:" destination="qdB-ZO-LHY" eventType="valueChanged" id="DNS-71-2ga"/>
</connections>
</switch>
</subviews>
</tableViewCellContentView>
<connections>
<outlet property="accessoryView" destination="ZAz-WT-FDb" id="SX3-lk-I3M"/>
</connections>
</tableViewCell>
</cells>
</tableViewSection>
<tableViewSection headerTitle="Logging Filter" id="EcH-KA-eLE">
<cells>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" accessoryType="detailDisclosureButton" indentationWidth="10" reuseIdentifier="settingsIgnoredCell" textLabel="UdM-Zm-G9p" detailTextLabel="bHb-Tw-nPR" style="IBUITableViewCellStyleValue2" id="fZR-we-Y0k">
<rect key="frame" x="0.0" y="155.5" width="320" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="fZR-we-Y0k" id="eqc-fj-p0d">
<rect key="frame" x="0.0" y="0.0" width="261" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="Ignore" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="UdM-Zm-G9p">
<rect key="frame" x="16" y="13" width="91" height="18"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleSubhead"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="0 Domains" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="bHb-Tw-nPR">
<rect key="frame" x="113" y="13" width="73" height="18"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleSubhead"/>
<color key="textColor" systemColor="secondaryLabelColor" red="0.23529411759999999" green="0.23529411759999999" blue="0.26274509800000001" alpha="0.59999999999999998" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</tableViewCellContentView>
<connections>
<segue destination="q3B-Yi-1bx" kind="push" identifier="segueFilterIgnored" id="EzT-Xq-wka"/>
</connections>
</tableViewCell>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" accessoryType="detailDisclosureButton" indentationWidth="10" reuseIdentifier="settingsBlockedCell" textLabel="fI0-Nt-Ucf" detailTextLabel="CGG-47-cdc" style="IBUITableViewCellStyleValue2" id="3pw-7c-M6R">
<rect key="frame" x="0.0" y="199.5" width="320" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="3pw-7c-M6R" id="Smv-n1-917">
<rect key="frame" x="0.0" y="0.0" width="261" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="Block" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="fI0-Nt-Ucf">
<rect key="frame" x="16" y="13" width="91" height="18"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleSubhead"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="0 Domains" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="CGG-47-cdc">
<rect key="frame" x="113" y="13" width="73" height="18"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleSubhead"/>
<color key="textColor" systemColor="secondaryLabelColor" red="0.23529411759999999" green="0.23529411759999999" blue="0.26274509800000001" alpha="0.59999999999999998" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</tableViewCellContentView>
<connections>
<segue destination="q3B-Yi-1bx" kind="push" identifier="segueFilterBlocked" id="cOY-j0-75m"/>
</connections>
</tableViewCell>
</cells>
</tableViewSection>
<tableViewSection headerTitle="Notification Settings" id="gNL-sO-BEp">
<cells>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" selectionStyle="blue" accessoryType="disclosureIndicator" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" textLabel="pN1-lL-bGz" detailTextLabel="ldE-NT-c2c" style="IBUITableViewCellStyleValue1" id="jZA-aP-aHG">
<rect key="frame" x="0.0" y="299.5" width="320" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="jZA-aP-aHG" id="OYo-TE-SLp">
<rect key="frame" x="0.0" y="0.0" width="293" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="Reminders" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="pN1-lL-bGz">
<rect key="frame" x="16" y="12" width="81.5" height="20.5"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleBody"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="Disabled" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="ldE-NT-c2c">
<rect key="frame" x="218" y="12" width="67" height="20.5"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleBody"/>
<color key="textColor" systemColor="secondaryLabelColor" red="0.23529411759999999" green="0.23529411759999999" blue="0.26274509800000001" alpha="0.59999999999999998" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</tableViewCellContentView>
<connections>
<segue destination="JYM-cs-i4H" kind="push" identifier="" id="uOT-Eo-Fm8"/>
</connections>
</tableViewCell>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" selectionStyle="blue" accessoryType="disclosureIndicator" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" textLabel="o7c-vQ-haI" detailTextLabel="VeV-go-DXR" style="IBUITableViewCellStyleValue1" id="OTC-Kt-LFT">
<rect key="frame" x="0.0" y="343.5" width="320" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="OTC-Kt-LFT" id="RLb-Oi-WBg">
<rect key="frame" x="0.0" y="0.0" width="293" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="Connection Alerts" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="o7c-vQ-haI">
<rect key="frame" x="16" y="12" width="137.5" height="20.5"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleBody"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="Disabled" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="VeV-go-DXR">
<rect key="frame" x="218" y="12" width="67" height="20.5"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleBody"/>
<color key="textColor" systemColor="secondaryLabelColor" red="0.23529411759999999" green="0.23529411759999999" blue="0.26274509800000001" alpha="0.59999999999999998" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</tableViewCellContentView>
<connections>
<segue destination="D2a-Po-vDU" kind="push" id="6NC-bN-nVR"/>
</connections>
</tableViewCell>
</cells>
</tableViewSection>
<tableViewSection headerTitle="Privacy Settings" id="wLR-T2-Qxm">
<cells>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="none" accessoryType="disclosureIndicator" indentationWidth="10" textLabel="8gD-At-D8n" detailTextLabel="Yy4-Ip-Wdv" style="IBUITableViewCellStyleValue1" id="Qyy-0U-yhd">
<rect key="frame" x="0.0" y="443.5" width="320" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="Qyy-0U-yhd" id="Mfs-fu-W5k">
<rect key="frame" x="0.0" y="0.0" width="293" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="Auto-Delete Logs" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="8gD-At-D8n">
<rect key="frame" x="16" y="12" width="134" height="20.5"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleBody"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="Never" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="Yy4-Ip-Wdv">
<rect key="frame" x="239.5" y="12" width="45.5" height="20.5"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleBody"/>
<color key="textColor" systemColor="secondaryLabelColor" red="0.23529411759999999" green="0.23529411759999999" blue="0.26274509800000001" alpha="0.59999999999999998" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</tableViewCellContentView>
</tableViewCell>
</cells>
</tableViewSection>
<tableViewSection headerTitle="Reset Settings" id="tBs-BI-JqN">
<cells>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="none" indentationWidth="10" id="Uii-Jp-53c">
<rect key="frame" x="0.0" y="543.5" width="320" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="Uii-Jp-53c" id="4Fp-Ox-yrk">
<rect key="frame" x="0.0" y="0.0" width="320" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="6B5-l4-Hgz">
<rect key="frame" x="74.5" y="7" width="171" height="30"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleSubhead"/>
<state key="normal" title="Reset Introduction Alerts"/>
<connections>
<action selector="resetTutorialAlerts:" destination="qdB-ZO-LHY" eventType="touchUpInside" id="hw8-as-4PZ"/>
</connections>
</button>
</subviews>
<constraints>
<constraint firstItem="6B5-l4-Hgz" firstAttribute="centerY" secondItem="4Fp-Ox-yrk" secondAttribute="centerY" id="h2Y-P2-Feo"/>
<constraint firstItem="6B5-l4-Hgz" firstAttribute="centerX" secondItem="4Fp-Ox-yrk" secondAttribute="centerX" id="jpA-gA-3jY"/>
</constraints>
</tableViewCellContentView>
</tableViewCell>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="none" indentationWidth="10" id="Xgc-6Z-IlH">
<rect key="frame" x="0.0" y="587.5" width="320" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="Xgc-6Z-IlH" id="efR-vn-6MX">
<rect key="frame" x="0.0" y="0.0" width="320" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="sE3-Vh-0lM">
<rect key="frame" x="111.5" y="7" width="97" height="30"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleSubhead"/>
<state key="normal" title="Delete all logs">
<color key="titleColor" systemColor="systemRedColor" red="1" green="0.23137254900000001" blue="0.18823529410000001" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</state>
<connections>
<action selector="clearDatabaseResults" destination="qdB-ZO-LHY" eventType="touchUpInside" id="heU-m1-oJq"/>
</connections>
</button>
</subviews>
<constraints>
<constraint firstItem="sE3-Vh-0lM" firstAttribute="centerX" secondItem="efR-vn-6MX" secondAttribute="centerX" id="TvC-jA-Wp5"/>
<constraint firstItem="sE3-Vh-0lM" firstAttribute="centerY" secondItem="efR-vn-6MX" secondAttribute="centerY" id="WoM-cy-cAY"/>
</constraints>
</tableViewCellContentView>
</tableViewCell>
</cells>
</tableViewSection>
<tableViewSection headerTitle="Advanced Settings" id="Vlg-nm-VB3">
<cells>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="none" indentationWidth="10" id="VnR-9B-1zl">
<rect key="frame" x="0.0" y="687.5" width="320" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="VnR-9B-1zl" id="ZTz-vZ-l5p">
<rect key="frame" x="0.0" y="0.0" width="320" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="twS-Ne-dU0">
<rect key="frame" x="125" y="7" width="70" height="30"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleSubhead"/>
<state key="normal" title="Export DB"/>
<connections>
<action selector="exportDB" destination="qdB-ZO-LHY" eventType="touchUpInside" id="FYN-Zz-UK4"/>
</connections>
</button>
</subviews>
<constraints>
<constraint firstItem="twS-Ne-dU0" firstAttribute="centerY" secondItem="ZTz-vZ-l5p" secondAttribute="centerY" id="LgK-8q-r6K"/>
<constraint firstItem="twS-Ne-dU0" firstAttribute="centerX" secondItem="ZTz-vZ-l5p" secondAttribute="centerX" id="ltC-Ba-Bxr"/>
</constraints>
</tableViewCellContentView>
</tableViewCell>
</cells>
</tableViewSection>
</sections>
<connections>
<outlet property="dataSource" destination="qdB-ZO-LHY" id="RH3-xR-dpC"/>
<outlet property="delegate" destination="qdB-ZO-LHY" id="eYf-Xd-2Jq"/>
</connections>
</tableView>
<navigationItem key="navigationItem" title="Settings" id="9Ce-p2-kGX"/>
<simulatedNavigationBarMetrics key="simulatedTopBarMetrics" prompted="NO"/>
<simulatedTabBarMetrics key="simulatedBottomBarMetrics"/>
<connections>
<outlet property="cellDomainsBlocked" destination="3pw-7c-M6R" id="AHT-FE-z0s"/>
<outlet property="cellDomainsIgnored" destination="fZR-we-Y0k" id="Huy-N3-gz7"/>
<outlet property="cellNotificationConnectionAlert" destination="OTC-Kt-LFT" id="XiG-CC-4lC"/>
<outlet property="cellNotificationReminder" destination="jZA-aP-aHG" id="sjo-2s-rqW"/>
<outlet property="cellPrivacyAutoDelete" destination="Qyy-0U-yhd" id="PzN-iv-kFl"/>
<outlet property="vpnToggle" destination="ZAz-WT-FDb" id="lGX-J8-WrU"/>
</connections>
</tableViewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="VNK-Z0-T0a" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="-200" y="0.0"/>
</scene>
<!--Domains-->
<scene sceneID="218-uP-X7b">
<objects>
<tableViewController id="q3B-Yi-1bx" customClass="TVCFilter" customModule="AppCheck" customModuleProvider="target" sceneMemberID="viewController">
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" allowsSelection="NO" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="28" sectionFooterHeight="28" id="GSg-ZZ-F8J">
<rect key="frame" x="0.0" y="0.0" width="320" height="568"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
<prototypes>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" reuseIdentifier="DomainFilterCell" textLabel="MrS-rb-RLB" style="IBUITableViewCellStyleDefault" id="EO2-ww-xuz">
<rect key="frame" x="0.0" y="28" width="320" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="EO2-ww-xuz" id="AtR-ce-uYs">
<rect key="frame" x="0.0" y="0.0" width="320" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="Title" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumScaleFactor="0.80000000000000004" id="MrS-rb-RLB">
<rect key="frame" x="16" y="0.0" width="288" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleBody"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</tableViewCellContentView>
</tableViewCell>
</prototypes>
<connections>
<outlet property="dataSource" destination="q3B-Yi-1bx" id="eWw-VO-n1c"/>
<outlet property="delegate" destination="q3B-Yi-1bx" id="02X-f0-d1a"/>
</connections>
</tableView>
<navigationItem key="navigationItem" title="Domains" id="FWA-IG-VIb">
<barButtonItem key="rightBarButtonItem" systemItem="add" id="RFW-bp-wwH">
<connections>
<action selector="addNewFilter" destination="q3B-Yi-1bx" id="JID-eH-y0p"/>
</connections>
</barButtonItem>
</navigationItem>
</tableViewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="Xzo-dO-WpK" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="1500" y="0.0"/>
</scene>
<!--Reminders-->
<scene sceneID="fWF-ss-cNz">
<objects>
<tableViewController id="JYM-cs-i4H" customClass="TVCReminderAlerts" customModule="AppCheck" customModuleProvider="target" sceneMemberID="viewController">
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="static" style="grouped" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="18" sectionFooterHeight="18" id="Dop-3B-Uvh">
<rect key="frame" x="0.0" y="0.0" width="320" height="568"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
<sections>
<tableViewSection headerTitle="Restart Reminder" id="UOi-fT-8Vh">
<string key="footerTitle">If VPN stops accidentally, show a notification 5 minutes later. It will remind you to re-enable the VPN after system reboot.
if Notification is enabled, show a notification banner once, stating the VPN has stopped.
If App Badge is enabled, display the letter "1" on the homescreen app icon, as long as the VPN is not running.</string>
<cells>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="none" indentationWidth="10" textLabel="dl8-4J-a0L" style="IBUITableViewCellStyleDefault" id="Z2r-Kz-TCt">
<rect key="frame" x="0.0" y="55.5" width="320" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="Z2r-Kz-TCt" id="rEy-qO-PEN">
<rect key="frame" x="0.0" y="0.0" width="320" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="Warn If VPN Stops" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="dl8-4J-a0L">
<rect key="frame" x="16" y="0.0" width="288" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleBody"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" contentHorizontalAlignment="center" contentVerticalAlignment="center" on="YES" id="zaV-mh-eqb">
<rect key="frame" x="252" y="6" width="54" height="31"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxY="YES"/>
<connections>
<action selector="toggleAllowRestartReminder:" destination="JYM-cs-i4H" eventType="valueChanged" id="F4e-k2-bni"/>
</connections>
</switch>
</subviews>
</tableViewCellContentView>
<connections>
<outlet property="accessoryView" destination="zaV-mh-eqb" id="irZ-hk-KoR"/>
</connections>
</tableViewCell>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="none" indentationWidth="10" textLabel="XC6-mj-vkg" style="IBUITableViewCellStyleDefault" id="5sU-vh-JDf">
<rect key="frame" x="0.0" y="99" width="320" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="5sU-vh-JDf" id="MDI-fb-989">
<rect key="frame" x="0.0" y="0.0" width="320" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="… with Notification" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="XC6-mj-vkg">
<rect key="frame" x="16" y="0.0" width="288" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleBody"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" contentHorizontalAlignment="center" contentVerticalAlignment="center" on="YES" id="HaE-En-NH3">
<rect key="frame" x="252" y="6" width="54" height="31"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxY="YES"/>
<connections>
<action selector="toggleAllowRestartNotify:" destination="JYM-cs-i4H" eventType="valueChanged" id="12C-h5-mrR"/>
</connections>
</switch>
</subviews>
</tableViewCellContentView>
<connections>
<outlet property="accessoryView" destination="HaE-En-NH3" id="dld-32-3vc"/>
</connections>
</tableViewCell>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="none" indentationWidth="10" textLabel="wHg-Wo-szR" style="IBUITableViewCellStyleDefault" id="01e-KG-qDH">
<rect key="frame" x="0.0" y="142.5" width="320" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="01e-KG-qDH" id="XWV-FF-VxR">
<rect key="frame" x="0.0" y="0.0" width="320" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="… with App Badge" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="wHg-Wo-szR">
<rect key="frame" x="16" y="0.0" width="288" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleBody"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" contentHorizontalAlignment="center" contentVerticalAlignment="center" on="YES" id="N2Q-cU-pkd">
<rect key="frame" x="252" y="6" width="54" height="31"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxY="YES"/>
<connections>
<action selector="toggleAllowRestartBadge:" destination="JYM-cs-i4H" eventType="valueChanged" id="76l-6y-fOu"/>
</connections>
</switch>
</subviews>
</tableViewCellContentView>
<connections>
<outlet property="accessoryView" destination="N2Q-cU-pkd" id="6LN-Zw-4Nf"/>
</connections>
</tableViewCell>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" accessoryType="disclosureIndicator" indentationWidth="10" textLabel="UBT-zI-VNd" detailTextLabel="tj7-1l-bts" style="IBUITableViewCellStyleValue1" id="pAS-8r-oS5">
<rect key="frame" x="0.0" y="186" width="320" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="pAS-8r-oS5" id="iMr-Gb-dhX">
<rect key="frame" x="0.0" y="0.0" width="293" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="Sound" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="UBT-zI-VNd">
<rect key="frame" x="16" y="12" width="49.5" height="20.5"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleBody"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="Detail" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="tj7-1l-bts">
<rect key="frame" x="241" y="12" width="44" height="20.5"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleBody"/>
<color key="textColor" systemColor="secondaryLabelColor" red="0.23529411759999999" green="0.23529411759999999" blue="0.26274509800000001" alpha="0.59999999999999998" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</tableViewCellContentView>
<connections>
<segue destination="I37-dZ-c9Q" kind="push" identifier="segueSoundRestartReminder" id="nBh-15-nBq"/>
</connections>
</tableViewCell>
</cells>
</tableViewSection>
<tableViewSection headerTitle="Recording Reminder" footerTitle="Very sporadic reminder. Triggered if your last recording is older than two weeks." id="9Wn-bc-wKX">
<cells>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="none" indentationWidth="10" textLabel="u55-7Z-Q0Q" style="IBUITableViewCellStyleDefault" id="87B-MT-J9s">
<rect key="frame" x="0.0" y="449" width="320" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="87B-MT-J9s" id="79D-rZ-spg">
<rect key="frame" x="0.0" y="0.0" width="320" height="43.5"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="Recording Reminder" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="u55-7Z-Q0Q">
<rect key="frame" x="16" y="0.0" width="288" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleBody"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" contentHorizontalAlignment="center" contentVerticalAlignment="center" on="YES" translatesAutoresizingMaskIntoConstraints="NO" id="mTm-Rm-1RQ">
<rect key="frame" x="255" y="6" width="49" height="31"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxY="YES"/>
<connections>
<action selector="toggleAllowRecordingReminder:" destination="JYM-cs-i4H" eventType="valueChanged" id="unC-Ur-jPM"/>
</connections>
</switch>
</subviews>
</tableViewCellContentView>
<connections>
<outlet property="accessoryView" destination="mTm-Rm-1RQ" id="MRe-3h-xfa"/>
</connections>
</tableViewCell>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" accessoryType="disclosureIndicator" indentationWidth="10" textLabel="VYC-xF-awf" detailTextLabel="Ywb-pT-l1W" style="IBUITableViewCellStyleValue1" id="UkL-k7-bB7">
<rect key="frame" x="0.0" y="492.5" width="320" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="UkL-k7-bB7" id="fZv-NH-YA3">
<rect key="frame" x="0.0" y="0.0" width="293" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="Sound" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="VYC-xF-awf">
<rect key="frame" x="16" y="12" width="49.5" height="20.5"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleBody"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="Detail" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="Ywb-pT-l1W">
<rect key="frame" x="241" y="12" width="44" height="20.5"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleBody"/>
<color key="textColor" systemColor="secondaryLabelColor" red="0.23529411759999999" green="0.23529411759999999" blue="0.26274509800000001" alpha="0.59999999999999998" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</tableViewCellContentView>
<connections>
<segue destination="I37-dZ-c9Q" kind="push" identifier="segueSoundRecordingReminder" id="xKB-i8-J9c"/>
</connections>
</tableViewCell>
</cells>
</tableViewSection>
</sections>
<connections>
<outlet property="dataSource" destination="JYM-cs-i4H" id="1ji-9q-6qB"/>
<outlet property="delegate" destination="JYM-cs-i4H" id="YU7-R1-VjB"/>
</connections>
</tableView>
<navigationItem key="navigationItem" title="Reminders" id="Z9N-kQ-xhI"/>
<connections>
<outlet property="recordingAllow" destination="mTm-Rm-1RQ" id="tqz-Pk-pSi"/>
<outlet property="recordingSound" destination="UkL-k7-bB7" id="Y9s-fL-cQU"/>
<outlet property="restartAllow" destination="zaV-mh-eqb" id="zcQ-1e-i4H"/>
<outlet property="restartAllowBadge" destination="N2Q-cU-pkd" id="RPU-f6-Dv3"/>
<outlet property="restartAllowNotify" destination="HaE-En-NH3" id="1BN-5h-zNR"/>
<outlet property="restartSound" destination="pAS-8r-oS5" id="9Dy-QR-WXq"/>
</connections>
</tableViewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="W7H-LK-3wW" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="-200" y="768"/>
</scene>
<!--Sound-->
<scene sceneID="3a5-wn-tdm">
<objects>
<tableViewController id="I37-dZ-c9Q" customClass="TVCChooseAlertTone" customModule="AppCheck" customModuleProvider="target" sceneMemberID="viewController">
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="grouped" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="18" sectionFooterHeight="18" id="w2R-BE-lM4">
<rect key="frame" x="0.0" y="0.0" width="320" height="568"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
<prototypes>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" accessoryType="checkmark" indentationWidth="10" reuseIdentifier="SettingsAlertToneCell" textLabel="O50-Db-5TI" style="IBUITableViewCellStyleDefault" id="38V-eP-HSv">
<rect key="frame" x="0.0" y="55.5" width="320" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="38V-eP-HSv" id="hoG-Cy-sHr">
<rect key="frame" x="0.0" y="0.0" width="280" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="Title" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="O50-Db-5TI">
<rect key="frame" x="16" y="0.0" width="256" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleBody"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</tableViewCellContentView>
</tableViewCell>
</prototypes>
<sections/>
<connections>
<outlet property="dataSource" destination="I37-dZ-c9Q" id="aji-Ci-VQs"/>
<outlet property="delegate" destination="I37-dZ-c9Q" id="YUg-WL-kh8"/>
</connections>
</tableView>
<navigationItem key="navigationItem" title="Sound" id="5hI-rp-d1Z"/>
</tableViewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="NXc-3P-uoW" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="1500" y="768"/>
</scene>
<!--Connection Alerts-->
<scene sceneID="JyV-QU-Dw8">
<objects>
<tableViewController id="D2a-Po-vDU" customClass="TVCConnectionAlerts" customModule="AppCheck" customModuleProvider="target" sceneMemberID="viewController">
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="static" style="grouped" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="18" sectionFooterHeight="18" id="u0e-LW-1Qh">
<rect key="frame" x="0.0" y="0.0" width="320" height="568"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
<sections>
<tableViewSection headerTitle="Connection Alerts" footerTitle="Get a notification whenever a specific DNS request occurs." id="4OJ-qA-l8L">
<cells>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="none" indentationWidth="10" textLabel="9g7-rO-sIS" style="IBUITableViewCellStyleDefault" id="8hz-pm-rV5">
<rect key="frame" x="0.0" y="55.5" width="320" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="8hz-pm-rV5" id="fz3-2p-ave">
<rect key="frame" x="0.0" y="0.0" width="320" height="43.5"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="Enable Alerts" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="9g7-rO-sIS">
<rect key="frame" x="16" y="0.0" width="288" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleBody"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" contentHorizontalAlignment="center" contentVerticalAlignment="center" on="YES" translatesAutoresizingMaskIntoConstraints="NO" id="who-8G-voz">
<rect key="frame" x="256" y="6" width="48" height="31"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxY="YES"/>
<connections>
<action selector="toggleShowNotifications:" destination="D2a-Po-vDU" eventType="valueChanged" id="Thg-6R-7wM"/>
</connections>
</switch>
</subviews>
</tableViewCellContentView>
<connections>
<outlet property="accessoryView" destination="who-8G-voz" id="6YE-dG-ThI"/>
</connections>
</tableViewCell>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" accessoryType="disclosureIndicator" indentationWidth="10" textLabel="pck-pT-tnX" detailTextLabel="l8v-5i-Zue" style="IBUITableViewCellStyleValue1" id="laE-pg-nAE">
<rect key="frame" x="0.0" y="99" width="320" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="laE-pg-nAE" id="157-KR-1R5">
<rect key="frame" x="0.0" y="0.0" width="293" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="Sound" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="pck-pT-tnX">
<rect key="frame" x="16" y="12" width="49.5" height="20.5"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleBody"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="Detail" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="l8v-5i-Zue">
<rect key="frame" x="241" y="12" width="44" height="20.5"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleBody"/>
<color key="textColor" systemColor="secondaryLabelColor" red="0.23529411759999999" green="0.23529411759999999" blue="0.26274509800000001" alpha="0.59999999999999998" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</tableViewCellContentView>
<connections>
<segue destination="I37-dZ-c9Q" kind="push" id="tUF-Kv-koO"/>
</connections>
</tableViewCell>
</cells>
</tableViewSection>
<tableViewSection headerTitle="Operation Mode" footerTitle="Select whether you'd like to manually include or manually exclude specific domains from notifications." id="9fV-UJ-d1S">
<cells>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" accessoryType="checkmark" indentationWidth="10" textLabel="Lug-Bp-oz0" style="IBUITableViewCellStyleDefault" id="ZMb-xn-r8o">
<rect key="frame" x="0.0" y="234" width="320" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="ZMb-xn-r8o" id="eT6-OU-8eU">
<rect key="frame" x="0.0" y="0.0" width="280" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="Notify only selected lists" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="Lug-Bp-oz0">
<rect key="frame" x="16" y="0.0" width="256" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleBody"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</tableViewCellContentView>
</tableViewCell>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" accessoryType="checkmark" indentationWidth="10" textLabel="FRE-W4-dw2" style="IBUITableViewCellStyleDefault" id="47P-B8-Sul">
<rect key="frame" x="0.0" y="277.5" width="320" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="47P-B8-Sul" id="RbD-bN-NCj">
<rect key="frame" x="0.0" y="0.0" width="280" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="Notify all, except selected" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="FRE-W4-dw2">
<rect key="frame" x="16" y="0.0" width="256" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleBody"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</tableViewCellContentView>
</tableViewCell>
</cells>
</tableViewSection>
<tableViewSection headerTitle="Include" id="Lus-cA-eCF">
<cells>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" accessoryType="checkmark" indentationWidth="10" textLabel="be7-GU-inU" style="IBUITableViewCellStyleDefault" id="2bN-EB-rDk">
<rect key="frame" x="0.0" y="421" width="320" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="2bN-EB-rDk" id="UxC-Sm-W4n">
<rect key="frame" x="0.0" y="0.0" width="280" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="Blocked Domains" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="be7-GU-inU">
<rect key="frame" x="16" y="0.0" width="256" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleBody"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</tableViewCellContentView>
</tableViewCell>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" accessoryType="checkmark" indentationWidth="10" textLabel="fYg-Mq-C4Q" style="IBUITableViewCellStyleDefault" id="UTd-2r-8c7">
<rect key="frame" x="0.0" y="464.5" width="320" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="UTd-2r-8c7" id="Z6Y-qL-4bw">
<rect key="frame" x="0.0" y="0.0" width="280" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="Domains of List A" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="fYg-Mq-C4Q">
<rect key="frame" x="16" y="0.0" width="256" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleBody"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</tableViewCellContentView>
</tableViewCell>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" accessoryType="checkmark" indentationWidth="10" textLabel="f4F-j9-uiy" style="IBUITableViewCellStyleDefault" id="dk0-Vg-0Zl">
<rect key="frame" x="0.0" y="508" width="320" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="dk0-Vg-0Zl" id="69j-ye-ziM">
<rect key="frame" x="0.0" y="0.0" width="280" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="Domains of List B" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="f4F-j9-uiy">
<rect key="frame" x="16" y="0.0" width="256" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleBody"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</tableViewCellContentView>
</tableViewCell>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" accessoryType="checkmark" indentationWidth="10" textLabel="RiJ-Eq-LiA" style="IBUITableViewCellStyleDefault" id="VTi-I6-dXQ">
<rect key="frame" x="0.0" y="551.5" width="320" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="VTi-I6-dXQ" id="PbB-ri-ibd">
<rect key="frame" x="0.0" y="0.0" width="280" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="Not in Any List" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="RiJ-Eq-LiA">
<rect key="frame" x="16" y="0.0" width="256" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleBody"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</tableViewCellContentView>
</tableViewCell>
</cells>
</tableViewSection>
<tableViewSection headerTitle="Custom Lists" footerTitle="" id="5bN-ic-93C">
<cells>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" accessoryType="disclosureIndicator" indentationWidth="10" textLabel="1fx-L3-esi" detailTextLabel="SAD-ad-RUa" style="IBUITableViewCellStyleValue2" id="fzJ-h6-8Ll">
<rect key="frame" x="0.0" y="658.5" width="320" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="fzJ-h6-8Ll" id="u6I-My-k4J">
<rect key="frame" x="0.0" y="0.0" width="293" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="List A" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="1fx-L3-esi">
<rect key="frame" x="16" y="13" width="91" height="18"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleSubhead"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="0 Domains" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="SAD-ad-RUa">
<rect key="frame" x="113" y="13" width="73" height="18"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleSubhead"/>
<color key="textColor" systemColor="secondaryLabelColor" red="0.23529411759999999" green="0.23529411759999999" blue="0.26274509800000001" alpha="0.59999999999999998" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</tableViewCellContentView>
<connections>
<segue destination="q3B-Yi-1bx" kind="push" identifier="segueFilterListCustomA" id="2ak-aX-wVl"/>
</connections>
</tableViewCell>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" accessoryType="disclosureIndicator" indentationWidth="10" textLabel="bP5-xR-UWP" detailTextLabel="3b0-Aj-9So" style="IBUITableViewCellStyleValue2" id="uTh-Xw-vp2">
<rect key="frame" x="0.0" y="702.5" width="320" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="uTh-Xw-vp2" id="h1L-kH-yQX">
<rect key="frame" x="0.0" y="0.0" width="293" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="List B" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="bP5-xR-UWP">
<rect key="frame" x="16" y="13" width="91" height="18"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleSubhead"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="0 Domains" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="3b0-Aj-9So">
<rect key="frame" x="113" y="13" width="73" height="18"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleSubhead"/>
<color key="textColor" systemColor="secondaryLabelColor" red="0.23529411759999999" green="0.23529411759999999" blue="0.26274509800000001" alpha="0.59999999999999998" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</tableViewCellContentView>
<connections>
<segue destination="q3B-Yi-1bx" kind="push" identifier="segueFilterListCustomB" id="6wc-d1-VYY"/>
</connections>
</tableViewCell>
</cells>
</tableViewSection>
</sections>
<connections>
<outlet property="dataSource" destination="D2a-Po-vDU" id="4t8-lb-7wO"/>
<outlet property="delegate" destination="D2a-Po-vDU" id="I1e-X5-6xm"/>
</connections>
</tableView>
<navigationItem key="navigationItem" title="Connection Alerts" id="5Re-pU-mt2"/>
<connections>
<outlet property="cellSound" destination="laE-pg-nAE" id="Qd5-mf-wox"/>
<outlet property="listsCustomA" destination="fzJ-h6-8Ll" id="77h-42-70y"/>
<outlet property="listsCustomB" destination="uTh-Xw-vp2" id="6OI-pU-Vff"/>
<outlet property="showNotifications" destination="who-8G-voz" id="cUz-Bg-ftS"/>
</connections>
</tableViewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="1z3-Sx-YAL" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="650" y="384"/>
</scene>
</scenes>
<inferredMetricsTieBreakers>
<segue reference="tUF-Kv-koO"/>
<segue reference="6wc-d1-VYY"/>
</inferredMetricsTieBreakers>
</document>

View File

@@ -0,0 +1,237 @@
import UIKit
class CustomAlert<CustomView: UIView>: UIViewController {
private let alertTitle: String?
private let alertDetail: String?
private let customView: CustomView
private var callback: ((CustomView) -> Void)?
/// Default: `[Cancel, Save]`
let buttonsBar: UIStackView = {
let cancel = QuickUI.button("Cancel", target: self, action: #selector(didTapCancel))
let save = QuickUI.button("Save", target: self, action: #selector(didTapSave))
save.titleLabel?.font = save.titleLabel?.font.bold()
let bar = UIStackView(arrangedSubviews: [cancel, save])
bar.axis = .horizontal
bar.distribution = .equalSpacing
return bar
}()
// MARK: - Init
required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") }
init(title: String? = nil, detail: String? = nil, view custom: CustomView) {
alertTitle = title
alertDetail = detail
customView = custom
super.init(nibName: nil, bundle: nil)
}
override var isModalInPresentation: Bool { set{} get{true} }
override var modalPresentationStyle: UIModalPresentationStyle { set{} get{.custom} }
override var transitioningDelegate: UIViewControllerTransitioningDelegate? {
set {} get {
SlideInTransitioningDelegate(for: .bottom, modal: true)
}
}
internal override func loadView() {
let control = UIView()
control.backgroundColor = .sysBackground
view = control
var tmpPrevivous: UIView? = nil
func adaptive(margin: CGFloat, _ fn: () -> NSLayoutConstraint) {
regularConstraints.append(fn() + margin)
compactConstraints.append(fn() + margin/2)
}
func addLabel(_ lbl: UILabel) {
lbl.numberOfLines = 0
control.addSubview(lbl)
lbl.anchor([.leading, .trailing], to: control.layoutMarginsGuide)
if let p = tmpPrevivous {
adaptive(margin: 16) { lbl.topAnchor =&= p.bottomAnchor }
} else {
adaptive(margin: 12) { lbl.topAnchor =&= control.layoutMarginsGuide.topAnchor }
}
tmpPrevivous = lbl
}
// Alert title & description
if let t = alertTitle {
let lbl = QuickUI.label(t, align: .center, style: .subheadline)
lbl.font = lbl.font.bold()
addLabel(lbl)
}
if let d = alertDetail {
addLabel(QuickUI.label(d, align: .center, style: .footnote))
}
// User content
control.addSubview(customView)
customView.anchor([.leading, .trailing], to: control)
if let p = tmpPrevivous {
customView.topAnchor =&= p.bottomAnchor | .defaultHigh
} else {
customView.topAnchor =&= control.layoutMarginsGuide.topAnchor
}
// Action buttons
control.addSubview(buttonsBar)
buttonsBar.anchor([.leading, .trailing], to: control.layoutMarginsGuide, margin: 8)
buttonsBar.topAnchor =&= customView.bottomAnchor | .defaultHigh
adaptive(margin: 12) { control.layoutMarginsGuide.bottomAnchor =&= buttonsBar.bottomAnchor }
adaptToNewTraits(traitCollection)
view.frame.size = view.systemLayoutSizeFitting(UIView.layoutFittingCompressedSize)
}
// MARK: - Adaptive Traits
private var compactConstraints: [NSLayoutConstraint] = []
private var regularConstraints: [NSLayoutConstraint] = []
private func adaptToNewTraits(_ traits: UITraitCollection) {
let flag = traits.verticalSizeClass == .compact
NSLayoutConstraint.deactivate(flag ? regularConstraints : compactConstraints)
NSLayoutConstraint.activate(flag ? compactConstraints : regularConstraints)
view.setNeedsLayout()
}
override func willTransition(to newCollection: UITraitCollection, with coordinator: UIViewControllerTransitionCoordinator) {
super.willTransition(to: newCollection, with: coordinator)
adaptToNewTraits(newCollection)
}
// MARK: - User Interaction
override var keyCommands: [UIKeyCommand]? {
[UIKeyCommand(input: UIKeyCommand.inputEscape, modifierFlags: [], action: #selector(didTapCancel))]
}
@objc private func didTapCancel() {
callback = nil
dismiss(animated: true)
}
@objc private func didTapSave() {
dismiss(animated: true) {
self.callback?(self.customView)
self.callback = nil
}
}
// MARK: - Present & Dismiss
func present(in viewController: UIViewController, onSuccess: @escaping (CustomView) -> Void) {
callback = onSuccess
viewController.present(self, animated: true)
}
}
// ###################################
// #
// # MARK: - Date Picker Alert
// #
// ###################################
class DatePickerAlert : CustomAlert<UIDatePicker> {
let datePicker = UIDatePicker()
required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") }
init(title: String? = nil, detail: String? = nil, initial date: Date? = nil) {
if let date = date {
datePicker.setDate(date, animated: false)
}
super.init(title: title, detail: detail, view: datePicker)
let now = QuickUI.button("Now", target: self, action: #selector(didTapNow))
now.titleLabel?.font = now.titleLabel?.font.bold()
now.setTitleColor(.sysLabel, for: .normal)
buttonsBar.insertArrangedSubview(now, at: 1)
}
@objc private func didTapNow() {
datePicker.date = Date()
}
func present(in viewController: UIViewController, onSuccess: @escaping (UIDatePicker, Date) -> Void) {
super.present(in: viewController) {
onSuccess($0, $0.date)
}
}
}
// #######################################
// #
// # MARK: - Duration Picker Alert
// #
// #######################################
class DurationPickerAlert: CustomAlert<UIPickerView>, UIPickerViewDataSource, UIPickerViewDelegate {
let pickerView = UIPickerView()
private let dataSource: [[String]]
private let compWidths: [CGFloat]
required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") }
/// - Parameter options: [[List of labels] per component]
/// - Parameter widths: If `nil` set all components to equal width
init(title: String? = nil, detail: String? = nil, options: [[String]], widths: [CGFloat]? = nil) {
assert(widths == nil || widths!.count == options.count, "widths.count != options.count")
dataSource = options
compWidths = widths ?? options.map { _ in 1 / CGFloat(options.count) }
super.init(title: title, detail: detail, view: pickerView)
pickerView.dataSource = self
pickerView.delegate = self
}
func numberOfComponents(in _: UIPickerView) -> Int {
dataSource.count
}
func pickerView(_: UIPickerView, numberOfRowsInComponent c: Int) -> Int {
dataSource[c].count
}
func pickerView(_: UIPickerView, titleForRow r: Int, forComponent c: Int) -> String? {
dataSource[c][r]
}
func pickerView(_ pickerView: UIPickerView, widthForComponent c: Int) -> CGFloat {
compWidths[c] * pickerView.frame.width
}
func present(in viewController: UIViewController, onSuccess: @escaping (UIPickerView, [Int]) -> Void) {
super.present(in: viewController) {
onSuccess($0, $0.selection)
}
}
}
extension UIPickerView {
var selection: [Int] {
get { (0..<numberOfComponents).map { selectedRow(inComponent: $0) } }
set { setSelection(newValue) }
}
/// - Warning: Does not check for boundaries!
func setSelection(_ selection: [Int], animated: Bool = false) {
assert(selection.count == numberOfComponents, "selection.count != components.count")
for (c, i) in selection.enumerated() {
selectRow(i, inComponent: c, animated: animated)
}
}
}

View File

@@ -0,0 +1,418 @@
import UIKit
protocol FilterPipelineDelegate: AnyObject {
/// Call `reloadData()`
func filterPipelineDidReset()
/// Call `safeDeleteRows()`
func filterPipeline(delete rows: [Int])
/// Call `safeInsertRow()`
func filterPipeline(insert row: Int)
/// Call `safeReloadRow()`
func filterPipeline(update row: Int)
/// Call `safeMoveRow()`
func filterPipeline(move oldRow: Int, to newRow: Int)
}
// MARK: - FilterPipeline
class FilterPipeline<T> {
private(set) fileprivate var dataSource: [T] = []
private var pipeline: [PipelineFilter<T>] = []
private var display: PipelineSorting<T>!
weak var delegate: FilterPipelineDelegate?
/// - Returns: Number of elements in `projection`
@inline(__always) func displayObjectCount() -> Int { display.projection.count }
/// Dereference `projection` index to `dataSource` index
/// - Complexity: O(1)
@inline(__always) func displayObject(at index: Int) -> T { dataSource[display.projection[index]] }
/// Search and return first element in `dataSource` that matches `predicate`.
/// - Returns: Index in `dataSource` and found object or `nil` if no matching item found.
/// - Complexity: O(*n*), where *n* is the length of the `dataSource`.
func dataSourceGet(where predicate: ((T) -> Bool)) -> (index: Int, object: T)? {
// TODO: use sorted dataSource for binary lookup?
// would require to shift filter and sorting indices for every new element
guard let i = dataSource.firstIndex(where: predicate) else {
return nil
}
return (i, dataSource[i])
}
/// Set new data source and re-built filter and display sorting order.
/// - Note: Will call `filterPipelineDidReset()`
func reset(dataSource: [T]) {
self.dataSource = dataSource
self.resetFilters()
delegate?.filterPipelineDidReset()
}
/// Returns the index set of either the last filter layer, or `dataSource` if no filter is set.
fileprivate func lastLayerIndices() -> [Int] {
pipeline.last?.selection ?? dataSource.indices.arr()
}
/// Get pipeline index of filter with given identifier
private func indexOfFilter(_ identifier: String) -> Int? {
pipeline.firstIndex(where: {$0.id == identifier})
}
// MARK: manage pipeline
/// Add new filter layer. Each layer is applied upon the previous layer. Therefore, each filter
/// can only restrict the display further. A filter cannot introduce previously removed elements.
/// - Warning: Use `[unowned self]` to prevent retain cycles!
/// - Note: Will call `filterPipelineDidReset()`
/// - Parameters:
/// - identifier: Use this id to find the filter again. For reload and remove operations.
/// - otherId: If `nil` or non-existent the new filter will be appended at the end.
/// - predicate: Return `true` if you want to keep the element.
func addFilter(_ identifier: String, before otherId: String? = nil, _ predicate: @escaping PipelineFilter<T>.Predicate) {
guard indexOfFilter(identifier) == nil else { return }
let newFilter = PipelineFilter(identifier, predicate)
if let other = otherId, let i = indexOfFilter(other) {
pipeline.insert(newFilter, at: i)
resetFilters(startingAt: i)
} else {
newFilter.reset(to: dataSource, previous: lastLayerIndices())
pipeline.append(newFilter)
display?.apply(moreRestrictive: newFilter.selection)
}
delegate?.filterPipelineDidReset()
}
/// Find and remove filter with given identifier. Will automatically update remaining filters and display sorting.
/// - Note: Will call `filterPipelineDidReset()`
func removeFilter(withId ident: String) {
guard let i = indexOfFilter(ident) else { return }
pipeline.remove(at: i)
if i == pipeline.count {
// only if we don't reset other layers we can assure `toLessRestrictive`
display?.apply(lessRestrictive: lastLayerIndices())
} else {
resetFilters(startingAt: i)
}
delegate?.filterPipelineDidReset()
}
/// Start filter evaluation on all entries from previous filter.
/// - Note: Will call `filterPipelineDidReset()`
func reloadFilter(withId ident: String) {
guard let i = indexOfFilter(ident) else { return }
resetFilters(startingAt: i)
delegate?.filterPipelineDidReset()
}
/// Sets the sort and display order. You should set the `delegate` to automatically update your `tableView`.
/// - Warning: Use `[unowned self]` to prevent retain cycles!
/// - Note: Will call `filterPipelineDidReset()`
/// - Parameter predicate: Return `true` if first element should be sorted before second element.
func setSorting(_ predicate: @escaping PipelineSorting<T>.Predicate) {
display = .init(predicate, pipe: self)
delegate?.filterPipelineDidReset()
}
/// Will reverse the current display order without resorting. This is faster than setting a new sorting `predicate`.
/// However, the `predicate` must be dynamic and support a sort order flag.
/// - Note: Will call `filterPipelineDidReset()`
/// - Warning: Make sure `predicate` does reflect the change or it will lead to data inconsistency!
func reverseSorting() {
// TODO: use semaphore to prevent concurrent edits
display?.reverseOrder()
delegate?.filterPipelineDidReset()
}
/// Re-built filter and display sorting order.
/// - Parameter index: Must be: `index <= pipeline.count`
private func resetFilters(startingAt index: Int = 0) {
for i in index..<pipeline.count {
pipeline[i].reset(to: dataSource, previous: (i>0)
? pipeline[i-1].selection : dataSource.indices.arr())
}
// Reset is NOT less-restrictive because filters are dynamic
// Calling reset on a filter twice may yield different results
// E.g. if filter uses variables outside of scope (current time, search term)
display?.reset(to: lastLayerIndices())
}
/// Push object through filter pipeline to check whether it survives all filters.
/// - Parameter index: The index of the object in the original `dataSource`
/// - Returns: `changed` is `true` if element persists or should be removed with this update.
/// `display` indicates whther element should be shown (`true`) or hidden (`false`).
/// - Complexity: O(*m* log *n*), where *m* is the number of filters and *n* the number of elements in each filter.
private func processPipeline(with obj: T, at index: Int) -> (changed: Bool, display: Bool) {
var keepGoing = true
for filter in pipeline {
let lastIndex: Int?
if keepGoing {
(keepGoing, lastIndex) = filter.update(obj, at: index)
} else {
lastIndex = filter.remove(dataSource: index)
}
// if it isnt in this layer, it wont appear in the following either
if lastIndex == nil { return (false, false) }
}
return (true, keepGoing)
}
// MARK: data updates
/// Add new element to the original `dataSource` and immediately apply filter and sorting.
/// - Note: Will call `filterPipeline(insert:)` if not filtered.
/// - Complexity: O((*m*+1) log *n*), where *m* is the number of filters and *n* the number of elements in each filter.
func addNew(_ obj: T) {
let index = dataSource.count
dataSource.append(obj)
for filter in pipeline {
if filter.add(obj, at: index) == nil { return }
}
// survived all filters
let displayIndex = display.insertNew(index)
delegate?.filterPipeline(insert: displayIndex)
}
/// Update element at `index` in the original `dataSource` and immediately re-apply filter and sorting.
/// - Note: Will call `filterPipeline(delete:)`, `(insert:)`, `(update:)`, or `(move:)`
/// - Parameters:
/// - obj: Element to be added. Will overwrite previous `dataSource` object.
/// - index: Index in the original `dataSource`
/// - Complexity: O(*n* + (*m*+1) log *n*), where *m* is the number of filters and *n* the number of elements in each filter / projection.
func update(_ obj: T, at index: Int) {
let status = processPipeline(with: obj, at: index)
guard status.changed else {
dataSource[index] = obj // we need to update anyway
return
}
let oldPos = display.deleteOld(index)
dataSource[index] = obj
guard status.display else {
if oldPos != -1 { delegate?.filterPipeline(delete: [oldPos]) }
return
}
let newPos = display.insertNew(index, previousIndex: oldPos)
if oldPos == -1 {
delegate?.filterPipeline(insert: newPos)
} else {
if oldPos == newPos {
delegate?.filterPipeline(update: oldPos)
} else {
delegate?.filterPipeline(move: oldPos, to: newPos)
}
}
}
/// Remove elements from the original `dataSource`, from all filters, and from display sorting.
/// - Note: Will call `filterPipeline(delete:)` if `sorted` array is not empty.
/// - Parameter sorted: Indices in the original `dataSource`
/// - Complexity: O(*t*(*m*+*n*) + *m* log *n*), where *t* is the number of filters,
/// *m* the number of elements in each filter / projection, and *n* the length of `sorted` indices.
func remove(indices sorted: [Int]) {
guard sorted.count > 0 else { return }
for i in sorted.reversed() {
dataSource.remove(at: i)
}
for filter in pipeline {
filter.shiftRemove(indices: sorted)
}
let indices = display.shiftRemove(indices: sorted)
delegate?.filterPipeline(delete: indices)
}
}
// MARK: - Filter
class PipelineFilter<T>: CustomStringConvertible {
var description: String { "\(Self.self)(id: \(id))" }
typealias Predicate = (T) -> Bool
let id: String
private(set) var selection: [Int] = []
private let shouldPersist: Predicate
/// - Parameter predicate: Return `true` if you want to keep the element
required init(_ identifier: String, _ predicate: @escaping Predicate) {
self.id = identifier
shouldPersist = predicate
}
/// Reset `selection` by copying the indices and applying the filter function
fileprivate func reset(to dataSource: [T], previous filterIndices: [Int]) {
selection = filterIndices
selection.removeAll { !shouldPersist(dataSource[$0]) }
}
/// Apply filter to `obj` and either insert or do nothing.
/// - Parameters:
/// - obj: Object that should be inserted if filter allows.
/// - index: Index of object in original `dataSource`
/// - Returns: Index in `selection` or `nil` if `obj` is removed by the filter.
/// - Complexity:
/// * O(1), if `index` is appended at end.
/// * O(log *n*), where *n* is the length of the `selection`.
fileprivate func add(_ obj: T, at index: Int) -> Int? {
guard shouldPersist(obj) else {
return nil
}
if selection.last ?? 0 < index { // in case we only append at end
selection.append(index)
return selection.count - 1
}
return selection.binTreeInsert(index, compare: (<))
}
/// Search and remove original `dataSource` index
/// - Parameter index: Index of object in original `dataSource`
/// - Returns: Index of removed element in `selection` or `nil` if element does not exist
/// - Complexity: O(log *n*), where *n* is the length of the `selection`.
fileprivate func remove(dataSource index: Int) -> Int? {
selection.binTreeRemove(index, compare: (<))
}
/// Perform filter check and update internal `selection` indices.
/// - Parameters:
/// - obj: Object that was inserted or updated.
/// - index: Index where the object is located after the update.
/// - Returns: `keep` indicates whether the value should be displayed (`true`) or hidden (`false`).
/// `idx` contains the selection filter index or `nil` if the value should be removed.
/// - Complexity: O(log *n*), where *n* is the length of the `selection`.
fileprivate func update(_ obj: T, at index: Int) -> (keep: Bool, idx: Int?) {
let currentIndex = selection.binTreeIndex(of: index, compare: (<), mustExist: true)
if shouldPersist(obj) {
return (true, currentIndex ?? selection.binTreeInsert(index, compare: (<)))
}
if let i = currentIndex { selection.remove(at: i) }
return (false, currentIndex)
}
/// Instead of re-sorting we can decrement all remaining elements after X.
/// - Parameter sorted: Elements to remove from collection
/// - Complexity: O(*m*+*n*), where *m* is the length of the `selection`.
/// *n* is equal to: *length of selection* `-` *index of first element* of `sorted` indices
fileprivate func shiftRemove(indices sorted: [Int]) {
guard sorted.count > 0 else {
return
}
var list = sorted
var del = list.popLast()
for (i, val) in selection.enumerated().reversed() {
while let d = del, d > val {
del = list.popLast()
}
guard let d = del else { break }
if d < val { selection[i] -= (list.count + 1) }
else if d == val { selection.remove(at: i) }
}
}
}
// MARK: - Sorting
class PipelineSorting<T> {
typealias Predicate = (T, T) -> Bool
private(set) var projection: [Int] = []
private let comperator: (Int, Int) -> Bool // links to pipeline.dataSource
/// Create a fresh, already sorted, display order projection.
/// - Parameter predicate: Return `true` if first element should be sorted before second element.
/// - Complexity: O(*n* log *n*), where *n* is the length of the `filter`.
required init(_ predicate: @escaping Predicate, pipe: FilterPipeline<T>) {
comperator = { [unowned pipe] in
predicate(pipe.dataSource[$0], pipe.dataSource[$1])
}
reset(to: pipe.lastLayerIndices())
}
/// - Warning: Make sure `predicate` does reflect the change. Or it will lead to data inconsistency.
/// - Complexity: O(*n*), where *n* is the length of the `filter`.
fileprivate func reverseOrder() {
projection.reverse()
}
/// Replace current `projection` with new filter indices and apply sorting.
/// - Complexity: O(*n* log *n*), where *n* is the length of the `filter`.
fileprivate func reset(to filterIndices: [Int]) {
projection = filterIndices.sorted(by: comperator)
}
/// After adding a new layer of filtering the new layer can only restrict the display even further.
/// Therefore, indices that were removed in the last layer will be removed from the projection too.
/// - Complexity: O(*m* log *n*), where *m* is the length of the `projection` and *n* the length of the `filter`.
fileprivate func apply(moreRestrictive filterIndices: [Int]) {
projection.removeAll { !filterIndices.binTreeExists($0, compare: (<)) }
}
/// After removing a layer of filtering the previous layers are less restrictive and thus contain more indices.
/// Therefore, the difference between both index sets will be inserted into the projection.
/// - Complexity: O(*m* log *n*), where *m* is the difference to the previous layer and *n* is the length of the `projection`.
fileprivate func apply(lessRestrictive filterIndices: [Int]) {
for x in filterIndices.difference(toSubset: projection.sorted(), compare: (<)) {
insertNew(x)
}
}
/// Add new element and automatically sort according to predicate
/// - Parameters:
/// - index: Index of the element position in the original `dataSource`
/// - prev: If greater than `0`, try re-insert at the same position.
/// - Returns: Index in the projection
/// - Complexity: O(log *n*), where *n* is the length of the `projection`.
@discardableResult fileprivate func insertNew(_ index: Int, previousIndex prev: Int = -1) -> Int {
if prev >= 0, prev <= projection.count { // '<=' because previous delete removed one element
if (prev == 0 || !comperator(index, projection[prev - 1])),
(prev == projection.count || !comperator(projection[prev], index)) {
// If element can be inserted at the same position without resorting, do that
projection.insert(index, at: prev)
return prev
}
}
return projection.binTreeInsert(index, compare: comperator)
}
/// Remove element from projection
/// - Parameter index: Index of the element position in the original `dataSource`
/// - Returns: Index in the projection or `-1` if element did not exist
/// - Complexity: O(*n*), where *n* is the length of the `projection`.
fileprivate func deleteOld(_ index: Int) -> Int {
guard let i = projection.firstIndex(of: index) else {
return -1
}
projection.remove(at: i)
return i
}
/// Instead of re-sorting we can decrement all remaining elements after X.
/// - Parameter sorted: Elements to remove from collection
/// - Returns: List of `projection` indices that were removed (reverse sort order)
/// - Complexity: O(*m* log *n*), where *m* is the length of the `projection` and *n* is the length of `sorted`.
@discardableResult fileprivate func shiftRemove(indices sorted: [Int]) -> [Int] {
guard sorted.count > 0 else {
return []
}
var listOfDeletes: [Int] = []
let min = sorted.first!, max = sorted.last!
for (i, val) in projection.enumerated().reversed() {
guard val >= min else { continue }
if val > max {
projection[i] -= sorted.count
} else {
let c = sorted.binTreeIndex(of: val, compare: (<))!
if val == sorted[c] {
projection.remove(at: i)
listOfDeletes.append(i)
} else {
projection[i] -= c
}
}
}
return listOfDeletes
}
}

View File

@@ -0,0 +1,83 @@
import UIKit
import CoreGraphics
// MARK: White Triangle Popup Arrow
@IBDesignable
class PopupTriangle: UIView {
@IBInspectable var rotation: CGFloat = 0
@IBInspectable var color: UIColor = .black
override func draw(_ rect: CGRect) {
guard let c = UIGraphicsGetCurrentContext() else { return }
let w = rect.width, h = rect.height
switch rotation {
case 90: // right
c.lineFromTo(x1: 0, y1: 0, x2: w, y2: h/2)
c.addLine(to: CGPoint(x: 0, y: h))
case 180: // bottom
c.lineFromTo(x1: w, y1: 0, x2: w/2, y2: h)
c.addLine(to: CGPoint(x: 0, y: 0))
case 270: // left
c.lineFromTo(x1: w, y1: h, x2: 0, y2: h/2)
c.addLine(to: CGPoint(x: w, y: 0))
default: // top
c.lineFromTo(x1: 0, y1: h, x2: w/2, y2: 0)
c.addLine(to: CGPoint(x: w, y: h))
}
c.closePath()
c.setFillColor(color.cgColor)
c.fillPath()
}
}
// MARK: Label as Tag Bubble
@IBDesignable
class TagLabel: UILabel {
private var em: CGFloat { font.pointSize }
@IBInspectable var padTop: CGFloat = 0
@IBInspectable var padLeft: CGFloat = 0
@IBInspectable var padRight: CGFloat = 0
@IBInspectable var padBottom: CGFloat = 0
private var padding: UIEdgeInsets {
.init(top: padTop + em/6, left: padLeft + em/3,
bottom: padBottom + em/6, right: padRight + em/3)
}
override func textRect(forBounds bounds: CGRect, limitedToNumberOfLines numberOfLines: Int) -> CGRect {
let i = padding
let ii = UIEdgeInsets(top: -i.top, left: -i.left, bottom: -i.bottom, right: -i.right)
return super.textRect(forBounds: bounds.inset(by: i),
limitedToNumberOfLines: numberOfLines).inset(by: ii)
}
override func drawText(in rect: CGRect) {
layer.masksToBounds = true
layer.cornerRadius = em/2.5
super.drawText(in: rect.inset(by: padding))
}
}
// MARK: Percentage meter
@IBDesignable
class MeterBar: UIView {
@IBInspectable var percent: CGFloat = 0 { didSet { setNeedsDisplay() } }
@IBInspectable var barColor: UIColor = .sysLink
@IBInspectable var horizontal: Bool = false
private var normPercent: CGFloat { 1 - max(0, min(percent, 1)) }
override func draw(_ rect: CGRect) {
let c = UIGraphicsGetCurrentContext()
c?.setFillColor(barColor.cgColor)
if horizontal {
c?.fill(rect.insetBy(dx: normPercent * (rect.width/2), dy: 0))
} else {
c?.fill(rect.insetBy(dx: 0, dy: normPercent * (rect.height/2)))
}
}
}

View File

@@ -0,0 +1,122 @@
import Foundation
enum Prefs {
private static var suite: UserDefaults { UserDefaults.standard }
private static func Int(_ key: String) -> Int { suite.integer(forKey: key) }
private static func Int(_ key: String, _ val: Int) { suite.set(val, forKey: key) }
private static func Bool(_ key: String) -> Bool { suite.bool(forKey: key) }
private static func Bool(_ key: String, _ val: Bool) { suite.set(val, forKey: key) }
private static func Str(_ key: String) -> String? { suite.string(forKey: key) }
private static func Str(_ key: String, _ val: String?) { suite.set(val, forKey: key) }
private static func Obj(_ key: String) -> Any? { suite.object(forKey: key) }
private static func Obj(_ key: String, _ val: Any?) { suite.set(val, forKey: key) }
static func registerDefaults() {
suite.register(defaults: [
"RecordingReminderEnabled" : true,
"contextAnalyisCoOccurrenceTime" : 5,
])
}
}
// MARK: - Tutorial
extension Prefs {
enum DidShowTutorial {
static var Welcome: Bool {
get { Prefs.Bool("didShowTutorialAppWelcome") }
set { Prefs.Bool("didShowTutorialAppWelcome", newValue) }
}
static var Recordings: Bool {
get { Prefs.Bool("didShowTutorialRecordings") }
set { Prefs.Bool("didShowTutorialRecordings", newValue) }
}
}
}
// MARK: - Date Filter
enum DateFilterKind: Int {
case Off = 0, LastXMin = 1, ABRange = 2;
}
enum DateFilterOrderBy: Int {
case Date = 0, Name = 1, Count = 2;
}
extension Prefs {
enum DateFilter {
static var Kind: DateFilterKind {
get { DateFilterKind(rawValue: Prefs.Int("dateFilterType"))! }
set { Prefs.Int("dateFilterType", newValue.rawValue) }
}
/// Default: `0` (disabled)
static var LastXMin: Int {
get { Prefs.Int("dateFilterLastXMin") }
set { Prefs.Int("dateFilterLastXMin", newValue) }
}
/// Default: `nil` (disabled)
static var RangeA: Timestamp? {
get { Prefs.Obj("dateFilterRangeA") as? Timestamp }
set { Prefs.Obj("dateFilterRangeA", newValue) }
}
/// Default: `nil` (disabled)
static var RangeB: Timestamp? {
get { Prefs.Obj("dateFilterRangeB") as? Timestamp }
set { Prefs.Obj("dateFilterRangeB", newValue) }
}
/// default: `.Date`
static var OrderBy: DateFilterOrderBy {
get { DateFilterOrderBy(rawValue: Prefs.Int("dateFilterOderType"))! }
set { Prefs.Int("dateFilterOderType", newValue.rawValue) }
}
/// default: `false` (Desc)
static var OrderAsc: Bool {
get { Prefs.Bool("dateFilterOderAsc") }
set { Prefs.Bool("dateFilterOderAsc", newValue) }
}
/// - Returns: Timestamp restriction depending on current selected date filter.
/// - `Off` : `(nil, nil)`
/// - `LastXMin` : `(now-LastXMin, nil)`
/// - `ABRange` : `(RangeA, RangeB)`
static func restrictions() -> (type: DateFilterKind, earliest: Timestamp?, latest: Timestamp?) {
let type = Kind
switch type {
case .Off: return (type, nil, nil)
case .LastXMin: return (type, Timestamp.past(minutes: Prefs.DateFilter.LastXMin), nil)
case .ABRange: return (type, Prefs.DateFilter.RangeA, Prefs.DateFilter.RangeB)
}
}
}
}
// MARK: - ContextAnalyis
extension Prefs {
enum ContextAnalyis {
static var CoOccurrenceTime: Int {
get { Prefs.Int("contextAnalyisCoOccurrenceTime") }
set { Prefs.Int("contextAnalyisCoOccurrenceTime", newValue) }
}
}
}
// MARK: - Notifications
extension Prefs {
enum RecordingReminder {
static var Enabled: Bool {
get { Prefs.Bool("RecordingReminderEnabled") }
set { Prefs.Bool("RecordingReminderEnabled", newValue) }
}
static var Sound: String {
get { Prefs.Str("RecordingReminderSound") ?? "#default" }
set { Prefs.Str("RecordingReminderSound", newValue) }
}
}
}

View File

@@ -0,0 +1,82 @@
import Foundation
enum PrefsShared {
private static var suite: UserDefaults { UserDefaults(suiteName: "group.de.uni-bamberg.psi.AppCheck")! }
private static func Int(_ key: String) -> Int { suite.integer(forKey: key) }
private static func Int(_ key: String, _ val: Int) { suite.set(val, forKey: key); suite.synchronize() }
private static func Bool(_ key: String) -> Bool { suite.bool(forKey: key) }
private static func Bool(_ key: String, _ val: Bool) { suite.set(val, forKey: key); suite.synchronize() }
private static func Str(_ key: String) -> String? { suite.string(forKey: key) }
private static func Str(_ key: String, _ val: String?) { suite.set(val, forKey: key); suite.synchronize() }
static func registerDefaults() {
suite.register(defaults: [
"RestartReminderEnabled" : true,
"RestartReminderWithText" : true,
"RestartReminderWithBadge" : true,
"ConnectionAlertsListsElse" : true,
])
}
static var AutoDeleteLogsDays: Int {
get { Int("AutoDeleteLogsDays") }
set { Int("AutoDeleteLogsDays", newValue) }
}
}
// MARK: - Notifications
extension PrefsShared {
enum RestartReminder {
static var Enabled: Bool {
get { PrefsShared.Bool("RestartReminderEnabled") }
set { PrefsShared.Bool("RestartReminderEnabled", newValue) }
}
static var WithText: Bool {
get { PrefsShared.Bool("RestartReminderWithText") }
set { PrefsShared.Bool("RestartReminderWithText", newValue) }
}
static var WithBadge: Bool {
get { PrefsShared.Bool("RestartReminderWithBadge") }
set { PrefsShared.Bool("RestartReminderWithBadge", newValue) }
}
static var Sound: String {
get { PrefsShared.Str("RestartReminderSound") ?? "#default" }
set { PrefsShared.Str("RestartReminderSound", newValue) }
}
}
enum ConnectionAlerts {
static var Enabled: Bool {
get { PrefsShared.Bool("ConnectionAlertsEnabled") }
set { PrefsShared.Bool("ConnectionAlertsEnabled", newValue) }
}
static var Sound: String {
get { PrefsShared.Str("ConnectionAlertsSound") ?? "#default" }
set { PrefsShared.Str("ConnectionAlertsSound", newValue) }
}
static var ExcludeMode: Bool {
get { PrefsShared.Bool("ConnectionAlertsExcludeMode") }
set { PrefsShared.Bool("ConnectionAlertsExcludeMode", newValue) }
}
enum Lists {
static var CustomA: Bool {
get { PrefsShared.Bool("ConnectionAlertsListsCustomA") }
set { PrefsShared.Bool("ConnectionAlertsListsCustomA", newValue) }
}
static var CustomB: Bool {
get { PrefsShared.Bool("ConnectionAlertsListsCustomB") }
set { PrefsShared.Bool("ConnectionAlertsListsCustomB", newValue) }
}
static var Blocked: Bool {
get { PrefsShared.Bool("ConnectionAlertsListsBlocked") }
set { PrefsShared.Bool("ConnectionAlertsListsBlocked", newValue) }
}
static var Else: Bool {
get { PrefsShared.Bool("ConnectionAlertsListsElse") }
set { PrefsShared.Bool("ConnectionAlertsListsElse", newValue) }
}
}
}
}

View File

@@ -0,0 +1,58 @@
import UIKit
struct QuickUI {
static func label(_ str: String, frame: CGRect = CGRect.zero, align: NSTextAlignment = .natural, style: UIFont.TextStyle = .body) -> UILabel {
let x = UILabel(frame: frame)
x.text = str
x.textAlignment = align
x.font = .preferredFont(forTextStyle: style)
x.constrainHuggingCompression(.horizontal, .defaultLow)
x.constrainHuggingCompression(.vertical, .defaultHigh)
x.sizeToFit()
if #available(iOS 10.0, *) {
x.adjustsFontForContentSizeCategory = true
}
return x
}
static func button(_ title: String, target: Any? = nil, action: Selector? = nil) -> UIButton {
let x = UIButton(type: .roundedRect)
x.setTitle(title, for: .normal)
x.titleLabel?.font = .preferredFont(forTextStyle: .body)
x.constrainHuggingCompression(.vertical, .defaultHigh)
x.sizeToFit()
if let a = action { x.addTarget(target, action: a, for: .touchUpInside) }
if #available(iOS 10.0, *) {
x.titleLabel?.adjustsFontForContentSizeCategory = true
}
return x
}
static func image(_ img: UIImage?, frame: CGRect = CGRect.zero) -> UIImageView {
let x = UIImageView(frame: frame)
x.contentMode = .scaleAspectFit
x.image = img
return x
}
static func text(_ str: String, frame: CGRect = CGRect.zero) -> UITextView {
let x = UITextView(frame: frame)
x.font = .preferredFont(forTextStyle: .body) // .systemFont(ofSize: UIFont.systemFontSize)
x.isSelectable = false
x.isEditable = false
x.text = str
if #available(iOS 10.0, *) {
x.adjustsFontForContentSizeCategory = true
}
return x
}
static func text(attributed: NSAttributedString, frame: CGRect = CGRect.zero) -> UITextView {
let txt = self.text("", frame: frame)
txt.attributedText = attributed
txt.textContainerInset = .zero
//txt.textContainer.lineFragmentPadding = 0 // remove left right padding
return txt
}
}

View File

@@ -0,0 +1,64 @@
import UIKit
class SearchBarManager: NSObject, UISearchResultsUpdating {
private(set) var isActive = false
private(set) var term = ""
private lazy var controller: UISearchController = {
let x = UISearchController(searchResultsController: nil)
x.searchBar.autocapitalizationType = .none
x.searchBar.autocorrectionType = .no
x.obscuresBackgroundDuringPresentation = false
x.searchResultsUpdater = self
return x
}()
private weak var tvc: UITableViewController?
private let onChangeCallback: (String) -> Void
/// Prepare `UISearchBar` for user input
/// - Parameter onChange: Code that will be executed every time the user changes the text (with 0.2s delay)
required init(onChange: @escaping (String) -> Void) {
onChangeCallback = onChange
super.init()
UITextField.appearance(whenContainedInInstancesOf: [UISearchBar.self])
.defaultTextAttributes = [.font: UIFont.preferredFont(forTextStyle: .body)]
}
/// Assigns the `UISearchBar` to `tableView.tableHeaderView` (iOS 9) or `navigationItem.searchController` (iOS 11).
func fuseWith(tableViewController: UITableViewController?) {
guard tvc !== tableViewController else { return }
tvc = tableViewController
if #available(iOS 11.0, *) {
tvc?.navigationItem.searchController = controller
} else {
let thv = tvc?.tableView.tableHeaderView
guard thv == nil || thv is UISearchBar else {
// Don't overwrite actions bar (co-occurrence, etc.)
// FIXME: find alternative or iOS 9-10 users can't search in hosts
tvc = nil
return
}
controller.loadViewIfNeeded() // Fix: "Attempting to load the view of a view controller while it is deallocating"
tvc?.definesPresentationContext = true // make search bar disappear if user changes scene (eg. select cell)
//tvc?.tableView.backgroundView = UIView() // iOS 11+ bug: bright white background in dark mode
tvc?.tableView.tableHeaderView = controller.searchBar
tvc?.tableView.setContentOffset(.init(x: 0, y: controller.searchBar.frame.height), animated: false)
}
}
/// Search callback
internal func updateSearchResults(for controller: UISearchController) {
NSObject.cancelPreviousPerformRequests(withTarget: self, selector: #selector(performSearch), object: nil)
perform(#selector(performSearch), with: nil, afterDelay: 0.2)
}
/// Internal callback function for delayed text evaluation.
/// This way we can avoid unnecessary searches while user is typing.
@objc private func performSearch() {
term = controller.searchBar.text?.lowercased() ?? ""
isActive = term.count > 0
onChangeCallback(term)
}
}

View File

@@ -0,0 +1,182 @@
import UIKit
enum PresentationEdge { case left, top, right, bottom }
// ########################################
// #
// # MARK: - Transitioning Delegate
// #
// ########################################
class SlideInTransitioningDelegate: NSObject, UIViewControllerTransitioningDelegate {
private var edge: PresentationEdge
private var modal: Bool
private var dismissable: Bool
private var shadow: UIColor?
init(for edge: PresentationEdge, modal: Bool, tapAnywhereToDismiss: Bool = false, modalBackgroundColor color: UIColor? = nil) {
self.edge = edge
self.dismissable = tapAnywhereToDismiss
self.shadow = color
self.modal = modal
}
func presentationController(forPresented presented: UIViewController, presenting: UIViewController?, source: UIViewController) -> UIPresentationController? {
StickyPresentationController(presented: presented, presenting: presenting, stickTo: edge, modal: modal, tapAnywhereToDismiss: dismissable, modalBackgroundColor: shadow)
}
func animationController(forPresented _: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
SlideInAnimationController(from: edge, isPresentation: true)
}
func animationController(forDismissed _: UIViewController) -> UIViewControllerAnimatedTransitioning? {
SlideInAnimationController(from: edge, isPresentation: false)
}
}
// ########################################
// #
// # MARK: - Animated Transitioning
// #
// ########################################
private final class SlideInAnimationController: NSObject, UIViewControllerAnimatedTransitioning {
let edge: PresentationEdge
let appear: Bool
init(from edge: PresentationEdge, isPresentation: Bool) {
self.edge = edge
self.appear = isPresentation
super.init()
}
func transitionDuration(using context: UIViewControllerContextTransitioning?) -> TimeInterval {
(context?.isAnimated ?? true) ? 0.3 : 0.0
}
func animateTransition(using context: UIViewControllerContextTransitioning) {
guard let vc = context.viewController(forKey: appear ? .to : .from) else { return }
var to = context.finalFrame(for: vc)
var from = to
switch edge {
case .left: from.origin.x = -to.width
case .right: from.origin.x = context.containerView.frame.width
case .top: from.origin.y = -to.height
case .bottom: from.origin.y = context.containerView.frame.height
}
if appear { context.containerView.addSubview(vc.view) }
else { swap(&from, &to) }
vc.view.frame = from
UIView.animate(withDuration: transitionDuration(using: context), animations: {
vc.view.frame = to
}, completion: { finished in
if !self.appear { vc.view.removeFromSuperview() }
context.completeTransition(finished)
})
}
}
// #########################################
// #
// # MARK: - Presentation Controller
// #
// #########################################
private class StickyPresentationController: UIPresentationController {
private let stickTo: PresentationEdge
private let isModal: Bool
private let bg = UIView()
private var availableSize: CGSize = .zero // save original size when resizing the container
override var shouldPresentInFullscreen: Bool { false }
override var frameOfPresentedViewInContainerView: CGRect { fittedContentFrame() }
required init(presented: UIViewController, presenting: UIViewController?, stickTo edge: PresentationEdge, modal: Bool = true, tapAnywhereToDismiss: Bool = false, modalBackgroundColor bgColor: UIColor? = nil) {
self.stickTo = edge
self.isModal = modal
super.init(presentedViewController: presented, presenting: presenting)
bg.backgroundColor = bgColor ?? .init(white: 0, alpha: 0.5)
if modal, tapAnywhereToDismiss {
bg.addGestureRecognizer(
UITapGestureRecognizer(target: self, action: #selector(didTapBackground))
)
}
}
// MARK: Present
override func presentationTransitionWillBegin() {
availableSize = containerView!.frame.size
guard isModal else { return }
containerView!.insertSubview(bg, at: 0)
bg.alpha = 0.0
if presentedViewController.transitionCoordinator?.animate(alongsideTransition: { _ in
self.bg.alpha = 1.0
}) != true { bg.alpha = 1.0 }
}
@objc func didTapBackground(_ sender: UITapGestureRecognizer) {
presentingViewController.dismiss(animated: true)
}
// MARK: Dismiss
override func dismissalTransitionWillBegin() {
if presentedViewController.transitionCoordinator?.animate(alongsideTransition: { _ in
self.bg.alpha = 0.0
}) != true { bg.alpha = 0.0 }
}
override func dismissalTransitionDidEnd(_ completed: Bool) {
if completed { bg.removeFromSuperview() }
}
// MARK: Update
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
availableSize = size
super.viewWillTransition(to: size, with: coordinator)
}
override func containerViewDidLayoutSubviews() {
super.containerViewDidLayoutSubviews()
bg.frame = containerView!.bounds
if isModal {
presentedView!.frame = fittedContentFrame()
} else {
containerView!.frame = fittedContentFrame()
presentedView!.frame = containerView!.bounds
}
}
/// Calculate `fittedContentSize()` then offset frame to sticky edge respecting *available* container size .
func fittedContentFrame() -> CGRect {
var frame = CGRect(origin: .zero, size: fittedContentSize())
switch stickTo {
case .right: frame.origin.x = availableSize.width - frame.width
case .bottom: frame.origin.y = availableSize.height - frame.height
default: break
}
return frame
}
/// Calculate best fitting size for available container size and presentation sticky edge.
func fittedContentSize() -> CGSize {
guard let target = presentedView else { return availableSize }
let full = availableSize
let preferred = presentedViewController.preferredContentSize
switch stickTo {
case .left, .right:
let fitted = target.fittingSize(fixedHeight: full.height, preferredWidth: preferred.width)
return CGSize(width: min(fitted.width, full.width), height: full.height)
case .top, .bottom:
let fitted = target.fittingSize(fixedWidth: full.width, preferredHeight: preferred.height)
return CGSize(width: full.width, height: min(fitted.height, full.height))
}
}
}

View File

@@ -0,0 +1,31 @@
import Foundation
class ThrottledBatchQueue<T> {
private var cache: [T] = []
private var scheduled: Bool = false
private let queue: DispatchQueue
private let delay: Double
init(_ delay: Double, using queue: DispatchQueue) {
self.queue = queue
self.delay = delay
}
func addDelayed(_ elem: T, afterDelay closure: @escaping ([T]) -> Void) {
queue.sync {
cache.append(elem)
guard !scheduled else {
return
}
scheduled = true
queue.asyncAfter(deadline: .now() + delay) {
let aCopy = self.cache
self.cache.removeAll(keepingCapacity: true)
self.scheduled = false
DispatchQueue.main.async {
closure(aCopy)
}
}
}
}
}

View File

@@ -0,0 +1,203 @@
import UIKit
fileprivate var margin: CGFloat { 20 }
fileprivate var sheetInset: CGFloat { cornerRadius/2 }
fileprivate var cornerRadius: CGFloat { 15 }
fileprivate var uniRect: CGRect { CGRect(x: 0, y: 0, width: 500, height: 500) }
class TutorialSheet: UIViewController, UIScrollViewDelegate {
/// Maximum displayable width of a Tutorial Sheet in portrait mode.
public static var verticalWidth: CGFloat {
let s = UIScreen.main.bounds.size
return min(s.width, s.height) - 2 * (margin + sheetInset)
}
public var buttonTitleNext: String = "Next"
public var buttonTitleDone: String = "Close"
private var priorIndex: Int?
private var lastAnchor: NSLayoutConstraint?
private var shouldAnimate: Bool = true
private var shouldCloseBlock: (() -> Bool)? = nil
private var didCloseBlock: (() -> Void)? = nil
private let sheetBg: UIView = {
let x = UIView(frame: uniRect)
x.autoresizingMask = [.flexibleWidth, .flexibleHeight]
x.backgroundColor = .sysBackground
x.layer.cornerRadius = cornerRadius
x.layer.shadowColor = UIColor.black.cgColor
x.layer.shadowRadius = 10
x.layer.shadowOpacity = 0.75
x.layer.shadowOffset = CGSize(width: 0, height: 4)
return x
}()
private let pager: UIPageControl = {
let x = UIPageControl(frame: uniRect)
x.frame.size.height = x.size(forNumberOfPages: 1).height
x.currentPageIndicatorTintColor = UIColor.sysLabel.withAlphaComponent(0.5)
x.pageIndicatorTintColor = UIColor.sysLabel.withAlphaComponent(0.25)
x.numberOfPages = 0
x.hidesForSinglePage = true
x.addTarget(self, action: #selector(pagerDidChange), for: .valueChanged)
return x
}()
private let pageScroll: UIScrollView = {
let x = UIScrollView(frame: uniRect)
x.bounces = false
x.isPagingEnabled = true
x.showsVerticalScrollIndicator = false
x.showsHorizontalScrollIndicator = false
let content = UIView()
x.addSubview(content)
content.anchor([.left, .right, .top, .bottom], to: x)
content.anchor([.width, .height], to: x) | .defaultLow
return x
}()
private let button: UIButton = {
let x = QuickUI.button("", target: self, action: #selector(buttonTapped))
x.contentEdgeInsets = UIEdgeInsets(all: 8)
return x
}()
// MARK: Init
required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") }
required init() {
super.init(nibName: nil, bundle: nil)
view = makeControlUI()
modalPresentationStyle = .custom
if #available(iOS 13.0, *) {
isModalInPresentation = true
}
UIDevice.orientationDidChangeNotification.observe(call: #selector(didChangeOrientation), on: self)
}
/// Present Tutorial Sheet Controller
/// - Parameter viewController: If set to `nil`, use main application as canvas. (Default: `nil`)
/// - Parameter animate: Use `present` and `dismiss` animations. (Default: `true`)
/// - Parameter shouldClose: Called before the view controller is dismissed. Return `false` to prevent the dismissal.
/// Use this block to extract user data from input fields. (Default: `nil`)
/// - Parameter didClose: Called after the view controller is completely dismissed (with animations).
/// Use this block to update UI and visible changes. (Default: `nil`)
func present(in viewController: UIViewController? = nil, animate: Bool = true, shouldClose: (() -> Bool)? = nil, didClose: (() -> Void)? = nil) {
guard let vc = viewController ?? UIApplication.shared.keyWindow?.rootViewController else {
return
}
shouldCloseBlock = shouldClose
didCloseBlock = didClose
shouldAnimate = animate
vc.present(self, animated: animate)
}
// MARK: Dynamic UI
@discardableResult func addSheet(_ closure: ((UIStackView) -> Void)? = nil) -> UIStackView {
pager.numberOfPages += 1
updateButtonTitle()
let x = UIStackView(frame: pageScroll.bounds)
x.axis = .vertical
x.backgroundColor = UIColor.black
x.isOpaque = true
guard let content = pageScroll.subviews.first else {
return x
}
let prev = content.subviews.last
content.addSubview(x)
x.anchor([.top, .height], to: pageScroll)
x.widthAnchor =&= sheetBg.widthAnchor - 2 * sheetInset
x.leadingAnchor =&= (prev==nil ? content.leadingAnchor : prev!.trailingAnchor)
lastAnchor?.isActive = false
lastAnchor = (x.trailingAnchor =&= pageScroll.trailingAnchor)
closure?(x)
return x
}
// MARK: Static UI
private func makeControlUI() -> UIView {
pageScroll.delegate = self
sheetBg.addSubview(pager)
sheetBg.addSubview(pageScroll)
sheetBg.addSubview(button)
pager.anchor([.top, .left, .right], to: sheetBg)
pageScroll.topAnchor =&= pager.bottomAnchor
pageScroll.anchor([.left, .right, .top, .bottom], to: sheetBg, margin: sheetInset) | .defaultHigh
button.topAnchor =&= pageScroll.bottomAnchor
button.anchor([.bottom, .centerX], to: sheetBg)
// button.bottomAnchor =&= sheetBg.bottomAnchor - 30
// button.centerXAnchor =&= sheetBg.centerXAnchor
let bg = UIView(frame: uniRect)
bg.autoresizingMask = [.flexibleWidth, .flexibleHeight]
bg.addSubview(sheetBg)
let h: CGFloat = UIApplication.shared.isStatusBarHidden ? 0 : UIApplication.shared.statusBarFrame.height
sheetBg.frame = bg.frame.inset(by: UIEdgeInsets(all: margin, top: margin + h))
return bg
}
// MARK: Delegates
override func viewWillLayoutSubviews() {
priorIndex = pager.currentPage
}
@objc private func didChangeOrientation() {
if let i = priorIndex {
priorIndex = nil
switchToSheet(i, animated: false)
}
for case let x as UIStackView in pageScroll.subviews.first!.subviews {
x.axis = (x.frame.width > x.frame.height) ? .horizontal : .vertical
}
}
func scrollViewDidScroll(_ scrollView: UIScrollView) {
let w = scrollView.frame.width
let new = Int((scrollView.contentOffset.x + w/2) / w)
if pager.currentPage != new {
pager.currentPage = new
updateButtonTitle()
}
}
@objc private func pagerDidChange(sender: UIPageControl) {
switchToSheet(sender.currentPage, animated: true)
}
private func switchToSheet(_ i: Int, animated: Bool) {
pageScroll.setContentOffset(CGPoint(x: CGFloat(i) * pageScroll.bounds.width, y: 0), animated: animated)
}
private func updateButtonTitle() {
let last = (pager.currentPage == pager.numberOfPages - 1)
let title = last ? buttonTitleDone : buttonTitleNext
if button.title(for: .normal) != title {
button.setTitle(title, for: .normal)
}
}
@objc private func buttonTapped() {
let next = pager.currentPage + 1
if next < pager.numberOfPages {
switchToSheet(next, animated: true)
} else {
if shouldCloseBlock?() ?? true {
dismiss(animated: shouldAnimate, completion: didCloseBlock)
}
}
}
}

495
main/DB/DBAppOnly.swift Normal file
View File

@@ -0,0 +1,495 @@
import Foundation
import SQLite3
typealias Timestamp = sqlite3_int64
extension SQLiteDatabase {
func initAppOnlyScheme() {
try? run(sql: CreateTable.heap)
try? run(sql: CreateTable.rec)
try? run(sql: CreateTable.recLog)
do {
try migrateDB()
} catch {
QLog.Error("during migration: \(error)")
}
}
func migrateDB() throws {
let version = try run(sql: "PRAGMA user_version;") { stmt -> Int32 in
try ifStep(stmt, SQLITE_ROW)
return sqlite3_column_int(stmt, 0)
}
if version != 1 {
// version 0 -> 1: req(domain) -> heap(fqdn, domain)
if version == 0 {
try tempMigrate()
}
try run(sql: "PRAGMA user_version = 1;")
}
}
private func tempMigrate() throws { // TODO: remove with next internal release
do {
try run(sql: "SELECT 1 FROM req LIMIT 1;") // fails if req doesnt exist
createFunction("domainof") { ($0.first as! String).extractDomain() }
transaction("""
INSERT INTO heap(ts,fqdn,domain,opt) SELECT ts,domain,domainof(domain),nullif(logOpt,0) FROM req;
DROP TABLE req;
""")
} catch { /* no need to migrate */ }
}
}
private enum TableName: String {
case heap, cache
}
extension SQLiteDatabase {
fileprivate func lastRowId(_ table: TableName) -> SQLiteRowID {
(try? run(sql:"SELECT rowid FROM \(table.rawValue) ORDER BY rowid DESC LIMIT 1;") {
try ifStep($0, SQLITE_ROW)
return sqlite3_column_int64($0, 0)
}) ?? 0
}
fileprivate func col_ts(_ stmt: OpaquePointer, _ col: Int32) -> Timestamp {
sqlite3_column_int64(stmt, col)
}
}
class WhereClauseBuilder: CustomStringConvertible {
var description: String = ""
private let prefix: String
private(set) var bindings: [DBBinding] = []
init(prefix p: String = "WHERE") { prefix = "\(p) " }
/// Append new clause by either prepending `WHERE` prefix or placing `AND` between clauses.
@discardableResult func and(_ clause: String, _ bind: DBBinding ...) -> Self {
description.append((description=="" ? prefix : " AND ") + clause)
bindings.append(contentsOf: bind)
return self
}
/// Restrict to `rowid >= {range}.start AND rowid <= {range}.end`.
/// Omitted if range is `nil` or individually if a value is `0`.
@discardableResult func and(in range: SQLiteRowRange) -> Self {
if range.start != 0 { and("rowid >= ?", BindInt64(range.start)) }
if range.end != 0 { and("rowid <= ?", BindInt64(range.end)) }
return self
}
/// Restrict to `ts >= {min} AND ts < {max}`. Omit one or the other if value is `0`.
@discardableResult func and(min: Timestamp = 0, max: Timestamp = 0) -> Self {
if min != 0 { and("ts >= ?", BindInt64(min)) }
if max != 0 { and("ts < ?", BindInt64(max)) }
return self
}
}
// MARK: - DNSLog
extension CreateTable {
/// `ts`: Timestamp, `fqdn`: String, `domain`: String, `opt`: Int
static var heap: String {"""
CREATE TABLE IF NOT EXISTS heap(
ts INTEGER DEFAULT (strftime('%s','now')),
fqdn TEXT NOT NULL,
domain TEXT NOT NULL,
opt INTEGER
);
"""} // opt currently only used as "blocked" flag
}
struct GroupedDomain {
let domain: String, total: Int32, blocked: Int32, lastModified: Timestamp
var options: FilterOptions? = nil
}
typealias GroupedTsOccurrence = (ts: Timestamp, total: Int32, blocked: Int32)
typealias DomainTsPair = (domain: String, ts: Timestamp)
extension SQLiteDatabase {
// MARK: write
/// Move newest entries from `cache` to `heap` and return range (in `heap`) of newly inserted entries.
/// - Returns: `nil` in case no entries were transmitted.
@discardableResult func dnsLogsPersist() -> SQLiteRowRange? {
guard lastRowId(.cache) > 0 else { return nil }
transaction("ALTER TABLE cache RENAME TO tmp_cache; \(CreateTable.cache)")
let before = lastRowId(.heap) + 1
createFunction("domainof") { ($0.first as! String).extractDomain() }
transaction("""
INSERT INTO heap(ts,fqdn,domain,opt) SELECT ts,dns,domainof(dns),nullif(opt&1,0) FROM tmp_cache;
DROP TABLE tmp_cache;
""")
let after = lastRowId(.heap)
return (before > after) ? nil : (before, after)
}
/// `DELETE FROM cache; DELETE FROM heap;`
func dnsLogsDeleteAll() throws {
try? run(sql: "DELETE FROM cache; DELETE FROM heap;")
vacuum()
}
/// Delete rows matching `ts >= ? AND domain = ?`
/// - Parameter strict: If `true`, use `fqdn` instead of `domain` column
/// - Returns: Number of changes aka. Number of rows deleted
@discardableResult func dnsLogsDelete(_ domain: String, strict: Bool, since ts: Timestamp = 0) -> Int32 {
let Where = WhereClauseBuilder().and(min: ts)
Where.and("\(strict ? "fqdn" : "domain") = ?", BindText(domain)) // (fqdn = ? OR fqdn LIKE '%.' || ?)
return (try? run(sql: "DELETE FROM heap \(Where);", bind: Where.bindings) { stmt -> Int32 in
try ifStep(stmt, SQLITE_DONE)
return numberOfChanges
}) ?? 0
}
// MARK: read
/// `SELECT min(ts) FROM heap`
func dnsLogsMinDate() -> Timestamp? {
try? run(sql:"SELECT min(ts) FROM heap") {
try ifStep($0, SQLITE_ROW)
return col_ts($0, 0)
}
}
/// Select min and max row id with given condition `ts >= ? AND ts < ?`
/// - Parameters:
/// - ts1: Restrict min `rowid` to `ts >= ?`. Pass `0` to omit restriction.
/// - ts2: Restrict max `rowid` to `ts < ?`. Pass `0` to omit restriction.
/// - range: If set, only look at the specified range. Default: `(0,0)`
/// - Returns: `nil` in case no rows are matching the condition
func dnsLogsRowRange(between ts1: Timestamp, and ts2: Timestamp, within range: SQLiteRowRange = (0,0)) -> SQLiteRowRange? {
let Where = WhereClauseBuilder().and(in: range).and(min: ts1, max: ts2)
return try? run(sql:"SELECT min(rowid), max(rowid) FROM heap \(Where);", bind: Where.bindings) {
try ifStep($0, SQLITE_ROW)
let max = col_ts($0, 1)
return (max == 0) ? nil : (col_ts($0, 0), max)
}
}
/// Get raw logs between two timestamps. `ts >= ? AND ts <= ?`
/// - Returns: List sorted by `ts` in descending order (newest entries first).
func dnsLogs(between ts1: Timestamp, and ts2: Timestamp) -> [DomainTsPair]? {
try? run(sql: "SELECT fqdn, ts FROM heap WHERE ts >= ? AND ts <= ? ORDER BY ts DESC, rowid ASC;",
bind: [BindInt64(ts1), BindInt64(ts2)]) {
allRows($0) {
(col_text($0, 0) ?? "", col_ts($0, 1))
}
}
}
/// Group DNS logs by domain, count occurences and number of blocked requests.
/// - Parameters:
/// - range: Whenever possible set range to improve SQL lookup times. `start <= rowid <= end `
/// - matchingDomain: Restrict `(fqdn|domain) = ?`. Which column is used is determined by `parentDomain`.
/// - parentDomain: If `nil` returns `domain` column. Else returns `fqdn` column with restriction on `domain == parentDomain`.
/// - Returns: List of grouped domains with no particular sorting order.
func dnsLogsGrouped(range: SQLiteRowRange, matchingDomain: String? = nil, parentDomain: String? = nil) -> [GroupedDomain]? {
let Where = WhereClauseBuilder().and(in: range)
let col: String // fqdn or domain
if let parent = parentDomain { // is subdomain
col = "fqdn"
Where.and("domain = ?", BindText(parent))
} else {
col = "domain"
}
if let matching = matchingDomain { // (fqdn = ? OR fqdn LIKE '%.' || ?)
Where.and("\(col) = ?", BindText(matching))
}
return try? run(sql: "SELECT \(col), COUNT(*), COUNT(opt), MAX(ts) FROM heap \(Where) GROUP BY \(col);", bind: Where.bindings) {
allRows($0) {
GroupedDomain(domain: col_text($0, 0) ?? "",
total: sqlite3_column_int($0, 1),
blocked: sqlite3_column_int($0, 2),
lastModified: col_ts($0, 3))
}
}
}
/// Get list or individual DNS entries. Mutliple entries in the very same second are grouped.
/// - Parameters:
/// - fqdn: Exact match for domain name `fqdn = ?`
/// - range: Whenever possible set range to improve SQL lookup times. `start <= rowid <= end `
/// - Returns: List sorted by reverse timestamp order (newest first)
func timesForDomain(_ fqdn: String, range: SQLiteRowRange) -> [GroupedTsOccurrence]? {
let Where = WhereClauseBuilder().and(in: range).and("fqdn = ?", BindText(fqdn))
return try? run(sql: "SELECT ts, COUNT(ts), COUNT(opt) FROM heap \(Where) GROUP BY ts ORDER BY ts DESC;", bind: Where.bindings) {
allRows($0) {
(col_ts($0, 0), sqlite3_column_int($0, 1), sqlite3_column_int($0, 2))
}
}
}
}
// MARK: - Context Analysis
typealias ContextAnalysisResult = (domain: String, count: Int32, avg: Double, rank: Double)
extension SQLiteDatabase {
/// Number of times how often given `fqdn` appears in the database
func dnsLogsCount(fqdn: String) -> Int? {
try? run(sql: "SELECT COUNT(*) FROM heap WHERE fqdn = ?;", bind: [BindText(fqdn)]) {
try ifStep($0, SQLITE_ROW)
return Int(sqlite3_column_int($0, 0))
}
}
/// Get sorted, unique list of `ts` with given `fqdn`.
func dnsLogsUniqTs(_ domain: String, isFQDN flag: Bool) -> [Timestamp]? {
try? run(sql: "SELECT DISTINCT ts FROM heap WHERE \(flag ? "fqdn" : "domain") = ? ORDER BY ts;",
bind: [BindText(domain)]) {
allRows($0) { col_ts($0, 0) }
}
}
/// Find other domains occurring regularly at roughly the same time as `fqdn`.
/// - Warning: `times` list must be **sorted** by time in ascending order.
/// - Parameters:
/// - times: List of `ts` from `dnsLogsUniqTs(fqdn)`
/// - dt: Search for `ts - dt <= X <= ts + dt`
/// - fqdn: Rows matching this domain will be excluded from the result set.
/// - Returns: List of tuples ordered by rank (ASC).
func contextAnalysis(coOccurrence times: [Timestamp], plusMinus dt: Timestamp, exclude domain: String, isFQDN flag: Bool) -> [ContextAnalysisResult]? {
guard times.count > 0 else { return nil }
createFunction("fnDist") {
let x = $0.first as! Timestamp
let i = times.binTreeIndex(of: x, compare: <)!
let dist: Timestamp
switch i {
case 0: dist = times[0] - x
case times.count: dist = x - times[i-1]
default: dist = min(times[i] - x, x - times[i-1])
}
return dist
}
// `avg ^ 2`: prefer results that are closer to `times`
// `_ / count`: prefer results with higher occurrence count
// `time / 2`: Weighting factor (low: prefer close, high: prefer count)
// `time` helpful esp. for smaller spans. `avg^2` will raise faster anyway.
let fnRank = "(avg * avg + (? / 2.0) + 1) / count" // +1 in case time == 0 -> avg^2 == 0
// improve query by excluding entries that are: before the first, or after the last ts
let low = times.first! - dt
let high = times.last! + dt
return try? run(sql: """
SELECT fqdn, count, avg, (\(fnRank)) rank FROM (
SELECT fqdn, COUNT(*) count, AVG(dist) avg FROM (
SELECT fqdn, fnDist(ts) dist FROM heap
WHERE ts BETWEEN ? AND ? AND \(flag ? "fqdn" : "domain") != ? AND dist <= ?
) GROUP BY fqdn
) ORDER BY rank ASC LIMIT 99;
""", bind: [BindInt64(dt), BindInt64(low), BindInt64(high), BindText(domain), BindInt64(dt)]) {
allRows($0) {
(col_text($0, 0) ?? "", sqlite3_column_int($0, 1), sqlite3_column_double($0, 2), sqlite3_column_double($0, 3))
}
}
}
}
// MARK: - Recordings
extension CreateTable {
/// `id`: Primary, `start`: Timestamp, `stop`: Timestamp, `appid`: String, `title`: String, `notes`: String
static var rec: String {"""
CREATE TABLE IF NOT EXISTS rec(
id INTEGER PRIMARY KEY,
start INTEGER DEFAULT (strftime('%s','now')),
stop INTEGER,
appid TEXT,
title TEXT,
notes TEXT
);
"""}
}
struct Recording {
let id: sqlite3_int64
let start: Timestamp
let stop: Timestamp?
var appId: String? = nil
var title: String? = nil
var notes: String? = nil
}
extension SQLiteDatabase {
// MARK: write
/// Create new recording with `stop` set to `NULL`.
func recordingStartNew() throws -> Recording {
try run(sql: "INSERT INTO rec (stop) VALUES (NULL);") { stmt -> Recording in
try ifStep(stmt, SQLITE_DONE)
return try recordingGet(withID: lastInsertedRow)
}
}
/// Update given recording by setting `stop` to current time.
func recordingStop(_ r: inout Recording) {
guard r.stop == nil else { return }
let theID = r.id
try? run(sql: "UPDATE rec SET stop = (strftime('%s','now')) WHERE id = ? LIMIT 1;",
bind: [BindInt64(theID)]) { stmt -> Void in
try ifStep(stmt, SQLITE_DONE)
r = try recordingGet(withID: theID)
}
}
/// Update given recording by replacing `title`, `appid`, and `notes` with new values.
func recordingUpdate(_ r: Recording) {
try? run(sql: "UPDATE rec SET title = ?, appid = ?, notes = ? WHERE id = ? LIMIT 1;",
bind: [BindTextOrNil(r.title), BindTextOrNil(r.appId), BindTextOrNil(r.notes), BindInt64(r.id)]) { stmt -> Void in
sqlite3_step(stmt)
}
}
/// Delete recording and all of its entries.
/// - Returns: `true` on success
func recordingDelete(_ r: Recording) throws -> Bool {
_ = try? recordingLogsDelete(r.id)
return try run(sql: "DELETE FROM rec WHERE id = ? LIMIT 1;", bind: [BindInt64(r.id)]) {
try ifStep($0, SQLITE_DONE)
return numberOfChanges > 0
}
}
// MARK: read
private func readRecording(_ stmt: OpaquePointer) -> Recording {
let end = col_ts(stmt, 2)
return Recording(id: sqlite3_column_int64(stmt, 0),
start: col_ts(stmt, 1),
stop: end == 0 ? nil : end,
appId: col_text(stmt, 3),
title: col_text(stmt, 4),
notes: col_text(stmt, 5))
}
/// `WHERE stop IS NULL`
func recordingGetOngoing() -> Recording? {
try? run(sql: "SELECT * FROM rec WHERE stop IS NULL LIMIT 1;") {
try ifStep($0, SQLITE_ROW)
return readRecording($0)
}
}
/// Get `Timestamp` of last recording.
func recordingLastTimestamp() -> Timestamp? {
try? run(sql: "SELECT stop FROM rec WHERE stop IS NOT NULL ORDER BY rowid DESC LIMIT 1;") {
try ifStep($0, SQLITE_ROW)
return col_ts($0, 0)
}
}
/// `WHERE stop IS NOT NULL`
func recordingGetAll() -> [Recording]? {
try? run(sql: "SELECT * FROM rec WHERE stop IS NOT NULL;") {
allRows($0) { readRecording($0) }
}
}
/// `WHERE id = ?`
private func recordingGet(withID: sqlite3_int64) throws -> Recording {
try run(sql: "SELECT * FROM rec WHERE id = ? LIMIT 1;", bind: [BindInt64(withID)]) {
try ifStep($0, SQLITE_ROW)
return readRecording($0)
}
}
}
// MARK: - RecordingLog
extension CreateTable {
/// `rid`: Reference `rec(id)`, `ts`: Timestamp, `domain`: String
static var recLog: String {"""
CREATE TABLE IF NOT EXISTS recLog(
rid INTEGER REFERENCES rec(id) ON DELETE CASCADE,
ts INTEGER,
domain TEXT
);
"""}
}
extension SQLiteDatabase {
// MARK: write
/// Duplicate and copy all log entries for given recording to `recLog` table
func recordingLogsPersist(_ r: Recording) {
guard let end = r.stop else { return }
// TODO: make sure cache entries get copied too.
// either by copying them directly from cache or perform sync first
try? run(sql: """
INSERT INTO recLog (rid, ts, domain) SELECT ?, ts, fqdn FROM heap
WHERE heap.ts >= ? AND heap.ts <= ?
""", bind: [BindInt64(r.id), BindInt64(r.start), BindInt64(end)]) {
try ifStep($0, SQLITE_DONE)
}
}
/// Delete all log entries with given recording id. Optional: only delete entries for a single domain
/// - Parameter d: If `nil` remove all entries for given recording
/// - Returns: Number of deleted rows
func recordingLogsDelete(_ recId: sqlite3_int64, matchingDomain d: String? = nil) throws -> Int32 {
try run(sql: "DELETE FROM recLog WHERE rid = ? \(d==nil ? "" : "AND domain = ?");",
bind: [BindInt64(recId), d==nil ? nil : BindText(d!)]) {
try ifStep($0, SQLITE_DONE)
return numberOfChanges
}
}
/// Delete one recording log entry with given `recording id`, matching `domain`, and `ts`.
/// - Returns: `true` if row was deleted
func recordingLogsDelete(_ recId: sqlite3_int64, singleEntry ts: Timestamp, domain: String) throws -> Bool {
try run(sql: "DELETE FROM recLog WHERE rid = ? AND ts = ? AND domain = ? LIMIT 1;",
bind: [BindInt64(recId), BindInt64(ts), BindText(domain)]) {
try ifStep($0, SQLITE_DONE)
return numberOfChanges > 0
}
}
// MARK: read
/// List of domains and count occurences for given recording.
/// - Returns: List of `(domain, ts)` pairs. Sorted by `ts` in ascending order (oldest first)
func recordingLogsGet(_ r: Recording) -> [DomainTsPair]? {
try? run(sql: "SELECT domain, ts FROM recLog WHERE rid = ? ORDER BY ts ASC, rowid DESC;",
bind: [BindInt64(r.id)]) {
allRows($0) { (col_text($0, 0) ?? "", col_ts($0, 1)) }
}
}
}
// MARK: - DBSettings
//extension CreateTable {
// static var settings: String {
// "CREATE TABLE IF NOT EXISTS settings(key TEXT UNIQUE NOT NULL, val TEXT);"
// }
//}
//
//extension SQLiteDatabase {
// func getSetting(for key: String) -> String? {
// try? run(sql: "SELECT val FROM settings WHERE key = ?;",
// bind: [BindText(key)]) { readText($0, 0) }
// }
// func setSetting(_ value: String?, for key: String) {
// if let value = value {
// try? run(sql: "INSERT OR REPLACE INTO settings (key, val) VALUES (?, ?);",
// bind: [BindText(value), BindText(key)]) { step($0) }
// } else {
// try? run(sql: "DELETE FROM settings WHERE key = ?;",
// bind: [BindText(key)]) { step($0) }
// }
// }
//}

108
main/DB/DBCommon.swift Normal file
View File

@@ -0,0 +1,108 @@
import Foundation
import SQLite3
enum CreateTable {} // used for CREATE TABLE statements
extension SQLiteDatabase {
func initCommonScheme() {
try? run(sql: CreateTable.cache)
try? run(sql: CreateTable.filter)
}
}
// MARK: - transit
extension CreateTable {
/// `ts`: Timestamp, `dns`: String, `opt`: Int
static var cache: String {"""
CREATE TABLE IF NOT EXISTS cache(
ts INTEGER DEFAULT (strftime('%s','now')),
dns TEXT NOT NULL,
opt INTEGER
);
"""}
}
extension SQLiteDatabase {
// /// `INSERT INTO cache (dns, opt) VALUES (?, ?);`
// func logWritePrepare() throws -> OpaquePointer {
// try prepare(sql: "INSERT INTO cache (dns, opt) VALUES (?, ?);")
// }
// /// `prep` must exist and be initialized with `logWritePrepare()`
// func logWrite(_ pStmt: OpaquePointer!, _ domain: String, blocked: Bool = false) throws {
// guard let prep = pStmt else {
// return
// }
// try prepared(run: prep, bind: [BindText(domain), BindInt32(blocked ? 1 : 0)])
// }
/// `INSERT INTO cache (dns, opt) VALUES (?, ?);`
func logWrite(_ domain: String, blocked: Bool = false) throws {
try self.run(sql: "INSERT INTO cache (dns, opt) VALUES (?, ?);",
bind: [BindText(domain), BindInt32(blocked ? 1 : 0)])
{ try ifStep($0, SQLITE_DONE) }
}
/// `DELETE FROM cache WHERE ts < (now - ? days);`
/// - Parameter days: if `0` or negative, this function does nothing.
/// - Returns: `true` if at least one row was deleted.
@discardableResult func dnsLogsDeleteOlderThan(days: Int) throws -> Bool {
guard days > 0 else { return false }
return try self.run(sql: "DELETE FROM cache WHERE ts < strftime('%s', 'now', ?);",
bind: [BindText("-\(days) days")]) {
try ifStep($0, SQLITE_DONE)
return numberOfChanges > 0
}
}
}
// MARK: - filter
extension CreateTable {
/// `domain`: String, `opt`: Int
static var filter: String {"""
CREATE TABLE IF NOT EXISTS filter(
domain TEXT UNIQUE NOT NULL,
opt INTEGER
);
"""}
}
struct FilterOptions: OptionSet {
let rawValue: Int32
static let none = FilterOptions([])
static let blocked = FilterOptions(rawValue: 1 << 0)
static let ignored = FilterOptions(rawValue: 1 << 1)
static let customA = FilterOptions(rawValue: 1 << 2)
static let customB = FilterOptions(rawValue: 1 << 3)
static let any = FilterOptions(rawValue: 0b1111)
}
extension SQLiteDatabase {
func loadFilters(where matching: FilterOptions? = nil) -> [String : FilterOptions]? {
let rv = matching?.rawValue ?? 0
return try? run(sql: "SELECT domain, opt FROM filter \(rv>0 ? "WHERE opt & ?" : "");",
bind: rv>0 ? [BindInt32(rv)] : []) {
allRowsKeyed($0) {
(key: col_text($0, 0) ?? "",
value: FilterOptions(rawValue: sqlite3_column_int($0, 1)))
}
}
}
func setFilter(_ domain: String, _ value: FilterOptions?) {
if let rv = value?.rawValue, rv > 0 {
try? run(sql: "INSERT OR REPLACE INTO filter (domain, opt) VALUES (?, ?);",
bind: [BindText(domain), BindInt32(rv)]) { _ = sqlite3_step($0) }
} else {
try? run(sql: "DELETE FROM filter WHERE domain = ? LIMIT 1;",
bind: [BindText(domain)]) { _ = sqlite3_step($0) }
}
}
// func loadFilterCount() -> (blocked: Int32, ignored: Int32)? {
// try? run(sql: "SELECT SUM(opt&1), SUM(opt&2)/2 FROM filter;") {
// try ifStep($0, SQLITE_ROW)
// return (sqlite3_column_int($0, 0), sqlite3_column_int($0, 1))
// }
// }
}

247
main/DB/DBCore.swift Normal file
View File

@@ -0,0 +1,247 @@
import Foundation
import SQLite3
// iOS 9.3 uses SQLite 3.8.10
enum SQLiteError: Error {
case OpenDatabase(message: String)
case Prepare(message: String)
case Step(message: String)
case Bind(message: String)
}
/// `try? SQLiteDatabase.open()`
var AppDB: SQLiteDatabase? { get { try? SQLiteDatabase.open() } }
typealias SQLiteRowID = sqlite3_int64
/// `0` indicates an unbound edge.
typealias SQLiteRowRange = (start: SQLiteRowID, end: SQLiteRowID)
// MARK: - SQLiteDatabase
class SQLiteDatabase {
fileprivate var functions = [String: [Int: Function]]()
private let dbPointer: OpaquePointer?
private init(dbPointer: OpaquePointer?) {
self.dbPointer = dbPointer
}
fileprivate var errorMessage: String {
if let errorPointer = sqlite3_errmsg(dbPointer) {
let errorMessage = String(cString: errorPointer)
return errorMessage
} else {
return "No error message provided from sqlite."
}
}
deinit {
sqlite3_close_v2(dbPointer)
}
static func destroyDatabase(path: String = URL.internalDB().relativePath) {
if FileManager.default.fileExists(atPath: path) {
do { try FileManager.default.removeItem(atPath: path) }
catch { print("Could not destroy database file: \(path)") }
}
}
static func open(path: String = URL.internalDB().relativePath) throws -> SQLiteDatabase {
var db: OpaquePointer?
if sqlite3_open_v2(path, &db, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_FULLMUTEX, nil) == SQLITE_OK {
return SQLiteDatabase(dbPointer: db)
} else {
defer { sqlite3_close_v2(db) }
if let errorPointer = sqlite3_errmsg(db) {
let message = String(cString: errorPointer)
throw SQLiteError.OpenDatabase(message: message)
} else {
throw SQLiteError.OpenDatabase(message: "No error message provided from sqlite.")
}
}
}
func run<T>(sql: String, bind: [DBBinding?] = [], step: (OpaquePointer) throws -> T) throws -> T {
// print("SQL run: \(sql)")
// for x in bind where x != nil {
// print(" -> \(x!)")
// }
var statement: OpaquePointer?
guard sqlite3_prepare_v2(dbPointer, sql, -1, &statement, nil) == SQLITE_OK,
let stmt = statement else {
throw SQLiteError.Prepare(message: errorMessage)
}
defer { sqlite3_finalize(stmt) }
var col: Int32 = 0
for b in bind.compactMap({$0}) {
col += 1
guard b.bind(stmt, col) == SQLITE_OK else {
throw SQLiteError.Bind(message: errorMessage)
}
}
return try step(stmt)
}
func run(sql: String) throws {
// print("SQL exec: \(sql)")
var err: UnsafeMutablePointer<Int8>? = nil
if sqlite3_exec(dbPointer, sql, nil, nil, &err) != SQLITE_OK {
let errMsg = (err != nil) ? String(cString: err!) : "Unknown execution error"
sqlite3_free(err);
throw SQLiteError.Step(message: errMsg)
}
}
/// `BEGIN TRANSACTION; \(sql); COMMIT;` on exception rollback.
func transaction(_ sql: String) {
do { try run(sql: "BEGIN TRANSACTION; \(sql); COMMIT;") }
catch { rollback() }
}
func ifStep(_ stmt: OpaquePointer, _ expected: Int32) throws {
guard sqlite3_step(stmt) == expected else {
throw SQLiteError.Step(message: errorMessage)
}
}
func vacuum() { NSLog("[SQL] VACUUM"); try? run(sql: "VACUUM;"); }
func rollback() { NSLog("[SQL] ROLLBACK"); try? run(sql: "ROLLBACK;"); }
}
// MARK: - Custom Functions
// let SQLITE_STATIC = unsafeBitCast(0, sqlite3_destructor_type.self)
let SQLITE_TRANSIENT = unsafeBitCast(-1, to: sqlite3_destructor_type.self)
public struct Blob {
public let bytes: [UInt8]
public init(bytes: [UInt8]) { self.bytes = bytes }
public init(bytes: UnsafeRawPointer, length: Int) {
let i8bufptr = UnsafeBufferPointer(start: bytes.assumingMemoryBound(to: UInt8.self), count: length)
self.init(bytes: [UInt8](i8bufptr))
}
}
extension SQLiteDatabase {
fileprivate typealias Function = @convention(block) (OpaquePointer?, Int32, UnsafeMutablePointer<OpaquePointer?>?) -> Void
func createFunction(_ function: String, argumentCount: UInt? = nil, deterministic: Bool = false, _ block: @escaping (_ args: [Any?]) -> Any?) {
let argc = argumentCount.map { Int($0) } ?? -1
let box: Function = { context, argc, argv in
let arguments: [Any?] = (0..<Int(argc)).map {
let value = argv![$0]
switch sqlite3_value_type(value) {
case SQLITE_BLOB: return Blob(bytes: sqlite3_value_blob(value), length: Int(sqlite3_value_bytes(value)))
case SQLITE_FLOAT: return sqlite3_value_double(value)
case SQLITE_INTEGER: return sqlite3_value_int64(value)
case SQLITE_NULL: return nil
case SQLITE_TEXT: return String(cString: UnsafePointer(sqlite3_value_text(value)))
case let type: fatalError("unsupported value type: \(type)")
}
}
let result = block(arguments)
if let r = result as? Blob { sqlite3_result_blob(context, r.bytes, Int32(r.bytes.count), nil) }
else if let r = result as? Double { sqlite3_result_double(context, r) }
else if let r = result as? Int64 { sqlite3_result_int64(context, r) }
else if let r = result as? Bool { sqlite3_result_int(context, r ? 1 : 0) }
else if let r = result as? String { sqlite3_result_text(context, r, Int32(r.count), SQLITE_TRANSIENT) }
else if result == nil { sqlite3_result_null(context) }
else { fatalError("unsupported result type: \(String(describing: result))") }
}
var flags = SQLITE_UTF8
if deterministic {
flags |= SQLITE_DETERMINISTIC
}
sqlite3_create_function_v2(dbPointer, function, Int32(argc), flags, unsafeBitCast(box, to: UnsafeMutableRawPointer.self), { context, argc, value in
let function = unsafeBitCast(sqlite3_user_data(context), to: Function.self)
function(context, argc, value)
}, nil, nil, nil)
if functions[function] == nil { functions[function] = [:] }
functions[function]?[argc] = box
}
}
// MARK: - Bindings
protocol DBBinding {
func bind(_ stmt: OpaquePointer!, _ col: Int32) -> Int32
}
struct BindInt32 : DBBinding {
let raw: Int32
init(_ value: Int32) { raw = value }
func bind(_ stmt: OpaquePointer!, _ col: Int32) -> Int32 { sqlite3_bind_int(stmt, col, raw) }
}
struct BindInt64 : DBBinding {
let raw: sqlite3_int64
init(_ value: sqlite3_int64) { raw = value }
func bind(_ stmt: OpaquePointer!, _ col: Int32) -> Int32 { sqlite3_bind_int64(stmt, col, raw) }
}
struct BindText : DBBinding {
let raw: String
init(_ value: String) { raw = value }
func bind(_ stmt: OpaquePointer!, _ col: Int32) -> Int32 { sqlite3_bind_text(stmt, col, (raw as NSString).utf8String, -1, nil) }
}
struct BindTextOrNil : DBBinding {
let raw: String?
init(_ value: String?) { raw = value }
func bind(_ stmt: OpaquePointer!, _ col: Int32) -> Int32 { sqlite3_bind_text(stmt, col, (raw == nil) ? nil : (raw! as NSString).utf8String, -1, nil) }
}
// MARK: - Easy Access func
extension SQLiteDatabase {
var numberOfChanges: Int32 { get { sqlite3_changes(dbPointer) } }
var lastInsertedRow: SQLiteRowID { get { sqlite3_last_insert_rowid(dbPointer) } }
func col_text(_ stmt: OpaquePointer, _ col: Int32) -> String? {
let val = sqlite3_column_text(stmt, col)
return (val != nil ? String(cString: val!) : nil)
}
func allRows<T>(_ stmt: OpaquePointer, _ fn: (OpaquePointer) -> T) -> [T] {
var r: [T] = []
while (sqlite3_step(stmt) == SQLITE_ROW) { r.append(fn(stmt)) }
return r
}
func allRowsKeyed<T,U>(_ stmt: OpaquePointer, _ fn: (OpaquePointer) -> (key: T, value: U)) -> [T:U] {
var r: [T:U] = [:]
while (sqlite3_step(stmt) == SQLITE_ROW) { let (k,v) = fn(stmt); r[k] = v }
return r
}
}
// MARK: - Prepared Statement
extension SQLiteDatabase {
func prepare(sql: String) throws -> OpaquePointer {
var pStmt: OpaquePointer?
guard sqlite3_prepare_v2(dbPointer, sql, -1, &pStmt, nil) == SQLITE_OK, let S = pStmt else {
sqlite3_finalize(pStmt)
throw SQLiteError.Prepare(message: errorMessage)
}
return S
}
@discardableResult func prepared(run pStmt: OpaquePointer!, bind: [DBBinding?] = []) throws -> Int32 {
defer { sqlite3_reset(pStmt) }
var col: Int32 = 0
for b in bind.compactMap({$0}) {
col += 1
guard b.bind(pStmt, col) == SQLITE_OK else {
throw SQLiteError.Bind(message: errorMessage)
}
}
return sqlite3_step(pStmt)
}
func prepared(finalize pStmt: OpaquePointer!) {
sqlite3_finalize(pStmt)
}
}

View File

@@ -0,0 +1,39 @@
import UIKit
extension GroupedDomain {
/// Return new `GroupedDomain` by adding `total` and `blocked` counts. Set `lastModified` to the maximum of the two.
static func +(a: GroupedDomain, b: GroupedDomain) -> Self {
GroupedDomain(domain: a.domain, total: a.total + b.total, blocked: a.blocked + b.blocked,
lastModified: max(a.lastModified, b.lastModified), options: a.options ?? b.options )
}
/// Return new `GroupedDomain` by subtracting `total` and `blocked` counts.
static func -(a: GroupedDomain, b: GroupedDomain) -> Self {
GroupedDomain(domain: a.domain, total: a.total - b.total, blocked: a.blocked - b.blocked,
lastModified: a.lastModified, options: a.options )
}
}
extension GroupedDomain {
var detailCellText: String { get {
return blocked > 0
? "\(DateFormat.seconds(lastModified))\(blocked)/\(total) blocked"
: "\(DateFormat.seconds(lastModified))\(total)"
}
}
}
extension FilterOptions {
func tableRowImage() -> UIImage? {
let blocked = contains(.blocked)
let ignored = contains(.ignored)
if blocked { return UIImage(named: ignored ? "block_ignore" : "shield-x") }
if ignored { return UIImage(named: "quicklook-not") }
return nil
}
}
extension Recording {
var fallbackTitle: String { get { "Unnamed Recording #\(id)" } }
var duration: Timestamp? { get { stop == nil ? nil : stop! - start } }
}

View File

@@ -1,276 +0,0 @@
import UIKit
let DBWrp = DBWrapper()
class DBWrapper {
private var latestModification: Timestamp = 0
private var dataA: [GroupedDomain] = [] // Domains
private var dataB: [[GroupedDomain]] = [] // Hosts
private var dataF: [String : FilterOptions] = [:] // Filters
private let Q = DispatchQueue(label: "de.uni-bamberg.psi.AppCheck.db-wrapper-queue", attributes: .concurrent)
// auto update rows callback
var currentlyOpenParent: String?
weak var dataA_delegate: IncrementalDataSourceUpdate?
weak var dataB_delegate: IncrementalDataSourceUpdate?
func dataB_delegate(_ parent: String) -> IncrementalDataSourceUpdate? {
(currentlyOpenParent == parent) ? dataB_delegate : nil
}
// MARK: - Data Source Getter
func listOfDomains() -> [GroupedDomain] {
Q.sync() { dataA }
}
func listOfHosts(_ parent: String) -> [GroupedDomain] {
Q.sync() { dataB[ifExist: dataA_index(of: parent)] ?? [] }
}
func dataF_list(_ filter: FilterOptions) -> [String] {
Q.sync() { dataF.compactMap { $1.contains(filter) ? $0 : nil } }
}
func dataF_counts() -> (blocked: Int, ignored: Int) {
Q.sync() { dataF.reduce((0, 0)) {
($0.0 + ($1.1.contains(.blocked) ? 1 : 0),
$0.1 + ($1.1.contains(.ignored) ? 1 : 0)) }}
}
func listOfTimes(_ domain: String?) -> [(Timestamp, Bool)] {
guard let domain = domain else { return [] }
return AppDB?.timesForDomain(domain)?.reversed() ?? []
}
// MARK: - Init
func initContentOfDB() {
DispatchQueue.global().async {
#if IOS_SIMULATOR
// self.generateTestData()
// DispatchQueue.main.async {
// // dont know why main queue is needed, wont start otherwise
// Timer.repeating(2, call: #selector(self.insertRandomEntry), on: self)
// }
#endif
self.dataF_init()
self.dataAB_init()
self.autoSyncTimer_init()
}
}
private func dataF_init() {
let list = AppDB?.loadFilters() ?? [:]
Q.async(flags: .barrier) {
self.dataF = list
NotifyFilterChanged.postAsyncMain()
}
}
private func dataAB_init() {
let list = AppDB?.domainList()
Q.async(flags: .barrier) {
self.dataA = []
self.dataB = []
self.latestModification = 0
if let allDomains = list {
for (parent, parts) in self.groupBySubdomains(allDomains) {
self.dataA.append(parent)
self.dataB.append(parts)
self.latestModification = max(parent.lastModified, self.latestModification)
}
}
NotifyLogHistoryReset.postAsyncMain()
}
}
/// Auto sync new logs every 7 seconds.
private func autoSyncTimer_init() {
Q.async() { // using Q to start timer only after init data A,B,F
DispatchQueue.main.async {
// dont know why main queue is needed, wont start otherwise
Timer.repeating(7, call: #selector(self.syncNewestLogs), on: self)
}
}
}
// MARK: - Partial Update History
@objc private func syncNewestLogs() {
QLog.Debug("\(#function)")
#if !IOS_SIMULATOR
guard currentVPNState == .on else { return }
#endif
guard let res = AppDB?.domainList(since: latestModification), res.count > 0 else {
return
}
QLog.Info("auto sync \(res.count) new logs")
Q.async(flags: .barrier) {
var c = 0
for (parent, parts) in self.groupBySubdomains(res) {
if let i = self.dataA_index(of: parent.domain) {
self.mergeExistingParts(parent.domain, at: i, newChildren: parts)
let merged = parent + self.dataA.remove(at: i)
self.dataA.insert(merged, at: c)
self.dataB.insert(self.dataB.remove(at: i), at: c)
self.dataA_delegate?.moveRow(merged, from: i, to: c)
} else {
self.dataA.insert(parent, at: c)
self.dataB.insert(parts, at: c)
self.dataA_delegate?.insertRow(parent, at: c)
}
c += 1
self.latestModification = max(parent.lastModified, self.latestModification)
}
}
}
private func mergeExistingParts(_ dom: String, at index: Int, newChildren: [GroupedDomain]) {
let tvc = dataB_delegate(dom)
var i = 0
for child in newChildren {
if let u = dataB[index].firstIndex(where: { $0.domain == child.domain }) {
let merged = child + dataB[index].remove(at: u)
dataB[index].insert(merged, at: i)
tvc?.moveRow(merged, from: u, to: i)
} else {
dataB[index].insert(child, at: i)
tvc?.insertRow(child, at: i)
}
i += 1
}
}
// MARK: - Delete History
func deleteHistory() {
DispatchQueue.global().async {
try? AppDB?.destroyContent()
AppDB?.vacuum()
self.dataAB_init()
}
}
func deleteHistory(domain: String, since ts: Timestamp) {
DispatchQueue.global().async {
let modified = (try? AppDB?.deleteRows(matching: domain, since: ts)) ?? 0
guard modified > 0 else {
return // nothing has changed
}
AppDB?.vacuum()
self.Q.async(flags: .barrier) {
guard let index = self.dataA_index(of: domain) else {
return // nothing has changed
}
let parentDom = self.dataA[index].domain
guard let list = AppDB?.domainList(matching: parentDom), list.count > 0 else {
self.dataA.remove(at: index)
self.dataB.remove(at: index)
self.dataA_delegate?.deleteRow(at: index)
self.dataB_delegate(parentDom)?.replaceData(with: [])
return // nothing left, after deleting matching rows
}
// else: incremental update, replace whole list
self.dataA[index] = list.merge(parentDom, options: self.dataF[parentDom])
self.dataA_delegate?.replaceRow(self.dataA[index], at: index)
self.dataB[index].removeAll()
for var child in list {
child.options = self.dataF[child.domain]
self.dataB[index].append(child)
}
self.dataB_delegate(parentDom)?.replaceData(with: self.dataB[index])
}
}
}
// MARK: - Partial Update Filter
func updateFilter(_ domain: String, add: FilterOptions) {
updateFilter(domain, set: (dataF[domain] ?? FilterOptions()).union(add))
}
func updateFilter(_ domain: String, remove: FilterOptions) {
updateFilter(domain, set: dataF[domain]?.subtracting(remove))
}
/// - Parameters:
/// - set: Remove a filter with `nil` or `.none`
private func updateFilter(_ domain: String, set: FilterOptions?) {
AppDB?.setFilter(domain, set)
Q.async(flags: .barrier) {
self.dataF[domain] = set
if let i = self.dataA_index(of: domain) {
if domain == self.dataA[i].domain {
self.dataA[i].options = (set == FilterOptions.none) ? nil : set
self.dataA_delegate?.replaceRow(self.dataA[i], at: i)
}
if let u = self.dataB[i].firstIndex(where: { $0.domain == domain }) {
self.dataB[i][u].options = (set == FilterOptions.none) ? nil : set
self.dataB_delegate(self.dataA[i].domain)?.replaceRow(self.dataB[i][u], at: u)
}
}
NotifyFilterChanged.postAsyncMain()
}
}
// MARK: - Helper methods
private func dataA_index(of domain: String) -> Int? {
dataA.firstIndex { domain.isSubdomain(of: $0.domain) }
}
private func groupBySubdomains(_ allDomains: [GroupedDomain]) -> [(parent: GroupedDomain, parts: [GroupedDomain])] {
var i: Int = 0
var indexOf: [String: Int] = [:]
var res: [(domain: String, list: [GroupedDomain])] = []
for var x in allDomains {
let domain = x.domain.splitDomainAndHost().domain
x.options = dataF[x.domain]
if let y = indexOf[domain] {
res[y].list.append(x)
} else {
res.append((domain, [x]))
indexOf[domain] = i
i += 1
}
}
return res.map { ($1.merge($0, options: self.dataF[$0]), $1) }
}
}
// MARK: - Test Data
extension DBWrapper {
private func generateTestData() {
guard let db = AppDB else { return }
let deleted = (try? db.deleteRows(matching: "test.com")) ?? 0
QLog.Debug("Deleting \(deleted) rows matching 'test.com'")
QLog.Debug("Writing 33 test logs")
try? db.insertDNSQuery("keeptest.com", blocked: false)
for _ in 1...4 { try? db.insertDNSQuery("test.com", blocked: false) }
for _ in 1...7 { try? db.insertDNSQuery("i.test.com", blocked: false) }
for i in 1...8 { try? db.insertDNSQuery("b.test.com", blocked: i>5) }
for i in 1...13 { try? db.insertDNSQuery("bi.test.com", blocked: i%2==0) }
QLog.Debug("Creating 4 filters")
db.setFilter("b.test.com", .blocked)
db.setFilter("i.test.com", .ignored)
db.setFilter("bi.test.com", [.blocked, .ignored])
QLog.Debug("Done")
}
@objc private func insertRandomEntry() {
QLog.Debug("Inserting 1 periodic log entry")
try? AppDB?.insertDNSQuery("\(arc4random() % 5).count.test.com", blocked: true)
}
}

View File

@@ -1,304 +0,0 @@
import Foundation
import SQLite3
typealias Timestamp = Int64
struct GroupedDomain {
let domain: String, total: Int32, blocked: Int32, lastModified: Timestamp
var options: FilterOptions? = nil
}
struct FilterOptions: OptionSet {
let rawValue: Int32
static let none = FilterOptions(rawValue: 0)
static let blocked = FilterOptions(rawValue: 1 << 0)
static let ignored = FilterOptions(rawValue: 1 << 1)
static let any = FilterOptions(rawValue: 0b11)
}
enum SQLiteError: Error {
case OpenDatabase(message: String)
case Prepare(message: String)
case Step(message: String)
case Bind(message: String)
}
// MARK: - SQLiteDatabase
var AppDB: SQLiteDatabase? { get { try? SQLiteDatabase.open() } }
class SQLiteDatabase {
private let dbPointer: OpaquePointer?
private init(dbPointer: OpaquePointer?) {
// print("SQLite path: \(basePath!.absoluteString)")
self.dbPointer = dbPointer
}
fileprivate var errorMessage: String {
if let errorPointer = sqlite3_errmsg(dbPointer) {
let errorMessage = String(cString: errorPointer)
return errorMessage
} else {
return "No error message provided from sqlite."
}
}
deinit {
sqlite3_close(dbPointer)
}
static func destroyDatabase(path: String = URL.internalDB().relativePath) {
if FileManager.default.fileExists(atPath: path) {
do { try FileManager.default.removeItem(atPath: path) }
catch { print("Could not destroy database file: \(path)") }
}
}
// static func export() throws -> URL {
// let fmt = DateFormatter()
// fmt.dateFormat = "yyyy-MM-dd"
// let dest = FileManager.default.exportDir().appendingPathComponent("\(fmt.string(from: Date()))-dns-log.sqlite")
// try? FileManager.default.removeItem(at: dest)
// try FileManager.default.copyItem(at: FileManager.default.internalDB(), to: dest)
// return dest
// }
static func open(path: String = URL.internalDB().relativePath) throws -> SQLiteDatabase {
var db: OpaquePointer?
//sqlite3_open_v2(path, &db, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_SHAREDCACHE, nil)
if sqlite3_open(path, &db) == SQLITE_OK {
return SQLiteDatabase(dbPointer: db)
} else {
defer {
if db != nil {
sqlite3_close(db)
}
}
if let errorPointer = sqlite3_errmsg(db) {
let message = String(cString: errorPointer)
throw SQLiteError.OpenDatabase(message: message)
} else {
throw SQLiteError.OpenDatabase(message: "No error message provided from sqlite.")
}
}
}
func run<T>(sql: String, bind: ((OpaquePointer) -> Bool)?, step: (OpaquePointer) throws -> T) throws -> T {
var statement: OpaquePointer?
guard sqlite3_prepare_v2(dbPointer, sql, -1, &statement, nil) == SQLITE_OK,
let stmt = statement else {
throw SQLiteError.Prepare(message: errorMessage)
}
defer { sqlite3_finalize(stmt) }
guard bind?(stmt) ?? true else {
throw SQLiteError.Bind(message: errorMessage)
}
return try step(stmt)
}
func ifStep(_ stmt: OpaquePointer, _ expected: Int32) throws {
guard sqlite3_step(stmt) == expected else {
throw SQLiteError.Step(message: errorMessage)
}
}
func createTable(table: SQLTable.Type) throws {
try run(sql: table.createStatement, bind: nil) {
try ifStep($0, SQLITE_DONE)
}
}
func vacuum() {
try? run(sql: "VACUUM;", bind: nil) { try ifStep($0, SQLITE_DONE) }
}
}
protocol SQLTable {
static var createStatement: String { get }
}
// MARK: - Easy Access func
private extension SQLiteDatabase {
func bindInt(_ stmt: OpaquePointer, _ col: Int32, _ value: Int32) -> Bool {
sqlite3_bind_int(stmt, col, value) == SQLITE_OK
}
func bindInt64(_ stmt: OpaquePointer, _ col: Int32, _ value: sqlite3_int64) -> Bool {
sqlite3_bind_int64(stmt, col, value) == SQLITE_OK
}
func bindText(_ stmt: OpaquePointer, _ col: Int32, _ value: String) -> Bool {
sqlite3_bind_text(stmt, col, (value as NSString).utf8String, -1, nil) == SQLITE_OK
}
func readText(_ stmt: OpaquePointer, _ col: Int32) -> String? {
let val = sqlite3_column_text(stmt, col)
return (val != nil ? String(cString: val!) : nil)
}
func readGroupedDomain(_ stmt: OpaquePointer) -> GroupedDomain {
GroupedDomain(domain: readText(stmt, 0) ?? "",
total: sqlite3_column_int(stmt, 1),
blocked: sqlite3_column_int(stmt, 2),
lastModified: sqlite3_column_int64(stmt, 3))
}
func allRows<T>(_ stmt: OpaquePointer, _ fn: (OpaquePointer) -> T) -> [T] {
var r: [T] = []
while (sqlite3_step(stmt) == SQLITE_ROW) { r.append(fn(stmt)) }
return r
}
func allRowsKeyed<T,U>(_ stmt: OpaquePointer, _ fn: (OpaquePointer) -> (key: T, value: U)) -> [T:U] {
var r: [T:U] = [:]
while (sqlite3_step(stmt) == SQLITE_ROW) { let (k,v) = fn(stmt); r[k] = v }
return r
}
}
extension SQLiteDatabase {
func initScheme() {
try? self.createTable(table: DNSQueryT.self)
try? self.createTable(table: DNSFilterT.self)
}
}
// MARK: - DNSQueryT
private struct DNSQueryT: SQLTable {
let ts: Timestamp
let domain: String
let wasBlocked: Bool
let options: FilterOptions
static var createStatement: String {
return """
CREATE TABLE IF NOT EXISTS req(
ts BIGINT DEFAULT (strftime('%s','now')),
domain VARCHAR(255) NOT NULL,
logOpt INT DEFAULT 0
);
"""
}
}
extension SQLiteDatabase {
// MARK: insert
func insertDNSQuery(_ domain: String, blocked: Bool) throws {
try? run(sql: "INSERT INTO req (domain, logOpt) VALUES (?, ?);", bind: {
self.bindText($0, 1, domain) && self.bindInt($0, 2, blocked ? 1 : 0)
}) {
try ifStep($0, SQLITE_DONE)
}
}
// MARK: delete
func destroyContent() throws {
try? run(sql: "DROP TABLE IF EXISTS req;", bind: nil) {
try ifStep($0, SQLITE_DONE)
}
try? createTable(table: DNSQueryT.self)
}
/// Delete rows matching `ts >= ? AND "domain" OR "*.domain"`
@discardableResult func deleteRows(matching domain: String, since ts: Timestamp = 0) throws -> Int32 {
try run(sql: "DELETE FROM req WHERE ts >= ? AND (domain = ? OR domain LIKE '%.' || ?);", bind: {
self.bindInt64($0, 1, ts) && self.bindText($0, 2, domain) && self.bindText($0, 3, domain)
}) { stmt -> Int32 in
try ifStep(stmt, SQLITE_DONE)
return sqlite3_changes(dbPointer)
}
}
// MARK: read
func domainList(since ts: Timestamp = 0) -> [GroupedDomain]? {
try? run(sql: "SELECT domain, COUNT(*), SUM(logOpt&1), MAX(ts) FROM req \(ts == 0 ? "" : "WHERE ts > ?") GROUP BY domain ORDER BY 4 DESC;", bind: {
ts == 0 || self.bindInt64($0, 1, ts)
}) {
allRows($0) { readGroupedDomain($0) }
}
}
func domainList(matching domain: String) -> [GroupedDomain]? {
try? run(sql: "SELECT domain, COUNT(*), SUM(logOpt&1), MAX(ts) FROM req WHERE (domain = ? OR domain LIKE '%.' || ?) GROUP BY domain ORDER BY 4 DESC;", bind: {
self.bindText($0, 1, domain) && self.bindText($0, 2, domain)
}) {
allRows($0) { readGroupedDomain($0) }
}
}
func timesForDomain(_ fullDomain: String) -> [(Timestamp, Bool)]? {
try? run(sql: "SELECT ts, logOpt FROM req WHERE domain = ?;", bind: {
self.bindText($0, 1, fullDomain)
}) {
allRows($0) { (sqlite3_column_int64($0, 0), sqlite3_column_int($0, 1) > 0) }
}
}
}
// MARK: - DNSFilterT
private struct DNSFilterT: SQLTable {
let domain: String
let options: FilterOptions
static var createStatement: String {
return """
CREATE TABLE IF NOT EXISTS filter(
domain VARCHAR(255) UNIQUE NOT NULL,
opt INT DEFAULT 0
);
"""
}
}
extension SQLiteDatabase {
// MARK: read
func loadFilters() -> [String : FilterOptions]? {
try? run(sql: "SELECT domain, opt FROM filter ORDER BY domain ASC;", bind: nil) {
allRowsKeyed($0) {
(key: readText($0, 0) ?? "",
value: FilterOptions(rawValue: sqlite3_column_int($0, 1)))
}
}
}
// MARK: write
func setFilter(_ domain: String, _ value: FilterOptions?) {
func removeFilter() {
try? run(sql: "DELETE FROM filter WHERE domain = ? LIMIT 1;", bind: {
self.bindText($0, 1, domain)
}) { stmt -> Void in
sqlite3_step(stmt)
}
}
guard let rv = value?.rawValue, rv > 0 else {
removeFilter()
return
}
func createFilter() throws {
try run(sql: "INSERT OR FAIL INTO filter (domain, opt) VALUES (?, ?);", bind: {
self.bindText($0, 1, domain) && self.bindInt($0, 2, rv)
}) {
try ifStep($0, SQLITE_DONE)
}
}
func updateFilter() {
try? run(sql: "UPDATE filter SET opt = ? WHERE domain = ? LIMIT 1;", bind: {
self.bindInt($0, 1, rv) && self.bindText($0, 2, domain)
}) { stmt -> Void in
sqlite3_step(stmt)
}
}
do { try createFilter() } catch { updateFilter() }
}
}

View File

@@ -0,0 +1,43 @@
import Foundation
struct TheGreatDestroyer {
/// Callback fired when user performs row edit -> delete action
static func deleteLogs(domain: String, since ts: Timestamp, strict flag: Bool) {
sync.pause()
DispatchQueue.global().async {
defer { sync.continue() }
guard let db = AppDB, db.dnsLogsDelete(domain, strict: flag, since: ts) > 0 else {
return // nothing has changed
}
db.vacuum()
sync.needsReloadDB(domain: domain)
}
}
/// Fired when user taps on Settings -> "Delete All Logs"
static func deleteAllLogs() {
sync.pause()
DispatchQueue.global().async {
defer { sync.continue() }
do {
try AppDB?.dnsLogsDeleteAll()
sync.needsReloadDB()
} catch {}
}
}
/// Fired when user changes Settings -> "Auto-delete logs" and every time the App enters foreground
static func deleteLogs(olderThan days: Int) {
guard days > 0 else { return }
sync.pause()
DispatchQueue.global().async {
defer { sync.continue() }
QLog.Info("Auto-delete logs")
guard let success = try? AppDB?.dnsLogsDeleteOlderThan(days: days), success else {
return // nothing changed
}
sync.needsReloadDB()
}
}
}

View File

@@ -0,0 +1,52 @@
import Foundation
enum DomainFilter {
static private var data = AppDB?.loadFilters() ?? [:]
/// Get filter with given `domain` name
@inline(__always) static subscript(_ domain: String) -> FilterOptions? {
data[domain]
}
/// Update local memory object by loading values from persistent db.
/// - Note: Will trigger `NotifyDNSFilterChanged` notification.
// static func reload() {
// data = AppDB?.loadFilters() ?? [:]
// NotifyDNSFilterChanged.post()
// }
/// Get list of domains (sorted by name) which do contain the given filter
static func list(where matching: FilterOptions) -> [String] {
data.compactMap { $1.contains(matching) ? $0 : nil }.sorted()
}
/// Get total number of blocked and ignored domains. Shown in settings overview.
static func counts() -> (blocked: Int, ignored: Int, listCustomA: Int, listCustomB: Int) {
data.reduce(into: (0, 0, 0, 0)) {
if $1.1.contains(.blocked) { $0.0 += 1 }
if $1.1.contains(.ignored) { $0.1 += 1 }
if $1.1.contains(.customA) { $0.2 += 1 }
if $1.1.contains(.customB) { $0.3 += 1 }
}
}
/// Union `filter` with set.
/// - Note: Will trigger `NotifyDNSFilterChanged` notification.
static func update(_ domain: String, add filter: FilterOptions) {
update(domain, set: (data[domain] ?? FilterOptions()).union(filter))
}
/// Subtract `filter` from set.
/// - Note: Will trigger `NotifyDNSFilterChanged` notification.
static func update(_ domain: String, remove filter: FilterOptions) {
update(domain, set: data[domain]?.subtracting(filter))
}
/// Update persistent db, local memory object, and post notification to subscribers
/// - Parameter set: Remove a filter with `nil` or `.none`
static private func update(_ domain: String, set: FilterOptions?) {
AppDB?.setFilter(domain, set)
data[domain] = (set == FilterOptions.none) ? nil : set
NotifyDNSFilterChanged.post(domain)
}
}

View File

@@ -0,0 +1,307 @@
import UIKit
protocol GroupedDomainDataSourceDelegate: UITableViewController {
/// Currently only called when a row is moved and the `tableView` is frontmost.
func groupedDomainDataSource(needsUpdate row: Int)
}
// ##########################
// #
// # MARK: DataSource
// #
// ##########################
class GroupedDomainDataSource: FilterPipelineDelegate, SyncUpdateDelegate {
let parent: String?
private let pipeline = FilterPipeline<GroupedDomain>()
private var currentOrder: DateFilterOrderBy = .Date
private var orderAsc = false
private(set) lazy var search = SearchBarManager { [unowned self] _ in
self.pipeline.reloadFilter(withId: "search")
}
/// Will init `sync.allowPullToRefresh()` on `tableView.refreshControl` as well.
weak var delegate: GroupedDomainDataSourceDelegate? {
willSet { if #available(iOS 10.0, *), newValue !== delegate {
sync.allowPullToRefresh(onTVC: newValue, forObserver: self)
}}}
/// - Note: Will call `tableview.reloadData()`
init(withParent: String?) {
parent = withParent
let len: Int
if let p = withParent, p.first != "#" { len = p.count } else { len = 0 }
pipeline.addFilter("search") { [unowned self] in
!self.search.isActive ||
$0.domain.prefix($0.domain.count - len).lowercased().contains(self.search.term)
}
pipeline.delegate = self
resetSortingOrder(force: true)
NotifyDNSFilterChanged.observe(call: #selector(didChangeDomainFilter), on: self)
NotifySortOrderChanged.observe(call: #selector(didChangeSortOrder), on: self)
sync.addObserver(self) // calls syncUpdate(reset:)
}
/// Callback fired when user changes date filter settings. (`NotifySortOrderChanged` notification)
@objc private func didChangeSortOrder(_ notification: Notification) {
resetSortingOrder()
}
/// Read user defaults and apply new sorting order. Either by setting a new or reversing the current.
/// - Parameter force: If `true` set new sorting even if the type does not differ.
private func resetSortingOrder(force: Bool = false) {
let orderAscChanged = (orderAsc <-? Prefs.DateFilter.OrderAsc)
let orderTypChanged = (currentOrder <-? Prefs.DateFilter.OrderBy)
if orderTypChanged || force {
switch currentOrder {
case .Date:
pipeline.setSorting { [unowned self] in
self.orderAsc ? $0.lastModified < $1.lastModified : $0.lastModified > $1.lastModified
}
case .Name:
pipeline.setSorting { [unowned self] in
self.orderAsc ? $0.domain < $1.domain : $0.domain > $1.domain
}
case .Count:
pipeline.setSorting { [unowned self] in
self.orderAsc ? $0.total < $1.total : $0.total > $1.total
}
}
} else if orderAscChanged {
pipeline.reverseSorting()
}
}
/// Callback fired when user edits list of `blocked` or `ignored` domains in settings. (`NotifyDNSFilterChanged` notification)
@objc private func didChangeDomainFilter(_ notification: Notification) {
guard let domain = notification.object as? String else {
preconditionFailure("Domain independent filter reset not implemented") // `syncUpdate(reset:)` async!
}
if let x = pipeline.dataSourceGet(where: { $0.domain == domain }) {
var obj = x.object
obj.options = DomainFilter[domain]
pipeline.update(obj, at: x.index)
}
}
// MARK: Table View Data Source
@inline(__always) var numberOfRows: Int { get { pipeline.displayObjectCount() } }
@inline(__always) subscript(_ row: Int) -> GroupedDomain { pipeline.displayObject(at: row) }
}
// ################################
// #
// # MARK: - Partial Update
// #
// ################################
extension GroupedDomainDataSource {
func syncUpdate(_: SyncUpdate, reset rows: SQLiteRowRange) {
var logs = AppDB?.dnsLogsGrouped(range: rows, parentDomain: parent) ?? []
for (i, val) in logs.enumerated() {
logs[i].options = DomainFilter[val.domain]
}
DispatchQueue.main.sync {
pipeline.reset(dataSource: logs)
}
}
func syncUpdate(_: SyncUpdate, insert rows: SQLiteRowRange, affects: SyncUpdateEnd) {
guard let latest = AppDB?.dnsLogsGrouped(range: rows, parentDomain: parent) else {
assertionFailure("NotifySyncInsert fired with empty range")
return
}
DispatchQueue.main.sync {
cellAnimationsGroup(if: latest.count > 14)
for x in latest {
if let (i, obj) = pipeline.dataSourceGet(where: { $0.domain == x.domain }) {
pipeline.update(obj + x, at: i)
} else {
var y = x
y.options = DomainFilter[x.domain]
pipeline.addNew(y)
}
}
cellAnimationsCommit()
}
}
func syncUpdate(_ sender: SyncUpdate, remove rows: SQLiteRowRange, affects: SyncUpdateEnd) {
if affects == .Latest {
// TODO: alternatively query last modified from db (last entry _before_ range)
syncUpdate(sender, reset: sender.rows)
return
}
guard let outdated = AppDB?.dnsLogsGrouped(range: rows, parentDomain: parent),
outdated.count > 0 else {
return
}
DispatchQueue.main.sync {
cellAnimationsGroup(if: outdated.count > 14)
var listOfDeletes: [Int] = []
for x in outdated {
guard let (i, obj) = pipeline.dataSourceGet(where: { $0.domain == x.domain }) else {
assertionFailure("Try to remove non-existent element")
continue // should never happen
}
if obj.total > x.total {
pipeline.update(obj - x, at: i)
} else {
listOfDeletes.append(i)
}
}
pipeline.remove(indices: listOfDeletes.sorted())
cellAnimationsCommit()
}
}
func syncUpdate(_ sender: SyncUpdate, partialRemove affectedFQDN: String) {
let affectedParent = affectedFQDN.extractDomain()
guard parent == nil || parent == affectedParent else {
return // does not affect current table
}
let affected = (parent == nil ? affectedParent : affectedFQDN)
let updated = AppDB?.dnsLogsGrouped(range: sender.rows, matchingDomain: affected, parentDomain: parent)?.first
DispatchQueue.main.sync {
guard let old = pipeline.dataSourceGet(where: { $0.domain == affected }) else {
// can only happen if delete sheet is open while background sync removed the element
return
}
if var updated = updated {
assert(old.object.domain == updated.domain)
updated.options = DomainFilter[updated.domain]
pipeline.update(updated, at: old.index)
} else {
pipeline.remove(indices: [old.index])
}
}
}
}
// #################################
// #
// # MARK: - Cell Animations
// #
// #################################
extension GroupedDomainDataSource {
/// Sets `pipeline.delegate = nil` to disable individual cell animations (update, insert, delete & move).
private func cellAnimationsGroup(if condition: Bool = true) {
if condition || delegate?.tableView.isFrontmost == false {
pipeline.delegate = nil
}
}
/// No-Op if cell animations are enabled already.
/// Else, set `pipeline.delegate = self` and perform `reloadData()`.
private func cellAnimationsCommit() {
if pipeline.delegate == nil {
pipeline.delegate = self
delegate?.tableView.reloadData()
}
}
// TODO: Collect animations and post them in a single animations block.
// This will require enormous work to translate them into a final set.
func filterPipelineDidReset() { delegate?.tableView.reloadData() }
func filterPipeline(delete rows: [Int]) { delegate?.tableView.safeDeleteRows(rows) }
func filterPipeline(insert row: Int) { delegate?.tableView.safeInsertRow(row, with: .left) }
func filterPipeline(update row: Int) {
guard let tv = delegate?.tableView else { return }
if !tv.isEditing { tv.safeReloadRow(row) }
else if tv.isFrontmost == true {
delegate?.groupedDomainDataSource(needsUpdate: row)
}
}
func filterPipeline(move oldRow: Int, to newRow: Int) {
delegate?.tableView.safeMoveRow(oldRow, to: newRow)
if delegate?.tableView.isFrontmost == true {
delegate?.groupedDomainDataSource(needsUpdate: newRow)
}
}
}
// ##########################
// #
// # MARK: - Edit Row
// #
// ##########################
protocol GroupedDomainEditRow : UIViewController, EditableRows {
var source: GroupedDomainDataSource { get }
}
extension GroupedDomainEditRow {
func editableRowActions(_ index: IndexPath) -> [(RowAction, String)] {
let x = source[index.row]
if x.domain.starts(with: "#") {
return [(.delete, "Delete")]
}
let b = x.options?.contains(.blocked) ?? false
let i = x.options?.contains(.ignored) ?? false
return [(.delete, "Delete"), (.block, b ? "Unblock" : "Block"), (.ignore, i ? "Unignore" : "Ignore")]
}
func editableRowActionColor(_: IndexPath, _ action: RowAction) -> UIColor? {
action == .block ? .systemOrange : nil
}
func editableRowUserInfo(_ index: IndexPath) -> Any? { source[index.row] }
func editableRowCallback(_ index: IndexPath, _ action: RowAction, _ userInfo: Any?) -> Bool {
let entry = userInfo as! GroupedDomain
switch action {
case .ignore: showFilterSheet(entry, .ignored)
case .block: showFilterSheet(entry, .blocked)
case .delete:
let name = entry.domain
let flag = (source.parent != nil)
AlertDeleteLogs(name, latest: entry.lastModified) {
TheGreatDestroyer.deleteLogs(domain: name, since: $0, strict: flag)
}.presentIn(self)
}
return true
}
private func showFilterSheet(_ entry: GroupedDomain, _ filter: FilterOptions) {
if entry.options?.contains(filter) ?? false {
DomainFilter.update(entry.domain, remove: filter)
} else {
// TODO: alert sheet
DomainFilter.update(entry.domain, add: filter)
}
}
}
// MARK: Extensions
extension TVCDomains : GroupedDomainEditRow {
override func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
getRowActionsIOS9(indexPath, tableView)
}
@available(iOS 11.0, *)
override func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
getRowActionsIOS11(indexPath)
}
}
extension TVCHosts : GroupedDomainEditRow {
override func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
getRowActionsIOS9(indexPath, tableView)
}
@available(iOS 11.0, *)
override func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
getRowActionsIOS11(indexPath)
}
}

View File

@@ -0,0 +1,56 @@
import Foundation
enum RecordingsDB {
/// Get last started recording (where `start` is set, but `stop` is not)
static func getCurrent() -> Recording? { AppDB?.recordingGetOngoing() }
/// Create new recording and set `start` timestamp to `now()`
static func startNew() -> Recording? { try? AppDB?.recordingStartNew() }
/// Finalize recording by setting the `stop` timestamp to `now()`
static func stop(_ r: inout Recording) { AppDB?.recordingStop(&r) }
/// Get list of all recordings
static func list() -> [Recording] { AppDB?.recordingGetAll() ?? [] }
/// Get `Timestamp` of latest recording
static func lastTimestamp() -> Timestamp? { AppDB?.recordingLastTimestamp() }
/// Copy log entries from generic `heap` table to recording specific `recLog` table
static func persist(_ r: Recording) {
sync.syncNow { // persist changes in cache before copying recording details
AppDB?.recordingLogsPersist(r)
}
}
/// Get list of domains that occured during the recording
static func details(_ r: Recording) -> [DomainTsPair] {
AppDB?.recordingLogsGet(r) ?? []
}
/// Update `title`, `appid`, and `notes` and post `NotifyRecordingChanged` notification.
static func update(_ r: Recording) {
AppDB?.recordingUpdate(r)
NotifyRecordingChanged.post((r, false))
}
/// Delete whole recording including all entries and post `NotifyRecordingChanged` notification.
static func delete(_ r: Recording) {
if (try? AppDB?.recordingDelete(r)) == true {
NotifyRecordingChanged.post((r, true))
}
}
/// Delete individual entries from recording while keeping the recording alive.
/// - Returns: `true` if at least one row is deleted.
static func deleteDetails(_ r: Recording, domain: String) -> Bool {
((try? AppDB?.recordingLogsDelete(r.id, matchingDomain: domain)) ?? 0) > 0
}
/// Delete individual entries from recording while keeping the recording alive.
/// - Returns: `true` if at least one row is deleted.
static func deleteSingle(_ r: Recording, domain: String, ts: Timestamp) -> Bool {
(try? AppDB?.recordingLogsDelete(r.id, singleEntry: ts, domain: domain)) ?? false
}
}

View File

@@ -0,0 +1,58 @@
import Foundation
#if IOS_SIMULATOR
fileprivate var hook : GlassVPNHook!
class SimulatorVPN {
static var timer: Timer?
static func load() {
QLog.Debug("SQLite path: \(URL.internalDB())")
let db = AppDB!
let deleted = db.dnsLogsDelete("test.com", strict: false)
try? db.run(sql: "DELETE FROM cache;")
QLog.Debug("Deleting \(deleted) rows matching 'test.com' (+ \(db.numberOfChanges) in cache)")
QLog.Debug("Writing 33 test logs")
try? db.logWrite("keeptest.com", blocked: false)
for _ in 1...4 { try? db.logWrite("test.com", blocked: false) }
for _ in 1...7 { try? db.logWrite("i.test.com", blocked: false) }
for i in 1...8 { try? db.logWrite("b.test.com", blocked: i>5) }
for i in 1...13 { try? db.logWrite("bi.test.com", blocked: i%2==0) }
db.dnsLogsPersist()
QLog.Debug("Creating 4 filters")
db.setFilter("b.test.com", .blocked)
db.setFilter("i.test.com", .ignored)
db.setFilter("bi.test.com", [.blocked, .ignored])
QLog.Debug("Done")
}
static func start() {
hook = GlassVPNHook()
timer = Timer.repeating(2, call: #selector(insertRandom), on: self)
}
static func stop() {
timer?.invalidate()
timer = nil
hook.cleanUp()
hook = nil
}
@objc static func insertRandom() {
//QLog.Debug("Inserting 1 periodic log entry")
let domain = "\(arc4random() % 5).count.test.com"
let kill = hook.processDNSRequest(domain)
if kill { QLog.Info("Blocked: \(domain)") }
}
static func sendMsg(_ messageData: Data) {
hook.handleAppMessage(messageData)
}
}
#endif

View File

@@ -0,0 +1,281 @@
import UIKit
let sync = SyncUpdate(periodic: 7)
class SyncUpdate {
private var lastSync: TimeInterval = 0
private var timer: Timer!
private var paused: Int = 1 // first start() will decrement
private var filterType: DateFilterKind
private var range: SQLiteRowRange? // written in reloadRangeFromDB()
/// `tsEarliest ?? 0`
private var tsMin: Timestamp { tsEarliest ?? 0 }
/// `(tsLatest + 1) ?? 0`
private var tsMax: Timestamp { (tsLatest ?? -1) + 1 }
/// Returns invalid range `(-1,-1)` if collection contains no rows
var rows: SQLiteRowRange { get { range ?? (-1,-1) } }
private(set) var tsEarliest: Timestamp? // as set per user, not actual earliest
private(set) var tsLatest: Timestamp? // as set per user, not actual latest
fileprivate init(periodic interval: TimeInterval) {
(filterType, tsEarliest, tsLatest) = Prefs.DateFilter.restrictions()
reloadRangeFromDB()
NotifyDateFilterChanged.observe(call: #selector(didChangeDateFilter), on: self)
timer = Timer.repeating(interval, call: #selector(periodicUpdate), on: self)
syncNow() // because timer will only fire after interval
}
/// Callback fired every `7` seconds.
@objc private func periodicUpdate() { if paused == 0 { syncNow() } }
/// Callback fired when user changes `DateFilter` on root tableView controller
@objc private func didChangeDateFilter() {
self.pause()
let filter = Prefs.DateFilter.restrictions()
filterType = filter.type
DispatchQueue.global().async {
// Not necessary, but improve execution order (delete then insert).
if self.tsMin <= (filter.earliest ?? 0) {
self.set(newEarliest: filter.earliest)
self.set(newLatest: filter.latest)
} else {
self.set(newLatest: filter.latest)
self.set(newEarliest: filter.earliest)
}
self.continue()
}
}
/// - Warning: Always call from a background thread!
func needsReloadDB(domain: String? = nil) {
assert(!Thread.isMainThread)
reloadRangeFromDB()
if let dom = domain {
notifyObservers { $0.syncUpdate(self, partialRemove: dom) }
} else {
notifyObservers { $0.syncUpdate(self, reset: rows) }
}
}
// MARK: - Sync Now
/// This will immediately resume timer updates, ignoring previous `pause()` requests.
func start() { paused = 0 }
/// All calls must be balanced with `continue()` calls.
/// Can be nested within other `pause-continue` pairs.
/// - Warning: An execution branch that results in unbalanced pairs will completely disable updates!
func pause() { paused += 1 }
/// Must be balanced with a `pause()` call. A `continue()` without a `pause()` is a `nop`.
/// - Note: Internally the sync timer keeps running. The `pause` will simply ignore execution during that time.
func `continue`() { if paused > 0 { paused -= 1 } }
/// Persist logs from cache and notify all observers. (`NotifySyncInsert`)
/// Determine rows of outdated entries that should be removed and notify observers as well. (`NotifySyncRemove`)
/// - Note: This method is rate limited. Sync will be performed at most once per second.
/// - Note: This method returns immediatelly. Syncing is done in a background thread.
/// - Parameter block: **Always** called on a background thread!
func syncNow(whenDone block: (() -> Void)? = nil) {
let now = Date().timeIntervalSince1970
guard (now - lastSync) > 1 else { // rate limiting
if let b = block { DispatchQueue.global().async { b() } }
return
}
lastSync = now
self.pause() // reduce concurrent load
DispatchQueue.global().async {
self.internalSync()
block?()
self.continue()
}
}
/// Called by `syncNow()`. Split to a separate func to reduce `self.` cluttering
private func internalSync() {
assert(!Thread.isMainThread)
// Always persist logs ...
if let newest = AppDB?.dnsLogsPersist() { // move cache -> heap
if filterType == .ABRange {
// ... even if we filter a few later
if let r = rows(tsMin, tsMax, scope: newest) {
notify(insert: r, .Latest)
}
} else {
notify(insert: newest, .Latest)
}
}
if filterType == .LastXMin {
set(newEarliest: Timestamp.past(minutes: Prefs.DateFilter.LastXMin))
}
// TODO: periodic hard delete old logs (will reset rowids!)
}
// MARK: - Internal
private func rows(_ ts1: Timestamp, _ ts2: Timestamp, scope: SQLiteRowRange = (0,0)) -> SQLiteRowRange? {
AppDB?.dnsLogsRowRange(between: ts1, and: ts2, within: scope)
}
private func reloadRangeFromDB() {
// `nil` is not SQLiteRowRange(0,0) aka. full collection.
// `nil` means invalid range. e.g. ts restriction too high or empty db.
range = rows(tsMin, tsMax)
}
/// Update internal `tsEarliest`, then post `NotifySyncInsert` or `NotifySyncRemove` notification with row ids.
/// - Warning: Always call from a background thread!
private func set(newEarliest: Timestamp?) {
func from(_ t: Timestamp?) -> Timestamp { t ?? 0 }
func to(_ t: Timestamp) -> Timestamp { tsLatest == nil ? t : min(t, tsMax) }
if let (old, new) = tsEarliest <-/ newEarliest {
if old != nil, (new == nil || new! < old!) {
if let r = rows(from(new), to(old!), scope: (0, range?.start ?? 0)) {
notify(insert: r, .Earliest)
}
} else if range != nil {
if let r = rows(from(old), to(new!), scope: range!) {
notify(remove: r, .Earliest)
}
}
}
}
/// Update internal `tsLatest`, then post `NotifySyncInsert` or `NotifySyncRemove` notification with row ids.
/// - Warning: Always call from a background thread!
private func set(newLatest: Timestamp?) {
func from(_ t: Timestamp) -> Timestamp { max(t + 1, tsMin) }
func to(_ t: Timestamp?) -> Timestamp { t == nil ? 0 : t! + 1 }
// +1: include upper end because `dnsLogsRowRange` selects `ts < X`
if let (old, new) = tsLatest <-/ newLatest {
if old != nil, (new == nil || old! < new!) {
if let r = rows(from(old!), to(new), scope: (range?.end ?? 0, 0)) {
notify(insert: r, .Latest)
}
} else if range != nil {
if let r = rows(from(new!), to(old), scope: range!) {
notify(remove: r, .Latest)
}
}
}
}
/// - Warning: Always call from a background thread!
private func notify(insert r: SQLiteRowRange, _ end: SyncUpdateEnd) {
if range == nil { range = r }
else {
switch end {
case .Earliest: range!.start = r.start
case .Latest: range!.end = r.end
}
}
notifyObservers { $0.syncUpdate(self, insert: r, affects: end) }
}
/// - Warning: `range` must not be `nil`!
/// - Warning: Always call from a background thread!
private func notify(remove r: SQLiteRowRange, _ end: SyncUpdateEnd) {
switch end {
case .Earliest: range!.start = r.end + 1
case .Latest: range!.end = r.start - 1
}
if range!.start > range!.end { range = nil }
notifyObservers { $0.syncUpdate(self, remove: r, affects: end) }
}
// MARK: - Observer List
private var observers: [WeakObserver] = []
/// Add `delegate` to observer list and immediatelly call `syncUpdate(reset:)` (on background thread).
func addObserver(_ delegate: SyncUpdateDelegate) {
observers.removeAll { $0.target == nil }
observers.append(.init(target: delegate))
DispatchQueue.global().async {
delegate.syncUpdate(self, reset: self.rows)
}
}
/// - Warning: Always call from a background thread!
private func notifyObservers(_ block: (SyncUpdateDelegate) -> Void) {
assert(!Thread.isMainThread)
self.pause()
for o in observers where o.target != nil { block(o.target!) }
self.continue()
}
}
/// Wrapper class for `SyncUpdateDelegate` that supports weak references
private struct WeakObserver {
weak var target: SyncUpdateDelegate?
weak var pullToRefresh: UIRefreshControl?
}
enum SyncUpdateEnd { case Earliest, Latest }
protocol SyncUpdateDelegate : AnyObject {
/// `SyncUpdate` has unpredictable changes. Reload your `dataSource`.
/// - Warning: This function will **always** be called from a background thread.
func syncUpdate(_ sender: SyncUpdate, reset rows: SQLiteRowRange)
/// `SyncUpdate` added new `rows` to database. Sync changes to your `dataSource`.
/// - Warning: This function will **always** be called from a background thread.
func syncUpdate(_ sender: SyncUpdate, insert rows: SQLiteRowRange, affects: SyncUpdateEnd)
/// `SyncUpdate` outdated some `rows` in database. Sync changes to your `dataSource`.
/// - Warning: This function will **always** be called from a background thread.
func syncUpdate(_ sender: SyncUpdate, remove rows: SQLiteRowRange, affects: SyncUpdateEnd)
/// Background process did delete some entries in database that match `affectedDomain`.
/// Update or remove entries from your `dataSource`.
/// - Warning: This function will **always** be called from a background thread.
func syncUpdate(_ sender: SyncUpdate, partialRemove affectedDomain: String)
}
// MARK: - Pull-To-Refresh
@available(iOS 10.0, *)
extension SyncUpdate {
/// Add Pull-To-Refresh control to `tableViewController`. On action notify `observer.syncUpdate(reset:)`
/// - Warning: Must be called after `addObserver()` such that `observer` exists in list of observers.
func allowPullToRefresh(onTVC tableViewController: UITableViewController?, forObserver: SyncUpdateDelegate) {
guard let i = observers.firstIndex(where: { $0.target === forObserver }) else {
assertionFailure("You must add the observer before enabling Pull-To-Refresh!")
return
}
// remove previous
observers[i].pullToRefresh?.removeTarget(self, action: #selector(pullToRefresh), for: .valueChanged)
observers[i].pullToRefresh = nil
if let tvc = tableViewController {
let rc = UIRefreshControl()
rc.addTarget(self, action: #selector(pullToRefresh), for: .valueChanged)
tvc.tableView.refreshControl = rc
observers[i].pullToRefresh = rc
}
}
/// Pull-To-Refresh callback method. Find observer with corresponding `RefreshControl` and notify `syncUpdate(reset:)`
@objc private func pullToRefresh(sender: UIRefreshControl) {
guard let x = observers.first(where: { $0.pullToRefresh === sender }) else {
assertionFailure("Should never happen. RefreshControl removed from table view while keeping it active somewhere else.")
return
}
syncNow {
x.target?.syncUpdate(self, reset: self.rows)
DispatchQueue.main.sync {
sender.endRefreshing()
}
}
}
}

View File

@@ -1,57 +1,73 @@
import UIKit
extension UIAlertController {
func presentIn(_ viewController: UIViewController) {
viewController.present(self, animated: true)
}
}
// MARK: Basic Alerts
/// - Parameters:
/// - buttonText: Default: `"Dismiss"`
func Alert(title: String?, text: String?, buttonText: String = "Dismiss") -> UIAlertController {
let alert = UIAlertController(title: title, message: text, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: buttonText, style: .cancel, handler: nil))
return alert
}
/// - Parameters:
/// - buttonText: Default:`"Dismiss"`
func ErrorAlert(_ error: Error, buttonText: String = "Dismiss") -> UIAlertController {
return Alert(title: "Error", text: error.localizedDescription, buttonText: buttonText)
}
func AskAlert(title: String?, text: String?, buttonText: String = "Continue", buttonStyle: UIAlertAction.Style = .default, action: @escaping () -> Void) -> UIAlertController {
/// - Parameters:
/// - buttonText: Default: `"Dismiss"`
func ErrorAlert(_ errorDescription: String, buttonText: String = "Dismiss") -> UIAlertController {
return Alert(title: "Error", text: errorDescription, buttonText: buttonText)
}
/// - Parameters:
/// - buttonText: Default: `"Continue"`
/// - buttonStyle: Default: `.default`
func AskAlert(title: String?, text: String?, buttonText: String = "Continue", buttonStyle: UIAlertAction.Style = .default, action: @escaping (UIAlertController) -> Void) -> UIAlertController {
let alert = Alert(title: title, text: text, buttonText: "Cancel")
alert.addAction(UIAlertAction(title: buttonText, style: buttonStyle) { _ in action() })
alert.addAction(UIAlertAction(title: buttonText, style: buttonStyle) { _ in action(alert) })
return alert
}
extension UIAlertController {
func presentIn(_ viewController: UIViewController?) {
viewController?.present(self, animated: true, completion: nil)
}
/// Show alert hinting the user to go to system settings and re-enable notifications.
func NotificationsDisabledAlert(presentIn viewController: UIViewController) {
Alert(title: "Notifications Disabled",
text: "Go to System Settings > Notifications > AppCheck to re-enable notifications."
).presentIn(viewController)
}
// MARK: Alert with multiple options
func AlertWithOptions(title: String?, text: String?, buttons: [String], lastIsDestructive: Bool = false, callback: @escaping (_ index: Int?) -> Void) -> UIAlertController {
/// - Parameters:
/// - buttons: Default: `[]`
/// - lastIsDestructive: Default: `false`
/// - cancelButtonText: Default: `"Dismiss"`
func BottomAlert(title: String?, text: String?, buttons: [String] = [], lastIsDestructive: Bool = false, cancelButtonText: String = "Cancel", callback: @escaping (_ index: Int?) -> Void) -> UIAlertController {
let alert = UIAlertController(title: title, message: text, preferredStyle: .actionSheet)
for (i, btn) in buttons.enumerated() {
let dangerous = (lastIsDestructive && i + 1 == buttons.count)
alert.addAction(UIAlertAction(title: btn, style: dangerous ? .destructive : .default) { _ in callback(i) })
}
alert.addAction(UIAlertAction(title: "Cancel", style: .cancel) { _ in callback(nil) })
alert.addAction(UIAlertAction(title: cancelButtonText, style: .cancel) { _ in callback(nil) })
return alert
}
func AlertDeleteLogs(_ domain: String, latest: Timestamp, success: @escaping (_ tsMin: Timestamp) -> Void) -> UIAlertController {
let sinceNow = TimestampNow() - latest
var buttons = ["Last 5 minutes", "Last 15 minutes", "Last hour", "Last 24 hours", "Delete everything"]
var times: [Timestamp] = [300, 900, 3600, 86400]
while times.count > 0, times[0] < sinceNow {
buttons.removeFirst()
times.removeFirst()
}
return AlertWithOptions(title: "Delete logs", text: "Delete logs for domain '\(domain)'", buttons: buttons, lastIsDestructive: true) {
guard let idx = $0 else {
return
}
if idx >= times.count {
success(0)
} else {
success(Timestamp(Date().timeIntervalSince1970) - times[idx])
let minutesPassed = (Timestamp.now() - latest) / 60
let times: [Int] = [5, 15, 60, 1440].compactMap { minutesPassed < $0 ? $0 : nil }
let fmt = TimeFormat(.full, allowed: [.hour, .minute])
let labels = times.map { "Last " + (fmt.from(minutes: $0) ?? "?") }
return BottomAlert(title: "Delete logs", text: "Delete logs for domain '\(domain)'", buttons: labels + ["Delete everything"], lastIsDestructive: true) {
if let i = $0 {
success(i < times.count ? Timestamp.past(minutes: times[i]) : 0)
}
}
}

View File

@@ -0,0 +1,88 @@
import Foundation
//extension Collection {
// subscript(ifExist i: Index?) -> Iterator.Element? {
// guard let i = i else { return nil }
// return indices.contains(i) ? self[i] : nil
// }
//}
extension Range where Bound == Int {
@inline(__always) func arr() -> [Bound] { self.map { $0 } }
}
// MARK: - Sorted Array
extension Array {
typealias CompareFn = (Element, Element) -> Bool
/// Binary tree search operation.
/// - Warning: Array must be sorted already.
/// - Parameters:
/// - mustExist: Determine whether to return low index or `nil` if element is missing.
/// - first: If `true`, keep searching for first matching element.
/// - Returns: Index or `nil` (only if `mustExist = true` and element does not exist).
/// - Complexity: O(log *n*), where *n* is the length of the array.
func binTreeIndex(of element: Element, compare fn: CompareFn, mustExist: Bool = false, findFirst: Bool = false) -> Int? {
var found = false
var lo = 0, hi = self.count - 1
while lo <= hi {
let mid = (lo + hi)/2
if fn(self[mid], element) {
lo = mid + 1
} else if fn(element, self[mid]) {
hi = mid - 1
} else {
if !findFirst { return mid } // exit early if we dont care about first index
hi = mid - 1
found = true
}
}
return (mustExist && !found) ? nil : lo // not found, would be inserted at position lo
}
/// Binary tree lookup whether element exists. Performs `binTreeIndex(of:compare:mustExist:)` internally.
func binTreeExists(_ element: Element, compare fn: CompareFn) -> Bool {
binTreeIndex(of: element, compare: fn, mustExist: true) != nil
}
/// Binary tree insert operation
/// - Warning: Array must be sorted already.
/// - Returns: Index at which `elem` was inserted
/// - Complexity: O(log *n*), where *n* is the length of the array.
@discardableResult mutating func binTreeInsert(_ elem: Element, compare fn: CompareFn) -> Int {
let newIndex = binTreeIndex(of: elem, compare: fn)!
insert(elem, at: newIndex)
return newIndex
}
/// Binary tree remove operation
/// - Warning: Array must be sorted already.
/// - Returns: Index of removed `elem` or `nil` if it does not exist
/// - Complexity: O(log *n*), where *n* is the length of the array.
@discardableResult mutating func binTreeRemove(_ elem: Element, compare fn: CompareFn) -> Int? {
if let i = binTreeIndex(of: elem, compare: fn, mustExist: true) {
remove(at: i)
return i
}
return nil
}
/// Sorted synchronous comparison between elements
/// - Parameter sortedSubset: Must be a strict subset of the sorted array.
/// - Returns: List of elements that are **not** present in `sortedSubset`.
/// - Complexity: O(*m*+*n*), where *n* is the length of the array and *m* the length of the `sortedSubset`.
/// If indices are found earlier, *n* may be significantly less (on average: `n/2`)
func difference(toSubset sortedSubset: [Element], compare fn: CompareFn) -> [Element] {
var result: [Element] = []
var iter = makeIterator()
for rhs in sortedSubset {
while let lhs = iter.next(), fn(lhs, rhs) {
result.append(lhs)
}
}
result.append(contentsOf: iter)
return result
}
}

View File

@@ -0,0 +1,99 @@
import UIKit
/*
Readable Auto Layout Constraints
Usage:
A.anchor =&= multiplier * B.anchor + constant | priority
*/
infix operator =&= : AdditionPrecedence
infix operator =<= : AdditionPrecedence
infix operator =>= : AdditionPrecedence
//infix operator | : AdditionPrecedence
/// Create and activate an `equal` constraint between left and right anchor. Format: `A.anchor =&= multiplier * B.anchor + constant | priority`
@discardableResult func =&= <T>(l: NSLayoutAnchor<T>, r: NSLayoutAnchor<T>) -> NSLayoutConstraint { l.constraint(equalTo: r).on() }
/// Create and activate a `lessThan` constraint between left and right anchor. Format: `A.anchor =<= multiplier * B.anchor + constant | priority`
@discardableResult func =<= <T>(l: NSLayoutAnchor<T>, r: NSLayoutAnchor<T>) -> NSLayoutConstraint { l.constraint(lessThanOrEqualTo: r).on() }
/// Create and activate a `greaterThan` constraint between left and right anchor. Format: `A.anchor =>= multiplier * B.anchor + constant | priority`
@discardableResult func =>= <T>(l: NSLayoutAnchor<T>, r: NSLayoutAnchor<T>) -> NSLayoutConstraint { l.constraint(greaterThanOrEqualTo: r).on() }
extension NSLayoutDimension { // higher precedence, so multiply first
/// Create intermediate anchor multiplier result.
static func *(l: CGFloat, r: NSLayoutDimension) -> AnchorMultiplier { .init(anchor: r, m: l) }
}
/// Intermediate `NSLayoutConstraint` anchor with multiplier supplement
struct AnchorMultiplier {
let anchor: NSLayoutDimension, m: CGFloat
/// Create and activate an `equal` constraint between left and right anchor. Format: `A.anchor =&= multiplier * B.anchor + constant | priority`
@discardableResult static func =&=(l: NSLayoutDimension, r: Self) -> NSLayoutConstraint { l.constraint(equalTo: r.anchor, multiplier: r.m).on() }
/// Create and activate a `lessThan` constraint between left and right anchor. Format: `A.anchor =<= multiplier * B.anchor + constant | priority`
@discardableResult static func =<=(l: NSLayoutDimension, r: Self) -> NSLayoutConstraint { l.constraint(lessThanOrEqualTo: r.anchor, multiplier: r.m).on() }
/// Create and activate a `greaterThan` constraint between left and right anchor. Format: `A.anchor =>= multiplier * B.anchor + constant | priority`
@discardableResult static func =>=(l: NSLayoutDimension, r: Self) -> NSLayoutConstraint { l.constraint(greaterThanOrEqualTo: r.anchor, multiplier: r.m).on() }
}
extension NSLayoutConstraint {
/// Change `isActive`to `true` and return `self`
func on() -> Self { isActive = true; return self }
/// Change `constant`attribute and return `self`
@discardableResult static func +(l: NSLayoutConstraint, r: CGFloat) -> NSLayoutConstraint { l.constant = r; return l }
/// Change `constant` attribute and return `self`
@discardableResult static func -(l: NSLayoutConstraint, r: CGFloat) -> NSLayoutConstraint { l.constant = -r; return l }
/// Change `priority` attribute and return `self`
@discardableResult static func |(l: NSLayoutConstraint, r: UILayoutPriority) -> NSLayoutConstraint { l.priority = r; return l }
}
extension NSLayoutDimension {
/// Create and activate an `equal` constraint with constant value. Format: `A.anchor =&= constant | priority`
@discardableResult static func =&= (l: NSLayoutDimension, r: CGFloat) -> NSLayoutConstraint { l.constraint(equalToConstant: r).on() }
/// Create and activate a `lessThan` constraint with constant value. Format: `A.anchor =<= constant | priority`
@discardableResult static func =<= (l: NSLayoutDimension, r: CGFloat) -> NSLayoutConstraint { l.constraint(lessThanOrEqualToConstant: r).on() }
/// Create and activate a `greaterThan` constraint with constant value. Format: `A.anchor =>= constant | priority`
@discardableResult static func =>= (l: NSLayoutDimension, r: CGFloat) -> NSLayoutConstraint { l.constraint(greaterThanOrEqualToConstant: r).on() }
}
/*
UIView extension to generate multiple constraints at once
Usage:
child.anchor([.width, .height], to: parent) | .defaultLow
*/
extension UIView {
/// Edges that need the relation to flip arguments. For these we need to inverse the constant value and relation.
private static let inverseItem: [NSLayoutConstraint.Attribute] = [.right, .bottom, .trailing, .lastBaseline, .rightMargin, .bottomMargin, .trailingMargin]
/// Create and active constraints for provided edges. Constraints will anchor the same edge on both `self` and `other`.
/// - Note: Will set `translatesAutoresizingMaskIntoConstraints = false`
/// - Parameters:
/// - edges: List of constraint attributes, e.g. `[.top, .bottom, .left, .right]`
/// - other: Instance to bind to, e.g. `UIView` or `UILayoutGuide`
/// - margin: Used as constant value. Multiplier will always be `1.0`. If you need to change the multiplier, use single constraints instead. (Default: `0`)
/// - rel: Constraint relation. (Default: `.equal`)
/// - Returns: List of created and active constraints
@discardableResult func anchor(_ edges: [NSLayoutConstraint.Attribute], to other: Any, margin: CGFloat = 0, if rel: NSLayoutConstraint.Relation = .equal) -> [NSLayoutConstraint] {
translatesAutoresizingMaskIntoConstraints = false
return edges.map {
let (A, B) = UIView.inverseItem.contains($0) ? (other, self) : (self, other)
return NSLayoutConstraint(item: A, attribute: $0, relatedBy: rel, toItem: B, attribute: $0, multiplier: 1, constant: margin).on()
}
}
/// Sets the priority with which a view resists being made smaller and larger than its intrinsic size.
func constrainHuggingCompression(_ axis: NSLayoutConstraint.Axis, _ priotity: UILayoutPriority) {
setContentHuggingPriority(priotity, for: axis)
setContentCompressionResistancePriority(priotity, for: axis)
}
}
extension Array where Element: NSLayoutConstraint {
/// set `priority` on all elements and return same list
@discardableResult static func |(l: Self, r: UILayoutPriority) -> Self {
for x in l { x.priority = r }
return l
}
}

View File

@@ -0,0 +1,25 @@
import UIKit
// See: https://noahgilmore.com/blog/dark-mode-uicolor-compatibility/
extension UIColor {
/// `.systemBackground ?? .white`
static var sysBackground: UIColor { if #available(iOS 13.0, *) { return .systemBackground } else { return .white } }
/// `.link ?? .systemBlue`
static var sysLink: UIColor { if #available(iOS 13.0, *) { return .link } else { return .systemBlue } }
/// `.label ?? .black`
static var sysLabel: UIColor { if #available(iOS 13.0, *) { return .label } else { return .black } }
/// `.secondaryLabel ?? rgba(60, 60, 67, 0.6)`
static var sysLabel2: UIColor { if #available(iOS 13.0, *) { return .secondaryLabel } else { return .init(red: 60/255.0, green: 60/255.0, blue: 67/255.0, alpha: 0.6) } }
/// `.tertiaryLabel ?? rgba(60, 60, 67, 0.3)`
static var sysLabel3: UIColor { if #available(iOS 13.0, *) { return .tertiaryLabel } else { return .init(red: 60/255.0, green: 60/255.0, blue: 67/255.0, alpha: 0.3) } }
}
extension NSMutableAttributedString {
func withColor(_ color: UIColor, fromBack: Int) -> Self {
let l = length - fromBack
let r = (l < 0) ? NSMakeRange(0, length) : NSMakeRange(l, fromBack)
self.addAttribute(.foregroundColor, value: color, range: r)
return self
}
}

View File

@@ -0,0 +1,33 @@
precedencegroup CompareAssignPrecedence {
assignment: true
associativity: left
higherThan: ComparisonPrecedence
}
infix operator <-? : CompareAssignPrecedence
infix operator <-/ : CompareAssignPrecedence
extension Equatable {
/// Assign a new value to `lhs` if `newValue` differs from the previous value. Return `false` if they are equal.
/// - Returns: `true` if `lhs` was overwritten with another value
static func <-?(lhs: inout Self, newValue: Self) -> Bool {
if lhs != newValue {
lhs = newValue
return true
}
return false
}
/// Assign a new value to `lhs` if `newValue` differs from the previous value.
/// Return tuple with both values. Or `nil` if they are equal.
/// - Returns: `nil` if `previousValue == newValue`
static func <-/(lhs: inout Self, newValue: Self) -> (previousValue: Self, newValue: Self)? {
let previousValue = lhs
if previousValue != newValue {
lhs = newValue
return (previousValue, newValue)
}
return nil
}
}

View File

@@ -1,23 +0,0 @@
import Foundation
fileprivate extension FileManager {
func exportDir() -> URL {
try! url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: true)
}
func appGroupDir() -> URL {
containerURL(forSecurityApplicationGroupIdentifier: "group.de.uni-bamberg.psi.AppCheck")!
}
func internalDB() -> URL {
appGroupDir().appendingPathComponent("dns-logs.sqlite")
}
func appGroupIPC() -> URL {
appGroupDir().appendingPathComponent("data-exchange.dat")
}
}
extension URL {
static func exportDir() -> URL { FileManager.default.exportDir() }
static func appGroupDir() -> URL { FileManager.default.appGroupDir() }
static func internalDB() -> URL { FileManager.default.internalDB() }
static func appGroupIPC() -> URL { FileManager.default.appGroupIPC() }
}

View File

@@ -0,0 +1,51 @@
import UIKit
extension UIFont {
func withTraits(traits: UIFontDescriptor.SymbolicTraits) -> UIFont {
UIFont(descriptor: fontDescriptor.withSymbolicTraits(traits)!, size: 0) // keep size as is
}
func bold() -> UIFont { withTraits(traits: .traitBold) }
func italic() -> UIFont { withTraits(traits: .traitItalic) }
func monoSpace() -> UIFont {
let traits = fontDescriptor.object(forKey: .traits) as? [UIFontDescriptor.TraitKey: Any] ?? [:]
let weight = (traits[.weight] as? CGFloat) ?? UIFont.Weight.regular.rawValue
return .monospacedDigitSystemFont(ofSize: pointSize, weight: .init(rawValue: weight))
}
}
extension NSAttributedString {
static func image(_ img: UIImage) -> Self {
let att = NSTextAttachment()
att.image = img
return self.init(attachment: att)
}
}
extension NSMutableAttributedString {
static private var def: UIFont = .preferredFont(forTextStyle: .body)
func normal(_ str: String, _ style: UIFont.TextStyle = .body) -> Self { append(str, withFont: .preferredFont(forTextStyle: style)) }
func bold(_ str: String, _ style: UIFont.TextStyle = .body) -> Self { append(str, withFont: UIFont.preferredFont(forTextStyle: style).bold()) }
func italic(_ str: String, _ style: UIFont.TextStyle = .body) -> Self { append(str, withFont: UIFont.preferredFont(forTextStyle: style).italic()) }
func h1(_ str: String) -> Self { normal(str, .title1) }
func h2(_ str: String) -> Self { normal(str, .title2) }
func h3(_ str: String) -> Self { normal(str, .title3) }
private func append(_ str: String, withFont: UIFont) -> Self {
append(NSAttributedString(string: str, attributes: [
.font : withFont,
.foregroundColor : UIColor.sysLabel
]))
return self
}
func centered(_ content: NSAttributedString) -> Self {
let before = length
append(content)
let ps = NSMutableParagraphStyle()
ps.alignment = .center
addAttribute(.paragraphStyle, value: ps, range: .init(location: before, length: content.length))
return self
}
}

View File

@@ -1,91 +0,0 @@
import Foundation
struct QLog {
private init() {}
static func m(_ message: String) { write("", message) }
static func Info(_ message: String) { write("[INFO] ", message) }
#if DEBUG
static func Debug(_ message: String) { write("[DEBUG] ", message) }
#else
static func Debug(_ _: String) {}
#endif
static func Error(_ message: String) { write("[ERROR] ", message) }
static func Warning(_ message: String) { write("[WARN] ", message) }
private static func write(_ tag: String, _ message: String) {
print(String(format: "%1.3f %@%@", Date().timeIntervalSince1970, tag, message))
}
}
extension Collection {
subscript(ifExist i: Index?) -> Iterator.Element? {
guard let i = i else { return nil }
return indices.contains(i) ? self[i] : nil
}
}
var listOfSLDs: [String : [String : Bool]] = {
let path = Bundle.main.url(forResource: "third-level", withExtension: "txt")
let content = try! String(contentsOf: path!)
var res: [String : [String : Bool]] = [:]
content.enumerateLines { line, _ in
let dom = line.split(separator: ".")
let tld = String(dom.first!)
let sld = String(dom.last!)
if res[tld] == nil { res[tld] = [:] }
res[tld]![sld] = true
}
return res
}()
extension String {
/// Check if string is equal to `domain` or ends with `.domain`
func isSubdomain(of domain: String) -> Bool { self == domain || self.hasSuffix("." + domain) }
/// Split string into top level domain part and host part
func splitDomainAndHost() -> (domain: String, host: String?) {
let lastChr = last?.asciiValue ?? 0
guard lastChr > UInt8(ascii: "9") || lastChr < UInt8(ascii: "0") else { // IP address
return (domain: "# IP connection", host: self)
}
var parts = components(separatedBy: ".")
guard let tld = parts.popLast(), let sld = parts.popLast() else {
return (domain: self, host: nil) // no subdomains, just plain SLD
}
var ending = sld + "." + tld
if listOfSLDs[tld]?[sld] ?? false, let rld = parts.popLast() {
ending = rld + "." + ending
}
return (domain: ending, host: parts.joined(separator: "."))
// var allDots = enumerated().compactMap { $1 == "." ? $0 : nil }
// let d1 = allDots.popLast() // we dont care about TLD
// guard let d2 = allDots.popLast() else {
// return (domain: self, host: nil) // no subdomains, just plain SLD
// }
// // TODO: check third level domains
//// let d3 = allDots.popLast()
// return (String(suffix(count - d2 - 1)), String(prefix(d2)))
}
}
extension Timer {
@discardableResult static func repeating(_ interval: TimeInterval, call selector: Selector, on target: Any, userInfo: Any? = nil) -> Timer {
Timer.scheduledTimer(timeInterval: interval, target: target, selector: selector,
userInfo: userInfo, repeats: true)
}
}
extension DateFormatter {
convenience init(withFormat: String) {
self.init()
dateFormat = withFormat
}
func with(format: String) -> Self {
dateFormat = format
return self
}
func string(from ts: Timestamp) -> String {
string(from: Date.init(timeIntervalSince1970: Double(ts)))
}
}
func TimestampNow() -> Timestamp { Timestamp(Date().timeIntervalSince1970) }

View File

@@ -1,20 +0,0 @@
import Foundation
extension GroupedDomain {
static func +(a: GroupedDomain, b: GroupedDomain) -> Self {
GroupedDomain(domain: a.domain, total: a.total + b.total, blocked: a.blocked + b.blocked,
lastModified: max(a.lastModified, b.lastModified), options: a.options ?? b.options )
}
}
extension Array where Element == GroupedDomain {
func merge(_ domain: String, options opt: FilterOptions? = nil) -> GroupedDomain {
var b: Int32 = 0, t: Int32 = 0, m: Timestamp = 0
for x in self {
b += x.blocked
t += x.total
m = Swift.max(m, x.lastModified)
}
return GroupedDomain(domain: domain, total: t, blocked: b, lastModified: m, options: opt)
}
}

View File

@@ -0,0 +1,17 @@
import Foundation
struct QLog {
private init() {}
static func m(_ message: String) { write("", message) }
static func Info(_ message: String) { write("[INFO] ", message) }
#if DEBUG
static func Debug(_ message: String) { write("[DEBUG] ", message) }
#else
static func Debug(_ _: String) {}
#endif
static func Error(_ message: String) { write("[ERROR] ", message) }
static func Warning(_ message: String) { write("[WARN] ", message) }
private static func write(_ tag: String, _ message: String) {
print(String(format: "%1.3f %@%@", Date().timeIntervalSince1970, tag, message))
}
}

View File

@@ -1,8 +1,10 @@
import Foundation
let NotifyVPNStateChanged = NSNotification.Name("GlassVPNStateChanged") // VPNState!
let NotifyFilterChanged = NSNotification.Name("PSIFilterSettingsChanged") // nil!
let NotifyLogHistoryReset = NSNotification.Name("PSILogHistoryReset") // nil!
let NotifyVPNStateChanged = NSNotification.Name("GlassVPNStateChanged") // nil!
let NotifyDNSFilterChanged = NSNotification.Name("PSIDNSFilterSettingsChanged") // domain: String!
let NotifyDateFilterChanged = NSNotification.Name("PSIDateFilterSettingsChanged") // nil!
let NotifySortOrderChanged = NSNotification.Name("PSIDateFilterSortOrderChanged") // nil!
let NotifyRecordingChanged = NSNotification.Name("PSIRecordingChanged") // (Recording, deleted: Bool)!
extension NSNotification.Name {

View File

@@ -1,8 +0,0 @@
import Foundation
let dateTimeFormat = DateFormatter(withFormat: "yyyy-MM-dd HH:mm:ss")
var currentVPNState: VPNState = .off
public enum VPNState : Int {
case on = 1, inbetween, off
}

View File

@@ -0,0 +1,42 @@
import UIKit
extension String {
/// Check if string is equal to `domain` or ends with `.domain`
func isSubdomain(of domain: String) -> Bool { self == domain || self.hasSuffix("." + domain) }
/// Extract second or third level domain name
func extractDomain() -> String {
let lastChr = last?.asciiValue ?? 0
guard lastChr > UInt8(ascii: "9") || lastChr < UInt8(ascii: "0") else { // IP address
return "# IP"
}
var parts = components(separatedBy: ".")
guard let tld = parts.popLast(), let sld = parts.popLast() else {
return self // no subdomains, just plain SLD
}
if listOfSLDs[tld]?[sld] ?? false, let rld = parts.popLast() {
return rld + "." + sld + "." + tld
}
return sld + "." + tld
}
/// Returns `true` if String matches list of known second level domains (e.g., `co.uk`).
func isKnownSLD() -> Bool {
let parts = components(separatedBy: ".")
return parts.count == 2 && listOfSLDs[parts.last!]?[parts.first!] ?? false
}
}
private var listOfSLDs: [String : [String : Bool]] = {
let path = Bundle.main.url(forResource: "third-level", withExtension: "txt")
let content = try! String(contentsOf: path!)
var res: [String : [String : Bool]] = [:]
content.enumerateLines { line, _ in
let dom = line.split(separator: ".")
let tld = String(dom.first!)
let sld = String(dom.last!)
if res[tld] == nil { res[tld] = [:] }
res[tld]![sld] = true
}
return res
}()

View File

@@ -1,93 +1,92 @@
import UIKit
extension GroupedDomain {
var detailCellText: String { get {
return blocked > 0
? "\(dateTimeFormat.string(from: lastModified))\(blocked)/\(total) blocked"
: "\(dateTimeFormat.string(from: lastModified))\(total)"
}
}
extension IndexPath {
/// Convenience init with `section: 0`
public init(row: Int) { self.init(row: row, section: 0) }
}
extension FilterOptions {
func tableRowImage() -> UIImage? {
let blocked = contains(.blocked)
let ignored = contains(.ignored)
if blocked { return UIImage(named: ignored ? "block_ignore" : "shield-x") }
if ignored { return UIImage(named: "quicklook-not") }
return nil
}
}
extension NSMutableAttributedString {
func withColor(_ color: UIColor, fromBack: Int) -> Self {
let l = length - fromBack
let r = (l < 0) ? NSMakeRange(0, length) : NSMakeRange(l, fromBack)
self.addAttribute(.foregroundColor, value: color, range: r)
return self
}
}
// MARK: Pull-to-Refresh
extension UIRefreshControl {
convenience init(call: Selector, on: UITableViewController) {
convenience init(call: Selector, on target: Any) {
self.init()
addTarget(on, action: call, for: .valueChanged)
addTarget(self, action: #selector(endRefreshing), for: .valueChanged)
addTarget(target, action: call, for: .valueChanged)
}
}
// MARK: - UITableView
extension UITableView {
/// Returns `true` if this `tableView` is the currently frontmost visible
var isFrontmost: Bool { window?.isKeyWindow ?? false }
/// If frontmost window, perform `insertRows()`; If not, perform `reloadData()`
func safeInsertRow(_ index: Int, with animation: UITableView.RowAnimation = .automatic) {
isFrontmost ? insertRows(at: [IndexPath(row: index)], with: animation) : reloadData()
}
/// If frontmost window, perform `insertRows()`; If not, perform `reloadData()`
func safeInsertRows(_ range: Range<Int>, with animation: UITableView.RowAnimation = .automatic) {
isFrontmost ? insertRows(at: range.map {IndexPath(row: $0)}, with: animation) : reloadData()
}
/// If frontmost window, perform `deleteRows()`; If not, perform `reloadData()`
func safeDeleteRows(_ indices: [Int], with animation: UITableView.RowAnimation = .automatic) {
isFrontmost ? deleteRows(at: indices.map {IndexPath(row: $0)}, with: animation) : reloadData()
}
/// If frontmost window, perform `deleteRows()`; If not, perform `reloadData()`
func safeDeleteRows(_ range: Range<Int>, with animation: UITableView.RowAnimation = .automatic) {
isFrontmost ? deleteRows(at: range.map {IndexPath(row: $0)}, with: animation) : reloadData()
}
/// If frontmost window, perform `reloadRows()`; If not, perform `reloadData()`
func safeReloadRow(_ index: Int, with animation: UITableView.RowAnimation = .automatic) {
isFrontmost ? reloadRows(at: [IndexPath(row: index)], with: animation) : reloadData()
}
/// If frontmost window, perform `moveRow()`; If not, perform `reloadData()`
func safeMoveRow(_ from: Int, to: Int) {
isFrontmost ? moveRow(at: IndexPath(row: from), to: IndexPath(row: to)) : reloadData()
}
}
// MARK: - Incremental Update Delegate
protocol IncrementalDataSourceUpdate : UITableViewController {
var dataSource: [GroupedDomain] { get set }
// MARK: - EditableRows
public enum RowAction {
case ignore, block, delete
}
extension IncrementalDataSourceUpdate {
func ifDisplayed(_ block: () -> Void) {
DispatchQueue.main.sync {
if self.tableView.window?.isKeyWindow ?? false {
block()
// TODO: custom handling if cell is being edited
} else {
self.tableView.reloadData()
protocol EditableRows {
func editableRowUserInfo(_ index: IndexPath) -> Any?
func editableRowActions(_ index: IndexPath) -> [(RowAction, String)]
func editableRowActionColor(_ index: IndexPath, _ action: RowAction) -> UIColor?
@discardableResult func editableRowCallback(_ atIndexPath: IndexPath, _ action: RowAction, _ userInfo: Any?) -> Bool
}
extension EditableRows where Self: UITableViewDelegate {
func getRowActionsIOS9(_ index: IndexPath, _ table: UITableView) -> [UITableViewRowAction]? {
let userInfo = editableRowUserInfo(index)
return editableRowActions(index).compactMap { a,t in
let x = UITableViewRowAction(style: a == .delete ? .destructive : .normal, title: t) {
self.editableRowCallback($1, a, userInfo)
table.isEditing = false
}
if let color = editableRowActionColor(index, a) {
x.backgroundColor = color
}
return x
}
}
func insertRow(_ obj: GroupedDomain, at index: Int) {
dataSource.insert(obj, at: index)
ifDisplayed {
self.tableView.insertRows(at: [IndexPath(row: index, section: 0)], with: .left)
}
}
func moveRow(_ obj: GroupedDomain, from: Int, to: Int) {
dataSource.remove(at: from)
dataSource.insert(obj, at: to)
ifDisplayed {
let source = IndexPath(row: from, section: 0)
let cell = self.tableView.cellForRow(at: source)
cell?.detailTextLabel?.text = obj.detailCellText
self.tableView.moveRow(at: source, to: IndexPath(row: to, section: 0))
}
}
func replaceRow(_ obj: GroupedDomain, at index: Int) {
dataSource[index] = obj
ifDisplayed {
self.tableView.reloadRows(at: [IndexPath(row: index, section: 0)], with: .automatic)
}
}
func deleteRow(at index: Int) {
dataSource.remove(at: index)
ifDisplayed {
self.tableView.deleteRows(at: [IndexPath(row: index, section: 0)], with: .automatic)
}
}
func replaceData(with newData: [GroupedDomain]) {
dataSource = newData
ifDisplayed {
self.tableView.reloadData()
}
@available(iOS 11.0, *)
func getRowActionsIOS11(_ index: IndexPath) -> UISwipeActionsConfiguration? {
let userInfo = editableRowUserInfo(index)
return UISwipeActionsConfiguration(actions: editableRowActions(index).compactMap { a,t in
let x = UIContextualAction(style: a == .delete ? .destructive : .normal, title: t) { $2(self.editableRowCallback(index, a, userInfo)) }
x.backgroundColor = editableRowActionColor(index, a)
return x
})
}
func editableRowUserInfo(_ index: IndexPath) -> Any? { nil }
}
protocol EditActionsRemove : EditableRows {}
extension EditActionsRemove where Self: UITableViewController {
func editableRowActions(_: IndexPath) -> [(RowAction, String)] { [(.delete, "Remove")] }
func editableRowActionColor(_: IndexPath, _: RowAction) -> UIColor? { nil }
}

102
main/Extensions/Time.swift Normal file
View File

@@ -0,0 +1,102 @@
import Foundation
extension DateFormatter {
convenience init(withFormat: String) {
self.init()
dateFormat = withFormat
}
}
extension Date {
/// Convert `Timestamp` to `Date`
init(_ ts: Timestamp) { self.init(timeIntervalSince1970: Double(ts)) }
/// Convert `Date` to `Timestamp`
var timestamp: Timestamp { get { Timestamp(self.timeIntervalSince1970) } }
}
extension Timestamp {
/// Current time as `Timestamp` (second accuracy)
static func now() -> Timestamp { Date().timestamp }
/// Create `Timestamp` with `now() - minutes * 60`
static func past(minutes: Int) -> Timestamp { now() - Timestamp(minutes * 60) }
/// Create `Timestamp` with `m * 60` seconds
static func minutes(_ m: Int) -> Timestamp { Timestamp(m * 60) }
/// Create `Timestamp` with `h * 3600` seconds
static func hours(_ h: Int) -> Timestamp { Timestamp(h * 3600) }
/// Create `Timestamp` with `d * 86400` seconds
static func days(_ d: Int) -> Timestamp { Timestamp(d * 86400) }
}
extension Timer {
/// Recurring timer maintains a strong reference to `target`.
@discardableResult static func repeating(_ interval: TimeInterval, call selector: Selector, on target: Any, userInfo: Any? = nil) -> Timer {
Timer.scheduledTimer(timeInterval: interval, target: target, selector: selector,
userInfo: userInfo, repeats: true)
}
}
// MARK: - DateFormat
enum DateFormat {
private static let _hms = DateFormatter(withFormat: "yyyy-MM-dd HH:mm:ss")
private static let _hm = DateFormatter(withFormat: "yyyy-MM-dd HH:mm")
/// Format: `yyyy-MM-dd HH:mm:ss`
static func seconds(_ date: Date) -> String { _hms.string(from: date) }
/// Format: `yyyy-MM-dd HH:mm:ss`
static func seconds(_ ts: Timestamp) -> String { _hms.string(from: Date(ts)) }
/// Format: `yyyy-MM-dd HH:mm`
static func minutes(_ date: Date) -> String { _hm.string(from: date) }
/// Format: `yyyy-MM-dd HH:mm`
static func minutes(_ ts: Timestamp) -> String { _hm.string(from: Date(ts)) }
}
// MARK: - TimeFormat
struct TimeFormat {
private var formatter: DateComponentsFormatter
/// Init new formatter with exactly 1 unit count. E.g., `61 min -> 1 hr`
/// - Parameter allowed: Default: `[.day, .hour, .minute, .second]`
init(_ style: DateComponentsFormatter.UnitsStyle, allowed: NSCalendar.Unit = [.day, .hour, .minute, .second]) {
formatter = DateComponentsFormatter()
formatter.maximumUnitCount = 1
formatter.allowedUnits = allowed
formatter.unitsStyle = style
}
/// Formatted duration string, e.g., `20 min` or `7 days`
func from(days: Int = 0, hours: Int = 0, minutes: Int = 0, seconds: Int = 0) -> String? {
formatter.string(from: DateComponents(day: days, hour: hours, minute: minutes, second: seconds))
}
// MARK: static
/// Time string with format `[HH:]mm:ss` (hours prepended only if duration is 1h+)
static func from(_ duration: Timestamp) -> String {
let min = duration / 60
let sec = duration % 60
if min >= 60 {
return String(format: "%02d:%02d:%02d", min / 60, min % 60, sec)
} else {
return String(format: "%02d:%02d", min, sec)
}
}
/// Duration string with format `mm:ss` or `mm:ss.SSS`
static func from(_ duration: TimeInterval, millis: Bool = false) -> String {
let t = Int(duration)
if millis {
let mil = Int(duration * 1000) % 1000
return String(format: "%02d:%02d.%03d", t / 60, t % 60, mil)
}
return String(format: "%02d:%02d", t / 60, t % 60)
}
/// Duration string with format `mm:ss` or `mm:ss.SSS` since reference date
static func since(_ date: Date, millis: Bool = false) -> String {
from(Date().timeIntervalSince(date), millis: millis)
}
}

31
main/Extensions/URL.swift Normal file
View File

@@ -0,0 +1,31 @@
import Foundation
fileprivate extension FileManager {
// func exportDir() -> URL {
// try! url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: true)
// }
func appGroupDir() -> URL {
containerURL(forSecurityApplicationGroupIdentifier: "group.de.uni-bamberg.psi.AppCheck")!
}
func internalDB() -> URL {
appGroupDir().appendingPathComponent("dns-logs.sqlite")
}
}
extension FileManager {
func sizeOf(path: String) -> Int64? {
try? attributesOfItem(atPath: path)[.size] as? Int64
}
func readableSizeOf(path: String) -> String? {
guard let fSize = sizeOf(path: path) else { return nil }
let bcf = ByteCountFormatter()
bcf.countStyle = .file
return bcf.string(fromByteCount: fSize)
}
}
extension URL {
// static func exportDir() -> URL { FileManager.default.exportDir() }
static func appGroupDir() -> URL { FileManager.default.appGroupDir() }
static func internalDB() -> URL { FileManager.default.internalDB() }
}

View File

@@ -0,0 +1,44 @@
import UIKit
extension UIView {
func asImage(insets: UIEdgeInsets = .zero) -> UIImage {
if #available(iOS 10.0, *) {
let renderer = UIGraphicsImageRenderer(bounds: bounds.inset(by: insets))
return renderer.image { rendererContext in
layer.render(in: rendererContext.cgContext)
}
} else {
UIGraphicsBeginImageContext(bounds.inset(by: insets).size)
let ctx = UIGraphicsGetCurrentContext()!
ctx.translateBy(x: -insets.left, y: -insets.top)
layer.render(in:ctx)
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return UIImage(cgImage: image!.cgImage!)
}
}
/// Find size that fits into frame with given `width` as precondition.
/// - Parameter preferredHeight:If unset, find smallest possible size.
func fittingSize(fixedWidth: CGFloat, preferredHeight: CGFloat = 0) -> CGSize {
systemLayoutSizeFitting(CGSize(width: fixedWidth, height: preferredHeight), withHorizontalFittingPriority: .required, verticalFittingPriority: .fittingSizeLevel)
}
/// Find size that fits into frame with given `height` as precondition.
/// - Parameter preferredWidth:If unset, find smallest possible size.
func fittingSize(fixedHeight: CGFloat, preferredWidth: CGFloat = 0) -> CGSize {
systemLayoutSizeFitting(CGSize(width: preferredWidth, height: fixedHeight), withHorizontalFittingPriority: .fittingSizeLevel, verticalFittingPriority: .required)
}
}
extension UIEdgeInsets {
init(all: CGFloat = 0, top: CGFloat? = nil, left: CGFloat? = nil, bottom: CGFloat? = nil, right: CGFloat? = nil) {
self.init(top: top ?? all, left: left ?? all, bottom: bottom ?? all, right: right ?? all)
}
}
extension UIStoryboard {
func load<T: UIViewController>(_ identifier: String) -> T {
instantiateViewController(withIdentifier: identifier) as! T
}
}

160
main/GlassVPN.swift Normal file
View File

@@ -0,0 +1,160 @@
import NetworkExtension
let GlassVPN = GlassVPNManager()
enum VPNState : Int { case on = 1, inbetween, off }
final class GlassVPNManager {
static let bundleIdentifier = "de.uni-bamberg.psi.AppCheck.VPN"
private var managerVPN: NETunnelProviderManager?
private(set) var state: VPNState = .off
fileprivate init() {
#if IOS_SIMULATOR
postProcessedVPNState(.on)
SimulatorVPN.start()
#else
NETunnelProviderManager.loadAllFromPreferences { managers, error in
self.managerVPN = managers?.first {
($0.protocolConfiguration as? NETunnelProviderProtocol)?
.providerBundleIdentifier == GlassVPNManager.bundleIdentifier
}
guard let mgr = self.managerVPN else {
self.postRawVPNState(.invalid)
return
}
mgr.loadFromPreferences { _ in
self.postRawVPNState(mgr.connection.status)
}
}
NSNotification.Name.NEVPNStatusDidChange.observe(call: #selector(vpnStatusChanged(_:)), on: self)
#endif
NotifyDNSFilterChanged.observe(call: #selector(didChangeDomainFilter), on: self)
}
func setEnabled(_ newState: Bool) {
#if IOS_SIMULATOR
postProcessedVPNState(newState ? .on : .off)
newState ? SimulatorVPN.start() : SimulatorVPN.stop()
#else
guard let mgr = self.managerVPN else {
self.createNewVPN { manager in
self.managerVPN = manager
self.setEnabled(newState)
}
return
}
let state = mgr.isEnabled && (mgr.connection.status == .connected)
if state != newState {
self.updateVPN({ mgr.isEnabled = true }) {
newState ? try? mgr.connection.startVPNTunnel() : mgr.connection.stopVPNTunnel()
}
}
#endif
}
/// Notify VPN extension about changes
/// - Returns: `true` on success, `false` if VPN is off or message could not be converted to `.utf8`
@discardableResult func send(_ message: VPNAppMessage) -> Bool {
#if IOS_SIMULATOR
if state == .on, let data = message.raw {
SimulatorVPN.sendMsg(data)
return true
}
#else
if let session = self.managerVPN?.connection as? NETunnelProviderSession,
session.status == .connected, let data = message.raw {
do {
try session.sendProviderMessage(data, responseHandler: nil)
return true
} catch {}
}
#endif
return false
}
// MARK: - Notify callback
@objc private func vpnStatusChanged(_ notification: Notification) {
postRawVPNState((notification.object as? NETunnelProviderSession)?.status ?? .invalid)
}
@objc private func didChangeDomainFilter(_ notification: Notification) {
send(.filterUpdate(domain: notification.object as? String))
}
// MARK: - Manage configuration
private func createNewVPN(_ success: @escaping (_ manager: NETunnelProviderManager) -> Void) {
let mgr = NETunnelProviderManager()
mgr.localizedDescription = "AppCheck Monitor"
let proto = NETunnelProviderProtocol()
proto.providerBundleIdentifier = GlassVPNManager.bundleIdentifier
proto.serverAddress = "127.0.0.1"
mgr.protocolConfiguration = proto
mgr.isEnabled = true
mgr.saveToPreferences { error in
guard error == nil else {
self.postProcessedVPNState(.off)
//ErrorAlert(error!).presentIn(self.window?.rootViewController)
return
}
success(mgr)
}
}
private func updateVPN(_ body: @escaping () -> Void, _ onSuccess: @escaping () -> Void) {
self.managerVPN?.loadFromPreferences { error in
guard error == nil else { return }
body()
self.managerVPN?.saveToPreferences { error in
guard error == nil else { return }
onSuccess()
}
}
}
// MARK: - Post Notifications
private func postRawVPNState(_ origState: NEVPNStatus) {
let state: VPNState
switch origState {
case .connected: state = .on
case .connecting, .disconnecting, .reasserting: state = .inbetween
case .invalid, .disconnected: fallthrough
@unknown default: state = .off
}
postProcessedVPNState(state)
}
private func postProcessedVPNState(_ state: VPNState) {
self.state = state
NotifyVPNStateChanged.post()
}
}
// ---------------------------------------------------------------
// |
// | MARK: - VPN message
// |
// ---------------------------------------------------------------
struct VPNAppMessage {
let raw: Data?
init(_ string: String) { raw = string.data(using: .utf8) }
static func filterUpdate(domain: String? = nil) -> Self {
.init("filter-update:\(domain ?? "")")
}
static func autoDelete(after interval: Int) -> Self {
.init("auto-delete:\(interval)")
}
/// Only used for connection alert notifications
static func notificationSettingsChanged() -> Self {
.init("notify-prefs-change:1")
}
}

138
main/GlassVPNHook.swift Normal file
View File

@@ -0,0 +1,138 @@
import Foundation
class GlassVPNHook {
private let queue = DispatchQueue.init(label: "PSIGlassDNSQueue", qos: .userInteractive, target: .main)
private var filterDomains: [String]!
private var filterOptions: [(block: Bool, ignore: Bool, customA: Bool, customB: Bool)]!
private var autoDeleteTimer: Timer? = nil
private var cachedNotify: CachedConnectionAlert!
init() { reset() }
/// Reload from stored settings and rebuilt binary search tree
private func reset() {
reloadDomainFilter()
setAutoDelete(PrefsShared.AutoDeleteLogsDays)
cachedNotify = CachedConnectionAlert()
}
/// Invalidate auto-delete timer and release stored properties. You should nullify this instance afterwards.
func cleanUp() {
filterDomains = nil
filterOptions = nil
autoDeleteTimer?.fire() // one last time before we quit
autoDeleteTimer?.invalidate()
cachedNotify = nil
}
/// Call this method from `PacketTunnelProvider.handleAppMessage(_:completionHandler:)`
func handleAppMessage(_ messageData: Data) {
let message = String(data: messageData, encoding: .utf8)
if let msg = message, let i = msg.firstIndex(of: ":") {
let action = msg.prefix(upTo: i)
let value = msg.suffix(from: msg.index(after: i))
switch action {
case "filter-update":
reloadDomainFilter() // TODO: reload only selected domain?
return
case "auto-delete":
setAutoDelete(Int(value) ?? PrefsShared.AutoDeleteLogsDays)
return
case "notify-prefs-change":
cachedNotify = CachedConnectionAlert()
return
default: break
}
}
NSLog("[VPN.WARN] This should never happen! Received unknown handleAppMessage: \(message ?? messageData.base64EncodedString())")
reset() // just in case we fallback to do everything
}
// MARK: - Process DNS Request
/// Log domain request and post notification (if enabled).
/// - Returns: `true` if the request shoud be blocked.
func processDNSRequest(_ domain: String) -> Bool {
let i = filterIndex(for: domain)
// TODO: disable ignore & block during recordings
let (block, ignore, cA, cB) = (i<0) ? (false, false, false, false) : filterOptions[i]
if ignore {
return block
}
queue.async {
do { try AppDB?.logWrite(domain, blocked: block) }
catch { NSLog("[VPN.WARN] Couldn't write: \(error)") }
}
cachedNotify.postOrIgnore(domain, blck: block, custA: cA, custB: cB)
// TODO: wait for notify response to block or allow connection
return block
}
/// Build binary tree for reverse DNS lookup
private func reloadDomainFilter() {
let tmp = AppDB?.loadFilters()?.map({
(String($0.reversed()), $1)
}).sorted(by: { $0.0 < $1.0 }) ?? []
let t1 = tmp.map { $0.0 }
let t2 = tmp.map { ($1.contains(.blocked),
$1.contains(.ignored),
$1.contains(.customA),
$1.contains(.customB)) }
filterDomains = t1
filterOptions = t2
}
/// Lookup for reverse DNS binary tree
private func filterIndex(for domain: String) -> Int {
let reverseDomain = String(domain.reversed())
var lo = 0, hi = filterDomains.count - 1
while lo <= hi {
let mid = (lo + hi)/2
if filterDomains[mid] < reverseDomain {
lo = mid + 1
} else if reverseDomain < filterDomains[mid] {
hi = mid - 1
} else {
return mid
}
}
if lo > 0, reverseDomain.hasPrefix(filterDomains[lo - 1] + ".") {
return lo - 1
}
return -1
}
// MARK: - Auto-delete Timer
/// Prepare auto-delete timer with interval between 1 hr - 1 day.
/// - Parameter days: Max age to keep when deleting
private func setAutoDelete(_ days: Int) {
autoDeleteTimer?.invalidate()
guard days > 0 else { return }
// Repeat interval uses days as hours. min 1 hr, max 24 hrs.
let interval = TimeInterval(min(24, days) * 60 * 60)
autoDeleteTimer = Timer.scheduledTimer(timeInterval: interval,
target: self, selector: #selector(autoDeleteNow),
userInfo: days, repeats: true)
autoDeleteTimer!.fire()
}
/// Callback fired when old data should be deleted.
@objc private func autoDeleteNow(_ sender: Timer) {
NSLog("[VPN.INFO] Auto-delete old logs")
queue.async {
do {
try AppDB?.dnsLogsDeleteOlderThan(days: sender.userInfo as! Int)
} catch {
NSLog("[VPN.WARN] Couldn't delete logs, will retry in 5 minutes. \(error)")
if sender.isValid {
sender.fireDate = Date().addingTimeInterval(300) // retry in 5 min
}
}
}
}
}

View File

@@ -0,0 +1,43 @@
import Foundation
import UserNotifications
struct CachedConnectionAlert {
let enabled: Bool
let invertedMode: Bool
let listBlocked, listCustomA, listCustomB, listElse: Bool
let tone: AnyObject?
init() {
enabled = PrefsShared.ConnectionAlerts.Enabled
guard #available(iOS 10.0, *), enabled else {
invertedMode = false
listBlocked = false
listCustomA = false
listCustomB = false
listElse = false
tone = nil
return
}
invertedMode = PrefsShared.ConnectionAlerts.ExcludeMode
listBlocked = PrefsShared.ConnectionAlerts.Lists.Blocked
listCustomA = PrefsShared.ConnectionAlerts.Lists.CustomA
listCustomB = PrefsShared.ConnectionAlerts.Lists.CustomB
listElse = PrefsShared.ConnectionAlerts.Lists.Else
tone = UNNotificationSound.from(string: PrefsShared.ConnectionAlerts.Sound)
}
/// If notifications are enabled and allowed, schedule new notification. Otherwise NOOP.
/// - Parameters:
/// - domain: Domain will be used as unique identifier for noticiation center and in notification message.
/// - blck: Indicator whether `domain` is part of `blocked` list
/// - custA: Indicator whether `domain` is part of custom list `A`
/// - custB: Indicator whether `domain` is part of custom list `B`
func postOrIgnore(_ domain: String, blck: Bool, custA: Bool, custB: Bool) {
if #available(iOS 10.0, *), enabled {
let onAnyList = listBlocked && blck || listCustomA && custA || listCustomB && custB || listElse
if invertedMode ? !onAnyList : onAnyList {
PushNotification.scheduleConnectionAlert(domain, sound: tone as! UNNotificationSound?)
}
}
}
}

View File

@@ -0,0 +1,153 @@
import UserNotifications
struct PushNotification {
enum Identifier: String {
case YouShallRecordMoreReminder
case CantStopMeNowReminder
case RestInPeaceTombstone
case AllConnectionAlertNotifications
}
static func allowed(_ closure: @escaping (NotificationRequestState) -> Void) {
guard #available(iOS 10, *) else { return }
UNUserNotificationCenter.current().getNotificationSettings { settings in
let state = NotificationRequestState(settings.authorizationStatus)
DispatchQueue.main.async {
closure(state)
}
}
}
/// Available in iOS 12+
static func requestProvisionalOrDoNothing(_ closure: @escaping (Bool) -> Void) {
guard #available(iOS 12, *) else { return closure(false) }
let opt: UNAuthorizationOptions = [.alert, .sound, .badge, .provisional, .providesAppNotificationSettings]
UNUserNotificationCenter.current().requestAuthorization(options: opt) { granted, _ in
DispatchQueue.main.async {
closure(granted)
}
}
}
static func requestAuthorization(_ closure: @escaping (Bool) -> Void) {
guard #available(iOS 10, *) else { return }
var opt: UNAuthorizationOptions = [.alert, .sound, .badge]
if #available(iOS 12, *) {
opt.formUnion(.providesAppNotificationSettings)
}
UNUserNotificationCenter.current().requestAuthorization(options: opt) { granted, _ in
DispatchQueue.main.async {
closure(granted)
}
}
}
static func hasPending(_ ident: Identifier, _ closure: @escaping (Bool) -> Void) {
guard #available(iOS 10, *) else { return }
UNUserNotificationCenter.current().getPendingNotificationRequests {
let hasIt = $0.contains { $0.identifier == ident.rawValue }
DispatchQueue.main.async {
closure(hasIt)
}
}
}
static func cancel(_ ident: Identifier, keepDelivered: Bool = false) {
guard #available(iOS 10, *) else { return }
let center = UNUserNotificationCenter.current()
guard ident != .AllConnectionAlertNotifications else {
// remove all connection alert notifications while
// keeping general purpose reminder notifications
center.getDeliveredNotifications {
var list = $0.map { $0.request.identifier }
list.removeAll { !$0.contains(".") } // each domain (or IP) has a dot
center.removeDeliveredNotifications(withIdentifiers: list)
// no need to do the same for pending since con-alerts are always immediate
}
return
}
center.removePendingNotificationRequests(withIdentifiers: [ident.rawValue])
if !keepDelivered {
center.removeDeliveredNotifications(withIdentifiers: [ident.rawValue])
}
}
@available(iOS 10.0, *)
static func schedule(_ ident: Identifier, content: UNNotificationContent, trigger: UNNotificationTrigger? = nil, waitUntilDone: Bool = false) {
schedule(ident.rawValue, content: content, trigger: trigger, waitUntilDone: waitUntilDone)
}
@available(iOS 10.0, *)
static func schedule(_ ident: String, content: UNNotificationContent, trigger: UNNotificationTrigger? = nil, waitUntilDone: Bool = false) {
let req = UNNotificationRequest(identifier: ident, content: content, trigger: trigger)
waitUntilDone ? req.pushAndWait() : req.push()
}
}
// MARK: - Reminder Alerts
extension PushNotification {
/// Auto-check preferences whether `withText` is set, then schedule notification to 5 min in the future.
static func scheduleRestartReminderBanner() {
guard #available(iOS 10, *), PrefsShared.RestartReminder.WithText else { return }
schedule(.CantStopMeNowReminder,
content: .make("AppCheck disabled",
body: "AppCheck can't monitor network traffic because VPN has stopped.",
sound: .from(string: PrefsShared.RestartReminder.Sound)),
trigger: .make(Date(timeIntervalSinceNow: 5 * 60)),
waitUntilDone: true)
}
/// Auto-check preferences whether `withBadge` is set, then post badge immediatelly.
/// - Parameter on: If `true`, set `1` on app icon. If `false`, remove badge on app icon.
static func scheduleRestartReminderBadge(on: Bool) {
guard #available(iOS 10, *), PrefsShared.RestartReminder.WithBadge else { return }
schedule(.RestInPeaceTombstone, content: .makeBadge(on ? 1 : 0), waitUntilDone: true)
}
}
// MARK: - Connection Alerts
extension PushNotification {
static private let queue = ThrottledBatchQueue<String>(0.5, using: .init(label: "PSINotificationQueue", qos: .default, target: .global()))
/// Post new notification with given domain name. If notification already exists, increase occurrence count.
/// - Parameter domain: Used in the description and as notification identifier.
@available(iOS 10.0, *)
static func scheduleConnectionAlert(_ domain: String, sound: UNNotificationSound?) {
queue.addDelayed(domain) { batch in
let groupSum = batch.reduce(into: [:]) { $0[$1] = ($0[$1] ?? 0) + 1 }
scheduleConnectionAlertMulti(groupSum, sound: sound)
}
}
/// Internal method to post a batch of counted domains.
@available(iOS 10.0, *)
static private func scheduleConnectionAlertMulti(_ group: [String: Int], sound: UNNotificationSound?) {
UNUserNotificationCenter.current().getDeliveredNotifications { delivered in
for (dom, count) in group {
let num: Int
if let prev = delivered.first(where: { $0.request.identifier == dom })?.request.content {
if let p = prev.body.split(separator: "×").first, let i = Int(p) {
num = count + i
} else {
num = count + 1
}
} else {
num = count
}
schedule(dom, content: .make("DNS connection", body: num > 1 ? "\(num)× \(dom)" : dom, sound: sound))
}
}
}
}

View File

@@ -0,0 +1,28 @@
import UserNotifications
extension PushNotification {
static func scheduleRecordingReminder(force: Bool) {
if force {
scheduleRecordingReminder()
} else {
hasPending(.YouShallRecordMoreReminder) {
if !$0 { scheduleRecordingReminder() }
}
}
}
private static func scheduleRecordingReminder() {
guard #available(iOS 10, *) else { return }
let now = Timestamp.now()
var next = RecordingsDB.lastTimestamp() ?? (now - 1)
while next < now {
next += .days(14)
}
schedule(.YouShallRecordMoreReminder,
content: .make("Start new recording",
body: "It's been a while since your last recording …",
sound: .from(string: Prefs.RecordingReminder.Sound)),
trigger: .make(Date(next)))
}
}

View File

@@ -0,0 +1,83 @@
import UserNotifications
enum NotificationRequestState {
case NotDetermined, Denied, Authorized, Provisional
@available(iOS 10.0, *)
init(_ from: UNAuthorizationStatus) {
switch from {
case .denied: self = .Denied
case .authorized: self = .Authorized
case .provisional: self = .Provisional
case .notDetermined: fallthrough
@unknown default: self = .NotDetermined
}
}
}
@available(iOS 10.0, *)
extension UNNotificationRequest {
func push() {
UNUserNotificationCenter.current().add(self) { error in
if let e = error {
NSLog("[ERROR] Can't add push notification: \(e)")
}
}
}
func pushAndWait() {
let semaphore = DispatchSemaphore(value: 0)
UNUserNotificationCenter.current().add(self) { error in
if let e = error {
NSLog("[ERROR] Can't add push notification: \(e)")
}
semaphore.signal()
}
_ = semaphore.wait(wallTimeout: .distantFuture)
}
}
@available(iOS 10.0, *)
extension UNNotificationContent {
/// - Parameter sound: Use `#default` or `nil` to play the default tone. Use `#mute` to play no tone at all. Else use an `UNNotificationSoundName`.
static func make(_ title: String, body: String, sound: UNNotificationSound? = .default) -> UNNotificationContent {
let x = UNMutableNotificationContent()
// use NSString.localizedUserNotificationString(forKey:arguments:)
x.title = title
x.body = body
x.sound = sound
return x
}
/// - Parameter value: `0` will remove the badge
static func makeBadge(_ value: Int) -> UNNotificationContent {
let x = UNMutableNotificationContent()
x.badge = value as NSNumber?
return x
}
}
@available(iOS 10.0, *)
extension UNNotificationTrigger {
/// Calls `(dateMatching: components, repeats: repeats)`
static func make(_ components: DateComponents, repeats: Bool) -> UNCalendarNotificationTrigger {
UNCalendarNotificationTrigger(dateMatching: components, repeats: repeats)
}
/// Calls `(dateMatching: components(second-year), repeats: false)`
static func make(_ date: Date) -> UNCalendarNotificationTrigger {
let components = Calendar.current.dateComponents([.year,.month,.day,.hour,.minute,.second], from: date)
return UNCalendarNotificationTrigger(dateMatching: components, repeats: false)
}
/// Calls `(timeInterval: time, repeats: repeats)`
static func make(_ time: TimeInterval, repeats: Bool) -> UNTimeIntervalNotificationTrigger {
UNTimeIntervalNotificationTrigger(timeInterval: time, repeats: repeats)
}
}
@available(iOS 10.0, *)
extension UNNotificationSound {
static func from(string: String) -> UNNotificationSound? {
switch string {
case "#mute": return nil
case "#default": return .default
case let name: return .init(named: UNNotificationSoundName(name + ".caf"))
}
}
}

View File

@@ -0,0 +1,91 @@
import UIKit
class TVCPreviousRecords: UITableViewController, EditActionsRemove {
private var dataSource: [Recording] = []
override func viewDidLoad() {
dataSource = RecordingsDB.list().reversed() // newest on top
NotifyRecordingChanged.observe(call: #selector(recordingDidChange(_:)), on: self)
}
func insertAndEditRecording(_ r: Recording) {
insertNewRecord(r)
editRecord(r, isNewRecording: true)
}
@objc private func recordingDidChange(_ notification: Notification) {
let (new, deleted) = notification.object as! (Recording, Bool)
if let i = dataSource.firstIndex(where: { $0.id == new.id }) {
if deleted {
dataSource.remove(at: i)
tableView.deleteRows(at: [IndexPath(row: i)], with: .automatic)
} else {
dataSource[i] = new
tableView.reloadRows(at: [IndexPath(row: i)], with: .automatic)
}
} else if !deleted {
insertNewRecord(new)
}
}
private func insertNewRecord(_ record: Recording) {
dataSource.insert(record, at: 0)
tableView.insertRows(at: [IndexPath(row: 0)], with: .top)
}
// MARK: - Table View Delegate
override func tableView(_ tableView: UITableView, accessoryButtonTappedForRowWith indexPath: IndexPath) {
editRecord(dataSource[indexPath.row])
}
private func editRecord(_ record: Recording, isNewRecording: Bool = false) {
performSegue(withIdentifier: "editRecordSegue", sender: (record, isNewRecording))
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "editRecordSegue" {
let (record, newlyCreated) = sender as! (Recording, Bool)
let target = segue.destination as! VCEditRecording
target.record = record
target.deleteOnCancel = newlyCreated
} else if segue.identifier == "openRecordDetailsSegue" {
if let i = tableView.indexPathForSelectedRow {
(segue.destination as? TVCRecordingDetails)?.record = dataSource[i.row]
}
}
}
// MARK: - Table View Data Source
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
dataSource.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "PreviousRecordCell")!
let x = dataSource[indexPath.row]
cell.textLabel?.text = x.title ?? x.fallbackTitle
cell.textLabel?.textColor = (x.title == nil) ? .systemGray : nil
cell.detailTextLabel?.text = "at \(DateFormat.seconds(x.start)), duration: \(TimeFormat.from(x.duration ?? 0))"
return cell
}
// MARK: - Editing
override func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
getRowActionsIOS9(indexPath, tableView)
}
@available(iOS 11.0, *)
override func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
getRowActionsIOS11(indexPath)
}
func editableRowCallback(_ index: IndexPath, _ action: RowAction, _ userInfo: Any?) -> Bool {
RecordingsDB.delete(self.dataSource[index.row])
return true
}
}

View File

@@ -0,0 +1,94 @@
import UIKit
class TVCRecordingDetails: UITableViewController, EditActionsRemove {
var record: Recording!
private lazy var isLongRecording: Bool = (record.duration ?? 0) > Timestamp.hours(1)
private var showRaw: Bool = false
/// Sorted by `ts` in ascending order (oldest first)
private lazy var dataSourceRaw: [DomainTsPair] = RecordingsDB.details(record)
/// Sorted by `count` (descending), then alphabetically
private lazy var dataSourceSum: [(domain: String, count: Int)] = {
var result: [String:Int] = [:]
for x in dataSourceRaw {
result[x.domain] = (result[x.domain] ?? 0) + 1 // group and count
}
return result.map{$0}.sorted {
$0.count > $1.count || $0.count == $1.count && $0.domain < $1.domain
}
}()
override func viewDidLoad() {
title = record.title ?? record.fallbackTitle
}
@IBAction private func toggleDisplayStyle(_ sender: UIBarButtonItem) {
showRaw = !showRaw
sender.image = UIImage(named: showRaw ? "line-collapse" : "line-expand")
tableView.reloadData()
}
// MARK: - Table View Data Source
override func tableView(_: UITableView, numberOfRowsInSection _: Int) -> Int {
showRaw ? dataSourceRaw.count : dataSourceSum.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell: UITableViewCell
if showRaw {
let x = dataSourceRaw[indexPath.row]
if isLongRecording {
cell = tableView.dequeueReusableCell(withIdentifier: "RecordDetailLongCell")!
cell.textLabel?.text = x.domain
cell.detailTextLabel?.text = DateFormat.seconds(x.ts)
} else {
cell = tableView.dequeueReusableCell(withIdentifier: "RecordDetailShortCell")!
cell.textLabel?.text = "+ " + TimeFormat.from(x.ts - record.start)
cell.detailTextLabel?.text = x.domain
}
} else {
let x = dataSourceSum[indexPath.row]
cell = tableView.dequeueReusableCell(withIdentifier: "RecordDetailCountedCell")!
cell.textLabel?.text = x.domain
cell.detailTextLabel?.text = "\(x.count)×"
}
return cell
}
// MARK: - Editing
override func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
getRowActionsIOS9(indexPath, tableView)
}
@available(iOS 11.0, *)
override func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
getRowActionsIOS11(indexPath)
}
func editableRowCallback(_ index: IndexPath, _ action: RowAction, _ userInfo: Any?) -> Bool {
if showRaw {
let x = dataSourceRaw[index.row]
if RecordingsDB.deleteSingle(record, domain: x.domain, ts: x.ts) {
if let i = dataSourceSum.firstIndex(where: { $0.domain == x.domain }) {
dataSourceSum[i].count -= 1
if dataSourceSum[i].count == 0 {
dataSourceSum.remove(at: i)
}
}
dataSourceRaw.remove(at: index.row)
tableView.deleteRows(at: [index], with: .automatic)
}
} else {
let dom = dataSourceSum[index.row].domain
if RecordingsDB.deleteDetails(record, domain: dom) {
dataSourceRaw.removeAll { $0.domain == dom }
dataSourceSum.remove(at: index.row)
tableView.deleteRows(at: [index], with: .automatic)
}
}
return true
}
}

View File

@@ -0,0 +1,131 @@
import UIKit
class VCEditRecording: UIViewController, UITextFieldDelegate, UITextViewDelegate {
var record: Recording!
var deleteOnCancel: Bool = false
@IBOutlet private var buttonCancel: UIBarButtonItem!
@IBOutlet private var buttonSave: UIBarButtonItem!
@IBOutlet private var inputTitle: UITextField!
@IBOutlet private var inputNotes: UITextView!
@IBOutlet private var inputDetails: UITextView!
@IBOutlet private var noteBottom: NSLayoutConstraint!
override func viewDidLoad() {
inputTitle.placeholder = record.fallbackTitle
inputTitle.text = record.title
inputNotes.text = record.notes
inputDetails.text = """
Start: \(DateFormat.seconds(record.start))
End: \(record.stop == nil ? "?" : DateFormat.seconds(record.stop!))
Duration: \(TimeFormat.from(record.duration ?? 0))
"""
validateSaveButton()
if deleteOnCancel { // mark as destructive
buttonCancel.tintColor = .systemRed
if #available(iOS 13.0, *) {
isModalInPresentation = true
}
}
UIResponder.keyboardWillShowNotification.observe(call: #selector(keyboardWillShow), on: self)
UIResponder.keyboardWillHideNotification.observe(call: #selector(keyboardWillHide), on: self)
}
// MARK: Save & Cancel Buttons
@IBAction func didTapSave(_ sender: UIBarButtonItem) {
let newlyCreated = deleteOnCancel
if newlyCreated {
// if remains true, `viewDidDisappear` will delete the record
deleteOnCancel = false
}
QLog.Debug("updating record #\(record.id)")
record.title = (inputTitle.text == "") ? nil : inputTitle.text
record.notes = (inputNotes.text == "") ? nil : inputNotes.text
dismiss(animated: true) {
RecordingsDB.update(self.record)
if newlyCreated {
RecordingsDB.persist(self.record)
if Prefs.RecordingReminder.Enabled {
PushNotification.scheduleRecordingReminder(force: true)
}
}
}
}
@IBAction func didTapCancel(_ sender: UIBarButtonItem) {
QLog.Debug("discard edit of record #\(record.id)")
dismiss(animated: true)
}
override func viewDidDisappear(_ animated: Bool) {
if deleteOnCancel {
QLog.Debug("deleting record #\(record.id)")
RecordingsDB.delete(record)
deleteOnCancel = false
}
}
// MARK: Handle Keyboard & Notes Frame
private var isEditingNotes: Bool = false
private var keyboardHeight: CGFloat = 0
@IBAction func hideKeyboard() { view.endEditing(false) }
func textViewDidBeginEditing(_ textView: UITextView) {
if textView == inputNotes {
isEditingNotes = true
updateKeyboard()
}
}
func textViewDidEndEditing(_ textView: UITextView) {
if textView == inputNotes {
isEditingNotes = false
updateKeyboard()
}
}
@objc func keyboardWillShow(_ notification: NSNotification) {
keyboardHeight = (notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue.height ?? 0
updateKeyboard()
}
@objc func keyboardWillHide(_ notification: NSNotification) {
keyboardHeight = 0
updateKeyboard()
}
private func updateKeyboard() {
guard let parent = inputNotes.superview, let stack = parent.superview else {
return
}
let adjust = (isEditingNotes && keyboardHeight > 0)
stack.subviews.forEach{ $0.isHidden = (adjust && $0 != parent) }
let title = parent.subviews.first as! UILabel
title.font = .preferredFont(forTextStyle: adjust ? .subheadline : .title2)
title.sizeToFit()
title.frame.size.width = parent.frame.width
noteBottom.constant = adjust ? view.frame.height - stack.frame.maxY - keyboardHeight : 0
}
// MARK: TextField & TextView Delegate
func textFieldDidChangeSelection(_ _: UITextField) { validateSaveButton() }
func textViewDidChange(_ _: UITextView) { validateSaveButton() }
private func validateSaveButton() {
let changed = (inputTitle.text != record.title ?? "" || inputNotes.text != record.notes ?? "")
buttonSave.isEnabled = changed || deleteOnCancel // always allow save for new recordings
}
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
textField == inputTitle ? inputNotes.becomeFirstResponder() : true
}
}

View File

@@ -0,0 +1,140 @@
import UIKit
class VCRecordings: UIViewController, UINavigationControllerDelegate {
private var currentRecording: Recording?
private var recordingTimer: Timer?
@IBOutlet private var timeLabel: UILabel!
@IBOutlet private var startButton: UIButton!
@IBOutlet private var startNewRecView: UIView!
private var prevRecController: UINavigationController!
override func viewDidLoad() {
prevRecController = (children.first as! UINavigationController)
prevRecController.delegate = self
timeLabel.font = timeLabel.font.monoSpace()
// hide timer if not running
updateUI(setRecording: false, animated: false)
currentRecording = RecordingsDB.getCurrent()
if !Prefs.DidShowTutorial.Recordings {
self.perform(#selector(showTutorial), with: nil, afterDelay: 0.5)
}
}
override func viewDidAppear(_ animated: Bool) {
if currentRecording != nil { startTimer(animate: false) }
}
override func viewWillDisappear(_ animated: Bool) {
stopTimer(animate: false)
}
func navigationController(_ nav: UINavigationController, willShow vc: UIViewController, animated: Bool) {
hideNewRecording(isRootVC: (vc == nav.viewControllers.first), didShow: false)
}
func navigationController(_ nav: UINavigationController, didShow vc: UIViewController, animated: Bool) {
// TODO: use interactive animation handler to dynamically animate "new recording" view
hideNewRecording(isRootVC: (vc == nav.viewControllers.first), didShow: true)
}
private func hideNewRecording(isRootVC: Bool, didShow: Bool) {
if isRootVC == didShow {
UIView.animate(withDuration: 0.3) {
self.startNewRecView.isHidden = !isRootVC // hide "new recording" if details open
}
}
}
// MARK: Start New Recording
@IBAction private func startRecordingButtonTapped(_ sender: UIButton) {
if recordingTimer == nil {
currentRecording = RecordingsDB.startNew()
startTimer(animate: true)
} else {
stopTimer(animate: true)
RecordingsDB.stop(&currentRecording!)
prevRecController.popToRootViewController(animated: true)
let editVC = (prevRecController.topViewController as! TVCPreviousRecords)
editVC.insertAndEditRecording(currentRecording!)
currentRecording = nil // otherwise it will restart
}
}
private func startTimer(animate: Bool) {
guard let r = currentRecording, r.stop == nil else {
return
}
recordingTimer = Timer.repeating(0.086, call: #selector(timerCallback(_:)), on: self, userInfo: Date(r.start))
updateUI(setRecording: true, animated: animate)
}
@objc private func timerCallback(_ sender: Timer) {
timeLabel.text = TimeFormat.since(sender.userInfo as! Date, millis: true)
}
private func stopTimer(animate: Bool) {
recordingTimer?.invalidate()
recordingTimer = nil
updateUI(setRecording: false, animated: animate)
}
private func updateUI(setRecording: Bool, animated: Bool) {
let title = setRecording ? "Stop Recording" : "Start New Recording"
let color = setRecording ? UIColor.systemRed : nil
let yT = setRecording ? 0 : -timeLabel.frame.height
let yB = (setRecording ? 1 : 0.5) * (startButton.superview!.frame.height - startButton.frame.height)
if !animated { // else title will flash
startButton.titleLabel?.text = title
}
UIView.animate(withDuration: animated ? 0.3 : 0) {
self.timeLabel.frame.origin.y = yT
self.startButton.frame.origin.y = yB
self.startButton.setTitle(title, for: .normal)
self.startButton.setTitleColor(color, for: .normal)
}
}
// MARK: Tutorial View Controller
@objc private func showTutorial() {
let x = TutorialSheet()
x.addSheet().addArrangedSubview(QuickUI.text(attributed: NSMutableAttributedString()
.h1("What are Recordings?\n")
.normal("\nSimilar to the default logging, recordings will intercept every request and log it for later review. " +
"Recordings are usually 3  5 minutes long and cover a single application. " +
"You can utilize recordings for App analysis or to get a ground truth for background traffic." +
"\n\n" +
"Optionally, you can help us by providing app specific recordings. " +
"Together with your findings we can create a community driven privacy monitor. " +
"The research results will help you and others avoid Apps that unnecessarily share data with third-party providers.")
))
x.addSheet().addArrangedSubview(QuickUI.text(attributed: NSMutableAttributedString()
.h1("How to record?\n")
.normal("\nBefore you begin a new recording make sure that you quit all running applications. " +
"Tap on the 'Start Recording' button and switch to the application you'd like to inspect. " +
"Use the App as you would normally. Try to get to all corners and functionality the App provides. " +
"When you feel that you have captured enough content, come back to ").italic("AppCheck").normal(" and stop the recording." +
"\n\n" +
"Upon completion you will find your recording in the 'Previous Recordings' section. " +
"You can review your results and remove user specific information if necessary.")
))
x.addSheet().addArrangedSubview(QuickUI.text(attributed: NSMutableAttributedString()
.h1("Share results\n")
.normal("\nThis step is completely ").bold("optional").normal(". " +
"You can choose to share your results with us. " +
"We can compare similar applications and suggest privacy friendly alternatives. " +
"Together with other likeminded individuals we can increase the awareness for privacy friendly design." +
"\n\n" +
"Thank you very much.")
))
x.buttonTitleDone = "Got it"
x.present {
Prefs.DidShowTutorial.Recordings = true
}
}
}

View File

@@ -0,0 +1,60 @@
import UIKit
protocol AnalysisBarDelegate {
func analysisBarWillOpenCoOccurrence() -> (domain: String, isFQDN: Bool)
}
class VCAnalysisBar: UIViewController, UITabBarDelegate {
@IBOutlet private var tabBar: UITabBar!
override func viewDidLoad() {
if #available(iOS 10.0, *) {
tabBar.unselectedItemTintColor = .sysLink
}
super.viewDidLoad()
}
override func willMove(toParent parent: UIViewController?) {
super.willMove(toParent: parent)
let enabled = (parent as? AnalysisBarDelegate) != nil
for item in tabBar.items! { item.isEnabled = enabled }
}
// MARK: - Tab Bar Appearance
override func viewWillAppear(_: Bool) {
resizeTableViewHeader()
}
override func traitCollectionDidChange(_: UITraitCollection?) {
resizeTableViewHeader()
}
func resizeTableViewHeader() {
guard let tableView = (parent as? UITableViewController)?.tableView,
let head = tableView.tableHeaderView else { return }
// Recalculate and apply new height. Otherwise tabBar won't compress
tabBar.sizeToFit()
head.frame.size.height = tabBar.frame.height
tableView.tableHeaderView = head
}
// MARK: - Tab Bar Delegate
func tabBar(_ tabBar: UITabBar, didSelect item: UITabBarItem) {
tabBar.selectedItem = nil
openCoOccurrence()
}
private func openCoOccurrence() {
guard let delegate = parent as? AnalysisBarDelegate,
let vc: VCCoOccurrence = storyboard?.load("IBCoOccurrence") else {
return
}
let info = delegate.analysisBarWillOpenCoOccurrence()
vc.domainName = info.domain
vc.isFQDN = info.isFQDN
present(vc, animated: true)
}
}

View File

@@ -0,0 +1,152 @@
import UIKit
class VCCoOccurrence: UIViewController, UITableViewDataSource {
var domainName: String!
var isFQDN: Bool!
private var dataSource: [ContextAnalysisResult] = []
@IBOutlet private var tableView: UITableView!
@IBOutlet private var timeSegment: UISegmentedControl!
private let availableTimes = [0, 5, 15, 30]
private var selectedTime = -1 {
didSet { logTimeDelta = log(CGFloat(max(2, selectedTime+1))) }
}
private var logTimeDelta: CGFloat = 1
private var logMaxCount: CGFloat = 1
override func viewDidLoad() {
super.viewDidLoad()
selectedTime = Prefs.ContextAnalyis.CoOccurrenceTime // calls `didSet` and `logTimeDelta`
timeSegment.removeAllSegments() // clear IB values
for (i, time) in availableTimes.enumerated() {
timeSegment.insertSegment(withTitle: TimeFormat(.abbreviated).from(seconds: time), at: i, animated: false)
if time == selectedTime {
timeSegment.selectedSegmentIndex = i
}
}
reloadDataSource()
}
func reloadDataSource() {
dataSource = [("Loading …", 0, 0, 0)]
logMaxCount = 1
tableView.reloadData()
let domain = domainName!
let flag = isFQDN!
let time = Timestamp(selectedTime)
DispatchQueue.global().async { [weak self] in
let temp: [ContextAnalysisResult]
let total: Int32
if let db = AppDB,
let times = db.dnsLogsUniqTs(domain, isFQDN: flag), times.count > 0,
let result = db.contextAnalysis(coOccurrence: times, plusMinus: time, exclude: domain, isFQDN: flag),
result.count > 0
{
temp = result
var sum: Int32 = 0
for x in result { sum += x.count }
total = sum // if statement guarantees >= 1
} else {
temp = []
total = 1
}
DispatchQueue.main.sync { [weak self] in
self?.dataSource = temp
self?.logMaxCount = log(CGFloat(total + 1))
self?.tableView.reloadData()
}
}
}
@IBAction func didChangeTime(_ sender: UISegmentedControl) {
selectedTime = availableTimes[sender.selectedSegmentIndex]
Prefs.ContextAnalyis.CoOccurrenceTime = selectedTime
reloadDataSource()
}
@IBAction func didClose(_ sender: UIBarButtonItem) {
dismiss(animated: true)
}
// MARK: - Table View Data Source
func tableView(_ _: UITableView, numberOfRowsInSection _: Int) -> Int {
dataSource.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "CoOccurrenceCell") as! CoOccurrenceCell
let src = dataSource[indexPath.row]
cell.title.text = src.domain
cell.rank.text = "\(indexPath.row + 1)."
cell.count.text = "\(src.count)"
cell.avgdiff.text = String(format: "%.2fs", src.avg)
// log percentage of total co-occurrence count + 1 (min: log(2))
cell.countMeter.percent = (log(CGFloat(src.count + 1)) / logMaxCount)
// log percentage of selected time window (0s/5s/15s/30s) + 1 (min: log(2))
cell.avgdiffMeter.percent = 1 - (log(CGFloat(src.avg + 1)) / logTimeDelta)
return cell
}
}
class CoOccurrenceCell: UITableViewCell {
@IBOutlet var title: UILabel!
@IBOutlet var rank: TagLabel!
@IBOutlet var count: TagLabel!
@IBOutlet var avgdiff: TagLabel!
@IBOutlet var countMeter: MeterBar!
@IBOutlet var avgdiffMeter: MeterBar!
}
// MARK: - Tutorial Screen
extension VCCoOccurrence {
@IBAction func showInfoScreen() {
let sampleCell: UIImage = {
let cell = tableView.dequeueReusableCell(withIdentifier: "CoOccurrenceCell") as! CoOccurrenceCell
cell.title.text = "example.org"
cell.rank.text = "9."
cell.count.text = "14"
cell.avgdiff.text = String(format: "%.2fs", 0.71)
cell.countMeter.percent = 0.35
cell.avgdiffMeter.percent = 0.95
// Bug: Sometimes dequeue will return a "broken" hidden cell.
// It can't be set visible and thus can't render an image.
// Funnily `cell.contentView` can rendered.
let theView = cell.isHidden ? cell.contentView : cell
// resize view to fit into tutorial sheet
let minWidth = TutorialSheet.verticalWidth - 10 //-> 2 * textContainer.lineFragmentPadding
theView.frame.size = theView.systemLayoutSizeFitting(UIView.layoutFittingCompressedSize)
theView.frame.size.width = min(theView.frame.size.width, minWidth)
// set width in two steps because first call may change layoutMargins
theView.frame.size.width += theView.layoutMargins.left + theView.layoutMargins.right
// FIXME: In case `hidden == false`, backgroundColor will be black in Dark mode.
theView.backgroundColor = tableView.backgroundColor
return theView.asImage(insets: theView.layoutMargins)
}()
let x = TutorialSheet()
x.addSheet().addArrangedSubview(QuickUI.text(attributed: NSMutableAttributedString()
.h3("Co-Occurrence")
.normal(" allows you to find requests that happen often at the same time as the selected domain. " +
"Hence it will give you a hint what Apps might be involved in the activity." +
"\n\nHow do you interpret these results? Lets look at an example:\n\n")
.centered(.image(sampleCell))
.normal("\n\nThe domain ").bold("example.org").normal(" had ").bold("14").normal(" requests with an ").italic("average time divergence").normal(" of ").bold("0.71 seconds").normal(". " +
"That is, these 14 domain calls happend, on average, less then a second before or after the original request of the selected domain." +
"\n\nClose temporal proximity and high occurrence counts are both indicators for domain correlation. " +
"Results are sorted by a ranking index (").bold("9.").normal(") which strikes a balance between the two. " +
"Preferring entries with higher counts as well as low time divergence.")
.italic("\n\nTip: ").normal("As a visual guide you can look for the colored bar beside each value. " +
"The larger the bar, the greater the correlation.")
))
x.present(in: self)
}
}

View File

@@ -1,41 +1,85 @@
import UIKit
class TVCDomains: UITableViewController, IncrementalDataSourceUpdate {
class TVCDomains: UITableViewController, UISearchBarDelegate, GroupedDomainDataSourceDelegate {
internal var dataSource: [GroupedDomain] = []
lazy var source = GroupedDomainDataSource(withParent: nil)
@IBOutlet private var filterButton: UIBarButtonItem!
@IBOutlet private var filterButtonDetail: UIBarButtonItem!
override func viewDidLoad() {
super.viewDidLoad()
if #available(iOS 10.0, *) {
tableView.refreshControl = UIRefreshControl(call: #selector(reloadDataSource), on: self)
}
NotifyLogHistoryReset.observe(call: #selector(reloadDataSource), on: self)
reloadDataSource()
DBWrp.dataA_delegate = self
NotifyDateFilterChanged.observe(call: #selector(didChangeDateFilter), on: self)
didChangeDateFilter()
source.delegate = self // init lazy var, ready for tableView data source
}
@objc func reloadDataSource() {
dataSource = DBWrp.listOfDomains()
tableView.reloadData()
override func viewDidAppear(_ animated: Bool) {
// iOS 11+ fix: fuse after `didAppear` to hide on app launch
source.search.fuseWith(tableViewController: self)
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if let index = tableView.indexPathForSelectedRow?.row {
(segue.destination as? TVCHosts)?.parentDomain = dataSource[index].domain
(segue.destination as? TVCHosts)?.parentDomain = source[index].domain
}
}
func pushOpen(domain: String) {
let A: TVCHosts = storyboard!.load("requestsHosts")
let B: TVCHostDetails = storyboard!.load("requestsOccurrences")
A.parentDomain = domain.extractDomain()
B.fullDomain = domain
navigationController?.pushViewController(A, animated: false)
navigationController?.pushViewController(B, animated: false)
}
// MARK: - Filter
@IBAction private func filterButtonTapped(_ sender: UIBarButtonItem) {
let vc = storyboard!.load("domainFilter")
vc.modalPresentationStyle = .custom
if #available(iOS 13.0, *) {
vc.isModalInPresentation = true
}
present(vc, animated: true)
}
@objc private func didChangeDateFilter() {
switch Prefs.DateFilter.Kind {
case .ABRange: // read start/end time
self.filterButtonDetail.title = "AB"
self.filterButton.image = UIImage(named: "filter-filled")
case .LastXMin: // most recent
let lastXMin = Prefs.DateFilter.LastXMin
if lastXMin == 0 { fallthrough }
self.filterButtonDetail.title = TimeFormat(.abbreviated).from(minutes: lastXMin)
self.filterButton.image = UIImage(named: "filter-filled")
default:
self.filterButtonDetail.title = ""
self.filterButton.image = UIImage(named: "filter-clear")
}
}
// MARK: - Table View Delegate
// MARK: - Table View Data Source
override func tableView(_ _: UITableView, numberOfRowsInSection _: Int) -> Int { dataSource.count }
override func tableView(_ _: UITableView, numberOfRowsInSection _: Int) -> Int { source.numberOfRows }
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "DomainCell")!
let entry = dataSource[indexPath.row]
let entry = source[indexPath.row]
cell.textLabel?.text = entry.domain
cell.detailTextLabel?.text = entry.detailCellText
cell.imageView?.image = entry.options?.tableRowImage()
return cell
}
func groupedDomainDataSource(needsUpdate row: Int) {
let entry = source[row]
let cell = tableView.cellForRow(at: IndexPath(row: row))
cell?.detailTextLabel?.text = entry.detailCellText
cell?.imageView?.image = entry.options?.tableRowImage()
}
}

View File

@@ -1,32 +1,99 @@
import UIKit
class TVCHostDetails: UITableViewController {
class TVCHostDetails: UITableViewController, SyncUpdateDelegate, AnalysisBarDelegate {
public var fullDomain: String!
private var dataSource: [(ts: Timestamp, blocked: Bool)] = []
private var dataSource: [GroupedTsOccurrence] = []
// TODO: respect date reverse sort order
override func viewDidLoad() {
super.viewDidLoad()
navigationItem.prompt = fullDomain
super.viewDidLoad()
sync.addObserver(self) // calls `syncUpdate(reset:)`
if #available(iOS 10.0, *) {
tableView.refreshControl = UIRefreshControl(call: #selector(reloadDataSource), on: self)
sync.allowPullToRefresh(onTVC: self, forObserver: self)
}
NotifyLogHistoryReset.observe(call: #selector(reloadDataSource), on: self)
reloadDataSource()
}
@objc func reloadDataSource() {
dataSource = DBWrp.listOfTimes(fullDomain)
tableView.reloadData()
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if let index = tableView.indexPathForSelectedRow?.row {
let tvc = segue.destination as? TVCOccurrenceContext
tvc?.domain = fullDomain
tvc?.ts = dataSource[index].ts
}
}
override func tableView(_ _: UITableView, numberOfRowsInSection _: Int) -> Int { dataSource.count }
func analysisBarWillOpenCoOccurrence() -> (domain: String, isFQDN: Bool) {
(fullDomain, true)
}
// MARK: - Table View Data Source
override func tableView(_: UITableView, numberOfRowsInSection _: Int) -> Int { dataSource.count }
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "HostDetailCell")!
let src = dataSource[indexPath.row]
cell.textLabel?.text = dateTimeFormat.string(from: src.ts)
cell.imageView?.image = (src.blocked ? UIImage(named: "shield-x") : nil)
cell.textLabel?.text = DateFormat.seconds(src.ts)
cell.detailTextLabel?.text = (src.total > 1) ? "\(src.total)×" : nil
cell.imageView?.image = (src.blocked > 0 ? UIImage(named: "shield-x") : nil)
return cell
}
}
// ################################
// #
// # MARK: - Partial Update
// #
// ################################
extension TVCHostDetails {
func syncUpdate(_ _: SyncUpdate, reset rows: SQLiteRowRange) {
dataSource = AppDB?.timesForDomain(fullDomain, range: rows) ?? []
DispatchQueue.main.sync { tableView.reloadData() }
}
func syncUpdate(_ _: SyncUpdate, insert rows: SQLiteRowRange, affects: SyncUpdateEnd) {
guard let latest = AppDB?.timesForDomain(fullDomain, range: rows), latest.count > 0 else {
return
}
// Assuming they are ordered by ts and in descending order
let range: Range<Int>
switch affects {
case .Earliest:
range = dataSource.endIndex..<(dataSource.endIndex + latest.count)
dataSource.append(contentsOf: latest)
case .Latest:
range = dataSource.startIndex..<(dataSource.startIndex + latest.count)
dataSource.insert(contentsOf: latest, at: 0)
}
DispatchQueue.main.sync { tableView.safeInsertRows(range, with: .left) }
}
func syncUpdate(_ sender: SyncUpdate, remove _: SQLiteRowRange, affects: SyncUpdateEnd) {
// Assuming they are ordered by ts and in descending order
let range: Range<Int>
switch affects {
case .Earliest:
guard let t = sender.tsEarliest,
let i = dataSource.lastIndex(where: { $0.ts >= t }),
(i+1) < dataSource.count else { return }
range = (i+1)..<dataSource.endIndex
dataSource.removeLast(dataSource.count - (i+1))
case .Latest:
guard let t = sender.tsLatest,
let i = dataSource.firstIndex(where: { $0.ts <= t }),
i > 0 else { return }
range = dataSource.startIndex..<i
dataSource.removeFirst(i)
}
DispatchQueue.main.sync { tableView.safeDeleteRows(range) }
}
func syncUpdate(_ sender: SyncUpdate, partialRemove affectedDomain: String) {
if fullDomain.isSubdomain(of: affectedDomain) {
syncUpdate(sender, reset: sender.rows)
}
}
}

View File

@@ -1,45 +1,38 @@
import UIKit
class TVCHosts: UITableViewController, IncrementalDataSourceUpdate {
class TVCHosts: UITableViewController, GroupedDomainDataSourceDelegate, AnalysisBarDelegate {
lazy var source = GroupedDomainDataSource(withParent: parentDomain)
public var parentDomain: String!
internal var dataSource: [GroupedDomain] = []
private var isSpecial: Bool = false
override func viewDidLoad() {
super.viewDidLoad()
navigationItem.prompt = parentDomain
super.viewDidLoad()
isSpecial = (parentDomain.first == "#") // aka: "# IP address"
if #available(iOS 10.0, *) {
tableView.refreshControl = UIRefreshControl(call: #selector(reloadDataSource), on: self)
}
NotifyLogHistoryReset.observe(call: #selector(reloadDataSource), on: self)
reloadDataSource()
DBWrp.currentlyOpenParent = parentDomain
DBWrp.dataB_delegate = self
}
deinit {
DBWrp.currentlyOpenParent = nil
}
@objc func reloadDataSource() {
dataSource = DBWrp.listOfHosts(parentDomain)
tableView.reloadData()
source.delegate = self // init lazy var, ready for tableView data source
source.search.fuseWith(tableViewController: self)
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if let index = tableView.indexPathForSelectedRow?.row {
(segue.destination as? TVCHostDetails)?.fullDomain = dataSource[index].domain
(segue.destination as? TVCHostDetails)?.fullDomain = source[index].domain
}
}
// MARK: - Data Source
func analysisBarWillOpenCoOccurrence() -> (domain: String, isFQDN: Bool) {
(parentDomain, false)
}
override func tableView(_ _: UITableView, numberOfRowsInSection _: Int) -> Int { dataSource.count }
// MARK: - Table View Data Source
override func tableView(_ _: UITableView, numberOfRowsInSection _: Int) -> Int { source.numberOfRows }
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "HostCell")!
let entry = dataSource[indexPath.row]
let entry = source[indexPath.row]
if isSpecial {
// currently only used for IP addresses
cell.textLabel?.text = entry.domain
@@ -51,4 +44,11 @@ class TVCHosts: UITableViewController, IncrementalDataSourceUpdate {
cell.imageView?.image = entry.options?.tableRowImage()
return cell
}
func groupedDomainDataSource(needsUpdate row: Int) {
let entry = source[row]
let cell = tableView.cellForRow(at: IndexPath(row: row))
cell?.detailTextLabel?.text = entry.detailCellText
cell?.imageView?.image = entry.options?.tableRowImage()
}
}

Some files were not shown because too many files have changed in this diff Show More