#!/usr/bin/perl -w

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

# vypise do suboru vsetkych userov na aktualnej masine, ktori maju vytvorenu domovsku 
# stranku

$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 ){
			&writeUser($name,"/~$login/");
		} else {
		     &writeUser($login,"/~$login/");
		}
	}
}

print OUT "</ul>\n";
close OUT ;	
close DATA ;
`sort users.html >temp.html`;
`mv temp.html users.html`;

sub writeUser {
	my ($name,$url) = @_;
	print OUT "<li><a href=\"$url\">$name</a></li>\n";
} 
