-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdie.go
180 lines (148 loc) · 5.39 KB
/
die.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
package main
import (
"fmt"
"flag"
"net/http"
"math/rand"
"time"
// "encoding/json"
// "strings"
// "github.com/NYTimes/gziphandler"
// "runtime"
)
func buildHTML( incluceHF int, outCSS []string, outJS []string, outHTML []string, isLoggedIn string, u *Users ) string {
o := ""
if(incluceHF == 1){
o += fileToString( conf.URLS["HTML"] + "/innerHeader.htm" )
}
for _, element := range outHTML {
o += fileToString( element )
}
css_o := ""
js_o := ""
for _, element := range outCSS {
css_o += fileToString( element )
}
for _, element := range outJS {
js_o += fileToString( element )
}
if(incluceHF == 1){
o += fileToString( conf.URLS["HTML"] + "/innerFooter.htm" )
}
o = iReplace(o, "<STYLE></STYLE>" , "<STYLE>" + css_o + "</STYLE>" ,1)
o = iReplace(o, "<SCRIPT></SCRIPT>" , "<SCRIPT>" + js_o + "</SCRIPT>" ,1)
o = iReplace(o, "<MYCX>" , u.Crosssite ,-1)
o = iReplace(o, "<ROOT_URL>" , conf.URLS["ROOT"] ,-1)
o = iReplace(o, "<ISLOGGEDIN>" , isLoggedIn ,-1)
o = iReplace(o, "<BACGROUNDIMG>" , randbg() ,-1)
return o
}
func uriHandler(w http.ResponseWriter, r *http.Request) {
var uri MyURI
err := uri.SetURI(r)
cErr(err, "Set URI Information", true)
if( uri.RFileExt == "ico" || uri.RFileExt == "png" || uri.RFileExt == "jpg" || uri.RFileExt == "pdf" || uri.RFileExt == "js" ||
uri.RFileExt == "css" || uri.RFileExt == "txt" || uri.RFileExt == "xml" || uri.RFileExt == "min.map" ||
uri.RFileExt == "wav" || uri.RFileExt == "mp4" || uri.RFileExt == "mov" || uri.RFileExt == "mp3" || uri.RFileExt == "webp" ){
if conf.BOOL_VALS["UseHTTPControlCashe"] { w.Header().Set("Cache-Control", "max-age=31536000") }
http.ServeFile(w, r, conf.URLS["PUBLIC"] + "/" + uri.RFilePath )
}else{
// Check Login
u := Users{}
isLoggedIn := "0";
Cookie := GetCookie(r, "dieroll")
passvars := Hreqs{}
pull_passvars( r, &passvars )
check_login( w, &Cookie, &isLoggedIn, &u, &passvars, uri.Controller ) // Sets User (u) if found.
if( uri.Controller == "er" ){
fmt.Fprintf(w, "%s", "1")
}else if( uri.Controller == "ajax" ){
// r.ParseForm() and then read the values using r.Form["username"][0]
// check cx u.cx == upload.cx
if( uri.Method == "login" ){
do_login(w,r,&passvars)
}else if( uri.Method == "logout" ){
do_logout(w,&u)
}else if( uri.Method == "get_dashboard" ){
pull_user_list(w,r,&u)
}else if( uri.Method == "update_user" ){
update_user(w,r,&u,&passvars)
}else if( uri.Method == "pull_die_roll" ){
pull_die_roll(w,r,&u,&passvars)
}else if( uri.Method == "die_roll" ){
die_roll(w,r,&u,&passvars)
}else if( uri.Method == "char_delete" ){
char_delete(w,r,&u,&passvars)
}else if( uri.Method == "char_list" ){
char_list(w,r,&u,&passvars)
}else if( uri.Method == "char_load" ){
char_load(w,r,&u,&passvars)
}else if( uri.Method == "char_update" ){
char_update(w,r,&u,&passvars)
}else if( uri.Method == "char_update_img" ){
char_update_img(w,r,&u,&passvars)
}else if( uri.Method == "camp_new" ){
camp_new(w,r,&u,&passvars)
}else if( uri.Method == "camp_list" ){
camp_list(w,r,&u,&passvars)
} else {
// Mabey do something?
}
// fmt.Fprintf(w, "%s", "useing ajax must be logged in.")
}else{
// Include Header / Footer, CSS, JS, HTM
css := []string{ conf.URLS["CSS"] + "/general.css" }
js := []string{ conf.URLS["JS"] + "/general.js" }
html := []string{ conf.URLS["HTML"] + "/home.htm" }
o := buildHTML(1, css, js, html, isLoggedIn, &u)
// fmt.Fprintf(w, "%s", "The page you are looking for does not exist.")
fmt.Fprintf(w, "%s", o)
}
}
/*
}else if( uri.Controller == "captcha" ){
uri_CAPTCHA(w, r, &uri)
}else if( uri.Controller == "scripts" ){
uri_SCRIPT(w, r, &uri)
}else if( uri.Controller == "ajax" ){
// $.ajaxSetup({ cache: false }); - Apparently we dont need to specify cache control because ajax post values.
//w.Header().Set("Cache-Control","no-store, must-revalidate")
//w.Header().Set("Pragma","no-cache")
//w.Header().Set("Expires","-1")
//w.Header().Set("Vary","Accept-Encoding")
uri_AJAX(w, r, &uri)
}else{
uri_NORMAL(w, r, &uri)
}
*/
}
func main() {
// command , default, options report
confPtr := flag.String("c","local","-c local|??|config_file_name")
flag.Parse()
if *confPtr != "" { *confPtr = *confPtr + ".conf" } else { *confPtr = "conf" }
conf.getConfig(*confPtr)
// runtime.GOMAXPROCS( conf.SERVER["GOMAXPROCS"] )
// File Setup
if( iExist("private/users/privileges.idx" ) ){
iWriteFileByte( "private/users/privileges.idx", []byte("") )
}
rand.Seed(time.Now().UnixNano())
Tools_init()
buildbg()
http.HandleFunc("/", uriHandler)
// go func(){
// err := http.ListenAndServeTLS(conf.URLS["listen_sport"], conf.SERVERSCRT["CERT_CRT"], conf.SERVERSCRT["CERT_KEY"], nil )
// cErr(err, "HTTPS: Server Error: ", true)
// }()
// go http.ListenAndServeTLS(conf.URLS["listen_sport"], conf.SERVERSCRT["CERT_CRT"], conf.SERVERSCRT["CERT_KEY"], nil )
if (conf.USEHTTPS == 1){
fmt.Println( "Listening Secure on: " + conf.HTTPSPORT )
err := http.ListenAndServeTLS(":" + conf.HTTPSPORT, conf.SERVERSCRT["CERT_CRT"], conf.SERVERSCRT["CERT_KEY"], nil )
cErr(err, "HTTPS: Server Error: ", false)
} else {
fmt.Println( "Listening on: " + conf.HTTPPORT )
err := http.ListenAndServe(":" + conf.HTTPPORT, nil )
cErr(err, "HTTP: Server Error: ", false)
}
}