package processing import ( "context" "log/slog" "sync" "time" "git.jmbit.de/jmb/scanfile/server/internal/database" "git.jmbit.de/jmb/scanfile/server/internal/processing/basic" "git.jmbit.de/jmb/scanfile/server/internal/processing/capa" "git.jmbit.de/jmb/scanfile/server/internal/processing/msoffice" "git.jmbit.de/jmb/scanfile/server/internal/processing/yara" "github.com/jackc/pgx/v5/pgtype" ) // Used to determine if a task was started by a previous instance that stalled out or died var startup time.Time func Setup(wg *sync.WaitGroup) { startup = time.Now() go yara.InitYara() } // Submit() starts the analysis process for a file. func Submit(ctx context.Context, file pgtype.UUID) error { // Always start a basic task job, err := database.NewProcessingJob(ctx, file, TypeBasic) if err != nil { slog.Error("Could not submit processing job", "error", err, "file-uuid", file, "type", TypeBasic) return err } go basic.BasicProcessing(job) //yaraJob, err := database.NewProcessingJob(ctx, file, TypeYARA) //if err != nil { // slog.Error("Could not submit processing job", "error", err, "file-uuid", file, "type", TypeBasic) // return err //} //go yara.YaraProcessing(yaraJob) mimeType, err := database.GetFileMime(file) if err != nil { slog.Error("Could not retrieve MimeType", "error", err, "file-uuid", file) return err } switch TypeFromMime(mimeType) { case TypeMSOffice: officeJob, err := database.NewProcessingJob(ctx, file, TypeMSOffice) if err != nil { slog.Error("Could not submit processing job", "error", err, "file-uuid", file, "type", TypeMSOffice) return err } go msoffice.MSOfficeProcessing(officeJob) case TypeELF: capaJob, err := database.NewProcessingJob(ctx, file, TypeELF) if err != nil { slog.Error("Could not submit processing job", "error", err, "file-uuid", file, "type", TypeCAPA) return err } go capa.CapaProcessing(capaJob) case TypePE: capaJob, err := database.NewProcessingJob(ctx, file, TypeELF) if err != nil { slog.Error("Could not submit processing job", "error", err, "file-uuid", file, "type", TypeCAPA) return err } go capa.CapaProcessing(capaJob) } return nil }