mirror of
https://github.com/j-a-n/raspberrymatic-addon-rmupdate.git
synced 2023-10-10 13:37:40 +02:00
Implement wlan scanning
This commit is contained in:
parent
50644651fa
commit
bf1a733119
@ -49,6 +49,35 @@ proc json_string {str} {
|
|||||||
return "[string map $replace_map $str]"
|
return "[string map $replace_map $str]"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
proc array_to_json {a} {
|
||||||
|
array set arr $a
|
||||||
|
set json "\["
|
||||||
|
set keys [array names arr]
|
||||||
|
set keys [lsort $keys]
|
||||||
|
set cur_id ""
|
||||||
|
foreach key $keys {
|
||||||
|
set tmp [split $key "::"]
|
||||||
|
set id [lindex $tmp 0]
|
||||||
|
set opt [lindex $tmp 2]
|
||||||
|
if {$cur_id != $id} {
|
||||||
|
if {$cur_id != ""} {
|
||||||
|
set json [string range $json 0 end-1]
|
||||||
|
append json "\},"
|
||||||
|
}
|
||||||
|
append json "\{"
|
||||||
|
set cur_id $id
|
||||||
|
}
|
||||||
|
set val [json_string $arr($key)]
|
||||||
|
append json "\"${opt}\":\"${val}\","
|
||||||
|
}
|
||||||
|
if {$cur_id != ""} {
|
||||||
|
set json [string range $json 0 end-1]
|
||||||
|
append json "\}"
|
||||||
|
}
|
||||||
|
append json "\]"
|
||||||
|
return $json
|
||||||
|
}
|
||||||
|
|
||||||
proc ::rmupdate::i18n {str} {
|
proc ::rmupdate::i18n {str} {
|
||||||
variable language
|
variable language
|
||||||
if {$language == "de"} {
|
if {$language == "de"} {
|
||||||
@ -897,31 +926,7 @@ proc ::rmupdate::get_addon_info {{fetch_available_version 0} {fetch_download_url
|
|||||||
}
|
}
|
||||||
|
|
||||||
if {$as_json == 1} {
|
if {$as_json == 1} {
|
||||||
set json "\["
|
return [array_to_json [array get addons]]
|
||||||
set keys [array names addons]
|
|
||||||
set keys [lsort $keys]
|
|
||||||
set cur_addon_id ""
|
|
||||||
foreach key $keys {
|
|
||||||
set tmp [split $key "::"]
|
|
||||||
set addon_id [lindex $tmp 0]
|
|
||||||
set opt [lindex $tmp 2]
|
|
||||||
if {$cur_addon_id != $addon_id} {
|
|
||||||
if {$cur_addon_id != ""} {
|
|
||||||
set json [string range $json 0 end-1]
|
|
||||||
append json "\},"
|
|
||||||
}
|
|
||||||
append json "\{"
|
|
||||||
set cur_addon_id $addon_id
|
|
||||||
}
|
|
||||||
set val [json_string $addons($key)]
|
|
||||||
append json "\"${opt}\":\"${val}\","
|
|
||||||
}
|
|
||||||
if {$cur_addon_id != ""} {
|
|
||||||
set json [string range $json 0 end-1]
|
|
||||||
append json "\}"
|
|
||||||
}
|
|
||||||
append json "\]"
|
|
||||||
return $json
|
|
||||||
} else {
|
} else {
|
||||||
return [array get addons]
|
return [array get addons]
|
||||||
}
|
}
|
||||||
@ -1021,6 +1026,40 @@ proc ::rmupdate::install_addon {{addon_id ""} {download_url ""}} {
|
|||||||
return [format [i18n "Addon %s successfully installed."] $addon_id]
|
return [format [i18n "Addon %s successfully installed."] $addon_id]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
proc ::rmupdate::wlan_scan {{as_json 0} {device "wlan0"}} {
|
||||||
|
array set ssids {}
|
||||||
|
set data [exec /usr/sbin/iw $device scan]
|
||||||
|
set cur_ssid ""
|
||||||
|
set cur_signal ""
|
||||||
|
foreach d [split $data "\n"] {
|
||||||
|
if { [regexp {^\s*SSID:\s*(\S.*)\s*$} $d match ssid] } {
|
||||||
|
set cur_ssid $ssid
|
||||||
|
}
|
||||||
|
if { [regexp {^\s*signal:\s*(\S.*)\s*$} $d match signal] } {
|
||||||
|
set cur_signal $signal
|
||||||
|
}
|
||||||
|
if { [regexp {^BSS\s([a-fA-F0-9\:]+)} $d match bss] } {
|
||||||
|
if {$cur_ssid != "" && $cur_signal != ""} {
|
||||||
|
set ssids(${cur_ssid}::ssid) $cur_ssid
|
||||||
|
set ssids(${cur_ssid}::signal) $cur_signal
|
||||||
|
set cur_ssid ""
|
||||||
|
set cur_signal ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if {$cur_ssid != "" && $cur_signal != ""} {
|
||||||
|
set ssids(${cur_ssid}::ssid) $cur_ssid
|
||||||
|
set ssids(${cur_ssid}::signal) $cur_signal
|
||||||
|
}
|
||||||
|
|
||||||
|
if {$as_json == 1} {
|
||||||
|
return [array_to_json [array get ssids]]
|
||||||
|
} else {
|
||||||
|
return [array get ssids]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#puts [rmupdate::get_latest_firmware_version]
|
#puts [rmupdate::get_latest_firmware_version]
|
||||||
#puts [rmupdate::get_firmware_info]
|
#puts [rmupdate::get_firmware_info]
|
||||||
#puts [rmupdate::get_available_firmware_images]
|
#puts [rmupdate::get_available_firmware_images]
|
||||||
@ -1037,4 +1076,4 @@ proc ::rmupdate::install_addon {{addon_id ""} {download_url ""}} {
|
|||||||
#puts [rmupdate::get_rpi_version]
|
#puts [rmupdate::get_rpi_version]
|
||||||
#puts [rmupdate::get_part_uuid "/dev/mmcblk0p3"]
|
#puts [rmupdate::get_part_uuid "/dev/mmcblk0p3"]
|
||||||
#puts [rmupdate::get_addon_info 1 1]
|
#puts [rmupdate::get_addon_info 1 1]
|
||||||
|
#puts [rmupdate::wlan_scan 1]
|
||||||
|
@ -412,6 +412,23 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function wlan_scan() {
|
||||||
|
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)
|
||||||
|
.append($('<i class="sign in icon">'), i18next.t('connect'));
|
||||||
|
$("#wlan-list tbody").append($('<tr>').append(
|
||||||
|
$('<td>').append($('<label>' + wlan.ssid + '</label>')),
|
||||||
|
$('<td>').append($('<label>' + wlan.signal + '</label>')),
|
||||||
|
$('<td class="center aligned">').append(bconnect)
|
||||||
|
));
|
||||||
|
});
|
||||||
|
setTimeout(function(){ wlan_scan(); }, 5000);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
i18next.init({
|
i18next.init({
|
||||||
lng: language,
|
lng: language,
|
||||||
@ -460,6 +477,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
install_addon_from_url: 'Install addon from url',
|
install_addon_from_url: 'Install addon from url',
|
||||||
install_addon_from_file: 'Install addon from file',
|
install_addon_from_file: 'Install addon from file',
|
||||||
choose_addon_file: 'Choose and install addon-file',
|
choose_addon_file: 'Choose and install addon-file',
|
||||||
|
wlan: "WLAN",
|
||||||
|
wlan_ssid: "SSID",
|
||||||
|
wlan_signal: "Signal",
|
||||||
|
connect: "Connect",
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
de: {
|
de: {
|
||||||
@ -505,6 +526,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
install_addon_from_url: 'Addon von URL installieren',
|
install_addon_from_url: 'Addon von URL installieren',
|
||||||
install_addon_from_file: 'Addon aus Datei installieren',
|
install_addon_from_file: 'Addon aus Datei installieren',
|
||||||
choose_addon_file: 'Addon-Datei auswählen und installieren',
|
choose_addon_file: 'Addon-Datei auswählen und installieren',
|
||||||
|
wlan: "WLAN",
|
||||||
|
wlan_ssid: "SSID",
|
||||||
|
wlan_signal: "Signal",
|
||||||
|
connect: "Verbinden",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -531,6 +556,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
get_system_info();
|
get_system_info();
|
||||||
get_firmware_info();
|
get_firmware_info();
|
||||||
get_addon_info();
|
get_addon_info();
|
||||||
|
wlan_scan();
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
@ -639,6 +665,25 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
choose_addon_file
|
choose_addon_file
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<h2 class="ui header">
|
||||||
|
<i class="wifi icon"></i>
|
||||||
|
<div data-i18n="wlan" class="content">
|
||||||
|
</div>
|
||||||
|
</h2>
|
||||||
|
<div>
|
||||||
|
<table id="wlan-list" class="ui celled stackable table">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th data-i18n="wlan_ssid"></th>
|
||||||
|
<th data-i18n="wlan_signal"></th>
|
||||||
|
<th class="center aligned" data-i18n="action"></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div style="height:60vh;" id="modal-log" class="ui modal">
|
<div style="height:60vh;" id="modal-log" class="ui modal">
|
||||||
|
@ -17,6 +17,10 @@
|
|||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#lappend auto_path /www
|
||||||
|
#set env(TCLLIBPATH) [list /www /usr/local/addons/rmupdate/lib]
|
||||||
|
#source once.tcl
|
||||||
|
#source session.tcl
|
||||||
source /usr/local/addons/rmupdate/lib/rmupdate.tcl
|
source /usr/local/addons/rmupdate/lib/rmupdate.tcl
|
||||||
|
|
||||||
proc process {} {
|
proc process {} {
|
||||||
@ -115,6 +119,8 @@ proc process {} {
|
|||||||
} elseif {[lindex $path 1] == "read_install_log"} {
|
} elseif {[lindex $path 1] == "read_install_log"} {
|
||||||
variable content_type "text/html"
|
variable content_type "text/html"
|
||||||
return [rmupdate::read_install_log]
|
return [rmupdate::read_install_log]
|
||||||
|
} elseif {[lindex $path 1] == "wlan_scan"} {
|
||||||
|
return [rmupdate::wlan_scan 1]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
error "invalid request" "Not found" 404
|
error "invalid request" "Not found" 404
|
||||||
|
Loading…
Reference in New Issue
Block a user