create a web interface
This commit is contained in:
@ -36,7 +36,7 @@ func (c *Conf) GetOutLength(arg, def int, label ...string) int {
|
||||
|
||||
// SetInLength sets the inbound length from the config file
|
||||
func (c *Conf) SetInLength(label ...string) {
|
||||
if v, ok := c.GetInt("outbound.length", label...); ok {
|
||||
if v, ok := c.GetInt("inbound.length", label...); ok {
|
||||
c.OutLength = v
|
||||
} else {
|
||||
c.OutLength = 3
|
||||
@ -45,7 +45,7 @@ func (c *Conf) SetInLength(label ...string) {
|
||||
|
||||
// SetOutLength sets the outbound lenth from the config file
|
||||
func (c *Conf) SetOutLength(label ...string) {
|
||||
if v, ok := c.GetInt("inbound.length", label...); ok {
|
||||
if v, ok := c.GetInt("outbound.length", label...); ok {
|
||||
c.InLength = v
|
||||
} else {
|
||||
c.InLength = 3
|
||||
|
@ -33,9 +33,11 @@ func (c *Conf) GetKeys(arg, def string, label ...string) string {
|
||||
|
||||
// SetKeys sets the key name from the config file
|
||||
func (c *Conf) SetKeys(label ...string) {
|
||||
if _, ok := c.Get("keys", label...); ok {
|
||||
if v, ok := c.Get("keys", label...); ok {
|
||||
c.TunName = v
|
||||
c.SaveFile = true
|
||||
} else {
|
||||
c.TunName = "forwarder"
|
||||
c.SaveFile = false
|
||||
}
|
||||
}
|
||||
|
@ -57,6 +57,8 @@ type Conf struct {
|
||||
AccessList []string
|
||||
MessageReliability string
|
||||
exists bool
|
||||
UserName string
|
||||
Password string
|
||||
}
|
||||
|
||||
// Print returns and prints a formatted list of configured tunnel settings.
|
||||
@ -261,6 +263,8 @@ func (c *Conf) I2PINILoad(iniFile string, label ...string) error {
|
||||
c.SetMessageReliability(label...)
|
||||
c.SetClientDest(label...)
|
||||
c.SetKeyFile(label...)
|
||||
c.SetUserName(label...)
|
||||
c.SetPassword(label...)
|
||||
if v, ok := c.Get("i2cp.accessList", label...); ok {
|
||||
csv := strings.Split(v, ",")
|
||||
for _, z := range csv {
|
||||
|
@ -11,26 +11,25 @@ func NewSAMHTTPClientFromConf(config *Conf) (*i2phttpproxy.SAMHTTPProxy, error)
|
||||
return i2phttpproxy.NewHttpProxy(
|
||||
i2phttpproxy.SetKeysPath(config.KeyFilePath),
|
||||
/*i2phttpproxy.SetHost(*samHostString),
|
||||
i2phttpproxy.SetPort(*samPortString),
|
||||
i2phttpproxy.SetProxyAddr(ln.Addr().String()),
|
||||
i2phttpproxy.SetControlAddr(cln.Addr().String()),
|
||||
i2phttpproxy.SetDebug(*debugConnection),
|
||||
i2phttpproxy.SetInLength(uint(*inboundTunnelLength)),
|
||||
i2phttpproxy.SetOutLength(uint(*outboundTunnelLength)),
|
||||
i2phttpproxy.SetInQuantity(uint(*inboundTunnels)),
|
||||
i2phttpproxy.SetOutQuantity(uint(*outboundTunnels)),
|
||||
i2phttpproxy.SetInBackups(uint(*inboundBackups)),
|
||||
i2phttpproxy.SetOutBackups(uint(*outboundBackups)),
|
||||
i2phttpproxy.SetInVariance(*inboundVariance),
|
||||
i2phttpproxy.SetOutVariance(*outboundVariance),
|
||||
i2phttpproxy.SetUnpublished(*dontPublishLease),
|
||||
i2phttpproxy.SetReduceIdle(*reduceIdle),
|
||||
i2phttpproxy.SetCompression(*useCompression),
|
||||
i2phttpproxy.SetReduceIdleTime(uint(*reduceIdleTime)),
|
||||
i2phttpproxy.SetReduceIdleQuantity(uint(*reduceIdleQuantity)),
|
||||
i2phttpproxy.SetCloseIdle(*closeIdle),
|
||||
i2phttpproxy.SetCloseIdleTime(uint(*closeIdleTime)),
|
||||
*/
|
||||
i2phttpproxy.SetPort(*samPortString),
|
||||
i2phttpproxy.SetProxyAddr(ln.Addr().String()),
|
||||
i2phttpproxy.SetControlAddr(cln.Addr().String()),
|
||||
i2phttpproxy.SetDebug(*debugConnection),
|
||||
i2phttpproxy.SetInLength(uint(*inboundTunnelLength)),
|
||||
i2phttpproxy.SetOutLength(uint(*outboundTunnelLength)),
|
||||
i2phttpproxy.SetInQuantity(uint(*inboundTunnels)),
|
||||
i2phttpproxy.SetOutQuantity(uint(*outboundTunnels)),
|
||||
i2phttpproxy.SetInBackups(uint(*inboundBackups)),
|
||||
i2phttpproxy.SetOutBackups(uint(*outboundBackups)),
|
||||
i2phttpproxy.SetInVariance(*inboundVariance),
|
||||
i2phttpproxy.SetOutVariance(*outboundVariance),
|
||||
i2phttpproxy.SetUnpublished(*dontPublishLease),
|
||||
i2phttpproxy.SetReduceIdle(*reduceIdle),
|
||||
i2phttpproxy.SetCompression(*useCompression),
|
||||
i2phttpproxy.SetReduceIdleTime(uint(*reduceIdleTime)),
|
||||
i2phttpproxy.SetReduceIdleQuantity(uint(*reduceIdleQuantity)),
|
||||
i2phttpproxy.SetCloseIdle(*closeIdle),
|
||||
i2phttpproxy.SetCloseIdleTime(uint(*closeIdleTime)),*/
|
||||
)
|
||||
}
|
||||
return nil, nil
|
||||
|
@ -64,12 +64,16 @@ var (
|
||||
"Client proxy mode(true or false)")
|
||||
injectHeaders = flag.Bool("ih", false,
|
||||
"Inject X-I2P-DEST headers")
|
||||
webAdmin = flag.Bool("w", false,
|
||||
webAdmin = flag.Bool("w", true,
|
||||
"Start web administration interface")
|
||||
sigType = flag.String("st", "",
|
||||
"Signature type")
|
||||
webPort = flag.String("wp", "7957",
|
||||
"Web port")
|
||||
webUser = flag.String("webuser", "samcatd",
|
||||
"Web interface username")
|
||||
webPass = flag.String("webpass", "",
|
||||
"Web interface password")
|
||||
webCSS = flag.String("css", "css/styles.css",
|
||||
"custom CSS for web interface")
|
||||
webJS = flag.String("js", "js/scripts.js",
|
||||
@ -189,6 +193,8 @@ func lbMain(ctx context.Context) {
|
||||
config.TargetForPort443 = config.GetPort443(*targetPort443, "")
|
||||
config.KeyFilePath = config.GetKeyFile(*encryptKeyFiles, "")
|
||||
config.ClientDest = config.GetClientDest(*targetDest, "", "")
|
||||
config.UserName = config.GetUserName(*webUser, "samcatd")
|
||||
config.Password = config.GetPassword(*webPass, "")
|
||||
|
||||
c := make(chan os.Signal, 1)
|
||||
signal.Notify(c, os.Interrupt)
|
||||
@ -201,7 +207,12 @@ func lbMain(ctx context.Context) {
|
||||
config.SamPort,
|
||||
"localhost",
|
||||
*webPort,
|
||||
*webCSS,
|
||||
*webJS,
|
||||
*startUp,
|
||||
*webAdmin,
|
||||
config.UserName,
|
||||
config.Password,
|
||||
); err == nil {
|
||||
go func() {
|
||||
for sig := range c {
|
||||
@ -210,9 +221,6 @@ func lbMain(ctx context.Context) {
|
||||
}
|
||||
}
|
||||
}()
|
||||
if *webAdmin {
|
||||
go samcatweb.Serve(manager, "", "", manager.WebHost, manager.WebPort)
|
||||
}
|
||||
manager.Serve()
|
||||
} else {
|
||||
log.Fatal(err)
|
||||
|
@ -23,13 +23,13 @@ i2cp.enableWhiteList = false
|
||||
i2cp.enableBlackList = false
|
||||
keyfile = "/usr/share/samcatd/samcatd"
|
||||
|
||||
#[sam-forwarder-tcp-server]
|
||||
#type = server
|
||||
#host = 127.0.0.1
|
||||
#port = 8081
|
||||
#inbound.length = 3
|
||||
#outbound.length = 3
|
||||
#keys = forwarder
|
||||
[sam-forwarder-tcp-server]
|
||||
type = server
|
||||
host = 127.0.0.1
|
||||
port = 8081
|
||||
inbound.length = 3
|
||||
outbound.length = 3
|
||||
keys = forwarder
|
||||
|
||||
[sam-forwarder-tcp-client]
|
||||
type = client
|
||||
@ -40,30 +40,30 @@ outbound.length = 3
|
||||
destination = i2p-projekt.i2p
|
||||
keys = forwarder-two
|
||||
|
||||
#[sam-forwarder-udp-server]
|
||||
#type = udpserver
|
||||
#host = 127.0.0.1
|
||||
#port = 8084
|
||||
#inbound.length = 6
|
||||
#outbound.length = 3
|
||||
#keys = forwarder-four
|
||||
[sam-forwarder-udp-server]
|
||||
type = udpserver
|
||||
host = 127.0.0.1
|
||||
port = 8084
|
||||
inbound.length = 6
|
||||
outbound.length = 3
|
||||
keys = forwarder-four
|
||||
|
||||
#[sam-forwarder-udp-client]
|
||||
#type = udpclient
|
||||
#host = 127.0.0.1
|
||||
#port = 8083
|
||||
#inbound.length = 3
|
||||
#outbound.length = 3
|
||||
#destination = i2p-projekt.i2p
|
||||
#keys = forwarder-three
|
||||
[sam-forwarder-udp-client]
|
||||
type = udpclient
|
||||
host = 127.0.0.1
|
||||
port = 8083
|
||||
inbound.length = 3
|
||||
outbound.length = 3
|
||||
destination = i2p-projekt.i2p
|
||||
keys = forwarder-three
|
||||
|
||||
#[sam-forwarder-tcp-http-server]
|
||||
#type = http
|
||||
#host = 127.0.0.1
|
||||
#port = 8085
|
||||
#inbound.length = 3
|
||||
#outbound.length = 3
|
||||
#keys = forwarder-five
|
||||
[sam-forwarder-tcp-http-server]
|
||||
type = http
|
||||
host = 127.0.0.1
|
||||
port = 8085
|
||||
inbound.length = 3
|
||||
outbound.length = 3
|
||||
keys = forwarder-five
|
||||
|
||||
#[sam-forwarder-vpn-server]
|
||||
#type = udpserver
|
||||
|
@ -3,6 +3,7 @@ package samtunnelhandler
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
import (
|
||||
@ -14,26 +15,35 @@ type TunnelHandler struct {
|
||||
}
|
||||
|
||||
func (t *TunnelHandler) Printdivf(id, key, value string, rw http.ResponseWriter, req *http.Request) {
|
||||
if req.FormValue("color") == "true" {
|
||||
fmt.Fprintf(rw, " <div id=\"%s\" class=\"%s\" >\n", t.SAMTunnel.ID()+"."+id, t.SAMTunnel.ID())
|
||||
fmt.Fprintf(rw, " <div id=\"%s\" class=\"key\">%s</div>=", t.SAMTunnel.ID()+"."+id, key)
|
||||
fmt.Fprintf(rw, " <div id=\"%s\" class=\"value\">%s</div>\n", t.SAMTunnel.ID()+"."+id, value)
|
||||
fmt.Fprintf(rw, " </div>\n")
|
||||
if key == "" || value == "" {
|
||||
return
|
||||
}
|
||||
ID := t.SAMTunnel.ID()
|
||||
if id != "" {
|
||||
ID = t.SAMTunnel.ID() + "." + id
|
||||
}
|
||||
if strings.HasSuffix(req.URL.Path, "color") {
|
||||
fmt.Fprintf(rw, " <div id=\"%s\" class=\"%s %s %s\" >\n", ID, t.SAMTunnel.ID(), key, t.SAMTunnel.GetType())
|
||||
fmt.Fprintf(rw, " <span id=\"%s\" class=\"key\">%s</span>=", ID, key)
|
||||
fmt.Fprintf(rw, " <span id=\"%s\" class=\"value\">%s</span>\n", ID, value)
|
||||
fmt.Fprintf(rw, " </div>\n\n")
|
||||
} else {
|
||||
fmt.Fprintf(rw, "%s=%s", t.SAMTunnel.ID()+"."+id, t.SAMTunnel.ID())
|
||||
fmt.Fprintf(rw, "%s=%s\n", ID, t.SAMTunnel.ID())
|
||||
}
|
||||
}
|
||||
|
||||
func (t *TunnelHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
|
||||
if req.FormValue("color") == "true" {
|
||||
if strings.HasSuffix(req.URL.Path, "color") {
|
||||
fmt.Fprintf(rw, " <div id=\"%s\" class=\"%s\" >", t.SAMTunnel.ID(), t.SAMTunnel.GetType())
|
||||
}
|
||||
t.Printdivf(t.SAMTunnel.ID(), "TunName", t.SAMTunnel.ID(), rw, req)
|
||||
for key, value := range t.SAMTunnel.Props() {
|
||||
t.Printdivf(key, key, value, rw, req)
|
||||
if key != "TunName" {
|
||||
t.Printdivf(key, key, value, rw, req)
|
||||
}
|
||||
}
|
||||
if req.FormValue("color") == "true" {
|
||||
fmt.Fprintf(rw, " </div>")
|
||||
if strings.HasSuffix(req.URL.Path, "color") {
|
||||
fmt.Fprintf(rw, " </div>\n\n")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -81,8 +81,8 @@ func Load(FilePath, TunName, passfile string, samConn *sam3.SAM, save bool) (i2p
|
||||
}
|
||||
|
||||
func Prop(in string) (string, string) {
|
||||
k := "unset"
|
||||
v := "unset"
|
||||
k := ""
|
||||
v := ""
|
||||
vals := strings.SplitN(in, "=", 2)
|
||||
if len(vals) >= 1 {
|
||||
k = vals[0]
|
||||
|
@ -34,6 +34,22 @@ func SetManagerHost(s string) func(*SAMManager) error {
|
||||
}
|
||||
}
|
||||
|
||||
//SetManagerWebUser sets the host of the SAMManager's SAM bridge
|
||||
func SetManagerWebUser(s string) func(*SAMManager) error {
|
||||
return func(c *SAMManager) error {
|
||||
c.config.UserName = s
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
//SetManagerWebPass sets the host of the SAMManager's SAM bridge
|
||||
func SetManagerWebPass(s string) func(*SAMManager) error {
|
||||
return func(c *SAMManager) error {
|
||||
c.config.Password = s
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
//SetManagerPort sets the port of the SAMManager's SAM bridge using a string
|
||||
func SetManagerPort(s string) func(*SAMManager) error {
|
||||
return func(c *SAMManager) error {
|
||||
@ -111,6 +127,14 @@ func SetManagerStart(s bool) func(*SAMManager) error {
|
||||
}
|
||||
}
|
||||
|
||||
//SetManagerWeb sets the host of the SAMManager's SAM bridge
|
||||
func SetManagerWeb(s bool) func(*SAMManager) error {
|
||||
return func(c *SAMManager) error {
|
||||
c.UseWeb = s
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
//SetTunName sets the host of the SAMManager's SAM bridge
|
||||
func SetTunName(s string) func(*SAMManager) error {
|
||||
return func(c *SAMManager) error {
|
||||
|
@ -3,6 +3,9 @@ package sammanager
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"os/signal"
|
||||
"time"
|
||||
)
|
||||
|
||||
import (
|
||||
@ -22,27 +25,43 @@ type SAMManager struct {
|
||||
ServerPort string
|
||||
SamHost string
|
||||
SamPort string
|
||||
useWeb bool
|
||||
UseWeb bool
|
||||
WebHost string
|
||||
WebPort string
|
||||
|
||||
tunnels []*samtunnelhandler.TunnelHandler
|
||||
cssFile string
|
||||
jsFile string
|
||||
|
||||
handlerMux *samtunnelhandler.TunnelHandlerMux
|
||||
}
|
||||
|
||||
func (s *SAMManager) Cleanup() {
|
||||
for _, k := range s.tunnels {
|
||||
for _, k := range s.handlerMux.Tunnels() {
|
||||
k.Cleanup()
|
||||
}
|
||||
}
|
||||
|
||||
func (s *SAMManager) Serve() bool {
|
||||
log.Println("Starting tunnels")
|
||||
for _, element := range s.tunnels {
|
||||
log.Println("Starting Tunnels()")
|
||||
for _, element := range s.handlerMux.Tunnels() {
|
||||
log.Println("Starting service tunnel", element.ID())
|
||||
go element.Serve()
|
||||
}
|
||||
for true {
|
||||
|
||||
if s.UseWeb == true {
|
||||
go s.handlerMux.ListenAndServe()
|
||||
}
|
||||
Close := false
|
||||
for !Close {
|
||||
time.Sleep(1 * time.Second)
|
||||
c := make(chan os.Signal, 1)
|
||||
signal.Notify(c, os.Interrupt)
|
||||
go func() {
|
||||
for sig := range c {
|
||||
log.Println(sig)
|
||||
Close = true
|
||||
}
|
||||
}()
|
||||
}
|
||||
return false
|
||||
}
|
||||
@ -52,7 +71,7 @@ func NewSAMManagerFromOptions(opts ...func(*SAMManager) error) (*SAMManager, err
|
||||
s.FilePath = ""
|
||||
s.save = true
|
||||
s.start = false
|
||||
s.useWeb = false
|
||||
s.UseWeb = true
|
||||
s.config = i2ptunconf.NewI2PBlankTunConf()
|
||||
s.ServerHost = "localhost"
|
||||
s.ServerPort = "8081"
|
||||
@ -61,11 +80,16 @@ func NewSAMManagerFromOptions(opts ...func(*SAMManager) error) (*SAMManager, err
|
||||
s.WebHost = "localhost"
|
||||
s.WebPort = "7957"
|
||||
s.tunName = "samcatd-"
|
||||
s.config.UserName = "samcatd"
|
||||
s.config.Password = ""
|
||||
s.cssFile = ""
|
||||
s.jsFile = ""
|
||||
for _, o := range opts {
|
||||
if err := o(&s); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
s.handlerMux = samtunnelhandler.NewTunnelHandlerMux(s.WebHost, s.WebPort, s.config.UserName, s.config.Password, s.cssFile, s.jsFile)
|
||||
log.Println("tunnel settings", s.ServerHost, s.ServerPort, s.SamHost, s.SamPort)
|
||||
var err error
|
||||
if s.FilePath != "" {
|
||||
@ -87,42 +111,42 @@ func NewSAMManagerFromOptions(opts ...func(*SAMManager) error) (*SAMManager, err
|
||||
case "http":
|
||||
if f, e := samtunnelhandler.NewTunnelHandler(i2ptunconf.NewSAMForwarderFromConfig(s.FilePath, s.SamHost, s.SamPort, label)); e == nil {
|
||||
log.Println("found http under", label)
|
||||
s.tunnels = append(s.tunnels, f)
|
||||
s.handlerMux = s.handlerMux.Append(f)
|
||||
} else {
|
||||
return nil, e
|
||||
}
|
||||
case "server":
|
||||
if f, e := samtunnelhandler.NewTunnelHandler(i2ptunconf.NewSAMForwarderFromConfig(s.FilePath, s.SamHost, s.SamPort, label)); e == nil {
|
||||
log.Println("found server under", label)
|
||||
s.tunnels = append(s.tunnels, f)
|
||||
s.handlerMux = s.handlerMux.Append(f)
|
||||
} else {
|
||||
return nil, e
|
||||
}
|
||||
case "client":
|
||||
if f, e := samtunnelhandler.NewTunnelHandler(i2ptunconf.NewSAMClientForwarderFromConfig(s.FilePath, s.SamHost, s.SamPort, label)); e == nil {
|
||||
log.Println("found client under", label)
|
||||
s.tunnels = append(s.tunnels, f)
|
||||
s.handlerMux = s.handlerMux.Append(f)
|
||||
} else {
|
||||
return nil, e
|
||||
}
|
||||
case "udpserver":
|
||||
if f, e := samtunnelhandler.NewTunnelHandler(i2ptunconf.NewSAMSSUForwarderFromConfig(s.FilePath, s.SamHost, s.SamPort, label)); e == nil {
|
||||
log.Println("found udpserver under", label)
|
||||
s.tunnels = append(s.tunnels, f)
|
||||
s.handlerMux = s.handlerMux.Append(f)
|
||||
} else {
|
||||
return nil, e
|
||||
}
|
||||
case "udpclient":
|
||||
if f, e := samtunnelhandler.NewTunnelHandler(i2ptunconf.NewSAMSSUClientForwarderFromConfig(s.FilePath, s.SamHost, s.SamPort, label)); e == nil {
|
||||
log.Println("found udpclient under", label)
|
||||
s.tunnels = append(s.tunnels, f)
|
||||
s.handlerMux = s.handlerMux.Append(f)
|
||||
} else {
|
||||
return nil, e
|
||||
}
|
||||
default:
|
||||
if f, e := samtunnelhandler.NewTunnelHandler(i2ptunconf.NewSAMForwarderFromConfig(s.FilePath, s.SamHost, s.SamPort, label)); e == nil {
|
||||
log.Println("found server under", label)
|
||||
s.tunnels = append(s.tunnels, f)
|
||||
s.handlerMux = s.handlerMux.Append(f)
|
||||
} else {
|
||||
return nil, e
|
||||
}
|
||||
@ -139,55 +163,51 @@ func NewSAMManagerFromOptions(opts ...func(*SAMManager) error) (*SAMManager, err
|
||||
case "http":
|
||||
if f, e := samtunnelhandler.NewTunnelHandler(i2ptunconf.NewSAMForwarderFromConfig(s.FilePath, s.SamHost, s.SamPort)); e == nil {
|
||||
log.Println("found default http")
|
||||
s.tunnels = append(s.tunnels, f)
|
||||
s.handlerMux = s.handlerMux.Append(f)
|
||||
} else {
|
||||
return nil, e
|
||||
}
|
||||
case "server":
|
||||
if f, e := samtunnelhandler.NewTunnelHandler(i2ptunconf.NewSAMForwarderFromConfig(s.FilePath, s.SamHost, s.SamPort)); e == nil {
|
||||
log.Println("found default server")
|
||||
s.tunnels = append(s.tunnels, f)
|
||||
s.handlerMux = s.handlerMux.Append(f)
|
||||
} else {
|
||||
return nil, e
|
||||
}
|
||||
case "client":
|
||||
if f, e := samtunnelhandler.NewTunnelHandler(i2ptunconf.NewSAMClientForwarderFromConfig(s.FilePath, s.SamHost, s.SamPort)); e == nil {
|
||||
log.Println("found default client")
|
||||
s.tunnels = append(s.tunnels, f)
|
||||
s.handlerMux = s.handlerMux.Append(f)
|
||||
} else {
|
||||
return nil, e
|
||||
}
|
||||
case "udpserver":
|
||||
if f, e := samtunnelhandler.NewTunnelHandler(i2ptunconf.NewSAMSSUForwarderFromConfig(s.FilePath, s.SamHost, s.SamPort)); e == nil {
|
||||
log.Println("found default udpserver")
|
||||
s.tunnels = append(s.tunnels, f)
|
||||
s.handlerMux = s.handlerMux.Append(f)
|
||||
} else {
|
||||
return nil, e
|
||||
}
|
||||
case "udpclient":
|
||||
if f, e := samtunnelhandler.NewTunnelHandler(i2ptunconf.NewSAMSSUClientForwarderFromConfig(s.FilePath, s.SamHost, s.SamPort)); e == nil {
|
||||
log.Println("found default udpclient")
|
||||
s.tunnels = append(s.tunnels, f)
|
||||
s.handlerMux = s.handlerMux.Append(f)
|
||||
} else {
|
||||
return nil, e
|
||||
}
|
||||
default:
|
||||
if f, e := samtunnelhandler.NewTunnelHandler(i2ptunconf.NewSAMClientForwarderFromConfig(s.FilePath, s.SamHost, s.SamPort)); e == nil {
|
||||
log.Println("found default client")
|
||||
s.tunnels = append(s.tunnels, f)
|
||||
s.handlerMux = s.handlerMux.Append(f)
|
||||
} else {
|
||||
return nil, e
|
||||
}
|
||||
}
|
||||
}
|
||||
if s.useWeb == true {
|
||||
s.handlerMux = samtunnelhandler.NewTunnelHandlerMux(s.tunnels, s.WebHost, s.WebPort)
|
||||
go s.handlerMux.ListenAndServe()
|
||||
}
|
||||
return &s, nil
|
||||
}
|
||||
|
||||
func NewSAMManager(inifile, servhost, servport, samhost, samport, webhost, webport string, start bool) (*SAMManager, error) {
|
||||
func NewSAMManager(inifile, servhost, servport, samhost, samport, webhost, webport, cssfile, jsfile string, start, web bool, webuser, webpass string) (*SAMManager, error) {
|
||||
log.Println("tunnel settings", servhost, servport, samhost, samport)
|
||||
return NewSAMManagerFromOptions(
|
||||
SetManagerFilePath(inifile),
|
||||
@ -198,10 +218,13 @@ func NewSAMManager(inifile, servhost, servport, samhost, samport, webhost, webpo
|
||||
SetManagerWebHost(webhost),
|
||||
SetManagerWebPort(webport),
|
||||
SetManagerStart(start),
|
||||
SetManagerWebUser(webuser),
|
||||
SetManagerWebPass(webpass),
|
||||
SetManagerWeb(web),
|
||||
)
|
||||
}
|
||||
|
||||
func NewSAMManagerFromConf(conf *i2ptunconf.Conf, servhost, servport, samhost, samport, webhost, webport string, start bool) (*SAMManager, error) {
|
||||
func NewSAMManagerFromConf(conf *i2ptunconf.Conf, servhost, servport, samhost, samport, webhost, webport, cssfile, jsfile string, start, web bool, webuser, webpass string) (*SAMManager, error) {
|
||||
log.Println("tunnel settings", servhost, servport, samhost, samport)
|
||||
return NewSAMManagerFromOptions(
|
||||
SetManagerConf(conf),
|
||||
@ -212,5 +235,8 @@ func NewSAMManagerFromConf(conf *i2ptunconf.Conf, servhost, servport, samhost, s
|
||||
SetManagerWebHost(webhost),
|
||||
SetManagerWebPort(webport),
|
||||
SetManagerStart(start),
|
||||
SetManagerWebUser(webuser),
|
||||
SetManagerWebPass(webpass),
|
||||
SetManagerWeb(web),
|
||||
)
|
||||
}
|
||||
|
@ -21,61 +21,61 @@ func stringify(s []string) string {
|
||||
func (s *SAMManager) List(search ...string) *[]string {
|
||||
var r []string
|
||||
if search == nil {
|
||||
for index, element := range s.tunnels {
|
||||
for index, element := range s.handlerMux.Tunnels() {
|
||||
r = append(r, fmt.Sprintf(" %v. %s", index, element.Print()))
|
||||
}
|
||||
return &r
|
||||
} else if len(search) > 0 {
|
||||
switch search[0] {
|
||||
case "":
|
||||
for index, element := range s.tunnels {
|
||||
for index, element := range s.handlerMux.Tunnels() {
|
||||
r = append(r, fmt.Sprintf(" %v. %s", index, element.Print()))
|
||||
}
|
||||
return &r
|
||||
case "ntcpserver":
|
||||
for index, element := range s.tunnels {
|
||||
for index, element := range s.handlerMux.Tunnels() {
|
||||
r = append(r, fmt.Sprintf(" %v. %s", index, element.Search(stringify(search))))
|
||||
}
|
||||
return &r
|
||||
case "httpserver":
|
||||
for index, element := range s.tunnels {
|
||||
for index, element := range s.handlerMux.Tunnels() {
|
||||
if element.GetType() == "http" {
|
||||
r = append(r, fmt.Sprintf(" %v. %s", index, element.Search(stringify(search))))
|
||||
}
|
||||
}
|
||||
return &r
|
||||
case "ntcpclient":
|
||||
for index, element := range s.tunnels {
|
||||
for index, element := range s.handlerMux.Tunnels() {
|
||||
r = append(r, fmt.Sprintf(" %v. %s", index, element.Search(stringify(search))))
|
||||
}
|
||||
return &r
|
||||
case "ssuserver":
|
||||
for index, element := range s.tunnels {
|
||||
for index, element := range s.handlerMux.Tunnels() {
|
||||
r = append(r, fmt.Sprintf(" %v. %s", index, element.Search(stringify(search))))
|
||||
}
|
||||
return &r
|
||||
case "ssuclient":
|
||||
for index, element := range s.tunnels {
|
||||
for index, element := range s.handlerMux.Tunnels() {
|
||||
r = append(r, fmt.Sprintf(" %v. %s", index, element.Search(stringify(search))))
|
||||
}
|
||||
return &r
|
||||
default:
|
||||
for index, element := range s.tunnels {
|
||||
for index, element := range s.handlerMux.Tunnels() {
|
||||
if element.Search(stringify(search)) != "" {
|
||||
r = append(r, fmt.Sprintf(" %v. %s", index, element.Search(stringify(search))))
|
||||
}
|
||||
}
|
||||
for index, element := range s.tunnels {
|
||||
for index, element := range s.handlerMux.Tunnels() {
|
||||
if element.Search(stringify(search)) != "" {
|
||||
r = append(r, fmt.Sprintf(" %v. %s", index, element.Search(stringify(search))))
|
||||
}
|
||||
}
|
||||
for index, element := range s.tunnels {
|
||||
for index, element := range s.handlerMux.Tunnels() {
|
||||
if element.Search(stringify(search)) != "" {
|
||||
r = append(r, fmt.Sprintf(" %v. %s", index, element.Search(stringify(search))))
|
||||
}
|
||||
}
|
||||
for index, element := range s.tunnels {
|
||||
for index, element := range s.handlerMux.Tunnels() {
|
||||
if element.Search(stringify(search)) != "" {
|
||||
r = append(r, fmt.Sprintf(" %v. %s", index, element.Search(stringify(search))))
|
||||
}
|
||||
|
@ -99,7 +99,7 @@ func (f *SAMClientForwarder) print() []string {
|
||||
"i2cp.reduceQuantity=" + f.reduceIdleQuantity,
|
||||
"i2cp.closeOnIdle=" + f.closeIdle,
|
||||
"i2cp.closeIdleTime=" + f.closeIdleTime,
|
||||
"i2cp.messageReliability" + f.messageReliability,
|
||||
"i2cp.messageReliability=" + f.messageReliability,
|
||||
"i2cp.encryptLeaseSet=" + f.encryptLeaseSet,
|
||||
lsk, lspk, lspsk,
|
||||
f.accesslisttype(),
|
||||
@ -108,7 +108,7 @@ func (f *SAMClientForwarder) print() []string {
|
||||
}
|
||||
|
||||
func (f *SAMClientForwarder) Props() map[string]string {
|
||||
var r map[string]string
|
||||
r := make(map[string]string)
|
||||
for _, prop := range f.print() {
|
||||
k, v := sfi2pkeys.Prop(prop)
|
||||
r[k] = v
|
||||
|
@ -125,7 +125,7 @@ func (f *SAMForwarder) print() []string {
|
||||
"i2cp.reduceQuantity=" + f.reduceIdleQuantity,
|
||||
"i2cp.closeOnIdle=" + f.closeIdle,
|
||||
"i2cp.closeIdleTime=" + f.closeIdleTime,
|
||||
"i2cp.messageReliability" + f.messageReliability,
|
||||
"i2cp.messageReliability=" + f.messageReliability,
|
||||
"i2cp.encryptLeaseSet=" + f.encryptLeaseSet,
|
||||
lsk, lspk, lspsk,
|
||||
f.accesslisttype(),
|
||||
@ -134,7 +134,7 @@ func (f *SAMForwarder) print() []string {
|
||||
}
|
||||
|
||||
func (f *SAMForwarder) Props() map[string]string {
|
||||
var r map[string]string
|
||||
r := make(map[string]string)
|
||||
for _, prop := range f.print() {
|
||||
k, v := sfi2pkeys.Prop(prop)
|
||||
r[k] = v
|
||||
|
@ -110,7 +110,7 @@ func (f *SAMSSUClientForwarder) print() []string {
|
||||
"i2cp.reduceQuantity=" + f.reduceIdleQuantity,
|
||||
"i2cp.closeOnIdle=" + f.closeIdle,
|
||||
"i2cp.closeIdleTime=" + f.closeIdleTime,
|
||||
"i2cp.messageReliability" + f.messageReliability,
|
||||
"i2cp.messageReliability=" + f.messageReliability,
|
||||
"i2cp.encryptLeaseSet=" + f.encryptLeaseSet,
|
||||
lsk, lspk, lspsk,
|
||||
f.accesslisttype(),
|
||||
@ -119,7 +119,7 @@ func (f *SAMSSUClientForwarder) print() []string {
|
||||
}
|
||||
|
||||
func (f *SAMSSUClientForwarder) Props() map[string]string {
|
||||
var r map[string]string
|
||||
r := make(map[string]string)
|
||||
for _, prop := range f.print() {
|
||||
k, v := sfi2pkeys.Prop(prop)
|
||||
r[k] = v
|
||||
|
@ -110,7 +110,7 @@ func (f *SAMSSUForwarder) print() []string {
|
||||
"i2cp.reduceQuantity=" + f.reduceIdleQuantity,
|
||||
"i2cp.closeOnIdle=" + f.closeIdle,
|
||||
"i2cp.closeIdleTime=" + f.closeIdleTime,
|
||||
"i2cp.messageReliability" + f.messageReliability,
|
||||
"i2cp.messageReliability=" + f.messageReliability,
|
||||
"i2cp.encryptLeaseSet=" + f.encryptLeaseSet,
|
||||
lsk, lspk, lspsk,
|
||||
f.accesslisttype(),
|
||||
@ -119,7 +119,7 @@ func (f *SAMSSUForwarder) print() []string {
|
||||
}
|
||||
|
||||
func (f *SAMSSUForwarder) Props() map[string]string {
|
||||
var r map[string]string
|
||||
r := make(map[string]string)
|
||||
for _, prop := range f.print() {
|
||||
k, v := sfi2pkeys.Prop(prop)
|
||||
r[k] = v
|
||||
|
Reference in New Issue
Block a user