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)
49 output_headers(1, 1, 2, 0, 0, 0, 0);
50 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 serv_printf("NEWU %s", bstr("name"));
131 become_logged_in(bstr("name"), bstr("pass"), buf);
132 serv_printf("SETP %s", bstr("pass"));
135 display_login(&buf[4]);
146 display_login("Your password was not accepted.");
151 void do_welcome(void)
155 get_preference("startpage", startpage);
156 if (strlen(startpage)==0) {
157 strcpy(startpage, "/dotskip&room=_BASEROOM_");
158 set_preference("startpage", startpage);
161 svprintf("STARTPAGE", WCS_STRING, startpage);
163 /* FIXME ... go to my start page, not to the summary */
169 * Disconnect from the Citadel server, and end this WebCit session
171 void end_webcit_session(void) {
174 /* close() of citadel socket will be done by do_housekeeping() */
182 strcpy(WC->wc_username, "");
183 strcpy(WC->wc_password, "");
184 strcpy(WC->wc_roomname, "");
186 /* Calling output_headers() this way causes the cookies to be un-set */
187 output_headers(1, 1, 0, 1, 0, 0, 0);
190 serv_puts("MESG goodbye");
193 if (WC->serv_sock >= 0) {
195 fmout(NULL, "CENTER");
197 wprintf("Goodbye\n");
201 wprintf("This program was unable to connect or stay "
202 "connected to the Citadel server. Please report "
203 "this problem to your system administrator."
207 wprintf("<hr /><a href=\"/\">Log in again</A> "
208 "<a href=\"javascript:window.close();\">Close window</A>"
211 end_webcit_session();
225 output_headers(1, 1, 0, 0, 0, 0, 0);
227 strcpy(buf, bstr("user"));
229 if (strlen(bstr("axlevel")) > 0) {
230 serv_printf("VALI %s|%s", buf, bstr("axlevel"));
233 wprintf("<b>%s</b><br />\n", &buf[4]);
240 wprintf("<b>%s</b><br />\n", &buf[4]);
246 do_template("beginbox_nt");
249 strcpy(user, &buf[4]);
250 serv_printf("GREG %s", user);
258 wprintf("User #%s<br /><H1>%s</H1>",
261 wprintf("PW: %s<br />\n", buf);
263 wprintf("%s<br />\n", buf);
265 wprintf("%s<br />\n", buf);
267 wprintf("%s, ", buf);
271 wprintf("%s<br />\n", buf);
273 wprintf("%s<br />\n", buf);
275 wprintf("Current access level: %d (%s)\n",
276 atoi(buf), axdefs[atoi(buf)]);
277 } while (strcmp(buf, "000"));
279 wprintf("<H1>%s</H1>%s<br />\n", user, &cmd[4]);
282 wprintf("<hr />Select access level for this user:<br />\n");
283 for (a = 0; a <= 6; ++a) {
284 wprintf("<A HREF=\"/validate&user=");
286 wprintf("&axlevel=%d\">%s</A> \n",
291 wprintf("</CENTER>\n");
292 do_template("endbox");
293 wprintf("</CENTER>\n");
300 * Display form for registration.
301 * (Set during_login to 1 if this registration is being performed during
302 * new user login and will require chaining to the proper screen.)
304 void display_reg(int during_login)
308 if (goto_config_room() != 0) {
309 if (during_login) do_welcome();
310 else display_main_menu();
314 vcard_msgnum = locate_user_vcard(WC->wc_username, -1);
315 if (vcard_msgnum < 0L) {
316 if (during_login) do_welcome();
317 else display_main_menu();
322 do_edit_vcard(vcard_msgnum, "1", "/do_welcome");
325 do_edit_vcard(vcard_msgnum, "1", "/display_main_menu");
334 * display form for changing your password
336 void display_changepw(void)
340 output_headers(1, 1, 0, 0, 0, 0, 0);
342 svprintf("BOXTITLE", WCS_STRING, "Change your password");
343 do_template("beginbox");
344 wprintf("<CENTER><br />");
345 serv_puts("MESG changepw");
348 fmout(NULL, "CENTER");
351 wprintf("<FORM ACTION=\"changepw\" METHOD=\"POST\">\n");
353 "<table border=\"0\" cellspacing=\"5\" cellpadding=\"5\" "
354 "BGCOLOR=\"#EEEEEE\">"
355 "<TR><TD>Enter new password:</TD>\n");
356 wprintf("<TD><INPUT TYPE=\"password\" NAME=\"newpass1\" VALUE=\"\" MAXLENGTH=\"20\"></TD></TR>\n");
357 wprintf("<TR><TD>Enter it again to confirm:</TD>\n");
358 wprintf("<TD><INPUT TYPE=\"password\" NAME=\"newpass2\" VALUE=\"\" MAXLENGTH=\"20\"></TD></TR>\n");
359 wprintf("</TABLE><br />\n");
360 wprintf("<INPUT type=\"submit\" NAME=\"action\" VALUE=\"Change\">\n"
362 "<INPUT type=\"submit\" NAME=\"action\" VALUE=\"Cancel\">\n");
363 wprintf("</CENTER>\n");
364 do_template("endbox");
374 char newpass1[32], newpass2[32];
376 if (strcmp(bstr("action"), "Change")) {
377 strcpy(WC->ImportantMessage,
378 "Cancelled. Password was not changed.");
382 strcpy(newpass1, bstr("newpass1"));
383 strcpy(newpass2, bstr("newpass2"));
385 if (strcasecmp(newpass1, newpass2)) {
386 strcpy(WC->ImportantMessage,
387 "They don't match. Password was not changed.");
391 serv_printf("SETP %s", newpass1);
393 strcpy(WC->ImportantMessage, &buf[4]);