Преглед изворни кода

feature: Better sosreports (#308)

James Read пре 2 година
родитељ
комит
f43ece4263

+ 10 - 2
internal/httpservers/webuiServer.go

@@ -8,8 +8,10 @@ import (
 	"net/http"
 	"net/http"
 	"os"
 	"os"
 	"path"
 	"path"
+	"path/filepath"
 
 
 	config "github.com/OliveTin/OliveTin/internal/config"
 	config "github.com/OliveTin/OliveTin/internal/config"
+	sv "github.com/OliveTin/OliveTin/internal/stringvariables"
 	updatecheck "github.com/OliveTin/OliveTin/internal/updatecheck"
 	updatecheck "github.com/OliveTin/OliveTin/internal/updatecheck"
 )
 )
 
 
@@ -43,12 +45,15 @@ func findWebuiDir() string {
 	// search order must be deterministic - the order that the slice was defined in.
 	// search order must be deterministic - the order that the slice was defined in.
 	for i := 0; i < len(directoriesToSearch); i++ {
 	for i := 0; i < len(directoriesToSearch); i++ {
 		dir := directoriesToSearch[i]
 		dir := directoriesToSearch[i]
+		absdir, _ := filepath.Abs(dir)
 
 
-		if _, err := os.Stat(dir); !os.IsNotExist(err) {
+		if _, err := os.Stat(absdir); !os.IsNotExist(err) {
 			log.WithFields(log.Fields{
 			log.WithFields(log.Fields{
-				"dir": dir,
+				"dir": absdir,
 			}).Infof("Found the webui directory")
 			}).Infof("Found the webui directory")
 
 
+			sv.Set("internal.webuidir", absdir+" ("+dir+")")
+
 			return dir
 			return dir
 		}
 		}
 	}
 	}
@@ -71,6 +76,9 @@ func setupCustomWebuiDir() {
 
 
 	if err != nil {
 	if err != nil {
 		log.Warnf("Could not create themes directory: %v", err)
 		log.Warnf("Could not create themes directory: %v", err)
+		sv.Set("internal.themesdir", err.Error())
+	} else {
+		sv.Set("internal.themesdir", dir)
 	}
 	}
 }
 }
 
 

+ 28 - 7
internal/installationinfo/runtimeinfo.go

@@ -4,6 +4,8 @@ import (
 	"bufio"
 	"bufio"
 	"errors"
 	"errors"
 	"os"
 	"os"
+	"path"
+	"path/filepath"
 	"runtime"
 	"runtime"
 	"strings"
 	"strings"
 )
 )
@@ -14,6 +16,32 @@ type runtimeInfo struct {
 	Arch                 string
 	Arch                 string
 	InContainer          bool
 	InContainer          bool
 	LastBrowserUserAgent string
 	LastBrowserUserAgent string
+	User                 string
+	Uid                  string
+	FoundSshKey          string
+}
+
+var Runtime = &runtimeInfo{
+	OS:                  runtime.GOOS,
+	Arch:                runtime.GOARCH,
+	InContainer:         isInContainer(),
+	OSReleasePrettyName: getOsReleasePrettyName(),
+	User:                os.Getenv("USER"),
+	Uid:                 os.Getenv("UID"),
+}
+
+func refreshRuntimeInfo() {
+	Runtime.FoundSshKey = searchForSshKey()
+}
+
+func searchForSshKey() string {
+	path, _ := filepath.Abs(path.Join(os.Getenv("HOME"), ".ssh/id_rsa"))
+
+	if _, err := os.Stat(path); err == nil {
+		return path
+	}
+
+	return "none-found at " + path
 }
 }
 
 
 func isInContainer() bool {
 func isInContainer() bool {
@@ -46,10 +74,3 @@ func getOsReleasePrettyName() string {
 
 
 	return "notfound"
 	return "notfound"
 }
 }
-
-var Runtime = &runtimeInfo{
-	OS:                  runtime.GOOS,
-	Arch:                runtime.GOARCH,
-	InContainer:         isInContainer(),
-	OSReleasePrettyName: getOsReleasePrettyName(),
-}

+ 11 - 0
internal/installationinfo/sosreport.go

@@ -3,6 +3,7 @@ package installationinfo
 import (
 import (
 	"fmt"
 	"fmt"
 	config "github.com/OliveTin/OliveTin/internal/config"
 	config "github.com/OliveTin/OliveTin/internal/config"
+	sv "github.com/OliveTin/OliveTin/internal/stringvariables"
 	"gopkg.in/yaml.v3"
 	"gopkg.in/yaml.v3"
 	"time"
 	"time"
 )
 )
@@ -18,6 +19,10 @@ type sosReportConfig struct {
 	ListenAddressRestActions        string
 	ListenAddressRestActions        string
 	ListenAddressGrpcActions        string
 	ListenAddressGrpcActions        string
 	Timezone                        string
 	Timezone                        string
+	TimeNow                         string
+	ConfigDirectory                 string
+	WebuiDirectory                  string
+	ThemesDirectory                 string
 }
 }
 
 
 func configToSosreport(cfg *config.Config) *sosReportConfig {
 func configToSosreport(cfg *config.Config) *sosReportConfig {
@@ -30,10 +35,16 @@ func configToSosreport(cfg *config.Config) *sosReportConfig {
 		ListenAddressRestActions:        cfg.ListenAddressRestActions,
 		ListenAddressRestActions:        cfg.ListenAddressRestActions,
 		ListenAddressGrpcActions:        cfg.ListenAddressGrpcActions,
 		ListenAddressGrpcActions:        cfg.ListenAddressGrpcActions,
 		Timezone:                        time.Now().Location().String(),
 		Timezone:                        time.Now().Location().String(),
+		TimeNow:                         time.Now().String(),
+		ConfigDirectory:                 cfg.GetDir(),
+		WebuiDirectory:                  sv.Get("internal.webuidir"),
+		ThemesDirectory:                 sv.Get("internal.themesdir"),
 	}
 	}
 }
 }
 
 
 func GetSosReport() string {
 func GetSosReport() string {
+	refreshRuntimeInfo()
+
 	ret := ""
 	ret := ""
 
 
 	ret += "### SOSREPORT START (copy all text to SOSREPORT END)\n"
 	ret += "### SOSREPORT START (copy all text to SOSREPORT END)\n"