forked from newlisponrockets/newLISP-on-Rockets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rockets-admin.lsp
executable file
·212 lines (186 loc) · 12.6 KB
/
rockets-admin.lsp
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#!/usr/bin/env newlisp
(load "newlisp-rockets.lisp") ; this is where the magic happens!
; (rockets-profile.lsp) - Rockets - Site admin / upload page
;
; This page allow the site owner to change the configuration of
; their newLISP on Rockets system.
;
; Written 2018 by Jeremy Reimer
(load "Rockets-config.lisp") ; load configuration information
(display-header (string RocketsConfig:Name " - Admin Page"))
(open-database RocketsConfig:Database)
(display-partial "rockets-checksignin") ; checks to see if user is signed in
(set 'active-page "rockets-profile")
(display-partial "rockets-navbar")
(define (update-page)
(save "Rockets-config.lisp" 'RocketsConfig)
(save "Rockets-navigation.lisp" 'RocketsNavigation)
;(displayln "POST: " ($POST))
(case ($GET "tab")
(nil (page-redirect "rockets-admin.lsp?updated=true"))
("custom" (page-redirect "rockets-admin.lsp?tab=custom&updated=true"))
("users" (page-redirect "rockets-admin.lsp?tab=users&updated=true"))
("media" (page-redirect "rockets-admin.lsp?tab=media&updated=true"))
)
)
(define (checked str-panel str-item)
(setq checkedvalue "")
(if (= str-panel "left") (if (find str-item RocketsConfig:LeftPanel) (setq checkedvalue " checked='checked'")))
(if (= str-panel "right") (if (find str-item RocketsConfig:RightPanel) (setq checkedvalue " checked='checked'")))
(setq return-value checkedvalue)
)
(displayln "<h2>Admin Page</h2>")
(if Rockets:IsUserAdmin (begin ; admin-only section
(if (nil? ($GET "tab")) (display-button-blue "General Configuration" "rockets-admin.lsp") (display-button "General Configuration" "rockets-admin.lsp"))
(if (= ($GET "tab") "custom") (display-button-blue "Custom Configuration" "rockets-admin.lsp?tab=custom") (display-button "Custom Configuration" "rockets-admin.lsp?tab=custom"))
(if (= ($GET "tab") "media") (display-button-blue "Media Configuration" "rockets-admin.lsp?tab=media") (display-button "Media Configuration" "rockets-admin.lsp?tab=media"))
(if (= ($GET "tab") "users") (display-button-blue "User Configuration" "rockets-admin.lsp?tab=users") (display-button "User Configuration" "rockets-admin.lsp?tab=users"))
(displayln "<p></p>")
; GENERAL CONFIGURATION ------------------------------------------------------------------------
(if (nil? ($GET "tab")) (begin
; if we made changes and updated the page, show success
(if ($GET "updated") (display-success "Settings updated."))
; display the form to make changes
(displayln "<form name='admin' method='POST'>")
(displayln "<h3>Site configuration</h3>")
(displayln "<p>Site short name: <input type='text' name='shortname' value='" RocketsConfig:ShortName "'></p>")
(displayln "<p>Site full name: <input type='text' name='longname' value='" RocketsConfig:Name "'></p>")
(displayln "<h3>Top menu navigation</h3>")
; display all navigation
(dolist (n RocketsNavigation:navbar-list)
(displayln "<p>Menu item: " $idx ": <input type='text' name='menuname" $idx "' value='" (n 0) "'>")
(displayln "Page destination: <input type='text' name='menuvalue" $idx "' value='" (n 1) "'>")
(if (> $idx 0) (display-button-red "Delete" (string "rockets-admin.lsp?del=" $idx)))
)
(displayln "</p><p>")
(display-button-green "Add menu item" (string "rockets-admin.lsp?add=true"))
(displayln "</p><hr>")
(displayln "<h3>Main Page configuration</h3>")
; this sets the default front page type if none was configured before
(if (nil? RocketsConfig:FrontPageType) (setq RocketsConfig:FrontPageType 1))
(setq page-choices '("Single page with custom content" "Single page with blog posts" "Two columns with custom left hand navbar content" "Three columns with custom left and right hand navbar content" ))
(displayln "<select name='mainpage' style='width: auto'>")
(dolist (c page-choices)
(display "<option value='" $idx "'")
(if (= $idx RocketsConfig:FrontPageType) (display " selected"))
(displayln ">" c "</option>")
)
(displayln "</select>")
; Left hand navigation options (only if you've enabled left-hand panel display)
(if (or (= RocketsConfig:FrontPageType 2) (= RocketsConfig:FrontPageType 3)) (begin
(displayln "<h3>Left-hand panel configuration</h3>")
(displayln "<input type='checkbox' name='leftpanel[]' value='box1'" (checked "left" "box1") ">Custom HTML display box 1<br>")
(displayln "<input type='checkbox' name='leftpanel[]' value='popposts'" (checked "left" "popposts") ">Most popular blog posts<br>")
(displayln "<input type='checkbox' name='leftpanel[]' value='recentposts'" (checked "left" "recentposts") ">Recent forum posts<br>")
(displayln "<input type='checkbox' name='leftpanel[]' value='forumlink'" (checked "left" "forumlink") ">Forum link<br>")
(displayln "<input type='checkbox' name='leftpanel[]' value='box2'" (checked "left" "box2") ">Custom HTML display box 2<br>")
(displayln "<input type='checkbox' name='leftpanel[]' value='box3'" (checked "left" "box3") ">Custom HTML display box 3<br>")
(displayln "<input type='checkbox' name='leftpanel[]' value='blogtopics'" (checked "left" "blogtopics") ">Blog topics<br>")
(displayln "<input type='checkbox' name='leftpanel[]' value='box4'" (checked "left" "box4") ">Custom HTML display box 4<br>")
))
(if (= RocketsConfig:FrontPageType 3) (begin
(displayln "<h3>Right-hand panel configuration</h3>")
(displayln "<input type='checkbox' name='rightpanel[]' value='box1'" (checked "right" "box1") ">Custom HTML display box 1<br>")
(displayln "<input type='checkbox' name='rightpanel[]' value='popposts'" (checked "right" "popposts") ">Most popular blog posts<br>")
(displayln "<input type='checkbox' name='rightpanel[]' value='recentposts'" (checked "right" "recentposts") ">Recent forum posts<br>")
(displayln "<input type='checkbox' name='rightpanel[]' value='forumlink'" (checked "right" "forumlink") ">Forum link<br>")
(displayln "<input type='checkbox' name='rightpanel[]' value='box2'" (checked "right" "box2") ">Custom HTML display box 2<br>")
(displayln "<input type='checkbox' name='rightpanel[]' value='box3'" (checked "right" "box3") ">Custom HTML display box 3<br>")
(displayln "<input type='checkbox' name='rightpanel[]' value='blogtopics'" (checked "right" "blogtopics") ">Blog topics<br>")
(displayln "<input type='checkbox' name='rightpanel[]' value='box4'" (checked "right" "box4") ">Custom HTML display box 4<br>")
))
(displayln "<hr><p><input type='submit' value='Save changes'></p>")
(displayln "</form>")
; add form for uploading a main image for the blog
(displayln "<p>Blog header image:")
(if RocketsConfig:HeaderImage
(displayln "<img src='images/" RocketsConfig:HeaderImage "' width=300 height=200>")
(displayln "Default image"))
(displayln "<form name='FileUpload' action='fileupload.lsp?updateheader=yes' method='POST' enctype='multipart/form-data'><input type='file' id='uploadName' name='uploaded_data' onChange='this.form.textname.value = this.value'><input type='hidden' name='textname'><input type='hidden' name='updateheaderimage' value='yes'><input type='submit' value='Upload' name='submit'></form>")
; if we've made changes to any items, save them.
(if ($POST) (begin
; check to see if name has changed
(setq get-name ($POST "shortname"))
(if get-name (begin
(setq RocketsConfig:ShortName get-name)
))
(setq get-long-name ($POST "longname"))
(if get-long-name (begin
(setq RocketsConfig:Name get-long-name)))
; check to see if links have changed
(dolist (m RocketsNavigation:navbar-list)
(setq item ($POST (string "menuname" $idx)))
(setq value ($POST (string "menuvalue" $idx)))
(setq (RocketsNavigation:navbar-list $idx 0) item)
(setq (RocketsNavigation:navbar-list $idx 1) value)
)
; check if main page layout has changed
(if ($POST "mainpage") (setq RocketsConfig:FrontPageType (int ($POST "mainpage"))))
; check if left and/or right hand panel configuration has changed
(if ($POST "leftpanel%5B%5D") (setq RocketsConfig:LeftPanel ($POST "leftpanel%5B%5D")))
(if ($POST "rightpanel%5B%5D") (setq RocketsConfig:RightPanel ($POST "rightpanel%5B%5D")))
(update-page)
))
; if we've added or deleted items, adjust list and save them
(if ($GET "add") (begin
(extend RocketsNavigation:navbar-list '(("New item" "filename-of-page")))
(update-page)
))
(if ($GET "del") (begin
(pop RocketsNavigation:navbar-list (int ($GET "del")))
(update-page)
))
)) ; end General Configuration section
; CUSTOM CONFIGURATION ------------------------------------------------------------------------
(if (= ($GET "tab") "custom") (begin
(if ($GET "updated") (display-success "Settings updated."))
(displayln "<form name='admin' method='POST'>")
(displayln "<h3>Custom HTML box 1</h3>")
(displayln "<textarea name='post1' id='html1' class='field span9' rows='10'>")
(if (read-file "partials/panel1.html") (displayln (read-file "partials/panel1.html")))
(displayln "</textarea>")
(displayln "<h3>Custom HTML box 2</h3>")
(displayln "<textarea name='post2' id='html2' class='field span9' rows='10'>")
(if (read-file "partials/panel2.html") (displayln (read-file "partials/panel2.html")))
(displayln "</textarea>")
(displayln "<h3>Custom HTML box 3</h3>")
(displayln "<textarea name='post3' id='html3' class='field span9' rows='10'>")
(if (read-file "partials/panel3.html") (displayln (read-file "partials/panel3.html")))
(displayln "</textarea>")
(displayln "<h3>Custom HTML box 4</h3>")
(displayln "<textarea name='post4' id='html4' class='field span9' rows='10'>")
(if (read-file "partials/panel4.html") (displayln (read-file "partials/panel4.html")))
(displayln "</textarea>")
(displayln "<hr><p><input type='submit' value='Save changes'></p>")
(displayln "</form>")
; note that we aren't doing any sanity checks on the HTML, because this page is only accessible to Admins
; if the admin wants to do a script injection attack on their own site, that's up to them!
(if ($POST) (begin
(if ($POST "post1") (begin
(write-file "partials/panel1.html" ($POST "post1"))
))
(if ($POST "post2") (begin
(write-file "partials/panel2.html" ($POST "post2"))
(displayln "POST2!!!!!!!!!!!!!!!!")
))
(if ($POST "post3") (begin
(write-file "partials/panel3.html" ($POST "post3"))
))
(if ($POST "post4") (begin
(write-file "partials/panel4.html" ($POST "post4"))
))
(update-page)
))
)) ; end General Configuration section
; MEDIA CONFIGURATION ------------------------------------------------------------------------
(if (= ($GET "tab") "media") (begin
)) ; end General Configuration section
; USERS CONFIGURATION ------------------------------------------------------------------------
(if (= ($GET "tab") "users") (begin
)) ; end General Configuration section
)
(displayln "<p>Sorry, you must be signed in to an admin account to access this page.</p><p><a href='rockets-main.lsp'>Return to main page.</a></p>")
)
(close-database)
(display-footer RocketsConfig:Owner)
(display-page) ; this is needed to actually display the page!