#!/usr/bin/perl -w

# This script creates HTML file with links to all available homepages
# on this machine ( sorted ).  

# zevraj to ma byt zrozumitelne, takze aj pre tych anglicky nehovoriacich:
# tento skriptik vypise ( do suboru )vsetkych userov na aktualnej masine, 
# ktori maju vytvorenu stranku index.html v adresari pulic_html. (samozrejme
# v tejto verzii uz su luzri zoradeni (teda skor "kvazi")

$htmlindex = "/public_html/index.html";
$out = "users.html";

open(DATA,"/etc/passwd")
	or die "Can't open /etc/passwd !\n";
open(OUT,">$out")
	or die "Can't rewrite $out !\n";
print OUT "<ul>\n";
while ($line = <DATA>) {
	@users = split (/:/,$line);
	($login,$home,$name) = ($users[0],$users[5],split (/,/,$users[4]) );
	if ( -r "$home$htmlindex" ) {
		if ( $name ){
			$list{"\u$name"}="/~$login/";
		} else {
		     $list{$login}="/~$login/";
		};
	};
};
 
foreach $name ( sort keys (%list) ) {
	print OUT "<li><a href=\"$list{$name}\">$name</a></li>\n";
}; 

print OUT "</ul>\n";
close DATA;
close OUT;
