home *** CD-ROM | disk | FTP | other *** search
- PHP_Imon
-
- PHP Klone of the ISDN4k Util iMon to monitore your ISDN channels and dial or hangup single ISDN devices
-
-
- <?
- /*
- This is heavily based on the isdn4k-utils part imon.c
- so all licences and terms of trade are copied from there,
- => GPL version 2 or later
-
- Source of all :
- imon.c "$Id: imon.c,v 1.3 1997/05/17 12:23:35 fritz Exp $" from
-
- TODO : make sure that you can use the exec function with isdnctrl
- (hint : php save mode dir !)
- make sure that other users can call isdnctrl
-
- Contact : mb@daxtar.de, http://www.daxtar.de/isdn/
- */
-
-
- // Feel free to change this Options :
-
- $FONT = "Arial"; // I like this grave Font :-)
- $online_color = "#11FF11"; // quite bright green
- $offline_color = "#FF2D1D"; // quite bright red
- $calling_color = "#FFFFFF"; // quite bright white :-)
- $bg_image="/images/bg.gif";
-
-
- // this is optional ...
- $phonebook["12345"] = "ISDN Test 01";
- $phonebook["67890"] = "ISDN Test 02";
-
-
- // enable this to gain control to dial / hangup the devices !
- $enable_isdnctrl = 1;
-
- // list your isdndevices here, if you enabled the line above !
- $devices = array("ippp0" => "Japan Online", "ippp1" => "Honulullu Com");
- $isdnctrl = "/sbin/isdnctrl";
-
- // enable this to trigger IMON.PHP3 not to read out
- // /dev/isdninfo, but to use defaults [see "if (ISDN_TEST)"]
- define("ISDN_TEST", 0);
-
- ?>
-
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
- <HTML>
- <HEAD>
- <TITLE>Php Imon</TITLE>
- </HEAD>
-
- <BODY BACKGROUND="<? echo $bg_image; ?>">
-
- <TABLE BORDER="4" CELLPADDING="0" CELLSPACING="0" ALIGN="CENTER">
-
- <TR><TH bgcolor="00007F"><FONT FACE=<? echo $FONT ?> SIZE=+1 COLOR="white">Isdnctrl / Imon </TH></FONT>
- </TR>
-
- <TR><TD bgcolor=#C0C0C0>
-
- <?
- // some constants token from "isdn.h"
- define("ISDN_MAX_CHANNELS", 8);
- define("ISDN_USAGE_RAW", 1);
- define("ISDN_USAGE_MODEM", 2);
- define("ISDN_USAGE_NET", 3);
- define("ISDN_USAGE_VOICE", 4);
- define("ISDN_USAGE_FAX", 5);
-
- $service_id[] = "unkown";
- $service_id[] = "RAW";
- $service_id[] = "MODEM";
- $service_id[] = "NET";
- $service_id[] = "VOICE";
- $service_id[] = "FAX";
-
-
- if ($action != "") {
- $command_line = sprintf ("%s %s %s", $isdnctrl, $action, $command_device);
- exec($command_line);
- }
-
- if (!($isdninfo = fopen("/dev/isdninfo", "r"))) {
- printf("Can't open /dev/isdninfo\n");
- }
- else
- {
- if (ISDN_TEST) {
- $idmap_line = "idmap: TA250034 - - - - - - - - - - - - - - -";
- $chmap_line = "chmap: 0 1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1";
- $drmap_line = "drmap: 0 0 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1";
- $usage_line = "usage: 1 2 0 3 4 0 5 0 129 0 130 131 132 0 0 133";
- $flags_line = "flags: 0 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?";
- $phone_line = "phone: 05114711 0815 ??? 5555 666666666 ??? 4711 ??? 875257 ??? 77848 7890 2345467 ??? ??? 88888";
- }
- else
- {
- $idmap_line = fgets($isdninfo, 4095);
- $chmap_line = fgets($isdninfo, 4095);
- $drmap_line = fgets($isdninfo, 4095);
- $usage_line = fgets($isdninfo, 4095);
- $flags_line = fgets($isdninfo, 4095);
- $phone_line = fgets($isdninfo, 4095);
- }
-
- $idmap_ptr = $chmap_ptr = $drmap_ptr = $usage_ptr = $flags_ptr = $phone_ptr = 7;
-
-
- printf ("<TABLE BORDER=\"0\" CELLSPACING=2 CELLPADDING=2>\n");
- printf ("<TR><TH><FONT FACE=\"%s\" COLOR=\"black\">Channel</FONT></TH>\n", $FONT);
- printf ("<TH><FONT FACE=\"%s\" COLOR=\"black\">State</FONT></TH>\n", $FONT);
- printf ("<TH><FONT FACE=\"%s\" COLOR=\"black\">Type</FONT></TH>\n", $FONT);
- printf ("<TH><FONT FACE=\"%s\" COLOR=\"black\">Direction</FONT></TH>\n", $FONT);
- printf ("<TH><FONT FACE=\"%s\" COLOR=\"black\">Phone</FONT></TH></TR>\n", $FONT);
-
- for ($channel = 0; $channel <= ISDN_MAX_CHANNELS; $channel++)
- {
- $idmap = $chmap = $drmap = $usage = $flags = $phone = "";
- $online = $usage = 0;
-
- do {
- $idmap = $idmap.$idmap_line[$idmap_ptr];
- $idmap_ptr++;
- } while ($idmap_line[$idmap_ptr] != " ");
- do { $idmap_ptr++; } while ($idmap_line[$idmap_ptr] == " ");
-
- do {
- $chmap = $chmap.$chmap_line[$chmap_ptr];
- $chmap_ptr++;
- } while ($chmap_line[$chmap_ptr] != " ");
- do { $chmap_ptr++; } while ($chmap_line[$chmap_ptr] == " ");
-
- do {
- $drmap = $drmap.$drmap_line[$drmap_ptr];
- $drmap_ptr++;
- } while ($drmap_line[$drmap_ptr] != " ");
- do { $drmap_ptr++; } while ($drmap_line[$drmap_ptr] == " ");
-
- do {
- $usage = $usage.$usage_line[$usage_ptr];
- $usage_ptr++;
- } while ($usage_line[$usage_ptr] != " ");
- do { $usage_ptr++; } while ($usage_line[$usage_ptr] == " ");
-
- do {
- $flags = $flags.$flags_line[$flags_ptr];
- $flags_ptr++;
- } while ($flags_line[$flags_ptr] != " ");
- do { $flags_ptr++; } while ($flagsp_line[$flags_ptr] == " ");
-
- do {
- $phone = $phone.$phone_line[$phone_ptr];
- $phone_ptr++;
- } while ($phone_line[$phone_ptr] != " ");
- do { $phone_ptr++; } while ($phone_line[$phone_ptr] == " ");
-
- if ($chmap >= 0)
- {
-
- if ($usage&7)
- {
- $online = ($flags & (1<<$chmap));
- if ($online)
- {
- $color = $online_color;
- $state = "online";
- }
- else
- {
- $color = $calling_color;
- $state = "calling";
- }
-
- if (usage&ISDN_USAGE_OUTGOING)
- $direction = "outgoing";
- else
- $direction = "incoming";
-
- if (!($phonebook[$phone] == ""))
- $phone = $phonebook[$phone];
-
- printf ("<TR><TD bgcolor=\"black\"><FONT FACE=\"%s\" COLOR=\"%s\"><B>%d</B></FONT></TD>\n", $FONT, $color, $chmap);
- printf ("<TD bgcolor=\"black\"><FONT COLOR=\"%s\" FACE=\"%s\"><B>%s</B></FONT></TD>\n", $color, $FONT, $state);
- printf ("<TD bgcolor=\"black\"><FONT COLOR=\"%s\" FACE=\"%s\"><B>%s</B></FONT></TD>\n", $color, $FONT, $service_id[($usage&7)]);
- printf ("<TD bgcolor=\"black\"><FONT COLOR=\"%s\" FACE=\"%s\"><B>%s</B></FONT></TD>\n", $color, $FONT, $direction);
- printf ("<TD bgcolor=\"black\"><FONT COLOR=\"%s\" FACE=\"%s\"><B>%s</B></FONT></TD>\n", $color, $FONT, $phone);
- printf("</TR>\n");
- }
- else
- {
- printf ("<TR><TD bgcolor=\"black\"><FONT FACE=\"%s\" COLOR=\"%s\"><B>%d</B></TD>\n", $FONT, $offline_color, $chmap);
- printf ("<TD bgcolor=\"black\" COLSPAN=4><FONT FACE=\"%s\" COLOR=\"%s\"><B>offline</B></TD></TR>\n", $FONT, $offline_color);
- }
-
- }
- }
-
- }
-
-
- if ($enable_isdnctrl)
- {
- printf ("<TR><TD COLSPAN=\"5\"><HR></TD></TR>");
-
- printf ("<TR><TD bgcolor=\"white\" VALIGN=\"middle\" bgcolor=#C0C0C0>\n");
- printf ("<FORM NAME=\"DIAL\" ACTION=\"%s\">\n", getenv("SCRIPT_NAME"));
- printf ("<input type=\"radio\" name=\"action\" value=\"dial\" checked ><FONT FACE=\"%s\" COLOR=\"black\">dial</FONT><BR>\n", $FONT);
- printf ("<input type=\"radio\" name=\"action\" value=\"hangup\"><FONT FACE=\"%s\" COLOR=\"black\">hangup</FONT></TD>\n", $FONT);
- printf ("<TD bgcolor=\"white\" ALIGN=\"CENTER\" VALIGN=\"middle\" COLSPAN=\"3\"><SELECT name=\"command_device\">\n");
- while (list( $key, $val ) = each($devices))
- printf("<OPTION value=\"%s\">%s (%s)", $key, $key, $val);
- printf ("</SELECT></TD>");
- printf ("<TD bgcolor=\"white\" ALIGN=\"CENTER\" VALIGN=\"middle\"><input type=\"submit\" value=\"Ok\"></TD>\n");
- printf ("</FORM>\n");
- printf ("</TD></TR>\n");
- }
-
- printf ("<TR><TD COLSPAN=\"5\"><HR></TD></TR>");
- printf ("<TR><TD ALIGN=\"left\" COLSPAN=\"2\"><FORM ACRTION=\"%s\"><input type=\"submit\" value=\" refresh \"></TD></FORM>", getenv("SCRIPT_NAME"));
- printf ("<TD ALIGN=\"right\" COLSPAN=\"3\"><FORM ACTION=\"%s\"><input type=\"submit\" value=\" ISDN Report \"></TD></FORM></TR>", "isdnrep.php3");
-
-
- printf ("</TABLE>\n");
- ?>
-
- </TD></TR>
- </TABLE>
-
- </BODY>
- </HTML>
-