Maxdist v1.04 (08-03-01) ------------- I wrote this program because of a need to see Ascend MAX user info in a web browser and to be able to disconnect those users at the same time. The code isn't the most efficient. I'm not a big "C" guru or anything. It uses C snmp calls for getting SNMP info, but still uses a popen() call to snmpset for setting/killing. Therefore I would suggest running this on a machine where users DONT have open access to the "ps" process list in fear of them seeing the read/write community string passed to snmpset. Yeah, I know it'd be a heck of a lot faster with the C SNMP call, but I haven't learned how to use it for setting yet, so, this works just fine for me right now. Being CGIs, you have to run these on a machine that acts as a web server if you instead to use them to view the data in a browser. They can be run from the command line for text-only output (see below) The files in this package are as follows: maxlist.c - CGI Program that lists the users on a box(s) maxlist-finger.c - CGI Program that lists the users on a box(s) via finger call.txt - MIB file for the snmp program. maxchk.cfg - Contains a list of your box's ips and # of lines for each. Also some other parameters such as community strings and paths. I usually put this in /etc THIS PROGRAM IS BUILT AROUND UCD-SNMP v3.6.2 AND HIGHER. IT MAY OR MAY NOT WORK AGAINST CMU-SNMP OR LOWER VERSIONS OF UCD-SNMP! Ucd-snmp can be found at ftp://ucd-snmp.ucdavis.edu/ I make no guarantees about this program, and take no responsibility for any ill effects it may have on your system. INSTALLATION ------------ For maxlist: 1. Make sure your max boxes allow SNMP read and write access from the IP you'll be running these programs from. For maxlist-finger: 1. Make sure your max boxes allow fingerring. In the menu system, set Ethernet->Mod Config->Finger to Yes 2. Edit the CONF define in the .c files to what the full system path of the maxchk.cfg file will be. For maxlist: 3. Edit the LOG_FILE and LOG_FILE_KILL define in the .c file to the file where kills and autokills will get logged to. 4. Make sure you have the program snmpset on your machine. Check the SNMP_SET define in the .c files to make sure they point to where yours are located. The defaults point to the UCD-SNMP versions of these programs. If you have the CMU-SNMP versions, you will probably need to remove the "-v 1" from the define (?) For maxlist: 5. Compile the .c file using either gcc or cc (i use gcc) Replace "/usr/include/ucd-snmp" below with the path to your snmp header files. If you dont know where they are try: locate snmp_api.h gcc -I/usr/include/ucd-snmp -o maxlist maxlist.c -lsnmp For maxlist-finger: 5. Compile the .c file using either gcc or cc (i use gcc) gcc -o maxlist-finger maxlist-finger.c 6. Edit the maxchk.cfg file for your MAX boxes under the "Chassis Info" section. Syntax of config lines is: <# of ports> <# of ports to kill at> Exmaple: 216.250.154.75 47 48 1,2 Hazleton Hazleton POP 1 216.250.154.111 46 47 1,2 Hazleton Hazleton POP 2 216.250.154.112 46 138 1,2 Hazleton Hazleton POP 3 216.250.154.76 23 23 1 Scranton Scranton POP 216.250.154.76 23 23 2 Bloomsburg Bloomsburg POP Multiple hosts for a POP location can be grouped into a common group name. Passing this group name to maxlist results in all hosts being checked in that group. Multiple POPs per box are configured by changing the wan lines number. In our example for IP 216.250.154.76, the Scranton location is on slot 1,port1. The Bloomsburg location is on slot1,port2. If you were using the third wan port on the box (slot2,port1) you would use the number 3. If "ports to kill at" is greater than number of ports on box, auto-killer on that particular box is disabled. For auto-killing by group. i.e. "maxlist -k Hazleton" the killer takes the "ports to kill at" from the last host in the group. So in our example, we have 139 total ports on the Hazleton group (47+46+46) and we're telling the program to start killing when total connections reach 138. If we wanted to disable the auto-killer for the group, we would change 138 to something higher thatn the total, such as 140. 7. Edit the rest of the options in the maxchk.cfg file. 8. Move the the compiled programs, and call.txt to cgi-bin if they're not in there already. Move the maxchk.cfg file into the path you specified in the .c files. 9. You might need to make a symbolic link called maxlist.cgi/maxlist-finger.cgi and point it to the maxlist/maxlist-finger program. From the directory maxlist/maxlist-finger is installed in: ln -s maxlist maxlist.cgi or ln -s maxlist-finger maxlist-finger.cgi This is so the web server knows you're calling a cgi. If you call the maxlist/maxlist-finger program directly, some servers wont know you're running a program. Some won't follow symbolic links either, unless configured specifically, so try it both ways. CALLING/RUNNING --------------- Replace "maxlist" with "maxlist-finger" below, if using maxlist-finger. NOTE: maxlist-finger does NOT take any options and only takes a single GROUP or HOST name as an argument. The maxlist program can be called from the command line or from a browser. The usage for maxlist is: Usage: maxlist [-PBk123] [hub/group1 hub/group2...] or [hub_username_sessionid] -P Plain - DONT add html codes to the output -B Basic - Only show username/IP information -k Auto-kill - Kill highest user on specified boxes if all lines used Port-kill - use "hub_username_sessionid" option Debugging: -1 - Basic debugging -2 - Verbose debugging -3 - Verbose debugging and SNMP debugging The -P and -B option can be combined. HTML-WISE: Called from a simple giving it single, multiple IP address arguments, or a combination of group names and ip addresses or or if these two hosts are in a group called "Hazleton" or if you only want basic information CMDLINE-WISE: Called it, giving it single, multiple IP address arguments, or a combination of group names and ip addresses $ maxlist -P 216.250.154.75 or $ maxlist -P 216.250.154.75 216.250.154.76 or if these two hosts are in a group called "Hazleton" $ maxlist -P Hazleton or if you only want basic information $ maxlist -P -B Hazleton AUTO-KILLING: Running maxlist with the -k option makes the program check to see if a box(s) is totally filled with users (or at specified # of users). If so, it will kick the highest user off to free up a modem. If multiple are hosts are organized in a group, it will pick the highest user between all those hosts. Should be run from either the command line or better still, a crontab. I run it from my crontab every minute. I SUPPOSE you can run it from a browser like but it wont output anything. You just assume it's done when the browser stops. As said, the auto-killer part of the program program should be run from the command line or from a crontab. A crontab entry for one host run every minute would look something like this: * * * * * /path/to/cgi/bin/maxlist -k 216.250.154.76 for our example above, for the group "Hazleton" * * * * * /path/to/cgi/bin/maxlist -k Hazleton for all hosts in the above example * * * * * /path/to/cgi/bin/maxlist -k Hazleton 216.250.154.76 PORT-KILLING/SESSION-KILLING: The maxlist program can be used to kill/disconnect specific users/sessions. To do this, you can either click on the username in the HTML table version or run it from the command line with the proper info. From the command line, run it like this: $ maxlist hub_username_sessionid i.e. $ maxlist 216.250.154.76_joeblow_240583988 The info above can be found with the -P option from the command line. -Tony Intergrafix Internet Services thelittleprince@asteroid-b612.org