Beispiel #1
0
void GetstrLC(char *sStr, int iMaxlen)
{
    unsigned char   ch = 0;
    int		    iPos = 0;

    strcpy(sStr, "");
    alarm_on();

    while (ch != 13) {

	ch = Readkey();

	if ((ch == 8) || (ch == KEY_DEL) || (ch == 127)) {
	    if (iPos > 0) {
		BackErase();
		sStr[--iPos] = '\0';
	    } else {
		Beep();
	    }
	}

	if ((ch > 31 && ch < 127) || traduce((char *)&ch)) {
	    if (iPos <= iMaxlen) {
		iPos++;
		snprintf(sStr + strlen(sStr), 5, "%c", ch);
		PUTCHAR(ch);
	    } else {
		Beep();
	    }
	}
    }

    Enter(1);
}
Beispiel #2
0
void Chg_Address()
{
    int	    i;
    char    temp[41];
    
    ReadExitinfo();
    Syslog('+', "Old address \"%s\"", exitinfo.address[0]);
    Syslog('+', "            \"%s\"", exitinfo.address[1]);
    Syslog('+', "            \"%s\"", exitinfo.address[2]);

    while (TRUE) {
	Enter(1);
	/* Old address: */
	pout(WHITE, BLACK, (char *) Language(476));
	Enter(1);
	colour(LIGHTBLUE, BLACK);
	PUTSTR(exitinfo.address[0]);
	Enter(1);
	PUTSTR(exitinfo.address[1]);
	Enter(1);
	PUTSTR(exitinfo.address[2]);
	Enter(2);
	/* Your address, maximum 3 lines (only visible for the sysop): */
	pout(YELLOW, BLACK, (char *) Language(474));
	Enter(1);

	for (i = 0; i < 3; i++ ) {
	    colour(YELLOW, BLACK);
	    printf("%d: ", i+1);
	    colour(CFG.InputColourF, CFG.InputColourB);
	    alarm_on();
	    GetstrC(temp, 40);
	    if (strcmp(temp, ""))
		Setup(exitinfo.address[i], temp);
	}

	if (strlen(exitinfo.address[0]) || strlen(exitinfo.address[1]) || strlen(exitinfo.address[2]))
	    break;

	Enter(1);
	/* You need to enter your address here */
	pout(LIGHTRED, BLACK, (char *)Language(475));
	Enter(1);
    }

    Syslog('+', "New address \"%s\"", exitinfo.address[0]);
    Syslog('+', "            \"%s\"", exitinfo.address[1]);
    Syslog('+', "            \"%s\"", exitinfo.address[2]);
    WriteExitinfo();
}
Beispiel #3
0
/*
 * Choose Message Editor
 */
void Chg_FsMsged()
{
    int	    z;
    char    temp[81];

    ReadExitinfo();
    Enter(2);

    /*                               Now using the */
    pout(LIGHTMAGENTA, BLACK, (char *)Language(372));
    /*                 Line/Fullscreen/External    */
    colour(LIGHTCYAN, BLACK);
    snprintf(temp, 81, " %s ", Language(387 + (exitinfo.MsgEditor & 3)));
    PUTSTR(temp);
    /*                                      Editor */
    pout(LIGHTMAGENTA, BLACK, (char *)Language(390));
    Enter(1);

    if (strlen(CFG.externaleditor))
	/* Select: 1) Fullscreen editor, 2) External editor */
	pout(WHITE, BLACK, (char *)Language(373));
    else
	/* Select: 1) Fullscreen editor */
	pout(WHITE, BLACK, (char *)Language(438));
    alarm_on();
    z = toupper(Readkey());

    if (z == Keystroke(373, 0)) {
	exitinfo.MsgEditor = FSEDIT;
	Syslog('+', "User selected fullscreen editor");
    } else if ((z == Keystroke(373, 1) && strlen(CFG.externaleditor))) {
	exitinfo.MsgEditor = EXTEDIT;
	Syslog('+', "User selected external editor");
    }

    Enter(2);

    /*                               Now using the */
    pout(LIGHTMAGENTA, BLACK, (char *)Language(372));
    /*                 Line/Fullscreen/External    */
    colour(LIGHTCYAN, BLACK);
    snprintf(temp, 81, " %s ", Language(387 + (exitinfo.MsgEditor & 3)));
    PUTSTR(temp);
    /*                                      Editor */
    pout(LIGHTMAGENTA, BLACK, (char *)Language(390));

    Enter(2);
    sleep(2);
    WriteExitinfo();
}
int
main(int argc, char* argv[])
{

	/************** VARIABLE DECLARATION */
	KeyStruct keyPadState;
	AlarmStruct state;
	EdgeStruct sense;
	char code[CODE_DIM+1];
	DEFAULT_CODE(code);
	bool isEquals;

	/************* INIT ***************/
	keypad_init(&keyPadState);
	timer_start();
	sense_init(&sense);
	alarm_init(&state);
	lcd_init();
	buzzer_init();

	/************** INFINITE LOOP *****/
	HD44780_ClrScr();
	HD44780_GotoXY(0,0);
	HD44780_PutStr("SALVE PRF FOGGIA");
	HD44780_GotoXY(0,1);
	HD44780_PutStr("Alarm System 1.0");
	keypad_flush(&keyPadState);

	while(1){
		state.eventsArray[MAGN1] = magn_one_read(&sense);
		state.eventsArray[MAGN2] = magn_two_read(&sense);
		state.eventsArray[MOVE1] = move_one_read(&sense);
		state.eventsArray[MOVE2] = move_two_read(&sense);
		state.eventsArray[MOVE3] = move_three_read(&sense);
		state.eventsArray[MOVE4] = move_four_read(&sense);
		state.eventsArray[KEYPAD] = get_code(&keyPadState);

		/******** Update State ***********/
		isEquals = true;

		if(state.eventsArray[KEYPAD]){
			pin_sound();
			int i=0;
			HD44780_ClrScr();
			HD44780_GotoXY(0,0);
			HD44780_PutStr("PIN:");
			HD44780_GotoXY(0,1);
			alarm_off();

			while(keyPadState.code[i] != '\0' && code[i] != '\0'){
				HD44780_PutChar(keyPadState.code[i]);
				(isEquals & (keyPadState.code[i] == code[i])) ? (isEquals = true) : (isEquals = false);
				i++;
			}

			if(isEquals){
				state.isActive = !state.isActive;
				keypad_flush(&keyPadState);

				if(state.isActive){
					HD44780_ClrScr();
					HD44780_GotoXY(0,0);
					HD44780_PutStr("ALLARME");
					HD44780_GotoXY(0,1);
					HD44780_PutStr("ATTIVATO");
				}else{
					HD44780_ClrScr();
					HD44780_GotoXY(0,0);
					HD44780_PutStr("ALLARME");
					HD44780_GotoXY(0,1);
					HD44780_PutStr("DISATTIVATO");
				}
			}
			if(!isEquals && keyPadState.index == CODE_DIM){
				HD44780_GotoXY(0,1);
				HD44780_PutStr("ERRATO");
				keypad_flush(&keyPadState);
			}
		}
		/******** Generate Outputs *******/
		if(state.eventsArray[MAGN1] && state.isActive){
			state.isRinging = true;
			HD44780_ClrScr();
			HD44780_GotoXY(0,0);
			HD44780_PutStr("VIOLAZIONE");
			HD44780_GotoXY(0,1);
			HD44780_PutStr("PORTA 1");
		}
		if(state.eventsArray[MAGN2] && state.isActive){
			state.isRinging = true;
			HD44780_ClrScr();
			HD44780_GotoXY(0,0);
			HD44780_PutStr("VIOLAZIONE");
			HD44780_GotoXY(0,1);
			HD44780_PutStr("PORTA 2");
		}
		if(state.eventsArray[MOVE1] && state.isActive){
			state.isRinging = true;
			HD44780_ClrScr();
			HD44780_GotoXY(0,0);
			HD44780_PutStr("VIOLAZIONE");
			HD44780_GotoXY(0,1);
			HD44780_PutStr("STANZA 1");
		}
		if(state.eventsArray[MOVE2] && state.isActive){
			state.isRinging = true;
			HD44780_ClrScr();
			HD44780_GotoXY(0,0);
			HD44780_PutStr("VIOLAZIONE");
			HD44780_GotoXY(0,1);
			HD44780_PutStr("STANZA 2");
		}
		if(state.eventsArray[MOVE3] && state.isActive){
			state.isRinging = true;
			HD44780_ClrScr();
			HD44780_GotoXY(0,0);
			HD44780_PutStr("VIOLAZIONE");
			HD44780_GotoXY(0,1);
			HD44780_PutStr("STANZA 3");
		}
		if(state.eventsArray[MOVE4] && state.isActive){
			state.isRinging = true;
			HD44780_ClrScr();
			HD44780_GotoXY(0,0);
			HD44780_PutStr("VIOLAZIONE");
			HD44780_GotoXY(0,1);
			HD44780_PutStr("STANZA 4");
		}

		if(!state.isActive){
			alarm_off();
			state.isRinging = false;
		}

		if(state.isRinging)
			alarm_on();

		if(keyPadState.prevChar == ENTER_CHAR)
			change_pin(code, &keyPadState);

		timer_sleep(1);
	}
}
Beispiel #5
0
int main(){
	alarm_clk_init();
	alarm_on();
	EnableInterrupts();
	while(1){}
}
Beispiel #6
0
/*
 * Receive a file with ZMODEM protocol
 *  Assumes file name frame is in secbuf
 */
