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);
202 strcpy(buf, &buf[1]);
209 * Disconnect from the Citadel server, and end this WebCit session
211 void end_webcit_session(void) {
214 /* close() of citadel socket will be done by do_housekeeping() */
222 safestrncpy(WC->wc_username, "", sizeof WC->wc_username);
223 safestrncpy(WC->wc_password, "", sizeof WC->wc_password);
224 safestrncpy(WC->wc_roomname, "", sizeof WC->wc_roomname);
226 /* Calling output_headers() this way causes the cookies to be un-set */
227 output_headers(1, 1, 0, 1, 0, 0);
230 serv_puts("MESG goodbye");
231 serv_getln(buf, sizeof buf);
233 if (WC->serv_sock >= 0) {
237 wprintf("Goodbye\n");
241 wprintf(_("This program was unable to connect or stay "
242 "connected to the Citadel server. Please report "
243 "this problem to your system administrator.")
247 wprintf("<hr /><a href=\".\">Log in again</A> "
248 "<a href=\"javascript:window.close();\">");
249 wprintf(_("Close window"));
250 wprintf("</a></center>\n");
252 end_webcit_session();
266 output_headers(1, 1, 2, 0, 0, 0);
267 wprintf("<div id=\"banner\">\n"
268 "<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#444455\"><TR><TD>"
269 "<SPAN CLASS=\"titlebar\">");
270 wprintf(_("Validate new users"));
271 wprintf("</SPAN></TD></TR></TABLE>\n</div>\n<div id=\"content\">\n");
273 safestrncpy(buf, bstr("user"), sizeof buf);
275 if (strlen(bstr("axlevel")) > 0) {
276 serv_printf("VALI %s|%s", buf, bstr("axlevel"));
277 serv_getln(buf, sizeof buf);
279 wprintf("<b>%s</b><br />\n", &buf[4]);
283 serv_getln(buf, sizeof buf);
286 wprintf("<b>%s</b><br />\n", &buf[4]);
291 wprintf("<div id=\"fix_scrollbar_bug\">"
292 "<table border=0 width=100%% bgcolor=\"#ffffff\"><tr><td>\n");
295 safestrncpy(user, &buf[4], sizeof user);
296 serv_printf("GREG %s", user);
297 serv_getln(cmd, sizeof cmd);
301 serv_getln(buf, sizeof buf);
304 wprintf("User #%s<br /><H1>%s</H1>",
307 wprintf("PW: %s<br />\n", buf);
309 wprintf("%s<br />\n", buf);
311 wprintf("%s<br />\n", buf);
313 wprintf("%s, ", buf);
317 wprintf("%s<br />\n", buf);
319 wprintf("%s<br />\n", buf);
321 wprintf(_("Current access level: %d (%s)\n"),
322 atoi(buf), axdefs[atoi(buf)]);
323 } while (strcmp(buf, "000"));
325 wprintf("<H1>%s</H1>%s<br />\n", user, &cmd[4]);
329 wprintf(_("Select access level for this user:"));
331 for (a = 0; a <= 6; ++a) {
332 wprintf("<a href=\"validate&user=");
334 wprintf("&axlevel=%d\">%s</A> \n",
339 wprintf("</CENTER>\n");
340 wprintf("</td></tr></table></div>\n");
347 * Display form for registration.
348 * (Set during_login to 1 if this registration is being performed during
349 * new user login and will require chaining to the proper screen.)
351 void display_reg(int during_login)
355 if (goto_config_room() != 0) {
356 if (during_login) do_welcome();
357 else display_main_menu();
361 vcard_msgnum = locate_user_vcard(WC->wc_username, -1);
362 if (vcard_msgnum < 0L) {
363 if (during_login) do_welcome();
364 else display_main_menu();
369 do_edit_vcard(vcard_msgnum, "1", "do_welcome");
372 do_edit_vcard(vcard_msgnum, "1", "display_main_menu");
381 * display form for changing your password
383 void display_changepw(void)
387 output_headers(1, 1, 2, 0, 0, 0);
388 wprintf("<div id=\"banner\">\n"
389 "<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#444455\"><TR><TD>"
390 "<SPAN CLASS=\"titlebar\">");
391 wprintf(_("Change your password"));
393 "</TD></TR></TABLE>\n"
394 "</div>\n<div id=\"content\">\n"
397 if (strlen(WC->ImportantMessage) > 0) {
398 do_template("beginbox_nt");
399 wprintf("<SPAN CLASS=\"errormsg\">"
400 "%s</SPAN><br />\n", WC->ImportantMessage);
401 do_template("endbox");
402 safestrncpy(WC->ImportantMessage, "", sizeof WC->ImportantMessage);
405 wprintf("<div id=\"fix_scrollbar_bug\">"
406 "<table border=0 width=100%% bgcolor=\"#ffffff\"><tr><td>\n");
408 wprintf("<CENTER><br />");
409 serv_puts("MESG changepw");
410 serv_getln(buf, sizeof buf);
415 wprintf("<form name=\"changepwform\" action=\"changepw\" method=\"post\">\n");
417 "<table border=\"0\" cellspacing=\"5\" cellpadding=\"5\" "
418 "BGCOLOR=\"#EEEEEE\">"
420 wprintf(_("Enter new password:"));
422 wprintf("<TD><INPUT TYPE=\"password\" NAME=\"newpass1\" VALUE=\"\" MAXLENGTH=\"20\"></TD></TR>\n");
424 wprintf(_("Enter it again to confirm:"));
426 wprintf("<TD><INPUT TYPE=\"password\" NAME=\"newpass2\" VALUE=\"\" MAXLENGTH=\"20\"></TD></TR>\n");
428 wprintf("</TABLE><br />\n");
429 wprintf("<INPUT type=\"submit\" name=\"change_action\" value=\"%s\">", _("Change password"));
431 wprintf("<INPUT type=\"submit\" name=\"cancel_action\" value=\"%s\">\n", _("Cancel"));
432 wprintf("</form></center>\n");
433 wprintf("</td></tr></table></div>\n");
443 char newpass1[32], newpass2[32];
445 if (strlen(bstr("change_action")) == 0) {
446 safestrncpy(WC->ImportantMessage,
447 _("Cancelled. Password was not changed."),
448 sizeof WC->ImportantMessage);
453 safestrncpy(newpass1, bstr("newpass1"), sizeof newpass1);
454 safestrncpy(newpass2, bstr("newpass2"), sizeof newpass2);
456 if (strcasecmp(newpass1, newpass2)) {
457 safestrncpy(WC->ImportantMessage,
458 _("They don't match. Password was not changed."),
459 sizeof WC->ImportantMessage);
464 if (strlen(newpass1) == 0) {
465 safestrncpy(WC->ImportantMessage,
466 _("Blank passwords are not allowed."),
467 sizeof WC->ImportantMessage);
472 serv_printf("SETP %s", newpass1);
473 serv_getln(buf, sizeof buf);
474 sprintf(WC->ImportantMessage, "%s", &buf[4]);
476 safestrncpy(WC->wc_password, buf, sizeof WC->wc_password);