[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

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

   1  #!/usr/bin/perl
   2  
   3  #########################################################################
   4  #   Projet SE3 : Ajout d'une imprimante à la branche printers de LDAP   #
   5  #                et configuration dans CUPS                             #
   6  #   /usr/share/se3/sbin/printerAdd.pl                                   #
   7  #   Patrice André <h.barca@free.fr>                                     #
   8  #   Carip-Académie de Lyon -avril-juin-2004                             #
   9  #   Distribué selon les termes de la licence GPL                        #
  10  #########################################################################
  11  
  12  #####Ajout de l'imprimante dans CUPS et LDAP#####
  13  
  14  ## $Id: printerAdd.pl 6654 2011-11-27 16:35:54Z dbo $ ##
  15  
  16  use Net::LDAP;
  17  use Unicode::String qw(latin1 utf8);
  18  
  19  require '/etc/SeConfig.ph';
  20  
  21  $ldap = Net::LDAP->new(
  22                 "$slapdIp",
  23                 port    => "$slapdPort",
  24                 debug   => "$slapdDebug",
  25                 timeout => "$slapdTimeout",
  26                 version => "$slapdVersion"
  27                );
  28  
  29  $ldap->bind(
  30          $adminDn,
  31          password => $adminPw
  32         );
  33  
  34  die("Erreur d'argument.\n") if ($#ARGV < 5);
  35  
  36  
  37  ($nom_imprimante,$uri_imprimante,$lieu_imprimante,$info_imprimante,$protocole,$pilote,$mode)=@ARGV;
  38  
  39  $nom_imprimante            = latin1($nom_imprimante)->utf8;
  40  $info_imprimante    = latin1($info_imprimante)->utf8;
  41  $lieu_imprimante    = latin1($lieu_imprimante)->utf8;
  42  
  43  
  44  if ( $protocole eq "socket" ){
  45    $uri_imprimante = "socket://".$uri_imprimante.":9100";
  46  }
  47  elsif ( $protocole eq "http" ){
  48    if ($uri_imprimante=~"^http://") {
  49        $uri_imprimante = $uri_imprimante.":631";
  50    } else {
  51        $uri_imprimante = "http://".$uri_imprimante.":631";
  52    }
  53  }
  54  elsif ( $protocole eq "ipp" ){
  55    if ($uri_imprimante=~"^http://") {
  56        $uri_imprimante=$$uri_imprimante.":631/printers/".$nom_imprimante;
  57    } else {
  58        $uri_imprimante="http://".$uri_imprimante.":631/printers/".$nom_imprimante;
  59    }
  60  }
  61  elsif ( $protocole eq "parallel" ){
  62    $uri_imprimante="parallel:/dev/".$uri_imprimante;
  63  }
  64  elsif ( $protocole eq "usb" ){
  65    $uri_imprimante="usb:/dev/usb/".$uri_imprimante;
  66  }
  67  elsif ( $protocole eq "lpd" ){
  68    $uri_imprimante="lpd://".$uri_imprimante."/".$nom_imprimante;
  69  }
  70  elsif ( $protocole ne "custom" ){
  71    $uri_imprimante="smb://adminse3:".$xppass."@".$uri_imprimante."/".$uri_imprimante."/".$nom_imprimante;
  72  }
  73  
  74  $result = $ldap->add( "printer-name=$nom_imprimante,$printersDn",
  75                attrs =>[
  76                     'printer-name'        => $nom_imprimante,
  77                     'printer-uri'        => $uri_imprimante,
  78                     'printer-location'    => $lieu_imprimante,
  79                     'printer-info'        => $info_imprimante,
  80                     'printer-more-info'     => $mode,
  81                     'nprintHardwareQueueName'=> $pilote,
  82                     objectClass =>['printerService','nprintNetworkPrinterInfo',
  83                            'extensibleObject'],
  84                    ]
  85              );        
  86  
  87  die("Echec à l'entrée dans ldap.\n") if ($result->code != 0);                    
  88  #$result->code && warn "failed to add entry: ", $result->error ;
  89  $mesg = $ldap->unbind;  # take down session
  90  
  91  # Puis on recrée pour pas de driver il faut envoyer raw a cups
  92  if($pilote eq "dep") {
  93           $pilote="raw";
  94  }
  95           
  96  
  97  die ("Configuration CUPS échouée.\n") if (system("/usr/bin/sudo /usr/share/se3/scripts/lpadmin.sh -p $nom_imprimante -v $uri_imprimante -D \"$info_imprimante\" -L \"$lieu_imprimante\" -m $pilote -E") != 0);
  98  
  99  die ("Redémarrage de Samba échoué.\n") if (system("/usr/bin/sudo /usr/share/se3/scripts/sambareload.sh") !=0);
 100  
 101  exit 0;


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