Răsfoiți Sursa

feature: sosreport in the browser outputs text/plain

jamesread 2 ani în urmă
părinte
comite
77ec2fea63
3 a modificat fișierele cu 29 adăugiri și 13 ștergeri
  1. 2 1
      OliveTin.proto
  2. 10 8
      internal/grpcapi/grpcApi.go
  3. 17 4
      internal/installationinfo/sosreport.go

+ 2 - 1
OliveTin.proto

@@ -3,6 +3,7 @@ syntax = "proto3";
 option go_package = "gen/grpc";
 
 import "google/api/annotations.proto";
+import "google/api/httpbody.proto";
 
 message Action {
 	string id = 1;
@@ -237,7 +238,7 @@ service OliveTinApiService {
 		};
 	}
 
-	rpc SosReport(SosReportRequest) returns (SosReportResponse) {
+	rpc SosReport(SosReportRequest) returns (google.api.HttpBody) {
 		option (google.api.http) = {
 			get: "/api/sosreport"
 		};

+ 10 - 8
internal/grpcapi/grpcApi.go

@@ -5,6 +5,7 @@ import (
 	pb "github.com/OliveTin/OliveTin/gen/grpc"
 	"github.com/google/uuid"
 	log "github.com/sirupsen/logrus"
+	"google.golang.org/genproto/googleapis/api/httpbody"
 	"google.golang.org/grpc"
 
 	"errors"
@@ -251,19 +252,20 @@ func (api *oliveTinAPI) WhoAmI(ctx ctx.Context, req *pb.WhoAmIRequest) (*pb.WhoA
 	return res, nil
 }
 
-func (api *oliveTinAPI) SosReport(ctx ctx.Context, req *pb.SosReportRequest) (*pb.SosReportResponse, error) {
+func (api *oliveTinAPI) SosReport(ctx ctx.Context, req *pb.SosReportRequest) (*httpbody.HttpBody, error) {
 	sos := installationinfo.GetSosReport()
 
-	res := &pb.SosReportResponse{}
-
-	if cfg.InsecureAllowDumpSos {
-		res.Alert = sos
-	} else {
-		res.Alert = "Your SOS Report has been logged to OliveTin logs."
+	if !cfg.InsecureAllowDumpSos {
 		log.Info(sos)
+		sos = "Your SOS Report has been logged to OliveTin logs.\n\nIf you are in a safe network, you can temporarily set `insecureAllowDumpSos: true` in your config.yaml, restart OliveTin, and refresh this page - it will put the output directly in the browser."
 	}
 
-	return res, nil
+	ret := &httpbody.HttpBody{
+		ContentType: "text/plain",
+		Data:        []byte(sos),
+	}
+
+	return ret, nil
 }
 
 func (api *oliveTinAPI) DumpVars(ctx ctx.Context, req *pb.DumpVarsRequest) (*pb.DumpVarsResponse, error) {

+ 17 - 4
internal/installationinfo/sosreport.go

@@ -4,19 +4,32 @@ import (
 	"fmt"
 	config "github.com/OliveTin/OliveTin/internal/config"
 	"gopkg.in/yaml.v3"
+	"time"
 )
 
 var Config *config.Config
 
 type sosReportConfig struct {
-	CountOfActions int
-	LogLevel       string
+	CountOfActions                  int
+	CountOfDashboards               int
+	LogLevel                        string
+	ListenAddressSingleHTTPFrontend string
+	ListenAddressWebUI              string
+	ListenAddressRestActions        string
+	ListenAddressGrpcActions        string
+	Timezone                        string
 }
 
 func configToSosreport(cfg *config.Config) *sosReportConfig {
 	return &sosReportConfig{
-		CountOfActions: len(cfg.Actions),
-		LogLevel:       cfg.LogLevel,
+		CountOfActions:                  len(cfg.Actions),
+		CountOfDashboards:               len(cfg.Dashboards),
+		LogLevel:                        cfg.LogLevel,
+		ListenAddressSingleHTTPFrontend: cfg.ListenAddressSingleHTTPFrontend,
+		ListenAddressWebUI:              cfg.ListenAddressWebUI,
+		ListenAddressRestActions:        cfg.ListenAddressRestActions,
+		ListenAddressGrpcActions:        cfg.ListenAddressGrpcActions,
+		Timezone:                        time.Now().Location().String(),
 	}
 }