mirror of
https://github.com/bjdgyc/anylink.git
synced 2025-08-10 04:58:12 +08:00
修改客户端分配的ip为CIDR格式,请注意原来network格式
This commit is contained in:
@@ -16,7 +16,7 @@ func Login(w http.ResponseWriter, r *http.Request) {
|
||||
// hd, _ := httputil.DumpRequest(r, true)
|
||||
// fmt.Println("DumpRequest: ", string(hd))
|
||||
|
||||
r.ParseForm()
|
||||
_ = r.ParseForm()
|
||||
admin_user := r.PostFormValue("admin_user")
|
||||
admin_pass := r.PostFormValue("admin_pass")
|
||||
|
||||
|
@@ -10,7 +10,7 @@ import (
|
||||
)
|
||||
|
||||
func GroupList(w http.ResponseWriter, r *http.Request) {
|
||||
r.ParseForm()
|
||||
_ = r.ParseForm()
|
||||
pageS := r.FormValue("page")
|
||||
page, _ := strconv.Atoi(pageS)
|
||||
if page < 1 {
|
||||
@@ -48,7 +48,7 @@ func GroupNames(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func GroupDetail(w http.ResponseWriter, r *http.Request) {
|
||||
r.ParseForm()
|
||||
_ = r.ParseForm()
|
||||
idS := r.FormValue("id")
|
||||
id, _ := strconv.Atoi(idS)
|
||||
if id < 1 {
|
||||
@@ -90,7 +90,7 @@ func GroupSet(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func GroupDel(w http.ResponseWriter, r *http.Request) {
|
||||
r.ParseForm()
|
||||
_ = r.ParseForm()
|
||||
idS := r.FormValue("id")
|
||||
id, _ := strconv.Atoi(idS)
|
||||
if id < 1 {
|
||||
|
@@ -11,7 +11,7 @@ import (
|
||||
)
|
||||
|
||||
func UserIpMapList(w http.ResponseWriter, r *http.Request) {
|
||||
r.ParseForm()
|
||||
_ = r.ParseForm()
|
||||
pageS := r.FormValue("page")
|
||||
page, _ := strconv.Atoi(pageS)
|
||||
if page < 1 {
|
||||
@@ -39,7 +39,7 @@ func UserIpMapList(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func UserIpMapDetail(w http.ResponseWriter, r *http.Request) {
|
||||
r.ParseForm()
|
||||
_ = r.ParseForm()
|
||||
idS := r.FormValue("id")
|
||||
id, _ := strconv.Atoi(idS)
|
||||
if id < 1 {
|
||||
@@ -58,7 +58,7 @@ func UserIpMapDetail(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func UserIpMapSet(w http.ResponseWriter, r *http.Request) {
|
||||
r.ParseForm()
|
||||
_ = r.ParseForm()
|
||||
|
||||
body, err := ioutil.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
@@ -92,7 +92,7 @@ func UserIpMapSet(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func UserIpMapDel(w http.ResponseWriter, r *http.Request) {
|
||||
r.ParseForm()
|
||||
_ = r.ParseForm()
|
||||
idS := r.FormValue("id")
|
||||
id, _ := strconv.Atoi(idS)
|
||||
|
||||
|
@@ -1,7 +1,6 @@
|
||||
package admin
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"runtime"
|
||||
@@ -84,9 +83,8 @@ func SetSystem(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func SetSoft(w http.ResponseWriter, r *http.Request) {
|
||||
datas := base.ServerCfg2Slice()
|
||||
b, _ := json.Marshal(datas)
|
||||
w.Write(b)
|
||||
data := base.ServerCfg2Slice()
|
||||
RespSucess(w, data)
|
||||
}
|
||||
|
||||
func decimal(f float64) float64 {
|
||||
|
@@ -19,7 +19,7 @@ import (
|
||||
)
|
||||
|
||||
func UserList(w http.ResponseWriter, r *http.Request) {
|
||||
r.ParseForm()
|
||||
_ = r.ParseForm()
|
||||
prefix := r.FormValue("prefix")
|
||||
pageS := r.FormValue("page")
|
||||
page, _ := strconv.Atoi(pageS)
|
||||
@@ -58,7 +58,7 @@ func UserList(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func UserDetail(w http.ResponseWriter, r *http.Request) {
|
||||
r.ParseForm()
|
||||
_ = r.ParseForm()
|
||||
idS := r.FormValue("id")
|
||||
id, _ := strconv.Atoi(idS)
|
||||
if id < 1 {
|
||||
@@ -77,7 +77,7 @@ func UserDetail(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func UserSet(w http.ResponseWriter, r *http.Request) {
|
||||
r.ParseForm()
|
||||
_ = r.ParseForm()
|
||||
|
||||
body, err := ioutil.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
@@ -111,7 +111,7 @@ func UserSet(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func UserDel(w http.ResponseWriter, r *http.Request) {
|
||||
r.ParseForm()
|
||||
_ = r.ParseForm()
|
||||
idS := r.FormValue("id")
|
||||
id, _ := strconv.Atoi(idS)
|
||||
|
||||
@@ -130,7 +130,7 @@ func UserDel(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func UserOtpQr(w http.ResponseWriter, r *http.Request) {
|
||||
r.ParseForm()
|
||||
_ = r.ParseForm()
|
||||
b64 := r.FormValue("b64")
|
||||
idS := r.FormValue("id")
|
||||
id, _ := strconv.Atoi(idS)
|
||||
@@ -148,11 +148,16 @@ func UserOtpQr(w http.ResponseWriter, r *http.Request) {
|
||||
if b64 == "1" {
|
||||
data, _ := qr.PNG(300)
|
||||
s := base64.StdEncoding.EncodeToString(data)
|
||||
fmt.Fprint(w, s)
|
||||
} else {
|
||||
qr.Write(300, w)
|
||||
_, err = fmt.Fprint(w, s)
|
||||
if err != nil {
|
||||
base.Error(err)
|
||||
}
|
||||
return
|
||||
}
|
||||
err = qr.Write(300, w)
|
||||
if err != nil {
|
||||
base.Error(err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 在线用户
|
||||
@@ -169,14 +174,14 @@ func UserOnline(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func UserOffline(w http.ResponseWriter, r *http.Request) {
|
||||
r.ParseForm()
|
||||
_ = r.ParseForm()
|
||||
token := r.FormValue("token")
|
||||
sessdata.CloseSess(token)
|
||||
RespSucess(w, nil)
|
||||
}
|
||||
|
||||
func UserReline(w http.ResponseWriter, r *http.Request) {
|
||||
r.ParseForm()
|
||||
_ = r.ParseForm()
|
||||
token := r.FormValue("token")
|
||||
sessdata.CloseCSess(token)
|
||||
RespSucess(w, nil)
|
||||
@@ -231,7 +236,10 @@ func userAccountMail(user *dbdata.User) error {
|
||||
}
|
||||
w := bytes.NewBufferString("")
|
||||
t, _ := template.New("auth_complete").Parse(htmlBody)
|
||||
t.Execute(w, data)
|
||||
err = t.Execute(w, data)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// fmt.Println(w.String())
|
||||
return SendMail(base.Cfg.Issuer+"平台通知", user.Email, w.String())
|
||||
}
|
||||
|
@@ -8,8 +8,8 @@ import (
|
||||
"github.com/bjdgyc/anylink/base"
|
||||
"github.com/bjdgyc/anylink/dbdata"
|
||||
"github.com/dgrijalva/jwt-go"
|
||||
"github.com/mojocn/base64Captcha"
|
||||
mail "github.com/xhit/go-simple-mail/v2"
|
||||
// "github.com/mojocn/base64Captcha"
|
||||
)
|
||||
|
||||
func SetJwtData(data map[string]interface{}, expiresAt int64) (string, error) {
|
||||
@@ -43,15 +43,6 @@ func GetJwtData(jwtToken string) (map[string]interface{}, error) {
|
||||
return claims, nil
|
||||
}
|
||||
|
||||
func createCaptcha() {
|
||||
var store = base64Captcha.DefaultMemStore
|
||||
var driver base64Captcha.Driver
|
||||
driverString := &base64Captcha.DriverString{}
|
||||
driver = driverString.ConvertFonts()
|
||||
c := base64Captcha.NewCaptcha(driver, store)
|
||||
_ = c
|
||||
}
|
||||
|
||||
func SendMail(subject, to, htmlBody string) error {
|
||||
|
||||
dataSmtp := &dbdata.SettingSmtp{}
|
||||
|
@@ -43,8 +43,10 @@ func respHttp(w http.ResponseWriter, respCode int, data interface{}, errS ...int
|
||||
|
||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.Write(b)
|
||||
|
||||
_, err = w.Write(b)
|
||||
if err != nil {
|
||||
base.Error(err)
|
||||
}
|
||||
// 记录返回数据
|
||||
// logger.Category("response").Debug(string(b))
|
||||
}
|
||||
|
39
admin/resp_test.go
Normal file
39
admin/resp_test.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package admin
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestRespSucess(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
w := httptest.NewRecorder()
|
||||
RespSucess(w, "data")
|
||||
// fmt.Println(w)
|
||||
assert.Equal(w.Code, 200)
|
||||
body, _ := ioutil.ReadAll(w.Body)
|
||||
res := Resp{}
|
||||
err := json.Unmarshal(body, &res)
|
||||
assert.Nil(err)
|
||||
assert.Equal(res.Code, 0)
|
||||
assert.Equal(res.Data, "data")
|
||||
|
||||
}
|
||||
|
||||
func TestRespError(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
w := httptest.NewRecorder()
|
||||
RespError(w, 10, "err-msg")
|
||||
// fmt.Println(w)
|
||||
assert.Equal(w.Code, 200)
|
||||
body, _ := ioutil.ReadAll(w.Body)
|
||||
res := Resp{}
|
||||
err := json.Unmarshal(body, &res)
|
||||
assert.Nil(err)
|
||||
assert.Equal(res.Code, 10)
|
||||
assert.Equal(res.Msg, "err-msg")
|
||||
}
|
Reference in New Issue
Block a user