From b4ae9acb4fb3f7a321dbe8f503be29397f659537 Mon Sep 17 00:00:00 2001 From: Miraty Date: Sun, 11 Jul 2021 14:00:35 +0200 Subject: [PATCH 1/6] Use POST instead of GET --- README.md | 2 +- README_fr.md | 2 +- inc.php | 6 ++ index.php | 162 ++++++++++++++++++++----------------------- locales/en.php | 1 - locales/fr.php | 1 - locales/oc.php | 2 - locales/template.php | 1 - manifest.php | 3 +- opensearch.php | 14 ++-- 10 files changed, 90 insertions(+), 104 deletions(-) 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..e9522b0 100644 --- a/inc.php +++ b/inc.php @@ -2,6 +2,12 @@ require "config.inc.php"; +define("DEFAULT_REDONDANCY", "H"); +define("DEFAULT_MARGIN", 2); +define("DEFAULT_SIZE", 4); +define("DEFAULT_BGCOLOR", "FFFFFF"); +define("DEFAULT_MAINCOLOR", "000000"); + $libreqrVersion = "1.3.0"; // Defines the locale to be used diff --git a/index.php b/index.php index ee4a995..8e34d9e 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=&size=&bgColor=&mainColor="> + - - ' . "\n"; } ?> - @@ -130,7 +116,7 @@ if (badQuery()) { -
+
@@ -143,13 +129,7 @@ if (badQuery()) {

- +
@@ -164,10 +144,10 @@ if (badQuery()) {
@@ -180,7 +160,7 @@ if (badQuery()) {

- +
@@ -192,7 +172,7 @@ if (badQuery()) {

- +
@@ -204,14 +184,14 @@ if (badQuery()) {
- "> +
- "> +
@@ -224,25 +204,31 @@ if (badQuery()) { +
+ +
- $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))); - ?> -
- -
- - - + <?= $loc[' id="qrCode" src=""/> + + + ?>