0: #!/usr/bin/perl
1: # Little user list thingy, controlled by an rc file in each users dir.
2: # Best used if run daily via crontab.
3: #
4: # Mark Thomas <mark@cidera.com>
5:
6: ## Description
7: ## All this does is look for a file in each persons home directory
8: ## called ".luserrc", this holds a few peices of information the syntax
9: ## of the .luserrc file is somthing along the lines of:
10: ## Name: blah
11: ## Email: blah@blah.com
12: ## Comment: blah blah!
13: ##
14: ## If there is no .luserrc in the home directory then it creates
15: ## a default one, and assigns it the correct permissions, if the
16: ## user does not want to be listed on the html page, then they simply
17: ## create a file called .noshow (touch ~/.noshow) and they will not
18: ## show up.
19: ##
20: ## If the user has a ~/public_html/index.html file then their homepage
21: ## will be linked, if not, then it just shows up as non-existant.
22: ##
23: ## I understand this is lame code, but also realize it was done fairly
24: ## quickly, so you understand right? :)
25: ## This is kinda tailored for my server, but can easily be changed.
26:
27: use strict;
28: require "ctime.pl";
29:
30: ## Standard Variables
31: # Set this to 1 if you want to see various output to stdout
32: my $debug = 0;
33: # This is the directory where all your users exist
34: my $homedir = "/home";
35: # This is the file this program reads from to generate the html
36: my $rcfile = ".luserrc";
37: # The hostname of this box.
38: my $hostname = "ackers.net";
39: # What is the file were generating?
40: my $htmlfile = "/var/www/htdocs/index.html";
41: # This is the file a user must have in their home
42: # Directory if they dont want to be listed on the
43: # $htmlfile.
44: my $dontshowme = ".noshow";
45:
46: #############
47:
48: my ($dir, @dirarray, $array);
49: my $current_time = &ctime(time());
50:
51: opendir (HOME, $homedir) or print "cannot open directory $dir!\n";
52: foreach $dir (readdir(HOME)) {
53: push(@dirarray, $dir) if $dir !~ /\./;
54: }
55:
56: open(HTMLFILE, ">$htmlfile");
57:
58: print HTMLFILE <<END_OF_HEADER;
59: <html>
60: <body bgColor=black link=orange vlink=orange text=white>
61: <title>Ackers...Were all assholes here.</title>
62: <center><img src="wankers.jpg"></center>
63: <br><br><br>
64: <center><font color=white><i><b>Users</b></i></center>
65: <center>
66:
67: END_OF_HEADER
68:
69: foreach $dir (@dirarray) {
70: my($name,$email,$comment,$homepage) = read_rc($dir);
71: print HTMLFILE "Name: $name<br>\nEmail: <a href=\"mailto:$email\">$email<\/a><br>\n"
72: if (-e "$homedir/$dir/$dontshowme" eq '');
73: if ($homepage eq 0) {
74: print HTMLFILE "Homepage: Non-Existant<br>\n"
75: if(-e "$homedir/$dir/$dontshowme" eq '');
76: } elsif ($homepage eq 1) {
77: print HTMLFILE "Homepage: <a href=\"\/\~$dir\">Here<\/a><br>\n"
78: if(-e "$homedir/$dir/$dontshowme" eq '');
79: }
80: print HTMLFILE "Comment: $comment<br><br>\n"
81: if(-e "$homedir/$dir/$dontshowme" eq '');
82: print "Name:\t\t$name\nEmail:\t\t$email\nComment:\t$comment\n\n" if ($debug eq 1);
83: }
84:
85: print HTMLFILE <<END_OF_FOOTER;
86:
87: </center>
88: <br><br><br><br>
89: <center>Last updated $current_time<\/center>
90: <br>
91: <center><a href=\"mailto:root\@ackers.net\">Problems?</a>
92: <br><br><br><br><br><br>
93: <center>Want the code that generated this page? <a href=\"makedex.txt\">Click here<\/a><\/center>
94: <br><br>
95: <center><img src="openbsd_pb.jpg"></center>
96:
97: </html>
98:
99: END_OF_FOOTER
100:
101: close(HTMLFILE);
102:
103: sub no_rc {
104: my($dir) = @_;
105: # If there is no rc file, we might as well give them one right?
106: my($name,$passwd,$uid,$gid,$quota,$comment,$realname,$hdir,$shell) = getpwnam $dir
107: or print "uhh for some reason $dir doesnt exist as a user\n" if ($debug eq 1);
108: open(RC, ">>$homedir/$dir/$rcfile") or print "Cannot open $dir/$rcfile for writing\n" if ($debug eq 1);
109: print RC "# Default $rcfile, please change to your liking!\n";
110: print RC "Name: $realname\n";
111: print RC "Email: $dir\@$hostname\n";
112: print RC "Comment: Hi my name is $realname, I suck!";
113: close(RC);
114: chmod 0755, '$homedir/$dir/$rcfile';
115: chown($uid,$gid,"$homedir/$dir/$rcfile");
116: return($realname,"$dir\@$hostname","Hi my name is $realname, I suck!");
117: }
118:
119:
120: sub read_rc {
121: my($dir) = @_;
122: my($name,$email,$comment,$option,$rest,$homepage);
123: open(RC, "$homedir/$dir/$rcfile") or ($name,$email,$comment) = no_rc($dir);
124: while (<RC>) {
125: s/\s+$//g; # Remove trailing whitespace
126: s/\s/ /g; # Replace whitespace with space
127: next if /^\s*\#/; # Ignore Comment Lines
128: s/\s*\#$//g; # Ignore Trailing Comment
129: next if /^\s*$/; # Ignore Empty Lines
130: my($option,$rest) = split(/:/);
131: $rest =~ s/^\s+//g; # Remove First white space.
132: if ($option eq 'Name') {
133: $name = $rest;
134: $name =~ s/<[^>]*>//gs;
135: }
136: elsif ($option eq 'Email') {
137: $email = $rest;
138: $email =~ s/<[^>]*>//gs;
139: }
140: elsif ($option eq 'Comment') {
141: $comment = $rest;
142: $comment =~ s/<[^>]*>//gs;
143: }
144: }
145: if(-e "$homedir/$dir/public_html/index.html") {
146: $homepage = 1;
147: } else { $homepage = 0; }
148: return($name,$email,$comment,$homepage);
149: close(RC);
150: }
151:
In reply to Server Users Webpage Generator by cleen
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |