#!/usr/bin/perl -w # # $Id: htmlvars,v 1.1 2006/08/24 21:54:41 vogelke Exp $ # # read stdin, substitute the listed variables # with their values. # # Environment variables: # FULLNAME User's full name # HOST Fully-qualified hostname # LOGNAME login name, same as USER # ORGANIZATION User's employer or organization # REPLYTO Where to send mail # # Other variables: # CWD Current working directory # MTIME Modification time of this file use Cwd; use strict; # # Set up variables. # my $cwd = getcwd; my $mtime = undef; my $fullname = $ENV{'FULLNAME'} || "Unknown fullname"; my $host = $ENV{'HOST'} || "Unknown host"; my $org = $ENV{'ORGANIZATION'} || "Unknown organization"; my $replyto = $ENV{'REPLYTO'} || "Unknown replyto"; my $user = $ENV{'USER'} || $ENV{'LOGNAME'} || "SERIOUS PROBLEM, no userid"; # # Replace them. # while (<>) { $mtime = modtime($ARGV) unless $mtime; s/\@CWD\@/$cwd/g; s/\@FULLNAME\@/$fullname/g; s/\@HOST\@/$host/g; s/\@LOGNAME\@/$user/g; s/\@MTIME\@/$mtime/g; s/\@ORGANIZATION\@/$org/g; s/\@REPLYTO\@/$replyto/g; s/\@USER\@/$user/g; print; } exit(0); sub modtime { my ($path) = @_; my ($hour, $mday, $min, $mon, $mt, $sec, $str, $year); if ($path eq '-') { $mt = (stat(STDIN))[9]; } else { $mt = (stat($path))[9]; } ($sec, $min, $hour, $mday, $mon, $year) = localtime($mt); $str = sprintf( "%2.2d/%2.2d/%4.4d %2.2d:%2.2d:%2.2d", $mon + 1, $mday, $year + 1900, $hour, $min, $sec ); return ($str); }