@@ -189,7 +189,7 @@ func parseSettings(c *cli.Context) (err error) {
189
189
return
190
190
}
191
191
192
- func runHook (c * cli. Context ) {
192
+ func runHook () {
193
193
if settings .HookSucc != "" {
194
194
logger .Debugf ("Run hook \" %s\" \n " , settings .HookSucc )
195
195
cmd := exec .Command (settings .HookSucc )
@@ -220,7 +220,7 @@ func cmdKeepalive(c *cli.Context) {
220
220
logger .Errorf ("Parse setting error: %s\n " , err )
221
221
os .Exit (1 )
222
222
}
223
- err = keepAliveLoop (c , c .Bool ("auth" ))
223
+ err = keepAliveLoop (c .Bool ("auth" ))
224
224
if err != nil {
225
225
logger .Errorf ("Keepalive error: %s\n " , err )
226
226
os .Exit (1 )
@@ -244,20 +244,6 @@ func authUtil(c *cli.Context, logout bool) error {
244
244
}
245
245
}
246
246
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
-
261
247
host := libauth .NewUrlProvider (domain , settings .Insecure )
262
248
if len (settings .Ip ) == 0 && ! settings .NoCheck {
263
249
online , _ , username := libauth .IsOnline (host , acID )
@@ -281,12 +267,6 @@ func authUtil(c *cli.Context, logout bool) error {
281
267
if err != nil {
282
268
return err
283
269
}
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
- }
290
270
}
291
271
292
272
// if settings.Campus {
@@ -300,12 +280,12 @@ func authUtil(c *cli.Context, logout bool) error {
300
280
}
301
281
if err == nil {
302
282
logger .Infof ("%s Successfully!\n " , action )
303
- runHook (c )
283
+ runHook ()
304
284
if settings .KeepOn {
305
285
if len (settings .Ip ) != 0 {
306
286
logger .Errorf ("Cannot keep another IP online\n " )
307
287
} else {
308
- return keepAliveLoop (c , true )
288
+ return keepAliveLoop (true )
309
289
}
310
290
}
311
291
} else {
@@ -314,7 +294,7 @@ func authUtil(c *cli.Context, logout bool) error {
314
294
return err
315
295
}
316
296
317
- func keepAliveLoop (c * cli. Context , campusOnly bool ) (ret error ) {
297
+ func keepAliveLoop (campusOnly bool ) (ret error ) {
318
298
logger .Infof ("Accessing websites periodically to keep you online" )
319
299
320
300
accessTarget := func (url string , ipv6 bool ) (ret error ) {
@@ -353,21 +333,23 @@ func keepAliveLoop(c *cli.Context, campusOnly bool) (ret error) {
353
333
for {
354
334
select {
355
335
case <- stop :
356
- break
336
+ return // Exits the goroutine when receiving a stop signal
357
337
case <- time .After (13 * time .Minute ):
358
338
_ = accessTarget (targetInside , true )
359
339
}
360
340
}
361
341
}()
362
342
343
+ // Label for the outer loop
344
+ loop:
363
345
for {
364
346
target := targetOutside
365
347
if campusOnly || settings .V6 {
366
348
target = targetInside
367
349
}
368
350
if ret = accessTarget (target , settings .V6 ); ret != nil {
369
351
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
371
353
}
372
354
time .Sleep (3 * time .Second )
373
355
}
@@ -394,7 +376,7 @@ func main() {
394
376
& cli.BoolFlag {Name : "help, h" , Usage : "print the help" },
395
377
},
396
378
Commands : []cli.Command {
397
- cli. Command {
379
+ {
398
380
Name : "auth" ,
399
381
Usage : "(default) Auth via auth.nyist.edu.cn" ,
400
382
Flags : []cli.Flag {
@@ -403,12 +385,12 @@ func main() {
403
385
},
404
386
Action : cmdAuth ,
405
387
},
406
- cli. Command {
388
+ {
407
389
Name : "deauth" ,
408
390
Usage : "De-authenticate via auth.nyist.edu.cn" ,
409
391
Action : cmdDeauth ,
410
392
},
411
- cli. Command {
393
+ {
412
394
Name : "keepalive" ,
413
395
Usage : "Keep the connection alive by pinging a server" ,
414
396
Action : cmdKeepalive ,
0 commit comments