|
|
1.1 root 1: /* spyon.c */
2:
3: /* Synchronet for *nix node spy */
4:
1.1.1.2 ! root 5: /* $Id: spyon.c,v 1.9 2011/09/09 23:58:03 deuce Exp $ */
1.1 root 6:
7: /****************************************************************************
8: * @format.tab-size 4 (Plain Text/Source Code File Header) *
9: * @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) *
10: * *
11: * Copyright 2003 Rob Swindell - http://www.synchro.net/copyright.html *
12: * *
13: * This program is free software; you can redistribute it and/or *
14: * modify it under the terms of the GNU General Public License *
15: * as published by the Free Software Foundation; either version 2 *
16: * of the License, or (at your option) any later version. *
17: * See the GNU General Public License for more details: gpl.txt or *
18: * http://www.fsf.org/copyleft/gpl.html *
19: * *
20: * Anonymous FTP access to the most recent released source is available at *
21: * ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net *
22: * *
23: * Anonymous CVS access to the development source and modification history *
24: * is available at cvs.synchro.net:/cvsroot/sbbs, example: *
25: * cvs -d :pserver:[email protected]:/cvsroot/sbbs login *
26: * (just hit return, no password is necessary) *
27: * cvs -d :pserver:[email protected]:/cvsroot/sbbs checkout src *
28: * *
29: * For Synchronet coding style and modification guidelines, see *
30: * http://www.synchro.net/source.html *
31: * *
32: * You are encouraged to submit any modifications (preferably in Unix diff *
33: * format) via e-mail to [email protected] *
34: * *
35: * Note: If this box doesn't appear square, then you need to fix your tabs. *
36: ****************************************************************************/
37:
38: #include <unistd.h>
39: #include <stdlib.h>
40: #include "sockwrap.h" /* Must go before <sys/un.h> */
41: #include <sys/un.h>
42: #include <stdio.h>
43: #include <string.h>
44: #include "sockwrap.h"
45: #include "spyon.h"
46: #include "ciolib.h"
1.1.1.2 ! root 47: #include "cterm.h"
! 48:
! 49: struct cterminal *cterm;
1.1 root 50:
51: int spyon(char *sockname) {
52: SOCKET spy_sock=INVALID_SOCKET;
53: struct sockaddr_un spy_name;
54: socklen_t spy_len;
55: unsigned char key;
56: unsigned char buf;
57: int i;
58: fd_set rd;
59: BOOL b;
60: int retval=0;
61: char ANSIbuf[32];
62: int parsing=0;
63: int telnet_strip=0;
64: struct text_info ti;
65: char *scrn;
66:
67: /* ToDo Test for it actually being a socket! */
68: /* Well, it will fail to connect won't it? */
69:
70: if((spy_sock=socket(PF_UNIX,SOCK_STREAM,0))==INVALID_SOCKET) {
71: printf("ERROR %d creating local spy socket", errno);
72: return(SPY_NOSOCKET);
73: }
74:
75: spy_name.sun_family=AF_UNIX;
76: SAFECOPY(spy_name.sun_path,sockname);
77: #ifdef SUN_LEN
78: spy_len=SUN_LEN(&spy_name);
79: #else
80: spy_len=sizeof(struct sockaddr_un);
81: #endif
82: if(connect(spy_sock,(struct sockaddr *)&spy_name,spy_len)) {
83: return(SPY_NOCONNECT);
84: }
85: i=1;
86:
87: gettextinfo(&ti);
88: scrn=(char *)alloca(ti.screenwidth*ti.screenheight*2);
89: gettext(1,1,ti.screenwidth,ti.screenheight,scrn);
90: textcolor(YELLOW);
91: textbackground(BLUE);
92: clrscr();
93: gotoxy(1,ti.screenheight);
94: cputs("Local spy mode... press CTRL-C to return to monitor");
95: clreol();
1.1.1.2 ! root 96: cterm=cterm_init(ti.screenheight-1,ti.screenwidth,1,1,0,NULL,CTERM_EMULATION_ANSI_BBS);
! 97: while(spy_sock!=INVALID_SOCKET && cterm != NULL) {
1.1 root 98: struct timeval tv;
99: tv.tv_sec=0;
100: tv.tv_usec=100;
101: FD_ZERO(&rd);
102: FD_SET(spy_sock,&rd);
103: if((select(spy_sock+1,&rd,NULL,NULL,&tv))<0) {
104: close(spy_sock);
105: spy_sock=INVALID_SOCKET;
106: retval=SPY_SELECTFAILED;
107: break;
108: }
109: if(!socket_check(spy_sock,NULL,&b,0)) {
110: close(spy_sock);
111: spy_sock=INVALID_SOCKET;
112: retval=SPY_SOCKETLOST;
113: break;
114: }
115: if(spy_sock != INVALID_SOCKET && FD_ISSET(spy_sock,&rd)) {
116: if((i=read(spy_sock,&buf,1))==1) {
117: if(telnet_strip) {
118: telnet_strip++;
119: if(buf==255 && telnet_strip==2) {
120: telnet_strip=0;
1.1.1.2 ! root 121: cterm_write(cterm, &buf,1,NULL,0,NULL);
1.1 root 122: }
123: if(telnet_strip==3)
124: telnet_strip=0;
125: }
126: else
127: if(buf==255)
128: telnet_strip=1;
129: else
1.1.1.2 ! root 130: cterm_write(cterm, &buf,1,NULL,0,NULL);
1.1 root 131: }
132: else if(i<0) {
133: close(spy_sock);
134: spy_sock=INVALID_SOCKET;
135: retval=SPY_SOCKETLOST;
136: break;
137: }
138: }
139: if(kbhit()) {
140: key=getch();
141: /* Check for control keys */
142: switch(key) {
143: case 0: /* Extended keys */
144: case 0xff:
145: getch();
146: break;
147: case 3: /* CTRL-C */
148: close(spy_sock);
149: spy_sock=INVALID_SOCKET;
150: retval=SPY_CLOSED;
151: break;
152: default:
153: write(spy_sock,&key,1);
154: }
155: }
156: }
1.1.1.2 ! root 157: cterm_end(cterm);
1.1 root 158: puttext(1,1,ti.screenwidth,ti.screenheight,scrn);
159: window(ti.winleft,ti.wintop,ti.winright,ti.winbottom);
160: textattr(ti.attribute);
161: gotoxy(ti.curx,ti.cury);
162: return(retval);
163: }
164:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.