-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
126 lines (104 loc) · 4.38 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
package main
import (
services "UlboraCmsV3/services"
"fmt"
"html/template"
"log"
"net/http"
"os"
//services "UlboraCmsV3/services"
usession "github.com/Ulbora/go-better-sessions"
oauth2 "github.com/Ulbora/go-oauth2-client"
"github.com/gorilla/mux"
)
var s usession.Session
var token *oauth2.Token
var credentialToken *oauth2.Token
//var templateLoc = getTemplate()
var templates *template.Template
var templatesAdmin = template.Must(template.ParseFiles("./static/admin/index.html", "./static/admin/header.html",
"./static/admin/footer.html", "./static/admin/navbar.html", "./static/admin/contentNavbar.html",
"./static/admin/addContent.html", "./static/admin/images.html", "./static/admin/templates.html",
"./static/admin/updateContent.html", "./static/admin/mailServer.html", "./static/admin/templateUpload.html",
"./static/admin/imageUpload.html"))
var username string
func main() {
var recapt string
setTemplate()
s.MaxAge = sessingTimeToLive
s.Name = userSession
if os.Getenv("SESSION_SECRET_KEY") != "" {
s.SessionKey = os.Getenv("SESSION_SECRET_KEY")
} else {
s.SessionKey = "115722gggg14ddfg4567"
}
router := mux.NewRouter()
if len(os.Args) == 2 {
recapt = os.Args[1]
}
getCaptchaSecret(recapt)
//Web Site
router.HandleFunc("/", handleIndex)
router.HandleFunc("/{content}", handleIndex)
router.HandleFunc("/contact/form", handleContactForm)
router.HandleFunc("/contact/send", handleContactSend)
//token link
router.HandleFunc("/admin/token", handleToken)
//Admin site
router.HandleFunc("/admin/main", handleAdminIndex)
router.HandleFunc("/admin/main/", handleAdminIndex)
router.HandleFunc("/admin/addContent", handleAddContent)
router.HandleFunc("/admin/addContent/", handleAddContent)
router.HandleFunc("/admin/newContent", handleNewContent)
router.HandleFunc("/admin/getContent/{id}", handleGetContent)
router.HandleFunc("/admin/updateContent", handleUpdateContent)
router.HandleFunc("/admin/deleteContent/{id}/{cat}", handleDeleteContent)
router.HandleFunc("/admin/mailServer", handleMailServer)
router.HandleFunc("/admin/mailServerUpdate", handleMailServerUpdate)
router.HandleFunc("/admin/addImage", handleAddImage)
router.HandleFunc("/admin/uploadImage", handleImagerUpload)
router.HandleFunc("/admin/images", handleImages)
router.HandleFunc("/admin/deleteImage/{id}", handleDeleteImage)
router.HandleFunc("/admin/templates", handleTemplates)
router.HandleFunc("/admin/addTemplate", handleAddTemplate)
router.HandleFunc("/admin/uploadTemplate", handleTemplateUpload)
router.HandleFunc("/admin/templateActive/{id}", handleTemplateActive)
router.HandleFunc("/admin/deleteTemplate/{id}/{name}", handleDeleteTemplate)
router.HandleFunc("/admin/logout", handleLogout)
router.HandleFunc("/admin/logout/", handleLogout)
// admin resources
router.PathPrefix("/").Handler(http.FileServer(http.Dir("./static/")))
//http.Handle("/js", fs)
fmt.Println("Ulbora CMS V3 running!")
log.Println("Listening on :8090...")
http.ListenAndServe(":8090", router)
}
func setTemplate() {
var templateLoc = "default"
var t services.TemplateService
t.ClientID = getAuthCodeClient()
t.APIKey = getGatewayAPIKey()
t.Host = getTemplateHost()
tmpl := t.GetTemplate("cms", getAuthCodeClient())
if tmpl.Active {
templateLoc = tmpl.Name
}
fmt.Println("using template " + templateLoc)
// templates = template.Must(template.ParseFiles("./static/templates/"+templateLoc+"/index.html", "./static/templates/"+templateLoc+"/header.html",
// "./static/templates/"+templateLoc+"/footer.html", "./static/templates/"+templateLoc+"/navbar.html",
// "./static/templates/"+templateLoc+"/contact.html"))
var tp *template.Template
var tperr error
tp, tperr = template.ParseFiles("./static/templates/"+templateLoc+"/index.html", "./static/templates/"+templateLoc+"/header.html",
"./static/templates/"+templateLoc+"/footer.html", "./static/templates/"+templateLoc+"/navbar.html",
"./static/templates/"+templateLoc+"/contact.html")
if tperr != nil {
fmt.Println("Can't find assigned template " + templateLoc + ", using default.")
fmt.Println(tperr)
templateLoc = "default"
tp, tperr = template.ParseFiles("./static/templates/"+templateLoc+"/index.html", "./static/templates/"+templateLoc+"/header.html",
"./static/templates/"+templateLoc+"/footer.html", "./static/templates/"+templateLoc+"/navbar.html",
"./static/templates/"+templateLoc+"/contact.html")
}
templates = template.Must(tp, tperr)
}