void DoMenu(int Type) { int Strlen, i, x; char *sPrompt, *sPromptBak, *temp; sPrompt = calloc(81, sizeof(char)); sPromptBak = calloc(81, sizeof(char)); temp = calloc(81, sizeof(char)); TimeCheck(); switch(Type) { case 0: /* Display Prompt Line Only */ break; case 1: /* Goto another menu */ strncpy(Menus[MenuLevel], menus.OptionalData, 14); break; case 2: /* Gosub another menu */ if (MenuLevel < 49) { MenuLevel++; strncpy(Menus[MenuLevel], menus.OptionalData, 14); } else Syslog('?', "More than 50 menu levels"); break; case 3: /* Return from gosub */ if (MenuLevel > 0) MenuLevel--; break; case 4: /* Return to top menu */ MenuLevel = 0; break; case 5: /* Display .a?? file with controlcodes */ DisplayFile(menus.OptionalData); break; case 6: /* Show menu prompt */ Strlen = strlen(menus.OptionalData); for (x = 0; x < Strlen; x++) { if (menus.OptionalData[x] == '~') { strcat(sPrompt, sUserTimeleft); } else { snprintf(temp, 81, "%c", menus.OptionalData[x]); strcat(sPrompt, temp); } } strcpy(sPromptBak, sPrompt); strcpy(sPrompt, ""); Strlen = strlen(sPromptBak); for (x = 0; x < Strlen; x++) { if (*(sPromptBak + x) == '@') strcat(sPrompt, sAreaDesc); else if (*(sPromptBak + x) == '^') strcat(sPrompt, sMsgAreaDesc); else if (*(sPromptBak + x) == '#') snprintf(sPrompt, 81, "%s%s", sPrompt, (char *) GetLocalHM()); else { snprintf(temp, 81, "%c", *(sPromptBak + x)); strcat(sPrompt, temp); } } if (le_int(menus.ForeGnd) || le_int(menus.BackGnd)) pout(le_int(menus.ForeGnd), le_int(menus.BackGnd), sPrompt); else pout(WHITE, BLACK, sPrompt); break; case 7: /* Run external program */ if (strlen(menus.DoorName) && !menus.HideDoor) { memset(temp, 0, sizeof(temp)); strcpy(temp, menus.DoorName); ExtDoor(menus.OptionalData, menus.NoDoorsys, menus.Y2Kdoorsys, menus.Comport, menus.NoSuid, menus.NoPrompt, menus.SingleUser, temp); } else { ExtDoor(menus.OptionalData, menus.NoDoorsys, menus.Y2Kdoorsys, menus.Comport, menus.NoSuid, menus.NoPrompt, menus.SingleUser, NULL); } break; case 8: /* Show product information */ cr(); break; case 9: /* display todays callers */ LastCallers(menus.OptionalData); break; case 10: /* display userlist */ UserList(menus.OptionalData); break; case 11: /* display time statistics */ TimeStats(); break; case 12: /* page sysop for chat */ Page_Sysop(menus.OptionalData); break; case 13: /* terminate call */ free(sPrompt); free(sPromptBak); free(temp); Good_Bye(FTNERR_OK); break; case 14: /* make a log entry */ LogEntry(menus.OptionalData); break; case 15: /* print text to screen */ if (exitinfo.Security.level >= le_int(menus.MenuSecurity.level)) { for (i = 0; i < strlen(menus.OptionalData); i++) if (*(menus.OptionalData + i) == '@') *(menus.OptionalData + i) = '\n'; snprintf(temp, 81, "%s\r\n", menus.OptionalData); PUTSTR(temp); } break; case 16: /* who's currently online */ WhosOn(menus.OptionalData); Pause(); break; case 17: /* comment to sysop */ SysopComment((char *)"Comment to Sysop"); break; case 18: /* send on-line message */ SendOnlineMsg(menus.OptionalData); break; case 19: /* display Textfile with more */ MoreFile(menus.OptionalData); break; case 20: /* display a?? file with controlcode and wait for enter */ DisplayFileEnter(menus.OptionalData); break; case 21: /* display menuline only */ break; case 22: /* Chat with any user */ Chat(NULL, NULL); break; case 101: FileArea_List(menus.OptionalData); break; case 102: File_List(); break; case 103: ViewFile(NULL); break; case 104: Download(); break; case 105: File_RawDir(menus.OptionalData); break; case 106: KeywordScan(); break; case 107: FilenameScan(); break; case 108: NewfileScan(TRUE); break; case 109: Upload(); break; case 110: EditTaglist(); break; case 111: /* View file in homedir */ break; case 112: DownloadDirect(menus.OptionalData, TRUE); break; case 113: Copy_Home(); break; case 114: List_Home(); break; case 115: Delete_Home(); break; /* 116 Unpack file in homedir */ /* 117 Pack files in homedir */ case 118: Download_Home(); break; case 119: Upload_Home(); break; case 201: MsgArea_List(menus.OptionalData); break; case 202: Post_Msg(); break; case 203: Read_Msgs(); break; case 204: CheckMail(); break; case 205: QuickScan_Msgs(); break; case 206: Delete_Msg(); break; case 207: MailStatus(); break; case 208: OLR_TagArea(); break; case 209: OLR_UntagArea(); break; case 210: OLR_ViewTags(); break; case 211: OLR_RestrictDate(); break; case 212: OLR_Upload(); break; case 213: OLR_DownBW(); break; case 214: OLR_DownQWK(); break; case 215: OLR_DownASCII(); break; case 216: Read_Email(); break; case 217: Write_Email(); break; case 218: Trash_Email(); break; case 219: Choose_Mailbox(menus.OptionalData); break; case 220: QuickScan_Email(); break; case 221: DisplayRules(); break; case 301: Chg_Protocol(); break; case 302: Chg_Password(); break; case 303: Chg_Location(); break; case 305: Chg_VoicePhone(); break; case 306: Chg_DataPhone(); break; case 307: Chg_News(); break; case 309: Chg_DOB(); break; case 310: Chg_Language(FALSE); break; case 311: Chg_Hotkeys(); break; case 312: Chg_Handle(); break; case 313: Chg_MailCheck(); break; case 314: Chg_Disturb(); break; case 315: Chg_FileCheck(); break; case 316: Chg_FsMsged(); break; case 317: Chg_FsMsgedKeys(); break; case 318: Chg_Address(); break; case 319: signature(); break; case 320: Chg_OLR_ExtInfo(); break; case 321: Chg_Charset(); break; case 322: Chg_Archiver(); break; case 401: Oneliner_Add(); break; case 402: Oneliner_List(); break; case 403: Oneliner_Show(); break; case 404: Oneliner_Delete(); break; case 405: Oneliner_Print(); break; default: Enter(1); pout(WHITE, BLACK, (char *) Language(339)); Enter(2); Syslog('?', "Option: %s -> Unknown Menu Type: %d on %s", menus.MenuKey, Type, Menus[MenuLevel]); Pause(); } free(sPrompt); free(sPromptBak); free(temp); }
void user(void) { FILE *pUsrConfig, *pLimits; int i, x, FoundName = FALSE, iFoundLimit = FALSE, IsNew = FALSE, logins = 0, Start; int l1, l2; char *token, temp[PATH_MAX], temp1[84], UserName[37], buf[128], *fullname; time_t LastLogin; struct stat st; grecno = 0; Syslog('+', "Unixmode login: %s", sUnixName); snprintf(temp, PATH_MAX, "%s/etc/users.data", getenv("FTND_ROOT")); if ((pUsrConfig = fopen(temp,"r+")) == NULL) { /* * This should not happen. */ WriteError("$Can't open %s", temp); PUTSTR((char *)"Can't open userfile, run \"newuser\" first"); Enter(1); ExitClient(FTNERR_OK); } fread(&usrconfighdr, sizeof(usrconfighdr), 1, pUsrConfig); while (fread(&usrconfig, usrconfighdr.recsize, 1, pUsrConfig) == 1) { if (strcmp(usrconfig.Name, sUnixName) == 0) { FoundName = TRUE; break; } else grecno++; } if (!FoundName) { fclose(pUsrConfig); snprintf(temp, PATH_MAX, "Unknown username: %s\r\n", sUnixName); PUTSTR(temp); /* FATAL ERROR: You are not in the BBS users file.*/ snprintf(temp, PATH_MAX, "%s\r\n", (char *) Language(389)); PUTSTR(temp); /* Please run 'newuser' to create an account */ snprintf(temp, PATH_MAX, "%s\r\n", (char *) Language(390)); PUTSTR(temp); Syslog('?', "FATAL: Could not find user in BBS users file."); Syslog('?', " and system is using unix accounts\n"); Free_Language(); ExitClient(FTNERR_OK); } /* * Copy username, split first and lastname. */ strncpy(UserName, usrconfig.sUserName, sizeof(UserName)-1); if ((strchr(UserName,' ') == NULL) && !CFG.iOneName) { token = strtok(UserName, " "); strncpy(FirstName, token, sizeof(FirstName)-1); token = strtok(NULL, "\0"); i = strlen(token); for (x = 2; x < i; x++) { if (token[x] == ' ') token[x] = '\0'; } strncpy(LastName, token, sizeof(LastName)-1); } else strncpy(FirstName, UserName, sizeof(FirstName)-1); strncpy(UserName, usrconfig.sUserName, sizeof(UserName)-1); Syslog('+', "%s On-Line from \"%s\", node %d", UserName, ttyinfo.comment, iNode); IsDoing("Just Logged In"); /* * Check some essential files, create them if they don't exist. */ ChkFiles(); /* * Setup users favourite language. */ utf8 = (usrconfig.Charset == FTNC_UTF8); Set_Language(usrconfig.iLanguage); Free_Language(); InitLanguage(); /* * User logged in, tell it to the server. Check if a location is * set, if Ask User location for new users is off, this field is * empty but we have to send something to the server. */ if (strlen(usrconfig.sLocation)) UserCity(mypid, usrconfig.Name, usrconfig.sLocation); else UserCity(mypid, usrconfig.Name, (char *)"N/A"); /* * Count simultaneous logins */ Start = TRUE; while (TRUE) { if (Start) snprintf(buf, 128, "GMON:1,1;"); else snprintf(buf, 128, "GMON:1,0;"); Start = FALSE; if (socket_send(buf) == 0) { strcpy(buf, socket_receive()); if (strncmp(buf, "100:0;", 6) == 0) break; /* No more data */ if (strstr(buf, "ftnbbs")) { /* * Only ftnbbs is wanted */ strtok(buf, ","); /* response */ strtok(NULL, ","); /* pid */ strtok(NULL, ","); /* tty */ fullname = xstrcpy(cldecode(strtok(NULL, ","))); /* username */ if (strcmp(fullname, usrconfig.Name) == 0) { logins++; } free(fullname); } } } if (CFG.max_logins && (logins > CFG.max_logins)) { Syslog('+', "User logins %d, allowed %d, disconnecting", logins, CFG.max_logins); colour(LIGHTRED, BLACK); snprintf(temp, PATH_MAX, "%s %d %s\r\n", (char *) Language(18), CFG.max_logins, (char *) Language(19)); PUTSTR(temp); Quick_Bye(FTNERR_INIT_ERROR); } /* * Set last file and message area so these numbers are saved when * the user hangs up or is logged off before het gets to the main * menu. Later in this function the areas are set permanent. */ iAreaNumber = usrconfig.iLastFileArea; iMsgAreaNumber = usrconfig.iLastMsgArea; /* * See if this user is the Sysop. */ strcpy(temp, UserName); strcpy(temp1, CFG.sysop_name); if ((strcasecmp(CFG.sysop_name, UserName)) == 0) { /* * If login name is sysop, set SYSOP true */ SYSOP = TRUE; Syslog('+', "Sysop is online"); } /* * Is this a new user? */ if (usrconfig.iTotalCalls == 0) IsNew = TRUE; /* * Pause after logo screen. */ alarm_on(); Pause(); if (usrconfig.Archiver[0] == '\0') { usrconfig.Archiver[0] = 'Z'; usrconfig.Archiver[1] = 'I'; usrconfig.Archiver[2] = 'P'; Syslog('+', "Setup default archiver ZIP"); } /* * Check users date format. We do it strict as we * need this to be good for several other purposes. * If it is correct, the users age is set in UserAge */ if (!Test_DOB(usrconfig.sDateOfBirth)) { Syslog('!', "Error in Date of Birth"); Chg_DOB(); strcpy(usrconfig.sDateOfBirth, exitinfo.sDateOfBirth); } /* * Check to see if user must expire */ snprintf(temp,PATH_MAX, "%s", (char *) GetDateDMY()); SwapDate(temp, usrconfig.sExpiryDate); /* Convert Date1 & Date2 to longs for compare */ l1 = atol(Date1); l2 = atol(Date2); if (l1 >= l2 && l2 != 0) { /* * If Expiry Date is the same as today expire to * Expire Sec level */ usrconfig.Security = usrconfig.ExpirySec; Syslog('!', "User is expired, resetting level"); /* * Show texfile to user telling him about this. */ DisplayFile((char *)"expired"); } free(Date1); free(Date2); /* * Copy limits.data into memory */ snprintf(temp, PATH_MAX, "%s/etc/limits.data", getenv("FTND_ROOT")); if ((pLimits = fopen(temp,"rb")) == NULL) { WriteError("$Can't open %s", temp); } else { fread(&LIMIThdr, sizeof(LIMIThdr), 1, pLimits); while (fread(&LIMIT, sizeof(LIMIT), 1, pLimits) == 1) { if (LIMIT.Security == usrconfig.Security.level) { iFoundLimit = TRUE; break; } } fclose(pLimits); } if (!iFoundLimit) { WriteError("Unknown Security Level in limits.data"); usrconfig.iTimeLeft = 0; /* Could not find limit, so set to Zero */ usrconfig.iTimeUsed = 0; /* Set to Zero as well */ } else { /* * Give user new time limit everyday, also new users get a new limit. */ snprintf(temp,PATH_MAX, "%s", (char *) GetDateDMY()); if (((strcmp(StrDateDMY(usrconfig.tLastLoginDate), temp)) != 0) || IsNew) { /* * If no timelimit set give user 24 hours. */ if (LIMIT.Time) usrconfig.iTimeLeft = LIMIT.Time; else usrconfig.iTimeLeft = 86400; usrconfig.iTimeUsed = 0; /* Set time used today to Zero */ usrconfig.iConnectTime = 0; /* Set connect time to Zero */ /* * Give user new bytes and files every day if needed. */ if (LIMIT.DownK) { usrconfig.DownloadKToday = LIMIT.DownK; } if (LIMIT.DownF) { usrconfig.DownloadsToday = LIMIT.DownF; } } } /* End of else */ usrconfig.iConnectTime = 0; /* Copy Users Protocol into Memory */ Set_Protocol(usrconfig.sProtocol); tlf(usrconfig.sProtocol); /* * Set last login Date and Time, copy previous session * values in memory. */ snprintf(LastLoginDate, 12, "%s", StrDateDMY(usrconfig.tLastLoginDate)); snprintf(LastLoginTime, 9, "%s", StrTimeHMS(usrconfig.tLastLoginDate)); LastLogin = usrconfig.tLastLoginDate; usrconfig.tLastLoginDate = ltime; /* Set current login to current date */ usrconfig.iTotalCalls++; /* * Update user record. */ if (fseek(pUsrConfig, usrconfighdr.hdrsize + (grecno * usrconfighdr.recsize), 0) != 0) { WriteError("Can't seek in %s/etc/users.data", getenv("FTND_ROOT")); } else { fwrite(&usrconfig, sizeof(usrconfig), 1, pUsrConfig); } fclose(pUsrConfig); /* * Write users structure to tmp file in ~/home/unixname/exitinfo * A copy of the userrecord is also in the variable exitinfo. */ if (! InitExitinfo()) Good_Bye(FTNERR_INIT_ERROR); /* * If user has not set a preferred character set, force this */ if (exitinfo.Charset == FTNC_NONE) { Chg_Charset(); } setlocale(LC_CTYPE, getlocale(exitinfo.Charset)); Syslog('b', "setlocale(LC_CTYPE, NULL) returns \"%s\"", printable(setlocale(LC_CTYPE, NULL), 0)); GetLastUser(); StartTime = xstrcpy(GetLocalHM()); ChangeHomeDir(exitinfo.Name, exitinfo.Email); Syslog('+', "User successfully logged into BBS"); Syslog('+', "Level %d (%s), %d mins. left, port %s", exitinfo.Security.level, LIMIT.Description, exitinfo.iTimeLeft, pTTY); Time2Go = time(NULL); Time2Go += exitinfo.iTimeLeft * 60; iUserTimeLeft = exitinfo.iTimeLeft; IsDoing("Welcome screens"); DisplayFile((char *)"mainlogo"); DisplayFile((char *)"welcome"); /* * The following files are only displayed if the user has * turned the Bulletins on. */ if (exitinfo.ieNEWS) { DisplayFile((char *)"welcome1"); DisplayFile((char *)"welcome2"); DisplayFile((char *)"welcome3"); DisplayFile((char *)"welcome4"); DisplayFile((char *)"welcome5"); DisplayFile((char *)"welcome6"); DisplayFile((char *)"welcome7"); DisplayFile((char *)"welcome8"); DisplayFile((char *)"welcome9"); snprintf(temp, PATH_MAX, "%s", (char *) GetDateDMY() ); if ((strcmp(exitinfo.sDateOfBirth, temp)) == 0) DisplayFile((char *)"birthday"); /* * Displays file if it exists DD-MM.A?? */ snprintf(temp, PATH_MAX, "%s", (char *) GetDateDMY()); strcpy(temp1, ""); strncat(temp1, temp, 5); snprintf(temp, PATH_MAX, "%s", temp1); DisplayFile(temp); /* * Displays users security file if it exists */ snprintf(temp, PATH_MAX, "sec%d", exitinfo.Security.level); DisplayFile(temp); /* * Display News file */ DisplayFile((char *)"news"); } /* * Display Onceonly file, first get the date of that * file, search order is the same as in DisplayFile() */ st.st_mtime = 0; snprintf(temp, PATH_MAX, "%s/share/int/txtfiles/%s/onceonly.ans", getenv("FTND_ROOT"), lang.lc); stat(temp, &st); if (st.st_mtime == 0) { snprintf(temp, PATH_MAX, "%s/share/int/txtfiles/%s/onceonly.ans", getenv("FTND_ROOT"), CFG.deflang); stat(temp, &st); } if (st.st_mtime == 0) { snprintf(temp, PATH_MAX, "%s/share/int/txtfiles/%s/onceonly.asc", getenv("FTND_ROOT"), lang.lc); stat(temp, &st); if (st.st_mtime == 0) { snprintf(temp, PATH_MAX, "%s/share/int/txtfiles/%s/onceonly.asc", getenv("FTND_ROOT"), CFG.deflang); stat(temp, &st); } } if ((st.st_mtime != 0) && (LastLogin < st.st_mtime)) DisplayFile((char *)"onceonly"); OLR_SyncTags(); if (exitinfo.MailScan) { IsDoing("New mail check"); CheckMail(); } /* * We don't show new files to new users. */ if (exitinfo.ieFILE && (!IsNew)) { IsDoing("New files check"); NewfileScan(FALSE); } /* * Copy last file Area in to current Area */ SetFileArea(exitinfo.iLastFileArea); /* * Copy Last Message Area in to Current Msg Area */ SetMsgArea(usrconfig.iLastMsgArea); SetEmailArea((char *)"mailbox"); /* * Set or Reset the DoNotDisturb flag, now is the time * we may be interrupted. */ UserSilent(usrconfig.DoNotDisturb); /* * Start the menu. */ menu(); }