-
Notifications
You must be signed in to change notification settings - Fork 0
/
Admin.go
53 lines (44 loc) · 1.24 KB
/
Admin.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package main
import (
"fmt"
"net/http"
"os"
"github.com/abbot/go-http-auth"
"golang.org/x/crypto/bcrypt"
)
// returns the size of the IGC Meta tracks database collection
func adminTracksCount(w http.ResponseWriter, r *auth.AuthenticatedRequest) {
count := MgoTrackDB.count()
http.Header.Add(w.Header(), "content-type", "text/plain")
fmt.Fprint(w, count)
}
// deletes all IGC Meta tracks from database collection
func trackDropTable(w http.ResponseWriter, r *auth.AuthenticatedRequest /*r *http.Request*/) {
http.Header.Add(w.Header(), "content-type", "text/plain")
count := MgoTrackDB.count()
if count < 1 {
fmt.Fprint(w, count)
return
}
err := MgoTrackDB.dropTable()
if err != nil {
http.Error(w, "serverside error, unable to drop collection", http.StatusInternalServerError)
return
}
fmt.Fprint(w, count)
}
// check to see if username and password is correct
func secret(user, realm string) string {
if user == "overlord" {
// alternatively password could be read from (encrypted)file
password := os.Getenv("ADMINPASSWORD")
if password == "" {
password = "pass"
}
hashedPassword, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
if err == nil {
return string(hashedPassword)
}
}
return ""
}