- Manually add a device to the constellation. It is recommended that you use the Cosmos app instead. Use this form to add another Nebula device manually
+ Add a device to the constellation using either the Cosmos or Nebula client
{
label="Owner"
formik={formik}
// disabled={!isAdmin}
- options={[
- ["admin", "admin"]
- ]}
+ options={
+ users.map((u) => {
+ return [u.nickname, u.nickname]
+ })
+ }
/>
{
variant="contained"
startIcon={}
>
- Manually Add Device
+ Add Device
>;
};
diff --git a/client/src/pages/constellation/index.jsx b/client/src/pages/constellation/index.jsx
index d0550bb..7c447d1 100644
--- a/client/src/pages/constellation/index.jsx
+++ b/client/src/pages/constellation/index.jsx
@@ -6,10 +6,16 @@ import PrettyTableView from "../../components/tableView/prettyTableView";
import { DeleteButton } from "../../components/delete";
import { CloudOutlined, DesktopOutlined, LaptopOutlined, MobileOutlined, TabletOutlined } from "@ant-design/icons";
import IsLoggedIn from "../../isLoggedIn";
+import { Button, CircularProgress, Stack } from "@mui/material";
+import { CosmosCheckbox, CosmosFormDivider } from "../config/users/formShortcuts";
+import MainCard from "../../components/MainCard";
+import { Formik } from "formik";
+import { LoadingButton } from "@mui/lab";
export const ConstellationIndex = () => {
const [isAdmin, setIsAdmin] = useState(false);
const [config, setConfig] = useState(null);
+ const [users, setUsers] = useState(null);
const [devices, setDevices] = useState(null);
const refreshConfig = async () => {
@@ -17,6 +23,7 @@ export const ConstellationIndex = () => {
setConfig(configAsync.data);
setIsAdmin(configAsync.isAdmin);
setDevices((await API.constellation.list()).data || []);
+ setUsers((await API.users.list()).data || []);
};
useEffect(() => {
@@ -40,12 +47,48 @@ export const ConstellationIndex = () => {
return <>
- {devices && config && <>
+ {(devices && config && users) ? <>
+
+
+
+
+ {
+ let newConfig = { ...config };
+ newConfig.ConstellationConfig.Enabled = values.Enabled;
+ return API.config.set(newConfig);
+ }}
+ >
+ {(formik) => (
+
+ )}
+
+
+
+
+
r.deviceName}
buttons={[
-
+
]}
columns={[
{
@@ -76,6 +119,9 @@ export const ConstellationIndex = () => {
}
]}
/>
- >}
+
+ > :
+
+ }
>
};
\ No newline at end of file
diff --git a/package.json b/package.json
index 649a5f8..11dd3e5 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "cosmos-server",
- "version": "0.10.0-unstable1",
+ "version": "0.10.0-unstable2",
"description": "",
"main": "test-server.js",
"bugs": {
diff --git a/src/configapi/set.go b/src/configapi/set.go
index 85b5624..a2aad63 100644
--- a/src/configapi/set.go
+++ b/src/configapi/set.go
@@ -5,6 +5,7 @@ import (
"encoding/json"
"github.com/azukaar/cosmos-server/src/utils"
"github.com/azukaar/cosmos-server/src/authorizationserver"
+ "github.com/azukaar/cosmos-server/src/constellation"
)
func ConfigApiSet(w http.ResponseWriter, req *http.Request) {
@@ -43,6 +44,7 @@ func ConfigApiSet(w http.ResponseWriter, req *http.Request) {
utils.DisconnectDB()
authorizationserver.Init()
utils.RestartHTTPServer()
+ constellation.RestartNebula()
json.NewEncoder(w).Encode(map[string]interface{}{
"status": "OK",
diff --git a/src/constellation/api_devices_create.go b/src/constellation/api_devices_create.go
index 014132c..f18c6f3 100644
--- a/src/constellation/api_devices_create.go
+++ b/src/constellation/api_devices_create.go
@@ -16,7 +16,6 @@ type DeviceCreateRequestJSON struct {
}
func DeviceCreate(w http.ResponseWriter, req *http.Request) {
-
if(req.Method == "POST") {
var request DeviceCreateRequestJSON
err1 := json.NewDecoder(req.Body).Decode(&request)
@@ -58,7 +57,8 @@ func DeviceCreate(w http.ResponseWriter, req *http.Request) {
}).Decode(&device)
if err2 == mongo.ErrNoDocuments {
- cert, key, err := generateNebulaCert(deviceName, request.IP, false)
+
+ cert, key, err := generateNebulaCert(deviceName, request.IP, request.PublicKey, false)
if err != nil {
utils.Error("DeviceCreation: Error while creating Device", err)
@@ -71,7 +71,6 @@ func DeviceCreate(w http.ResponseWriter, req *http.Request) {
"Nickname": nickname,
"DeviceName": deviceName,
"PublicKey": cert,
- "PrivateKey": key,
"IP": request.IP,
})
diff --git a/src/constellation/index.go b/src/constellation/index.go
index 07426ba..58299c1 100644
--- a/src/constellation/index.go
+++ b/src/constellation/index.go
@@ -23,7 +23,7 @@ func Init() {
if _, err := os.Stat(utils.CONFIGFOLDER + "cosmos.crt"); os.IsNotExist(err) {
utils.Log("Constellation: cosmos.crt not found, generating...")
// generate cosmos.crt
- generateNebulaCert("cosmos", "192.168.201.0/24", true)
+ generateNebulaCert("cosmos", "192.168.201.0/24", "", true)
}
// export nebula.yml
diff --git a/src/constellation/nebula.go b/src/constellation/nebula.go
index 227b331..bb5d306 100644
--- a/src/constellation/nebula.go
+++ b/src/constellation/nebula.go
@@ -58,7 +58,7 @@ func stop() error {
defer processMux.Unlock()
if process == nil {
- return errors.New("nebula is not running")
+ return nil
}
if err := process.Process.Kill(); err != nil {
@@ -69,11 +69,9 @@ func stop() error {
return nil
}
-func restart() error {
- if err := stop(); err != nil {
- return err
- }
- return startNebulaInBackground()
+func RestartNebula() {
+ stop()
+ Init()
}
func ExportConfigToYAML(overwriteConfig utils.ConstellationConfig, outputPath string) error {
@@ -192,15 +190,36 @@ func killAllNebulaInstances() error {
return nil
}
-func generateNebulaCert(name, ip string, saveToFile bool) (string, string, error) {
+func generateNebulaCert(name, ip, PK string, saveToFile bool) (string, string, error) {
// Run the nebula-cert command
- cmd := exec.Command(binaryToRun() + "-cert",
- "sign",
- "-ca-crt", utils.CONFIGFOLDER + "ca.crt",
- "-ca-key", utils.CONFIGFOLDER + "ca.key",
- "-name", name,
- "-ip", ip,
- )
+ var cmd *exec.Cmd
+
+ if(PK == "") {
+ cmd = exec.Command(binaryToRun() + "-cert",
+ "sign",
+ "-ca-crt", utils.CONFIGFOLDER + "ca.crt",
+ "-ca-key", utils.CONFIGFOLDER + "ca.key",
+ "-name", name,
+ "-ip", ip,
+ )
+ } else {
+ // write PK to temp.cert
+ err := ioutil.WriteFile("./temp.cert", []byte(PK), 0644)
+ if err != nil {
+ return "", "", fmt.Errorf("failed to write temp.cert: %s", err)
+ }
+ cmd = exec.Command(binaryToRun() + "-cert",
+ "sign",
+ "-ca-crt", utils.CONFIGFOLDER + "ca.crt",
+ "-ca-key", utils.CONFIGFOLDER + "ca.key",
+ "-name", name,
+ "-ip", ip,
+ "-in-pub", "./temp.cert",
+ )
+ // delete temp.cert
+ defer os.Remove("./temp.cert")
+ }
+
utils.Debug(cmd.String())
cmd.Stderr = os.Stderr