Skip to content

Commit

Permalink
Detect app version
Browse files Browse the repository at this point in the history
  • Loading branch information
toolsprods committed Oct 16, 2019
1 parent 8d7f1c2 commit 49eb9f4
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 18 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -3,7 +3,7 @@

# EasyDoH

EasyDoH is a simple addon for Firefox that allows to easily activate [DNS over HTTPS](https://en.wikipedia.org/wiki/DNS_over_HTTPS) and its mode with one click.
EasyDoH is a simple addon for Firefox that allows to easily activate [DNS over HTTPS](https://en.wikipedia.org/wiki/DNS_over_HTTPS) and its working mode with just one click.

It contains explanations for the different modes allowed (only available in _about:config_) and DoH servers to choose from.

Expand Down
50 changes: 34 additions & 16 deletions add-on/popup/js/script.js
@@ -1,14 +1,14 @@
$(function() {
var data = { mode: "init", uri: "" };
port.postMessage(JSON.stringify(data));

loadJSON();
});

var port = browser.extension
.getBackgroundPage()
.browser.runtime.connectNative("com.elevenpaths.easydoh");

$(function() {
var version = { mode: "version", uri: "" };
port.postMessage(JSON.stringify(version));

loadJSON("doh.json", 1, "default");
});

var dnsValues = "";

document.getElementById("change-content").onclick = function() {
Expand All @@ -35,7 +35,7 @@ document.getElementById("serverInput").onclick = function() {
var server = document.getElementById("serverInput");
var serverSelect = server.options[server.selectedIndex].value;

if (serverSelect === "manual") {
if (serverSelect == "manual") {
document.getElementById("serverManualInput").classList.remove("d-none");
document.getElementById("change-content").setAttribute("disabled", true);
} else {
Expand All @@ -55,17 +55,35 @@ Listen for messages from the app.
*/
port.onMessage.addListener(response => {
console.log("Received: " + response);

mode = response["mode"];
uri = getDnsFromUri(response["uri"]);
uri = response["uri"];

if (mode == "version") {
var version = browser.runtime.getManifest().version;
if (version != uri) {
message =
'<p>Addon version incorrect.</br>Please, download and install new version from <a href="https://easydoh.e-paths.com/download.html">here</a>.</p>';
setMessage(message);
} else {
var data = { mode: "init", uri: "" };
port.postMessage(JSON.stringify(data));
}
} else {
uri = getDnsFromUri(uri);

loadJSON(mode, uri);
var dohRepo =
"https://raw.githubusercontent.com/ElevenPaths/EasyDoH/master/add-on/popup/doh.json";
loadJSON("doh.json", mode, uri);
loadJSON(dohRepo, mode, uri);
}
});

port.onDisconnect.addListener(response => {
console.log("Disconnect: " + response);

message =
'<p>Addon not detected.</p><p>Check if it is in the right path or download and install it from <a href="https://easydoh.e-paths.com/download.html">here</a>.</p>';
'<p>Addon not detected.</br>Check if it is in the right path or download and install it from <a href="https://easydoh.e-paths.com/download.html">here</a>.</p>';
setMessage(message);
});

Expand All @@ -75,7 +93,7 @@ function buttonAction() {
var uri = document.getElementById("serverInput");
var valueUri = uri.options[uri.selectedIndex].value;

if (valueUri === "manual") {
if (valueUri == "manual") {
valueUri = "manual;" + document.getElementById("serverManualInput").value;
} else {
valueUri = dnsValues[valueUri].url;
Expand Down Expand Up @@ -107,7 +125,7 @@ function sendData(mode, uri) {
port.postMessage(JSON.stringify(data));

message =
"<p>Restart the browser to apply changes<br/>EasyDoH will show Cloudfare configuration by default,<br/>but your configuration wil be shown in TRR <i>about:config</i></p>";
"<p>Restart the browser to apply changes.<br/>Your configuration will be shown in TRR <i>about:config</i>.</p>";
setMessage(message);
}

Expand All @@ -123,7 +141,7 @@ function setOptionsValue(mode, uri) {
document.getElementById("modeInput").options.selectedIndex = mode;
var serverInput = document.getElementById("serverInput").options;

if (uri === "default") {
if (uri == "default") {
uri = "cloudflare";
} else if (uri.includes("manual;")) {
var manual = uri.split(";");
Expand All @@ -141,7 +159,7 @@ function setOptionsValue(mode, uri) {
}
}

function loadJSON(mode, uri) {
function loadJSON(cdn, mode, uri) {
xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
Expand All @@ -159,6 +177,6 @@ function loadJSON(mode, uri) {
setOptionsValue(mode, uri);
}
};
xmlhttp.open("GET", "doh.json", true);
xmlhttp.open("GET", cdn, true);
xmlhttp.send();
}
Binary file modified app/Windows/easydoh.exe
Binary file not shown.
7 changes: 6 additions & 1 deletion app/macOS-Linux/easydoh.py
Expand Up @@ -9,6 +9,8 @@
import subprocess
import sys

VERSION = "1.1.0"

# Templates for configuration parameters
trr_mode = 'network.trr.mode'
trr_uri = 'network.trr.uri'
Expand Down Expand Up @@ -155,7 +157,10 @@ def write_firefox_user_pref(mode, uri):
while True:
received_message = get_message()
data = json.loads(received_message)
if data["mode"] == "init":
if data["mode"] == "version":
values = {"mode": "version", "uri": VERSION}
send_message(encode_message(values))
elif data["mode"] == "init":
mode, uri = get_firefox_dns_pref()
values = {"mode": mode, "uri": uri}
send_message(encode_message(values))
Expand Down

0 comments on commit 49eb9f4

Please sign in to comment.