commit 57e28e0efc3cc5d4ade0aab336df93cab23113ee Author: Daniel Berteaud Date: Tue Mar 27 15:00:09 2012 +0200 Initial commit diff --git a/createlinks b/createlinks new file mode 100644 index 0000000..91b9b2c --- /dev/null +++ b/createlinks @@ -0,0 +1,9 @@ +#!/usr/bin/perl -w + +use esmith::Build::CreateLinks qw(:all); + +templates2events("/etc/cron.hourly/awstats", qw(webapps-update bootstrap-console-save domain-create domain-modify domain-delete)); + +foreach my $event (qw/webapps-update bootstrap-console-save domain-create domain-modify domain-delete/){ + event_link("awstats-dir", "$event", "80"); +} diff --git a/ipasserelle-stats.spec b/ipasserelle-stats.spec new file mode 100644 index 0000000..70ac121 --- /dev/null +++ b/ipasserelle-stats.spec @@ -0,0 +1,53 @@ +%define version 0.0.1 +%define release 1.beta0 +%define name ipasserelle-stats + + +Summary: Statistiques web +Name: %{name} +Version: %{version} +Release: %{release}%{?dist} +License: GPL +Group: Networking/Daemons +Source: %{name}-%{version}.tar.gz + +BuildRoot: /var/tmp/%{name}-%{version}-%{release}-buildroot +BuildArchitectures: noarch +BuildRequires: e-smith-devtools + +Requires: ipasserelle-base +Requires: awstats + +%description +Génère des statistique de consultation de vos sites web + +%changelog +* Tue Mar 27 2012 Daniel Berteaud 0.0.1-1.sme +- initial release + + +%prep +%setup -q -n %{name}-%{version} + +%build +perl createlinks +%{__mkdir_p} root/home/e-smith/files/stats/ + +%install +/bin/rm -rf $RPM_BUILD_ROOT +(cd root ; /usr/bin/find . -depth -print | /bin/cpio -dump $RPM_BUILD_ROOT) +/bin/rm -f %{name}-%{version}-filelist +/sbin/e-smith/genfilelist $RPM_BUILD_ROOT \ + --dir /home/e-smith/files/stats/ 'attr(0750,root,www)' \ + > %{name}-%{version}-filelist + +%files -f %{name}-%{version}-filelist +%defattr(-,root,root) + +%clean +rm -rf $RPM_BUILD_ROOT + +%post + +%preun + diff --git a/root/etc/e-smith/db/configuration/defaults/awstats/access b/root/etc/e-smith/db/configuration/defaults/awstats/access new file mode 100644 index 0000000..3e18ebf --- /dev/null +++ b/root/etc/e-smith/db/configuration/defaults/awstats/access @@ -0,0 +1 @@ +private diff --git a/root/etc/e-smith/db/configuration/defaults/awstats/status b/root/etc/e-smith/db/configuration/defaults/awstats/status new file mode 100644 index 0000000..86981e6 --- /dev/null +++ b/root/etc/e-smith/db/configuration/defaults/awstats/status @@ -0,0 +1 @@ +enabled diff --git a/root/etc/e-smith/db/configuration/defaults/awstats/type b/root/etc/e-smith/db/configuration/defaults/awstats/type new file mode 100644 index 0000000..1b93c9e --- /dev/null +++ b/root/etc/e-smith/db/configuration/defaults/awstats/type @@ -0,0 +1 @@ +webapp diff --git a/root/etc/e-smith/events/actions/awstats-dir b/root/etc/e-smith/events/actions/awstats-dir new file mode 100644 index 0000000..42de48d --- /dev/null +++ b/root/etc/e-smith/events/actions/awstats-dir @@ -0,0 +1,37 @@ +#!/usr/bin/perl -w + +use esmith::DomainsDB; +use File::Path qw/rmtree/; + +my $event = $ARGV [0]; +my $domain = $ARGV [1]; +use esmith::DomainsDB; +my $d = esmith::DomainsDB->open_ro or die "Couldn't open DomainsDB\n"; + +die "Event name missing\n" unless defined ($event); + +my @domains = (); +if (defined $domain){ + @domains = $d->get($domain); +} +else{ + @doains = ($d->domains); +} + +foreach my $dom (@domains){ + my $name = $dom->key; + if (($event eq 'domain-delete') ){ + rmtree "/home/e-smith/files/stats/$domain"; + } + else{ + my $stats = $dom->prop('Stats') || 'disabled'; + if (($stats eq 'enabled') && (!-d "/home/e-smith/files/stats/$domain")){ + mkdir "/home/e-smith/files/stats/$domain", 0755; + } + elsif (($stats ne 'enabled') && (-d "/home/e-smith/files/stats/$domain")){ + rmtree "/home/e-smith/files/stats/$domain"; + } + } +} + +exit (0); diff --git a/root/etc/e-smith/events/actions/awstats-init-domain b/root/etc/e-smith/events/actions/awstats-init-domain new file mode 100644 index 0000000..7804c9e --- /dev/null +++ b/root/etc/e-smith/events/actions/awstats-init-domain @@ -0,0 +1,50 @@ +#!/usr/bin/perl -w +#---------------------------------------------------------------------- +# copyright (C) 2012 Firewall-Services +# daniel@firewall-services.com +# +# 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 +#---------------------------------------------------------------------- + +use strict; +use warnings; +use esmith::DomainsDB; +use esmith::ConfigDB; + +my $d = esmith::DomainsDB->open or die "Couldn't open DomainsDB\n"; +my $c = esmith::ConfigDB->open_ro() or die "Couldn't open ConfigDB\n"; + +my $domain = $c->get('DomainName')->value; +my $vhost; + +$vhost = $d->get("stats.$domain"); + +if (!$vhost){ + $d->new_record("stats.$domain",{ + type => 'domain', + Content => 'Primary', + Description => "Statistiques web", + Nameservers => 'internet', + TemplatePath => 'WebAppVirtualHost', + DocumentRoot => '/home/e-smith/files/stats', + LemonLDAP => 'enabled', + Removable => 'yes', + }); + + unless ( system("/sbin/e-smith/signal-event", "domain-create", "stats.$domain") == 0 ){ + die "Failed to create domain stats.$domain\n"; + } +} + diff --git a/root/etc/e-smith/templates/etc/cron.hourly/awstats/10All b/root/etc/e-smith/templates/etc/cron.hourly/awstats/10All new file mode 100644 index 0000000..f71966e --- /dev/null +++ b/root/etc/e-smith/templates/etc/cron.hourly/awstats/10All @@ -0,0 +1,12 @@ +{ +use esmith::DomainsDB; +my $d = esmith::DomainsDB->open_ro or die "Couldn't open DomainsDB\n"; + +foreach my $dom ($d->domains){ + my $stats = $dom->prop('Stats') || 'disabled'; + next if ($stats ne 'enabled'); + my $name = $dom->key; + my $lang = $awstats{'Language'} || 'fr'; + $OUT .= "/usr/share/awstats/tools/awstats_buildstaticpages.pl -config=$name -update -lang=$lang -dir=/var/lib/stats/$name\n"; +} +} diff --git a/root/etc/e-smith/templates/etc/httpd/conf/httpd.conf/98awstats b/root/etc/e-smith/templates/etc/httpd/conf/httpd.conf/98awstats new file mode 100644 index 0000000..c5fa621 --- /dev/null +++ b/root/etc/e-smith/templates/etc/httpd/conf/httpd.conf/98awstats @@ -0,0 +1,63 @@ +{ +use esmith::DomainsDB; +my $d = esmith::DomainsDB->open_ro or die "Couldn't open DomainsDB\n"; + +my $status = $awstats{'status'} || 'disabled'; +my $access = $awstats{'access'} || 'private'; + +if ($status ne 'enabled'){ + $OUT .= "# AWStats is disabled\n"; +} +else{ + my $allow = ($status eq 'public') ? 'all':"$localAccess $externalSSLAccess"; + $OUT .=<<"EOF"; + +Alias /awstatsclasses "/usr/share/awstats/wwwroot/classes/" +Alias /awstatscss "/usr/share/awstats/wwwroot/css/" +Alias /awstatsicons "/usr/share/awstats/wwwroot/icon/" + + + Options None + AllowOverride None + Order deny,allow + Deny from all + Allow from $allow + + + Deny from all + + + SetEnv PERL5LIB /usr/share/awstats/lib:/usr/share/awstats/plugins + + + + Options None + Options +Indexes + Order deny,allow + Deny from all + Allow from $allow + SSLRequireSSL on + + +foreach my $dom ($d->domains){ + my $stats = $dom->prop('Stats') || 'disabled'; + next unless ($stats eq 'enabled'); + my $name = $dom->key; + my @users = split /[;,]/, ($dom->prop('StatsUsers') || ''); + foreach my $u (@users){ + $OUT .= " SetEnvIf Auth-User \"$u\" allow_$name\n"; + } + my $allowfromenv = (scalar @users > 0) ? "allow from env=allow_$name":''; + $OUT .=<<"HERE"; + + + DirectoryIndex awstats.$name.html + $allowfromenv + + +HERE +} + +EOF +} +} diff --git a/root/etc/e-smith/templates/var/lib/lemonldap-ng/conf/lmConf/070awstats b/root/etc/e-smith/templates/var/lib/lemonldap-ng/conf/lmConf/070awstats new file mode 100644 index 0000000..3fb8a84 --- /dev/null +++ b/root/etc/e-smith/templates/var/lib/lemonldap-ng/conf/lmConf/070awstats @@ -0,0 +1,28 @@ +{ + +$conf->{'exportedHeaders'}->{"stats.$domain"} = { + 'Auth-User' => '$uid', +} unless ($conf->{'exportedHeaders'}->{"stats.$domain"}); + + +$conf->{'locationRules'}->{"stats.$domain"} = { + 'default' => '$groups =~ /\\badmins\\b/', +} unless ($conf->{'locationRules'}->{"stats.$domain"}); + + +$conf->{'applicationList'}->{'030admin'}->{'awstats'} = { + 'options' => { + 'logo' => 'network.png', + 'name' => 'Statistiques web', + 'description' => 'AWStats', + 'uri' => "https://stats.$domain", + 'display' => 'auto' + }, + 'type' => 'application' +} unless ($conf->{'applicationList'}->{'030admin'}->{'awstats'}); + + +$OUT = ''; + +} +