|
|
@ -35,7 +35,7 @@ func (n *NetForward) Close() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (n *NetForward) Status() int32 {
|
|
|
|
func (n *NetForward) Status() int32 {
|
|
|
|
return n.running
|
|
|
|
return atomic.LoadInt32(&n.running)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (n *NetForward) Run() error {
|
|
|
|
func (n *NetForward) Run() error {
|
|
|
@ -48,61 +48,63 @@ func (n *NetForward) Run() error {
|
|
|
|
n.DialTimeout = time.Second * 5
|
|
|
|
n.DialTimeout = time.Second * 5
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if n.StdinMode {
|
|
|
|
if n.StdinMode {
|
|
|
|
breakfor:
|
|
|
|
go func() {
|
|
|
|
for {
|
|
|
|
for {
|
|
|
|
cmd := strings.TrimSpace(stario.MessageBoxRaw("", "").MustString())
|
|
|
|
cmd := strings.TrimSpace(stario.MessageBox("", "").MustString())
|
|
|
|
for strings.Contains(cmd, " ") {
|
|
|
|
for strings.Contains(cmd, " ") {
|
|
|
|
cmd = strings.Replace(cmd, " ", " ", -1)
|
|
|
|
cmd = strings.Replace(cmd, " ", " ", -1)
|
|
|
|
}
|
|
|
|
|
|
|
|
cmds := strings.Split(cmd, " ")
|
|
|
|
|
|
|
|
if len(cmds) < 3 {
|
|
|
|
|
|
|
|
starlog.Errorln("Invalid Command", cmd)
|
|
|
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
switch cmds[0] + cmds[1] {
|
|
|
|
|
|
|
|
case "setremote":
|
|
|
|
|
|
|
|
n.RemoteURI = cmds[2]
|
|
|
|
|
|
|
|
starlog.Noticef("Remote URI Set to %s\n", n.RemoteURI)
|
|
|
|
|
|
|
|
case "setdelaytoward":
|
|
|
|
|
|
|
|
tmp, err := strconv.Atoi(cmds[2])
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
starlog.Errorln("Invalid Delay Toward Value", cmds[2])
|
|
|
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
n.DelayToward = tmp
|
|
|
|
|
|
|
|
starlog.Noticef("Delay Toward Set to %d\n", n.DelayToward)
|
|
|
|
|
|
|
|
case "setdelay":
|
|
|
|
|
|
|
|
tmp, err := strconv.Atoi(cmds[2])
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
starlog.Errorln("Invalid Delay Value", cmds[2])
|
|
|
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
n.DelayMilSec = tmp
|
|
|
|
|
|
|
|
starlog.Noticef("Delay Set to %d\n", n.DelayMilSec)
|
|
|
|
|
|
|
|
case "setdialtimeout":
|
|
|
|
|
|
|
|
tmp, err := strconv.Atoi(cmds[2])
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
starlog.Errorln("Invalid Dial Timeout Value", cmds[2])
|
|
|
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
n.DialTimeout = time.Millisecond * time.Duration(tmp)
|
|
|
|
starlog.Debugf("Recv Command %s\n", cmd)
|
|
|
|
starlog.Noticef("Dial Timeout Set to %d\n", n.DialTimeout)
|
|
|
|
cmds := strings.Split(cmd, " ")
|
|
|
|
case "setudptimeout":
|
|
|
|
if len(cmds) < 3 {
|
|
|
|
tmp, err := strconv.Atoi(cmds[2])
|
|
|
|
starlog.Errorln("Invalid Command", cmd)
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
starlog.Errorln("Invalid UDP Timeout Value", cmds[2])
|
|
|
|
|
|
|
|
continue
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
n.UDPTimeout = time.Millisecond * time.Duration(tmp)
|
|
|
|
switch cmds[0] + cmds[1] {
|
|
|
|
starlog.Noticef("UDP Timeout Set to %d\n", n.UDPTimeout)
|
|
|
|
case "setremote":
|
|
|
|
case "setstdin":
|
|
|
|
n.RemoteURI = cmds[2]
|
|
|
|
if cmds[2] == "off" {
|
|
|
|
starlog.Noticef("Remote URI Set to %s\n", n.RemoteURI)
|
|
|
|
n.StdinMode = false
|
|
|
|
case "setdelaytoward":
|
|
|
|
starlog.Noticef("Stdin Mode Off\n")
|
|
|
|
tmp, err := strconv.Atoi(cmds[2])
|
|
|
|
break breakfor
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
starlog.Errorln("Invalid Delay Toward Value", cmds[2])
|
|
|
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
n.DelayToward = tmp
|
|
|
|
|
|
|
|
starlog.Noticef("Delay Toward Set to %d\n", n.DelayToward)
|
|
|
|
|
|
|
|
case "setdelay":
|
|
|
|
|
|
|
|
tmp, err := strconv.Atoi(cmds[2])
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
starlog.Errorln("Invalid Delay Value", cmds[2])
|
|
|
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
n.DelayMilSec = tmp
|
|
|
|
|
|
|
|
starlog.Noticef("Delay Set to %d\n", n.DelayMilSec)
|
|
|
|
|
|
|
|
case "setdialtimeout":
|
|
|
|
|
|
|
|
tmp, err := strconv.Atoi(cmds[2])
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
starlog.Errorln("Invalid Dial Timeout Value", cmds[2])
|
|
|
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
n.DialTimeout = time.Millisecond * time.Duration(tmp)
|
|
|
|
|
|
|
|
starlog.Noticef("Dial Timeout Set to %d\n", n.DialTimeout)
|
|
|
|
|
|
|
|
case "setudptimeout":
|
|
|
|
|
|
|
|
tmp, err := strconv.Atoi(cmds[2])
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
starlog.Errorln("Invalid UDP Timeout Value", cmds[2])
|
|
|
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
n.UDPTimeout = time.Millisecond * time.Duration(tmp)
|
|
|
|
|
|
|
|
starlog.Noticef("UDP Timeout Set to %d\n", n.UDPTimeout)
|
|
|
|
|
|
|
|
case "setstdin":
|
|
|
|
|
|
|
|
if cmds[2] == "off" {
|
|
|
|
|
|
|
|
n.StdinMode = false
|
|
|
|
|
|
|
|
starlog.Noticef("Stdin Mode Off\n")
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if n.EnableTCP {
|
|
|
|
if n.EnableTCP {
|
|
|
|
go n.runTCP()
|
|
|
|
go n.runTCP()
|
|
|
@ -148,7 +150,7 @@ func (n *NetForward) runTCP() error {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
log.Infof("TCP Connect %s <==> %s\n", conn.RemoteAddr().String(), rmt.RemoteAddr().String())
|
|
|
|
log.Infof("TCP Connect %s <==> %s\n", conn.RemoteAddr().String(), rmt.RemoteAddr().String())
|
|
|
|
n.copy(rmt, conn)
|
|
|
|
n.copy(rmt, conn)
|
|
|
|
log.Noticef("TCP Connection Closed %s <==> %s", conn.RemoteAddr().String(), n.RemoteURI)
|
|
|
|
log.Noticef("TCP Connection Closed %s <==> %s\n", conn.RemoteAddr().String(), n.RemoteURI)
|
|
|
|
}(conn)
|
|
|
|
}(conn)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|