[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

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

   1  <?
   2  //====================================================================================
   3  // OCS INVENTORY REPORTS
   4  // Copyleft Pierre LEMMET 2006
   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 06/23/2006
  12  
  13  if( isset($_POST["systemid"]) )
  14      $_GET["systemid"] = $_POST["systemid"];
  15  
  16  if( !isset($_GET["systemid"]) ) {
  17      $lareq = getPrelim( $_SESSION["storedRequest"] );
  18      $res = @mysql_query( $lareq, $_SESSION["readServer"] ) or die(mysql_error());
  19      $val = mysql_fetch_array( $res );
  20      $id = $val["h.id"];
  21  }
  22  else {
  23      $id = $_GET["systemid"];    
  24  }
  25  
  26  if( isset($_POST["ipdiscover"]) ){
  27      
  28      $ok = resetIpdiscover( $id );
  29  
  30      if( $_POST["ipdiscover"]=="never" ){
  31          $ok = makeIpdiscover( $id, 0 );
  32      }
  33      else if( $_POST["ipdiscover"]!="des" ) {
  34          $ok = makeIpdiscover( $id, 2, $_POST["ipdiscover"] );    
  35      }
  36      if( $ok ) {
  37          echo "<script language='javascript'>history.go(-2);</script>";
  38          die();
  39      }
  40  }
  41  
  42  $nbMach = getCount($_SESSION["storedRequest"]);
  43  if( $nbMach != 1 && ! isset($_GET["systemid"])) {
  44      echo "<script language='javascript'>alert(\"".$l->g(517)."\");history.go(-1);</script>";
  45      die();
  46  }
  47  
  48  PrintEnTete( $l->g(518) );
  49  echo "<br><center><a href='javascript:void(0);' OnClick='history.go(-1)'><= ".$l->g(188)."</a></center>";
  50  
  51  $resIpd = mysql_query("SELECT tvalue, ivalue FROM devices WHERE name='IPDISCOVER' AND hardware_id=$id",$_SESSION["readServer"] );
  52  $valIpd = mysql_fetch_array( $resIpd );
  53  
  54  $resInt = mysql_query("SELECT ipaddress FROM networks WHERE hardware_id=$id",$_SESSION["readServer"] );
  55  while( $valInt = mysql_fetch_array( $resInt ))
  56      $lesRez[] = $valInt["ipaddress"];
  57  
  58  $mode = 0;
  59  if( $valIpd["tvalue"] && $valIpd["ivalue"]==1 ) {
  60      echo "<br><center><b>".$l->g(519).": ".$valIpd["tvalue"]."</b></center>";
  61      $mode = 1;
  62  }
  63  else if( $valIpd["ivalue"]==2 ) {
  64      echo "<br><center><b>".$l->g(520).": ".$valIpd["tvalue"]."</b></center>";
  65      $mode = 3;
  66  }
  67  else if( $valIpd["ivalue"]==="0" ) {
  68      echo "<br><center><b>".$l->g(521)."</b></center>";
  69      $mode = 2;    
  70  }
  71  else {
  72      echo "<br><center><b>".$l->g(522)."</b></center>";        
  73  }
  74  
  75  ?>
  76  <br>
  77  <form action='index.php?multi=23' method='post'>
  78  <table align='center' BGCOLOR='#C7D9F5' BORDERCOLOR='#9894B5' width='30%'>
  79      <tr bgcolor='#F2F2F2'>
  80          <td><? echo $l->g(518); ?>:</td><td><select name='ipdiscover'>
  81          <? foreach($lesRez as $leRez) echo "<option>$leRez</option>";
  82          if( $mode==3 || $mode==2) {?>
  83              <option value='des'><? echo $l->g(523); ?></option>
  84          <? } ?>
  85          <option value='never'><? echo $l->g(524); ?></option>
  86          </select></td>
  87      </tr>
  88      <tr bgcolor='#FFFFFF'>
  89      <td align='center'>
  90  
  91          &nbsp;</td>
  92          <td align='center'>
  93          <? if( isset($_GET["systemid"]) ) {
  94              echo "<input type='hidden' value='".$_GET["systemid"]."' name='systemid'>";
  95           } ?>
  96          <input type='Submit' value='<? echo $l->g(433); ?>' name='sub'></td>
  97      </tr>
  98  </table>
  99  </form>
 100  </form>
 101  
 102  <?
 103  function makeIpdiscover($id, $sens, $ip=NULL) {
 104  
 105      if( $ip != NULL )
 106          $ipsubnet = getSub( $id, $ip );
 107      else 
 108          $ipsubnet = NULL;
 109      
 110      if( ! @mysql_query( "INSERT INTO devices(HARDWARE_ID, NAME, IVALUE".($ipsubnet!=NULL?",TVALUE":"").") VALUES('$id', 'IPDISCOVER', '$sens'".($ipsubnet!=NULL?",'$ipsubnet'":"").")", $_SESSION["writeServer"] )) {
 111          echo "<br><center><font color=red><b>ERROR: MySql problem<br>".mysql_error($_SESSION["writeServer"])."</b></font></center>";
 112          return false;
 113      }
 114      return true;    
 115  }
 116      
 117  function resetIpdiscover( $id ) {
 118  
 119      if( ! @mysql_query( "DELETE FROM devices WHERE name='IPDISCOVER' AND hardware_id='$id'", $_SESSION["writeServer"] )) {
 120          echo "<br><center><font color=red><b>ERROR: MySql problem<br>".mysql_error($_SESSION["writeServer"])."</b></font></center>";
 121          return false;
 122      }    
 123      return true;        
 124  }
 125  
 126  function getSub( $id, $ip ) {
 127      if( ! ($res = @mysql_query( "SELECT ipsubnet FROM networks WHERE ipaddress='$ip' AND hardware_id='$id'", $_SESSION["readServer"] ))) {
 128          echo "<br><center><font color=red><b>ERROR: MySql problem<br>".mysql_error($_SESSION["readServer"])."</b></font></center>";
 129      }
 130      $val = mysql_fetch_array( $res );
 131      return $val["ipsubnet"];
 132  }
 133  ?>
 134  


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