#!/usr/local/bin/gawk -f
# @(#) htmluser.awk 3.1 97/07/15
# 94/03/22 John H. DuBois III (john@armory.com)
# 94/03/31 Deal with an odd number of finger files, and ignore 0-length files.
# 95/06/02 Write to cache file if requested.
# 95/09/05 Generalized from htmlfinger; added all options;
# convert to awk script.
# 95/09/07 Added l option.
# 96/07/20 Print letter banner for quick access.
# 96/11/12 Added d option; made it be off by default.
# 97/03/01 Use config file.
# 97/05/12 Added T option (table support).
# 97/05/24 Added timezone to 'list last built' date; added r option;
# make cache tempfile have PID extension.
# 97/05/26 Split help printf for non-GNU awk; mangle - to + in help if needed;
# added _strftime() for non-gawk portability.
# 97/07/15 3.1 Emit Expires: field.
# Porting:
# This program works under SCO UNIX. It will likely need tweaking on other
# systems. If the awk part does not work with your awk, try gawk.
# Any non-GNU awk will likely need to have the '_strftime' function at the
# end of this program renamed to 'strftime'.
# On systems that have a fingerd that runs as root (so it can read any .plan
# file regardless of ownership/perms), change the [ -r $home/$file ] test
# to [ -f $home/$file ]. That still will not find finger files in
# non-executable home dirs, which a root fingerd could find. Also, it will
# be incorrect for files other than finger files (web pages, etc).
# If finger files are named something other than .plan (e.g. .usrrc), change
# that.
# The FTP testfile and URL will have to be changed to reflect where user
# anonymous FTP dirs are kept.
# If the GCOS (comment) field in /etc/passwd contains something other than
# user name[,office] it will have to be dealt with.
# The http URLs intentionally do not include a hostname,
# so that the hostname from the page this is found on will be used,
# since it might be different than the hostname given for the finger address.
BEGIN {
Err = 0
Name = "htmluser"
rcFile = "/etc/default/" Name
Usage = "Usage: " Name " [-dhlpwtNT] [-n] [-u]\n"\
" [-r] [-e] [cachefile]"
ARGC = Opts(Name,Usage,"n:ptu:dr:wTe#hlx",0,rcFile,
"HOSTNAME,FINGER,FTP,USERS,ALLUSERS,TRAILER,WEB,TABLES",1,"N")
Debug = "x" in Options
# BadFiles: Files that hold the names of users whose files s/b ignored
# TestFiles: Names of files to check for. If path does not start with /,
# it is taken to be relative to user's home dir; if it does, /username
# is attached to the end.
# URLs: URL to access user's files. User name is substituted for %s,
# Host name is substituted for HOSTNAME.
# TypeNames: The "long names" used to build selectable fields. If the
# lines end up being too long, these are shorted to their first word.
TypeInfo("finger",BadFiles,TestFiles,URLs,TypeNames,
"/usr/local/lib/ignorefinger,.plan,http:/cgi-bin/fing?%s,finger file")
TypeInfo("web",BadFiles,TestFiles,URLs,TypeNames,
"/usr/local/lib/ignorepages,.public_html/index.html,http:/~%s/,web page")
# FTP: does not pick up a hostname relative to the page being read
TypeInfo("ftp",BadFiles,TestFiles,URLs,TypeNames,
"/usr/local/lib/ignoreftp,/usr/local/ftp/pub/user,ftp://HOSTNAME/pub/user/%s,FTP dir")
# The order to list info in the html page
split("web,finger,ftp",InfoOrder,",")
if ("h" in Options) {
print mangleHelp(sprintf(\
"%s: build an HTML file listing all users with finger files, web pages, or\n"\
"anonymous FTP directories.\n"\
"%s\n"\
"This program finds all user names and home directories by reading\n"\
"/etc/passwd, and checks each for the existance and readability of a %s or a\n"\
"%s file. It also looks for a directory with the user's\n"\
"name in %s. If there are finger files, web pages, or\n"\
"anonymous FTP directories that should be ignored for whatever reason (e.g.,\n"\
"those with 100K character long lines, which chokes some browsers), put them\n"\
"in %s, %s, or %s\n"\
"respectively, one per line, and make the file readable. The finger URLs\n"\
"produced by %s depend on the existence of a cgi finger program accessible\n"\
"through the URL /cgi-bin/fing. %s can either be called directly as a\n"\
"cgi-bin program, or can be run at regular intervals to build a cache file\n"\
"that is referenced via URL. The latter is a better option if you find\n"\
"that running this program takes a long time, as it probably will if there\n"\
"are a lot of users on the system it is run on, since it has to check every\n"\
"user's home directory for the existence of finger files and web pages. If\n"\
"it is run regularly, it should be run with approximately the same level of\n"\
"authorization that fingerd, httpd, and FTP run with, so it will find only\n"\
"the files that those daemons will be able to access. Running it as nouser\n"\
"is often good enough, as long as nouser can access the anonymous FTP\n"\
"directories using a local pathname.\n"\
"If the name of a cache file is supplied on the command line, the output is\n"\
"first stored in a file of the same name but with a '-' attached, and is\n"\
"then moved to the cache file name, in order to minimize the time during\n"\
"which the file contents are not available. The directory that the cache\n"\
"file is in must be writable by the process.",
Name,Usage,TestFiles["finger"],TestFiles["web"],TestFiles["ftp"],
BadFiles["finger"],BadFiles["web"],BadFiles["ftp"],Name,Name),"\n[")
print mangleHelp(sprintf(\
"Options:\n"\
"Some of the following options can also be set by assigning values to\n"\
"variables in a configuration file named %s. Variables are\n"\
"assigned to with the syntax: varname=value or in the case of flags, by\n"\
"simply putting the indicated variable name in the file without a value.\n"\
"Options given on the command line override assigments in the configuration\n"\
"file. Flag options set in the configuration file can be turned off on the\n"\
"command line by following them immediately with \"-\", e.g. -v- to turn\n"\
"off the v option in such a way that it cannot be turned on in the config\n"\
"file. Variable names appear in parentheses in the option descriptions.\n"\
"\n"\
"The following three options determine what types of user-presented\n"\
"information are searched for and included in the output. If none are\n"\
"selected, all are included. If any are given in the command line, any\n"\
"values given in the configuration file are ignored.\n"\
"-p: Include finger files (.plans) in the output. (FINGER)\n"\
"-w: Include web pages in the output. (WEB)\n"\
"-t: Include anonymous FTP directories in the output. (FTP)\n"\
"Other options:\n"\
"-h: Print this help.\n"\
"-n: Set the hostname used in text and for the FTP host name.\n"\
" The HTTP URL hostname is left relative to the output page. The default\n"\
" is to use the output of the \"hostname\" command. (HOSTNAME)\n"\
"-u: Process only the users given in the comma-separated list.\n"\
" (USERS)\n"\
"-d: Normally, files in a particular home directory will only be listed\n"\
" for the first user who has that home directory. -d causes them to be\n"\
" listed for all users who have each home directory. (ALLUSERS)\n"\
"-l: Generate a logged-in users report, listing various information about\n"\
" the users currently logged into the system (similar to what 'who'\n"\
" prints), along with links for the information that those users have\n"\
" available.\n"\
"-r: Insert the contents of into the output\n"\
" after all other body contents have been emitted, just before the\n"\
"