-
Notifications
You must be signed in to change notification settings - Fork 0
/
server_linux.go
73 lines (69 loc) · 1.61 KB
/
server_linux.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// +build !windows
package main
import (
"fmt"
"net"
"net/http"
"os"
"strconv"
"syscall"
"unsafe"
"github.com/fumiama/imago"
log "github.com/sirupsen/logrus"
)
func main() {
arglen := len(os.Args)
if arglen == 6 || arglen == 7 {
configfile = os.Args[2]
imgdir = os.Args[3]
custimgdir = os.Args[4]
err := loadconf(configfile)
if err != nil {
panic(err)
}
go flushconf()
if imgdir[len(imgdir)-1] != '/' {
imgdir += "/"
}
if custimgdir[len(custimgdir)-1] != '/' {
custimgdir += "/"
}
err = imago.Scanimgs(imgdir)
if err != nil {
panic(err)
}
pwd, _ = u82int(os.Args[5])
pwdstr := (*[2]uintptr)(unsafe.Pointer(&os.Args[5]))
for i := 0; i < len(os.Args[5]); i++ {
*(*uint8)(unsafe.Pointer((*pwdstr)[0] + uintptr(i))) = '*'
}
listener, err := net.Listen("tcp", os.Args[1])
if err != nil {
panic(err)
} else {
if arglen == 7 {
uid, err1 := strconv.Atoi(os.Args[6])
if err == nil {
syscall.Setuid(uid)
syscall.Setgid(uid)
} else {
panic(err1)
}
}
http.HandleFunc("/", index)
http.HandleFunc("/index.html", index)
http.HandleFunc("/signup", signup)
http.HandleFunc("/img", img)
http.HandleFunc("/upform", upform)
http.HandleFunc("/upload", upload)
http.HandleFunc("/vote", vote)
http.HandleFunc("/pick", pick)
http.HandleFunc("/pickdl", pickdl)
http.HandleFunc("/dice", dice)
// http.Handle("/yuka/", http.StripPrefix("/yuka/", http.FileServer(http.Dir(imgdir))))
log.Fatal(http.Serve(listener, nil))
}
} else {
fmt.Println("Usage: <listen_addr> <configfile> <imgdir> <custimgdir> <password> (userid)")
}
}