diff --git a/.gitignore b/.gitignore index 603894f..7d1d33c 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,6 @@ main ruijie HustWebAuth* .vscode/ -*.yaml \ No newline at end of file +*.yaml +__debug_bin* +.lh/ \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 4593f7c..15e62f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). Nothing right now. +## [1.1.4] - 2023.06.14 更新 + +### Added + +1. Add `--encrypt` flag to judge whether the password is encrypted + ## [1.1.3] - 2023.05.12 更新 ### Changed diff --git a/README.md b/README.md index cadd7cc..a8f5e66 100644 --- a/README.md +++ b/README.md @@ -17,11 +17,11 @@ Web认证 ----------- 1. 安装 > 方式一: 使用 `go install` 命令安装 - > + > > ```bash > go install github.com/a76yyyy/HustWebAuth@latest > ``` - > + > > 方式二: 下载 `release` 可执行文件 > > 1. 下载指定架构的[可执行文件](https://github.com/a76yyyy/HustWebAuth/releases) @@ -34,7 +34,7 @@ Web认证 3. 命令行运行 `HustWebAuth -a account -p password` 进行认证测试 > ### Tips: - > + > > 1. 请确保你的账号密码正确 > 2. 请确保你的网络连接正常, 且使用锐捷 Web 认证方式 > 3. 可使用 `HustWebAuth -a account -p password -o` 进行认证并保存配置文件至 `$HOME` 文件夹下 @@ -72,6 +72,7 @@ Flags: --cycleRetry int Cycle retry times, -1 means retry forever (default 3) -d, --daemon Enable daemon mode, not support windows --daemonPidFile string Daemon pid file + -e, --encrypt bool Password is encrypted or not(default false) -h, --help help for main.exe --logAppend Log file append mode. NOTE: if logRandom is true, it will be ignored (default true) diff --git a/cmd/login.go b/cmd/login.go index f12976a..bfa0a60 100644 --- a/cmd/login.go +++ b/cmd/login.go @@ -58,16 +58,22 @@ func GetCookie(url string) (*http.Cookie, error) { } // Login to auth the network -func login(url string, queryString string, account string, password string, serviceType string, cookie *http.Cookie) (string, error) { +func login(url string, queryString string, account string, password string, serviceType string, encrypt bool, cookie *http.Cookie) (string, error) { trueurl := strings.Split(url, "/eportal/")[0] + "/eportal/InterFace.do?method=login" client := &http.Client{} var req *http.Request + var passwordEncrypt string + if encrypt { + passwordEncrypt = "true" + } else { + passwordEncrypt = "false" + } data := "userId=" + account + "&password=" + password + "&service=" + serviceType + "&queryString=" + queryString + - "&operatorPwd=&operatorUserId=&validcode=&passwordEncrypt=false" + "&operatorPwd=&operatorUserId=&validcode=&passwordEncrypt=" + passwordEncrypt req, _ = http.NewRequest("POST", trueurl, strings.NewReader(data)) req.AddCookie(cookie) @@ -123,14 +129,14 @@ func Login() (res string, err error) { return "", err } - login_res, err := login(url, queryString, account, password, serviceType, cookie) + login_res, err := login(url, queryString, account, password, serviceType, encrypt, cookie) if err != nil { return "", err } if len(strings.Split(login_res, "\"result\":\"success\"")) == 2 { res = "Login success!" } else { - return "", errors.New("Login fail: " + res) + return "", errors.New("Login fail: " + login_res) } if register { diff --git a/cmd/root.go b/cmd/root.go index a52a93f..e60f803 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -42,6 +42,7 @@ var ( account string password string serviceType string + encrypt bool pingIP string pingCount int pingTimeout time.Duration @@ -196,13 +197,14 @@ func init() { rootCmd.PersistentFlags().StringVarP(&account, "account", "a", "", "Account for ruijie web authentication") rootCmd.PersistentFlags().StringVarP(&password, "password", "p", "", "Password for ruijie web authentication") rootCmd.PersistentFlags().StringVarP(&serviceType, "serviceType", "s", "internet", "Service type, options: [internet, local]") + rootCmd.PersistentFlags().BoolVarP(&encrypt, "encrypt", "e", false, "Password is encrypted or not (default false)") rootCmd.PersistentFlags().StringVar(&pingIP, "pingIP", "202.114.0.131", "IP address to ping") rootCmd.PersistentFlags().IntVar(&pingCount, "pingCount", 3, "ping count") rootCmd.PersistentFlags().DurationVar(&pingTimeout, "pingTimeout", 3*time.Second, "Ping timeout") - rootCmd.PersistentFlags().BoolVar(&pingPrivilege, "pingPrivilege", true, `Sets the type of ping pinger will send. -false means pinger will send an "unprivileged" UDP ping. -true means pinger will send a "privileged" raw ICMP ping. + rootCmd.PersistentFlags().BoolVar(&pingPrivilege, "pingPrivilege", true, `Sets the type of ping pinger will send. +false means pinger will send an "unprivileged" UDP ping. +true means pinger will send a "privileged" raw ICMP ping. NOTE: setting to true requires that it be run with super-user privileges. `) rootCmd.PersistentFlags().StringVar(&redirectURL, "redirectURL", "http://123.123.123.123", "Redirect URL") @@ -225,6 +227,7 @@ NOTE: setting to true requires that it be run with super-user privileges. viper.BindPFlag("auth.account", rootCmd.PersistentFlags().Lookup("account")) viper.BindPFlag("auth.password", rootCmd.PersistentFlags().Lookup("password")) viper.BindPFlag("auth.serviceType", rootCmd.PersistentFlags().Lookup("serviceType")) + viper.BindPFlag("auth.encrypt", rootCmd.PersistentFlags().Lookup("encrypt")) viper.BindPFlag("ping.ip", rootCmd.PersistentFlags().Lookup("pingIP")) viper.BindPFlag("ping.count", rootCmd.PersistentFlags().Lookup("pingCount")) viper.BindPFlag("ping.timeout", rootCmd.PersistentFlags().Lookup("pingTimeout")) @@ -287,6 +290,7 @@ func initConfig() { account = viper.GetString("auth.account") password = viper.GetString("auth.password") serviceType = viper.GetString("auth.serviceType") + encrypt = viper.GetBool("auth.encrypt") pingIP = viper.GetString("ping.ip") pingCount = viper.GetInt("ping.count") pingTimeout = viper.GetDuration("ping.timeout")