@@ -0,0 +1,6 @@ | |||
FROM golang | |||
MAINTAINER yk | |||
WORKDIR /go/src/ | |||
COPY . . | |||
EXPOSE 8090 | |||
CMD ["/bin/bash", "/go/src/build.sh"] |
@@ -0,0 +1,2 @@ | |||
#!/usr/bin/env bash | |||
cd /go/src/ && ./honorRH |
@@ -0,0 +1,5 @@ | |||
{ | |||
"port": 8090, | |||
"remoteSrv": "https://apig.hihonor.com/api", | |||
"door": "GATE1" | |||
} |
@@ -0,0 +1,5 @@ | |||
module rh1 | |||
go 1.19 | |||
require github.com/patrickmn/go-cache v2.1.0+incompatible // indirect |
@@ -0,0 +1,2 @@ | |||
github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc= | |||
github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ= |
@@ -0,0 +1,206 @@ | |||
<!DOCTYPE html> | |||
<html class="text-start"> | |||
<head> | |||
<meta charset="utf-8"> | |||
<meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no"> | |||
<title>首页</title> | |||
<link rel="stylesheet" href="assets/bootstrap/css/bootstrap.min.css"> | |||
<link rel="stylesheet" href="assets/fonts/font-awesome.min.css"> | |||
<link rel="stylesheet" href="assets/fonts/ionicons.min.css"> | |||
<link rel="stylesheet" href="assets/css/Login-Form-Dark.css"> | |||
<link rel="stylesheet" href="assets/css/Toggle-Switch-1.css"> | |||
<link rel="stylesheet" href="assets/css/Toggle-Switch.css"> | |||
<link rel="stylesheet" href="assets/css/Toggle-Switches.css"> | |||
<style type="text/css"> | |||
.close{ | |||
float: right; | |||
font-size: 21px; | |||
font-weight: 700; | |||
line-height: 1; | |||
color: #000; | |||
text-shadow: 0 1px 0 #fff; | |||
filter: alpha(opacity=20); | |||
opacity: .2; | |||
} | |||
.alert{ | |||
padding: 5px; | |||
/*margin-bottom: 20px;*/ | |||
border: 1px solid transparent; | |||
border-radius: 4px; | |||
width: 100%; | |||
height: fit-content; | |||
} | |||
a{ | |||
text-decoration: none; | |||
} | |||
</style> | |||
</head> | |||
<body id="page-top" data-bs-spy="scroll" data-bs-target="#mainNav" data-bs-offset="56"> | |||
<nav class="navbar navbar-light navbar-expand-lg fixed-top" id="mainNav"> | |||
<div class="container"><a class="navbar-brand" href="#page-top"><img src="assets/img/honor-logo-black.svg"></a><button data-bs-toggle="collapse" data-bs-target="#navbarResponsive" class="navbar-toggler float-end" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation"><i class="fa fa-bars"></i></button> | |||
<div class="collapse navbar-collapse" id="navbarResponsive"> | |||
<ul class="navbar-nav ms-auto"> | |||
<!-- <li class="nav-item"><a class="nav-link" href="/changePwd">修改密码</a></li> --> | |||
<li class="nav-item"><a class="nav-link logout" href="#">注销</a></li> | |||
</ul> | |||
</div> | |||
</div> | |||
</nav> | |||
<header class="masthead" style="background: url(assets/img/bg-pattern.png), linear-gradient(to left, #1B2C45, #41464b);height: 100%;padding-top: 70px;"> | |||
<div id="myAlert" class="alert alert-success" role="alert" style="display: none;margin-bottom: 5px;position: absolute;z-index: 999;"> | |||
<a href="#" class="close" data-dismiss="alert">×</a> | |||
<h6 class="alert-heading" style="margin: 0;">操作成功!</h6> | |||
</div> | |||
<div class="container h-100"> | |||
<div class="row h-100"> | |||
<div class="col"> | |||
<div class="card" style="color: black;"> | |||
<div class="card-header"> | |||
<h5 class="mb-0">远程操作</h5> | |||
</div> | |||
<!-- <div class="card-body" style="padding: 1rem 1rem 0rem 1rem;border-bottom: 1px solid #313b4840;"> | |||
<div> | |||
<label class="form-label" style="height: 50px;vertical-align: middle;font-size: 20px;">人行通道1</label><label class="switch"> | |||
<input class="ck-status" type="checkbox" id="ck-GATE1-status" devId="GATE1"> | |||
<span class="slider round"></span> | |||
</label> | |||
</div> | |||
</div> --> | |||
<div class="card-body" style="padding: 1rem 1rem 0rem 1rem;border-bottom: 1px solid #313b4840;"> | |||
<div> | |||
<label class="form-label" style="height: 50px;vertical-align: middle;font-size: 20px;">人行通道1</label><label class="switch"> | |||
<input class="ck-status" type="checkbox" id="ck-PSGATE01-status" devId="PSGATE01"> | |||
<span class="slider round"></span> | |||
</label> | |||
</div> | |||
</div> | |||
<div class="card-body" style="padding: 1rem 1rem 0rem 1rem;border-bottom: 1px solid #313b4840;"> | |||
<div> | |||
<label class="form-label" style="height: 75px;vertical-align: middle;font-size: 20px;">人行通道2</label><label class="switch"> | |||
<input class="ck-status" type="checkbox" id="ck-PSGATE02-status" devId="PSGATE02"> | |||
<span class="slider round"></span> | |||
</label> | |||
</div> | |||
</div> | |||
<div class="card-body" style="padding: 1rem 1rem 0rem 1rem;border-bottom: 1px solid #313b4840;"> | |||
<div> | |||
<label class="form-label" style="height: 75px;vertical-align: middle;font-size: 20px;">人行通道3</label><label class="switch"> | |||
<input class="ck-status" type="checkbox" id="ck-PSGATE03-status" devId="PSGATE03"> | |||
<span class="slider round"></span> | |||
</label> | |||
</div> | |||
</div> | |||
<div class="card-body" style="padding: 1rem 1rem 0rem 1rem;"> | |||
<div> | |||
<label class="form-label" style="height: 75px;vertical-align: middle;font-size: 20px;">货物通道1</label><label class="switch"> | |||
<input class="ck-status" type="checkbox" id="ck-PSGATE04-status" devId="PSGATE04"> | |||
<span class="slider round"></span> | |||
</label> | |||
</div> | |||
</div> | |||
</div> | |||
</div> | |||
</div> | |||
</div> | |||
</header> | |||
<div class="modal" id="loadingModal" backdrop="static" keyborad="false" style="display:none;background: black;opacity: 0.75;"> | |||
<img src="assets/img/loading2.gif" alt="" style="width: 100px;height: 100px;z-index: 2000;position: absolute;text-align: center;left: 50%;top:50%;margin-left: -50px;margin-top: -50px;" /> | |||
</div> | |||
<footer style="position: absolute;bottom: 0;width: 100%;"> | |||
<div class="container"> | |||
<p>© 内部使用 禁止外传</p> | |||
</div> | |||
</footer> | |||
<script src="assets/js/jquery-3.5.0.min.js"></script> | |||
<script src="assets/bootstrap/js/bootstrap.min.js"></script> | |||
<script src="assets/js/cust.js"></script> | |||
<script src="assets/js/new-age.js"></script> | |||
<script type="text/javascript"> | |||
$(function(){ | |||
$(".logout").on('click', function () { | |||
document.cookie=""; | |||
window.location.href = "/login"; | |||
}) | |||
var devs = ["PSGATE01","PSGATE02","PSGATE03","PSGATE04"]; | |||
devs.map(function(ss){ | |||
$.ajax({url:"/devList",data:{dev:ss}, method:"post",cache: false, | |||
contentType: "application/x-www-form-urlencoded",beforeSend:function(){ | |||
showLoading(); | |||
},success:function(data){ | |||
hideLoading(); | |||
if (data.Code == 200) { | |||
// $("#myAlert").css("display", "block"); | |||
$("#ck-"+ss+"-status").prop("checked",true); | |||
} else { | |||
// obj.prop("checked",!flag); | |||
$("#ck-"+ss+"-status").prop("checked",false); | |||
} | |||
},error:function(err){ | |||
}}) | |||
}) | |||
$(".ck-status").click(function(){ | |||
var flag = $(this).is(":checked"); | |||
var dev = $(this).attr("devId"); | |||
var obj = $(this); | |||
$.ajax({url:"/handleAct",data:{active:flag?0:1, dev:dev}, method:"post",cache: false, | |||
contentType: "application/x-www-form-urlencoded",beforeSend:function(){ | |||
showLoading(); | |||
},success:function(data){ | |||
hideLoading(); | |||
if (data.Code == 200 && (data.Msg == "" || data.Msg.indexOf("成功") > -1)) { | |||
$(".alert-heading").html("操作成功!"); | |||
$("#myAlert").css("display", "block"); | |||
$("#myAlert").removeClass("alert-warning").addClass("alert-success"); | |||
setTimeout(function(){ | |||
$("#myAlert").css("display", "none"); | |||
},2500) | |||
} else { | |||
if (data.Msg) { | |||
$(".alert-heading").html("操作失败,请稍候重试!<small>("+(data.Msg)+")</small>"); | |||
$("#myAlert").removeClass("alert-success").addClass("alert-warning"); | |||
$("#myAlert").css("display", "block"); | |||
obj.prop("checked",!flag); | |||
} else { | |||
window.location.href = "/login"; | |||
} | |||
} | |||
},error:function(err){ | |||
hideLoading(); | |||
$(".alert-heading").html("操作失败,请稍候重试!"); | |||
$("#myAlert").removeClass("alert-success").addClass("alert-warning"); | |||
$("#myAlert").css("display", "block"); | |||
obj.prop("checked",!flag); | |||
}}) | |||
}) | |||
function showLoading(){ | |||
$("#loadingModal").css("display", "block"); | |||
} | |||
function hideLoading(){ | |||
$("#loadingModal").css("display", "none"); | |||
} | |||
$(".close").click(function(){ | |||
$("#myAlert").css("display", "none"); | |||
}); | |||
}) | |||
</script> | |||
</body> | |||
</html> |
@@ -0,0 +1,107 @@ | |||
package aes | |||
import ( | |||
"bytes" | |||
"crypto/aes" | |||
"crypto/cipher" | |||
"crypto/des" | |||
"fmt" | |||
"encoding/hex" | |||
) | |||
func AesEncryptCBC(origData2, key2 string) (encrypted []byte) { | |||
origData := []byte(origData2) | |||
key := []byte(key2) | |||
// 分组秘钥 | |||
// NewCipher该函数限制了输入k的长度必须为16, 24或者32 | |||
block, _ := aes.NewCipher(key) | |||
blockSize := block.BlockSize() // 获取秘钥块的长度 | |||
origData = pkcs5Padding(origData, blockSize) // 补全码 | |||
blockMode := cipher.NewCBCEncrypter(block, key[:blockSize]) // 加密模式 | |||
encrypted = make([]byte, len(origData)) // 创建数组 | |||
blockMode.CryptBlocks(encrypted, origData) // 加密 | |||
return encrypted | |||
} | |||
func AesDecryptCBC(encrypted2 , key2 string) (decrypted []byte) { | |||
encrypted := []byte(encrypted2) | |||
key := []byte(key2) | |||
block, _ := aes.NewCipher(key) // 分组秘钥 | |||
blockSize := block.BlockSize() // 获取秘钥块的长度 | |||
blockMode := cipher.NewCBCDecrypter(block, key[:blockSize]) // 加密模式 | |||
decrypted = make([]byte, len(encrypted)) // 创建数组 | |||
blockMode.CryptBlocks(decrypted, encrypted) // 解密 | |||
decrypted = pkcs5UnPadding(decrypted) // 去除补全码 | |||
return decrypted | |||
} | |||
func pkcs5Padding(ciphertext []byte, blockSize int) []byte { | |||
padding := blockSize - len(ciphertext)%blockSize | |||
padtext := bytes.Repeat([]byte{byte(padding)}, padding) | |||
return append(ciphertext, padtext...) | |||
} | |||
func pkcs5UnPadding(origData []byte) []byte{ | |||
length := len(origData) | |||
unpadding := int(origData[length-1]) | |||
fmt.Println(length) | |||
fmt.Println(unpadding) | |||
if (length<=unpadding) { | |||
return []byte("") | |||
} | |||
return origData[:(length - unpadding)] | |||
} | |||
func EncryptDES_ECB(src, key string) string { | |||
data := []byte(src) | |||
keyByte := []byte(key) | |||
block, err := des.NewCipher(keyByte) | |||
if err != nil { | |||
panic(err) | |||
} | |||
bs := block.BlockSize() | |||
//对明文数据进行补码 | |||
data = pkcs5Padding(data, bs) | |||
if len(data)%bs != 0 { | |||
panic("Need a multiple of the blocksize") | |||
} | |||
out := make([]byte, len(data)) | |||
dst := out | |||
for len(data) > 0 { | |||
//对明文按照blocksize进行分块加密 | |||
//必要时可以使用go关键字进行并行加密 | |||
block.Encrypt(dst, data[:bs]) | |||
data = data[bs:] | |||
dst = dst[bs:] | |||
} | |||
return fmt.Sprintf("%X", out) | |||
} | |||
// Go DES ECB解密 | |||
func DecryptDES_ECB(src, key string) string { | |||
data, err := hex.DecodeString(src) | |||
if err != nil { | |||
fmt.Println("prase error"); | |||
panic(err) | |||
} | |||
keyByte := []byte(key) | |||
block, err := des.NewCipher(keyByte) | |||
if err != nil { | |||
fmt.Println("prase error22"); | |||
panic(err) | |||
} | |||
bs := block.BlockSize() | |||
if len(data)%bs != 0 { | |||
panic("crypto/cipher: input not full blocks") | |||
} | |||
out := make([]byte, len(data)) | |||
dst := out | |||
for len(data) > 0 { | |||
block.Decrypt(dst, data[:bs]) | |||
data = data[bs:] | |||
dst = dst[bs:] | |||
} | |||
fmt.Println(out) | |||
out = pkcs5UnPadding(out) | |||
return string(out) | |||
} |
@@ -0,0 +1,58 @@ | |||
package main | |||
import ( | |||
"log" | |||
"net/http" | |||
"rh1/utils" | |||
"rh1/route" | |||
"strconv" | |||
"fmt" | |||
) | |||
func main() { | |||
//utils.WriteStructDataToJsonFile(); | |||
config := utils.DeserializeJson2() | |||
//utils.UpdateUserData(utils.Userdata{Name:"admin1", Pwd:"123456"}) | |||
http.Handle("/assets/", http.StripPrefix("/assets/", http.FileServer(http.Dir("./template/assets")))) | |||
http.HandleFunc("/login", route.Login) | |||
http.HandleFunc("/changePwd", route.ChangePwd) | |||
http.HandleFunc("/", route.Index) | |||
http.HandleFunc("/index", route.Index) | |||
http.HandleFunc("/handleAct", route.RemoteHandle) | |||
http.HandleFunc("/devList", route.DevList) | |||
/*origData := "hello" // 待加密的数据 | |||
log.Println("原文:", string(origData)) | |||
now := time.Now() | |||
log.Println(now) | |||
kk := now.Format("20060102") | |||
log.Println(kk) | |||
log.Println("------------------ECB模式 --------------------") | |||
encrypted2 := aes.EncryptDES_ECB(origData, kk) | |||
log.Println("密文(hex):", encrypted2) | |||
log.Println("密文(base64):", base64.StdEncoding.EncodeToString([]byte(encrypted2))) | |||
decrypted2 := aes.DecryptDES_ECB(encrypted2, kk) | |||
log.Println("解密结果:", string(decrypted2))*/ | |||
err := http.ListenAndServe(":"+strconv.Itoa(config.Port), nil) | |||
if err != nil { | |||
log.Fatal(err) | |||
} | |||
fmt.Printf("start successful. Port: %d", config.Port) | |||
} | |||
@@ -0,0 +1 @@ | |||
./honorRH: ./honorRH: cannot execute binary file |
@@ -0,0 +1,346 @@ | |||
package route | |||
import ( | |||
"io/ioutil" | |||
"net/http" | |||
"text/template" | |||
"rh1/utils" | |||
"encoding/base64" | |||
"encoding/json" | |||
"mime/multipart" | |||
"fmt" | |||
"log" | |||
"bytes" | |||
) | |||
type Resp struct { | |||
Code int | |||
Msg string | |||
} | |||
func addHeader(w http.ResponseWriter, r *http.Request) (http.ResponseWriter, bool){ | |||
if (!(r.URL.Path == "/login")) { | |||
cookie,err := r.Cookie("aa") | |||
if cookie == nil && err != nil { | |||
http.Redirect(w, r, "/login", http.StatusFound) | |||
return w, false; | |||
} | |||
cookie2,err2 := r.Cookie("bb") | |||
if cookie2 == nil && err2 != nil { | |||
http.Redirect(w, r, "/login", http.StatusFound) | |||
return w, false; | |||
} | |||
} | |||
// Get the string associated with the key "foo" from the cache | |||
fmt.Println("addHeader===="+r.URL.Path) | |||
w.Header().Set("Access-Control-Allow-Origin", "*") // 可将将 * 替换为指定的域名 | |||
w.Header().Set("Access-Control-Request-Private-Network", "true") | |||
w.Header().Set("Access-Control-Allow-Headers", "Content-Type,AccessToken,X-CSRF-Token, Authorization") //你想放行的header也可以在后面自行添加 | |||
w.Header().Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS") //我自己只使用 get post 所以只放行它 | |||
//w.Header().Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE, UPDATE") | |||
w.Header().Set("Access-Control-Expose-Headers", "Content-Length, Access-Control-Allow-Origin, Access-Control-Allow-Headers, Content-Type") | |||
w.Header().Set("Access-Control-Allow-Credentials", "true") | |||
return w, true | |||
} | |||
func Login(w http.ResponseWriter, r *http.Request) { | |||
w , flag := addHeader(w,r) | |||
if !flag {return} | |||
if r.Method == "GET" { | |||
t, _ := template.ParseFiles("./template/login.html") | |||
cookie := &http.Cookie{ | |||
Name: "aa", | |||
Value: "", | |||
MaxAge: -1, | |||
HttpOnly:true, | |||
} | |||
cookie2 := &http.Cookie{ | |||
Name: "bb", | |||
Value: "", | |||
MaxAge: -1, | |||
HttpOnly:true, | |||
} | |||
http.SetCookie(w, cookie) | |||
http.SetCookie(w, cookie2) | |||
t.Execute(w, nil) | |||
} else { | |||
r.ParseForm() | |||
userName := r.Form.Get("username")//取得传递的用户名 | |||
userPwd := r.Form.Get("pwd")//取得传递的密码 | |||
log.Printf("Name: %s Pwd: %s\n", userName, userPwd); | |||
pwd,_ := base64.StdEncoding.DecodeString(userPwd); | |||
log.Println(string(pwd)); | |||
ableUserData := utils.IsAbleUserData(userName, string(pwd)); | |||
log.Println("ableUserData:"+(utils.Str(ableUserData,"1","0"))) | |||
if (ableUserData){ | |||
cookie := &http.Cookie{ | |||
Name: "aa", | |||
Value: userName, | |||
HttpOnly:true, | |||
} | |||
cookie2 := &http.Cookie{ | |||
Name: "bb", | |||
Value: string(pwd), | |||
HttpOnly:true, | |||
} | |||
http.SetCookie(w, cookie) | |||
http.SetCookie(w, cookie2) | |||
w.Header().Set("Location","/index") | |||
w.WriteHeader(302) | |||
return ; | |||
} else { | |||
t, _ := template.ParseFiles("./template/login.html") | |||
data := map[string]interface{}{"errTag": "登录失败", "errMsg":"用户名或密码错误", "userName":userName} | |||
// 渲染模板数据并相应页面 | |||
t.Execute(w, data) | |||
} | |||
} | |||
} | |||
type RespResult struct { | |||
Result string `json."result"` | |||
Message string `json."message"` | |||
} | |||
func RemoteHandle(w http.ResponseWriter, r *http.Request) { | |||
w, flag := addHeader(w,r) | |||
if !flag {return} | |||
if r.Method == "POST" { | |||
r.ParseForm() | |||
active := r.FormValue("active") | |||
dev := r.FormValue("dev") | |||
activeStr := "" | |||
if ("1" == active) { | |||
activeStr = "11" | |||
} else { | |||
activeStr = "00" | |||
} | |||
log.Println(active); | |||
w.Header().Set("content-type","text/json") | |||
config := utils.DeserializeJson2() | |||
url := config.SrvUrl+"/api/remoteConfig" | |||
method := "POST" | |||
payload := &bytes.Buffer{} | |||
writer := multipart.NewWriter(payload) | |||
_ = writer.WriteField("actStatus", "dirClose") | |||
_ = writer.WriteField("actValue", activeStr) | |||
_ = writer.WriteField("devs[]", dev) | |||
err := writer.Close() | |||
if err != nil { | |||
fmt.Println(err) | |||
return | |||
} | |||
client := &http.Client { | |||
} | |||
req, err := http.NewRequest(method, url, payload) | |||
if err != nil { | |||
fmt.Println(err) | |||
return | |||
} | |||
req.Header.Set("Content-Type", writer.FormDataContentType()) | |||
req.Header.Set("X-HW-ID", "872cc0ff771dae8401773d60fba800ca") | |||
req.Header.Set("X-HW-APPKEY", "5jOraqWkB7VSMnXYzoJpbQ==") | |||
res, err := client.Do(req) | |||
if err != nil { | |||
fmt.Println(err) | |||
return | |||
} | |||
defer res.Body.Close() | |||
body, err := ioutil.ReadAll(res.Body) | |||
if err != nil { | |||
fmt.Println(err) | |||
return | |||
} | |||
fmt.Println(string(body)) | |||
jsonAsBytes := []byte(string(body)) | |||
var result RespResult | |||
err = json.Unmarshal(jsonAsBytes, &result) | |||
fmt.Printf("%#v", result) | |||
if err != nil { | |||
panic(err) | |||
} | |||
msg, _ := json.Marshal(Resp{Code: 200, Msg: result.Message}) | |||
w.Write(msg) | |||
} else { | |||
http.Redirect(w, r, "/index", http.StatusFound) | |||
} | |||
} | |||
func Index(w http.ResponseWriter, r *http.Request) { | |||
w , flag:= addHeader(w,r) | |||
if !flag {return} | |||
cookie,err := r.Cookie("aa") | |||
if cookie == nil && err != nil { | |||
http.Redirect(w, r, "/login", http.StatusFound) | |||
return ; | |||
} | |||
cookie2,err2 := r.Cookie("bb") | |||
if cookie2 == nil && err2 != nil { | |||
http.Redirect(w, r, "/login", http.StatusFound) | |||
return ; | |||
} | |||
http.SetCookie(w, cookie); | |||
http.SetCookie(w, cookie2); | |||
ableUserData := utils.IsAbleUserData(cookie.Value, cookie2.Value); | |||
log.Println("ableUserData:"+(utils.Str(ableUserData,"1","0"))) | |||
if (ableUserData){ | |||
t, _ := template.ParseFiles("./template/index.html") | |||
t.Execute(w, nil) | |||
return ; | |||
} else { | |||
t, _ := template.ParseFiles("./template/login.html") | |||
data := map[string]interface{}{"errTag": "登录失败", "errMsg":"登录失效或账户信息已变动,请重新登录"} | |||
// 渲染模板数据并相应页面 | |||
t.Execute(w, data) | |||
} | |||
} | |||
func ChangePwd(w http.ResponseWriter, r *http.Request) { | |||
w , flag:= addHeader(w,r) | |||
if !flag {return} | |||
if r.Method == "GET" { | |||
t, _ := template.ParseFiles("./template/resetPwd.html") | |||
t.Execute(w, nil) | |||
} else { | |||
r.ParseForm() | |||
userName := r.Form.Get("username")//取得传递的用户名 | |||
userPwd := r.Form.Get("pwd")//取得传递的密码 | |||
log.Printf("Name: %s Pwd: %s\n", userName, userPwd); | |||
pwd,_ := base64.StdEncoding.DecodeString(userPwd); | |||
log.Println(string(pwd)); | |||
ableUserData := utils.IsAbleUserData(userName, string(pwd)); | |||
log.Println("ableUserData:"+(utils.Str(ableUserData,"1","0"))) | |||
if (ableUserData){ | |||
t, _ := template.ParseFiles("./template/index.html") | |||
data := map[string]interface{}{"username": userName, "errMsg":""} | |||
// 渲染模板数据并相应页面 | |||
t.Execute(w, data) | |||
return ; | |||
} | |||
t, _ := template.ParseFiles("./template/login.html") | |||
data := map[string]interface{}{"errTag": "登录失败", "errMsg":"用户名或密码错误"} | |||
// 渲染模板数据并相应页面 | |||
t.Execute(w, data) | |||
} | |||
} | |||
func DevList(w http.ResponseWriter, r *http.Request) { | |||
w , flag:= addHeader(w,r) | |||
if !flag {return} | |||
r.ParseForm() | |||
dev := r.FormValue("dev") | |||
log.Println(dev); | |||
w.Header().Set("content-type","text/json") | |||
config := utils.DeserializeJson2() | |||
url := config.SrvUrl+"/api/remoteDev" | |||
method := "POST" | |||
payload := &bytes.Buffer{} | |||
writer := multipart.NewWriter(payload) | |||
_ = writer.WriteField("dev", dev) | |||
err := writer.Close() | |||
if err != nil { | |||
fmt.Println(err) | |||
return | |||
} | |||
client := &http.Client { | |||
} | |||
req, err := http.NewRequest(method, url, payload) | |||
if err != nil { | |||
fmt.Println(err) | |||
return | |||
} | |||
req.Header.Set("Content-Type", writer.FormDataContentType()) | |||
req.Header.Set("X-HW-ID", "872cc0ff771dae8401773d60fba800ca") | |||
req.Header.Set("X-HW-APPKEY", "5jOraqWkB7VSMnXYzoJpbQ==") | |||
res, err := client.Do(req) | |||
if err != nil { | |||
fmt.Println(err) | |||
return | |||
} | |||
defer res.Body.Close() | |||
body, err := ioutil.ReadAll(res.Body) | |||
if err != nil { | |||
fmt.Println(err) | |||
return | |||
} | |||
fmt.Println(string(body)) | |||
jsonAsBytes := []byte(string(body)) | |||
var result RespResult | |||
err = json.Unmarshal(jsonAsBytes, &result) | |||
fmt.Printf("%#v", result) | |||
if err != nil { | |||
panic(err) | |||
} | |||
if (result.Result == "false") { | |||
msg, _ := json.Marshal(Resp{Code: 0, Msg: result.Message}) | |||
w.Write(msg) | |||
} else { | |||
msg, _ := json.Marshal(Resp{Code: 200, Msg: result.Message}) | |||
w.Write(msg) | |||
} | |||
} | |||
@@ -0,0 +1,77 @@ | |||
.login-dark { | |||
height: 94%; | |||
display: flex; | |||
background: #475d62 url(../../assets/img/star-sky.jpg); | |||
background-size: cover; | |||
position: relative; | |||
} | |||
.login-dark form { | |||
/*max-width: 278px;*/ | |||
width: 90%; | |||
background-color: #1e2833; | |||
padding: 5px 45px; | |||
border-radius: 4px; | |||
transform: translate(-50%, -50%); | |||
position: absolute; | |||
top: 50%; | |||
left: 50%; | |||
color: #fff; | |||
box-shadow: 3px 3px 4px rgba(0,0,0,0.2); | |||
} | |||
.login-dark .illustration { | |||
text-align: center; | |||
padding: 0px 0 20px; | |||
font-size: 53px; | |||
color: #2980ef; | |||
} | |||
.login-dark form .form-control { | |||
background: none; | |||
border: none; | |||
border-bottom: 1px solid #434a52; | |||
border-radius: 0; | |||
box-shadow: none; | |||
outline: none; | |||
color: inherit; | |||
} | |||
.login-dark form .btn-primary { | |||
background: #214a80; | |||
border: none; | |||
border-radius: 4px; | |||
padding: 11px; | |||
box-shadow: none; | |||
margin-top: 26px; | |||
text-shadow: none; | |||
outline: none; | |||
} | |||
.login-dark form .btn-primary:hover, .login-dark form .btn-primary:active { | |||
background: #214a80; | |||
outline: none; | |||
} | |||
.login-dark form .forgot { | |||
display: block; | |||
text-align: center; | |||
font-size: 12px; | |||
color: #6f7a85; | |||
opacity: 0.9; | |||
text-decoration: none; | |||
} | |||
.login-dark form .forgot:hover, .login-dark form .forgot:active { | |||
opacity: 1; | |||
text-decoration: none; | |||
} | |||
.login-dark form .btn-primary:active { | |||
transform: translateY(1px); | |||
} | |||
.switch { | |||
margin-left: 30%; | |||
} | |||
@@ -0,0 +1,57 @@ | |||
.switch { | |||
position: relative; | |||
display: inline-block; | |||
width: 60px; | |||
height: 34px; | |||
} | |||
.switch input { | |||
display: none; | |||
} | |||
.slider { | |||
position: absolute; | |||
cursor: pointer; | |||
top: 0; | |||
left: 0; | |||
right: 0; | |||
bottom: 0; | |||
background-color: #ccc; | |||
-webkit-transition: .4s; | |||
transition: .4s; | |||
} | |||
.slider:before { | |||
position: absolute; | |||
content: ""; | |||
height: 26px; | |||
width: 26px; | |||
left: 4px; | |||
bottom: 4px; | |||
background-color: white; | |||
-webkit-transition: .4s; | |||
transition: .4s; | |||
} | |||
input:checked + .slider { | |||
background-color: #2196F3; | |||
} | |||
input:focus + .slider { | |||
box-shadow: 0 0 1px #2196F3; | |||
} | |||
input:checked + .slider:before { | |||
-webkit-transform: translateX(55px); | |||
-ms-transform: translateX(55px); | |||
transform: translateX(55px); | |||
} | |||
.slider.round { | |||
border-radius: 34px; | |||
} | |||
.slider.round:before { | |||
border-radius: 50%; | |||
} | |||
@@ -0,0 +1,47 @@ | |||
.switch { | |||
position: relative; | |||
display: inline-block; | |||
width: 115px; | |||
height: 60px | |||
} | |||
.switch input { | |||
display: none; | |||
} | |||
.slider { | |||
position: absolute; | |||
cursor: pointer; | |||
top: 0; | |||
left: 0; | |||
right: 0; | |||
bottom: 0; | |||
background-color: #ccc; | |||
-webkit-transition: .4s; | |||
transition: .4s; | |||
} | |||
.slider:before { | |||
position: absolute; | |||
content: ""; | |||
height: 50px; | |||
width: 50px; | |||
left: 5px; | |||
bottom: 5px; | |||
background-color: white; | |||
-webkit-transition: .4s; | |||
transition: .4s; | |||
} | |||
input:focus + .slider { | |||
box-shadow: 0 0 1px #2196F3; | |||
} | |||
.slider.round { | |||
border-radius: 34px; | |||
} | |||
.slider.round:before { | |||
border-radius: 50%; | |||
} | |||
@@ -0,0 +1,103 @@ | |||
#addnew-form input { | |||
font-size: 14px; | |||
margin-top: 10px; | |||
padding-left: 16px; | |||
} | |||
fieldset { | |||
margin: 0; | |||
/*padding: 2rem;*/ | |||
box-sizing: border-box; | |||
display: block; | |||
border: none; | |||
/*border: solid 1px #CCC;*/ | |||
min-width: 0; | |||
background-color: #FFF; | |||
} | |||
fieldset legend { | |||
margin: 0 0 1.5rem; | |||
padding: 0; | |||
width: 100%; | |||
float: left; | |||
display: table; | |||
font-size: 1.5rem; | |||
line-height: 140%; | |||
font-weight: 600; | |||
color: #333; | |||
} | |||
fieldset legend + * { | |||
clear: both; | |||
} | |||
.toggle { | |||
margin: 0 0 1.5rem; | |||
box-sizing: border-box; | |||
font-size: 0; | |||
display: flex; | |||
flex-flow: row nowrap; | |||
justify-content: flex-start; | |||
align-items: stretch; | |||
} | |||
.toggle input { | |||
width: 0; | |||
height: 0; | |||
position: absolute; | |||
left: -9999px; | |||
} | |||
.toggle input + label { | |||
margin: 0; | |||
padding: .75rem 2rem; | |||
box-sizing: border-box; | |||
position: relative; | |||
display: inline-block; | |||
border: solid 1px #DDD; | |||
background-color: #FFF; | |||
font-size: 1rem; | |||
line-height: 140%; | |||
font-weight: 600; | |||
text-align: center; | |||
box-shadow: 0 0 0 rgba(255, 255, 255, 0); | |||
transition: border-color .15s ease-out, color .25s ease-out, background-color .15s ease-out, box-shadow .15s ease-out; | |||
} | |||
.toggle input + label:first-of-type { | |||
border-radius: 6px 0 0 6px; | |||
border-right: none; | |||
} | |||
.toggle input + label:last-of-type { | |||
border-radius: 0 6px 6px 0; | |||
border-left: none; | |||
} | |||
.toggle input:hover + label { | |||
border-color: #213140; | |||
} | |||
.toggle input:checked + label { | |||
background-color: #4B9DEA; | |||
color: #FFF; | |||
box-shadow: 0 0 10px rgba(102, 179, 251, 0.5); | |||
border-color: #4B9DEA; | |||
z-index: 1; | |||
} | |||
.toggle input:focus + label { | |||
outline: dotted 1px #CCC; | |||
outline-offset: .45rem; | |||
} | |||
@media (max-width: 800px) { | |||
.toggle input + label { | |||
padding: .75rem .25rem; | |||
flex: 0 0 50%; | |||
display: flex; | |||
justify-content: center; | |||
align-items: center; | |||
} | |||
} | |||
@@ -0,0 +1,25 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<!-- Generator: Adobe Illustrator 16.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) --> | |||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> | |||
<svg version="1.1" id="图层_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" | |||
width="110px" height="25px" viewBox="0 0 110 25" enable-background="new 0 0 130 25" xml:space="preserve"> | |||
<title>logo</title> | |||
<g id="控件"> | |||
<g id="Nav_x2F_web" transform="translate(-80.000000, -20.000000)"> | |||
<g id="Nav"> | |||
<path id="logo" d="M93.237,22.276v8.295h-8.166v-8.295H81.4v20.465h3.671v-8.524h8.166v8.524h3.671V22.276H93.237z | |||
M178.19,25.922h4.087c1.677,0,3.035,1.349,3.035,3.013c0,1.665-1.358,3.014-3.035,3.014h-4.087V25.922z M174.521,22.276v20.465 | |||
h3.67v-9.107l7.641,9.107h4.77l-6.263-7.46c3.144-1,5.088-4.12,4.585-7.359c-0.503-3.239-3.304-5.634-6.604-5.646h-7.805H174.521 | |||
z M139.803,22.215v12.77l-8.911-12.77h-2.932v20.463h3.672V29.85l8.955,12.829h2.882V22.215H139.803z M105.533,32.495 | |||
c0.002-3.785,3.093-6.852,6.904-6.851c3.812,0.002,6.9,3.071,6.899,6.856s-3.09,6.853-6.902,6.853 | |||
c-1.831,0-3.586-0.722-4.88-2.007s-2.021-3.029-2.021-4.847V32.495z M101.862,32.499c0,4.248,2.575,8.076,6.526,9.702 | |||
c3.951,1.625,8.498,0.728,11.522-2.275c3.024-3.003,3.929-7.519,2.292-11.443c-1.636-3.924-5.492-6.482-9.768-6.482 | |||
c-5.836,0.001-10.567,4.698-10.57,10.495L101.862,32.499z M152.096,32.495c0.002-3.785,3.093-6.853,6.905-6.851 | |||
c3.812,0.002,6.899,3.072,6.897,6.857c-0.001,3.785-3.092,6.853-6.904,6.851c-1.83,0-3.585-0.722-4.88-2.007 | |||
s-2.021-3.029-2.021-4.847L152.096,32.495z M148.422,32.499c-0.001,4.248,2.575,8.076,6.525,9.702 | |||
c3.951,1.625,8.499,0.728,11.522-2.275s3.93-7.519,2.292-11.443c-1.636-3.924-5.491-6.482-9.768-6.482 | |||
c-5.836,0.001-10.568,4.698-10.571,10.495L148.422,32.499z"/> | |||
</g> | |||
</g> | |||
</g> | |||
</svg> |
@@ -0,0 +1,230 @@ | |||
/** | |||
* DES 加密算法 | |||
* | |||
* 该函数接受一个 8 字节字符串作为普通 DES 算法的密钥(也就是 64 位,但是算法只使用 56 位),或者接受一个 24 字节字符串作为 3DES | |||
* 算法的密钥;第二个参数是要加密或解密的信息字符串;第三个布尔值参数用来说明信息是加密还是解密;接下来的可选参数 mode 如果是 0 表示 ECB | |||
* 模式,1 表示 CBC 模式,默认是 ECB 模式;最后一个可选项是一个 8 字节的输入向量字符串(在 ECB 模式下不使用)。返回的密文是字符串。 | |||
* | |||
* 参数: <br> | |||
* key: 8字节字符串作为普通 DES 算法的密钥,或 24 字节字符串作为 3DES <br> | |||
* message: 加密或解密的信息字符串<br> | |||
* encrypt: 布尔值参数用来说明信息是加密还是解密<br> | |||
* mode: 1:CBC模式,0:ECB模式(默认)<br> | |||
* iv:<br> | |||
* padding: 可选项, 8字节的输入向量字符串(在 ECB 模式下不使用) | |||
*/ | |||
//this takes the key, the message, and whether to encrypt or decrypt | |||
function des (key, message, encrypt, mode, iv, padding) { | |||
if(encrypt) //如果是加密的话,首先转换编码 | |||
message = unescape(encodeURIComponent(message)); | |||
//declaring this locally speeds things up a bit | |||
var spfunction1 = new Array (0x1010400,0,0x10000,0x1010404,0x1010004,0x10404,0x4,0x10000,0x400,0x1010400,0x1010404,0x400,0x1000404,0x1010004,0x1000000,0x4,0x404,0x1000400,0x1000400,0x10400,0x10400,0x1010000,0x1010000,0x1000404,0x10004,0x1000004,0x1000004,0x10004,0,0x404,0x10404,0x1000000,0x10000,0x1010404,0x4,0x1010000,0x1010400,0x1000000,0x1000000,0x400,0x1010004,0x10000,0x10400,0x1000004,0x400,0x4,0x1000404,0x10404,0x1010404,0x10004,0x1010000,0x1000404,0x1000004,0x404,0x10404,0x1010400,0x404,0x1000400,0x1000400,0,0x10004,0x10400,0,0x1010004); | |||
var spfunction2 = new Array (-0x7fef7fe0,-0x7fff8000,0x8000,0x108020,0x100000,0x20,-0x7fefffe0,-0x7fff7fe0,-0x7fffffe0,-0x7fef7fe0,-0x7fef8000,-0x80000000,-0x7fff8000,0x100000,0x20,-0x7fefffe0,0x108000,0x100020,-0x7fff7fe0,0,-0x80000000,0x8000,0x108020,-0x7ff00000,0x100020,-0x7fffffe0,0,0x108000,0x8020,-0x7fef8000,-0x7ff00000,0x8020,0,0x108020,-0x7fefffe0,0x100000,-0x7fff7fe0,-0x7ff00000,-0x7fef8000,0x8000,-0x7ff00000,-0x7fff8000,0x20,-0x7fef7fe0,0x108020,0x20,0x8000,-0x80000000,0x8020,-0x7fef8000,0x100000,-0x7fffffe0,0x100020,-0x7fff7fe0,-0x7fffffe0,0x100020,0x108000,0,-0x7fff8000,0x8020,-0x80000000,-0x7fefffe0,-0x7fef7fe0,0x108000); | |||
var spfunction3 = new Array (0x208,0x8020200,0,0x8020008,0x8000200,0,0x20208,0x8000200,0x20008,0x8000008,0x8000008,0x20000,0x8020208,0x20008,0x8020000,0x208,0x8000000,0x8,0x8020200,0x200,0x20200,0x8020000,0x8020008,0x20208,0x8000208,0x20200,0x20000,0x8000208,0x8,0x8020208,0x200,0x8000000,0x8020200,0x8000000,0x20008,0x208,0x20000,0x8020200,0x8000200,0,0x200,0x20008,0x8020208,0x8000200,0x8000008,0x200,0,0x8020008,0x8000208,0x20000,0x8000000,0x8020208,0x8,0x20208,0x20200,0x8000008,0x8020000,0x8000208,0x208,0x8020000,0x20208,0x8,0x8020008,0x20200); | |||
var spfunction4 = new Array (0x802001,0x2081,0x2081,0x80,0x802080,0x800081,0x800001,0x2001,0,0x802000,0x802000,0x802081,0x81,0,0x800080,0x800001,0x1,0x2000,0x800000,0x802001,0x80,0x800000,0x2001,0x2080,0x800081,0x1,0x2080,0x800080,0x2000,0x802080,0x802081,0x81,0x800080,0x800001,0x802000,0x802081,0x81,0,0,0x802000,0x2080,0x800080,0x800081,0x1,0x802001,0x2081,0x2081,0x80,0x802081,0x81,0x1,0x2000,0x800001,0x2001,0x802080,0x800081,0x2001,0x2080,0x800000,0x802001,0x80,0x800000,0x2000,0x802080); | |||
var spfunction5 = new Array (0x100,0x2080100,0x2080000,0x42000100,0x80000,0x100,0x40000000,0x2080000,0x40080100,0x80000,0x2000100,0x40080100,0x42000100,0x42080000,0x80100,0x40000000,0x2000000,0x40080000,0x40080000,0,0x40000100,0x42080100,0x42080100,0x2000100,0x42080000,0x40000100,0,0x42000000,0x2080100,0x2000000,0x42000000,0x80100,0x80000,0x42000100,0x100,0x2000000,0x40000000,0x2080000,0x42000100,0x40080100,0x2000100,0x40000000,0x42080000,0x2080100,0x40080100,0x100,0x2000000,0x42080000,0x42080100,0x80100,0x42000000,0x42080100,0x2080000,0,0x40080000,0x42000000,0x80100,0x2000100,0x40000100,0x80000,0,0x40080000,0x2080100,0x40000100); | |||
var spfunction6 = new Array (0x20000010,0x20400000,0x4000,0x20404010,0x20400000,0x10,0x20404010,0x400000,0x20004000,0x404010,0x400000,0x20000010,0x400010,0x20004000,0x20000000,0x4010,0,0x400010,0x20004010,0x4000,0x404000,0x20004010,0x10,0x20400010,0x20400010,0,0x404010,0x20404000,0x4010,0x404000,0x20404000,0x20000000,0x20004000,0x10,0x20400010,0x404000,0x20404010,0x400000,0x4010,0x20000010,0x400000,0x20004000,0x20000000,0x4010,0x20000010,0x20404010,0x404000,0x20400000,0x404010,0x20404000,0,0x20400010,0x10,0x4000,0x20400000,0x404010,0x4000,0x400010,0x20004010,0,0x20404000,0x20000000,0x400010,0x20004010); | |||
var spfunction7 = new Array (0x200000,0x4200002,0x4000802,0,0x800,0x4000802,0x200802,0x4200800,0x4200802,0x200000,0,0x4000002,0x2,0x4000000,0x4200002,0x802,0x4000800,0x200802,0x200002,0x4000800,0x4000002,0x4200000,0x4200800,0x200002,0x4200000,0x800,0x802,0x4200802,0x200800,0x2,0x4000000,0x200800,0x4000000,0x200800,0x200000,0x4000802,0x4000802,0x4200002,0x4200002,0x2,0x200002,0x4000000,0x4000800,0x200000,0x4200800,0x802,0x200802,0x4200800,0x802,0x4000002,0x4200802,0x4200000,0x200800,0,0x2,0x4200802,0,0x200802,0x4200000,0x800,0x4000002,0x4000800,0x800,0x200002); | |||
var spfunction8 = new Array (0x10001040,0x1000,0x40000,0x10041040,0x10000000,0x10001040,0x40,0x10000000,0x40040,0x10040000,0x10041040,0x41000,0x10041000,0x41040,0x1000,0x40,0x10040000,0x10000040,0x10001000,0x1040,0x41000,0x40040,0x10040040,0x10041000,0x1040,0,0,0x10040040,0x10000040,0x10001000,0x41040,0x40000,0x41040,0x40000,0x10041000,0x1000,0x40,0x10040040,0x1000,0x41040,0x10001000,0x40,0x10000040,0x10040000,0x10040040,0x10000000,0x40000,0x10001040,0,0x10041040,0x40040,0x10000040,0x10040000,0x10001000,0x10001040,0,0x10041040,0x41000,0x41000,0x1040,0x1040,0x40040,0x10000000,0x10041000); | |||
//create the 16 or 48 subkeys we will need | |||
var keys = des_createKeys (key); | |||
var m=0, i, j, temp, temp2, right1, right2, left, right, looping; | |||
var cbcleft, cbcleft2, cbcright, cbcright2 | |||
var endloop, loopinc; | |||
var len = message.length; | |||
var chunk = 0; | |||
//set up the loops for single and triple des | |||
var iterations = keys.length == 32 ? 3 : 9; //single or triple des | |||
if (iterations == 3) {looping = encrypt ? new Array (0, 32, 2) : new Array (30, -2, -2);} | |||
else {looping = encrypt ? new Array (0, 32, 2, 62, 30, -2, 64, 96, 2) : new Array (94, 62, -2, 32, 64, 2, 30, -2, -2);} | |||
//pad the message depending on the padding parameter | |||
if (padding == 2) message += " "; //pad the message with spaces | |||
else if (padding == 1) { | |||
if(encrypt) { | |||
temp = 8-(len%8); | |||
message += String.fromCharCode(temp,temp,temp,temp,temp,temp,temp,temp); | |||
if (temp===8) len+=8; | |||
} | |||
} //PKCS7 padding | |||
else if (!padding) message += "\0\0\0\0\0\0\0\0"; //pad the message out with null bytes | |||
//store the result here | |||
var result = ""; | |||
var tempresult = ""; | |||
if (mode == 1) { //CBC mode | |||
cbcleft = (iv.charCodeAt(m++) << 24) | (iv.charCodeAt(m++) << 16) | (iv.charCodeAt(m++) << 8) | iv.charCodeAt(m++); | |||
cbcright = (iv.charCodeAt(m++) << 24) | (iv.charCodeAt(m++) << 16) | (iv.charCodeAt(m++) << 8) | iv.charCodeAt(m++); | |||
m=0; | |||
} | |||
//loop through each 64 bit chunk of the message | |||
while (m < len) { | |||
left = (message.charCodeAt(m++) << 24) | (message.charCodeAt(m++) << 16) | (message.charCodeAt(m++) << 8) | message.charCodeAt(m++); | |||
right = (message.charCodeAt(m++) << 24) | (message.charCodeAt(m++) << 16) | (message.charCodeAt(m++) << 8) | message.charCodeAt(m++); | |||
//for Cipher Block Chaining mode, xor the message with the previous result | |||
if (mode == 1) {if (encrypt) {left ^= cbcleft; right ^= cbcright;} else {cbcleft2 = cbcleft; cbcright2 = cbcright; cbcleft = left; cbcright = right;}} | |||
//first each 64 but chunk of the message must be permuted according to IP | |||
temp = ((left >>> 4) ^ right) & 0x0f0f0f0f; right ^= temp; left ^= (temp << 4); | |||
temp = ((left >>> 16) ^ right) & 0x0000ffff; right ^= temp; left ^= (temp << 16); | |||
temp = ((right >>> 2) ^ left) & 0x33333333; left ^= temp; right ^= (temp << 2); | |||
temp = ((right >>> 8) ^ left) & 0x00ff00ff; left ^= temp; right ^= (temp << 8); | |||
temp = ((left >>> 1) ^ right) & 0x55555555; right ^= temp; left ^= (temp << 1); | |||
left = ((left << 1) | (left >>> 31)); | |||
right = ((right << 1) | (right >>> 31)); | |||
//do this either 1 or 3 times for each chunk of the message | |||
for (j=0; j<iterations; j+=3) { | |||
endloop = looping[j+1]; | |||
loopinc = looping[j+2]; | |||
//now go through and perform the encryption or decryption | |||
for (i=looping[j]; i!=endloop; i+=loopinc) { //for efficiency | |||
right1 = right ^ keys[i]; | |||
right2 = ((right >>> 4) | (right << 28)) ^ keys[i+1]; | |||
//the result is attained by passing these bytes through the S selection functions | |||
temp = left; | |||
left = right; | |||
right = temp ^ (spfunction2[(right1 >>> 24) & 0x3f] | spfunction4[(right1 >>> 16) & 0x3f] | |||
| spfunction6[(right1 >>> 8) & 0x3f] | spfunction8[right1 & 0x3f] | |||
| spfunction1[(right2 >>> 24) & 0x3f] | spfunction3[(right2 >>> 16) & 0x3f] | |||
| spfunction5[(right2 >>> 8) & 0x3f] | spfunction7[right2 & 0x3f]); | |||
} | |||
temp = left; left = right; right = temp; //unreverse left and right | |||
} //for either 1 or 3 iterations | |||
//move then each one bit to the right | |||
left = ((left >>> 1) | (left << 31)); | |||
right = ((right >>> 1) | (right << 31)); | |||
//now perform IP-1, which is IP in the opposite direction | |||
temp = ((left >>> 1) ^ right) & 0x55555555; right ^= temp; left ^= (temp << 1); | |||
temp = ((right >>> 8) ^ left) & 0x00ff00ff; left ^= temp; right ^= (temp << 8); | |||
temp = ((right >>> 2) ^ left) & 0x33333333; left ^= temp; right ^= (temp << 2); | |||
temp = ((left >>> 16) ^ right) & 0x0000ffff; right ^= temp; left ^= (temp << 16); | |||
temp = ((left >>> 4) ^ right) & 0x0f0f0f0f; right ^= temp; left ^= (temp << 4); | |||
//for Cipher Block Chaining mode, xor the message with the previous result | |||
if (mode == 1) {if (encrypt) {cbcleft = left; cbcright = right;} else {left ^= cbcleft2; right ^= cbcright2;}} | |||
tempresult += String.fromCharCode ((left>>>24), ((left>>>16) & 0xff), ((left>>>8) & 0xff), (left & 0xff), (right>>>24), ((right>>>16) & 0xff), ((right>>>8) & 0xff), (right & 0xff)); | |||
chunk += 8; | |||
if (chunk == 512) {result += tempresult; tempresult = ""; chunk = 0;} | |||
} //for every 8 characters, or 64 bits in the message | |||
//return the result as an array | |||
result += tempresult; | |||
result = result.replace(/\0*$/g, ""); | |||
if(!encrypt ) { //如果是解密的话,解密结束后对PKCS7 padding进行解码,并转换成utf-8编码 | |||
if(padding === 1) { //PKCS7 padding解码 | |||
var len = result.length, paddingChars = 0; | |||
len && (paddingChars = result.charCodeAt(len-1)); | |||
(paddingChars <= 8) && (result = result.substring(0, len - paddingChars)); | |||
} | |||
//转换成UTF-8编码 | |||
result = decodeURIComponent(escape(result)); | |||
} | |||
return result; | |||
} //end of des | |||
//des_createKeys | |||
//this takes as input a 64 bit key (even though only 56 bits are used) | |||
//as an array of 2 integers, and returns 16 48 bit keys | |||
function des_createKeys (key) { | |||
//declaring this locally speeds things up a bit | |||
var pc2bytes0 = new Array (0,0x4,0x20000000,0x20000004,0x10000,0x10004,0x20010000,0x20010004,0x200,0x204,0x20000200,0x20000204,0x10200,0x10204,0x20010200,0x20010204); | |||
var pc2bytes1 = new Array (0,0x1,0x100000,0x100001,0x4000000,0x4000001,0x4100000,0x4100001,0x100,0x101,0x100100,0x100101,0x4000100,0x4000101,0x4100100,0x4100101); | |||
var pc2bytes2 = new Array (0,0x8,0x800,0x808,0x1000000,0x1000008,0x1000800,0x1000808,0,0x8,0x800,0x808,0x1000000,0x1000008,0x1000800,0x1000808); | |||
var pc2bytes3 = new Array (0,0x200000,0x8000000,0x8200000,0x2000,0x202000,0x8002000,0x8202000,0x20000,0x220000,0x8020000,0x8220000,0x22000,0x222000,0x8022000,0x8222000); | |||
var pc2bytes4 = new Array (0,0x40000,0x10,0x40010,0,0x40000,0x10,0x40010,0x1000,0x41000,0x1010,0x41010,0x1000,0x41000,0x1010,0x41010); | |||
var pc2bytes5 = new Array (0,0x400,0x20,0x420,0,0x400,0x20,0x420,0x2000000,0x2000400,0x2000020,0x2000420,0x2000000,0x2000400,0x2000020,0x2000420); | |||
var pc2bytes6 = new Array (0,0x10000000,0x80000,0x10080000,0x2,0x10000002,0x80002,0x10080002,0,0x10000000,0x80000,0x10080000,0x2,0x10000002,0x80002,0x10080002); | |||
var pc2bytes7 = new Array (0,0x10000,0x800,0x10800,0x20000000,0x20010000,0x20000800,0x20010800,0x20000,0x30000,0x20800,0x30800,0x20020000,0x20030000,0x20020800,0x20030800); | |||
var pc2bytes8 = new Array (0,0x40000,0,0x40000,0x2,0x40002,0x2,0x40002,0x2000000,0x2040000,0x2000000,0x2040000,0x2000002,0x2040002,0x2000002,0x2040002); | |||
var pc2bytes9 = new Array (0,0x10000000,0x8,0x10000008,0,0x10000000,0x8,0x10000008,0x400,0x10000400,0x408,0x10000408,0x400,0x10000400,0x408,0x10000408); | |||
var pc2bytes10 = new Array (0,0x20,0,0x20,0x100000,0x100020,0x100000,0x100020,0x2000,0x2020,0x2000,0x2020,0x102000,0x102020,0x102000,0x102020); | |||
var pc2bytes11 = new Array (0,0x1000000,0x200,0x1000200,0x200000,0x1200000,0x200200,0x1200200,0x4000000,0x5000000,0x4000200,0x5000200,0x4200000,0x5200000,0x4200200,0x5200200); | |||
var pc2bytes12 = new Array (0,0x1000,0x8000000,0x8001000,0x80000,0x81000,0x8080000,0x8081000,0x10,0x1010,0x8000010,0x8001010,0x80010,0x81010,0x8080010,0x8081010); | |||
var pc2bytes13 = new Array (0,0x4,0x100,0x104,0,0x4,0x100,0x104,0x1,0x5,0x101,0x105,0x1,0x5,0x101,0x105); | |||
//how many iterations (1 for des, 3 for triple des) | |||
var iterations = key.length > 8 ? 3 : 1; //changed by Paul 16/6/2007 to use Triple DES for 9+ byte keys | |||
//stores the return keys | |||
var keys = new Array (32 * iterations); | |||
//now define the left shifts which need to be done | |||
var shifts = new Array (0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0); | |||
//other variables | |||
var lefttemp, righttemp, m=0, n=0, temp; | |||
for (var j=0; j<iterations; j++) { //either 1 or 3 iterations | |||
var left = (key.charCodeAt(m++) << 24) | (key.charCodeAt(m++) << 16) | (key.charCodeAt(m++) << 8) | key.charCodeAt(m++); | |||
var right = (key.charCodeAt(m++) << 24) | (key.charCodeAt(m++) << 16) | (key.charCodeAt(m++) << 8) | key.charCodeAt(m++); | |||
temp = ((left >>> 4) ^ right) & 0x0f0f0f0f; right ^= temp; left ^= (temp << 4); | |||
temp = ((right >>> -16) ^ left) & 0x0000ffff; left ^= temp; right ^= (temp << -16); | |||
temp = ((left >>> 2) ^ right) & 0x33333333; right ^= temp; left ^= (temp << 2); | |||
temp = ((right >>> -16) ^ left) & 0x0000ffff; left ^= temp; right ^= (temp << -16); | |||
temp = ((left >>> 1) ^ right) & 0x55555555; right ^= temp; left ^= (temp << 1); | |||
temp = ((right >>> 8) ^ left) & 0x00ff00ff; left ^= temp; right ^= (temp << 8); | |||
temp = ((left >>> 1) ^ right) & 0x55555555; right ^= temp; left ^= (temp << 1); | |||
//the right side needs to be shifted and to get the last four bits of the left side | |||
temp = (left << 8) | ((right >>> 20) & 0x000000f0); | |||
//left needs to be put upside down | |||
left = (right << 24) | ((right << 8) & 0xff0000) | ((right >>> 8) & 0xff00) | ((right >>> 24) & 0xf0); | |||
right = temp; | |||
//now go through and perform these shifts on the left and right keys | |||
for (var i=0; i < shifts.length; i++) { | |||
//shift the keys either one or two bits to the left | |||
if (shifts[i]) {left = (left << 2) | (left >>> 26); right = (right << 2) | (right >>> 26);} | |||
else {left = (left << 1) | (left >>> 27); right = (right << 1) | (right >>> 27);} | |||
left &= -0xf; right &= -0xf; | |||
//now apply PC-2, in such a way that E is easier when encrypting or decrypting | |||
//this conversion will look like PC-2 except only the last 6 bits of each byte are used | |||
//rather than 48 consecutive bits and the order of lines will be according to | |||
//how the S selection functions will be applied: S2, S4, S6, S8, S1, S3, S5, S7 | |||
lefttemp = pc2bytes0[left >>> 28] | pc2bytes1[(left >>> 24) & 0xf] | |||
| pc2bytes2[(left >>> 20) & 0xf] | pc2bytes3[(left >>> 16) & 0xf] | |||
| pc2bytes4[(left >>> 12) & 0xf] | pc2bytes5[(left >>> 8) & 0xf] | |||
| pc2bytes6[(left >>> 4) & 0xf]; | |||
righttemp = pc2bytes7[right >>> 28] | pc2bytes8[(right >>> 24) & 0xf] | |||
| pc2bytes9[(right >>> 20) & 0xf] | pc2bytes10[(right >>> 16) & 0xf] | |||
| pc2bytes11[(right >>> 12) & 0xf] | pc2bytes12[(right >>> 8) & 0xf] | |||
| pc2bytes13[(right >>> 4) & 0xf]; | |||
temp = ((righttemp >>> 16) ^ lefttemp) & 0x0000ffff; | |||
keys[n++] = lefttemp ^ temp; keys[n++] = righttemp ^ (temp << 16); | |||
} | |||
} //for each iterations | |||
//return the keys we've created | |||
return keys; | |||
} //end of des_createKeys | |||
function genkey(key, start, end) { | |||
//8 byte / 64 bit Key (DES) or 192 bit Key | |||
return {key:pad(key.slice(start, end)),vector: 1}; | |||
} | |||
function pad(key) { | |||
for (var i = key.length; i<24; i++) { | |||
key+="0"; | |||
} | |||
return key; | |||
} | |||
var des3iv = 'qXSdHWfbSZaaLeHBRhLg'; | |||
var DES3 = { | |||
//3DES加密,CBC/PKCS5Padding | |||
encrypt:function(key,input){ | |||
var genKey = genkey(key, 0, 24); | |||
console.log(genKey); | |||
return btoa(des(genKey.key, input, 1, 1, des3iv, 1)); | |||
}, | |||
////3DES解密,CBC/PKCS5Padding | |||
decrypt:function(key,input){ | |||
var genKey = genkey(key, 0, 24); | |||
return des(genKey.key, atob(input), 0, 1, des3iv, 1); | |||
} | |||
}; | |||
function encryptByDES(message, key){ | |||
let keyHex = CryptoJS.enc.Utf8.parse(key); | |||
let encrypted = CryptoJS.DES.encrypt(message, keyHex, { | |||
mode: CryptoJS.mode.ECB, | |||
padding: CryptoJS.pad.Pkcs7 | |||
}); | |||
return encrypted.ciphertext.toString(); | |||
} | |||
// JS DES ECB模式 解密 | |||
function decryptByDES(ciphertext, key){ | |||
let keyHex = CryptoJS.enc.Utf8.parse(key); | |||
let decrypted = CryptoJS.DES.decrypt({ | |||
ciphertext: CryptoJS.enc.Hex.parse(ciphertext) | |||
}, keyHex, { | |||
mode: CryptoJS.mode.ECB, | |||
padding: CryptoJS.pad.Pkcs7 | |||
}); | |||
let result_value = decrypted.toString(CryptoJS.enc.Utf8); | |||
return result_value; | |||
} |
@@ -0,0 +1,10 @@ | |||
(function() { | |||
$("#ck-status").change(function () { | |||
console.log("983473874"); | |||
if ($(this).attr("checked") == "checked") { | |||
alert(111); | |||
} else { | |||
alert(11122); | |||
} | |||
}); | |||
}) |
@@ -0,0 +1,43 @@ | |||
(function() { | |||
"use strict"; // Start of use strict | |||
var mainNav = document.querySelector('#mainNav'); | |||
if (mainNav) { | |||
var navbarCollapse = mainNav.querySelector('.navbar-collapse'); | |||
if (navbarCollapse) { | |||
var collapse = new bootstrap.Collapse(navbarCollapse, { | |||
toggle: false | |||
}); | |||
var navbarItems = navbarCollapse.querySelectorAll('a'); | |||
// Closes responsive menu when a scroll trigger link is clicked | |||
for (var item of navbarItems) { | |||
item.addEventListener('click', function (event) { | |||
collapse.hide(); | |||
}); | |||
} | |||
} | |||
// Collapse Navbar | |||
var collapseNavbar = function() { | |||
var scrollTop = (window.pageYOffset !== undefined) ? window.pageYOffset : (document.documentElement || document.body.parentNode || document.body).scrollTop; | |||
if (scrollTop > 100) { | |||
mainNav.classList.add("navbar-shrink"); | |||
} else { | |||
mainNav.classList.remove("navbar-shrink"); | |||
} | |||
}; | |||
// Collapse now if page is not at top | |||
collapseNavbar(); | |||
// Collapse the navbar when page is scrolled | |||
document.addEventListener("scroll", collapseNavbar); | |||
} | |||
})(); // End of use strict |
@@ -0,0 +1,206 @@ | |||
<!DOCTYPE html> | |||
<html class="text-start"> | |||
<head> | |||
<meta charset="utf-8"> | |||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0;"/> | |||
<title>首页</title> | |||
<link rel="stylesheet" href="assets/bootstrap/css/bootstrap.min.css"> | |||
<link rel="stylesheet" href="assets/fonts/font-awesome.min.css"> | |||
<link rel="stylesheet" href="assets/fonts/ionicons.min.css"> | |||
<link rel="stylesheet" href="assets/css/Login-Form-Dark.css"> | |||
<link rel="stylesheet" href="assets/css/Toggle-Switch-1.css"> | |||
<link rel="stylesheet" href="assets/css/Toggle-Switch.css"> | |||
<link rel="stylesheet" href="assets/css/Toggle-Switches.css"> | |||
<style type="text/css"> | |||
.close{ | |||
float: right; | |||
font-size: 21px; | |||
font-weight: 700; | |||
line-height: 1; | |||
color: #000; | |||
text-shadow: 0 1px 0 #fff; | |||
filter: alpha(opacity=20); | |||
opacity: .2; | |||
} | |||
.alert{ | |||
padding: 5px; | |||
/*margin-bottom: 20px;*/ | |||
border: 1px solid transparent; | |||
border-radius: 4px; | |||
width: 100%; | |||
height: fit-content; | |||
} | |||
a{ | |||
text-decoration: none; | |||
} | |||
</style> | |||
</head> | |||
<body id="page-top" data-bs-spy="scroll" data-bs-target="#mainNav" data-bs-offset="56"> | |||
<nav class="navbar navbar-light navbar-expand-lg fixed-top" id="mainNav"> | |||
<div class="container"><a class="navbar-brand" href="#page-top"><img src="assets/img/honor-logo-black.svg"></a><button data-bs-toggle="collapse" data-bs-target="#navbarResponsive" class="navbar-toggler float-end" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation"><i class="fa fa-bars"></i></button> | |||
<div class="collapse navbar-collapse" id="navbarResponsive"> | |||
<ul class="navbar-nav ms-auto"> | |||
<!-- <li class="nav-item"><a class="nav-link" href="/changePwd">修改密码</a></li> --> | |||
<li class="nav-item"><a class="nav-link logout" href="#">注销</a></li> | |||
</ul> | |||
</div> | |||
</div> | |||
</nav> | |||
<header class="masthead" style="background: url(assets/img/bg-pattern.png), linear-gradient(to left, #1B2C45, #41464b);height: 100%;padding-top: 70px;"> | |||
<div id="myAlert" class="alert alert-success" role="alert" style="display: none;margin-bottom: 5px;position: absolute;z-index: 999;"> | |||
<a href="#" class="close" data-dismiss="alert">×</a> | |||
<h6 class="alert-heading" style="margin: 0;">操作成功!</h6> | |||
</div> | |||
<div class="container h-100"> | |||
<div class="row h-100"> | |||
<div class="col"> | |||
<div class="card" style="color: black;"> | |||
<div class="card-header"> | |||
<h5 class="mb-0">远程操作</h5> | |||
</div> | |||
<!-- <div class="card-body" style="padding: 1rem 1rem 0rem 1rem;border-bottom: 1px solid #313b4840;"> | |||
<div> | |||
<label class="form-label" style="height: 50px;vertical-align: middle;font-size: 20px;">人行通道1</label><label class="switch"> | |||
<input class="ck-status" type="checkbox" id="ck-GATE1-status" devId="GATE1"> | |||
<span class="slider round"></span> | |||
</label> | |||
</div> | |||
</div> --> | |||
<div class="card-body" style="padding: 1rem 1rem 0rem 1rem;border-bottom: 1px solid #313b4840;"> | |||
<div> | |||
<label class="form-label" style="height: 50px;vertical-align: middle;font-size: 20px;">人行通道1</label><label class="switch"> | |||
<input class="ck-status" type="checkbox" id="ck-PSGATE01-status" devId="PSGATE01"> | |||
<span class="slider round"></span> | |||
</label> | |||
</div> | |||
</div> | |||
<div class="card-body" style="padding: 1rem 1rem 0rem 1rem;border-bottom: 1px solid #313b4840;"> | |||
<div> | |||
<label class="form-label" style="height: 75px;vertical-align: middle;font-size: 20px;">人行通道2</label><label class="switch"> | |||
<input class="ck-status" type="checkbox" id="ck-PSGATE02-status" devId="PSGATE02"> | |||
<span class="slider round"></span> | |||
</label> | |||
</div> | |||
</div> | |||
<div class="card-body" style="padding: 1rem 1rem 0rem 1rem;border-bottom: 1px solid #313b4840;"> | |||
<div> | |||
<label class="form-label" style="height: 75px;vertical-align: middle;font-size: 20px;">人行通道3</label><label class="switch"> | |||
<input class="ck-status" type="checkbox" id="ck-PSGATE03-status" devId="PSGATE03"> | |||
<span class="slider round"></span> | |||
</label> | |||
</div> | |||
</div> | |||
<div class="card-body" style="padding: 1rem 1rem 0rem 1rem;"> | |||
<div> | |||
<label class="form-label" style="height: 75px;vertical-align: middle;font-size: 20px;">货物通道1</label><label class="switch"> | |||
<input class="ck-status" type="checkbox" id="ck-PSGATE04-status" devId="PSGATE04"> | |||
<span class="slider round"></span> | |||
</label> | |||
</div> | |||
</div> | |||
</div> | |||
</div> | |||
</div> | |||
</div> | |||
</header> | |||
<div class="modal" id="loadingModal" backdrop="static" keyborad="false" style="display:none;background: black;opacity: 0.75;"> | |||
<img src="assets/img/loading2.gif" alt="" style="width: 100px;height: 100px;z-index: 2000;position: absolute;text-align: center;left: 50%;top:50%;margin-left: -50px;margin-top: -50px;" /> | |||
</div> | |||
<footer style="position: absolute;bottom: 0;width: 100%;"> | |||
<div class="container"> | |||
<p>© 内部使用 禁止外传</p> | |||
</div> | |||
</footer> | |||
<script src="assets/js/jquery-3.5.0.min.js"></script> | |||
<script src="assets/bootstrap/js/bootstrap.min.js"></script> | |||
<script src="assets/js/cust.js"></script> | |||
<script src="assets/js/new-age.js"></script> | |||
<script type="text/javascript"> | |||
$(function(){ | |||
$(".logout").on('click', function () { | |||
document.cookie=""; | |||
window.location.href = "/login"; | |||
}) | |||
var devs = ["PSGATE01","PSGATE02","PSGATE03","PSGATE04"]; | |||
devs.map(function(ss){ | |||
$.ajax({url:"/devList",data:{dev:ss}, method:"post",cache: false, | |||
contentType: "application/x-www-form-urlencoded",beforeSend:function(){ | |||
showLoading(); | |||
},success:function(data){ | |||
hideLoading(); | |||
if (data.Code == 200) { | |||
// $("#myAlert").css("display", "block"); | |||
$("#ck-"+ss+"-status").prop("checked",true); | |||
} else { | |||
// obj.prop("checked",!flag); | |||
$("#ck-"+ss+"-status").prop("checked",false); | |||
} | |||
},error:function(err){ | |||
}}) | |||
}) | |||
$(".ck-status").click(function(){ | |||
var flag = $(this).is(":checked"); | |||
var dev = $(this).attr("devId"); | |||
var obj = $(this); | |||
$.ajax({url:"/handleAct",data:{active:flag?0:1, dev:dev}, method:"post",cache: false, | |||
contentType: "application/x-www-form-urlencoded",beforeSend:function(){ | |||
showLoading(); | |||
},success:function(data){ | |||
hideLoading(); | |||
if (data.Code == 200 && (data.Msg == "" || data.Msg.indexOf("成功") > -1)) { | |||
$(".alert-heading").html("操作成功!"); | |||
$("#myAlert").css("display", "block"); | |||
$("#myAlert").removeClass("alert-warning").addClass("alert-success"); | |||
setTimeout(function(){ | |||
$("#myAlert").css("display", "none"); | |||
},2500) | |||
} else { | |||
if (data.Msg) { | |||
$(".alert-heading").html("操作失败,请稍候重试!<small>("+(data.Msg)+")</small>"); | |||
$("#myAlert").removeClass("alert-success").addClass("alert-warning"); | |||
$("#myAlert").css("display", "block"); | |||
obj.prop("checked",!flag); | |||
} else { | |||
window.location.href = "/login"; | |||
} | |||
} | |||
},error:function(err){ | |||
hideLoading(); | |||
$(".alert-heading").html("操作失败,请稍候重试!"); | |||
$("#myAlert").removeClass("alert-success").addClass("alert-warning"); | |||
$("#myAlert").css("display", "block"); | |||
obj.prop("checked",!flag); | |||
}}) | |||
}) | |||
function showLoading(){ | |||
$("#loadingModal").css("display", "block"); | |||
} | |||
function hideLoading(){ | |||
$("#loadingModal").css("display", "none"); | |||
} | |||
$(".close").click(function(){ | |||
$("#myAlert").css("display", "none"); | |||
}); | |||
}) | |||
</script> | |||
</body> | |||
</html> |
@@ -0,0 +1,153 @@ | |||
<!DOCTYPE html> | |||
<html> | |||
<head> | |||
<meta charset="utf-8"> | |||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0;"/> | |||
<title>登录</title> | |||
<link rel="stylesheet" href="assets/bootstrap/css/bootstrap.min.css"> | |||
<link rel="stylesheet" href="assets/fonts/font-awesome.min.css"> | |||
<link rel="stylesheet" href="assets/fonts/ionicons.min.css"> | |||
<link rel="stylesheet" href="assets/css/Login-Form-Dark.css"> | |||
<link rel="stylesheet" href="assets/css/Toggle-Switch-1.css"> | |||
<link rel="stylesheet" href="assets/css/Toggle-Switch.css"> | |||
<link rel="stylesheet" href="assets/css/Toggle-Switches.css"> | |||
<style type="text/css"> | |||
.close{ | |||
float: right; | |||
font-size: 21px; | |||
font-weight: 700; | |||
line-height: 1; | |||
color: #000; | |||
text-shadow: 0 1px 0 #fff; | |||
filter: alpha(opacity=20); | |||
opacity: .2; | |||
} | |||
.alert{ | |||
padding: 15px; | |||
margin-bottom: 20px; | |||
border: 1px solid transparent; | |||
border-radius: 4px; | |||
width: 100%; | |||
height: fit-content; | |||
} | |||
a{ | |||
text-decoration: none; | |||
} | |||
</style> | |||
</head> | |||
<body id="page-top" data-bs-spy="scroll" data-bs-target="#mainNav" data-bs-offset="56" style="/*height: 90%;*/display: initial;"> | |||
<section class="login-dark"> | |||
{{if .errMsg}} | |||
<div id="myAlert" class="alert alert-warning"> | |||
<a href="#" class="close" data-dismiss="alert">×</a> | |||
<strong>{{.errTag}}</strong><span style="display: block;padding: 10px 20px;">{{.errMsg}}</span> | |||
</div> | |||
{{else}} | |||
<div id="myAlert" class="alert alert-warning" style="display: none;"> | |||
<a href="#" class="close" data-dismiss="alert">×</a> | |||
<strong>登录失败</strong><span style="display: block;padding: 10px 20px;"></span> | |||
</div> | |||
{{end}} | |||
<form method="post" id="loginForm" action="/login" onsubmit="return ableCommit()"> | |||
<h2 class="visually-hidden">Login Form</h2> | |||
<div class="illustration"><i class="icon ion-ios-locked-outline"></i></div> | |||
{{if .userName}} | |||
<div class="mb-3"><input class="form-control" type="text" name="username" id="uname" placeholder="用户名" value="{{.userName}}" onfocus="hideErrDiv()"></div> | |||
{{else}} | |||
<div class="mb-3"><input class="form-control" type="text" name="username" id="uname" placeholder="用户名" onfocus="hideErrDiv()"></div> | |||
{{end}} | |||
<div class="mb-3"><input class="form-control" type="password" name="pwd" id="pwd" placeholder="密码" onblur="encodePwd()" onfocus="decodePwd()"></div> | |||
<div class="mb-3"><button class="btn btn-primary d-block w-100" type="submit" id="loginAct" >登录</button></div> | |||
</form> | |||
</section> | |||
<footer style="position: absolute;bottom: 0;width: 100%;"> | |||
<div class="container"> | |||
<p>© 内部使用 禁止外传</p> | |||
</div> | |||
</footer> | |||
<script src="assets/js/jquery-3.5.0.min.js"></script> | |||
<script src="assets/js/DES3.js"></script> | |||
<script src="assets/js/crypto-js.min.js"></script> | |||
<script src="assets/bootstrap/js/bootstrap.min.js"></script> | |||
<script src="assets/js/cust.js"></script> | |||
<script src="assets/js/new-age.js"></script> | |||
<script type="text/javascript"> | |||
var date = new Date(); | |||
var kk = ''+date.getFullYear()+(date.getMonth()>8?date.getMonth()+1:"0"+(date.getMonth()+1))+(date.getDate()>9?date.getDate():"0"+date.getDate()); | |||
var key = kk; | |||
function ableCommit(){ | |||
var uname = $("#uname").val(); | |||
var pwd = $("#pwd").val(); | |||
pwd = atob(pwd); | |||
pwd = decryptByDES(pwd, key); | |||
if (uname.trim() == "" || pwd.trim() == "") { | |||
$("#myAlert").children("span").html(" 用户名或密码不允许为空!"); | |||
$("#myAlert").css("display", "block"); | |||
return false; | |||
} else { | |||
console.log(22222); | |||
} | |||
} | |||
$(function(){ | |||
$("#loginAct").click(function(){ | |||
console.log(889998); | |||
}) | |||
$(".close").click(function(){ | |||
$("#myAlert").css("display", "none"); | |||
}); | |||
}) | |||
//alert(decrypt_3des); | |||
function encodePwd(){ | |||
let pwd = $("#pwd").val(); | |||
if (pwd.trim() != "") { | |||
var des3en = encryptByDES(pwd,key); | |||
des3en = des3en.toUpperCase(); | |||
var encode = encodeURI(des3en); | |||
// 对编码的字符串转化base64 | |||
var base64 = btoa(encode); | |||
$("#pwd").val(base64); | |||
} | |||
} | |||
function decodePwd(){ | |||
hideErrDiv(); | |||
let pwd = $("#pwd").val(); | |||
pwd = atob(pwd); | |||
var des3de = decryptByDES(pwd, key); | |||
$("#pwd").val(des3de); | |||
} | |||
function hideErrDiv(){ | |||
$("#myAlert").css("display", "none"); | |||
} | |||
</script> | |||
</body> | |||
</html> |
@@ -0,0 +1,153 @@ | |||
<!DOCTYPE html> | |||
<html> | |||
<head> | |||
<meta charset="utf-8"> | |||
<meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no"> | |||
<title>重置密码</title> | |||
<link rel="stylesheet" href="assets/bootstrap/css/bootstrap.min.css"> | |||
<link rel="stylesheet" href="assets/fonts/font-awesome.min.css"> | |||
<link rel="stylesheet" href="assets/fonts/ionicons.min.css"> | |||
<link rel="stylesheet" href="assets/css/Login-Form-Dark.css"> | |||
<link rel="stylesheet" href="assets/css/Toggle-Switch-1.css"> | |||
<link rel="stylesheet" href="assets/css/Toggle-Switch.css"> | |||
<link rel="stylesheet" href="assets/css/Toggle-Switches.css"> | |||
<style type="text/css"> | |||
.close{ | |||
float: right; | |||
font-size: 21px; | |||
font-weight: 700; | |||
line-height: 1; | |||
color: #000; | |||
text-shadow: 0 1px 0 #fff; | |||
filter: alpha(opacity=20); | |||
opacity: .2; | |||
} | |||
.alert{ | |||
padding: 15px; | |||
margin-bottom: 20px; | |||
border: 1px solid transparent; | |||
border-radius: 4px; | |||
width: 100%; | |||
height: fit-content; | |||
} | |||
a{ | |||
text-decoration: none; | |||
} | |||
</style> | |||
</head> | |||
<body id="page-top" data-bs-spy="scroll" data-bs-target="#mainNav" data-bs-offset="56" style="/*height: 90%;*/display: initial;"> | |||
<section class="login-dark"> | |||
{{if .errMsg}} | |||
<div id="myAlert" class="alert alert-warning"> | |||
<a href="#" class="close" data-dismiss="alert">×</a> | |||
<strong>{{.errTag}}</strong><span style="display: block;padding: 10px 20px;">{{.errMsg}}</span> | |||
</div> | |||
{{else}} | |||
<div id="myAlert" class="alert alert-warning" style="display: none;"> | |||
<a href="#" class="close" data-dismiss="alert">×</a> | |||
<strong>重置密码失败</strong><span style="display: block;padding: 10px 20px;"></span> | |||
</div> | |||
{{end}} | |||
<form method="post" action="/changePwd" id="loginForm" onsubmit="return ableCommit()"> | |||
<h2 class="visually-hidden">ChangePwd Form</h2> | |||
<div class="illustration"><i class="icon ion-ios-locked-outline"></i></div> | |||
<div class="mb-3"><input class="form-control" type="password" name="newpwd" id="newpwd" placeholder="新密码" onblur="encodePwd()" onfocus="decodePwd()"></div> | |||
<div class="mb-3"><input class="form-control" type="password" name="repeatnewpwd" id="repeatnewpwd" placeholder="重复新密码" onblur="encodePwd()" onfocus="decodePwd()"></div> | |||
<div class="mb-3"><button class="btn btn-primary d-block w-100" type="submit" id="loginAct" >确认</button></div> | |||
</form> | |||
</section> | |||
<footer style="position: absolute;bottom: 0;width: 100%;"> | |||
<div class="container"> | |||
<p>© 内部使用 禁止外传</p> | |||
</div> | |||
</footer> | |||
<script src="assets/js/jquery-3.5.0.min.js"></script> | |||
<script src="assets/js/DES3.js"></script> | |||
<script src="assets/js/crypto-js.min.js"></script> | |||
<script src="assets/bootstrap/js/bootstrap.min.js"></script> | |||
<script src="assets/js/cust.js"></script> | |||
<script src="assets/js/new-age.js"></script> | |||
<script type="text/javascript"> | |||
var date = new Date(); | |||
var kk = ''+date.getFullYear()+(date.getMonth()>8?date.getMonth()+1:"0"+date.getMonth()+1)+(date.getDate()>9?date.getDate():"0"+date.getDate()); | |||
var key = kk; | |||
function ableCommit(){ | |||
var uname = $("#uname").val(); | |||
var oldpwd = $("#oldpwd").val(); | |||
var newpwd = $("#newpwd").val(); | |||
console.log("1,pwd==="+pwd); | |||
pwd = atob(pwd); | |||
pwd = decryptByDES(pwd, key); | |||
console.log("2,pwd==="+pwd); | |||
if (uname.trim() == "" || oldpwd.trim() == "" || newpwd.trim() == "") { | |||
$("#myAlert").children("span").html(" 用户名或密码不允许为空!"); | |||
$("#myAlert").css("display", "block"); | |||
return false; | |||
} else { | |||
} | |||
} | |||
$(function(){ | |||
console.log(888); | |||
$("#loginAct").click(function(){ | |||
console.log(889998); | |||
}) | |||
$(".close").click(function(){ | |||
$("#myAlert").css("display", "none"); | |||
}); | |||
}) | |||
//alert(decrypt_3des); | |||
function encodePwd(){ | |||
let pwd = $("#pwd").val(); | |||
console.log(pwd); | |||
if (pwd.trim() != "") { | |||
var des3en = encryptByDES(pwd,key); | |||
console.log(des3en); | |||
des3en = des3en.toUpperCase(); | |||
var encode = encodeURI(des3en); | |||
console.log(encode); | |||
// 对编码的字符串转化base64 | |||
var base64 = btoa(encode); | |||
console.log(base64); | |||
console.log(atob(base64)); | |||
$("#pwd").val(base64); | |||
} | |||
} | |||
function decodePwd(){ | |||
hideErrDiv(); | |||
let pwd = $("#pwd").val(); | |||
pwd = atob(pwd); | |||
var des3de = decryptByDES(pwd, key); | |||
console.log(des3de); | |||
$("#pwd").val(des3de); | |||
} | |||
function hideErrDiv(){ | |||
$("#myAlert").css("display", "none"); | |||
} | |||
</script> | |||
</body> | |||
</html> |
@@ -0,0 +1,10 @@ | |||
[ | |||
{ | |||
"name": "admin1", | |||
"pwd": "honor@2022" | |||
}, | |||
{ | |||
"name": "admin2", | |||
"pwd": "honor@2022" | |||
} | |||
] |
@@ -0,0 +1,25 @@ | |||
package utils | |||
// Str string类型的条件表达式函数 | |||
func Str(expr bool, a, b string) string { | |||
if expr { | |||
return a | |||
} | |||
return b | |||
} | |||
// Int int类型的条件表达式函数 | |||
func Int(expr bool, a, b int) int { | |||
if expr { | |||
return a | |||
} | |||
return b | |||
} | |||
// Float64 float64类型的条件表达式函数 | |||
func Float64(expr bool, a, b float64) float64 { | |||
if expr { | |||
return a | |||
} | |||
return b | |||
} |
@@ -0,0 +1,153 @@ | |||
package utils | |||
import ( | |||
"fmt" | |||
"io/ioutil" | |||
"encoding/json" | |||
"time" | |||
"rh1/lib" | |||
) | |||
type Userdata struct { | |||
Name string `json:"name"` | |||
Pwd string `json:"pwd"` | |||
} | |||
type Config struct{ | |||
SrvUrl string `json:"remoteSrv"` | |||
Door string `json:"door"` | |||
Port int `json:"port"` | |||
} | |||
func GetConfigs() string { | |||
b, err := ioutil.ReadFile("./user.json") // just pass the file name | |||
if err != nil { | |||
fmt.Print(err) | |||
} | |||
str := string(b) // convert content to a 'string' | |||
fmt.Println(str) // print the content as a 'string' | |||
return str | |||
} | |||
func DeserializeJson(configJson string) []Userdata { | |||
jsonStr := configJson | |||
jsonAsBytes := []byte(jsonStr) | |||
configs := make([]Userdata, 0) | |||
if len(jsonAsBytes) == 0{ | |||
return nil | |||
} | |||
err := json.Unmarshal(jsonAsBytes, &configs) | |||
fmt.Printf("%#v", configs) | |||
if err != nil { | |||
panic(err) | |||
} | |||
return configs | |||
} | |||
func GetConfigs2() string { | |||
b, err := ioutil.ReadFile("./config.json") // just pass the file name | |||
if err != nil { | |||
fmt.Print(err) | |||
} | |||
str := string(b) // convert content to a 'string' | |||
fmt.Println(str) // print the content as a 'string' | |||
return str | |||
} | |||
func DeserializeJson2() Config { | |||
jsonStr := GetConfigs2(); | |||
jsonAsBytes := []byte(jsonStr) | |||
var configs Config; | |||
err := json.Unmarshal(jsonAsBytes, &configs) | |||
fmt.Printf("%#v", configs) | |||
if err != nil { | |||
panic(err) | |||
} | |||
return configs | |||
} | |||
func IsAbleUserData(name string, pwd string) bool{ | |||
jsonConfigList := GetConfigs() | |||
now := time.Now() | |||
kk := now.Format("20060102")//时间格式 | |||
originPwd := aes.DecryptDES_ECB(pwd, kk) | |||
originPwd = string(originPwd);//原密码 | |||
unmarshelledConfigs := DeserializeJson(jsonConfigList) | |||
for _, configObj := range unmarshelledConfigs { | |||
if (configObj.Name == name && configObj.Pwd == originPwd){ | |||
return true; | |||
} | |||
fmt.Printf("Name: %s Pwd: %s", configObj.Name, configObj.Pwd) | |||
} | |||
return false | |||
} | |||
func WriteStructDataToJsonFile() { | |||
jsonConfigList := GetConfigs() | |||
unmarshelledConfigs := DeserializeJson(jsonConfigList) | |||
output,err := json.MarshalIndent(&unmarshelledConfigs,"","\t") | |||
if err != nil { | |||
fmt.Println("转换失败") | |||
return | |||
} | |||
err = ioutil.WriteFile("./user.json",output,0644) | |||
if err != nil { | |||
fmt.Println("写文件失败") | |||
return | |||
} | |||
} | |||
func UpdateUserData(user Userdata){ | |||
jsonConfigList := GetConfigs() | |||
unmarshelledConfigs := DeserializeJson(jsonConfigList) | |||
for i, configObj := range unmarshelledConfigs { | |||
if (configObj.Name == user.Name){ | |||
unmarshelledConfigs[i].Pwd = user.Pwd | |||
break; | |||
} | |||
fmt.Printf("Name: %s Pwd: %s", configObj.Name, configObj.Pwd) | |||
} | |||
output,err := json.MarshalIndent(&unmarshelledConfigs,"","\t") | |||
if err != nil { | |||
fmt.Println("转换失败") | |||
return | |||
} | |||
err = ioutil.WriteFile("./user.json",output,0644) | |||
if err != nil { | |||
fmt.Println("写文件失败") | |||
return | |||
} | |||
} | |||