1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,100 @@ |
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: 650px; |
|
73 |
+ margin-left: auto; |
|
74 |
+ margin-right: auto; |
|
75 |
+} |
|
76 |
+ |
|
77 |
+p.instructions { |
|
78 |
+ font-size: 16px; |
|
79 |
+ color: #404055; |
|
80 |
+} |
|
81 |
+ |
|
82 |
+#errormessage { |
|
83 |
+ font-size: 16px; |
|
84 |
+ color: #ff0000; |
|
85 |
+} |
|
86 |
+p.title { |
|
87 |
+ font-size: 28px; |
|
88 |
+ padding: 0px 0px 20px 0px; |
|
89 |
+} |
|
90 |
+ |
|
91 |
+.aligned { |
|
92 |
+ list-style-type: none; |
|
93 |
+ padding-left: 60px; |
|
94 |
+} |
|
95 |
+ |
|
96 |
+.aligned .label { |
|
97 |
+ float: left; |
|
98 |
+ width: 200px; |
|
99 |
+ padding: 4px 10px 0px 0px; |
|
100 |
+} |
0 | 101 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,18 @@ |
1 |
+<!DOCTYPE html> |
|
2 |
+<html> |
|
3 |
+<head><title>Nuevo usuario</title> |
|
4 |
+ <link rel="stylesheet" type="text/css" href="newuser.css"> |
|
5 |
+</head> |
|
6 |
+<body> |
|
7 |
+ <div class="centered"> |
|
8 |
+ <p class='title'>Crear usuario</p> |
|
9 |
+ <p class='instructions'>Por favor, introduce los siguientes datos para proceder a la creación de tu nuevo usuario</p> |
|
10 |
+ <p><span id='errormessage'></span></p> |
|
11 |
+ <p class="aligned"><span class='label'>Nombre de usuario</span> <input class='almostrounded' id='user' type ='input' value=''/></p> |
|
12 |
+ <p class="aligned"><span class='label'>Clave</span> <input class='almostrounded' id='pass1' type ='password' value=''/></p> |
|
13 |
+ <p class="aligned"><span class='label'>Repite la clave</span> <input class='almostrounded' id='pass2' type ='password' value=''/></p> |
|
14 |
+ <span class='centeredbutton'><input class='rounded' id='donewuser' type ='button' value='Crear'/></span> |
|
15 |
+ </div> |
|
16 |
+ <script src='newuser.js'></script> |
|
17 |
+</body> |
|
18 |
+</html> |
0 | 19 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,32 @@ |
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 |
+ |
|
21 |
+donewuser.onclick = function(e) { |
|
22 |
+ if ( ! ( pass1.value == pass2.value ) ) { |
|
23 |
+ document.getElementById("errormessage").innerHTML = "Las dos claves no coinciden"; |
|
24 |
+ } else { |
|
25 |
+ request("/newuser"+window.location.search+"&u="+encodeURIComponent(user.value)+"&p="+encodeURIComponent(pass1.value),function(r) { |
|
26 |
+ window.location=r;},function() { |
|
27 |
+ document.getElementById("errormessage").innerHTML = "El nombre de usuario no es v�lido"; |
|
28 |
+ }); |
|
29 |
+ } |
|
30 |
+}; |
|
31 |
+ |
|
32 |
+}()); |
... | ... |
@@ -18,8 +18,8 @@ function request(querytext, func, errorfunc) { |
18 | 18 |
} |
19 | 19 |
|
20 | 20 |
dologin.onclick = function(e) { |
21 |
- request("/doLogin?u="+encodeURIComponent(user.value)+"&p="+encodeURIComponent(pass.value),function(r) { |
|
22 |
- newpage(r);},function() {}); |
|
21 |
+ request("/login?u="+encodeURIComponent(user.value)+"&p="+encodeURIComponent(pass.value),function(r) { |
|
22 |
+ window.location=r;},function() {}); |
|
23 | 23 |
}; |
24 | 24 |
|
25 | 25 |
}()); |
... | ... |
@@ -6,7 +6,7 @@ LDFLAGS= |
6 | 6 |
all: kakumei kakumei-invite |
7 | 7 |
|
8 | 8 |
clean: |
9 |
- rm -f *.o kakumei ../res/gen_res.[ch] |
|
9 |
+ rm -f *.o kakumei kakumei-invite ../res/gen_res.[ch] |
|
10 | 10 |
|
11 | 11 |
kakumei: kakumei.o loglib.o parselib.o sbuf.o \ |
12 | 12 |
socklib.o webkernel.o gen_res.o |
... | ... |
@@ -15,7 +15,8 @@ kakumei: kakumei.o loglib.o parselib.o sbuf.o \ |
15 | 15 |
|
16 | 16 |
kakumei.o: kakumei.c ../src/gen_res.c |
17 | 17 |
|
18 |
-../src/gen_res.c: ../res/index.html ../res/script.js ../res/style.css |
|
18 |
+../src/gen_res.c: ../res/index.html ../res/script.js ../res/style.css \ |
|
19 |
+ ../res/newuser.html ../res/newuser.js ../res/newuser.css |
|
19 | 20 |
( cd ../res && ./gen.sh ) |
20 | 21 |
|
21 | 22 |
gen_res.o: ../src/gen_res.c |
... | ... |
@@ -12,10 +12,20 @@ |
12 | 12 |
#include <unistd.h> |
13 | 13 |
#include <string.h> |
14 | 14 |
#include <signal.h> |
15 |
+#include <sys/types.h> |
|
16 |
+#include <sys/stat.h> |
|
17 |
+#include <unistd.h> |
|
15 | 18 |
#include "gen_res.h" |
16 | 19 |
#include "socklib.h" |
17 | 20 |
#include "webkernel.h" |
18 | 21 |
|
22 |
+#define INVITATIONUSER "invitation" |
|
23 |
+#define DATADIR "data" |
|
24 |
+#define INVITESDIR "data/invitations" |
|
25 |
+#define USERSDIR "data/users" |
|
26 |
+#define POSTSDIR "data/posts" |
|
27 |
+#define SESSIONSDIR "data/sessions" |
|
28 |
+ |
|
19 | 29 |
typedef struct kakumei { |
20 | 30 |
sselect *ssel; |
21 | 31 |
wk *web; |
... | ... |
@@ -27,6 +37,13 @@ static void sigint(int signum); |
27 | 37 |
volatile int sigint_flag=0; |
28 | 38 |
|
29 | 39 |
wk_action callback_http(wk *web, int connid, wk_uri *uri, void *userptr); |
40 |
+wk_action http_login(wk *web, int connid, wk_uri *uri, void *userptr); |
|
41 |
+wk_action http_newuser(wk *web, int connid, wk_uri *uri, void *userptr); |
|
42 |
+ |
|
43 |
+int pass_check(char *user, char *passwd); |
|
44 |
+char *session_new(char *user, char *session, int sessionsize); |
|
45 |
+ |
|
46 |
+ |
|
30 | 47 |
|
31 | 48 |
int |
32 | 49 |
main(int argc, char *argv[]) |
... | ... |
@@ -66,24 +83,24 @@ callback_http(wk *web, int connid, wk_uri *uri, void *userptr) |
66 | 83 |
{ |
67 | 84 |
kakumei *ka=(kakumei *)userptr; |
68 | 85 |
resindex *res; |
86 |
+ char partialpath[1024]; |
|
87 |
+ char *ptr; |
|
69 | 88 |
if(ka==NULL) |
70 | 89 |
return(wkact_finished); |
90 |
+ printf("http: %s\n",uri->path); |
|
91 |
+ strncpy(partialpath,uri->path,sizeof(partialpath)-1); |
|
92 |
+ partialpath[sizeof(partialpath)-1]='\0'; |
|
93 |
+ if((ptr=strchr(partialpath,'?'))!=NULL) |
|
94 |
+ *ptr='\0'; |
|
71 | 95 |
if((strcmp(uri->path,"/")==0 && (res=res_find(resindexdata,"index.html"))!=NULL) || |
72 |
- (uri->path[0]=='/' && (res=res_find(resindexdata,uri->path+1))!=NULL)) { |
|
96 |
+ (partialpath[0]=='/' && (res=res_find(resindexdata,partialpath+1))!=NULL)) { |
|
73 | 97 |
wk_serve_buffer_as_file(web,connid,res->data,res->len,mime_getdefault(res->name,"application/octet-stream")); |
74 | 98 |
return(wkact_finished); |
75 | 99 |
} |
76 |
- if(memcmp(uri->path,"/doLogin?",9)==0) { |
|
77 |
- char u[128],p[128]; |
|
78 |
- if(wk_uri_copyvar(uri,"u",u,sizeof(u))==NULL) |
|
79 |
- u[0]='\0'; |
|
80 |
- if(wk_uri_copyvar(uri,"p",p,sizeof(p))==NULL) |
|
81 |
- p[0]='\0'; |
|
82 |
- printf("URI: %s\n",uri->path); |
|
83 |
- printf("Login: \"%s\"\n",u); |
|
84 |
- printf("Pass.: \"%s\"\n",p); |
|
85 |
- wk_serve_error(web,connid,wkerr_internal); |
|
86 |
- return(wkact_finished); |
|
100 |
+ if(memcmp(uri->path,"/login?",7)==0) { |
|
101 |
+ return(http_login(web,connid,uri,userptr)); |
|
102 |
+ } else if(memcmp(uri->path,"/newuser?",9)==0) { |
|
103 |
+ return(http_newuser(web,connid,uri,userptr)); |
|
87 | 104 |
} |
88 | 105 |
printf("URI not found: %s\n",uri->path); |
89 | 106 |
wk_serve_error(web,connid,wkerr_notfound); |
... | ... |
@@ -106,3 +123,65 @@ sigint(int signum) |
106 | 123 |
sigint_flag=1; |
107 | 124 |
} |
108 | 125 |
|
126 |
+wk_action |
|
127 |
+http_login(wk *web, int connid, wk_uri *uri, void *userptr) |
|
128 |
+{ |
|
129 |
+ char u[128],p[128]; |
|
130 |
+ char reply[1024]; |
|
131 |
+ char invitepath[1024]; |
|
132 |
+ char userpath[1024]; |
|
133 |
+ char session[1024]; |
|
134 |
+ struct stat st; |
|
135 |
+ if(wk_uri_copyvar(uri,"u",u,sizeof(u))==NULL) |
|
136 |
+ u[0]='\0'; |
|
137 |
+ if(wk_uri_copyvar(uri,"p",p,sizeof(p))==NULL) |
|
138 |
+ p[0]='\0'; |
|
139 |
+ /* check for invitation */ |
|
140 |
+ snprintf(invitepath,sizeof(invitepath),"%s/%s",INVITESDIR,p); |
|
141 |
+ invitepath[sizeof(invitepath)-1]='\0'; |
|
142 |
+ snprintf(userpath,sizeof(userpath),"%s/%s/passwd",USERSDIR,u); |
|
143 |
+ userpath[sizeof(userpath)-1]='\0'; |
|
144 |
+ if(strcmp(u,INVITATIONUSER)==0 && |
|
145 |
+ strchr(p,'/')==NULL && strchr(p,'.')==NULL && |
|
146 |
+ stat(invitepath,&st)==0 && S_ISREG(st.st_mode)) { |
|
147 |
+ /* valid invitation */ |
|
148 |
+ snprintf(reply,sizeof(reply),"/newuser.html?i=%s",p); |
|
149 |
+ reply[sizeof(reply)-1]='\0'; |
|
150 |
+ wk_serve_buffer_as_file(web,connid,reply,strlen(reply),"text/plain"); |
|
151 |
+ return(wkact_finished); |
|
152 |
+ } else if(strchr(u,'/')==NULL && strchr(u,'.')==NULL && |
|
153 |
+ stat(userpath,&st)==0 && S_ISREG(st.st_mode) && pass_check(u,p)==0 && |
|
154 |
+ session_new(u,session,sizeof(session))!=NULL) { |
|
155 |
+ /* valid login */ |
|
156 |
+ snprintf(reply,sizeof(reply),"/posts.html?s=%s",session); |
|
157 |
+ reply[sizeof(reply)-1]='\0'; |
|
158 |
+ wk_serve_buffer_as_file(web,connid,reply,strlen(reply),"text/plain"); |
|
159 |
+ return(wkact_finished); |
|
160 |
+ } |
|
161 |
+ wk_serve_error(web,connid,wkerr_internal); |
|
162 |
+ return(wkact_finished); |
|
163 |
+} |
|
164 |
+ |
|
165 |
+wk_action |
|
166 |
+http_newuser(wk *web, int connid, wk_uri *uri, void *userptr) |
|
167 |
+{ |
|
168 |
+#warning TODO |
|
169 |
+ wk_serve_error(web,connid,wkerr_internal); |
|
170 |
+ return(wkact_finished); |
|
171 |
+} |
|
172 |
+ |
|
173 |
+ |
|
174 |
+int |
|
175 |
+pass_check(char *user, char *passwd) |
|
176 |
+{ |
|
177 |
+#warning TODO |
|
178 |
+ return(-1); |
|
179 |
+} |
|
180 |
+ |
|
181 |
+char * |
|
182 |
+session_new(char *user, char *session, int sessionsize) |
|
183 |
+{ |
|
184 |
+#warning TODO |
|
185 |
+ return(NULL); |
|
186 |
+} |
|
187 |
+ |