Skip to content

Commit

Permalink
interact and persist
Browse files Browse the repository at this point in the history
  • Loading branch information
fakeboboliu committed Mar 24, 2022
1 parent b142949 commit 7ae3327
Showing 1 changed file with 31 additions and 5 deletions.
36 changes: 31 additions & 5 deletions authpass.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,32 @@ func init() {
}
}

func interactParam() {
fmt.Printf("您未提供生成参数,请提供下面的参数: \n > 隧道访问地址(如 https://something:12345): ")
fmt.Scanln(&u)
u = strings.TrimSpace(u)
if pu, err := url.Parse(u); err != nil || pu.Scheme != "https" {
u = "https://" + u
if _, err = url.Parse(u); err != nil {
fmt.Println("您提供的隧道访问地址无法解析,请检查输入")
return
}
}

fmt.Printf(" > 访问验证密码: ")
fmt.Scanln(&p)
p = strings.TrimSpace(p)

var s string
fmt.Printf(" > 是否记住认证(Y/N, 默认为Y): ")
fmt.Scanln(&s)
nopersist = strings.ToLower(strings.TrimSpace(s)) == "n"
}

type data struct {
Url string `json:"url"`
Pass string `json:"pass"`
Url string `json:"url"`
Pass string `json:"pass"`
Persist bool `json:"persist"`
}

func parseEmbed() {
Expand All @@ -76,6 +99,7 @@ func parseEmbed() {
}
u = d.Url
p = d.Pass
nopersist = !d.Persist
}

func genExe() {
Expand All @@ -100,8 +124,9 @@ func genExe() {
index += len(t)

d := data{
Url: u,
Pass: p,
Url: u,
Pass: p,
Persist: !nopersist,
}
j, err := json.Marshal(d)
if err != nil {
Expand Down Expand Up @@ -133,7 +158,8 @@ func main() {
if u == "" || p == "" {
parseEmbed()
if u == "" || p == "" {
flag.PrintDefaults()
interactParam()
genExe()
return
}
} else {
Expand Down

0 comments on commit 7ae3327

Please sign in to comment.