4 * Handles authentication of users to a Citadel server.
15 #include <sys/types.h>
17 #include <sys/socket.h>
20 #include <netinet/in.h>
42 * Display the login screen
44 void display_login(char *mesg)
48 output_headers(1, 1, 2, 0, 0, 0, 0);
49 wprintf("<div style=\"position:absolute; top:20px; left:20px; right:20px\">\n");
51 if (mesg != NULL) if (strlen(mesg) > 0) {
52 stresc(buf, mesg, 0, 0);
53 svprintf("mesg", WCS_STRING, "%s", buf);
56 svprintf("hello", WCS_SERVCMD, "MESG hello");
57 svprintf("BOXTITLE", WCS_STRING, "%s - powered by Citadel",
58 serv_info.serv_humannode);
69 * This function needs to get called whenever the session changes from
70 * not-logged-in to logged-in, either by an explicit login by the user or
71 * by a timed-out session automatically re-establishing with a little help
72 * from the browser cookie. Either way, we need to load access controls and
73 * preferences from the server.
75 void become_logged_in(char *user, char *pass, char *serv_response)
80 extract_token(WC->wc_username, &serv_response[4], 0, '|', sizeof WC->wc_username);
81 safestrncpy(WC->wc_password, pass, sizeof WC->wc_password);
82 WC->axlevel = extract_int(&serv_response[4], 1);
83 if (WC->axlevel >= 6) {
90 serv_getln(buf, sizeof buf);
92 WC->new_mail = extract_int(&buf[4], 0);
93 WC->need_regi = extract_int(&buf[4], 1);
94 WC->need_vali = extract_int(&buf[4], 2);
95 extract_token(WC->cs_inet_email, &buf[4], 3, '|', sizeof WC->cs_inet_email);
104 if (!strcasecmp(bstr("action"), "Exit")) {
108 if (!strcasecmp(bstr("action"), "Login")) {
109 serv_printf("USER %s", bstr("name"));
110 serv_getln(buf, sizeof buf);
112 serv_printf("PASS %s", bstr("pass"));
113 serv_getln(buf, sizeof buf);
115 become_logged_in(bstr("name"),
118 display_login(&buf[4]);
122 display_login(&buf[4]);
126 if (!strcasecmp(bstr("action"), "New User")) {
127 if (strlen(bstr("pass")) == 0) {
128 display_login("Blank passwords are not allowed.");
131 serv_printf("NEWU %s", bstr("name"));
132 serv_getln(buf, sizeof buf);
134 become_logged_in(bstr("name"), bstr("pass"), buf);
135 serv_printf("SETP %s", bstr("pass"));
136 serv_getln(buf, sizeof buf);
138 display_login(&buf[4]);
149 display_login("Your password was not accepted.");
154 void do_welcome(void)
157 #ifdef XXX_NOT_FINISHED_YET_XXX
162 * See if we have to run the first-time setup wizard
166 sprintf(wizard_filename, "setupwiz.%s.%s",
168 for (i=0; i<strlen(wizard_filename); ++i) {
169 if ( (wizard_filename[i]==' ')
170 || (wizard_filename[i] == '/')
172 wizard_filename[i] = '_';
176 fp = fopen(wizard_filename, "r");
178 fgets(buf, sizeof buf, fp);
179 buf[strlen(buf)-1] = 0;
181 if (atoi(buf) == serv_info.serv_rev_level) {
182 setup_wizard = 1; /* already run */
188 http_redirect("/setup_wizard");
194 * Go to the user's preferred start page
196 get_preference("startpage", buf, sizeof buf);
197 if (strlen(buf)==0) {
198 safestrncpy(buf, "/dotskip&room=_BASEROOM_", sizeof buf);
199 set_preference("startpage", buf, 1);
206 * Disconnect from the Citadel server, and end this WebCit session
208 void end_webcit_session(void) {
211 /* close() of citadel socket will be done by do_housekeeping() */
219 safestrncpy(WC->wc_username, "", sizeof WC->wc_username);
220 safestrncpy(WC->wc_password, "", sizeof WC->wc_password);
221 safestrncpy(WC->wc_roomname, "", sizeof WC->wc_roomname);
223 /* Calling output_headers() this way causes the cookies to be un-set */
224 output_headers(1, 1, 0, 1, 0, 0, 0);
227 serv_puts("MESG goodbye");
228 serv_getln(buf, sizeof buf);
230 if (WC->serv_sock >= 0) {
232 fmout(NULL, "CENTER");
234 wprintf("Goodbye\n");
238 wprintf("This program was unable to connect or stay "
239 "connected to the Citadel server. Please report "
240 "this problem to your system administrator."
244 wprintf("<hr /><a href=\"/\">Log in again</A> "
245 "<a href=\"javascript:window.close();\">Close window</A>"
248 end_webcit_session();
262 output_headers(1, 1, 2, 0, 0, 0, 0);
263 wprintf("<div id=\"banner\">\n"
264 "<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#444455\"><TR><TD>"
265 "<SPAN CLASS=\"titlebar\">Validate new users</SPAN>"
266 "</TD></TR></TABLE>\n"
267 "</div>\n<div id=\"content\">\n"
270 safestrncpy(buf, bstr("user"), sizeof buf);
272 if (strlen(bstr("axlevel")) > 0) {
273 serv_printf("VALI %s|%s", buf, bstr("axlevel"));
274 serv_getln(buf, sizeof buf);
276 wprintf("<b>%s</b><br />\n", &buf[4]);
280 serv_getln(buf, sizeof buf);
283 wprintf("<b>%s</b><br />\n", &buf[4]);
288 wprintf("<div id=\"fix_scrollbar_bug\">"
289 "<table border=0 width=100%% bgcolor=\"#ffffff\"><tr><td>\n");
292 safestrncpy(user, &buf[4], sizeof user);
293 serv_printf("GREG %s", user);
294 serv_getln(cmd, sizeof cmd);
298 serv_getln(buf, sizeof buf);
301 wprintf("User #%s<br /><H1>%s</H1>",
304 wprintf("PW: %s<br />\n", buf);
306 wprintf("%s<br />\n", buf);
308 wprintf("%s<br />\n", buf);
310 wprintf("%s, ", buf);
314 wprintf("%s<br />\n", buf);
316 wprintf("%s<br />\n", buf);
318 wprintf("Current access level: %d (%s)\n",
319 atoi(buf), axdefs[atoi(buf)]);
320 } while (strcmp(buf, "000"));
322 wprintf("<H1>%s</H1>%s<br />\n", user, &cmd[4]);
325 wprintf("<hr />Select access level for this user:<br />\n");
326 for (a = 0; a <= 6; ++a) {
327 wprintf("<A HREF=\"/validate&user=");
329 wprintf("&axlevel=%d\">%s</A> \n",
334 wprintf("</CENTER>\n");
335 wprintf("</td></tr></table></div>\n");
342 * Display form for registration.
343 * (Set during_login to 1 if this registration is being performed during
344 * new user login and will require chaining to the proper screen.)
346 void display_reg(int during_login)
350 if (goto_config_room() != 0) {
351 if (during_login) do_welcome();
352 else display_main_menu();
356 vcard_msgnum = locate_user_vcard(WC->wc_username, -1);
357 if (vcard_msgnum < 0L) {
358 if (during_login) do_welcome();
359 else display_main_menu();
364 do_edit_vcard(vcard_msgnum, "1", "/do_welcome");
367 do_edit_vcard(vcard_msgnum, "1", "/display_main_menu");
376 * display form for changing your password
378 void display_changepw(void)
382 output_headers(1, 1, 2, 0, 0, 0, 0);
383 wprintf("<div id=\"banner\">\n"
384 "<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#444455\"><TR><TD>"
385 "<SPAN CLASS=\"titlebar\">Change your password</SPAN>"
386 "</TD></TR></TABLE>\n"
387 "</div>\n<div id=\"content\">\n"
390 if (strlen(WC->ImportantMessage) > 0) {
391 do_template("beginbox_nt");
392 wprintf("<SPAN CLASS=\"errormsg\">"
393 "%s</SPAN><br />\n", WC->ImportantMessage);
394 do_template("endbox");
395 safestrncpy(WC->ImportantMessage, "", sizeof WC->ImportantMessage);
398 wprintf("<div id=\"fix_scrollbar_bug\">"
399 "<table border=0 width=100%% bgcolor=\"#ffffff\"><tr><td>\n");
401 wprintf("<CENTER><br />");
402 serv_puts("MESG changepw");
403 serv_getln(buf, sizeof buf);
405 fmout(NULL, "CENTER");
408 wprintf("<form name=\"changepwform\" action=\"changepw\" method=\"post\">\n");
410 "<table border=\"0\" cellspacing=\"5\" cellpadding=\"5\" "
411 "BGCOLOR=\"#EEEEEE\">"
412 "<TR><TD>Enter new password:</TD>\n");
413 wprintf("<TD><INPUT TYPE=\"password\" NAME=\"newpass1\" VALUE=\"\" MAXLENGTH=\"20\"></TD></TR>\n");
414 wprintf("<TR><TD>Enter it again to confirm:</TD>\n");
415 wprintf("<TD><INPUT TYPE=\"password\" NAME=\"newpass2\" VALUE=\"\" MAXLENGTH=\"20\"></TD></TR>\n");
417 wprintf("</TABLE><br />\n");
418 wprintf("<INPUT type=\"submit\" name=\"action\" value=\"Change\">"
420 "<INPUT type=\"submit\" name=\"action\" value=\"Cancel\">\n");
421 wprintf("</form></center>\n");
422 wprintf("</td></tr></table></div>\n");
432 char newpass1[32], newpass2[32];
434 if (strcmp(bstr("action"), "Change")) {
435 safestrncpy(WC->ImportantMessage,
436 "Cancelled. Password was not changed.",
437 sizeof WC->ImportantMessage);
442 safestrncpy(newpass1, bstr("newpass1"), sizeof newpass1);
443 safestrncpy(newpass2, bstr("newpass2"), sizeof newpass2);
445 if (strcasecmp(newpass1, newpass2)) {
446 safestrncpy(WC->ImportantMessage,
447 "They don't match. Password was not changed.",
448 sizeof WC->ImportantMessage);
453 if (strlen(newpass1) == 0) {
454 safestrncpy(WC->ImportantMessage,
455 "Blank passwords are not allowed.",
456 sizeof WC->ImportantMessage);
461 serv_printf("SETP %s", newpass1);
462 serv_getln(buf, sizeof buf);
463 sprintf(WC->ImportantMessage, "%s", &buf[4]);
465 safestrncpy(WC->wc_password, buf, sizeof WC->wc_password);