@@ -61,183 +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 */
81- system ("type goaccess 2>&1>/dev/null " , $ retval );
82- if ($ retval === 0 ) {
83-
84- foreach ($ records as $ rec ) {
85- $ yesterday = date ('Ymd ' , strtotime ("-1 day " , time ()));
86-
87- $ log_folder = 'log ' ;
88-
89- if ($ rec ['type ' ] == 'vhostsubdomain ' || $ rec ['type ' ] == 'vhostalias ' ) {
90- $ tmp = $ app ->db ->queryOneRecord ('SELECT `domain` FROM web_domain WHERE domain_id = ? ' , $ rec ['parent_domain_id ' ]);
91- $ subdomain_host = preg_replace ('/^(.*)\. ' . preg_quote ($ tmp ['domain ' ], '/ ' ) . '$/ ' , '$1 ' , $ rec ['domain ' ]);
92- if ($ subdomain_host == '' ) $ subdomain_host = 'web ' .$ rec ['domain_id ' ];
93- $ log_folder .= '/ ' . $ subdomain_host ;
94- unset($ tmp );
95- }
64+ if (is_array ($ records ) && !empty ($ records )) {
9665
97- $ logfile = $ rec ['document_root ' ].'/ ' . $ log_folder . '/ ' .$ yesterday .'-access.log ' ;
66+ /* Check if goaccess binary is in path/installed */
67+ if ($ app ->system ->is_installed ('goaccess ' )) {
9868
99- if (!@is_file ($ logfile )) {
100- $ logfile = $ rec ['document_root ' ].'/ ' . $ log_folder . '/ ' .$ yesterday .'-access.log.gz ' ;
101- if (!@is_file ($ logfile )) {
102- continue ;
69+ $ goaccess_conf_locs = array ('/etc/goaccess.conf ' , '/etc/goaccess/goaccess.conf ' );
70+ $ count = 0 ;
71+
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+ }
83+
84+
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 );
10396 }
104- }
10597
106- $ web_folder = (($ rec ['type ' ] == 'vhostsubdomain ' || $ rec ['type ' ] == 'vhostalias ' ) ? $ rec ['web_folder ' ] : 'web ' );
107- $ domain = $ rec ['domain ' ];
108- $ statsdir = $ rec ['document_root ' ].'/ ' .$ web_folder .'/stats ' ;
109- $ goaccess_conf = $ rec ['document_root ' ].'/log/goaccess.conf ' ;
98+ $ logfile = $ rec ['document_root ' ].'/ ' . $ log_folder . '/ ' .$ yesterday .'-access.log ' ;
99+
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+ }
110106
111- /*
112- 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/.
113- By default the originally, with GoAccess shipped goaccess.conf from /etc/ or /etc/goaccess will be used along with the log-format value COMBINED.
114- */
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 ' ;
115111
116- if (file_exists ("/usr/local/ispconfig/server/conf-custom/goaccess.conf.master " ) && (!file_exists ($ goaccess_conf ))) {
117- $ app ->system ->copy ("/usr/local/ispconfig/server/conf-custom/goaccess.conf.master " , $ goaccess_conf );
118- } elseif (!file_exists ($ goaccess_conf )) {
119112 /*
120- 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 .
121- Also there was no /usr/local/ispconfig/server/conf-custom/ goaccess.conf.master, so we gonna use /etc/goaccess.conf as the base conf.
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.
122115 */
123116
124- $ app ->system ->copy ($ goaccess_conf_main , $ goaccess_conf );
125- $ content = $ app ->system ->file_get_contents ($ goaccess_conf , true );
126- $ content = preg_replace ('/^(#)?log-format COMBINED/m ' , "log-format COMBINED " , $ content );
127- $ app ->system ->file_put_contents ($ goaccess_conf , $ content , true );
128- unset($ content );
129- }
130-
131- /* Update the primary domain name in the title, it could occasionally change */
132- if (is_file ($ goaccess_conf ) && (filesize ($ goaccess_conf ) > 0 )) {
133- $ content = $ app ->system ->file_get_contents ($ goaccess_conf , true );
134- $ content = preg_replace ('/^(#)?html-report-title(.*)/m ' , "html-report-title $ domain " , $ content );
135- $ app ->system ->file_put_contents ($ goaccess_conf , $ content , true );
136- unset($ content );
137- }
138-
139- $ username = $ rec ['system_user ' ];
140- $ groupname = $ rec ['system_group ' ];
141- $ docroot = $ rec ['document_root ' ];
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 )) {
142120
143- if (!@is_dir ($ statsdir )) $ app ->system ->mkdirpath ($ statsdir , 0755 , $ username , $ groupname );
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+ */
144125
145- $ goa_db_dir = $ docroot . ' / ' . $ web_folder . ' /stats/.db/ ' ;
146- $ output_html = $ docroot . ' / ' . $ web_folder . ' /stats/goaindex.html ' ;
147- if (!@ is_dir ( $ goa_db_dir )) $ app -> system -> mkdirpath ( $ goa_db_dir );
148-
149- if ( is_link ( ' /var/log/ispconfig/httpd/ ' . $ domain . ' /yesterday-access.log ' )) $ app -> system -> unlink ( ' /var/log/ispconfig/httpd/ ' . $ domain . ' /yesterday-access.log ' );
150- symlink ( $ logfile , ' /var/log/ispconfig/httpd/ ' . $ domain . ' /yesterday-access.log ' );
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 );
131+ }
151132
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 );
139+ }
152140
153- $ app ->system ->exec_safe ('chown -R ?:? ? ' , $ username , $ groupname , $ statsdir );
141+ $ username = $ rec ['system_user ' ];
142+ $ groupname = $ rec ['system_group ' ];
143+ $ docroot = $ rec ['document_root ' ];
154144
155- $ goamonth = date ("n " );
156- $ goayear = date ("Y " );
145+ if (!@is_dir ($ statsdir )) $ app ->system ->mkdirpath ($ statsdir , 0755 , $ username , $ groupname );
157146
158- if (date ("d " ) == 1 ) {
159- $ goamonth = date ("m " )-1 ;
160- if (date ("m " ) == 1 ) {
161- $ goayear = date ("Y " )-1 ;
162- $ goamonth = "12 " ;
163- }
164- }
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 ' );
165152
166- if (date ("d " ) == 2 ) {
167- $ goamonth = date ("m " )-1 ;
168- if (date ("m " ) == 1 ) {
169- $ goayear = date ("Y " )-1 ;
170- $ goamonth = "12 " ;
153+ symlink ($ logfile , '/var/log/ispconfig/httpd/ ' .$ domain .'/yesterday-access.log ' );
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+ }
171165 }
172166
173- $ statsdirold = $ statsdir ."/ " .$ goayear ."- " .$ goamonth ."/ " ;
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+ }
174179
175- if (! is_dir ( $ statsdirold )) {
176- $ app -> system -> mkdirpath ( $ statsdirold , 0755 , $ username , $ groupname );
177- }
180+ // don't rotate db files per month
181+ //rename($goa_db_dir, $statsdirold.'db' );
182+ //mkdir($goa_db_dir);
178183
179- // don't rotate db files per month
180- //rename($goa_db_dir, $statsdirold.'db');
181- //mkdir($goa_db_dir);
182184
183- $ files = scandir ($ statsdir );
185+ $ files = scandir ($ statsdir );
184186
185- foreach ($ files as $ file ) {
186- 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+ }
187190 }
188- }
189-
190- // Get the GoAccess version
191- $ match = array ();
192191
193- $ 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 ' );
194196
195- if (preg_match ('/[0-9]\.[0-9]{1,2}/ ' , $ goaccess_version , $ match )) {
196- $ goaccess_version = $ match [0 ];
197- }
197+ if (preg_match ('/[0-9]\.[0-9]{1,2}/ ' , $ goaccess_version , $ match )) {
198+ $ goaccess_version = $ match [0 ];
199+ }
198200
199201
200- /*
201- * GoAccess removed with 1.4 btree support and supports from this version on only "In-Memory with On-Disk Persitance Storage".
202- * For versions prior 1.4 you need GoAccess with btree support compiled!
203- */
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+ */
204206
205- $ cust_lang = $ conf ['language ' ]."_ " .strtoupper ($ conf ['language ' ]);
206-
207- if (version_compare ($ goaccess_version ,1.4 ) >= 0 ) {
208- $ app ->system ->exec_safe ("LANG=? goaccess -f ? --config-file ? --restore --persist --db-path=? --output=? " , $ cust_lang , $ logfile , $ goaccess_conf , $ goa_db_dir , $ output_html );
209- } else {
210- $ output = $ app ->system ->system_safe ('goaccess --help 2>&1 ' );
211- preg_match ('/keep-db-files/ ' , $ output , $ match );
212- if ($ match [0 ] == "keep-db-files " ) {
213- $ 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 );
214- } else {
215- $ 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 );
216- }
217- unset($ output );
218- }
219- unset($ cust_lang );
207+ $ cust_lang = $ conf ['language ' ]."_ " .strtoupper ($ conf ['language ' ]);
220208
221- if (!is_file ($ rec ['document_root ' ]."/ " .$ web_folder ."/stats/index.php " )) {
222- if (file_exists ("/usr/local/ispconfig/server/conf-custom/goaccess_index.php.master " )) {
223- $ 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 );
224211 } else {
225- $ 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+ }
226229 }
227- }
228230
229- $ app ->log ('Created GoAccess statistics for ' . $ domain , LOGLEVEL_DEBUG );
230- if (is_file ($ rec ['document_root ' ]."/ " .$ web_folder ."/stats/index.php " )) {
231- chown ($ rec ['document_root ' ]."/ " .$ web_folder ."/stats/index.php " , $ rec ['system_user ' ]);
232- chgrp ($ rec ['document_root ' ]."/ " .$ web_folder ."/stats/index.php " , $ rec ['system_group ' ]);
233- }
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+ }
234236
235- $ 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 );
236241 }
237242
238- } else {
239- $ 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 );
240- }
243+ }
241244
242245 parent ::onRunJob ();
243246 }
0 commit comments