blob: 26a7e293270ba11ec36ce8fb9373ee20ea58db06 (
plain)
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
54
55
56
57
58
59
60
61
62
|
package main
// YEAH YEAH CARGO CULT PROGRAMMING
// *HACK* *HACK* *COPY* *HACK*
import (
"flag"
"fmt"
"time"
"net/http"
"log"
"encoding/json"
"os/exec"
)
type Clubinfo struct {
Last_event string
Club_offen bool
}
func main() {
// WAAAAAH!
var url = flag.String("url", "http://club.entropia.de", "Target URL for JSON data")
var timeout = flag.Int("timeout", 1, "Timeout in hours")
var dryrun = flag.Bool("dryrun", false, "Dry run")
flag.Parse()
resp, err := http.Get(*url)
if err != nil {
log.Fatal(err)
}
defer resp.Body.Close()
// WAAAAAAAAHAAAAAA!
decoder := json.NewDecoder(resp.Body)
var c Clubinfo
err = decoder.Decode(&c)
if err != nil {
log.Fatal(err)
}
// RFC3339 without ':' for time zone foooooo
last, _ := time.Parse("2006-01-02T15:04:05Z0700", c.Last_event)
// WAAAAABWHARGLGLRELRLLLllmn...
if time.Since(last).Hours() > float64(*timeout) {
if !c.Club_offen {
if !*dryrun {
cmd := exec.Command("shutdown", "-h +5")
cmd.Start()
} else {
fmt.Println("I advise against letting this machine run any longer.");
}
}
}
}
|