1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,91 @@ |
1 |
+body { |
|
2 |
+ font-family: Sans; |
|
3 |
+ color: #8080a5; |
|
4 |
+ padding: 80px 0px 0px 0px; |
|
5 |
+} |
|
6 |
+ |
|
7 |
+input.rounded { |
|
8 |
+ border: 1px solid #ccc; |
|
9 |
+ -moz-border-radius: 10px; |
|
10 |
+ -webkit-border-radius: 10px; |
|
11 |
+ border-radius: 10px; |
|
12 |
+ -moz-box-shadow: 2px 2px 3px #666; |
|
13 |
+ -webkit-box-shadow: 2px 2px 3px #666; |
|
14 |
+ box-shadow: 2px 2px 3px #666; |
|
15 |
+ font-size: 20px; |
|
16 |
+ padding: 4px 7px; |
|
17 |
+ outline: 0; |
|
18 |
+ -webkit-appearance: none; |
|
19 |
+} |
|
20 |
+input.rounded:focus { |
|
21 |
+ border-color: #339933; |
|
22 |
+} |
|
23 |
+ |
|
24 |
+input.almostrounded { |
|
25 |
+ border: 1px solid #ccc; |
|
26 |
+ -moz-border-radius: 2px; |
|
27 |
+ -webkit-border-radius: 2px; |
|
28 |
+ border-radius: 2px; |
|
29 |
+ -moz-box-shadow: 0px 0px 3px #666; |
|
30 |
+ -webkit-box-shadow: 0px 0px 3px #666; |
|
31 |
+ box-shadow: 0px 0px 3px #666; |
|
32 |
+ font-size: 20px; |
|
33 |
+ padding: 4px 7px; |
|
34 |
+ outline: 0; |
|
35 |
+ -webkit-appearance: none; |
|
36 |
+} |
|
37 |
+ |
|
38 |
+input.almostrounded:focus { |
|
39 |
+ border-color: #339933; |
|
40 |
+} |
|
41 |
+ |
|
42 |
+div.centered { |
|
43 |
+/* gradient */ |
|
44 |
+background-image: -webkit-gradient( |
|
45 |
+ linear, |
|
46 |
+ left bottom, |
|
47 |
+ left bottom, |
|
48 |
+ color-stop(0.11, #C7C7C7), |
|
49 |
+ color-stop(0.81, #EEEEEE) |
|
50 |
+); |
|
51 |
+background-image: -o-linear-gradient(left bottom, #C7C7C7 11%, #EEEEEE 81%); |
|
52 |
+background-image: -moz-linear-gradient(left bottom, #C7C7C7 11%, #EEEEEE 81%); |
|
53 |
+background-image: -webkit-linear-gradient(left bottom, #C7C7C7 11%, #EEEEEE 81%); |
|
54 |
+background-image: -ms-linear-gradient(left bottom, #C7C7C7 11%, #EEEEEE 81%); |
|
55 |
+background-image: linear-gradient(to left bottom, #C7C7C7 11%, #EEEEEE 81%); |
|
56 |
+/* border */ |
|
57 |
+ border: 1px solid #ccc; |
|
58 |
+ -moz-border-radius: 2px; |
|
59 |
+ -webkit-border-radius: 2px; |
|
60 |
+ border-radius: 2px; |
|
61 |
+ -moz-box-shadow: 0px 0px 3px #666; |
|
62 |
+ -webkit-box-shadow: 0px 0px 3px #666; |
|
63 |
+ box-shadow: 0px 0px 3px #666; |
|
64 |
+ font-size: 20px; |
|
65 |
+ padding: 16px 24px; |
|
66 |
+ outline: 0; |
|
67 |
+ -webkit-appearance: none; |
|
68 |
+} |
|
69 |
+ |
|
70 |
+div.centered { |
|
71 |
+ text-align: center; |
|
72 |
+ width: 450px; |
|
73 |
+ margin-left: auto; |
|
74 |
+ margin-right: auto; |
|
75 |
+} |
|
76 |
+ |
|
77 |
+p.title { |
|
78 |
+ font-size: 28px; |
|
79 |
+ padding: 0px 0px 20px 0px; |
|
80 |
+} |
|
81 |
+ |
|
82 |
+.aligned { |
|
83 |
+ list-style-type: none; |
|
84 |
+ padding-left: 30px; |
|
85 |
+} |
|
86 |
+ |
|
87 |
+.aligned .label { |
|
88 |
+ float: left; |
|
89 |
+ width: 50px; |
|
90 |
+ padding: 4px 10px 0px 0px; |
|
91 |
+} |
0 | 92 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,11 @@ |
1 |
+<!DOCTYPE html> |
|
2 |
+<html> |
|
3 |
+<head><title>kakumei posts</title> |
|
4 |
+ <link rel="stylesheet" type="text/css" href="posts.css"> |
|
5 |
+</head> |
|
6 |
+<body> |
|
7 |
+ <p> No posts for now</p> |
|
8 |
+ <span class='centeredbutton'><input class='rounded' id='gotonewpost' type ='button' value='Nuevo post'/></span> |
|
9 |
+ <script src='posts.js'></script> |
|
10 |
+</body> |
|
11 |
+</html> |
0 | 12 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,24 @@ |
1 |
+(function () { |
|
2 |
+"use strict"; |
|
3 |
+ |
|
4 |
+function request(querytext, func, errorfunc) { |
|
5 |
+ var req = new XMLHttpRequest(); |
|
6 |
+ req.onreadystatechange = function() { |
|
7 |
+ if (req.readyState !== 4) { |
|
8 |
+ return; |
|
9 |
+ } |
|
10 |
+ if (req.status !== 200) { |
|
11 |
+ errorfunc(); |
|
12 |
+ return; |
|
13 |
+ } |
|
14 |
+ func(req.responseText); |
|
15 |
+ }; |
|
16 |
+ req.open("GET",querytext); |
|
17 |
+ req.send(); |
|
18 |
+} |
|
19 |
+ |
|
20 |
+gotonewpost.onclick = function(e) { |
|
21 |
+ window.location="/newpost.html"+window.location.search |
|
22 |
+}; |
|
23 |
+ |
|
24 |
+}()); |
... | ... |
@@ -20,7 +20,8 @@ kakumei: kakumei.o loglib.o parselib.o sbuf.o \ |
20 | 20 |
kakumei.o: kakumei.c ../src/gen_res.c |
21 | 21 |
|
22 | 22 |
../src/gen_res.c: ../res/index.html ../res/script.js ../res/style.css \ |
23 |
- ../res/newuser.html ../res/newuser.js ../res/newuser.css |
|
23 |
+ ../res/newuser.html ../res/newuser.js ../res/newuser.css \ |
|
24 |
+ ../res/posts.html ../res/posts.js ../res/posts.css |
|
24 | 25 |
( cd ../res && ./gen.sh ) |
25 | 26 |
|
26 | 27 |
gen_res.o: ../src/gen_res.c |
... | ... |
@@ -26,6 +26,9 @@ static int signal_init(int signum, void (*fn)(int)); |
26 | 26 |
static void sigint(int signum); |
27 | 27 |
volatile int sigint_flag=0; |
28 | 28 |
|
29 |
+int kakumei_inviteexists(kakumei *ka, char *invite); |
|
30 |
+int kakumei_invitedel(kakumei *ka, char *invite); |
|
31 |
+ |
|
29 | 32 |
wk_action callback_http(wk *web, int connid, wk_uri *uri, void *userptr); |
30 | 33 |
wk_action http_login(wk *web, int connid, wk_uri *uri, void *userptr); |
31 | 34 |
wk_action http_newuser(wk *web, int connid, wk_uri *uri, void *userptr); |
... | ... |
@@ -89,6 +92,39 @@ kakumei_userexists(kakumei *ka, char *username) |
89 | 92 |
return(0); |
90 | 93 |
} |
91 | 94 |
|
95 |
+int |
|
96 |
+kakumei_inviteexists(kakumei *ka, char *invite) |
|
97 |
+{ |
|
98 |
+ char filename[1024]; |
|
99 |
+ struct stat st; |
|
100 |
+ if(invite==NULL) |
|
101 |
+ return(-1); |
|
102 |
+ if(strchr(invite,'/')!=NULL) |
|
103 |
+ return(-1); |
|
104 |
+ if(strcmp(invite,".")==0 || strcmp(invite,"..")==0) |
|
105 |
+ return(-1); |
|
106 |
+ snprintf(filename,sizeof(filename),"%s/%s",INVITESDIR,invite); |
|
107 |
+ filename[sizeof(filename)-1]='\0'; |
|
108 |
+ if(stat(filename,&st)!=0 || !S_ISREG(st.st_mode)) |
|
109 |
+ return(-1); |
|
110 |
+ return(0); |
|
111 |
+} |
|
112 |
+ |
|
113 |
+int |
|
114 |
+kakumei_invitedel(kakumei *ka, char *invite) |
|
115 |
+{ |
|
116 |
+ char filename[1024]; |
|
117 |
+ if(kakumei_inviteexists(ka,invite)!=0) |
|
118 |
+ return(-1); /* doesn't exist */ |
|
119 |
+ snprintf(filename,sizeof(filename),"%s/%s",INVITESDIR,invite); |
|
120 |
+ filename[sizeof(filename)-1]='\0'; |
|
121 |
+ unlink(filename); |
|
122 |
+ if(kakumei_inviteexists(ka,invite)==0) |
|
123 |
+ return(-1); /* couldn't remove invite */ |
|
124 |
+ return(0); |
|
125 |
+} |
|
126 |
+ |
|
127 |
+ |
|
92 | 128 |
wk_action |
93 | 129 |
callback_http(wk *web, int connid, wk_uri *uri, void *userptr) |
94 | 130 |
{ |
... | ... |
@@ -139,12 +175,9 @@ sigint(int signum) |
139 | 175 |
wk_action |
140 | 176 |
http_login(wk *web, int connid, wk_uri *uri, void *userptr) |
141 | 177 |
{ |
142 |
- char u[128],p[128]; |
|
178 |
+ char u[MAXUSERSIZE+1],p[MAXPASSWDSIZE+1]; |
|
143 | 179 |
char reply[1024]; |
144 |
- char invitepath[1024]; |
|
145 |
- char userpath[1024]; |
|
146 |
- char session[1024]; |
|
147 |
- struct stat st; |
|
180 |
+ char session[SESSIONSIZE]; |
|
148 | 181 |
kakumei *ka=(kakumei *)userptr; |
149 | 182 |
if(web==NULL || connid<0 || uri==NULL || ka==NULL) |
150 | 183 |
return(wkact_finished); /* internal error */ |
... | ... |
@@ -153,22 +186,15 @@ http_login(wk *web, int connid, wk_uri *uri, void *userptr) |
153 | 186 |
if(wk_uri_copyvar(uri,"p",p,sizeof(p))==NULL) |
154 | 187 |
p[0]='\0'; |
155 | 188 |
/* check for invitation */ |
156 |
- snprintf(invitepath,sizeof(invitepath),"%s/%s",INVITESDIR,p); |
|
157 |
- invitepath[sizeof(invitepath)-1]='\0'; |
|
158 |
- snprintf(userpath,sizeof(userpath),"%s/%s/passwd",USERSDIR,u); |
|
159 |
- userpath[sizeof(userpath)-1]='\0'; |
|
160 | 189 |
if(strcmp(u,INVITATIONUSER)==0 && |
161 |
- strchr(p,'/')==NULL && strchr(p,'.')==NULL && |
|
162 |
- stat(invitepath,&st)==0 && S_ISREG(st.st_mode)) { |
|
190 |
+ kakumei_inviteexists(ka,p)==0) { |
|
163 | 191 |
/* valid invitation */ |
164 | 192 |
snprintf(reply,sizeof(reply),"/newuser.html?i=%s",p); |
165 | 193 |
reply[sizeof(reply)-1]='\0'; |
166 | 194 |
wk_serve_buffer_as_file(web,connid,reply,strlen(reply),"text/plain"); |
167 | 195 |
return(wkact_finished); |
168 |
- } else if(strchr(u,'/')==NULL && strchr(u,'.')==NULL && |
|
169 |
- stat(userpath,&st)==0 && S_ISREG(st.st_mode) && |
|
170 |
- pass_check(ka,u,p)==0 && |
|
171 |
- session_new(ka,u,session,sizeof(session))!=NULL) { |
|
196 |
+ } else if(pass_check(ka,u,p)==0 && |
|
197 |
+ session_new(ka,u,session,sizeof(session))!=NULL) { |
|
172 | 198 |
/* valid login */ |
173 | 199 |
snprintf(reply,sizeof(reply),"/posts.html?s=%s",session); |
174 | 200 |
reply[sizeof(reply)-1]='\0'; |
... | ... |
@@ -182,8 +208,43 @@ http_login(wk *web, int connid, wk_uri *uri, void *userptr) |
182 | 208 |
wk_action |
183 | 209 |
http_newuser(wk *web, int connid, wk_uri *uri, void *userptr) |
184 | 210 |
{ |
185 |
-#warning TODO |
|
186 |
- wk_serve_error(web,connid,wkerr_internal); |
|
211 |
+ char u[MAXUSERSIZE+1],p[MAXPASSWDSIZE+1],i[MAXPASSWDSIZE+1]; |
|
212 |
+ char reply[1024]; |
|
213 |
+ char session[SESSIONSIZE]; |
|
214 |
+ kakumei *ka=(kakumei *)userptr; |
|
215 |
+ if(web==NULL || connid<0 || uri==NULL || ka==NULL) |
|
216 |
+ return(wkact_finished); /* internal error */ |
|
217 |
+ /* get vars */ |
|
218 |
+ if(wk_uri_copyvar(uri,"i",u,sizeof(i))==NULL) |
|
219 |
+ i[0]='\0'; |
|
220 |
+ if(wk_uri_copyvar(uri,"u",u,sizeof(u))==NULL) |
|
221 |
+ u[0]='\0'; |
|
222 |
+ if(wk_uri_copyvar(uri,"p",p,sizeof(p))==NULL) |
|
223 |
+ p[0]='\0'; |
|
224 |
+ /* check validity */ |
|
225 |
+ if(kakumei_inviteexists(ka,i)!=0) { |
|
226 |
+ /* retry login */ |
|
227 |
+ wk_serve_buffer_as_file(web,connid,"/",1,"text/plain"); |
|
228 |
+ return(wkact_finished); |
|
229 |
+ } |
|
230 |
+ /* create user */ |
|
231 |
+ if(pass_new(ka,u,p)!=0) { |
|
232 |
+ /* error with username */ |
|
233 |
+ wk_serve_error(web,connid,wkerr_internal); |
|
234 |
+ return(wkact_finished); |
|
235 |
+ } |
|
236 |
+ /* delete invitation */ |
|
237 |
+ kakumei_invitedel(ka,i); |
|
238 |
+ /* create session and go to "posts" page */ |
|
239 |
+ if(session_new(ka,u,session,sizeof(session))==NULL) { |
|
240 |
+ /* "autologin" didn't work, ask for login */ |
|
241 |
+ wk_serve_buffer_as_file(web,connid,"/",1,"text/plain"); |
|
242 |
+ return(wkact_finished); |
|
243 |
+ } |
|
244 |
+ /* valid login */ |
|
245 |
+ snprintf(reply,sizeof(reply),"/posts.html?s=%s",session); |
|
246 |
+ reply[sizeof(reply)-1]='\0'; |
|
247 |
+ wk_serve_buffer_as_file(web,connid,reply,strlen(reply),"text/plain"); |
|
187 | 248 |
return(wkact_finished); |
188 | 249 |
} |
189 | 250 |
|