4 * Handles authentication of users to a Citadel server.
22 * Display the login screen
24 void display_login(char *mesg)
28 output_headers(1, 1, 2, 0, 0, 0);
29 wprintf("<div style=\"position:absolute; top:20px; left:20px; right:20px\">\n");
31 if (mesg != NULL) if (strlen(mesg) > 0) {
32 stresc(buf, mesg, 0, 0);
33 svprintf("mesg", WCS_STRING, "%s", buf);
36 svprintf("LOGIN_INSTRUCTIONS", WCS_STRING,
38 "<li><b>If you already have an account on %s</b>, "
39 "enter your user name and password and click "Login." "
40 "<li><b>If you are a new user</b>, enter the name and password "
42 "and click "New User." "
43 "<li>Please log off properly when finished. "
44 "<li>You must use a browser that supports <i>frames</i> and "
46 "<li>Also keep in mind that if your browser is "
47 "configured to block pop-up windows, you will not be able "
48 "to receive any instant messages.<br />"
50 serv_info.serv_humannode
53 svprintf("LOGIN_BUTTON", WCS_STRING, "%s", _("Login"));
54 svprintf("NEWUSER_BUTTON", WCS_STRING, "%s", _("New User"));
55 svprintf("EXIT_BUTTON", WCS_STRING, "%s", _("Exit"));
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 (strlen(bstr("exit_action")) > 0) {
108 if (strlen(bstr("login_action")) > 0) {
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 (strlen(bstr("newuser_action")) > 0) {
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);
227 serv_puts("MESG goodbye");
228 serv_getln(buf, sizeof buf);
230 if (WC->serv_sock >= 0) {
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();\">");
246 wprintf(_("Close window"));
247 wprintf("</a></center>\n");
249 end_webcit_session();
263 output_headers(1, 1, 2, 0, 0, 0);
264 wprintf("<div id=\"banner\">\n"
265 "<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#444455\"><TR><TD>"
266 "<SPAN CLASS=\"titlebar\">");
267 wprintf(_("Validate new users"));
268 wprintf("</SPAN></TD></TR></TABLE>\n</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]);
326 wprintf(_("Select access level for this user:"));
328 for (a = 0; a <= 6; ++a) {
329 wprintf("<A HREF=\"/validate&user=");
331 wprintf("&axlevel=%d\">%s</A> \n",
336 wprintf("</CENTER>\n");
337 wprintf("</td></tr></table></div>\n");
344 * Display form for registration.
345 * (Set during_login to 1 if this registration is being performed during
346 * new user login and will require chaining to the proper screen.)
348 void display_reg(int during_login)
352 if (goto_config_room() != 0) {
353 if (during_login) do_welcome();
354 else display_main_menu();
358 vcard_msgnum = locate_user_vcard(WC->wc_username, -1);
359 if (vcard_msgnum < 0L) {
360 if (during_login) do_welcome();
361 else display_main_menu();
366 do_edit_vcard(vcard_msgnum, "1", "/do_welcome");
369 do_edit_vcard(vcard_msgnum, "1", "/display_main_menu");
378 * display form for changing your password
380 void display_changepw(void)
384 output_headers(1, 1, 2, 0, 0, 0);
385 wprintf("<div id=\"banner\">\n"
386 "<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#444455\"><TR><TD>"
387 "<SPAN CLASS=\"titlebar\">");
388 wprintf(_("Change your password"));
390 "</TD></TR></TABLE>\n"
391 "</div>\n<div id=\"content\">\n"
394 if (strlen(WC->ImportantMessage) > 0) {
395 do_template("beginbox_nt");
396 wprintf("<SPAN CLASS=\"errormsg\">"
397 "%s</SPAN><br />\n", WC->ImportantMessage);
398 do_template("endbox");
399 safestrncpy(WC->ImportantMessage, "", sizeof WC->ImportantMessage);
402 wprintf("<div id=\"fix_scrollbar_bug\">"
403 "<table border=0 width=100%% bgcolor=\"#ffffff\"><tr><td>\n");
405 wprintf("<CENTER><br />");
406 serv_puts("MESG changepw");
407 serv_getln(buf, sizeof buf);
412 wprintf("<form name=\"changepwform\" action=\"changepw\" method=\"post\">\n");
414 "<table border=\"0\" cellspacing=\"5\" cellpadding=\"5\" "
415 "BGCOLOR=\"#EEEEEE\">"
417 wprintf(_("Enter new password:"));
419 wprintf("<TD><INPUT TYPE=\"password\" NAME=\"newpass1\" VALUE=\"\" MAXLENGTH=\"20\"></TD></TR>\n");
421 wprintf(_("Enter it again to confirm:"));
423 wprintf("<TD><INPUT TYPE=\"password\" NAME=\"newpass2\" VALUE=\"\" MAXLENGTH=\"20\"></TD></TR>\n");
425 wprintf("</TABLE><br />\n");
426 wprintf("<INPUT type=\"submit\" name=\"change_action\" value=\"%s\">", _("Change password"));
428 wprintf("<INPUT type=\"submit\" name=\"cancel_action\" value=\"%s\">\n", _("Cancel"));
429 wprintf("</form></center>\n");
430 wprintf("</td></tr></table></div>\n");
440 char newpass1[32], newpass2[32];
442 if (strlen(bstr("change_action")) == 0) {
443 safestrncpy(WC->ImportantMessage,
444 _("Cancelled. Password was not changed."),
445 sizeof WC->ImportantMessage);
450 safestrncpy(newpass1, bstr("newpass1"), sizeof newpass1);
451 safestrncpy(newpass2, bstr("newpass2"), sizeof newpass2);
453 if (strcasecmp(newpass1, newpass2)) {
454 safestrncpy(WC->ImportantMessage,
455 _("They don't match. Password was not changed."),
456 sizeof WC->ImportantMessage);
461 if (strlen(newpass1) == 0) {
462 safestrncpy(WC->ImportantMessage,
463 _("Blank passwords are not allowed."),
464 sizeof WC->ImportantMessage);
469 serv_printf("SETP %s", newpass1);
470 serv_getln(buf, sizeof buf);
471 sprintf(WC->ImportantMessage, "%s", &buf[4]);
473 safestrncpy(WC->wc_password, buf, sizeof WC->wc_password);