Merge pull request 'Use POST instead of GET' (#13) from post into main

Reviewed-on: #13
This commit is contained in:
Miraty 2021-10-19 16:41:33 +02:00
commit d1774ac141
11 changed files with 149 additions and 167 deletions

View File

@ -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.

View File

@ -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.

10
inc.php
View File

@ -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);

159
index.php
View File

@ -20,66 +20,54 @@ This file is part of LibreQR.
-->
<?php
function badQuery() { // Check if browser must be redirected
$params = array(
"txt" => "",
"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()) {
<meta name="description" content="<?= $loc['description'] ?>">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="manifest" href="manifest.php">
<link rel="search" type="application/opensearchdescription+xml" title="<?= $loc['opensearch_actionName'] ?>" href="opensearch.php&#63;redondancy=<?= $_GET['redondancy'] ?>&amp;margin=<?= $_GET['margin'] ?>&amp;size=<?= $_GET['size'] ?>&amp;bgColor=<?= urlencode($_GET['bgColor']) ?>&amp;mainColor=<?= urlencode($_GET['mainColor']) ?>">
<?php
<link rel="search" type="application/opensearchdescription+xml" title="LibreQR" href="opensearch.php&#63;redondancy=<?= $params['redondancy'] ?>&amp;margin=<?= $params['margin'] ?>&amp;size=<?= $params['size'] ?>&amp;bgColor=<?= urlencode($params['bgColor']) ?>&amp;mainColor=<?= urlencode($params['mainColor']) ?>">
<?php
// If style.min.css exists
if (file_exists("temp/style.min.css"))
// And if it's older than theme.php or config.inc.php (so not up to date)
@ -108,12 +96,10 @@ if (badQuery()) {
?>
<link type="text/css" rel="stylesheet" href="temp/<?= $cssFileName ?>">
<?php
<?php
foreach($themeDimensionsIcons as $dimFav) { // Set all icons dimensions
echo ' <link rel="icon" type="image/png" href="themes/' . $theme . '/icons/' . $dimFav . '.png" sizes="' . $dimFav . 'x' . $dimFav . '">' . "\n";
} ?>
</head>
<body>
@ -130,11 +116,11 @@ if (badQuery()) {
</a>
</header>
<form method="get" action="./">
<form method="post" action="./">
<div id="firstWrapper">
<div class="param">
<div class="param" id="txtParam">
<label for="txt">
<details>
<summary><?= $loc['label_content'] ?></summary>
@ -143,13 +129,7 @@ if (badQuery()) {
</p>
</details>
</label>
<textarea rows="8" required="" id="txt" placeholder="<?= $loc['placeholder'] ?>" name="txt"><?php
if (isset($_GET['txt'])) {
echo htmlspecialchars($_GET['txt']);
}
?></textarea>
<textarea rows="8" required="" id="txt" placeholder="<?= $loc['placeholder'] ?>" name="txt" minlenght="5" maxlenght="50"><?= htmlspecialchars($params['txt']) ?></textarea>
</div>
<div id="sideParams">
@ -164,10 +144,10 @@ if (badQuery()) {
</details>
</label>
<select id="redondancy" name="redondancy">
<option <?php if (isset($_GET['redondancy']) AND ($_GET['redondancy'] == "L")) {echo 'selected="" ';} ?>value="L">L - 7%</option>
<option <?php if (isset($_GET['redondancy']) AND ($_GET['redondancy'] == "M")) {echo 'selected="" ';} ?>value="M">M - 15%</option>
<option <?php if (isset($_GET['redondancy']) AND ($_GET['redondancy'] == "Q")) {echo 'selected="" ';} ?>value="Q">Q - 25%</option>
<option <?php if ((isset($_GET['redondancy']) AND ($_GET['redondancy'] == "H")) OR (!isset($_GET['redondancy']) OR empty($_GET['redondancy']))) {echo 'selected="" ';} ?>value="H">H - 30%</option>
<option <?php if ($params['redondancy'] === "L") echo 'selected="" '; ?>value="L">L - 7%</option>
<option <?php if ($params['redondancy'] === "M") echo 'selected="" '; ?>value="M">M - 15%</option>
<option <?php if ($params['redondancy'] === "Q") echo 'selected="" '; ?>value="Q">Q - 25%</option>
<option <?php if ($params['redondancy'] === "H") echo 'selected="" '; ?>value="H">H - 30%</option>
</select>
</div>
@ -180,7 +160,7 @@ if (badQuery()) {
</p>
</details>
</label>
<input type="number" id="margin" placeholder="2" name="margin" min="0" value="<?= $_GET['margin'] ?>">
<input type="number" id="margin" placeholder="2" name="margin" min="0" max="128" value="<?= htmlspecialchars($params['margin']) ?>">
</div>
<div class="param">
@ -192,7 +172,7 @@ if (badQuery()) {
</p>
</details>
</label>
<input type="number" id="size" placeholder="4" name="size" min="1" max="44" value="<?= $_GET['size'] ?>">
<input type="number" id="size" placeholder="4" name="size" min="1" max="128" value="<?= htmlspecialchars($params['size']) ?>">
</div>
</div>
@ -204,14 +184,14 @@ if (badQuery()) {
<div class="param">
<label for="bgColor"><?= $loc['label_bgColor'] ?></label>
<div class="inputColorContainer">
<input type="color" name="bgColor" id="bgColor" value="<?php if (!empty($_GET['bgColor'])) {echo htmlspecialchars($_GET['bgColor']);} else {echo "#FFFFFF";} ?>">
<input type="color" name="bgColor" id="bgColor" value="<?= htmlspecialchars($params['bgColor']) ?>">
</div>
</div>
<div class="param">
<label for="mainColor"><?= $loc['label_mainColor'] ?></label>
<div class="inputColorContainer">
<input type="color" name="mainColor" id="mainColor" value="<?php if (!empty($_GET['mainColor'])) {echo htmlspecialchars($_GET['mainColor']);} else {echo "#000000";} ?>">
<input type="color" name="mainColor" id="mainColor" value="<?= htmlspecialchars($params['mainColor']) ?>">
</div>
</div>
</div>
@ -222,27 +202,36 @@ if (badQuery()) {
</form>
<section id="output">
<?php
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'])) {
if (!empty($params['txt'])) {
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)));
$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))
);
?>
<div class="centered">
<a href="<?php echo $cheminImage; ?>" class="button" download="<?php echo htmlspecialchars($_GET['txt']); ?>.png"><?= $loc['button_download'] ?></a>
<div class="centered" id="downloadQR">
<a href="<?php echo $imagePath; ?>" class="button" download="<?= htmlspecialchars($params['txt']); ?>.png"><?= $loc['button_download'] ?></a>
</div>
<div class="centered" id="showOnlyQR">
<a title="<?= $loc['title_showOnlyQR'] ?>" href="<?php echo $cheminImage; ?>"><img alt='<?= $loc['alt_QR_before'] ?><?php echo htmlspecialchars($_GET['txt']); ?><?= $loc['alt_QR_after'] ?>' id="qrCode" src="<?php echo $cheminImage; ?>"/></a>
<a title="<?= $loc['title_showOnlyQR'] ?>" href="<?= $imagePath; ?>"><img alt='<?= $loc['alt_QR_before'] ?><?= htmlspecialchars($params['txt']); ?><?= $loc['alt_QR_after'] ?>' id="qrCode" src="<?= $imagePath; ?>"/></a>
</div>
<?php
}
}
?>
<?php } ?>
</section>
<footer>

View File

@ -46,5 +46,4 @@ $loc = array(
'metaText_legal' => "LibreQR " . $libreqrVersion . " is a free software whose <a href='https://code.antopie.org/miraty/libreqr/'>source code</a> is available under the terms of the <abbr title='GNU Affero General Public License version 3 or any later version'><a href='LICENSE.html'>AGPLv3</a>+</abbr>.",
'opensearch_description' => "Generate QR codes from your search or address bar",
'opensearch_actionName' => "Generate QR codes from your search or address bar",
);

View File

@ -46,5 +46,4 @@ $loc = array(
'metaText_legal' => "LibreQR " . $libreqrVersion . " est un logiciel libre dont le <a href='https://code.antopie.org/miraty/libreqr/'>code source</a> est disponible selon les termes de l'<abbr title='GNU Affero General Public License version 3 ou toute version ultérieure'><a href='LICENSE.html'>AGPLv3</a>+</abbr>.",
'opensearch_description' => "Générez des codes QR depuis votre barre de recherche ou d'adresse",
'opensearch_actionName' => "Générez des codes QR depuis votre barre de recherche ou d'adresse",
);

View File

@ -46,6 +46,4 @@ $loc = array(
'metaText_legal' => "LibreQR " . $libreqrVersion . " es un logicial liure que son <a href='https://code.antopie.org/miraty/libreqr/'>còdi font</a> es disponible jols tèrmes de la licéncia <abbr title='GNU Affero General Public License version 3 or any later version'><a href='LICENSE.html'>AGPLv3</a>+</abbr>.",
'opensearch_description' => "Generatz de còdis QR a partir de la barra de recèrca o dadreça",
'opensearch_actionName' => "Generatz de còdis QR a partir de la barra de recèrca o dadreça",
);

View File

@ -31,5 +31,4 @@ $loc = array(
'metaText_legal' => "metaText_legal",
'opensearch_description' => "opensearch_description",
'opensearch_actionName' => "opensearch_actionName",
);

View File

@ -7,8 +7,7 @@
"description": "<?= $loc['subtitle'] ?>",
"start_url": "<?= $rootPath; ?>",
"scope": "<?= $rootPath; ?>",
"display": "standalone",
"orientation": "portrait",
"orientation": "any",
"icons":
[
<?php for ($i = 0; $i < (count($themeDimensionsIcons) - 1); $i++) { ?>

View File

@ -2,7 +2,7 @@
<?xml version="1.0" encoding="UTF-8" ?>
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
<ShortName>LibreQR</ShortName>
<Description><?= $loc['opensearch_actionName'] ?></Description>
<Description><?= $loc['description'] ?></Description>
<?php
foreach($themeDimensionsIcons as $dimIcon) {
echo ' <Image height="' . $dimIcon . '" width="' . $dimIcon . '" type="image/png">' . $rootPath . 'themes/' . $theme . '/icons/' . $dimIcon . '.png</Image>' . "\n";
@ -10,13 +10,13 @@
<Language>*</Language>
<InputEncoding>UTF-8</InputEncoding>
<?php
$redondancy = htmlspecialchars((isset($_GET['redondancy'])) ? $_GET['redondancy'] : 'H');
$margin = htmlspecialchars((isset($_GET['margin'])) ? $_GET['margin'] : '2');
$size = htmlspecialchars((isset($_GET['size'])) ? $_GET['size'] : '4');
$bgColor = htmlspecialchars(urlencode((isset($_GET['bgColor'])) ? $_GET['bgColor'] : '%23FFFFFF'));
$mainColor = htmlspecialchars(urlencode((isset($_GET['mainColor'])) ? $_GET['mainColor'] : '%23000000'));
$redondancy = htmlspecialchars((isset($_GET['redondancy'])) ? $_GET['redondancy'] : DEFAULT_REDONDANCY);
$margin = htmlspecialchars((isset($_GET['margin'])) ? $_GET['margin'] : DEFAULT_MARGIN);
$size = htmlspecialchars((isset($_GET['size'])) ? $_GET['size'] : DEFAULT_SIZE);
$bgColor = htmlspecialchars(urlencode((isset($_GET['bgColor'])) ? $_GET['bgColor'] : "%23" . DEFAULT_BGCOLOR));
$mainColor = htmlspecialchars(urlencode((isset($_GET['mainColor'])) ? $_GET['mainColor'] : "%23" . DEFAULT_MAINCOLOR));
?>
<Url type="text/html" template="<?= $rootPath; ?>">
<Url type="text/html" method="post" template="<?= $rootPath ?>">
<Param name="txt" value="{searchTerms}"/>
<Param name="redondancy" value="<?= $redondancy ?>"/>
<Param name="margin" value="<?= $margin ?>"/>
@ -24,7 +24,7 @@
<Param name="bgColor" value="<?= $bgColor ?>"/>
<Param name="mainColor" value="<?= $mainColor ?>"/>
</Url>
<Url type="application/opensearchdescription+xml" rel="self" template="<?= $rootPath; ?>opensearch.php">
<Url type="application/opensearchdescription+xml" rel="self" template="<?= $rootPath ?>opensearch.php">
<Param name="redondancy" value="<?= $redondancy ?>"/>
<Param name="margin" value="<?= $margin ?>"/>
<Param name="size" value="<?= $size ?>"/>

View File

@ -27,6 +27,27 @@ You should have received a copy of the GNU Affero General Public License along w
}
}
html {
height: 100%;
}
body {
margin: 0px;
font-weight: normal;
font-size: 20px;
height: 100%;
@media @light {
color: @text-light;
background-color: @bg-light;
}
@media @dark {
color: @text-dark;
background-color: @bg-dark;
}
}
a {
text-decoration: underline;
@ -43,11 +64,8 @@ a {
}
}
p {
margin: 10px;
}
details .helpText {
.helpText {
margin: 5px 0px 0px 0px;
padding: 5px;
border-radius: 10px;
text-align: left;
@ -61,6 +79,11 @@ details .helpText {
}
}
#sideParams {
text-align: center;
margin-left: 12px;
}
#sideParams summary {
text-align: center;
margin-left: 20px;
@ -84,46 +107,22 @@ details .helpText {
text-decoration: none;
}
form {
flex-grow: 1;
margin-bottom: 30px;
}
main {
display: flex;
flex-direction: column;
margin-left: auto;
margin-right: auto;
width: 814px;
height: 99%;
}
body {
margin: 18px;
font-weight: normal;
font-size: 20px;
height: 99%;
@media @light {
color: @text-light;
background-color: @bg-light;
}
@media @dark {
color: @text-dark;
background-color: @bg-dark;
}
}
html {
height: 97%;
height: 100%;
}
header {
text-align: center;
padding: 0px;
padding-top: 12px;
margin: 0px;
height: 64px;
display: flex;
justify-content: center;
}
#logo {
@ -141,7 +140,7 @@ h1, h2, h3, h4, h5, h6 {
}
h1 {
font-size: 33px;
font-size: 29px;
}
h2 {
@ -156,7 +155,11 @@ h2 {
flex-direction: row;
}
#showOnlyQR {
section#output {
flex-grow: 1;
}
#showOnlyQR, #downloadQR {
margin-top: 30px;
}
@ -187,8 +190,8 @@ h2 {
}
}
label[for=txt] {
padding-left: 22px;
label[for=txt] summary {
margin-left: 22px;
}
#colors {
@ -231,7 +234,7 @@ label[for=txt] {
footer {
font-size: 14px;
padding-top: 20px;
margin-top: 10px;
text-align: left;
}
@ -304,8 +307,15 @@ header, footer {
}
}
#redondancy, #size, #margin {
#redondancy {
width: 250px;
}
#size, #margin {
width: 234px;
}
#redondancy, #size, #margin {
height: 40px;
@media @light {
background-color: @bgField-light;
@ -384,10 +394,6 @@ input[type=color] {
flex-direction: column;
}
body {
margin: 10px;
}
#txt {
width: 92%;
}
@ -400,11 +406,6 @@ input[type=color] {
flex-direction: column;
}
h1 {
font-size: 28px;
padding-top: 6px;
}
#txt {
width: 85%;
}
@ -414,11 +415,3 @@ input[type=color] {
}
}
@media (max-width: 415px) {
h1 {
padding: 0px;
}
}