4 * This file contains code which relates to authentication of users to Citadel.
16 #include <sys/types.h>
18 #include <sys/socket.h>
21 #include <netinet/in.h>
43 * Display the login screen
45 void display_login(char *mesg)
51 if (mesg != NULL) if (strlen(mesg) > 0) {
53 svprintf("mesg", WCS_STRING, "%s", buf);
56 stresc(buf, serv_info.serv_humannode, 1);
57 svprintf("humannode", WCS_STRING, "%s", buf);
59 svprintf("hello", WCS_SERVCMD, "MESG hello");
64 wDumpContent(0); /* No menu here; not logged in yet! */
71 * This function needs to get called whenever the session changes from
72 * not-logged-in to logged-in, either by an explicit login by the user or
73 * by a timed-out session automatically re-establishing with a little help
74 * from the browser cookie. Either way, we need to load access controls and
75 * preferences from the server.
77 void become_logged_in(char *user, char *pass, char *serv_response)
80 extract(WC->wc_username, &serv_response[4], 0);
81 strcpy(WC->wc_password, pass);
82 WC->axlevel = extract_int(&serv_response[4], 1);
83 if (WC->axlevel >= 6) {
96 if (!strcasecmp(bstr("action"), "Exit")) {
100 if (!strcasecmp(bstr("action"), "Login")) {
101 serv_printf("USER %s", bstr("name"));
104 serv_printf("PASS %s", bstr("pass"));
107 become_logged_in(bstr("name"),
110 display_login(&buf[4]);
114 display_login(&buf[4]);
118 if (!strcasecmp(bstr("action"), "New User")) {
119 serv_printf("NEWU %s", bstr("name"));
122 become_logged_in(bstr("name"), bstr("pass"), buf);
123 serv_printf("SETP %s", bstr("pass"));
126 display_login(&buf[4]);
134 WC->new_mail = extract_int(&buf[4], 0);
135 need_regi = extract_int(&buf[4], 1);
136 WC->need_vali = extract_int(&buf[4], 2);
144 display_login("Your password was not accepted.");
149 void do_welcome(void)
153 get_preference("startpage", startpage);
154 if (strlen(startpage)==0) {
155 strcpy(startpage, "/dotskip&room=_BASEROOM_");
156 set_preference("startpage", startpage);
159 svprintf("STARTPAGE", WCS_STRING, startpage);
161 do_template("mainframeset");
162 clear_local_substs();
167 * Disconnect from the Citadel server, and end this WebCit session
169 void end_webcit_session(void) {
172 /* close() of citadel socket will be done by do_housekeeping() */
180 strcpy(WC->wc_username, "");
181 strcpy(WC->wc_password, "");
182 strcpy(WC->wc_roomname, "");
184 output_headers(2); /* note "2" causes cookies to be unset */
187 serv_puts("MESG goodbye");
193 wprintf("Goodbye\n");
195 wprintf("<HR><A HREF=\"/\">Log in again</A> "
196 "<A HREF=\"javascript:window.close();\">Close window</A>"
199 end_webcit_session();
216 strcpy(buf, bstr("user"));
218 if (strlen(bstr("WC->axlevel")) > 0) {
219 serv_printf("VALI %s|%s", buf, bstr("WC->axlevel"));
222 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
229 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
233 strcpy(user, &buf[4]);
234 serv_printf("GREG %s", user);
242 wprintf("User #%s<BR><H1>%s</H1>",
245 wprintf("PW: %s<BR>\n", buf);
247 wprintf("%s<BR>\n", buf);
249 wprintf("%s<BR>\n", buf);
251 wprintf("%s, ", buf);
255 wprintf("%s<BR>\n", buf);
257 wprintf("%s<BR>\n", buf);
259 wprintf("Current access level: %d (%s)\n",
260 atoi(buf), axdefs[atoi(buf)]);
261 } while (strcmp(buf, "000"));
263 wprintf("<H1>%s</H1>%s<BR>\n", user, &cmd[4]);
266 wprintf("<CENTER><TABLE border><CAPTION>Select access level:");
267 wprintf("</CAPTION><TR>");
268 for (a = 0; a <= 6; ++a) {
269 wprintf("<TD><A HREF=\"/validate&user=");
271 wprintf("&WC->axlevel=%d\">%s</A></TD>\n",
274 wprintf("</TR></TABLE><CENTER><BR>\n");
284 * Display form for registration.
285 * (Set during_login to 1 if this registration is being performed during
286 * new user login and will require chaining to the proper screen.)
288 void display_reg(int during_login)
295 wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=007700><TR><TD>");
296 wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
297 wprintf("<B>Enter registration info</B>\n");
298 wprintf("</FONT></TD></TR></TABLE>\n");
301 serv_puts("MESG register");
306 wprintf("<FORM ACTION=\"/register\" METHOD=\"POST\">\n");
307 wprintf("<INPUT TYPE=\"hidden\" NAME=\"during_login\" VALUE=\"%d\">\n", during_login);
309 serv_puts("GREG _SELF_");
312 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
315 wprintf("<H1>%s</H1><TABLE border>\n", &buf[4]);
317 while (serv_gets(buf), strcmp(buf, "000")) {
322 wprintf("Real Name:</TD><TD><INPUT TYPE=\"text\" NAME=\"realname\" VALUE=\"%s\" MAXLENGTH=\"29\"><BR>\n", buf);
325 wprintf("Street Address:</TD><TD><INPUT TYPE=\"text\" NAME=\"address\" VALUE=\"%s\" MAXLENGTH=\"24\"><BR>\n", buf);
328 wprintf("City/town:</TD><TD><INPUT TYPE=\"text\" NAME=\"city\" VALUE=\"%s\" MAXLENGTH=\"14\"><BR>\n", buf);
331 wprintf("State/province:</TD><TD><INPUT TYPE=\"text\" NAME=\"state\" VALUE=\"%s\" MAXLENGTH=\"2\"><BR>\n", buf);
334 wprintf("ZIP/postal code:</TD><TD><INPUT TYPE=\"text\" NAME=\"zip\" VALUE=\"%s\" MAXLENGTH=\"10\"><BR>\n", buf);
337 wprintf("Telephone:</TD><TD><INPUT TYPE=\"text\" NAME=\"phone\" VALUE=\"%s\" MAXLENGTH=\"14\"><BR>\n", buf);
340 wprintf("E-Mail:</TD><TD><INPUT TYPE=\"text\" NAME=\"email\" VALUE=\"%s\" MAXLENGTH=\"31\"><BR>\n", buf);
343 wprintf("Country:</TD><TD><INPUT TYPE=\"text\" NAME=\"country\" VALUE=\"%s\" MAXLENGTH=\"31\"><BR>\n", buf);
346 wprintf("</TD></TR>\n");
348 wprintf("</TABLE><P>");
350 wprintf("<INPUT type=\"submit\" NAME=\"action\" VALUE=\"Register\">\n");
351 wprintf("<INPUT type=\"submit\" NAME=\"action\" VALUE=\"Cancel\">\n");
352 wprintf("</CENTER>\n");
359 void register_user(void)
363 if (strcmp(bstr("action"), "Register")) {
364 display_error("Cancelled. Registration was not saved.");
370 display_error(&buf[4]);
372 serv_puts(bstr("realname"));
373 serv_puts(bstr("address"));
374 serv_puts(bstr("city"));
375 serv_puts(bstr("state"));
376 serv_puts(bstr("zip"));
377 serv_puts(bstr("phone"));
378 serv_puts(bstr("email"));
379 serv_puts(bstr("country"));
382 if (atoi(bstr("during_login"))) {
385 display_success("Registration information has been saved.");
394 * display form for changing your password
396 void display_changepw(void)
402 wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=770000><TR><TD>");
403 wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
404 wprintf("<B>Change your password</B>\n");
405 wprintf("</FONT></TD></TR></TABLE>\n");
408 serv_puts("MESG changepw");
413 wprintf("<FORM ACTION=\"changepw\" METHOD=\"POST\">\n");
414 wprintf("<CENTER><TABLE border><TR><TD>Enter new password:</TD>\n");
415 wprintf("<TD><INPUT TYPE=\"password\" NAME=\"newpass1\" VALUE=\"\" MAXLENGTH=\"20\"></TD></TR>\n");
416 wprintf("<TR><TD>Enter it again to confirm:</TD>\n");
417 wprintf("<TD><INPUT TYPE=\"password\" NAME=\"newpass2\" VALUE=\"\" MAXLENGTH=\"20\"></TD></TR>\n");
418 wprintf("</TABLE>\n");
419 wprintf("<INPUT type=\"submit\" NAME=\"action\" VALUE=\"Change\">\n");
420 wprintf("<INPUT type=\"submit\" NAME=\"action\" VALUE=\"Cancel\">\n");
421 wprintf("</CENTER>\n");
431 char newpass1[32], newpass2[32];
433 if (strcmp(bstr("action"), "Change")) {
434 display_error("Cancelled. Password was not changed.");
437 strcpy(newpass1, bstr("newpass1"));
438 strcpy(newpass2, bstr("newpass2"));
440 if (strcasecmp(newpass1, newpass2)) {
441 display_error("They don't match. Password was not changed.");
444 serv_printf("SETP %s", newpass1);
447 display_success(&buf[4]);
449 display_error(&buf[4]);