home *** CD-ROM | disk | FTP | other *** search
/ H4CK3R 4 / hacker04 / 04_HACK04.ISO / src / PHP / phpimon.php3.txt < prev    next >
Encoding:
Text File  |  2002-05-06  |  8.3 KB  |  235 lines

  1. PHP_Imon 
  2.  
  3. PHP Klone of the ISDN4k Util iMon to monitore your ISDN channels and dial or hangup single ISDN devices 
  4.  
  5.  
  6. <?
  7.   /*
  8.   This is heavily based on the isdn4k-utils part imon.c
  9.   so all licences and terms of trade are copied from there,
  10.   => GPL version 2 or later 
  11.  
  12.   Source of all :  
  13.             imon.c  "$Id: imon.c,v 1.3 1997/05/17 12:23:35 fritz Exp $" from 
  14.  
  15.   TODO    : make sure that you can use the exec function with isdnctrl 
  16.             (hint : php save mode dir !)
  17.             make sure that other users can call isdnctrl
  18.  
  19.   Contact : mb@daxtar.de, http://www.daxtar.de/isdn/
  20.   */
  21.         
  22.  
  23.   // Feel free to change this Options :
  24.     
  25.     $FONT          = "Arial";   // I like this grave Font :-)
  26.     $online_color  = "#11FF11"; // quite bright green
  27.     $offline_color = "#FF2D1D"; // quite bright red
  28.     $calling_color = "#FFFFFF"; // quite bright white :-)
  29.     $bg_image="/images/bg.gif";
  30.  
  31.  
  32.   // this is optional ...
  33.     $phonebook["12345"] = "ISDN Test 01";
  34.     $phonebook["67890"] = "ISDN Test 02";
  35.   
  36.     
  37.   // enable this to gain control to dial / hangup the devices !
  38.     $enable_isdnctrl = 1;
  39.     
  40.   // list your isdndevices here, if you enabled the line above !
  41.     $devices = array("ippp0" => "Japan Online", "ippp1" => "Honulullu Com");
  42.     $isdnctrl = "/sbin/isdnctrl";
  43.     
  44.   // enable this to trigger IMON.PHP3 not to read out 
  45.   // /dev/isdninfo, but to use defaults [see "if (ISDN_TEST)"]
  46.     define("ISDN_TEST", 0);
  47.   
  48. ?>
  49.  
  50. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
  51. <HTML>
  52. <HEAD>
  53. <TITLE>Php Imon</TITLE>
  54. </HEAD>
  55.  
  56. <BODY BACKGROUND="<? echo $bg_image; ?>">
  57.  
  58. <TABLE BORDER="4" CELLPADDING="0" CELLSPACING="0" ALIGN="CENTER">
  59.  
  60. <TR><TH bgcolor="00007F"><FONT  FACE=<? echo $FONT ?> SIZE=+1 COLOR="white">Isdnctrl / Imon </TH></FONT>
  61. </TR>
  62.  
  63. <TR><TD bgcolor=#C0C0C0>
  64.  
  65. <?
  66.   // some constants token from "isdn.h"
  67.   define("ISDN_MAX_CHANNELS", 8);
  68.   define("ISDN_USAGE_RAW", 1);
  69.   define("ISDN_USAGE_MODEM", 2);
  70.   define("ISDN_USAGE_NET", 3);
  71.   define("ISDN_USAGE_VOICE", 4);
  72.   define("ISDN_USAGE_FAX", 5);
  73.   
  74.   $service_id[] = "unkown";
  75.   $service_id[] = "RAW";
  76.   $service_id[] = "MODEM";
  77.   $service_id[] = "NET";
  78.   $service_id[] = "VOICE";
  79.   $service_id[] = "FAX";
  80.  
  81.  
  82.   if ($action != "") {
  83.     $command_line = sprintf ("%s %s %s", $isdnctrl, $action, $command_device);
  84.       exec($command_line);
  85.   }
  86.     
  87.   if (!($isdninfo = fopen("/dev/isdninfo", "r"))) {
  88.     printf("Can't open /dev/isdninfo\n");
  89.   }
  90.   else
  91.   {
  92.     if (ISDN_TEST) {
  93.       $idmap_line = "idmap: TA250034 - - - - - - - - - - - - - - -";
  94.       $chmap_line = "chmap: 0 1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1";
  95.       $drmap_line = "drmap: 0 0 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1";   
  96.       $usage_line = "usage: 1 2 0 3 4 0 5 0 129 0 130 131 132 0 0 133";
  97.       $flags_line = "flags: 0 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?";
  98.       $phone_line = "phone: 05114711 0815 ??? 5555 666666666 ??? 4711 ??? 875257 ??? 77848 7890 2345467 ??? ??? 88888";
  99.     }
  100.     else
  101.     {
  102.       $idmap_line = fgets($isdninfo, 4095);
  103.       $chmap_line = fgets($isdninfo, 4095);
  104.       $drmap_line = fgets($isdninfo, 4095);
  105.       $usage_line = fgets($isdninfo, 4095);
  106.       $flags_line = fgets($isdninfo, 4095);
  107.       $phone_line = fgets($isdninfo, 4095);
  108.     }
  109.     
  110.     $idmap_ptr = $chmap_ptr = $drmap_ptr = $usage_ptr = $flags_ptr = $phone_ptr = 7;
  111.  
  112.     
  113.     printf ("<TABLE BORDER=\"0\" CELLSPACING=2 CELLPADDING=2>\n");
  114.     printf ("<TR><TH><FONT FACE=\"%s\" COLOR=\"black\">Channel</FONT></TH>\n", $FONT);
  115.     printf ("<TH><FONT FACE=\"%s\" COLOR=\"black\">State</FONT></TH>\n", $FONT);
  116.     printf ("<TH><FONT FACE=\"%s\" COLOR=\"black\">Type</FONT></TH>\n", $FONT);
  117.     printf ("<TH><FONT FACE=\"%s\" COLOR=\"black\">Direction</FONT></TH>\n", $FONT);
  118.     printf ("<TH><FONT FACE=\"%s\" COLOR=\"black\">Phone</FONT></TH></TR>\n", $FONT);
  119.         
  120.     for ($channel = 0; $channel <= ISDN_MAX_CHANNELS; $channel++)
  121.     {
  122.       $idmap = $chmap = $drmap = $usage = $flags = $phone = "";
  123.       $online = $usage = 0;
  124.       
  125.       do {
  126.          $idmap = $idmap.$idmap_line[$idmap_ptr];
  127.          $idmap_ptr++;
  128.       } while ($idmap_line[$idmap_ptr] != " ");
  129.       do { $idmap_ptr++; } while ($idmap_line[$idmap_ptr] == " ");
  130.       
  131.       do {
  132.         $chmap = $chmap.$chmap_line[$chmap_ptr];
  133.         $chmap_ptr++;
  134.       } while ($chmap_line[$chmap_ptr] != " ");
  135.       do { $chmap_ptr++; } while ($chmap_line[$chmap_ptr] == " ");
  136.       
  137.       do {
  138.         $drmap = $drmap.$drmap_line[$drmap_ptr];
  139.         $drmap_ptr++;
  140.       } while ($drmap_line[$drmap_ptr] != " ");
  141.       do { $drmap_ptr++; } while ($drmap_line[$drmap_ptr] == " ");
  142.       
  143.       do {
  144.         $usage = $usage.$usage_line[$usage_ptr];
  145.         $usage_ptr++;
  146.       } while ($usage_line[$usage_ptr] != " ");
  147.       do { $usage_ptr++; } while ($usage_line[$usage_ptr] == " ");
  148.           
  149.       do {
  150.         $flags = $flags.$flags_line[$flags_ptr];
  151.         $flags_ptr++;
  152.       } while ($flags_line[$flags_ptr] != " ");
  153.       do { $flags_ptr++; } while ($flagsp_line[$flags_ptr] == " ");
  154.       
  155.       do {
  156.         $phone = $phone.$phone_line[$phone_ptr];
  157.         $phone_ptr++;
  158.       } while ($phone_line[$phone_ptr] != " ");
  159.       do { $phone_ptr++; } while ($phone_line[$phone_ptr] == " ");
  160.             
  161.       if ($chmap >= 0)
  162.       {
  163.         
  164.         if ($usage&7)
  165.         {
  166.           $online = ($flags & (1<<$chmap));
  167.           if ($online)
  168.           {
  169.             $color = $online_color;
  170.             $state = "online";
  171.           }
  172.           else
  173.           {
  174.             $color = $calling_color;
  175.             $state = "calling";
  176.           }
  177.           
  178.           if (usage&ISDN_USAGE_OUTGOING)
  179.             $direction = "outgoing";
  180.           else
  181.             $direction = "incoming";
  182.             
  183.           if (!($phonebook[$phone] == ""))
  184.             $phone = $phonebook[$phone];
  185.             
  186.           printf ("<TR><TD bgcolor=\"black\"><FONT FACE=\"%s\" COLOR=\"%s\"><B>%d</B></FONT></TD>\n", $FONT, $color, $chmap);
  187.           printf ("<TD bgcolor=\"black\"><FONT COLOR=\"%s\" FACE=\"%s\"><B>%s</B></FONT></TD>\n", $color, $FONT, $state);
  188.           printf ("<TD bgcolor=\"black\"><FONT COLOR=\"%s\" FACE=\"%s\"><B>%s</B></FONT></TD>\n", $color, $FONT, $service_id[($usage&7)]);
  189.           printf ("<TD bgcolor=\"black\"><FONT COLOR=\"%s\" FACE=\"%s\"><B>%s</B></FONT></TD>\n", $color, $FONT, $direction);
  190.           printf ("<TD bgcolor=\"black\"><FONT COLOR=\"%s\" FACE=\"%s\"><B>%s</B></FONT></TD>\n", $color, $FONT, $phone);
  191.           printf("</TR>\n");
  192.         }
  193.         else
  194.           {
  195.             printf ("<TR><TD bgcolor=\"black\"><FONT FACE=\"%s\" COLOR=\"%s\"><B>%d</B></TD>\n", $FONT, $offline_color, $chmap);
  196.             printf ("<TD bgcolor=\"black\" COLSPAN=4><FONT FACE=\"%s\" COLOR=\"%s\"><B>offline</B></TD></TR>\n", $FONT, $offline_color);
  197.           }
  198.  
  199.       }
  200.     }
  201.     
  202.   }
  203.   
  204.  
  205.   if ($enable_isdnctrl)
  206.   {
  207.     printf ("<TR><TD COLSPAN=\"5\"><HR></TD></TR>");
  208.     
  209.     printf ("<TR><TD bgcolor=\"white\" VALIGN=\"middle\" bgcolor=#C0C0C0>\n");
  210.     printf ("<FORM NAME=\"DIAL\" ACTION=\"%s\">\n", getenv("SCRIPT_NAME"));
  211.     printf ("<input type=\"radio\" name=\"action\" value=\"dial\" checked ><FONT FACE=\"%s\" COLOR=\"black\">dial</FONT><BR>\n", $FONT);
  212.     printf ("<input type=\"radio\" name=\"action\" value=\"hangup\"><FONT FACE=\"%s\" COLOR=\"black\">hangup</FONT></TD>\n", $FONT);
  213.     printf ("<TD bgcolor=\"white\" ALIGN=\"CENTER\" VALIGN=\"middle\" COLSPAN=\"3\"><SELECT name=\"command_device\">\n");
  214.     while (list( $key, $val ) = each($devices))
  215.        printf("<OPTION value=\"%s\">%s (%s)", $key, $key, $val);
  216.     printf ("</SELECT></TD>");
  217.     printf ("<TD bgcolor=\"white\" ALIGN=\"CENTER\" VALIGN=\"middle\"><input type=\"submit\" value=\"Ok\"></TD>\n");
  218.     printf ("</FORM>\n");
  219.     printf ("</TD></TR>\n");    
  220.   }
  221.   
  222.   printf ("<TR><TD COLSPAN=\"5\"><HR></TD></TR>");
  223.   printf ("<TR><TD ALIGN=\"left\" COLSPAN=\"2\"><FORM ACRTION=\"%s\"><input type=\"submit\" value=\"     refresh     \"></TD></FORM>", getenv("SCRIPT_NAME"));
  224.   printf ("<TD ALIGN=\"right\" COLSPAN=\"3\"><FORM ACTION=\"%s\"><input type=\"submit\" value=\"       ISDN Report        \"></TD></FORM></TR>", "isdnrep.php3");
  225.  
  226.  
  227.   printf ("</TABLE>\n");
  228. ?>
  229.  
  230. </TD></TR>
  231. </TABLE>
  232.  
  233. </BODY>
  234. </HTML>
  235.