|
|
1.1 root 1: /* sbbscon.c */
2:
3: /* Synchronet vanilla/console-mode "front-end" */
4:
5: /* $Id: sbbscon.c,v 1.14 2000/11/17 05:07:53 rswindell Exp $ */
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 2000 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: /* Synchronet-specific headers */
39: #include "sbbs.h"
40: #include "conwrap.h" /* kbhit/getch */
41: #include "bbs_thrd.h" /* bbs_thread */
42: #include "ftpsrvr.h" /* ftp_startup_t, ftp_server */
43: #include "mailsrvr.h" /* mail_startup_t, mail_server */
44:
45: /* Constants */
46: #define SBBSCON_VERSION "1.00"
47:
48: /* Global variables */
49: BOOL bbs_running=FALSE;
50: bbs_startup_t bbs_startup;
51: BOOL ftp_running=FALSE;
52: ftp_startup_t ftp_startup;
53: BOOL mail_running=FALSE;
54: mail_startup_t mail_startup;
55:
56: static const char* prompt = "Command (?=Help): ";
57:
58: static void lputs(char *str)
59: {
60: static pthread_mutex_t mutex;
61: static BOOL mutex_initialized;
62:
63: if(!mutex_initialized) {
64: pthread_mutex_init(&mutex,NULL);
65: mutex_initialized=TRUE;
66: }
67:
68: pthread_mutex_lock(&mutex);
69: printf("\r%*s\r%s\n",strlen(prompt),"",str);
70: printf(prompt);
71: fflush(stdout);
72: pthread_mutex_unlock(&mutex);
73: }
74:
75: /************************************************/
76: /* Truncates white-space chars off end of 'str' */
77: /************************************************/
78: static void truncsp(char *str)
79: {
80: uint c;
81:
82: c=strlen(str);
83: while(c && (uchar)str[c-1]<=' ') c--;
84: str[c]=0;
85: }
86:
87: /****************************************************************************/
88: /* BBS local/log print routine */
89: /****************************************************************************/
90: static int bbs_lputs(char *str)
91: {
92: char logline[512];
93: char tstr[64];
94: time_t t;
95: struct tm* tm_p;
96:
97: t=time(NULL);
98: tm_p=localtime(&t);
99: if(tm_p==NULL)
100: tstr[0]=0;
101: else
102: sprintf(tstr,"%d/%d %02d:%02d:%02d "
103: ,tm_p->tm_mon+1,tm_p->tm_mday
104: ,tm_p->tm_hour,tm_p->tm_min,tm_p->tm_sec);
105:
106: sprintf(logline,"%sbbs %.*s",tstr,sizeof(logline)-2,str);
107: truncsp(logline);
108: lputs(logline);
109:
110: return(strlen(logline)+1);
111: }
112:
113: static void bbs_started(void)
114: {
115: bbs_running=TRUE;
116: }
117:
118: static void bbs_terminated(int code)
119: {
120: bbs_running=FALSE;
121: }
122:
123: /****************************************************************************/
124: /* FTP local/log print routine */
125: /****************************************************************************/
126: static int ftp_lputs(char *str)
127: {
128: char logline[512];
129: char tstr[64];
130: time_t t;
131: struct tm* tm_p;
132:
133: t=time(NULL);
134: tm_p=localtime(&t);
135: if(tm_p==NULL)
136: tstr[0]=0;
137: else
138: sprintf(tstr,"%d/%d %02d:%02d:%02d "
139: ,tm_p->tm_mon+1,tm_p->tm_mday
140: ,tm_p->tm_hour,tm_p->tm_min,tm_p->tm_sec);
141:
142: sprintf(logline,"%sftp %.*s",tstr,sizeof(logline)-2,str);
143: truncsp(logline);
144: lputs(logline);
145:
146: return(strlen(logline)+1);
147: }
148:
149: static void ftp_started(void)
150: {
151: ftp_running=TRUE;
152: }
153:
154: static void ftp_terminated(int code)
155: {
156: ftp_running=FALSE;
157: }
158:
159: /****************************************************************************/
160: /* Mail Server local/log print routine */
161: /****************************************************************************/
162: static int mail_lputs(char *str)
163: {
164: char logline[512];
165: char tstr[64];
166: time_t t;
167: struct tm* tm_p;
168:
169: t=time(NULL);
170: tm_p=localtime(&t);
171: if(tm_p==NULL)
172: tstr[0]=0;
173: else
174: sprintf(tstr,"%d/%d %02d:%02d:%02d "
175: ,tm_p->tm_mon+1,tm_p->tm_mday
176: ,tm_p->tm_hour,tm_p->tm_min,tm_p->tm_sec);
177:
178: sprintf(logline,"%smail %.*s",tstr,sizeof(logline)-2,str);
179: truncsp(logline);
180: lputs(logline);
181:
182: return(strlen(logline)+1);
183: }
184:
185: static void mail_started(void)
186: {
187: mail_running=TRUE;
188: }
189:
190: static void mail_terminated(int code)
191: {
192: mail_running=FALSE;
193: }
194:
195: /****************************************************************************/
196: /* Main Entry Point */
197: /****************************************************************************/
198: int main(int argc, char** argv)
199: {
200: char ch;
201: char* ctrl_dir;
202: BOOL quit=FALSE;
203:
204: printf("\nSynchronet BBS Console Version %s Copyright 2000 Rob Swindell\n"
205: ,SBBSCON_VERSION);
206:
207: ctrl_dir=getenv("SBBSCTRL"); /* read from environment variable */
208: if(ctrl_dir==NULL)
209: ctrl_dir="/sbbs/ctrl/"; /* Not set? Use default */
210:
211: /* Initialize BBS startup structure */
212: memset(&bbs_startup,0,sizeof(bbs_startup));
213: bbs_startup.size=sizeof(bbs_startup);
214: bbs_startup.first_node=1;
215: bbs_startup.last_node=4;
216: bbs_startup.telnet_port=IPPORT_TELNET;
217: bbs_startup.telnet_interface=INADDR_ANY;
218: bbs_startup.options|=BBS_OPT_NO_QWK_EVENTS;
219:
220: #ifdef USE_RLOGIN
221: bbs_startup.rlogin_port=513;
222: bbs_startup.rlogin_interface=INADDR_ANY;
223: bbs_startup.options|=BBS_OPT_ALLOW_RLOGIN;
224: #endif
225:
226: bbs_startup.lputs=bbs_lputs;
227: bbs_startup.started=bbs_started;
228: bbs_startup.terminated=bbs_terminated;
229: /* These callbacks haven't been created yet
230: bbs_startup.status=bbs_status;
231: bbs_startup.clients=bbs_clients;
232: bbs_startup.thread_up=thread_up;
233: bbs_startup.client_on=client_on;
234: bbs_startup.socket_open=socket_open;
235: */
236: strcpy(bbs_startup.ctrl_dir,ctrl_dir);
237:
238: /* Initialize FTP startup structure */
239: memset(&ftp_startup,0,sizeof(ftp_startup));
240: ftp_startup.size=sizeof(ftp_startup);
241: ftp_startup.port=IPPORT_FTP;
242: ftp_startup.interface_addr=INADDR_ANY;
243: ftp_startup.lputs=ftp_lputs;
244: ftp_startup.started=ftp_started;
245: ftp_startup.terminated=ftp_terminated;
246: ftp_startup.options=FTP_OPT_INDEX_FILE|FTP_OPT_ALLOW_QWK;
247: strcpy(ftp_startup.index_file_name,"00index");
248: strcpy(ftp_startup.ctrl_dir,ctrl_dir);
249:
250: /* Initialize Mail Server startup structure */
251: memset(&mail_startup,0,sizeof(mail_startup));
252: mail_startup.size=sizeof(mail_startup);
253: mail_startup.smtp_port=IPPORT_SMTP;
254: mail_startup.pop3_port=110;
255: mail_startup.max_clients=10;
256: mail_startup.max_inactivity=120;
257: mail_startup.max_delivery_attempts=10;
258: mail_startup.rescan_frequency=300; /* In seconds */
259: mail_startup.relay_port=IPPORT_SMTP;
260: mail_startup.interface_addr=INADDR_ANY;
261: mail_startup.lputs=mail_lputs;
262: mail_startup.started=mail_started;
263: mail_startup.terminated=mail_terminated;
264: mail_startup.options|=MAIL_OPT_ALLOW_POP3;
265: strcpy(mail_startup.ctrl_dir,ctrl_dir);
266:
267: _beginthread((void(*)(void*))bbs_thread,0,&bbs_startup);
268: _beginthread((void(*)(void*))ftp_server,0,&ftp_startup);
269: _beginthread((void(*)(void*))mail_server,0,&mail_startup);
270:
271: while(!quit) {
272: ch=getch();
273: printf("%c\n",ch);
274: switch(ch) {
275: case 'q':
276: quit=TRUE;
277: break;
278: default:
279: printf("\nSynchronet BBS Console Version %s Help\n\n",SBBSCON_VERSION);
280: printf("q = quit\n");
281: #if 0 /* to do */
282: printf("n = node list\n");
283: printf("w = who's online\n");
284: printf("l# = lock node #\n");
285: printf("d# = down node #\n");
286: printf("i# = interrupt node #\n");
287: printf("c# = chat with node #\n");
288: printf("s# = spy on node #\n");
289: #endif
290: lputs(""); /* redisplay prompt */
291: break;
292: }
293: }
294:
295: bbs_terminate();
296: ftp_terminate();
297: mail_terminate();
298:
299: while(bbs_running || ftp_running || mail_running)
300: mswait(1);
301:
302: /* erase the prompt */
303: printf("\r%*s\r",strlen(prompt),"");
304:
305: return(0);
306: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.