diff --git a/.gitattributes b/.gitattributes
index 980512b4..41737229 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -241,6 +241,8 @@ bureau/admin/js/prototype.js -text
bureau/admin/login.php -text
bureau/admin/logo.png -text
bureau/admin/logo2.png -text
+bureau/admin/logs_download.php -text
+bureau/admin/logs_list.php -text
bureau/admin/mail_add.php -text
bureau/admin/mail_alias_create.inc.php -text
bureau/admin/mail_alias_doedit.php -text
@@ -336,6 +338,7 @@ bureau/class/m_export.php -text
bureau/class/m_ftp.php -text
bureau/class/m_hooks.php -text
bureau/class/m_hta.php -text
+bureau/class/m_log.php -text
bureau/class/m_mail.php -text
bureau/class/m_mail_alias.php -text
bureau/class/m_mail_jabber.php -text
@@ -410,6 +413,7 @@ etc/alternc/alternc-sudoers -text
etc/alternc/alternc.ini -text
etc/alternc/apache2-ssl.conf -text
etc/alternc/apache2.conf -text
+etc/alternc/apache_logformat.conf -text
etc/alternc/dbusers.cnf.sample -text
etc/alternc/functions_hosting/hosting_massvhost.sh -text
etc/alternc/menulist.txt -text
@@ -503,8 +507,10 @@ src/alternc-check -text
src/alternc-dboptimize -text
src/alternc-passwd -text
src/alternc_reload -text
+src/compress_logs.sh -text
src/cron_users.sh -text
src/cron_users_doit.sh -text
+src/delete_logs.sh -text
src/du.pl -text
src/export_account.php -text
src/fixperms.sh -text
diff --git a/bureau/admin/logs_download.php b/bureau/admin/logs_download.php
new file mode 100644
index 00000000..f8ec3397
--- /dev/null
+++ b/bureau/admin/logs_download.php
@@ -0,0 +1,42 @@
+ array ("request", "string", ""),
+);
+getFields($fields);
+
+if (empty($file)) {
+$error="";
+}
+
+$log->download_link($file);
+?>
diff --git a/bureau/admin/logs_list.php b/bureau/admin/logs_list.php
new file mode 100644
index 00000000..b7500b65
--- /dev/null
+++ b/bureau/admin/logs_list.php
@@ -0,0 +1,68 @@
+list_logs_directory_all($log->get_logs_directory());
+?>
+
+
+
+$error";
+}
+if(!$list || empty($list)){
+ echo ""._("You have no sql logs to list a the moment.")."
";
+}
+?>
+
+ | | | |
+";
+while (list($key,$val)=each($list)){
+ $col=3-$col;
+ foreach($val as $k => $v){
+ ?>
+
+ |
+ |
+ |
+ "._("Download")."";?> |
+
+
+
+
diff --git a/bureau/class/functions.php b/bureau/class/functions.php
index 8bbb9c0b..3ebb3269 100644
--- a/bureau/class/functions.php
+++ b/bureau/class/functions.php
@@ -35,6 +35,11 @@ mt_srand((float) $sec + ((float) $usec * 100000));
/* Format a field value for input or textarea : */
function fl($str) { return str_replace("<","<",str_replace("\"",""",$str)); }
+// Use of m_log
+function compare_logname($a, $b) {
+ return strcmp($a['name'],$b['name']);
+}
+
/*
Check if a domain can be hosted on this server :
Return a negative value in case of an error,
diff --git a/bureau/class/m_log.php b/bureau/class/m_log.php
new file mode 100644
index 00000000..56ec19a4
--- /dev/null
+++ b/bureau/class/m_log.php
@@ -0,0 +1,100 @@
+Cette classe gère les logs utilisasteurs
+*
+* Copyleft {@link http://alternc.net/ AlternC Team}
+*
+* @copyright AlternC-Team 2002-11-01 http://alternc.net/
+*/
+
+
+class m_log {
+
+ function m_log(){
+ }
+
+ function list_logs_directory($dir){
+ global $cuid,$err;
+ $err->log("log","list_logs_directory");
+
+ $dir2=$dir;
+ if ($dir = @opendir($dir)) {
+ while (($file = readdir($dir)) !== false) {
+ if ($file!="." && $file!=".." && realpath($dir2 . "/" . $file) == $dir2 . "/" . $file){
+ $absfile=$dir2."/".$file;
+ $c[]=array("name"=>$file,
+ "creation_date"=>date("F d Y H:i:s.", filectime($absfile)),
+ "filesize"=>filesize($absfile),
+ "downlink"=>"logs_download.php?file=".urlencode($file),
+ );
+ }
+ }
+ closedir($dir);
+ }
+ usort($c,"compare_logname");
+ return $c;
+
+ }//list_logs
+
+ function list_logs_directory_all($dirs){
+ global $err;
+ $err->log("log","get_logs_directory_all");
+ $c=array();
+ foreach($dirs as $dir=>$val){
+ $c[$dir]=$this->list_logs_directory($val);
+ }
+ return $c;
+
+ }
+
+ function get_logs_directory(){
+ global $cuid,$db,$err;
+ $err->log("log","get_logs_directory");
+
+ $db->query("select login from membres where uid=$cuid ;");
+ if ($db->num_rows()==0) {
+ $err->raise("log",1);
+ return false;
+ }
+ $db->next_record();
+ $c=array("dir"=>"/var/alternc/logs/".$cuid."-".$db->f("login"));
+ return $c;
+ }
+
+ function download_link($file){
+ global $err,$mem;
+ $err->log("log","download_link");
+ header("Content-Disposition: attachment; filename=".$mem->user["login"].".zip");
+ header("Content-Type: application/force-download");
+ header("Content-Transfer-Encoding: binary");
+ $f=$this->get_logs_directory();
+ $ff=$f['dir']."/".basename($file);
+ set_time_limit(0);
+ readfile($ff);
+ }
+
+
+} // end class
+
diff --git a/debian/alternc.cron.d b/debian/alternc.cron.d
index 305c9aea..cb4d358e 100644
--- a/debian/alternc.cron.d
+++ b/debian/alternc.cron.d
@@ -1,6 +1,12 @@
# Every day at 4am, produce raw statistics
0 4 * * * root /usr/lib/alternc/rawstat.daily
+# Every 2 days compress log files
+0 4 * * * root /usr/lib/alternc/compress_logs.sh
+
+# Suppress log files older than one year
+0 4 * * * root /usr/lib/alternc/delete_logs.sh
+
# Every day at 5am and every week at 4am, make requested SQL backups
0 5 * * * www-data /usr/lib/alternc/sqlbackup.sh -t daily
0 4 * * 0 www-data /usr/lib/alternc/sqlbackup.sh -t weekly
diff --git a/debian/alternc.dirs b/debian/alternc.dirs
index 8abe90df..66fcff55 100644
--- a/debian/alternc.dirs
+++ b/debian/alternc.dirs
@@ -102,6 +102,7 @@ var/alternc/mail/z
var/alternc/mla
var/alternc/sessions
var/alternc/tmp
+var/alternc/logs
var/backups/alternc
var/log/alternc
var/run/alternc
diff --git a/debian/control b/debian/control
index daf3f2fe..7d1510e6 100644
--- a/debian/control
+++ b/debian/control
@@ -10,8 +10,8 @@ Standards-Version: 3.9.1
Package: alternc
Architecture: all
Pre-depends: debconf (>= 0.5.00) | debconf-2.0
-Depends: debianutils (>= 1.13.1), apache2-mpm-itk, libapache2-mod-php5, php5-mysql, phpmyadmin, postfix, proftpd-mod-mysql, proftpd-basic, squirrelmail, squirrelmail-locales, bind9, wget, rsync, quota, ca-certificates, locales, perl-suid, perl, postfix-mysql, wwwconfig-common, sasl2-bin, fam | gamin, libsasl2-modules, php5-cli, lockfile-progs (>= 0.1.9), gettext (>= 0.10.40-5), sudo, adduser, mysql-client, dnsutils, bash, acl, dovecot-common (>= 1:1.2.15), dovecot-imapd, dovecot-pop3d
-Recommends: mysql-server(>= 5.0), dovecot-managesieved, dovecot-sieve, dovecot-mysql
+Depends: debianutils (>= 1.13.1), apache2-mpm-itk, libapache2-mod-php5, php5-mysql, phpmyadmin, postfix, proftpd-mod-mysql, proftpd-basic, squirrelmail, squirrelmail-locales, bind9, wget, rsync, quota, ca-certificates, locales, perl-suid, perl, postfix-mysql, wwwconfig-common, sasl2-bin, fam | gamin, libsasl2-modules, php5-cli, lockfile-progs (>= 0.1.9), gettext (>= 0.10.40-5), sudo, adduser, mysql-client, dnsutils, bash, acl, dovecot-common (>= 1:1.2.15), dovecot-imapd, dovecot-pop3d,vlogger
+Recommends: mysql-server(>= 5.0), dovecot-managesieved, dovecot-sieve, dovecot-mysql, ntpdate
Conflicts: alternc-admintools, alternc-awstats (< 1.0), alternc-webalizer (<= 0.9.4), alternc-mailman (< 2.0), courier-authdaemon
Provides: alternc-admintools
Replaces: alternc-admintools
diff --git a/debian/rules b/debian/rules
index ff694624..fd0d18f5 100755
--- a/debian/rules
+++ b/debian/rules
@@ -71,6 +71,9 @@ install: build
done ;\
done
+ #log directory
+ mkdir -p debian/alternc/var/alternc/logs
+ chown alterncpanel:alterncpanel debian/alternc/var/alternc/logs
# Group and user 1999 reference alterncpanel
chown 1999:1999 debian/alternc/var/alternc/html/*
diff --git a/etc/alternc/apache_logformat.conf b/etc/alternc/apache_logformat.conf
new file mode 100644
index 00000000..c4bd50a1
--- /dev/null
+++ b/etc/alternc/apache_logformat.conf
@@ -0,0 +1,5 @@
+LogFormat "%{LOGIN}e %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" alternc
+CustomLog "|| /usr/sbin/vlogger -u alterncpanel -g alterncpanel -s access.log /var/alternc/logs" alternc
+
+#Uncomment the following line to active Buffered Logs (Default: Off)
+#BufferedLogs On
diff --git a/etc/alternc/templates/apache2/panel.conf b/etc/alternc/templates/apache2/panel.conf
index 5e686f4a..24418c91 100644
--- a/etc/alternc/templates/apache2/panel.conf
+++ b/etc/alternc/templates/apache2/panel.conf
@@ -7,7 +7,4 @@
alias /alternc-sql /usr/share/phpmyadmin
alias /webmail /usr/share/squirrelmail
-
- LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %T %{Host}i" alternc
- CustomLog /var/log/apache2/access.log alternc
diff --git a/etc/alternc/templates/apache2/url.conf b/etc/alternc/templates/apache2/url.conf
index 69754bf2..ed7e5830 100644
--- a/etc/alternc/templates/apache2/url.conf
+++ b/etc/alternc/templates/apache2/url.conf
@@ -7,6 +7,4 @@
RewriteEngine On
RewriteRule ^/(.*)$ %%redirect%%/$1 [R=301,L]
- LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %T %{Host}i" alternc
- CustomLog /var/log/apache2/access.log alternc
diff --git a/etc/alternc/templates/apache2/vhost.conf b/etc/alternc/templates/apache2/vhost.conf
index 5b80eb9d..5a40cf65 100644
--- a/etc/alternc/templates/apache2/vhost.conf
+++ b/etc/alternc/templates/apache2/vhost.conf
@@ -1,7 +1,8 @@
ServerName %%fqdn%%
DocumentRoot "%%document_root%%"
- AssignUserId #%%UID%% #%%GID%%
+ AssignUserId #%%UID%% #%%GID%%
+ SetEnv LOGIN "%%UID%%-%%LOGIN%%"
php_admin_value open_basedir "%%account_root%%:/usr/share/php/:/var/alternc/tmp:/tmp"
@@ -11,6 +12,5 @@
AllowOverride AuthConfig FileInfo Limit Options Indexes
- LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %T %{Host}i" alternc
- CustomLog /var/log/apache2/access.log alternc
+
diff --git a/etc/alternc/templates/apache2/webmail.conf b/etc/alternc/templates/apache2/webmail.conf
index a10f44b0..a92ea8b2 100644
--- a/etc/alternc/templates/apache2/webmail.conf
+++ b/etc/alternc/templates/apache2/webmail.conf
@@ -9,6 +9,4 @@
Options Indexes FollowSymLinks
- LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %T %{Host}i" alternc
- CustomLog /var/log/apache2/access.log alternc
diff --git a/src/Makefile b/src/Makefile
index 8ad557f6..be2707c2 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -26,7 +26,7 @@
# ----------------------------------------------------------------------
#
SETUID=mail_add mail_del quota_edit quota_get mem_add mem_del du.pl
-SCRIPTS=sqlbackup.sh rawstat.daily quota_init quota_delete update_domains.sh slave_dns sendmail spoolsize.php fixperms.sh alternc-dboptimize export_account.php cron_users_doit.sh cron_users.sh
+SCRIPTS=sqlbackup.sh rawstat.daily quota_init quota_delete update_domains.sh slave_dns sendmail spoolsize.php fixperms.sh alternc-dboptimize export_account.php cron_users_doit.sh cron_users.sh compress_logs.sh delete_logs.sh
LIBS=functions.sh functions_hosting.sh functions_dns.sh
BIN=$(DESTDIR)/usr/lib/alternc/
diff --git a/src/compress_logs.sh b/src/compress_logs.sh
new file mode 100644
index 00000000..cd4f6dcd
--- /dev/null
+++ b/src/compress_logs.sh
@@ -0,0 +1,16 @@
+#! /bin/bash
+
+for CONFIG_FILE in \
+ /etc/alternc/local.sh \
+ /usr/lib/alternc/functions.sh
+ do
+ if [ ! -r "$CONFIG_FILE" ]; then
+ echo "Can't access $CONFIG_FILE."
+ exit 1
+ fi
+ . "$CONFIG_FILE"
+done
+$days=2
+#parcourir tous les logs pour trouver ceux qui on plus de 2 jours et en faire un tar.
+find "$ALTERNC_LOC/logs" -not -name '*.gz' -mtime +$days -exec gzip '{}' \;
+
diff --git a/src/delete_logs.sh b/src/delete_logs.sh
new file mode 100644
index 00000000..44abd316
--- /dev/null
+++ b/src/delete_logs.sh
@@ -0,0 +1,15 @@
+#!/bin/bash
+
+for CONFIG_FILE in \
+ /etc/alternc/local.sh \
+ /usr/lib/alternc/functions.sh
+ do
+ if [ ! -r "$CONFIG_FILE" ]; then
+ echo "Can't access $CONFIG_FILE."
+ exit 1
+ fi
+ . "$CONFIG_FILE"
+done
+days=366
+#parcourir tous les logs pour trouver ceux qui on plus de 1 ans et les deletes.
+find "$ALTERNC_LOC/logs" -mtime +$days -exec rm '{}' \;
diff --git a/src/functions_hosting.sh b/src/functions_hosting.sh
index 4968618a..3cfc569a 100644
--- a/src/functions_hosting.sh
+++ b/src/functions_hosting.sh
@@ -93,6 +93,7 @@ host_create() {
# Put the good value in the conf file
sed -i \
+ -e "s#%%LOGIN%%#$USER#g" \
-e "s#%%fqdn%%#$FQDN2#g" \
-e "s#%%document_root%%#$DOCUMENT_ROOT2#g" \
-e "s#%%account_root%%#$ACCOUNT_ROOT2#g" \
diff --git a/src/update_domains.sh b/src/update_domains.sh
index 279c8105..05216584 100644
--- a/src/update_domains.sh
+++ b/src/update_domains.sh
@@ -19,6 +19,7 @@ umask 022
LOCK_FILE="$ALTERNC_LOC/bureau/cron.lock"
OLDIFS="$IFS"
NEWIFS=" "
+LOGFORMAT_FILE="/etc/alternc/apache_logformat.conf"
RELOAD_ZONES="$(mktemp /tmp/alternc_reload_zones.XXXX)"
RELOAD_WEB="$(mktemp /tmp/alternc_reload_web.XXXX)"
DNS_DO_RESTART="/tmp/alternc.do_do_restart.$$"
@@ -117,13 +118,26 @@ do
echo -n " $dom " >> "$RELOAD_ZONES"
done
-
if [ ! -z "$(cat "$RELOAD_WEB")" ] ; then
echo " apache " >> "$RELOAD_ZONES"
# Concat the apaches files
tempo=$(mktemp "$VHOST_FILE.XXXXX")
- find "$VHOST_DIR" -mindepth 2 -type f -iname "*.conf" -print0 | xargs -0 cat > "$tempo"
+
+ (
+ echo "###BEGIN OF ALTERNC AUTO-GENERATED FILE - DO NOT EDIT MANUALLY###"
+ # If exists and readable, include conf file "apache_logformat.conf"
+ # contain LogFormat and CustomLog directives for our Vhosts)
+ echo "## LogFormat informations"
+ if [ ! -r "$LOGFORMAT_FILE" ] ; then
+ echo "## Warning : Cannot read $LOGFORMAT_FILE"
+ else
+ echo "Include \"$LOGFORMAT_FILE\""
+ fi
+ find "$VHOST_DIR" -mindepth 2 -type f -iname "*.conf" -print0 | xargs -0 cat
+ echo "###END OF ALTERNC AUTO-GENERATED FILE - DO NOT EDIT MANUALLY###"
+ ) > "$tempo"
+
if [ $? -ne 0 ] ; then
log_error " web file concatenation failed"
fi