init
This commit is contained in:
@@ -0,0 +1,150 @@
|
||||
function getAppIP( network, device, app ) {
|
||||
let deviceIP;
|
||||
let port;
|
||||
|
||||
console.log(network, " - ", device, " - ", app)
|
||||
|
||||
if (network == 'tailscale') {
|
||||
deviceIP = (device == 'qnap') ? '100.97.249.88' : '100.115.109.63';
|
||||
} else {
|
||||
deviceIP = (device == 'qnap') ? '192.168.1.81' : '192.168.1.13';
|
||||
}
|
||||
|
||||
switch (app) {
|
||||
case 'nginx':
|
||||
port = ":81";
|
||||
break;
|
||||
case 'qnas':
|
||||
port = ":8080";
|
||||
break;
|
||||
case 'dockerRegistry':
|
||||
port = ":5000";
|
||||
break;
|
||||
case 'jellyfin':
|
||||
port = ":8096";
|
||||
break;
|
||||
case 'qtorrent':
|
||||
port = ":8181";
|
||||
break;
|
||||
case 'radarr':
|
||||
port = ":7878";
|
||||
break;
|
||||
default:
|
||||
port = ""
|
||||
// case sonarr:
|
||||
// port = ":"
|
||||
// break;
|
||||
// case lidarr:
|
||||
// port = ":"
|
||||
// break;
|
||||
// case gitRegistry:
|
||||
// port = ":"
|
||||
// break;
|
||||
};
|
||||
|
||||
return "http://" + deviceIP + port;
|
||||
}
|
||||
|
||||
function propigateIps( network ) {
|
||||
console.log('prop started: ', network)
|
||||
const ipHasPortRegex = /^http:\/\/(\d{1,3}\.){3}\d{1,3}:\d+$/;
|
||||
['qnap', 'pc'].forEach(function(deviceClass) {
|
||||
$("." + deviceClass).each(function() {
|
||||
let appName = $(this).attr("id");
|
||||
let ipAddress = getAppIP(network, deviceClass, appName);
|
||||
if (ipHasPortRegex.test(ipAddress)) {
|
||||
$(this).attr('href', ipAddress);
|
||||
} else {
|
||||
$(this).removeAttr('href');
|
||||
$(this).removeClass('button');
|
||||
$(this).addClass('button-disabled');
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function determineNetwork() {
|
||||
const apiUrlTailscale = 'http://100.97.249.88:3030/';
|
||||
try {
|
||||
fetch(apiUrlTailscale);
|
||||
console.log('determined: tailscale')
|
||||
return 'tailscale';
|
||||
} catch {
|
||||
console.log('determined: local')
|
||||
return'local';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
async function fillIpsBasedOnNetwork() {
|
||||
const apiUrlTailscale = 'http://100.97.249.88:3030/';
|
||||
let network;
|
||||
try {
|
||||
await fetch(apiUrlTailscale);
|
||||
console.log('determined: tailscale')
|
||||
network = 'tailscale'
|
||||
setHeader (network)
|
||||
propigateIps(network);
|
||||
} catch {
|
||||
console.log('determined: local')
|
||||
network = 'local'
|
||||
setHeader (network)
|
||||
propigateIps(network);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function setHeader( network ) {
|
||||
const networkName = network.charAt(0).toUpperCase() + network.slice(1) + ' Network';
|
||||
$("#currentDashboard").text(networkName);
|
||||
}
|
||||
|
||||
$(document).ready(function() {
|
||||
fillIpsBasedOnNetwork();
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* document.addEventListener('DOMContentLoaded', function() {
|
||||
const changeDashboardButton = document.getElementById('changeDashboardButton');
|
||||
|
||||
changeDashboardButton.addEventListener('click', function() {
|
||||
console.log("click")
|
||||
$("#currentDashboard")
|
||||
const currentDashboard = $("#currentDashboard")
|
||||
|
||||
let currentDashboardClasses = currentDashboard.attr('class');
|
||||
let newNetwork = currentDashboardClasses.includes('tailscale') ? 'local' : 'tailscale';
|
||||
|
||||
['qnap', 'pc'].forEach(function(deviceClass) {
|
||||
$("." + deviceClass).each(function() {
|
||||
let appName = $(this).attr("id");
|
||||
let ipAddress = getIP(newNetwork, deviceClass, appName);
|
||||
if (ipRegex.test(ipAddress)) {
|
||||
$(this).attr('href', ipAddress);
|
||||
$(this).removeClass('button-disabled');
|
||||
$(this).addClass('button');
|
||||
} else {
|
||||
$(this).removeAttr('href');
|
||||
$(this).removeClass('button');
|
||||
$(this).addClass('button-disabled');
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
currentDashboard.toggleClass('local tailscale');
|
||||
let networkName = newNetwork.charAt(0).toUpperCase() + newNetwork.slice(1) + ' Network';
|
||||
currentDashboard.text(networkName)
|
||||
|
||||
const logoOn = $('#logoOn');
|
||||
const logoOff = $('#logoOff');
|
||||
let logoOnSrc = logoOn.attr('src');
|
||||
let logoOffSrc = logoOff.attr('src');
|
||||
|
||||
logoOn.attr('src', logoOffSrc)
|
||||
logoOff.attr('src', logoOnSrc)
|
||||
});
|
||||
}); */
|
||||
Reference in New Issue
Block a user