Skip to content

Commit 2f3fbd7

Browse files
committed
fixed #5689 plus some additional clean ups
1 parent 3318f4f commit 2f3fbd7

File tree

2 files changed

+148
-147
lines changed

2 files changed

+148
-147
lines changed

interface/web/sites/web_vhost_domain_edit.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -244,17 +244,17 @@ function onShowEnd() {
244244

245245
if($this->_vhostdomain_type == 'domain') {
246246
if($this->dataRecord['php'] == 'php-fpm' || ($this->dataRecord['php'] == 'hhvm' && $server_type == 'nginx')){
247-
$php_records = $app->db->queryAllRecords("SELECT * FROM server_php WHERE php_fpm_init_script != '' AND php_fpm_ini_dir != '' AND php_fpm_pool_dir != '' AND server_id = ? AND (client_id = 0 OR client_id=?) AND active = 'y'", ($this->id > 0 ? $this->dataRecord['server_id'] : $client['default_webserver']), $_SESSION['s']['user']['client_id']);
247+
$php_records = $app->db->queryAllRecords("SELECT * FROM server_php WHERE php_fpm_init_script != '' AND php_fpm_ini_dir != '' AND php_fpm_pool_dir != '' AND server_id = ? AND (client_id = 0 OR client_id=?) AND active = 'y' ORDER BY server_php.name", ($this->id > 0 ? $this->dataRecord['server_id'] : $client['default_webserver']), $_SESSION['s']['user']['client_id']);
248248
}
249249
if($this->dataRecord['php'] == 'fast-cgi'){
250-
$php_records = $app->db->queryAllRecords("SELECT * FROM server_php WHERE php_fastcgi_binary != '' AND php_fastcgi_ini_dir != '' AND server_id = ? AND (client_id = 0 OR client_id=?) AND active = 'y'", ($this->id > 0 ? $this->dataRecord['server_id'] : $client['default_webserver']), $_SESSION['s']['user']['client_id']);
250+
$php_records = $app->db->queryAllRecords("SELECT * FROM server_php WHERE php_fastcgi_binary != '' AND php_fastcgi_ini_dir != '' AND server_id = ? AND (client_id = 0 OR client_id=?) AND active = 'y' ORDER BY server_php.name", ($this->id > 0 ? $this->dataRecord['server_id'] : $client['default_webserver']), $_SESSION['s']['user']['client_id']);
251251
}
252252
} else {
253253
if($this->dataRecord['php'] == 'php-fpm' || ($this->dataRecord['php'] == 'hhvm' && $server_type == 'nginx')){
254-
$php_records = $app->db->queryAllRecords("SELECT * FROM server_php WHERE php_fpm_init_script != '' AND php_fpm_ini_dir != '' AND php_fpm_pool_dir != '' AND server_id = ? AND (client_id = 0 OR client_id=?) AND active = 'y'", $parent_domain['server_id'], $_SESSION['s']['user']['client_id']);
254+
$php_records = $app->db->queryAllRecords("SELECT * FROM server_php WHERE php_fpm_init_script != '' AND php_fpm_ini_dir != '' AND php_fpm_pool_dir != '' AND server_id = ? AND (client_id = 0 OR client_id=?) AND active = 'y' ORDER BY server_php.name", $parent_domain['server_id'], $_SESSION['s']['user']['client_id']);
255255
}
256256
if($this->dataRecord['php'] == 'fast-cgi'){
257-
$php_records = $app->db->queryAllRecords("SELECT * FROM server_php WHERE php_fastcgi_binary != '' AND php_fastcgi_ini_dir != '' AND server_id = ? AND (client_id = 0 OR client_id=?) AND active = 'y'", $parent_domain['server_id'], $_SESSION['s']['user']['client_id']);
257+
$php_records = $app->db->queryAllRecords("SELECT * FROM server_php WHERE php_fastcgi_binary != '' AND php_fastcgi_ini_dir != '' AND server_id = ? AND (client_id = 0 OR client_id=?) AND active = 'y' ORDER BY server_php.name", $parent_domain['server_id'], $_SESSION['s']['user']['client_id']);
258258
}
259259
}
260260
if (empty($web_config['php_default_hide']) || 'n' === $web_config['php_default_hide']) {

server/lib/classes/cron.d/150-goaccess.inc.php

Lines changed: 144 additions & 143 deletions
Original file line numberDiff line numberDiff line change
@@ -61,185 +61,186 @@ public function onRunJob() {
6161

6262
$web_config = $app->getconf->get_server_config($conf['server_id'], 'web');
6363

64-
$goaccess_conf_locs = array('/etc/goaccess.conf', '/etc/goaccess/goaccess.conf');
65-
$count = 0;
66-
67-
foreach($goaccess_conf_locs as $goa_loc) {
68-
if(is_file($goa_loc) && (filesize($goa_loc) > 0)) {
69-
$goaccess_conf_main = $goa_loc;
70-
break;
71-
} else {
72-
$count++;
73-
if($count == 2) {
74-
$app->log("No GoAccess base config found. Make sure that GoAccess is installed and that the goaccess.conf does exist in /etc or /etc/goaccess", LOGLEVEL_ERROR);
75-
}
76-
}
77-
}
78-
79-
80-
/* Check if goaccess binary is in path/installed */
81-
if($app->system->is_installed('goaccess')) {
82-
83-
foreach($records as $rec) {
84-
$yesterday = date('Ymd', strtotime("-1 day", time()));
85-
86-
$log_folder = 'log';
87-
88-
if($rec['type'] == 'vhostsubdomain' || $rec['type'] == 'vhostalias') {
89-
$tmp = $app->db->queryOneRecord('SELECT `domain` FROM web_domain WHERE domain_id = ?', $rec['parent_domain_id']);
90-
$subdomain_host = preg_replace('/^(.*)\.' . preg_quote($tmp['domain'], '/') . '$/', '$1', $rec['domain']);
91-
if($subdomain_host == '') $subdomain_host = 'web'.$rec['domain_id'];
92-
$log_folder .= '/' . $subdomain_host;
93-
unset($tmp);
94-
}
95-
96-
$logfile = $rec['document_root'].'/' . $log_folder . '/'.$yesterday.'-access.log';
64+
if(is_array($records) && !empty($records)) {
9765

98-
if(!@is_file($logfile)) {
99-
$logfile = $rec['document_root'].'/' . $log_folder . '/'.$yesterday.'-access.log.gz';
100-
if(!@is_file($logfile)) {
101-
continue;
102-
}
103-
}
66+
/* Check if goaccess binary is in path/installed */
67+
if($app->system->is_installed('goaccess')) {
10468

105-
$web_folder = (($rec['type'] == 'vhostsubdomain' || $rec['type'] == 'vhostalias') ? $rec['web_folder'] : 'web');
106-
$domain = $rec['domain'];
107-
$statsdir = $rec['document_root'].'/'.$web_folder.'/stats';
108-
$goaccess_conf = $rec['document_root'].'/log/goaccess.conf';
69+
$goaccess_conf_locs = array('/etc/goaccess.conf', '/etc/goaccess/goaccess.conf');
70+
$count = 0;
10971

110-
/*
111-
In case that you use a different log format, you should use a custom goaccess.conf which you'll have to put into /usr/local/ispconfig/server/conf-custom/.
112-
By default the originally, with GoAccess shipped goaccess.conf from /etc/ or /etc/goaccess will be used along with the log-format value COMBINED.
113-
*/
72+
foreach($goaccess_conf_locs as $goa_loc) {
73+
if(is_file($goa_loc) && (filesize($goa_loc) > 0)) {
74+
$goaccess_conf_main = $goa_loc;
75+
break;
76+
} else {
77+
$count++;
78+
if($count == 2) {
79+
$app->log("No GoAccess base config found. Make sure that GoAccess is installed and that the goaccess.conf does exist in /etc or /etc/goaccess", LOGLEVEL_ERROR);
80+
}
81+
}
82+
}
11483

115-
if(file_exists("/usr/local/ispconfig/server/conf-custom/goaccess.conf.master") && (!file_exists($goaccess_conf))) {
116-
$app->system->copy("/usr/local/ispconfig/server/conf-custom/goaccess.conf.master", $goaccess_conf);
117-
} elseif(!file_exists($goaccess_conf)) {
118-
/*
119-
By default the goaccess.conf should get copied by the webserver plugin but in case it wasn't, or it got deleted by accident we gonna copy it again to the destination dir.
120-
Also there was no /usr/local/ispconfig/server/conf-custom/goaccess.conf.master, so we gonna use /etc/goaccess.conf or /etc/goaccess/goaccess.conf as the base conf.
121-
*/
12284

123-
$app->system->copy($goaccess_conf_main, $goaccess_conf);
124-
$content = $app->system->file_get_contents($goaccess_conf, true);
125-
$content = preg_replace('/^(#)?log-format COMBINED/m', "log-format COMBINED", $content);
126-
$app->system->file_put_contents($goaccess_conf, $content, true);
127-
unset($content);
128-
}
85+
foreach($records as $rec) {
86+
$yesterday = date('Ymd', strtotime("-1 day", time()));
87+
88+
$log_folder = 'log';
89+
90+
if($rec['type'] == 'vhostsubdomain' || $rec['type'] == 'vhostalias') {
91+
$tmp = $app->db->queryOneRecord('SELECT `domain` FROM web_domain WHERE domain_id = ?', $rec['parent_domain_id']);
92+
$subdomain_host = preg_replace('/^(.*)\.' . preg_quote($tmp['domain'], '/') . '$/', '$1', $rec['domain']);
93+
if($subdomain_host == '') $subdomain_host = 'web'.$rec['domain_id'];
94+
$log_folder .= '/' . $subdomain_host;
95+
unset($tmp);
96+
}
12997

130-
/* Update the primary domain name in the title, it could occasionally change */
131-
if(is_file($goaccess_conf) && (filesize($goaccess_conf) > 0)) {
132-
$content = $app->system->file_get_contents($goaccess_conf, true);
133-
$content = preg_replace('/^(#)?html-report-title(.*)/m', "html-report-title $domain", $content);
134-
$app->system->file_put_contents($goaccess_conf, $content, true);
135-
unset($content);
136-
}
98+
$logfile = $rec['document_root'].'/' . $log_folder . '/'.$yesterday.'-access.log';
13799

138-
$username = $rec['system_user'];
139-
$groupname = $rec['system_group'];
140-
$docroot = $rec['document_root'];
100+
if(!@is_file($logfile)) {
101+
$logfile = $rec['document_root'].'/' . $log_folder . '/'.$yesterday.'-access.log.gz';
102+
if(!@is_file($logfile)) {
103+
continue;
104+
}
105+
}
141106

142-
if(!@is_dir($statsdir)) $app->system->mkdirpath($statsdir, 0755, $username, $groupname);
107+
$web_folder = (($rec['type'] == 'vhostsubdomain' || $rec['type'] == 'vhostalias') ? $rec['web_folder'] : 'web');
108+
$domain = $rec['domain'];
109+
$statsdir = $rec['document_root'].'/'.$web_folder.'/stats';
110+
$goaccess_conf = $rec['document_root'].'/log/goaccess.conf';
143111

144-
$goa_db_dir = $docroot.'/'.$web_folder.'/stats/.db/';
145-
$output_html = $docroot.'/'.$web_folder.'/stats/goaindex.html';
146-
if(!@is_dir($goa_db_dir)) $app->system->mkdirpath($goa_db_dir);
147-
148-
if(is_link('/var/log/ispconfig/httpd/'.$domain.'/yesterday-access.log')) $app->system->unlink('/var/log/ispconfig/httpd/'.$domain.'/yesterday-access.log');
149-
$app->system->create_relative_link($logfile, '/var/log/ispconfig/httpd/'.$domain.'/yesterday-access.log');
112+
/*
113+
In case that you use a different log format, you should use a custom goaccess.conf which you'll have to put into /usr/local/ispconfig/server/conf-custom/.
114+
By default the originally, with GoAccess shipped goaccess.conf from /etc/ or /etc/goaccess will be used along with the log-format value COMBINED.
115+
*/
150116

151-
$app->system->exec_safe('chown -R ?:? ?', $username, $groupname, $statsdir);
117+
if(file_exists("/usr/local/ispconfig/server/conf-custom/goaccess.conf.master") && (!file_exists($goaccess_conf))) {
118+
$app->system->copy("/usr/local/ispconfig/server/conf-custom/goaccess.conf.master", $goaccess_conf);
119+
} elseif(!file_exists($goaccess_conf)) {
152120

153-
$goamonth = date("n");
154-
$goayear = date("Y");
121+
/*
122+
By default the goaccess.conf should get copied by the webserver plugin but in case it wasn't, or it got deleted by accident we gonna copy it again to the destination dir.
123+
Also there was no /usr/local/ispconfig/server/conf-custom/goaccess.conf.master, so we gonna use /etc/goaccess.conf or /etc/goaccess/goaccess.conf as the base conf.
124+
*/
155125

156-
if (date("d") == 1) {
157-
$goamonth = date("m")-1;
158-
if (date("m") == 1) {
159-
$goayear = date("Y")-1;
160-
$goamonth = "12";
126+
$app->system->copy($goaccess_conf_main, $goaccess_conf);
127+
$content = $app->system->file_get_contents($goaccess_conf, true);
128+
$content = preg_replace('/^(#)?log-format COMBINED/m', "log-format COMBINED", $content);
129+
$app->system->file_put_contents($goaccess_conf, $content, true);
130+
unset($content);
161131
}
162-
}
163132

164-
if (date("d") == 2) {
165-
$goamonth = date("m")-1;
166-
if (date("m") == 1) {
167-
$goayear = date("Y")-1;
168-
$goamonth = "12";
133+
/* Update the primary domain name in the title, it could occasionally change */
134+
if(is_file($goaccess_conf) && (filesize($goaccess_conf) > 0)) {
135+
$content = $app->system->file_get_contents($goaccess_conf, true);
136+
$content = preg_replace('/^(#)?html-report-title(.*)/m', "html-report-title $domain", $content);
137+
$app->system->file_put_contents($goaccess_conf, $content, true);
138+
unset($content);
169139
}
170140

171-
$statsdirold = $statsdir."/".$goayear."-".$goamonth."/";
141+
$username = $rec['system_user'];
142+
$groupname = $rec['system_group'];
143+
$docroot = $rec['document_root'];
144+
145+
if(!@is_dir($statsdir)) $app->system->mkdirpath($statsdir, 0755, $username, $groupname);
172146

173-
if(!is_dir($statsdirold)) {
174-
$app->system->mkdirpath($statsdirold, 0755, $username, $groupname);
147+
$goa_db_dir = $docroot.'/'.$web_folder.'/stats/.db/';
148+
$output_html = $docroot.'/'.$web_folder.'/stats/goaindex.html';
149+
if(!@is_dir($goa_db_dir)) $app->system->mkdirpath($goa_db_dir);
150+
151+
if(is_link('/var/log/ispconfig/httpd/'.$domain.'/yesterday-access.log')) $app->system->unlink('/var/log/ispconfig/httpd/'.$domain.'/yesterday-access.log');
152+
$app->system->create_relative_link($logfile, '/var/log/ispconfig/httpd/'.$domain.'/yesterday-access.log');
153+
154+
$app->system->exec_safe('chown -R ?:? ?', $username, $groupname, $statsdir);
155+
156+
$goamonth = date("n");
157+
$goayear = date("Y");
158+
159+
if (date("d") == 1) {
160+
$goamonth = date("m")-1;
161+
if (date("m") == 1) {
162+
$goayear = date("Y")-1;
163+
$goamonth = "12";
164+
}
175165
}
176166

177-
// don't rotate db files per month
178-
//rename($goa_db_dir, $statsdirold.'db');
179-
//mkdir($goa_db_dir);
167+
if (date("d") == 2) {
168+
$goamonth = date("m")-1;
169+
if (date("m") == 1) {
170+
$goayear = date("Y")-1;
171+
$goamonth = "12";
172+
}
173+
174+
$statsdirold = $statsdir."/".$goayear."-".$goamonth."/";
175+
176+
if(!is_dir($statsdirold)) {
177+
$app->system->mkdirpath($statsdirold, 0755, $username, $groupname);
178+
}
180179

181-
$app->system->copy($output_html, $statsdirold);
182-
$app->system->unlink($output_html);
180+
// don't rotate db files per month
181+
//rename($goa_db_dir, $statsdirold.'db');
182+
//mkdir($goa_db_dir);
183183

184184

185-
$files = scandir($statsdir);
185+
$files = scandir($statsdir);
186186

187-
foreach ($files as $file) {
188-
if (substr($file, 0, 1) != "." && !is_dir("$statsdir"."/"."$file") && substr($file, 0, 1) != "w" && substr($file, 0, 1) != "i") $app->system->copy("$statsdir"."/"."$file", "$statsdirold"."$file");
187+
foreach ($files as $file) {
188+
if (substr($file, 0, 1) != "." && !is_dir("$statsdir"."/"."$file") && substr($file, 0, 1) != "w" && substr($file, 0, 1) != "i") $app->system->copy("$statsdir"."/"."$file", "$statsdirold"."$file");
189+
}
189190
}
190-
}
191-
192-
// Get the GoAccess version
193-
$match = array();
194191

195-
$goaccess_version = $app->system->system_safe('goaccess --version 2>&1');
192+
// Get the GoAccess version
193+
$match = array();
194+
195+
$goaccess_version = $app->system->system_safe('goaccess --version 2>&1');
196196

197-
if(preg_match('/[0-9]\.[0-9]{1,2}/', $goaccess_version, $match)) {
198-
$goaccess_version = $match[0];
199-
}
197+
if(preg_match('/[0-9]\.[0-9]{1,2}/', $goaccess_version, $match)) {
198+
$goaccess_version = $match[0];
199+
}
200200

201201

202-
/*
203-
* GoAccess removed with 1.4 btree support and supports from this version on only "In-Memory with On-Disk Persitance Storage".
204-
* For versions prior 1.4 you need GoAccess with btree support compiled!
205-
*/
202+
/*
203+
* GoAccess removed with 1.4 btree support and supports from this version on only "In-Memory with On-Disk Persitance Storage".
204+
* For versions prior 1.4 you need GoAccess with btree support compiled!
205+
*/
206206

207-
$cust_lang = $conf['language']."_".strtoupper($conf['language']);
208-
209-
if(version_compare($goaccess_version,1.4) >= 0) {
210-
$app->system->exec_safe("LANG=? goaccess -f ? --config-file ? --restore --persist --db-path=? --output=?", $cust_lang, $logfile, $goaccess_conf, $goa_db_dir, $output_html);
211-
} else {
212-
$output = $app->system->system_safe('goaccess --help 2>&1');
213-
preg_match('/keep-db-files/', $output, $match);
214-
if($match[0] == "keep-db-files") {
215-
$app->system->exec_safe("LANG=? goaccess -f ? --config-file ? --load-from-disk --keep-db-files --db-path=? --output=?", $cust_lang, $logfile, $goaccess_conf, $goa_db_dir, $output_html);
216-
} else {
217-
$app->log("Stats not generated. The GoAccess binary was not compiled with btree support. Please recompile/reinstall GoAccess with btree support, or install GoAccess version >= 1.4!", LOGLEVEL_ERROR);
218-
}
219-
unset($output);
220-
}
221-
unset($cust_lang);
207+
$cust_lang = $conf['language']."_".strtoupper($conf['language']);
222208

223-
if(!is_file($rec['document_root']."/".$web_folder."/stats/index.php")) {
224-
if(file_exists("/usr/local/ispconfig/server/conf-custom/goaccess_index.php.master")) {
225-
$app->system->copy("/usr/local/ispconfig/server/conf-custom/goaccess_index.php.master", $rec['document_root']."/".$web_folder."/stats/index.php");
209+
if(version_compare($goaccess_version,1.4) >= 0) {
210+
$app->system->exec_safe("LANG=? goaccess -f ? --config-file ? --restore --persist --db-path=? --output=?", $cust_lang, $logfile, $goaccess_conf, $goa_db_dir, $output_html);
226211
} else {
227-
$app->system->copy("/usr/local/ispconfig/server/conf/goaccess_index.php.master", $rec['document_root']."/".$web_folder."/stats/index.php");
212+
$output = $app->system->system_safe('goaccess --help 2>&1');
213+
preg_match('/keep-db-files/', $output, $match);
214+
if($match[0] == "keep-db-files") {
215+
$app->system->exec_safe("LANG=? goaccess -f ? --config-file ? --load-from-disk --keep-db-files --db-path=? --output=?", $cust_lang, $logfile, $goaccess_conf, $goa_db_dir, $output_html);
216+
} else {
217+
$app->log("Stats not generated. The GoAccess binary was not compiled with btree support. Please recompile/reinstall GoAccess with btree support, or install GoAccess version >= 1.4!", LOGLEVEL_ERROR);
218+
}
219+
unset($output);
220+
}
221+
unset($cust_lang);
222+
223+
if(!is_file($rec['document_root']."/".$web_folder."/stats/index.php")) {
224+
if(file_exists("/usr/local/ispconfig/server/conf-custom/goaccess_index.php.master")) {
225+
$app->system->copy("/usr/local/ispconfig/server/conf-custom/goaccess_index.php.master", $rec['document_root']."/".$web_folder."/stats/index.php");
226+
} else {
227+
$app->system->copy("/usr/local/ispconfig/server/conf/goaccess_index.php.master", $rec['document_root']."/".$web_folder."/stats/index.php");
228+
}
228229
}
229-
}
230230

231-
$app->log('Created GoAccess statistics for ' . $domain, LOGLEVEL_DEBUG);
232-
if(is_file($rec['document_root']."/".$web_folder."/stats/index.php")) {
233-
$app->system->chown($rec['document_root']."/".$web_folder."/stats/index.php", $rec['system_user']);
234-
$app->system->chgrp($rec['document_root']."/".$web_folder."/stats/index.php", $rec['system_group']);
235-
}
231+
$app->log('Created GoAccess statistics for ' . $domain, LOGLEVEL_DEBUG);
232+
if(is_file($rec['document_root']."/".$web_folder."/stats/index.php")) {
233+
$app->system->chown($rec['document_root']."/".$web_folder."/stats/index.php", $rec['system_user']);
234+
$app->system->chgrp($rec['document_root']."/".$web_folder."/stats/index.php", $rec['system_group']);
235+
}
236236

237-
$app->system->exec_safe('chown -R ?:? ?', $username, $groupname, $statsdir);
237+
$app->system->exec_safe('chown -R ?:? ?', $username, $groupname, $statsdir);
238+
}
239+
} else {
240+
$app->log("Stats not generated. The GoAccess binary couldn't be found. Make sure that GoAccess is installed and that it is in \$PATH", LOGLEVEL_ERROR);
238241
}
239242

240-
} else {
241-
$app->log("Stats not generated. The GoAccess binary couldn't be found. Make sure that GoAccess is installed and that it is in \$PATH", LOGLEVEL_ERROR);
242-
}
243+
}
243244

244245
parent::onRunJob();
245246
}

0 commit comments

Comments
 (0)