Location: PHPKode > projects > Web-Net-Admin > webnetadmin/serveurs/dhcp/dhcp_module.php
<?
session_start();

////////////////////////add////////////////////////////

function	add_pc_in_dhcp($uid, $ip)
{
  include "sortir_variable_obl.php";
  $connexion = mysql_connect($serv_mysql, $mysql_login, $mysql_pass) or die('Connexion au serveur sql impossible<br>');
  mysql_select_db($name_base, $connexion) or die('Sélection de la base de donnée impossible<br>');
  if ($ip != "000.000.000.000")
    {
      $subnet = recup_subnet_ip($ip, $connexion);
      $req = "UPDATE Machines SET Reseau='$subnet' WHERE Uid='$uid'";
      $res = mysql_query($req, $connexion);
      if (!$res)
	return(1);
    }
  mysql_close($connexion);
  write_file_dhcp();
  return(0);
}
//////////////////////modif/////////////////////////

function	change_pc_network($ip, $old, $new)
{
  $name = $old;
  if ($old != $new)
    $name = $new;
  $ip_in = explode(".", $ip);
  include "sortir_variable_obl.php";
  $connexion = mysql_connect($serv_mysql, $mysql_login, $mysql_pass) or die('Connexion au serveur sql impossible<br>');
  mysql_select_db($name_base, $connexion) or die('Sélection de la base de donnée impossible<br>');
  $res = mysql_query("SELECT * FROM DHCP", $connexion);  
  $sub = 0;
  $oc_save = 0;
  $oc = 0;
  while ($tmp = mysql_fetch_object($res))
    {
      $tab_s = explode(".", $tmp->Base_ip);
      for ($i = 0; $i < 4; $i++)
	if ($tab_s[$i] != "0")
	  $count++;
      for ($i = 0; $i < 4; $i++)
	if ($ip_in[$i] == $tab_s[$i] && $tab_s[$i] != "0")
	  $oc++;
      if ($oc == $count)
	if ($oc > $oc_save)
	  {
	    $sub = $tmp->Numero;
	    $oc_save = $oc;
	  }
      $oc = 0;
      $count = 0;
    }
  $req = "UPDATE Machines SET Reseau='$sub' WHERE Nom='$name'";
//   echo "Rq DHCP : $req<p>";
  $res = mysql_query($req, $connexion);
  mysql_close($connexion);
  return (0);
}

/////////////////////////////////////////////////////////////////
//////////////////////////////////DEL////////////////////////////
/////////////////////////////////////////////////////////////////

function	del_pc_in_dhcp($pc)
{
  include "sortir_variable_obl.php";
  $connexion = mysql_connect($serv_mysql, $mysql_login, $mysql_pass) or die('Connexion au serveur sql impossible<br>');
  mysql_select_db($name_base, $connexion) or die('Sélection de la base de donnée impossible<br>');
  $ip = "000.000.000.000";
  $rq = "UPDATE Machine SET Reseau='0', Ip='$ip' WHERE Nom='$pc'";
  mysql_query($rq, $connexion);
  write_file_dhcp();
  mysql_close($connexion);
}

/////////////////////////////////////////////////////////////
///////////////////////////WRITE FILE////////////////////////
/////////////////////////////////////////////////////////////



function	write_file_dhcp()
{
  include "sortir_variable_obl.php";
  $connexion = mysql_connect($serv_mysql, $mysql_login, $mysql_pass) 
    or die('Connexion au serveur sql impossible<br>');
  mysql_select_db($name_base, $connexion) 
    or die('Sélection de la base de donnée impossible<br>');
  $path_rep = "./TEMP";
  $path_file = "$path_rep/tmp_dhcp";
  if (file_exists($path_file))
    unlink($path_file);
  $touch = touch($path_file);
  if ($touch)
    {
      chmod($path_file, 0604);
      $file = fopen($path_file, "w");
      fputs($file, "ddns-update-style none\n");
      fputs($file, "deny unknown-clients\n\n");
      $res = mysql_query("SELECT * FROM DHCP", $connexion);
      ////////////////////////////////////////////////////////////////
      ////////////////////////ECRITURE DE LA DESCRIPTION//////////////
      ///////////////////////////////////////////////////////////////
      while($des = mysql_fetch_object($res))
	{
	  $name = $des->Nom_network;
	  if ($name != $save_name)
	    $change = "on";
	  if ($change == "on")
	    {
	      $line = "shared-network $name {\n";
	      $save_name = $name;
	      $change = "off";
	      fputs($file, $line);
	    }
	  $line2 = "subnet $des->Base_ip netmask $des->Masque\n\t{\n\t";
	  $opt = $des->Param_opt;
	  $len = strlen($opt);
	  fputs($file, $line2);
	  for ($i = 0; $i < $len; $i++)
	    {
	      fputs($file, $opt[$i]);
	      if ($opt[$i] == ";" && $opt[$i + 1])
		fputs($file, "\n\t");
	    }
	  fputs($file, "\n\t}\n\n");
	}
	  /////////////////////////////////////////////////////////////
	  //////////////////////////ECRITURE DES MACHINES//////////////
	  /////////////////////////////////////////////////////////////

      $res = mysql_query("SELECT * FROM Machines ORDER BY Reseau", $connexion);
      $i = 0;
      while ($host = mysql_fetch_object($res))
	{
	  $group = $host->Reseau;
	  if ($group)
	    {
	      if ($group != $save_number)
		$change = "on";
	      if ($change == "on")
		{
		  if ($i != 0)
		    fputs($file, "\t}\n\n");
		  $line = "group\n\t{\n\tuse-host-decl-names on ;\n\n";
		  $save_number = $group;
		  $change = "off";
		  fputs($file, $line);
		  $i++;
		}
	      $line1 = "\thost $host->Nom\n\t\t\t{\n";
	      $line2 = "\t\thardware ethernet $host->MAC;\n";
	      $line3 = "\t\tfixed-address $host->Ip;\n\t\t\t}\n\n";
	      fputs($file, $line1);
	      fputs($file, $line2);
	      fputs($file, $line3);
	    }
	}
      fputs($file, "\t}\n");
      fclose($file);
    }
  else
    {
      echo "Erreur de création du fichier temporaire "
	."dans TEMP/ Vérifier les droit d'accés du répertoire<p>";
    }
  mysql_close($connexion);
}
?>
Return current item: Web-Net-Admin