[vhffs-dev] [1986] removed Vhffs::Functions::hash_webdir() |
[ Thread Index |
Date Index
| More vhffs.org/vhffs-dev Archives
]
Revision: 1986
Author: gradator
Date: 2012-02-01 23:50:39 +0100 (Wed, 01 Feb 2012)
Log Message:
-----------
removed Vhffs::Functions::hash_webdir()
Modified Paths:
--------------
trunk/vhffs-api/src/Vhffs/Functions.pm
trunk/vhffs-api/src/Vhffs/Services/Web.pm
trunk/vhffs-robots/src/web_stats.pl
trunk/vhffs-tools/src/vhffs-webstats
Modified: trunk/vhffs-api/src/Vhffs/Functions.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Functions.pm 2012-01-31 23:12:01 UTC (rev 1985)
+++ trunk/vhffs-api/src/Vhffs/Functions.pm 2012-02-01 22:50:39 UTC (rev 1986)
@@ -62,17 +62,6 @@
return 0;
}
-sub hash_webdir
-{
- use Digest::MD5 qw(md5 md5_hex md5_base64);
- my $servername = shift;
- my $hash = md5_hex( $servername );
- my $webdir = substr( $hash , 0 , 2 ) . "/" . substr( $hash , 2 , 2 ) . "/" .substr( $hash , 4 , 2 ) . "/" .$servername;
-
- return $webdir;
-
-}
-
sub create_dir
{
my $dir = shift;
Modified: trunk/vhffs-api/src/Vhffs/Services/Web.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Services/Web.pm 2012-01-31 23:12:01 UTC (rev 1985)
+++ trunk/vhffs-api/src/Vhffs/Services/Web.pm 2012-02-01 22:50:39 UTC (rev 1986)
@@ -143,9 +143,24 @@
my $self = shift;
require Digest::MD5;
my $hash = Digest::MD5::md5_hex( $self->{'servername'} );
- return $self->{main}->get_config->get_datadir.'/web/'.substr( $hash, 0, 2 ).'/'.substr( $hash, 2, 2 ).'/'.substr( $hash, 4, 2 ).'/'.$self->{'servername'};
+ return $self->{main}->get_config->get_datadir.'/web/'.$self->get_hash();
}
+=head2 get_hash
+
+ my $dir = $httpd->get_hash;
+
+Same as get_dir, but only return the hashed part.
+
+=cut
+
+sub get_hash {
+ my $self = shift;
+ require Digest::MD5;
+ my $hash = Digest::MD5::md5_hex( $self->{'servername'} );
+ return substr( $hash, 0, 2 ).'/'.substr( $hash, 2, 2 ).'/'.substr( $hash, 4, 2 ).'/'.$self->{'servername'};
+}
+
=head2 get_label
See C<Vhffs::Object::get_label>.
Modified: trunk/vhffs-robots/src/web_stats.pl
===================================================================
--- trunk/vhffs-robots/src/web_stats.pl 2012-01-31 23:12:01 UTC (rev 1985)
+++ trunk/vhffs-robots/src/web_stats.pl 2012-02-01 22:50:39 UTC (rev 1986)
@@ -74,10 +74,8 @@
Vhffs::Robots::lock( $vhffs , "webstats" );
my %websites;
-foreach my $ws ( @{$webs} ) {
- $websites{$ws->get_servername}{'servername'} = $ws->get_servername;
- $websites{$ws->get_servername}{'owner_uid'} = $ws->get_owner_uid;
- $websites{$ws->get_servername}{'owner_gid'} = $ws->get_owner_gid;
+foreach ( @{$webs} ) {
+ $websites{$_->get_servername} = $_;
}
my @webservers;
@@ -134,35 +132,32 @@
# Parse http logs
-my %logs;
-my $line;
-my $svname;
-my $log;
my $prev = "";
open( MERGEDIN , "< ".$log_incoming_root."/mergedlog" );
open( REJECTOUT, "> ".$log_incoming_root."/rejectlog" );
-while( $line = <MERGEDIN> ) {
- if( ( $svname , $log ) = ( $line =~ /([a-zA-Z0-9\.\-]+)\s(.+)/g) ) {
+while( my $line = <MERGEDIN> ) {
+ if( my ( $svname , $log ) = ( $line =~ /([a-zA-Z0-9\.\-]+)\s(.+)/g) ) {
# Discard www
$svname =~ s/^www\.//;
- # We are _NOT_ hosting this website
- if( ! exists $websites{$svname} ) {
+ my $web = $websites{$svname};
- print REJECTOUT $svname." ".$log."\n";
+ # We are _NOT_ hosting this website
+ unless( $web ) {
+ print REJECTOUT $svname.' '.$log."\n";
}
# We host this website
else {
# the website changed
if ( $prev ne $svname ) {
- my $dir = $log_parsed_root."/".Vhffs::Functions::hash_webdir( $svname )."/logs";
+ my $dir = $log_parsed_root.'/'.$web->get_hash;
unless( -d $dir ) {
Vhffs::Functions::create_dir($dir);
- chown( $websites{$svname}{'owner_uid'} , $websites{$svname}{'owner_gid'} , $dir );
+ chown( $web->get_owner_uid, $web->get_owner_gid, $dir );
chmod( 0770 , $dir );
}
@@ -184,11 +179,11 @@
# Create a configuration file and generate statistic for each website
-foreach ( @{$webs} )
+foreach my $web ( @{$webs} )
{
- my $svname = $_->get_servername;
+ my $svname = $web->get_servername;
- my $weblogdir = $log_parsed_root."/".Vhffs::Functions::hash_webdir( $svname );
+ my $weblogdir = $log_parsed_root.'/'.$web->get_hash;
my $logpath = $weblogdir."/logs/access.log";
my $datadir = $weblogdir."/awstats";
my $conffile = $datadir."/awstats.".$svname.".conf";
@@ -198,7 +193,7 @@
next if ( ! -f $logpath );
unless( -d $datadir ) {
Vhffs::Functions::create_dir($datadir);
- chown( $websites{$svname}{'owner_uid'} , $websites{$svname}{'owner_gid'} , $datadir );
+ chown( $web->get_owner_uid, $web->get_owner_gid, $datadir );
chmod( 0775 , $datadir );
}
@@ -206,7 +201,7 @@
open( AWFILEIN , "< ".$awstats_sample );
open( AWFILEOUT , "> ".$conffile );
- while( $line = <AWFILEIN> )
+ while( my $line = <AWFILEIN> )
{
$line =~ s/MY_DOMAINNAME/$svname/g;
$line =~ s/MY_LOGPATH/$logpath/g;
Modified: trunk/vhffs-tools/src/vhffs-webstats
===================================================================
--- trunk/vhffs-tools/src/vhffs-webstats 2012-01-31 23:12:01 UTC (rev 1985)
+++ trunk/vhffs-tools/src/vhffs-webstats 2012-02-01 22:50:39 UTC (rev 1986)
@@ -53,7 +53,7 @@
foreach ( @{$webs} )
{
my $svname = $_->get_servername;
- my $awstatsdir = $log_parsed_root.'/'.Vhffs::Functions::hash_webdir( $svname ).'/awstats';
+ my $awstatsdir = $log_parsed_root.'/'.$_->get_hash.'/awstats';
next unless -d $awstatsdir;
my ( $pages , $hits , $bandwidth, $visits );