int rzfile(void)
{
    int	c, n;

    Eofseen=FALSE;
    rxbytes = 0l;
    if ((c = procheader(secbuf))) {
	return (tryzhdrtype = c);
    }

    n = 20;

    for (;;) {
	stohdr(rxbytes);
	zshhdr(ZRPOS, Txhdr);
nxthdr:
	switch (c = zgethdr(Rxhdr)) {
	    default:	    Syslog('z', "rzfile: Wrong header %d", c);
			    if ( --n < 0) {
				Syslog('+', "Zmodem: wrong header %d", c);
				return TERROR;
			    }
			    continue;
	    case ZCAN:	    Syslog('+', "Zmodem: sender CANcelled");
			    return TERROR;
	    case ZNAK:	    if ( --n < 0) {
				Syslog('+', "Zmodem: Got ZNAK");
				return TERROR;
			    }
			    continue;
	    case TIMEOUT:   if ( --n < 0) {
				Syslog('z', "Zmodem: TIMEOUT");
				return TERROR;
			    }
			    continue;
	    case ZFILE:	    zrdata(secbuf, MAXBLOCK);
			    continue;
	    case ZEOF:	    if (rclhdr(Rxhdr) != rxbytes) {
				/*
				 * Ignore eof if it's at wrong place - force
				 *  a timeout because the eof might have gone
				 *  out before we sent our zrpos.
				 */
				errors = 0;
				goto nxthdr;
			    }
			    if (closeit(1)) {
				tryzhdrtype = ZFERR;
				Syslog('+', "Zmodem: error closing file");
				return TERROR;
			    }
			    fout = NULL;
			    Syslog('z', "rzfile: normal EOF");
			    return c;
	    case HANGUP:    Syslog('+', "Zmodem: Lost Carrier");
			    return TERROR;
	    case TERROR:    /* Too much garbage in header search error */
			    if (--n < 0) {
				Syslog('+', "Zmodem: Too many errors");
				return TERROR;
			    }
			    zmputs(Attn);
			    continue;
	    case ZSKIP:	    Modtime = 1;
			    closeit(1);
			    Syslog('+', "Zmodem: Sender SKIPPED file");
			    return c;
	    case ZDATA:	    if (rclhdr(Rxhdr) != rxbytes) {
				if ( --n < 0) {
				    Syslog('+', "Zmodem: Data has bad address");
				    return TERROR;
				}
				zmputs(Attn);  
				continue;
			    }
moredata:
			    Nopper();
			    alarm_on();
			    switch (c = zrdata(secbuf, MAXBLOCK)) {
				case ZCAN:	Syslog('+', "Zmodem: sender CANcelled");
						return TERROR;
				case HANGUP:	Syslog('+', "Zmodem: Lost Carrier");
						return TERROR;
				case TERROR:	/* CRC error */
						if (--n < 0) {
						    Syslog('+', "Zmodem: Too many errors");
						    return TERROR;
						}
						zmputs(Attn);
						continue;
				case TIMEOUT:	if ( --n < 0) {
						    Syslog('+', "Zmodem: TIMEOUT");
						    return TERROR;
						}
						continue;
				case GOTCRCW:	n = 20;
						putsec(secbuf, Rxcount);
						rxbytes += Rxcount;
						stohdr(rxbytes);
						PUTCHAR(XON);
						zshhdr(ZACK, Txhdr);
						goto nxthdr;
				case GOTCRCQ:	n = 20;
						putsec(secbuf, Rxcount);
						rxbytes += Rxcount;
						stohdr(rxbytes);
						zshhdr(ZACK, Txhdr);
						goto moredata;
				case GOTCRCG:	n = 20;
						putsec(secbuf, Rxcount);
						rxbytes += Rxcount;
						goto moredata;
				case GOTCRCE:	n = 20;
						putsec(secbuf, Rxcount);
						rxbytes += Rxcount;
						goto nxthdr;
			    }
	}
    }
}
Beispiel #7
0
void Write_Email(void)
{
    faddr   *Dest = NULL;
    int	    i;
    char    *orgbox;

    if (HasNoEmail())
	return;

    orgbox = xstrcpy(sMailbox);
    SetEmailArea((char *)"mailbox");

    WhosDoingWhat(READ_POST, NULL);
    clear();

    for (i = 0; i < (TEXTBUFSIZE + 1); i++)
	Message[i] = (char *) calloc(MAX_LINE_LENGTH +1, sizeof(char));
    Line = 1;

    Msg_New();

    Enter(1);
    colour(LIGHTBLUE, BLACK);
    /* Posting message in area: */
    pout(LIGHTBLUE, BLACK, (char *) Language(156));
    PUTSTR((char *)"\"mailbox\"");
    Enter(2);

    /* From   : */
    pout(YELLOW, BLACK, (char *) Language(157));
    if (CFG.EmailMode != E_PRMISP) {
	/*
	 * If not permanent connected to the internet, use fidonet.org style addressing.
	 */
	Dest = fido2faddr(CFG.EmailFidoAka);
	snprintf(Msg.From, 101, "%s@%s (%s)", exitinfo.sUserName, ascinode(Dest, 0x2f), exitinfo.sUserName);
    } else
	snprintf(Msg.From, 101, "%s@%s (%s)", exitinfo.Name, CFG.sysdomain, exitinfo.sUserName);
    
    for (i = 0; i < strlen(Msg.From); i++) {
        if (Msg.From[i] == ' ')
            Msg.From[i] = '_';
        if (Msg.From[i] == '@')
            break;
    }
    
    pout(CFG.MsgInputColourF, CFG.MsgInputColourB, Msg.From);
    Syslog('b', "Setting From: %s", Msg.From);
    Enter(1);

    /* To     : */
    pout(YELLOW, BLACK, (char *) Language(158));
    colour(CFG.MsgInputColourF, CFG.MsgInputColourB);
    alarm_on();
    GetstrU(Msg.To, 63);

    if ((strcmp(Msg.To, "")) == 0) {
	for (i = 0; i < (TEXTBUFSIZE + 1); i++)
	    free(Message[i]);
	SetEmailArea(orgbox);
	free(orgbox);
	return;
    }

    /* Subject  :  */
    pout(YELLOW, BLACK, (char *) Language(161));
    colour(CFG.MsgInputColourF, CFG.MsgInputColourB);
    alarm_on();
    GetstrP(Msg.Subject, 65, 0);
    mbse_CleanSubject(Msg.Subject);

    if ((strcmp(Msg.Subject, "")) == 0) {
	Enter(1);
	/* Abort Message [y/N] ?: */
	pout(CYAN, BLACK, (char *) Language(162));
	alarm_on();

	if (toupper(Readkey()) == Keystroke(162, 0)) {
	    for (i = 0; i < (TEXTBUFSIZE + 1); i++)
		free(Message[i]);
	    SetEmailArea(orgbox);
	    free(orgbox);
	    return;
	}
    }

    Msg.Private = TRUE;

    if (Edit_Msg()) {
	Save_Email(FALSE);
    }

    for (i = 0; i < (TEXTBUFSIZE + 1); i++)
	free(Message[i]);

    SetEmailArea(orgbox);
    free(orgbox);
}
Beispiel #8
0
/*
 * The panel bar under the message while email reading
 */
