informatique:printer

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Les deux révisions précédentes Révision précédente
Prochaine révision
Révision précédente
informatique:printer [04/10/2019 14:25] ldalbegueinformatique:printer [06/01/2026 11:38] (Version actuelle) bchicard
Ligne 1: Ligne 1:
-==== Annuaire du GNI ====+==== Les Impressions au GNI ====
  
-<PHP>+== Présentation du système d’accounting des impressions : PaperCut ==
  
-// mydap version 4 +//Pourquoi PaperCut ?// 
-// https://samjlevy.com/mydap/ + PaperCut est une solution logicielle dédiée à la gestion et au suivi des impressions dans les environnements éducatifs et professionnelsAu GRETA Nord IsèrePaperCut nous permet de :
- function mydap_start($username,$password,$host,$port=389) { +
- global $mydap; +
- if(isset($mydap)) die('Error, LDAP connection already established'); +
-  +
- // Connect to AD +
- $mydap = ldap_connect($host,$port) or die('Error connecting to LDAP'); +
-  +
- ldap_set_option($mydap,LDAP_OPT_PROTOCOL_VERSION,3); +
- @ldap_bind($mydap,$username,$password) or die('Error binding to LDAP: '.ldap_error($mydap)); +
-  +
- return true; +
-+
-  +
-function mydap_end() { +
- global $mydap; +
- if(!isset($mydap)) die('Error, no LDAP connection established'); +
-  +
- // Close existing LDAP connection +
- ldap_unbind($mydap); +
-+
-  +
-function mydap_attributes($user_dn,$keep=false) { +
- global $mydap; +
- if(!isset($mydap)) die('Error, no LDAP connection established'); +
- if(empty($user_dn)) die('Error, no LDAP user specified'); +
-  +
- // Disable pagination setting, not needed for individual attribute queries +
- ldap_control_paged_result($mydap,1); +
-  +
- // Query user attributes +
- $results = (($keep) ldap_search($mydap,$user_dn,'cn=*',$keep) : ldap_search($mydap,$user_dn,'cn=*')) +
- or die('Error searching LDAP: '.ldap_error($mydap)); +
-  +
- $attributes = ldap_get_entries($mydap,$results); +
-  +
- // Return attributes list +
- if(isset($attributes[0])) return $attributes[0]; +
- else return array(); +
-+
-  +
-function mydap_members($object_dn,$object_class='g') { +
- global $mydap; +
- if(!isset($mydap)) die('Error, no LDAP connection established'); +
- if(empty($object_dn)) die('Error, no LDAP object specified'); +
-  +
- // Determine class of object we are dealing with +
-  +
- // Groups, use range to overcome LDAP attribute limit +
- if($object_class == 'g') { +
- $output = array(); +
- $range_size = 1500; +
- $range_start = 0; +
- $range_end = $range_size - 1; +
- $range_stop = false; +
-  +
- do { +
- // Query Group members +
- $results = ldap_search($mydap,$object_dn,'cn=*',array("member;range=$range_start-$range_end")) or die('Error searching LDAP: '.ldap_error($mydap)); +
- $members = ldap_get_entries($mydap,$results); +
-  +
- $member_base = false; +
-  +
- // Determine array key of the member results +
-  +
- // If array key matches the format of range=$range_start-* we are at the end of the results +
- if(isset($members[0]["member;range=$range_start-*"])) { +
- // Set flag to break the do loop +
- $range_stop = true; +
- // Establish the key of this last segment +
- $member_base = $members[0]["member;range=$range_start-*"]; +
-  +
- // Otherwise establish the key of this next segment +
- } elseif(isset($members[0]["member;range=$range_start-$range_end"])) +
- $member_base = $members[0]["member;range=$range_start-$range_end"]; +
-  +
- if($member_base && isset($member_base['count']) && $member_base['count'] != 0) { +
- // Remove 'count' element from array +
- array_shift($member_base); +
-  +
- // Append this segment of members to output +
- $output = array_merge($output,$member_base); +
- } else $range_stop = true; +
-  +
- if(!$range_stop) { +
- // Advance range +
- $range_start = $range_end + 1; +
- $range_end = $range_end + $range_size; +
-+
- } while($range_stop == false); +
-  +
- // Containers and Organizational Units, use pagination to overcome SizeLimit +
- } elseif($object_class == 'c' || $object_class == "o") { +
-  +
- $pagesize = 1000; +
- $counter = ""; +
- do { +
- ldap_control_paged_result($mydap,$pagesize,true,$counter); +
-  +
- // Query Container or Organizational Unit members +
- $results = ldap_search($mydap,$object_dn,'objectClass=user',array('sn')) or die('Error searching LDAP'.ldap_error($mydap)); +
- $members = ldap_get_entries($mydap, $results); +
-  +
- // Remove 'count' element from array +
- array_shift($members); +
-  +
- // Pull the 'dn' from each result, append to output +
- foreach($members as $e) $output[] = $e['dn']; +
-  +
- ldap_control_paged_result_response($mydap,$results,$counter); +
- } while($counter !== null && $counter != ""); +
-  +
- // Invalid object_class specified +
- } else die("Invalid mydap_member object_class, must be c, g, or o"); +
-  +
- // Return alphabetized member list +
- sort($output); +
- return $output; +
-+
-  +
-// ================================================================================== +
-// Example Usage +
-// ================================================================================== +
-/*  +
-// Establish connection +
-mydap_start( +
- 'joe@ad.local', // Active Directory search user +
- 'password', // Active Directory search user password +
- 'ad.local', // Active Directory server +
- 389 // Port (optional) +
-); +
-  +
-// Query users using mydap_members(object_dn,object_class) +
-// The object_dn parameter should be the distinguishedName of the object +
-// The object_class parameter should be 'c' for Container, 'g' for Group, or 'o' for Organizational Unit +
-// If left blank object_class will assume Group +
-// Ex: the default 'Users' object in AD is a Container +
-// The function returns an array of member distinguishedName'+
-$members = mydap_members('CN=Users,DC=ad,DC=local','c'); +
-if(!$members) die('No members found, make sure you are specifying the correct object_class'); +
-  +
-// Now collect attributes for each member pulled +
-// Specify user attributes we want to collect, to be used as the keep parameter of mydap_attributes +
-$keep = array('samaccountname','mail','employeeID'); +
-  +
-// Iterate each member to get attributes +
-$i = 1; // For counting our output +
-foreach($members as $m) { +
- // Query a user's attributes using mydap_attributes(member_dn,keep) +
- // The member_dn is the step $m of this foreach +
- $attr = mydap_attributes($m,$keep); +
-  +
- // Each attribute is returned as an array, the first key is [count], [0]+ will contain the actual value(s) +
- // You will want to make sure the key exists to account for situations in which the attribute is not returned (has no value) +
- $employeeID = isset($attr['employeeid'][0]) ? $attr['employeeid'][0] : "[no employee ID]"; +
- $samaccountname = isset($attr['samaccountname'][0]) ? $attr['samaccountname'][0] : "[no account name]"; +
- $mail = isset($attr['mail'][0]) ? $attr['mail'][0] : "[no email]"; +
-  +
- // Do what you will, such as store or display member information +
- echo "$i. $samaccountname, $mail - $employeeID<br>"; +
-  +
- $i++; +
-+
-  +
-// Here you could run another mydap_members() if needed, merge with previous results, etc. +
-  +
-// Close connection +
-mydap_end(); +
-*/  +
-// Here you can open a new connection with mydap_connect() if needed, such as to a different AD server+
  
-mydap_start( +  * Contrôler les coûts en attribuant des quotas d’impression à chaque utilisateur. 
- 'olympe@gni.loc', // Active Directory search user +  * Réduire le gaspillage en encourageant une utilisation responsable des ressources
- '*GNI/2011'// Active Directory search user password +  Suivre les impressions (noir et blanccouleur, recto-verso, etc.) pour une gestion transparente
- 'sc-srv-ad.gni.loc', // Active Directory server +  * Simplifier l’administration grâce à une interface intuitive pour les gestionnaires et les utilisateurs.
- 389 // Port (optional) +
-);+
  
-$members = mydap_members('OU=Personnel,OU=Users,OU=Current,OU=GNI,DC=gni,DC=loc','c'); +**Fonctionnalités clés :**
-if(!$members) die('No members found, make sure you are specifying the correct object_class'); +
-echo 'Nbr de Personnes dans l\'annuaire ' . count($members) . '<br/>';+
  
-// Now collect attributes for each member pulled +  * Authentification sécurisée : Connexion via les identifiants GRETA pour accéder aux services d’impression. 
-// Specify user attributes we want to collectto be used as the keep parameter of mydap_attributes +  * Tableau de bord utilisateur : Visualisation du soldede l’historique et des options d’impression disponible [[https://print.gretani.com | 🔗 ici]]
-$keep = array('samaccountname','mail','cn','ipphone','mobile','telephonenumber','title','givenName','sn','pager','facsimile TelephoneNumber'); +
-foreach($members as $m) { +
- // Query a user's attributes using mydap_attributes(member_dn,keep) +
- // The member_dn is the step $m of this foreach +
- $attr = mydap_attributes($m,$keep);+
  
-  // Each attribute is returned as an array, the first key is [count], [0]+ will contain the actual value(s) +Comment utiliser PaperCut Besoin d’aide ?
- // You will want to make sure the key exists to account for situations in which the attribute is not returned (has no value) +
-  +
- $user['login'] = isset($attr['samaccountname'][0]) $attr['samaccountname'][0] : ""; +
- $user['mail'] = isset($attr['mail'][0]) $attr['mail'][0] : ""; +
- $user['nom'] = isset($attr['sn'][0]) ? $attr['sn'][0] : ""; +
- $user['prenom'] = isset($attr['givenname'][0]) ? $attr['givenname'][0] : ""; +
- $user['fullname'] = isset($attr['cn'][0]) ? $attr['cn'][0] : ""; +
- $user['telip'] = isset($attr['ipphone'][0]) ? $attr['ipphone'][0] : ""; +
- $user['telmob'] = isset($attr['mobile'][0]) ? $attr['mobile'][0] : ""; +
- $user['telext'] = isset($attr['telephonenumber'][0]) ? $attr['telephonenumber'][0] : ""; +
- $user['fonction'] = isset($attr['title'][0]) ? $attr['title'][0] : ""; +
- $user['code'] = isset($attr['pager'][0]) ? $attr['pager'][0] : ""; +
- $user['badge'] = isset($attr['facsimile TelephoneNumber'][0]) ? $attr['facsimile TelephoneNumber'][0] : "";+
  
-//Photo des users +Consultez le tutoriel officiel PaperCut pour apprendre à utiliser le système : 
-$file = 'https://gni.gretani.com/tools/thumb/'.$user['login'].'.jpg'; +[[https://files.gretani.com/gni/tutos_applicatif/papercut/sharp-copieur.pdf | 🔗 Tutoriel PaperCut – Guide utilisateur]]
-$file_headers = @get_headers($file); +
-if($file_headers[0] == 'HTTP/1.1 404 Not Found') { +
-    $user['photo'= 'tools\thumb\personne.jpg'; +
-+
-else { +
-    $user['photo'= 'tools\\thumb\\'.$user['login'].'.jpg'; +
-}+
  
- $users[$user['login']] = $user; 
-} 
  
-// Trie par nom 
-foreach ($users as $key => $row)  
-{ 
- $rang[$key] = $row['nom']; 
-} 
-array_multisort($rang, SORT_ASC, $users); 
  
-// Génération du tableau de sortie 
-echo '<br>'; 
-echo '<table border=1 align="center">'; 
-echo '<tr align="center"><td align="center" colspan=2>Nom</td><td align="center"> Tel Interne </td><td align="center"> Tel Externe & Tel Mobile </td><td align="center">Fonction</td></tr>'<td align="center">Code</td></tr>'<td align="center">Badge</td></tr>'; 
- 
-foreach($users as $login => $user)  
-{ 
- echo '<tr align="center"><td align="center"><img src='.$user['photo'].' height="50"></td><td align="left"><a href="mailto:'.$user['mail'].'">'.'  '.$user['nom'].' '.$user['prenom'].'</a></td><td> '.$user['telip'].' </td><td> '.$user['telext'].'<br>'.$user['telmob'].' </td><td> '.$user['fonction'].' </td><td> '.$user['code'].' </td><td> '.$user['badge'].' </td></tr>'; 
-} 
- 
-echo '</table>'; 
- 
-</PHP> 
  • informatique/printer.1570195536.txt.gz
  • Dernière modification : 04/10/2019 14:25
  • de ldalbegue