Example #1
0
int Chg_Language(int NewMode)
{
    FILE    *pLang;
    int	    iLang, iFoundLang = FALSE;
    char    *temp;

    temp = calloc(PATH_MAX, sizeof(char));

    if (!NewMode)
	ReadExitinfo();

    while(TRUE) {
	snprintf(temp, PATH_MAX, "%s/etc/language.data", getenv("FTND_ROOT"));
	if(( pLang = fopen(temp, "r")) == NULL) {
	    WriteError("$Can't open %s", temp);
	    snprintf(temp, 81, "\nFATAL: Can't open language file\n\n");
	    PUTSTR(temp);
	    Pause();
	    free(temp);
	    return 0;
	}
	fread(&langhdr, sizeof(langhdr), 1, pLang);

	colour(CFG.HiliteF, CFG.HiliteB);
	/* Select your preferred language */
	snprintf(temp, 81, "\r\n%s\r\n\r\n", (char *) Language(378));
	PUTSTR(temp);

	iLang = 6;
	colour(LIGHTBLUE, BLACK);
	while (fread(&lang, langhdr.recsize, 1, pLang) == 1)
	    if (lang.Available) {
		colour(LIGHTMAGENTA, BLACK);
		snprintf(temp, 81, "(%s)", lang.LangKey);
		PUTSTR(temp);
   		colour(DARKGRAY, BLACK);
   		snprintf(temp, 81, " %c ", 46);
		PUTSTR(temp);
   		colour(CYAN, BLACK);
		snprintf(temp, 81, "%-29s    ", lang.Name);
		PUTSTR(temp);

		iLang++;
		if ((iLang % 2) == 0) {
		    PUTCHAR('\r');
		    PUTCHAR('\n');
		}
	    }
	Enter(1);

	colour(CFG.HiliteF, CFG.HiliteB);
	/* Select language: */
        snprintf(temp, 81, "\n%s", (char *) Language(379));
	PUTSTR(temp);

	alarm_on();
	iLang = toupper(Readkey());

	PUTCHAR(iLang);

	fseek(pLang, langhdr.hdrsize, 0);

	while (fread(&lang, langhdr.recsize, 1, pLang) == 1) {
	    strcpy(lang.LangKey,tu(lang.LangKey));
	    if ((lang.LangKey[0] == iLang) && (lang.Available)) {
		strcpy(current_language, lang.lc);
		iFoundLang = TRUE;
		break;
	    }
	}
	
	fclose(pLang);

	if(!iFoundLang) {
	    Enter(2);
	    /* Invalid selection, please try again! */
	    pout(LIGHTGREEN, BLACK, (char *) Language(265));
	    Enter(2);
	} else {
	    exitinfo.iLanguage = iLang;
	    strcpy(current_language, lang.lc);
	    Free_Language();
	    InitLanguage();

	    colour(LIGHTGREEN, BLACK);
	    /* Language now set to" */
	    snprintf(temp, 81, "\r\n\r\n%s%s\r\n\r\n", (char *) Language(380), lang.Name);
	    PUTSTR(temp);

	    if (!NewMode) {
		Syslog('+', "Changed language to %s", lang.Name);
		WriteExitinfo();
		Pause();
	    }
	    break;
	}
    }

    free(temp);
    Enter(1);
    return iLang;
}
Example #2
0
File: bye.c Project: ftnapps/FTNd
void Good_Bye(int onsig)
{
    FILE    *pUsrConfig, *pExitinfo;
    char    *temp;
    int	    offset;
    time_t  t_end;
    int	    i;

    IsDoing("Hangup");
    temp = calloc(PATH_MAX, sizeof(char));
    Syslog('+', "Good_Bye(%d)", onsig);

    /*
     * Don't display goodbye screen on SIGHUP and idle timeout.
     * With idle timeout this will go into a loop.
     */
    if ((onsig != SIGALRM) && (onsig != FTNERR_TIMEOUT) && (hanged_up == 0))
	DisplayFile((char *)"goodbye");

    SaveLastCallers();

    /*
     * Update the users database record.
     */
    snprintf(temp, PATH_MAX, "%s/etc/users.data", getenv("FTND_ROOT"));
    if ((pUsrConfig = fopen(temp,"r+")) != NULL) {
	snprintf(temp, PATH_MAX, "%s/%s/exitinfo", CFG.bbs_usersdir, exitinfo.Name);
	if ((pExitinfo = fopen(temp,"rb")) != NULL) {
	    fread(&usrconfighdr, sizeof(usrconfighdr), 1, pUsrConfig);
	    fread(&exitinfo, sizeof(exitinfo), 1, pExitinfo);

	    usrconfig = exitinfo;
	    fclose(pExitinfo);
	    usrconfig.iLastFileArea = iAreaNumber;

	    /* If time expired, do not say say successful logoff */
	    if (!iExpired && !hanged_up)
		Syslog('+', "User successfully logged off BBS");

	    usrconfig.iLastMsgArea = iMsgAreaNumber;

	    offset = usrconfighdr.hdrsize + (grecno * usrconfighdr.recsize);
	    if (fseek(pUsrConfig, offset, SEEK_SET) != 0) {
		WriteError("$Can't move pointer in file %s/etc/users.data", getenv("FTND_ROOT"));
	    } else {
	        fwrite(&usrconfig, sizeof(usrconfig), 1, pUsrConfig);
	    }
	    fclose(pUsrConfig);
	}
    }

    /*
     * Update mib counters
     */
    t_end = time(NULL);
    mib_minutes = (unsigned int) ((t_end - t_start) / 60);
    mib_sessions++;

    sendmibs();

    /*
     * Flush all data to the user, wait 5 seconds to
     * be sure the user received all data.
     */
    if ((onsig != SIGALRM) && (onsig != FTNERR_TIMEOUT) && (hanged_up == 0)) {
	colour(LIGHTGRAY, BLACK);
	sleep(4);
    }

    for (i = 0; i < NSIG; i++) {
	if (i == SIGCHLD)
	    signal(i, SIG_DFL);
	else if ((i != SIGKILL) && (i != SIGSTOP))
	    signal(i, SIG_DFL);
    }

    if ((onsig != SIGALRM) && (onsig != FTNERR_TIMEOUT) && (hanged_up == 0)) {
    	cookedport();
    }

    /*
     * Ignore SIGHUP during hangup.
     */
    signal(SIGHUP, SIG_IGN);
    hangup();

    for (i = 0; i < NSIG; i++) {
	if ((i == SIGHUP) || (i == SIGPIPE) || (i == SIGBUS) || (i == SIGILL) || (i == SIGSEGV) || (i == SIGTERM))
	    signal(i, SIG_DFL);
    }
    
    if (do_mailout)
	CreateSema((char *)"mailout");

    t_end = time(NULL);
    Syslog(' ', "FTNDBBS finished in %s", t_elapsed(t_start, t_end));
    sleep(1);

    /*
     * Start shutting down this session, cleanup some files.
     */
    socket_shutdown(mypid);
    snprintf(temp, PATH_MAX, "%s/tmp/ftnd%d", getenv("FTND_ROOT"), getpid());
    unlink(temp);

    snprintf(temp, PATH_MAX, "%s/%s/.quote", CFG.bbs_usersdir, exitinfo.Name);
    unlink(temp);

    snprintf(temp, PATH_MAX, "%s/%s/data.msg", CFG.bbs_usersdir, exitinfo.Name);
    unlink(temp);

    snprintf(temp, PATH_MAX, "%s/%s/door.sys", CFG.bbs_usersdir, exitinfo.Name);
    unlink(temp);

    snprintf(temp, PATH_MAX, "%s/%s/door32.sys", CFG.bbs_usersdir, exitinfo.Name);
    unlink(temp);

    snprintf(temp, PATH_MAX, "%s/%s/exitinfo", CFG.bbs_usersdir, exitinfo.Name);
    unlink(temp);
    free(temp);
    unlink("taglist");

    Free_Language();
    free(pTTY);
    if (StartTime)
	free(StartTime);
    deinitnl();
    exit(onsig);
}
Example #3
0
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();
}