2018-09-13 18:14:22 -04:00
|
|
|
package i2ptunconf
|
|
|
|
|
2018-12-03 13:53:48 -05:00
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
)
|
2018-09-13 18:14:22 -04:00
|
|
|
|
|
|
|
// GetType takes an argument and a default. If the argument differs from the
|
|
|
|
// default, the argument is always returned. If the argument and default are
|
|
|
|
// the same and the key exists, the key is returned. If the key is absent, the
|
|
|
|
// default is returned.
|
2019-08-31 00:13:10 -04:00
|
|
|
func (c *Conf) GetTypes(argc, argu, argh bool, def string, label ...string) string {
|
2018-09-13 18:14:22 -04:00
|
|
|
var typ string
|
|
|
|
if argu {
|
|
|
|
typ += "udp"
|
|
|
|
}
|
|
|
|
if argc {
|
2019-04-25 23:52:08 -04:00
|
|
|
if argh == true {
|
|
|
|
typ += "http"
|
|
|
|
}
|
2018-09-13 18:14:22 -04:00
|
|
|
typ += "client"
|
|
|
|
c.Client = true
|
|
|
|
} else {
|
|
|
|
if argh == true {
|
|
|
|
typ += "http"
|
|
|
|
} else {
|
|
|
|
typ += "server"
|
|
|
|
}
|
2019-09-02 20:46:17 -04:00
|
|
|
if typ != def {
|
|
|
|
return typ
|
|
|
|
}
|
2018-09-13 18:14:22 -04:00
|
|
|
}
|
2019-06-12 09:16:13 -04:00
|
|
|
if def == "kcpclient" {
|
2019-09-02 20:46:17 -04:00
|
|
|
return def
|
2019-06-12 09:16:13 -04:00
|
|
|
}
|
|
|
|
if def == "kcpserver" {
|
2019-09-02 20:46:17 -04:00
|
|
|
return def
|
2019-06-12 09:16:13 -04:00
|
|
|
}
|
2019-09-02 20:46:17 -04:00
|
|
|
if def == "eephttpd" {
|
|
|
|
return def
|
|
|
|
}
|
|
|
|
if def == "vpnclient" {
|
|
|
|
return def
|
|
|
|
}
|
|
|
|
if def == "vpnserver" {
|
|
|
|
return def
|
|
|
|
}
|
2019-09-08 16:20:30 -04:00
|
|
|
if def == "outproxy" {
|
|
|
|
return def
|
|
|
|
}
|
|
|
|
if def == "outproxyhttp" {
|
|
|
|
return def
|
|
|
|
}
|
2019-09-02 20:46:17 -04:00
|
|
|
if def == "browserclient" {
|
|
|
|
return def
|
2019-06-12 09:16:13 -04:00
|
|
|
}
|
|
|
|
if c.Config == nil {
|
|
|
|
return typ
|
|
|
|
}
|
|
|
|
if x, o := c.Get("type", label...); o {
|
|
|
|
return x
|
|
|
|
}
|
|
|
|
return def
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Conf) GetOtherType(typ, def string, label ...string) string {
|
2018-09-13 18:14:22 -04:00
|
|
|
if typ != def {
|
|
|
|
return typ
|
|
|
|
}
|
2018-11-29 19:05:19 -05:00
|
|
|
if c.Config == nil {
|
2018-09-13 18:14:22 -04:00
|
|
|
return typ
|
|
|
|
}
|
|
|
|
if x, o := c.Get("type", label...); o {
|
|
|
|
return x
|
|
|
|
}
|
|
|
|
return def
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetType sets the type of proxy to create from the config file
|
|
|
|
func (c *Conf) SetType(label ...string) {
|
|
|
|
if v, ok := c.Get("type", label...); ok {
|
|
|
|
if strings.Contains(v, "client") {
|
|
|
|
c.Client = true
|
|
|
|
}
|
2019-08-25 20:32:50 -04:00
|
|
|
switch c.Type {
|
|
|
|
case "server":
|
2018-09-13 18:14:22 -04:00
|
|
|
c.Type = v
|
2019-08-25 20:32:50 -04:00
|
|
|
case "http":
|
|
|
|
c.Type = v
|
|
|
|
case "client":
|
|
|
|
c.Type = v
|
|
|
|
case "httpclient":
|
|
|
|
c.Type = v
|
|
|
|
case "browserclient":
|
|
|
|
c.Type = v
|
|
|
|
case "udpserver":
|
|
|
|
c.Type = v
|
|
|
|
case "udpclient":
|
|
|
|
c.Type = v
|
2019-09-02 20:46:17 -04:00
|
|
|
case "eephttpd":
|
|
|
|
c.Type = v
|
2019-09-08 16:20:30 -04:00
|
|
|
case "outproxy":
|
|
|
|
c.Type = v
|
|
|
|
case "outproxyhttp":
|
|
|
|
c.Type = v
|
2019-08-25 20:32:50 -04:00
|
|
|
case "vpnserver":
|
|
|
|
c.Type = v
|
|
|
|
case "vpnclient":
|
|
|
|
c.Type = v
|
|
|
|
case "kcpclient":
|
|
|
|
c.Type = v
|
|
|
|
case "kcpserver":
|
|
|
|
c.Type = v
|
|
|
|
default:
|
|
|
|
c.Type = "browserclient"
|
2018-09-13 18:14:22 -04:00
|
|
|
}
|
|
|
|
} else {
|
2019-08-25 20:32:50 -04:00
|
|
|
c.Type = "browserclient"
|
|
|
|
}
|
|
|
|
}
|