$localeFile)
$availableLocales[$key] = basename($localeFile, ".php");
foreach ($clientLocales as $clientLocale) {
if (in_array($clientLocale, $availableLocales)) {
$locale = $clientLocale;
break;
}
}
}
require "locales/" . $locale . ".php";
$chosen_loc = $loc;
if ($locale != DEFAULT_LOCALE) {
require "locales/" . DEFAULT_LOCALE . ".php";
$default_loc = $loc;
} else
$default_loc = $chosen_loc;
require "locales/template.php";
$template_loc = $loc;
// Function to get a specific string from the locale file, fall back on default then template if missing
function getIntlString(
$string_label,
$raw = false
) {
global $chosen_loc, $default_loc, $template_loc, $locale;
if (array_key_exists($string_label, $chosen_loc))
return $chosen_loc[$string_label];
if ($locale != DEFAULT_LOCALE AND array_key_exists($string_label, $default_loc)) {
if ($raw)
return $default_loc[$string_label];
return "" . $default_loc[$string_label] . "";
}
if ($raw)
return $template_loc[$string_label];
return "" . $template_loc[$string_label] . "";
}
require "themes/" . THEME . "/theme.php";
$colorScheme['theme'] = THEME;
$css_filename = Less_Cache::Get(
less_files: ['style.less' => ''],
parser_options: ['cache_dir' => 'css/', 'compress' => true],
modify_vars: $colorScheme,
);
preg_match('#.*/(?.*)$#', $_SERVER['REQUEST_URI'], $matches);
define('PAGE', match ($matches['page']) {
'wifi' => 'wifi',
'' => 'home',
default => 'unknown',
});
if (PAGE === 'unknown') {
$allowed_filenames['css/' . $css_filename] = 'text/css';
foreach ($themeDimensionsIcons as $icon_dimension)
$allowed_filenames['themes/' . THEME . '/icons/' . $icon_dimension . '.png'] = 'image/png';
foreach ($allowed_filenames as $filename => $type) {
if (str_ends_with($_SERVER['REQUEST_URI'], $filename)) {
header('Content-Type: ' . $type);
echo file_get_contents($filename);
exit();
}
}
http_response_code(404);
}
$_POST = [
"form" => $_POST['form'] ?? NULL,
"wifi" => [
"ssid" => $_POST['wifi']['ssid'] ?? "",
"password" => $_POST['wifi']['password'] ?? "",
],
"main" => [
"txt" => $_POST['main']['txt'] ?? "",
"redundancy" => $_POST['main']['redundancy'] ?? DEFAULT_REDUNDANCY,
"margin" => $_POST['main']['margin'] ?? DEFAULT_MARGIN,
"size" => $_POST['main']['size'] ?? DEFAULT_SIZE,
"bgColor" => $_POST['main']['bgColor'] ?? "#" . DEFAULT_BGCOLOR,
"fgColor" => $_POST['main']['fgColor'] ?? "#" . DEFAULT_FGCOLOR,
],
];
if ($_POST['wifi']['ssid'] !== "") {
if (!(strlen($_POST['wifi']['ssid']) >= 1 AND strlen($_POST['wifi']['ssid']) <= 4096)) {
http_response_code(400);
exit("Wrong value for ssid");
}
$escaped_ssid = preg_replace("/([\\\;\,\"\:])/", "\\\\$1", $_POST['wifi']['ssid']);
if ($_POST['wifi']['password'] === "")
$_POST['main']['txt'] = "WIFI:T:nopass;S:{$escaped_ssid};;";
else {
if (strlen($_POST['wifi']['password']) > 4096) {
http_response_code(400);
exit("Wrong value for password");
}
$escaped_password = preg_replace("/([\\\;\,\"\:])/", "\\\\$1", $_POST['wifi']['password']);
$_POST['main']['txt'] = "WIFI:T:WPA;S:{$escaped_ssid};P:{$escaped_password};;";
}
}
$qrCodeAvailable = NULL;
if ($_POST['main']['txt'] !== "") {
$qrCodeAvailable = true;
if (!(strlen($_POST['main']['txt']) >= 1 AND strlen($_POST['main']['txt']) <= 4096)) {
http_response_code(400);
exit("Wrong value for txt");
}
if (!in_array($_POST['main']['redundancy'], ["low", "medium", "quartile", "high"], strict: true)) {
http_response_code(400);
exit("Wrong value for redundancy");
}
if (!(is_numeric($_POST['main']['margin']) AND $_POST['main']['margin'] >= 0 AND $_POST['main']['margin'] <= 1024)) {
http_response_code(400);
exit("Wrong value for margin");
}
if (!(is_numeric($_POST['main']['size']) AND $_POST['main']['size'] >= 21 AND $_POST['main']['size'] <= 4096)) {
http_response_code(400);
exit("Wrong value for size");
}
if (preg_match("/^#[abcdefABCDEF0-9]{6}$/", $_POST['main']['bgColor']) === false) {
http_response_code(400);
exit("Wrong value for bgColor");
}
if (preg_match("/^#[abcdefABCDEF0-9]{6}$/", $_POST['main']['fgColor']) === false) {
http_response_code(400);
exit("Wrong value for fgColor");
}
$rgbBgColor = [
'r' => hexdec(substr($_POST['main']['bgColor'],1,2)),
'g' => hexdec(substr($_POST['main']['bgColor'],3,2)),
'b' => hexdec(substr($_POST['main']['bgColor'],5,2)),
];
$qrCode = Builder::create()
->data($_POST['main']['txt'])
->margin($_POST['main']['margin'])
->size($_POST['main']['size'])
->errorCorrectionLevel(match ($_POST['main']['redundancy']) {
"low" => new ErrorCorrectionLevelLow(),
"medium" => new ErrorCorrectionLevelMedium(),
"quartile" => new ErrorCorrectionLevelQuartile(),
"high" => new ErrorCorrectionLevelHigh(),
})
->backgroundColor(new Color(
$rgbBgColor['r'],
$rgbBgColor['g'],
$rgbBgColor['b'],
))
->foregroundColor(new Color(
hexdec(substr($_POST['main']['fgColor'],1,2)),
hexdec(substr($_POST['main']['fgColor'],3,2)),
hexdec(substr($_POST['main']['fgColor'],5,2)),
));
try {
$result = $qrCode->build();
} catch (Exception $ex) {
http_response_code(500);
$qrCodeAvailable = false;
error_log("LibreQR encountered an error while generating a QR code: " . $ex);
}
}
?>
=
match (PAGE) {
'home' => 'LibreQR · ' . getIntlString('subtitle'),
'wifi' => getIntlString('tab_wifi_title') . ' · LibreQR',
'unknown' => getIntlString('error_404') . ' · LibreQR',
}
?>
' . "\n";
?>
= getIntlString('error_404') ?>
getDataUri();
$qrSize = $_POST['main']['size'] + 2 * $_POST['main']['margin'];
?>
" . getIntlString('error_generation') . "
";
}
?>