SammelUIDs

From NJH-Wiki

Jump to: navigation, search

Vorraussetzungen

Folgende Struktur wird vom script erwartet:

<Ordner Rechnername>
  <passwd>
  <groups>
</Ordner>
<Ordner Rechnername2>
  <passwd>
  <groups>
</Ordner>

Script

#!/usr/bin/php
 
<?php
 
$system_users = array(
        'root',
        'bin',
        'daemon',
        'lp',
        'mail',
        'games',
        'wwwrun',
        'named',
        'nobody',
        'ftp',
        'man',
        'news',
        'uucp',
        'postfix',
        'at',
        'sshd',
        'ntp',
        'domino',
        'aris',
        'fgcenter',
        'stunnel',
        'oracle',
        'hacluster',
        'websphere',
        'adm',
        'sync',
        'shutdown',
        'halt',
        'operator',
        'gopher',
        'mysql',
        'nscd',
        'rpcuser',
        'rpc',
        'rpm',
        'gdm',
        'xfs',
        'mailnull',
        'apache',
        'vsca',
        'radvd',
        'ident',
        'nfsnobody',
        'sitestat',
        'ew2adm',
        'oraew2',
        'postgres',
        'opc_op',
        'ibb_sap',
        'ibb_ftp',
        'ibb_webre');
 
$start_path = ".";
 
if (is_dir($start_path)) {
 
        $dirs = array();
        $dh = opendir($start_path);
        while (false !== ($dir = readdir($dh))) {
                if ($dir != '.' && $dir != '..') {
                        $dirs[] = $dir;
                }
        }
        closedir($dh);
 
        $users = array();
        $already_in = array();
 
        foreach ($dirs as $dir) {
                if (file_exists($dir.'/passwd')) {
                        $lines = file($dir.'/passwd');
                        // gehe die zeilen der passwort datei durch
                        foreach ($lines as $line) {
                                // trenne sie auf
                                $line_array = explode(':',$line);
                                // wenn es sich nicht um einen system nutzer handelt
                                if (!in_array($line_array[0], $system_users) && $line_array[2] > 100) {
                                        // wenn der benutzer noch nicht um array ist
                                        if (!in_array($line_array[0], $already_in)) {
                                                // fuege ihn hinzu
                                                $already_in[] = $line_array[0];
                                                // und ebenfalls im ausgabearray die verbindung rechnername => uid
                                                $users[$line_array[0]] = $dir."->".$line_array[2].",";
                                        } else {
                                                // sonst fuege nur die verbindung rechnername => uid hinzu
                                                $users[$line_array[0]] .= $dir."->".$line_array[2].",";
                                        }
                                }
                        }
                }
        }
        foreach ($users as $key => $value) {
                echo "^".$key."|   |".$value."|\n";
        }
}
 
?>

Personal tools