Browse Source

Use POST instead of GET

pull/13/head
Miraty 5 months ago
parent
commit
b4ae9acb4f
  1. 2
      README.md
  2. 2
      README_fr.md
  3. 6
      inc.php
  4. 170
      index.php
  5. 1
      locales/en.php
  6. 1
      locales/fr.php
  7. 2
      locales/oc.php
  8. 1
      locales/template.php
  9. 3
      manifest.php
  10. 14
      opensearch.php

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

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

6
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

170
index.php

@ -20,66 +20,54 @@ This file is part of LibreQR.
-->
<?php
function badQuery() { // Check if browser must be redirected
// 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;
$params = array(
"txt" => "",
"redondancy" => DEFAULT_REDONDANCY,
"margin" => DEFAULT_MARGIN,
"size" => DEFAULT_SIZE,
"bgColor" => "#" . DEFAULT_BGCOLOR,
"mainColor" => "#" . DEFAULT_MAINCOLOR,
);
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;
}
if (badQuery()) {
parse_str(parse_url($_SERVER['REQUEST_URI'], PHP_URL_QUERY), $params);
exit("Wrong value for txt");
if (!isset($params['txt']))
$params['txt'] = "";
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 ($_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");
if (!isset($params['margin']) OR !is_numeric($params['margin']))
$params['margin'] = 2;
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['size']) OR !is_numeric($params['size']))
$params['size'] = 4;
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['bgColor']) OR !is_string($params['bgColor']))
$params['bgColor'] = "#FFFFFF";
if (preg_match("/^#[abcdefABCDEF0-9]{6}$/", $_POST['bgColor']))
$params['bgColor'] = $_POST['bgColor'];
else
exit("Wrong value for bgColor");
if (!isset($params['mainColor']) OR !is_string($params['mainColor']))
$params['mainColor'] = "#000000";
if (preg_match("/^#[abcdefABCDEF0-9]{6}$/", $_POST['mainColor']))
$params['mainColor'] = $_POST['mainColor'];
else
exit("Wrong value for mainColor");
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,7 +116,7 @@ if (badQuery()) {
</a>
</header>
<form method="get" action="./">
<form method="post" action="./">
<div id="firstWrapper">
@ -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>
@ -224,25 +204,31 @@ if (badQuery()) {
<?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'])) {
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)));
?>
<div class="centered">
<a href="<?php echo $cheminImage; ?>" class="button" download="<?php echo htmlspecialchars($_GET['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>
</div>
<?php
}
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))
);
?>
<div class="centered">
<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="<?= $imagePath; ?>"><img alt='<?= $loc['alt_QR_before'] ?><?= htmlspecialchars($params['txt']); ?><?= $loc['alt_QR_after'] ?>' id="qrCode" src="<?= $imagePath; ?>"/></a>
</div>
<?php
}
?>
?>
<footer>

1
locales/en.php

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

1
locales/fr.php

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

2
locales/oc.php

@ -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 d’adreça",
'opensearch_actionName' => "Generatz de còdis QR a partir de la barra de recèrca o d’adreça",
);

1
locales/template.php

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

3
manifest.php

@ -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++) { ?>

14
opensearch.php

@ -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 ?>"/>

Loading…
Cancel
Save