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

Fully agree. If somebody knows how to do it off-the-shelf, please let us know.

You could place the qr code as png/svg/... in the folder /www/code.svg then everybody can fetch this image with http://openwrt.lan/code.svg or http://192.168.1.1/code.svg.

Isn't that nice, but you can save the link in your bookmarks or everybody has to remember the url!

For the generation of the qr code you can use this script.

#!/bin/sh

NAME=${1:-$(uci get wireless.default_radio0.ssid)}
KEY=${2:-$(uci get wireless.default_radio0.key)}

command -v qrencode >/dev/null 2>&1 || (
  opkg update && opkg install qrencode
) || exit 1

echo "WIFI:T:WPA;S:${NAME};P:${KEY};;" | qrencode -o /www/code.svg -t SVG
5 Likes

Interesting thread ... on my travel routers I patch the luci login (sysauth.htm) with a little script like that, e.g.:

If this dirty way is a suitable way for you, I can provide the source code of the little script, of course. :wink:

2 Likes

I'm interested and would like to use your script...

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

boxify...

        printf "%s\n" "<div class='ifacebox'>" >> "${luci_file}"
        printf "%s\n" "<div class='ifacebox-head-center'>" >> "${luci_file}"
        printf "%s\n" "<h5>${device} SSID:${ssid}</h5>" >> "${luci_file}"
		printf "%s\n" "</div>" >> "${luci_file}"
        qrencode --inline --8bit --type=SVG --output=- "WIFI:S:${ssid};T:WPA;P:${pass};" >> "${luci_file}"
		printf "%s\n" "</div>" >> "${luci_file}"
4 Likes

Interesting idea I would like to create a nodog captive portal to display by default, and letting there the qr to access a full guess interface

That might actually be interesting, if the QR visibility could be controlled from the settings per AP. For example, you might want to show the guest network but not the private network.

1 Like

OK, I've slightly enhanced the script ... I took the style tweaks from @anon50098793 and added an optional "guest-ssid" parameter. By default all APs are listed, e.g:

With the optional guest ssid parameter (e.g. ./patch.sh "blackhole-win10") only the guest-wifi ssid will be exposed:

And the source ...:slight_smile:

#!/bin/sh

. /lib/functions.sh

ssid_list=""
guest_ssid="${1}"
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 "${guest_ssid}" ] || [ "${guest_ssid}" = "${ssid}" ]; }
    then
	ssid_list="${ssid_list} ${ssid}"
	printf "%s\n" "<div class='ifacebox'>" >> "${luci_file}"
	printf "%s\n" "<div class='ifacebox-head-center'>" >> "${luci_file}"
	printf "%s\n" "<h5 style='padding-left:5px;padding-right:5px;line-height:24px;}'>${device}<br />${ssid}</5>" >> "${luci_file}"
	printf "%s\n" "</div>" >> "${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}"

10 Likes

Sorry to bump this topic! But I thought this was a good idea for a simple iot beginners project. I took the tips in this thread and soldered some AliExpress parts together.

The guest wifi password changes every night with a random generated 12 character string. A QR-code is generated on the Luci login page and also a simple text file in the www folder with the QR-code payload. The ESP8266 (nodemcu) together with a ST7789 LCD-screen refreshes the payload over the main wifi and the display generates a QR-code which a phone can scan.

I'll update this post later with a link to a github repo.

6 Likes

@ psilox whatever happened to the repo. You did a great job on this one. I'm looking forward to seeing how it can become normal.

GREAT ! thanks

Where is everyone storing the script?

/root/ may be sufficient...
You can also add a call from /etc/rc.local to have a fresh update of qrcodes at bootup...

As obvious as it sounds, has anyone proposed the idea of having a dedicated LuCI page to show QR codes for WireGuard client configurations and SSIDs?

It would be a nice feature for OpenWrt to have a page you could display QR codes for the WireGuard client configurations so that clients can QR scan their configuration in with the smartphone app for example and also you could show the QR codes for all of the SSIDs.

1 Like

I fully support this!

Hats off man! I really love this solution!! :slight_smile:

@dibdot How would one go about adding that guest ssid parameter to the code?
I have tried several combinations but no success, atm I have this:

guest_ssid="(./patch.sh "whatevername")"

I would like the same thing but viewable only when authenticated on Luci.

Someone have done like that ?
How can I do that ?

seems not working anymore with latest 22.03.2, any ideas?