44 lines
976 B
Go
44 lines
976 B
Go
package main
|
|
|
|
import (
|
|
"flag"
|
|
"log"
|
|
"net/http"
|
|
"path/filepath"
|
|
)
|
|
|
|
var tftpDir string
|
|
|
|
func main() {
|
|
var studentsFile string
|
|
|
|
var bind = flag.String("bind", ":8081", "Bind port/socket")
|
|
flag.StringVar(&studentsFile, "students", "./students.csv", "Path to a CSV file containing students list")
|
|
flag.StringVar(&ARPTable, "arp", ARPTable, "Path to ARP table")
|
|
flag.StringVar(&tftpDir, "tftpdir", "/var/tftp/", "Path to TFTPd directory")
|
|
flag.Parse()
|
|
|
|
var err error
|
|
|
|
// Sanitize options
|
|
log.Println("Checking paths...")
|
|
if tftpDir, err = filepath.Abs(tftpDir); err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
var students []Student
|
|
students, err = readStudentsList(studentsFile)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
log.Println("Registering handlers...")
|
|
mux := http.NewServeMux()
|
|
mux.HandleFunc("/", Index)
|
|
mux.Handle("/login", loginChecker{students})
|
|
http.HandleFunc("/", mux.ServeHTTP)
|
|
|
|
log.Println("Ready, listening on port", *bind)
|
|
http.ListenAndServe(*bind, nil)
|
|
}
|