|
@@ -51,6 +51,54 @@
|
|
<div class="ui divider"></div>
|
|
<div class="ui divider"></div>
|
|
<h2>Wake On LAN</h2>
|
|
<h2>Wake On LAN</h2>
|
|
<p>Wake up a remote server by WOL Magic Packet or an IoT device</p>
|
|
<p>Wake up a remote server by WOL Magic Packet or an IoT device</p>
|
|
|
|
+ <div class="ui form">
|
|
|
|
+ <div class="two fields">
|
|
|
|
+ <div class="field">
|
|
|
|
+ <input type="text" id="wol_servername" placeholder="Server Name">
|
|
|
|
+ </div>
|
|
|
|
+ <div class="field">
|
|
|
|
+ <input type="text" id="wol_mac" placeholder="MAC Address">
|
|
|
|
+ </div>
|
|
|
|
+ <div class="field">
|
|
|
|
+ <button class="ui basic right floated button" onclick="setWoLAddress();"><i class="ui blue add icon"></i> Add Address</button>
|
|
|
|
+ </div>
|
|
|
|
+ </div>
|
|
|
|
+ </div>
|
|
|
|
+ <div class="ui accordion">
|
|
|
|
+ <div class="title">
|
|
|
|
+ <i class="dropdown icon"></i>
|
|
|
|
+ Pick from mDNS scan results
|
|
|
|
+ </div>
|
|
|
|
+ <div class="content">
|
|
|
|
+ <div class="ui basic segment">
|
|
|
|
+ <div class="ui selection fluid dropdown" id="mdnsWoL">
|
|
|
|
+ <input type="hidden">
|
|
|
|
+ <i class="dropdown icon"></i>
|
|
|
|
+ <div class="default text">Select a server</div>
|
|
|
|
+ <div class="menu" id="mdnsResultForWoL">
|
|
|
|
+ </div>
|
|
|
|
+ </div>
|
|
|
|
+ <br>
|
|
|
|
+ <button class="ui basic button" onclick="updateMDNSListForWoL();"><i class="ui green refresh icon"></i> Refresh mDNS Results</button>
|
|
|
|
+ <button class="ui basic button" onclick="selectMdnsResultForWol();"><i class="ui blue add icon"></i> Add from mDNS</button>
|
|
|
|
+ </div>
|
|
|
|
+ </div>
|
|
|
|
+ </div>
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ <table class="ui celled unstackable table">
|
|
|
|
+ <thead>
|
|
|
|
+ <tr><th>Server Name</th>
|
|
|
|
+ <th>MAC Address</th>
|
|
|
|
+ <th>Action</th>
|
|
|
|
+ </tr></thead>
|
|
|
|
+ <tbody id="wolAddressList">
|
|
|
|
+ <tr>
|
|
|
|
+ <td colspan="3"><i class="ui green circle checkmark"></i> No stored MAC address</td>
|
|
|
|
+ </tr>
|
|
|
|
+ </tbody>
|
|
|
|
+ </table>
|
|
|
|
+ <button class="ui basic button" onclick="listWoL();"><i class="ui green refresh icon"></i> Refresh</button>
|
|
</div>
|
|
</div>
|
|
|
|
|
|
<div class="ui bottom attached tab segment" data-tab="tab3">
|
|
<div class="ui bottom attached tab segment" data-tab="tab3">
|
|
@@ -71,7 +119,7 @@
|
|
|
|
|
|
<script>
|
|
<script>
|
|
// Activate the default tab
|
|
// Activate the default tab
|
|
-
|
|
|
|
|
|
+ $('.ui.accordion').accordion();
|
|
$('.menu .nettools.item').tab();
|
|
$('.menu .nettools.item').tab();
|
|
$('.menu .nettools.item').addClass("activated");
|
|
$('.menu .nettools.item').addClass("activated");
|
|
|
|
|
|
@@ -198,6 +246,191 @@ function renderNICInfo(){
|
|
});
|
|
});
|
|
}
|
|
}
|
|
renderNICInfo();
|
|
renderNICInfo();
|
|
|
|
+
|
|
|
|
+/*
|
|
|
|
+ Wake On Lan functions
|
|
|
|
+*/
|
|
|
|
+
|
|
|
|
+const wake_on_lan_API = "/api/tools/wol";
|
|
|
|
+
|
|
|
|
+function selectMdnsResultForWol(){
|
|
|
|
+ let selectedText = $("#mdnsWoL").dropdown("get value");
|
|
|
|
+ let selectedWoL = JSON.parse(decodeURIComponent(selectedText));
|
|
|
|
+ $("#wol_servername").val(selectedWoL[0]);
|
|
|
|
+ $("#wol_mac").val(selectedWoL[1]);
|
|
|
|
+ setWoLAddress();
|
|
|
|
+ $("#mdnsWoL").dropdown("clear");
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+//Set Wake On Lan address
|
|
|
|
+function setWoLAddress() {
|
|
|
|
+ var name = $("#wol_servername").val().trim();
|
|
|
|
+ var mac = $("#wol_mac").val().trim();
|
|
|
|
+
|
|
|
|
+ if (name.length == 0){
|
|
|
|
+ $("#wol_servername").parent().addClass("error");
|
|
|
|
+ }else{
|
|
|
|
+ $("#wol_servername").parent().removeClass("error");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (!isValidMacAddress(mac)){
|
|
|
|
+ $("#wol_mac").parent().addClass("error");
|
|
|
|
+ msgbox("Invalid MAC address given", false, 5000);
|
|
|
|
+ return
|
|
|
|
+ }else{
|
|
|
|
+ $("#wol_mac").parent().removeClass("error");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $.ajax({
|
|
|
|
+ url: wake_on_lan_API,
|
|
|
|
+ type: "POST",
|
|
|
|
+ data: {
|
|
|
|
+ set: mac,
|
|
|
|
+ name: name
|
|
|
|
+ },
|
|
|
|
+ success: function(result) {
|
|
|
|
+ msgbox(result.error || "WoL MAC Added", (result.error == undefined), (result.error == undefined)?3000:5000);
|
|
|
|
+ listWoL();
|
|
|
|
+
|
|
|
|
+ if (result.error == undefined){
|
|
|
|
+ $("#wol_servername").val("");
|
|
|
|
+ $("#wol_mac").val("");
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ error: function(error) {
|
|
|
|
+ console.error(error);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+function delWoLAddr(mac, name) {
|
|
|
|
+ if (confirm(`Confirm remove WoL record for ${name} (${mac}) ?`)){
|
|
|
|
+ $.ajax({
|
|
|
|
+ url: wake_on_lan_API,
|
|
|
|
+ type: "POST",
|
|
|
|
+ data: {
|
|
|
|
+ del: mac.trim()
|
|
|
|
+ },
|
|
|
|
+ success: function(result) {
|
|
|
|
+ msgbox(result.error || "WoL MAC Removed", (result.error == undefined), (result.error == undefined)?3000:5000);
|
|
|
|
+ listWoL();
|
|
|
|
+ },
|
|
|
|
+ error: function(error) {
|
|
|
|
+ console.error(error);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+function wakeWoL(mac, object=undefined) {
|
|
|
|
+ if (object != undefined){
|
|
|
|
+ $(object).addClass("loading").addClass("disabled");
|
|
|
|
+ }
|
|
|
|
+ $.ajax({
|
|
|
|
+ url: wake_on_lan_API,
|
|
|
|
+ type: "POST",
|
|
|
|
+ data: {
|
|
|
|
+ wake: mac
|
|
|
|
+ },
|
|
|
|
+ success: function(result) {
|
|
|
|
+ if (result.error != undefined){
|
|
|
|
+ msgbox(result.error, false, 5000);
|
|
|
|
+ }else{
|
|
|
|
+ //Success?
|
|
|
|
+ setTimeout(function(){
|
|
|
|
+ if (object != undefined){
|
|
|
|
+ $(object).removeClass("loading").removeClass("disabled");
|
|
|
|
+ }
|
|
|
|
+ }, 5000);
|
|
|
|
+ }
|
|
|
|
+ console.log(result);
|
|
|
|
+ },
|
|
|
|
+ error: function(error) {
|
|
|
|
+ console.error(error);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+function listWoL(callback) {
|
|
|
|
+ $.ajax({
|
|
|
|
+ url: wake_on_lan_API,
|
|
|
|
+ type: "GET",
|
|
|
|
+ success: function(data) {
|
|
|
|
+ // Clear existing rows from the table
|
|
|
|
+ $("#wolAddressList").empty();
|
|
|
|
+
|
|
|
|
+ // Loop through data and create a new row for each object
|
|
|
|
+ for (var i = 0; i < data.length; i++) {
|
|
|
|
+ let thisServerName = data[i].ServerName;
|
|
|
|
+ let thisMacAddr = data[i].MacAddr
|
|
|
|
+ $("#wolAddressList").append(`
|
|
|
|
+ <tr class="wolmacentry" mac="${thisMacAddr}">
|
|
|
|
+ <td>${thisServerName}</td>
|
|
|
|
+ <td>${thisMacAddr}</td>
|
|
|
|
+ <td>
|
|
|
|
+ <button onclick="wakeWoL('${thisMacAddr}', this);" class="ui tiny basic button"><i class="green power icon"></i>Wake on LAN</button>
|
|
|
|
+ <button onclick="delWoLAddr('${thisMacAddr}', '${thisServerName}');" class="ui tiny red basic icon button"><i class="red trash icon"></i></button>
|
|
|
|
+ </td>
|
|
|
|
+
|
|
|
|
+ </tr>
|
|
|
|
+ `);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (data.length == 0){
|
|
|
|
+ $("#wolAddressList").append(`<tr>
|
|
|
|
+ <td colspan="3"><i class="ui green circle check icon"></i> No stored MAC address for Wake On Lan (WoL)</td>
|
|
|
|
+ </tr>`);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //Also update the MDNS list
|
|
|
|
+ updateMDNSListForWoL();
|
|
|
|
+
|
|
|
|
+ if (callback) {
|
|
|
|
+ callback(data);
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ error: function(error) {
|
|
|
|
+ console.error(error);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+}
|
|
|
|
+listWoL();
|
|
|
|
+
|
|
|
|
+function isValidMacAddress(macAddress) {
|
|
|
|
+ const macRegex = /^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$/;
|
|
|
|
+ return macRegex.test(macAddress);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+function updateMDNSListForWoL(){
|
|
|
|
+ let alreadyAddedEntries = [];
|
|
|
|
+ $(".wolmacentry").each(function(){
|
|
|
|
+ let thisMac = $(this).attr("mac").trim();
|
|
|
|
+ if (isValidMacAddress(thisMac)){
|
|
|
|
+ console.log(thisMac);
|
|
|
|
+ alreadyAddedEntries.push(thisMac);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ $("#mdnsResultForWoL").html("");
|
|
|
|
+ $.get("/api/mdns/list", function(data){
|
|
|
|
+ data.forEach(thisServer => {
|
|
|
|
+ if (thisServer.MacAddr.length > 0){
|
|
|
|
+ for (var i = 0; i < thisServer.MacAddr.length; i++){
|
|
|
|
+ let thisMacAddr = thisServer.MacAddr[i];
|
|
|
|
+ if (!isValidMacAddress(thisMacAddr) || alreadyAddedEntries.includes(thisMacAddr)){
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ let encodedObject = encodeURIComponent(JSON.stringify([thisServer.HostName, thisMacAddr]));
|
|
|
|
+ $("#mdnsResultForWoL").append(`<div class="item" data-value="${encodedObject}"><i class="server icon"></i> ${thisServer.HostName} (${thisMacAddr})</div>`);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ $("#mdnsResultForWoL").parent().dropdown();
|
|
|
|
+ });
|
|
|
|
+}
|
|
|
|
+updateMDNSListForWoL();
|
|
|
|
+
|
|
|
|
+
|
|
</script>
|
|
</script>
|
|
|
|
|
|
|
|
|