From 128c3230b961d559d997a818bd208cdc3bfea5dc Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Thu, 22 Aug 2019 16:05:46 +0200 Subject: [PATCH] Added sample code for QR code generation in remote provisioning --- src/xmlrpc/provisioning.php | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/xmlrpc/provisioning.php b/src/xmlrpc/provisioning.php index 19e5079..8c1c529 100644 --- a/src/xmlrpc/provisioning.php +++ b/src/xmlrpc/provisioning.php @@ -19,10 +19,34 @@ */ header("Access-Control-Allow-Origin: *"); -header("Content-Type: application/xml; charset=UTF-8"); include_once __DIR__ . '/../misc/utilities.php'; +if (isset($_GET['qrcode']) && $_GET['qrcode'] == 1) { + $query = $_GET; + $query['qrcode'] = 0; + $query_result = http_build_query($query); + $data = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https://" : "http://") . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] . "?" . $query_result; + + // https://github.com/tecnickcom/tc-lib-barcode GPLv3 + require __DIR__ . '/../vendor/tecnickcom/tc-lib-barcode/resources/autoload.php'; + $barcode = new \Com\Tecnick\Barcode\Barcode(); + $bobj = $barcode->getBarcodeObj( + 'QRCODE,H', // barcode type and additional comma-separated parameters + $data, // data string to encode + -4, // bar width (use absolute or negative value as multiplication factor) + -4, // bar height (use absolute or negative value as multiplication factor) + 'black', // foreground color + array(-2, -2, -2, -2) // padding (use absolute or negative values as multiplication factors) + )->setBackgroundColor('white'); // background color + + header("Content-Type: text/html; charset=UTF-8"); + echo $bobj->getHtmlDiv(); + return; +} + +header("Content-Type: application/xml; charset=UTF-8"); + $xml = ''; $xml = $xml . '';