55 lines
1.8 KiB
Go
55 lines
1.8 KiB
Go
package msoffice
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"io"
|
|
"log/slog"
|
|
"net/http"
|
|
"net/url"
|
|
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
"github.com/spf13/viper"
|
|
)
|
|
|
|
type oleidResponse struct {
|
|
ContainerFormat string `json:"Container format"`
|
|
Encrypted bool `json:"Encrypted"`
|
|
ExternalRelationships int `json:"External Relationships"`
|
|
FileFormat string `json:"File format"`
|
|
FlashObjects int `json:"Flash objects"`
|
|
ObjectPool bool `json:"ObjectPool"`
|
|
VBAMacros string `json:"VBA Macros"`
|
|
XLMMacros string `json:"XLM Macros"`
|
|
}
|
|
|
|
func OleIDScan(fileID pgtype.UUID) (oleidResponse, error) {
|
|
|
|
slog.Debug("Starting OleID scan", "file-uuid", fileID.String())
|
|
oleidUrl, err := url.Parse(viper.GetString("processing.oleurl"))
|
|
if err != nil {
|
|
slog.Error("Error in OleIDScan parsing URL for ole service", "file-uuid", fileID.String(), "error", err)
|
|
}
|
|
oleidUrl.Path = "/oleid/analyze"
|
|
oleidUrl.RawQuery = fmt.Sprintf("file=%s", fileID.String())
|
|
oleidResp, err := http.Get(oleidUrl.String())
|
|
slog.Debug("OleIDScan request", "file-uuid", fileID.String(), "url", oleidUrl.String(), "status-code", oleidResp.StatusCode)
|
|
if err != nil {
|
|
slog.Error("Error in OleIDScan getting oleid info from service", "file-uuid", fileID.String(), "error", err)
|
|
}
|
|
defer oleidResp.Body.Close()
|
|
body, err := io.ReadAll(oleidResp.Body)
|
|
if err != nil {
|
|
slog.Error("Error in OleIDScan parsing oleid body", "file-uuid", fileID.String(), "error", err)
|
|
}
|
|
var jsonResponse oleidResponse
|
|
|
|
err = json.Unmarshal(body, &jsonResponse)
|
|
if err != nil {
|
|
slog.Error("Error in OleIDScan when trying to unmarshal response", "file-uuid", fileID.String(), "error", err)
|
|
return jsonResponse, err
|
|
}
|
|
|
|
slog.Debug("OleIDScan", "file-uuid", fileID.String(), "data", body)
|
|
return jsonResponse, nil
|
|
}
|