PluginProbe ʕ •ᴥ•ʔ
Wordfence Security – Firewall, Malware Scan, and Login Security / 7.1.11
Wordfence Security – Firewall, Malware Scan, and Login Security v7.1.11
8.2.2 8.2.1 8.2.0 3.7.1 3.7.2 3.8.1 3.8.2 3.8.3 3.8.4 3.8.5 3.8.6 3.8.7 3.8.8 3.8.9 3.9.1 4.0.1 4.0.2 4.0.3 5.0.1 5.0.2 5.0.3 5.0.4 5.0.5 5.0.6 5.0.7 5.0.8 5.0.9 5.1.1 5.1.2 5.1.4 5.1.5 5.1.6 5.1.7 5.1.8 5.1.9 5.2.1 5.2.2 5.2.3 5.2.4 5.2.5 5.2.6 5.2.7 5.2.8 5.2.9 5.3.1 5.3.10 5.3.11 5.3.12 5.3.2 5.3.3 5.3.4 5.3.5 5.3.6 5.3.7 5.3.8 5.3.9 6.0.1 6.0.10 6.0.11 6.0.12 6.0.14 6.0.15 6.0.16 6.0.17 6.0.18 6.0.19 6.0.2 6.0.20 6.0.21 6.0.22 6.0.23 6.0.24 6.0.25 6.0.3 6.0.4 6.0.5 6.0.6 6.0.7 6.0.8 6.0.9 6.1.1 6.1.10 6.1.11 6.1.12 6.1.14 6.1.15 6.1.16 6.1.17 6.1.2 6.1.3 6.1.4 6.1.5 6.1.6 6.1.7 6.1.8 6.1.9 6.2.0 6.2.1 6.2.10 6.2.2 6.2.3 6.2.4 6.2.5 6.2.6 6.2.7 6.2.8 6.2.9 6.3.0 6.3.1 6.3.10 6.3.11 6.3.12 6.3.14 6.3.15 6.3.16 6.3.17 6.3.18 6.3.19 6.3.2 6.3.20 6.3.21 6.3.22 6.3.3 6.3.4 6.3.5 6.3.6 6.3.7 6.3.8 6.3.9 7.0.1 7.0.2 7.0.3 7.0.4 7.0.5 7.1.0 7.1.1 7.1.10 7.1.11 7.1.12 7.1.14 7.1.15 7.1.16 7.1.17 7.1.18 7.1.19 7.1.2 7.1.20 7.1.3 7.1.4 7.1.5 7.1.6 7.1.7 7.1.8 7.1.9 7.10.0 7.10.1 7.10.2 7.10.3 7.10.4 7.10.5 7.10.6 7.10.7 7.11.0 7.11.1 7.11.2 7.11.3 7.11.4 7.11.5 7.11.6 7.11.7 7.2.1 7.2.2 7.2.3 7.2.4 7.2.5 7.3.1 7.3.2 7.3.3 7.3.4 7.3.5 7.3.6 7.4.0 7.4.1 7.4.10 7.4.11 7.4.12 7.4.14 7.4.2 7.4.3 trunk 7.4.4 1.1 7.4.5 1.2 7.4.6 1.3 7.4.7 1.3.1 7.4.8 1.3.2 7.4.9 1.3.3 7.5.0 1.4.2 7.5.1 1.4.3 7.5.10 1.4.4 7.5.11 1.4.5 7.5.2 1.4.6 7.5.3 1.4.7 7.5.4 1.4.8 7.5.5 1.5.1 7.5.6 1.5.2 7.5.7 1.5.3 7.5.8 1.5.4 7.5.9 1.5.5 7.6.0 1.5.6 7.6.1 2.0.1 7.6.2 2.0.2 7.7.0 2.0.3 7.7.1 2.0.5 7.8.0 2.0.6 7.8.1 2.0.7 7.8.2 2.1.0 7.9.0 2.1.1 7.9.1 2.1.2 7.9.2 2.1.3 7.9.3 2.1.4 8.0.0 2.1.5 8.0.1 3.0.2 8.0.2 3.0.3 8.0.3 3.0.4 8.0.4 3.0.5 8.0.5 3.0.6 8.1.0 3.0.7 8.1.1 3.0.8 8.1.2 3.0.9 8.1.3 3.1.0 8.1.4 3.1.1 v1.4.1 3.1.2 3.1.4 3.1.6 3.2.1 3.2.3 3.2.4 3.2.5 3.2.6 3.2.7 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.4.1 3.4.4 3.4.5 3.5.1 3.5.2 3.6.1 3.6.3 3.6.4 3.6.5 3.6.6 3.6.7 3.6.8 3.6.9
wordfence / lib / wfDB.php
wordfence / lib Last commit date
Diff 8 years ago dashboard 7 years ago .htaccess 8 years ago Diff.php 14 years ago GeoLite2-Country.mmdb 7 years ago IPTraf.php 8 years ago IPTrafList.php 8 years ago compat.php 8 years ago conntest.php 7 years ago cronview.php 8 years ago dbview.php 8 years ago diffResult.php 8 years ago email_genericAlert.php 7 years ago email_newIssues.php 7 years ago email_unlockRequest.php 8 years ago email_unsubscribeRequest.php 7 years ago live_activity.php 8 years ago menu_dashboard.php 8 years ago menu_dashboard_options.php 8 years ago menu_firewall.php 8 years ago menu_firewall_blocking.php 7 years ago menu_firewall_blocking_options.php 8 years ago menu_firewall_waf.php 8 years ago menu_firewall_waf_options.php 8 years ago menu_options.php 7 years ago menu_scanner.php 8 years ago menu_scanner_credentials.php 8 years ago menu_scanner_options.php 8 years ago menu_support.php 7 years ago menu_tools.php 8 years ago menu_tools_commentSpam.php 8 years ago menu_tools_diagnostic.php 7 years ago menu_tools_livetraffic.php 7 years ago menu_tools_twoFactor.php 8 years ago menu_tools_whois.php 8 years ago sysinfo.php 8 years ago unknownFiles.php 8 years ago viewFullActivityLog.php 8 years ago wf503.php 7 years ago wfAPI.php 7 years ago wfActivityReport.php 7 years ago wfAdminNoticeQueue.php 8 years ago wfArray.php 7 years ago wfBrowscap.php 8 years ago wfBrowscapCache.php 8 years ago wfBulkCountries.php 8 years ago wfCache.php 9 years ago wfConfig.php 7 years ago wfCountryMap.php 8 years ago wfCrawl.php 8 years ago wfCredentialsController.php 8 years ago wfCrypt.php 8 years ago wfDB.php 8 years ago wfDashboard.php 8 years ago wfDateLocalization.php 8 years ago wfDiagnostic.php 8 years ago wfDict.php 8 years ago wfDirectoryIterator.php 7 years ago wfHelperBin.php 11 years ago wfHelperString.php 11 years ago wfIPWhitelist.php 9 years ago wfImportExportController.php 8 years ago wfIssues.php 7 years ago wfLockedOut.php 7 years ago wfLog.php 7 years ago wfMD5BloomFilter.php 8 years ago wfNotification.php 8 years ago wfOnboardingController.php 7 years ago wfPersistenceController.php 8 years ago wfRESTAPI.php 9 years ago wfScan.php 7 years ago wfScanEngine.php 7 years ago wfSchema.php 7 years ago wfStyle.php 8 years ago wfSupportController.php 7 years ago wfUnlockMsg.php 7 years ago wfUpdateCheck.php 8 years ago wfUtils.php 7 years ago wfVersionCheckController.php 8 years ago wfView.php 10 years ago wfViewResult.php 8 years ago wordfenceClass.php 7 years ago wordfenceConstants.php 7 years ago wordfenceHash.php 8 years ago wordfenceScanner.php 7 years ago wordfenceURLHoover.php 7 years ago
wfDB.php
311 lines
1 <?php
2 class wfDB {
3 public $errorMsg = false;
4
5 /**
6 * Returns the table prefix for the main site on multisites and the site itself on single site installations.
7 *
8 * @return string
9 */
10 public static function networkPrefix() {
11 global $wpdb;
12 return $wpdb->base_prefix;
13 }
14
15 /**
16 * Returns the table with the site (single site installations) or network (multisite) prefix added.
17 *
18 * @param string $table
19 * @return string
20 */
21 public static function networkTable($table) {
22 return self::networkPrefix() . $table;
23 }
24
25 /**
26 * Returns the table prefix for the given blog ID. On single site installations, this will be equivalent to wfDB::networkPrefix().
27 *
28 * @param int $blogID
29 * @return string
30 */
31 public static function blogPrefix($blogID) {
32 global $wpdb;
33 return $wpdb->get_blog_prefix($blogID);
34 }
35
36 /**
37 * Returns the table with the site (single site installations) or blog-specific (multisite) prefix added.
38 *
39 * @param string $table
40 * @return string
41 */
42 public static function blogTable($table, $blogID) {
43 return self::blogPrefix($blogID) . $table;
44 }
45
46 public function __construct(){
47 }
48 public function querySingle(){
49 global $wpdb;
50 if(func_num_args() > 1){
51 $args = func_get_args();
52 return $wpdb->get_var(call_user_func_array(array($wpdb, 'prepare'), $args));
53 } else {
54 return $wpdb->get_var(func_get_arg(0));
55 }
56 }
57 public function querySingleRec(){ //queryInSprintfFormat, arg1, arg2, ... :: Returns a single assoc-array or null if nothing found.
58 global $wpdb;
59 if(func_num_args() > 1){
60 $args = func_get_args();
61 return $wpdb->get_row(call_user_func_array(array($wpdb, 'prepare'), $args), ARRAY_A);
62 } else {
63 return $wpdb->get_row(func_get_arg(0), ARRAY_A);
64 }
65 }
66 public function queryWrite(){
67 global $wpdb;
68 if(func_num_args() > 1){
69 $args = func_get_args();
70 return $wpdb->query(call_user_func_array(array($wpdb, 'prepare'), $args));
71 } else {
72 return $wpdb->query(func_get_arg(0));
73 }
74 }
75 public function flush(){ //Clear cache
76 global $wpdb;
77 $wpdb->flush();
78 }
79 public function querySelect(){ //sprintfString, arguments :: always returns array() and will be empty if no results.
80 global $wpdb;
81 if(func_num_args() > 1){
82 $args = func_get_args();
83 return $wpdb->get_results(call_user_func_array(array($wpdb, 'prepare'), $args), ARRAY_A);
84 } else {
85 return $wpdb->get_results(func_get_arg(0), ARRAY_A);
86 }
87 }
88 public function queryWriteIgnoreError(){ //sprintfString, arguments
89 global $wpdb;
90 $oldSuppress = $wpdb->suppress_errors(true);
91 $args = func_get_args();
92 call_user_func_array(array($this, 'queryWrite'), $args);
93 $wpdb->suppress_errors($oldSuppress);
94 }
95 public function columnExists($table, $col){
96 $table = wfDB::networkTable($table);
97 $q = $this->querySelect("desc $table");
98 foreach($q as $row){
99 if($row['Field'] == $col){
100 return true;
101 }
102 }
103 return false;
104 }
105 public function dropColumn($table, $col){
106 $table = wfDB::networkTable($table);
107 $this->queryWrite("alter table $table drop column $col");
108 }
109 public function createKeyIfNotExists($table, $col, $keyName){
110 $table = wfDB::networkTable($table);
111
112 $exists = $this->querySingle(<<<SQL
113 SELECT TABLE_NAME FROM information_schema.TABLES
114 WHERE TABLE_SCHEMA=DATABASE()
115 AND TABLE_NAME='%s'
116 SQL
117 , $table);
118 $keyFound = false;
119 if($exists){
120 $q = $this->querySelect("show keys from $table");
121 foreach($q as $row){
122 if($row['Key_name'] == $keyName){
123 $keyFound = true;
124 }
125 }
126 }
127 if(! $keyFound){
128 $this->queryWrite("alter table $table add KEY $keyName($col)");
129 }
130 }
131 public function getMaxAllowedPacketBytes(){
132 $rec = $this->querySingleRec("show variables like 'max_allowed_packet'");
133 return intval($rec['Value']);
134 }
135 public function getMaxLongDataSizeBytes() {
136 $rec = $this->querySingleRec("show variables like 'max_long_data_size'");
137 return $rec['Value'];
138 }
139 public function truncate($table){ //Ensures everything is deleted if user is using MySQL >= 5.1.16 and does not have "drop" privileges
140 $this->queryWrite("truncate table $table");
141 $this->queryWrite("delete from $table");
142 }
143 public function getLastError(){
144 global $wpdb;
145 return $wpdb->last_error;
146 }
147 public function realEscape($str){
148 global $wpdb;
149 return $wpdb->_real_escape($str);
150 }
151 }
152
153 abstract class wfModel {
154
155 private $data;
156 private $db;
157 private $dirty = false;
158
159 /**
160 * Column name of the primary key field.
161 *
162 * @return string
163 */
164 abstract public function getIDColumn();
165
166 /**
167 * Table name.
168 *
169 * @return mixed
170 */
171 abstract public function getTable();
172
173 /**
174 * Checks if this is a valid column in the table before setting data on the model.
175 *
176 * @param string $column
177 * @return boolean
178 */
179 abstract public function hasColumn($column);
180
181 /**
182 * wfModel constructor.
183 * @param array|int|string $data
184 */
185 public function __construct($data = array()) {
186 if (is_array($data) || is_object($data)) {
187 $this->setData($data);
188 } else if (is_numeric($data)) {
189 $this->fetchByID($data);
190 }
191 }
192
193 public function fetchByID($id) {
194 $id = absint($id);
195 $data = $this->getDB()->get_row($this->getDB()->prepare('SELECT * FROM ' . $this->getTable() .
196 ' WHERE ' . $this->getIDColumn() . ' = %d', $id));
197 if ($data) {
198 $this->setData($data);
199 return true;
200 }
201 return false;
202 }
203
204 /**
205 * @return bool
206 */
207 public function save() {
208 if (!$this->dirty) {
209 return false;
210 }
211 $this->dirty = ($this->getPrimaryKey() ? $this->update() : $this->insert()) === false;
212 return !$this->dirty;
213 }
214
215 /**
216 * @return false|int
217 */
218 public function insert() {
219 $data = $this->getData();
220 unset($data[$this->getPrimaryKey()]);
221 $rowsAffected = $this->getDB()->insert($this->getTable(), $data);
222 $this->setPrimaryKey($this->getDB()->insert_id);
223 return $rowsAffected;
224 }
225
226 /**
227 * @return false|int
228 */
229 public function update() {
230 return $this->getDB()->update($this->getTable(), $this->getData(), array(
231 $this->getIDColumn() => $this->getPrimaryKey(),
232 ));
233 }
234
235 /**
236 * @param $name string
237 * @return mixed
238 */
239 public function __get($name) {
240 if (!$this->hasColumn($name)) {
241 return null;
242 }
243 return array_key_exists($name, $this->data) ? $this->data[$name] : null;
244 }
245
246 /**
247 * @param $name string
248 * @param $value mixed
249 */
250 public function __set($name, $value) {
251 if (!$this->hasColumn($name)) {
252 return;
253 }
254 $this->data[$name] = $value;
255 $this->dirty = true;
256 }
257
258 /**
259 * @return array
260 */
261 public function getData() {
262 return $this->data;
263 }
264
265 /**
266 * @param array $data
267 * @param bool $flagDirty
268 */
269 public function setData($data, $flagDirty = true) {
270 $this->data = array();
271 foreach ($data as $column => $value) {
272 if ($this->hasColumn($column)) {
273 $this->data[$column] = $value;
274 $this->dirty = (bool) $flagDirty;
275 }
276 }
277 }
278
279 /**
280 * @return wpdb
281 */
282 public function getDB() {
283 if ($this->db === null) {
284 global $wpdb;
285 $this->db = $wpdb;
286 }
287 return $this->db;
288 }
289
290 /**
291 * @param wpdb $db
292 */
293 public function setDB($db) {
294 $this->db = $db;
295 }
296
297 /**
298 * @return int
299 */
300 public function getPrimaryKey() {
301 return $this->{$this->getIDColumn()};
302 }
303
304 /**
305 * @param int $value
306 */
307 public function setPrimaryKey($value) {
308 $this->{$this->getIDColumn()} = $value;
309 }
310 }
311