mirror of
https://github.com/j-a-n/raspberrymatic-addon-rmupdate.git
synced 2023-10-10 13:37:40 +02:00
Implement wlan connect / disconnect
This commit is contained in:
parent
bf1a733119
commit
e18c9ac2f6
@ -1032,6 +1032,7 @@ proc ::rmupdate::wlan_scan {{as_json 0} {device "wlan0"}} {
|
||||
set data [exec /usr/sbin/iw $device scan]
|
||||
set cur_ssid ""
|
||||
set cur_signal ""
|
||||
set cur_connected 0
|
||||
foreach d [split $data "\n"] {
|
||||
if { [regexp {^\s*SSID:\s*(\S.*)\s*$} $d match ssid] } {
|
||||
set cur_ssid $ssid
|
||||
@ -1043,8 +1044,13 @@ proc ::rmupdate::wlan_scan {{as_json 0} {device "wlan0"}} {
|
||||
if {$cur_ssid != "" && $cur_signal != ""} {
|
||||
set ssids(${cur_ssid}::ssid) $cur_ssid
|
||||
set ssids(${cur_ssid}::signal) $cur_signal
|
||||
set ssids(${cur_ssid}::connected) $cur_connected
|
||||
set cur_ssid ""
|
||||
set cur_signal ""
|
||||
set cur_connected 0
|
||||
}
|
||||
if { [regexp {associated} $d match] } {
|
||||
set cur_connected 1
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1060,6 +1066,48 @@ proc ::rmupdate::wlan_scan {{as_json 0} {device "wlan0"}} {
|
||||
}
|
||||
}
|
||||
|
||||
proc ::rmupdate::wlan_connect {ssid {password ""}} {
|
||||
set psk ""
|
||||
if {$password != ""} {
|
||||
set data [exec /usr/sbin/wpa_passphrase $ssid $password]
|
||||
foreach d [split $data "\n"] {
|
||||
if { [regexp {^\s*psk\s*=\s*(\S+)\s*$} $d match p] } {
|
||||
set psk $p
|
||||
}
|
||||
}
|
||||
}
|
||||
set fd [open /etc/config/wpa_supplicant.conf "w"]
|
||||
puts $fd "ctrl_interface=/var/run/wpa_supplicant"
|
||||
puts $fd "ap_scan=1"
|
||||
puts $fd "network=\{"
|
||||
puts $fd " ssid=\"${ssid}\""
|
||||
puts $fd " scan_ssid=1"
|
||||
if {$psk == ""} {
|
||||
puts $fd " key_mgmt=NONE"
|
||||
} else {
|
||||
puts $fd " proto=WPA RSN"
|
||||
puts $fd " key_mgmt=WPA-PSK"
|
||||
puts $fd " pairwise=CCMP TKIP"
|
||||
puts $fd " group=CCMP TKIP"
|
||||
puts $fd " psk=${psk}"
|
||||
}
|
||||
puts $fd "\}"
|
||||
close $fd
|
||||
|
||||
catch { exec /sbin/ifdown wlan0 }
|
||||
catch { exec /sbin/ifup wlan0 }
|
||||
}
|
||||
|
||||
proc ::rmupdate::wlan_disconnect {} {
|
||||
set fd [open /etc/config/wpa_supplicant.conf "w"]
|
||||
puts $fd "ctrl_interface=/var/run/wpa_supplicant"
|
||||
puts $fd "ap_scan=1"
|
||||
close $fd
|
||||
|
||||
catch { exec /sbin/ifdown wlan0 }
|
||||
catch { exec /sbin/ifup wlan0 }
|
||||
}
|
||||
|
||||
#puts [rmupdate::get_latest_firmware_version]
|
||||
#puts [rmupdate::get_firmware_info]
|
||||
#puts [rmupdate::get_available_firmware_images]
|
||||
@ -1077,3 +1125,4 @@ proc ::rmupdate::wlan_scan {{as_json 0} {device "wlan0"}} {
|
||||
#puts [rmupdate::get_part_uuid "/dev/mmcblk0p3"]
|
||||
#puts [rmupdate::get_addon_info 1 1]
|
||||
#puts [rmupdate::wlan_scan 1]
|
||||
#rmupdate::wlan_connect xxx yyyyy
|
||||
|
@ -37,6 +37,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
var running_installation = "";
|
||||
var current_firmware = '?';
|
||||
var latest_firmware = '?';
|
||||
var wlanScanTimer;
|
||||
|
||||
function display_message(type, text, millis) {
|
||||
clear_message();
|
||||
@ -416,16 +417,38 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
rest("GET", "/wlan_scan", null, function(data) {
|
||||
$('#wlan-list tbody').empty();
|
||||
data.forEach(function(wlan) {
|
||||
var bconnect = $('<div class="ui green basic button disabled">')
|
||||
.attr('data-connect-ssid', wlan.ssid)
|
||||
var cls = (wlan.connected == "1") ? "disabled" : "";
|
||||
var bconnect = $('<div class="ui green basic button ' + cls + '">')
|
||||
.attr('data-ssid', wlan.ssid)
|
||||
.append($('<i class="sign in icon">'), i18next.t('connect'));
|
||||
$("#wlan-list tbody").append($('<tr>').append(
|
||||
bconnect.click(function() {
|
||||
$('#form-connect-wlan').form('clear');
|
||||
$('#form-connect-wlan').attr('data-ssid', this.getAttribute('data-ssid'));
|
||||
$('#modal-connect-wlan').modal('show');
|
||||
});
|
||||
|
||||
cls = (wlan.connected == "1") ? "" : "disabled";
|
||||
var bdisconnect = $('<div class="ui orange basic button ' + cls + '">')
|
||||
.attr('data-ssid', wlan.ssid)
|
||||
.append($('<i class="delete icon">'), i18next.t('disconnect'));
|
||||
bdisconnect.click(function() {
|
||||
$('.button[data-ssid]').addClass('loading');
|
||||
rest("POST", "/wlan_disconnect");
|
||||
});
|
||||
var connected_checked = ((wlan.connected == "1") ? 'checked=""' : '')
|
||||
cls = (wlan.connected == "1") ? "positive" : "";
|
||||
$("#wlan-list tbody").append($('<tr class="' + cls + '">').append(
|
||||
$('<td>').append($('<label>' + wlan.ssid + '</label>')),
|
||||
$('<td class="center aligned">').append($('<div class="ui disabled checkbox">').append($('<input type="checkbox" disabled="disabled" ' + connected_checked + '>'),$('<label></label>'))),
|
||||
$('<td>').append($('<label>' + wlan.signal + '</label>')),
|
||||
$('<td class="center aligned">').append(bconnect)
|
||||
$('<td class="center aligned">').append(bconnect, bdisconnect)
|
||||
));
|
||||
});
|
||||
setTimeout(function(){ wlan_scan(); }, 5000);
|
||||
wlanScanTimer = setTimeout(function(){ wlan_scan(); }, 5000);
|
||||
},
|
||||
function(xhr, ajaxOptions, thrownError) {
|
||||
clearTimeout(myVar);
|
||||
wlanScanTimer = setTimeout(function(){ wlan_scan(); }, 5000);
|
||||
});
|
||||
}
|
||||
|
||||
@ -480,7 +503,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
wlan: "WLAN",
|
||||
wlan_ssid: "SSID",
|
||||
wlan_signal: "Signal",
|
||||
wlan_connected: "Connected",
|
||||
connect_to_wlan: "Connect with wifi",
|
||||
password: "Password",
|
||||
connect: "Connect",
|
||||
disconnect: "Disconnect",
|
||||
}
|
||||
},
|
||||
de: {
|
||||
@ -529,7 +556,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
wlan: "WLAN",
|
||||
wlan_ssid: "SSID",
|
||||
wlan_signal: "Signal",
|
||||
wlan_connected: "Verbunden",
|
||||
connect_to_wlan: "Mit WLAN verbinden",
|
||||
password: "Passwort",
|
||||
connect: "Verbinden",
|
||||
disconnect: "Trennen",
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -544,6 +575,27 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
$('#install-addon-url-button').contents().last()[0].textContent = i18next.t('install');
|
||||
$('#install-addon-file-button').contents().last()[0].textContent = i18next.t('choose_addon_file');
|
||||
});
|
||||
var form_config = {
|
||||
on: 'blur',
|
||||
fields: {
|
||||
password: {
|
||||
identifier: 'password'
|
||||
}
|
||||
},
|
||||
onSuccess: function(event, fields) {
|
||||
if (wlanScanTimer) {
|
||||
clearTimeout(wlanScanTimer);
|
||||
}
|
||||
wlanScanTimer = setTimeout(function(){ wlan_scan(); }, 10000);
|
||||
$(event.currentTarget).closest("div.modal").modal('hide');
|
||||
var ssid = $('#form-connect-wlan').attr('data-ssid');
|
||||
var password = $(event.currentTarget).form('get value', 'password');
|
||||
$('.button[data-ssid]').addClass('loading');
|
||||
rest("POST", "/wlan_connect", JSON.stringify({"ssid": ssid, "password": password}));
|
||||
event.preventDefault();
|
||||
}
|
||||
};
|
||||
$('#form-connect-wlan').form(form_config);
|
||||
|
||||
rest("GET", "/version", null, function(version) {
|
||||
document.title = document.title + " " + version;
|
||||
@ -676,6 +728,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
<thead>
|
||||
<tr>
|
||||
<th data-i18n="wlan_ssid"></th>
|
||||
<th data-i18n="wlan_connected"></th>
|
||||
<th data-i18n="wlan_signal"></th>
|
||||
<th class="center aligned" data-i18n="action"></th>
|
||||
</tr>
|
||||
@ -712,5 +765,22 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="modal-connect-wlan" class="ui modal">
|
||||
<i class="close icon"></i>
|
||||
<div class="header" data-i18n="connect_to_wlan">
|
||||
</div>
|
||||
<div class="content">
|
||||
<form id="form-connect-wlan" class="ui form">
|
||||
<div class="field">
|
||||
<label data-i18n="password"></label>
|
||||
<input type="password" name="password">
|
||||
</div>
|
||||
<div class="ui error message"></div>
|
||||
<div class="ui button" onclick="$('#modal-connect-wlan').modal('hide');" data-i18n="cancel"></div>
|
||||
<div id="submit-connect-wlan" class="ui primary submit button" data-i18n="connect"></div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
@ -121,6 +121,13 @@ proc process {} {
|
||||
return [rmupdate::read_install_log]
|
||||
} elseif {[lindex $path 1] == "wlan_scan"} {
|
||||
return [rmupdate::wlan_scan 1]
|
||||
} elseif {[lindex $path 1] == "wlan_connect"} {
|
||||
regexp {\"ssid\"\s*:\s*\"([^\"]+)\"} $data match ssid
|
||||
set password ""
|
||||
regexp {\"password\"\s*:\s*\"([^\"]+)\"} $data match password
|
||||
return [rmupdate::wlan_connect $ssid $password]
|
||||
} elseif {[lindex $path 1] == "wlan_disconnect"} {
|
||||
return [rmupdate::wlan_disconnect]
|
||||
}
|
||||
}
|
||||
error "invalid request" "Not found" 404
|
||||
|
Loading…
Reference in New Issue
Block a user