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");
51 if (mesg != NULL) if (strlen(mesg) > 0) {
52 stresc(buf, mesg, 0, 0);
53 svprintf("mesg", WCS_STRING, "%s", buf);
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(WC->wc_username, &serv_response[4], 0);
81 strcpy(WC->wc_password, pass);
82 WC->axlevel = extract_int(&serv_response[4], 1);
83 if (WC->axlevel >= 6) {
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(WC->cs_inet_email, &buf[4], 3);
104 if (!strcasecmp(bstr("action"), "Exit")) {
108 if (!strcasecmp(bstr("action"), "Login")) {
109 serv_printf("USER %s", bstr("name"));
112 serv_printf("PASS %s", bstr("pass"));
115 become_logged_in(bstr("name"),
118 display_login(&buf[4]);
122 display_login(&buf[4]);
126 if (!strcasecmp(bstr("action"), "New User")) {
127 serv_printf("NEWU %s", bstr("name"));
130 become_logged_in(bstr("name"), bstr("pass"), buf);
131 serv_printf("SETP %s", bstr("pass"));
134 display_login(&buf[4]);
145 display_login("Your password was not accepted.");
150 void do_welcome(void)
154 get_preference("startpage", startpage);
155 if (strlen(startpage)==0) {
156 strcpy(startpage, "/dotskip&room=_BASEROOM_");
157 set_preference("startpage", startpage);
160 http_redirect(startpage);
165 * Disconnect from the Citadel server, and end this WebCit session
167 void end_webcit_session(void) {
170 /* close() of citadel socket will be done by do_housekeeping() */
178 strcpy(WC->wc_username, "");
179 strcpy(WC->wc_password, "");
180 strcpy(WC->wc_roomname, "");
182 /* Calling output_headers() this way causes the cookies to be un-set */
183 output_headers(1, 1, 0, 1, 0, 0, 0);
186 serv_puts("MESG goodbye");
189 if (WC->serv_sock >= 0) {
191 fmout(NULL, "CENTER");
193 wprintf("Goodbye\n");
197 wprintf("This program was unable to connect or stay "
198 "connected to the Citadel server. Please report "
199 "this problem to your system administrator."
203 wprintf("<hr /><a href=\"/\">Log in again</A> "
204 "<a href=\"javascript:window.close();\">Close window</A>"
207 end_webcit_session();
221 output_headers(1, 1, 0, 0, 0, 0, 0);
223 strcpy(buf, bstr("user"));
225 if (strlen(bstr("axlevel")) > 0) {
226 serv_printf("VALI %s|%s", buf, bstr("axlevel"));
229 wprintf("<b>%s</b><br />\n", &buf[4]);
236 wprintf("<b>%s</b><br />\n", &buf[4]);
242 do_template("beginbox_nt");
245 strcpy(user, &buf[4]);
246 serv_printf("GREG %s", user);
254 wprintf("User #%s<br /><H1>%s</H1>",
257 wprintf("PW: %s<br />\n", buf);
259 wprintf("%s<br />\n", buf);
261 wprintf("%s<br />\n", buf);
263 wprintf("%s, ", buf);
267 wprintf("%s<br />\n", buf);
269 wprintf("%s<br />\n", buf);
271 wprintf("Current access level: %d (%s)\n",
272 atoi(buf), axdefs[atoi(buf)]);
273 } while (strcmp(buf, "000"));
275 wprintf("<H1>%s</H1>%s<br />\n", user, &cmd[4]);
278 wprintf("<hr />Select access level for this user:<br />\n");
279 for (a = 0; a <= 6; ++a) {
280 wprintf("<A HREF=\"/validate&user=");
282 wprintf("&axlevel=%d\">%s</A> \n",
287 wprintf("</CENTER>\n");
288 do_template("endbox");
289 wprintf("</CENTER>\n");
296 * Display form for registration.
297 * (Set during_login to 1 if this registration is being performed during
298 * new user login and will require chaining to the proper screen.)
300 void display_reg(int during_login)
304 if (goto_config_room() != 0) {
305 if (during_login) do_welcome();
306 else display_main_menu();
310 vcard_msgnum = locate_user_vcard(WC->wc_username, -1);
311 if (vcard_msgnum < 0L) {
312 if (during_login) do_welcome();
313 else display_main_menu();
318 do_edit_vcard(vcard_msgnum, "1", "/do_welcome");
321 do_edit_vcard(vcard_msgnum, "1", "/display_main_menu");
330 * display form for changing your password
332 void display_changepw(void)
336 output_headers(1, 1, 0, 0, 0, 0, 0);
338 svprintf("BOXTITLE", WCS_STRING, "Change your password");
339 do_template("beginbox");
340 wprintf("<CENTER><br />");
341 serv_puts("MESG changepw");
344 fmout(NULL, "CENTER");
347 wprintf("<FORM ACTION=\"changepw\" METHOD=\"POST\">\n");
349 "<table border=\"0\" cellspacing=\"5\" cellpadding=\"5\" "
350 "BGCOLOR=\"#EEEEEE\">"
351 "<TR><TD>Enter new password:</TD>\n");
352 wprintf("<TD><INPUT TYPE=\"password\" NAME=\"newpass1\" VALUE=\"\" MAXLENGTH=\"20\"></TD></TR>\n");
353 wprintf("<TR><TD>Enter it again to confirm:</TD>\n");
354 wprintf("<TD><INPUT TYPE=\"password\" NAME=\"newpass2\" VALUE=\"\" MAXLENGTH=\"20\"></TD></TR>\n");
355 wprintf("</TABLE><br />\n");
356 wprintf("<INPUT type=\"submit\" NAME=\"action\" VALUE=\"Change\">\n"
358 "<INPUT type=\"submit\" NAME=\"action\" VALUE=\"Cancel\">\n");
359 wprintf("</CENTER>\n");
360 do_template("endbox");
370 char newpass1[32], newpass2[32];
372 if (strcmp(bstr("action"), "Change")) {
373 strcpy(WC->ImportantMessage,
374 "Cancelled. Password was not changed.");
378 strcpy(newpass1, bstr("newpass1"));
379 strcpy(newpass2, bstr("newpass2"));
381 if (strcasecmp(newpass1, newpass2)) {
382 strcpy(WC->ImportantMessage,
383 "They don't match. Password was not changed.");
387 serv_printf("SETP %s", newpass1);
389 strcpy(WC->ImportantMessage, &buf[4]);