WEBSERV.C
资源名称:ertos.rar [点击查看]
上传用户:sunrenlu
上传日期:2022-06-13
资源大小:1419k
文件大小:5k
源码类别:
操作系统开发
开发平台:
DOS
- /*
- * modem - more advanced terminal server
- * - allows multiple TELNETs in
- */
- #include <dos.h>
- #include <stdio.h>
- #include <rtos.h>
- #include <string.h>
- #include <mem.h>
- #include <telnetd.h>
- #include <ftpd.h>
- #include <httpd.h>
- #include <smtpcli.h>
- #include <process.h>
- #include <inifile.h>
- #include <syslog.h>
- #include "webpart.h"
- #define MAXHTTPD 5
- #define MAXTELNETD 4
- static void (*old_init)(char *name, char *value);
- char *emailuserid = NULL;
- DWORD oursysloghost = 0;
- char *syslogname = NULL;
- DWORD snmptraphost = 0;
- char *snmptrapname = NULL;
- #define EMAILNOTIFY "email.notify"
- #define SYSLOGHOST "syslog.host"
- #define SNMPHOST "snmptrap.host"
- char *loginuserid = NULL;
- char *loginpassword = NULL;
- int inuse[ MAXTELNETD ];
- /********************************************************************/
- void init_vars(void)
- {
- char *p;
- int i;
- p = GetIniString( "TCP.CFG", "settings", EMAILNOTIFY, "");
- if ( *p ) {
- emailuserid = p;
- printf("Configured email userid to %s.rn", emailuserid );
- } else {
- emailuserid = NULL;
- kfree( p );
- printf("No email userid set.rn");
- }
- p = GetIniString( "TCP.CFG", "settings", SYSLOGHOST, "");
- if ( *p ) {
- syslogname = p;
- printf("Configured syslogging to %s.rn", syslogname);
- oursysloghost = resolve( syslogname );
- } else {
- oursysloghost = 0;
- syslogname = NULL;
- kfree( p );
- printf("No syslogging configured.rn");
- }
- p = GetIniString( "TCP.CFG", "settings", SNMPHOST, "");
- if ( *p ) {
- snmptrapname = p;
- printf("Configured syslogging to %s.rn", snmptrapname);
- snmptraphost = resolve( snmptrapname );
- } else {
- snmptrapname = NULL;
- snmptraphost = 0;
- kfree( p );
- printf("No SNMP trap host configured.rn");
- }
- p = GetIniString( "TCP.CFG","settings","userid","");
- if ( *p ) {
- loginuserid = p;
- printf("Login permitted with userid: %srn", loginuserid );
- } else {
- kfree( p );
- printf("No Web login userid specifiedrn");
- }
- p = GetIniString("TCP.CFG","settings","password","");
- if ( *p ) {
- loginpassword = p;
- printf("Login permitted with password: %srn", loginpassword );
- } else
- kfree( p );
- }
- /********************************************************************/
- void teld_write_string( void *t, char *s )
- {
- teld_write( t, s, strlen(s) );
- }
- /********************************************************************/
- /* telnet_server - each thread executes this
- */
- void telnet_server( DWORD virtualport )
- {
- #define CBUFSIZ 128
- BYTE ch;
- BYTE buffer[ CBUFSIZ ];
- teld_str *t;
- int i;
- do {
- inuse[ virtualport ] = 0;
- printf("Listenning... TELNET #%urn", virtualport);
- t = teld_listen( 0 );
- printf("connection arrived... TELNETD session #%urn", virtualport);
- /* if syslog enabled, notify log of change */
- if ( oursysloghost )
- syslog( oursysloghost, LOG_DAEMON, LOG_ERR, "connection arrived");
- inuse[ virtualport ] = 1;
- teld_write_string( t, "DEMO TERMSERVrnCopyright (c) 1990, 1999 Erick Engelkern");
- rt_sleep( 1000 );
- teld_write_string( t, "press any key to exitrn");
- i = 0;
- do {
- /* way to break out */
- if ( kbhit() ) exit( 0 );
- /* look for TELNET arriving chars */
- ch = teld_getc( t );
- if ( ch == 255 ) break; /* end of connection */
- if ( ch != 0 ) {
- teld_write_string( t, "rnuser pressed a key, session ending");
- break;
- }
- rt_sleep( 1000 );
- sprintf( buffer, "%urn", i++ );
- teld_write_string( t, buffer);
- } while ( 1 );
- teld_close( t );
- printf("Connection closed... Telnet #%urn", virtualport);
- /* if syslog enabled, notify log of change */
- if ( oursysloghost )
- syslog( oursysloghost, LOG_DAEMON, LOG_ERR, "connection closed");
- } while ( 1 );
- }
- /********************************************************************/
- /* main - setup everything then wait for a keystroke
- */
- #pragma argsused
- void main(int argc, char **argv )
- {
- int temp;
- DWORD dummy;
- rt_init( 100 );
- puts("TERMSERV 1.1rn");
- puts("Copyright (c) 1990, 1999 Erick Engelkern");
- dbug_init();
- sock_init();
- init_vars();
- kdebug = 1;
- puts("Press any key to exitrn");
- rt_newthread( ftpdthread, 1,2048, 0, "ftpd" );
- for ( temp = 1 ; temp < MAXTELNETD ; ++temp ) {
- rt_newthread( &telnet_server, temp, 4096, 0, "telnet thread");
- }
- rt_newthread( collector, 1,2048, 0, "collector" );
- for ( temp = 0 ; temp < MAXHTTPD; ++temp )
- rt_newthread( httpdthread, (DWORD)&user_proc, 2048, 0, "httpd worker" );
- if ( emailuserid != NULL ) {
- printf("Sending Email notification to %srn", emailuserid );
- smtp_client( 0, "thisbox", emailuserid, "AUTOSEND: TermServer restarted",
- "The terminal server has restarted");
- }
- /* if syslog enabled, notify log of change */
- if ( oursysloghost )
- syslog( oursysloghost, LOG_DAEMON, LOG_ERR, "termserver started");
- while ( 1 ) {
- if ( kbhit() ) break;
- rt_sleep( 250 );
- }
- }