diff options
-rw-r--r-- | src/remmina_pref.c | 16 | ||||
-rw-r--r-- | src/remmina_pref.h | 2 | ||||
-rw-r--r-- | src/remmina_stats.c | 29 | ||||
-rw-r--r-- | src/remmina_sysinfo.c | 60 | ||||
-rw-r--r-- | src/remmina_sysinfo.h | 1 | ||||
-rw-r--r-- | src/remmina_utils.c | 32 | ||||
-rw-r--r-- | src/remmina_utils.h | 1 | ||||
-rw-r--r-- | src/rmnews.c | 57 |
8 files changed, 107 insertions, 91 deletions
diff --git a/src/remmina_pref.c b/src/remmina_pref.c index 3a36d28b2..5d0bea612 100644 --- a/src/remmina_pref.c +++ b/src/remmina_pref.c @@ -668,6 +668,16 @@ void remmina_pref_init(void) else remmina_pref.periodic_rmnews_last_get = 0; + if (g_key_file_has_key(gkeyfile, "remmina_news", "periodic_rmnews_get_count", NULL)) + remmina_pref.periodic_rmnews_get_count = g_key_file_get_int64(gkeyfile, "remmina_news", "periodic_rmnews_get_count", NULL); + else + remmina_pref.periodic_rmnews_get_count = 0; + + if (g_key_file_has_key(gkeyfile, "remmina_news", "periodic_rmnews_uuid_prefix", NULL)) + remmina_pref.periodic_rmnews_uuid_prefix = g_key_file_get_string(gkeyfile, "remmina_news", "periodic_rmnews_uuid_prefix", NULL); + else + remmina_pref.periodic_rmnews_uuid_prefix = NULL; + /* Default settings */ if (!g_key_file_has_key(gkeyfile, "remmina", "name", NULL)) { g_key_file_set_string(gkeyfile, "remmina", "name", ""); @@ -802,9 +812,13 @@ gboolean remmina_pref_save(void) g_key_file_set_boolean(gkeyfile, "usage_stats", "periodic_usage_stats_permitted", remmina_pref.periodic_usage_stats_permitted); g_key_file_set_int64(gkeyfile, "usage_stats", "periodic_usage_stats_last_sent", remmina_pref.periodic_usage_stats_last_sent); - g_key_file_set_int64(gkeyfile, "remmina_news", "periodic_rmnews_last_get", remmina_pref.periodic_rmnews_last_get); g_key_file_set_string(gkeyfile, "usage_stats", "periodic_usage_stats_uuid_prefix", remmina_pref.periodic_usage_stats_uuid_prefix ? remmina_pref.periodic_usage_stats_uuid_prefix : ""); + g_key_file_set_int64(gkeyfile, "remmina_news", "periodic_rmnews_last_get", remmina_pref.periodic_rmnews_last_get); + g_key_file_set_integer(gkeyfile, "remmina_news", "periodic_rmnews_get_count", remmina_pref.periodic_rmnews_get_count); + g_key_file_set_string(gkeyfile, "remmina_news", "periodic_rmnews_uuid_prefix", + remmina_pref.periodic_rmnews_uuid_prefix ? remmina_pref.periodic_rmnews_uuid_prefix : ""); + /* Default settings */ g_key_file_set_string(gkeyfile, "remmina", "name", ""); g_key_file_set_integer(gkeyfile, "remmina", "ignore-tls-errors", 1); diff --git a/src/remmina_pref.h b/src/remmina_pref.h index 5f5aa559b..de30ed8f4 100644 --- a/src/remmina_pref.h +++ b/src/remmina_pref.h @@ -204,6 +204,8 @@ typedef struct _RemminaPref { /* Remmina news */ glong periodic_rmnews_last_get; + glong periodic_rmnews_get_count; + gchar *periodic_rmnews_uuid_prefix; } RemminaPref; diff --git a/src/remmina_stats.c b/src/remmina_stats.c index 4fb494f86..f5cf8072c 100644 --- a/src/remmina_stats.c +++ b/src/remmina_stats.c @@ -170,33 +170,6 @@ struct ProfilesData { gchar datestr; }; -static gchar* remmina_stats_gen_random_uuid_prefix() -{ - TRACE_CALL(__func__); - GRand *rand; - GTimeVal t; - gchar *result; - int i; - static char alpha[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; - - result = g_malloc0(15); - - g_get_current_time(&t); - rand = g_rand_new_with_seed((guint32)t.tv_sec ^ (guint32)t.tv_usec); - - for (i = 0; i < 7; i++) { - result[i] = alpha[g_rand_int_range(rand, 0, sizeof(alpha) - 1)]; - } - - g_rand_set_seed(rand, (guint32)t.tv_usec); - for (i = 0; i < 7; i++) { - result[i + 7] = alpha[g_rand_int_range(rand, 0, sizeof(alpha) - 1)]; - } - g_rand_free(rand); - - return result; -} - JsonNode *remmina_stats_get_uid() { TRACE_CALL(__func__); @@ -213,7 +186,7 @@ JsonNode *remmina_stats_get_uid() if (remmina_pref.periodic_usage_stats_uuid_prefix == NULL || remmina_pref.periodic_usage_stats_uuid_prefix[0] == 0) { /* Generate a new UUID_PREFIX for this installation */ - uid_prefix = remmina_stats_gen_random_uuid_prefix(); + uid_prefix = remmina_gen_random_uuid(); if (remmina_pref.periodic_usage_stats_uuid_prefix) g_free(remmina_pref.periodic_usage_stats_uuid_prefix); remmina_pref.periodic_usage_stats_uuid_prefix = uid_prefix; diff --git a/src/remmina_sysinfo.c b/src/remmina_sysinfo.c index bec4d6966..dd0afb9be 100644 --- a/src/remmina_sysinfo.c +++ b/src/remmina_sysinfo.c @@ -154,63 +154,3 @@ gchar *remmina_sysinfo_get_wm_name() } return ret; } - -/** - * Try to get a unique system+user ID to identify this remmina user - * and avoid some duplicated task, especially on news management - * @return a string - * @warning The returned string must be freed with g_free. - */ -gchar *remmina_sysinfo_get_unique_user_id() -{ - unsigned long long uid, sddinodenumber, machineid, id; - struct stat sb; - const gchar * const * sdd; - int fdmid, i; - gchar *buf; - - uid = (unsigned long long)getuid(); - - fdmid = open("/etc/machine-id", O_RDONLY, 0); - machineid = 0; - if (fdmid >= 0) { - /* According to freedesktop specs, machine-id is a 32char hex string - * representing a 128bits value. We are fitting it into a 64bit - valie (machineid)*/ - buf = g_malloc(32); - if (read(fdmid, buf, 32) == 32) { - for(i = 0; i < 32; i++) { - char c; - unsigned char b; - c = buf[i]; - if (c >= '0' && c <= '9') - b = c - '0'; - else if (c >= 'A' && c <= 'F') - b = c - 'A' + 10; - else if (c >= 'a' && c <= 'f') - b = c - 'a' + 10; - else - b = 0; - machineid = ((machineid >> 60) | (machineid << 4)) ^ b; - } - } - close(fdmid); - g_free(buf); - } - - /* Get the 1st inode number of g_get_system_data_dirs() */ - sdd = g_get_system_data_dirs(); - sddinodenumber = 0; - if (sdd != NULL && sdd[0] != NULL) { - if ( stat(sdd[0], &sb) == 0 ) { - sddinodenumber = (unsigned long long)sb.st_ino; - } - } - - /* Mix up the three value in a irreversible way */ - id = machineid ^ uid << 32 ^ sddinodenumber; - - /* First 2 chars before '-' are the version number of IDs */ - return g_strdup_printf("01-%llu", id); - -} diff --git a/src/remmina_sysinfo.h b/src/remmina_sysinfo.h index 2980f7ff6..d0349f1d1 100644 --- a/src/remmina_sysinfo.h +++ b/src/remmina_sysinfo.h @@ -41,7 +41,6 @@ G_BEGIN_DECLS gboolean remmina_sysinfo_is_appindicator_available(void); gchar *remmina_sysinfo_get_gnome_shell_version(void); gchar *remmina_sysinfo_get_wm_name(void); -gchar *remmina_sysinfo_get_unique_user_id(void); G_END_DECLS diff --git a/src/remmina_utils.c b/src/remmina_utils.c index 779a7ecd7..bf44852bf 100644 --- a/src/remmina_utils.c +++ b/src/remmina_utils.c @@ -500,3 +500,35 @@ gchar* remmina_sha1_file (const gchar *filename) return digest; } + +/** + * Generate a random sting of chars to be used as part of UID for news or stats + * @return a string or NULL. Caller must free it with g_free(). + */ +gchar* remmina_gen_random_uuid() +{ + TRACE_CALL(__func__); + GRand *rand; + GTimeVal t; + gchar *result; + int i; + static char alpha[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; + + result = g_malloc0(15); + + g_get_current_time(&t); + rand = g_rand_new_with_seed((guint32)t.tv_sec ^ (guint32)t.tv_usec); + + for (i = 0; i < 7; i++) { + result[i] = alpha[g_rand_int_range(rand, 0, sizeof(alpha) - 1)]; + } + + g_rand_set_seed(rand, (guint32)t.tv_usec); + for (i = 0; i < 7; i++) { + result[i + 7] = alpha[g_rand_int_range(rand, 0, sizeof(alpha) - 1)]; + } + g_rand_free(rand); + + return result; +} + diff --git a/src/remmina_utils.h b/src/remmina_utils.h index 4ac6be477..e4e581070 100644 --- a/src/remmina_utils.h +++ b/src/remmina_utils.h @@ -56,4 +56,5 @@ gchar *remmina_utils_get_lsb_codename(); GHashTable *remmina_utils_get_etc_release(); const gchar *remmina_utils_get_os_info(); gchar *remmina_sha1_file(const gchar *filename); +gchar* remmina_gen_random_uuid(); G_END_DECLS diff --git a/src/rmnews.c b/src/rmnews.c index 81b3964f1..c337b0882 100644 --- a/src/rmnews.c +++ b/src/rmnews.c @@ -54,6 +54,7 @@ #include "remmina_utils.h" #include "remmina_scheduler.h" #include "remmina_stats_sender.h" +#include "remmina_stats.h" #include "remmina_sysinfo.h" #include "rmnews.h" @@ -339,11 +340,52 @@ static void rmnews_get_url_cb(SoupSession *session, SoupMessage *msg, gpointer d g_get_current_time(&t); remmina_pref.periodic_rmnews_last_get = t.tv_sec; } + /* Increase counter with number of successful GETs */ + remmina_pref.periodic_rmnews_get_count = remmina_pref.periodic_rmnews_get_count + 1; remmina_pref_save(); } } g_object_unref(msg); } +/** + * Try to get a unique system+user ID to identify this remmina user + * and avoid some duplicated task, especially on news management + * @return a string + * @warning The returned string must be freed with g_free. + */ +gchar *rmnews_get_uid() +{ + TRACE_CALL(__func__); + GChecksum *chs; + const gchar *uname, *hname; + const gchar *uid_suffix; + gchar *uid_prefix; + gchar *uid; + + /* This code is very similar to remmina_stats_get_uid() */ + + if (remmina_pref.periodic_rmnews_uuid_prefix == NULL || remmina_pref.periodic_rmnews_uuid_prefix[0] == 0) { + /* Generate a new UUID_PREFIX for news on this installation */ + uid_prefix = remmina_gen_random_uuid(); + if (remmina_pref.periodic_rmnews_uuid_prefix) + g_free(remmina_pref.periodic_rmnews_uuid_prefix); + remmina_pref.periodic_rmnews_uuid_prefix = uid_prefix; + remmina_pref_save(); + } + + uname = g_get_user_name(); + hname = g_get_host_name(); + chs = g_checksum_new(G_CHECKSUM_SHA256); + g_checksum_update(chs, (const guchar*)uname, strlen(uname)); + g_checksum_update(chs, (const guchar*)hname, strlen(hname)); + uid_suffix = g_checksum_get_string(chs); + + uid = g_strdup_printf("02-%s-%.10s", remmina_pref.periodic_rmnews_uuid_prefix, uid_suffix); + g_checksum_free(chs); + + return uid; +} + void rmnews_get_url(const char *url) { @@ -367,7 +409,9 @@ void rmnews_get_news() SoupLogger *logger = NULL; int fd; gchar *uid; + gchar mage[20], gcount[20]; gboolean sa; + struct stat sb; gchar *cachedir = g_build_path("/", g_get_user_cache_dir(), REMMINA_APP_ID, NULL); gint d = g_mkdir_with_parents(cachedir, 0750); @@ -409,7 +453,7 @@ void rmnews_get_news() gchar *lang = remmina_utils_get_lang(); g_debug("Language %s", lang); - uid = remmina_sysinfo_get_unique_user_id(); + uid = rmnews_get_uid(); sa = FALSE; if (remmina_pref.periodic_usage_stats_permitted && @@ -418,6 +462,13 @@ void rmnews_get_news() sa = TRUE; } + if (stat("/etc/machine-id", &sb) == 0) + sprintf(mage, "%ld", (long)(time(NULL) - sb.st_mtim.tv_sec)); + else + strcpy(mage, "0"); + + sprintf(gcount, "%ld", remmina_pref.periodic_rmnews_get_count); + rmnews_get_url(g_strconcat(REMMINA_URL, "news/remmina_news.php?lang=", lang, @@ -427,6 +478,10 @@ void rmnews_get_news() uid, "&sa=", sa ? "1" : "0", + "&mage=", + mage, + "&gcount=", + gcount, NULL)); g_free(uid); |