Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 36c80a7
Showing
12 changed files
with
266 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# qubes-url-redirector 0.5 | ||
|
||
Qubes OS URL Redirector 0.5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
- webRequest redirection |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
browser.browserAction.onClicked.addListener(() => { | ||
browser.runtime.openOptionsPage(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
function createMenus() | ||
{ | ||
browser.contextMenus.create({ | ||
id: "dvm", | ||
title: "Open in dvm", | ||
contexts: ["link"] | ||
}); | ||
|
||
getVmName().then(item => { | ||
browser.contextMenus.create({ | ||
id: "default-vm", | ||
title: "Open in " + item.vmname + " VM", | ||
contexts: ["link"], | ||
enabled: item.menu_enabled | ||
}); | ||
|
||
browser.contextMenus.create({ | ||
id: "some-vm", | ||
title: "Open in VM...", | ||
contexts: ["link"] | ||
}); | ||
|
||
browser.contextMenus.create({ | ||
id: "here", | ||
title: "Open here", | ||
contexts: ["link"] | ||
}); | ||
}); | ||
|
||
browser.contextMenus.onClicked.addListener((info, tab) => { | ||
switch (info.menuItemId) { | ||
case "dvm": | ||
/* in native.js */ | ||
openurl("$dispvm", info.linkUrl); | ||
break; | ||
case "default-vm": | ||
/* in native.js */ | ||
getVmName().then(item => { | ||
openurl(item.vmname, info.linkUrl); | ||
}); | ||
break; | ||
case "some-vm": | ||
browser.windows.create({ | ||
type: "popup", | ||
url: "choose-vm/popup.html?url=" + info.linkUrl, | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong. |
||
width: 600, | ||
height: 160 | ||
}); | ||
break; | ||
case "here": | ||
browser.tabs.create({url: info.linkUrl}); | ||
break; | ||
} | ||
}); | ||
} | ||
|
||
function getVmName() | ||
{ | ||
return browser.storage.local.get("settings") | ||
.then(item => { | ||
if (item.settings) | ||
item = item.settings; | ||
else | ||
item = {} | ||
|
||
item.menu_enabled = !item.vmname || item.vmname == "" ? false : true; | ||
item.vmname = !item.vmname || item.vmname == "" ? "default" : item.vmname; | ||
return item; | ||
}); | ||
} | ||
|
||
function updateMenus() | ||
{ | ||
getVmName().then(item => { | ||
browser.contextMenus.update("default-vm", { | ||
title: "Open in " + item.vmname + " VM", | ||
enabled: item.menu_enabled | ||
}); | ||
}); | ||
} | ||
|
||
createMenus(); | ||
browser.storage.onChanged.addListener(updateMenus); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
function openurl(vm, url) | ||
{ | ||
browser.runtime.sendNativeMessage("qvm_open_in_vm", {"vmname": vm, "url": url}); | ||
} | ||
|
||
browser.runtime.onMessage.addListener((req, sender, sendResponse) => { | ||
openurl(req.vmname, req.url); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<style> | ||
span { | ||
display: inline-block; | ||
margin-bottom: 10px; | ||
} | ||
|
||
#vmname { | ||
width: 95%; | ||
margin-bottom: 10px; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<form id="urlForm"> | ||
<span id="url">URL: </span><br> | ||
<label for="vmname">Insert VM Name:</label><br> | ||
<input type="text" id="vmname" name="vmname"> | ||
<button type="submit">Open</button> | ||
</form> | ||
<script src="popup.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
function redirect(e) | ||
{ | ||
let form = e.target; | ||
|
||
let vmname = form["vmname"].value; | ||
|
||
if (vmname == null || vmname == "") | ||
alert("VM name cannot be empty!"); | ||
|
||
browser.runtime.sendMessage({"vmname": vmname, "url": url}); | ||
e.preventDefault(); | ||
window.close(); | ||
} | ||
|
||
document.getElementById("urlForm").addEventListener("submit", redirect); | ||
let url = (new URL(document.location.href)).searchParams.get("url"); | ||
document.getElementById("url").textContent = "URL: " + url; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
{ | ||
"manifest_version": 2, | ||
|
||
"name": "qubes-url-redirector", | ||
"version": "0.5", | ||
"applications": { | ||
"gecko": { | ||
"id": "qubes-url-redirector@raffaeleflorio.github.io" | ||
} | ||
}, | ||
|
||
"author": "Raffaele Florio", | ||
"homepage_url": "https://github.com/raffaeleflorio/qubes-url-redirector", | ||
|
||
"options_ui": { | ||
"page": "options/settings.html", | ||
"browser_style": true | ||
}, | ||
|
||
"browser_action": { | ||
"browser_style": true, | ||
"default_title": "Qubes URL Redirector" | ||
}, | ||
|
||
"background": { | ||
"scripts": [ | ||
"backgrounds/main.js", | ||
"backgrounds/native.js", | ||
"backgrounds/menus.js" | ||
] | ||
}, | ||
|
||
"permissions": [ | ||
"contextMenus", | ||
"storage", | ||
"nativeMessaging", | ||
"webRequest" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/usr/bin/env python3 | ||
import sys | ||
import json | ||
import struct | ||
import re | ||
import os | ||
|
||
def getMessage(): | ||
msglen = sys.stdin.buffer.read(4) | ||
if len(msglen) == 0: | ||
sys.exit(1) | ||
msglen = struct.unpack("@I", msglen)[0] | ||
msg = sys.stdin.buffer.read(msglen).decode("utf-8") | ||
return json.loads(msg) | ||
|
||
msg = getMessage() | ||
if not re.match(".*://.*", msg["url"]): | ||
sys.exit(1) | ||
|
||
#check msg["vmname"] | ||
os.execvp("qvm-open-in-vm", ["qvm-open-in-vm", msg["vmname"], msg["url"]]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"name": "qvm_open_in_vm", | ||
"description": "Open URL in other VM", | ||
"allowed_extensions": ["qubes-url-redirector@raffaeleflorio.github.io"], | ||
"type": "stdio", | ||
"path": "/usr/local/bin/qvm-open-in-vm-we.py" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<style> | ||
#settings > * { | ||
margin: 5px; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<form id="settings"> | ||
Default action:<br> | ||
<label><input type="radio" name="default" id="dvm" value="dvm" checked>Open in dvm</label><br> | ||
<label><input type="radio" name="default" id="vm" value="vm">Open in VM:</label><input type="text" name="vmname"><br> | ||
<label style="color: red"><input type="radio" name="default" id="here" value="here">Open here</label><br> | ||
<button type="submit">Save</button> | ||
</form> | ||
<script src="settings.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
function save(e) | ||
{ | ||
let form = e.target; | ||
|
||
let settings = { | ||
default_action: form["default"].value, | ||
vmname: form["vmname"].value /* check esitenza ? */ | ||
}; | ||
|
||
browser.storage.local.set({"settings": settings}) | ||
.then( | ||
() => alert("Saved succesfully!"), | ||
() => { | ||
alert("Failed to save!"); | ||
restore(); | ||
} | ||
); | ||
|
||
e.preventDefault(); | ||
} | ||
|
||
function restore() | ||
{ | ||
let form = document.getElementById("settings"); | ||
|
||
browser.storage.local.get("settings") | ||
.then(item => { | ||
if (!item.settings) | ||
return; | ||
item = item.settings; | ||
form[item.default_action].checked = true; | ||
form["vmname"].value = item.vmname; | ||
}); | ||
} | ||
|
||
restore(); | ||
document.getElementById("settings").addEventListener("submit", save); |
Should this be url encoded? Does a
&
in info.linkUrl cause truncation?