示例#1
0
 public static function dailyCron()
 {
     $api = new wfAPI(wfConfig::get('apiKey'), wfUtils::getWPVersion());
     $keyData = $api->call('ping_api_key');
     if (isset($keyData['_isPaidKey']) && $keyData['_isPaidKey']) {
         $keyExpDays = $keyData['_keyExpDays'];
         $keyIsExpired = $keyData['_expired'];
         if (!empty($keyData['_autoRenew'])) {
             if ($keyExpDays > 12) {
                 wfConfig::set('keyAutoRenew10Sent', '');
             } else {
                 if ($keyExpDays <= 12 && $keyExpDays > 0 && !wfConfig::get('keyAutoRenew10Sent')) {
                     wfConfig::set('keyAutoRenew10Sent', 1);
                     $email = "Your Premium Wordfence API Key is set to auto-renew in 10 days.";
                     self::alert($email, "{$email} To update your API key settings please visit http://www.wordfence.com/zz9/dashboard", false);
                 }
             }
         } else {
             if ($keyExpDays > 15) {
                 wfConfig::set('keyExp15Sent', '');
                 wfConfig::set('keyExp7Sent', '');
                 wfConfig::set('keyExp2Sent', '');
                 wfConfig::set('keyExp1Sent', '');
                 wfConfig::set('keyExpFinalSent', '');
             } else {
                 if ($keyExpDays <= 15 && $keyExpDays > 0) {
                     if ($keyExpDays <= 15 && $keyExpDays >= 11 && !wfConfig::get('keyExp15Sent')) {
                         wfConfig::set('keyExp15Sent', 1);
                         self::keyAlert("Your Premium Wordfence API Key expires in less than 2 weeks.");
                     } else {
                         if ($keyExpDays <= 7 && $keyExpDays >= 4 && !wfConfig::get('keyExp7Sent')) {
                             wfConfig::set('keyExp7Sent', 1);
                             self::keyAlert("Your Premium Wordfence API Key expires in less than a week.");
                         } else {
                             if ($keyExpDays == 2 && !wfConfig::get('keyExp2Sent')) {
                                 wfConfig::set('keyExp2Sent', 1);
                                 self::keyAlert("Your Premium Wordfence API Key expires in 2 days.");
                             } else {
                                 if ($keyExpDays == 1 && !wfConfig::get('keyExp1Sent')) {
                                     wfConfig::set('keyExp1Sent', 1);
                                     self::keyAlert("Your Premium Wordfence API Key expires in 1 day.");
                                 }
                             }
                         }
                     }
                 } else {
                     if ($keyIsExpired && !wfConfig::get('keyExpFinalSent')) {
                         wfConfig::set('keyExpFinalSent', 1);
                         self::keyAlert("Your Wordfence Premium API Key has Expired!");
                     }
                 }
             }
         }
     }
     $wfdb = new wfDB();
     global $wpdb;
     $p = $wpdb->base_prefix;
     try {
         $patData = $api->call('get_known_vuln_pattern');
         if (is_array($patData) && $patData['pat']) {
             if (@preg_match($patData['pat'], 'wordfence_test_vuln_match')) {
                 wfConfig::set('vulnRegex', $patData['pat']);
             }
         }
     } catch (Exception $e) {
         wordfence::status(4, 'error', "Could not fetch vulnerability patterns in scheduled job: " . $e->getMessage());
     }
     $wfdb->queryWrite("delete from {$p}" . "wfLocs where ctime < unix_timestamp() - %d", WORDFENCE_MAX_IPLOC_AGE);
     $wfdb->truncate($p . "wfBadLeechers");
     //only uses date that's less than 1 minute old
     $wfdb->queryWrite("delete from {$p}" . "wfBlocks where (blockedTime + %s < unix_timestamp()) and permanent=0", wfConfig::get('blockedTime'));
     $wfdb->queryWrite("delete from {$p}" . "wfCrawlers where lastUpdate < unix_timestamp() - (86400 * 7)");
     $wfdb->truncate($p . "wfVulnScanners");
     //We only report data within the last hour in hourlyCron.
     // So if we do a once a day truncate to be safe, we'll only potentially lose the hour right before the truncate.
     // Worth it to clean out the table completely once a day.
     self::trimWfHits();
     /*
     		$count6 = $wfdb->querySingle("select count(*) as cnt from $p"."wfPerfLog");
     		if($count6 > 20000){
     			$wfdb->truncate($p . "wfPerfLog"); //So we don't slow down sites that have very large wfHits tables
     		} else if($count6 > 2000){
     			$wfdb->queryWrite("delete from $p"."wfPerfLog order by id asc limit %d", ($count6 - 100));
     		}
     */
     $maxRows = 1000;
     //affects stuff further down too
     foreach (array('wfLeechers', 'wfScanners') as $table) {
         //This is time based per IP so shouldn't get too big
         $wfdb->queryWrite("delete from {$p}" . "{$table} where eMin < ((unix_timestamp() - (86400 * 2)) / 60)");
     }
     $wfdb->queryWrite("delete from {$p}" . "wfLockedOut where blockedTime + %s < unix_timestamp()", wfConfig::get('loginSec_lockoutMins') * 60);
     $count2 = $wfdb->querySingle("select count(*) as cnt from {$p}" . "wfLogins");
     if ($count2 > 20000) {
         $wfdb->truncate($p . "wfLogins");
         //in case of Dos
     } else {
         if ($count2 > $maxRows) {
             $wfdb->queryWrite("delete from {$p}" . "wfLogins order by ctime asc limit %d", $count2 - 100);
         }
     }
     $wfdb->queryWrite("delete from {$p}" . "wfReverseCache where unix_timestamp() - lastUpdate > 86400");
     $count3 = $wfdb->querySingle("select count(*) as cnt from {$p}" . "wfThrottleLog");
     if ($count3 > 20000) {
         $wfdb->truncate($p . "wfThrottleLog");
         //in case of DoS
     } else {
         if ($count3 > $maxRows) {
             $wfdb->queryWrite("delete from {$p}" . "wfThrottleLog order by endTime asc limit %d", $count3 - 100);
         }
     }
     $count4 = $wfdb->querySingle("select count(*) as cnt from {$p}" . "wfStatus");
     if ($count4 > 100000) {
         $wfdb->truncate($p . "wfStatus");
     } else {
         if ($count4 > 1000) {
             //max status events we keep. This determines how much gets emailed to us when users sends us a debug report.
             $wfdb->queryWrite("delete from {$p}" . "wfStatus where level != 10 order by ctime asc limit %d", $count4 - 1000);
             $count5 = $wfdb->querySingle("select count(*) as cnt from {$p}" . "wfStatus where level=10");
             if ($count5 > 100) {
                 $wfdb->queryWrite("delete from {$p}" . "wfStatus where level = 10 order by ctime asc limit %d", $count5 - 100);
             }
         }
     }
     $report = new wfActivityReport();
     $report->rotateIPLog();
 }