00001
00002
00003
00011 #include "webcit.h"
00012
00013
00014
00020 char *axdefs[7];
00021
00022 void initialize_axdefs(void) {
00023 axdefs[0] = _("Deleted");
00024 axdefs[1] = _("New User");
00025 axdefs[2] = _("Problem User");
00026 axdefs[3] = _("Local User");
00027 axdefs[4] = _("Network User");
00028 axdefs[5] = _("Preferred User");
00029 axdefs[6] = _("Aide");
00030 }
00031
00032
00033
00034
00039 void display_login(char *mesg)
00040 {
00041 char buf[SIZ];
00042
00043 output_headers(1, 1, 2, 0, 0, 0);
00044 wprintf("<div id=\"login_screen\">\n");
00045
00046 if (mesg != NULL) if (strlen(mesg) > 0) {
00047 stresc(buf, mesg, 0, 0);
00048 svprintf("mesg", WCS_STRING, "%s", buf);
00049 }
00050
00051 svprintf("LOGIN_INSTRUCTIONS", WCS_STRING,
00052 _("<ul>"
00053 "<li><b>If you already have an account on %s</b>, "
00054 "enter your user name and password and click "Login." "
00055 "<li><b>If you are a new user</b>, enter the name and password "
00056 "you wish to use, "
00057 "and click "New User." "
00058 "<li>Please log off properly when finished. "
00059 "<li>You must use a browser that supports <i>frames</i> and "
00060 "<i>cookies</i>. "
00061 "<li>Also keep in mind that if your browser is "
00062 "configured to block pop-up windows, you will not be able "
00063 "to receive any instant messages.<br />"
00064 "</ul>"),
00065 serv_info.serv_humannode
00066 );
00067
00068 svprintf("USERNAME_BOX", WCS_STRING, "%s", _("User name:"));
00069 svprintf("PASSWORD_BOX", WCS_STRING, "%s", _("Password:"));
00070 svprintf("LANGUAGE_BOX", WCS_STRING, "%s", _("Language:"));
00071 svprintf("LOGIN_BUTTON", WCS_STRING, "%s", _("Login"));
00072 svprintf("NEWUSER_BUTTON", WCS_STRING, "%s", _("New User"));
00073 svprintf("EXIT_BUTTON", WCS_STRING, "%s", _("Exit"));
00074 svprintf("hello", WCS_SERVCMD, "MESG hello");
00075 svprintf("BOXTITLE", WCS_STRING, _("%s - powered by <a href=\"http://www.citadel.org\">Citadel</a>"),
00076 serv_info.serv_humannode);
00077 svcallback("DO_LANGUAGE_BOX", offer_languages);
00078 if (serv_info.serv_newuser_disabled) {
00079 svprintf("NEWUSER_BUTTON_PRE", WCS_STRING, "<div style=\"display:none;\">");
00080 svprintf("NEWUSER_BUTTON_POST", WCS_STRING, "</div>");
00081 }
00082 else {
00083 svprintf("NEWUSER_BUTTON_PRE", WCS_STRING, "");
00084 svprintf("NEWUSER_BUTTON_POST", WCS_STRING, "");
00085 }
00086
00087 do_template("login");
00088
00089 wDumpContent(2);
00090 }
00091
00092
00093
00094
00106 void become_logged_in(char *user, char *pass, char *serv_response)
00107 {
00108 char buf[SIZ];
00109
00110 WC->logged_in = 1;
00111 extract_token(WC->wc_fullname, &serv_response[4], 0, '|', sizeof WC->wc_fullname);
00112 safestrncpy(WC->wc_username, user, sizeof WC->wc_username);
00113 safestrncpy(WC->wc_password, pass, sizeof WC->wc_password);
00114 WC->axlevel = extract_int(&serv_response[4], 1);
00115 if (WC->axlevel >= 6) {
00116 WC->is_aide = 1;
00117 }
00118
00119 load_preferences();
00120
00121 serv_puts("CHEK");
00122 serv_getln(buf, sizeof buf);
00123 if (buf[0] == '2') {
00124 WC->new_mail = extract_int(&buf[4], 0);
00125 WC->need_regi = extract_int(&buf[4], 1);
00126 WC->need_vali = extract_int(&buf[4], 2);
00127 extract_token(WC->cs_inet_email, &buf[4], 3, '|', sizeof WC->cs_inet_email);
00128 }
00129
00130 get_preference("current_iconbar", buf, sizeof buf);
00131 WC->current_iconbar = atoi(buf);
00132
00133 get_preference("floordiv_expanded", WC->floordiv_expanded, sizeof WC->floordiv_expanded);
00134 }
00135
00136
00141 void do_login(void)
00142 {
00143 char buf[SIZ];
00144
00145 if (strlen(bstr("language")) > 0) {
00146 set_selected_language(bstr("language"));
00147 go_selected_language();
00148 }
00149
00150 if (strlen(bstr("exit_action")) > 0) {
00151 do_logout();
00152 return;
00153 }
00154 if (strlen(bstr("login_action")) > 0) {
00155 serv_printf("USER %s", bstr("name"));
00156 serv_getln(buf, sizeof buf);
00157 if (buf[0] == '3') {
00158 serv_printf("PASS %s", bstr("pass"));
00159 serv_getln(buf, sizeof buf);
00160 if (buf[0] == '2') {
00161 become_logged_in(bstr("name"),
00162 bstr("pass"), buf);
00163 } else {
00164 display_login(&buf[4]);
00165 return;
00166 }
00167 } else {
00168 display_login(&buf[4]);
00169 return;
00170 }
00171 }
00172 if (strlen(bstr("newuser_action")) > 0) {
00173 if (strlen(bstr("pass")) == 0) {
00174 display_login(_("Blank passwords are not allowed."));
00175 return;
00176 }
00177 serv_printf("NEWU %s", bstr("name"));
00178 serv_getln(buf, sizeof buf);
00179 if (buf[0] == '2') {
00180 become_logged_in(bstr("name"), bstr("pass"), buf);
00181 serv_printf("SETP %s", bstr("pass"));
00182 serv_getln(buf, sizeof buf);
00183 } else {
00184 display_login(&buf[4]);
00185 return;
00186 }
00187 }
00188 if (WC->logged_in) {
00189 if (WC->need_regi) {
00190 display_reg(1);
00191 } else {
00192 do_welcome();
00193 }
00194 } else {
00195 display_login(_("Your password was not accepted."));
00196 }
00197
00198 }
00199
00205 void do_welcome(void)
00206 {
00207 char buf[SIZ];
00208 #ifdef XXX_NOT_FINISHED_YET_XXX
00209 FILE *fp;
00210 int i;
00211
00215 if (WC->is_aide) {
00216 if (!setup_wizard) {
00217 sprintf(wizard_filename, "setupwiz.%s.%s",
00218 ctdlhost, ctdlport);
00219 for (i=0; i<strlen(wizard_filename); ++i) {
00220 if ( (wizard_filename[i]==' ')
00221 || (wizard_filename[i] == '/')
00222 ) {
00223 wizard_filename[i] = '_';
00224 }
00225 }
00226
00227 fp = fopen(wizard_filename, "r");
00228 if (fp != NULL) {
00229 fgets(buf, sizeof buf, fp);
00230 buf[strlen(buf)-1] = 0;
00231 fclose(fp);
00232 if (atoi(buf) == serv_info.serv_rev_level) {
00233 setup_wizard = 1;
00234 }
00235 }
00236 }
00237
00238 if (!setup_wizard) {
00239 http_redirect("setup_wizard");
00240 }
00241 }
00242 #endif
00243
00247 get_preference("startpage", buf, sizeof buf);
00248 if (strlen(buf)==0) {
00249 safestrncpy(buf, "dotskip&room=_BASEROOM_", sizeof buf);
00250 set_preference("startpage", buf, 1);
00251 }
00252 if (buf[0] == '/') {
00253 strcpy(buf, &buf[1]);
00254 }
00255 http_redirect(buf);
00256 }
00257
00258
00262 void end_webcit_session(void) {
00263 char buf[256];
00264
00265 if (WC->logged_in) {
00266 sprintf(buf, "%d", WC->current_iconbar);
00267 set_preference("current_iconbar", buf, 0);
00268 set_preference("floordiv_expanded", WC->floordiv_expanded, 1);
00269 }
00270
00271 serv_puts("QUIT");
00272 WC->killthis = 1;
00273
00274 }
00275
00279 void do_logout(void)
00280 {
00281 char buf[SIZ];
00282
00283 safestrncpy(WC->wc_username, "", sizeof WC->wc_username);
00284 safestrncpy(WC->wc_password, "", sizeof WC->wc_password);
00285 safestrncpy(WC->wc_roomname, "", sizeof WC->wc_roomname);
00286 safestrncpy(WC->wc_fullname, "", sizeof WC->wc_fullname);
00287
00289 output_headers(1, 1, 0, 1, 0, 0);
00290
00291 wprintf("<center>");
00292 serv_puts("MESG goodbye");
00293 serv_getln(buf, sizeof buf);
00294
00295 if (WC->serv_sock >= 0) {
00296 if (buf[0] == '1') {
00297 fmout("CENTER");
00298 } else {
00299 wprintf("Goodbye\n");
00300 }
00301 }
00302 else {
00303 wprintf(_("This program was unable to connect or stay "
00304 "connected to the Citadel server. Please report "
00305 "this problem to your system administrator.")
00306 );
00307 }
00308
00309 wprintf("<hr /><a href=\".\">");
00310 wprintf(_("Log in again"));
00311 wprintf("</A> "
00312 "<a href=\"javascript:window.close();\">");
00313 wprintf(_("Close window"));
00314 wprintf("</a></center>\n");
00315 wDumpContent(2);
00316 end_webcit_session();
00317 }
00318
00319
00320
00321
00322
00323 void validate(void)
00324 {
00325 char cmd[SIZ];
00326 char user[SIZ];
00327 char buf[SIZ];
00328 int a;
00329
00330 output_headers(1, 1, 2, 0, 0, 0);
00331 wprintf("<div id=\"banner\">\n"
00332 "<TABLE class=\"auth_banner\"><TR><TD>"
00333 "<SPAN CLASS=\"titlebar\">");
00334 wprintf(_("Validate new users"));
00335 wprintf("</SPAN></TD></TR></TABLE>\n</div>\n<div id=\"content\">\n");
00336
00338 safestrncpy(buf, bstr("user"), sizeof buf);
00339 if (strlen(buf) > 0) {
00340 if (strlen(bstr("axlevel")) > 0) {
00341 serv_printf("VALI %s|%s", buf, bstr("axlevel"));
00342 serv_getln(buf, sizeof buf);
00343 if (buf[0] != '2') {
00344 wprintf("<b>%s</b><br />\n", &buf[4]);
00345 }
00346 }
00347 }
00348
00350 serv_puts("GNUR");
00351 serv_getln(buf, sizeof buf);
00352 if (buf[0] == '2') {
00353 wprintf("<b>");
00354 wprintf(_("No users require validation at this time."));
00355 wprintf("</b><br />\n");
00356 wDumpContent(1);
00357 return;
00358 }
00359 if (buf[0] != '3') {
00360 wprintf("<b>%s</b><br />\n", &buf[4]);
00361 wDumpContent(1);
00362 return;
00363 }
00364
00365 wprintf("<div class=\"fix_scrollbar_bug\">"
00366 "<table class=\"auth_validate\"><tr><td>\n");
00367 wprintf("<center>");
00368
00369 safestrncpy(user, &buf[4], sizeof user);
00370 serv_printf("GREG %s", user);
00371 serv_getln(cmd, sizeof cmd);
00372 if (cmd[0] == '1') {
00373 a = 0;
00374 do {
00375 serv_getln(buf, sizeof buf);
00376 ++a;
00377 if (a == 1)
00378 wprintf("#%s<br /><H1>%s</H1>",
00379 buf, &cmd[4]);
00380 if (a == 2)
00381 wprintf("PW: %s<br />\n", buf);
00382 if (a == 3)
00383 wprintf("%s<br />\n", buf);
00384 if (a == 4)
00385 wprintf("%s<br />\n", buf);
00386 if (a == 5)
00387 wprintf("%s, ", buf);
00388 if (a == 6)
00389 wprintf("%s ", buf);
00390 if (a == 7)
00391 wprintf("%s<br />\n", buf);
00392 if (a == 8)
00393 wprintf("%s<br />\n", buf);
00394 if (a == 9)
00395 wprintf(_("Current access level: %d (%s)\n"),
00396 atoi(buf), axdefs[atoi(buf)]);
00397 } while (strcmp(buf, "000"));
00398 } else {
00399 wprintf("<H1>%s</H1>%s<br />\n", user, &cmd[4]);
00400 }
00401
00402 wprintf("<hr />");
00403 wprintf(_("Select access level for this user:"));
00404 wprintf("<br />\n");
00405 for (a = 0; a <= 6; ++a) {
00406 wprintf("<a href=\"validate&user=");
00407 urlescputs(user);
00408 wprintf("&axlevel=%d\">%s</A> \n",
00409 a, axdefs[a]);
00410 }
00411 wprintf("<br />\n");
00412
00413 wprintf("</CENTER>\n");
00414 wprintf("</td></tr></table></div>\n");
00415 wDumpContent(1);
00416 }
00417
00418
00419
00426 void display_reg(int during_login)
00427 {
00428 long vcard_msgnum;
00429
00430 if (goto_config_room() != 0) {
00431 if (during_login) do_welcome();
00432 else display_main_menu();
00433 return;
00434 }
00435
00436 vcard_msgnum = locate_user_vcard(WC->wc_fullname, -1);
00437 if (vcard_msgnum < 0L) {
00438 if (during_login) do_welcome();
00439 else display_main_menu();
00440 return;
00441 }
00442
00443 if (during_login) {
00444 do_edit_vcard(vcard_msgnum, "1", "do_welcome");
00445 }
00446 else {
00447 do_edit_vcard(vcard_msgnum, "1", "display_main_menu");
00448 }
00449
00450 }
00451
00452
00453
00454
00458 void display_changepw(void)
00459 {
00460 char buf[SIZ];
00461
00462 output_headers(1, 1, 2, 0, 0, 0);
00463 wprintf("<div id=\"banner\">\n"
00464 "<TABLE class=\"auth_banner\"><TR><TD>"
00465 "<SPAN CLASS=\"titlebar\">");
00466 wprintf(_("Change your password"));
00467 wprintf("</SPAN>"
00468 "</TD></TR></TABLE>\n"
00469 "</div>\n<div id=\"content\">\n"
00470 );
00471
00472 if (strlen(WC->ImportantMessage) > 0) {
00473 do_template("beginbox_nt");
00474 wprintf("<SPAN CLASS=\"errormsg\">"
00475 "%s</SPAN><br />\n", WC->ImportantMessage);
00476 do_template("endbox");
00477 safestrncpy(WC->ImportantMessage, "", sizeof WC->ImportantMessage);
00478 }
00479
00480 wprintf("<div class=\"fix_scrollbar_bug\">"
00481 "<table class=\"auth_validate\"><tr><td>\n");
00482
00483 wprintf("<CENTER><br />");
00484 serv_puts("MESG changepw");
00485 serv_getln(buf, sizeof buf);
00486 if (buf[0] == '1') {
00487 fmout("CENTER");
00488 }
00489
00490 wprintf("<form name=\"changepwform\" action=\"changepw\" method=\"post\">\n");
00491 wprintf("<CENTER>"
00492 "<table border=\"0\" cellspacing=\"5\" cellpadding=\"5\" "
00493 "BGCOLOR=\"#EEEEEE\">"
00494 "<TR><TD>");
00495 wprintf(_("Enter new password:"));
00496 wprintf("</TD>\n");
00497 wprintf("<TD><INPUT TYPE=\"password\" NAME=\"newpass1\" VALUE=\"\" MAXLENGTH=\"20\"></TD></TR>\n");
00498 wprintf("<TR><TD>");
00499 wprintf(_("Enter it again to confirm:"));
00500 wprintf("</TD>\n");
00501 wprintf("<TD><INPUT TYPE=\"password\" NAME=\"newpass2\" VALUE=\"\" MAXLENGTH=\"20\"></TD></TR>\n");
00502
00503 wprintf("</TABLE><br />\n");
00504 wprintf("<INPUT type=\"submit\" name=\"change_action\" value=\"%s\">", _("Change password"));
00505 wprintf(" ");
00506 wprintf("<INPUT type=\"submit\" name=\"cancel_action\" value=\"%s\">\n", _("Cancel"));
00507 wprintf("</form></center>\n");
00508 wprintf("</td></tr></table></div>\n");
00509 wDumpContent(1);
00510 }
00511
00516 void changepw(void)
00517 {
00518 char buf[SIZ];
00519 char newpass1[32], newpass2[32];
00520
00521 if (strlen(bstr("change_action")) == 0) {
00522 safestrncpy(WC->ImportantMessage,
00523 _("Cancelled. Password was not changed."),
00524 sizeof WC->ImportantMessage);
00525 display_main_menu();
00526 return;
00527 }
00528
00529 safestrncpy(newpass1, bstr("newpass1"), sizeof newpass1);
00530 safestrncpy(newpass2, bstr("newpass2"), sizeof newpass2);
00531
00532 if (strcasecmp(newpass1, newpass2)) {
00533 safestrncpy(WC->ImportantMessage,
00534 _("They don't match. Password was not changed."),
00535 sizeof WC->ImportantMessage);
00536 display_changepw();
00537 return;
00538 }
00539
00540 if (strlen(newpass1) == 0) {
00541 safestrncpy(WC->ImportantMessage,
00542 _("Blank passwords are not allowed."),
00543 sizeof WC->ImportantMessage);
00544 display_changepw();
00545 return;
00546 }
00547
00548 serv_printf("SETP %s", newpass1);
00549 serv_getln(buf, sizeof buf);
00550 sprintf(WC->ImportantMessage, "%s", &buf[4]);
00551 if (buf[0] == '2') {
00552 safestrncpy(WC->wc_password, buf, sizeof WC->wc_password);
00553 display_main_menu();
00554 }
00555 else {
00556 display_changepw();
00557 }
00558 }
00559
00560
00561