From 12270029c320be15e87e0ed17292e1b78439e4e9 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Sun, 3 Oct 2021 15:46:03 +0300 Subject: add QR codes to wg-quick instructions --- assets/js/main.js | 38 +++++++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) (limited to 'assets') diff --git a/assets/js/main.js b/assets/js/main.js index 90295f0..5b26576 100644 --- a/assets/js/main.js +++ b/assets/js/main.js @@ -198,13 +198,21 @@ Data.prototype.hide_error = function() { $('#params_error').hide(); } -var ConfigFile = function(name, contents) { +function format_pre_text(text) { + return $('
').text(text);
+}
+
+var ConfigFile = function(name, text) {
     this.name = name;
-    this.contents = contents;
+    this.text = text;
 }
 
 ConfigFile.prototype.toString = function() {
-    return this.contents;
+    return this.text;
+}
+
+ConfigFile.prototype.format = function() {
+    return format_pre_text(this.toString());
 }
 
 var Script = function(text) {
@@ -215,6 +223,24 @@ Script.prototype.toString = function() {
     return this.text;
 }
 
+Script.prototype.format = function() {
+    return format_pre_text(this.toString());
+}
+
+var QRCode = function(text) {
+    this.text = text;
+}
+
+QRCode.prototype.format = function() {
+    var canvas = $('');
+    var qr = new QRious({
+        element: canvas[0],
+        value: this.text,
+        size: 350
+    });
+    return $('
').append(canvas); +} + function wg_quick_client_file(data) { var path = `/etc/wireguard/${iface}.conf`; return new ConfigFile(path, @@ -401,7 +427,9 @@ var InstructWgQuick = function() {} InstructWgQuick.prototype.name = function() { return 'wg-quick'; } InstructWgQuick.prototype.for_client = function(data) { - return [wg_quick_client_file(data)]; + var config = wg_quick_client_file(data); + var qr = new QRCode(config.text); + return [config, qr]; } InstructWgQuick.prototype.for_server = function(data) { @@ -450,7 +478,7 @@ function clear_instructors() { function format_instructions(instructions) { var container = $('
'); instructions.forEach(function(instruction) { - container.append($('
').text(instruction.toString()));
+        container.append(instruction.format());
     });
     return container;
 }
-- 
cgit v1.2.3