4 * Handles authentication of users to a Citadel server.
12 void initialize_axdefs(void) {
13 axdefs[0] = _("Deleted");
14 axdefs[1] = _("New User");
15 axdefs[2] = _("Problem User");
16 axdefs[3] = _("Local User");
17 axdefs[4] = _("Network User");
18 axdefs[5] = _("Preferred User");
19 axdefs[6] = _("Aide");
26 * Display the login screen
28 void display_login(char *mesg)
32 output_headers(1, 1, 2, 0, 0, 0);
33 wprintf("<div style=\"position:absolute; top:20px; left:20px; right:20px\">\n");
35 if (mesg != NULL) if (strlen(mesg) > 0) {
36 stresc(buf, mesg, 0, 0);
37 svprintf("mesg", WCS_STRING, "%s", buf);
40 svprintf("LOGIN_INSTRUCTIONS", WCS_STRING,
42 "<li><b>If you already have an account on %s</b>, "
43 "enter your user name and password and click "Login." "
44 "<li><b>If you are a new user</b>, enter the name and password "
46 "and click "New User." "
47 "<li>Please log off properly when finished. "
48 "<li>You must use a browser that supports <i>frames</i> and "
50 "<li>Also keep in mind that if your browser is "
51 "configured to block pop-up windows, you will not be able "
52 "to receive any instant messages.<br />"
54 serv_info.serv_humannode
57 svprintf("USERNAME_BOX", WCS_STRING, "%s", _("User name:"));
58 svprintf("PASSWORD_BOX", WCS_STRING, "%s", _("Password:"));
59 svprintf("LANGUAGE_BOX", WCS_STRING, "%s", _("Language:"));
60 svprintf("LOGIN_BUTTON", WCS_STRING, "%s", _("Login"));
61 svprintf("NEWUSER_BUTTON", WCS_STRING, "%s", _("New User"));
62 svprintf("EXIT_BUTTON", WCS_STRING, "%s", _("Exit"));
63 svprintf("hello", WCS_SERVCMD, "MESG hello");
64 svprintf("BOXTITLE", WCS_STRING, _("%s - powered by Citadel"),
65 serv_info.serv_humannode);
66 svcallback("DO_LANGUAGE_BOX", offer_languages);
77 * This function needs to get called whenever the session changes from
78 * not-logged-in to logged-in, either by an explicit login by the user or
79 * by a timed-out session automatically re-establishing with a little help
80 * from the browser cookie. Either way, we need to load access controls and
81 * preferences from the server.
83 void become_logged_in(char *user, char *pass, char *serv_response)
88 extract_token(WC->wc_fullname, &serv_response[4], 0, '|', sizeof WC->wc_fullname);
89 safestrncpy(WC->wc_username, user, sizeof WC->wc_username);
90 safestrncpy(WC->wc_password, pass, sizeof WC->wc_password);
91 WC->axlevel = extract_int(&serv_response[4], 1);
92 if (WC->axlevel >= 6) {
99 serv_getln(buf, sizeof buf);
101 WC->new_mail = extract_int(&buf[4], 0);
102 WC->need_regi = extract_int(&buf[4], 1);
103 WC->need_vali = extract_int(&buf[4], 2);
104 extract_token(WC->cs_inet_email, &buf[4], 3, '|', sizeof WC->cs_inet_email);
107 get_preference("current_iconbar", buf, sizeof buf);
108 WC->current_iconbar = atoi(buf);
110 get_preference("floordiv_expanded", WC->floordiv_expanded, sizeof WC->floordiv_expanded);
118 if (strlen(bstr("language")) > 0) {
119 set_selected_language(bstr("language"));
120 go_selected_language();
123 if (strlen(bstr("exit_action")) > 0) {
127 if (strlen(bstr("login_action")) > 0) {
128 serv_printf("USER %s", bstr("name"));
129 serv_getln(buf, sizeof buf);
131 serv_printf("PASS %s", bstr("pass"));
132 serv_getln(buf, sizeof buf);
134 become_logged_in(bstr("name"),
137 display_login(&buf[4]);
141 display_login(&buf[4]);
145 if (strlen(bstr("newuser_action")) > 0) {
146 if (strlen(bstr("pass")) == 0) {
147 display_login(_("Blank passwords are not allowed."));
150 serv_printf("NEWU %s", bstr("name"));
151 serv_getln(buf, sizeof buf);
153 become_logged_in(bstr("name"), bstr("pass"), buf);
154 serv_printf("SETP %s", bstr("pass"));
155 serv_getln(buf, sizeof buf);
157 display_login(&buf[4]);
168 display_login(_("Your password was not accepted."));
173 void do_welcome(void)
176 #ifdef XXX_NOT_FINISHED_YET_XXX
181 * See if we have to run the first-time setup wizard
185 sprintf(wizard_filename, "setupwiz.%s.%s",
187 for (i=0; i<strlen(wizard_filename); ++i) {
188 if ( (wizard_filename[i]==' ')
189 || (wizard_filename[i] == '/')
191 wizard_filename[i] = '_';
195 fp = fopen(wizard_filename, "r");
197 fgets(buf, sizeof buf, fp);
198 buf[strlen(buf)-1] = 0;
200 if (atoi(buf) == serv_info.serv_rev_level) {
201 setup_wizard = 1; /* already run */
207 http_redirect("setup_wizard");
213 * Go to the user's preferred start page
215 get_preference("startpage", buf, sizeof buf);
216 if (strlen(buf)==0) {
217 safestrncpy(buf, "dotskip&room=_BASEROOM_", sizeof buf);
218 set_preference("startpage", buf, 1);
221 strcpy(buf, &buf[1]);
228 * Disconnect from the Citadel server, and end this WebCit session
230 void end_webcit_session(void) {
234 sprintf(buf, "%d", WC->current_iconbar);
235 set_preference("current_iconbar", buf, 0);
236 set_preference("floordiv_expanded", WC->floordiv_expanded, 1);
241 /* close() of citadel socket will be done by do_housekeeping() */
249 safestrncpy(WC->wc_username, "", sizeof WC->wc_username);
250 safestrncpy(WC->wc_password, "", sizeof WC->wc_password);
251 safestrncpy(WC->wc_roomname, "", sizeof WC->wc_roomname);
252 safestrncpy(WC->wc_fullname, "", sizeof WC->wc_fullname);
254 /* Calling output_headers() this way causes the cookies to be un-set */
255 output_headers(1, 1, 0, 1, 0, 0);
258 serv_puts("MESG goodbye");
259 serv_getln(buf, sizeof buf);
261 if (WC->serv_sock >= 0) {
265 wprintf("Goodbye\n");
269 wprintf(_("This program was unable to connect or stay "
270 "connected to the Citadel server. Please report "
271 "this problem to your system administrator.")
275 wprintf("<hr /><a href=\".\">");
276 wprintf(_("Log in again"));
277 wprintf("</A> "
278 "<a href=\"javascript:window.close();\">");
279 wprintf(_("Close window"));
280 wprintf("</a></center>\n");
282 end_webcit_session();
296 output_headers(1, 1, 2, 0, 0, 0);
297 wprintf("<div id=\"banner\">\n"
298 "<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#444455\"><TR><TD>"
299 "<SPAN CLASS=\"titlebar\">");
300 wprintf(_("Validate new users"));
301 wprintf("</SPAN></TD></TR></TABLE>\n</div>\n<div id=\"content\">\n");
303 /* If the user just submitted a validation, process it... */
304 safestrncpy(buf, bstr("user"), sizeof buf);
305 if (strlen(buf) > 0) {
306 if (strlen(bstr("axlevel")) > 0) {
307 serv_printf("VALI %s|%s", buf, bstr("axlevel"));
308 serv_getln(buf, sizeof buf);
310 wprintf("<b>%s</b><br />\n", &buf[4]);
315 /* Now see if any more users require validation. */
317 serv_getln(buf, sizeof buf);
320 wprintf(_("No users require validation at this time."));
321 wprintf("</b><br />\n");
326 wprintf("<b>%s</b><br />\n", &buf[4]);
331 wprintf("<div class=\"fix_scrollbar_bug\">"
332 "<table border=0 width=100%% bgcolor=\"#ffffff\"><tr><td>\n");
335 safestrncpy(user, &buf[4], sizeof user);
336 serv_printf("GREG %s", user);
337 serv_getln(cmd, sizeof cmd);
341 serv_getln(buf, sizeof buf);
344 wprintf("#%s<br /><H1>%s</H1>",
347 wprintf("PW: %s<br />\n", buf);
349 wprintf("%s<br />\n", buf);
351 wprintf("%s<br />\n", buf);
353 wprintf("%s, ", buf);
357 wprintf("%s<br />\n", buf);
359 wprintf("%s<br />\n", buf);
361 wprintf(_("Current access level: %d (%s)\n"),
362 atoi(buf), axdefs[atoi(buf)]);
363 } while (strcmp(buf, "000"));
365 wprintf("<H1>%s</H1>%s<br />\n", user, &cmd[4]);
369 wprintf(_("Select access level for this user:"));
371 for (a = 0; a <= 6; ++a) {
372 wprintf("<a href=\"validate&user=");
374 wprintf("&axlevel=%d\">%s</A> \n",
379 wprintf("</CENTER>\n");
380 wprintf("</td></tr></table></div>\n");
387 * Display form for registration.
388 * (Set during_login to 1 if this registration is being performed during
389 * new user login and will require chaining to the proper screen.)
391 void display_reg(int during_login)
395 if (goto_config_room() != 0) {
396 if (during_login) do_welcome();
397 else display_main_menu();
401 vcard_msgnum = locate_user_vcard(WC->wc_fullname, -1);
402 if (vcard_msgnum < 0L) {
403 if (during_login) do_welcome();
404 else display_main_menu();
409 do_edit_vcard(vcard_msgnum, "1", "do_welcome");
412 do_edit_vcard(vcard_msgnum, "1", "display_main_menu");
421 * display form for changing your password
423 void display_changepw(void)
427 output_headers(1, 1, 2, 0, 0, 0);
428 wprintf("<div id=\"banner\">\n"
429 "<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#444455\"><TR><TD>"
430 "<SPAN CLASS=\"titlebar\">");
431 wprintf(_("Change your password"));
433 "</TD></TR></TABLE>\n"
434 "</div>\n<div id=\"content\">\n"
437 if (strlen(WC->ImportantMessage) > 0) {
438 do_template("beginbox_nt");
439 wprintf("<SPAN CLASS=\"errormsg\">"
440 "%s</SPAN><br />\n", WC->ImportantMessage);
441 do_template("endbox");
442 safestrncpy(WC->ImportantMessage, "", sizeof WC->ImportantMessage);
445 wprintf("<div class=\"fix_scrollbar_bug\">"
446 "<table border=0 width=100%% bgcolor=\"#ffffff\"><tr><td>\n");
448 wprintf("<CENTER><br />");
449 serv_puts("MESG changepw");
450 serv_getln(buf, sizeof buf);
455 wprintf("<form name=\"changepwform\" action=\"changepw\" method=\"post\">\n");
457 "<table border=\"0\" cellspacing=\"5\" cellpadding=\"5\" "
458 "BGCOLOR=\"#EEEEEE\">"
460 wprintf(_("Enter new password:"));
462 wprintf("<TD><INPUT TYPE=\"password\" NAME=\"newpass1\" VALUE=\"\" MAXLENGTH=\"20\"></TD></TR>\n");
464 wprintf(_("Enter it again to confirm:"));
466 wprintf("<TD><INPUT TYPE=\"password\" NAME=\"newpass2\" VALUE=\"\" MAXLENGTH=\"20\"></TD></TR>\n");
468 wprintf("</TABLE><br />\n");
469 wprintf("<INPUT type=\"submit\" name=\"change_action\" value=\"%s\">", _("Change password"));
471 wprintf("<INPUT type=\"submit\" name=\"cancel_action\" value=\"%s\">\n", _("Cancel"));
472 wprintf("</form></center>\n");
473 wprintf("</td></tr></table></div>\n");
483 char newpass1[32], newpass2[32];
485 if (strlen(bstr("change_action")) == 0) {
486 safestrncpy(WC->ImportantMessage,
487 _("Cancelled. Password was not changed."),
488 sizeof WC->ImportantMessage);
493 safestrncpy(newpass1, bstr("newpass1"), sizeof newpass1);
494 safestrncpy(newpass2, bstr("newpass2"), sizeof newpass2);
496 if (strcasecmp(newpass1, newpass2)) {
497 safestrncpy(WC->ImportantMessage,
498 _("They don't match. Password was not changed."),
499 sizeof WC->ImportantMessage);
504 if (strlen(newpass1) == 0) {
505 safestrncpy(WC->ImportantMessage,
506 _("Blank passwords are not allowed."),
507 sizeof WC->ImportantMessage);
512 serv_printf("SETP %s", newpass1);
513 serv_getln(buf, sizeof buf);
514 sprintf(WC->ImportantMessage, "%s", &buf[4]);
516 safestrncpy(WC->wc_password, buf, sizeof WC->wc_password);