I'm trying to write a front end of sorts for my BBS (Daydream BBS) in C. It has 4 options. (1) Show the PIDs of in.telnetd (2) Kill PID if applicable (3) "Snoop" a node and (4) Telnet to the BBS.
What I want to do, is allow option #1 to run in the foreground, in a window at the top of the screen, and be in real time, or, maybe even every 2 seconds, like what the command wait
does. Is this possible? Here's the code I have so far:
// Ignatius' Daydream BBS frontend
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <signal.h>
#include <dirent.h>
#include <sys/types.h>
#include <unistd.h>
#include <ncurses.h>
/////////// variables /////////////////////////////
int group;
const int maxQuestionID = 4;
const int maxFileID = 10;
int cmdKey = 0;
int fileID = 0;
int questionID = 0;
/////////// end variables /////////////////////////
/////////// init function /////////////////////////
void init()
{
printf("\e(U");
initscr();
cbreak();
noecho();
nonl();
keypad(stdscr, TRUE);
}
///////////// main screen /////////////////////////
int main()
{
system("/usr/bin/clear");
init();
space();
const char *questions[] = {"^[[23;1H^[[1;30m[^[[1;34;44mNODES^[[0;37m^[[1;30m] ^[[0;37mlogin snoop kill quit ",
"^[[23;1H^[[0;37m nodes ^[[1;30m[^[[1;34;44mLOGIN^[[0;37m^[[1;30m]^[[0;37m snoop kill quit ",
"^[[23;1H^[[0;37m nodes login ^[[1;30m[^[[1;34;44mSNOOP^[[0;37m^[[1;30m]^[[0;37m kill quit ",
"^[[23;1H^[[0;37m nodes login snoop ^[[0;37m^[[1;30m[^[[1;34;44mKILL^[[0;37m^[[1;30m]^[[0;37m quit ",
"^[[23;1H nodes ^[[0;37mlogin snoop kill ^[[0;37m^[[1;30m[^[[1;34;44mQUIT^[[0;37m^[[1;30m]^[[0;37m "};
const char *files[] = {"^[[8;1H^[[0;37m^[[1;30m[^[[1;36;46mNODE 1^[[0;37m^[[1;30m]^[[0;37m
^[[9;1H ^[[0;37mnode 2 ^[[10;1H ^[[0;37mnode 3 ^[[11;1H ^[[0;37mnode 4 ^[[12;1H ^[[0;37mnode 5 ",
"^[[8;1H ^[[0;37mnode 1 ^[[9;1H^[[0;37m^[[1;30m[^[[1;36;46mNODE 2^[[0;37m^[[1;30m]^[[0;37m
^[[10;1H ^[[0;37mnode 3 ^[[11;1H ^[[0;37mnode 4 ^[[12;1H ^[[0;37mnode 5 ",
"^[[8;1H ^[[0;37mnode 1 ^[[9;1H ^[[0;37mnode 2 ^[[10;1H^[[0;37m^[[1;30m[^[[1;36;46mNODE 3^[[0;37m^[[1;30m]^[[0;37m
^[[11;1H ^[[0;37mnode 4 ^[[12;1H ^[[0;37mnode 5 ",
"^[[8;1H ^[[0;37mnode 1 ^[[9;1H ^[[0;37mnode 2 ^[[10;1H ^[[0;37mnode 3
^[[11;1H^[[0;37m^[[1;30m[^[[1;36;46mNODE 4^[[0;37m^[[1;30m]^[[0;37m ^[[12;1H ^[[0;37mnode 5 ",
"^[[8;1H ^[[0;37mnode 1 ^[[9;1H ^[[0;37mnode 2 ^[[10;1H ^[[0;37mnode 3
^[[11;1H ^[[0;37mnode 4 ^[[12;1H^[[0;37m^[[1;30m[^[[1;36;46mNODE 5^[[0;37m^[[1;30m]^[[0;37m "};
while (cmdKey != 13)
{
int cmdKey = getchar();
switch(cmdKey)
{
case 68: // left
case 'a':
if (questionID > 0) questionID--;
break;
case 67: // right
case 's':
if (questionID < maxQuestionID) questionID++;
break;
case 65: // up
case 'd':
if (fileID > 0) fileID--;
break;
case 66: // down
case 'f':
if (fileID < maxFileID) fileID++;
break;
case 13:
case 'x':
if (questionID == 0)
{
system("/usr/bin/reset");
system("/usr/bin/ps xua|grep telnet");
init();
break;
}
else if (questionID == 1)
{
system("/usr/bin/ztelnet catch22bbs.com");
system("/usr/bin/reset");
init();
break;
}
else if (questionID == 0)
{
//display();
break;
}
else if (questionID == 3)
{
killproc();
break;
}
else if (questionID == 4)
{
quit();
}
if (fileID == 0)
{
system("/usr/bin/ddsnoop 1");
}
else if (fileID == 1)
{
system("/usr/bin/ddsnoop 2");
}
else if (fileID == 2)
{
system("/usr/bin/ddsnoop 3");
}
else if (fileID == 3)
{
system("/usr/bin/ddsnoop 4");
}
else if (fileID == 4)
{
system("/usr/bin/ddsnoop 5");
}
}
printf("%s\n%s\n", files[fileID], questions[questionID]);
int quit()
{
system("/usr/bin/reset");
exit(1);
return 0;
}
int space()
{
char *tty_name = ttyname(STDIN_FILENO);
char command[255] = "/usr/sbin/writevt -t "; strcpy(stpcpy(command + 21, tty_name), " -T $\' '"); system(command);
}
int killproc(void)
{
int killpid;
pid_t pid;
printf("Input PID of process you would like to kill: \n");
scanf("%d", &pid);
killpid = kill(pid, SIGKILL);
if(killpid == -1){
printf("Termination failed!\n");
return 0;
}
printf("Terminated process [%d]!", pid);
return 0;
}
If someone could take a look at this, and, maybe point me in the right direction. I'd grately appreciate it.
Thanks.
It looks like you're new here. If you want to get involved, click one of these buttons!
Comments
Actually, I meant the
watch
command. Notwait