-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
171 lines (150 loc) · 3.29 KB
/
main.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
package main
import (
// "html/template"
// "fmt"
_ "github.com/go-sql-driver/mysql"
"github.com/gorilla/sessions"
// "github.com/shurcooL/github_flavored_markdown"
// "html/template"
"net"
"net/http"
"net/http/fcgi"
"regexp"
)
var (
// key must be 16, 24 or 32 bytes long (AES-128, AES-192 or AES-256)
key = []byte("17923641793298746918723649781112")
store = sessions.NewCookieStore(key)
)
type regdata struct {
Invite string
Username string
Password string
Resume string
Url string
To string
}
type regchk struct {
Invitech int
Usernamereg int
Usernameex int
Passwordrx int
Passwordcon int
fnrx, snrx int
pln, fln, sln int
}
type zombie struct {
Zho string
}
type Getout struct{
Who string
}
type User struct {
id int
username string
fname string
sname string
password string
email string
about string
userpic string
timereg string
}
type Signdata struct {
Id int
Userpic string
Username,Fname,Sname string
}
var validStr = regexp.MustCompile("^([a-zA-Z0-9а-яА-Я]+)$")
type posttype struct
{
Id int
Post []byte
Pfname string
Psname string
Posttime string
}
type commtype struct {
Comment []byte
Username, Comtime string
}
type Postdata struct {
Id int
Post []byte
Fname, Sname string
Username string
Posttime string
Userpic string
}
type Postformdata struct {
Id int
Username,Fname, Sname string
Userpic string
}
type Comformdata struct {
Id int
Username,Fname,Sname string
Userpic string
}
type Comformdata2 struct {
Postid int
Pusername,Fname, Sname string
Posttime string
}
type tmp struct {
Title, Note string
}
var validnon = regexp.MustCompile("^/(postform|reg|regproc|enter|sign|post|posts|exit|home|profile|filesave)/$")
var vaitdn = regexp.MustCompile("^/(comform|comment|users)/([0-9]+)$")
var validsoap = regexp.MustCompile("^/(checkemail)/(.*)$")
func chknon(w http.ResponseWriter, r *http.Request) {
m := validnon.FindStringSubmatch(r.URL.Path)
if m == nil {
http.Redirect(w,r,"/static/404.htmml",301)
}
}
func chkn(w http.ResponseWriter, r *http.Request) {
m := vaitdn.FindStringSubmatch(r.URL.Path)
if m == nil {
http.Redirect(w,r,"/static/404.htmml",301)
}
}
func chksoap(w http.ResponseWriter, r *http.Request) {
m := validsoap.FindStringSubmatch(r.URL.Path)
if m == nil {
http.Redirect(w,r,"/static/404.htmml",301)
}
}
func main() {
db := dbConnect()
// mux := http.NewServeMux()
fs := http.FileServer(http.Dir("./static"))
http.Handle("/",fs)
// mux.HandleFunc("/user/)
http.Handle("/reg", fs)
http.HandleFunc("/regproc/", regprocHandle)
http.Handle("/enter",fs)
http.HandleFunc("/sign/",signHandler)
http.HandleFunc("/postform/",postForm)
http.HandleFunc("/post/",postHandle)
http.HandleFunc("/posts/",postsHandle)
http.HandleFunc("/comform/",comForm)
http.HandleFunc("/comment/",comHandler)
http.HandleFunc("/exit/", leaveHandler)
http.HandleFunc("/users/",usersHandler)
http.HandleFunc("/checkemail/",checkemail)
http.HandleFunc("/home/",Home);
http.HandleFunc("/profile/",fileform)
http.HandleFunc("/filesave/",filesave)
// mux.HandleFunc("/comment/",comments)
// mux.HandleFunc("/secret", secret)
// mux.HandleFunc("/logout", logout)
// r.HandleFunc("/enter", enterHandler)
l, err := net.Listen("tcp", ":9001")
if err != nil{
return
}
fcgi.Serve(l, nil)
db.Close()
// http.ListenAndServe(":8000", r)
}