|
Server : Apache/2.4.62 System : FreeBSD fbsdweb2.web.rcn.net 14.1-RELEASE FreeBSD 14.1-RELEASE releng/14.1-n267679-10e31f0946d8 GENERIC amd64 User : www ( 80) PHP Version : 8.3.8 Disable Function : NONE Directory : /config/ |
Upload File : |
#!/usr/bin/perl
use NDBM_File;
use Fcntl;
use strict;
my $domain_path = '/domains/';
open(LOG,">>/config/log.txt");
print LOG "opened log\n";
my $mtime = (stat('/vhost_dbm.db'))[9];
my %DB;
tie (%DB, 'NDBM_File', "/vhost_dbm" ,O_RDONLY, 0644) or die 'Cannot open file for read?' ;
while(<>)
{
next unless m/daemon.info/;
s/(.*)pound: //;
my ($vhost) = split;
s/^(\S+) //;
my ($user) = vhost_to_user($vhost);
my ($sec,$min,$hour,$day,$month,$year,$wday,$yday) = (localtime())[0..7];
$month++; $year+=1900;
my ($file) = sprintf "ex%04d%02d%02d.log" , $year,$month,$day;
unless ( -d "$domain_path${user}/logs/" )
{
mkdir "$domain_path${user}/logs/" || warn " bad";
}
open(FILE,">>$domain_path${user}/logs/$file");
print FILE $_;
close(FILE);
# print LOG "wrote to log\n";
}
close (LOG);
sub vhost_to_user($)
{
my ($vhost) = lc(shift);
$vhost =~ s/:80$//;
# my $new_mtime = (stat('/vhost_dbm.db'))[9];
# if($new_mtime != $mtime)
# {
# reopen();
# $mtime = $new_mtime;
# print LOG "reopened DB file";
# }
my ($username) = $DB{$vhost};
print LOG "can not find [$vhost] -> [$username]\n" unless $username;
return $username;
}
sub reopen()
{
untie %DB if defined %DB;
tie (%DB, 'NDBM_File', "/vhost_dbm" ,O_RDONLY, 0644) or die 'Cannot open file for read?' ;
}