1 |
nishi |
1 |
/* $Id: modern.c 6 2024-08-21 00:44:17Z nishi $ */
|
|
|
2 |
|
|
|
3 |
#include "rv_query.h"
|
|
|
4 |
|
|
|
5 |
#include "rv_util.h"
|
|
|
6 |
#include "rv_version.h"
|
3 |
nishi |
7 |
#include "rv_auth.h"
|
1 |
nishi |
8 |
#include "rv_db.h"
|
|
|
9 |
|
|
|
10 |
#include "../../config.h"
|
|
|
11 |
|
|
|
12 |
#include <stdlib.h>
|
|
|
13 |
#include <string.h>
|
|
|
14 |
|
|
|
15 |
extern char* buffer;
|
|
|
16 |
void add_data(char** data, const char* txt);
|
|
|
17 |
void render_stuff();
|
|
|
18 |
|
|
|
19 |
char* title = NULL;
|
|
|
20 |
char* desc = NULL;
|
|
|
21 |
char* page = NULL;
|
6 |
nishi |
22 |
extern char* user;
|
1 |
nishi |
23 |
|
3 |
nishi |
24 |
void render_page(void) {
|
1 |
nishi |
25 |
rv_load_query('Q');
|
|
|
26 |
char* query = rv_get_query("page");
|
|
|
27 |
if(query == NULL) query = "welcome";
|
|
|
28 |
|
3 |
nishi |
29 |
if(strcmp(query, "welcome") == 0) {
|
1 |
nishi |
30 |
title = rv_strdup("Welcome");
|
|
|
31 |
desc = rv_strdup("Welcome to " INSTANCE_NAME ".");
|
|
|
32 |
page = rv_strcat3("Welcome to " INSTANCE_NAME ".<br>This instance is running RepoView version ", rv_get_version(), ".");
|
3 |
nishi |
33 |
} else if(strcmp(query, "login") == 0) {
|
1 |
nishi |
34 |
title = rv_strdup("Login");
|
|
|
35 |
desc = rv_strdup("You can log in to your account here.");
|
|
|
36 |
page = rv_strdup("");
|
|
|
37 |
|
|
|
38 |
add_data(&page, "<form action=\"");
|
|
|
39 |
add_data(&page, INSTANCE_ROOT);
|
|
|
40 |
add_data(&page, "/?page=sendlogin\" method=\"POST\">\n");
|
|
|
41 |
add_data(&page, " <table border=\"0\">\n");
|
|
|
42 |
add_data(&page, " <tr>\n");
|
|
|
43 |
add_data(&page, " <th>Username</th>\n");
|
|
|
44 |
add_data(&page, " <td>\n");
|
|
|
45 |
add_data(&page, " <input name=\"username\">\n");
|
|
|
46 |
add_data(&page, " </td>\n");
|
|
|
47 |
add_data(&page, " </tr>\n");
|
|
|
48 |
add_data(&page, " <tr>\n");
|
|
|
49 |
add_data(&page, " <th>Password</th>\n");
|
|
|
50 |
add_data(&page, " <td>\n");
|
|
|
51 |
add_data(&page, " <input name=\"password\" type=\"password\">\n");
|
|
|
52 |
add_data(&page, " </td>\n");
|
|
|
53 |
add_data(&page, " </tr>\n");
|
|
|
54 |
add_data(&page, " </table>\n");
|
|
|
55 |
add_data(&page, " <input type=\"submit\" value=\"Login\">\n");
|
|
|
56 |
add_data(&page, "</form>\n");
|
3 |
nishi |
57 |
} else if(strcmp(query, "sendlogin") == 0) {
|
1 |
nishi |
58 |
title = rv_strdup("Login Result");
|
|
|
59 |
page = rv_strdup("");
|
|
|
60 |
|
|
|
61 |
rv_load_query('P');
|
3 |
nishi |
62 |
if(rv_get_query("username") == NULL || rv_get_query("password") == NULL) {
|
5 |
nishi |
63 |
add_data(&page, "Invalid form.\n");
|
3 |
nishi |
64 |
} else {
|
|
|
65 |
if(rv_has_user(rv_get_query("username"))) {
|
5 |
nishi |
66 |
if(rv_check_password(rv_get_query("username"), rv_get_query("password"))) {
|
6 |
nishi |
67 |
if(user != NULL) free(user);
|
|
|
68 |
user = rv_strdup(rv_get_query("username"));
|
5 |
nishi |
69 |
add_data(&page, "Welcome back.\n");
|
|
|
70 |
rv_save_login(rv_get_query("username"));
|
|
|
71 |
} else {
|
|
|
72 |
add_data(&page, "Invalid password.");
|
|
|
73 |
}
|
3 |
nishi |
74 |
} else {
|
5 |
nishi |
75 |
add_data(&page, "User does not exist.");
|
1 |
nishi |
76 |
}
|
|
|
77 |
}
|
6 |
nishi |
78 |
} else if(strcmp(query, "mypage") == 0) {
|
|
|
79 |
title = rv_strdup("My Page");
|
|
|
80 |
desc = rv_strdup("You manage your information here.");
|
|
|
81 |
if(user == NULL) {
|
|
|
82 |
page = rv_strdup("It looks like you are not logged in.<br>Want to <a href=\"");
|
|
|
83 |
add_data(&page, INSTANCE_ROOT);
|
|
|
84 |
add_data(&page, "/?page=login\">log in</a>?\n");
|
|
|
85 |
}
|
1 |
nishi |
86 |
}
|
|
|
87 |
|
|
|
88 |
if(title == NULL) title = rv_strdup("");
|
|
|
89 |
if(desc == NULL) desc = rv_strdup("");
|
|
|
90 |
if(page == NULL) page = rv_strdup("");
|
|
|
91 |
render_stuff();
|
|
|
92 |
free(page);
|
|
|
93 |
free(desc);
|
|
|
94 |
free(title);
|
|
|
95 |
}
|
|
|
96 |
|
3 |
nishi |
97 |
char* escape(const char* str) {
|
1 |
nishi |
98 |
char* r = malloc(1);
|
|
|
99 |
r[0] = 0;
|
|
|
100 |
char cbuf[2];
|
|
|
101 |
cbuf[1] = 0;
|
|
|
102 |
int i;
|
3 |
nishi |
103 |
for(i = 0; str[i] != 0; i++) {
|
|
|
104 |
if(str[i] == '<') {
|
1 |
nishi |
105 |
char* tmp = r;
|
|
|
106 |
r = rv_strcat(tmp, "<");
|
|
|
107 |
free(tmp);
|
3 |
nishi |
108 |
} else if(str[i] == '>') {
|
1 |
nishi |
109 |
char* tmp = r;
|
|
|
110 |
r = rv_strcat(tmp, ">");
|
|
|
111 |
free(tmp);
|
3 |
nishi |
112 |
} else {
|
1 |
nishi |
113 |
cbuf[0] = str[i];
|
|
|
114 |
char* tmp = r;
|
|
|
115 |
r = rv_strcat(tmp, cbuf);
|
|
|
116 |
free(tmp);
|
|
|
117 |
}
|
|
|
118 |
}
|
|
|
119 |
return r;
|
|
|
120 |
}
|
|
|
121 |
|
3 |
nishi |
122 |
void render_stuff(void) {
|
1 |
nishi |
123 |
char* escaped;
|
|
|
124 |
add_data(&buffer, "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">\n");
|
|
|
125 |
add_data(&buffer, "<html>\n");
|
|
|
126 |
add_data(&buffer, " <head>\n");
|
|
|
127 |
add_data(&buffer, " <meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\">\n");
|
|
|
128 |
add_data(&buffer, " <title>");
|
|
|
129 |
add_data(&buffer, INSTANCE_NAME);
|
|
|
130 |
add_data(&buffer, " - ");
|
|
|
131 |
add_data(&buffer, title);
|
|
|
132 |
add_data(&buffer, "</title>\n");
|
|
|
133 |
add_data(&buffer, " <style type=\"text/css\">\n");
|
|
|
134 |
add_data(&buffer, "* {\n");
|
|
|
135 |
add_data(&buffer, " padding: 0;\n");
|
|
|
136 |
add_data(&buffer, " margin: 0;\n");
|
|
|
137 |
add_data(&buffer, "}\n");
|
|
|
138 |
add_data(&buffer, "li {\n");
|
|
|
139 |
add_data(&buffer, " list-style: outside;\n");
|
|
|
140 |
add_data(&buffer, " margin-left: 1.25em;\n");
|
|
|
141 |
add_data(&buffer, "}\n");
|
|
|
142 |
add_data(&buffer, "a {\n");
|
|
|
143 |
add_data(&buffer, " text-decoration: none;\n");
|
|
|
144 |
add_data(&buffer, "}\n");
|
|
|
145 |
add_data(&buffer, "#nav div {\n");
|
|
|
146 |
add_data(&buffer, " float: left;\n");
|
|
|
147 |
add_data(&buffer, " margin: 0 0;\n");
|
|
|
148 |
add_data(&buffer, " padding-left: 0;\n");
|
|
|
149 |
add_data(&buffer, " padding-right: 20px;\n");
|
|
|
150 |
add_data(&buffer, " padding-top: 7px;\n");
|
|
|
151 |
add_data(&buffer, "}\n");
|
|
|
152 |
add_data(&buffer, "body {\n");
|
|
|
153 |
add_data(&buffer, " background-color: #1F4677;\n");
|
|
|
154 |
add_data(&buffer, " width: 940px;\n");
|
|
|
155 |
add_data(&buffer, " margin: 5px auto;\n");
|
|
|
156 |
add_data(&buffer, " font-family: sans-serif;\n");
|
|
|
157 |
add_data(&buffer, "}\n");
|
|
|
158 |
add_data(&buffer, "#nav {\n");
|
|
|
159 |
add_data(&buffer, " background-color: white;\n");
|
6 |
nishi |
160 |
add_data(&buffer, " background-image: url('");
|
|
|
161 |
add_data(&buffer, INSTANCE_NAVBAR);
|
|
|
162 |
add_data(&buffer, "');\n");
|
1 |
nishi |
163 |
add_data(&buffer, " height: 44px;\n");
|
|
|
164 |
add_data(&buffer, " padding: 8px;\n");
|
|
|
165 |
add_data(&buffer, " padding-left: 32px;\n");
|
|
|
166 |
add_data(&buffer, " font-size: 22px;\n");
|
|
|
167 |
add_data(&buffer, " font-weight: bold;\n");
|
|
|
168 |
add_data(&buffer, "}\n");
|
|
|
169 |
add_data(&buffer, "#index {\n");
|
|
|
170 |
add_data(&buffer, " list-style: none;\n");
|
|
|
171 |
add_data(&buffer, " line-height: normal;\n");
|
|
|
172 |
add_data(&buffer, " margin: auto 0;\n");
|
|
|
173 |
add_data(&buffer, " padding-left: 0;\n");
|
|
|
174 |
add_data(&buffer, "}\n");
|
|
|
175 |
add_data(&buffer, "#desc {\n");
|
|
|
176 |
add_data(&buffer, " background-color: #D2E1F6;\n");
|
|
|
177 |
add_data(&buffer, " margin: 9px auto;\n");
|
|
|
178 |
add_data(&buffer, " height: 128px;\n");
|
|
|
179 |
add_data(&buffer, " padding: 24px;\n");
|
|
|
180 |
add_data(&buffer, "}\n");
|
|
|
181 |
add_data(&buffer, "#descinside {\n");
|
|
|
182 |
add_data(&buffer, " float: left;\n");
|
|
|
183 |
add_data(&buffer, "}\n");
|
|
|
184 |
add_data(&buffer, "#logo {\n");
|
|
|
185 |
add_data(&buffer, " float: right;\n");
|
|
|
186 |
add_data(&buffer, "}\n");
|
|
|
187 |
add_data(&buffer, "#content {\n");
|
|
|
188 |
add_data(&buffer, " background-color: #FFFFFF;\n");
|
|
|
189 |
add_data(&buffer, " margin: -10px auto;\n");
|
|
|
190 |
add_data(&buffer, " padding: 8px 24px 24px;\n");
|
|
|
191 |
add_data(&buffer, " min-height: 128px;\n");
|
|
|
192 |
add_data(&buffer, "}\n");
|
|
|
193 |
add_data(&buffer, "#pageindex {\n");
|
|
|
194 |
add_data(&buffer, " background-color: #FFFFFF;\n");
|
|
|
195 |
add_data(&buffer, " padding-right: 24px;\n");
|
|
|
196 |
add_data(&buffer, " padding-bottom: 24px;\n");
|
|
|
197 |
add_data(&buffer, " float: left;\n");
|
|
|
198 |
add_data(&buffer, " border-right: 4px #1F4677 solid;\n");
|
|
|
199 |
add_data(&buffer, " width: 150px;\n");
|
|
|
200 |
add_data(&buffer, "}\n");
|
|
|
201 |
add_data(&buffer, "#pagecontent {\n");
|
|
|
202 |
add_data(&buffer, " background-color: #FFFFFF;\n");
|
|
|
203 |
add_data(&buffer, " width: 670px;\n");
|
|
|
204 |
add_data(&buffer, " float: right;\n");
|
|
|
205 |
add_data(&buffer, " padding-left: 24px;\n");
|
|
|
206 |
add_data(&buffer, "}\n");
|
|
|
207 |
add_data(&buffer, "#footer {\n");
|
|
|
208 |
add_data(&buffer, " background-color: #D2E1F6;\n");
|
|
|
209 |
add_data(&buffer, " padding: 8px 8px 48px;\n");
|
|
|
210 |
add_data(&buffer, " margin: 8px auto;\n");
|
|
|
211 |
add_data(&buffer, " font-size: 15px;\n");
|
|
|
212 |
add_data(&buffer, " height: 32px;\n");
|
|
|
213 |
add_data(&buffer, "}\n");
|
|
|
214 |
add_data(&buffer, ".fixfloat {\n");
|
|
|
215 |
add_data(&buffer, " clear: both;\n");
|
|
|
216 |
add_data(&buffer, "}\n");
|
|
|
217 |
add_data(&buffer, "#copyright {\n");
|
|
|
218 |
add_data(&buffer, " float: right;\n");
|
|
|
219 |
add_data(&buffer, " font-size: 10px;\n");
|
|
|
220 |
add_data(&buffer, " margin-top: 16px;\n");
|
|
|
221 |
add_data(&buffer, "}\n");
|
|
|
222 |
add_data(&buffer, "#gotop {\n");
|
|
|
223 |
add_data(&buffer, " position: absolute;\n");
|
|
|
224 |
add_data(&buffer, "}\n");
|
|
|
225 |
add_data(&buffer, "h2, h3 {\n");
|
|
|
226 |
add_data(&buffer, " padding-top: 8px;\n");
|
|
|
227 |
add_data(&buffer, " padding-bottom: 8px;\n");
|
|
|
228 |
add_data(&buffer, "}\n");
|
|
|
229 |
add_data(&buffer, "img {\n");
|
|
|
230 |
add_data(&buffer, " border: none;\n");
|
|
|
231 |
add_data(&buffer, "}\n");
|
|
|
232 |
add_data(&buffer, " </style>\n");
|
|
|
233 |
add_data(&buffer, " </head>\n");
|
|
|
234 |
add_data(&buffer, " <body>\n");
|
|
|
235 |
add_data(&buffer, " <div id=\"nav\">\n");
|
|
|
236 |
add_data(&buffer, " <div>\n");
|
|
|
237 |
add_data(&buffer, " <a href=\"");
|
|
|
238 |
add_data(&buffer, INSTANCE_ROOT);
|
|
|
239 |
add_data(&buffer, "/\">Home</a>\n");
|
|
|
240 |
add_data(&buffer, " </div>\n");
|
5 |
nishi |
241 |
if(user == NULL) {
|
|
|
242 |
add_data(&buffer, " <div>\n");
|
|
|
243 |
add_data(&buffer, " <a href=\"");
|
|
|
244 |
add_data(&buffer, INSTANCE_ROOT);
|
|
|
245 |
add_data(&buffer, "/?page=login\">Login</a>\n");
|
|
|
246 |
add_data(&buffer, " </div>\n");
|
|
|
247 |
}
|
6 |
nishi |
248 |
if(user != NULL) {
|
|
|
249 |
add_data(&buffer, "<div style=\"float: right;font-size: 10px;padding-top: 36px;padding-right: 0;font-style: italic;\">You have logged in as <a href=\"");
|
|
|
250 |
add_data(&buffer, INSTANCE_ROOT);
|
|
|
251 |
add_data(&buffer, "/?page=mypage\">");
|
|
|
252 |
add_data(&buffer, user);
|
|
|
253 |
add_data(&buffer, "</a></div>");
|
|
|
254 |
}
|
1 |
nishi |
255 |
add_data(&buffer, " </div>\n");
|
|
|
256 |
add_data(&buffer, " <div id=\"desc\">\n");
|
|
|
257 |
add_data(&buffer, " <div id=\"descinside\">\n");
|
|
|
258 |
add_data(&buffer, " <h1>");
|
|
|
259 |
add_data(&buffer, title);
|
|
|
260 |
add_data(&buffer, "</h1>\n");
|
|
|
261 |
add_data(&buffer, " <p>\n");
|
|
|
262 |
add_data(&buffer, desc);
|
|
|
263 |
add_data(&buffer, " </p>\n");
|
|
|
264 |
add_data(&buffer, " </div>\n");
|
|
|
265 |
add_data(&buffer, " <img id=\"logo\" src=\"");
|
|
|
266 |
add_data(&buffer, INSTANCE_LOGO);
|
|
|
267 |
add_data(&buffer, "\" height=\"128px\" alt=\"logo\">\n");
|
|
|
268 |
add_data(&buffer, " </div>\n");
|
|
|
269 |
add_data(&buffer, " <div id=\"content\">\n");
|
|
|
270 |
add_data(&buffer, " <div id=\"pageindex\">\n");
|
|
|
271 |
add_data(&buffer, " <h3>Page Menu</h3>\n");
|
|
|
272 |
add_data(&buffer, " <ul>\n");
|
|
|
273 |
add_data(&buffer, " </ul>\n");
|
|
|
274 |
add_data(&buffer, " </div>\n");
|
|
|
275 |
add_data(&buffer, " <div id=\"pagecontent\">\n");
|
|
|
276 |
add_data(&buffer, page);
|
|
|
277 |
add_data(&buffer, " <div class=\"fixfloat\"></div>\n");
|
|
|
278 |
add_data(&buffer, " </div>\n");
|
|
|
279 |
add_data(&buffer, " </div>\n");
|
|
|
280 |
add_data(&buffer, " <div id=\"footer\">\n");
|
|
|
281 |
add_data(&buffer, " <div id=\"gotop\">\n");
|
|
|
282 |
add_data(&buffer, " <a href=\"#top\">Top</a>\n");
|
|
|
283 |
add_data(&buffer, " </div>\n");
|
|
|
284 |
add_data(&buffer, " <div id=\"copyright\">\n");
|
|
|
285 |
add_data(&buffer, " ");
|
|
|
286 |
escaped = escape(INSTANCE_ADMIN);
|
|
|
287 |
add_data(&buffer, escaped);
|
|
|
288 |
free(escaped);
|
|
|
289 |
add_data(&buffer, "\n");
|
|
|
290 |
add_data(&buffer, " </div>\n");
|
|
|
291 |
add_data(&buffer, " <div class=\"fixfloat\"></div>\n");
|
|
|
292 |
add_data(&buffer, " </div>\n");
|
|
|
293 |
add_data(&buffer, " </body>\n");
|
|
|
294 |
add_data(&buffer, "</html>\n");
|
5 |
nishi |
295 |
if(user != NULL) free(user);
|
1 |
nishi |
296 |
}
|