From bc5c2bb823d4b670a7b69c39b003634eed90a407 Mon Sep 17 00:00:00 2001 From: Daniel Berteaud Date: Tue, 23 Oct 2012 22:56:13 +0200 Subject: [PATCH] First commit --- createlinks | 8 +++ .../defaults/httpd-e-smith/Log2Sql | 1 + .../migrate/ApacheLogSqlPassword | 29 +++++++++++ .../etc/e-smith/sql/init/ApacheLogSql | 1 + .../etc/e-smith/sql/init/ApacheLogSql | 46 +++++++++++++++++ .../conf/httpd.conf/20LoadModule85LogSQL | 29 +++++++++++ smeserver-mod_log_sql.spec | 50 +++++++++++++++++++ 7 files changed, 164 insertions(+) create mode 100644 createlinks create mode 100644 root/etc/e-smith/db/configuration/defaults/httpd-e-smith/Log2Sql create mode 100644 root/etc/e-smith/db/configuration/migrate/ApacheLogSqlPassword create mode 100644 root/etc/e-smith/templates.metadata/etc/e-smith/sql/init/ApacheLogSql create mode 100644 root/etc/e-smith/templates/etc/e-smith/sql/init/ApacheLogSql create mode 100644 root/etc/e-smith/templates/etc/httpd/conf/httpd.conf/20LoadModule85LogSQL create mode 100644 smeserver-mod_log_sql.spec diff --git a/createlinks b/createlinks new file mode 100644 index 0000000..22dcb7f --- /dev/null +++ b/createlinks @@ -0,0 +1,8 @@ +#!/usr/bin/perl -w + +use esmith::Build::CreateLinks qw(:all); + +foreach my $event (qw/bootstrap-console-save webapps-update/){ + templates2events("/etc/e-smith/sql/init/ApacheLogSql", $event); +} + diff --git a/root/etc/e-smith/db/configuration/defaults/httpd-e-smith/Log2Sql b/root/etc/e-smith/db/configuration/defaults/httpd-e-smith/Log2Sql new file mode 100644 index 0000000..86981e6 --- /dev/null +++ b/root/etc/e-smith/db/configuration/defaults/httpd-e-smith/Log2Sql @@ -0,0 +1 @@ +enabled diff --git a/root/etc/e-smith/db/configuration/migrate/ApacheLogSqlPassword b/root/etc/e-smith/db/configuration/migrate/ApacheLogSqlPassword new file mode 100644 index 0000000..b2862a9 --- /dev/null +++ b/root/etc/e-smith/db/configuration/migrate/ApacheLogSqlPassword @@ -0,0 +1,29 @@ +{ + my $rec = $DB->get('httpd-e-smith') + || $DB->new_record('httpd-e-smith', {type => 'service'}); + my $pw = $rec->prop('DbPassword'); + if (not $pw){ + use MIME::Base64 qw(encode_base64); + + $pw = "not set due to error"; + if ( open( RANDOM, "/dev/urandom" ) ){ + my $buf; + # 57 bytes is a full line of Base64 coding, and contains + # 456 bits of randomness - given a perfectly random /dev/random + if ( read( RANDOM, $buf, 57 ) != 57 ){ + warn("Short read from /dev/random: $!"); + } + else{ + $pw = encode_base64($buf); + chomp $pw; + # This module doesn't like / in the password + $pw =~ s|/||g; + } + close RANDOM; + } + else{ + warn "Could not open /dev/urandom: $!"; + } + $rec->set_prop('DbPassword', $pw); + } +} diff --git a/root/etc/e-smith/templates.metadata/etc/e-smith/sql/init/ApacheLogSql b/root/etc/e-smith/templates.metadata/etc/e-smith/sql/init/ApacheLogSql new file mode 100644 index 0000000..940dcf3 --- /dev/null +++ b/root/etc/e-smith/templates.metadata/etc/e-smith/sql/init/ApacheLogSql @@ -0,0 +1 @@ +PERMS=0750 diff --git a/root/etc/e-smith/templates/etc/e-smith/sql/init/ApacheLogSql b/root/etc/e-smith/templates/etc/e-smith/sql/init/ApacheLogSql new file mode 100644 index 0000000..fe62fee --- /dev/null +++ b/root/etc/e-smith/templates/etc/e-smith/sql/init/ApacheLogSql @@ -0,0 +1,46 @@ +{ +my $db = ${'httpd-e-smith'}{'DbName'} || 'http_log'; +my $user = ${'httpd-e-smith'}{'DbUser'} || 'httpd'; +my $pass = ${'httpd-e-smith'}{'DbPassword'} || 'secret'; + +my $dbstruct = `rpm -qd mod_log_sql | grep create_tables.sql`; + +$OUT .= <<"END"; +#! /bin/sh +if [ ! -d /var/lib/mysql/$db ]; then + /usr/bin/mysql -e 'create database $db' + /usr/bin/mysql $db < $dbstruct +fi + +/usr/bin/mysql < +LoadModule log_sql_ssl_module modules/mod_log_sql_ssl.so + + +LogSQLLoginInfo mysql://$dbuser:$dbpass\@$dbhost/$dbname +LogSQLDBParam socketfile /var/lib/mysql/mysql.sock +LogSQLCreateTables on + +LogSQLTransferLogTable access_log +LogSQLTransferLogFormat AbHhmRSsTUuv + +EOF +} +else{ + $OUT .= "# SQL Logging is disabled\n"; +} +} diff --git a/smeserver-mod_log_sql.spec b/smeserver-mod_log_sql.spec new file mode 100644 index 0000000..38d4328 --- /dev/null +++ b/smeserver-mod_log_sql.spec @@ -0,0 +1,50 @@ +%define version 0.1.0 +%define release 1.beta1 +%define name smeserver-mod_log_sql + + +Summary: Apache SQL logging for SME Server +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: mod_log_sql +Requires: smeserver-webapps-common + +%description +Enable apache logging into MySQL + +%changelog +* Tue Oct 23 2012 Daniel Berteaud 0.1.0 +- Initial release + +%prep +%setup -q -n %{name}-%{version} + +%build +perl createlinks + +%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 \ + > %{name}-%{version}-filelist + +echo "%doc CHANGELOG.git" >> %{name}-%{version}-filelist +%files -f %{name}-%{version}-filelist +%defattr(-,root,root) + +%clean +rm -rf $RPM_BUILD_ROOT + +%post +%preun +