int EmailPanel(void)
{
    int	input;

    WhosDoingWhat(READ_POST, NULL);

    /* (A)gain, (N)ext, (L)ast, (R)eply, (E)nter, (D)elete, (Q)uit, e(X)port */
    pout(WHITE, RED, (char *) Language(214));
    if (exitinfo.Security.level >= CFG.sysop_access)
	PUTSTR((char *)", (!)");
    PUTSTR((char *)": ");
    alarm_on();
    input = toupper(Readkey());

    if (input == '!') {
	if (exitinfo.Security.level >= CFG.sysop_access) {
	    if (Kludges)
		Kludges = FALSE;
	    else
		Kludges = TRUE;
	    Read_a_Email(LastNum);
	}
    } else if (input == Keystroke(214, 0)) { /* (A)gain */
	Read_a_Email(LastNum);
    } else if (input == Keystroke(214, 4)) { /* (P)ost */
	Write_Email();
	Read_a_Email(LastNum);
    } else if (input == Keystroke(214, 2)) { /* (L)ast */
	if (LastNum  > EmailBase.Lowest)
	    LastNum--;
	Read_a_Email(LastNum);
    } else if (input == Keystroke(214, 3)) { /* (R)eply */
	Reply_Email(TRUE);
	Read_a_Email(LastNum);
    } else if (input == Keystroke(214, 5)) { /* (Q)uit */
	/* Quit */
	pout(WHITE, BLACK, (char *) Language(189));
	Enter(1);
	return FALSE;
    } else if (input == Keystroke(214, 7)) { /* e(X)port */
	Export_a_Email(LastNum);
	Read_a_Email(LastNum);
    } else if (input == '+') {
	if (Msg.Reply) 
	    LastNum = Msg.Reply;
	Read_a_Email(LastNum);
    } else if (input == '-') {
	if (Msg.Original) 
	    LastNum = Msg.Original;
	Read_a_Email(LastNum);
    } else if (input == Keystroke(214, 6)) { /* (D)elete */
//		Delete_EmailNum(LastNum);
	if (LastNum < EmailBase.Highest) {
	    LastNum++;
	    Read_a_Email(LastNum);
	} else {
	    return FALSE;
	}
    } else {
	/* Next */
	pout(WHITE, BLACK, (char *) Language(216));
	if (LastNum < EmailBase.Highest)
	    LastNum++;
	else
	    return FALSE;
	Read_a_Email(LastNum);
    }
    return TRUE;
}
Beispiel #9
0
void main(void)
{

		init_DigIO();
	  	init_timer();
	   	
		init_adc();	   ////
		init_SWTimer();   
     // Enable peripherial interrupts and start processing
     PEIE = 1; // Enable peripheral interrupt
     GIE = 1; // Enable global interrupt
 Start_Timer(TIMER_3,10); 
unsigned char tempcounter;
//Switch Off alarm and heater;
alarm_on();
heater_off();
while (1)
	{


if (GetTimer_State(TIMER_3) ==TIMER_EXPIRED)
{
 Start_Timer(TIMER_3,10); // Call every 10ms cyclic timer

if(Read_Adc_E1() == TRUE)//true
{

WaterSensed_State = Read_Adc_E0();
/*

if(WaterSensed_State == E0_E1_SHORT)
{
	alarm_on();
	heater_on();

}
else
{
	alarm_off();
	heater_off();


}
*/

				
	            
			//-------------------------------------------------------------------------------------
				if ((WaterSensed_PrevState == E0_E1_SHORT  ) && ( WaterSensed_State == E0_E1_OPEN ))
				{
				Start_Timer(TIMER_0,5000); // For 5 Seconds
                pressuresw_Flag = FALSE;
				}
				else if (GetTimer_State(TIMER_0) ==TIMER_EXPIRED)
				{
				alarm_on();
				heater_off();
	         
				Stop_Timer(TIMER_0);
				
				}
			//-------------------------------------------------------------------------------------
				
				 
		 

	

//-------------------------------------------------------------------------------------
				if ((WaterSensed_PrevState == E0_E1_OPEN )  && ( WaterSensed_State == E0_E1_SHORT ))
			{
				Start_Timer(TIMER_1,5000);// For 5 Seconds
				}
			else  if (GetTimer_State(TIMER_1) ==TIMER_EXPIRED)
				{


				alarm_off();
				pressuresw_Flag = TRUE;
				Stop_Timer(TIMER_1);
				
				}

WaterSensed_PrevState =WaterSensed_State;
			//-------------------------------------------------------------------------------------
			
			
				if (E0_E1_UNKNOWN == WaterSensed_State) //ADC E0 is inbetween 1 and 2 Volts which is error case;
				{
					alarm_on();
					heater_off();
				
				}

			// Delay 2 sec
			//------------Pressure switch case----true---------------------------------------------------------------------
			
if (pressuresw_Flag)
  {
			Switch_State = read_pressure_switch();
			if ((Switch_PrevState == FALSE )&& (Switch_State == TRUE))
			{
				Start_Timer(TIMER_2,2000);
			
			}

			if ((GetTimer_State(TIMER_2) ==TIMER_EXPIRED) &&  (Switch_State == TRUE))		
			{
			heater_on();
			alarm_off();
			}
		
		
			 if(Switch_State == FALSE)
				{
				Stop_Timer(TIMER_2);
				heater_off();
			
				}
   }
		

			//----------------------------------------------------------------------------------------

	Switch_PrevState=Switch_State;
}

	else	{ // E1 voltage is  other than  1.25
		alarm_on();
		heater_off();
		}



 // While ends
}
}
}
Beispiel #10
0
int Fs_Edit()
{
    unsigned char   ch;
    int		    i, Changed = FALSE;
    char	    *filname, *tmpname;
    FILE	    *fd;

    Syslog('b', "FSEDIT: Entering FullScreen editor");
    if (utf8)
	chartran_init((char *)"CP437", (char *)"UTF-8", 'B');

    clear();
    InsMode = TRUE;
    TopVisible = 1;
    Col = 1;
    Row = 1;
    Refresh();

    while (TRUE) {
	Nopper();
	alarm_on();
	ch = Readkey();
	CurRow = Row + TopVisible - 1;

	switch (ch) {
	    case KEY_ENTER:
			    if (Col == 1) {
				/* Enter at beginning of line */
				for (i = Line; i >= CurRow; i--) {
				    snprintf(Message[i+1], TEXTBUFSIZE +1, "%s", Message[i]);
				}
				Message[i+1][0] = '\0';
			    } else {
				for (i = Line; i > CurRow; i--) {
				    snprintf(Message[i+1], TEXTBUFSIZE +1, "%s", Message[i]);
				}
				Message[CurRow+1][0] = '\0';
				if (Col <= strlen(Message[CurRow])) {
				    /* Enter in middle of line */
				    for (i = Col-1; i <= strlen(Message[CurRow]); i++) {
					snprintf(Message[CurRow+1] + strlen(Message[CurRow+1]), 5, "%c", Message[CurRow][i]);
				    }
				    Message[CurRow][Col-1] = '\0';
				}
				/* else Enter at end of line */
			    }
			    Line++;
			    Row++;
			    Col = 1;
			    if (Row >= (rows -1)) 
				ScrollDown();
			    Refresh();
			    Changed = TRUE;
			    break;

	    case ('N' - 64):  /* Insert line, scroll down */
			    for (i = Line; i >= CurRow; i--)
				snprintf(Message[i+1], TEXTBUFSIZE +1, "%s", Message[i]);
			    Message[CurRow][0] = '\0';
			    Line++;
			    Col = 1;
			    Refresh();
			    Changed = TRUE;
			    break;

	    case ('Y' - 64):  /* Erase line, scroll up */
			    if (Line == CurRow) {
				/* Erasing last line */
				if ((Line > 1) || (strlen(Message[CurRow]) > 0)) {
				    Message[CurRow][0] = '\0';
				    if (Line > 1) {
					Line--;
					if (Row == 1) 
					    ScrollUp();
					Row--;
				    }
				    if (Col > strlen(Message[CurRow]))
					Col = strlen(Message[CurRow]);
				    Refresh();
				    Changed = TRUE;
				} else
				    Beep();
			    } else {
				/* Erasing line in the middle */
				for (i = CurRow; i < Line; i++) {
				    snprintf(Message[i], TEXTBUFSIZE +1, "%s", Message[i+1]);
				}
				Message[i+1][0] = '\0';
				Line--;
				if (Col > strlen(Message[CurRow]) + 1)
				    Col = strlen(Message[CurRow]) + 1;
				Refresh();
				Changed = TRUE;
			    }
			    break;

	    case KEY_UP:
	    case ('E' - 64):
			    FsMove(KEY_UP);
			    break;

	    case KEY_DOWN:
	    case ('X' - 64):
			    FsMove(KEY_DOWN);
			    break;

	    case KEY_LEFT:
	    case ('S' - 64):
			    FsMove(KEY_LEFT);
			    break;

	    case KEY_RIGHT:
	    case ('D' - 64):
			    FsMove(KEY_RIGHT);
			    break;

	    case KEY_DEL:
			    if (Col <= strlen(Message[CurRow])) {
				/*
				 * If before the end of the line...
				 */
				Setcursor();
				for (i = Col; i <= strlen(Message[CurRow]); i++) {
				    Message[CurRow][i-1] = Message[CurRow][i];
				    PUTCHAR(Message[CurRow][i]);
				}
				PUTCHAR(' ');
				PUTCHAR('\b');
				Message[CurRow][i-1] = '\0';
				Setcursor();
			    } else if (((strlen(Message[CurRow]) + strlen(Message[CurRow+1]) < 75) 
				    || (strlen(Message[CurRow]) == 0)) && (CurRow < Line)) {
				for (i = 0; i < strlen(Message[CurRow+1]); i++)
				    snprintf(Message[CurRow] + strlen(Message[CurRow]), 5, "%c", Message[CurRow+1][i]);
				for (i = CurRow+1; i < Line; i++)
				    snprintf(Message[i], TEXTBUFSIZE +1, "%s", Message[i+1]);
				Message[Line][0] = '\0';
				Line--;
				Refresh();
			    } else
                                Beep();

			    /* 
			     * Trap the extra code so it isn't
			     * inserted in the text
			     */
			    if (ch == KEY_DEL) 
				Readkey();
			    break;

	    case KEY_BACKSPACE:
	    case KEY_RUBOUT:
			    if (Col == 1 && CurRow == 1) {
				/* BS on first character in message */
				Beep();
			    } else if (Col == 1) {
				/* BS at beginning of line */
				if ((strlen(Message[CurRow-1]) + strlen(Message[CurRow]) < 75) || strlen(Message[CurRow]) == 0) {
				    Col = strlen(Message[CurRow-1]) + 1;
				    strcat(Message[CurRow-1], Message[CurRow]);
				    for ( i = CurRow; i < Line; i++)
					snprintf(Message[i], TEXTBUFSIZE +1, "%s", Message[i+1]);
				    Message[i+1][0] = '\0';
				    Line--;
				    if (Row == 1) 
					ScrollUp();
				    Row--;
				    Refresh();
				    Changed = TRUE;
				} else {
				    i = strlen(Message[CurRow-1]) + strlen(Message[CurRow]);
				    Beep();
				}
			    } else {
				if (Col == strlen(Message[CurRow]) + 1) {
				    /* BS at end of line */
				    BackErase();
				    Col--;
				    Message[CurRow][Col-1] = '\0';
				    Changed = TRUE;
				} else {
				    /* BS in middle of line */
				    Col--;
				    Setcursor();
				    for (i = Col; i <= strlen(Message[CurRow]); i++) {
					Message[CurRow][i-1] = Message[CurRow][i];
					PUTCHAR(Message[CurRow][i]);
				    }
				    PUTCHAR(' ');
				    PUTCHAR('\b');
				    Message[CurRow][strlen(Message[CurRow])] = '\0';
				    Setcursor();
				    Changed = TRUE;
				}
			    }
			    break;

	    case KEY_INS:  /* Toggle Insert Mode */
	    case ('V' - 64):
			    InsMode = !InsMode;
			    Show_Ins();
			    colour(CFG.TextColourF, CFG.TextColourB);
			    Setcursor();
			    /* 
			     * Trap the extra code so it isn't
			     * inserted in the text
			     */
			    if (ch == KEY_INS) 
				Readkey();
			    break;

	    case ('L' - 64):  /* Refresh screen */
			    Refresh();
			    break;

	    case ('R' - 64):  /* Read from file */
			    Syslog('b', "FSEDIT: Read from file");

			    tmpname = calloc(PATH_MAX, sizeof(char));
			    filname = calloc(PATH_MAX, sizeof(char));

			    Enter(1);
			    /* Please enter filename: */
			    pout(YELLOW, BLACK, (char *) Language(245));
			    colour(CFG.InputColourF, CFG.InputColourB);
			    GetstrLC(filname, 80);

			    if ((strcmp(filname, "") == 0)) {
				Enter(2);
				/* No filename entered, aborting */
				pout(CFG.HiliteF, CFG.HiliteB, (char *) Language(246));
				Enter(1);
				Pause();
				free(filname);
				free(tmpname);
				Refresh();
				break;
			    }

			    if (*(filname) == '/' || *(filname) == ' ') {
				Enter(2);
				/* Illegal filename */
				pout(CFG.HiliteF, CFG.HiliteB, (char *) Language(247));
				Enter(1);
				Pause();
				free(tmpname);
				free(filname);
				Refresh();
				break;
			    }

			    snprintf(tmpname, PATH_MAX, "%s/%s/wrk/%s", CFG.bbs_usersdir, exitinfo.Name, filname);
			    if ((fd = fopen(tmpname, "r")) == NULL) {
				WriteError("$Can't open %s", tmpname);
				Enter(2);
				/* File does not exist, please try again */
				pout(CFG.HiliteF, CFG.HiliteB, (char *) Language(296));
				Enter(1);
				Pause();
			    } else {
				while ((fgets(filname, 80, fd)) != NULL) {
				    for (i = 0; i < strlen(filname); i++) {
					if (*(filname + i) == '\0')
					    break;
					if (*(filname + i) == '\n')
					    *(filname + i) = '\0';
					if (*(filname + i) == '\r')
					    *(filname + i) = '\0';
				    }
				    /*
				     * Make sure that any tear or origin lines are
				     * made invalid.
				     */
				    if (strncmp(filname, (char *)"--- ", 4) == 0)
					filname[1] = 'v';
				    if (strncmp(filname, (char *)" * Origin:", 10) == 0)
					filname[1] = '+';
				    snprintf(Message[Line], TEXTBUFSIZE +1, "%s", filname);
				    Line++;
				    if ((Line - 1) == TEXTBUFSIZE)
					break;
				}
				fclose(fd);
				Changed = TRUE;
				Syslog('+', "FSEDIT: Inserted file %s", tmpname);
			    }

			    free(tmpname);
			    free(filname);
			    Col = 1;
			    Refresh();
			    break;

	    case KEY_ESCAPE:  /* Editor menu */
			    Top_Menu();

			    ch = toupper(Readkey());
			    if (ch == 'A' || ch == 'S') {
				Syslog('b', "FSEDIT: %s message (%c)", (ch == 'S' && Changed) ? "Saving" : "Aborting", ch);
				clear();
				chartran_close();
				if (ch == 'S' && Changed) {
				    Syslog('+', "FSEDIT: Message will be saved");
				    return TRUE;
				} else {
				    Syslog('+', "FSEDIT: Message aborted");
				    return FALSE;
				}
			    }

			    if (ch == 'H') {
				Full_Help();
				ch = Readkey();
				Refresh();
			    } else
				Top_Help();

			    colour(CFG.TextColourF, CFG.TextColourB);
			    Setcursor();
			    break;
			
	    default:
			    if ((ch > 31) || traduce((char *)&ch) ) {
				/*
				 *  Normal printable characters or hi-ascii
				 */
				if (Col == strlen(Message[CurRow]) + 1) {
				    /*
				     *  Append to line
				     */
				    snprintf(Message[CurRow] + strlen(Message[CurRow]), 5, "%c", ch);
				    if (strlen(Message[CurRow]) > 79){
					Col = FsWordWrap();
					Row++;
					Refresh();
				    } else {
					Col++;
					PUTCHAR(ch);
				    }
				    Changed = TRUE;
				} else {
				    /*
				     *  Insert or overwrite
				     */
				    if (InsMode) {
					for (i = strlen(Message[CurRow]); i >= (Col-1); i--) {
					    /*
					     * Shift characters right
					     */
					    Message[CurRow][i+1] = Message[CurRow][i];
					}
					Message[CurRow][Col-1] = ch;
					Col++;
					if (strlen(Message[CurRow]) > 80) {
					    i = FsWordWrap();
					    if (Col > strlen(Message[CurRow])+1) {
						Col = Col - strlen(Message[CurRow]);
						if (Col > 1) 
						    Col--;
						Row++;
					    }
					    if (Row > (rows -1))
						ScrollDown();
					    else
						Refresh();
					} else {
					    locate(Row + 1, 1);
					    PUTSTR(Message[CurRow]);
					    Setcursor();
					}
					Changed = TRUE;
				    } else {
					Message[CurRow][Col-1] = ch;
					PUTCHAR(ch);
					Col++;
					Changed = TRUE;
				    }
				}
			    } 
	}
    }

    chartran_close();
    WriteError("FsEdit(): Impossible to be here");
    return FALSE;
}
Beispiel #11
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;
}
Beispiel #12
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();
}
Beispiel #13
0
/*
 * Upload files from the user.
 * Returns:
 *  0 - All seems well
 *  1 - No transfer protocol selected.
 *  2 - Transfer failed
 */
