mirror of
https://github.com/gravitl/netmaker.git
synced 2025-10-16 13:51:42 +08:00
fixing server
This commit is contained in:
@@ -21,6 +21,6 @@ services:
|
||||
ports:
|
||||
- "80:80"
|
||||
environment:
|
||||
BACKEND_URL: "http://HOST_IP:8081"
|
||||
BACKEND_URL: "http://3.235.190.90:8081"
|
||||
volumes:
|
||||
mongovol: {}
|
||||
|
@@ -1,7 +1,8 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
// "fmt"
|
||||
// "fmt"
|
||||
// "github.com/davecgh/go-spew/spew"
|
||||
"errors"
|
||||
"context"
|
||||
"encoding/json"
|
||||
@@ -21,7 +22,6 @@ func intClientHandlers(r *mux.Router) {
|
||||
r.HandleFunc("/api/intclient/{clientid}", securityCheck(http.HandlerFunc(getIntClient))).Methods("GET")
|
||||
r.HandleFunc("/api/intclients", securityCheck(http.HandlerFunc(getAllIntClients))).Methods("GET")
|
||||
r.HandleFunc("/api/intclients/deleteall", securityCheck(http.HandlerFunc(deleteAllIntClients))).Methods("DELETE")
|
||||
r.HandleFunc("/api/intclient/{clientid}", securityCheck(http.HandlerFunc(deleteIntClient))).Methods("DELETE")
|
||||
r.HandleFunc("/api/intclient/{clientid}", securityCheck(http.HandlerFunc(updateIntClient))).Methods("PUT")
|
||||
r.HandleFunc("/api/intclient/register", http.HandlerFunc(registerIntClient)).Methods("POST")
|
||||
r.HandleFunc("/api/intclient/{clientid}", http.HandlerFunc(deleteIntClient)).Methods("DELETE")
|
||||
@@ -138,13 +138,17 @@ func RegisterIntClient(client models.IntClient) (models.IntClient, error) {
|
||||
client.Address = newAddress
|
||||
}
|
||||
if client.Network == "" { client.Network = "comms" }
|
||||
|
||||
wgconfig := servercfg.GetWGConfig()
|
||||
client.ServerPublicEndpoint = servercfg.GetAPIHost()
|
||||
client.ServerAPIPort = servercfg.GetAPIPort()
|
||||
client.ServerPrivateAddress = wgconfig.GRPCWGAddress
|
||||
client.ServerWGPort = wgconfig.GRPCWGPort
|
||||
client.ServerGRPCPort = servercfg.GetGRPCPort()
|
||||
server, err := serverctl.GetServerWGConf()
|
||||
//spew.Dump(server)
|
||||
if err != nil {
|
||||
return client, err
|
||||
}
|
||||
client.ServerPublicEndpoint = server.ServerPublicEndpoint
|
||||
client.ServerAPIPort = server.ServerAPIPort
|
||||
client.ServerPrivateAddress = server.ServerPrivateAddress
|
||||
client.ServerWGPort = server.ServerWGPort
|
||||
client.ServerGRPCPort = server.ServerGRPCPort
|
||||
client.ServerKey = server.ServerKey
|
||||
|
||||
if client.ClientID == "" {
|
||||
clientid := StringWithCharset(7, charset)
|
||||
@@ -152,11 +156,11 @@ func RegisterIntClient(client models.IntClient) (models.IntClient, error) {
|
||||
client.ClientID = clientname
|
||||
}
|
||||
|
||||
|
||||
//spew.Dump(client)
|
||||
collection := mongoconn.Client.Database("netmaker").Collection("intclients")
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
// insert our network into the network table
|
||||
_, err := collection.InsertOne(ctx, client)
|
||||
_, err = collection.InsertOne(ctx, client)
|
||||
defer cancel()
|
||||
|
||||
if err != nil {
|
||||
|
@@ -14,6 +14,7 @@ import (
|
||||
func serverHandlers(r *mux.Router) {
|
||||
r.HandleFunc("/api/server/addnetwork/{network}", securityCheckServer(http.HandlerFunc(addNetwork))).Methods("POST")
|
||||
r.HandleFunc("/api/server/getconfig", securityCheckServer(http.HandlerFunc(getConfig))).Methods("GET")
|
||||
r.HandleFunc("/api/server/getwgconfig", securityCheckServer(http.HandlerFunc(getWGConfig))).Methods("GET")
|
||||
r.HandleFunc("/api/server/removenetwork/{network}", securityCheckServer(http.HandlerFunc(removeNetwork))).Methods("DELETE")
|
||||
}
|
||||
|
||||
@@ -84,11 +85,35 @@ func getConfig(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
// get params
|
||||
|
||||
scfg := servercfg.GetConfig()
|
||||
scfg := servercfg.GetServerConfig()
|
||||
w.WriteHeader(http.StatusOK)
|
||||
json.NewEncoder(w).Encode(scfg)
|
||||
}
|
||||
|
||||
func getWGConfig(w http.ResponseWriter, r *http.Request) {
|
||||
// Set header
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
|
||||
// get params
|
||||
|
||||
wgcfg := servercfg.GetWGConfig()
|
||||
w.WriteHeader(http.StatusOK)
|
||||
json.NewEncoder(w).Encode(wgcfg)
|
||||
}
|
||||
|
||||
/*
|
||||
func getMongoConfig(w http.ResponseWriter, r *http.Request) {
|
||||
// Set header
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
|
||||
// get params
|
||||
|
||||
mcfg := servercfg.GetMongoConfig()
|
||||
w.WriteHeader(http.StatusOK)
|
||||
json.NewEncoder(w).Encode(mcfg)
|
||||
}
|
||||
*/
|
||||
|
||||
func addNetwork(w http.ResponseWriter, r *http.Request) {
|
||||
// Set header
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
|
@@ -45,7 +45,7 @@ func CreateServerToken(netID string) (string, error) {
|
||||
privAddr = network.LocalRange
|
||||
}
|
||||
|
||||
accessstringdec := " " + "|"+ address + "|" + address + "|" + netID + "|" + accesskey.Value + "|" + privAddr
|
||||
accessstringdec := address + "|"+ address + "|" + address + "|" + netID + "|" + accesskey.Value + "|" + privAddr
|
||||
|
||||
accesskey.AccessString = base64.StdEncoding.EncodeToString([]byte(accessstringdec))
|
||||
|
||||
|
2
main.go
2
main.go
@@ -146,7 +146,7 @@ func runGRPC(wg *sync.WaitGroup, installserver bool) {
|
||||
}()
|
||||
log.Println("Agent Server succesfully started on port " + grpcport + " (gRPC)")
|
||||
|
||||
if installserver {
|
||||
if !installserver {
|
||||
fmt.Println("Adding server to default network")
|
||||
success, err := serverctl.AddNetwork("default")
|
||||
if err != nil {
|
||||
|
@@ -8,11 +8,11 @@ type IntClient struct {
|
||||
Address string `json:"address" bson:"address"`
|
||||
Address6 string `json:"address6" bson:"address6"`
|
||||
Network string `json:"network" bson:"network"`
|
||||
ServerPublicEndpoint string `json:"serverwgendpoint" bson:"serverwgendpoint"`
|
||||
ServerAPIPort string `json:"serverapiendpoint" bson:"serverapiendpoint"`
|
||||
ServerPrivateAddress string `json:"serveraddress" bson:"serveraddress"`
|
||||
ServerWGPort string `json:"serverport" bson:"serverport"`
|
||||
ServerGRPCPort string `json:"serverport" bson:"serverport"`
|
||||
ServerPublicEndpoint string `json:"serverpublicendpoint" bson:"serverpublicendpoint"`
|
||||
ServerAPIPort string `json:"serverapiport" bson:"serverapiport"`
|
||||
ServerPrivateAddress string `json:"serverprivateaddress" bson:"serverprivateaddress"`
|
||||
ServerWGPort string `json:"serverwgport" bson:"serverwgport"`
|
||||
ServerGRPCPort string `json:"servergrpcport" bson:"servergrpcport"`
|
||||
ServerKey string `json:"serverkey" bson:"serverkey"`
|
||||
IsServer string `json:"isserver" bson:"isserver"`
|
||||
}
|
||||
|
@@ -13,7 +13,7 @@ import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"errors"
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
// "github.com/davecgh/go-spew/spew"
|
||||
)
|
||||
|
||||
func Register(cfg config.GlobalConfig) error {
|
||||
@@ -57,12 +57,12 @@ func Register(cfg config.GlobalConfig) error {
|
||||
}
|
||||
var wgclient models.IntClient
|
||||
json.Unmarshal(bodyBytes, &wgclient)
|
||||
spew.Dump(wgclient)
|
||||
//spew.Dump(wgclient)
|
||||
err = config.ModGlobalConfig(wgclient)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
spew.Dump(wgclient)
|
||||
//spew.Dump(wgclient)
|
||||
err = wireguard.InitGRPCWireguard(wgclient)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@@ -1,7 +1,7 @@
|
||||
package wireguard
|
||||
|
||||
import (
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
// "github.com/davecgh/go-spew/spew"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"errors"
|
||||
@@ -117,7 +117,7 @@ func InitGRPCWireguard(client models.IntClient) error {
|
||||
return err
|
||||
}
|
||||
}
|
||||
spew.Dump(conf)
|
||||
//spew.Dump(conf)
|
||||
err = wgclient.ConfigureDevice(ifacename, conf)
|
||||
|
||||
if err != nil {
|
||||
|
7
scripts/reset-network.sh
Executable file
7
scripts/reset-network.sh
Executable file
@@ -0,0 +1,7 @@
|
||||
rm -rf /etc/systemd/system/netclient-default.timer
|
||||
rm -rf /etc/systemd/system/netclient@.service
|
||||
rm -rf /etc/netclient/
|
||||
systemctl daemon-reload
|
||||
ip link del nm-default
|
||||
ip link del nm-grpc-wg
|
||||
docker-compose -f /root/netmaker/compose/docker-compose.yml down --volumes
|
@@ -16,7 +16,7 @@ func SetHost() error {
|
||||
os.Setenv("SERVER_HOST", remoteip)
|
||||
return nil
|
||||
}
|
||||
func GetConfig() config.ServerConfig {
|
||||
func GetServerConfig() config.ServerConfig {
|
||||
var cfg config.ServerConfig
|
||||
cfg.APIHost = GetAPIHost()
|
||||
cfg.APIPort = GetAPIPort()
|
||||
@@ -56,6 +56,7 @@ func GetWGConfig() config.WG{
|
||||
}
|
||||
cfg.GRPCWGInterface = GetGRPCWGInterface()
|
||||
cfg.GRPCWGAddress = GetGRPCWGAddress()
|
||||
cfg.GRPCWGAddressRange = GetGRPCWGAddressRange()
|
||||
cfg.GRPCWGPort = GetGRPCWGPort()
|
||||
cfg.GRPCWGPubKey = GetGRPCWGPubKey()
|
||||
cfg.GRPCWGPrivKey = GetGRPCWGPrivKey()
|
||||
|
@@ -224,6 +224,7 @@ func AddNetwork(network string) (bool, error) {
|
||||
log.Println("could not change netclient directory permissions")
|
||||
return false, err
|
||||
}
|
||||
log.Println("executing network join: " + "/etc/netclient/netclient "+"join "+"-t "+token+" -name "+"netmaker"+" -endpoint "+pubip)
|
||||
out, err := exec.Command("/etc/netclient/netclient","join","-t",token,"-name","netmaker","-endpoint",pubip).Output()
|
||||
if string(out) != "" {
|
||||
log.Println(string(out))
|
||||
|
@@ -63,10 +63,10 @@ func InitServerWireGuard() error {
|
||||
client.PublicKey = wgconfig.GRPCWGPubKey
|
||||
client.ServerPublicEndpoint = servercfg.GetAPIHost()
|
||||
client.ServerAPIPort = servercfg.GetAPIPort()
|
||||
client.ServerPrivateAddress = wgconfig.GRPCWGAddress
|
||||
client.ServerWGPort = wgconfig.GRPCWGPort
|
||||
client.ServerPrivateAddress = servercfg.GetGRPCWGAddress()
|
||||
client.ServerWGPort = servercfg.GetGRPCWGPort()
|
||||
client.ServerGRPCPort = servercfg.GetGRPCPort()
|
||||
client.Address = wgconfig.GRPCWGAddress
|
||||
client.Address = servercfg.GetGRPCWGAddress()
|
||||
client.IsServer = "yes"
|
||||
client.Network = "comms"
|
||||
exists, _ := functions.ServerIntClientExists()
|
||||
|
Reference in New Issue
Block a user