Ejemplo n.º 1
0
int doaxui(int argc, char *argv[],void *p) {
char *cp;
char name[AXBUF];
char buf[256];
int i;
char tmpcall[AXALEN];
char tmpcall2[AXALEN];
struct session *sp;
struct mbuf *bp;
struct iface *axif,*ifc;
int first = 1;

	int goto_restart = 0, goto_done = 0;
  
	/* Check if this comes from console */
	if(Curproc->input != Command->input)
		return 1;

	/* Check to see if AXUI is already running. Only one copy at a time */
	if (Axui_sock != -1)	{
		tprintf("%s already running\n", Sestypes[AXUITNC]);
		return 1;
	}

	if(((axif = if_lookup(argv[1])) == NULLIF) || (axif->type != CL_AX25)) {
		tprintf("Iface %s not defined or not an AX25 type interface\n",argv[1]);
		return 1;
	}

	if (argc == 2 || setcall (tmpcall, argv[2]) == -1)
		memcpy (tmpcall, Ax25multi[IDCALL], AXALEN);
        if(argc > 3)  /* digis present? */
            if(connect_filt(argc,argv,tmpcall,axif) == 0)
                return 1;

	/* Now everything seems okay ! Get a session */
	if((sp = newsession("axui",AXUITNC,1)) == NULLSESSION) {
		j2tputs(TooManySessions);
		return 1;
	}

	while (1)
	{

/* restart: replace GOTO label with while loop */

	tprintf("%s%s session %u UI frames %s->%s on interface %s\n",
		(first) ? "" : "\n", Sestypes[sp->type],sp->num,
			pax25(buf, axif->hwaddr), pax25(name,tmpcall), axif->name);
	Axui_sock = Curproc->output;
	first = 0;
  
	/* Process whatever's typed on the terminal */
	while(recvline(Curproc->input,buf,sizeof(buf)-1) >= 0)
	{
		goto_restart = 0;	/* replaces GOTO label */
		goto_done = 0;		/* replaces GOTO label */

		if(buf[0] == '/')
		{
			rip (buf);
			cp = skipnonwhite(buf);  /* advance to first arg */
			cp = skipwhite(cp);

			/* process commands */
			switch(tolower(buf[1]))
			{
				case 'h':
				case '?':
						j2tputs("<Cmds>: /c call; /i iface; /q (to quit); /t (toggle timestamp)\n");
						goto_restart = 1;
						break;
				case 'c':
						if (argc > 3)
						{
							j2tputs(DigisUsed);
							break;
						}
						if (setcall (tmpcall2, cp) == -1)
							break;
						memcpy (tmpcall, tmpcall2, AXALEN);
						goto_restart = 1;
						break;
				case 'i':
						if (argc > 3)
						{
							j2tputs(DigisUsed);
							break;
						}
						if(((ifc = if_lookup(cp)) != NULLIF)
							&& (ifc->type == CL_AX25))
						{
							axif = ifc;
							goto_restart = 1;
						}
						else
							j2tputs ("<invalid interface>\n");
						break;
				case 'b':
				case 'e':
				case 'q':
						goto_done = 1;
						break;
				case 't':
						ui_timestamp = !ui_timestamp;
						break;
			}
			if (goto_done)	/* replaces GOTO 'done:' label */
				break;
			if (goto_restart)	/* replaces GOTO 'restart:' label */
				break;
		}
		else
		{
			i = strlen(buf);
			if((bp = alloc_mbuf(i)) == NULLBUF)
				break;

			/* unwritten protocol is that AX.25 lines end in \r, not \n.
			 * recvline will always return at least one character.  If the
			 * operater typed more than sizeof(buf) - 1 without eol,
			 * TOUGH! - K5JB
			 */
			buf[i - 1] = '\r';

			bp->cnt = i;	
			memcpy(bp->data,buf,(size_t)i);

			/* send it */
			(*axif->output)(axif, tmpcall, axif->hwaddr, PID_NO_L3, bp);
		}
		usflush(Curproc->output);
	}

	if (!goto_restart)	/* means the recv_line while naturally exited */
		break;			/* this covers the goto_done cases nicely */

	}	/* end of GOTO while loop */

/* done: */
	if (argc > 3)	/* remove digi route added by connect_filt */
		ax_drop(tmpcall, axif, 0);
	Axui_sock = -1;
	tprintf("\n%s session %u closed: EOF\n", Sestypes[sp->type],sp->num);
	keywait(NULLCHAR,1);
	freesession(sp);
	return 0;
}
Ejemplo n.º 2
0
int do_sysop(int argc, char **argv)
{
	int i, len;
	char *p;
	int net_pos[5];
	time_t md5key;
	char md5str[40];
	char source[256];
	char netrom[6];

	md5key = time(NULL);
	srandom(md5key);
	len = strlen (cfg.password);

	for (i = 0; i < 5; i++)
	{
		net_pos[i] = (random () % len);
		netrom[i] = cfg.password[net_pos[i]];
	}
	netrom[i] = '\0';

	node_msg("%s> %d %d %d %d %d [%010ld]", 
			cfg.alt_callsign, 
			net_pos[0] + 1,
			net_pos[1] + 1,
			net_pos[2] + 1,
			net_pos[3] + 1,
			net_pos[4] + 1,
			md5key);

	sprintf(source, "%010ld%s", md5key, cfg.password);
	MD5String(md5str, source);

	usflush(User.fd);
	User.state = STATE_IDLE;
	time(&User.cmdtime);
	update_user();
	alarm(IdleTimeout);
	for (;;)
	{
		if ((p = readline(User.fd)) == NULL) 
		{
			if (errno == EINTR)
				continue;
			logout("User disconnected");
		}
		break;
	}

	/* Plain text */
	if (strcasecmp(p, cfg.password) == 0)
	{
		sys_mode = 1;
		node_msg("Pass OK");
	}
	/* NetRom */
	else if (strcasecmp(p, netrom) == 0)
	{
		sys_mode = 1;
		node_msg("Nrom OK");
	}
	/* MD5 */
	else if (strcasecmp(p, md5str) == 0)
	{
		sys_mode = 1;
		node_msg("MD5 OK");
	}
	
	return(0);
}
Ejemplo n.º 3
0
void dxp_machine (int dev, HFDD_PARAMS *hfddp)
{
	int c, bbs_mode = 0;

	hfdd_state = init;

	hfdd_conn_flag = 0;	/* default no connected */ 
 
	/* 19Feb2005, Maiko, Okay DXP now has bbs mode as well */
	if (!memcmp ("bbs", hfddp->call, 3))
		bbs_mode = 1;

    while (hfdd_state != finished)
	{
		if (pwait (NULL))
			break;

		/* move init and connect into the machine now */
		switch (hfdd_state)
		{
			case init:
				dxp_init (dev, hfddp->pactor);
				hfdd_state = call;
				break;

			case call:
			/* 19Feb2005, Maiko, Okay DXP now has bbs mode as well */
				if (!bbs_mode)
					dxp_connect (dev, hfddp->call, hfddp->pactor);
				hfdd_state = called;	
				break;

			case idle:
			case called:
			case connected:
			case finished:
				break;
		}

		if ((c = get_asy (dev)) == -1)
			break;

		if (c == 0x80)
		{
#ifdef	DEBUG
			log_flush ();
#endif
    		if ((c = get_asy (dev)) == -1)
				break;

			/* 04Oct2006, Maiko, More restructuring, etc */

			if (c == 0x7a)
			{
				if (dxp_fsk_status (dev) == -1)
					break;

				continue;
			}

			if (dxp_status (dev, c) == -1)
				break;

			if (c == 0x23 || c == 0x24)
			{
				if (dxp_eat_the_END (dev) == -1)
					break;

				if (hfddp->keyboard)
				{
					if (c == 0x23)
						tprintf ("*** disconnected from %s\n", hfddp->call);
					else
						tprintf ("*** failure with %s\n", hfddp->call);
				}

				hfdd_state = finished;

				break;
			}
			/* 22Jan2005, Maiko, Stumbled across this new one */
			else if (c == 0x09)
			{
				if (hfddp->keyboard)
					tprintf ("*** modem reset\n");

				hfdd_state = finished;

				break;
			}
			/*
			 * 21Jan2005, Maiko, Added 'signal lost' conditional
			 * 14Feb2005, Maiko, Oops, HalComm says I should ignore this,
			 * since the modem will send me the link failed status (8024)
			 * when the link actually fails !!! I should NOT be terminating
			 * session on 'signal lost' conditions. Just warn the user !
			 */
			else if (c == 0x25)
			{
				if (dxp_eat_the_END (dev) == -1)
					break;

				if (hfddp->keyboard)
					tprintf ("*** signal lost with %s\n", hfddp->call);

				break;
			}
			else if (bbs_mode || (hfdd_state == call) || (hfdd_state == called))
			{
				if (c == 0x10)
				{
					if (hfddp->keyboard)
						j2tputs ("Trying... Escape sequence is: +++<CR>\n");
				}
				/* 16Feb2005, Maiko, Added P-Mode connected flag */
				else if ((c == 0x20) || (c == 0x2b))
				{
					if (bbs_mode)
					{
						/* 05Mar2005, Maiko, Get incoming callsign */
						if (dxp_get_incall (dev, hfddp->call) == -1)
						{
							log (-1, "dxp_get_incall () failed !!!");
							hfdd_state = finished;
							break;
						}

						/* 09Oct2006, Maiko, Lower case the call */
	                    strlwr (hfddp->call);

						/* 06Mar2005, Maiko, Now a generic function */
   						hfdd_mbox (dev, mbxs,
							(void*)TTY_LINK, (void*)(hfddp->call));
					}
					else
					{
						if (hfddp->keyboard)
							tprintf ("*** connected to %s\n", hfddp->call);

						hfdd_state = connected;
					}

					/* 18Jan2005, Maiko, integrated into fwding now */
					/* 28Feb2005, Maiko, Set this either way !! */
					hfdd_conn_flag = 1;
				}
			}

#ifdef	DONT_COMPILE
			if (hfddp->keyboard)
				usflush (Curproc->output);
#endif
			continue;
		}

		/*
		 * 04Oct2006, Maiko, Forgot about the *other* ESC character. If we
		 * get one of these, then the byte that follows is actual DATA !!!
		 */
		if (c == 0x81)
		{
			log (-1, "escape character");

    		if ((c = get_asy (dev)) == -1)
				break;
		}
		
#ifdef	DEBUG
		log_data (c);
#endif
		/* 18Jan2005, Maiko, Now doing fwd support for Halcomm */

		if (hfdd_fwdsock != -1)
		{
			usputc (hfdd_fwdsock, c);

			usflush (hfdd_fwdsock);
		}
		else if (bbs_mode)
		{
            usputc (mbxs[0], c);

			usflush (mbxs[0]);
		}
		else
		{
			if (hfddp->keyboard)
			{
				/* Map to NL or else we loose data when we display it */
				if (c == 0x0d)
					c = '\n';

				tputc (c); /* assuming this is actual data (for now) */

    			tflush ();
			}
		}
	}

	if (hfddp->keyboard)
		usflush (Curproc->output);
}