int upload(up_list **upload_list)
{
    char	    *temp;
    struct dirent   *dp;
    DIR		    *dirp;
    struct stat	    statfile;
    struct timeval  starttime, endtime;
    struct timezone tz;
    unsigned int    Size = 0;
    int		    err, Count = 0, rc = 0, want1k = FALSE, wantg = FALSE;
    up_list	    *tmp, *ta;

    /*
     * If user has no default protocol, make sure he has one.
     */
    if (!ForceProtocol()) {
	return 1;
    }

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

    /* Please start your upload now */
    snprintf(temp, PATH_MAX, "%s, %s", sProtAdvice, (char *) Language(283));
    pout(CFG.HiliteF, CFG.HiliteB, temp);
    Enter(2);
    Syslog('+', "Upload using %s", sProtName);

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

    if (chdir(temp)) {
	WriteError("$Can't chdir to %s", temp);
	free(temp);
	return 1;
    }
    sleep(2);

    if (uProtInternal) {
	if ((strncasecmp(sProtName, "zmodem", 6) == 0) || 
	    (strncasecmp(sProtName, "ymodem", 6) == 0) || 
	    (strncasecmp(sProtName, "xmodem", 6) == 0)) {

	    if (strncasecmp(sProtName, "zmodem", 6) == 0) {
		zmodem_requested = TRUE;
		protocol = ZM_ZMODEM;
	    } else {
		zmodem_requested = FALSE;
	    }
	    if (strncasecmp(sProtName, "ymodem", 6) == 0)
		protocol = ZM_YMODEM;
	    if (strncasecmp(sProtName, "xmodem", 6) == 0)
		protocol = ZM_XMODEM;

	    if (strstr(sProtName, "-1K") && (protocol != ZM_ZMODEM)) {
		Syslog('x', "%s: want 1K blocks", protname());
		want1k = TRUE;
	    }
	    if ((strstr(sProtName, "-G")) && (protocol == ZM_YMODEM)) {
		Syslog('x', "%s: want Ymodem-G", protname());
		wantg = TRUE;
	    }
	    rc = zmrcvfiles(want1k, wantg);

	    Syslog('b', "Begin dir processing");
	    if ((dirp = opendir(".")) == NULL) {
	        WriteError("$Upload: can't open ./upl");
	        Home();
	        rc = 1;
	    } else {
	        while ((dp = readdir(dirp)) != NULL) {
		    if (*(dp->d_name) != '.') {
			if (rc == 0) {
			    stat(dp->d_name, &statfile);
			    Syslog('b', "Uploaded \"%s\", %ld bytes", dp->d_name, statfile.st_size);
			    snprintf(temp, PATH_MAX, "%s/%s/upl/%s", CFG.bbs_usersdir, exitinfo.Name, dp->d_name);
			    chmod(temp, 0660);

			    /*
			     * Add uploaded file to the list
			     */
			    tmp = (up_list *)malloc(sizeof(up_list));
			    tmp->next = NULL;
			    tmp->filename = xstrcpy(temp);
			    tmp->size = Size;
			    if (*upload_list == NULL) {
				*upload_list = tmp;
			    } else {
				for (ta = *upload_list; ta; ta = ta->next) {
				    if (ta->next == NULL) {
					ta->next = (up_list *)tmp;
					break;
				    }
				}
			    }
			} else {
			    Syslog('+', "Remove failed %s result %d", dp->d_name, unlink(dp->d_name));
			}
		    }
		}
		closedir(dirp);
	    }
	} else {
	    Syslog('!', "Internal protocol %s not supported", sProtName);
	    free(temp);
	    return 1;
	}
    } else {
	/*
	 * External protocol
	 */
	gettimeofday(&starttime, &tz);
    
	Altime(7200);
	alarm_set(7190);
	err = execute_str(sProtUp, (char *)"", NULL, NULL, NULL, NULL);
	if (rawport() != 0) {
	    WriteError("Unable to set raw mode");
	}
	if (err) {
	    WriteError("$Upload error %d, prot: %s", err, sProtUp);
	    rc = 2;
	}
	Altime(0);
	alarm_off();
	alarm_on();

	gettimeofday(&endtime, &tz);

	/*
	 * With external protocols we don't know anything about what we got.
	 * Just check the files in the users upload directory.
	 */
	if ((dirp = opendir(".")) == NULL) {
	    WriteError("$Upload: can't open ./upl");
	    Home();
	    rc = 1;
	} else {
	    while ((dp = readdir(dirp)) != NULL) {
		if (*(dp->d_name) != '.') {
		    stat(dp->d_name, &statfile);
		    Syslog('+', "Uploaded \"%s\", %ld bytes", dp->d_name, statfile.st_size);
		    Count++;
		    Size += statfile.st_size;
		    snprintf(temp, PATH_MAX, "%s/%s/upl/%s", CFG.bbs_usersdir, exitinfo.Name, dp->d_name);
		    chmod(temp, 0660);

		    /*
		     * Add uploaded file to the list
		     */
		    tmp = (up_list *)malloc(sizeof(up_list));
		    tmp->next = NULL;
		    tmp->filename = xstrcpy(temp);
		    tmp->size = Size;

		    if (*upload_list == NULL) {
			*upload_list = tmp;
		    } else {
			for (ta = *upload_list; ta; ta = ta->next) {
			    if (ta->next == NULL) {
				ta->next = (up_list *)tmp;
				break;
			    }
			}
		    }
		}
	    }
	    closedir(dirp);
	    Syslog('+', "Upload %s in %d file(s)", transfertime(starttime, endtime, (unsigned int)Size, FALSE), Count);
	}
    }
    free(temp);
    Syslog('b', "Done, return rc=%d", rc);

    return rc;
}
Beispiel #14
0
/*
 * Download files to the user.
 * Returns:
 *  0 - All seems well
 *  1 - No transfer protocol selected
 *  2 - No files to download.
 */
