/usr/portage

Starting with kadmin 5

Since today, kadmin is my new favourite project. It is a server-administration software, written in PHP, using XML-files for storing data, also as MySQL. There is neither a homepage until now nor a bugtracker or something like this but I’m able to show you my first clean work. A function to parse the content of /etc/passwd into a sorted array.
<!– readmore: Read the code –>
&lt;?php

/*
function: kadmin_get_user_attr_array ()
desc: Returns an array in which all the userdata from /etc/passwd is included */

function kadmin_get_user_attr_array () { if (file_exists (”/etc/shadow”)) { $kadmin_etc_passwd = file (”/etc/passwd”); /* Delete newlines that are in /etc/passwd */ foreach ($kadmin_etc_passwd as $kadmin_etc_passwd_key => $value) { $kadmin_etc_passwd[$kadmin_etc_passwd_key] = ereg_replace (”\n$”, ‘’, $kadmin_etc_passwd[$kadmin_etc_passwd_key]); }

/* Put values into a well sorted array */ foreach ($kadmin_etc_passwd as $kadmin_passwd_line) { list ($kadmin_tmp_username, $trash) = split (”:”, $kadmin_passwd_line, 2); list ($kadmin_passwd_user_attr[$kadmin_tmp_username][‘username’], $kadmin_passwd_user_attr[$kadmin_tmp_username][‘password’], $kadmin_passwd_user_attr[$kadmin_tmp_username][‘uid’], $kadmin_passwd_user_attr[$kadmin_tmp_username][‘gid’], $kadmin_passwd_user_attr[$kadmin_tmp_username][‘extra’], $kadmin_passwd_user_attr[$kadmin_tmp_username][‘home’], $kadmin_passwd_user_attr[$kadmin_tmp_username][‘shell’]) = split(”:”, $kadmin_passwd_line); } } /* Delete system users from the array */ foreach ($kadmin_passwd_user_attr as $kadmin_passwd_key => $value) { if (ereg (”/bin/false”, $kadmin_passwd_user_attr[$kadmin_passwd_key][‘shell’])) { unset ($kadmin_passwd_user_attr[$kadmin_passwd_key]); } } return $kadmin_passwd_user_attr; }

/*
function: kadmin_get_user_attr_by_name ( $username, $field )
desc: Returns the value of the given field of the given username */
function kadmin_get_user_attr_by_name ($kadmin_username, $kadmin_field) { $kadmin_passwd_array = kadmin_get_user_attr_array (); if (! is_null ($kadmin_passwd_array[$kadmin_username][$kadmin_field])) { return $kadmin_passwd_array[$kadmin_username][$kadmin_field]; } else { return FALSE; }
}
?>

<!– /readmore –>

Filed under & five comments & four trackbacks

Trackbacks

Trackback specific URI for this entry

No Trackbacks

Comments

  1. Bernd says:
    published on December 6th 2004, 08:46:44 am *

    Das ist jetzt nicht dein Ernst: $kadmin_etc_passwd[$kadmin_etc_passwd_key] = ereg_replace ("\n$", ‘’, $kadmin_etc_passwd[$kadmin_etc_passwd_key]);

    Erstens steht bei ereg_replace() ganz gro

    Reply

  2. Bernd supposes:
    published on December 6th 2004, 08:48:19 am *

    Argh, replyce soll nat

    Reply

  3. Lars means:
    published on December 6th 2004, 04:55:31 pm *

    Danke f

    Reply

  4. citizen428 returns:
    published on December 9th 2004, 06:26:33 pm *

    chop ist nichts PHP-spezifisches, Perl und Ruby haben das auch.

    Reply

  5. Lars Strojny opines:
    published on December 9th 2004, 08:23:31 pm *

    OK, wenn es nur Perl und Ruby so machen, f

    Reply

Add a Comment & let me know what you think