Commit 91238f80 authored by Nate Fox's avatar Nate Fox
Browse files

added option for MS style href (fixes #1), fixed errant SSH/RDP in links

parent 17819700
var default_data = {
rdp_user: "Administrator",
ssh_user: "ec2-user",
always_override_user: false
always_override_user: false,
rdp_style: "MS"
}
\ No newline at end of file
<!DOCTYPE html>
<html>
<head>
<script src="jquery-2.2.2.min.js"></script>
<script src="defaults.js"></script>
<script src="options.js"></script>
<title>AWS SSH RDP Options</title>
<style>
body { padding: 10px; min-width: 200px; }
......@@ -14,6 +18,13 @@
RDP User<br>
<input type="input" id="rdp_user" value="Administrator">
</div>
<div>
RDP Link Style<br>
<select id="rdp_style">
<option value="MS">Microsoft</option>
<option value="CoRD">CoRD</option>
</select>
</div>
<div>
Default SSH User<br>
......@@ -30,8 +41,9 @@
<button id="save">Save</button>
</div>
<script src="jquery-2.2.2.min.js"></script>
<script src="defaults.js"></script>
<script src="options.js"></script>
<div>
<a href="https://github.com/natefox/aws-ssh-rdp-links">Website</a> |
<a href="https://github.com/natefox/aws-ssh-rdp-links/issues">Report a bug?</a>
</div>
</body>
</html>
\ No newline at end of file
......@@ -3,11 +3,13 @@ function save_options() {
var rdp_user = document.getElementById('rdp_user').value;
var ssh_user = document.getElementById('ssh_user').value;
var always_override_user = document.getElementById('always_override_user').checked;
var rdp_style = $("rdp_style").val();
chrome.storage.sync.set({
rdp_user: rdp_user,
ssh_user: ssh_user,
always_override_user: always_override_user
always_override_user: always_override_user,
rdp_style: rdp_style
}, function() {
window.close()
});
......@@ -15,12 +17,15 @@ function save_options() {
// Restores select box and checkbox state using the preferences
function load_options() {
$("#save").click(save_options);
chrome.storage.sync.get(default_data, function(items) {
document.getElementById('rdp_user').value = items.rdp_user;
document.getElementById('ssh_user').value = items.ssh_user;
document.getElementById('always_override_user').checked = items.always_override_user;
$("#rdp_style").val(items.rdp_style);
});
}
document.addEventListener('DOMContentLoaded', load_options);
document.getElementById('save').addEventListener('click', save_options);
......@@ -42,14 +42,14 @@ function go() {
add_to_field(private_dns)
add_to_field(public_dns)
add_to_field(top_row)
add_to_field(top_row, true)
}
function add_to_field(fld) {
field_text = (fld.text().indexOf(':') > -1)
function add_to_field(fld, is_top_row = false) {
field_text = (is_top_row)
// grab last item via reverse->first item
? fld.text().split(" ").reverse()[0]
: fld.text().split(" ")[0]
? fld.contents().first().text().split(" ").reverse()[0]
: fld.contents().first().text()
if (field_text.indexOf("-") == 0 || field_text.trim().length == 0)
return
......@@ -62,21 +62,33 @@ function add_to_field(fld) {
str_to_add = (platform == "windows")
? create_rdp(field_text)
: create_ssh(field_text);
: create_ssh(field_text)
span.append(str_to_add)
fld.append(span)
}
function create_ssh(host) {
user = get_ssh_user();
user = get_ssh_user()
href = $("<a />", {href: "ssh://"+user+host , text: "SSH"})
return href
}
function create_rdp(host) {
user = get_windows_user();
href = $("<a />", {href: "rdp://"+user+host , text: "RDP"})
user = get_windows_user()
if (saved_data['rdp_style'] == "MS") {
query_string_opts = []
if (user.length > 0) query_string_opts.push("username=s:"+user)
query_string_opts.push("full%20address=s:"+host+":3389")
query_string = query_string_opts.join("&")
href = $("<a />", {href: "rdp://"+query_string, text: "RDP"})
} else if (saved_data['rdp_style'] == "CoRD") {
user_at = (user.length > 0) ? user+"@" : ""
href = $("<a />", {href: "rdp://"+user_at+host , text: "RDP"})
}
return href
}
......@@ -106,11 +118,7 @@ function get_ssh_user() {
function get_windows_user() {
user = saved_data['rdp_user']
if (user.length)
return user + "@"
else
return ""
return user
}
function get_selector(row,div) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment