From 77ec2fea63ac1abc7e3aee7a8dda005a5041d4d8 Mon Sep 17 00:00:00 2001 From: jamesread Date: Sun, 25 Feb 2024 21:10:47 +0000 Subject: [PATCH] feature: sosreport in the browser outputs text/plain --- OliveTin.proto | 3 ++- internal/grpcapi/grpcApi.go | 18 ++++++++++-------- internal/installationinfo/sosreport.go | 21 +++++++++++++++++---- 3 files changed, 29 insertions(+), 13 deletions(-) diff --git a/OliveTin.proto b/OliveTin.proto index 6ead647..7ba4a64 100644 --- a/OliveTin.proto +++ b/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" }; diff --git a/internal/grpcapi/grpcApi.go b/internal/grpcapi/grpcApi.go index 9358379..8bb48f3 100644 --- a/internal/grpcapi/grpcApi.go +++ b/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) { diff --git a/internal/installationinfo/sosreport.go b/internal/installationinfo/sosreport.go index 3b7d8cd..b70566a 100644 --- a/internal/installationinfo/sosreport.go +++ b/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(), } }