2020-10-27 17:17:41 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"math/rand"
|
|
|
|
"net/http"
|
|
|
|
"time"
|
2022-08-16 00:23:29 +02:00
|
|
|
|
|
|
|
"github.com/leon-richardt/jaf/exifscrubber"
|
2020-10-27 17:17:41 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
const allowedChars = "0123456789ABCDEFGHIJKLMNOPQRTSUVWXYZabcdefghijklmnopqrstuvwxyz"
|
|
|
|
|
2022-08-16 00:23:29 +02:00
|
|
|
var config Config
|
2020-10-27 17:17:41 +01:00
|
|
|
|
|
|
|
type parameters struct {
|
|
|
|
configFile string
|
|
|
|
}
|
|
|
|
|
|
|
|
func parseParams() *parameters {
|
|
|
|
configFile := flag.String("configFile", "jaf.conf", "path to config file")
|
|
|
|
flag.Parse()
|
|
|
|
|
|
|
|
retval := ¶meters{}
|
|
|
|
retval.configFile = *configFile
|
|
|
|
return retval
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
rand.Seed(time.Now().UnixNano())
|
|
|
|
log.SetPrefix("jaf > ")
|
|
|
|
|
|
|
|
params := parseParams()
|
|
|
|
|
|
|
|
// Read config
|
|
|
|
config, err := ConfigFromFile(params.configFile)
|
|
|
|
if err != nil {
|
2022-08-23 12:04:56 +02:00
|
|
|
log.Fatalf("could not parse config file: %s\n", err.Error())
|
2020-10-27 17:17:41 +01:00
|
|
|
}
|
|
|
|
|
2022-08-16 00:23:29 +02:00
|
|
|
handler := uploadHandler{
|
|
|
|
config: config,
|
|
|
|
}
|
|
|
|
|
|
|
|
if config.ScrubExif {
|
|
|
|
scrubber := exifscrubber.NewExifScrubber(config.ExifAllowedIds, config.ExifAllowedPaths)
|
|
|
|
handler.exifScrubber = &scrubber
|
|
|
|
}
|
|
|
|
|
2020-10-27 17:17:41 +01:00
|
|
|
// Start server
|
|
|
|
uploadServer := &http.Server{
|
|
|
|
ReadTimeout: 30 * time.Second,
|
|
|
|
WriteTimeout: 30 * time.Second,
|
|
|
|
Addr: fmt.Sprintf(":%d", config.Port),
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Printf("starting jaf on port %d\n", config.Port)
|
2022-08-16 00:23:29 +02:00
|
|
|
http.Handle("/upload", &handler)
|
2020-10-27 17:17:41 +01:00
|
|
|
uploadServer.ListenAndServe()
|
|
|
|
}
|