2019-10-08 17:58:46 +00:00
|
|
|
function msgShow(retcode,msg) {
|
2021-11-25 09:02:59 +00:00
|
|
|
if(retcode == 0) { var alertType = 'success';
|
2019-10-08 17:58:46 +00:00
|
|
|
} else if(retcode == 2 || retcode == 1) {
|
|
|
|
var alertType = 'danger';
|
|
|
|
}
|
|
|
|
var htmlMsg = '<div class="alert alert-'+alertType+' alert-dismissible" role="alert"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>'+msg+'</div>';
|
|
|
|
return htmlMsg;
|
|
|
|
}
|
|
|
|
|
|
|
|
function createNetmaskAddr(bitCount) {
|
|
|
|
var mask=[];
|
|
|
|
for(i=0;i<4;i++) {
|
|
|
|
var n = Math.min(bitCount, 8);
|
|
|
|
mask.push(256 - Math.pow(2, 8-n));
|
|
|
|
bitCount -= n;
|
|
|
|
}
|
|
|
|
return mask.join('.');
|
|
|
|
}
|
|
|
|
|
|
|
|
function loadSummary(strInterface) {
|
2023-09-14 17:56:36 +00:00
|
|
|
var csrfToken = $('meta[name=csrf_token]').attr('content');
|
|
|
|
$.post('ajax/networking/get_ip_summary.php',{'interface': strInterface, 'csrf_token': csrfToken},function(data){
|
2019-10-08 17:58:46 +00:00
|
|
|
jsonData = JSON.parse(data);
|
|
|
|
if(jsonData['return'] == 0) {
|
|
|
|
$('#'+strInterface+'-summary').html(jsonData['output'].join('<br />'));
|
|
|
|
} else if(jsonData['return'] == 2) {
|
|
|
|
$('#'+strInterface+'-summary').append('<div class="alert alert-danger alert-dismissible" role="alert"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>'+jsonData['output'].join('<br />')+'</div>');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function getAllInterfaces() {
|
2019-11-04 16:15:04 +00:00
|
|
|
$.get('ajax/networking/get_all_interfaces.php',function(data){
|
2019-10-08 17:58:46 +00:00
|
|
|
jsonData = JSON.parse(data);
|
|
|
|
$.each(jsonData,function(ind,value){
|
|
|
|
loadSummary(value)
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function setupTabs() {
|
|
|
|
$('a[data-toggle="tab"]').on('shown.bs.tab',function(e){
|
|
|
|
var target = $(e.target).attr('href');
|
|
|
|
if(!target.match('summary')) {
|
|
|
|
var int = target.replace("#","");
|
|
|
|
loadCurrentSettings(int);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
$(document).on("click", ".js-add-dhcp-static-lease", function(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
var container = $(".js-new-dhcp-static-lease");
|
|
|
|
var mac = $("input[name=mac]", container).val().trim();
|
|
|
|
var ip = $("input[name=ip]", container).val().trim();
|
2021-07-27 16:33:00 +00:00
|
|
|
var comment = $("input[name=comment]", container).val().trim();
|
2019-10-08 17:58:46 +00:00
|
|
|
if (mac == "" || ip == "") {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var row = $("#js-dhcp-static-lease-row").html()
|
|
|
|
.replace("{{ mac }}", mac)
|
2021-07-27 16:33:00 +00:00
|
|
|
.replace("{{ ip }}", ip)
|
|
|
|
.replace("{{ comment }}", comment);
|
2019-10-08 17:58:46 +00:00
|
|
|
$(".js-dhcp-static-lease-container").append(row);
|
|
|
|
|
|
|
|
$("input[name=mac]", container).val("");
|
|
|
|
$("input[name=ip]", container).val("");
|
2021-07-27 16:33:00 +00:00
|
|
|
$("input[name=comment]", container).val("");
|
2019-10-08 17:58:46 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
$(document).on("click", ".js-remove-dhcp-static-lease", function(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
$(this).parents(".js-dhcp-static-lease-row").remove();
|
|
|
|
});
|
|
|
|
|
|
|
|
$(document).on("submit", ".js-dhcp-settings-form", function(e) {
|
|
|
|
$(".js-add-dhcp-static-lease").trigger("click");
|
|
|
|
});
|
|
|
|
|
2020-02-28 22:37:52 +00:00
|
|
|
$(document).on("click", ".js-add-dhcp-upstream-server", function(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
var field = $("#add-dhcp-upstream-server-field")
|
|
|
|
var row = $("#dhcp-upstream-server").html().replace("{{ server }}", field.val())
|
|
|
|
|
|
|
|
if (field.val().trim() == "") { return }
|
|
|
|
|
|
|
|
$(".js-dhcp-upstream-servers").append(row)
|
|
|
|
|
|
|
|
field.val("")
|
|
|
|
});
|
|
|
|
|
|
|
|
$(document).on("click", ".js-remove-dhcp-upstream-server", function(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
$(this).parents(".js-dhcp-upstream-server").remove();
|
|
|
|
});
|
|
|
|
|
|
|
|
$(document).on("submit", ".js-dhcp-settings-form", function(e) {
|
|
|
|
$(".js-add-dhcp-upstream-server").trigger("click");
|
|
|
|
});
|
|
|
|
|
2020-03-04 18:43:22 +00:00
|
|
|
/**
|
|
|
|
* mark a form field, e.g. a select box, with the class `.js-field-preset`
|
|
|
|
* and give it an attribute `data-field-preset-target` with a text field's
|
|
|
|
* css selector.
|
|
|
|
*
|
|
|
|
* now, if the element marked `.js-field-preset` receives a `change` event,
|
|
|
|
* its value will be copied to all elements matching the selector in
|
|
|
|
* data-field-preset-target.
|
|
|
|
*/
|
|
|
|
$(document).on("change", ".js-field-preset", function(e) {
|
|
|
|
var selector = this.getAttribute("data-field-preset-target")
|
|
|
|
var value = "" + this.value
|
|
|
|
var syncValue = function(el) { el.value = value }
|
|
|
|
|
|
|
|
if (value.trim() === "") { return }
|
|
|
|
|
|
|
|
document.querySelectorAll(selector).forEach(syncValue)
|
|
|
|
});
|
|
|
|
|
2020-02-27 17:21:57 +00:00
|
|
|
$(document).on("click", "#gen_wpa_passphrase", function(e) {
|
|
|
|
$('#txtwpapassphrase').val(genPassword(63));
|
|
|
|
});
|
|
|
|
|
2024-03-08 09:45:05 +00:00
|
|
|
$(document).on("click", "#gen_apikey", function(e) {
|
|
|
|
$('#txtapikey').val(genPassword(32).toLowerCase());
|
|
|
|
});
|
|
|
|
|
2022-09-26 19:54:12 +00:00
|
|
|
$(document).on("click", "#js-clearhostapd-log", function(e) {
|
2023-09-16 08:39:14 +00:00
|
|
|
var csrfToken = $('meta[name=csrf_token]').attr('content');
|
|
|
|
$.post('ajax/logging/clearlog.php?',{'logfile':'/tmp/hostapd.log', 'csrf_token': csrfToken},function(data){
|
2022-09-26 19:54:12 +00:00
|
|
|
jsonData = JSON.parse(data);
|
|
|
|
$("#hostapd-log").val("");
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-09-27 09:46:59 +00:00
|
|
|
$(document).on("click", "#js-cleardnsmasq-log", function(e) {
|
2023-09-16 08:39:14 +00:00
|
|
|
var csrfToken = $('meta[name=csrf_token]').attr('content');
|
|
|
|
$.post('ajax/logging/clearlog.php?',{'logfile':'/var/log/dnsmasq.log', 'csrf_token': csrfToken},function(data){
|
2022-09-27 09:46:59 +00:00
|
|
|
jsonData = JSON.parse(data);
|
|
|
|
$("#dnsmasq-log").val("");
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-09-27 10:04:54 +00:00
|
|
|
$(document).on("click", "#js-clearopenvpn-log", function(e) {
|
2023-09-16 08:39:14 +00:00
|
|
|
var csrfToken = $('meta[name=csrf_token]').attr('content');
|
|
|
|
$.post('ajax/logging/clearlog.php?',{'logfile':'/tmp/openvpn.log', 'csrf_token': csrfToken},function(data){
|
2022-09-27 10:04:54 +00:00
|
|
|
jsonData = JSON.parse(data);
|
|
|
|
$("#openvpn-log").val("");
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2021-04-20 14:19:00 +00:00
|
|
|
// Enable Bootstrap tooltips
|
|
|
|
$(function () {
|
|
|
|
$('[data-toggle="tooltip"]').tooltip()
|
|
|
|
})
|
|
|
|
|
2020-02-27 17:21:57 +00:00
|
|
|
function genPassword(pwdLen) {
|
|
|
|
var pwdChars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
|
|
|
var rndPass = Array(pwdLen).fill(pwdChars).map(function(x) { return x[Math.floor(Math.random() * x.length)] }).join('');
|
|
|
|
return rndPass;
|
|
|
|
}
|
|
|
|
|
2019-10-08 17:58:46 +00:00
|
|
|
function setupBtns() {
|
|
|
|
$('#btnSummaryRefresh').click(function(){getAllInterfaces();});
|
|
|
|
$('.intsave').click(function(){
|
|
|
|
var int = $(this).data('int');
|
2021-11-25 09:02:59 +00:00
|
|
|
saveNetworkSettings(int);
|
2019-10-08 17:58:46 +00:00
|
|
|
});
|
|
|
|
$('.intapply').click(function(){
|
|
|
|
applyNetworkSettings();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function setCSRFTokenHeader(event, xhr, settings) {
|
|
|
|
var csrfToken = $('meta[name=csrf_token]').attr('content');
|
|
|
|
if (/^(POST|PATCH|PUT|DELETE)$/i.test(settings.type)) {
|
|
|
|
xhr.setRequestHeader("X-CSRF-Token", csrfToken);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function contentLoaded() {
|
2020-12-15 13:48:51 +00:00
|
|
|
pageCurrent = window.location.href.split("/").pop();
|
2019-10-08 17:58:46 +00:00
|
|
|
switch(pageCurrent) {
|
|
|
|
case "network_conf":
|
|
|
|
getAllInterfaces();
|
|
|
|
setupTabs();
|
|
|
|
setupBtns();
|
2021-02-02 04:30:24 +00:00
|
|
|
break;
|
2019-12-27 06:43:49 +00:00
|
|
|
case "hostapd_conf":
|
2023-11-05 13:44:45 +00:00
|
|
|
getChannel();
|
2023-03-19 15:47:30 +00:00
|
|
|
setHardwareModeTooltip();
|
2021-02-02 04:30:24 +00:00
|
|
|
break;
|
2020-11-19 12:31:48 +00:00
|
|
|
case "dhcpd_conf":
|
2020-11-21 13:52:20 +00:00
|
|
|
loadInterfaceDHCPSelect();
|
2019-10-08 17:58:46 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function loadWifiStations(refresh) {
|
|
|
|
return function() {
|
|
|
|
var complete = function() { $(this).removeClass('loading-spinner'); }
|
|
|
|
var qs = refresh === true ? '?refresh' : '';
|
|
|
|
$('.js-wifi-stations')
|
|
|
|
.addClass('loading-spinner')
|
|
|
|
.empty()
|
2019-11-04 16:15:04 +00:00
|
|
|
.load('ajax/networking/wifi_stations.php'+qs, complete);
|
2019-10-08 17:58:46 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
$(".js-reload-wifi-stations").on("click", loadWifiStations(true));
|
|
|
|
|
2020-11-30 17:33:17 +00:00
|
|
|
/*
|
|
|
|
Populates the DHCP server form fields
|
|
|
|
Option toggles are set dynamically depending on the loaded configuration
|
|
|
|
*/
|
2020-11-21 13:52:20 +00:00
|
|
|
function loadInterfaceDHCPSelect() {
|
2021-05-01 16:24:37 +00:00
|
|
|
var strInterface = $('#cbxdhcpiface').val();
|
2024-03-11 17:52:34 +00:00
|
|
|
var csrfToken = $('meta[name=csrf_token]').attr('content');
|
|
|
|
$.post('ajax/networking/get_netcfg.php', {'iface' : strInterface, 'csrf_token': csrfToken}, function(data){
|
2020-11-16 18:19:40 +00:00
|
|
|
jsonData = JSON.parse(data);
|
|
|
|
$('#dhcp-iface')[0].checked = jsonData.DHCPEnabled;
|
2020-11-26 17:16:54 +00:00
|
|
|
$('#txtipaddress').val(jsonData.StaticIP);
|
2020-11-30 12:10:44 +00:00
|
|
|
$('#txtsubnetmask').val(jsonData.SubnetMask);
|
2020-11-26 17:16:54 +00:00
|
|
|
$('#txtgateway').val(jsonData.StaticRouters);
|
|
|
|
$('#chkfallback')[0].checked = jsonData.FallbackEnabled;
|
2021-04-02 23:43:42 +00:00
|
|
|
$('#default-route').prop('checked', jsonData.DefaultRoute);
|
2023-05-19 11:18:25 +00:00
|
|
|
if (strInterface.startsWith("wl")) {
|
|
|
|
$('#nohook-wpa-supplicant').parent().parent().parent().show()
|
|
|
|
$('#nohook-wpa-supplicant').prop('checked', jsonData.NoHookWPASupplicant);
|
|
|
|
} else {
|
|
|
|
$('#nohook-wpa-supplicant').parent().parent().parent().hide()
|
|
|
|
}
|
2020-11-16 18:19:40 +00:00
|
|
|
$('#txtrangestart').val(jsonData.RangeStart);
|
|
|
|
$('#txtrangeend').val(jsonData.RangeEnd);
|
|
|
|
$('#txtrangeleasetime').val(jsonData.leaseTime);
|
|
|
|
$('#txtdns1').val(jsonData.DNS1);
|
|
|
|
$('#txtdns2').val(jsonData.DNS2);
|
|
|
|
$('#cbxrangeleasetimeunits').val(jsonData.leaseTimeInterval);
|
2020-11-17 11:18:10 +00:00
|
|
|
$('#no-resolv')[0].checked = jsonData.upstreamServersEnabled;
|
|
|
|
$('#cbxdhcpupstreamserver').val(jsonData.upstreamServers[0]);
|
2020-11-26 17:16:54 +00:00
|
|
|
$('#txtmetric').val(jsonData.Metric);
|
2020-11-30 17:33:17 +00:00
|
|
|
|
2020-11-30 12:10:44 +00:00
|
|
|
if (jsonData.StaticIP !== null && jsonData.StaticIP !== '' && !jsonData.FallbackEnabled) {
|
2024-10-28 07:28:59 +00:00
|
|
|
$('#chkstatic').prop('checked', true).closest('.btn').addClass('active');
|
|
|
|
$('#chkdhcp').prop('checked', false).closest('.btn').removeClass('active');
|
2020-11-27 16:25:46 +00:00
|
|
|
$('#chkfallback').prop('disabled', true);
|
2023-11-09 16:26:51 +00:00
|
|
|
$('#dhcp-iface').removeAttr('disabled');
|
2020-11-26 17:16:54 +00:00
|
|
|
} else {
|
2024-10-28 07:28:59 +00:00
|
|
|
$('#chkdhcp').closest('.btn').addClass('active');
|
|
|
|
$('#chkdhcp').closest('.btn').button.blur();
|
2020-11-26 17:16:54 +00:00
|
|
|
}
|
2020-11-30 17:33:17 +00:00
|
|
|
if (jsonData.FallbackEnabled || $('#chkdhcp').is(':checked')) {
|
2020-11-30 12:10:44 +00:00
|
|
|
$('#dhcp-iface').prop('disabled', true);
|
2023-11-09 16:26:51 +00:00
|
|
|
setDhcpFieldsDisabled();
|
2020-11-30 12:10:44 +00:00
|
|
|
}
|
2020-11-16 18:19:40 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-11-27 16:25:46 +00:00
|
|
|
function setDHCPToggles(state) {
|
2020-11-30 17:33:17 +00:00
|
|
|
if ($('#chkfallback').is(':checked') && state) {
|
|
|
|
$('#chkfallback').prop('checked', state);
|
|
|
|
}
|
|
|
|
if ($('#dhcp-iface').is(':checked') && !state) {
|
|
|
|
$('#dhcp-iface').prop('checked', state);
|
2023-11-09 16:26:51 +00:00
|
|
|
setDhcpFieldsDisabled();
|
2020-11-30 17:33:17 +00:00
|
|
|
}
|
2020-11-27 16:25:46 +00:00
|
|
|
$('#chkfallback').prop('disabled', state);
|
|
|
|
$('#dhcp-iface').prop('disabled', !state);
|
|
|
|
}
|
|
|
|
|
2024-10-28 07:28:59 +00:00
|
|
|
$('#chkfallback').change(function() {
|
|
|
|
if ($('#chkfallback').is(':checked')) {
|
|
|
|
setStaticFieldsEnabled();
|
|
|
|
} else {
|
|
|
|
setStaticFieldsDisabled();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2023-10-31 20:31:27 +00:00
|
|
|
$('#debugModal').on('shown.bs.modal', function (e) {
|
|
|
|
var csrfToken = $('meta[name=csrf_token]').attr('content');
|
|
|
|
$.post('ajax/system/sys_debug.php',{'csrf_token': csrfToken},function(data){
|
2023-12-31 08:03:19 +00:00
|
|
|
window.location.replace('/ajax/system/sys_get_logfile.php');
|
2023-10-31 20:31:27 +00:00
|
|
|
$('#debugModal').modal('hide');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2023-11-20 14:45:55 +00:00
|
|
|
$('#chkupdateModal').on('shown.bs.modal', function (e) {
|
|
|
|
var csrfToken = $('meta[name=csrf_token]').attr('content');
|
|
|
|
$.post('ajax/system/sys_chk_update.php',{'csrf_token': csrfToken},function(data){
|
|
|
|
var response = JSON.parse(data);
|
|
|
|
var tag = response.tag;
|
|
|
|
var update = response.update;
|
|
|
|
var msg;
|
|
|
|
var msgUpdate = $('#msgUpdate').data('message');
|
|
|
|
var msgLatest = $('#msgLatest').data('message');
|
|
|
|
var msgInstall = $('#msgInstall').data('message');
|
|
|
|
var msgDismiss = $('#js-check-dismiss').data('message');
|
|
|
|
var faCheck = '<i class="fas fa-check ml-2"></i><br />';
|
2023-11-23 07:49:03 +00:00
|
|
|
$("#updateSync").removeClass("fa-spin");
|
2023-11-20 14:45:55 +00:00
|
|
|
if (update === true) {
|
|
|
|
msg = msgUpdate +' '+tag;
|
|
|
|
$("#msg-check-update").html(msg);
|
|
|
|
$("#msg-check-update").append(faCheck);
|
|
|
|
$("#msg-check-update").append("<p>"+msgInstall+"</p>");
|
|
|
|
$("#js-sys-check-update").removeClass("collapse");
|
|
|
|
} else {
|
|
|
|
msg = msgLatest;
|
|
|
|
dismiss = $("#js-check-dismiss");
|
|
|
|
$("#msg-check-update").html(msg);
|
|
|
|
$("#msg-check-update").append(faCheck);
|
|
|
|
$("#js-sys-check-update").remove();
|
|
|
|
dismiss.text(msgDismiss);
|
|
|
|
dismiss.removeClass("btn-outline-secondary");
|
|
|
|
dismiss.addClass("btn-primary");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2023-11-24 18:10:16 +00:00
|
|
|
$('#performUpdate').on('submit', function(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
var csrfToken = $('meta[name=csrf_token]').attr('content');
|
|
|
|
$.post('ajax/system/sys_perform_update.php',{
|
|
|
|
'csrf_token': csrfToken
|
|
|
|
})
|
2023-11-20 14:45:55 +00:00
|
|
|
$('#chkupdateModal').modal('hide');
|
2023-11-23 07:49:03 +00:00
|
|
|
$('#performupdateModal').modal('show');
|
2023-11-20 14:45:55 +00:00
|
|
|
});
|
|
|
|
|
2023-11-23 07:49:03 +00:00
|
|
|
$('#performupdateModal').on('shown.bs.modal', function (e) {
|
|
|
|
fetchUpdateResponse();
|
2023-11-20 14:45:55 +00:00
|
|
|
});
|
|
|
|
|
2023-11-23 07:49:03 +00:00
|
|
|
function fetchUpdateResponse() {
|
|
|
|
const xhr = new XMLHttpRequest();
|
2023-11-23 07:54:38 +00:00
|
|
|
const complete = 6;
|
|
|
|
const error = 7;
|
2023-11-23 07:49:03 +00:00
|
|
|
let phpFile = 'ajax/system/sys_read_logfile.php';
|
|
|
|
$.ajax({
|
|
|
|
url: phpFile,
|
|
|
|
type: 'GET',
|
|
|
|
success: function(response) {
|
2023-11-23 07:54:38 +00:00
|
|
|
let endPolling = false;
|
2023-11-23 07:49:03 +00:00
|
|
|
for (let i = 1; i <= 6; i++) {
|
|
|
|
let divId = '#updateStep' + i;
|
2023-11-23 07:54:38 +00:00
|
|
|
if (response.includes(i.toString())) {
|
2023-11-23 07:49:03 +00:00
|
|
|
$(divId).removeClass('invisible');
|
|
|
|
}
|
2023-11-23 07:54:38 +00:00
|
|
|
if (response.includes(complete)) {
|
2023-11-23 11:43:38 +00:00
|
|
|
var successMsg = $('#successMsg').data('message');
|
|
|
|
$('#updateMsg').after('<span class="small">' + successMsg + '</span>');
|
|
|
|
$('#updateMsg').addClass('fa-check');
|
|
|
|
$('#updateMsg').removeClass('invisible');
|
2023-11-23 07:54:38 +00:00
|
|
|
$('#updateStep6').removeClass('invisible');
|
|
|
|
$('#updateSync2').removeClass("fa-spin");
|
2023-11-23 11:43:38 +00:00
|
|
|
$('#updateOk').removeAttr('disabled');
|
2023-11-23 07:54:38 +00:00
|
|
|
endPolling = true;
|
|
|
|
break;
|
|
|
|
} else if (response.includes(error)) {
|
|
|
|
var errorMsg = $('#errorMsg').data('message');
|
2023-11-23 11:43:38 +00:00
|
|
|
$('#updateMsg').after('<span class="small">' + errorMsg + '</span>');
|
|
|
|
$('#updateMsg').addClass('fa-times');
|
|
|
|
$('#updateMsg').removeClass('invisible');
|
2023-11-23 07:54:38 +00:00
|
|
|
$('#updateSync2').removeClass("fa-spin");
|
2023-11-23 11:43:38 +00:00
|
|
|
$('#updateOk').removeAttr('disabled');
|
2023-11-23 07:54:38 +00:00
|
|
|
endPolling = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!endPolling) {
|
|
|
|
setTimeout(fetchUpdateResponse, 500);
|
2023-11-23 07:49:03 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
error: function(xhr, status, error) {
|
2023-11-23 07:54:38 +00:00
|
|
|
console.error(error);
|
2023-11-23 07:49:03 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2023-11-20 14:45:55 +00:00
|
|
|
|
2020-12-24 20:52:18 +00:00
|
|
|
$('#hostapdModal').on('shown.bs.modal', function (e) {
|
2023-10-21 14:43:49 +00:00
|
|
|
var seconds = 3;
|
|
|
|
var pct = 0;
|
2020-12-24 20:52:18 +00:00
|
|
|
var countDown = setInterval(function(){
|
|
|
|
if(seconds <= 0){
|
|
|
|
clearInterval(countDown);
|
|
|
|
}
|
2020-12-26 08:51:45 +00:00
|
|
|
document.getElementsByClassName('progress-bar').item(0).setAttribute('style','width:'+Number(pct)+'%');
|
2020-12-24 20:52:18 +00:00
|
|
|
seconds --;
|
2023-10-21 14:43:49 +00:00
|
|
|
pct = Math.floor(100-(seconds*100/4));
|
|
|
|
}, 500);
|
2020-12-24 20:52:18 +00:00
|
|
|
});
|
|
|
|
|
2021-02-02 16:55:46 +00:00
|
|
|
$('#configureClientModal').on('shown.bs.modal', function (e) {
|
|
|
|
});
|
|
|
|
|
2021-02-07 11:59:16 +00:00
|
|
|
$('#ovpn-confirm-delete').on('click', '.btn-delete', function (e) {
|
|
|
|
var cfg_id = $(this).data('recordId');
|
2023-09-16 08:39:14 +00:00
|
|
|
var csrfToken = $('meta[name=csrf_token]').attr('content');
|
|
|
|
$.post('ajax/openvpn/del_ovpncfg.php',{'cfg_id':cfg_id, 'csrf_token': csrfToken},function(data){
|
2021-02-07 11:59:16 +00:00
|
|
|
jsonData = JSON.parse(data);
|
|
|
|
$("#ovpn-confirm-delete").modal('hide');
|
2021-02-07 18:51:21 +00:00
|
|
|
var row = $(document.getElementById("openvpn-client-row-" + cfg_id));
|
|
|
|
row.fadeOut( "slow", function() {
|
|
|
|
row.remove();
|
|
|
|
});
|
2021-02-07 11:59:16 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
$('#ovpn-confirm-delete').on('show.bs.modal', function (e) {
|
|
|
|
var data = $(e.relatedTarget).data();
|
|
|
|
$('.btn-delete', this).data('recordId', data.recordId);
|
|
|
|
});
|
|
|
|
|
|
|
|
$('#ovpn-confirm-activate').on('click', '.btn-activate', function (e) {
|
2021-06-12 12:29:37 +00:00
|
|
|
var cfg_id = $(this).data('record-id');
|
2023-09-16 08:39:14 +00:00
|
|
|
var csrfToken = $('meta[name=csrf_token]').attr('content');
|
|
|
|
$.post('ajax/openvpn/activate_ovpncfg.php',{'cfg_id':cfg_id, 'csrf_token': csrfToken},function(data){
|
2021-02-07 11:59:16 +00:00
|
|
|
jsonData = JSON.parse(data);
|
|
|
|
$("#ovpn-confirm-activate").modal('hide');
|
2021-02-07 13:50:55 +00:00
|
|
|
setTimeout(function(){
|
|
|
|
window.location.reload();
|
|
|
|
},300);
|
2021-02-07 11:59:16 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
$('#ovpn-confirm-activate').on('shown.bs.modal', function (e) {
|
|
|
|
var data = $(e.relatedTarget).data();
|
|
|
|
$('.btn-activate', this).data('recordId', data.recordId);
|
|
|
|
});
|
|
|
|
|
2021-03-27 09:29:09 +00:00
|
|
|
$('#ovpn-userpw,#ovpn-certs').on('click', function (e) {
|
|
|
|
if (this.id == 'ovpn-userpw') {
|
|
|
|
$('#PanelCerts').hide();
|
|
|
|
$('#PanelUserPW').show();
|
|
|
|
} else if (this.id == 'ovpn-certs') {
|
|
|
|
$('#PanelUserPW').hide();
|
|
|
|
$('#PanelCerts').show();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2023-04-03 16:47:58 +00:00
|
|
|
$('#js-system-reset-confirm').on('click', function (e) {
|
2023-04-05 15:03:12 +00:00
|
|
|
var progressText = $('#js-system-reset-confirm').attr('data-message');
|
2023-04-04 20:30:03 +00:00
|
|
|
var successHtml = $('#system-reset-message').attr('data-message');
|
|
|
|
var closeHtml = $('#js-system-reset-cancel').attr('data-message');
|
2023-04-04 20:05:25 +00:00
|
|
|
var csrfToken = $('meta[name=csrf_token]').attr('content');
|
2023-04-05 15:03:12 +00:00
|
|
|
var progressHtml = $('<div>').text(progressText).html() + '<i class="fas fa-cog fa-spin ml-2"></i>';
|
2023-04-04 20:30:03 +00:00
|
|
|
$('#system-reset-message').html(progressHtml);
|
2023-04-04 20:05:25 +00:00
|
|
|
$.post('ajax/networking/do_sys_reset.php?',{'csrf_token':csrfToken},function(data){
|
|
|
|
setTimeout(function(){
|
2023-04-04 20:30:03 +00:00
|
|
|
jsonData = JSON.parse(data);
|
|
|
|
if(jsonData['return'] == 0) {
|
|
|
|
$('#system-reset-message').text(successHtml);
|
|
|
|
} else {
|
|
|
|
$('#system-reset-message').text('Error occured: '+ jsonData['return']);
|
|
|
|
}
|
|
|
|
$("#js-system-reset-confirm").hide();
|
|
|
|
$("#js-system-reset-cancel").text(closeHtml);
|
|
|
|
},750);
|
2023-04-03 16:47:58 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2023-10-08 17:21:43 +00:00
|
|
|
$('#js-sys-reboot, #js-sys-shutdown').on('click', function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
var csrfToken = $('meta[name=csrf_token]').attr('content');
|
|
|
|
var action = $(this).data('action');
|
|
|
|
$.post('ajax/system/sys_actions.php?',{'a': action, 'csrf_token': csrfToken},function(data){
|
|
|
|
var response = JSON.parse(data);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-07-06 22:11:16 +00:00
|
|
|
$(document).ready(function(){
|
2023-11-09 22:48:39 +00:00
|
|
|
$("#PanelManual").hide();
|
|
|
|
$('.ip_address').mask('0ZZ.0ZZ.0ZZ.0ZZ', {
|
|
|
|
translation: {
|
|
|
|
'Z': {
|
|
|
|
pattern: /[0-9]/, optional: true
|
|
|
|
}
|
|
|
|
},
|
|
|
|
placeholder: "___.___.___.___"
|
|
|
|
});
|
2024-01-12 18:01:48 +00:00
|
|
|
$('.date').mask('FF:FF:FF:FF:FF:FF', {
|
|
|
|
translation: {
|
|
|
|
"F": {
|
|
|
|
pattern: /[0-9a-z]/, optional: true
|
|
|
|
}
|
|
|
|
},
|
|
|
|
placeholder: "__:__:__:__:__:__"
|
|
|
|
});
|
2021-07-06 22:11:16 +00:00
|
|
|
});
|
|
|
|
|
2021-07-06 21:18:43 +00:00
|
|
|
$('#wg-upload,#wg-manual').on('click', function (e) {
|
|
|
|
if (this.id == 'wg-upload') {
|
|
|
|
$('#PanelManual').hide();
|
|
|
|
$('#PanelUpload').show();
|
|
|
|
} else if (this.id == 'wg-manual') {
|
|
|
|
$('#PanelUpload').hide();
|
|
|
|
$('#PanelManual').show();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-03-27 16:43:15 +00:00
|
|
|
// Add the following code if you want the name of the file appear on select
|
|
|
|
$(".custom-file-input").on("change", function() {
|
|
|
|
var fileName = $(this).val().split("\\").pop();
|
|
|
|
$(this).siblings(".custom-file-label").addClass("selected").html(fileName);
|
|
|
|
});
|
2021-02-07 11:59:16 +00:00
|
|
|
|
2023-11-05 13:44:45 +00:00
|
|
|
// Retrieves the 'channel' value specified in hostapd.conf
|
|
|
|
function getChannel() {
|
|
|
|
$.get('ajax/networking/get_channel.php',function(data){
|
|
|
|
jsonData = JSON.parse(data);
|
|
|
|
loadChannelSelect(jsonData);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-12-26 06:14:03 +00:00
|
|
|
/*
|
2023-11-05 13:44:45 +00:00
|
|
|
Sets the wirelss channel select options based on frequencies reported by iw.
|
|
|
|
|
|
|
|
See: https://git.kernel.org/pub/scm/linux/kernel/git/sforshee/wireless-regdb.git
|
|
|
|
Also: https://en.wikipedia.org/wiki/List_of_WLAN_channels
|
2019-12-26 06:14:03 +00:00
|
|
|
*/
|
2019-12-27 06:43:49 +00:00
|
|
|
function loadChannelSelect(selected) {
|
2023-11-05 13:44:45 +00:00
|
|
|
var iface = $('#cbxinterface').val();
|
|
|
|
var hwmodeText = '';
|
|
|
|
var csrfToken = $('meta[name=csrf_token]').attr('content');
|
|
|
|
|
|
|
|
// update hardware mode tooltip
|
|
|
|
setHardwareModeTooltip();
|
|
|
|
|
|
|
|
$.post('ajax/networking/get_frequencies.php',{'interface': iface, 'csrf_token': csrfToken, 'selected': selected},function(response){
|
2019-12-31 19:10:48 +00:00
|
|
|
var hw_mode = $('#cbxhwmode').val();
|
|
|
|
var country_code = $('#cbxcountries').val();
|
|
|
|
var channel_select = $('#cbxchannel');
|
2023-11-05 13:44:45 +00:00
|
|
|
var btn_save = $('#btnSaveHostapd');
|
|
|
|
var data = JSON.parse(response);
|
|
|
|
var selectableChannels = [];
|
2019-12-31 19:10:48 +00:00
|
|
|
|
2023-11-05 13:44:45 +00:00
|
|
|
// Map selected hw_mode to available channels
|
2021-08-09 16:54:46 +00:00
|
|
|
if (hw_mode === 'a') {
|
2023-11-05 13:44:45 +00:00
|
|
|
selectableChannels = data.filter(item => item.MHz.toString().startsWith('5'));
|
|
|
|
} else if (hw_mode !== 'ac') {
|
|
|
|
selectableChannels = data.filter(item => item.MHz.toString().startsWith('24'));
|
|
|
|
} else if (hw_mode === 'b') {
|
|
|
|
selectableChannels = data.filter(item => item.MHz.toString().startsWith('24'));
|
|
|
|
} else if (hw_mode === 'ac') {
|
|
|
|
selectableChannels = data.filter(item => item.MHz.toString().startsWith('5'));
|
|
|
|
}
|
|
|
|
|
|
|
|
// If selected channel doeesn't exist in allowed channels, set default or null (unsupported)
|
|
|
|
if (!selectableChannels.find(item => item.Channel === selected)) {
|
|
|
|
if (selectableChannels.length === 0) {
|
|
|
|
selectableChannels[0] = { Channel: null };
|
|
|
|
} else {
|
|
|
|
defaultChannel = selectableChannels[0].Channel;
|
|
|
|
selected = defaultChannel
|
|
|
|
}
|
2019-12-31 19:10:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Set channel select with available values
|
|
|
|
channel_select.empty();
|
2023-11-05 13:44:45 +00:00
|
|
|
if (selectableChannels[0].Channel === null) {
|
|
|
|
channel_select.append($("<option></option>").attr("value", "").text("---"));
|
|
|
|
channel_select.prop("disabled", true);
|
|
|
|
btn_save.prop("disabled", true);
|
|
|
|
} else {
|
|
|
|
channel_select.prop("disabled", false);
|
|
|
|
btn_save.prop("disabled", false);
|
|
|
|
$.each(selectableChannels, function(key,value) {
|
|
|
|
channel_select.append($("<option></option>").attr("value", value.Channel).text(value.Channel));
|
|
|
|
});
|
|
|
|
channel_select.val(selected);
|
|
|
|
}
|
2019-12-26 06:14:03 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-11-05 13:44:45 +00:00
|
|
|
/* Sets hardware mode tooltip text for selected interface
|
|
|
|
* and calls loadChannelSelect()
|
2023-03-19 15:47:30 +00:00
|
|
|
*/
|
|
|
|
function setHardwareModeTooltip() {
|
|
|
|
var iface = $('#cbxinterface').val();
|
2023-03-20 18:14:24 +00:00
|
|
|
var hwmodeText = '';
|
2023-09-14 17:56:36 +00:00
|
|
|
var csrfToken = $('meta[name=csrf_token]').attr('content');
|
2023-03-20 18:14:24 +00:00
|
|
|
// Explanatory text if 802.11ac is disabled
|
|
|
|
if ($('#cbxhwmode').find('option[value="ac"]').prop('disabled') == true ) {
|
|
|
|
var hwmodeText = $('#hwmode').attr('data-tooltip');
|
|
|
|
}
|
2023-11-05 13:44:45 +00:00
|
|
|
$.post('ajax/networking/get_nl80211_band.php?',{'interface': iface, 'csrf_token': csrfToken},function(data){
|
2023-03-20 18:14:24 +00:00
|
|
|
var responseText = JSON.parse(data);
|
|
|
|
$('#tiphwmode').attr('data-original-title', responseText + '\n' + hwmodeText );
|
2023-03-19 15:47:30 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-04-02 07:12:59 +00:00
|
|
|
/* Updates the selected blocklist
|
|
|
|
* Request is passed to an ajax handler to download the associated list.
|
|
|
|
* Interface elements are updated to indicate current progress, status.
|
2020-03-27 09:24:48 +00:00
|
|
|
*/
|
|
|
|
function updateBlocklist() {
|
2023-10-06 12:41:55 +00:00
|
|
|
var opt = $('#cbxblocklist option:selected');
|
|
|
|
var blocklist_id = opt.val();
|
2023-09-16 08:39:14 +00:00
|
|
|
var csrfToken = $('meta[name=csrf_token]').attr('content');
|
2020-03-27 09:24:48 +00:00
|
|
|
if (blocklist_id == '') { return; }
|
2020-03-31 00:04:52 +00:00
|
|
|
$('#cbxblocklist-status').find('i').removeClass('fas fa-check').addClass('fas fa-cog fa-spin');
|
|
|
|
$('#cbxblocklist-status').removeClass('check-hidden').addClass('check-progress');
|
2023-09-16 08:39:14 +00:00
|
|
|
$.post('ajax/adblock/update_blocklist.php',{ 'blocklist_id':blocklist_id, 'csrf_token': csrfToken},function(data){
|
2020-03-27 09:24:48 +00:00
|
|
|
var jsonData = JSON.parse(data);
|
|
|
|
if (jsonData['return'] == '0') {
|
2020-03-31 00:04:52 +00:00
|
|
|
$('#cbxblocklist-status').find('i').removeClass('fas fa-cog fa-spin').addClass('fas fa-check');
|
|
|
|
$('#cbxblocklist-status').removeClass('check-progress').addClass('check-updated').delay(500).animate({ opacity: 1 }, 700);
|
2023-10-06 12:41:55 +00:00
|
|
|
$('#blocklist-'+jsonData['list']).text("Just now");
|
2020-03-27 09:24:48 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
function clearBlocklistStatus() {
|
2020-03-31 00:04:52 +00:00
|
|
|
$('#cbxblocklist-status').removeClass('check-updated').addClass('check-hidden');
|
2020-03-27 09:24:48 +00:00
|
|
|
}
|
2021-02-24 08:45:53 +00:00
|
|
|
|
|
|
|
// Handler for the wireguard generate key button
|
2021-02-24 10:32:07 +00:00
|
|
|
$('.wg-keygen').click(function(){
|
2021-02-24 18:07:19 +00:00
|
|
|
var entity_pub = $(this).parent('div').prev('input[type="text"]');
|
|
|
|
var entity_priv = $(this).parent('div').next('input[type="hidden"]');
|
|
|
|
var updated = entity_pub.attr('name')+"-pubkey-status";
|
2023-09-16 08:39:14 +00:00
|
|
|
var csrfToken = $('meta[name=csrf_token]').attr('content');
|
|
|
|
$.post('ajax/networking/get_wgkey.php',{'entity':entity_pub.attr('name'), 'csrf_token': csrfToken},function(data){
|
2021-02-24 08:45:53 +00:00
|
|
|
var jsonData = JSON.parse(data);
|
2021-02-24 18:07:19 +00:00
|
|
|
entity_pub.val(jsonData.pubkey);
|
2021-02-24 10:32:07 +00:00
|
|
|
$('#' + updated).removeClass('check-hidden').addClass('check-updated').delay(500).animate({ opacity: 1 }, 700);
|
2021-02-24 08:45:53 +00:00
|
|
|
})
|
2021-02-24 10:32:07 +00:00
|
|
|
})
|
2021-02-24 08:45:53 +00:00
|
|
|
|
2021-03-15 10:12:18 +00:00
|
|
|
// Handler for wireguard client.conf download
|
|
|
|
$('.wg-client-dl').click(function(){
|
|
|
|
var req = new XMLHttpRequest();
|
|
|
|
var url = 'ajax/networking/get_wgcfg.php';
|
|
|
|
req.open('get', url, true);
|
|
|
|
req.responseType = 'blob';
|
|
|
|
req.setRequestHeader('Content-type', 'text/plain; charset=UTF-8');
|
|
|
|
req.onreadystatechange = function (event) {
|
|
|
|
if(req.readyState == 4 && req.status == 200) {
|
|
|
|
var blob = req.response;
|
|
|
|
var link=document.createElement('a');
|
|
|
|
link.href=window.URL.createObjectURL(blob);
|
|
|
|
link.download = 'client.conf';
|
|
|
|
link.click();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
req.send();
|
|
|
|
})
|
|
|
|
|
2021-03-07 13:19:56 +00:00
|
|
|
// Event listener for Bootstrap's form validation
|
|
|
|
window.addEventListener('load', function() {
|
|
|
|
// Fetch all the forms we want to apply custom Bootstrap validation styles to
|
|
|
|
var forms = document.getElementsByClassName('needs-validation');
|
|
|
|
// Loop over them and prevent submission
|
|
|
|
var validation = Array.prototype.filter.call(forms, function(form) {
|
|
|
|
form.addEventListener('submit', function(event) {
|
|
|
|
if (form.checkValidity() === false) {
|
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
|
|
|
}
|
|
|
|
form.classList.add('was-validated');
|
|
|
|
}, false);
|
|
|
|
});
|
|
|
|
}, false);
|
|
|
|
|
2023-11-09 16:26:51 +00:00
|
|
|
// DHCP or Static IP option group
|
|
|
|
$('#chkstatic').on('change', function() {
|
|
|
|
if (this.checked) {
|
|
|
|
setStaticFieldsEnabled();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$('#chkdhcp').on('change', function() {
|
|
|
|
this.checked ? setStaticFieldsDisabled() : null;
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
$('input[name="dhcp-iface"]').change(function() {
|
|
|
|
if ($('input[name="dhcp-iface"]:checked').val() == '1') {
|
|
|
|
setDhcpFieldsEnabled();
|
|
|
|
} else {
|
|
|
|
setDhcpFieldsDisabled();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
function setStaticFieldsEnabled() {
|
|
|
|
$('#txtipaddress').prop('required', true);
|
|
|
|
$('#txtsubnetmask').prop('required', true);
|
|
|
|
$('#txtgateway').prop('required', true);
|
|
|
|
|
|
|
|
$('#txtipaddress').removeAttr('disabled');
|
|
|
|
$('#txtsubnetmask').removeAttr('disabled');
|
|
|
|
$('#txtgateway').removeAttr('disabled');
|
|
|
|
}
|
|
|
|
|
|
|
|
function setStaticFieldsDisabled() {
|
|
|
|
$('#txtipaddress').prop('disabled', true);
|
|
|
|
$('#txtsubnetmask').prop('disabled', true);
|
|
|
|
$('#txtgateway').prop('disabled', true);
|
|
|
|
|
|
|
|
$('#txtipaddress').removeAttr('required');
|
|
|
|
$('#txtsubnetmask').removeAttr('required');
|
|
|
|
$('#txtgateway').removeAttr('required');
|
|
|
|
}
|
|
|
|
|
|
|
|
function setDhcpFieldsEnabled() {
|
|
|
|
$('#txtrangestart').prop('required', true);
|
|
|
|
$('#txtrangeend').prop('required', true);
|
|
|
|
$('#txtrangeleasetime').prop('required', true);
|
|
|
|
$('#cbxrangeleasetimeunits').prop('required', true);
|
|
|
|
|
|
|
|
$('#txtrangestart').removeAttr('disabled');
|
|
|
|
$('#txtrangeend').removeAttr('disabled');
|
|
|
|
$('#txtrangeleasetime').removeAttr('disabled');
|
|
|
|
$('#cbxrangeleasetimeunits').removeAttr('disabled');
|
|
|
|
$('#txtdns1').removeAttr('disabled');
|
|
|
|
$('#txtdns2').removeAttr('disabled');
|
|
|
|
$('#txtmetric').removeAttr('disabled');
|
|
|
|
}
|
|
|
|
|
|
|
|
function setDhcpFieldsDisabled() {
|
|
|
|
$('#txtrangestart').removeAttr('required');
|
|
|
|
$('#txtrangeend').removeAttr('required');
|
|
|
|
$('#txtrangeleasetime').removeAttr('required');
|
|
|
|
$('#cbxrangeleasetimeunits').removeAttr('required');
|
|
|
|
|
|
|
|
$('#txtrangestart').prop('disabled', true);
|
|
|
|
$('#txtrangeend').prop('disabled', true);
|
|
|
|
$('#txtrangeleasetime').prop('disabled', true);
|
|
|
|
$('#cbxrangeleasetimeunits').prop('disabled', true);
|
|
|
|
$('#txtdns1').prop('disabled', true);
|
|
|
|
$('#txtdns2').prop('disabled', true);
|
|
|
|
$('#txtmetric').prop('disabled', true);
|
|
|
|
}
|
|
|
|
|
2019-12-26 06:14:03 +00:00
|
|
|
// Static Array method
|
|
|
|
Array.range = (start, end) => Array.from({length: (end - start)}, (v, k) => k + start);
|
|
|
|
|
2019-10-08 17:58:46 +00:00
|
|
|
$(document).on("click", ".js-toggle-password", function(e) {
|
|
|
|
var button = $(e.target)
|
|
|
|
var field = $(button.data("target"));
|
2023-03-24 11:02:50 +00:00
|
|
|
|
2019-10-08 17:58:46 +00:00
|
|
|
if (field.is(":input")) {
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
if (!button.data("__toggle-with-initial")) {
|
2023-03-24 11:02:50 +00:00
|
|
|
$("i", this).removeClass("fas fa-eye").addClass(button.attr("data-toggle-with"));
|
2019-10-08 17:58:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (field.attr("type") === "password") {
|
|
|
|
field.attr("type", "text");
|
|
|
|
} else {
|
2023-03-24 11:02:50 +00:00
|
|
|
$("i", this).removeClass("fas fa-eye-slash").addClass("fas fa-eye");
|
2019-10-08 17:58:46 +00:00
|
|
|
field.attr("type", "password");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$(function() {
|
|
|
|
$('#theme-select').change(function() {
|
2024-03-21 20:31:37 +00:00
|
|
|
var theme = themes[$( "#theme-select" ).val() ];
|
|
|
|
|
|
|
|
var hasDarkTheme = theme === 'custom.php' ||
|
|
|
|
theme === 'material-light.php';
|
|
|
|
var nightModeChecked = $("#night-mode").prop("checked");
|
|
|
|
|
|
|
|
if (nightModeChecked && hasDarkTheme) {
|
|
|
|
if (theme === "custom.php") {
|
|
|
|
set_theme("lightsout.php");
|
|
|
|
} else if (theme === "material-light.php") {
|
|
|
|
set_theme("material-dark.php");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
set_theme(theme);
|
|
|
|
}
|
2019-10-08 17:58:46 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
function set_theme(theme) {
|
|
|
|
$('link[title="main"]').attr('href', 'app/css/' + theme);
|
|
|
|
// persist selected theme in cookie
|
|
|
|
setCookie('theme',theme,90);
|
|
|
|
}
|
|
|
|
|
2021-02-15 19:02:13 +00:00
|
|
|
$(function() {
|
2023-08-28 21:17:31 +00:00
|
|
|
var currentTheme = getCookie('theme');
|
|
|
|
// Check if the current theme is a dark theme
|
2023-11-29 09:20:27 +00:00
|
|
|
var isDarkTheme = currentTheme === 'lightsout.php' || currentTheme === 'material-dark.php';
|
2023-08-28 21:17:31 +00:00
|
|
|
|
|
|
|
$('#night-mode').prop('checked', isDarkTheme);
|
2021-02-15 19:02:13 +00:00
|
|
|
$('#night-mode').change(function() {
|
|
|
|
var state = $(this).is(':checked');
|
2023-08-28 21:17:31 +00:00
|
|
|
var currentTheme = getCookie('theme');
|
|
|
|
|
|
|
|
if (state == true) {
|
|
|
|
if (currentTheme == 'custom.php') {
|
2023-11-29 09:20:27 +00:00
|
|
|
set_theme('lightsout.php');
|
2023-08-28 21:17:31 +00:00
|
|
|
} else if (currentTheme == 'material-light.php') {
|
|
|
|
set_theme('material-dark.php');
|
|
|
|
}
|
2021-02-15 19:02:13 +00:00
|
|
|
} else {
|
2023-11-29 09:20:27 +00:00
|
|
|
if (currentTheme == 'lightsout.php') {
|
2023-08-28 21:17:31 +00:00
|
|
|
set_theme('custom.php');
|
|
|
|
} else if (currentTheme == 'material-dark.php') {
|
|
|
|
set_theme('material-light.php');
|
|
|
|
}
|
2021-02-15 19:02:13 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-10-08 17:58:46 +00:00
|
|
|
function setCookie(cname, cvalue, exdays) {
|
|
|
|
var d = new Date();
|
|
|
|
d.setTime(d.getTime() + (exdays*24*60*60*1000));
|
|
|
|
var expires = "expires="+ d.toUTCString();
|
|
|
|
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
|
|
|
|
}
|
|
|
|
|
2019-10-20 17:26:25 +00:00
|
|
|
function getCookie(cname) {
|
|
|
|
var regx = new RegExp(cname + "=([^;]+)");
|
|
|
|
var value = regx.exec(document.cookie);
|
|
|
|
return (value != null) ? unescape(value[1]) : null;
|
|
|
|
}
|
|
|
|
|
2020-06-30 15:54:30 +00:00
|
|
|
// Define themes
|
2019-10-08 17:58:46 +00:00
|
|
|
var themes = {
|
2020-06-30 15:54:30 +00:00
|
|
|
"default": "custom.php",
|
2019-10-08 17:58:46 +00:00
|
|
|
"hackernews" : "hackernews.css",
|
2023-11-29 09:20:27 +00:00
|
|
|
"lightsout" : "lightsout.php",
|
2023-08-28 12:31:23 +00:00
|
|
|
"material-light" : "material-light.php",
|
|
|
|
"material-dark" : "material-dark.php",
|
2019-10-08 17:58:46 +00:00
|
|
|
}
|
|
|
|
|
2019-10-24 20:38:33 +00:00
|
|
|
// Toggles the sidebar navigation.
|
|
|
|
// Overrides the default SB Admin 2 behavior
|
|
|
|
$("#sidebarToggleTopbar").on('click', function(e) {
|
|
|
|
$("body").toggleClass("sidebar-toggled");
|
2019-10-28 20:22:32 +00:00
|
|
|
$(".sidebar").toggleClass("toggled d-none");
|
2019-10-24 20:38:33 +00:00
|
|
|
});
|
|
|
|
|
2019-10-28 16:28:48 +00:00
|
|
|
// Overrides SB Admin 2
|
|
|
|
$("#sidebarToggle, #sidebarToggleTop").on('click', function(e) {
|
|
|
|
var toggled = $(".sidebar").hasClass("toggled");
|
|
|
|
// Persist state in cookie
|
2019-10-29 14:18:16 +00:00
|
|
|
setCookie('sidebarToggled',toggled, 90);
|
2019-10-28 16:28:48 +00:00
|
|
|
});
|
|
|
|
|
2019-10-24 20:38:33 +00:00
|
|
|
$(function() {
|
|
|
|
if ($(window).width() < 768) {
|
|
|
|
$('.sidebar').addClass('toggled');
|
2019-10-29 14:18:16 +00:00
|
|
|
setCookie('sidebarToggled',false, 90);
|
2019-10-24 20:38:33 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-10-28 16:28:48 +00:00
|
|
|
$(window).on("load resize",function(e) {
|
2019-10-24 20:38:33 +00:00
|
|
|
if ($(window).width() > 768) {
|
2019-10-29 14:18:16 +00:00
|
|
|
$('.sidebar').removeClass('d-none d-md-block');
|
|
|
|
if (getCookie('sidebarToggled') == 'false') {
|
|
|
|
$('.sidebar').removeClass('toggled');
|
|
|
|
}
|
|
|
|
}
|
2019-10-24 21:23:57 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// Adds active class to current nav-item
|
|
|
|
$(window).bind("load", function() {
|
|
|
|
var url = window.location;
|
|
|
|
$('ul.navbar-nav a').filter(function() {
|
2019-11-04 16:15:04 +00:00
|
|
|
return this.href == url;
|
|
|
|
}).parent().addClass('active');
|
2019-10-24 21:23:57 +00:00
|
|
|
});
|
2019-10-24 20:38:33 +00:00
|
|
|
|
2019-10-08 17:58:46 +00:00
|
|
|
$(document)
|
|
|
|
.ajaxSend(setCSRFTokenHeader)
|
|
|
|
.ready(contentLoaded)
|
2019-12-27 06:43:49 +00:00
|
|
|
.ready(loadWifiStations());
|