[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/se3-ocs/sources/www/ -> ipdiscover.php (source)

   1  <?
   2  //====================================================================================
   3  // OCS INVENTORY REPORTS
   4  // Copyleft Pierre LEMMET 2005
   5  // Web: http://ocsinventory.sourceforge.net
   6  //
   7  // This code is open source and may be copied and modified as long as the source
   8  // code is always made freely available.
   9  // Please refer to the General Public Licence http://www.gnu.org/ or Licence.txt
  10  //====================================================================================
  11  //Modified on 07/05/2006
  12  
  13  set_time_limit(0);
  14  $nbpop=0;
  15  $fipdisc = "ipdiscover-util.pl" ;
  16  if( $scriptPresent = @stat($fipdisc) ) {
  17      $filePresent = true;
  18      if( ! is_executable($fipdisc) ) {
  19          $scriptPresent = false;
  20      }
  21      else if( ! is_writable(".") ) {
  22          $scriptPresent = false;
  23      }    
  24  }
  25  
  26  if( !isset( $_GET["mode"] )) {
  27      $_SESSION["retour"] = "multi=3";
  28  }
  29  
  30  $_SESSION["pas"] = isset($_GET["pas"]) ? $_GET["pas"] : $_SESSION["pas"];
  31  $nomRez = getNameFromRes($_SESSION["pas"]);
  32  
  33  switch( $_GET["mode"] ) {
  34      case 12: $_SESSION["retour"] = "multi=3&mode=12"; break;
  35      case 6:  $_SESSION["retour"] = "multi=3&mode=6&pas=".$_GET["pas"]."&nam".$_GET["nam"]; break;
  36      case 2:  $_SESSION["retour"] = "multi=3&mode=2&pas=".$_GET["pas"]."&nam".$_GET["nam"]; 
  37              if( $filePresent ) {
  38                  if( ! is_executable($fipdisc) ) {
  39                      echo "<br><center><b><font color='red'>$fipdisc ".$l->g(341)."</b></center>";
  40                  }
  41                  else if( ! is_writable(".") ) {
  42                      echo "<br><center><b><font color='red'>".$l->g(342)." $fipdisc</b></center>";
  43                  }    
  44              }
  45              break;
  46              
  47      case 8:  
  48              $_SESSION["direct"] = isset($_GET["direct"]) ? $_GET["direct"] : $_SESSION["direct"];
  49              if( $_GET["direct"] == 2 )
  50                  $_SESSION["retour"] = "multi=3&mode=1";
  51              else if( isset($_GET["direct"]) ) {                                                
  52                          $toPage =  $_GET["direct"] == 3 ? 2 : 6 ;
  53                          $_SESSION["retour"] = "multi=3&mode=$toPage&pas=".$_SESSION["pas"]; break;
  54              }
  55      default;    
  56  }
  57  
  58  foreach ($_GET as $gk=>$gv) {
  59      if($gk=="rev" || $gk=="c"|| $gk=="a") continue;
  60  //    $_SESSION["fromPage"] .= "&{$gk}=$gv"; TODO: c� koi ?
  61  }
  62  
  63  if( ! $scriptPresent && ! $_GET["mode"] ) {
  64      $scriptPresent = false ;
  65  }
  66  
  67  if(!isset($_GET["mode"])) {
  68  
  69      printEnTete($l->g(43));
  70      echo "<br><table width='400px' border='0' align='center'>";
  71      echo "<tr align='center'><td width='40px'><img src='image/Gest_admin1.png'></td><td align='left'><a href='?multi=3&mode=1'>".$l->g(289)."</a></img></td></tr>";
  72      if( $scriptPresent ) {
  73          echo "<tr align='center'><td width='40px'><img src='image/Gest_admin1.png'></td><td align='left'><a href='?multi=3&mode=7'>".$l->g(290)."</a></img></td></tr>";
  74      }    
  75      echo "<tr align='center'><td width='40px'><img src='image/Gest_admin1.png'></td><td align='left'><a href='?multi=3&mode=9'>".$l->g(107)."</a></img></td></tr></table>";
  76  }
  77  else if( $_GET["mode"] == 12 ) {
  78      printEnTete($l->g(219));
  79      echo "<br><center><a href=index.php?multi=3><= ".$l->g(188)."</a></center>";
  80      $req = "SELECT ip,mac,mask,date FROM netmap LEFT JOIN(networks) ON mac=macaddr WHERE macaddr IS NULL";
  81      $reqC = "SELECT COUNT(ip) FROM netmap LEFT JOIN(networks) ON mac=macaddr WHERE macaddr IS NULL";
  82      
  83      $requete = new Req($l->g(219),$req,$reqC,"","","");
  84      ShowResults($requete,true,false,false,false,false);
  85  }
  86  else if( $_GET["mode"] == 9 ) {
  87      $_SESSION["fromdet"] = false;
  88      printEnTete($l->g(107));
  89  ?>    
  90      <br><center><a href=index.php?multi=3><= <?echo $l->g(188);?></a></center><br>
  91      <table width='400px' border='0' align='center'>
  92      <tr align='center'><td width='40px'><img src='image/Gest_admin1.png'></td><td align='left'><a href='?multi=3&mode=10'><?echo $l->g(293);?></a></img></td></tr>
  93      <tr align='center'><td width='40px'><img src='image/Gest_admin1.png'></td><td align='left'><a href='?multi=3&mode=11'><?echo $l->g(294);?></a></img></td></tr>
  94      </table>
  95  <?    
  96  }
  97  else if( $_GET["mode"] == 11 ) {
  98      if( isset($_GET["ipa"]) && ! isset($_GET["self"]) ) {
  99          $_SESSION["fromdet"] = true;
 100      }
 101      
 102      if( isset( $_POST["subRez"] ) ) {
 103          if( $_POST["nomrez"] == "" || $_POST["dpt"] == "" || $_POST["ipa"] == "" || $_POST["ipm"] == "" ) {
 104              echo "<center><font color='red'><b>".$l->g(298)."</b></font></center>";
 105          }
 106          else if( ! preg_match("/^([0-9]{1,3}\.){3}[0-9]{1,3}$/",$_POST["ipa"] )) {
 107              echo "<center><font color='red'><b>".$l->g(299)."</b></font></center>";
 108          }
 109          else if( (! preg_match("/^([0-9]{1,3}\.){3}[0-9]{1,3}$/", $_POST["ipm"] )) && ((! preg_match("/^[0-9]{1,2}$/", $_POST["ipm"] ) )||($_POST["ipm"]>32)) ) {
 110              echo "<center><font color='red'><b>".$l->g(300)."</b></font></center>";
 111          }    
 112          else {
 113              $newRez = true;
 114              $exist = true;
 115              unset($_SESSION["lastTri"]);
 116              $reqDelete = "DELETE FROM subnet WHERE netid ='".$_POST["ipa"]."'";
 117              @mysql_query( $reqDelete, $_SESSION["writeServer"] );
 118              $reqInsert = "INSERT INTO subnet(name, id, netid, mask) VALUES ('".$_POST["nomrez"]."', '".$_POST["dpt"]."', '".$_POST["ipa"]."','".$_POST["ipm"]."')";
 119              @mysql_query( $reqInsert, $_SESSION["writeServer"] );
 120              if(mysql_affected_rows()>0)
 121                  echo "<br><center><font color='green'><b>".$l->g(301)." (".$_POST["nomrez"]."  ".$_POST["dpt"]."  ".$_POST["ipa"]." / ".$_POST["ipm"].")</b></font></center>";
 122              else
 123                  echo "<br><center><font color='red'><b>".$l->g(362)." ".$_POST["ipa"]." ".$l->g(363)."</b></font></center>";
 124          }
 125      }
 126      
 127      if( isset($_GET["delrez"])) {
 128          unset($_SESSION["lastTri"]);
 129          $reqSupp = "DELETE FROM subnet WHERE netid='".$_GET["delrez"]."';";
 130          mysql_query( $reqSupp, $_SESSION["writeServer"]) or die(mysql_error($_SESSION["writeServer"]));
 131          echo "<center><font color='green'><b>".$l->g(302)." (netid :".$_GET["delrez"]." )</b></font></center>";
 132      }    
 133      
 134      $tab[0] = Array($l->g(295),$l->g(296),$l->g(82),$l->g(208));
 135      $tailles = Array( 300, 30, 150,150 );
 136      $types = Array("SORT_STRING","SORT_NUMERIC","SORT_STRING","SORT_STRING");
 137      
 138      $reqSubnet = "SELECT  name, id, netid, mask FROM subnet";
 139      $resSubnet = mysql_query($reqSubnet, $_SESSION["readServer"]) or die(mysql_error($_SESSION["readServer"]));
 140      
 141      while( $valSubnet = mysql_fetch_array($resSubnet) ) {
 142          $tab[] = array( "<a href=index.php?multi=3&self=1&mode=11&ipa=".urlencode($valSubnet["netid"])."&nomrez=".urlencode($valSubnet["name"])."&dpt=".urlencode($valSubnet["id"])."&ipm=".urlencode($valSubnet["mask"]).">".$valSubnet["name"]."</a>",
 143              $valSubnet["id"],$valSubnet["netid"],  $valSubnet["mask"] ,
 144          "<a href='index.php?multi=3&mode=11&tri=".$_GET["tri"]."&delrez=".urlencode($valSubnet["netid"])."'><img src=image/supp.png></a>");
 145          $exist = true;
 146      }
 147      
 148      printEnTete($l->g(303));
 149      $tri = isset($_GET["tri"])?$_GET["tri"]:$_POST["tri"];
 150      $ValNomRez =  isset($_POST["nomrez"]) ? $_POST["nomrez"] : (isset($_GET["nomrez"]) ? $_GET["nomrez"] : "") ;
 151      $ValDpt    =  isset($_POST["dpt"])? $_POST["dpt"] : (isset($_GET["dpt"]) ? $_GET["dpt"] : "") ;
 152      $ValIpa    =  isset($_POST["ipa"])? $_POST["ipa"] : (isset($_GET["ipa"]) ? $_GET["ipa"] : "") ;
 153      $ValIpm    =  isset($_POST["ipm"])? $_POST["ipm"] : (isset($_GET["ipm"]) ? $_GET["ipm"] : "") ;
 154          
 155      ?>
 156      <br><form name='formip' action='index.php?multi=3&mode=11' method='POST'>
 157      <table align='center'>
 158          <tr><td><?echo $l->g(304);?> :</td><td><input type='text' size='50' name='nomrez' value='<?echo $ValNomRez;?>'></td><td>&nbsp;&nbsp;
 159          <?echo $l->g(305);?> :</td><td><input type='text' size='3' name='dpt' value='<?echo $ValDpt;?>'></td></tr>
 160          </tr><tr><td><?echo $l->g(34);?> :</td><td><input type='text' name='ipa' value='<?echo $ValIpa;?>'</td><td>&nbsp;&nbsp;<?echo $l->g(208);?>:
 161          </td><td><input type='text' name='ipm' value='<?echo $ValIpm;?>'></td></tr>
 162          <tr><td align='right' colspan='4'><input type='submit' name='subRez' value='<?echo $l->g(13);?>'>
 163          <input type='hidden' name='tri' value='<?echo $tri;?>'></td></tr>
 164          </tr>
 165      </table>
 166      </form>
 167      <br><center><a href=index.php?multi=3&mode=<? echo $_SESSION["fromdet"]==true ? "1" : "9" ; ?>><= <?echo $l->g(188);?></a></center>
 168      <?
 169      if( $exist ) {
 170          printEnTete($l->g(306));
 171          echo "<br>";
 172          $toPrint = $tab;
 173          
 174          if( $tri != "" )
 175              $toPrint = trieTab($tab,$tri,$types );
 176              
 177          printTab($toPrint,false,$tailles);
 178      }
 179      
 180  }
 181  else if( $_GET["mode"] == 10 ) {
 182      printEnTete($l->g(307));
 183      
 184      if( isset( $_POST["subTyp"]) && $_POST["nomtyp"]!="" ) {
 185          $val = addslashes( $_POST["nomtyp"] );
 186          unset($_SESSION["lastTri"]);
 187          $reqAddTyp = "INSERT INTO devicetype(name) VALUES('$val')";
 188          mysql_query( $reqAddTyp , $_SESSION["writeServer"]) or die(mysql_error($_SESSION["writeServer"]));
 189      }
 190      
 191      if( isset( $_GET["deltyp"] )) {
 192          $reqDelTyp = "DELETE FROM devicetype WHERE name='".urldecode($_GET["deltyp"])."'";
 193          mysql_query( $reqDelTyp, $_SESSION["writeServer"] ) or die(mysql_error($_SESSION["writeServer"]));
 194      }
 195          
 196      ?>    
 197      <br><center><a href='index.php?multi=3<?echo ($scriptPresent?"&mode=9":""); ?>'><= <?echo $l->g(188);?></a></center><br>
 198      <br><form name='formip' action='index.php?multi=3&mode=10' method='POST'>
 199      <table align='center'>
 200          <tr><td><?echo $l->g(308);?> :</td><td><input type='text' size='50' name='nomtyp'></td></tr>
 201          <tr><td align='right' colspan='4'><input type='submit' name='subTyp' value='<?echo $l->g(13);?>'></td></tr>
 202      </table>
 203      </form>
 204  
 205      <?
 206      $reqTypes = "SELECT DISTINCT(name) FROM devicetype";
 207      $resType = mysql_query( $reqTypes, $_SESSION["readServer"] ) or die(mysql_error($_SESSION["readServer"]));
 208      $tab[0] = Array("Type","");
 209      $tailles = Array(200,30);
 210      $cptligne = 1;
 211      while( $valType = mysql_fetch_array($resType) ) {
 212          $tab[] = Array( stripslashes($valType["name"]) , "<a href='index.php?multi=3&mode=10&deltyp=".urlencode($valType["name"])."'><img src=image/supp.png></a>");
 213          $cptligne++;
 214          $exist = true;
 215      }
 216      if( $exist ) {
 217          printEnTete($l->g(309));
 218          echo "<br>";
 219          printTab($tab,false,$tailles);
 220      }
 221  
 222  }
 223  // Page with all detailed networks
 224  else if( $_GET["mode"] == 1 ) {
 225              
 226      $reqIpConf = "SELECT ivalue FROM config WHERE name='IPDISCOVER'";
 227      $resIpConf = mysql_query( $reqIpConf, $_SESSION["readServer"] ) or die(mysql_error($_SESSION["readServer"]));
 228      $valIpConf = mysql_fetch_array( $resIpConf );
 229      $maxIpConfig = $valIpConf["ivalue"];
 230      
 231      if(isset($_POST["maxipd"])) {
 232          if( $_POST["maxipd"] == $l->g(215) ) {
 233              unset( $_POST["maxipd"] );
 234              unset( $_SESSION["maxipd"] );
 235          }
 236          else {
 237              $_SESSION["maxipd"] = $_POST["maxipd"];
 238          }
 239      }
 240      else
 241          $_SESSION["maxipd"] = $maxIpConfig;
 242      
 243      $totNinvReq = "SELECT COUNT(DISTINCT mac) as total FROM netmap WHERE mac NOT IN (SELECT DISTINCT(macaddr) FROM networks)";
 244      $totNinvRes = mysql_query( $totNinvReq, $_SESSION["readServer"]) or die(mysql_error($_SESSION["readServer"]));
 245      $totNinvVal = mysql_fetch_array( $totNinvRes );
 246  
 247      $t[0]    = Array("",$l->g(295),"","Uid","",$l->g(304),"",$l->g(364),"",$l->g(365),"",$l->g(312),"",$l->g(366));
 248      $types   = Array("","SORT_STRING","","SORT_NUMERIC","","SORT_STRING","","SORT_NUMERIC","","SORT_NUMERIC","","SORT_NUMERIC","","SORT_NUMERIC");
 249      $tailles = Array( 0,250,0,50,0,250,0,70,0,70,0,70,0,70);    
 250      
 251      $cptL = 1;
 252      $reqGateway = "SELECT ipsubnet as nbrez, COUNT(hardware_id) AS nbc FROM networks WHERE ipsubnet<>'0.0.0.0' AND description NOT LIKE '%PPP%' GROUP BY(ipsubnet)";
 253      $strEnTete = $l->g(289)."<br><br>(<font color='red'>".$totNinvVal["total"]."</font> ".$l->g(219).")";
 254      
 255      printEnTete($strEnTete);
 256      echo "<br><center><a href=index.php?multi=3><= ".$l->g(188)."</a></center><br>";
 257      $auMoinsUnRezo = false;
 258      $resGateway = mysql_query($reqGateway, $_SESSION["readServer"]) or die(mysql_error($_SESSION["readServer"]));    
 259  
 260      while( $arrGateway = mysql_fetch_array($resGateway) ) {
 261          $auMoinsUnRezo = true;
 262          $resIpd = mysql_query("SELECT COUNT(*) AS nbi FROM devices WHERE name='IPDISCOVER' AND tvalue='".$arrGateway["nbrez"]."'", $_SESSION["readServer"]) or die(mysql_error($_SESSION["readServer"]));
 263          $arrIpd = mysql_fetch_array( $resIpd );
 264  
 265          if( ! preg_match("/^([0-9]{1,3}\.){3}[0-9]{1,3}$/",$arrGateway["nbrez"]) ) {
 266              continue ;
 267          }
 268          $masque = getMask( $arrGateway["nbrez"] ) ;                            
 269  
 270          $reqSubnet = "SELECT name,id,mask FROM subnet WHERE NETID='".$arrGateway["nbrez"]."'";
 271          $resSubnet = mysql_query($reqSubnet, $_SESSION["readServer"]) or die(mysql_error());
 272          if( $valSubnet = mysql_fetch_array( $resSubnet ) ) {            
 273              $t[ $cptL ][] = "";
 274              $t[ $cptL ][] = "<a href=index.php?multi=3&mode=11&ipa=".urlencode($arrGateway["nbrez"])."&nomrez=".urlencode($valSubnet["name"])."&dpt=".urlencode($valSubnet["id"])."&ipm=".urlencode($valSubnet["mask"]).">".$valSubnet["name"]."</a>";
 275              $t[ $cptL ][] = "";
 276              $t[ $cptL ][] = $valSubnet["id"];
 277          }
 278          else {                
 279              $t[ $cptL ][] = "";
 280              $t[ $cptL ][] = "<a href=index.php?multi=3&mode=11&ipa=".$arrGateway["nbrez"].">-> ".$l->g(295)." <-</a>";
 281              $t[ $cptL ][] = "";
 282              $t[ $cptL ][] = "0";
 283          }
 284          
 285          $t[ $cptL ][] = "";
 286          $t[ $cptL ][] = $arrGateway["nbrez"];
 287          
 288          $t[ $cptL ][] = popup("multi=3&mode=4&pas=".urlencode($arrGateway["nbrez"]));
 289          $t[ $cptL ][] = $arrGateway["nbc"];
 290          
 291          $reqNonInv = "SELECT COUNT(*) AS nbnoninv FROM netmap WHERE NETID='".$arrGateway["nbrez"]."' 
 292          AND mac NOT IN (SELECT DISTINCT(macaddr) FROM networks) AND mac NOT IN (SELECT DISTINCT(macaddr) FROM network_devices)";
 293          $resNonInv = mysql_query($reqNonInv, $_SESSION["readServer"]) or die(mysql_error());
 294          
 295          if( $valNonInv = mysql_fetch_array( $resNonInv ) ) {    
 296              if( $valNonInv["nbnoninv"] > 0)
 297                  $t[ $cptL ][] = popup("multi=3&mode=2&pas=".$arrGateway["nbrez"]);
 298              else
 299                  $t[ $cptL ][] = "";
 300                  
 301              $t[ $cptL ][] = $valNonInv["nbnoninv"]."</a>";
 302          }
 303          else {
 304              $t[ $cptL ][] = "";
 305              $t[ $cptL ][] = "-";
 306          }
 307          
 308          if($arrIpd["nbi"]>0) {
 309              $t[ $cptL ][] = popup("multi=3&mode=5&pas=".urlencode($arrGateway["nbrez"]));
 310              $t[ $cptL ][] = $arrIpd["nbi"]."</a>";
 311          }
 312          else {
 313              $t[ $cptL ][] = "" ;
 314              $t[ $cptL ][] = "0" ;
 315          }
 316  
 317          $reqSais = "SELECT COUNT(id) as nbSais FROM network_devices n,netmap a WHERE a.netid='".$arrGateway["nbrez"]."' AND n.macaddr=a.mac";
 318          
 319          $resSais = mysql_query($reqSais, $_SESSION["readServer"]) or die(mysql_error());
 320          if( ($valSais = mysql_fetch_array( $resSais )) && ($valSais["nbSais"] > 0)) {
 321              $t[ $cptL ][] = popup("multi=3&mode=8&direct=2&pas=".urlencode($arrGateway["nbrez"]));
 322              $t[ $cptL ][] = $valSais["nbSais"]."</a>";
 323          }
 324          else {
 325              $t[ $cptL ][] = "" ;
 326              $t[ $cptL ][] = "0" ;
 327          }
 328          
 329          $cptL++;
 330      }    
 331      $toPrint = $t;
 332      
 333      if( $auMoinsUnRezo ) {
 334          if( isset($_GET["tri"] ) )
 335              $toPrint = trieTab($t,$_GET["tri"],$types );            
 336          
 337          printTab($toPrint,false,$tailles,true,true);
 338      }
 339      else
 340          echo "<div align=center><b>".$l->g(42)."</b></div>";
 341  }
 342  else if( $_GET["mode"] == 4 ) {
 343  
 344      $strEnTete = $l->g(367)." ".$_GET["pas"]."<br><br>".$nomRez;
 345      printEnTete($strEnTete);
 346      //echo "<br><center><a href=index.php?multi=3&mode=1><= ".$l->g(188)."</a></center><br>";
 347      if($_GET["pas"] == ""){
 348          $finSubnet = "is null";
 349      }
 350      else
 351          $finSubnet = "='".$_GET["pas"]."'";
 352  
 353      $lbl = $l->g(313)." ".$_GET["pas"];    
 354      $sql = "n.ipsubnet $finSubnet";
 355      $whereId = "n.id";
 356      $linkId = "n.id";
 357      $select = array_merge( array("h.id"=>"h.id", "h.deviceid"=>"deviceid","n.ipmask"=>$l->g(208),"n.ipgateway"=>"n.ipgateway","quality"=>"quality","fidelity"=>"fidelity"), $_SESSION["currentFieldList"] );    
 358      $selectPrelim = array( "n.id"=>"n.id" );
 359      $from = "hardware h LEFT JOIN accountinfo a ON a.hardware_id=h.id LEFT JOIN bios b ON b.hardware_id=h.id LEFT JOIN networks n ON n.hardware_id=h.id";
 360      $fromPrelim = "";
 361      $group = "";
 362      $order = "";
 363      $countId = "h.id";
 364      
 365      $requete = new Req($lbl,$whereId,$linkId,$sql,$select,$selectPrelim,$from,$fromPrelim,$group,$order,$countId,true);
 366      ShowResults($requete,true,false,false,false);
 367  }
 368  else  if( $_GET["mode"] == 5 ) {
 369  
 370      $strEnTete = $l->g(367)." ".$_GET["pas"]."<br><br>".$nomRez;
 371      printEnTete($strEnTete);
 372      //echo "<br><center><a href=index.php?multi=3&mode=1><= ".$l->g(188)."</a></center><br>";
 373      if($_GET["pas"] == ""){
 374          $finGateway = "is null";
 375      }
 376      else
 377          $finGateway = "='".$_GET["pas"]."'";
 378      
 379      $lbl = $l->g(314)." ".$_GET["pas"];    
 380      $sql = "d.name='IPDISCOVER' AND (d.ivalue=1||d.ivalue=2) AND d.tvalue ='".$_GET["pas"]."'";
 381      $whereId = "d.name='IPDISCOVER' AND h.id";
 382      $linkId = "h.id";
 383      $select = array_merge( array("h.id"=>"h.id", "h.deviceid"=>"deviceid","quality"=>"quality","fidelity"=>"fidelity"), $_SESSION["currentFieldList"] );    
 384      $selectPrelim = array( "h.id"=>"h.id" );
 385      $from = "hardware h LEFT JOIN accountinfo a ON a.hardware_id=h.id LEFT JOIN bios b ON b.hardware_id=h.id LEFT JOIN devices d ON d.hardware_id = h.id";
 386      $fromPrelim = "";
 387      $group = "";
 388      $order = "";
 389      $countId = "h.id";
 390      
 391      $requete = new Req($lbl,$whereId,$linkId,$sql,$select,$selectPrelim,$from,$fromPrelim,$group,$order,$countId,true);
 392      ShowResults($requete,true,false,false,false);    
 393  }
 394  // Network analyze
 395  else  if( $_GET["mode"] == 3 ) {
 396      
 397      $tabBalises = Array("LABEL","UID","NETNAME","NETNUMBER");
 398      printEnTete($l->g(315));
 399      $buf = runCommand();
 400      $ret = getXmlFromBuffer($buf, "NETWORK", $tabBalises );     
 401      $ret[0] = Array($l->g(295),$l->g(296),$l->g(82),$l->g(55));
 402      $tailles = Array( "300", "20", "200", "40");        
 403      
 404      $total = 0;
 405      for( $li = 1 ; $li < sizeof( $ret ) ; $li++ ) {
 406          $link = "<a href=index.php?multi=3&mode=2&pas=".$ret[$li][2]."&nam=".urlencode($ret[$li][0]).">";
 407          $total += $ret[$li][3];
 408          for( $c = 0 ; $c < sizeof( $ret[ $li ] ) ; $c++ ) {                
 409              $ret[$li][$c] = $link.$ret[$li][$c]."</a>";
 410          }        
 411      }
 412      
 413      echo "<center><b>".$l->g(87)." $total</b></center>";
 414      echo "<br><center><a href=index.php?multi=3><= ".$l->g(188)."</a></center>";
 415      echo "<br><br>";
 416      printTab($ret,FALSE,$tailles);
 417  }
 418  else  if( $_GET["mode"] == 2 ) {
 419      if( isset($_GET["delmac"]) ) {
 420          mysql_query("DELETE FROM netmap WHERE mac='".$_GET["delmac"]."'", $_SESSION["writeServer"] ) or die(mysql_error());
 421      }
 422      printEnTete($l->g(316)." ".$_GET["pas"]."<br><br>".$nomRez);
 423  ?>
 424      <br><center><form name='analyse' action='index.php' method='GET'>
 425  <?
 426  if($scriptPresent) {
 427  ?>
 428      <input type='submit' name='subbutton' value='<?echo $l->g(317);?>'>
 429  <?}?>
 430      <input type='hidden' name='multi' value='3'>
 431      <input type='hidden' name='mode' value='6'>
 432      <input type='hidden' name='pas' value='<?=$_GET["pas"]?>'>
 433      <input type='hidden' name='popup' value='1'>
 434      </form>
 435      </center>
 436  <?
 437      $reqRez = "SELECT ip, mac, mask, date, name FROM netmap WHERE netid='".$_GET["pas"]."' AND mac NOT IN (SELECT DISTINCT(macaddr) FROM networks) 
 438      AND mac NOT IN (SELECT DISTINCT(macaddr) FROM network_devices)";
 439      $resRez = mysql_query( $reqRez, $_SESSION["readServer"] ) or die(mysql_error());
 440      $_SESSION["forcedRequest"] = $reqRez;
 441      echo "<center><a href='ipcsv.php' target=_blank>(".$l->g(183).")</a></center><br>";
 442      $t[0]    = Array($l->g(34),$l->g(95),$l->g(318),$l->g(232));
 443      $types   = Array("SORT_STRING","SORT_STRING","SORT_STRING","SORT_STRING");
 444      $cptL = 1;
 445      while( $valRez = mysql_fetch_array($resRez) )  {
 446          //$hname = gethostbyaddr($valRez["ip"]); TODO:remettre
 447          $t[ $cptL ] = array($valRez["ip"],$valRez["mac"],$valRez["name"],$valRez["date"]);
 448          $cptL++;
 449      }
 450      
 451      if( isset($_SESSION["triEnreg"]) && ! isset($_GET["tri"])) {
 452          $_GET["tri"] = $_SESSION["triEnreg"];
 453      }
 454      
 455      if( isset($_GET["tri"] ) ) {
 456          $tri = trieTab($t,$_GET["tri"],$types );
 457          $_SESSION["triEnreg"] = $_GET["tri"];
 458      }
 459      else
 460          $tri = $t;
 461  
 462      printTab($tri,true,null,false,false,true);
 463      
 464  }
 465  else  if( $_GET["mode"] == 6 ) {
 466      
 467      $pas = isset( $_GET["pas"] ) ? $_GET["pas"] : $_POST["pas"];
 468      $rez = $nomRez;
 469      printEnTete($l->g(319)." $pas<br><br>$rez");
 470      echo "<br><center><a href='index.php?popup=1&multi=3&mode=2&pas=$pas'><= ".$l->g(188)."</a></center>";
 471      $fname = "ipd/$pas.ipd";
 472      $buf = "";
 473      if( $_GET["nocache"] != 1 || $_SESSION["fromEnreg"] )
 474          if( $hndl = @fopen ( $fname , "r" ) ) {
 475              
 476              $dateF = filemtime( $fname );
 477              $dte = date( "j/m/Y \� H:m:s ", $dateF );
 478              $txt = $l->g(320). " $dte, ".$l->g(321);
 479  echo <<<END
 480              <script language='javascript'>
 481                  if ( !confirm('$txt') ) {
 482                      window.location = 'index.php?multi=3&mode=6&popup=1&nocache=1&pas=$pas&nam=$nam';
 483                  }
 484              </script>
 485  END;
 486              flush();
 487              if( filesize ($fname) == 0 )
 488                  unlink( $fname );
 489              else {    
 490                  $buf = fread($hndl, filesize ($fname));
 491                  echo "<br><center><font color=red><b>".$l->g(322)." (".$l->g(323)." $dte)</b></font></center>";
 492                  
 493                  fclose($hndl);
 494              }
 495          }
 496      $_SESSION["fromEnreg"] = false;
 497      $tabBalises = Array("IP","MAC","NAME","DATE","TYPE");
 498      
 499      if( $buf == "" ) {
 500          $buf = runCommand("-cache -net=".$_GET["pas"]);
 501      }
 502          
 503      $ret = getXmlFromBuffer($buf, "HOST" , $tabBalises);     
 504      $ret[0] = Array($l->g(34),$l->g(95),$l->g(318)."/NetBIOS",$l->g(232));
 505      
 506      $tabTypes = Array("WINDOWS","LINUX","NETWORK","PHANTOM","FILTERED");
 507      foreach( $tabTypes as $tt ) {        
 508          $win = getLignes($ret, $tt, 4);
 509          if( sizeof($win) > 1 ) {
 510              echo "<br><br><center><b>".$l->g(324)." $tt</b></center><br>";
 511              printTab($win,true);            
 512          }
 513      }
 514      echo "<br>";
 515      
 516  }
 517  else  if( $_GET["mode"] == 7 ) {
 518      include_once ('preferences.php');
 519      if( ! isset($_GET["modepopup"] ) ) {
 520          printEnTete($l->g(290));
 521          echo "<br><center><a href=index.php?multi=3><= ".$l->g(188)."</a></center>";
 522  ?>
 523      <br><form name='formip' action='index.php?multi=3&mode=7' method='POST'>
 524      <table align='center'>
 525          <tr><td><?echo $l->g(34);?> :</td><td><input type='text' name='ipa' 
 526          <?echo ( isset($_POST["ipa"])?"value='".$_POST["ipa"]."'":""); ?>></td><td>&nbsp;&nbsp;<?echo $l->g(208);?>:</td><td><input type='text' name='ipm' 
 527          <?echo ( isset($_POST["ipm"])?"value='".$_POST["ipm"]."'":""); ?>></td></tr>
 528          <tr><td align='right' colspan='4'><input type='submit' value='<?echo $l->g(13);?>'></td></tr>
 529          </tr>
 530      </table>
 531      </form>
 532  <?
 533      }
 534      $ipa = isset( $_POST["ipa"] ) ?  $_POST["ipa"] :  ( isset ( $_GET["ipa"] ) ? $_GET["ipa"] : null );
 535      $ipm = isset( $_POST["ipm"] ) ?  $_POST["ipm"] :  ( isset ( $_GET["ipm"] ) ? $_GET["ipm"] : null );
 536      
 537      if( $ipa ) {
 538          
 539          if( ! preg_match("/^([0-9]{1,3}\.){3}[0-9]{1,3}$/",$ipa )) {
 540              echo "<script language='javascript'>alert('".$l->g(299)."');</script>";
 541          }
 542          else if( (! preg_match("/^([0-9]{1,3}\.){3}[0-9]{1,3}$/", $ipm )) && (! preg_match("/^[0-9]{2}$/", $ipm ) ) && $ipm != "") {
 543              echo "<script language='javascript'>alert('".$l->g(300)."');</script>";
 544          }    
 545          else {
 546              $tabBalises = Array("DISCOVERED","DNS","INVENTORIED","IP","NETBIOS","NETNAME","NETNUM","TYPE");
 547              $command = "-ip=".$ipa."/". ( $ipm !="" ? $ipm : "00" ); 
 548              $buf = runCommand($command);
 549              $ret = getXmlFromBuffer($buf, "IP" , $tabBalises );
 550              echo "<br><br>";
 551              
 552              $disc = $ret[1][0]; $dns = $ret[1][1]; $inv = $ret[1][2]; 
 553              $ip = $ret[1][3]; $net= $ret[1][4]; $nam = $ret[1][5]; $num = $ret[1][6];$typ = $ret[1][7];
 554              $ipmask = $ipa." (".$l->g(208).": ". ( $ipm != "" ? $ipm : $l->g(325) ) .")";
 555              $coulDisc = ( $disc == "yes" ? "green" : "red" );
 556              $coulInv = ( $inv == "yes" ? "green" : "red" );
 557              $err = $ipm !="" ? "" : "<font color='red'>".$l->g(326)."</font>";
 558              if( $err != "" ) $num ="";
 559              $width = isset($_GET["modepopup"]) ? "90" : "50";            
 560              
 561  echo "<table width='$width%' BORDER='0' ALIGN = 'Center' CELLPADDING='0' BGCOLOR='#C7D9F5' BORDERCOLOR='#9894B5'>
 562  <tr height='20px'><td colspan='2' align='center'><b>".$l->g(327)." $ipmask</b></td></tr>";
 563  
 564          if( ! isset($_GET["modepopup"] )) {
 565  echo "<tr height='20px' bgcolor='#FFFFFF'><td align='center'>".$l->g(328).":</font></td><td align='center'><font color='$coulDisc'><b>$disc</b></font></td></tr>
 566  <tr height='20px' bgcolor='#F2F2F2'><td align='center'>".$l->g(329).":</font></td><td align='center'><font color='$coulInv'><b>$inv</b></font></td></tr>";
 567          }
 568  echo "<tr height='20px' bgcolor='#FFFFFF'><td align='center'>".$l->g(66).":</td><td align='center'><b>$typ</b></font></td></tr>
 569  <tr height='20px' bgcolor='#F2F2F2'><td align='center'>".$l->g(318).":</td><td align='center'><b>$dns</b></font></td></tr>
 570  <tr height='20px' bgcolor='#FFFFFF'><td align='center'>".$l->g(330).":</td><td align='center'><b>$net</b></font></td></tr>
 571  <tr height='20px' bgcolor='#F2F2F2'><td align='center'>".$l->g(304).":</td><td align='center'><b>$nam</b></font></td></tr>
 572  <tr height='20px' bgcolor='#FFFFFF'><td align='center'>".$l->g(331).":</td><td align='center'><b>$err$num</b></font></td></tr>
 573  </table><br>
 574  <script language=javascript>document.getElementById(\"wait\").innerHTML=\"\";</script>";
 575          }
 576      }
 577  }
 578  else  if( $_GET["mode"] == 8 ) { // insertion network device
 579      
 580      if( isset($_POST["pas"]) )
 581          $_GET["pas"] = $_POST["pas"];
 582          
 583      $_SESSION["fromEnreg"] = true;
 584  
 585      if( $_GET["direct"] != 2 && $_SESSION["retour"] != "multi=3&mode=1" ) 
 586          echo "<br><center><a href=index.php?popup=1&".$_SESSION["retour"]."><= ".$l->g(188)."</a></center>";    
 587                  
 588      if( isset( $_POST["macaddr"] )) {
 589          // cherche l'ip correspondante
 590          $reqIp = "SELECT ip,netid FROM netmap WHERE mac = '".$_POST["macaddr"]."'";
 591          $resIp = mysql_query($reqIp, $_SESSION["readServer"]) or die(mysql_error($_SESSION["readServer"]));
 592          $valIp = mysql_fetch_array( $resIp );
 593          unset($_SESSION["lastTri"]);
 594          if( checkNetwork(addslashes($_POST["macaddr"])) ) {
 595              $reqNet = "INSERT INTO network_devices(description, type, macaddr, user)          
 596              VALUES ('".addslashes($_POST["description"])."','".addslashes($_POST["type"])."','".addslashes($_POST["macaddr"])."'
 597              ,'".$_SESSION["loggeduser"]."');";
 598              mysql_query($reqNet, $_SESSION["writeServer"]) or die(mysql_error($_SESSION["writeServer"]));
 599          }
 600          else
 601              echo "<br><center><font color=red><b>".$_POST["macaddr"]." ".$l->g(363)."</b></font></center><br>";
 602      }
 603      
 604      if( isset($_GET["mac"]) ) {
 605          printEnTete($l->g(333));        
 606          echo "<br><br>";
 607          
 608          echo "<form action='index.php?multi=3&mode=8&popup=1' method='POST'>
 609              <table BORDER='0' WIDTH='30%' ALIGN = 'Center' CELLPADDING='0' BGCOLOR='#C7D9F5' BORDERCOLOR='#9894B5'>
 610              <tr height='20px' bgcolor='#FFFFFF'><td align='center'>".$l->g(95).":</td><td align='left'>
 611              <input type='hidden' name='popup' value='1'>";
 612          if( isset($_GET["mac"]) ) {
 613              echo $_GET["mac"];
 614              echo "<input type='hidden' name='macaddr' value='".$_GET["mac"]."'>";
 615          }
 616          else echo "<input type='text' size='17' name='macaddr' value='".$_GET["mac"]."'>";
 617          
 618          if( isset($_GET["pas"]) )
 619              echo "<input type='hidden' name='pas' value='".$_GET["pas"]."'>";
 620          
 621          echo "</td>
 622              <tr height='20px' bgcolor='#FFFFFF'><td align='center'>".$l->g(53).":</td><td align='left'><input type='text' size='30' maxlength='120' name='description' value='".$_GET["nam"]."'></td></tr>
 623              <tr height='20px' bgcolor='#FFFFFF'><td align='center'>".$l->g(66).":</td><td align='left'><select name='type'>";
 624          
 625          $reqTypes = "SELECT DISTINCT(name) FROM devicetype";
 626          $resType = mysql_query( $reqTypes, $_SESSION["readServer"] ) or die(mysql_error($_SESSION["readServer"]));
 627          while( $valType = mysql_fetch_array($resType) ) {
 628              echo "<option>".$valType["name"]."</option>\n";
 629          }
 630          
 631          echo "</select></td></tr>
 632              <tr height='30px' bgcolor='#FFFFFF'><td align=right colspan='2'><input type='submit' value='".$l->g(13)."'></td></tr>
 633              </table>
 634              </form>";        
 635  
 636      }
 637  
 638      $ent = $l->g(334)." ".$l->g(368)." ".$_GET["pas"]."<br><br>".$nomRez;
 639  
 640      printEnTete($ent);echo "<br>";    
 641      if( isset($_GET["pas"]) ) {
 642          $sql  = "a.netid='".$_GET["pas"]."'";
 643      }
 644      
 645      $lbl = $l->g(314)." ".$_GET["pas"];    
 646      $whereId = "n.id";
 647      $linkId = "n.id";
 648      $select = array( "n.macaddr"=>$l->g(95), "a.ip"=>$l->g(34), "a.netid"=>$l->g(331), "n.type"=>$l->g(335), 
 649      "n.description"=>$l->g(336), "n.user"=>$l->g(369));    
 650      $selectPrelim = array( "n.id"=>"n.id" );
 651      $from = "network_devices n LEFT JOIN netmap a ON a.mac=n.macaddr"; 
 652      $fromPrelim = "";
 653      $group = "";
 654      $order = "n.macaddr";
 655      $countId = "n.id";
 656      
 657      $requete = new Req($lbl,$whereId,$linkId,$sql,$select,$selectPrelim,$from,$fromPrelim,$group,$order,$countId);
 658      ShowResults($requete);
 659  }
 660  
 661  if(!$filePresent&&$_GET["mode"]==2) echo "<br><font color=red><center><b>".$l->g(338)."</b></font><br>".$l->g(339)."</center>";
 662  
 663  function trieTab($t,$colTri,$types) {
 664  
 665      if( sizeof($t)<=1 ) return $t;
 666      
 667      // tris invers�s
 668      if( !isset($_SESSION["orderIpdisc"]) )
 669          $_SESSION["orderIpdisc"] = "SORT_ASC";
 670      
 671      if( $_SESSION["lastTri"] == $colTri ) {
 672          $_SESSION["orderIpdisc"] = ($_SESSION["orderIpdisc"]=="SORT_ASC" ? "SORT_DESC" : "SORT_ASC") ;
 673      }
 674  
 675      $_SESSION["lastTri"] = $colTri;
 676      //    
 677          
 678      foreach ($t[0] as $c) {            
 679          $enTete[] = array_shift( $t[0] );    
 680      }
 681      array_shift( $t );
 682      
 683      foreach($t as $ligne) {
 684          $col = 0;
 685          foreach($ligne as $case) {
 686              $inv[$col][] = $case;
 687              $col++;
 688          }        
 689      }
 690      
 691      $strSort = "array_multisort(";
 692      $colNbr = 0;
 693      
 694      $strSort .= "\$inv[$colTri],".$_SESSION["orderIpdisc"].",".$types[$colTri];
 695      foreach($inv as $col) {
 696          if( $colNbr == $colTri ) {
 697              $colNbr++;
 698              continue;
 699          }
 700          
 701          $strSort .= ",\$inv[$colNbr],";
 702          $strSort .= $types[$colNbr] != "" ? $types[$colNbr] : "SORT_REGULAR" ;
 703          $colNbr++;
 704      }
 705      $strSort .="); ";
 706      //echo $strSort;
 707      eval($strSort);
 708      
 709      foreach($inv as $ligne) {
 710          $cl = 1;
 711          foreach($ligne as $case) {
 712              $ret[$cl][] = $case;
 713              $cl++;
 714          }
 715      }
 716      $ret[0] = $enTete ;
 717      return $ret;
 718  }
 719  
 720  function printTab($t ,$modeReg=false, $tailles=null, $unSurDeux=false, $scroll = false, $modeDel = false) {
 721      global $_GET;
 722      $lesget="";
 723      foreach($_GET as $nom=>$val) {
 724          if($nom == "tri"||$nom == "delrez")
 725              continue;
 726              
 727          $lesget.="&$nom=".urlencode($val);
 728      }
 729              
 730      if( $scroll ) {
 731          $ftd = "</font></td>";
 732          echo "<div id='headers' style='position:absolute'>
 733          <table BORDER='0' ALIGN = 'Center' CELLPADDING='0' BGCOLOR='#C7D9F5' BORDERCOLOR='#9894B5'>
 734          <tr height=25px>";
 735          $col = 0;
 736          foreach($t[0] as $case) {
 737              if( $unSurDeux && $col%2==0 ) {
 738                  $col++;
 739                  continue;
 740              }
 741                      
 742              $taille = $tailles!=null ? $tailles[$col] : "200px" ;
 743              $tdsp = "<td align='center' width='{$taille}px'>";            
 744              echo "$tdsp<a href=?tri=$col{$lesget}><b>$case</b></a>$ftd";
 745              $col++;
 746          }
 747          echo "</tr></table></div>";
 748      }
 749      else
 750          echo "<div id='headers'></div>";
 751  
 752      global $l;
 753      $totCol = sizeof( $t[0] );
 754      $_SESSION["history"] = 0 ;
 755      echo "<table BORDER='0' ALIGN = 'Center' CELLPADDING='0' BGCOLOR='#C7D9F5' BORDERCOLOR='#9894B5'>";
 756      
 757      $td = "<td align='center'>";
 758      
 759      $lnum = 0 ;
 760      $ligne = 0;
 761      while( isset($t[$ligne]) ) { // chque ligne        
 762              
 763          if($ligne==0) {
 764              echo "<TR height=25px>";
 765          }
 766          else    
 767              echo "<TR height=25px bgcolor='". ($ligne%2 == 1 ? "#FFFFFF" : "#F2F2F2") ."'>";
 768  
 769          for( $col=0 ; $col < sizeof($t[$ligne]) ; $col++) {
 770          
 771              $c = $t[$ligne][$col];
 772              
 773              if( $unSurDeux && $col%2==0 ) {
 774                  $ah = $c;
 775                  continue;
 776              }
 777              
 778              if($ligne==0) {
 779                  $taille = $tailles!=null ? $tailles[$col] : "200px" ;
 780                  $tdsp = "<td align='center' width='{$taille}px'>";
 781                  echo "$tdsp<a href=?tri=$col{$lesget}><b>$c</b></a>$ftd";
 782              }
 783              else {
 784                  echo $td.$ah.$c.$ftd;
 785              }
 786          }
 787          
 788          if( $modeReg ) {
 789              if($ligne==0)
 790                  echo "<td align='center' width='50px'><a href=\"javascript:void(0)\"><b>".$l->g(114)."</b></a></td>";
 791              else if( $_GET["mode"] == 6 )            
 792                  echo "<td align=center><a href=index.php?popup=1&multi=3&mode=8&direct=4&mac=".$t[$ligne][1]."&nam=".$t[$ligne][2]."&pas=".urlencode($_GET["pas"])."><img src='image/Gest_admin1.png'></a></td>";
 793              else
 794                  echo "<td align=center><a href=index.php?popup=1&multi=3&mode=8&direct=3&mac=".$t[$ligne][1]."&nam=".$t[$ligne][2]."&pas=".urlencode($_GET["pas"])."><img src='image/Gest_admin1.png'></a></td>";
 795          
 796          }
 797          
 798          if( $modeDel ) {
 799              if($ligne==0)
 800                  echo "<td align='center' width='30px'>&nbsp;</td>";
 801              else
 802                  echo "<td align=center><a href=index.php?popup=1&multi=3&mode=2&delmac=".$t[$ligne][1]."&pas=".urlencode($_GET["pas"])."><img src='image/supp.png'></a></td>";
 803          }
 804          
 805          echo "</tr>";
 806              
 807          $ligne++;
 808      }
 809      echo "</table>";
 810      
 811  }
 812  
 813  function runCommand($command="") {
 814      global $l;
 815      $command = "perl ipdiscover-util.pl $command -xml -h=".$_SESSION["SERVEUR_SQL"]." -u=".$_SESSION["COMPTE_BASE"]." -p=".$_SESSION["PSWD_BASE"];
 816      //echo $command."<br>";
 817      $fd = popen($command,"r");    
 818      if($fd==FALSE) {
 819          echo "pas de handle";
 820          return FALSE;
 821      }
 822      $buffer = "";
 823      while (!feof($fd)) {
 824          $buffer .= fgets($fd, 4096);         
 825      }
 826      
 827      pclose ($fd);
 828      
 829      if($buffer == "") {
 830          echo "<br><center><font color='red'><b>".$l->g(337)."</b></font></center>";
 831          return FALSE;
 832      }
 833      else if( strstr ( $buffer, "ERROR")) {
 834          $tabBalises[] = "MESSAGE";
 835          $ret = getXmlFromBuffer($buffer, "ERROR" , $tabBalises);
 836          echo "<br><center><font color='red'><b>".$l->g($ret[1][0])."</b></font></center>";
 837          return FALSE;
 838      }
 839      
 840      return $buffer;
 841  }
 842      
 843  function getXmlFromBuffer($buffer, $baliseLigne , $balisesInt) {    
 844      $ret = null;
 845      $p = xml_parser_create();
 846      xml_parse_into_struct($p,$buffer,$vals,$index);
 847      xml_parser_free($p);
 848      $ligne = 1;
 849      foreach($vals as $val) {
 850          if( $val["tag"] == $baliseLigne && $val["type"] == "open" ) {
 851              $cOuvert = true;
 852              continue;
 853          }            
 854          if( $val["tag"] == $baliseLigne && $val["type"] == "close" ) {
 855              $cOuvert = false;
 856              $ligne++;
 857              continue;
 858          }
 859          
 860          if( in_array($val["tag"],$balisesInt) && $val["type"] == "complete" && $cOuvert ) {            
 861              $temp = array_flip ( $balisesInt );    
 862              $ret[$ligne][ $temp[ $val["tag"] ] ] = $val["value"];            
 863          }
 864      }
 865      
 866      return $ret;
 867  }
 868  
 869  function getLignes($t, $val, $saufCol=null) {
 870      
 871      if( isset($saufCol) ) {
 872          unset( $t[0][$saufCol] );
 873      }
 874      $ret[] = $t[0];        
 875      for( $l = 1 ; $l < sizeof( $t ) ; $l++ ) {
 876          for( $c = 0 ; $c < sizeof( $t[$l] ) ; $c++ ) {
 877              if( $t[$l][$c] == $val || $val == -1 ) {
 878                  if( isset($saufCol) ) {
 879                      unset( $t[$l][$saufCol] );
 880                  }
 881                  $ret[] = $t[$l];                
 882              }
 883          }
 884      }    
 885      return $ret;
 886  }
 887  
 888  function getMask( $ip ) {
 889      $reqMsk = "SELECT ipmask FROM networks WHERE ipsubnet='$ip' AND ipmask <>''";
 890      $resMsk = mysql_query( $reqMsk, $_SESSION["readServer"] ) or die( mysql_error($_SESSION["readServer"]) );
 891      while( $ligMsk = mysql_fetch_array( $resMsk ) ) {
 892          if( preg_match("/^([0-9]{1,3}\.){3}[0-9]{1,3}$/",$ligMsk[0]) ) {
 893              return $ligMsk[0];
 894          }
 895      }
 896  }
 897  
 898  function popup($val) {
 899      global $l,$nbpop;
 900      $nbpop++;
 901      return "<a href=\"index.php?popup=1&$val\" OnClick=\"window.open('index.php?popup=1&$val','popup$nbpop','location=0,status=0,scrollbars=1,menubar=0,resizable=1,width=1024,height=668');return false;\">";
 902  }
 903  
 904  function getNameFromRes($nbrez) {
 905      $reqSub = "SELECT name FROM subnet s WHERE s.netid='$nbrez'";
 906      $resSub = mysql_query($reqSub, $_SESSION["readServer"]) or die(mysql_error($_SESSION["readServer"]));    
 907      if($valSub = mysql_fetch_array( $resSub )){
 908          return $valSub["name"];
 909      }
 910      return "";
 911  }
 912  
 913  function checkNetwork($mac) {
 914      $reqMac = "SELECT id FROM network_devices WHERE macaddr='$mac'";
 915      $resMac = mysql_query( $reqMac, $_SESSION["readServer"] ) or die(mysql_error(mysql_error($_SESSION["readServer"])));    
 916      return( mysql_num_rows( $resMac ) == 0 );
 917  }
 918  ?>


Generated: Tue Mar 17 22:47:18 2015 Cross-referenced by PHPXref 0.7.1