/** * Create or modify the AWStats configuration file for the given domain. * Modified by Berend Dekens to allow custom configurations. * * @param logFile * @param siteDomain * @param hostAliases * @return null */ function createAWStatsConf($logFile, $siteDomain, $hostAliases, $customerDocroot, $awstats_params = array()) { global $pathtophpfiles, $settings; // Generation header $header = "## GENERATED BY FROXLOR\n"; $header2 = "## Do not remove the line above! This tells Froxlor to update this configuration\n## If you wish to manually change this configuration file, remove the first line to make sure Froxlor won't rebuild this file\n## Generated for domain {SITE_DOMAIN} on " . date('l dS \\of F Y h:i:s A') . "\n"; $awstats_dir = makeCorrectDir($customerDocroot . '/awstats/' . $siteDomain . '/'); if (!is_dir($awstats_dir)) { safe_exec('mkdir -p ' . escapeshellarg($awstats_dir)); } // chown created folder, #258 makeChownWithNewStats($awstats_params); // weird but could happen... if (!is_dir($settings['system']['awstats_conf'])) { safe_exec('mkdir -p ' . escapeshellarg($settings['system']['awstats_conf'])); } // These are the variables we will replace $regex = array('/\\{LOG_FILE\\}/', '/\\{SITE_DOMAIN\\}/', '/\\{HOST_ALIASES\\}/', '/\\{CUSTOMER_DOCROOT\\}/', '/\\{AWSTATS_CONF\\}/'); $replace = array(makeCorrectFile($logFile), $siteDomain, $hostAliases, $awstats_dir, makeCorrectDir($settings['system']['awstats_conf'])); // File names $domain_file = makeCorrectFile($settings['system']['awstats_conf'] . '/awstats.' . $siteDomain . '.conf'); $model_file = dirname(dirname(dirname(dirname(__FILE__)))); $model_file .= '/templates/misc/awstatsmodel/'; if ($settings['system']['mod_log_sql'] == '1') { $model_file .= 'awstats.froxlor.model_log_sql.conf'; } else { $model_file .= 'awstats.froxlor.model.conf'; } $model_file = makeCorrectFile($model_file); // Test if the file exists if (file_exists($domain_file)) { // Check for the generated header - if this is a manual modification we won't update $awstats_domain_conf = fopen($domain_file, 'r'); if (fgets($awstats_domain_conf, strlen($header)) != $header) { fclose($awstats_domain_conf); return; } // Close the file fclose($awstats_domain_conf); } $awstats_domain_conf = fopen($domain_file, 'w'); $awstats_model_conf = fopen($model_file, 'r'); // Write the header fwrite($awstats_domain_conf, $header); fwrite($awstats_domain_conf, preg_replace($regex, $replace, $header2)); // Write the configuration file while (($line = fgets($awstats_model_conf, 4096)) !== false) { if (!preg_match('/^#/', $line) && trim($line) != '') { fwrite($awstats_domain_conf, preg_replace($regex, $replace, $line)); } } fclose($awstats_domain_conf); fclose($awstats_model_conf); }
$httptraffic += floatval(callWebalizerGetTraffic($row['loginname'] . '-' . $domain, $row['documentroot'] . '/webalizer/' . $domain . '/', $domain, $domainlist[$row['customerid']])); } } } reset($domainlist[$row['customerid']]); // callAwstatsGetTraffic is called ONLY HERE and // *not* also in the special-logfiles-loop, because the function // will iterate through all customer-domains and the awstats-configs // know the logfile-name, #246 if (Settings::Get('system.awstats_enabled') == '1') { $httptraffic += floatval(callAwstatsGetTraffic($row['customerid'], $row['documentroot'] . '/awstats/', $domainlist[$row['customerid']])); } else { $httptraffic += floatval(callWebalizerGetTraffic($row['loginname'], $row['documentroot'] . '/webalizer/', $caption, $domainlist[$row['customerid']])); } // make the stuff readable for the customer, #258 makeChownWithNewStats($row); } /** * FTP-Traffic */ fwrite($debugHandler, 'ftp traffic for ' . $row['loginname'] . ' started...' . "\n"); $ftptraffic_stmt = Database::prepare("\n\t\tSELECT SUM(`up_bytes`) AS `up_bytes_sum`, SUM(`down_bytes`) AS `down_bytes_sum`\n\t\tFROM `" . TABLE_FTP_USERS . "` WHERE `customerid` = :customerid\n\t"); $ftptraffic = Database::pexecute_first($ftptraffic_stmt, array('customerid' => $row['customerid'])); if (!is_array($ftptraffic)) { $ftptraffic = array('up_bytes_sum' => 0, 'down_bytes_sum' => 0); } $upd_stmt = Database::prepare("\n\t\tUPDATE `" . TABLE_FTP_USERS . "` SET `up_bytes` = '0', `down_bytes` = '0' WHERE `customerid` = :customerid\n\t"); Database::pexecute($upd_stmt, array('customerid' => $row['customerid'])); /** * Mail-Traffic */