int download(down_list *download_list)
{
    down_list	    *tmpf;
    int		    err, maxrc = 0, Count = 0;
    char	    *temp, *symTo, *symFrom;
    unsigned int    Size = 0;
    struct dirent   *dp;
    DIR		    *dirp;
    struct timeval  starttime, endtime;
    struct timezone tz;

    Syslog('b', "download()");
    for (tmpf = download_list; tmpf; tmpf = tmpf->next) {
	Syslog('b', "%s,%s,%ld,%ld,%ld,%s,%s,%s", tmpf->local, tmpf->remote, tmpf->cps, tmpf->area, tmpf->size,
		tmpf->kfs ?"KFS":"KEEP", tmpf->sent ?"SENT":"N/A", tmpf->failed ?"FAILED":"N/A");
    }

    /*
     * If user has no default protocol, make sure he has one.
     */
    if (!ForceProtocol()) {
	return 1;
    }

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

    /*
     * Build symlinks into the users tag directory.
     */
    chdir("./tag");
    for (tmpf = download_list; tmpf; tmpf = tmpf->next) {
        if (!tmpf->sent && !tmpf->failed) {
	    snprintf(symFrom, PATH_MAX, "%s/%s/tag/%s", CFG.bbs_usersdir, exitinfo.Name, tmpf->remote);
	    Syslog('b', "test \"%s\" \"%s\"", symFrom, tmpf->local);
	    if (strcmp(symFrom, tmpf->local)) {
		Syslog('b', "different, need a symlink");
		unlink(tmpf->remote);
		snprintf(symFrom, PATH_MAX, "%s", tmpf->remote);
		snprintf(symTo, PATH_MAX, "%s", tmpf->local);
		if (symlink(symTo, symFrom)) {
		    WriteError("$Can't create symlink %s %s %d", symTo, symFrom, errno);
		    tmpf->failed = TRUE;
		} else {
		    Syslog('b', "Created symlink %s -> %s", symFrom, symTo);
		}
		tmpf->kfs = FALSE;
	    } else {
		Syslog('b', "the same, file is in tag directory");
	    }

	    /*
	     * Check if file or symlink is really there.
	     */
	    snprintf(symFrom, PATH_MAX, "%s", tmpf->remote);
	    if ((access(symFrom, F_OK)) != 0) {
	        WriteError("File or symlink %s check failed, unmarking download", symFrom);
	        tmpf->failed = TRUE;
	    } else {
	        Count++;
		Size += tmpf->size;
	    }
	}
    }
    Home();

    if (!Count) {
        /*
         * Nothing to download
         */
        free(temp);
        free(symTo);
        free(symFrom);
        return 2;
    }

    clear();
    /* File(s)     : */
    pout(YELLOW, BLACK, (char *) Language(349)); snprintf(temp, PATH_MAX, "%d", Count);     PUTSTR(temp); Enter(1);
    /* Size        : */
    pout(  CYAN, BLACK, (char *) Language(350)); snprintf(temp, PATH_MAX, "%u", Size);      PUTSTR(temp); Enter(1);
    /* Protocol    : */
    pout(  CYAN, BLACK, (char *) Language(351)); snprintf(temp, PATH_MAX, "%s", sProtName); PUTSTR(temp); Enter(1);

    Syslog('+', "Download files start, protocol: %s", sProtName);

    PUTSTR(sProtAdvice);
    Enter(2);

    /*
     * Wait a while before download
     */
    sleep(2);
    
    if (uProtInternal) {
	snprintf(temp, PATH_MAX, "%s/%s/tag", CFG.bbs_usersdir, exitinfo.Name);
	chdir(temp);
	if (strncasecmp(sProtName, "zmodem-8k", 9) == 0) {
	    maxrc = zmsndfiles(download_list, TRUE);
	    Home();
	} else if (strncasecmp(sProtName, "zmodem", 6) == 0) {
	    maxrc = zmsndfiles(download_list, FALSE);
	    Home();
	} else if ((strncasecmp(sProtName, "xmodem", 6) == 0) || (strncasecmp(sProtName, "ymodem", 6) == 0)) {
	    if (strncasecmp(sProtName, "xmodem", 6) == 0)
		protocol = ZM_XMODEM;
	    else
		protocol = ZM_YMODEM;
	    if (strstr(sProtName, "1K") || strstr(sProtName, "1k"))
		maxrc = ymsndfiles(download_list, TRUE);
	    else
		maxrc = ymsndfiles(download_list, FALSE);
	    Home();
	} else {
	    Syslog('!', "Warning internal protocol %s not supported", sProtName);
	    maxrc = 1;
	}
    } else {
	gettimeofday(&starttime, &tz);

	/*
	 * Transfer the files. Set the Client/Server time at the maximum
	 * time the user has plus 10 minutes. The overall timer 10 seconds
	 * less. Not a nice but working solution.
	 */
	alarm_set(((exitinfo.iTimeLeft + 10) * 60) - 10);
	Altime((exitinfo.iTimeLeft + 10) * 60);

	snprintf(temp, PATH_MAX, "%s/%s/tag", CFG.bbs_usersdir, exitinfo.Name);
	if ((dirp = opendir(temp)) == NULL) {
	    WriteError("$Download: Can't open dir: %s", temp);
	    free(temp);
	} else {
	    chdir(temp);
	    free(temp);
	    temp = NULL;
	    while ((dp = readdir(dirp)) != NULL ) {
		if (*(dp->d_name) != '.') {
		    if (temp != NULL) {
			temp = xstrcat(temp, (char *)" ");
			temp = xstrcat(temp, dp->d_name);
		    } else {
			temp = xstrcpy(dp->d_name);
		    }
		}
	    }
	    if (temp != NULL) {
		if ((err = execute_str(sProtDn, temp, NULL, NULL, NULL, NULL))) {
		    WriteError("$Download error %d, prot: %s", err, sProtDn);
		}
		/*
		 * Restore rawport
		 */
		rawport();
		free(temp);
	    } else {
		WriteError("No filebatch created");
	    }
	    closedir(dirp);
	}

	purgeline(200); /* Wait a while, some Wintendo programs ignore input for a few seconds */
	Altime(0);
	alarm_off();
	alarm_on();
	Home();
	gettimeofday(&endtime, &tz);

	/*
	 * Checking the successfull sent files, they are missing from
	 * the ./tag directory. Failed files are still there.
	 */
	Count = Size = 0;

	for (tmpf = download_list; tmpf && (maxrc < 2); tmpf = tmpf->next) {
	    if (!tmpf->sent && !tmpf->failed) {
		snprintf(symTo, PATH_MAX, "./tag/%s", tmpf->remote);
		/*
		 * If symlink is gone the file is sent.
		 */
		if ((access(symTo, R_OK)) != 0) {
		    Syslog('+', "File %s from area %d sent ok", tmpf->remote, tmpf->area);
		    tmpf->sent = TRUE;
		    Size += tmpf->size;
		    Count++;
		} else {
		    Syslog('+', "Failed to sent %s from area %d", Tag.LFile, Tag.Area);
		}
	    }
	}

	/*
	 * Work out transfer rate in seconds by dividing the
	 * Size of the File by the amount of time it took to download 
	 * the file.
	 */
	Syslog('+', "Download %s in %d file(s)", transfertime(starttime, endtime, (unsigned int)Size, TRUE), Count);
    }
    
    free(symTo);
    free(symFrom);

    for (tmpf = download_list; tmpf; tmpf = tmpf->next) {
	Syslog('b', "%s,%s,%ld,%ld,%ld,%s,%s,%s", tmpf->local, tmpf->remote, tmpf->cps, tmpf->area, tmpf->size,
		tmpf->kfs ?"KFS":"KEEP", tmpf->sent ?"SENT":"N/A", tmpf->failed ?"FAILED":"N/A");
    }

    Syslog('b', "download() rc=%d", maxrc);
    return maxrc;
}
Beispiel #15
0
void menu()
{
    FILE    *pMenuFile;
    int	    Key, IsANSI;
    char    temp[81], *Input, *sMenuPathFileName, buf[81];

    Input = calloc(PATH_MAX, sizeof(char));
    sMenuPathFileName = calloc(PATH_MAX, sizeof(char));
    Syslog('+', "Starting menu loop");

    /* 
     * Loop forever, this is what a BBS should do until a user logs out.
     */
    while (TRUE) {

	WhosDoingWhat(BROWSING, NULL);

	/*
	 * Open menufile, first users language menu, if it fails
	 * try to open the default menu.
	 */
	snprintf(sMenuPathFileName, PATH_MAX, "%s/share/int/menus/%s/%s", getenv("FTND_ROOT"), lang.lc, Menus[MenuLevel]);
	if ((pMenuFile = fopen(sMenuPathFileName, "r")) == NULL) {
	    snprintf(sMenuPathFileName, PATH_MAX, "%s/share/int/menus/%s/%s", getenv("FTND_ROOT"), CFG.deflang, Menus[MenuLevel]);
	    pMenuFile = fopen(sMenuPathFileName,"r");
	    if (pMenuFile != NULL)
		Syslog('b', "Menu %s (Default)", Menus[MenuLevel]);
	} else {
	    Syslog('b', "Menu %s (%s)", Menus[MenuLevel], lang.Name);
	}

	if (pMenuFile == NULL) {
	    clear();
	    WriteError("Can't open menu file: %s", sMenuPathFileName);
	    MenuError++;

	    /*
	     * Is this the last attempt to open the default menu?
	     */
	    if (MenuError == 10) {
		WriteError("FATAL ERROR: Too many menu errors");
		snprintf(temp, 81, "Too many menu errors, notifying Sysop\r\n\r\n");
		PUTSTR(temp);
		sleep(3);
		die(FTNERR_CONFIG_ERROR);
	    }

	    /*
	     * Switch back to the default menu
	     */
	    MenuLevel = 0;
	    strcpy(Menus[0], CFG.default_menu);
	} else {
	    /*
	     * Display Menu Text Fields and Perform all autoexec menus in order of menu file.
	     * First check if there are any ANSI menus, if not, send a clearscreen first.
	     */
	    IsANSI = FALSE;
	    while (fread(&menus, sizeof(menus), 1, pMenuFile) == 1) {
		if ( Le_Access(exitinfo.Security, menus.MenuSecurity) && (UserAge >= le_int(menus.Age))){
		    if ((le_int(menus.MenuType) == 5) || (le_int(menus.MenuType) == 19) || (le_int(menus.MenuType) == 20))
			IsANSI = TRUE;
		}
	    }
	    fseek(pMenuFile, 0, SEEK_SET);
	    if (! IsANSI)
		clear();

	    while (fread(&menus, sizeof(menus), 1, pMenuFile) == 1) {
		if ( Le_Access(exitinfo.Security, menus.MenuSecurity) && (UserAge >= le_int(menus.Age))){
		    if (menus.AutoExec) {
			DoMenu( le_int(menus.MenuType) );
		    }
		    DisplayMenu( ); 
		}
	    }

	    /*
	     * Check if the BBS closed down for Zone Mail Hour or
	     * system shutdown. If so, we run the Goodbye show.
	     */
	    if (CheckStatus() == FALSE) {
		fclose(pMenuFile);
		Syslog('+', "Kicking user out, the BBS is closed.");
		sleep(3);
		Good_Bye(FTNERR_OK);
	    }

	    /*
	     * Check the upsdown semafore
	     */
	    if (IsSema((char *)"upsdown")) {
		fclose(pMenuFile);
		Syslog('+', "Kicking user out, upsdown semafore detected");
		snprintf(temp, 81, "System power failure, closing the bbs");
		PUTSTR(temp);
		Enter(2);
		sleep(3);
		Good_Bye(FTNERR_OK);
	    }

	    /*
	     * Check if SysOp wants to chat to user everytime user gets prompt.
	     */
	    if (CFG.iChatPromptChk) {
		snprintf(buf, 81, "CISC:1,%d", mypid);
		if (socket_send(buf) == 0) {
		    strcpy(buf, socket_receive());
		    if (strcmp(buf, "100:1,1;") == 0) {
			Syslog('+', "Forced sysop/user chat");
			Chat(exitinfo.Name, (char *)"#sysop");
			continue;
		    }
		}
	    }

	    /*
	     * Check users timeleft
	     */
	    TimeCheck();
	    alarm_on();

	    if (exitinfo.HotKeys) {
		Key = Readkey();
		snprintf(Input, 81, "%c", Key);
		Enter(1);
	    } else {
		colour(CFG.InputColourF, CFG.InputColourB);
		GetstrC(Input, 80);
	    }

	    if ((strcmp(Input, "")) != 0) {

		fseek(pMenuFile, 0, SEEK_SET);

		while (fread(&menus, sizeof(menus), 1, pMenuFile) == 1) {
		 
		    if ((strcmp(tu(Input), menus.MenuKey)) == 0) {
			if ((Le_Access(exitinfo.Security, menus.MenuSecurity)) && (UserAge >= le_int(menus.Age))) {
			    Syslog('+', "Menu[%d] %d=(%s), Opt: '%s'", MenuLevel, le_int(menus.MenuType), 
					menus.TypeDesc, menus.OptionalData);
			    if (le_int(menus.MenuType) == 13) {
				/*
				 *  Terminate call, cleanup here
				 */
				free(Input);
				free(sMenuPathFileName);
				fclose(pMenuFile);
			    }
			    DoMenu(le_int(menus.MenuType));
			    break;
			}
		    }
		}
	    }
	    fclose(pMenuFile);

	} /* If menu open */
    } /* while true */
}
Beispiel #16
0
/*
 * Change default archiver.
 */
