Diff
14 years ago
.htaccess
14 years ago
Diff.php
14 years ago
IPTraf.php
14 years ago
diffResult.php
14 years ago
dropAll.php
14 years ago
email_genericAlert.php
14 years ago
email_newIssues.php
14 years ago
email_unlockRequest.php
14 years ago
menu_activity.php
14 years ago
menu_blockedIPs.php
14 years ago
menu_config.php
14 years ago
menu_options.php
14 years ago
menu_scan.php
14 years ago
sysinfo.php
14 years ago
viewFullActivityLog.php
14 years ago
wf503.php
14 years ago
wfAPI.php
14 years ago
wfAction.php
14 years ago
wfBrowscap.php
14 years ago
wfBrowscapCache.php
14 years ago
wfConfig.php
14 years ago
wfCrawl.php
14 years ago
wfDB.php
14 years ago
wfDict.php
14 years ago
wfIssues.php
14 years ago
wfLockedOut.php
14 years ago
wfLog.php
14 years ago
wfModTracker.php
14 years ago
wfRate.php
14 years ago
wfScanEngine.php
14 years ago
wfSchema.php
14 years ago
wfUnlockMsg.php
14 years ago
wfUtils.php
14 years ago
wfViewResult.php
14 years ago
wordfenceClass.php
14 years ago
wordfenceConstants.php
14 years ago
wordfenceHash.php
14 years ago
wordfenceScanner.php
14 years ago
wordfenceURLHoover.php
14 years ago
wfModTracker.php
126 lines
| 1 | <?php |
| 2 | require_once('wordfenceClass.php'); |
| 3 | class wfModTracker { |
| 4 | private $themeSum = false; |
| 5 | private $pluginSum = false; |
| 6 | private $coreSum = false; |
| 7 | private $db = false; |
| 8 | private $changesTable = false; |
| 9 | private $anyFilesChangedCached = false; |
| 10 | public function __construct(){ |
| 11 | global $wpdb; |
| 12 | $this->changesTable = $wpdb->base_prefix . 'wfFileChanges'; |
| 13 | $this->status(2, 'info', "Getting file change DB handle"); |
| 14 | $this->db = new wfDB(); |
| 15 | $this->status(2, 'info', "Starting theme change check"); |
| 16 | $this->themeSum = $this->makeSum(get_theme_root()); |
| 17 | $this->status(2, 'info', "Starting plugin change scan"); |
| 18 | $this->pluginSum = $this->makeSum(WP_PLUGIN_DIR); |
| 19 | $this->status(2, 'info', "Starting core file change scan"); |
| 20 | $this->coreSum = $this->makeCoreSum(); |
| 21 | $this->allFilesSum = array(); |
| 22 | $this->status(2, 'info', "Getting changes in all other files"); |
| 23 | $this->getAllFilesSum(ABSPATH); |
| 24 | $this->status(2, 'info', "Done compiling file changes"); |
| 25 | } |
| 26 | public static function resetChanges(){ |
| 27 | wfConfig::set('wfmdt_coreSum', ''); |
| 28 | wfConfig::set('wfmdt_themeSum', ''); |
| 29 | wfConfig::set('wfmdt_pluginSum', ''); |
| 30 | $db = new wfDB(); |
| 31 | global $wpdb; |
| 32 | $db->query("delete from " . $wpdb->base_prefix . 'wfFileChanges'); |
| 33 | } |
| 34 | public function filesModifiedInCore(){ if(wfConfig::get('wfmdt_coreSum') != $this->coreSum){ return true; } else { return false; } } |
| 35 | public function filesModifiedInThemes(){ if(wfConfig::get('wfmdt_themeSum') != $this->themeSum){ return true; } else { return false; } } |
| 36 | public function filesModifiedInPlugins(){ if(wfConfig::get('wfmdt_pluginSum') != $this->pluginSum){ return true; } else { return false; } } |
| 37 | public function getChangedFiles($stripPath, $filterOutFiles){ |
| 38 | $changed = array(); |
| 39 | foreach($this->allFilesSum as $file => $md5){ |
| 40 | if(in_array($file, $filterOutFiles)){ continue; } |
| 41 | $dbSig = $this->db->querySingle("select md5 from " . $this->changesTable . " where filenameHash='%s'", hash('sha256', $file)); |
| 42 | if($dbSig != $md5){ |
| 43 | $changed[] = substr($file, strlen($stripPath) - 1); |
| 44 | } |
| 45 | } |
| 46 | return $changed; |
| 47 | } |
| 48 | public function anyFilesChanged(){ |
| 49 | if(! $this->anyFilesChangedCached){ |
| 50 | $changed = false; |
| 51 | $q = $this->db->query("select file, md5 from " . $this->changesTable); |
| 52 | $knownDBFiles = array(); |
| 53 | while($row = mysql_fetch_assoc($q)){ |
| 54 | $knownDBFiles[$row['file']] = true; |
| 55 | if( (! isset($this->allFilesSum[$row['file']])) || $this->allFilesSum[$row['file']] != $row['md5']){ |
| 56 | $changed = true; |
| 57 | //Can't break because we need to populate all of knownDBFiles |
| 58 | } |
| 59 | } |
| 60 | foreach($this->allFilesSum as $file => $md5){ |
| 61 | if(! isset($knownDBFiles[$file])){ |
| 62 | //We have a new file the DB doesn't know about |
| 63 | $changed = true; |
| 64 | break; |
| 65 | } |
| 66 | } |
| 67 | $this->anyFilesChangedCached = $changed ? 'true' : 'false'; |
| 68 | } |
| 69 | return $this->anyFilesChangedCached == 'true' ? true : false; |
| 70 | } |
| 71 | public function logCurrentState(){ |
| 72 | wfConfig::set('wfmdt_coreSum', $this->coreSum); |
| 73 | wfConfig::set('wfmdt_themeSum', $this->themeSum); |
| 74 | wfConfig::set('wfmdt_pluginSum', $this->pluginSum); |
| 75 | foreach($this->allFilesSum as $file => $md5){ |
| 76 | $this->db->query("insert into " . $this->changesTable . " (file, md5, filenameHash) values ('%s', '%s', '%s') ON DUPLICATE KEY UPDATE md5='%s'", $file, $md5, hash('sha256', $file), $md5); |
| 77 | } |
| 78 | $q = $this->db->query("select file from " . $this->changesTable); |
| 79 | while($row = mysql_fetch_assoc($q)){ |
| 80 | if(! isset($this->allFilesSum[$row['file']])){ |
| 81 | $this->db->query("delete from " . $this->changesTable . " where filenameHash='%s'", hash('sha256', $row['file'])); |
| 82 | } |
| 83 | } |
| 84 | } |
| 85 | private function getAllFilesSum($path){ |
| 86 | $path = rtrim($path, '/'); |
| 87 | $files = scandir($path); |
| 88 | foreach($files as $file){ |
| 89 | if($file == '.' || $file == '..'){ continue; } |
| 90 | $file = $path . '/' . $file; |
| 91 | if(is_file($file)){ |
| 92 | $md5 = @md5_file($file); |
| 93 | if($md5){ $this->allFilesSum[$file] = $md5; } |
| 94 | } else if(is_dir($file)){ |
| 95 | $this->getAllFilesSum($file, $this->allFilesSum); |
| 96 | } |
| 97 | } |
| 98 | } |
| 99 | private function makeCoreSum(){ |
| 100 | return md5( |
| 101 | $this->makeSum(ABSPATH, true) . //norecurse |
| 102 | $this->makeSum(ABSPATH . '/wp-admin/') . |
| 103 | $this->makeSum(ABSPATH . '/wp-includes/') |
| 104 | ); |
| 105 | } |
| 106 | public function makeSum($dir, $norecurse = false, $str = ''){ |
| 107 | $dir = rtrim($dir, '/'); |
| 108 | $files = scandir($dir); |
| 109 | foreach($files as $file){ |
| 110 | if($file == '.' || $file == '..'){ continue; } |
| 111 | $file = $dir . '/' . $file; |
| 112 | if(is_file($file)){ |
| 113 | $md5 = @md5_file($file); |
| 114 | if($md5){ $str .= $md5; } |
| 115 | } else if((! $norecurse) && is_dir($file)){ |
| 116 | $str .= md5($this->makeSum($file, $norecurse, $str)); |
| 117 | } |
| 118 | } |
| 119 | return md5($str); |
| 120 | } |
| 121 | private function status($level, $type, $msg){ |
| 122 | wordfence::status($level, $type, $msg); |
| 123 | } |
| 124 | } |
| 125 | ?> |
| 126 |