mirror of https://github.com/Xhofe/alist
🔒 random initial password
parent
3201b6da76
commit
9013add749
|
@ -3,6 +3,7 @@ package bootstrap
|
||||||
import (
|
import (
|
||||||
"github.com/Xhofe/alist/conf"
|
"github.com/Xhofe/alist/conf"
|
||||||
"github.com/Xhofe/alist/model"
|
"github.com/Xhofe/alist/model"
|
||||||
|
"github.com/Xhofe/alist/utils"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -27,7 +28,7 @@ func InitSettings() {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Key: "password",
|
Key: "password",
|
||||||
Value: "alist",
|
Value: utils.RandomStr(8),
|
||||||
Description: "password",
|
Description: "password",
|
||||||
Type: "string",
|
Type: "string",
|
||||||
Access: model.PRIVATE,
|
Access: model.PRIVATE,
|
||||||
|
@ -235,6 +236,9 @@ func InitSettings() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == gorm.ErrRecordNotFound {
|
if err == gorm.ErrRecordNotFound {
|
||||||
err = model.SaveSetting(v)
|
err = model.SaveSetting(v)
|
||||||
|
if v.Key == "password" {
|
||||||
|
log.Infof("Initial password: %s", v.Value)
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("failed write setting: %s", err.Error())
|
log.Fatalf("failed write setting: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@ import (
|
||||||
func (driver Cloud139) Request(pathname string, method int, headers, query, form map[string]string, data interface{}, resp interface{}, account *model.Account) ([]byte, error) {
|
func (driver Cloud139) Request(pathname string, method int, headers, query, form map[string]string, data interface{}, resp interface{}, account *model.Account) ([]byte, error) {
|
||||||
url := "https://yun.139.com" + pathname
|
url := "https://yun.139.com" + pathname
|
||||||
req := base.RestyClient.R()
|
req := base.RestyClient.R()
|
||||||
randStr := randomStr(16)
|
randStr := utils.RandomStr(16)
|
||||||
ts := time.Now().Format("2006-01-02 15:04:05")
|
ts := time.Now().Format("2006-01-02 15:04:05")
|
||||||
log.Debugf("%+v", data)
|
log.Debugf("%+v", data)
|
||||||
body, err := utils.Json.Marshal(data)
|
body, err := utils.Json.Marshal(data)
|
||||||
|
|
|
@ -5,7 +5,6 @@ import (
|
||||||
"github.com/Xhofe/alist/drivers/base"
|
"github.com/Xhofe/alist/drivers/base"
|
||||||
"github.com/Xhofe/alist/model"
|
"github.com/Xhofe/alist/model"
|
||||||
"github.com/Xhofe/alist/utils"
|
"github.com/Xhofe/alist/utils"
|
||||||
"math/rand"
|
|
||||||
"net/url"
|
"net/url"
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
@ -13,16 +12,6 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func randomStr(n int) string {
|
|
||||||
builder := strings.Builder{}
|
|
||||||
t := "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
|
|
||||||
for i := 0; i < n; i++ {
|
|
||||||
r := rand.Intn(len(t))
|
|
||||||
builder.WriteString(t[r : r+1])
|
|
||||||
}
|
|
||||||
return builder.String()
|
|
||||||
}
|
|
||||||
|
|
||||||
func encodeURIComponent(str string) string {
|
func encodeURIComponent(str string) string {
|
||||||
r := url.QueryEscape(str)
|
r := url.QueryEscape(str)
|
||||||
r = strings.Replace(r, "+", "%20", -1)
|
r = strings.Replace(r, "+", "%20", -1)
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
package utils
|
||||||
|
|
||||||
|
import (
|
||||||
|
"math/rand"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
func RandomStr(n int) string {
|
||||||
|
builder := strings.Builder{}
|
||||||
|
t := "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
|
||||||
|
for i := 0; i < n; i++ {
|
||||||
|
r := rand.Intn(len(t))
|
||||||
|
builder.WriteString(t[r : r+1])
|
||||||
|
}
|
||||||
|
return builder.String()
|
||||||
|
}
|
Loading…
Reference in New Issue