Skip to content

Commit

Permalink
Updated AnalyticsSettings.cs to v1.1.0 standards
Browse files Browse the repository at this point in the history
Due to security reasons this file is not being shared in its entirety. The code is stripped from all API-tokens and the entire function handling sending analytics data to the ACC webserver. All censored content has been replaced with dummy code, making sure ACC still works if you use this file (if you fork the project).
  • Loading branch information
AlbertMN authored Sep 24, 2018
1 parent 8903be5 commit 5aa5689
Showing 1 changed file with 37 additions and 37 deletions.
74 changes: 37 additions & 37 deletions AssistantComputerControl/AnalyticsSettings.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;

namespace AssistantComputerControl {
class AnalyticsSettings {
//private static string requestKey = null; // < version 1.1
const string getKeyUrl = "https://acc.albe.pw/functions/ReceiveAnalyticsData.php";
const string sendDataUrl = "https://acc.albe.pw/functions/ReceiveAnalyticsData.php";
private static readonly HttpClient client = new HttpClient();
//ACC truly is open source, but for security reasons we will not share this one file with the whole world.
//This file handles sending analytics to the developers' webserver and contains a few variables that contain -
//sensitive access-tokens to integrations like Sentry.IO

public static readonly string[] actions = new String[13] { //No changing this order!
//The public version of this file is exactly like the full version, but stripped of -
//API-keys and sensitive information.
//Cencored items have placeholders to ensure that everyone can fork and run the project without errors
public const string sentryToken = "super_secret";

public static readonly string[] actions = new String[] { //No changing this order!
"shutdown", //0
"restart", //1
"open", //2
Expand All @@ -29,9 +25,18 @@ class AnalyticsSettings {
"next_song", //10
"die", //11
"hibernate", //12
"monitors_off", //13
"keypress", //14
"write_out", //15

"key_shortcut", //16
"create_file", //17
"delete_file", //18
"append_text", //19
"message_box", //20
};

public static readonly string[] assistants = new String[4] { //No changing this order!
public static readonly string[] assistants = new String[] { //No changing this order!
"google",
"alexa",
"cortana",
Expand All @@ -43,7 +48,7 @@ class KeyHandler {
public string Message { get; set; }
public string Key { get; set; }
}

public static void SetupAnalyticsAsync() {
//Unique user-ID
if (Properties.Settings.Default.UID == "" || Properties.Settings.Default.UID == null) {
Expand All @@ -66,19 +71,20 @@ public static void SetupAnalyticsAsync() {

int[] actionsExecuted = Properties.Settings.Default.TotalActionsExecuted;
if (actions.Length != actionsExecuted.Length) {
MainProgram.DoDebug(actions.Length + "!= " + actionsExecuted.Length);
//MainProgram.DoDebug(actions.Length + " != " + actionsExecuted.Length);

//New action most likely added
int[] oldSettings = actionsExecuted
, newSettings = new int[actions.Length];

//Populate new analytics array with old values
int i = 0;
foreach(int ac in oldSettings) {
newSettings[i] = ac;
foreach (int ac in oldSettings) {
if (i != newSettings.Length)
newSettings[i] = ac;
i++;
}

Properties.Settings.Default.TotalActionsExecuted = newSettings;
Properties.Settings.Default.Save();
}
Expand All @@ -94,7 +100,6 @@ public static void SetupAnalyticsAsync() {
MainProgram.DoDebug("Annonymous analytics are not being shared");
}
}

public static void PrintAnalytics() {
int i = 0
, totalCount = 0;
Expand All @@ -114,11 +119,14 @@ public static void AddCount(string action, string type) {
AddTypeCount(type);
int pos = Array.IndexOf(actions, action);
if (pos > -1) {
//MainProgram.DoDebug("Added +1 to " + action + " at pos " + pos);
Properties.Settings.Default.TotalActionsExecuted[pos]++;
Properties.Settings.Default.Save();
} else {
MainProgram.DoDebug("Could not find action \"" + action + "\" in action-array (analytics)");
}

SendAnalyticsData();
}
public static void AddCount(int action, string type) {
AddTypeCount(type);
Expand All @@ -145,22 +153,14 @@ private static void AddTypeCount(string type) {
}
}

/*public static async System.Threading.Tasks.Task SendDataAsync() { // < for version 1.1
if (ACC_Updater.RemoteFileExists(sendDataUrl)) {
using (var wb = new WebClient()) {
var values = new Dictionary<string, string> {
{ "actions_executed", JsonConvert.SerializeObject(Properties.Settings.Default.TotalActionsExecuted) },
{ "thing2", "world" }
};
var content = new FormUrlEncodedContent(values);
var response = await client.PostAsync("http://www.example.com/recepticle.aspx", content);
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", "Your Oauth token");
var responseString = await response.Content.ReadAsStringAsync();
}
public static string SendAnalyticsData() {
//Sends analytics data to the server
if (Properties.Settings.Default.SendAnonymousAnalytics) {
//Do it (sensitive code)
} else {
//Don't do it (does nothing here)
}
}*/
return "";
}
}
}
}

0 comments on commit 5aa5689

Please sign in to comment.