minor cleanups

This commit is contained in:
0xdcarns
2021-09-28 14:08:16 -04:00
parent 90d941854b
commit 90cbbfdf4a
5 changed files with 17 additions and 46 deletions

View File

@@ -33,7 +33,6 @@ func (s *NodeServiceServer) ReadNode(ctx context.Context, req *nodepb.Object) (*
return nil, err return nil, err
} }
node.Update(&node) node.Update(&node)
node.SetDefaults()
response := &nodepb.Object{ response := &nodepb.Object{
Data: string(nodeData), Data: string(nodeData),
Type: nodepb.NODE_TYPE, Type: nodepb.NODE_TYPE,

View File

@@ -11,7 +11,6 @@ RUN GOOS=linux GOARCH=amd64 CGO_ENABLED=1 /usr/local/go/bin/go build -ldflags="-
WORKDIR /app/netclient WORKDIR /app/netclient
RUN GOOS=linux GOARCH=amd64 CGO_ENABLED=0 /usr/local/go/bin/go build -ldflags="-w -s" -o netclient main.go RUN GOOS=linux GOARCH=amd64 CGO_ENABLED=0 /usr/local/go/bin/go build -ldflags="-w -s" -o netclient main.go
#second stage #second stage

View File

@@ -53,6 +53,9 @@ func initialize() { // Client Mode Prereq Check
if uid != 0 { if uid != 0 {
log.Fatal("To run in client mode requires root privileges. Either disable client mode or run with sudo.") log.Fatal("To run in client mode requires root privileges. Either disable client mode or run with sudo.")
} }
if err := serverctl.InitServerNetclient(); err != nil {
log.Fatal("Did not find netclient to use CLIENT_MODE")
}
} }
if servercfg.IsDNSMode() { if servercfg.IsDNSMode() {

View File

@@ -532,25 +532,6 @@ func GetAllNodes() ([]Node, error) {
return nodes, nil return nodes, nil
} }
func GetNode(macaddress string, network string) (Node, error) {
var node Node
key, err := GetID(macaddress, network)
if err != nil {
return node, err
}
data, err := database.FetchRecord(database.NODES_TABLE_NAME, key)
if err != nil {
return node, err
}
if err = json.Unmarshal([]byte(data), &node); err != nil {
return node, err
}
return node, err
}
func GetID(macaddress string, network string) (string, error) { func GetID(macaddress string, network string) (string, error) {
if macaddress == "" || network == "" { if macaddress == "" || network == "" {
return "", errors.New("unable to get record key") return "", errors.New("unable to get record key")

View File

@@ -100,8 +100,7 @@ func RemoveNetwork(network string) (bool, error) {
} }
func HandleContainedClient() error { func InitServerNetclient() error {
log.SetFlags(log.Flags() &^ (log.Llongfile | log.Lshortfile))
netclientDir := ncutils.GetNetclientPath() netclientDir := ncutils.GetNetclientPath()
netclientPath := ncutils.GetNetclientPathSpecific() netclientPath := ncutils.GetNetclientPathSpecific()
_, err := os.Stat(netclientDir) _, err := os.Stat(netclientDir)
@@ -123,11 +122,19 @@ func HandleContainedClient() error {
log.Println("could not change netclient binary permissions") log.Println("could not change netclient binary permissions")
return err return err
} }
return nil
}
func HandleContainedClient() error {
log.SetFlags(log.Flags() &^ (log.Llongfile | log.Lshortfile))
netclientPath := ncutils.GetNetclientPathSpecific()
checkinCMD := exec.Command(netclientPath+"netclient", "checkin", "-n", "all") checkinCMD := exec.Command(netclientPath+"netclient", "checkin", "-n", "all")
checkinCMD.Stdout = os.Stdout if servercfg.GetVerbose() >= 2 {
checkinCMD.Stdout = os.Stdout
}
checkinCMD.Stderr = os.Stderr checkinCMD.Stderr = os.Stderr
err = checkinCMD.Start() err := checkinCMD.Start()
if err != nil { if err != nil {
if servercfg.GetVerbose() >= 2 { if servercfg.GetVerbose() >= 2 {
log.Println(err) log.Println(err)
@@ -151,36 +158,18 @@ func AddNetwork(network string) (bool, error) {
log.Println("could not get public IP.") log.Println("could not get public IP.")
return false, err return false, err
} }
netclientDir := ncutils.GetNetclientPath()
netclientPath := ncutils.GetNetclientPathSpecific() netclientPath := ncutils.GetNetclientPathSpecific()
_, err = os.Stat(netclientDir)
if os.IsNotExist(err) {
os.Mkdir(netclientDir, 744)
} else if err != nil {
log.Println("could not find or create", netclientDir)
return false, err
}
token, err := functions.CreateServerToken(network) token, err := functions.CreateServerToken(network)
if err != nil { if err != nil {
log.Println("could not create server token for " + network) log.Println("could not create server token for " + network)
return false, err return false, err
} }
_, err = os.Stat(netclientPath + "netclient")
if os.IsNotExist(err) {
err = InstallNetclient()
if err != nil {
return false, err
}
}
err = os.Chmod(netclientPath+"netclient", 0755)
if err != nil {
log.Println("could not change netclient directory permissions")
return false, err
}
functions.PrintUserLog(models.NODE_SERVER_NAME, "executing network join: "+netclientPath+"netclient "+"join "+"-t "+token+" -name "+models.NODE_SERVER_NAME+" -endpoint "+pubip, 0) functions.PrintUserLog(models.NODE_SERVER_NAME, "executing network join: "+netclientPath+"netclient "+"join "+"-t "+token+" -name "+models.NODE_SERVER_NAME+" -endpoint "+pubip, 0)
var joinCMD *exec.Cmd var joinCMD *exec.Cmd
if servercfg.IsClientMode() == "contained" { if servercfg.IsClientMode() == "contained" {
joinCMD = exec.Command(netclientPath+"netclient", "join", "-t", token, "-name", models.NODE_SERVER_NAME, "-endpoint", pubip, "-daemon", "off") joinCMD = exec.Command(netclientPath+"netclient", "join", "-t", token, "-name", models.NODE_SERVER_NAME, "-endpoint", pubip, "-daemon", "off", "-dnson", "no")
} else { } else {
joinCMD = exec.Command(netclientPath+"netclient", "join", "-t", token, "-name", models.NODE_SERVER_NAME, "-endpoint", pubip) joinCMD = exec.Command(netclientPath+"netclient", "join", "-t", token, "-name", models.NODE_SERVER_NAME, "-endpoint", pubip)
} }