2022-07-11 17:57:33 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"path"
|
2022-11-03 00:31:11 +00:00
|
|
|
"strings"
|
2022-07-11 17:57:33 +00:00
|
|
|
|
2023-11-22 11:16:53 +00:00
|
|
|
"go.uber.org/multierr"
|
|
|
|
|
2022-10-29 15:03:57 +00:00
|
|
|
"srs.epita.fr/fic-server/admin/sync"
|
2022-07-11 17:57:33 +00:00
|
|
|
"srs.epita.fr/fic-server/libfic"
|
|
|
|
)
|
|
|
|
|
2023-11-22 11:16:53 +00:00
|
|
|
func EPITACheckFile(file *fic.EFile, _ *fic.Exercice, exceptions *sync.CheckExceptions) (errs error) {
|
2022-07-11 17:57:33 +00:00
|
|
|
// Enforce file format
|
2022-11-03 00:31:38 +00:00
|
|
|
if path.Ext(file.Name) == ".rar" || path.Ext(file.Name) == ".7z" {
|
2023-11-22 11:16:53 +00:00
|
|
|
errs = multierr.Append(errs, fmt.Errorf("this file use a forbidden archive type."))
|
2022-07-11 17:57:33 +00:00
|
|
|
}
|
|
|
|
|
2022-11-03 01:28:45 +00:00
|
|
|
// Check for stange file extension
|
|
|
|
if strings.HasSuffix(file.Name, ".tar.zip") {
|
2023-11-22 11:16:53 +00:00
|
|
|
errs = multierr.Append(errs, fmt.Errorf(".tar.zip is not a valid tar format"))
|
2022-11-03 01:28:45 +00:00
|
|
|
}
|
|
|
|
|
2022-11-03 00:31:11 +00:00
|
|
|
// Check .gz files have a dedicated hash
|
|
|
|
if path.Ext(file.Name) == ".gz" && !strings.HasSuffix(file.Name, ".tar.gz") && len(file.ChecksumShown) == 0 {
|
2023-11-22 11:16:53 +00:00
|
|
|
errs = multierr.Append(errs, fmt.Errorf("digest of original, uncompressed, file missing in DIGESTS.txt"))
|
2022-11-03 00:31:11 +00:00
|
|
|
}
|
|
|
|
|
2022-11-03 01:28:45 +00:00
|
|
|
// Check for huge file to compress
|
|
|
|
if file.Size > 4000000 && path.Ext(file.Name) == ".tar" {
|
2023-11-22 11:16:53 +00:00
|
|
|
errs = multierr.Append(errs, fmt.Errorf("archive to compress with bzip2"))
|
2022-11-03 01:28:45 +00:00
|
|
|
} else if file.Size > 40000000 && (path.Ext(file.Name) == "" ||
|
|
|
|
path.Ext(file.Name) == ".csv" ||
|
|
|
|
path.Ext(file.Name) == ".dump" ||
|
|
|
|
path.Ext(file.Name) == ".eml" ||
|
|
|
|
path.Ext(file.Name) == ".json" ||
|
|
|
|
path.Ext(file.Name) == ".log" ||
|
|
|
|
path.Ext(file.Name) == ".mbox" ||
|
|
|
|
path.Ext(file.Name) == ".pcap" ||
|
|
|
|
path.Ext(file.Name) == ".pcapng" ||
|
|
|
|
path.Ext(file.Name) == ".txt") {
|
2023-11-22 11:16:53 +00:00
|
|
|
errs = multierr.Append(errs, fmt.Errorf("huge file to compress with gzip"))
|
2022-11-03 01:28:45 +00:00
|
|
|
}
|
|
|
|
|
2022-07-11 17:57:33 +00:00
|
|
|
return
|
|
|
|
}
|