Add backup server
This commit is contained in:
parent
84be1b6d67
commit
1fc1490f9b
|
@ -8,6 +8,7 @@ import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
|
|
||||||
"github.com/james4k/rcon"
|
"github.com/james4k/rcon"
|
||||||
"golang.org/x/crypto/acme/autocert"
|
"golang.org/x/crypto/acme/autocert"
|
||||||
|
@ -18,6 +19,7 @@ type config struct {
|
||||||
Servers []server `json:"servers"`
|
Servers []server `json:"servers"`
|
||||||
TLSHostname string `json:"tlshostname"`
|
TLSHostname string `json:"tlshostname"`
|
||||||
DebugServerPort int `json:"debugserverport"`
|
DebugServerPort int `json:"debugserverport"`
|
||||||
|
BackupDir string `json:"backupDir"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type server struct {
|
type server struct {
|
||||||
|
@ -69,12 +71,20 @@ func main() {
|
||||||
log.Fatalf("Error parsing config file: %v\n", err)
|
log.Fatalf("Error parsing config file: %v\n", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
serveBackups := true
|
||||||
|
if stat, err := os.Stat(config.BackupDir); os.IsNotExist(err) || !stat.IsDir() {
|
||||||
|
log.Printf("Backup directory %v does not exist; not serving backups.", config.BackupDir)
|
||||||
|
serveBackups = false
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set up templates
|
||||||
fmt.Print("Parsing templates...\n")
|
fmt.Print("Parsing templates...\n")
|
||||||
t, err := template.ParseFiles("templates/index.html")
|
t, err := template.ParseFiles("templates/index.html")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Error parsing HTML template: %v\n", err)
|
fmt.Printf("Error parsing HTML template: %v\n", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Connect to RCON servers
|
||||||
for i := range config.Servers {
|
for i := range config.Servers {
|
||||||
s := config.Servers[i]
|
s := config.Servers[i]
|
||||||
config.Servers[i].rconConnection, err = rcon.Dial(fmt.Sprintf("%v:%v", s.Host, s.RCONPort), s.RCONPassword)
|
config.Servers[i].rconConnection, err = rcon.Dial(fmt.Sprintf("%v:%v", s.Host, s.RCONPort), s.RCONPassword)
|
||||||
|
@ -114,6 +124,11 @@ func main() {
|
||||||
t.Execute(w, data)
|
t.Execute(w, data)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// Serve backup directory
|
||||||
|
if serveBackups {
|
||||||
|
http.Handle("/backups/", http.StripPrefix("/backups/", http.FileServer(http.Dir(config.BackupDir))))
|
||||||
|
}
|
||||||
|
|
||||||
if config.UseTLS {
|
if config.UseTLS {
|
||||||
|
|
||||||
certManager := autocert.Manager{
|
certManager := autocert.Manager{
|
||||||
|
|
|
@ -11,7 +11,8 @@
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>blackolivepineapple.pizza Factorio</h1>
|
<h1>blackolivepineapple.pizza Factorio</h1>
|
||||||
<p>Hosted by the <a href="https://blackolivepineapple.pizza/">Black Olive-Pineapple Pizza Consortium</a></p>
|
<p>Hosted by the <a href="https://blackolivepineapple.pizza/">Black Olive-Pineapple Pizza Consortium</a>, in collaboration with UMD's ACM Club</p>
|
||||||
|
<p>Backups are taken and archived periodically, and made available in the <a href="/backups">backup archive</a>.</p>
|
||||||
{{range .}}
|
{{range .}}
|
||||||
<h3>{{.Title}}</h3>
|
<h3>{{.Title}}</h3>
|
||||||
<ul>
|
<ul>
|
||||||
|
|
Loading…
Reference in a new issue