/** * Updates an existing file and will chmod it too if required. * @author Bobby Allen (ballen@bobbyallen.me) * @param string $path The path and file name to the file to update. * @param string $chmod Permissions mode to use for the new file. (eg. 0777) * @param string $sting The content to update the file with. * @return boolean */ static function UpdateFile($path, $chmod = 0777, $string = "") { if (!file_exists($path)) { fs_filehandler::ResetFile($path); } $fp = @fopen($path, 'w'); @fwrite($fp, $string); @fclose($fp); fs_director::SetFileSystemPermissions($path, $chmod); return true; }
* Calculate the bandwidth used for each user. */ $checksql = $zdbh->query("SELECT COUNT(*) AS total FROM x_vhosts WHERE vh_deleted_ts IS NULL")->fetch(); echo fs_filehandler::NewLine() . "START Calculating bandwidth usage for all client accounts.." . fs_filehandler::NewLine(); if ($checksql['total'] > 0) { $domainssql = $zdbh->query("SELECT vh_acc_fk, vh_name_vc FROM x_vhosts WHERE vh_deleted_ts IS NULL"); while ($domain = $domainssql->fetch()) { $domainowner = ctrl_users::GetUserDetail($domain['vh_acc_fk']); $bandwidthlog = ctrl_options::GetSystemOption('log_dir') . 'domains/' . $domainowner['username'] . '/' . $domain['vh_name_vc'] . '-bandwidth.log'; $snapshotfile = ctrl_options::GetSystemOption('log_dir') . 'domains/' . $domainowner['username'] . '/' . $domain['vh_name_vc'] . '-snapshot.bw'; $bandwidth = 0; echo "Processing domain \"" . $domain['vh_name_vc'] . "\"" . fs_filehandler::NewLine(); if (fs_director::CheckFileExists($bandwidthlog)) { fs_filehandler::CopyFile($bandwidthlog, $snapshotfile); if (fs_director::CheckFileExists($snapshotfile)) { fs_filehandler::ResetFile($bandwidthlog); echo "Generating bandwidth.. " . fs_filehandler::NewLine(); $bandwidth = sys_bandwidth::CalculateFromApacheLog($snapshotfile); if (file_exists($snapshotfile)) { @unlink($snapshotfile); echo "usage: " . $bandwidth . " (" . fs_director::ShowHumanFileSize($bandwidth) . ")" . fs_filehandler::NewLine(); } } } if (!fs_director::CheckForEmptyValue($bandwidth)) { //$zdbh->query("UPDATE x_bandwidth SET bd_transamount_bi=(bd_transamount_bi+" . $bandwidth . ") WHERE bd_acc_fk = " . $domain['vh_acc_fk'] . " AND bd_month_in = " . date("Ym") . ""); $numrows = $zdbh->prepare("UPDATE x_bandwidth SET bd_transamount_bi=(bd_transamount_bi+:bandwidth) WHERE bd_acc_fk = :vh_acc_fk AND bd_month_in = :date"); $numrows->bindParam(':bandwidth', $bandwidth); $date = date("Ym"); $numrows->bindParam(':date', $date); $numrows->bindParam(':vh_acc_fk', $domain['vh_acc_fk']);