4 * WebcitAuth; Handles authentication of users to a Citadel server.
12 void display_reg(int during_login);
15 * Access level definitions. This is initialized from a function rather than a
16 * static array so that the strings may be localized.
20 void initialize_axdefs(void) {
21 axdefs[0] = _("Deleted"); /* an erased user */
22 axdefs[1] = _("New User"); /* a new user */
23 axdefs[2] = _("Problem User"); /* a trouble maker */
24 axdefs[3] = _("Local User"); /* user with normal privileges */
25 axdefs[4] = _("Network User"); /* a user that may access network resources */
26 axdefs[5] = _("Preferred User");/* a moderator */
27 axdefs[6] = _("Aide"); /* chief */
34 * Display the login screen
35 * mesg = the error message if last attempt failed.
37 void display_login(char *mesg)
41 output_headers(1, 1, 2, 0, 0, 0);
42 wprintf("<div id=\"login_screen\">\n");
44 if ((mesg != NULL) && (!IsEmptyStr(mesg))) {
45 stresc(buf, SIZ, mesg, 0, 0);
46 svprintf(HKEY("MESG"), WCS_STRING, "%s", buf);
49 svprintf(HKEY("LOGIN_INSTRUCTIONS"), WCS_STRING,
51 "<li><b>If you already have an account on %s</b>, "
52 "enter your user name and password and click "Login." "
53 "<li><b>If you are a new user</b>, enter the name and password "
55 "and click "New User." "
56 "<li>Please log off properly when finished. "
57 "<li>You must use a browser that supports <i>frames</i> and "
59 "<li>Also keep in mind that if your browser is "
60 "configured to block pop-up windows, you will not be able "
61 "to receive any instant messages.<br />"
63 serv_info.serv_humannode
66 svput("USERNAME_BOX", WCS_STRING, _("User name:"));
67 svput("PASSWORD_BOX", WCS_STRING, _("Password:"));
68 svput("LANGUAGE_BOX", WCS_STRING, _("Language:"));
69 svput("LOGIN_BUTTON", WCS_STRING, _("Login"));
70 svput("NEWUSER_BUTTON", WCS_STRING, _("New User"));
71 svput("EXIT_BUTTON", WCS_STRING, _("Exit"));
72 svput("HELLO", WCS_SERVCMD, "MESG hello");
73 svprintf(HKEY("BOXTITLE"), WCS_STRING, _("%s - powered by <a href=\"http://www.citadel.org\">Citadel</a>"),
74 serv_info.serv_humannode);
75 svcallback("DO_LANGUAGE_BOX", offer_languages);
76 if (serv_info.serv_newuser_disabled) {
77 svput("NEWUSER_BUTTON_PRE", WCS_STRING, "<div style=\"display:none;\">");
78 svput("NEWUSER_BUTTON_POST", WCS_STRING, "</div>");
81 svput("NEWUSER_BUTTON_PRE", WCS_STRING, "");
82 svput("NEWUSER_BUTTON_POST", WCS_STRING, "");
85 if (serv_info.serv_supports_openid) {
86 svprintf(HKEY("OFFER_OPENID_LOGIN"), WCS_STRING,
88 "<a href=\"display_openid_login\">"
89 "<img src=\"static/openid-small.gif\" border=0 valign=middle>"
97 svput("OFFER_OPENID_LOGIN", WCS_STRING, "");
100 do_template("login", NULL);
109 * Display the openid-enabled login screen
110 * mesg = the error message if last attempt failed.
112 void display_openid_login(char *mesg)
116 output_headers(1, 1, 2, 0, 0, 0);
117 wprintf("<div id=\"login_screen\">\n");
119 if ((mesg != NULL) && (!IsEmptyStr(mesg))) {
120 stresc(buf, SIZ, mesg, 0, 0);
121 svprintf(HKEY("MESG"), WCS_STRING, "%s", buf);
124 svprintf(HKEY("LOGIN_INSTRUCTIONS"), WCS_STRING,
126 "<li>Enter your OpenID URL and click "Login"."
127 "<li><a href=\"http://www.citadel.org/doku.php/documentation:openid\">"
128 "Click here to learn what OpenID is and how Citadel is using it.</a>"
129 "<li>Please log off properly when finished. "
130 "<li>You must use a browser that supports <i>frames</i> and "
132 "<li>Also keep in mind that if your browser is "
133 "configured to block pop-up windows, you will not be able "
134 "to receive any instant messages.<br />"
138 svput("OPENID_BOX", WCS_STRING, _("OpenID URL:"));
139 svput("LANGUAGE_BOX", WCS_STRING, _("Language:"));
140 svput("LOGIN_BUTTON", WCS_STRING, _("Login"));
141 svput("EXIT_BUTTON", WCS_STRING, _("Exit"));
142 svput("HELLO", WCS_SERVCMD, "MESG hello");
143 svprintf(HKEY("BOXTITLE"), WCS_STRING, _("%s - powered by <a href=\"http://www.citadel.org\">Citadel</a>"),
144 serv_info.serv_humannode);
145 svcallback("DO_LANGUAGE_BOX", offer_languages);
147 svprintf(HKEY("OFFER_CONVENTIONAL_LOGIN"), WCS_STRING,
149 "<a href=\"display_login\">"
153 "Log in using a user name and password"
156 do_template("openid_login", NULL);
161 void display_openid_name_request(char *claimed_id, char *username) {
164 output_headers(1, 1, 2, 0, 0, 0);
165 wprintf("<div id=\"login_screen\">\n");
167 stresc(buf, sizeof buf, claimed_id, 0, 0);
168 svprintf(HKEY("VERIFIED"), WCS_STRING, _("Your OpenID <tt>%s</tt> was successfully verified."),
170 svput("CLAIMED_ID", WCS_STRING, claimed_id);
173 if (!IsEmptyStr(username)) {
174 stresc(buf, sizeof buf, username, 0, 0);
175 svprintf(HKEY("REASON"), WCS_STRING,
176 _("However, the user name '%s' conflicts with an existing user."), username);
179 svput("REASON", WCS_STRING, "");
182 svput("ACTION_REQUESTED", WCS_STRING, _("Please specify the user name you would like to use."));
184 svput("USERNAME_BOX", WCS_STRING, _("User name:"));
185 svput("NEWUSER_BUTTON", WCS_STRING, _("New User"));
186 svput("EXIT_BUTTON", WCS_STRING, _("Exit"));
188 svprintf(HKEY("BOXTITLE"), WCS_STRING, _("%s - powered by <a href=\"http://www.citadel.org\">Citadel</a>"),
189 serv_info.serv_humannode);
191 do_template("openid_manual_create", NULL);
197 /* Initialize the session
199 * This function needs to get called whenever the session changes from
200 * not-logged-in to logged-in, either by an explicit login by the user or
201 * by a timed-out session automatically re-establishing with a little help
202 * from the browser cookie. Either way, we need to load access controls and
203 * preferences from the server.
207 * serv_response The parameters returned from a Citadel USER or NEWU command
209 void become_logged_in(char *user, char *pass, char *serv_response)
215 extract_token(WC->wc_fullname, &serv_response[4], 0, '|', sizeof WC->wc_fullname);
216 safestrncpy(WC->wc_username, user, sizeof WC->wc_username);
217 safestrncpy(WC->wc_password, pass, sizeof WC->wc_password);
218 WC->axlevel = extract_int(&serv_response[4], 1);
219 if (WC->axlevel >= 6) {
226 serv_getln(buf, sizeof buf);
228 WC->new_mail = extract_int(&buf[4], 0);
229 WC->need_regi = extract_int(&buf[4], 1);
230 WC->need_vali = extract_int(&buf[4], 2);
231 extract_token(WC->cs_inet_email, &buf[4], 3, '|', sizeof WC->cs_inet_email);
234 get_pref_long("current_iconbar", &WC->current_iconbar, current_iconbar_menu);
236 get_preference("floordiv_expanded", &FloorDiv);
237 WC->floordiv_expanded = FloorDiv;
242 * Perform authentication using a user name and password
248 if (havebstr("language")) {
249 set_selected_language(bstr("language"));
250 go_selected_language();
253 if (havebstr("exit_action")) {
257 if (havebstr("login_action")) {
258 serv_printf("USER %s", bstr("name"));
259 serv_getln(buf, sizeof buf);
261 serv_printf("PASS %s", bstr("pass"));
262 serv_getln(buf, sizeof buf);
264 become_logged_in(bstr("name"), bstr("pass"), buf);
266 display_login(&buf[4]);
270 display_login(&buf[4]);
274 if (havebstr("newuser_action")) {
275 if (!havebstr("pass")) {
276 display_login(_("Blank passwords are not allowed."));
279 serv_printf("NEWU %s", bstr("name"));
280 serv_getln(buf, sizeof buf);
282 become_logged_in(bstr("name"), bstr("pass"), buf);
283 serv_printf("SETP %s", bstr("pass"));
284 serv_getln(buf, sizeof buf);
286 display_login(&buf[4]);
291 set_preference("language", NewStrBufPlain(bstr("language"), -1), 1);
294 } else if (WC->need_vali) {
300 display_login(_("Your password was not accepted."));
306 * Try to create an account manually after an OpenID was verified
308 void openid_manual_create(void)
310 if (havebstr("exit_action")) {
316 if (havebstr("newuser_action")) {
317 serv_printf("OIDC %s", bstr("name"));
318 serv_getln(buf, sizeof buf);
320 char gpass[1024] = "";
321 serv_puts("SETP GENERATE_RANDOM_PASSWORD");
322 serv_getln(gpass, sizeof gpass);
323 become_logged_in(bstr("name"), &gpass[4], buf);
330 } else if (WC->need_vali) {
336 display_openid_name_request(bstr("openid_url"), bstr("name"));
343 * Perform authentication using OpenID
344 * assemble the checkid_setup request and then redirect to the user's identity provider
346 void do_openid_login(void)
350 if (havebstr("language")) {
351 set_selected_language(bstr("language"));
352 go_selected_language();
355 if (havebstr("exit_action")) {
359 if (havebstr("login_action")) {
360 snprintf(buf, sizeof buf,
361 "OIDS %s|%s://%s/finalize_openid_login|%s://%s",
363 (is_https ? "https" : "http"), WC->http_host,
364 (is_https ? "https" : "http"), WC->http_host
368 serv_getln(buf, sizeof buf);
370 lprintf(CTDL_DEBUG, "OpenID server contacted; redirecting to %s\n", &buf[4]);
371 http_redirect(&buf[4]);
375 display_openid_login(&buf[4]);
380 /* If we get to this point then something failed. */
381 display_openid_login(_("Your password was not accepted."));
385 * Complete the authentication using OpenID
386 * This function handles the positive or negative assertion from the user's Identity Provider
388 void finalize_openid_login(void)
391 struct wcsession *WCC = WC;
392 int already_logged_in = (WCC->logged_in) ;
394 char result[128] = "";
395 char username[128] = "";
396 char password[128] = "";
397 char logged_in_response[1024] = "";
398 char claimed_id[1024] = "";
400 if (havebstr("openid.mode")) {
401 if (!strcasecmp(bstr("openid.mode"), "id_res")) {
404 serv_getln(buf, sizeof buf);
413 Cursor = GetNewHashPos ();
414 while (GetNextHashPos(WCC->urlstrings, Cursor, &HKLen, &HKey, &U)) {
416 if (!strncasecmp(u->url_key, "openid.", 7)) {
417 serv_printf("%s|%s", &u->url_key[7], ChrPtr(u->url_data));
424 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
425 if (linecount == 0) safestrncpy(result, buf, sizeof result);
426 if (!strcasecmp(result, "authenticate")) {
427 if (linecount == 1) {
428 safestrncpy(username, buf, sizeof username);
430 else if (linecount == 2) {
431 safestrncpy(password, buf, sizeof password);
433 else if (linecount == 3) {
434 safestrncpy(logged_in_response, buf,
435 sizeof logged_in_response);
438 else if (!strcasecmp(result, "verify_only")) {
439 if (linecount == 1) {
440 safestrncpy(claimed_id, buf, sizeof claimed_id);
442 if (linecount == 2) {
443 safestrncpy(username, buf, sizeof username);
452 /* If we were already logged in, this was an attempt to associate an OpenID account */
453 if (already_logged_in) {
458 /* If this operation logged us in, either by connecting with an existing account or by
459 * auto-creating one using Simple Registration Extension, we're already on our way.
461 if (!strcasecmp(result, "authenticate")) {
462 become_logged_in(username, password, logged_in_response);
465 /* The specified OpenID was verified but the desired user name was either not specified via SRI
466 * or conflicts with an existing user. Either way the user will need to specify a new name.
469 else if (!strcasecmp(result, "verify_only")) {
470 display_openid_name_request(claimed_id, username);
473 /* Did we manage to log in? If so, continue with the normal flow... */
481 display_openid_login(_("Your password was not accepted."));
488 * Display a welcome screen to the user.
490 * If this is the first time login, and the web based setup is enabled,
491 * lead the user through the setup routines
493 void do_welcome(void)
496 #ifdef XXX_NOT_FINISHED_YET_XXX
501 * See if we have to run the first-time setup wizard
506 sprintf(wizard_filename, "setupwiz.%s.%s",
508 len = strlen(wizard_filename);
509 for (i=0; i<len; ++i) {
510 if ( (wizard_filename[i]==' ')
511 || (wizard_filename[i] == '/')
513 wizard_filename[i] = '_';
517 fp = fopen(wizard_filename, "r");
519 fgets(buf, sizeof buf, fp);
520 buf[strlen(buf)-1] = 0;
522 if (atoi(buf) == serv_info.serv_rev_level) {
523 setup_wizard = 1; /**< already run */
529 http_redirect("setup_wizard");
535 * Go to the user's preferred start page
537 if (!get_preference("startpage", &Buf)) {
539 StrBufPrintf(Buf, "dotskip&room=_BASEROOM_");
540 set_preference("startpage", Buf, 1);
542 if (ChrPtr(Buf)[0] == '/') {
543 StrBufCutLeft(Buf, 1);
545 if (StrLength(Buf) == 0)
546 StrBufAppendBufPlain(Buf, "dotgoto?room=_BASEROOM_", -1, 0);
547 http_redirect(ChrPtr(Buf));
552 * Disconnect from the Citadel server, and end this WebCit session
554 void end_webcit_session(void) {
557 set_pref_long("current_iconbar", WC->current_iconbar, 0);
562 /* close() of citadel socket will be done by do_housekeeping() */
572 safestrncpy(WC->wc_username, "", sizeof WC->wc_username);
573 safestrncpy(WC->wc_password, "", sizeof WC->wc_password);
574 safestrncpy(WC->wc_roomname, "", sizeof WC->wc_roomname);
575 safestrncpy(WC->wc_fullname, "", sizeof WC->wc_fullname);
577 /** Calling output_headers() this way causes the cookies to be un-set */
578 output_headers(1, 1, 0, 1, 0, 0);
580 wprintf("<div id=\"logout_screen\">");
581 wprintf("<div class=\"box\">");
582 wprintf("<div class=\"boxlabel\">");
583 wprintf(_("Log off"));
584 wprintf("</div><div class=\"boxcontent\">");
585 serv_puts("MESG goodbye");
586 serv_getln(buf, sizeof buf);
588 if (WC->serv_sock >= 0) {
592 wprintf("Goodbye\n");
596 wprintf(_("This program was unable to connect or stay "
597 "connected to the Citadel server. Please report "
598 "this problem to your system administrator.")
600 wprintf("<a href=\"http://www.citadel.org/doku.php/"
601 "faq:mastering_your_os:net#netstat\">%s</a>",
605 wprintf("<hr /><div class=\"buttons\"> "
606 "<span class=\"button_link\"><a href=\".\">");
607 wprintf(_("Log in again"));
608 wprintf("</a></span> <span class=\"button_link\">"
609 "<a href=\"javascript:window.close();\">");
610 wprintf(_("Close window"));
611 wprintf("</a></span></div></div></div></div>\n");
613 end_webcit_session();
627 output_headers(1, 1, 2, 0, 0, 0);
628 wprintf("<div id=\"banner\">\n");
630 wprintf(_("Validate new users"));
634 wprintf("<div id=\"content\" class=\"service\">\n");
636 /* If the user just submitted a validation, process it... */
637 safestrncpy(buf, bstr("user"), sizeof buf);
638 if (!IsEmptyStr(buf)) {
639 if (havebstr("axlevel")) {
640 serv_printf("VALI %s|%s", buf, bstr("axlevel"));
641 serv_getln(buf, sizeof buf);
643 wprintf("<b>%s</b><br />\n", &buf[4]);
648 /* Now see if any more users require validation. */
650 serv_getln(buf, sizeof buf);
653 wprintf(_("No users require validation at this time."));
654 wprintf("</b><br />\n");
659 wprintf("<b>%s</b><br />\n", &buf[4]);
664 wprintf("<div class=\"fix_scrollbar_bug\">"
665 "<table class=\"auth_validate\"><tr><td>\n");
668 safestrncpy(user, &buf[4], sizeof user);
669 serv_printf("GREG %s", user);
670 serv_getln(cmd, sizeof cmd);
674 serv_getln(buf, sizeof buf);
677 wprintf("#%s<br /><H1>%s</H1>",
686 while (!IsEmptyStr(pch))
690 else if (isalpha(*pch))
701 pch = _("very weak");
714 wprintf("PW: %s<br />\n", pch);
717 wprintf("%s<br />\n", buf);
719 wprintf("%s<br />\n", buf);
721 wprintf("%s, ", buf);
725 wprintf("%s<br />\n", buf);
727 wprintf("%s<br />\n", buf);
729 wprintf(_("Current access level: %d (%s)\n"),
730 atoi(buf), axdefs[atoi(buf)]);
731 } while (strcmp(buf, "000"));
733 wprintf("<H1>%s</H1>%s<br />\n", user, &cmd[4]);
737 wprintf(_("Select access level for this user:"));
739 for (a = 0; a <= 6; ++a) {
740 wprintf("<a href=\"validate?nonce=%d?user=", WC->nonce);
742 wprintf("&axlevel=%d\">%s</A> \n",
747 wprintf("</CENTER>\n");
748 wprintf("</td></tr></table></div>\n");
755 * Display form for registration.
757 * (Set during_login to 1 if this registration is being performed during
758 * new user login and will require chaining to the proper screen.)
760 void display_reg(int during_login)
764 if (goto_config_room() != 0) {
765 if (during_login) do_welcome();
766 else display_main_menu();
770 vcard_msgnum = locate_user_vcard(WC->wc_fullname, -1);
771 if (vcard_msgnum < 0L) {
772 if (during_login) do_welcome();
773 else display_main_menu();
778 do_edit_vcard(vcard_msgnum, "1", "do_welcome", USERCONFIGROOM);
781 do_edit_vcard(vcard_msgnum, "1", "display_main_menu", USERCONFIGROOM);
790 * display form for changing your password
792 void display_changepw(void)
796 output_headers(1, 1, 1, 0, 0, 0);
798 Buf = NewStrBufPlain(_("Change your password"), -1);
799 DoTemplate(HKEY("beginbox"), NULL, Buf, CTX_STRBUF);
803 if (!IsEmptyStr(WC->ImportantMessage)) {
804 wprintf("<span class=\"errormsg\">"
805 "%s</span><br />\n", WC->ImportantMessage);
806 safestrncpy(WC->ImportantMessage, "", sizeof WC->ImportantMessage);
809 serv_puts("MESG changepw");
810 serv_getln(buf, sizeof buf);
815 wprintf("<form name=\"changepwform\" action=\"changepw\" method=\"post\">\n");
816 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
817 wprintf("<table class=\"altern\" ");
818 wprintf("<tr class=\"even\"><td>");
819 wprintf(_("Enter new password:"));
820 wprintf("</td><td>");
821 wprintf("<input type=\"password\" name=\"newpass1\" value=\"\" maxlength=\"20\"></td></tr>\n");
822 wprintf("<tr class=\"odd\"><td>");
823 wprintf(_("Enter it again to confirm:"));
824 wprintf("</td><td>");
825 wprintf("<input type=\"password\" name=\"newpass2\" value=\"\" maxlength=\"20\"></td></tr>\n");
826 wprintf("</table>\n");
828 wprintf("<div class=\"buttons\">\n");
829 wprintf("<input type=\"submit\" name=\"change_action\" value=\"%s\">", _("Change password"));
831 wprintf("<input type=\"submit\" name=\"cancel_action\" value=\"%s\">\n", _("Cancel"));
833 wprintf("</form>\n");
835 do_template("endbox", NULL);
841 * if passwords match, propagate it to citserver.
846 char newpass1[32], newpass2[32];
848 if (!havebstr("change_action")) {
849 safestrncpy(WC->ImportantMessage,
850 _("Cancelled. Password was not changed."),
851 sizeof WC->ImportantMessage);
856 safestrncpy(newpass1, bstr("newpass1"), sizeof newpass1);
857 safestrncpy(newpass2, bstr("newpass2"), sizeof newpass2);
859 if (strcasecmp(newpass1, newpass2)) {
860 safestrncpy(WC->ImportantMessage,
861 _("They don't match. Password was not changed."),
862 sizeof WC->ImportantMessage);
867 if (IsEmptyStr(newpass1)) {
868 safestrncpy(WC->ImportantMessage,
869 _("Blank passwords are not allowed."),
870 sizeof WC->ImportantMessage);
875 serv_printf("SETP %s", newpass1);
876 serv_getln(buf, sizeof buf);
877 sprintf(WC->ImportantMessage, "%s", &buf[4]);
879 safestrncpy(WC->wc_password, buf, sizeof WC->wc_password);
887 int ConditionalAide(WCTemplateToken *Token, void *Context, int ContextType)
889 return (WC->is_aide == 0);
892 int ConditionalRoomAide(WCTemplateToken *Token, void *Context, int ContextType)
894 return (WC->is_room_aide == 0);
897 int ConditionalRoomAcessDelete(WCTemplateToken *Token, void *Context, int ContextType)
899 struct wcsession *WCC = WC;
900 return ( (WCC->is_room_aide) || (WCC->is_mailbox) || (WCC->room_flags2 & QR2_COLLABDEL) );
905 void _display_openid_login(void) {display_openid_login(NULL);}
906 void _display_reg(void) {display_reg(0);}
913 WebcitAddUrlHandler(HKEY("do_welcome"), do_welcome, ANONYMOUS);
914 WebcitAddUrlHandler(HKEY("login"), do_login, ANONYMOUS);
915 WebcitAddUrlHandler(HKEY("display_openid_login"), _display_openid_login, ANONYMOUS);
916 WebcitAddUrlHandler(HKEY("openid_login"), do_openid_login, ANONYMOUS);
917 WebcitAddUrlHandler(HKEY("finalize_openid_login"), finalize_openid_login, ANONYMOUS);
918 WebcitAddUrlHandler(HKEY("openid_manual_create"), openid_manual_create, ANONYMOUS);
919 WebcitAddUrlHandler(HKEY("do_logout"), do_logout, 0);
920 WebcitAddUrlHandler(HKEY("validate"), validate, 0);
921 WebcitAddUrlHandler(HKEY("display_reg"), _display_reg, 0);
922 WebcitAddUrlHandler(HKEY("display_changepw"), display_changepw, 0);
923 WebcitAddUrlHandler(HKEY("changepw"), changepw, 0);
924 WebcitAddUrlHandler(HKEY("termquit"), do_logout, 0);
926 RegisterConditional(HKEY("COND:AIDE"), 2, ConditionalAide, CTX_NONE);
927 RegisterConditional(HKEY("COND:ROOMAIDE"), 2, ConditionalRoomAide, CTX_NONE);
928 RegisterConditional(HKEY("COND:ACCESS:DELETE"), 2, ConditionalRoomAcessDelete, CTX_NONE);