void Chg_Archiver()
{
    FILE    *fp;
    int	    Found = FALSE;
    char    *temp;

    temp = calloc(PATH_MAX, sizeof(char));
    ReadExitinfo();
    Syslog('+', "Old archiver %s", exitinfo.Archiver);

    while(TRUE) {
	snprintf(temp, PATH_MAX, "%s/etc/archiver.data", getenv("FTND_ROOT"));

	if ((fp = fopen(temp, "r")) == NULL) {
	    WriteError("$Can't open %s", temp);
	    /* Can't open archiver file. */
	    Enter(1);
	    PUTSTR((char *) Language(86));
	    Enter(2);
	    Pause();
	    free(temp);
	    return;
	}
	fread(&archiverhdr, sizeof(archiverhdr), 1, fp);

	Enter(1);
	/* Select your preferred archiver */
	pout(CFG.HiliteF, CFG.HiliteB, (char *) Language(87));
	Enter(2);
	while (fread(&archiver, archiverhdr.recsize, 1, fp) == 1) {
	    if (archiver.available && strlen(archiver.marc) && strlen(archiver.farc)) {
		colour(LIGHTBLUE, BLACK);
		snprintf(temp, 81, "%-6s", archiver.name);
		PUTSTR(temp);
		colour(WHITE, BLACK);
		snprintf(temp, 81, "%s\r\n", archiver.comment);
		PUTSTR(temp);
	    }
	}

	Enter(1);
	/* Select Archiver (Enter to Quit): */
	pout(CFG.HiliteF, CFG.HiliteB, (char *) Language(88));

	alarm_on();
	memset(temp, 0, PATH_MAX);
	GetstrC(temp, 5);
	if (strlen(temp) == 0) {
	    free(temp);
	    return;
	}

	Found = FALSE;
	fseek(fp, archiverhdr.hdrsize, SEEK_SET);
	while (fread(&archiver, archiverhdr.recsize, 1, fp) == 1) {
	    if (archiver.available && strlen(archiver.marc) && strlen(archiver.farc)) {
		if (strcasecmp(archiver.name, temp) == 0) {
		    /* Valid input, set new archiver */
		    Found = TRUE;
		    break;
		}
	    }
	}
	fclose(fp);

	if (Found)
	    break;

	Enter(2);
	/* Invalid selection, please try again! */
	pout(LIGHTGREEN, BLACK, (char *) Language(265));
	Enter(2);
	/* Loop for new attempt */
    }

    strncpy(exitinfo.Archiver, archiver.name, 6);
    /* Archiver now set to: */
    snprintf(temp, 81, "%s %s", Language(89), exitinfo.Archiver);
    colour(WHITE, BLACK);
    PUTSTR(temp);
    Syslog('+', "New archiver %s", exitinfo.Archiver);
    WriteExitinfo();
    free(temp);
    Enter(2);
    Pause();
}
Beispiel #17
0
/*
 * Change default protocol.
 */
