4 * This file contains code which relates to authentication of users to Citadel.
16 #include <sys/types.h>
18 #include <sys/socket.h>
21 #include <netinet/in.h>
43 * Display the login screen
45 void display_login(char *mesg)
51 if (mesg != NULL) if (strlen(mesg) > 0) {
53 svprintf("mesg", WCS_STRING, "%s", buf);
56 svprintf("hello", WCS_SERVCMD, "MESG hello");
61 wDumpContent(0); /* No menu here; not logged in yet! */
68 * This function needs to get called whenever the session changes from
69 * not-logged-in to logged-in, either by an explicit login by the user or
70 * by a timed-out session automatically re-establishing with a little help
71 * from the browser cookie. Either way, we need to load access controls and
72 * preferences from the server.
74 void become_logged_in(char *user, char *pass, char *serv_response)
79 extract(WC->wc_username, &serv_response[4], 0);
80 strcpy(WC->wc_password, pass);
81 WC->axlevel = extract_int(&serv_response[4], 1);
82 if (WC->axlevel >= 6) {
91 WC->new_mail = extract_int(&buf[4], 0);
92 WC->need_regi = extract_int(&buf[4], 1);
93 WC->need_vali = extract_int(&buf[4], 2);
94 extract(WC->cs_inet_email, &buf[4], 3);
103 if (!strcasecmp(bstr("action"), "Exit")) {
107 if (!strcasecmp(bstr("action"), "Login")) {
108 serv_printf("USER %s", bstr("name"));
111 serv_printf("PASS %s", bstr("pass"));
114 become_logged_in(bstr("name"),
117 display_login(&buf[4]);
121 display_login(&buf[4]);
125 if (!strcasecmp(bstr("action"), "New User")) {
126 serv_printf("NEWU %s", bstr("name"));
129 become_logged_in(bstr("name"), bstr("pass"), buf);
130 serv_printf("SETP %s", bstr("pass"));
133 display_login(&buf[4]);
144 display_login("Your password was not accepted.");
149 void do_welcome(void)
153 get_preference("startpage", startpage);
154 if (strlen(startpage)==0) {
155 strcpy(startpage, "/dotskip&room=_BASEROOM_");
156 set_preference("startpage", startpage);
159 svprintf("STARTPAGE", WCS_STRING, startpage);
161 do_template("mainframeset");
162 clear_local_substs();
167 * Disconnect from the Citadel server, and end this WebCit session
169 void end_webcit_session(void) {
172 /* close() of citadel socket will be done by do_housekeeping() */
180 strcpy(WC->wc_username, "");
181 strcpy(WC->wc_password, "");
182 strcpy(WC->wc_roomname, "");
184 output_headers(2); /* note "2" causes cookies to be unset */
187 serv_puts("MESG goodbye");
190 if (WC->serv_sock >= 0) {
194 wprintf("Goodbye\n");
198 wprintf("This program was unable to connect or stay "
199 "connected to the Citadel server. Please report "
200 "this problem to your system administrator."
204 wprintf("<HR><A HREF=\"/\">Log in again</A> "
205 "<A HREF=\"javascript:window.close();\">Close window</A>"
208 end_webcit_session();
225 strcpy(buf, bstr("user"));
227 if (strlen(bstr("WC->axlevel")) > 0) {
228 serv_printf("VALI %s|%s", buf, bstr("WC->axlevel"));
231 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
238 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
242 strcpy(user, &buf[4]);
243 serv_printf("GREG %s", user);
251 wprintf("User #%s<BR><H1>%s</H1>",
254 wprintf("PW: %s<BR>\n", buf);
256 wprintf("%s<BR>\n", buf);
258 wprintf("%s<BR>\n", buf);
260 wprintf("%s, ", buf);
264 wprintf("%s<BR>\n", buf);
266 wprintf("%s<BR>\n", buf);
268 wprintf("Current access level: %d (%s)\n",
269 atoi(buf), axdefs[atoi(buf)]);
270 } while (strcmp(buf, "000"));
272 wprintf("<H1>%s</H1>%s<BR>\n", user, &cmd[4]);
275 wprintf("<CENTER><TABLE border><CAPTION>Select access level:");
276 wprintf("</CAPTION><TR>");
277 for (a = 0; a <= 6; ++a) {
278 wprintf("<TD><A HREF=\"/validate&user=");
280 wprintf("&WC->axlevel=%d\">%s</A></TD>\n",
283 wprintf("</TR></TABLE><CENTER><BR>\n");
290 * Display form for registration.
291 * (Set during_login to 1 if this registration is being performed during
292 * new user login and will require chaining to the proper screen.)
294 void display_reg(int during_login)
298 if (goto_config_room() != 0) {
299 if (during_login) do_welcome();
300 else display_main_menu();
304 vcard_msgnum = locate_user_vcard(WC->wc_username, -1);
305 if (vcard_msgnum < 0L) {
306 if (during_login) do_welcome();
307 else display_main_menu();
312 do_edit_vcard(vcard_msgnum, "1", "/do_welcome");
315 do_edit_vcard(vcard_msgnum, "1", "/display_main_menu");
324 * display form for changing your password
326 void display_changepw(void)
332 wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#770000\"><TR><TD>");
333 wprintf("<SPAN CLASS=\"titlebar\">Change your password</SPAN>\n");
334 wprintf("</TD></TR></TABLE>\n");
337 serv_puts("MESG changepw");
342 wprintf("<FORM ACTION=\"changepw\" METHOD=\"POST\">\n");
343 wprintf("<CENTER><TABLE border><TR><TD>Enter new password:</TD>\n");
344 wprintf("<TD><INPUT TYPE=\"password\" NAME=\"newpass1\" VALUE=\"\" MAXLENGTH=\"20\"></TD></TR>\n");
345 wprintf("<TR><TD>Enter it again to confirm:</TD>\n");
346 wprintf("<TD><INPUT TYPE=\"password\" NAME=\"newpass2\" VALUE=\"\" MAXLENGTH=\"20\"></TD></TR>\n");
347 wprintf("</TABLE>\n");
348 wprintf("<INPUT type=\"submit\" NAME=\"action\" VALUE=\"Change\">\n");
349 wprintf("<INPUT type=\"submit\" NAME=\"action\" VALUE=\"Cancel\">\n");
350 wprintf("</CENTER>\n");
360 char newpass1[32], newpass2[32];
362 if (strcmp(bstr("action"), "Change")) {
363 display_error("Cancelled. Password was not changed.");
366 strcpy(newpass1, bstr("newpass1"));
367 strcpy(newpass2, bstr("newpass2"));
369 if (strcasecmp(newpass1, newpass2)) {
370 display_error("They don't match. Password was not changed.");
373 serv_printf("SETP %s", newpass1);
376 display_success(&buf[4]);
378 display_error(&buf[4]);