diff --git a/README.md b/README.md index ffeed09..97713a0 100755 --- a/README.md +++ b/README.md @@ -90,7 +90,7 @@ This source code includes: ## License -[AGPLv3+](https://code.antopie.org/miraty/libreqr/src/branch/master/LICENSE) +[AGPLv3+](https://code.antopie.org/miraty/libreqr/src/branch/main/LICENSE) LibreQR is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. diff --git a/README_fr.md b/README_fr.md index 6e0f028..775e0b6 100644 --- a/README_fr.md +++ b/README_fr.md @@ -90,7 +90,7 @@ Ce code source inclus : ## Licence -[AGPLv3+](https://code.antopie.org/miraty/libreqr/src/branch/master/LICENSE) +[AGPLv3+](https://code.antopie.org/miraty/libreqr/src/branch/main/LICENSE) LibreQR est un logiciel libre ; vous pouvez le diffuser et le modifier suivant les termes de la GNU Affero General Public License telle que publiée par la Free Software Foundation ; soit la version 3 de cette licence, soit (à votre convenance) une version ultérieure. diff --git a/inc.php b/inc.php index 0966155..e857d40 100644 --- a/inc.php +++ b/inc.php @@ -2,10 +2,16 @@ require "config.inc.php"; -$libreqrVersion = "1.3.0"; +define("DEFAULT_REDONDANCY", "H"); +define("DEFAULT_MARGIN", 2); +define("DEFAULT_SIZE", 4); +define("DEFAULT_BGCOLOR", "FFFFFF"); +define("DEFAULT_MAINCOLOR", "000000"); + +$libreqrVersion = "1.4.0dev"; // Defines the locale to be used -if ($forceLocale == false) { +if ($forceLocale == false AND isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { $clientLocales = $_SERVER['HTTP_ACCEPT_LANGUAGE']; $clientLocales = preg_replace("#[A-Z0-9]|q=|;|-|\.#", "", $clientLocales); $clientLocales = explode(',', $clientLocales); diff --git a/index.php b/index.php index ee4a995..c2b078a 100755 --- a/index.php +++ b/index.php @@ -20,66 +20,54 @@ This file is part of LibreQR. --> "", + "redondancy" => DEFAULT_REDONDANCY, + "margin" => DEFAULT_MARGIN, + "size" => DEFAULT_SIZE, + "bgColor" => "#" . DEFAULT_BGCOLOR, + "mainColor" => "#" . DEFAULT_MAINCOLOR, +); - // Check if parameters are set - if (!isset($_GET['txt'])) - return true; - else if (!isset($_GET['size'])) - return true; - else if (!isset($_GET['redondancy'])) - return true; - else if (!isset($_GET['margin'])) - return true; - else if (!isset($_GET['bgColor'])) - return true; - else if (!isset($_GET['mainColor'])) - return true; - - // Check parameters's types - else if (!is_numeric($_GET['size'])) - return true; - else if (!is_string($_GET['redondancy'])) - return true; - else if (!is_numeric($_GET['margin'])) - return true; - else if (!is_string($_GET['bgColor'])) - return true; - else if (!is_string($_GET['mainColor'])) - return true; - - // Check if redondancy value is correct - else if ($_GET['redondancy'] != "L" AND $_GET['redondancy'] != "M" AND $_GET['redondancy'] != "Q" AND $_GET['redondancy'] != "H") - return true; +if ( + isset($_POST['txt']) + AND isset($_POST['redondancy']) + AND isset($_POST['margin']) + AND isset($_POST['size']) + AND isset($_POST['bgColor']) + AND isset($_POST['mainColor']) +) { + if (strlen($_POST['txt']) >= 1 AND strlen($_POST['txt']) <= 4096) + $params['txt'] = $_POST['txt']; else - return false; -} + exit("Wrong value for txt"); -if (badQuery()) { + if ($_POST['redondancy'] === "L" OR $_POST['redondancy'] === "M" OR $_POST['redondancy'] === "Q" OR $_POST['redondancy'] === "H") + $params['redondancy'] = $_POST['redondancy']; + else + exit("Wrong value for redondancy"); - parse_str(parse_url($_SERVER['REQUEST_URI'], PHP_URL_QUERY), $params); + if (is_numeric($_POST['margin']) AND $_POST['margin'] >= 0 AND $_POST['margin'] <= 128) + $params['margin'] = $_POST['margin']; + else + exit("Wrong value for margin"); - if (!isset($params['txt'])) - $params['txt'] = ""; + if (is_numeric($_POST['size']) AND $_POST['size'] >= 1 AND $_POST['size'] <= 128) + $params['size'] = $_POST['size']; + else + exit("Wrong value for size"); - if (!isset($params['redondancy']) OR !is_string($params['redondancy']) OR ($params['redondancy'] != "L" AND $params['redondancy'] != "M" AND $params['redondancy'] != "Q" AND $params['redondancy'] != "H")) - $params['redondancy'] = "H"; + if (preg_match("/^#[abcdefABCDEF0-9]{6}$/", $_POST['bgColor'])) + $params['bgColor'] = $_POST['bgColor']; + else + exit("Wrong value for bgColor"); - if (!isset($params['margin']) OR !is_numeric($params['margin'])) - $params['margin'] = 2; + if (preg_match("/^#[abcdefABCDEF0-9]{6}$/", $_POST['mainColor'])) + $params['mainColor'] = $_POST['mainColor']; + else + exit("Wrong value for mainColor"); - if (!isset($params['size']) OR !is_numeric($params['size'])) - $params['size'] = 4; - - if (!isset($params['bgColor']) OR !is_string($params['bgColor'])) - $params['bgColor'] = "#FFFFFF"; - - if (!isset($params['mainColor']) OR !is_string($params['mainColor'])) - $params['mainColor'] = "#000000"; - - header('Location: ' . $rootPath . "?" . http_build_query($params)); - exit; } ?> @@ -91,8 +79,8 @@ if (badQuery()) { - - &margin== $params['margin'] ?>&size== $params['size'] ?>&bgColor== urlencode($params['bgColor']) ?>&mainColor== urlencode($params['mainColor']) ?>"> + - - ' . "\n"; } ?> -
@@ -130,11 +116,11 @@ if (badQuery()) { - - - if (!empty($_GET['txt']) AND !empty($_GET['size']) AND !empty($_GET['redondancy']) AND !empty($_GET['margin']) AND !empty($_GET['bgColor']) AND !empty($_GET['mainColor'])) { - if (isset($_GET['txt']) AND isset($_GET['size']) AND isset($_GET['redondancy']) AND isset($_GET['margin']) AND isset($_GET['bgColor']) AND isset($_GET['mainColor'])) { - - require "phpqrcode.php"; - - $cheminImage = "temp/" . generateRandomString($fileNameLenght) . ".png"; - QRcode::png($_GET['txt'], $cheminImage, $_GET['redondancy'], $_GET['size'], $_GET['margin'], false, hexdec(substr($_GET['bgColor'], -6)), hexdec(substr($_GET['mainColor'], -6))); - ?> - - - + + if (!empty($params['txt'])) { + require "phpqrcode.php"; + + $imagePath = "temp/" . generateRandomString($fileNameLenght) . ".png"; + QRcode::png( + $params['txt'], + $imagePath, + $params['redondancy'], + $params['size'], + $params['margin'], + false, + hexdec(substr($params['bgColor'], -6)), + hexdec(substr($params['mainColor'], -6)) + ); + ?> + + + + + + +