Skip to content

Commit 4176bc3

Browse files
author
woytu
committed
合并下载和获取key页面,修复一个获取key的bug
1 parent ea48489 commit 4176bc3

File tree

8 files changed

+54
-164
lines changed

8 files changed

+54
-164
lines changed

controller.go

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ package main
33
import (
44
"fmt"
55
"github.com/gin-gonic/gin"
6-
log "github.com/sirupsen/logrus"
76
"io"
7+
"log"
88
"net/http"
99
"os"
1010
"path"
@@ -69,15 +69,14 @@ func GetKey(c *gin.Context) {
6969
// 获取当前绝对路径
7070
dir, err := os.Getwd()
7171
if err != nil {
72-
log.Error(err)
72+
log.Println(err)
7373
c.JSON(http.StatusOK, result.SystemError())
7474
return
7575
}
7676
if company == "netsarang" {
7777
out, err := utils.ExecutePython(path.Join(dir, "pyutils", "xshell_key.py"), app, version)
7878
if err != nil {
79-
log.Error(err)
80-
fmt.Println(err)
79+
log.Println(err)
8180
c.JSON(http.StatusOK, result.SystemError())
8281
return
8382
}
@@ -115,13 +114,13 @@ func Upload(c *gin.Context) {
115114
fmt.Println(header.Filename)
116115
out, err := os.Create("./tmp/" + filename + ".png")
117116
if err != nil {
118-
log.Error(err)
117+
log.Println(err)
119118
}
120119
defer out.Close()
121120
// 拷贝上传的文件信息到新建的out文件中
122121
_, err = io.Copy(out, file)
123122
if err != nil {
124-
log.Error(err)
123+
log.Println(err)
125124
}
126125
}
127126

@@ -140,17 +139,8 @@ func Dowload(c *gin.Context) {
140139
c.DataFromReader(http.StatusOK, response.ContentLength, response.Header.Get("Content-Type"), response.Body, extraHeaders)
141140
}
142141

143-
// Netsarang下载页面
144-
func NetsarangDownloadIndex(c *gin.Context) {
145-
// 301重定向
146-
//c.Redirect(http.StatusMovedPermanently, "/static")
147-
// 返回HTML页面
148-
//c.HTML(http.StatusOK, "index.html", nil)
149-
c.HTML(http.StatusOK, "netsarang.html", gin.H{})
150-
}
151-
152-
// 获取Netsarang下载url
153-
func GetXshellUrl(c *gin.Context) {
142+
// 获取NetSarang下载url
143+
func GetNetSarangDownloadUrl(c *gin.Context) {
154144
// POST 获取的所有参数内容的类型都是 string
155145
app := c.PostForm("app")
156146
if utils.IsStringEmpty(app) {
@@ -164,7 +154,7 @@ func GetXshellUrl(c *gin.Context) {
164154
}
165155
url, err := reptile.DownloadNetsarang(app)
166156
if err != nil {
167-
log.Error(err)
157+
log.Println(err)
168158
c.JSON(http.StatusOK, result.SystemError())
169159
return
170160
}
@@ -194,13 +184,13 @@ func NginxFormatPython(c *gin.Context) {
194184
// 获取当前绝对路径
195185
dir, err := os.Getwd()
196186
if err != nil {
197-
log.Error(err)
187+
log.Println(err)
198188
c.JSON(http.StatusOK, result.SystemError())
199189
return
200190
}
201191
out, err := utils.ExecutePython(path.Join(dir, "pyutils", "nginxfmt.py"), code)
202192
if err != nil {
203-
log.Error(err)
193+
log.Println(err)
204194
c.JSON(http.StatusOK, result.SystemError())
205195
return
206196
}

pyutils/xshell_key.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@
6969
[ProductCode['Xshell'], 0x52, 0, 'Educational', 2],
7070
[ProductCode['Xshell'], 0x55, 0, 'Standard', 1],
7171
[ProductCode['Xshell'], 0x56, 0, 'Educational', 1],
72-
[ProductCode['Xshell'], 0x60, 0, 'Standard', 1], # ������
73-
[ProductCode['Xshell'], 0x61, 0, 'Standard', 2], # ������
72+
[ProductCode['Xshell'], 0x60, 0, 'Standard', 1],
73+
[ProductCode['Xshell'], 0x61, 0, 'Standard', 2],
7474
[ProductCode['Xshell'], 0x62, 0, 'Standard', 1],
7575
[ProductCode['Xshell'], 0x63, 0, 'Standard', 2],
7676
[ProductCode['Xlpd'], 0x0B, 0, 'Standard', 2],

reptile/Netsarang.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,19 @@ func SendMail(mail, product string) error {
3434
}
3535

3636
var url string
37-
if product == "xshell" {
37+
if product == "Xshell" {
3838
url = "https://www.netsarang.com/zh/xshell-download"
3939
}
4040

41-
if product == "xftp" {
41+
if product == "Xftp" {
4242
url = "https://www.netsarang.com/zh/xftp-download"
4343
}
4444

45-
if product == "xmanager-power-suite" {
45+
if product == "Xmanager" {
4646
url = "https://www.netsarang.com/zh/xmanager-power-suite-download"
4747
}
4848

49-
if product == "xshell-plus" || product == "" {
49+
if product == "Xshell Plus" || product == "" {
5050
url = "https://www.netsarang.com/zh/xshell-plus-download"
5151
}
5252

static/js/index.js

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ function selectCompany() {
4545
$("#version").append('<option value="4">4</option>');
4646
$("#version").append('<option value="3">3</option>');
4747
$("#version").append('<option value="2">2</option>');
48+
$("#netSarangDownloadBtn").show();
4849
} else if (company == "mobatek") {
4950
$("#app").empty();
5051
//为Select追加一个Option(下拉项)
@@ -68,6 +69,7 @@ function selectCompany() {
6869
$("#version").append('<option value="9.2">9.2</option>');
6970
$("#version").append('<option value="9.1">9.1</option>');
7071
$("#version").append('<option value="9.0">9.0</option>');
72+
$("#netSarangDownloadBtn").hide();
7173
} else if (company == "torchsoft") {
7274
$("#app").empty();
7375
//为Select追加一个Option(下拉项)
@@ -84,6 +86,7 @@ function selectCompany() {
8486
$("#version").append('<option value="3">3</option>');
8587
$("#version").append('<option value="2">2</option>');
8688
$("#version").append('<option value="1" selected>1</option>');
89+
$("#netSarangDownloadBtn").hide();
8790
}
8891
}
8992

@@ -150,11 +153,22 @@ function getKey() {
150153

151154
// ======================================= 下载Netsarang ======================================
152155

153-
function xshellDownload() {
154-
let app = $("#xshell-app").val();
155-
let version = $("#xshell-version").val();
156+
function netSarangDownload() {
157+
let company = $("#company").val();
158+
if (company != "netsarang") {
159+
//提示层
160+
layer.msg("只提供NetSarang的产品最新版本下载", {icon: 5});
161+
return;
162+
}
163+
let app = $("#app").val();
164+
let version = $("#version").val();
165+
if (version != "6") {
166+
//提示层
167+
layer.msg("只提供NetSarang的产品最新版本下载", {icon: 5});
168+
return;
169+
}
156170
//加载层,0代表加载的风格,支持0-2,0.5透明度的白色背景
157-
let index = layer.load(0, {shade: [0.5,'#fff']});
171+
let index = layer.load(0, {shade: [0.5, '#fff']});
158172
$.ajax({
159173
url: "/getXshellUrl",
160174
type: "POST",
@@ -165,7 +179,7 @@ function xshellDownload() {
165179
layer.close(index);
166180
if (result.code == 200) {
167181
let html = "<div style='width:100%;height:100%;padding:5%;text-align:center;word-wrap:break-word;'>" +
168-
"<p><b>下载地址:</b></p>" +
182+
"<p><b>" + app + " 下载地址:</b></p>" +
169183
"<p><a href='" + result.data.url + "' target='_blank'>" + result.data.url + "</a></p>" +
170184
"</div>";
171185
let area_width = "40%";

templates/index.html

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
<meta charset="UTF-8">
55
<meta name="viewport" content="width=device-width, initial-scale=1.0">
66
<meta name="description" content="本网页提供Xshell和Xftp激活秘钥">
7-
<meta name="keywords" content="Xshell,Xftp,Xftp,Xshell Plus,Xmanager Power Suite各版本激活"/>
7+
<meta name="keywords"
8+
content="Xshell,Xftp,Xftp,Xshell Plus,Xmanager Power Suite各版本激活,Xshell,Xshell5下载,Xshell5官网下载,
9+
Xshell免费版,Xshell个人版,Xftp,Xftp免费版下载,Xshell免费版下载,NetSarang"/>
810
<title>Shell激活</title>
911
<link rel="shortcut icon" type="image/x-icon" href="/static/images/favicon.ico"/>
1012
<link rel="stylesheet" href="https://fonts.lug.ustc.edu.cn/css?family=Raleway:200"/>
@@ -20,8 +22,8 @@
2022
<body>
2123
<div id="main">
2224
<div class="header">
23-
<h1>Xshell / Xftp 激活</h1>
24-
<h2>支持Xshell、Xftp、Xshell Plus、Xmanager Power Suite各版本激活</h2>
25+
<h1>Xshell / Xftp 激活下载</h1>
26+
<h2>支持Xshell、Xftp、Xshell Plus、Xmanager Power Suite各版本激活下载</h2>
2527
<table>
2628
<tbody>
2729
<tr>
@@ -41,7 +43,9 @@ <h2>支持Xshell、Xftp、Xshell Plus、Xmanager Power Suite各版本激活</h2>
4143
<div class="content">
4244
<p>
4345
<b>下载官方版本:</b>
44-
<a target="_blank" href="/download">download</a>
46+
<a target="_blank" href="https://www.netsarang.com/zh/all-downloads">
47+
https://www.netsarang.com/zh/all-downloads
48+
</a>
4549
</p>
4650
<p>
4751
<b>安装方式:</b>
@@ -65,7 +69,7 @@ <h2>支持Xshell、Xftp、Xshell Plus、Xmanager Power Suite各版本激活</h2>
6569
<fieldset>
6670
<label for="company"><b>公司:</b></label>
6771
<select class="pure-input-1" id="company" onchange="selectCompany()">
68-
<option value="netsarang" selected>Netsarang</option>
72+
<option value="netsarang" selected>NetSarang</option>
6973
<option value="mobatek">Mobatek</option>
7074
<option value="torchsoft">torchsoft</option>
7175
</select>
@@ -89,6 +93,10 @@ <h2>支持Xshell、Xftp、Xshell Plus、Xmanager Power Suite各版本激活</h2>
8993
onclick="getKey()">
9094
点击获取秘钥
9195
</a>
96+
<br/>
97+
<br/>
98+
<a id="netSarangDownloadBtn" class="button-secondary pure-button pure-input-rounded pure-u-1 a-active"
99+
onclick="netSarangDownload()">点击获取下载链接</a>
92100
</fieldset>
93101
</form>
94102

templates/netsarang.html

Lines changed: 0 additions & 123 deletions
This file was deleted.

tool-gin.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,7 @@ func main() {
9595
router.POST("/getKey", GetKey)
9696
router.POST("/SystemInfo", SystemInfo)
9797
router.Any("/", WebRoot)
98-
router.Any("/download", NetsarangDownloadIndex)
99-
router.POST("/getXshellUrl", GetXshellUrl)
98+
router.POST("/getXshellUrl", GetNetSarangDownloadUrl)
10099
router.Any("/nginx-format", NginxFormatIndex)
101100
router.POST("/nginx-format-py", NginxFormatPython)
102101

utils/exec.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@ func ExecutePython(script string, args ...string) (string, error) {
1717
return "", err
1818
}
1919
name := "python"
20-
//if runtime.GOOS == "linux" {
21-
// name = "python3"
22-
//}
20+
// 判断是否同时装了python2.7和python3,优先使用python3
21+
_, err := Execute("python3", "-V")
22+
if err == nil {
23+
name = "python3"
24+
}
2325
// 把脚本和参数组合到一个字符串数组
2426
args = append([]string{script}, args...)
2527
out, err := Execute(name, args...)

0 commit comments

Comments
 (0)