Need advices - Creating an application for WIFI QR Code

Hello everybody,

I would like to write a simple application that will prompt a QR code image for the configured WiFi networks.

I need your advices to choose the language that I'll use.
If I'm correct, there is lua, ucode and js languages available to create an application for OpenWrt ?

I think about creating the application in .js format but I'm a bit concerned about the security aspect.
The js and the picture file should always stay on the router side and when disconnecting from Luci, there should be no way to get those js or QR code picture file from the computer(cache or anywhere else) without connecting back to Luci.
Could js be ok for those security aspects or should I select another language ?

Thank you by advance.

1 Like

lua is on its way out, don't introduce new lua dependencies if you can help it (and in this case it's just a little uci parsing in POSIX shell and feeding that to qrencode). iirc the travelmate package has similar features, so there should be working example code.

2 Likes

You can run PHP on openwrt device. And either use the built-in uhttpd as server, or any other well known one.

Doesn't the Wireguard or OpenVPN package offer a similar functionality? Perhaps it might be a good starting point...

Just a thought, when your users see the qrcode they can take a picture, so this is only security against people you did not already share the credentials with, unless you rapidly change the password.

1 Like

I've made a script doing this for my personal usage a view years ago. Basically you can use this script just appending the qrcode to any (luci) html file. Not quite elegant. :smiley: You just have to write sth. calling the script after changing wifi settings. Sysauth.htm is not there anymore. I've just tested it with luci_file="/tmp/wifi.html" setup. It is still working.

#!/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" "<h0 style='padding-left:3px;padding-right:3px;line-height:8px;}'><br />${ssid}</0>" >> "${luci_file}"
	printf "%s\n" "</div>" >> "${luci_file}"
	qrencode --size=3 --dpi=120 --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}"

For one time use there are better things nowdays available:

P. S. I have no clue anymore if I adopted anything from anywhere. But I guess I've looked into lua/luci code to get a clue. What I know is it took me a while to adjust the qrcode output. :smiley: So I do not claim anything here to be "my" code.