Skip to content

Commit 67adb62

Browse files
committed
remove AcID and NasID
1 parent f03456a commit 67adb62

File tree

2 files changed

+13
-31
lines changed

2 files changed

+13
-31
lines changed

cli/main.go

+12-30
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ func parseSettings(c *cli.Context) (err error) {
189189
return
190190
}
191191

192-
func runHook(c *cli.Context) {
192+
func runHook() {
193193
if settings.HookSucc != "" {
194194
logger.Debugf("Run hook \"%s\"\n", settings.HookSucc)
195195
cmd := exec.Command(settings.HookSucc)
@@ -220,7 +220,7 @@ func cmdKeepalive(c *cli.Context) {
220220
logger.Errorf("Parse setting error: %s\n", err)
221221
os.Exit(1)
222222
}
223-
err = keepAliveLoop(c, c.Bool("auth"))
223+
err = keepAliveLoop(c.Bool("auth"))
224224
if err != nil {
225225
logger.Errorf("Keepalive error: %s\n", err)
226226
os.Exit(1)
@@ -244,20 +244,6 @@ func authUtil(c *cli.Context, logout bool) error {
244244
}
245245
}
246246

247-
if len(settings.Ip) == 0 && len(settings.AcID) == 0 {
248-
// Probe the ac_id parameter
249-
// We do this only in Tsinghua, since it requires access to usereg.t.e.c/net.t.e.c
250-
// For v6, ac_id must be probed using different url
251-
retAcID, err := libauth.GetAcID(settings.V6)
252-
// FIXME: currently when logout, the GetAcID is actually broken.
253-
// Though logout does not require correct ac_id now, it can break.
254-
if err != nil && !logout {
255-
logger.Debugf("Failed to get ac_id: %v", err)
256-
logger.Debugf("Login may fail with 'IP地址异常'.")
257-
}
258-
acID = retAcID
259-
}
260-
261247
host := libauth.NewUrlProvider(domain, settings.Insecure)
262248
if len(settings.Ip) == 0 && !settings.NoCheck {
263249
online, _, username := libauth.IsOnline(host, acID)
@@ -281,12 +267,6 @@ func authUtil(c *cli.Context, logout bool) error {
281267
if err != nil {
282268
return err
283269
}
284-
if len(settings.Ip) != 0 && len(settings.Host) == 0 && len(settings.AcID) == 0 {
285-
// Auth for another IP requires correct NAS ID since July 2020
286-
if retNasID, err := libauth.GetNasID(settings.Ip, settings.Username, settings.Password); err == nil {
287-
acID = retNasID
288-
}
289-
}
290270
}
291271

292272
// if settings.Campus {
@@ -300,12 +280,12 @@ func authUtil(c *cli.Context, logout bool) error {
300280
}
301281
if err == nil {
302282
logger.Infof("%s Successfully!\n", action)
303-
runHook(c)
283+
runHook()
304284
if settings.KeepOn {
305285
if len(settings.Ip) != 0 {
306286
logger.Errorf("Cannot keep another IP online\n")
307287
} else {
308-
return keepAliveLoop(c, true)
288+
return keepAliveLoop(true)
309289
}
310290
}
311291
} else {
@@ -314,7 +294,7 @@ func authUtil(c *cli.Context, logout bool) error {
314294
return err
315295
}
316296

317-
func keepAliveLoop(c *cli.Context, campusOnly bool) (ret error) {
297+
func keepAliveLoop(campusOnly bool) (ret error) {
318298
logger.Infof("Accessing websites periodically to keep you online")
319299

320300
accessTarget := func(url string, ipv6 bool) (ret error) {
@@ -353,21 +333,23 @@ func keepAliveLoop(c *cli.Context, campusOnly bool) (ret error) {
353333
for {
354334
select {
355335
case <-stop:
356-
break
336+
return // Exits the goroutine when receiving a stop signal
357337
case <-time.After(13 * time.Minute):
358338
_ = accessTarget(targetInside, true)
359339
}
360340
}
361341
}()
362342

343+
// Label for the outer loop
344+
loop:
363345
for {
364346
target := targetOutside
365347
if campusOnly || settings.V6 {
366348
target = targetInside
367349
}
368350
if ret = accessTarget(target, settings.V6); ret != nil {
369351
ret = fmt.Errorf("accessing %s failed (re-login might be required): %w", target, ret)
370-
break
352+
break loop // Break out of the outer loop using the label
371353
}
372354
time.Sleep(3 * time.Second)
373355
}
@@ -394,7 +376,7 @@ func main() {
394376
&cli.BoolFlag{Name: "help, h", Usage: "print the help"},
395377
},
396378
Commands: []cli.Command{
397-
cli.Command{
379+
{
398380
Name: "auth",
399381
Usage: "(default) Auth via auth.nyist.edu.cn",
400382
Flags: []cli.Flag{
@@ -403,12 +385,12 @@ func main() {
403385
},
404386
Action: cmdAuth,
405387
},
406-
cli.Command{
388+
{
407389
Name: "deauth",
408390
Usage: "De-authenticate via auth.nyist.edu.cn",
409391
Action: cmdDeauth,
410392
},
411-
cli.Command{
393+
{
412394
Name: "keepalive",
413395
Usage: "Keep the connection alive by pinging a server",
414396
Action: cmdKeepalive,

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module github.com/z4yx/GoAuthing
1+
module github.com/Palvef/AuthingNYIST
22

33
go 1.17
44

0 commit comments

Comments
 (0)