From d434e9b0f5742e17b26ccb5f8b6aa68d3b79fbff Mon Sep 17 00:00:00 2001 From: Wendell Sun Date: Thu, 25 Jan 2018 01:12:21 +0800 Subject: [PATCH 1/8] Implements generate service url function --- utils/pwd.go | 35 ---------------------------- utils/utils.go | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 35 deletions(-) delete mode 100644 utils/pwd.go create mode 100644 utils/utils.go diff --git a/utils/pwd.go b/utils/pwd.go deleted file mode 100644 index 8f7ff3b..0000000 --- a/utils/pwd.go +++ /dev/null @@ -1,35 +0,0 @@ -package utils - -import ( - "crypto/rand" - "io" -) - -var StdChars = []byte("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789") - -func NewPasswd(length int) string { - return rand_char(length, StdChars) -} - -func rand_char(length int, chars []byte) string { - new_pword := make([]byte, length) - random_data := make([]byte, length+(length/4)) // storage for random bytes. - clen := byte(len(chars)) - maxrb := byte(256 - (256 % len(chars))) - i := 0 - for { - if _, err := io.ReadFull(rand.Reader, random_data); err != nil { - panic(err) - } - for _, c := range random_data { - if c >= maxrb { - continue - } - new_pword[i] = chars[c%clen] - i++ - if i == length { - return string(new_pword) - } - } - } -} diff --git a/utils/utils.go b/utils/utils.go new file mode 100644 index 0000000..44381f3 --- /dev/null +++ b/utils/utils.go @@ -0,0 +1,62 @@ +package utils + +import ( + "crypto/rand" + "encoding/base64" + "fmt" + "io" + "strings" +) + +var StdChars = []byte("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789") + +func NewPasswd(length int) string { + return rand_char(length, StdChars) +} + +func rand_char(length int, chars []byte) string { + new_pword := make([]byte, length) + random_data := make([]byte, length+(length/4)) // storage for random bytes. + clen := byte(len(chars)) + maxrb := byte(256 - (256 % len(chars))) + i := 0 + for { + if _, err := io.ReadFull(rand.Reader, random_data); err != nil { + panic(err) + } + for _, c := range random_data { + if c >= maxrb { + continue + } + new_pword[i] = chars[c%clen] + i++ + if i == length { + return string(new_pword) + } + } + } +} + +func ServiceURL(serviceType, host string, port int, method, password string) string { + var protocol, base64Link string + switch serviceType { + case "SS", "": + protocol = "ss" + //method:password@server:port + base64Link = ssbase64Encode(fmt.Sprintf("%s:%s@%s:%d", method, password, host, port)) + case "SSR": + protocol = "ssr" + //server:port:protocol:method:obfs:password_base64/?suffix_base64 + base64Pwd := ssbase64Encode(password) + suffix := fmt.Sprintf("protoparam=%s", ssbase64Encode("32")) + base64Link = ssbase64Encode(fmt.Sprintf("%s:%d:%s:%s:%s:%s/?%s", host, port, "auth_aes128_md5", method, "tls1.2_ticket_auth_compatible", base64Pwd, suffix)) + default: + return "" + } + return fmt.Sprintf("%s://%s", protocol, base64Link) +} + +func ssbase64Encode(s string) string { + encoded := base64.URLEncoding.EncodeToString([]byte(s)) + return strings.TrimRight(encoded, "=") +} From 6d21581e094f24d6c7fe3774f3242d9b351d6b9f Mon Sep 17 00:00:00 2001 From: Wendell Sun Date: Thu, 25 Jan 2018 09:51:02 +0800 Subject: [PATCH 2/8] Return service url field --- controllers/panel.go | 2 ++ models/user.go | 1 + 2 files changed, 3 insertions(+) diff --git a/controllers/panel.go b/controllers/panel.go index 414f68d..8696f1d 100644 --- a/controllers/panel.go +++ b/controllers/panel.go @@ -9,6 +9,7 @@ import ( "github.com/gin-gonic/gin" "github.com/go-ignite/ignite/models" "github.com/go-ignite/ignite/ss" + "github.com/go-ignite/ignite/utils" ) var ( @@ -65,6 +66,7 @@ func (router *MainRouter) PanelIndexHandler(c *gin.Context) { ServiceMethod: user.ServiceMethod, ServiceType: user.ServiceType, Expired: user.Expired.Format("2006-01-02"), + ServiceURL: utils.ServiceURL(user.ServiceType, utils.HOST_Address, user.ServicePort, user.ServiceMethod, user.ServicePwd), } if uInfo.ServiceMethod == "" { uInfo.ServiceMethod = "aes-256-cfb" diff --git a/models/user.go b/models/user.go index 5b48b67..e2f5e28 100644 --- a/models/user.go +++ b/models/user.go @@ -35,5 +35,6 @@ type UserInfo struct { ServicePwd string ServiceMethod string ServiceType string + ServiceURL string Expired string } From 7d0fd60cc3cc84fc120edf7fa9fb5120973a9e14 Mon Sep 17 00:00:00 2001 From: vv13 Date: Fri, 26 Jan 2018 01:52:47 +0800 Subject: [PATCH 3/8] feat: QRcode ui --- static/css/styles.css | 73 +++++++++++++++++++++++++++---------------- static/js/panel.js | 28 +++-------------- templates/footer.html | 16 +--------- templates/panel.html | 28 ++++++++++++----- 4 files changed, 72 insertions(+), 73 deletions(-) diff --git a/static/css/styles.css b/static/css/styles.css index a214f64..d8b669b 100644 --- a/static/css/styles.css +++ b/static/css/styles.css @@ -213,9 +213,6 @@ h2::after { content: " "; border: solid 2px #3dc9b3; display: block; width: 35px } @media (max-width: 768px) { - .navbar-fixed-bottom { - display: none; - } .hero, .infobox { width: 100% !important; @@ -223,7 +220,7 @@ h2::after { content: " "; border: solid 2px #3dc9b3; display: block; width: 35px .basic-slide { display: block !important; justify-content: space-around; - max-height: 200px; + max-height: 300px; overflow: auto; } .progressbar { @@ -237,9 +234,9 @@ Hero ========================================================================== */ .hero { position: absolute; - top: 50%; - left: 50%; - transform: translate(-50%, -50%); + top: 70px; + left: 0; + right: 0; height: auto; z-index: 2; } @@ -350,12 +347,11 @@ InfoBox .header-bar { width: 100%; - height: 50px; background: rgba(61, 201, 179, 0.67); color: white; font-size: 20px; /*background: rgba(236, 155, 59, 0.67);*/ - padding: 13px 10px; + padding: 5px 10px; margin: 0px 0px 0px 0px; border-top-left-radius: 15px; border-top-right-radius: 15px; @@ -363,7 +359,6 @@ InfoBox .middle-bar { width: 100%; - height: 50px; background: rgba(61, 201, 179, 0.67); color: white; font-size: 20px; @@ -375,7 +370,6 @@ InfoBox .infobox span { position: relative; display: inline-block; - margin: 5px 10px; } .basic-slide_line { @@ -411,7 +405,8 @@ InfoBox .basic-slide_wrap { display: block; width: 280px; - margin: auto; + margin-left: auto; + margin-right: auto; } .basic-slide_label { @@ -578,6 +573,31 @@ InfoBox -webkit-animation-delay: 11s; animation-delay: 11s; } + +#icon-qrcode { + color: #fff; + font-size: 20px; + margin-left: 10px; + cursor: pointer; +} + +#icon-qrcode .icon-qrcode { + font-size: 25px; +} + +.qrcode-wrap { + display: none; +} + +.showQR .qrcode-wrap { + display: block; +} +.showQR .basic-slide_wrap { + display: none; +} +.showQR .icon-qrcode { + color: #7eea19; +} @-webkit-keyframes square { 0% { -webkit-transform: translateY(0); @@ -600,21 +620,6 @@ InfoBox } -/*Footer -========================================================================== */ -.footer { - display: flex; - justify-content: space-between; -} -footer a { color: #a1a9b0; } -footer { background-color: rgba(0,0,0,0.5); padding: 5px 0 5px; } -footer p { color: #fff; } -ul.legals { list-style: none; color: #fff; line-height: 25px; } -ul.legals li { display: inline-block; } -ul.legals li::after { content: " |"; } -ul.legals li:last-child::after { content: ""; } -.legals { text-align: left; } -.credit { text-align: right; } /* ========================================================================== FlexSlider Custom CSS ========================================================================== */ @@ -630,3 +635,17 @@ Waypoints .wp3 { background: url('/static/images/iphone-bg.png') no-repeat center center; background-position: 200px 10px; height: 100%; } + +/* boostrap reset */ +.popover-content { + overflow: auto; +} + +.qrcode-url-line span { + display: table-cell; + cursor: pointer; +} +.qrcode-url-line { + width: 80%; + margin: auto; +} diff --git a/static/js/panel.js b/static/js/panel.js index 33837d7..769f866 100644 --- a/static/js/panel.js +++ b/static/js/panel.js @@ -12,14 +12,14 @@ var Panel = function () { // $('#account-detail').slideToggle('slow'); // } // }); - + $('#icon-qrcode').click(function() { + $('.infobox').toggleClass('showQR'); + }); $('#server-type').on('change', function (e) { var methods = []; if (this.value == 'SS') { - // for ss methods = ssMethods; } else if (this.value == "SSR") { - // for ssr methods = ssrMethods; } $("#method").empty(); @@ -44,25 +44,7 @@ var Panel = function () { var url = form.attr("action"); $.post(url, form.serialize(), function (resp) { if (resp.success) { - $('#host').val(resp.data.host); - $('#port').val(resp.data.servicePort); - $('#pwd').val(resp.data.servicePwd); - $('#encrypt').val($('#method').val()); - var serverType = $('#server-type').val(); - $('#types').val(serverType); - if (serverType == "SSR") { - $('.infobox').addClass("multiline"); - $('#ssr_info').css('display', 'block'); - } - - $('#package-limit').html(resp.data.packageLimit + 'GB'); - $('#package-used').html('0GB'); - $('#package-left').html(resp.data.packageLimit + 'GB'); - $('.progressbar').attr('data-perc', '0'); - $('#service-status').html('
运行中'); - - $('.boxLoading').css('display', 'none'); - $('.infobox').fadeIn(1500); + window.location.href = '/panel/index' } else { $('.boxLoading').css('display', 'block'); $('.boxLoading').fadeOut(500); @@ -80,4 +62,4 @@ var Panel = function () { createHandler(); } }; -}(); \ No newline at end of file +}(); diff --git a/templates/footer.html b/templates/footer.html index 5dae1b5..f42a358 100644 --- a/templates/footer.html +++ b/templates/footer.html @@ -1,19 +1,5 @@ {{ define "footer.html" }} - - - + diff --git a/templates/panel.html b/templates/panel.html index 8098bbd..ee1c5ed 100644 --- a/templates/panel.html +++ b/templates/panel.html @@ -12,7 +12,7 @@ - + @@ -61,14 +61,21 @@

创建服务

-