From 3103affe1fe7dc363dc09831b9deb413c3326f60 Mon Sep 17 00:00:00 2001 From: genshen Date: Sun, 9 Jun 2024 21:28:04 +0800 Subject: [PATCH] feat(vpn-qr-code): generate qr code via its content directly, instead of requsting qr image The content of the qr code is a url of `https://sis.ustb.edu.cn/connect/state?sid=${SID}`, we can generate the qr code via the parsed ${SID}. Then the http request of the qr image can be omitted. --- client-ui/qr_login_ui.go | 14 ++++------- go.mod | 1 + go.sum | 2 ++ plugins/vpn/qr_code.go | 52 +++++++++++++++++++++++++++++++++++----- 4 files changed, 53 insertions(+), 16 deletions(-) diff --git a/client-ui/qr_login_ui.go b/client-ui/qr_login_ui.go index d4d7d83..fb22eaf 100644 --- a/client-ui/qr_login_ui.go +++ b/client-ui/qr_login_ui.go @@ -2,24 +2,18 @@ package main import ( "fyne.io/fyne/v2/canvas" - "fyne.io/fyne/v2/storage" "github.com/genshen/wssocks-plugin-ustb/plugins/vpn" log "github.com/sirupsen/logrus" ) // LoadQRImage shows QR image for login func LoadQRImage() *canvas.Image { - if qrCodeImgUrl, err := vpn.ParseQRCodeImgUrl(); err != nil { + if qrImgReader, err := vpn.LoadQrAuthImage(); err != nil { log.Println(err) // todo return nil } else { - if uri, err := storage.ParseURI(qrCodeImgUrl); err != nil { - log.Println(err) // todo: - return nil - } else { - image := canvas.NewImageFromURI(uri) - image.FillMode = canvas.ImageFillOriginal - return image - } + image := canvas.NewImageFromReader(qrImgReader, "qr.png") + image.FillMode = canvas.ImageFillOriginal + return image } } diff --git a/go.mod b/go.mod index 2cbf603..660580a 100644 --- a/go.mod +++ b/go.mod @@ -7,6 +7,7 @@ require ( github.com/genshen/cmds v0.0.0-20200505065256-d4c52690e15b github.com/genshen/wssocks v0.6.1 github.com/sirupsen/logrus v1.9.3 + github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e golang.org/x/crypto v0.18.0 gopkg.in/yaml.v3 v3.0.1 ) diff --git a/go.sum b/go.sum index 2ce2577..a72ef01 100644 --- a/go.sum +++ b/go.sum @@ -305,6 +305,8 @@ github.com/shurcooL/vfsgen v0.0.0-20200824052919-0d455de96546/go.mod h1:TrYk7fJV github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= +github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e h1:MRM5ITcdelLK2j1vwZ3Je0FKVCfqOLp5zO6trqMLYs0= +github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e/go.mod h1:XV66xRDqSt+GTGFMVlhk3ULuV0y9ZmzeVGR4mloJI3M= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= github.com/spf13/afero v1.6.0/go.mod h1:Ai8FlHk4v/PARR026UzYexafAt9roJ7LcLMAmO6Z93I= diff --git a/plugins/vpn/qr_code.go b/plugins/vpn/qr_code.go index 91a0e07..40aba98 100644 --- a/plugins/vpn/qr_code.go +++ b/plugins/vpn/qr_code.go @@ -5,13 +5,16 @@ import ( "bytes" "errors" "fmt" + "github.com/skip2/go-qrcode" "gopkg.in/yaml.v3" + "io" "net/http" "net/url" "strings" ) const LoadImgUrl = "https://n.ustb.edu.cn/login/" +const SisAuthPath = "https://sis.ustb.edu.cn" const FindQrcodeUrlRegex = `"ustb-qrcode",` const FindQrcodeImgTagRegex = `