Files
webgui/emhttp/plugins/dynamix/Wireless.page
2025-02-03 17:16:40 +01:00

153 lines
4.7 KiB
Plaintext

Menu="NetworkSettings:1000"
Title="_(Wireless)_ wlan0"
Tag="fa-wifi"
Cond="file_exists('/sys/class/net/wlan0')"
---
<?PHP
/* Copyright 2005-2025, Lime Technology
* Copyright 2012-2025, Bergware International.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*/
?>
<?
$title = _('Connect to WiFi network');
$cfg = '/boot/config/wireless.cfg';
if (file_exists($cfg)) $wlan0 = parse_ini_file($cfg,true)['wlan0'];
?>
<div class="title nocontrol shift">&nbsp;</div>
<form markdown="1" name="wifi_settings" method="POST" action="/update.php" target="progressFrame" onsubmit="enable_wifi(this.WIFI.value)">
<input type="hidden" name="#file" value="<?=$cfg?>"/>
<input type="hidden" name="#section" value="wlan0"/>
<input type="hidden" name="#command" value="/webGui/scripts/wireless">
<input type="hidden" name="#arg[1]" value=""/>
_(Wi-Fi)_:
: <select name="WIFI">
<?=mk_option(_var($wlan0,'WIFI'), "no", _("Disabled"))?>
<?=mk_option(_var($wlan0,'WIFI'), "yes", _("Enabled"))?>
</select>
&nbsp;
: <input type="submit" value="_(Apply)_" disabled><input type="button" value="_(Done)_" onclick="done()">
</form>
<div id="wifi" class="hide">
<div markdown="1" id="connected" class="shade-<?=$display['theme']?>">
_(Connected)_:
: <i class="fa fa-spin fa-circle-o-notch"></i>
</div>
<div markdown="1" id="my_networks" class="shade-<?=$display['theme']?>">
_(My networks)_:
: <i class="fa fa-spin fa-circle-o-notch"></i>
</div>
<div markdown="1" id="other_networks" class="shade-<?=$display['theme']?>">
_(Other networks)_:
: <i class="fa fa-spin fa-circle-o-notch"></i>
</div>
<div markdown="1" class="shade-<?=$display['theme']?>">
_(Add network)_:
: <span class="wifi"><input name="CUSTOM" type="text" class="narrow" maxlength="20" autocomplete="off" spellcheck="false" value=""></span><i class="fa fa-wifi hand grey-text" onclick="manage_wifi(encodeURIComponent($('input[name=CUSTOM]').val()),3)" title="<?=$title?>"></i>
</div>
</div>
<script>
function enable_wifi(state) {
$('input[name="#arg[1]"]').val(state);
}
function update_wifi() {
$.post('/webGui/include/Wireless.php',{cmd:'list'},function(text) {
if (text.length > 0) {
var wifi = JSON.parse(text);
$('#connected').html(wifi.active);
$('#my_networks').html(wifi.saved);
$('#other_networks').html(wifi.other);
}
});
timers.wifi = setTimeout(update_wifi,10000);
}
function manage_wifi(ssid,task) {
if (task==2) {
$.post('/webGui/include/Wireless.php',{cmd:'forget',ssid:ssid},function(){
clearTimeout(timers.wifi);
swal.close();
setTimeout(update_wifi);
});
return;
}
if (ssid) {
$.post('/webGui/include/Wireless.php',{cmd:'join',ssid:ssid,task:task},function(text) {
swal({title:decodeURIComponent(ssid),text:text,animation:'none',html:true,confirmButtonText:"_(Join this network)_",showCancelButton:true,cancelButtonText:"_(Cancel)_"},function(join){
if (join) $('form[name=wifi]').submit();
});
});
} else {
swal({title:"_(Missing Network Name)_",animation:'none',html:true,type:'error',confirmButtonText:"_(Ok)_"});
}
}
function showDHCP(val,v) {
if (val=='no') {
$('tr.static'+v).show();
$('select[name=DNS'+v+']').val('yes');
$('select[name=DNS'+v+'] option:eq(0)').prop('disabled',true);
if (v=='6') $('tr.dns6').show();
$('tr.server'+v).show();
} else if (val=='yes') {
$('tr.static'+v).hide();
$('select[name=DNS'+v+']').val('no');
$('select[name=DNS'+v+'] option:eq(0)').prop('disabled',false);
if (v=='6') $('tr.dns6').show();
$('tr.server'+v).hide();
} else {
$('tr.static'+v).hide();
$('tr.dns'+v).hide();
$('tr.server'+v).hide();
}
}
function showDNS(val,v) {
if (val=='no') $('tr.server'+v).hide();
if (val=='yes') $('tr.server'+v).show();
}
function showPassword() {
if ($('#showPass').hasClass('checked')) {
$('#showPass').removeClass('checked fa-eye-slash').addClass('fa-eye');
var view = 'password';
} else {
$('#showPass').addClass('checked fa-eye-slash').removeClass('fa-eye');
var view = 'text';
}
$('input[name="PASSWORD"]').attr('type',view);
}
function showSecurity(val) {
if (val=='none') {
$('#username,#password').hide();
} else if (val.slice(-1)=='e') {
$('#username,#password').show();
} else {
$('#username').hide();
$('#password').show();
}
}
<?if (_var($wlan0,'WIFI')=='yes'):?>
$(function() {
$('#wifi').show();
update_wifi();
});
<?endif;?>
</script>