void Chg_Protocol()
{
    FILE    *pProtConfig;
    int	    iProt, iFoundProt = FALSE, precno = 0;
    char    *temp, Prot[2];

    temp = calloc(PATH_MAX, sizeof(char));
    ReadExitinfo();
    Set_Protocol(exitinfo.sProtocol);
    Syslog('+', "Old protocol %s", sProtName);

    while(TRUE) {
	snprintf(temp, PATH_MAX, "%s/etc/protocol.data", getenv("FTND_ROOT"));
	
	if ((pProtConfig = fopen(temp, "r")) == NULL) {
	    WriteError("$Can't open %s", temp);
	    /* Protocol: Can't open protocol file. */
	    Enter(1);
	    PUTSTR((char *) Language(262));
	    Enter(2);
	    Pause();
	    free(temp);
	    fclose(pProtConfig);
	    return;
	}
	fread(&PROThdr, sizeof(PROThdr), 1, pProtConfig);

	Enter(1);
	/* Select your preferred protocol */
	pout(CFG.HiliteF, CFG.HiliteB, (char *) Language(263));
	Enter(2);

	while (fread(&PROT, PROThdr.recsize, 1, pProtConfig) == 1) {
	    if (PROT.Available && Access(exitinfo.Security, PROT.Level)) {
		colour(LIGHTBLUE, BLACK);
		PUTCHAR('(');
		colour(WHITE, BLACK);
		PUTSTR(PROT.ProtKey);
		colour(LIGHTBLUE, BLACK);
		snprintf(temp, 81, ")  %-20s Efficiency %3d %%\r\n", PROT.ProtName, PROT.Efficiency);
		PUTSTR(temp);
	    }
	}
	
	Enter(1);
        pout(CFG.HiliteF, CFG.HiliteB, (char *) Language(264));

        alarm_on();
        iProt = toupper(Readkey());

        PUTCHAR(iProt);
        snprintf(Prot, 2, "%c", iProt);

        fseek(pProtConfig, PROThdr.hdrsize, 0);
        while (fread(&PROT, PROThdr.recsize, 1, pProtConfig) == 1) {
	    if ((strncmp(PROT.ProtKey, Prot, 1) == 0) && PROT.Available && Access(exitinfo.Security, PROT.Level)) {
	        strcpy(sProtName, PROT.ProtName);
	        strcpy(sProtUp, PROT.ProtUp);
	        strcpy(sProtDn, PROT.ProtDn);
	        strcpy(sProtAdvice, PROT.Advice);
	        uProtInternal = PROT.Internal;
	        iProtEfficiency = PROT.Efficiency;
	        iFoundProt = TRUE;
	    } else
	        precno++;
	}

        fclose(pProtConfig);

        if (iProt == 13) {
	    free(temp);
	    return;
	} else {
	    if (!iFoundProt) {
	        Enter(2);
	        pout(LIGHTGREEN, BLACK, (char *) Language(265));
	        Enter(2);
	        /* Loop for new attempt */
	    } else {
	        Setup(exitinfo.sProtocol, sProtName);
	        Enter(1);
	        /* Protocol now set to: */
	        pout(LIGHTGREEN, BLACK, (char *) Language(266));
		PUTSTR(sProtName);
	        Enter(2);
	        Pause();
	        break;
	    }
	}
    }

    Syslog('+', "New protocol %s", sProtName);
    WriteExitinfo();
    free(temp);
}
Beispiel #18
0
/*
 * Chat, if the parameters are not NULL, a connection with the named
 * channel is made with the give username which will be forced to the
 * used nick name. This mode is used for forced sysop chat.
 * If the parameters are NULL, then it's up to the user what happens.
 */
