|
@@ -10,6 +10,7 @@ import (
|
|
|
"os"
|
|
|
"os/user"
|
|
|
"path"
|
|
|
+ "regexp"
|
|
|
"strconv"
|
|
|
"strings"
|
|
|
)
|
|
@@ -31,21 +32,6 @@ type TunnelConfiguration struct {
|
|
|
HttpAuth string `yaml:"auth"`
|
|
|
}
|
|
|
|
|
|
-func defaultPath() string {
|
|
|
- user, err := user.Current()
|
|
|
-
|
|
|
- // user.Current() does not work on linux when cross compilling because
|
|
|
- // it requires CGO; use os.Getenv("HOME") hack until we compile natively
|
|
|
- homeDir := os.Getenv("HOME")
|
|
|
- if err != nil {
|
|
|
- log.Warn("Failed to get user's home directory: %s. Using $HOME: %s", err.Error(), homeDir)
|
|
|
- } else {
|
|
|
- homeDir = user.HomeDir
|
|
|
- }
|
|
|
-
|
|
|
- return path.Join(homeDir, ".ngrok")
|
|
|
-}
|
|
|
-
|
|
|
func LoadConfiguration(opts *Options) (config *Configuration, err error) {
|
|
|
configPath := opts.config
|
|
|
if configPath == "" {
|
|
@@ -70,6 +56,15 @@ func LoadConfiguration(opts *Options) (config *Configuration, err error) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+ // try to parse the old .ngrok format for backwards compatibility
|
|
|
+ matched := false
|
|
|
+ content := strings.TrimSpace(string(configBuf))
|
|
|
+ if matched, err = regexp.MatchString("^[0-9a-zA-Z_\\-!]+$", content); err != nil {
|
|
|
+ return
|
|
|
+ } else if matched {
|
|
|
+ config = &Configuration{AuthToken: content}
|
|
|
+ }
|
|
|
+
|
|
|
// set configuration defaults
|
|
|
if config.ServerAddr == "" {
|
|
|
config.ServerAddr = defaultServerAddr
|
|
@@ -169,6 +164,21 @@ func LoadConfiguration(opts *Options) (config *Configuration, err error) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+func defaultPath() string {
|
|
|
+ user, err := user.Current()
|
|
|
+
|
|
|
+ // user.Current() does not work on linux when cross compilling because
|
|
|
+ // it requires CGO; use os.Getenv("HOME") hack until we compile natively
|
|
|
+ homeDir := os.Getenv("HOME")
|
|
|
+ if err != nil {
|
|
|
+ log.Warn("Failed to get user's home directory: %s. Using $HOME: %s", err.Error(), homeDir)
|
|
|
+ } else {
|
|
|
+ homeDir = user.HomeDir
|
|
|
+ }
|
|
|
+
|
|
|
+ return path.Join(homeDir, ".ngrok")
|
|
|
+}
|
|
|
+
|
|
|
func normalizeAddress(addr string, propName string) (string, error) {
|
|
|
// normalize port to address
|
|
|
if _, err := strconv.Atoi(addr); err == nil {
|