/* * This file is part of Linode Manager Classic. * * Linode Manager Classic is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Linode Manager Classic is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Linode Manager Classic. If not, see . */ import { settings, elements, apiGet, parseParams, setupHeader } from "/global.js"; (function() { // Element names specific to this page elements.ipFailover = "ip-failover"; elements.ipRemove = "ip-remove"; elements.ipSwap = "ip-swap"; elements.ipv4Addrs = "ipv4-addrs"; elements.ipv4Gateways = "ipv4-gateways"; elements.linkLocal = "link-local"; elements.linodeLabel = "linode-label"; elements.linodeTag = "linode-tag"; elements.linodeTagLink = "linode-tag-link"; elements.lishLink = "lish-link"; elements.privateIPGuide = "private-ips-guide"; elements.privateIPs = "private-ips"; elements.resolvers = "resolvers"; elements.slaacAddr = "slaac-addr"; elements.slaacGateway = "slaac-gateway"; elements.slaacPrefix = "slaac-prefix"; elements.slaacRdns = "slaac-rdns"; elements.sshLink = "ssh-link"; // Data recieved from API calls var data = {}; data.linode = {}; data.netInfo = {}; // The Linode API does not supply resolvers, so they must be hard-coded data.resolvers = { "us-central": [ "173.255.199.5", "66.228.53.5", "96.126.122.5", "96.126.124.5", "96.126.127.5", "198.58.107.5", "198.58.111.5", "23.239.24.5", "2600:3c00::5", "2600:3c00::6", "2600:3c00::7", "2600:3c00::8", "2600:3c00::9", "2600:3c00::b", "2600:3c00::c" ], "us-west": [ "173.230.145.5", "173.230.147.5", "173.230.155.5", "173.255.212.5", "173.255.219.5", "173.255.241.5", "173.255.243.5", "173.255.244.5", "2600:3c01::5", "2600:3c01::6", "2600:3c01::7", "2600:3c01::8", "2600:3c01::9", "2600:3c01::b", "2600:3c01::c" ], "us-southeast": [ "173.230.129.5", "173.230.136.5", "173.230.140.5", "66.228.59.5", "66.228.62.5", "50.116.35.5", "50.116.41.5", "23.239.18.5", "2600:3c02::5", "2600:3c02::6", "2600:3c02::7", "2600:3c02::8", "2600:3c02::9", "2600:3c02::b", "2600:3c02::c" ], "us-east": [ "66.228.42.5", "96.126.106.5", "50.116.53.5", "50.116.58.5", "50.116.61.5", "50.116.62.5", "66.175.211.5", "2600:3c03::5", "2600:3c03::6", "2600:3c03::7", "2600:3c03::8", "2600:3c03::9", "2600:3c03::b", "2600:3c03::c" ], "us-east-1b": [ "172.104.200.4", "172.104.200.5", "2400:8903::5", "2400:8903::6", "2400:8903::7", "2400:8903::8", "2400:8903::9", "2400:8903::b", "2400:8903::c" ], "eu-west": [ "178.79.182.5", "176.58.107.5", "176.58.116.5", "176.58.121.5", "151.236.220.5", "212.71.252.5", "212.71.253.5", "2a01:7e00::5", "2a01:7e00::6", "2a01:7e00::7", "2a01:7e00::8", "2a01:7e00::9", "2a01:7e00::b", "2a01:7e00::c" ], "ap-south": [ "139.162.11.5", "139.162.13.5", "139.162.14.5", "139.162.15.5", "139.162.16.5", "139.162.21.5", "139.162.27.5", "2400:8901::5", "2400:8901::6", "2400:8901::7", "2400:8901::8", "2400:8901::9", "2400:8901::b", "2400:8901::c" ], "eu-central": [ "139.162.130.5", "139.162.131.5", "139.162.132.5", "139.162.133.5", "139.162.134.5", "139.162.135.5", "139.162.136.5", "139.162.137.5", "139.162.138.5", "139.162.139.5", "2a01:7e01::5", "2a01:7e01::6", "2a01:7e01::7", "2a01:7e01::8", "2a01:7e01::9", "2a01:7e01::b", "2a01:7e01::c" ], "ap-northeast": [ "106.187.90.5", "106.187.93.5", "106.187.94.5", "106.187.95.5", "106.186.116.5", "106.186.123.5", "106.186.124.5", "2400:8900::5", "2400:8900::6", "2400:8900::7", "2400:8900::8", "2400:8900::9", "2400:8900::b", "2400:8900::c" ], "ap-northeast-1a": [ "139.162.66.5", "139.162.67.5", "139.162.68.5", "139.162.69.5", "139.162.70.5", "139.162.71.5", "139.162.72.5", "139.162.73.5", "139.162.74.5", "139.162.75.5", "2400:8902::5", "2400:8902::6", "2400:8902::7", "2400:8902::8", "2400:8902::9", "2400:8902::b", "2400:8902::c" ], "ca-central": [ "172.105.0.5", "172.105.3.5", "172.105.4.5", "172.105.5.5", "172.105.6.5", "172.105.7.5", "172.105.8.5", "172.105.9.5", "172.105.10.5", "172.105.11.5", "2600:3C04::5", "2600:3C04::6", "2600:3C04::7", "2600:3C04::8", "2600:3C04::9", "2600:3C04::b", "2600:3C04::c" ], "ap-west": [ "172.105.34.5", "172.105.35.5", "172.105.36.5", "172.105.37.5", "172.105.38.5", "172.105.39.5", "172.105.40.5", "172.105.41.5", "172.105.42.5", "172.105.43.5", "2400:8904::5", "2400:8904::6", "2400:8904::7", "2400:8904::8", "2400:8904::9", "2400:8904::b", "2400:8904::c" ], "ap-southeast": [ "172.105.166.5", "172.105.169.5", "172.105.168.5", "172.105.172.5", "172.105.162.5", "172.105.170.5", "172.105.167.5", "172.105.171.5", "172.105.181.5", "172.105.161.5", "2400:8907::5", "2400:8907::6", "2400:8907::7", "2400:8907::8", "2400:8907::9", "2400:8907::b", "2400:8907::c" ], "philadelphia": [ "100.90.80.253", "2400:8906::5", "2400:8906::6", "2400:8906::7", "2400:8906::8", "2400:8906::9", "2400:8906::b", "2400:8906::c" ] }; // LISH uses different DC names than the API uses, so we need to translate them data.lishDCs = { "us-central": "dallas", "us-west": "fremont", "us-southeast": "atlanta", "us-east": "newark", "us-east-1b": "cjj2", "eu-west": "london", "ap-south": "singapore", "eu-central": "frankfurt", "ap-northeast": "shg1", "ap-northeast-1a": "shg1", "ca-central": "tor1", "ap-west": "mum1", "ap-southeast": "syd1", "philadelphia": "phl1" }; // Static references to UI elements var ui = {}; ui.ipFailover = {}; ui.ipRemove = {}; ui.ipSwap = {}; ui.ipv4Addrs = {}; ui.ipv4Gateways = {}; ui.linkLocal = {}; ui.linodeLabel = {}; ui.linodeTag = {}; ui.linodeTagLink = {}; ui.lishLink = {}; ui.privateIPGuide = {}; ui.privateIPs = {}; ui.resolvers = {}; ui.slaacAddr = {}; ui.slaacGateway = {}; ui.slaacPrefix = {}; ui.slaacRdns = {}; ui.sshLink = {}; // Callback for linode details API call var displayDetails = function(response) { data.linode = response; // Set page title and header stuff document.title += " // " + data.linode.label; ui.linodeLabel.innerHTML = data.linode.label; if (data.linode.tags.length == 1) { ui.linodeTagLink.href = "/linodes?tag=" + data.linode.tags[0]; ui.linodeTagLink.innerHTML = "(" + data.linode.tags[0] + ")"; ui.linodeTag.style.display = "inline"; } // Replace user in SSH link if we're running CoreOS Container Linux if (data.linode.image == "linode/containerlinux") { ui.sshLink.href = ui.sshLink.href.replace("root", "core"); ui.sshLink.innerHTML = ui.sshLink.innerHTML.replace("root", "core"); } // Get list of other instances in the same region var filters = { "region": data.linode.region }; apiGet("/linode/instances", displayIPLinks, filters); // Display resolvers for (var i = 0; i < data.resolvers[data.linode.region].length; i++) { var resolver = document.createElement("span"); resolver.innerHTML = data.resolvers[data.linode.region][i]; var br = document.createElement("br"); ui.resolvers.appendChild(resolver); ui.resolvers.appendChild(br); } // Update the LISH link ui.lishLink.href = ui.lishLink.href.replace("lish-", "lish-" + data.lishDCs[data.linode.region]); ui.lishLink.innerHTML = ui.lishLink.innerHTML.replace("lish-", "lish-" + data.lishDCs[data.linode.region]); ui.lishLink.innerHTML += " " + data.linode.label; }; // Callback for regional instances API call var displayIPLinks = function(response) { // Only enable IP failover and swap links if there are 2 or more instances in this location if (response.data.length < 2) return; var ipFailover = document.createElement("a"); ipFailover.href = "/linodes/ip_failover?lid=" + data.params.lid; ipFailover.innerHTML = "IP Failover"; ui.ipFailover.replaceWith(ipFailover); var ipSwap = document.createElement("a"); ipSwap.href = "/linodes/ip_swap?lid=" + data.params.lid; ipSwap.innerHTML = "IP Swap"; ui.ipSwap.replaceWith(ipSwap); }; // Callback for user info API call var displayLishUser = function(response) { // Insert username into LISH link ui.lishLink.href = ui.lishLink.href.replace("@", response.username + "@"); ui.lishLink.innerHTML = ui.lishLink.innerHTML.replace("@", response.username + "@"); }; // Callback for network info API call var displayNetInfo = function(response) { data.netInfo = response; // Set SSH link // CoreOS Container Linux uses core instead of root var user = "root"; if (data.linode && data.linode.image == "linode/containerlinux") user = "core"; if (data.netInfo.ipv4["public"].length > 0) { ui.sshLink.href = "ssh://" + user + "@" + data.netInfo.ipv4["public"][0].address; ui.sshLink.innerHTML = "ssh " + user + "@" + data.netInfo.ipv4["public"][0].address; } // Show public IPv4 info for (var i = 0; i < data.netInfo.ipv4["public"].length; i++) { var ipinfo = document.createElement("span"); ipinfo.innerHTML = data.netInfo.ipv4["public"][i].address + " / " + data.netInfo.ipv4["public"][i].prefix + " ( " + data.netInfo.ipv4["public"][i].rdns + " )"; var gateway = document.createElement("span"); gateway.innerHTML = data.netInfo.ipv4["public"][i].gateway; var br = document.createElement("br"); ui.ipv4Addrs.appendChild(ipinfo); ui.ipv4Addrs.appendChild(br); ui.ipv4Gateways.appendChild(gateway); ui.ipv4Gateways.appendChild(br.cloneNode(false)); } // Show public IPv6 info ui.slaacAddr.innerHTML = data.netInfo.ipv6.slaac.address; ui.slaacGateway.innerHTML = data.netInfo.ipv6.slaac.gateway; ui.slaacPrefix.innerHTML = data.netInfo.ipv6.slaac.prefix; ui.slaacRdns.innerHTML = data.netInfo.ipv6.slaac.rdns; // Enable IP remove link if multiple IPv4s if (data.netInfo.ipv4["public"].length > 1) { var ipRemove = document.createElement("a"); ipRemove.href = "/linodes/ip_remove?lid=" + data.params.lid; ipRemove.innerHTML = "IP Remove"; ui.ipRemove.replaceWith(ipRemove); } // Display private IP info if (data.netInfo.ipv4["private"].length > 0) { ui.privateIPs.innerHTML = ""; ui.privateIPGuide.style.visibility = "visible"; } for (var i = 0; i < data.netInfo.ipv4["private"].length; i++) { var ip = document.createElement("span"); ip.innerHTML = data.netInfo.ipv4["private"][i].address + " / " + data.netInfo.ipv4["private"][i].prefix; var br = document.createElement("br"); ui.privateIPs.appendChild(ip); ui.privateIPs.appendChild(br); } // Display link-local IPv6 address ui.linkLocal.innerHTML = data.netInfo.ipv6.link_local.address + " / " + data.netInfo.ipv6.link_local.prefix; }; // Initial setup var setup = function() { // Parse URL parameters data.params = parseParams(); // We need a Linode ID, so die if we don't have it if (!data.params.lid) { alert("No Linode ID supplied!"); return; } setupHeader(); // Update links on page to include proper Linode ID var anchors = document.getElementsByTagName("a"); for (var i = 0; i < anchors.length; i++) { anchors[i].href = anchors[i].href.replace("lid=00", data.params.lid); anchors[i].href = anchors[i].href.replace("lid=0", "lid=" + data.params.lid); } // Get element references ui.ipFailover = document.getElementById(elements.ipFailover); ui.ipRemove = document.getElementById(elements.ipRemove); ui.ipSwap = document.getElementById(elements.ipSwap); ui.ipv4Addrs = document.getElementById(elements.ipv4Addrs); ui.ipv4Gateways = document.getElementById(elements.ipv4Gateways); ui.linkLocal = document.getElementById(elements.linkLocal); ui.linodeLabel = document.getElementById(elements.linodeLabel); ui.linodeTag = document.getElementById(elements.linodeTag); ui.linodeTagLink = document.getElementById(elements.linodeTagLink); ui.lishLink = document.getElementById(elements.lishLink); ui.privateIPGuide = document.getElementById(elements.privateIPGuide); ui.privateIPs = document.getElementById(elements.privateIPs); ui.resolvers = document.getElementById(elements.resolvers); ui.slaacAddr = document.getElementById(elements.slaacAddr); ui.slaacGateway = document.getElementById(elements.slaacGateway); ui.slaacPrefix = document.getElementById(elements.slaacPrefix); ui.slaacRdns = document.getElementById(elements.slaacRdns); ui.sshLink = document.getElementById(elements.sshLink); // Get data from API apiGet("/linode/instances/" + data.params.lid, displayDetails, null); apiGet("/linode/instances/" + data.params.lid + "/ips", displayNetInfo, null); apiGet("/profile", displayLishUser, null); }; // Attach onload handler window.addEventListener("load", setup); })();