本文整理汇总了PHP中unix::compress方法的典型用法代码示例。如果您正苦于以下问题:PHP unix::compress方法的具体用法?PHP unix::compress怎么用?PHP unix::compress使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类unix
的用法示例。
在下文中一共展示了unix::compress方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: subdomains
function subdomains()
{
$subdomains = "https://ransomwaretracker.abuse.ch/downloads/RW_DOMBL.txt";
$MAIN = unserialize(@file_get_contents("/root/ransomwaretracker.db"));
$curl = new ccurl($subdomains);
if ($curl->GetFile("/root/RW_DOMBL.txt")) {
$f = explode("\n", @file_get_contents("/root/RW_DOMBL.txt"));
while (list($index, $line) = each($f)) {
$line = trim($line);
if (substr($line, 0, 1) == "#") {
continue;
}
$MAIN["DOMAINS"][$line] = true;
}
} else {
echo "{$subdomains} failed\n";
}
$ips = "https://ransomwaretracker.abuse.ch/downloads/RW_IPBL.txt";
$curl = new ccurl($ips);
if ($curl->GetFile("/root/RW_IPBL.txt")) {
$f = explode("\n", @file_get_contents("/root/RW_IPBL.txt"));
while (list($index, $line) = each($f)) {
$line = trim($line);
if (substr($line, 0, 1) == "#") {
continue;
}
$MAIN["IPS"][$line] = true;
}
} else {
echo "{$ips} failed\n";
}
$uris = "https://ransomwaretracker.abuse.ch/downloads/RW_URLBL.txt";
$curl = new ccurl($uris);
if ($curl->GetFile("/root/RW_URLBL.txt")) {
$f = explode("\n", @file_get_contents("/root/RW_URLBL.txt"));
while (list($index, $line) = each($f)) {
$line = trim($line);
if (substr($line, 0, 1) == "#") {
continue;
}
$MAIN["URIS"][$line] = true;
}
} else {
echo "{$uris} failed\n";
}
$MAIN2["TIME"] = time();
$MAIN2["MD5"] = md5(serialize($MAIN));
@file_put_contents("/root/ransomwaretracker.db", serialize($MAIN));
@file_put_contents("/root/ransomwaretracker.txt", serialize($MAIN2));
$unix = new unix();
$unix->compress("/root/ransomwaretracker.db", "/root/ransomwaretracker.gz");
PushToRepo("/root/ransomwaretracker.txt");
PushToRepo("/root/ransomwaretracker.gz");
}
示例2: export
function export()
{
$workdir = dirname(__FILE__) . "/ressources/squid-export";
if (!is_dir($workdir)) {
@mkdir($workdir, 0777, true);
}
if (!($handle = opendir("/etc/artica-postfix/settings/Daemons"))) {
@mkdir("/etc/artica-postfix/settings/Daemons", 0755, true);
die;
}
while (false !== ($filename = readdir($handle))) {
if ($filename == ".") {
continue;
}
if ($filename == "..") {
continue;
}
$targetFile = "/etc/artica-postfix/settings/Daemons/{$filename}";
if ($GLOBALS["VERBOSE"]) {
echo "Exporting {$filename}\n";
}
$array[$filename] = @file_get_contents($targetFile);
}
if ($GLOBALS["VERBOSE"]) {
echo count($array) . " items....\n";
}
$finalitems = base64_encode(serialize($array));
$unix = new unix();
$tmpf = $unix->FILE_TEMP();
@file_put_contents($tmpf, $finalitems);
if ($GLOBALS["VERBOSE"]) {
echo "compressing in {$workdir}/settingsHD.gz\n";
}
if (!$unix->compress($tmpf, "{$workdir}/settingsHD.gz")) {
@unlink("{$workdir}/settingsHD.gz");
}
@chmod("{$workdir}/settingsHD.gz", 0777);
@unlink($tmpf);
if ($GLOBALS["VERBOSE"]) {
echo "compressing in {$workdir}/settingsHD.gz done\n";
}
}
示例3: compress_debug
function compress_debug()
{
$unix = new unix();
$sourcefile = "/var/log/artica-wifidog.log";
$destfile = "/usr/share/artica-postfix/ressources/logs/web/hotspot.debug.gz";
@unlink($destfile);
$unix = new unix();
$unix->compress($sourcefile, $destfile);
@chmod($destfile, 0777);
}
示例4: import_backup_file
function import_backup_file($filepath)
{
if ($GLOBALS["VERBOSE"]) {
echo "Import {$filepath}\n";
}
$dirname = dirname($filepath);
$filename = basename($filepath);
$filecontent = $dirname . "/" . str_replace(".email", ".msg", $filename);
if (!is_file($filecontent)) {
echo "{$filecontent} no such file\n";
@unlink($filepath);
return true;
}
$last_modified = filemtime($filepath);
//$FinalLog="$Subject|||$Sender|||$recipt|||$body_hash|||$body_length||$rententiontime";
$F = explode("|||", @file_get_contents($filepath));
print_r($F);
if (count($F) < 5) {
echo "Truncated file index : {$filepath} !\n";
return false;
}
$q = new postgres_sql();
$zdate = date("Y-m-d H:i:s", $last_modified);
$subject = str_replace("'", "`", $F[0]);
$mailfrom = $F[1];
$mailfrom = str_replace("<", "", $mailfrom);
$mailfrom = str_replace(">", "", $mailfrom);
$mailfromz = explode("@", $mailfrom);
$domainfrom = $mailfromz[1];
$mailto_line = $F[2];
$hash = $F[3];
$retentiontime = $F[5];
$filesize = @filesize($filecontent);
$msgmd5 = md5_file($filecontent);
$final = strtotime("+{$retentiontime} minutes", $last_modified);
$prefix = "INSERT INTO backupmsg (zdate,final,msgmd5,size,subject,mailfrom,mailto,domainfrom,domainto ) VALUES ";
$mailsTo_array = explode(";", $mailto_line);
$f = array();
while (list($a, $mailto) = each($mailsTo_array)) {
$mailto = trim(strtolower($mailto));
$mailto = str_replace("<", "", $mailto);
$mailto = str_replace(">", "", $mailto);
if ($mailto == null) {
continue;
}
$mailtoz = explode("@", $mailto);
$domainto = $mailtoz[1];
$f[] = "('{$zdate}','{$final}','{$msgmd5}','{$filesize}','{$subject}','{$mailfrom}','{$mailto}','{$domainfrom}','{$domainto}')";
}
if (count($f) == 0) {
echo "No... count(f)=0\n";
@unlink($filepath);
@unlink($filecontent);
return false;
}
$final_sql = $prefix . " " . @implode(",", $f);
$q->QUERY_SQL($final_sql);
if (!$q->ok) {
echo $q->mysql_error . "\n{$final_sql}\n";
echo "No... PostgreSQL error\n";
return false;
}
$filecontent_gz = "{$filecontent}.gz";
$unix = new unix();
if (!$unix->compress($filecontent, $filecontent_gz)) {
@unlink($filecontent_gz);
echo "No... Compress error\n";
return;
}
@chmod($filecontent_gz, 0777);
$q->QUERY_SQL("INSERT INTO backupdata (zdate,msgmd5,final,contentid) VALUES ('{$zdate}','{$msgmd5}','{$final}',lo_import('{$filecontent_gz}') ) ON CONFLICT DO NOTHING");
if (!$q->ok) {
echo $q->mysql_error . "\n";
echo "No... PostgreSQL error\n";
return false;
}
$unix->ToSyslog("from=<{$mailfrom}> [{$subject}] {$filepath} success to backup");
echo "{$filepath} (success)\n{$filecontent} (success)\n";
@unlink($filepath);
@unlink($filecontent);
@unlink($filecontent_gz);
return true;
}
示例5: backup
function backup()
{
build_progress_idb("{backup_database}", 20);
$unix = new unix();
$targetFilename = "/home/ArticaStatsBackup/backup.db";
$su = $unix->find_program("su");
@mkdir("/home/ArticaStatsBackup", 0777, true);
@chmod("/home/ArticaStatsBackup", 0777);
if (is_file($targetFilename)) {
@unlink($targetFilename);
}
$InFluxBackupDatabaseDir = @file_get_contents("/etc/artica-postfix/settings/Daemons/InFluxBackupDatabaseDir");
if ($InFluxBackupDatabaseDir == null) {
$InFluxBackupDatabaseDir = "/home/artica/influx/backup";
}
$CompressFileName = "{$InFluxBackupDatabaseDir}/snapshot." . date("Y-m-d-H-i") . ".gz";
@mkdir($InFluxBackupDatabaseDir, 0755, true);
if (is_file($CompressFileName)) {
build_progress_idb("{backup_database} already exists", 110);
}
$cmdline = "{$su} -c \"/usr/local/ArticaStats/bin/pg_dumpall -c --if-exists -S ArticaStats -f {$targetFilename} -h /var/run/ArticaStats\" ArticaStats";
echo $cmdline . "\n";
exec($cmdline, $results);
build_progress_idb("{backup_database}", 30);
if (!is_file($targetFilename)) {
echo "{$targetFilename} No such file\n";
while (list($num, $val) = each($results)) {
echo "{$val}\n";
}
build_progress_idb("{backup_database} {failed}", 110);
return;
}
build_progress_idb("{compressing}", 50);
echo "Compress {$targetFilename}\n";
echo "Destination {$CompressFileName}\n";
if (!$unix->compress($targetFilename, $CompressFileName)) {
build_progress_idb("{compressing} {failed}", 110);
squid_admin_mysql(0, "Snaphost BigData database {failed} ( compress )", null, __FILE__, __LINE__);
@unlink($targetFilename);
@unlink($CompressFileName);
return;
}
@unlink($targetFilename);
$size = FormatBytes(@filesize($CompressFileName) / 1024);
squid_admin_mysql(2, "Backup [" . basename($CompressFileName) . "] BigData database ({$size}) done", null, __FILE__, __LINE__);
build_progress_idb("{scanning}", 80);
ScanBackup();
build_progress_idb("{backup_database} {success}", 100);
}
示例6: range_fichier_source
function range_fichier_source($filepath, $BackupMaxDaysDir, $EXTERN = false)
{
$syslog = new mysql_storelogs();
$unix = new unix();
$ext = $unix->file_extension($filepath);
$hostname = $unix->hostname_g();
$sock = new sockets();
$LogRotatePath = $sock->GET_INFO("LogRotatePath");
if ($LogRotatePath == null) {
$LogRotatePath = "/home/logrotate";
}
$LogRotateAccess = "{$LogRotatePath}/access";
$LogRotateAccessFailed = "{$LogRotatePath}/failed";
$LogRotateAccessMerged = "{$LogRotatePath}/merged";
$SquidRotateMergeFiles = $sock->GET_INFO("SquidRotateMergeFiles");
if (!is_numeric($SquidRotateMergeFiles)) {
$SquidRotateMergeFiles = 1;
}
$LogsRotateDeleteSize = intval($sock->GET_INFO("LogsRotateDeleteSize"));
if ($LogsRotateDeleteSize == 0) {
$LogsRotateDeleteSize = 5000;
}
$basename = basename($filepath);
if ($basename == "access.merged.log") {
return;
}
$syslog->events("Analyze {$filepath} [{$ext}] ", __FUNCTION__, __LINE__);
if ($ext == "gz") {
if (preg_match("#\\.tar\\.gz\$#", $basename)) {
$syslog->events("{$filepath} is a tarball!", __FUNCTION__, __LINE__);
return;
}
$syslog->events("Extract {$filepath}", __FUNCTION__, __LINE__);
$ExtractedFile = "{$LogRotateAccess}/{$basename}.log";
if (!$unix->uncompress($filepath, $ExtractedFile)) {
@unlink($ExtractedFile);
$syslog->events("Unable to extract {$filepath} to {$ExtractedFile}", __FUNCTION__, __LINE__);
return;
}
$syslog->events("Removing {$filepath} [{$ext}] ", __FUNCTION__, __LINE__);
@unlink($filepath);
$filepath = $ExtractedFile;
}
$unix = new unix();
$ztimes = access_logs_getdates($filepath);
if (!$ztimes) {
$syslog->events("Failed to parse {$filepath}", __FUNCTION__, __LINE__);
@mkdir($LogRotateAccessFailed, 0755, true);
if (@copy($filepath, "{$LogRotateAccessFailed}/{$basename}")) {
@unlink($filepath);
}
return false;
}
$xdatefrom = $ztimes[0];
$xdateTo = $ztimes[1];
$dateFrom = date("Y-m-d_H-i-s", $xdatefrom);
$dateTo = date("Y-m-d_H-i-s", $xdateTo);
$NewFileName = filename_from_arraydates($ztimes);
if ($SquidRotateMergeFiles == 1) {
@mkdir($LogRotateAccessMerged, 0755, true);
if (!is_dir($LogRotateAccessMerged)) {
$syslog->events("Unable to create Merged directory {$LogRotateAccessMerged}", __FUNCTION__, __LINE__);
} else {
if (!@copy($filepath, "{$LogRotateAccessMerged}/{$basename}")) {
@unlink("{$LogRotateAccessMerged}/{$basename}");
$syslog->events("Unable to copy {$filepath} -> {$LogRotateAccessMerged}/{$basename}", __FUNCTION__, __LINE__);
}
}
}
$FinalDirectory = "{$BackupMaxDaysDir}/proxy/" . date("Y", $xdatefrom) . "/" . date("m", $xdatefrom) . "/" . date("d", $xdatefrom);
@mkdir($FinalDirectory, 0755, true);
if (!is_dir($FinalDirectory)) {
$syslog->events("Unable to create {$FinalDirectory} directory permission denied", __FUNCTION__, __LINE__);
return;
}
if (!$unix->compress($filepath, "{$FinalDirectory}/{$NewFileName}")) {
@unlink("{$FinalDirectory}/{$NewFileName}");
$syslog->events("Unable to compress {$FinalDirectory}/{$NewFileName} permission denied", __FUNCTION__, __LINE__);
return;
}
$syslog->events("Success to create {$FinalDirectory}/{$NewFileName}", __FUNCTION__, __LINE__);
$syslog->events("Removing source file {$filepath}", __FUNCTION__, __LINE__);
@unlink($filepath);
}
示例7: GetIndex
//.........这里部分代码省略.........
continue;
}
if ($categoryname == "redirector") {
continue;
}
if ($categoryname == "ads") {
continue;
}
if ($categoryname == "drogue") {
continue;
}
$MyStoreMd5 = md5_file($TargetFile);
if ($MyStoreMd5 == $md5) {
echo "Skipping {$filename}\n";
continue;
}
echo "Downloading {$filename}\n";
$curl = new ccurl("{$mainuri}/{$filename}");
$tmpfile = $unix->FILE_TEMP();
if (!$curl->GetFile($tmpfile)) {
echo "Failed {$curl->error}\n";
@unlink($tmpfile);
continue;
}
$md5_tmp = md5_file($tmpfile);
if ($md5_tmp != $md5) {
echo "Failed Corrupted file\n";
@unlink($tmpfile);
continue;
}
if (is_file($TargetFile)) {
@unlink($TargetFile);
}
if (!@copy($tmpfile, $TargetFile)) {
echo "Failed Copy file\n";
@unlink($tmpfile);
@unlink($TargetFile);
continue;
}
@unlink($tmpfile);
$MyStoreMd5 = md5_file($TargetFile);
if ($MyStoreMd5 != $md5) {
echo "Failed MD5 file\n";
@unlink($TargetFile);
continue;
}
@mkdir("{$WORKING_DIR}/{$categoryname}", 0755, true);
echo "Extracting {$TargetFile}\n";
$cmd = "{$tar} xvf {$TargetFile} -C {$WORKING_DIR}/{$categoryname}/";
echo $cmd . "\n";
system($cmd);
$SOURCE_DIR = find_sources("{$WORKING_DIR}/{$categoryname}");
if (!is_file("{$SOURCE_DIR}/domains")) {
echo "Failed {$SOURCE_DIR}/domains no such file\n";
@unlink($TargetFile);
continue;
}
$COUNT_OF_DOMAINS = $unix->COUNT_LINES_OF_FILE("{$SOURCE_DIR}/domains");
echo "{$categoryname} {$COUNT_OF_DOMAINS} domains\n";
if ($COUNT_OF_DOMAINS == 0) {
shell_exec("{$rm} -rf {$WORKING_DIR}/{$categoryname}");
@unlink($TargetFile);
continue;
}
if (is_file("{$SOURCE_DIR}/domains.ufdb")) {
@unlink("{$SOURCE_DIR}/domains.ufdb");
}
if (!is_file("{$SOURCE_DIR}/urls")) {
@touch("{$SOURCE_DIR}/urls");
}
$u = " -u {$SOURCE_DIR}/urls";
$d = " -d {$SOURCE_DIR}/domains";
$cmd = "{$EXEC_NICE}{$ufdbGenTable} -n -q -W -t {$categoryname}{$d}{$u}";
echo $cmd . "\n";
shell_exec($cmd);
if (!is_file("{$SOURCE_DIR}/domains.ufdb")) {
echo "Failed to compile {$categoryname}\n";
@unlink($TargetFile);
continue;
}
$MD5SRC = md5_file("{$SOURCE_DIR}/domains.ufdb");
if (is_file("{$WORKING_UPLOAD}/{$categoryname}.gz")) {
@unlink("{$WORKING_UPLOAD}/{$categoryname}.gz");
}
$unix->compress("{$SOURCE_DIR}/domains.ufdb", "{$WORKING_UPLOAD}/{$categoryname}.gz");
$MD5GZ = md5_file("{$WORKING_UPLOAD}/{$categoryname}.gz");
$UPDATED++;
$NOTIFICATIONS[] = "{$categoryname} updated with {$COUNT_OF_DOMAINS} domains";
$MAIN_ARRAY[$categoryname]["ROWS"] = $COUNT_OF_DOMAINS;
$MAIN_ARRAY[$categoryname]["MD5SRC"] = $MD5SRC;
$MAIN_ARRAY[$categoryname]["MD5GZ"] = $MD5GZ;
$MAIN_ARRAY[$categoryname]["TIME"] = time();
$MAIN_ARRAY[$categoryname]["SIZE"] = @filesize("{$WORKING_UPLOAD}/{$categoryname}.gz");
@file_put_contents("{$WORKING_UPLOAD}/index.txt", base64_encode(serialize($MAIN_ARRAY)));
}
if ($UPDATED > 0) {
PushToRepo_alls();
sendEmail("{$UPDATED} Toulouse Unversity databases uploaded.", @implode("\n", $NOTIFICATIONS));
}
}
示例8: ROTATE_DIR
function ROTATE_DIR($backupdir)
{
$unix = new unix();
$cat = $unix->find_program("cat");
$files = $unix->DirFiles($backupdir);
$suffix = "influx";
if (is_file("/usr/local/ArticaStats/bin/postgres")) {
$suffix = "postgres";
}
$today = date("Y-m-d");
while (list($basename, $subarray) = each($files)) {
if (preg_match("#^([0-9\\-]+)\\.gz\$#", $basename, $re)) {
continue;
}
if (preg_match("#^([0-9\\-]+)\\.back\$#", $basename, $re)) {
if ($re[1] != $today) {
if (!$unix->compress("{$backupdir}/{$basename}", "{$backupdir}/{$re[1]}.gz")) {
@unlink("{$backupdir}/{$re[1]}.gz");
continue;
}
@unlink("{$backupdir}/{$basename}");
}
continue;
}
if (!preg_match("#^([0-9]+)\\.{$suffix}\\.log\$#", $basename, $re)) {
echo "{$basename} no match...\n";
continue;
}
$time = $re[1];
$day = date("Y-m-d", $time);
$handleOUT = @fopen("{$backupdir}/{$basename}", "r");
$handleIN = @fopen("{$backupdir}/{$day}.back", "a");
$c = 0;
while (!feof($handleOUT)) {
$line = trim(fgets($handleOUT, 4096));
@fwrite($handleIN, "{$line}\n");
$c++;
}
events("{$backupdir}/{$basename} {$c} line(s)");
fclose($handleOUT);
fclose($handleIN);
@unlink("{$backupdir}/{$basename}");
}
}
示例9: import_quarantine
//.........这里部分代码省略.........
$MimeDefangMaxQuartime = 129600;
}
if ($GLOBALS["VERBOSE"]) {
echo "Retention time.: {$MimeDefangMaxQuartime}Mn\n";
}
$f = explode("\n", @file_get_contents("{$directory}/HEADERS"));
while (list($index, $line) = each($f)) {
if (preg_match("#Subject:\\s+(.*)#", $line, $re)) {
if ($GLOBALS["VERBOSE"]) {
echo "Subject........: {$re[1]}\n";
}
$Subject = $re[1];
}
if (preg_match("#From:\\s+(.*)#i", $line, $re)) {
if ($GLOBALS["VERBOSE"]) {
echo "From...........: {$re[1]}\n";
}
$FromHeader = $re[1];
$FromHeader = str_replace("<", "", $FromHeader);
$FromHeader = str_replace(">", "", $FromHeader);
$FromHeader = trim($FromHeader);
if (preg_match("#(.*?)\\s+#", $FromHeader, $re)) {
$FromHeader = $re[1];
}
}
}
$mailsTo_array = array();
$f = explode("\n", @file_get_contents("{$directory}/RECIPIENTS"));
while (list($index, $line) = each($f)) {
$line = trim($line);
if ($line == null) {
continue;
}
$line = str_replace("<", "", $line);
$line = str_replace(">", "", $line);
if (strpos($line, "@") == 0) {
continue;
}
if ($GLOBALS["VERBOSE"]) {
echo "Recipient......: {$line}\n";
}
$mailsTo_array[$line] = $line;
}
$mailfrom = trim(@file_get_contents("{$directory}/SENDER"));
if ($GLOBALS["VERBOSE"]) {
echo "Sender.........: {$mailfrom}\n";
}
if ($mailfrom == null) {
$mailfrom = $FromHeader;
}
$mailfrom = str_replace("<", "", $mailfrom);
$mailfrom = str_replace(">", "", $mailfrom);
$q = new postgres_sql();
$Subject = str_replace("'", "`", $Subject);
$mailfromz = explode("@", $mailfrom);
$domainfrom = $mailfromz[1];
$final = strtotime("+{$MimeDefangMaxQuartime} minutes", $last_modified);
$prefix = "INSERT INTO quarmsg (zdate,final,msgmd5,size,subject,mailfrom,mailto,domainfrom,domainto ) VALUES ";
$f = array();
while (list($a, $mailto) = each($mailsTo_array)) {
$mailto = trim(strtolower($mailto));
if ($mailto == null) {
continue;
}
$mailtoz = explode("@", $mailto);
$domainto = $mailtoz[1];
$f[] = "('{$zdate}','{$final}','{$msgmd5}','{$filesize}','{$Subject}','{$mailfrom}','{$mailto}','{$domainfrom}','{$domainto}')";
}
if (count($f) == 0) {
echo "No... count(f)=0\n";
shell_exec("{$rm} -rf \"{$directory}\"");
return false;
}
$final_sql = $prefix . " " . @implode(",", $f);
$q->QUERY_SQL($final_sql);
if (!$q->ok) {
echo $q->mysql_error . "\n{$final_sql}\n";
echo "No... PostgreSQL error\n";
return false;
}
$filecontent_gz = $unix->FILE_TEMP() . ".gz";
$unix = new unix();
if (!$unix->compress("{$directory}/ENTIRE_MESSAGE", $filecontent_gz)) {
@unlink($filecontent_gz);
echo "No... Compress error\n";
return;
}
@chmod($filecontent_gz, 0777);
$q->QUERY_SQL("INSERT INTO quardata (zdate,msgmd5,final,contentid) VALUES ('{$zdate}','{$msgmd5}','{$final}',lo_import('{$filecontent_gz}') ) ON CONFLICT DO NOTHING");
if (!$q->ok) {
echo $q->mysql_error . "\n";
echo "No... PostgreSQL error\n";
return false;
}
@unlink($filecontent_gz);
$unix->ToSyslog("from=<{$mailfrom}> [{$Subject}] {$directory}/ENTIRE_MESSAGE success to Quarantine");
echo "{$directory}/ENTIRE_MESSAGE (success)\n";
shell_exec("{$rm} -rf \"{$directory}\"");
return true;
}
示例10: check_all_squid
function check_all_squid()
{
$sock = new sockets();
$unix = new unix();
$syslog = new mysql_storelogs();
$php5 = $unix->LOCATE_PHP5_BIN();
$pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
$timefile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".time";
$pid = file_get_contents("{$pidfile}");
if (system_is_overloaded(basename(__FILE__))) {
die;
}
if ($unix->process_exists($pid, basename(__FILE__))) {
$timeMin = $unix->PROCCESS_TIME_MIN($pid);
if ($timeMin > 240) {
system_admin_events("Too many TTL, {$pid} will be killed", __FUNCTION__, __FILE__, __LINE__, "logrotate");
$kill = $unix->find_program("kill");
unix_system_kill_force($pid);
} else {
die;
}
}
$time = $unix->file_time_min($timefile);
if ($time < 300) {
return;
}
@file_put_contents($pidfile, getmypid());
@file_put_contents($timefile, time());
$php = $unix->LOCATE_PHP5_BIN();
$bzip2 = $unix->find_program("bzip2");
$ALREADYCOMP["gz"] = true;
$ALREADYCOMP["bz2"] = true;
$LogRotateCompress = 1;
$LogRotatePath = $sock->GET_INFO("LogRotatePath");
$ApacheLogRotate = $sock->GET_INFO("ApacheLogRotate");
if (!is_numeric($ApacheLogRotate)) {
$ApacheLogRotate = 1;
}
if ($LogRotatePath == null) {
$LogRotatePath = "/home/logrotate";
}
$LogsRotateDefaultSizeRotation = $sock->GET_INFO("LogsRotateDefaultSizeRotation");
if (!is_numeric($LogsRotateDefaultSizeRotation)) {
$LogsRotateDefaultSizeRotation = 100;
}
foreach (glob("/var/log/squid/*") as $filename) {
if (is_dir($filename)) {
continue;
}
$size = $unix->file_size($filename);
$time = $unix->file_time_min($filename);
$size = round($size / 1024 / 1000, 2);
if ($size > $LogsRotateDefaultSizeRotation) {
if ($filename == "/var/log/squid/access.log") {
events("{$filename} -> is a production log for Squid, launch the rotation procedure.");
squid_admin_mysql(1, "{$filename} {$size}M exceed {$LogsRotateDefaultSizeRotation}M, launch rotation", null, __FILE__, __LINE__);
shell_exec("{$php} /usr/share/artica-postfix/exec.squid.php --rotate");
continue;
}
$TOROT[$filename] = true;
events("{$filename} -> Add to queue {$size}M exceed {$LogsRotateDefaultSizeRotation}M");
continue;
}
if ($time > 1440) {
if ($filename == "/var/log/squid/access.log") {
events("{$filename} -> is a production log for Squid, launch the rotation procedure.");
squid_admin_mysql(1, "{$filename} {$size}M exceed {$LogsRotateDefaultSizeRotation}M, launch rotation", null, __FILE__, __LINE__);
shell_exec("{$php} /usr/share/artica-postfix/exec.squid.php --rotate");
continue;
}
events("{$filename} -> Add to queue {$time}mn exceed 1440mn");
$TOROT[$filename] = true;
continue;
}
}
if (count($TOROT) == 0) {
return;
}
while (list($filename, $none) = each($TOROT)) {
$extension = pathinfo($filename, PATHINFO_EXTENSION);
$filedate = date('Y-m-d H:i:s', filemtime($filename));
$basename = basename($filename);
if (preg_match("#sarg\\.#", $filename)) {
shell_exec("{$php5} " . dirname(__FILE__) . "/exec.sarg.php --rotate {$basename} >/dev/null 2>&1 &");
continue;
}
if (preg_match("#access\\.log\\.[0-9]+\$#", $filename)) {
continue;
}
if ($extension != "gz") {
if (!$unix->compress($filename, "{$filename}.gz")) {
continue;
}
$filename = $filename . ".gz";
$extension = "gz";
}
echo "[{$filedate}]: {$filename} ({$extension})\n";
if ($syslog->ROTATE_TOMYSQL($filename, $filedate)) {
@unlink($filename);
}
//.........这里部分代码省略.........
示例11: BACKUP_PROGRESS
function BACKUP_PROGRESS()
{
build_progress_backup("{backup} {rules}", 5);
$tables[] = "webauth_rules";
$tables[] = "webauth_settings";
$tables[] = "hotspot_members";
$q = new mysql_squid_builder();
$cmdline = $q->MYSQL_CMDLINES;
$unix = new unix();
$mysqldump = $unix->find_program("mysqldump");
$bzip2 = $unix->find_program("bzip2");
$bzip2_cmd = "| {$bzip2} ";
$filename = "/usr/share/artica-postfix/ressources/logs/web/hotspot.rules.backup.sql";
$fileCompressName = "/usr/share/artica-postfix/ressources/logs/web/hotspot.rules.backup.gz";
if (is_file($filename)) {
@unlink($filename);
}
build_progress_backup("{backup} {tables}", 50);
$cmd = "{$mysqldump} {$cmdline} --skip-add-drop-table --insert-ignore --single-transaction --skip-add-locks --skip-lock-tables squidlogs " . @implode(" ", $tables) . "> {$filename} 2>&1";
echo $cmd . "\n";
system("{$cmd}");
if (!is_file($filename)) {
build_progress_backup("{backup} {failed}", 110);
return;
}
$size = @filesize($filename);
echo "Size: " . $size . " bytes " . FormatBytes($size / 1024, true) . "\n";
sleep(3);
build_progress_backup("{backup} {compress}", 80);
if (!$unix->compress($filename, $fileCompressName)) {
@unlink($filename);
build_progress_backup("{backup} {compress} failed}", 110);
return;
}
@unlink($filename);
$size = @filesize($fileCompressName);
echo "Size: ( after compression) " . $size . " bytes " . FormatBytes($size / 1024, true) . "\n";
sleep(2);
build_progress_backup("{backup} {done}", 100);
}
示例12: date
$GLOBALS["deflog_start"] = "Starting......: " . date("H:i:s") . " [INIT]: Milter Greylist Daemon";
$GLOBALS["deflog_sstop"] = "Stopping......: " . date("H:i:s") . " [INIT]: Milter Greylist Daemon";
$GLOBALS["ROOT"] = true;
$GLOBALS["FORCE"] = false;
if (preg_match("#--verbose#", @implode(" ", $argv))) {
$GLOBALS["FORCE"] = true;
}
$GLOBALS["WHOPROCESS"] = "daemon";
if (!is_file("/root/ftp-hostname")) {
echo "/root/ftp-hostname No such file...\n";
die;
}
$unix = new unix();
if (is_file("/etc/artica-postfix/spamassassin-rules1.cf")) {
@unlink("/etc/artica-postfix/spamassassin-rules1.gz");
if (!$unix->compress("/etc/artica-postfix/spamassassin-rules1.cf", "/etc/artica-postfix/spamassassin-rules1.gz")) {
die;
}
$MAIN["SPAMASS_1"]["TIME"] = time();
$MAIN["SPAMASS_1"]["MD5"] = md5_file("/etc/artica-postfix/spamassassin-rules1.gz");
}
if (is_file("/etc/artica-postfix/spamassassin-rules3.cf")) {
@unlink("/etc/artica-postfix/spamassassin-rules3.gz");
if (!$unix->compress("/etc/artica-postfix/spamassassin-rules3.cf", "/etc/artica-postfix/spamassassin-rules3.gz")) {
die;
}
$MAIN["SPAMASS_2"]["TIME"] = time();
$MAIN["SPAMASS_2"]["MD5"] = md5_file("/etc/artica-postfix/spamassassin-rules3.gz");
}
if (is_file("/etc/artica-postfix/spamassassin-rules4.cf")) {
@unlink("/etc/artica-postfix/spamassassin-rules4.gz");
示例13: SaveCSV
function SaveCSV($ID)
{
$unix = new unix();
$chmod = $unix->find_program("chmod");
$tablename = "WebTrackMem{$ID}";
@unlink("/home/squid-work/csv.txt");
@mkdir("/home/squid-work", 0777);
$sql = "SELECT * INTO OUTFILE '/home/squid-work/csv.txt' FIELDS TERMINATED BY ',' \n\tOPTIONALLY ENCLOSED BY '\"' LINES TERMINATED BY '\n' FROM {$tablename};";
shell_exec("chmod 1777 /home/squid-work");
$q = new mysql_squid_builder();
$q->QUERY_SQL($sql);
if (!$q->ok) {
ufdbguard_admin_events("CSV failed {$q->mysql_error}", __FUNCTION__, __FILE__, __LINE__, "reports");
return;
}
$unix->compress("/home/squid-work/csv.txt", "/home/squid-work/csv.txt.gz");
@unlink("/home/squid-work/csv.txt");
$f = addslashes(@file_get_contents("/home/squid-work/csv.txt.gz"));
@unlink("/home/squid-work/csv.txt.gz");
$sql = "UPDATE TrackMembers SET csvContent='{$f}' WHERE ID='{$ID}'";
$q->QUERY_SQL($sql);
if (!$q->ok) {
ufdbguard_admin_events("CSV failed {$q->mysql_error}", __FUNCTION__, __FILE__, __LINE__, "reports");
return;
}
}
示例14: CheckOldCachesLog
function CheckOldCachesLog()
{
@mkdir("/home/squid/cache-logs", 0755, true);
$unix = new unix();
foreach (glob("/var/log/squid/cache.log.*") as $filename) {
if ($GLOBALS["VERBOSE"]) {
echo "Move {$filename} to /home/squid/cache-logs\n";
}
Events("Move {$filename} to /home/squid/cache-logs");
@copy($filename, "/home/squid/cache-logs/" . basename($filename));
@unlink($filename);
}
foreach (glob("/home/squid/cache-logs/*") as $filename) {
$ext = $unix->file_ext($filename);
if (is_numeric($ext)) {
Events("Compress {$filename} to {$filename}.gz");
if ($unix->compress($filename, "{$filename}.gz")) {
@unlink($filename);
}
continue;
}
if ($ext == "gz") {
$time = $unix->file_time_min($filename);
if ($GLOBALS["VERBOSE"]) {
echo "{$filename} = {$time}Mn\n";
}
if ($time > 4320) {
Events("Remove {$filename} (exceed 3 days on disk...)");
@unlink($filename);
continue;
}
}
}
if ($GLOBALS["VERBOSE"]) {
echo "CheckOldCachesLog:: END\n";
}
}
示例15: CleanSuricataLogs
function CleanSuricataLogs()
{
if (!is_dir("/var/log/suricata")) {
return;
}
$unix = new unix();
$sock = new sockets();
$LogsRotateDefaultSizeRotation = $sock->GET_INFO("LogsRotateDefaultSizeRotation");
if (!is_numeric($LogsRotateDefaultSizeRotation)) {
$LogsRotateDefaultSizeRotation = 100;
}
$BackupMaxDaysDir = $sock->GET_INFO("BackupMaxDaysDir");
if ($BackupMaxDaysDir == null) {
$BackupMaxDaysDir = "/home/logrotate_backup";
}
@mkdir($BackupMaxDaysDir, 0755, true);
$echo = $unix->find_program("echo");
@unlink("/etc/artica-postfix/pids/CleanSuricataLogs.time");
@file_put_contents("/etc/artica-postfix/pids/CleanSuricataLogs.time", time());
if ($handle = opendir("/var/log/suricata")) {
while (false !== ($fileZ = readdir($handle))) {
if ($fileZ == ".") {
continue;
}
if ($fileZ == "..") {
continue;
}
$path = "/var/log/suricata/{$fileZ}";
if (preg_match("#unified2\\.alert\\.#", $fileZ)) {
if ($unix->file_time_min($path) > 30) {
@unlink($path);
}
continue;
}
}
}
$f[] = "fast.log";
$f[] = "http.log";
$f[] = "keyword_perf.log";
$f[] = "packet_stats.log";
$f[] = "rule_perf.log";
$f[] = "sid_changes.log";
$f[] = "stats.log";
$RELOAD = false;
$pathRange = "{$BackupMaxDaysDir}/" . date("Y") . "/" . date("m") . "/" . date("d");
while (list($index, $filename) = each($f)) {
$filepath = "/var/log/suricata/{$filename}";
$size = @filesize($filepath) / 1024 / 1000;
echo "{$filepath} {$size}MB <> {$LogsRotateDefaultSizeRotation}M\n";
if ($size > $LogsRotateDefaultSizeRotation) {
@mkdir($pathRange, 0755, true);
$unix->compress($filepath, $pathRange . "/IDS-" . time() . ".{$filename}.gz");
system_admin_mysql(2, "Rotate file {$filepath} {$size}>{$LogsRotateDefaultSizeRotation}", null, __FILE__, __LINE__);
shell_exec("{$echo} \"\">{$filepath}");
$RELOAD = true;
}
}
$size = @filesize("/var/log/suricata/eve.json") / 1024 / 1000;
if ($size > $LogsRotateDefaultSizeRotation) {
system_admin_mysql(2, "Rotate file /var/log/suricata/eve.json {$size}>{$LogsRotateDefaultSizeRotation}", null, __FILE__, __LINE__);
@mkdir($pathRange, 0755, true);
$unix->compress($filepath, $pathRange . "/IDS-" . time() . ".eve.json.gz");
shell_exec("{$echo} \"\">/var/log/suricata/eve.json");
$RELOAD = true;
}
if ($RELOAD) {
shell_exec("/etc/init.d/suricata reload");
}
}