fixed stuff

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-01-03 12:40:31 -06:00
parent f332c0eaf6
commit 3be643036f
5 changed files with 59 additions and 57 deletions

3
.gitignore vendored
View File

@ -4,5 +4,4 @@ control-panel-dns
*.swp *.swp
/plugins/* /plugins/*
examples/control-panel-digitalocean/control-panel-digitalocean control-panel-dns
examples/control-panel-cloudflare/control-panel-cloudflare

View File

@ -18,9 +18,10 @@ import (
"time" "time"
"strconv" "strconv"
"reflect" "reflect"
"errors"
"go.wit.com/log" "go.wit.com/log"
"go.wit.com/gui" "go.wit.com/gui/gui"
"go.wit.com/gui/gadgets" "go.wit.com/gui/gadgets"
"go.wit.com/shell" "go.wit.com/shell"
@ -127,7 +128,7 @@ func NewDigStatusWindow(p *gui.Node) *digStatus {
func (ds *digStatus) Update() { func (ds *digStatus) Update() {
log.Info("digStatus() Update() START") log.Info("digStatus() Update() START")
if ds == nil { if ds == nil {
log.Error("digStatus() Update() ds == nil") log.Error(errors.New("digStatus() Update() ds == nil"))
return return
} }
duration := timeFunction(func () { duration := timeFunction(func () {
@ -206,7 +207,7 @@ func (ds *digStatus) set(a any, s string) {
ol.Set(s) ol.Set(s)
return return
} }
log.Error("unknown type TypeOf(a) =", reflect.TypeOf(a), "a =", a) log.Warn("unknown type TypeOf(a) =", reflect.TypeOf(a), "a =", a)
os.Exit(0) os.Exit(0)
} }
@ -216,12 +217,12 @@ func (ds *digStatus) updateDnsStatus() {
log.Info("updateDnsStatus() START") log.Info("updateDnsStatus() START")
if (ds == nil) { if (ds == nil) {
log.Error("updateDnsStatus() not initialized yet. ds == nil") log.Error(errors.New("updateDnsStatus() not initialized yet. ds == nil"))
return return
} }
if (! ds.ready) { if (! ds.ready) {
log.Error("updateDnsStatus() not ready yet") log.Error(errors.New("updateDnsStatus() not ready yet"))
return return
} }

View File

@ -7,7 +7,7 @@ import (
"go.wit.com/log" "go.wit.com/log"
"go.wit.com/shell" "go.wit.com/shell"
"go.wit.com/control-panel-dns/cloudflare" "go.wit.com/gui/cloudflare"
"github.com/miekg/dns" "github.com/miekg/dns"
// will try to get this hosts FQDN // will try to get this hosts FQDN

4
log.go
View File

@ -3,7 +3,7 @@ package main
import ( import (
"log" "log"
"reflect" "reflect"
witlog "go.wit.com/gui/log" witlog "go.wit.com/log"
) )
var LogPrefix = "ipv6cp" // ipv6 control panel debugging line var LogPrefix = "ipv6cp" // ipv6 control panel debugging line
@ -19,7 +19,7 @@ var LogNet bool = false // general network debugging
var LogProc bool = false // turn on /proc debugging output var LogProc bool = false // turn on /proc debugging output
var LogExec bool = false // turn on os.Exec() debugging var LogExec bool = false // turn on os.Exec() debugging
var SPEW witlog.Spewt // var SPEW witlog.Spewt
// var log interface{} // var log interface{}

96
net.go
View File

@ -5,6 +5,8 @@ import (
// "log" // "log"
"net" "net"
"strings" "strings"
"go.wit.com/log"
) )
// this doesn't work // this doesn't work
@ -16,21 +18,21 @@ func watchNetworkInterfaces() {
// Set up a notification channel // Set up a notification channel
notification := make(chan net.Interface) notification := make(chan net.Interface)
debug(LogNet, "watchNet()") log.Log(NET, "watchNet()")
// Start goroutine to watch for changes // Start goroutine to watch for changes
go func() { go func() {
debug(LogNet, "watchNet() func") log.Log(NET, "watchNet() func")
for { for {
debug(LogNet, "forever loop start") log.Log(NET, "forever loop start")
// Check for changes in each interface // Check for changes in each interface
for _, i := range interfaces { for _, i := range interfaces {
debug(LogNet, "something on i =", i) log.Log(NET, "something on i =", i)
if status := i.Flags & net.FlagUp; status != 0 { if status := i.Flags & net.FlagUp; status != 0 {
notification <- i notification <- i
debug(LogNet, "something on i =", i) log.Log(NET, "something on i =", i)
} }
} }
debug(LogNet, "forever loop end") log.Log(NET, "forever loop end")
} }
}() }()
} }
@ -42,20 +44,20 @@ func IsIPv6(address string) bool {
func (t *IPtype) IsReal() bool { func (t *IPtype) IsReal() bool {
if (t.ip.IsPrivate() || t.ip.IsLoopback() || t.ip.IsLinkLocalUnicast()) { if (t.ip.IsPrivate() || t.ip.IsLoopback() || t.ip.IsLinkLocalUnicast()) {
debug(LogNet, "\t\tIP is Real = false") log.Log(NET, "\t\tIP is Real = false")
return false return false
} else { } else {
debug(LogNet, "\t\tIP is Real = true") log.Log(NET, "\t\tIP is Real = true")
return true return true
} }
} }
func IsReal(ip *net.IP) bool { func IsReal(ip *net.IP) bool {
if (ip.IsPrivate() || ip.IsLoopback() || ip.IsLinkLocalUnicast()) { if (ip.IsPrivate() || ip.IsLoopback() || ip.IsLinkLocalUnicast()) {
debug(LogNet, "\t\tIP is Real = false") log.Log(NET, "\t\tIP is Real = false")
return false return false
} else { } else {
debug(LogNet, "\t\tIP is Real = true") log.Log(NET, "\t\tIP is Real = true")
return true return true
} }
} }
@ -72,7 +74,7 @@ func renameInterface(i *net.Interface) {
func checkInterface(i net.Interface) { func checkInterface(i net.Interface) {
val, ok := me.ifmap[i.Index] val, ok := me.ifmap[i.Index]
if ! ok { if ! ok {
debug(i.Name, "is a new network interface. The linux kernel index =", i.Index) log.Info(i.Name, "is a new network interface. The linux kernel index =", i.Index)
me.ifmap[i.Index] = new(IFtype) me.ifmap[i.Index] = new(IFtype)
me.ifmap[i.Index].gone = false me.ifmap[i.Index].gone = false
me.ifmap[i.Index].iface = &i me.ifmap[i.Index].iface = &i
@ -84,9 +86,9 @@ func checkInterface(i net.Interface) {
return return
} }
me.ifmap[i.Index].gone = false me.ifmap[i.Index].gone = false
debug(LogNet, "me.ifmap[i] does exist. Need to compare everything.", i.Index, i.Name, val.iface.Index, val.iface.Name) log.Log(NET, "me.ifmap[i] does exist. Need to compare everything.", i.Index, i.Name, val.iface.Index, val.iface.Name)
if (val.iface.Name != i.Name) { if (val.iface.Name != i.Name) {
debug(val.iface.Name, "has changed to it's name to", i.Name) log.Info(val.iface.Name, "has changed to it's name to", i.Name)
me.ifmap[i.Index].iface = &i me.ifmap[i.Index].iface = &i
me.changed = true me.changed = true
if (me.Interfaces != nil) { if (me.Interfaces != nil) {
@ -141,14 +143,14 @@ func checkDNS() (map[string]*IPtype, map[string]*IPtype) {
ipt = "IPv6" ipt = "IPv6"
} }
if (t.IsReal()) { if (t.IsReal()) {
debug("\tIP is Real ", ipt, i.Index, i.Name, s) log.Info("\tIP is Real ", ipt, i.Index, i.Name, s)
if (t.ipv6) { if (t.ipv6) {
ipv6s[s] = t ipv6s[s] = t
} else { } else {
ipv4s[s] = t ipv4s[s] = t
} }
} else { } else {
debug("\tIP is not Real", ipt, i.Index, i.Name, s) log.Info("\tIP is not Real", ipt, i.Index, i.Name, s)
} }
} }
return ipv6s, ipv4s return ipv6s, ipv4s
@ -156,14 +158,14 @@ func checkDNS() (map[string]*IPtype, map[string]*IPtype) {
// Will figure out if an IP address is new // Will figure out if an IP address is new
func checkIP(ip *net.IPNet, i net.Interface) bool { func checkIP(ip *net.IPNet, i net.Interface) bool {
debug(LogNet, "\t\taddr.(type) = *net.IPNet") log.Log(NET, "\t\taddr.(type) = *net.IPNet")
debug(LogNet, "\t\taddr.(type) =", ip) log.Log(NET, "\t\taddr.(type) =", ip)
var realip string var realip string
realip = ip.IP.String() realip = ip.IP.String()
val, ok := me.ipmap[realip] val, ok := me.ipmap[realip]
if ok { if ok {
debug(LogNet, val.ipnet.IP.String(), "is already a defined IP address") log.Log(NET, val.ipnet.IP.String(), "is already a defined IP address")
me.ipmap[realip].gone = false me.ipmap[realip].gone = false
return false return false
} }
@ -190,50 +192,50 @@ func checkIP(ip *net.IPNet, i net.Interface) bool {
} }
} }
if (IsReal(&ip.IP)) { if (IsReal(&ip.IP)) {
debug("\tIP is Real ", t, i.Index, i.Name, realip) log.Info("\tIP is Real ", t, i.Index, i.Name, realip)
} else { } else {
debug("\tIP is not Real", t, i.Index, i.Name, realip) log.Info("\tIP is not Real", t, i.Index, i.Name, realip)
} }
debug(LogNet, "\t\tIP is IsPrivate() =", ip.IP.IsPrivate()) log.Log(NET, "\t\tIP is IsPrivate() =", ip.IP.IsPrivate())
debug(LogNet, "\t\tIP is IsLoopback() =", ip.IP.IsLoopback()) log.Log(NET, "\t\tIP is IsLoopback() =", ip.IP.IsLoopback())
debug(LogNet, "\t\tIP is IsLinkLocalUnicast() =", ip.IP.IsLinkLocalUnicast()) log.Log(NET, "\t\tIP is IsLinkLocalUnicast() =", ip.IP.IsLinkLocalUnicast())
// debug("HERE HERE", "realip =", realip, "me.ip[realip]=", me.ipmap[realip]) // log.Info("HERE HERE", "realip =", realip, "me.ip[realip]=", me.ipmap[realip])
return true return true
} }
func scanInterfaces() { func scanInterfaces() {
debug(LogNet, "scanInterfaces() START") log.Log(NET, "scanInterfaces() START")
ifaces, _ := net.Interfaces() ifaces, _ := net.Interfaces()
// me.ifnew = ifaces // me.ifnew = ifaces
debug(LogNet, SPEW, ifaces) log.Log(NET, SPEW, ifaces)
for _, i := range ifaces { for _, i := range ifaces {
addrs, _ := i.Addrs() addrs, _ := i.Addrs()
// debug("range ifaces = ", i) // log.Info("range ifaces = ", i)
checkInterface(i) checkInterface(i)
debug(LogNet, "*net.Interface.Name = ", i.Name, i.Index) log.Log(NET, "*net.Interface.Name = ", i.Name, i.Index)
debug(LogNet, SPEW, i) log.Log(NET, SPEW, i)
debug(LogNet, SPEW, addrs) log.Log(NET, SPEW, addrs)
for _, addr := range addrs { for _, addr := range addrs {
debug(LogNet, "\taddr =", addr) log.Log(NET, "\taddr =", addr)
debug(LogNet, SPEW, addrs) log.Log(NET, SPEW, addrs)
ips, _ := net.LookupIP(addr.String()) ips, _ := net.LookupIP(addr.String())
debug(LogNet, "\tLookupIP(addr) =", ips) log.Log(NET, "\tLookupIP(addr) =", ips)
switch v := addr.(type) { switch v := addr.(type) {
case *net.IPNet: case *net.IPNet:
if checkIP(v, i) { if checkIP(v, i) {
debug(true, "scanInterfaces() IP is new () i =", v.IP.String()) log.Log(true, "scanInterfaces() IP is new () i =", v.IP.String())
} }
default: default:
debug(LogNet, "\t\taddr.(type) = NO IDEA WHAT TO DO HERE v =", v) log.Log(NET, "\t\taddr.(type) = NO IDEA WHAT TO DO HERE v =", v)
} }
} }
} }
if deleteChanges() { if deleteChanges() {
me.changed = true me.changed = true
debug(LogNow, "deleteChanges() detected network changes") log.Log(NET, "deleteChanges() detected network changes")
} }
updateRealAAAA() updateRealAAAA()
debug(LogNet, "scanInterfaces() END") log.Log(NET, "scanInterfaces() END")
} }
// displays the IP address found on your network interfaces // displays the IP address found on your network interfaces
@ -243,22 +245,22 @@ func updateRealAAAA() {
for s, t := range me.ipmap { for s, t := range me.ipmap {
if (t.ipv4) { if (t.ipv4) {
all4 += s + "\n" all4 += s + "\n"
debug(LogNet, "IPv4 =", s) log.Log(NET, "IPv4 =", s)
} else if (t.ipv6) { } else if (t.ipv6) {
all6 += s + "\n" all6 += s + "\n"
debug(LogNet, "IPv6 =", s) log.Log(NET, "IPv6 =", s)
} else { } else {
debug(LogNet, "???? =", s) log.Log(NET, "???? =", s)
} }
} }
all4 = sortLines(all4) all4 = sortLines(all4)
all6 = sortLines(all6) all6 = sortLines(all6)
if (me.IPv4.S != all4) { if (me.IPv4.S != all4) {
debug(LogNow, "IPv4 addresses have changed", all4) log.Log(NET, "IPv4 addresses have changed", all4)
me.IPv4.SetText(all4) me.IPv4.SetText(all4)
} }
if (me.IPv6.S != all6) { if (me.IPv6.S != all6) {
debug(LogNow, "IPv6 addresses have changed", all6) log.Log(NET, "IPv6 addresses have changed", all6)
me.IPv6.SetText(all6) me.IPv6.SetText(all6)
} }
} }
@ -268,7 +270,7 @@ func deleteChanges() bool {
var changed bool = false var changed bool = false
for i, t := range me.ifmap { for i, t := range me.ifmap {
if (t.gone) { if (t.gone) {
debug(LogChange, "DELETE int =", i, "name =", t.name, t.iface) log.Log(LogChange, "DELETE int =", i, "name =", t.name, t.iface)
delete(me.ifmap, i) delete(me.ifmap, i)
changed = true changed = true
} }
@ -276,10 +278,10 @@ func deleteChanges() bool {
} }
for s, t := range me.ipmap { for s, t := range me.ipmap {
if (t.gone) { if (t.gone) {
debug(LogChange, "DELETE name =", s, "IPv4 =", t.ipv4) log.Log(LogChange, "DELETE name =", s, "IPv4 =", t.ipv4)
debug(LogChange, "DELETE name =", s, "IPv6 =", t.ipv6) log.Log(LogChange, "DELETE name =", s, "IPv6 =", t.ipv6)
debug(LogChange, "DELETE name =", s, "iface =", t.iface) log.Log(LogChange, "DELETE name =", s, "iface =", t.iface)
debug(LogChange, "DELETE name =", s, "ip =", t.ip) log.Log(LogChange, "DELETE name =", s, "ip =", t.ip)
delete(me.ipmap, s) delete(me.ipmap, s)
changed = true changed = true
} }