void Chat(char *username, char *channel)
{
    int		    width, curpos = 0, stop = FALSE, data, rc;
    unsigned char   ch;
    char	    sbuf[81], resp[128], *name, *mname;
    static char	    buf[200];
    time_t	    c_start, c_end;


    WhosDoingWhat(SYSOPCHAT, NULL);
    clear();

    rsize = rows - 5;
    rpointer = 0;

    if (SYSOP == TRUE) {
	/*
	 * Forbid the sysop to chat, the sysop MUST use mbmon.
	 */
	Syslog('+', "The Sysop attempted to chat");
	pout(LIGHTRED, BLACK, (char *) Language(29));
	Enter(1);
	Pause();
	return;
    }
   
    if (username && channel) {
	colour(LIGHTGREEN, BLACK);
	PUTCHAR('\007');
	/* *** Sysop is starting chat *** */
	pout(LIGHTGREEN, BLACK, (char *) Language(59));
	Enter(1);
	sleep(1);
	PUTCHAR('\007');
	sleep(1);
	PUTCHAR('\007');
	Syslog('+', "Sysop chat started");
	chat_with_sysop = TRUE;
    } else {
	Syslog('+', "User started chatting");
    }
    
    /*
     * Setup the screen, this is only possible in ANSI mode.
     */
    clear();
    locate(1, 1);
    colour(WHITE, BLUE);
    snprintf(buf, 200, "%-*s", cols, " MBSE BBS Chat Server");
    mvprintw(1, 1, buf);

    mname = xstrcpy(clencode(exitinfo.sUserName));
    name  = xstrcpy(clencode(exitinfo.Name));
    width = cols - (strlen(name) + 3);
    snprintf(buf, 200, "CCON,4,%d,%s,%s,0;", mypid, mname, name);
    free(mname);
    free(name);
    if (socket_send(buf) == 0) {
	strncpy(buf, socket_receive(), sizeof(buf)-1);
	if (strncmp(buf, "200:1,", 6) == 0) {
	    Syslog('!', "Chat server is not available");
	    colour(LIGHTRED, BLACK);
	    mvprintw(4, 1, (char *) Language(30));
	    Enter(2);
	    Pause();
	    chat_with_sysop = FALSE;
	    return;
	}
    }

    locate(rows - 2, 1);
    colour(WHITE, BLUE);
    snprintf(buf, 200, "%-*s", cols, " Type \"/EXIT\" to exit or \"/HELP\" for help.");
    mvprintw(rows - 2, 1, buf);

    colour(WHITE, BLACK);
    mvprintw(rows - 1, 1, ">");
    mvprintw(rows - 1, width + 2, "<");
    memset(&sbuf, 0, sizeof(sbuf));
    memset(&rbuf, 0, sizeof(rbuf));
    colour(LIGHTGRAY, BLACK);

    /*
     * If username and channelname are given, send the /nick and /join
     * commands to the chatserver.
     */
    if (username && channel) {
	snprintf(buf, 200, "CPUT:2,%d,/nick %s;", mypid, clencode(username));
	if (socket_send(buf) == 0)
	    strcpy(buf, socket_receive());
	snprintf(buf, 200, "CPUT:2,%d,/join %s;", mypid, clencode(channel));
	if (socket_send(buf) == 0)
	    strcpy(buf, socket_receive());
    }

    chatting = TRUE;
    c_start = time(NULL);

    while (stop == FALSE) {

	/*
	 * Check for new message, loop fast until no more data available.
	 */
	data = TRUE;
	while (data) {
	    snprintf(buf, 200, "CGET:1,%d;", mypid);
	    if (socket_send(buf) == 0) {
		strncpy(buf, socket_receive(), sizeof(buf)-1);
		if (strncmp(buf, "100:2,", 6) == 0) {
		    strncpy(resp, strtok(buf, ":"), 10);    /* Should be 100        */
		    strncpy(resp, strtok(NULL, ","), 5);    /* Should be 2          */
		    strncpy(resp, strtok(NULL, ","), 5);    /* 1= fatal, chat ended */
		    rc = atoi(resp);
		    memset(&resp, 0, sizeof(resp));
		    strncpy(resp, cldecode(strtok(NULL, ";")), 80);  /* The message          */
		    DispMsg(resp);
		    if (rc == 1) {
			Syslog('+', "Chat server error: %s", resp);
			stop = TRUE;
			data = FALSE;
		    }
		} else {
		    data = FALSE;
		}
	    }
	}

	if (stop)
	    break;

        /*
	 * Check for a pressed key, if so then process it.
	 * Allow hi-ascii for multi-language.
	 */
	ch = testkey(rows -1, curpos + 2);
	if ((ch == KEY_BACKSPACE) || (ch == KEY_RUBOUT) || (ch == KEY_DEL)) {
	    alarm_on();
	    if (curpos) {
		curpos--;
		sbuf[curpos] = '\0';
		BackErase();
	    } else {
		PUTCHAR(7);
	    }
	/* if KEY_DEL isprint, do no output again */
	} else if (isprint(ch) || traduce((char *)&ch)) {
	    alarm_on();
	    if (curpos < width) {
		PUTCHAR(ch);
		sbuf[curpos] = ch;
		curpos++;
	    } else {
		PUTCHAR(7);
	    }
	} else if ((ch == '\r') && curpos) {
	    alarm_on();
	    snprintf(buf, 200, "CPUT:2,%d,%s;", mypid, clencode(sbuf));
	    if (socket_send(buf) == 0) {
		strcpy(buf, socket_receive());
		if (strncmp(buf, "100:2,", 6) == 0) {
		    strncpy(resp, strtok(buf, ":"), 10);    /* Should be 100            */
		    strncpy(resp, strtok(NULL, ","), 5);    /* Should be 2              */
		    strncpy(resp, strtok(NULL, ","), 5);    /* 1= fatal, chat ended	*/
		    rc = atoi(resp);
		    strncpy(resp, cldecode(strtok(NULL, ";")), 80);  /* The message              */
		    DispMsg(resp);
		    if (rc == 1) {
			Syslog('+', "Chat server error: %s", resp);
			stop = TRUE;
		    }
		}
	    }
	    curpos = 0;
	    memset(&sbuf, 0, sizeof(sbuf));
	    locate(rows - 1, 2);
	    clrtoeol();
	    colour(WHITE, BLACK);
	    mvprintw(rows - 1, 1, ">");
	    mvprintw(rows - 1, width + 2, "<");
	    colour(LIGHTGRAY, BLACK);
	}
    }
    chatting = FALSE;
    c_end = time(NULL);
    mib_chats++;
    mib_chatminutes += (unsigned int) ((c_end - c_start) / 60);


    /* 
     * Before sending the close command, purge all outstanding messages.
     */
    data = TRUE;
    while (data) {
	snprintf(buf, 200, "CGET:1,%d;", mypid);
	if (socket_send(buf) == 0) {
	    strncpy(buf, socket_receive(), sizeof(buf)-1);
	    if (strncmp(buf, "100:2,", 6) == 0) {
		strncpy(resp, strtok(buf, ":"), 10);    /* Should be 100        */
		strncpy(resp, strtok(NULL, ","), 5);    /* Should be 2          */
		strncpy(resp, strtok(NULL, ","), 5);	/* 1= fatal error	*/
		rc = atoi(resp);
		memset(&resp, 0, sizeof(resp));
		strncpy(resp, cldecode(strtok(NULL, ";")), 80);  /* The message          */
		DispMsg(resp);
		if (rc == 1) {
		    Syslog('+', "Chat server error: %s", resp);
		    data = FALSE;   /* Even if there is more, prevent a loop */
		}
	    } else {
		data = FALSE;
	    }
	}
    }

    if (username && channel) {
	/*
	 * Disjoin sysop channel
	 */

	/* *** Sysop has terminated chat *** */
	snprintf(buf, 200, "%s", (char *) Language(60));
	DispMsg(buf);
	Syslog('+', "Sysop chat ended");
	chat_with_sysop = FALSE;
    } else {
	Syslog('+', "User chat ended");
    }

    /*
     * Close server connection
     */
    snprintf(buf, 200, "CCLO,1,%d;", mypid);
    if (socket_send(buf) == 0) {
	strcpy(buf, socket_receive());
    }
    sleep(2);
    clear();
}
Beispiel #19
0
/*
 * Edit signature file with a simple line editor.
 */
int editsignature(void)
{
    FILE    *fp;
    int	    i, x;
    char    *temp, *temp1;

    temp  = calloc(PATH_MAX, sizeof(char));
    temp1 = calloc(PATH_MAX, sizeof(char));
    snprintf(temp, PATH_MAX, "%s/%s/.signature", CFG.bbs_usersdir, exitinfo.Name);

    while (TRUE) {
	Enter(1);
	/* Functions available: */
	poutCR(CFG.HiliteF, CFG.HiliteB, (char *) Language(113));
	Enter(1);
	/* (L)ist, (R)eplace text, (E)dit line, (A)bort, (S)ave */
	pout(YELLOW, RED, (char *) Language(114));
	Enter(2);

	/* Select: */
  	pout(CFG.HiliteF, CFG.HiliteB, (char *) Language(115));

	alarm_on();
	i = toupper(Readkey());
	Enter(1);

	if (i == Keystroke(114, 3)) {
	    /* Aborting... */
	    pout(CFG.HiliteF, CFG.HiliteB, (char *) Language(116));
	    Syslog('+', "User aborted .signature editor");
	    free(temp);
	    free(temp1);
	    return TRUE;

	} else if (i == Keystroke(114, 2)) {
	    Enter(1);
	    /* Edit which line: */
	    snprintf(temp, 80, " %s", (char *) Language(118));
	    pout(CFG.HiliteF, CFG.HiliteB, temp);
	    colour(CFG.InputColourF, CFG.InputColourB);
	    GetstrC(temp, 3);

	    if ((strcmp(temp, "")) == 0)
		break;

	    i = atoi(temp);
	    if ((i < 1) || (i > MAXSIGLINES)) {
		Enter(1);
		/* Line does not exist. */
		poutCR(LIGHTRED, BLACK, (char *) Language(119));
		break;
	    }

	    x = strlen(sLiNE[i-1]);
	    snprintf(temp, 80, "%d:", i);
	    pout(LIGHTRED, BLACK, temp);
	    pout(CFG.InputColourF, CFG.InputColourB, sLiNE[i-1]);
	    GetstrP(sLiNE[i-1], LENSIGLINES-1, x);

	} else if (i == Keystroke(114, 0)) {
	    /* List lines */
	    toprow();
	    for (i = 0; i < MAXSIGLINES; i++) {
		snprintf(temp, 80, "%d:", i+1);
		pout(LIGHTRED, BLACK, temp);
		poutCR(CFG.MoreF, CFG.MoreB, sLiNE[i]);
	    }
	    botrow();

	} else if (i == Keystroke(114, 4)) {
	    Enter(1);
	    /* Saving... */
	    pout(CFG.HiliteF, CFG.HiliteB, (char *) Language(340));

	    /* Open TextFile for Writing NextUser Info */
	    snprintf(temp, PATH_MAX, "%s/%s/.signature", CFG.bbs_usersdir, exitinfo.Name);
	    if ((fp = fopen(temp, "w")) == NULL) {
		WriteError("$Can't open %s", temp);
		free(temp);
		free(temp1);
		return TRUE;
	    }
	    for (i = 0; i < MAXSIGLINES; i++) {
		if (strlen(sLiNE[i]))
		    fprintf(fp, "%s\n", sLiNE[i]);
	    }
	    fclose(fp);
		
	    Syslog('+', "User Saved .signature");
	    free(temp);
	    free(temp1);
	    return TRUE;

	} else if (i == Keystroke(114, 1)) {
	    Enter(1);
	    /* Edit which line: */
	    pout(CFG.HiliteF, CFG.HiliteB, (char *) Language(118));
	    colour(CFG.InputColourF, CFG.InputColourB);
	    GetstrC(temp, 3);

	    if ((strcmp(temp, "")) == 0)
		break;

	    i = atoi(temp);

	    if ((i < 1) || (i > MAXSIGLINES)) {
		Enter(1);
		/* Line does not exist. */
		poutCR(LIGHTRED, BLACK, (char *) Language(119));
		break;
	    }

	    Enter(1);
	    /* Line reads: */
	    poutCR(CFG.MoreF, CFG.MoreB, (char *) Language(186));
	    snprintf(temp, 81, "%d:%s", i, sLiNE[i-1]);
	    poutCR(CFG.MoreF, CFG.MoreB, temp);

	    Enter(1);
	    /* Text to replace: */
	    pout(CFG.HiliteF, CFG.HiliteB, (char *) Language(195));
	    colour(CFG.InputColourF, CFG.InputColourB);
	    GetstrC(temp, LENSIGLINES-1);

	    if ((strcmp(temp, "")) == 0)
		break;

	    /* Replacement text: */
	    pout(CFG.HiliteF, CFG.HiliteB, (char *) Language(196));
	    colour(CFG.InputColourF, CFG.InputColourB);
	    GetstrC(temp1, LENSIGLINES-1);

	    if ((strcmp(temp1, "")) == 0)
		break;
	    strreplace(sLiNE[i-1], temp, temp1);

	} else
	    Enter(1);
    }

    free(temp);
    free(temp1);
    return FALSE;
}