onward
This commit is contained in:
parent
92f8b42706
commit
09e7dfbb2b
10
http.go
10
http.go
|
@ -8,6 +8,7 @@ import (
|
|||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"go.wit.com/log"
|
||||
|
@ -48,6 +49,7 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
/*
|
||||
if route == "/list" {
|
||||
all := me.portmaps.All()
|
||||
for all.Scan() {
|
||||
|
@ -61,6 +63,7 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
return
|
||||
}
|
||||
*/
|
||||
|
||||
if route == "/save" {
|
||||
log.Info("event log is len =", me.events.Len())
|
||||
|
@ -71,14 +74,17 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
|
|||
if route == "/enable" {
|
||||
log.HttpMode(w)
|
||||
defer log.HttpMode(nil)
|
||||
log.Info("enable port/dest", port, dest)
|
||||
num, _ := strconv.Atoi(port)
|
||||
log.Info("enable port =", num, "dest =", dest)
|
||||
enablePort(num, dest)
|
||||
return
|
||||
}
|
||||
|
||||
if route == "/disable" {
|
||||
log.HttpMode(w)
|
||||
defer log.HttpMode(nil)
|
||||
log.Info("enable port/dest", port, dest)
|
||||
num, _ := strconv.Atoi(port)
|
||||
log.Info("disable port =", num, "dest =", dest)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
30
main.go
30
main.go
|
@ -43,7 +43,7 @@ func main() {
|
|||
if me.portmaps == nil {
|
||||
me.portmaps = NewPortmaps()
|
||||
p := new(Portmap)
|
||||
p.Connect = "testing:323"
|
||||
p.Dest = "testing:323"
|
||||
me.portmaps.Append(p)
|
||||
}
|
||||
|
||||
|
@ -61,7 +61,7 @@ func main() {
|
|||
if !pm.Enabled {
|
||||
continue
|
||||
}
|
||||
log.Info("portmap enabled for port", pm.Listen, "to", pm.Connect)
|
||||
log.Info("portmap enabled for port", pm.Localport, "to", pm.Dest)
|
||||
go gus3000(pm)
|
||||
}
|
||||
startHTTP()
|
||||
|
@ -74,7 +74,7 @@ func main() {
|
|||
if !pm.Enabled {
|
||||
continue
|
||||
}
|
||||
log.Info("portmap enabled for port", pm.Listen, "to", pm.Connect)
|
||||
log.Info("portmap enabled for port", pm.Localport, "to", pm.Dest)
|
||||
go gus3000(pm)
|
||||
}
|
||||
// go NewWatchdog()
|
||||
|
@ -84,8 +84,8 @@ func main() {
|
|||
|
||||
// func doME(pm *Portmap, gus listener.Accept) {
|
||||
func doME(pm *Portmap, gus net.Listener) {
|
||||
localport := int(pm.Listen)
|
||||
where := pm.Connect
|
||||
localport := int(pm.Localport)
|
||||
where := pm.Dest
|
||||
|
||||
/*
|
||||
// Listen on local port 3000
|
||||
|
@ -113,8 +113,8 @@ func doME(pm *Portmap, gus net.Listener) {
|
|||
}
|
||||
|
||||
func gus3000(pm *Portmap) {
|
||||
port := int(pm.Listen)
|
||||
connect := pm.Connect
|
||||
port := int(pm.Localport)
|
||||
connect := pm.Dest
|
||||
|
||||
// Listen on local port 3000
|
||||
s := fmt.Sprintf("0.0.0.0:%d", port)
|
||||
|
@ -177,3 +177,19 @@ func handleConnection(clientConn net.Conn, where string, localport int) {
|
|||
me.eventsChanged = true
|
||||
log.Printf("Connection closed on port %d from client: %s to where = %s\n", localport, clientConn.RemoteAddr(), where)
|
||||
}
|
||||
|
||||
func enablePort(port int, dest string) {
|
||||
all := me.portmaps.All()
|
||||
for all.Scan() {
|
||||
pm := all.Next()
|
||||
if int(pm.Localport) == port {
|
||||
log.Info("Found port!", port)
|
||||
}
|
||||
if pm.Enabled {
|
||||
log.Info("portmap already enabled for", pm.Localport, "to", pm.Dest)
|
||||
} else {
|
||||
log.Info("portmap not enabled for", pm.Localport, "to", pm.Dest)
|
||||
}
|
||||
// go gus3000(pm)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,8 +3,8 @@ syntax = "proto3";
|
|||
package gus;
|
||||
|
||||
message Portmap {
|
||||
int64 listen = 1; // `autogenpb:unique`
|
||||
string connect = 2;
|
||||
int64 localport = 1; // `autogenpb:unique`
|
||||
string dest = 2;
|
||||
bool enabled = 3;
|
||||
bool allowIPv4 = 4;
|
||||
bool useME = 5;
|
||||
|
|
|
@ -42,7 +42,7 @@ func doMachinesUpgradeTable() {
|
|||
// display the protobuf
|
||||
me.portwin.TB = AddMachinesPB(me.portwin.box, me.portmaps)
|
||||
f := func(m *Portmap) {
|
||||
log.Info("Triggering machine", m.Connect, "to upgrade portwin")
|
||||
log.Info("Triggering machine", m.Dest, "to upgrade portwin")
|
||||
m.Enabled = true
|
||||
}
|
||||
me.portwin.TB.Custom(f)
|
||||
|
@ -55,7 +55,7 @@ func AddMachinesPB(tbox *gui.Node, pb *Portmaps) *PortmapsTable {
|
|||
t.SetParent(tbox)
|
||||
|
||||
editf := func(m *Portmap) string {
|
||||
log.Info("machine =", m.Connect)
|
||||
log.Info("machine =", m.Dest)
|
||||
return "edit"
|
||||
}
|
||||
t.AddButtonFunc("edit", editf)
|
||||
|
@ -78,8 +78,8 @@ func AddMachinesPB(tbox *gui.Node, pb *Portmaps) *PortmapsTable {
|
|||
}
|
||||
t.AddStringFunc("enabled", enabledf)
|
||||
|
||||
t.AddListen()
|
||||
t.AddConnect()
|
||||
t.AddLocalport()
|
||||
t.AddDest()
|
||||
t.ShowTable()
|
||||
return t
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue