This commit is contained in:
delorean 2023-11-01 08:11:34 -05:00
parent ae6356fb7b
commit 746058a6d3
3 changed files with 25 additions and 22 deletions

View File

@ -1,4 +1,4 @@
webroot = "./www"
webroot = "www"
lport = "5000"
vhost = "hardfiles.org"
dbfile = "dbfile.db"

37
main.go
View File

@ -37,19 +37,18 @@ func LoadConf() {
}
}
func shred(path string) error {
log.Info().Msg("shredding file")
func Shred(path string) error {
fileinfo, err := os.Stat(path)
if err != nil {
return err
}
size := fileinfo.Size()
err = scramble(path, size)
err = Scramble(path, size)
if err != nil {
return err
}
err = zeros(path, size)
err = Zeros(path, size)
if err != nil {
return err
}
@ -62,14 +61,15 @@ func shred(path string) error {
return nil
}
func scramble(path string, size int64) error {
func Scramble(path string, size int64) error {
var i int64
for i = 0; i < 7; i++ { // 7 iterations
file, err := os.OpenFile(path, os.O_RDWR, 0)
defer file.Close()
if err != nil {
return err
}
defer file.Close()
offset, err := file.Seek(0, 0)
if err != nil {
return err
@ -82,12 +82,12 @@ func scramble(path string, size int64) error {
return nil
}
func zeros(path string, size int64) error {
func Zeros(path string, size int64) error {
file, err := os.OpenFile(path, os.O_RDWR, 0)
defer file.Close()
if err != nil {
return err
}
defer file.Close()
offset, err := file.Seek(0, 0)
if err != nil {
@ -120,8 +120,7 @@ func CheckFile(name string) bool { // false if doesn't exist, true if exists
func UploadHandler(w http.ResponseWriter, r *http.Request) {
// expiry sanitize
twentyfour := int64(86400)
// twentyfour := int64(10)
twentyfour := int64(10)
file, _, err := r.FormFile("file")
if err != nil {
@ -184,7 +183,7 @@ func Cull() {
continue
}
if time.Now().After(time.Unix(eol, 0)) {
if err := shred(conf.FileFolder + "/" + string(k)); err != nil {
if err := Shred(conf.FileFolder + "/" + string(k)); err != nil {
log.Error().Err(err).Msg("shredding failed")
} else {
removed += 1
@ -195,7 +194,7 @@ func Cull() {
return nil
})
if removed >= 1 {
log.Info().Int("amount", removed).Msg("expired")
log.Info().Int("amount", removed).Msg("shredded")
}
time.Sleep(5 * time.Second)
}
@ -206,7 +205,7 @@ func main() {
LoadConf()
err := landlock.V2.BestEffort().RestrictPaths(
landlock.RWDirs("./"+conf.FileFolder),
landlock.RWDirs(conf.FileFolder),
landlock.RWDirs(conf.Webroot),
landlock.RWFiles(conf.DBFile),
)
@ -237,7 +236,7 @@ func main() {
r := mux.NewRouter()
r.HandleFunc("/", UploadHandler).Methods("POST")
r.HandleFunc("/uploads/{name}", func(w http.ResponseWriter, r *http.Request) { // upload hits
r.HandleFunc("/uploads/{name}", func(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
if !CheckFile(vars["name"]) {
w.WriteHeader(http.StatusNotFound)
@ -248,6 +247,12 @@ func main() {
r.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, conf.Webroot+"/index.html")
}).Methods("GET")
r.HandleFunc("/index.html", func(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, conf.Webroot+"/index.html")
}).Methods("GET")
r.HandleFunc("/fist.ico", func(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, conf.Webroot+"/fist.ico")
}).Methods("GET")
http.Handle("/", r)
go Cull()
@ -256,12 +261,10 @@ func main() {
Addr: ":" + conf.LPort,
Handler: r,
ErrorLog: nil,
//ReadTimeout: 20 * time.Second,
//WriteTimeout: 20 * time.Second,
IdleTimeout: 20 * time.Second,
}
log.Info().Err(err).Msg("listening...")
log.Info().Err(err).Msg("listening on port " + conf.LPort + "...")
if err := serv.ListenAndServe(); err != nil {
log.Fatal().Err(err).Msg("error starting server")

View File

@ -3,7 +3,7 @@
<head>
<script type="text/javascript" src="//code.jquery.com/jquery-1.10.2.min.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="icon" href="https://i.imgur.com/FdC3YNu.png">
<link rel="icon" href="fist.ico">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Black+Ops+One&display=swap" rel="stylesheet">