diff --git a/cmd/kjudge/main.go b/cmd/kjudge/main.go index 36fe110..e8ffc90 100644 --- a/cmd/kjudge/main.go +++ b/cmd/kjudge/main.go @@ -16,6 +16,8 @@ import ( var ( dbfile = flag.String("file", "kjudge.db", "Path to the database file.") + faviconfile = flag.String("favicon", "", "Path to favicon file. Will not be served if not specified.") + sandboxImpl = flag.String("sandbox", "isolate", "The sandbox implementation to be used (isolate, raw). Defaults to isolate.") port = flag.Int("port", 8088, "The port for the server to listen on.") verbose = flag.Bool("verbose", false, "Log every http requests") @@ -42,6 +44,17 @@ func main() { opts = append(opts, server.Verbose()) } + if *faviconfile != "" { + log.Printf("Serving favicon from %s", *faviconfile) + opt, err := server.Favicon(*faviconfile) + if err != nil { + panic(err) + } + opts = append(opts, opt) + } else { + log.Printf("Not serving favicon") + } + // Start the queue queue := worker.Queue{Sandbox: sandbox, DB: db} diff --git a/scripts/start_container.sh b/scripts/start_container.sh index dc50c73..9f7c8de 100755 --- a/scripts/start_container.sh +++ b/scripts/start_container.sh @@ -19,7 +19,10 @@ showUsage() { - CERT_O [nki inc.] Certificate Organization Name - CERT_CN [kjudge] Certificate Common name - CERT_EMAIL [not@nkagami.me] Certificate Email address - - CERT_ALTNAMES [IP:127.0.0.1,DNS:localhost] A list of hosts that kjudge will be listening on, either by IP (as 'IP:1.2.3.4') or DNS (as 'DNS:google.com'), separated by ','" + - CERT_ALTNAMES [IP:127.0.0.1,DNS:localhost] A list of hosts that kjudge will be listening on, either by IP (as 'IP:1.2.3.4') or DNS (as 'DNS:google.com'), separated by ',' + + favicon usage: + If /data/favicon.ico, start kjudge with favicon support." } if [ "$1" = "--help" ] || [ "$1" = "-h" ]; then @@ -43,8 +46,18 @@ case ${HTTPS} in ;; esac +cmd="kjudge" +args="-file /data/kjudge.db" + if [ "${useHTTPS}" = true ]; then - kjudge -port 443 -file /data/kjudge.db -https /certs "$@" + args="$args -port 443 -https /certs" else - kjudge -port 80 -file /data/kjudge.db "$@" + args="$args -port 80" +fi + +if [ -f "/data/favicon.ico" ]; then + args="$args -favicon /data/favicon.ico" fi + +# shellcheck disable=SC2086 +$cmd $args "$@" diff --git a/server/opts.go b/server/opts.go index 3bc0304..693f2d4 100644 --- a/server/opts.go +++ b/server/opts.go @@ -1,5 +1,11 @@ package server +import ( + "os" + + "github.com/pkg/errors" +) + // Opt represents an option for the server. type Opt func(s *Server) @@ -9,3 +15,13 @@ func Verbose() Opt { s.verbose = true } } + +// Favicon makes the server serves given file at /favicon.ico +func Favicon(path string) (Opt, error) { + if _, err := os.Stat(path); err != nil { + return nil, errors.Wrap(err, "while searching for favicon") + } + return func(s *Server) { + s.faviconPath = path + }, nil +} diff --git a/server/server.go b/server/server.go index c44eb08..82f63ab 100644 --- a/server/server.go +++ b/server/server.go @@ -29,7 +29,8 @@ type Server struct { db *db.DB echo *echo.Echo - verbose bool + verbose bool + faviconPath string } // New creates a new server. @@ -37,6 +38,9 @@ func New(db *db.DB, opts ...Opt) (*Server, error) { s := &Server{ db: db, echo: echo.New(), + + verbose: false, + faviconPath: "", } for _, opt := range opts { @@ -70,6 +74,10 @@ func New(db *db.DB, opts ...Opt) (*Server, error) { s.SetupProfiling() + if s.faviconPath != "" { + s.echo.File("/favicon.ico", s.faviconPath) + } + au, err := auth.NewAdmin() if err != nil { return nil, err