Moved qr code generation to server side in order to get more compatible codes
This commit is contained in:
parent
409123b038
commit
c1538a8912
@ -1,23 +0,0 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2020 datalog
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
Code downloaded from https://github.com/datalog/qrcode-svg on 2025-02-18.
|
12
api/qr.py
Normal file
12
api/qr.py
Normal file
@ -0,0 +1,12 @@
|
||||
import qrcode
|
||||
import qrcode.image.svg
|
||||
|
||||
def generate_qr(data: str):
|
||||
qr = qrcode.QRCode(image_factory=qrcode.image.svg.SvgPathImage,
|
||||
error_correction=qrcode.constants.ERROR_CORRECT_L,
|
||||
border=0)
|
||||
qr.add_data(data)
|
||||
qr.make(fit=True)
|
||||
|
||||
svg = qr.make_image(attrib={'width': '', 'height': ''})
|
||||
return svg.to_string(encoding='unicode')
|
@ -10,6 +10,7 @@ import subprocess
|
||||
from dateutil.relativedelta import relativedelta
|
||||
|
||||
from .exceptions import ClientLimitError, ValiditySpecificationError
|
||||
from .qr import generate_qr
|
||||
|
||||
|
||||
confsuffix = '.conf'
|
||||
@ -335,6 +336,7 @@ class WireGuard:
|
||||
'description': metadata['description'],
|
||||
'created': creation_date,
|
||||
'expires': expiry_date,
|
||||
'qrcode': generate_qr(configdata),
|
||||
'data': configdata}
|
||||
|
||||
def delete_config(self, *args) -> None:
|
||||
|
@ -3,9 +3,8 @@
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<link rel="stylesheet" type="text/css" href="static/style.css?2">
|
||||
<script type="text/javascript" src="static/script.js?2"></script>
|
||||
<script type="text/javascript" src="static/qrcode.min.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="static/style.css?3">
|
||||
<script type="text/javascript" src="static/script.js?3"></script>
|
||||
<title>WG-selfserve</title>
|
||||
</head>
|
||||
<body>
|
||||
@ -52,7 +51,7 @@
|
||||
<name role="heading" aria-label="client name"></name>
|
||||
<description aria-label="client description"></description>
|
||||
<data></data>
|
||||
<qrcode></qrcode>
|
||||
<qrcode class="qr"></qrcode>
|
||||
<footer>
|
||||
<button class="download">Download</button>
|
||||
<button class="edit">Edit</button>
|
||||
|
2
public/static/qrcode.min.js
vendored
2
public/static/qrcode.min.js
vendored
File diff suppressed because one or more lines are too long
@ -74,16 +74,15 @@
|
||||
.then((data) => {
|
||||
config.id = 'config-' + config_id;
|
||||
config.querySelector('name').textContent = data.name;
|
||||
config.querySelector('description').textContent = data.description;
|
||||
config.querySelector('description').textContent =
|
||||
data.description;
|
||||
config.querySelector('data').textContent = data.data;
|
||||
|
||||
const qr = QRCode({msg: data.data,
|
||||
pad: 0,
|
||||
ecl: 'L'});
|
||||
qr.classList.add('qr');
|
||||
qr.setAttribute('aria-label', 'QR code');
|
||||
qr.setAttribute('shape-rendering', 'crisp-edges');
|
||||
config.querySelector('qrcode').replaceWith(qr);
|
||||
const qr = config.querySelector('.qr');
|
||||
qr.innerHTML = data.qrcode;
|
||||
const svg = qr.querySelector('svg');
|
||||
svg.setAttribute('shape-rendering', 'crisp-edges');
|
||||
svg.setAttribute('aria-label', 'QR code');
|
||||
|
||||
const expires = config.querySelector('expires');
|
||||
if(data.expires) {
|
||||
|
@ -135,6 +135,11 @@ config > footer {
|
||||
place-self: end;
|
||||
}
|
||||
|
||||
qrcode > svg {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
name {
|
||||
font-size: 1.5rem;
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
flask
|
||||
requests
|
||||
python-dateutil
|
||||
qrcode[pil]
|
||||
|
Loading…
x
Reference in New Issue
Block a user