diff --git a/README.md b/README.md index 506660ae4..92e0d6889 100644 --- a/README.md +++ b/README.md @@ -124,4 +124,5 @@ vscode ➜ /workspaces/topoViewer (development ✗) go run go_cloudshellwrapper/ ## Run TopoViewer Binary ```Shell [aarafat@nsp-clab1 topoViewer]$ sudo topoviewer clab --allowed-hostnames 149.204.21.68 --clab-user aarafat --server-port 8087 --topology-file-json /home/aarafat/topoViewer/rawTopoFile/clab/nokia-MultiAccessGateway-lab/clab-nokia-MAGc-lab/topology-data.json - ``` \ No newline at end of file + ``` + \ No newline at end of file diff --git a/go_cloudshellwrapper/cmdClab.go b/go_cloudshellwrapper/cmdClab.go index d9c1426f1..993b9bad4 100644 --- a/go_cloudshellwrapper/cmdClab.go +++ b/go_cloudshellwrapper/cmdClab.go @@ -11,6 +11,7 @@ import ( "strconv" "strings" "sync" + "syscall" "time" topoengine "github.com/asadarafat/topoViewer/go_topoengine" @@ -169,7 +170,23 @@ func reader(conn *websocket.Conn) { } } +func checkSudoAccess() { + euid := syscall.Geteuid() + + if euid == 0 { + log.Infof("Yo, this app is running with sudo access (as root).") + } else { + log.Infof("This app ain't got no sudo powers, bro.") + os.Exit(1) + + } +} + func Clab(_ *cobra.Command, _ []string) error { + + //check sudo + checkSudoAccess() + // initialise the cloudshellLogger // tools.InitCloudShellLog(tools.Format(confClab.GetString("log-format")), tools.Level(confClab.GetString("log-level"))) diff --git a/go_cloudshellwrapper/cmdNsp.go b/go_cloudshellwrapper/cmdNsp.go index 663132a79..7218b8860 100644 --- a/go_cloudshellwrapper/cmdNsp.go +++ b/go_cloudshellwrapper/cmdNsp.go @@ -18,7 +18,7 @@ import ( xtermjs "github.com/asadarafat/topoViewer/go_xtermjs" "github.com/usvc/go-config" - log "github.com/asadarafat/topoViewer/go_tools" + log "github.com/sirupsen/logrus" "github.com/gorilla/mux" "github.com/prometheus/client_golang/prometheus/promhttp" @@ -505,7 +505,7 @@ func Nsp(_ *cobra.Command, _ []string) error { sourceImageFolder := htmlStaticPrefixPath + "images" destinationImageFolder := htmlPublicPrefixPath + "IetfTopology-L2" + "/images" err := cp.Copy(sourceImageFolder, destinationImageFolder) - log.Debugf("Copying images folder error: ", err) + log.Debugf("Copying images folder error: %s", err) // topoPrefixName := "NspIetfTopoLayer2" // should be added with NSP server ip address diff --git a/go_cloudshellwrapper/constants.go b/go_cloudshellwrapper/constants.go index 6498d8e27..97f5c5dbb 100644 --- a/go_cloudshellwrapper/constants.go +++ b/go_cloudshellwrapper/constants.go @@ -1,11 +1,3 @@ package cloudshellwrapper -<<<<<<< HEAD var VersionInfo string = "nightly-24.01.26" -======= -<<<<<<< HEAD -var VersionInfo string = "nightly-24.01.21p" -======= -var VersionInfo string = "nightly-24.01.21p" ->>>>>>> 086a68742ab98e626a7a3b18058f719644aaaddd ->>>>>>> d14e5c344ebf83e4b4ac85b517d7e5ae5238600f diff --git a/go_cloudshellwrapper/utils.go b/go_cloudshellwrapper/utils.go index 3fda9c47a..7b4e1923c 100644 --- a/go_cloudshellwrapper/utils.go +++ b/go_cloudshellwrapper/utils.go @@ -19,7 +19,7 @@ import ( func FileExists(filename string) bool { f, err := os.Stat(filename) if err != nil { - log.Debug("error while trying to access file %v: %v", filename, err) + log.Debugf("error while trying to access file %v: %v", filename, err) return false } @@ -67,14 +67,14 @@ func createMemoryLog() tools.Logger { func addIncomingRequestLogging(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - then := time.Now() + startTime := time.Now() defer func() { if recovered := recover(); recovered != nil { createRequestLog(r).Info("request errored out") } }() next.ServeHTTP(w, r) - duration := time.Now().Sub(then) + duration := time.Since(startTime) createRequestLog(r).Infof("request completed in %vms", float64(duration.Nanoseconds())/1000000) }) } diff --git a/html-static/template/clab/button.tmpl b/html-static/template/clab/button.tmpl index 15cf7d54b..c86f2a0da 100644 --- a/html-static/template/clab/button.tmpl +++ b/html-static/template/clab/button.tmpl @@ -244,25 +244,25 @@ + + + + + + + + + +
+