[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/se3master/usr/share/se3/sbin/ -> machineDel.pl (source)

   1  #!/usr/bin/perl
   2  
   3  # $Id: machineDel.pl 8108 2014-04-03 22:44:11Z keyser $ #
   4  
   5  ##### Script utilisé pour virer les machines des l'annuaire
   6  
   7  use Net::Domain;
   8  use Unicode::String qw(latin1 utf8);
   9  use Net::LDAP;
  10  use POSIX;
  11  
  12  require '/etc/SeConfig.ph';
  13  
  14  die("Erreur d'argument.\n") if ($#ARGV != 1);
  15  ($machine_uid, $ipAddress) = @ARGV;
  16  $machine = $machine_uid;
  17  chop($machine);
  18  # print "$machine\n";
  19  # print "$machine_uid\n";
  20  
  21  # Recherche LDAP de la machine dans la branche ou=Computers
  22  # ---------------------------------------------------------
  23  $ldap = Net::LDAP->new(
  24     "$slapdIp",
  25     port => "$slapdPort",
  26     debug => "$slapdDebug",
  27     timeout => "$slapdTimeout",
  28     version => "$slapdVersion"
  29  );
  30  $ldap->bind(); # Anonymous BIND
  31  $res = $ldap->search(
  32     base => "cn=$machine,$computersDn",
  33     scope => 'base',
  34     attrs => ['cn'],
  35     filter => "cn=$machine"
  36  );
  37  print "$machine n'existe pas dans $computersDn\n"  if $res->code;
  38  #print "res->code = ". $res->code .", res->entries0 = ". ($res->entries)[0] ."\n";
  39  if (($res->entries)[0]) {
  40     $cn = ($res->entries)[0]->get_value('cn');
  41     print "entree cn=$cn existante\n"
  42  }
  43  # base => 'uid='.$machine_uid.','.$ComputersDn,
  44  $res = $ldap->search(
  45     base => 'uid='.$machine_uid.','.$computersDn,
  46     scope => 'base',
  47     filter => 'uid=*'
  48  );
  49  print "$machine_uid n'existe pas dans $computersDn\n"  if $res->code;
  50  if (($res->entries)[0]) {
  51     $uid = ($res->entries)[0]->get_value('uid');
  52     print "entree uid=$uid existante \n"
  53  }
  54  $ldap->unbind();
  55  
  56  if ($uid) {
  57  print "on supprime l'entree machine existante en \"uid=$machine_uid,$computersDn\"\n";
  58  
  59  system("/usr/share/se3/sbin/entryDel.pl \"uid=$machine_uid,$computersDn\"");
  60  }
  61  # $cn=1;
  62  if ($cn) {
  63  # on vire l'entree machine existante
  64  print "on supprime l'entree machine existante \"cn=$machine,$computersDn\"\n";
  65  system("/usr/share/se3/sbin/entryDel.pl \"cn=$machine,$computersDn\"");
  66  }
  67  
  68  $res = $ldap->search(
  69     base => "$parcsDn",
  70     scope => 'base',
  71     attrs => ['cn'],
  72     filter => 'member=cn='.$machine.','.$computerDn
  73  );
  74  print "$machine n'est pas dans un parc\n"  if $res->code;
  75  if (($res->entries)[0]) {
  76     $cn = ($res->entries)[0]->get_value('cn');
  77     print "entree cn=$cn existante\n"
  78  }
  79  
  80  
  81  # print "ip=$ip\n";
  82  # print "mac=$mac\n";
  83  #print "arp=$arp\n";
  84  $ldap = Net::LDAP->new(
  85  "$slapdIp",
  86  port => "$slapdPort",
  87  debug => "$slapdDebug",
  88  timeout => "$slapdTimeout",
  89  version => "$slapdVersion"
  90  );
  91  $ldap->bind(
  92  $adminDn,
  93  password => $adminPw
  94  );
  95  # Ajoût
  96  # -----
  97  $res = $ldap->add(
  98  "cn=$machine,$computersDn",
  99  attrs => [
 100  cn => $machine,
 101  objectClass => 'top',
 102  objectClass => 'ipHost',
 103  objectClass => 'ieee802Device',
 104  objectClass => 'organizationalRole',    
 105  ipHostNumber => $ipAddress,
 106  macAddress => $mac
 107  ]);
 108  die("Erreur lors de l'ajoût de l'entrée dans l'annuaire.\n") if ($res->code() != 0);
 109  
 110  # Déconnexion
 111  # -----------
 112  $ldap->unbind;
 113  
 114  exit 0;
 115  
 116  


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