#!/usr/bin/perl -wT ############################################################################### # defindex.txt - A script for setting a default index page in Cpanel6 boxes # Version 0.1.2 beta - 23/MAR/2003 # (c) 2003 Juan R. Pozo # http://html.conclase.net/cp/scripts/ # mailto:jrpozo@conclase.net ############################################################################### # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the Free # Software Foundation; either version 2 of the License, or (at your option) # any later version. # # This program is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License # for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ############################################################################### # INSTALLATION # 1) Check if there exists a file /scripts/postwwwacct in your server # 2) If it exists, I guess you'll figure out how to install this, skip the rest # If it doesn't exist, follow steps 3 to 9: # 3) switch to root user # 4) cd /scripts # 5) wget http://html.conclase.net/cp/scripts/defindex.txt # 6) chown root.root defindex.txt # 7) chmod 0700 defindex.txt # 8) Customize your settings (see below) # 9) mv defindex.txt postwwwacct # From now on, you should see the text "Default index page written" # upon successful account creation. ############################################################################### # Changelog: # 0.1.2 - 23/mar/2003 - Fixed regex for domain name. Also, now tries to find # the IP even for domain names which still don't resolve. A new default_ip # variable is introduced. # 0.1.1 - 10/mar/2003 - New %ip% placeholder # 0.1 - 10/mar/2003 - First public release ############################################################################### # Please consider making a donation today. Visit my amazon.com wishlist at: # http://html.conclase.net/link/wishlist # Thank you :) ############################################################################### use strict; $ENV{'PATH'} = '/bin:/usr/bin'; delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'}; ############################################################################### # Please customize your settings ############################################################################### # The name of the index page at your skeleton directory my $index = 'index.html'; my $default_ip = '172.26.0.1'; ############################################################################### # Customization done ############################################################################### my (@userdata, $user, $uid, $gid, $homedir, $domain, $ip, $infile, $outfile); my $inWHM = (defined($ENV{'WHM50'}) && $ENV{'WHM50'} ne ""); print "\nRunning postwwwacct...\n"; # Checks username if (!@ARGV || $ARGV[1] eq "" || $ARGV[1] !~ /^([^\s:]{1,})$/) { deaderror("Missing or wrong argument (user) in /scripts/postwwwacct\n"); } else { $user = $1; } @userdata = getpwnam($user) or deaderror("Username not found"); ($uid, $gid, $homedir) = ($userdata[2], $userdata[3], $userdata[7]); # Checks domain name if (!@ARGV || $ARGV[0] eq "" || $ARGV[0] !~ /(\S+)/) { deaderror("Missing or wrong argument (domain) in /scripts/postwwwacct\n"); } else { $domain = validatedomain($1); print "Setting \%domain\% = $domain\n"; $ip = ""; if (-r "/var/cpanel/accounting.log") { my $lastline = `tail -1 /var/cpanel/accounting.log`; if ($lastline =~ /CREATE:(?:[^:]+:){3}([^:]+)/) { $ip = $1; } } if ($ip eq "") { print "Warning, could not determine IP number from accounting.log\n"; $ip = $default_ip; } print "Setting \%ip\% = $ip\n"; } # Creates the index.html file $infile = "/$homedir/public_html/$index"; $outfile = "/$homedir/public_html/$index.postwwwacct"; open(IN, "<$infile") or deaderror("Cannot read index.html"); open(OUT, ">$outfile") or deaderror("Cannot open temp file"); while () { s/\%domain\%/$domain/g; s/\%ip\%/$ip/g; print OUT; } close (OUT); close (IN); unlink ($infile); rename ($outfile, $infile); chown ($uid, $gid, $infile); chmod (0644, $infile); if ($inWHM) { print "

"; } print "Default index page written"; if ($inWHM) { print "

"; } print "\n"; exit; sub deaderror { my ($error) = @_; if ($inWHM) { print "
"; } print "$error\n"; if ($inWHM) { print "
\n\n"; } sleep(4); exit; } sub validatedomain { my $domain = shift; # Only alphanumeric chars, dots and hyphens are allowed $domain =~ s/[^\w\.\-]*//g; $domain =~ s/[_]*//g; # This validation is good enough for our purposes return $domain; }