From 64ed933361957230b3896cbe60e89d6ddf6357eb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Kevin=20R=C3=B6bert?=
Date: Fri, 31 Aug 2018 20:55:15 +0200
Subject: [PATCH] New Feature - Report URLs
Lately, I have received relatively few requests with potentially bad URLs. On the one hand, that could be because ClearURLs are working very well by now. But I also think that not everyone wants to sign up to GitLab to report a URL. That's why I've added a new button that reports the current URL in the active tab to me, so I can take a closer look at the URL.
So that you can see exactly what data will be sent to me, I have uploaded the source code for the PHP script, of course, without a password etc.
Please be careful not to send URLs with personal information or tokens.
---
_locales/de/messages.json | 25 +++++++++++++++++++++++++
_locales/en/messages.json | 25 +++++++++++++++++++++++++
clearurls.js | 15 +++++++++++++++
core_js/popup_new.js | 22 ++++++++++++++++++++++
core_js/settings.js | 4 ++++
html/popup.html | 15 +++++++++++----
html/settings.html | 5 +++++
manifest.json | 2 +-
server/report_url.php | 35 +++++++++++++++++++++++++++++++++++
9 files changed, 143 insertions(+), 5 deletions(-)
create mode 100644 server/report_url.php
diff --git a/_locales/de/messages.json b/_locales/de/messages.json
index 45186e2..3a71bf2 100644
--- a/_locales/de/messages.json
+++ b/_locales/de/messages.json
@@ -154,6 +154,16 @@
"description": ""
},
+ "popup_html_report_button": {
+ "message": "Aktuelle URL melden",
+ "description": ""
+ },
+
+ "popup_html_report_button_title": {
+ "message": "Meldet die aktuelle URL aus diesem Tab.",
+ "description": ""
+ },
+
"core_save_on_disk": {
"message": "[ClearURLs]: Auf Festplatte gespeichert.",
"description": ""
@@ -217,5 +227,20 @@
"setting_types_label": {
"message": "Request types (Expertenniveau)",
"description": ""
+ },
+
+ "setting_report_server_label": {
+ "message": "Meldungsserver für URLs",
+ "description": ""
+ },
+
+ "success_report_url": {
+ "message": "Die URL wurde erfolgreich gemeldet. Wir werden sie in Kürze prüfen.",
+ "description": ""
+ },
+
+ "error_report_url": {
+ "message": "Es schaut so aus, als ob diese URL schon gemeldet wurde.",
+ "description": ""
}
}
diff --git a/_locales/en/messages.json b/_locales/en/messages.json
index b8c1460..855eeaa 100644
--- a/_locales/en/messages.json
+++ b/_locales/en/messages.json
@@ -154,6 +154,16 @@
"description": ""
},
+ "popup_html_report_button": {
+ "message": "Report current URL",
+ "description": ""
+ },
+
+ "popup_html_report_button_title": {
+ "message": "Report the current URL from this tab.",
+ "description": ""
+ },
+
"core_save_on_disk": {
"message": "[ClearURLs]: Save on disk.",
"description": ""
@@ -217,5 +227,20 @@
"setting_types_label": {
"message": "Request types (expert level)",
"description": ""
+ },
+
+ "setting_report_server_label": {
+ "message": "Report server for URLs",
+ "description": ""
+ },
+
+ "success_report_url": {
+ "message": "The URL was successfully reported. We will check this URL soon.",
+ "description": ""
+ },
+
+ "error_report_url": {
+ "message": "It seems like this URL has already been reported.",
+ "description": ""
}
}
diff --git a/clearurls.js b/clearurls.js
index a046205..e3f7440 100644
--- a/clearurls.js
+++ b/clearurls.js
@@ -11,6 +11,7 @@ var siteBlockedAlert = 'javascript:void(0)';
var dataHash;
var localDataHash;
var os;
+var currentURL;
var storage = [];
@@ -580,6 +581,7 @@ function start(items)
{
delete badges[tabId];
}
+ currentURL = tabInfo.url;
}
/**
@@ -592,6 +594,9 @@ function start(items)
*/
function handleActivated(activeInfo) {
tabid = activeInfo.tabId;
+ browser.tabs.get(tabid).then(function (tab) {
+ currentURL = tab.url;
+ });
}
/**
@@ -840,6 +845,7 @@ function initSettings()
storage.hashURL = "https://gitlab.com/KevinRoebert/ClearUrls/raw/master/data/rules.hash";
storage.ruleURL = "https://gitlab.com/KevinRoebert/ClearUrls/raw/master/data/data.json";
storage.types = ["main_frame", "sub_frame", "xmlhttprequest"];
+ storage.reportServer = "https://clearurls.xn--rb-fka.it";
}
/**
@@ -875,3 +881,12 @@ function isEmpty(obj)
{
return (Object.getOwnPropertyNames(obj).length === 0);
}
+
+/**
+ * Returns the current URL.
+ * @return {String} [description]
+ */
+function getCurrentURL()
+{
+ return currentURL;
+}
diff --git a/core_js/popup_new.js b/core_js/popup_new.js
index 3b08b56..b2e94e5 100644
--- a/core_js/popup_new.js
+++ b/core_js/popup_new.js
@@ -11,6 +11,8 @@ var badgedStatus;
var hashStatus;
var loggingStatus;
var statisticsStatus;
+var currentURL;
+var reportServer;
var core = function (func) {
return browser.runtime.getBackgroundPage().then(func);
@@ -26,6 +28,8 @@ function getData()
hashStatus = ref.getData('hashStatus');
loggingStatus = ref.getData('loggingStatus');
statisticsStatus = ref.getData('statisticsStatus');
+ currentURL = ref.getCurrentURL();
+ reportServer = ref.getData('reportServer');
});
}
@@ -174,6 +178,7 @@ $(document).ready(function(){
changeSwitchButton("statistics", "statisticsStatus");
$('#loggingPage').attr('href', browser.extension.getURL('./html/log.html'));
$('#settings').attr('href', browser.extension.getURL('./html/settings.html'));
+ $('#reportButton').on("click", reportURL);
setText();
} else {
$('#config_section').remove();
@@ -202,6 +207,7 @@ function setText()
injectText('configs_switch_filter','popup_html_configs_switch_filter');
injectText('configs_head','popup_html_configs_head');
injectText('configs_switch_statistics','configs_switch_statistics');
+ injectText('reportButton', 'popup_html_report_button', true);
}
/**
@@ -237,3 +243,19 @@ function translate(string)
{
return browser.i18n.getMessage(string);
}
+
+/**
+ * Send the url to the DB on clearurls.röb.it to checked for tracking fields.
+ */
+function reportURL()
+{
+ $.ajax({
+ url: reportServer+'/report_url.php?url='+encodeURI(currentURL),
+ success: function(result) {
+ window.alert(translate('success_report_url'));
+ },
+ error: function(result) {
+ window.alert(translate('error_report_url'));
+ }
+ });
+}
diff --git a/core_js/settings.js b/core_js/settings.js
index 52dfd07..a88e5a9 100644
--- a/core_js/settings.js
+++ b/core_js/settings.js
@@ -49,6 +49,7 @@ function save()
ref.setData('ruleURL', $('input[name=rule_url]').val());
ref.setData('hashURL', $('input[name=hash_url]').val());
ref.setData('types', $('input[name=types]').val());
+ ref.setData('reportServer', $('input[name=report_server]').val());
ref.saveOnExit();
ref.reload();
});
@@ -76,6 +77,7 @@ function getData()
settings.rule_url = ref.getData('ruleURL');
settings.hash_url = ref.getData('hashURL');
settings.types = ref.getData('types');
+ settings.reportServer = ref.getData('reportServer');
});
}
@@ -98,4 +100,6 @@ function setText()
$('input[name=types]').val(settings.types);
$('#save_settings_btn').text(translate('settings_html_save_button'));
$('#save_settings_btn').prop('title', translate('settings_html_save_button_title'));
+ $('#report_server_label').html(translate('setting_report_server_label'));
+ $('input[name=report_server]').val(settings.reportServer);
}
diff --git a/html/popup.html b/html/popup.html
index 39eeb25..e9b48e6 100644
--- a/html/popup.html
+++ b/html/popup.html
@@ -133,12 +133,19 @@
-
+ class="btn btn-default btn-sm btn-block">
+
-
-
+
+
diff --git a/html/settings.html b/html/settings.html
index 517dab2..9144260 100644
--- a/html/settings.html
+++ b/html/settings.html
@@ -62,6 +62,11 @@
+
+
+
+
+
diff --git a/manifest.json b/manifest.json
index e861720..10c149f 100644
--- a/manifest.json
+++ b/manifest.json
@@ -1,7 +1,7 @@
{
"manifest_version": 2,
"name": "ClearURLs",
- "version": "1.3.3.11",
+ "version": "1.3.3.12",
"author": "Kevin R.",
"description": "Remove tracking elements form URLs.",
"homepage_url": "https://gitlab.com/KevinRoebert/ClearUrls",
diff --git a/server/report_url.php b/server/report_url.php
new file mode 100644
index 0000000..b9516a4
--- /dev/null
+++ b/server/report_url.php
@@ -0,0 +1,35 @@
+connect_error) {
+ http_response_code(505);
+ }
+
+ $sql = "INSERT INTO reports (hash, url) VALUES ('$hash', '$url')";
+
+ if ($conn->query($sql) === TRUE) {
+ http_response_code(200);
+ } else {
+ http_response_code(500);
+ }
+
+ $conn->close();
+}
+else {
+ http_response_code(505);
+}
+
+?>