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

I want to simplify connecting to my guest network while keeping a security of a 63 char long password. Is anyone aware of a solution to generate/display a QR code?

If not, is there a way to use luci-app-commands to display a generated image?

There is a package called qrencode that you could install, but I'm not sure that it really solves everything because it you'd still need a way to create/call/display the QR Code in the first place.

Can you describe a bit more about your use case? Keep in mind that your guests wouldn't be able to connect to the router to get the QR code in the first place if they don't have the password to connect to the SSID, so unless you are pulling it up for them on your own device, a QR code displayed on the router doesn't do all that much good.

There are online and app-based QR code generators, though... so you could easily generate an image that you could save on your phone or print out for your guests to scan. Here is one such site (from a quick Google search)

2 Likes

Well, I think that e.g. travelmate and wireguard LuCI apps already display the QR code, so you could mimic the code and write a similar screen.

https://github.com/openwrt/luci/blob/master/applications/luci-app-travelmate/luasrc/view/travelmate/runtime.htm#L200

https://github.com/openwrt/luci/blob/784e76445fa41b354573329260a35ff24c4bec38/applications/luci-app-wireguard/luasrc/view/wireguard.htm#L197

This is from travelmate:

2 Likes

Well, generating the QR code is easy. I was looking for a way to display it without having to login into the router. The use case would be kids letting their friends use guest wifi when they visit.

Since there would be no connection to the router if they can’t get on WiFi (no password), the original idea/solution would not be particularly useful. Maybe print it out and on the fridge?

1 Like

Yes, I considered that. But it is boring.

The kid will always have a connection to a network that can access the router to load a page. Then the friends just scan the QR code.

Ah. That was the part I was missing :smiley:.

Attach an e-paper to an ESP8266 and connect to your wifi. :slight_smile:

1 Like

That is neat idea! But jokes aside, some off-the-shelves routers do provide a very easy way of doing so. I was hoping there is a good enough substitute I could use with OpenWrt.

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
3 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:

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}"
6 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}"
3 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 @wulfy23 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}"

5 Likes