1- using System ;
2- using System . Collections . Generic ;
3- using System . Net . Http ;
4- using System . Net . Http . Headers ;
5- using System . Threading . Tasks ;
1+ using System ;
62
73namespace AssistantComputerControl {
84 class AnalyticsSettings {
9- const string sendDataUrl = "https://acc.albe.pw/api/ReceiveAnalyticsData.php" ;
10- const string sendSharingUrl = "https://acc.albe.pw/api/IsSharing.php" ;
11- public const string sentryToken = "https://[email protected] /1287269" ; 12- private static readonly HttpClient client = new HttpClient ( ) ;
5+ //ACC truly is open source, but for security reasons we will not share this one file with the whole world.
6+ //This file handles sending analytics to the developers' webserver and contains a few variables that contain -
7+ //sensitive access-tokens to integrations like Sentry.IO
8+
9+ //The public version of this file is exactly like the full version, but stripped of -
10+ //API-keys and sensitive information.
11+ //Cencored items have placeholders to ensure that everyone can fork and run the project without errors
12+ public const string sentryToken = "super_secret" ;
1313
1414 public static readonly string [ ] actions = new String [ ] { //No changing this order!
1515 "shutdown" , //0
@@ -43,31 +43,13 @@ class AnalyticsSettings {
4343 "unknown" ,
4444 } ;
4545
46- public static void UpdateSharing ( bool doShare ) {
47- Properties . Settings . Default . SendAnonymousAnalytics = doShare ;
48- Properties . Settings . Default . Save ( ) ;
49-
50- //Notify server whether
51- client . DefaultRequestHeaders . Authorization = new AuthenticationHeaderValue ( "Bearer" , @"jmF}AXK6NH!#{@/:ZHV#qK6r#YxytM>K/W6#5q/}tEK!&*_Gd\_YNUBNN/$a+$r" ) ;
52-
53- var parameters = new Dictionary < string , string > {
54- [ "uid" ] = Properties . Settings . Default . UID ,
55- [ "share" ] = doShare ? "true" : "false"
56- } ;
57-
58- try {
59- var response = client . PostAsync ( sendSharingUrl , new FormUrlEncodedContent ( parameters ) ) . Result ;
60- var contents = response . Content . ReadAsStringAsync ( ) . Result ;
61- MainProgram . DoDebug ( "Posted user response" ) ;
62- } catch ( Exception e ) {
63- MainProgram . DoDebug ( "Failed to send analytics data - something wrong with the server?" ) ;
64- MainProgram . DoDebug ( e . ToString ( ) ) ;
65- }
66-
67- SetupAnalytics ( ) ;
46+ class KeyHandler {
47+ public bool Status { get ; set ; }
48+ public string Message { get ; set ; }
49+ public string Key { get ; set ; }
6850 }
69-
70- public static void SetupAnalytics ( ) {
51+
52+ public static void SetupAnalyticsAsync ( ) {
7153 //Unique user-ID
7254 if ( Properties . Settings . Default . UID == "" || Properties . Settings . Default . UID == null ) {
7355 string newUID = Guid . NewGuid ( ) . ToString ( "N" ) ;
@@ -97,12 +79,12 @@ public static void SetupAnalytics() {
9779
9880 //Populate new analytics array with old values
9981 int i = 0 ;
100- foreach ( int ac in oldSettings ) {
82+ foreach ( int ac in oldSettings ) {
10183 if ( i != newSettings . Length )
10284 newSettings [ i ] = ac ;
10385 i ++ ;
10486 }
105-
87+
10688 Properties . Settings . Default . TotalActionsExecuted = newSettings ;
10789 Properties . Settings . Default . Save ( ) ;
10890 }
@@ -113,22 +95,11 @@ public static void SetupAnalytics() {
11395 Properties . Settings . Default . Save ( ) ;
11496 }
11597
116- DateTime dateTime = DateTime . UtcNow . Date ;
117- string thisDay = dateTime . ToString ( "yyyy/MM/dd" ) ;
118- if ( Properties . Settings . Default . AnalyticsUnsentData && Properties . Settings . Default . AnalyticsThisDay == thisDay ) {
119- //Resume data for today
120- ScheduleAnalyticsSend ( ) ;
121- } else if ( Properties . Settings . Default . AnalyticsUnsentData && Properties . Settings . Default . AnalyticsThisDay != thisDay ) {
122- //Didn't send last time - sending now
123- SendAnalyticsData ( ) ;
124- }
125-
12698 MainProgram . DoDebug ( "Annonymous analytics setup done" ) ;
12799 } else {
128100 MainProgram . DoDebug ( "Annonymous analytics are not being shared" ) ;
129101 }
130102 }
131-
132103 public static void PrintAnalytics ( ) {
133104 int i = 0
134105 , totalCount = 0 ;
@@ -150,25 +121,17 @@ public static void AddCount(string action, string type) {
150121 if ( pos > - 1 ) {
151122 //MainProgram.DoDebug("Added +1 to " + action + " at pos " + pos);
152123 Properties . Settings . Default . TotalActionsExecuted [ pos ] ++ ;
153-
154- if ( ! Properties . Settings . Default . AnalyticsUnsentData ) {
155- Properties . Settings . Default . AnalyticsUnsentData = true ;
156- ScheduleAnalyticsSend ( ) ;
157- }
158124 Properties . Settings . Default . Save ( ) ;
159125 } else {
160126 MainProgram . DoDebug ( "Could not find action \" " + action + "\" in action-array (analytics)" ) ;
161127 }
128+
129+ SendAnalyticsData ( ) ;
162130 }
163131 public static void AddCount ( int action , string type ) {
164132 AddTypeCount ( type ) ;
165133 if ( actions [ action ] != null ) {
166134 Properties . Settings . Default . TotalActionsExecuted [ action ] ++ ;
167-
168- if ( ! Properties . Settings . Default . AnalyticsUnsentData ) {
169- Properties . Settings . Default . AnalyticsUnsentData = true ;
170- ScheduleAnalyticsSend ( ) ;
171- }
172135 Properties . Settings . Default . Save ( ) ;
173136 } else {
174137 MainProgram . DoDebug ( "Could not find action with index \" " + action + "\" in action-array (analytics)" ) ;
@@ -190,67 +153,14 @@ private static void AddTypeCount(string type) {
190153 }
191154 }
192155
193- static void ScheduleAnalyticsSend ( ) {
194- //Time when method needs to be called
195- MainProgram . DoDebug ( "Analytics scheduled to be sent at 00:00" ) ;
196-
197- DateTime dateTime = DateTime . UtcNow . Date ;
198- Properties . Settings . Default . AnalyticsThisDay = dateTime . ToString ( "yyyy/MM/dd" ) ;
199- Properties . Settings . Default . Save ( ) ;
200-
201- var DailyTime = "00:00:00" ;
202- var timeParts = DailyTime . Split ( new char [ 1 ] { ':' } ) ;
203-
204- var dateNow = DateTime . Now ;
205- var date = new DateTime ( dateNow . Year , dateNow . Month , dateNow . Day ,
206- int . Parse ( timeParts [ 0 ] ) , int . Parse ( timeParts [ 1 ] ) , int . Parse ( timeParts [ 2 ] ) ) ;
207- TimeSpan ts ;
208- if ( date > dateNow )
209- ts = date - dateNow ;
210- else {
211- date = date . AddDays ( 1 ) ;
212- ts = date - dateNow ;
213- }
214-
215- Task . Delay ( ts ) . ContinueWith ( ( x ) => SendAnalyticsData ( ) ) ;
216- }
217-
218156 public static string SendAnalyticsData ( ) {
157+ //Sends analytics data to the server
219158 if ( Properties . Settings . Default . SendAnonymousAnalytics ) {
220- if ( MainProgram . HasInternet ( ) ) {
221- client . DefaultRequestHeaders . Authorization = new AuthenticationHeaderValue ( "Bearer" , @"jmF}AXK6NH!#{@/:ZHV#qK6r#YxytM>K/W6#5q/}tEK!&*_Gd\_YNUBNN/$a+$r" ) ;
222-
223- var parameters = new Dictionary < string , string > {
224- [ "uid" ] = Properties . Settings . Default . UID ,
225- [ "actions" ] = string . Join ( "," , Properties . Settings . Default . TotalActionsExecuted ) ,
226- [ "assistants" ] = string . Join ( "," , Properties . Settings . Default . AssistantType ) ,
227- [ "start_with_windows" ] = Properties . Settings . Default . StartWithWindows ? "true" : "false" ,
228- [ "version" ] = MainProgram . softwareVersion ,
229- [ "beta_program" ] = Properties . Settings . Default . BetaProgram ? "true" : "false" ,
230- [ "date" ] = Properties . Settings . Default . AnalyticsThisDay
231- } ;
232-
233- try {
234- var response = client . PostAsync ( sendDataUrl , new FormUrlEncodedContent ( parameters ) ) . Result ;
235- var contents = response . Content . ReadAsStringAsync ( ) . Result ;
236-
237- //Success
238- Properties . Settings . Default . AnalyticsUnsentData = false ;
239- Properties . Settings . Default . Save ( ) ;
240- MainProgram . DoDebug ( "Analytics successfully posted" ) ;
241- return contents ;
242- } catch ( Exception e ) {
243- MainProgram . DoDebug ( "Failed to send analytics data - something wrong with the server?" ) ;
244- MainProgram . DoDebug ( e . ToString ( ) ) ;
245- return "" ;
246- }
247- } else {
248- MainProgram . DoDebug ( "Failed to send analytics data; no internet connection" ) ;
249- return "" ;
250- }
159+ //Do it (sensitive code)
251160 } else {
252- return "" ;
161+ //Don't do it (does nothing here)
253162 }
163+ return "" ;
254164 }
255165 }
256- }
166+ }
0 commit comments