| Current Path : /var/www/html/mmishra/indem/scripts/php/ |
| Current File : /var/www/html/mmishra/indem/scripts/php/idleaccount.php |
<?php
echo "IDLE ACCOUNTS\n=============\n";
echo "Enter category [employee/student/rgiit/general]:\n";
$cat = trim(fgets(STDIN));
if (!$cat) exit;
if ($cat == "general") $ous = array("general","webadmin");
else if ($cat == "rgiit") $ous = array("rgiit");
else if ($cat == "employee") $ous = array("faculty", "officer","techstaff","adminstaff","projectstaff");
else $ous = array("it,ou=btech", "ece,ou=btech","mtech", "mba", "ms", "phd");
$ds = ldap_connect("ldap.iiita.ac.in");
ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
$no = 0;
$nos = 0;
$tot = 0;
foreach ($ous as $ou) {
$nos += $no;
if ($nos) echo "( status: $no idle / $i accounts )\n";
$no = 0;
$i = 0;
echo "\n[ " . strtoupper(str_replace("ou=","",$ou)) . " ]\n";
if ($cat == "general") $ou = "ou=$ou";
else if ($cat == "rgiit") $ou = "ou=$ou";
else if ($cat == "employee") $ou = "ou=$ou,ou=employee";
else $ou = "ou=$ou,ou=student";
$rec = ldap_search($ds, "$ou,dc=iiita,dc=ac,dc=in","(&(uid=*)(objectClass=posixAccount))");
while ($acc = ldap_get_entries($ds, $rec)) {
$uid = strtolower($acc[$i]["uid"][0]);
$tot++;
$i++;
if ($uid) {
$found = shell_exec("cat /var/log/squirrelmail/access.log | grep $uid");
if ($found) echo ".";
else {
$found = shell_exec("cat /var/log/squirrelmail/access.log | grep " . strtoupper($uid));
if ($found) echo ".";
else {
echo " $uid ";
$no++;
}
}
} else break;
}
}
$nos += $no;
if ($nos) echo "( status: $no idle / $i accounts )\n \n$nos OUT OF $tot ACCOUNTS ARE IDLE\n";
ldap_close($ds);
?>