From b9a3ef486ebcde18a5ade37865ff8f397185d24f Mon Sep 17 00:00:00 2001 From: Till Brehm <tbrehm@ispconfig.org> Date: Sun, 24 Jul 2016 05:30:59 -0400 Subject: [PATCH] Fixed #3979 Mailbox users unable to save autoresponders --- server/lib/classes/cron.d/150-awstats.inc.php | 32 +++++++++++++++++++++++--------- 1 files changed, 23 insertions(+), 9 deletions(-) diff --git a/server/lib/classes/cron.d/150-awstats.inc.php b/server/lib/classes/cron.d/150-awstats.inc.php index 7c59b57..2d281c7 100644 --- a/server/lib/classes/cron.d/150-awstats.inc.php +++ b/server/lib/classes/cron.d/150-awstats.inc.php @@ -54,8 +54,8 @@ // Create awstats statistics //###################################################################################################### - $sql = "SELECT domain_id, domain, document_root, web_folder, type, system_user, system_group, parent_domain_id FROM web_domain WHERE (type = 'vhost' or type = 'vhostsubdomain') and stats_type = 'awstats' AND server_id = ".$conf['server_id']; - $records = $app->db->queryAllRecords($sql); + $sql = "SELECT domain_id, domain, document_root, web_folder, type, system_user, system_group, parent_domain_id FROM web_domain WHERE (type = 'vhost' or type = 'vhostsubdomain' or type = 'vhostalias') and stats_type = 'awstats' AND server_id = ?"; + $records = $app->db->queryAllRecords($sql, $conf['server_id']); $web_config = $app->getconf->get_server_config($conf['server_id'], 'web'); @@ -64,8 +64,8 @@ $yesterday = date('Ymd', strtotime("-1 day", time())); $log_folder = 'log'; - if($rec['type'] == 'vhostsubdomain') { - $tmp = $app->db->queryOneRecord('SELECT `domain` FROM web_domain WHERE domain_id = '.intval($rec['parent_domain_id'])); + if($rec['type'] == 'vhostsubdomain' || $rec['type'] == 'vhostalias') { + $tmp = $app->db->queryOneRecord('SELECT `domain` FROM web_domain WHERE domain_id = ?', $rec['parent_domain_id']); $subdomain_host = preg_replace('/^(.*)\.' . preg_quote($tmp['domain'], '/') . '$/', '$1', $rec['domain']); if($subdomain_host == '') $subdomain_host = 'web'.$rec['domain_id']; $log_folder .= '/' . $subdomain_host; @@ -78,7 +78,7 @@ continue; } } - $web_folder = ($rec['type'] == 'vhostsubdomain' ? $rec['web_folder'] : 'web'); + $web_folder = (($rec['type'] == 'vhostsubdomain' || $rec['type'] == 'vhostalias') ? $rec['web_folder'] : 'web'); $domain = escapeshellcmd($rec['domain']); $statsdir = escapeshellcmd($rec['document_root'].'/'.$web_folder.'/stats'); $awstats_pl = $web_config['awstats_pl']; @@ -89,8 +89,8 @@ if(is_file($awstats_website_conf_file)) unlink($awstats_website_conf_file); - $sql = "SELECT domain FROM web_domain WHERE (type = 'alias' OR type = 'subdomain') AND parent_domain_id = ".$rec['domain_id']; - $aliases = $app->db->queryAllRecords($sql); + $sql = "SELECT domain FROM web_domain WHERE (type = 'alias' OR type = 'subdomain') AND parent_domain_id = ?"; + $aliases = $app->db->queryAllRecords($sql, $rec['domain_id']); $aliasdomain = ''; if(is_array($aliases)) { @@ -100,14 +100,27 @@ } if(!is_file($awstats_website_conf_file)) { - $awstats_conf_file_content = 'Include "'.$awstats_conf_dir.'/awstats.conf" + if (is_file($awstats_conf_dir."/awstats.conf")) { + $include_file = $awstats_conf_dir."/awstats.conf"; + } elseif (is_file($awstats_conf_dir."/awstats.model.conf")) { + $include_file = $awstats_conf_dir."/awstats.model.conf"; + } + $awstats_conf_file_content = 'Include "'.$include_file.'" LogFile="/var/log/ispconfig/httpd/'.$domain.'/yesterday-access.log" SiteDomain="'.$domain.'" HostAliases="www.'.$domain.' localhost 127.0.0.1'.$aliasdomain.'"'; - file_put_contents($awstats_website_conf_file, $awstats_conf_file_content); + if (isset($include_file)) { + file_put_contents($awstats_website_conf_file, $awstats_conf_file_content); + } else { + $app->log("No awstats base config found. Either awstats.conf or awstats.model.conf must exist in ".$awstats_conf_dir.".", LOGLEVEL_WARN); + } } if(!@is_dir($statsdir)) mkdir($statsdir); + $username = escapeshellcmd($rec['system_user']); + $groupname = escapeshellcmd($rec['system_group']); + chown($statsdir, $username); + chgrp($statsdir, $groupname); if(is_link('/var/log/ispconfig/httpd/'.$domain.'/yesterday-access.log')) unlink('/var/log/ispconfig/httpd/'.$domain.'/yesterday-access.log'); symlink($logfile, '/var/log/ispconfig/httpd/'.$domain.'/yesterday-access.log'); @@ -165,6 +178,7 @@ chgrp($rec['document_root']."/".$web_folder."/stats/index.php", $rec['system_group']); } + exec('chown -R '.$username.':'.$groupname.' '.$statsdir); } -- Gitblit v1.9.1