#include #include #include #include /* START OF USER DEFINABLE SETTINGS */ #define CONF "/etc/maxchk.cfg" /* the max number of chassises you will be checking */ #define MAX_CHASSISES 20 /* if you have a web-based program to ping ips */ #define WEBPING_PATH "http://myhost.net/max/cgi-bin/ping.sh?host=%s&count=5" /* END OF USER DEFINABLE SETTINGS */ /* config variables */ int MAXSES=0; int MAX_CHASSIS=0; int MUST_BE_AT_TIME=0; /* for killing */ int DEBUG=0; int DEBUG2=0; char READ_COMM[20]; char RW_COMM[20]; char URL[200]; char except_list_shown[500]; char except_list_killed[500]; char except_list_all[500]; int hostindex=0; void read_config2(void); void remove_first_comma(char *inpstr); char *strip_user(char *str); struct { char hostname[32]; char groupname[32]; char name[32]; int linestotal; int beforekill; /* for killing */ char wanline[10]; int wanport1; int wanport2; int wanport3; int wanport4; } pwtable[MAX_CHASSISES]; int main(int argc, char **argv) { int i=0,count=0,totalactive=0,totalfree=0; char session_id[11],linechan[6],slotport[6],txrate[6]; char rxrate[6],service[16],ip2[16],username2[64]; char command[257]; char mess[257]; char mess2[257]; char line[512]; char line2[257]; time_t tm; FILE *pp; fprintf(stdout,"Content-type: text/html\n\n"); fprintf(stdout,"\n"); fprintf(stdout,"\n"); fprintf(stdout,"\n"); fprintf(stdout,"\n"); fprintf(stdout,"
\n"); time(&tm); fprintf(stdout,"Ascend Max Port Usage
\n"); fprintf(stdout,"%s",ctime(&tm)); fprintf(stdout,"
\n");

read_config2();

while (hostindex < MAX_CHASSIS) {

if (!strcmp(pwtable[hostindex].groupname,argv[1]) ||
    !strcmp(pwtable[hostindex].hostname,argv[1])) {
	sprintf(command,"finger @%s\n",pwtable[hostindex].hostname);
	if (!(pp=popen(command,"r"))) {
	printf("Can't open pipe\n");
	hostindex++;
	continue;
	}

	while (fgets(line2,256,pp) != NULL) {
	count++;
	if (count==1) {
		printf("\n%s (%s)\n",pwtable[hostindex].name,pwtable[hostindex].hostname);
		continue;
		}
	else if (count==2 || count==3) {
		if (strstr(line2,"No Active Users")) { count=3; break; }
		remove_first(line2);
		printf("%s",line2);
		continue;
	}
	else {
	fflush(stdout);
	remove_first(line2);	/* I or O */
	sscanf(line2,"%s",session_id);		
	remove_first(line2);	/* session id */
	sscanf(line2,"%s",linechan);		
	remove_first(line2);	/* line and channel */
	sscanf(line2,"%s",slotport);		
	remove_first(line2);	/* slot and port */
	sscanf(line2,"%s",txrate);		
	remove_first(line2);	/* txrate */
	sscanf(line2,"%s",rxrate);		
	remove_first(line2);	/* rxrate */
	sscanf(line2,"%s",service);		
	remove_first(line2);	/* service type */
	sscanf(line2,"%s",ip2);
	remove_first(line2);	/* ip address */
	sscanf(line2,"%s",username2);		
	strcpy(username2,strip_user(username2));
	if (!strcmp(username2,"User") ||
	    !strcmp(username2,"Name") ||
	    !strcmp(username2,"Answer")) { count--; continue; }

	sprintf(mess2,WEBPING_PATH,ip2);
	sprintf(mess,URL,pwtable[hostindex].hostname,username2,session_id);
	sprintf(line,"%s %-5s %-5s %-5s %-5s %-15s %-15s %s",
		session_id,linechan,slotport,txrate,rxrate,service,
		mess2,ip2,mess,username2);
	fprintf(stdout,"%s\n",line);
	} /* end of else */
	} /* end of pp while */
	pclose(pp);
	fprintf(stdout,"Active modems: %-3d Free modems: %d\n",count-3,pwtable[hostindex].linestotal-(count-3));
	totalactive+=(count-3);
	totalfree+=(pwtable[hostindex].linestotal-(count-3));

	username2[0]=0;
	ip2[0]=0;
	line[0]=0;
	line2[0]=0;
	count=0;
	} /* end of if group match */
hostindex++;
} /* end of group while */

fprintf(stdout,"\n\nTotal Active: %-5d Total Free: %d

\n",totalactive,totalfree); fprintf(stdout,"
\n"); fprintf(stdout,"\n"); } /*** removes first word at front of string and moves rest down ***/ remove_first(inpstr) char *inpstr; { int newpos,oldpos; newpos=0; oldpos=0; /* find first word */ while(inpstr[oldpos]==' ') { if (!inpstr[oldpos]) { inpstr[0]=0; return; } oldpos++; } /* find end of first word */ while(inpstr[oldpos]!=' ') { if (!inpstr[oldpos]) { inpstr[0]=0; return; } oldpos++; } /* find second word */ while(inpstr[oldpos]==' ') { if (!inpstr[oldpos]) { inpstr[0]=0; return; } oldpos++; } while(inpstr[oldpos]!=0) inpstr[newpos++]=inpstr[oldpos++]; inpstr[newpos]='\0'; } char *strip_user(char *str) { int z=0,type=0; static char usern2[64]; for (z=0;z\n\n"); exit(0); } else { yy=0; zz=0; while (fgets(fileline,256,fp2) != NULL) { fileline[strlen(fileline)-1]=0; if (fileline[0]=='#' || fileline[0]==' ' || !strlen(fileline)) continue; else { if (yy==0) { MAXSES=atoi(fileline); } else if (yy==1) { MUST_BE_AT_TIME=atoi(fileline); } else if (yy==2) { strcpy(READ_COMM,fileline); } else if (yy==3) { strcpy(RW_COMM,fileline); } else if (yy==4) { strcpy(URL,fileline); } else if (yy==5) { strcpy(except_list_shown,fileline); } else if (yy==6) { strcpy(except_list_killed,fileline); } else if (yy==7) { strcpy(except_list_all,fileline); } else if (yy >= 8) { sscanf(fileline,"%s ",pwtable[zz].hostname); remove_first(fileline); sscanf(fileline,"%s ",readbuf); pwtable[zz].linestotal=atoi(readbuf); remove_first(fileline); /* scan in beforekill line */ sscanf(fileline,"%s ",readbuf); pwtable[zz].beforekill=atoi(readbuf); remove_first(fileline); /* before kill */ sscanf(fileline,"%s ",pwtable[zz].wanline); if (strstr(pwtable[zz].wanline,",")) { for (i=0;i