First commit

master
Daniel Berteaud 12 years ago
commit bc5c2bb823
  1. 8
      createlinks
  2. 1
      root/etc/e-smith/db/configuration/defaults/httpd-e-smith/Log2Sql
  3. 29
      root/etc/e-smith/db/configuration/migrate/ApacheLogSqlPassword
  4. 1
      root/etc/e-smith/templates.metadata/etc/e-smith/sql/init/ApacheLogSql
  5. 46
      root/etc/e-smith/templates/etc/e-smith/sql/init/ApacheLogSql
  6. 29
      root/etc/e-smith/templates/etc/httpd/conf/httpd.conf/20LoadModule85LogSQL
  7. 50
      smeserver-mod_log_sql.spec

@ -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);
}

@ -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);
}
}

@ -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 <<EOF
USE mysql;
REPLACE INTO user (
host,
user,
password)
VALUES (
'localhost',
'$user',
PASSWORD ('$pass'));
REPLACE INTO db (
host,
db,
user,
select_priv, insert_priv, update_priv, delete_priv,
create_priv, alter_priv, index_priv, drop_priv, create_tmp_table_priv,
grant_priv, lock_tables_priv, references_priv)
VALUES (
'localhost',
'$db',
'$user',
'Y', 'Y', 'Y', 'Y',
'Y', 'Y', 'Y', 'Y', 'Y',
'N', 'Y', 'Y');
FLUSH PRIVILEGES;
EOF
END
}

@ -0,0 +1,29 @@
{
my $status = ${'httpd-e-smith'}{'Log2Sql'} || 'disabled';
if ($status =~ m/^enabled|on|1|yes$/i){
my $dbname = ${'httpd-e-smith'}{'DbName'} || 'http_log';
my $dbuser = ${'httpd-e-smith'}{'DbUser'} || 'httpd';
my $dbpass = ${'httpd-e-smith'}{'DbPassword'} || 'secret';
my $dbhost = ${'httpd-e-smith'}{'DbHost'} || 'localhost';
$OUT .=<<"EOF";
LoadModule log_sql_module modules/mod_log_sql.so
LoadModule log_sql_mysql_module modules/mod_log_sql_mysql.so
<IfModule mod_ssl.c>
LoadModule log_sql_ssl_module modules/mod_log_sql_ssl.so
</IfModule>
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";
}
}

@ -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 <daniel@firewall-services.com> 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
Loading…
Cancel
Save