Commit 149bc1de authored by Nate Fox's avatar Nate Fox
Browse files

initial commit

parents
var default_data = {
rdp_user: "Administrator",
ssh_user: "ec2-user",
always_override_user: false
}
\ No newline at end of file
This diff is collapsed.
{
"manifest_version": 2,
"name": "AWS SSH RDP Links",
"description": "Adds SSH and RDP links to the AWS Console",
"version": "0.1.0",
"content_scripts": [
{
"matches": [
"https://*.console.aws.amazon.com/ec2/v2/*",
"https://console.aws.amazon.com/ecs/v2/*"
],
"js": [
"defaults.js",
"page.js",
"jquery-2.2.2.min.js"
],
"css": [
"page.css"
],
"run_at": "document_start"
}
],
"options_ui": {
"page": "options.html",
"chrome_style": true
},
"browser_action": {
"default_icon": {
"19": "icons/icon19.png",
"38": "icons/icon38.png"
},
"default_popup": "options.html",
"default_title": "AWS Links"
},
"icons": { "16": "icons/icon16.png",
"48": "icons/icon48.png",
"128": "icons/icon128.png" },
"permissions": [
"activeTab",
"storage",
"https://*.console.aws.amazon.com/ec2/v2/*",
"https://console.aws.amazon.com/ec2/v2/*"
]
}
\ No newline at end of file
<!DOCTYPE html>
<html>
<head>
<title>AWS SSH RDP Options</title>
<style>
body { padding: 10px; min-width: 200px; }
div { padding: 5px; }
input { width: 100px; }
</style>
</head>
<body>
<div>
RDP User<br>
<input type="input" id="rdp_user" value="Administrator">
</div>
<div>
Default SSH User<br>
<input type="input" id="ssh_user" value="ec2-user">
</div>
<div>
<input type="checkbox" id="always_override_user">
<label for="always_override_user">Always use Default SSH User</label>
</div>
<div id="status"></div>
<div>
<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>
</body>
</html>
\ No newline at end of file
// Saves options to chrome.storage.sync.
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;
chrome.storage.sync.set({
rdp_user: rdp_user,
ssh_user: ssh_user,
always_override_user: always_override_user
}, function() {
window.close()
});
}
// Restores select box and checkbox state using the preferences
function load_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;
});
}
document.addEventListener('DOMContentLoaded', load_options);
document.getElementById('save').addEventListener('click', save_options);
.awssshrdplink {
font-size: 0.8em;
}
\ No newline at end of file
var saved_data = {}
chrome.storage.onChanged.addListener(function(){
get_storage();
})
document.addEventListener('DOMContentLoaded', function() {
$(document).click(function(){
if (window.location.hash.startsWith("#Instances"))
get_storage();
})
});
// I really want something like this!
// http://stackoverflow.com/a/3597640/517606
function get_storage() {
chrome.storage.sync.get(default_data, function(items){
saved_data = items
// go();
window.setTimeout(function(){
go();
}, 400);
})
}
function go() {
private_dns = get_selector(4,0);
private_ip = get_selector(5,0);
public_dns = get_selector(1,1);
public_ip = get_selector(2,1);
elastic_ip = get_selector(3,1);
top_row = $("div.GMB span:eq(2)")
add_to_field(private_ip)
add_to_field(public_ip)
add_to_field(elastic_ip)
add_to_field(private_dns)
add_to_field(public_dns)
add_to_field(top_row)
}
function add_to_field(fld) {
field_text = (fld.text().indexOf(':') > -1)
// grab last item via reverse->first item
? fld.text().split(" ").reverse()[0]
: fld.text()
if (field_text.indexOf("-") == 0 || field_text.trim().length == 0)
return
span = ($("span.awssshrdplink", fld).length)
? $("span.awssshrdplink", fld).empty()
: $("<span />", {class: "awssshrdplink"})
platform = get_selector(8,1).text();
str_to_add = (platform == "windows")
? create_rdp(field_text)
: create_ssh(field_text);
span.append(str_to_add)
fld.append(span)
}
function create_ssh(host) {
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"})
return href
}
function get_ssh_user() {
default_user = saved_data['ssh_user']
ami = get_selector(7,1).text();
if (ami.indexOf("ubuntu") > -1)
user = "ubuntu"
else if (ami.indexOf("amzn") > -1)
user = "ec2-user"
else if (ami.indexOf("RHEL") > -1)
user = "ec2-user"
else if (ami.indexOf("suse-sles") > -1)
user = "ec2-user"
else
user = default_user
if (saved_data['always_override_user'])
user = default_user
return user + "@"
}
function get_windows_user() {
return saved_data['rdp_user'] + "@"
}
function get_selector(row,div) {
return $("table.LJ > tbody tr:eq("+row+") div.NJ:eq("+div+")")
}
\ No newline at end of file
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