This commit is contained in:
2023-12-22 22:53:54 -05:00
commit 2821b7e9a1
45 changed files with 8425 additions and 0 deletions

295
logsrv/client.c Normal file
View File

@@ -0,0 +1,295 @@
/*
WILDTHANG DATA SERVER VERSION 1.0
WildThang is dvmitche@midway.ecn.uoknor.edu
Please note that due to the nature of this program
I have not opted to comment the code. I have done this for
Various reasons!
*/
/* do you REALLY think we need ALL of these *grin* */
#include <ctype.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/wait.h>
#include <netdb.h>
#include <time.h>
#include <ctype.h>
#include <arpa/inet.h>
#include <termios.h>
#ifdef SIGTSTP
#include <sys/ioctl.h>
#include <sys/file.h>
#endif
#include <sys/param.h>
#include <stdio.h>
#include <errno.h>
#include <netinet/in.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <string.h>
#include <signal.h>
#include "config.h"
int PORTNUM = PORT,newsockfd,level;
int NUMUSERS=0; /* counter of users logged in */
int REFPROCESS=0;
char buf[512],*hostname;
char *Serv;
char tempp[512];
char sockbuf[512],*sptr;
char loginname[20];
extern char *linetok[]; /* from socketc. */
extern int USEIDENT; /* from socket.c */
extern char *get_server(char *fromhost); /* from socket.c */
/* WARNING:THIS MUST NOT BE CHANGED... ELSE STRANGE THINGS SEEM TO HAPPEN */
#define SOCKLINK 9219423
#define VERSION "TELCLIENT_1.8"
void handle_kids()
{int pid;
#ifdef OSF1
union wait *status;
status = (union wait *)malloc(sizeof(long));
while( (pid = wait3(status,WNOHANG, (struct rusage *)0)) > 0) { }
#else
union wait status;
while( (pid = wait3(&status,WNOHANG, (struct rusage *)0)) > 0) { }
#endif /* OSF1 */
NUMUSERS--;
}
main(argc,argv)
int argc;
char **argv;
{ int m,j,sockfd,insockfd,retlen,retval,outfd,infd,i,route;
struct sockaddr_in sockst,insock;
struct hostent *hp;
int opt=1;
struct sockaddr_in from;
int fromlen;
char hostid[255],hosthld[255];
signal(SIGCLD,handle_kids);
if(BACKGROUND) goto_bg();
if(argc > 1) { /* process command line options */
if(*argv[1] == '-') {
*argv[1]++;
if(*argv[1]=='p')
if(atoi(argv[2])>6000) PORTNUM = atoi(argv[2]);
}
}
if ((sockfd=socket(AF_INET,SOCK_STREAM,0))<0) {
perror("socked");
exit(1);
}
if(!BACKGROUND) printf("GOT SOCKET %d\n",sockfd);
#ifdef SO_REUSEADDR
if (setsockopt(sockfd,SOL_SOCKET, SO_REUSEADDR,&opt,sizeof(opt)) <0)
{ exit(-1); }
#endif
sockst.sin_family=AF_INET;
sockst.sin_addr.s_addr=INADDR_ANY;
sockst.sin_port=htons(PORTNUM);
if ((bind(sockfd,(struct sockaddr *)&sockst,sizeof(sockst)))<0) {
perror("bind");
exit(1);
}
if(!BACKGROUND) printf("BIND SOCKET Complete\n");
if ((listen(sockfd,1))<0) {
perror("listen");
exit(1);
}
if(!BACKGROUND) printf("Listening for connections\n");
while(1)
{ if ((newsockfd=accept(sockfd,(struct sockaddr *) 0,(int *) 0))<0)
{
continue;
/* will receive a sig from dying children */
}
if(!BACKGROUND) printf("GOT CONNECTION %d\n",newsockfd);
if (!fork())
{
close(sockfd);
do_menu(newsockfd);
close(newsockfd);
exit(0);
}
close(newsockfd);
}
}
int bbs_cat(sck,filename)
int sck;
char *filename;
{
FILE *fp;
char *sbuf;
char line[512],command[512];
if ( (fp = fopen(filename,"r")) == NULL)
return 0;
for(; ;) {
if(fgets(line,80,fp) == NULL) { fclose(fp); return 1; }
if(write(sck,line,strlen(line)) != strlen(line)) {
fclose(fp); return 1; }
if(write(sck,"",0) != 0) {
fclose(fp); return 1; }
}
}
int bbs_pcom(sck,command)
int sck;
char *command;
{
FILE *fp;
char *sbuf;
char line[512];
if ( (fp = popen(command,"r")) == NULL)
return 0;
for(; ;) {
if(fgets(line,80,fp) == NULL) { pclose(fp); return 1; }
if(write(sck,line,strlen(line)) != strlen(line)) {
pclose(fp); return 1; }
if(write(sck,"",0) != 0) {
pclose(fp); return 1; }
}
}
int bbs_grep(sck,filename)
int sck;
char *filename;
{
FILE *fp;
int i;
char *sbuf,*token[256];
char line[512],command[512];
strcpy(line,sockbuf);
token[i=0]=strtok(sockbuf," ");
while(token[++i]=strtok(NULL, " ")); token[i]=NULL;
if(i < 1) return 0;
sprintf(command,"%s -i %s %s",GREPCOM,token[0],filename);
bbs_pcom(sck,command);
}
int bbs_tail(sck,filename)
int sck;
char *filename;
{
FILE *fp;
int i;
char *sbuf,*token[256];
char line[512],command[512];
strcpy(line,sockbuf);
token[i=0]=strtok(sockbuf," ");
while(token[++i]=strtok(NULL, " ")); token[i]=NULL;
if(i < 1) return 0;
sprintf(command,"%s -50 %s",TAILCOM,filename);
bbs_pcom(sck,command);
}
goto_bg()
{
register int child,fd;
#ifdef SUN
fclose(stdin); fclose(stdout); fclose(stderr);
#else
close(0); close(1); close(2);
#endif
if(getppid() == 1) goto out;
#ifdef SIGTTOU
signal(SIGTTOU,SIG_IGN);
#endif
#ifdef SIGTTIN
signal(SIGTTIN,SIG_IGN);
#endif
#ifdef SIGTSTP
signal(SIGTSTP,SIG_IGN);
#endif
if( (child =fork()) < 0)
perror("fork");
else if (child > 0)
exit(0);
#ifdef SIGTSTP
if (setpgrp(0,getpid()) == -1)
perror("SETGROUP");
if( (fd = open("/dev/tty",O_RDWR)) >= 0) {
ioctl(fd, TIOCNOTTY, (char *)NULL);
close(fd);
}
#else
if(setpgrp() == -1)
perror("set group");
signal(SIGHUP,SIG_IGN);
if( (child = fork()) < 0)
perror("cant fork");
else if (child > 0)
exit(0);
#endif
out:
for(fd=0;fd<NOFILE;fd++)
close(fd);
errno = 0;
#ifdef SIGTSTP
signal(SIGCLD, handle_kids);
#else
signal(SIGCLD, SIG_IGN);
#endif
}
do_menu(int sckfd)
{
writeln(sckfd," Welcome to WildThang's Uworld Log report Service\n");
writeln(sckfd," ==================================================\n");
writeln(sckfd," please specify the word you wish to search for\n");
writeln(sckfd," from the log database. some special commands are:\n");
writeln(sckfd," ALL -- Displays the entire log file to you\n");
writeln(sckfd," TAIL -- Displays the last 50 lines of the log\n");
writeln(sckfd," KTEL -- Displays the activity of BANNED telusers\n");
writeln(sckfd," KILL -- Displays the activity of KILLS by IRCops\n");
writeln(sckfd," <word> -- scans log file for occurances of 'word'\n");
writeln(sckfd," ==================================================\n");
writeln(sckfd,"\nEnter Choice: (press return when done) :");
readcom(sckfd,10);
if(strlen(sockbuf) < 1){ close(sckfd); exit(0); }
if(!strncasecmp(sockbuf,"tail",4)) bbs_tail(newsockfd,DATAFILE);
else if(!strncasecmp(sockbuf,"all",3)) bbs_cat(newsockfd,DATAFILE);
else bbs_grep(newsockfd,DATAFILE);
}