2016-12-02 07:38:54 +00:00
|
|
|
package main
|
2016-12-03 11:06:47 +00:00
|
|
|
import "fmt"
|
2016-12-02 07:38:54 +00:00
|
|
|
import "log"
|
|
|
|
import "bytes"
|
|
|
|
import "net/http"
|
|
|
|
|
2017-01-17 07:55:46 +00:00
|
|
|
var error_internal []byte
|
|
|
|
var error_notfound []byte
|
|
|
|
func init_errors() error {
|
|
|
|
var b bytes.Buffer
|
|
|
|
user := User{0,"Guest","",0,false,false,false,false,false,false,GuestPerms,"",false,"","","","","",0,0,"0.0.0.0.0"}
|
|
|
|
pi := Page{"Internal Server Error",user,nList,tList,"A problem has occurred in the system."}
|
|
|
|
err := templates.ExecuteTemplate(&b,"error.html", pi)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
error_internal = b.Bytes()
|
|
|
|
|
|
|
|
b.Reset()
|
|
|
|
pi = Page{"Not Found",user,nList,tList,"The requested page doesn't exist."}
|
|
|
|
err = templates.ExecuteTemplate(&b,"error.html", pi)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
error_notfound = b.Bytes()
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-02-05 16:36:54 +00:00
|
|
|
func InternalError(err error, w http.ResponseWriter, r *http.Request) {
|
2017-01-17 07:55:46 +00:00
|
|
|
w.Write(error_internal)
|
2016-12-02 07:38:54 +00:00
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2017-02-05 16:36:54 +00:00
|
|
|
func InternalErrorJSQ(err error, w http.ResponseWriter, r *http.Request, is_js string) {
|
2017-01-17 07:55:46 +00:00
|
|
|
w.WriteHeader(500)
|
2016-12-02 07:38:54 +00:00
|
|
|
if is_js == "0" {
|
2017-01-17 07:55:46 +00:00
|
|
|
w.Write(error_internal)
|
2016-12-02 07:38:54 +00:00
|
|
|
} else {
|
2017-03-01 11:36:50 +00:00
|
|
|
w.Write([]byte(`{"errmsg":"A problem has occured in the system."}`))
|
2016-12-02 07:38:54 +00:00
|
|
|
}
|
2017-01-17 07:55:46 +00:00
|
|
|
log.Fatal(err)
|
2016-12-02 07:38:54 +00:00
|
|
|
}
|
|
|
|
|
2017-02-28 09:27:28 +00:00
|
|
|
func InternalErrorJS(err error, w http.ResponseWriter, r *http.Request) {
|
|
|
|
w.WriteHeader(500)
|
2017-03-01 11:36:50 +00:00
|
|
|
w.Write([]byte(`{"errmsg":"A problem has occured in the system."}`))
|
2017-02-28 09:27:28 +00:00
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2017-02-05 16:36:54 +00:00
|
|
|
func PreError(errmsg string, w http.ResponseWriter, r *http.Request) {
|
|
|
|
w.WriteHeader(500)
|
|
|
|
user := User{ID:0,Group:6,Perms:GuestPerms,}
|
|
|
|
pi := Page{"Error",user,nList,tList,errmsg}
|
|
|
|
var b bytes.Buffer
|
|
|
|
templates.ExecuteTemplate(&b,"error.html",pi)
|
|
|
|
fmt.Fprintln(w,b.String())
|
|
|
|
}
|
|
|
|
|
2016-12-02 07:38:54 +00:00
|
|
|
func LocalError(errmsg string, w http.ResponseWriter, r *http.Request, user User) {
|
2017-01-17 07:55:46 +00:00
|
|
|
w.WriteHeader(500)
|
|
|
|
pi := Page{"Local Error",user,nList,tList,errmsg}
|
2016-12-02 07:38:54 +00:00
|
|
|
var b bytes.Buffer
|
2017-02-05 16:36:54 +00:00
|
|
|
templates.ExecuteTemplate(&b,"error.html",pi)
|
2017-01-17 07:55:46 +00:00
|
|
|
fmt.Fprintln(w,b.String())
|
2016-12-02 07:38:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func LoginRequired(w http.ResponseWriter, r *http.Request, user User) {
|
2017-01-17 07:55:46 +00:00
|
|
|
w.WriteHeader(401)
|
|
|
|
pi := Page{"Local Error",user,nList,tList,"You need to login to do that."}
|
2016-12-02 07:38:54 +00:00
|
|
|
var b bytes.Buffer
|
2017-02-05 16:36:54 +00:00
|
|
|
templates.ExecuteTemplate(&b,"error.html",pi)
|
2017-01-17 07:55:46 +00:00
|
|
|
fmt.Fprintln(w,b.String())
|
2016-12-02 07:38:54 +00:00
|
|
|
}
|
|
|
|
|
2017-02-05 16:36:54 +00:00
|
|
|
func PreErrorJSQ(errmsg string, w http.ResponseWriter, r *http.Request, is_js string) {
|
|
|
|
w.WriteHeader(500)
|
|
|
|
if is_js == "0" {
|
|
|
|
user := User{ID:0,Group:6,Perms:GuestPerms,}
|
|
|
|
pi := Page{"Local Error",user,nList,tList,errmsg}
|
|
|
|
var b bytes.Buffer
|
|
|
|
templates.ExecuteTemplate(&b,"error.html", pi)
|
|
|
|
fmt.Fprintln(w,b.String())
|
|
|
|
} else {
|
2017-03-01 11:36:50 +00:00
|
|
|
w.Write([]byte(`{"errmsg":"` + errmsg + `"}`))
|
2017-02-05 16:36:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-02 07:38:54 +00:00
|
|
|
func LocalErrorJSQ(errmsg string, w http.ResponseWriter, r *http.Request, user User, is_js string) {
|
2017-01-17 07:55:46 +00:00
|
|
|
w.WriteHeader(500)
|
2016-12-02 07:38:54 +00:00
|
|
|
if is_js == "0" {
|
2017-01-17 07:55:46 +00:00
|
|
|
pi := Page{"Local Error",user,nList,tList,errmsg}
|
2016-12-02 07:38:54 +00:00
|
|
|
var b bytes.Buffer
|
|
|
|
templates.ExecuteTemplate(&b,"error.html", pi)
|
2017-01-17 07:55:46 +00:00
|
|
|
fmt.Fprintln(w,b.String())
|
2016-12-02 07:38:54 +00:00
|
|
|
} else {
|
2017-03-01 11:36:50 +00:00
|
|
|
w.Write([]byte(`{"errmsg":"` + errmsg + `"}`))
|
2016-12-02 07:38:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-28 09:27:28 +00:00
|
|
|
func LocalErrorJS(errmsg string, w http.ResponseWriter, r *http.Request) {
|
|
|
|
w.WriteHeader(500)
|
|
|
|
w.Write([]byte(`{'errmsg': '` + errmsg + `'}`))
|
|
|
|
}
|
|
|
|
|
2016-12-03 10:25:39 +00:00
|
|
|
func NoPermissions(w http.ResponseWriter, r *http.Request, user User) {
|
2017-01-17 07:55:46 +00:00
|
|
|
w.WriteHeader(403)
|
|
|
|
pi := Page{"Local Error",user,nList,tList,"You don't have permission to do that."}
|
2016-12-03 10:25:39 +00:00
|
|
|
var b bytes.Buffer
|
|
|
|
templates.ExecuteTemplate(&b,"error.html", pi)
|
|
|
|
errpage := b.String()
|
2016-12-03 11:06:47 +00:00
|
|
|
fmt.Fprintln(w,errpage)
|
2016-12-03 10:25:39 +00:00
|
|
|
}
|
|
|
|
|
2016-12-02 07:38:54 +00:00
|
|
|
func NoPermissionsJSQ(w http.ResponseWriter, r *http.Request, user User, is_js string) {
|
2017-01-17 07:55:46 +00:00
|
|
|
w.WriteHeader(403)
|
2016-12-02 07:38:54 +00:00
|
|
|
if is_js == "0" {
|
2017-01-17 07:55:46 +00:00
|
|
|
pi := Page{"Local Error",user,nList,tList,"You don't have permission to do that."}
|
2016-12-02 07:38:54 +00:00
|
|
|
var b bytes.Buffer
|
2016-12-04 10:44:28 +00:00
|
|
|
templates.ExecuteTemplate(&b,"error.html", pi)
|
2017-01-17 07:55:46 +00:00
|
|
|
fmt.Fprintln(w,b.String())
|
2016-12-04 10:44:28 +00:00
|
|
|
} else {
|
2017-03-01 11:36:50 +00:00
|
|
|
w.Write([]byte(`{"errmsg":"You don't have permission to do that."}`))
|
2016-12-04 10:44:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func Banned(w http.ResponseWriter, r *http.Request, user User) {
|
2017-01-17 07:55:46 +00:00
|
|
|
w.WriteHeader(403)
|
|
|
|
pi := Page{"Banned",user,nList,tList,"You have been banned from this site."}
|
2016-12-04 10:44:28 +00:00
|
|
|
var b bytes.Buffer
|
|
|
|
templates.ExecuteTemplate(&b,"error.html", pi)
|
2017-01-17 07:55:46 +00:00
|
|
|
fmt.Fprintln(w,b.String())
|
2016-12-04 10:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func BannedJSQ(w http.ResponseWriter, r *http.Request, user User, is_js string) {
|
2017-01-17 07:55:46 +00:00
|
|
|
w.WriteHeader(403)
|
2016-12-04 10:44:28 +00:00
|
|
|
if is_js == "0" {
|
2017-01-17 07:55:46 +00:00
|
|
|
pi := Page{"Banned",user,nList,tList,"You have been banned from this site."}
|
2016-12-04 10:44:28 +00:00
|
|
|
var b bytes.Buffer
|
2016-12-02 07:38:54 +00:00
|
|
|
templates.ExecuteTemplate(&b,"error.html", pi)
|
2017-01-17 07:55:46 +00:00
|
|
|
fmt.Fprintln(w,b.String())
|
2016-12-02 07:38:54 +00:00
|
|
|
} else {
|
2017-03-01 11:36:50 +00:00
|
|
|
w.Write([]byte(`{"errmsg":"You have been banned from this site."}`))
|
2016-12-02 07:38:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func LoginRequiredJSQ(w http.ResponseWriter, r *http.Request, user User, is_js string) {
|
2017-01-17 07:55:46 +00:00
|
|
|
w.WriteHeader(401)
|
2016-12-02 07:38:54 +00:00
|
|
|
if is_js == "0" {
|
2017-01-17 07:55:46 +00:00
|
|
|
pi := Page{"Local Error",user,nList,tList,"You need to login to do that."}
|
2016-12-02 07:38:54 +00:00
|
|
|
var b bytes.Buffer
|
|
|
|
templates.ExecuteTemplate(&b,"error.html", pi)
|
2017-01-17 07:55:46 +00:00
|
|
|
fmt.Fprintln(w,b.String())
|
2016-12-02 07:38:54 +00:00
|
|
|
} else {
|
2017-03-01 11:36:50 +00:00
|
|
|
w.Write([]byte(`{"errmsg":"You need to login to do that."}`))
|
2016-12-02 07:38:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-06 10:26:48 +00:00
|
|
|
func SecurityError(w http.ResponseWriter, r *http.Request, user User) {
|
2017-01-17 07:55:46 +00:00
|
|
|
w.WriteHeader(403)
|
|
|
|
pi := Page{"Security Error",user,nList,tList,"There was a security issue with your request."}
|
2016-12-06 10:26:48 +00:00
|
|
|
var b bytes.Buffer
|
|
|
|
templates.ExecuteTemplate(&b,"error.html", pi)
|
2017-01-17 07:55:46 +00:00
|
|
|
fmt.Fprintln(w,b.String())
|
2016-12-06 10:26:48 +00:00
|
|
|
}
|
|
|
|
|
2017-02-05 16:36:54 +00:00
|
|
|
func NotFound(w http.ResponseWriter, r *http.Request) {
|
2016-12-06 10:26:48 +00:00
|
|
|
w.WriteHeader(404)
|
2017-01-17 07:55:46 +00:00
|
|
|
w.Write(error_notfound)
|
2016-12-06 10:26:48 +00:00
|
|
|
}
|
|
|
|
|
2017-01-03 07:47:31 +00:00
|
|
|
func CustomError(errmsg string, errcode int, errtitle string, w http.ResponseWriter, r *http.Request, user User) {
|
2017-01-17 07:55:46 +00:00
|
|
|
w.WriteHeader(errcode)
|
|
|
|
pi := Page{errtitle,user,nList,tList,errmsg}
|
2017-01-03 07:47:31 +00:00
|
|
|
var b bytes.Buffer
|
|
|
|
templates.ExecuteTemplate(&b,"error.html", pi)
|
2017-01-17 07:55:46 +00:00
|
|
|
fmt.Fprintln(w,b.String())
|
2017-01-03 07:47:31 +00:00
|
|
|
}
|
|
|
|
|
2016-12-02 07:38:54 +00:00
|
|
|
func CustomErrorJSQ(errmsg string, errcode int, errtitle string, w http.ResponseWriter, r *http.Request, user User, is_js string) {
|
2017-01-17 07:55:46 +00:00
|
|
|
w.WriteHeader(errcode)
|
2016-12-02 07:38:54 +00:00
|
|
|
if is_js == "0" {
|
2017-01-17 07:55:46 +00:00
|
|
|
pi := Page{errtitle,user,nList,tList,errmsg}
|
2016-12-02 07:38:54 +00:00
|
|
|
var b bytes.Buffer
|
|
|
|
templates.ExecuteTemplate(&b,"error.html", pi)
|
2017-01-17 07:55:46 +00:00
|
|
|
fmt.Fprintln(w,b.String())
|
2016-12-02 07:38:54 +00:00
|
|
|
} else {
|
2017-03-01 11:36:50 +00:00
|
|
|
w.Write([]byte(`{"errmsg":"` + errmsg + `"}`))
|
2016-12-02 07:38:54 +00:00
|
|
|
}
|
|
|
|
}
|