Différences
Ci-dessous, les différences entre deux révisions de la page.
| 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] – ldalbegue | informatique: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:// | + | PaperCut est une solution logicielle dédiée à la gestion et au suivi des impressions dans les environnements éducatifs et professionnels. Au GRETA Nord Isère, PaperCut nous permet de : |
| - | | + | |
| - | global $mydap; | + | |
| - | if(isset($mydap)) die(' | + | |
| - | + | ||
| - | // Connect to AD | + | |
| - | $mydap = ldap_connect($host, | + | |
| - | + | ||
| - | ldap_set_option($mydap, | + | |
| - | @ldap_bind($mydap, | + | |
| - | + | ||
| - | return true; | + | |
| - | } | + | |
| - | + | ||
| - | function mydap_end() { | + | |
| - | global $mydap; | + | |
| - | if(!isset($mydap)) die(' | + | |
| - | + | ||
| - | // Close existing LDAP connection | + | |
| - | ldap_unbind($mydap); | + | |
| - | } | + | |
| - | + | ||
| - | function mydap_attributes($user_dn, | + | |
| - | global $mydap; | + | |
| - | if(!isset($mydap)) die(' | + | |
| - | if(empty($user_dn)) die(' | + | |
| - | + | ||
| - | // Disable pagination setting, not needed for individual attribute queries | + | |
| - | ldap_control_paged_result($mydap, | + | |
| - | + | ||
| - | // Query user attributes | + | |
| - | $results = (($keep) | + | |
| - | or die(' | + | |
| - | + | ||
| - | $attributes = ldap_get_entries($mydap, | + | |
| - | + | ||
| - | // Return attributes list | + | |
| - | if(isset($attributes[0])) return $attributes[0]; | + | |
| - | else return array(); | + | |
| - | } | + | |
| - | + | ||
| - | function mydap_members($object_dn, | + | |
| - | global $mydap; | + | |
| - | if(!isset($mydap)) die(' | + | |
| - | if(empty($object_dn)) die(' | + | |
| - | + | ||
| - | // Determine class of object we are dealing with | + | |
| - | + | ||
| - | // Groups, use range to overcome LDAP attribute limit | + | |
| - | if($object_class == ' | + | |
| - | $output = array(); | + | |
| - | $range_size = 1500; | + | |
| - | $range_start = 0; | + | |
| - | $range_end = $range_size - 1; | + | |
| - | $range_stop = false; | + | |
| - | + | ||
| - | do { | + | |
| - | // Query Group members | + | |
| - | $results = ldap_search($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][" | + | |
| - | // Set flag to break the do loop | + | |
| - | $range_stop = true; | + | |
| - | // Establish the key of this last segment | + | |
| - | $member_base = $members[0][" | + | |
| - | + | ||
| - | // Otherwise establish the key of this next segment | + | |
| - | } elseif(isset($members[0][" | + | |
| - | $member_base = $members[0][" | + | |
| - | + | ||
| - | if($member_base && isset($member_base[' | + | |
| - | // Remove ' | + | |
| - | array_shift($member_base); | + | |
| - | + | ||
| - | // Append this segment of members to output | + | |
| - | $output = array_merge($output, | + | |
| - | } 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 == ' | + | |
| - | + | ||
| - | $pagesize = 1000; | + | |
| - | $counter = ""; | + | |
| - | do { | + | |
| - | ldap_control_paged_result($mydap, | + | |
| - | + | ||
| - | // Query Container or Organizational Unit members | + | |
| - | $results = ldap_search($mydap, | + | |
| - | $members = ldap_get_entries($mydap, | + | |
| - | + | ||
| - | // Remove ' | + | |
| - | array_shift($members); | + | |
| - | + | ||
| - | // Pull the ' | + | |
| - | foreach($members as $e) $output[] = $e[' | + | |
| - | + | ||
| - | ldap_control_paged_result_response($mydap, | + | |
| - | } while($counter !== null && $counter != "" | + | |
| - | + | ||
| - | // Invalid object_class specified | + | |
| - | } else die(" | + | |
| - | + | ||
| - | // Return alphabetized member list | + | |
| - | sort($output); | + | |
| - | return $output; | + | |
| - | } | + | |
| - | + | ||
| - | // ================================================================================== | + | |
| - | // Example Usage | + | |
| - | // ================================================================================== | + | |
| - | /* | + | |
| - | // Establish connection | + | |
| - | mydap_start( | + | |
| - | ' | + | |
| - | ' | + | |
| - | ' | + | |
| - | 389 // Port (optional) | + | |
| - | ); | + | |
| - | + | ||
| - | // Query users using mydap_members(object_dn, | + | |
| - | // The object_dn parameter should be the distinguishedName of the object | + | |
| - | // The object_class parameter should be ' | + | |
| - | // If left blank object_class will assume Group | + | |
| - | // Ex: the default ' | + | |
| - | // The function returns an array of member distinguishedName' | + | |
| - | $members = mydap_members(' | + | |
| - | if(!$members) die(' | + | |
| - | + | ||
| - | // 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(' | + | |
| - | + | ||
| - | // 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, | + | |
| - | // The member_dn is the step $m of this foreach | + | |
| - | $attr = mydap_attributes($m, | + | |
| - | + | ||
| - | // 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[' | + | |
| - | $samaccountname = isset($attr[' | + | |
| - | $mail = isset($attr[' | + | |
| - | + | ||
| - | // Do what you will, such as store or display member information | + | |
| - | echo "$i. $samaccountname, | + | |
| - | + | ||
| - | $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. |
| - | ' | + | * Réduire le gaspillage en encourageant une utilisation responsable des ressources. |
| - | '*GNI/ | + | * Suivre les impressions (noir et blanc, couleur, 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(' | + | **Fonctionnalités clés :** |
| - | if(!$members) die(' | + | |
| - | echo 'Nbr de Personnes dans l\' | + | |
| - | // 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 collect, to be used as the keep parameter of mydap_attributes | + | * Tableau de bord utilisateur : Visualisation du solde, de l’historique et des options d’impression disponible [[https://print.gretani.com | 🔗 ici]] |
| - | $keep = array(' | + | |
| - | foreach($members as $m) { | + | |
| - | // Query a user's attributes using mydap_attributes(member_dn, | + | |
| - | // The member_dn is the step $m of this foreach | + | |
| - | $attr = mydap_attributes($m, | + | |
| - | // Each attribute is returned as an array, the first key is [count], [0]+ will contain the actual value(s) | + | Comment utiliser PaperCut |
| - | // You will want to make sure the key exists to account for situations in which the attribute is not returned (has no value) | + | |
| - | + | ||
| - | $user[' | + | |
| - | $user[' | + | |
| - | $user[' | + | |
| - | $user[' | + | |
| - | $user[' | + | |
| - | $user[' | + | |
| - | $user[' | + | |
| - | $user[' | + | |
| - | $user[' | + | |
| - | $user[' | + | |
| - | $user[' | + | |
| - | //Photo des users | + | Consultez le tutoriel officiel PaperCut pour apprendre à utiliser le système : |
| - | $file = 'https://gni.gretani.com/ | + | [[https://files.gretani.com/ |
| - | $file_headers = @get_headers($file); | + | |
| - | if($file_headers[0] == 'HTTP/1.1 404 Not Found' | + | |
| - | $user[' | + | |
| - | } | + | |
| - | else { | + | |
| - | $user[' | + | |
| - | } | + | |
| - | $users[$user[' | ||
| - | } | ||
| - | // Trie par nom | ||
| - | foreach ($users as $key => $row) | ||
| - | { | ||
| - | $rang[$key] = $row[' | ||
| - | } | ||
| - | array_multisort($rang, | ||
| - | // Génération du tableau de sortie | ||
| - | echo '< | ||
| - | echo '< | ||
| - | echo '< | ||
| - | |||
| - | foreach($users as $login => $user) | ||
| - | { | ||
| - | echo '< | ||
| - | } | ||
| - | |||
| - | echo '</ | ||
| - | |||
| - | </ | ||