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");
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)
159 get_preference("startpage", startpage);
160 if (strlen(startpage)==0) {
161 strcpy(startpage, "/dotskip&room=_BASEROOM_");
162 set_preference("startpage", startpage);
165 http_redirect(startpage);
170 * Disconnect from the Citadel server, and end this WebCit session
172 void end_webcit_session(void) {
175 /* close() of citadel socket will be done by do_housekeeping() */
183 strcpy(WC->wc_username, "");
184 strcpy(WC->wc_password, "");
185 strcpy(WC->wc_roomname, "");
187 /* Calling output_headers() this way causes the cookies to be un-set */
188 output_headers(1, 1, 0, 1, 0, 0, 0);
191 serv_puts("MESG goodbye");
194 if (WC->serv_sock >= 0) {
196 fmout(NULL, "CENTER");
198 wprintf("Goodbye\n");
202 wprintf("This program was unable to connect or stay "
203 "connected to the Citadel server. Please report "
204 "this problem to your system administrator."
208 wprintf("<hr /><a href=\"/\">Log in again</A> "
209 "<a href=\"javascript:window.close();\">Close window</A>"
212 end_webcit_session();
226 output_headers(1, 1, 2, 0, 0, 0, 0);
227 wprintf("<div id=\"banner\">\n"
228 "<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#444455\"><TR><TD>"
229 "<SPAN CLASS=\"titlebar\">Validate new users</SPAN>"
230 "</TD></TR></TABLE>\n"
231 "</div>\n<div id=\"content\">\n"
234 strcpy(buf, bstr("user"));
236 if (strlen(bstr("axlevel")) > 0) {
237 serv_printf("VALI %s|%s", buf, bstr("axlevel"));
240 wprintf("<b>%s</b><br />\n", &buf[4]);
247 wprintf("<b>%s</b><br />\n", &buf[4]);
252 wprintf("<center><table border=0 width=99%% bgcolor=\"#ffffff\"><tr><td>\n");
255 strcpy(user, &buf[4]);
256 serv_printf("GREG %s", user);
264 wprintf("User #%s<br /><H1>%s</H1>",
267 wprintf("PW: %s<br />\n", buf);
269 wprintf("%s<br />\n", buf);
271 wprintf("%s<br />\n", buf);
273 wprintf("%s, ", buf);
277 wprintf("%s<br />\n", buf);
279 wprintf("%s<br />\n", buf);
281 wprintf("Current access level: %d (%s)\n",
282 atoi(buf), axdefs[atoi(buf)]);
283 } while (strcmp(buf, "000"));
285 wprintf("<H1>%s</H1>%s<br />\n", user, &cmd[4]);
288 wprintf("<hr />Select access level for this user:<br />\n");
289 for (a = 0; a <= 6; ++a) {
290 wprintf("<A HREF=\"/validate&user=");
292 wprintf("&axlevel=%d\">%s</A> \n",
297 wprintf("</CENTER>\n");
298 wprintf("</td></tr></table></center>\n");
305 * Display form for registration.
306 * (Set during_login to 1 if this registration is being performed during
307 * new user login and will require chaining to the proper screen.)
309 void display_reg(int during_login)
313 if (goto_config_room() != 0) {
314 if (during_login) do_welcome();
315 else display_main_menu();
319 vcard_msgnum = locate_user_vcard(WC->wc_username, -1);
320 if (vcard_msgnum < 0L) {
321 if (during_login) do_welcome();
322 else display_main_menu();
327 do_edit_vcard(vcard_msgnum, "1", "/do_welcome");
330 do_edit_vcard(vcard_msgnum, "1", "/display_main_menu");
339 * display form for changing your password
341 void display_changepw(void)
345 output_headers(1, 1, 2, 0, 0, 0, 0);
346 wprintf("<div id=\"banner\">\n"
347 "<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#444455\"><TR><TD>"
348 "<SPAN CLASS=\"titlebar\">Change your password</SPAN>"
349 "</TD></TR></TABLE>\n"
350 "</div>\n<div id=\"content\">\n"
353 if (strlen(WC->ImportantMessage) > 0) {
354 do_template("beginbox_nt");
355 wprintf("<SPAN CLASS=\"errormsg\">"
356 "%s</SPAN><br />\n", WC->ImportantMessage);
357 do_template("endbox");
358 strcpy(WC->ImportantMessage, "");
361 wprintf("<center><table border=0 width=99%% bgcolor=\"#ffffff\"><tr><td>\n");
363 wprintf("<CENTER><br />");
364 serv_puts("MESG changepw");
367 fmout(NULL, "CENTER");
370 wprintf("<form name=\"changepwform\" action=\"changepw\" method=\"post\">\n");
372 "<table border=\"0\" cellspacing=\"5\" cellpadding=\"5\" "
373 "BGCOLOR=\"#EEEEEE\">"
374 "<TR><TD>Enter new password:</TD>\n");
375 wprintf("<TD><INPUT TYPE=\"password\" NAME=\"newpass1\" VALUE=\"\" MAXLENGTH=\"20\"></TD></TR>\n");
376 wprintf("<TR><TD>Enter it again to confirm:</TD>\n");
377 wprintf("<TD><INPUT TYPE=\"password\" NAME=\"newpass2\" VALUE=\"\" MAXLENGTH=\"20\"></TD></TR>\n");
379 wprintf("</TABLE><br />\n");
380 wprintf("<INPUT type=\"submit\" name=\"action\" value=\"Change\">"
382 "<INPUT type=\"submit\" name=\"action\" value=\"Cancel\">\n");
383 wprintf("</form></center>\n");
384 wprintf("</td></tr></table></center>\n");
394 char newpass1[32], newpass2[32];
396 if (strcmp(bstr("action"), "Change")) {
397 strcpy(WC->ImportantMessage,
398 "Cancelled. Password was not changed.");
403 strcpy(newpass1, bstr("newpass1"));
404 strcpy(newpass2, bstr("newpass2"));
406 if (strcasecmp(newpass1, newpass2)) {
407 strcpy(WC->ImportantMessage,
408 "They don't match. Password was not changed.");
413 if (strlen(newpass1) == 0) {
414 strcpy(WC->ImportantMessage,
415 "Blank passwords are not allowed.");
420 serv_printf("SETP %s", newpass1);
422 sprintf(WC->ImportantMessage, "%s", &buf[4]);