Guest WiFi QR Code (via luci-app-commands?)

OK, as I said before: this is quick & dirty only tested for my needs. This snippet makes a backup of the original sysauth.htm and adds all APs it finds in the wireless configuration:

#!/bin/sh

. /lib/functions.sh

ssid_list=""
luci_file="/usr/lib/lua/luci/view/sysauth.htm"
backup_file="/usr/lib/lua/luci/view/sysauth.htm.backup"

handle_qrcode()
{
	local device mode ssid pass

	device="$(uci_get "wireless" "${section}" "device")"
	mode="$(uci_get "wireless" "${section}" "mode")"
	ssid="$(uci_get "wireless" "${section}" "ssid")"
	pass="$(uci_get "wireless" "${section}" "key")"

	if [ -n "${ssid}" ] && [ -n "${pass}" ] && [ "${mode}"="ap" ] && [ -z "$(printf "%s" "${ssid_list}" | grep -o "${ssid}")" ]
	then
		ssid_list="${ssid_list} ${ssid}"
		printf "%s\n" "<div>" >> "${luci_file}"
		printf "%s\n" "<hr />" >> "${luci_file}"
		printf "%s\n" "<em>AP on ${device} with SSID ${ssid} </em>" >> "${luci_file}"
		printf "%s\n" "<hr />" >> "${luci_file}"
		qrencode --inline --8bit --type=SVG --output=- "WIFI:S:${ssid};T:WPA;P:${pass};" >> "${luci_file}"
		printf "%s\n" "</div>" >> "${luci_file}"
	fi
}

if [ ! -f "${backup_file}" ]
then
	cp -p "${luci_file}" "${backup_file}"
fi
head -n-1 "${backup_file}" > "${luci_file}"

config_load wireless
config_foreach handle_qrcode

printf "%s\n" "<%+footer%>" >> "${luci_file}"
8 Likes