feature: sosreport in the browser outputs text/plain

This commit is contained in:
jamesread 2024-02-25 21:10:47 +00:00
parent 83beab4c92
commit 77ec2fea63
3 changed files with 29 additions and 13 deletions

View File

@ -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"
};

View File

@ -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) {

View File

@ -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(),
}
}