2020-02-26 18:51:04 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
require_once '../../includes/config.php';
|
|
|
|
require_once '../../includes/defaults.php';
|
2020-02-28 00:52:35 +01:00
|
|
|
require_once '../../includes/functions.php';
|
2020-02-26 18:51:04 +01:00
|
|
|
|
2020-07-11 10:03:23 +02:00
|
|
|
// prevent direct file access
|
|
|
|
if (!isset($_SERVER['HTTP_REFERER'])) {
|
|
|
|
header('HTTP/1.0 403 Forbidden');
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
2021-11-25 10:02:59 +01:00
|
|
|
function qr_encode($str)
|
|
|
|
{
|
|
|
|
return preg_replace('/(?<!\\\)([\":;,])/', '\\\\\1', $str);
|
|
|
|
}
|
|
|
|
|
2020-02-26 18:51:04 +01:00
|
|
|
$hostapd = parse_ini_file(RASPI_HOSTAPD_CONFIG, false, INI_SCANNER_RAW);
|
|
|
|
|
|
|
|
// assume wpa encryption and get the passphrase
|
|
|
|
$type = "WPA";
|
|
|
|
$password = isset($hostapd['wpa_psk']) ? $hostapd['wpa_psk'] : $hostapd['wpa_passphrase'];
|
|
|
|
|
2021-11-25 10:02:59 +01:00
|
|
|
// use wep if configured
|
|
|
|
$wep_default_key = intval($hostapd['wep_default_key']);
|
|
|
|
$wep_key = 'wep_key' . $wep_default_key;
|
|
|
|
if (array_key_exists($wep_key, $hostapd)) {
|
|
|
|
$type = "WEP";
|
|
|
|
$password = $hostapd[$wep_key];
|
|
|
|
}
|
|
|
|
|
2020-02-26 18:51:04 +01:00
|
|
|
// if password is still empty, assume nopass
|
|
|
|
if (empty($password)) {
|
|
|
|
$type = "nopass";
|
|
|
|
}
|
|
|
|
|
|
|
|
$ssid = $hostapd['ssid'];
|
|
|
|
$hidden = intval($hostapd['ignore_broadcast_ssid']) != 0 ? "H:true" : "";
|
|
|
|
|
|
|
|
$ssid = qr_encode($ssid);
|
|
|
|
$password = qr_encode($password);
|
|
|
|
|
|
|
|
$data = "WIFI:S:$ssid;T:$type;P:$password;$hidden;";
|
2021-05-08 19:29:59 +02:00
|
|
|
$command = "qrencode -t svg -m 1 -o - " . mb_escapeshellarg($data);
|
2020-02-26 18:51:04 +01:00
|
|
|
$svg = shell_exec($command);
|
|
|
|
|
|
|
|
$config_mtime = filemtime(RASPI_HOSTAPD_CONFIG);
|
|
|
|
$last_modified = gmdate('D, d M Y H:i:s ', $config_mtime) . 'GMT';
|
2020-02-28 00:53:48 +01:00
|
|
|
$etag = hash('sha256', $data);
|
2020-02-26 18:51:04 +01:00
|
|
|
$content_length = strlen($svg);
|
|
|
|
|
|
|
|
header("Content-Type: image/svg+xml");
|
|
|
|
header("Content-Length: $content_length");
|
|
|
|
header("Last-Modified: $last_modified");
|
2021-03-16 22:31:00 +01:00
|
|
|
header("Content-Disposition: attachment; filename=\"qr.svg\"");
|
2020-02-28 00:53:48 +01:00
|
|
|
header("ETag: \"$etag\"");
|
2020-02-26 18:51:04 +01:00
|
|
|
header("X-QR-Code-Content: $data");
|
2021-03-16 22:31:00 +01:00
|
|
|
echo $svg;
|
2020-02-26 18:51:04 +01:00
|
|
|
|