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 id=\"content\">\n");
50 wprintf("<div style=\"position:absolute; top:20px; left:20px; right:20px\">\n");
52 if (mesg != NULL) if (strlen(mesg) > 0) {
53 stresc(buf, mesg, 0, 0);
54 svprintf("mesg", WCS_STRING, "%s", buf);
57 svprintf("hello", WCS_SERVCMD, "MESG hello");
58 svprintf("BOXTITLE", WCS_STRING, "%s - powered by Citadel",
59 serv_info.serv_humannode);
70 * This function needs to get called whenever the session changes from
71 * not-logged-in to logged-in, either by an explicit login by the user or
72 * by a timed-out session automatically re-establishing with a little help
73 * from the browser cookie. Either way, we need to load access controls and
74 * preferences from the server.
76 void become_logged_in(char *user, char *pass, char *serv_response)
81 extract(WC->wc_username, &serv_response[4], 0);
82 strcpy(WC->wc_password, pass);
83 WC->axlevel = extract_int(&serv_response[4], 1);
84 if (WC->axlevel >= 6) {
93 WC->new_mail = extract_int(&buf[4], 0);
94 WC->need_regi = extract_int(&buf[4], 1);
95 WC->need_vali = extract_int(&buf[4], 2);
96 extract(WC->cs_inet_email, &buf[4], 3);
105 if (!strcasecmp(bstr("action"), "Exit")) {
109 if (!strcasecmp(bstr("action"), "Login")) {
110 serv_printf("USER %s", bstr("name"));
113 serv_printf("PASS %s", bstr("pass"));
116 become_logged_in(bstr("name"),
119 display_login(&buf[4]);
123 display_login(&buf[4]);
127 if (!strcasecmp(bstr("action"), "New User")) {
128 if (strlen(bstr("pass")) == 0) {
129 display_login("Blank passwords are not allowed.");
132 serv_printf("NEWU %s", bstr("name"));
135 become_logged_in(bstr("name"), bstr("pass"), buf);
136 serv_printf("SETP %s", bstr("pass"));
139 display_login(&buf[4]);
150 display_login("Your password was not accepted.");
155 void do_welcome(void)
162 * See if we have to run the first-time setup wizard
165 sprintf(wizard_filename, "setupwiz.%s.%s", ctdlhost, ctdlport);
166 for (i=0; i<strlen(wizard_filename); ++i) {
167 if ( (wizard_filename[i]==' ')
168 || (wizard_filename[i] == '/')
170 wizard_filename[i] = '_';
174 fp = fopen(wizard_filename, "r");
176 fgets(buf, sizeof buf, fp);
177 buf[strlen(buf)-1] = 0;
179 if (atoi(buf) != serv_info.serv_rev_level) {
180 setup_wizard = 1; /* already run */
186 http_redirect("/setup_wizard");
190 * Go to the user's preferred start page
192 get_preference("startpage", buf);
193 if (strlen(buf)==0) {
194 strcpy(buf, "/dotskip&room=_BASEROOM_");
195 set_preference("startpage", buf);
202 * Disconnect from the Citadel server, and end this WebCit session
204 void end_webcit_session(void) {
207 /* close() of citadel socket will be done by do_housekeeping() */
215 strcpy(WC->wc_username, "");
216 strcpy(WC->wc_password, "");
217 strcpy(WC->wc_roomname, "");
219 /* Calling output_headers() this way causes the cookies to be un-set */
220 output_headers(1, 1, 0, 1, 0, 0, 0);
223 serv_puts("MESG goodbye");
226 if (WC->serv_sock >= 0) {
228 fmout(NULL, "CENTER");
230 wprintf("Goodbye\n");
234 wprintf("This program was unable to connect or stay "
235 "connected to the Citadel server. Please report "
236 "this problem to your system administrator."
240 wprintf("<hr /><a href=\"/\">Log in again</A> "
241 "<a href=\"javascript:window.close();\">Close window</A>"
244 end_webcit_session();
258 output_headers(1, 1, 2, 0, 0, 0, 0);
259 wprintf("<div id=\"banner\">\n"
260 "<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#444455\"><TR><TD>"
261 "<SPAN CLASS=\"titlebar\">Validate new users</SPAN>"
262 "</TD></TR></TABLE>\n"
263 "</div>\n<div id=\"content\">\n"
266 strcpy(buf, bstr("user"));
268 if (strlen(bstr("axlevel")) > 0) {
269 serv_printf("VALI %s|%s", buf, bstr("axlevel"));
272 wprintf("<b>%s</b><br />\n", &buf[4]);
279 wprintf("<b>%s</b><br />\n", &buf[4]);
284 wprintf("<div id=\"fix_scrollbar_bug\">"
285 "<table border=0 width=100%% bgcolor=\"#ffffff\"><tr><td>\n");
288 strcpy(user, &buf[4]);
289 serv_printf("GREG %s", user);
297 wprintf("User #%s<br /><H1>%s</H1>",
300 wprintf("PW: %s<br />\n", buf);
302 wprintf("%s<br />\n", buf);
304 wprintf("%s<br />\n", buf);
306 wprintf("%s, ", buf);
310 wprintf("%s<br />\n", buf);
312 wprintf("%s<br />\n", buf);
314 wprintf("Current access level: %d (%s)\n",
315 atoi(buf), axdefs[atoi(buf)]);
316 } while (strcmp(buf, "000"));
318 wprintf("<H1>%s</H1>%s<br />\n", user, &cmd[4]);
321 wprintf("<hr />Select access level for this user:<br />\n");
322 for (a = 0; a <= 6; ++a) {
323 wprintf("<A HREF=\"/validate&user=");
325 wprintf("&axlevel=%d\">%s</A> \n",
330 wprintf("</CENTER>\n");
331 wprintf("</td></tr></table></div>\n");
338 * Display form for registration.
339 * (Set during_login to 1 if this registration is being performed during
340 * new user login and will require chaining to the proper screen.)
342 void display_reg(int during_login)
346 if (goto_config_room() != 0) {
347 if (during_login) do_welcome();
348 else display_main_menu();
352 vcard_msgnum = locate_user_vcard(WC->wc_username, -1);
353 if (vcard_msgnum < 0L) {
354 if (during_login) do_welcome();
355 else display_main_menu();
360 do_edit_vcard(vcard_msgnum, "1", "/do_welcome");
363 do_edit_vcard(vcard_msgnum, "1", "/display_main_menu");
372 * display form for changing your password
374 void display_changepw(void)
378 output_headers(1, 1, 2, 0, 0, 0, 0);
379 wprintf("<div id=\"banner\">\n"
380 "<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#444455\"><TR><TD>"
381 "<SPAN CLASS=\"titlebar\">Change your password</SPAN>"
382 "</TD></TR></TABLE>\n"
383 "</div>\n<div id=\"content\">\n"
386 if (strlen(WC->ImportantMessage) > 0) {
387 do_template("beginbox_nt");
388 wprintf("<SPAN CLASS=\"errormsg\">"
389 "%s</SPAN><br />\n", WC->ImportantMessage);
390 do_template("endbox");
391 strcpy(WC->ImportantMessage, "");
394 wprintf("<div id=\"fix_scrollbar_bug\">"
395 "<table border=0 width=100%% bgcolor=\"#ffffff\"><tr><td>\n");
397 wprintf("<CENTER><br />");
398 serv_puts("MESG changepw");
401 fmout(NULL, "CENTER");
404 wprintf("<form name=\"changepwform\" action=\"changepw\" method=\"post\">\n");
406 "<table border=\"0\" cellspacing=\"5\" cellpadding=\"5\" "
407 "BGCOLOR=\"#EEEEEE\">"
408 "<TR><TD>Enter new password:</TD>\n");
409 wprintf("<TD><INPUT TYPE=\"password\" NAME=\"newpass1\" VALUE=\"\" MAXLENGTH=\"20\"></TD></TR>\n");
410 wprintf("<TR><TD>Enter it again to confirm:</TD>\n");
411 wprintf("<TD><INPUT TYPE=\"password\" NAME=\"newpass2\" VALUE=\"\" MAXLENGTH=\"20\"></TD></TR>\n");
413 wprintf("</TABLE><br />\n");
414 wprintf("<INPUT type=\"submit\" name=\"action\" value=\"Change\">"
416 "<INPUT type=\"submit\" name=\"action\" value=\"Cancel\">\n");
417 wprintf("</form></center>\n");
418 wprintf("</td></tr></table></div>\n");
428 char newpass1[32], newpass2[32];
430 if (strcmp(bstr("action"), "Change")) {
431 strcpy(WC->ImportantMessage,
432 "Cancelled. Password was not changed.");
437 strcpy(newpass1, bstr("newpass1"));
438 strcpy(newpass2, bstr("newpass2"));
440 if (strcasecmp(newpass1, newpass2)) {
441 strcpy(WC->ImportantMessage,
442 "They don't match. Password was not changed.");
447 if (strlen(newpass1) == 0) {
448 strcpy(WC->ImportantMessage,
449 "Blank passwords are not allowed.");
454 serv_printf("SETP %s", newpass1);
456 sprintf(WC->ImportantMessage, "%s", &buf[4]);
458 safestrncpy(WC->wc_password, buf, sizeof WC->wc_password);