/* wmnetmon - A network ICMP ping host monitoring tool. Copyright (C) 1999 Alvaro Lopes This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #define VERSION "0.2" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "config.h" #include "wmgeneral.h" #include "wmnetmon.h" /* Please define this in the Makefile if you want to force coredumps */ #ifdef FORCECORE #include #endif #include "config.h" #include "leds.h" #include "pinger.h" #include "list.h" #include "configfile.h" #include "logger.h" /* Global variables */ ListItem hosts; char *configfile = 0; /* Files - FIXME */ char soundfile[128],soundplayer[128]; /* Pixmap */ #include "wmnetmon.xpm" char *wmnetmon_mask_bits; const int wmnetmon_mask_width=64; const int wmnetmon_mask_height=64; const time_t max_sleep_time=250000L; int poll_time=30; int poll_yellowtime=60; int poll_redtime=200; int default_flags = 0; ledarray leds; int need_to_scroll_title = 0; void drawtimeout(hostmon *h); void cleararea(int x, int y, int width, int height) { copyXPMArea(89,17,width,height,x,y); } void settitles (char*newtitle, int permanent, int justscroll) { static char title[MAX_HOSTNAME+1]; static char temptitle[MAX_HOSTNAME+1]; static int currenttitle; /* 0-> title, 1-> temp */ static int scroll_direction; if (!newtitle && need_to_scroll_title) { need_to_scroll_title += scroll_direction; if (!need_to_scroll_title) { scroll_direction=1; need_to_scroll_title=1; } else if (need_to_scroll_title > (strlen(currenttitle ? temptitle: title)*5 - 55)) { scroll_direction=-1; need_to_scroll_title--; } } if (!justscroll) currenttitle=0; if (newtitle) { if (permanent) strcpy(title,newtitle); else strcpy(temptitle,newtitle); currenttitle = ! permanent; scroll_direction=1; need_to_scroll_title = (strlen(newtitle) > 11); } cleararea(4,4,56,8); writetextat(4,4,currenttitle ? temptitle : title); RedrawWindow(); } void settemptitle(char*newtitle) { settitles(newtitle,0,0); } void settitle(char*newtitle) { settitles(newtitle,1,0); } void writetextat(int x,int y, char *string) { int cpos,index; int hoffset,partial; int skip; /* Number of characters to skip at beggining */ int total; /* Big total number of chars to display -> 11 or 12 */ if (need_to_scroll_title<5) skip=0; else skip = ((need_to_scroll_title - 1 )) / 5; if (need_to_scroll_title) total = (need_to_scroll_title-1) % 5 == 0 ? 11 : 12; else total=11; if ( total > strlen(string) ) total = strlen(string); for (cpos=skip; cpos < total+skip ; cpos++) { if (string[cpos]!=' ') { if (string[cpos]<='9') index=string[cpos]-'0'+('z'-'a'+1); else index=tolower(string[cpos])-'a'; /* index is the source offset */ if (! need_to_scroll_title) copyXPMArea(5*index ,64, 5 ,6, x + (5*cpos) , y); else { /* Partial columns of the first char we won't display */ partial = (need_to_scroll_title - 1) % 5; /* hoffset is where we start to draw the character */ hoffset= x + ( (cpos-skip)*5 ) - partial; if (hoffsetcurrent_status = color; } usleep(100000); display_leds(0); RedrawWindow(); } } void checkledtouch(ListItem hst, int x, int y) { ListItem iterator; hostmon *h; /* leds start at 6, 16 */ if (x < 6 || y < 16) return; for (iterator=hst;iterator;iterator=iterator->next) { h=(hostmon*)ListData(iterator); if (x >= h->lx && y >= h->ly) { if (x <= (h->lx +5) && y <= (h->ly +5 )) { settemptitle(h->hostname); return; } } } settemptitle("SELECT HOST"); } void checkledbuttonpress(ListItem hst, XButtonEvent ev) { ListItem iterator; hostmon *h; /* leds start at 6, 16 */ if (ev.x < 6 || ev.y < 16) return; for (iterator=hst;iterator;iterator=iterator->next) { h=(hostmon*)ListData(iterator); if (ev.x >= h->lx && ev.y >= h->ly) { if (ev.x <= (h->lx +5) && ev.y <= (h->ly +5 )) { if (ev.button == 3) { if (h->flags&FLAG_MUTED) { h->flags &= ~FLAG_MUTED; leds[h->x][h->y]->current_status=LED_OFF; } else { h->flags |= FLAG_MUTED; leds[h->x][h->y]->current_status=LED_BLUE; } } } } } } hostmon* add_host(pinger *p, char *hostip, char *hostname) { hostmon *hm; pinger_host *h; int numberofhosts; int cx,cy; numberofhosts=ListSize(&hosts); cy = numberofhosts / XLEDS; cx = numberofhosts % XLEDS; hm=malloc(sizeof(hostmon)); h=pinger_addhost(p,hostip); if (!h) return 0; hm->h=h; strncpy(hm->hostname, hostname, MAX_HOSTNAME); hm->flags=default_flags; leds[cx][cy]=add_led(6 + cx*6, 16+ cy*6 ,LED_OFF); hm->lx = 6 + cx*6; hm->ly = 16+ cy*6; hm->x=cx; hm->y=cy; /* cx++; if (cx>=XLEDS) { cy++; cx=0; } */ return ListInsert(&hosts,hm)!=0 ? hm : 0 ; } int init_pinger_hosts(pinger *p, ListItem *hosts, struct led *leds[XLEDS][YLEDS]) { ListInit(hosts); if (readconf(p,leds,configfile)!=0) return -1; display_leds(0); RedrawWindow(); return 0; } void usage() { printf("WMNetMon: a network host/services monitoring tool\n\n"); printf("Usage: wmnetmon [-d] [-t