Пример #1
0
/*
 * Function will initialize language variables and load them into
 * memory for speed
 */
void InitLanguage()
{
    FILE    *pLang;
    int	    iLang = 0;
    char    *temp;

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

    snprintf(temp, PATH_MAX, "%s/share/int/language.%s", getenv("FTND_ROOT"), current_language);
    if ((pLang = fopen(temp, "rb")) == NULL) {
	WriteError("$FATAL: Can't open %s", temp);
	ExitClient(FTNERR_INIT_ERROR);
    }

    while (fread(&ldata, sizeof(ldata), 1, pLang) == 1) {
	*(mLanguage + iLang) = (char *) calloc(strlen(ldata.sString) + 1, sizeof(char));
	*(mKeystroke + iLang) = (char *) calloc(strlen(ldata.sKey) + 1, sizeof(char));  
	strcpy(mLanguage[iLang], ldata.sString);
	strcpy(mKeystroke[iLang], ldata.sKey);
	iLang++;

	if (iLang >= LANG) {
	    Enter(1);
	    PUTSTR((char *)"FATAL: Language file has to many lines in it");
	    Enter(2);
	    ExitClient(FTNERR_INIT_ERROR);
	}
    }

    fclose(pLang);
    Syslog('b', "%d language lines read (%s)", iLang, current_language);
    free(temp);
}
Пример #2
0
void NewClient(svcInfoPtr psvc, int sock)
{
    int one=1;


    if (setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (char *)&one, sizeof(one)) < 0) {
        Err("setsockopt failed");
        close(sock);
        return;
     }

    psvc->sock = sock;
    if (WriteExact(psvc, psvc->version, RUISVC_VERSION_LEN) < 0) {
        Err("NewClient: write");
        ExitClient(psvc);
        return;
    }

    if (fcntl(sock, F_SETFL, O_NONBLOCK) < 0) {
        Err("fcntl failed");
        close(sock);
        return;
    }

    //pthread_attr_t myattr;
    //pthread_attr_init(&myattr);
    pthread_create(&psvc->client_thread, NULL, clientInput, (void *)psvc);
    void* rtn = 0;
    pthread_join(psvc->client_thread, &rtn);
}
Пример #3
0
void die(int onsig)
{
    signal(onsig, SIG_IGN);
    CloseDupes();
    Msg_Close();

    if (onsig) {
	if (onsig <= NSIG)
	    WriteError("Terminated on signal %d (%s)", onsig, SigName[onsig]);
	else
	    WriteError("Terminated with error %d", onsig);
    }

    if (do_mailout)
	CreateSema((char *)"mailout");

    t_end = time(NULL);
    Syslog('+', "Send [%6lu] Received [%6lu]", sentbytes, rcvdbytes);
    Syslog(' ', "FTNNNTP finished in %s", t_elapsed(t_start, t_end));

    if (envptr)
	free(envptr);

    ExitClient(onsig);

    msleep(1);      /* For the linker only */
}
Пример #4
0
int ChkFiles()
{
    FILE	*fp;
    char	*temp;
    time_t	Now;

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

    /*
     * Check if users.data exists, if not create a new one.
     */
    snprintf(temp, PATH_MAX, "%s/etc/users.data", getenv("FTND_ROOT"));
    if ((fp = fopen(temp,"rb")) == NULL) {
	if ((fp = fopen(temp,"wb")) == NULL) {
	    WriteError("$Can't create %s", temp);
	    ExitClient(FTNERR_INIT_ERROR); 
	} else {
	    usrconfighdr.hdrsize = sizeof(usrconfighdr);
	    usrconfighdr.recsize = sizeof(usrconfig);
	    fwrite(&usrconfighdr, sizeof(usrconfighdr), 1, fp);
	    fclose(fp);
	}
    } else {
	fclose(fp);
    }
    chmod(temp, 0660);

    /*
     * Check if sysinfo.data exists, if not, create a new one.
     */
    snprintf(temp, PATH_MAX, "%s/etc/sysinfo.data", getenv("FTND_ROOT"));
    if ((fp = fopen(temp, "rb")) == NULL) {
	if ((fp = fopen(temp, "wb")) == NULL) {
	    WriteError("$ChkFiles: Can't create %s", temp);
	} else {
	    memset((char *)&SYSINFO, 0, sizeof(SYSINFO));
	    Now = time(NULL);
	    SYSINFO.StartDate = Now;
	    fwrite(&SYSINFO, sizeof(SYSINFO), 1, fp);
	    fclose(fp);
	}
    } else {
	fclose(fp);
    }
    chmod(temp, 0660);

    free(temp);
    return 1;
}
Пример #5
0
void die(int onsig)
{
    /*
     * First check if a child is running, if so, kill it.
     */
    if (e_pid) {
        if ((kill(e_pid, SIGTERM)) == 0)
            Syslog('+', "SIGTERM to pid %d succeeded", e_pid);
        else {
            if ((kill(e_pid, SIGKILL)) == 0)
                Syslog('+', "SIGKILL to pid %d succeded", e_pid);
            else
                WriteError("$Failed to kill pid %d", e_pid);
        }

        /*
         * In case the child had the tty in raw mode...
         */
        if (!do_quiet)
            execute_pth((char *)"stty", (char *)"sane", (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null");
    }

    signal(onsig, SIG_IGN);

    if (onsig) {
        if (onsig <= NSIG)
            WriteError("Terminated on signal %d (%s)", onsig, SigName[onsig]);
        else
            WriteError("Terminated with error %d", onsig);
    }

    clean_tmpwork();
    ulockprogram((char *)"ftnfile");
    t_end = time(NULL);
    Syslog(' ', "FTNFILE finished in %s", t_elapsed(t_start, t_end));

    if (!do_quiet) {
        ftnd_colour(LIGHTGRAY, BLACK);
        fflush(stdout);
    }
    ExitClient(onsig);
}
Пример #6
0
void die(int onsig)
{
    signal(onsig, SIG_IGN);

    if (onsig) {
	if (onsig <= NSIG)
	    WriteError("Terminated on signal %d (%s)", onsig, SigName[onsig]);
	else
	    WriteError("Terminated with error %d", onsig);
    }

    ulockprogram((char *)"ftnaff");
    t_end = time(NULL);
    Syslog(' ', "FTNDAFF finished in %s", t_elapsed(t_start, t_end));

    if (!do_quiet) {
	ftnd_colour(LIGHTGRAY, BLACK);
	printf("\n");
    }
    ExitClient(onsig);
}
Пример #7
0
void die(int onsig)
{
    if (onsig && (onsig <= NSIG)) {
	signal(onsig, SIG_IGN);
    }

    if (!do_quiet) {
	printf("\r");
	mbse_colour(CYAN, BLACK);
    }

    if (MsgBase.Locked)
	Msg_UnLock();
    if (MsgBase.Open)
	Msg_Close();

    if (onsig) {
	if (onsig <= NSIG)
	    WriteError("Terminated on signal %d (%s)", onsig, SigName[onsig]);
	else
	    WriteError("Terminated with error %d", onsig);
    }

    if (are_tot || are_proc || msg_link)
    	Syslog('+', "Areas  [%6d] Processed [%6d] Linked [%6d]", are_tot, are_proc, msg_link);
    if (msg_tot || msg_del)
	Syslog('+', "Msgs   [%6d]   Deleted [%6d]", msg_tot, msg_del);

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

    umask(oldmask);
    if (!do_quiet) {
	mbse_colour(LIGHTGRAY, BLACK);
	printf("\r                                                          \n");
    }
    ExitClient(onsig);
}
Пример #8
0
int main(int argc, char **argv)
{
	struct passwd	*pw;
	unsigned int	seq;

	InitConfig();

	pw = getpwuid(getuid());

	InitClient(pw->pw_name, (char *)"ftnseq", CFG.location, CFG.logfile, 
		CFG.util_loglevel, CFG.error_log, CFG.mgrlog, CFG.debuglog);

	Syslog(' ', " "); 
	Syslog(' ', "FTNSEQ v%s", VERSION);

	seq = sequencer();
	Syslog('+', "Sequence string %08lx", seq);
	printf("%08x", seq);
	fflush(stdout);

	Syslog(' ', "FTNSEQ finished");
	ExitClient(0);
	return 0;
}
Пример #9
0
/*
 * 	abcdefghijklmnopqrstuvwxyz
 *      e  hi klmno q  t u
 *      |  || ||||| |  | |
 *      |  || ||||| |  | +get screen (full res)
 *      |  || ||||| |  + touch(down,x,y)
 *      |  || ||||| +quit client
 *      |  || ||||+ftp_err
 *      |  || |||+ftp_data
 *      |  || ||+ftp_upload_req
 *      |  || |+ftp_download_req
 *      |  || +ftp_filelist_req
 *      |  |+get screen info
 *      |  +get screen (half req)
 *      +stop service
 */
static int ProcessClientMessage(svcInfoPtr psvc, FBCCMD* pmsg)
{
	//FBCCMD msg;
    //char msg;
    int n = 0;
    int nSize;

    //if( (n = ReadExact(psvc, (char*)&msg, FBCCMD_HEADER)) <= 0 ) {
    //    Err("ProcessClientMessage : read(%d)\n", n);
    //    return false;
    //}
    pmsg->size = ntohl(pmsg->size);
    pmsg->size -= FBCCMD_HEADER;
    //Log("msg received(%c: size - %d)\n", pmsg->cmd, pmsg->size);
    if( pmsg->size > 0) {
    	pmsg->data = (char*)malloc(pmsg->size);
        if( (n = ReadExact(psvc, (char*)pmsg->data, pmsg->size)) <= 0 ) {
            Err("ProcessClientMessage : read(%d)\n", n);
            return false;
        }
    }
    //Log("after alloc %02x %02x %02x %02x\n", msg.data[0],msg.data[1],msg.data[2],msg.data[3]);


    unsigned int data;
#ifdef PERFORMANCE_REPORT
	struct timeval tS, tE;

	gettimeofday(&tS,NULL);
	psvc->frame_client += ELAPSED(tLast, tS);
#endif
    switch(pmsg->cmd) {

        case 'i':
        {
        	FBCCMD_SCRINFO res;
        	res.cmd = 'i';
        	res.size = htonl(sizeof(FBCCMD_SCRINFO));

        	res.width = htonl(g_fbinfo.width);
        	res.height = htonl(g_fbinfo.height);
        	res.bpp = htonl(g_fbinfo.bpp);
        	res.touchfd = htonl( (touchfd != -1 ) ? 1 : 0);
        	LOCK(psvc->output_mutex);
            int rtn = WriteExact(psvc, (const char*)&res, sizeof(FBCCMD_SCRINFO));
            UNLOCK(psvc->output_mutex);
            //Log("response i %d to :%d\n", res.size, rtn);
        }
            break;
        case 'u':
        	//Log("signal-u\n");
        	g_halfmode = 0;
        	//TSIGNAL(psvc->updateCond);
        	read_rgb_framebuffer_to_jpeg(psvc);
#ifdef PERFORMANCE_REPORT
	gettimeofday(&tE,NULL);

	psvc->frame_total += ELAPSED(tS, tE);
	tS = tE;
#endif
            break;
        case 'h':
        	g_halfmode = 1;
        	//Log("signal-h\n");
        	//TSIGNAL(psvc->updateCond);
            //g_halfmode = 0;
            read_rgb_framebuffer_to_jpeg(psvc);
#ifdef PERFORMANCE_REPORT
	gettimeofday(&tE,NULL);

	psvc->frame_total += ELAPSED(tS, tE);
	tS = tE;
#endif
            break;
        case 'e':
            return false;
            break;
        case 'q':
        	ExitClient(psvc);
        	ShutdownSockets(psvc);
        	break;
        // ftp
        case 'k':	// ftp filestlist req
        	onFilelistReq(psvc, pmsg);
        	break;
        case 'l':	// ftp filedownload req
        	onFileDownloadReq(psvc, pmsg);
        	break;
        case 'm':	// ftp fileupload req
        	onFileUploadReq(psvc, pmsg);
        	break;
        case 'n':	// ftp fileupload data
            //Log("case n\n");

        	onFileMsg(psvc, pmsg);
        	break;
        case 'o':	// ftp fileerr
        	onFileErr(psvc, pmsg);
        	break;
        case 't':
        	onTouch(psvc, pmsg);
        	break;
    }

    if( pmsg->size > 0) {
    	free(pmsg->data);
    }

    //if(( psvc->frame_sent++ % 5) == 0) {
    //	g_fbinfo.orientation = get_dev_rotation();
    //	//int isScreenOn = get_screen_on();
    //	//Log("isScreenOn(%d)\n",isScreenOn);
    //}

#ifdef PERFORMANCE_REPORT

            if( (psvc->frame_sent % 10) == 0)
            {
            	double frame_total;
            	double frame_capture;
            	double frame_compress;
            	double frame_colorspace;
            	double frame_tx;
            	double frame_client;
            	double fps, fps_svr;



            	fps = (double)10 * 1000000 / (psvc->frame_total + psvc->frame_client);
            	fps_svr = (double)10 * 1000000 / psvc->frame_total;
            	frame_total = psvc->frame_total / 10000;
            	frame_capture = psvc->frame_capture / 10000;
            	frame_compress = psvc->frame_compress / 10000;
            	frame_colorspace = psvc->frame_colorspace / 10000;
            	frame_tx = psvc->frame_tx / 10000;
            	frame_client = psvc->frame_client / 10000;

                if( psvc->frame_sent > 10 )
                {
                	Log("FPS(%5.2f),SVR(%4.1f) TOT(%3.0f),CAP(%3.0f),ZIP(%3.0f),CNV(%2.0f),TX(%2.0f),CLI(%2.0f)\n",
                			//psvc->frame_sent-1,
                			fps, fps_svr,
                			frame_total, frame_capture, frame_compress, frame_colorspace, frame_tx,frame_client);
                }
            	psvc->frame_total		=	0;
            	psvc->frame_capture		=	0;
            	psvc->frame_compress	=	0;
            	psvc->frame_colorspace	=	0;
            	psvc->frame_tx			=	0;
            	psvc->frame_client		= 	0;

            }
            gettimeofday(&tLast,NULL);
#endif /* PERFORMANCE_REPORT */
           // Log("end loop");
    return true;

}
Пример #10
0
static void * clientInput(void *data)
{
    svcInfoPtr psvc = (svcInfoPtr)data;
    Log("clientInput Thread started(%d)\n", psvc->sock);

    struct sockaddr_in addr;
    socklen_t addrlen = sizeof(struct sockaddr_in);
    getpeername(psvc->sock, (struct sockaddr *)&addr, &addrlen);
    strcpy(psvc->host, inet_ntoa(addr.sin_addr));
    Log("Client(%s) connected\n",psvc->host);

    fd_set rfds, sfds;
    struct timeval tv;
    int n;

    psvc->frame_sent 		= 0;
#ifdef PERFORMANCE_REPORT
	psvc->frame_total		=	0;
	psvc->frame_capture		=	0;
	psvc->frame_compress	=	0;
	psvc->frame_colorspace	=	0;
	psvc->frame_tx			=	0;
    psvc->frame_client		= 	0;
    gettimeofday(&tLast,NULL);
#endif /* PERFORMANCE_REPORT */

    //LOCK(psvc->output_mutex);
    //last_fbc_output_current = fbc_output_current;
    //UNLOCK(psvc->output_mutex);
    FBCCMD msgt, msg;
    while (1) {

        FD_ZERO(&rfds);
        FD_SET(psvc->sock, &rfds);
        //FD_ZERO(&sfds);
        //FD_SET(psvc->sock, &sfds);


        tv.tv_sec = 30;
        tv.tv_usec = 0;	// 50 msec
        n = select(psvc->sock + 1, &rfds,  /*&sfds*/ NULL, NULL, &tv);
        if (n < 0) {
            Err("ReadExact: select");
            break;
        }
        
        if (psvc->sock == -1) {
            Log("client disconnected\n");
            break;
        }

        if (FD_ISSET(psvc->sock, &rfds) ) {
            if( ReadExact(psvc, (char*)&msg, FBCCMD_HEADER) <= 0 ) {
                Err("Read Err");
                break;
            }

            if( msg.cmd == 'h')
            {
				while( 1 )
				{
					FD_ZERO(&rfds);
					FD_SET(psvc->sock, &rfds);
					tv.tv_sec = 0;
					tv.tv_usec = 1000;
					n = select(psvc->sock + 1, &rfds,  /*&sfds*/ NULL, NULL, &tv);
					if( n== 0) // no more packet
						break;
					if (FD_ISSET(psvc->sock, &rfds) ) {
						if( ReadExact(psvc, (char*)&msgt, FBCCMD_HEADER) <= 0 ) {
							Err("Read Err2\n");
							break;
						}

						if( msgt.cmd == msg.cmd ) {// same update packet
							//Log("skip same update cmd\n");
							continue;
						}
						ProcessClientMessage(psvc, &msg);
						msg = msgt;
					}
					break;
				}
            }
            if( 0 == ProcessClientMessage(psvc, &msg) )
                break;
        }
        /*
        if (FD_ISSET(psvc->sock, &sfds) ) {
            LOCK(psvc->output_mutex);

            if( last_fbc_output_current != fbc_output_current )
            {
            	//Log("output-start %d-%d\n",last_fbc_output_current,fbc_output_current);
            	//Log("client  outbuf  last:%d current:%d\n", last_fbc_output_current, fbc_output_current);
            	unsigned int size = fbc_output[last_fbc_output_current].size;
            	fbc_output[last_fbc_output_current].size = htonl(size);
            	//int result1, result2;
            	WriteExact(psvc, (const char*)&fbc_output[last_fbc_output_current], FBCCMD_HEADER);
            	WriteExact(psvc, (const char*)fbc_output[last_fbc_output_current].jpegBuf, size - FBCCMD_HEADER);
            	last_fbc_output_current = fbc_output_current;
            	//Log("output result(%d,%d:%d)\n", result1, result2,size);
            }
            UNLOCK(psvc->output_mutex);
        }
        */

        if (psvc->sock == -1) {
            Log("client disconnected\n");
            break;
        }
    }

    ExitClient(psvc);

    Log("clientInput Thread Exit\n");

    return NULL;
}
Пример #11
0
static void die(int onsig)
{
    FILE    *fp;
    char    *temp;
    int	    i;

    signal(onsig, SIG_IGN);
    if ((!init) && (onsig != FTNERR_NO_PROGLOCK))
	screen_stop(); 

    if (exp_golded && (config_read() != -1)) {
	temp = calloc(PATH_MAX, sizeof(char));

	/*
	 * Export ~/etc/msg.txt for MsgEd.
	 */
	snprintf(temp, PATH_MAX, "%s/etc/msg.txt", getenv("FTND_ROOT"));
	if ((fp = fopen(temp, "w")) != NULL) {
	    fprintf(fp, "; msg.txt -- Automatic created by ftnsetup %s -- Do not edit!\n;\n", VERSION);
	    fprintf(fp, "; Mail areas for MsgEd.\n;\n");
	    msged_areas(fp);
	    fclose(fp);
	    Syslog('+', "Created new %s", temp);
	} else {
	    WriteError("$Could not create %s", temp);
	}

	/*
	 * Export ~/etc/golded.inc for GoldED
	 */
	snprintf(temp, PATH_MAX, "%s/etc/golded.inc", getenv("FTND_ROOT"));
	if ((fp = fopen(temp, "w")) != NULL) {
	    fprintf(fp, "; GoldED.inc -- Automatic created by ftnsetup %s -- Do not edit!\n\n", VERSION);
	    fprintf(fp, "; Basic information.\n;\n");
	    if (strlen(CFG.sysop_name) && CFG.akavalid[0] && CFG.aka[0].zone) {
		fprintf(fp, "USERNAME %s\n\n", CFG.sysop_name);
		fprintf(fp, "ADDRESS %s\n", aka2str(CFG.aka[0]));
		for (i = 1; i < 40; i++)
		    if (CFG.akavalid[i])
			fprintf(fp, "AKA     %s\n", aka2str(CFG.aka[i]));
		    fprintf(fp, "\n");

		gold_akamatch(fp);
		fprintf(fp, "; JAM MessageBase Setup\n;\n");
		fprintf(fp, "JAMPATH %s/tmp/\n", getenv("FTND_ROOT"));
		fprintf(fp, "JAMHARDDELETE NO\n\n");

		fprintf(fp, "; Semaphore files\n;\n");
		fprintf(fp, "SEMAPHORE NETSCAN    %s/var/sema/mailout\n", getenv("FTND_ROOT"));
		fprintf(fp, "SEMAPHORE ECHOSCAN   %s/var/sema/mailout\n\n", getenv("FTND_ROOT"));

		gold_areas(fp);
	    }
	    fclose(fp);
	    Syslog('+', "Created new %s", temp);
	} else {
	    WriteError("$Could not create %s", temp);
	}

	free(temp);
    }

    ulockprogram((char *)"ftnsetup");
    umask(oldmask);
    if (onsig && (onsig <= NSIG))
	WriteError("FTNSETUP finished on signal %s", SigName[onsig]);
    else
	Syslog(' ', "FTNSETUP finished");
    ExitClient(onsig);
}
Пример #12
0
/*
 * Function will check and create a home directory for the user if
 * needed. It will also change into the users home directory when
 * they login.
 */
char *ChangeHomeDir(char *Name, int Mailboxes)
{
    char	*temp;
    static char	temp1[PATH_MAX];
    FILE	*fp;

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

    /*
     * set umask bits to zero's then reset with mkdir
     */
    umask(000);
	
    /*
     * First check to see if users home directory exists
     * else try create directory, as set in CFG.bbs_usersdir
     */
    if ((access(CFG.bbs_usersdir, R_OK)) != 0) {
	WriteError("$FATAL: Access to %s failed", CFG.bbs_usersdir);
	free(temp);
	ExitClient(MBERR_INIT_ERROR);
    }

    snprintf(temp1, PATH_MAX, "%s/%s", CFG.bbs_usersdir, Name);

    /*
     * Then check to see if users directory exists in the home dir
     */
    if ((access(temp1, R_OK)) != 0) {
	WriteError("$FATAL: Users homedir %s doesn't exist", temp1);
	free(temp);
	ExitClient(MBERR_INIT_ERROR);
    }

    /*
     * Change to users home directory
     */
    if (chdir(temp1) != 0) {
	WriteError("$FATAL: Can't change to users home dir, aborting: %s", temp1);
	free(temp);
	ExitClient(MBERR_INIT_ERROR);
    }
    setenv("HOME", temp1, 1);

    /*
     * Check if user has a .signature file.
     * If not, create a simple one.
     */
    snprintf(temp, PATH_MAX, "%s/%s/.signature", CFG.bbs_usersdir, Name);
    if (access(temp, R_OK)) {
	Syslog('+', "Creating users .signature file");
        if ((fp = fopen(temp, "w")) == NULL) {
	    WriteError("$Can't create %s", temp);
	} else {
	    fprintf(fp,     "    Greetings, %s\n", exitinfo.sUserName);
	    if ((CFG.EmailMode == E_PRMISP) && exitinfo.Email && CFG.GiveEmail)
	        fprintf(fp, "    email: %s@%s\n", exitinfo.Name, CFG.sysdomain);
	    fclose(fp);
	}
    }

    /*
     * Check subdirectories, create them if they don't exist.
     */
    snprintf(temp, PATH_MAX, "%s/wrk", temp1);
    CheckDir(temp);
    snprintf(temp, PATH_MAX, "%s/tag", temp1);
    CheckDir(temp);
    snprintf(temp, PATH_MAX, "%s/upl", temp1);
    CheckDir(temp);
    snprintf(temp, PATH_MAX, "%s/tmp", temp1);
    CheckDir(temp);
    snprintf(temp, PATH_MAX, "%s/.dosemu", temp1);
    CheckDir(temp);
    snprintf(temp, PATH_MAX, "%s/.dosemu/run", temp1);
    CheckDir(temp);
    snprintf(temp, PATH_MAX, "%s/.dosemu/tmp", temp1);
    CheckDir(temp);
    umask(007);

    /*
     * Check users private emailboxes
     */
    if (Mailboxes) {
	snprintf(temp, PATH_MAX, "%s/mailbox", temp1);
	if (Msg_Open(temp))
	    Msg_Close();
	snprintf(temp, PATH_MAX, "%s/archive", temp1);
	if (Msg_Open(temp))
	    Msg_Close();
	snprintf(temp, PATH_MAX, "%s/trash", temp1);
	if (Msg_Open(temp))
	    Msg_Close();
    }
	
    free(temp);
    return temp1;
}
Пример #13
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();
}