TUN-881: Display trial zone URL upon successful registration
This commit is contained in:
parent
f0126d1af2
commit
0e6492342b
|
@ -342,6 +342,14 @@ func RegisterTunnel(ctx context.Context, muxer *h2mux.Muxer, config *TunnelConfi
|
||||||
if registration.TunnelID != "" {
|
if registration.TunnelID != "" {
|
||||||
config.Logger.Info("Tunnel ID: " + registration.TunnelID)
|
config.Logger.Info("Tunnel ID: " + registration.TunnelID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Print out the user's trial zone URL in a nice box (if they requested and got one)
|
||||||
|
if isTrialTunnel := config.Hostname == "" && registration.Url != ""; isTrialTunnel {
|
||||||
|
for _, line := range asciiBox(trialZoneMsg(registration.Url), 2) {
|
||||||
|
config.Logger.Infoln(line)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
config.Logger.Infof("Route propagating, it may take up to 1 minute for your new route to become functional")
|
config.Logger.Infof("Route propagating, it may take up to 1 minute for your new route to become functional")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -632,3 +640,35 @@ func uint8ToString(input uint8) string {
|
||||||
func isLBProbeRequest(req *http.Request) bool {
|
func isLBProbeRequest(req *http.Request) bool {
|
||||||
return strings.HasPrefix(req.UserAgent(), lbProbeUserAgentPrefix)
|
return strings.HasPrefix(req.UserAgent(), lbProbeUserAgentPrefix)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Print out the given lines in a nice ASCII box.
|
||||||
|
func asciiBox(lines []string, padding int) (box []string) {
|
||||||
|
maxLen := maxLen(lines)
|
||||||
|
spacer := strings.Repeat(" ", padding)
|
||||||
|
|
||||||
|
border := "+" + strings.Repeat("-", maxLen+(padding*2)) + "+"
|
||||||
|
|
||||||
|
box = append(box, border)
|
||||||
|
for _, line := range lines {
|
||||||
|
box = append(box, "|"+spacer+line+strings.Repeat(" ", maxLen-len(line))+spacer+"|")
|
||||||
|
}
|
||||||
|
box = append(box, border)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func maxLen(lines []string) int {
|
||||||
|
max := 0
|
||||||
|
for _, line := range lines {
|
||||||
|
if len(line) > max {
|
||||||
|
max = len(line)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return max
|
||||||
|
}
|
||||||
|
|
||||||
|
func trialZoneMsg(url string) []string {
|
||||||
|
return []string{
|
||||||
|
"Your free tunnel has started! Visit it:",
|
||||||
|
" " + url,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue