Version Description
Download this release
Release Info
Developer | xknown |
Plugin | VaultPress |
Version | 1.2.7 |
Comparing to | |
See all releases |
Version 1.2.7
- class.vaultpress-database.php +140 -0
- class.vaultpress-filesystem.php +202 -0
- class.vaultpress-hotfixes.php +636 -0
- class.vaultpress-ixr-ssl-client.php +132 -0
- readme.txt +53 -0
- vaultpress.php +1828 -0
class.vaultpress-database.php
ADDED
@@ -0,0 +1,140 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class VaultPress_Database {
|
4 |
+
|
5 |
+
var $table = null;
|
6 |
+
var $pks = null;
|
7 |
+
|
8 |
+
function VaultPress_Database() {
|
9 |
+
$this->__construct();
|
10 |
+
}
|
11 |
+
|
12 |
+
function __construct() {
|
13 |
+
}
|
14 |
+
|
15 |
+
function attach( $table ) {
|
16 |
+
$this->table=$table;
|
17 |
+
}
|
18 |
+
|
19 |
+
function get_tables( $filter=null ) {
|
20 |
+
global $wpdb;
|
21 |
+
$rval = $wpdb->get_col( 'SHOW TABLES' );
|
22 |
+
if ( $filter )
|
23 |
+
$rval = preg_grep( $filter, $rval );
|
24 |
+
return $rval;
|
25 |
+
}
|
26 |
+
|
27 |
+
function show_create() {
|
28 |
+
global $wpdb;
|
29 |
+
if ( !$this->table )
|
30 |
+
return false;
|
31 |
+
$table = $wpdb->escape( $this->table );
|
32 |
+
$results = $wpdb->get_row( "SHOW CREATE TABLE `$table`" );
|
33 |
+
$want = 'Create Table';
|
34 |
+
if ( $results )
|
35 |
+
$results = $results->$want;
|
36 |
+
return $results;
|
37 |
+
}
|
38 |
+
|
39 |
+
function explain() {
|
40 |
+
global $wpdb;
|
41 |
+
if ( !$this->table )
|
42 |
+
return false;
|
43 |
+
$table = $wpdb->escape( $this->table );
|
44 |
+
return $wpdb->get_results( "EXPLAIN `$table`" );
|
45 |
+
}
|
46 |
+
|
47 |
+
function diff( $signatures ) {
|
48 |
+
global $wpdb;
|
49 |
+
if ( !is_array( $signatures ) || !count( $signatures ) )
|
50 |
+
return false;
|
51 |
+
if ( !$this->table )
|
52 |
+
return false;
|
53 |
+
$table = $wpdb->escape( $this->table );
|
54 |
+
$diff = array();
|
55 |
+
foreach ( $signatures as $where => $signature ) {
|
56 |
+
$pksig = md5( $where );
|
57 |
+
unset( $wpdb->queries );
|
58 |
+
$row = $wpdb->get_row( "SELECT * FROM `$table` WHERE $where" );
|
59 |
+
if ( !$row ) {
|
60 |
+
$diff[$pksig] = array ( 'change' => 'deleted', 'where' => $where );
|
61 |
+
continue;
|
62 |
+
}
|
63 |
+
$row = serialize( $row );
|
64 |
+
$hash = md5( $row );
|
65 |
+
if ( $hash != $signature )
|
66 |
+
$diff[$pksig] = array( 'change' => 'modified', 'where' => $where, 'signature' => $hash, 'row' => $row );
|
67 |
+
}
|
68 |
+
return $diff;
|
69 |
+
}
|
70 |
+
|
71 |
+
function count( $columns ) {
|
72 |
+
global $wpdb;
|
73 |
+
if ( !is_array( $columns ) || !count( $columns ) )
|
74 |
+
return false;
|
75 |
+
if ( !$this->table )
|
76 |
+
return false;
|
77 |
+
$table = $wpdb->escape( $this->table );
|
78 |
+
$column = $wpdb->escape( array_shift( $columns ) );
|
79 |
+
return $wpdb->get_var( "SELECT COUNT( $column ) FROM `$table`" );
|
80 |
+
}
|
81 |
+
|
82 |
+
function wpdb( $query, $function='get_results' ) {
|
83 |
+
global $wpdb;
|
84 |
+
|
85 |
+
if ( !is_callable( array( $wpdb, $function ) ) )
|
86 |
+
return false;
|
87 |
+
|
88 |
+
$res = $wpdb->$function( $query );
|
89 |
+
if ( !$res )
|
90 |
+
return $res;
|
91 |
+
switch ( $function ) {
|
92 |
+
case 'get_results':
|
93 |
+
foreach ( $res as $idx => $row ) {
|
94 |
+
if ( isset( $row->option_name ) && $row->option_name == 'cron' )
|
95 |
+
$res[$idx]->option_value = serialize( array() );
|
96 |
+
}
|
97 |
+
break;
|
98 |
+
case 'get_row':
|
99 |
+
if ( isset( $res->option_name ) && $res->option_name == 'cron' )
|
100 |
+
$res->option_value = serialize( array() );
|
101 |
+
break;
|
102 |
+
}
|
103 |
+
return $res;
|
104 |
+
}
|
105 |
+
|
106 |
+
function get_cols( $columns, $limit=false, $offset=false, $where=false ) {
|
107 |
+
global $wpdb;
|
108 |
+
if ( !is_array( $columns ) || !count( $columns ) )
|
109 |
+
return false;
|
110 |
+
if ( !$this->table )
|
111 |
+
return false;
|
112 |
+
$table = $wpdb->escape( $this->table );
|
113 |
+
$limitsql = '';
|
114 |
+
$offsetsql = '';
|
115 |
+
$wheresql = '';
|
116 |
+
if ( $limit )
|
117 |
+
$limitsql = ' LIMIT ' . intval( $limit );
|
118 |
+
if ( $offset )
|
119 |
+
$offsetsql = ' OFFSET ' . intval( $offset );
|
120 |
+
if ( $where )
|
121 |
+
$wheresql = ' WHERE ' . base64_decode($where);
|
122 |
+
$rval = array();
|
123 |
+
foreach ( $wpdb->get_results( "SELECT * FROM `$this->table` $wheresql $limitsql $offsetsql" ) as $row ) {
|
124 |
+
// We don't need to actually record a real cron option value, just an empty array
|
125 |
+
if ( isset( $row->option_name ) && $row->option_name == 'cron' )
|
126 |
+
$row->option_value = serialize( array() );
|
127 |
+
$keys = array();
|
128 |
+
$vals = array();
|
129 |
+
foreach ( get_object_vars( $row ) as $i => $v ) {
|
130 |
+
$keys[] = sprintf( "`%s`", $wpdb->escape( $i ) );
|
131 |
+
$vals[] = sprintf( "'%s'", $wpdb->escape( $v ) );
|
132 |
+
if ( !in_array( $i, $columns ) )
|
133 |
+
unset( $row->$i );
|
134 |
+
}
|
135 |
+
$row->hash = md5( sprintf( "(%s) VALUES(%s)", implode( ',',$keys ), implode( ',',$vals ) ) );
|
136 |
+
$rval[]=$row;
|
137 |
+
}
|
138 |
+
return $rval;
|
139 |
+
}
|
140 |
+
}
|
class.vaultpress-filesystem.php
ADDED
@@ -0,0 +1,202 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class VaultPress_Filesystem {
|
4 |
+
|
5 |
+
var $type = null;
|
6 |
+
var $dir = null;
|
7 |
+
var $keys = array( 'ino', 'uid', 'gid', 'size', 'mtime', 'blksize', 'blocks' );
|
8 |
+
|
9 |
+
function VaultPress_Filesystem() {
|
10 |
+
$this->__construct();
|
11 |
+
}
|
12 |
+
|
13 |
+
function __construct() {
|
14 |
+
}
|
15 |
+
|
16 |
+
function want( $type ) {
|
17 |
+
$vp = VaultPress::init();
|
18 |
+
|
19 |
+
if ( $type == 'plugins' ) {
|
20 |
+
$this->dir = realpath( $vp->resolve_content_dir() . 'plugins' );
|
21 |
+
$this->type = 'p';
|
22 |
+
return true;
|
23 |
+
}
|
24 |
+
if ( $type == 'themes' ) {
|
25 |
+
$this->dir = realpath( $vp->resolve_content_dir() . 'themes' );
|
26 |
+
$this->type = 't';
|
27 |
+
return true;
|
28 |
+
}
|
29 |
+
if ( $type == 'uploads' ) {
|
30 |
+
$this->dir = realpath( $vp->resolve_upload_path() );
|
31 |
+
$this->type = 'u';
|
32 |
+
return true;
|
33 |
+
}
|
34 |
+
if ( $type == 'content' ) {
|
35 |
+
$this->dir = realpath( $vp->resolve_content_dir() );
|
36 |
+
$this->type = 'c';
|
37 |
+
return true;
|
38 |
+
}
|
39 |
+
if ( $type == 'root' ) {
|
40 |
+
$this->dir = realpath( ABSPATH );
|
41 |
+
$this->type = 'r';
|
42 |
+
return true;
|
43 |
+
}
|
44 |
+
die( 'naughty naughty' );
|
45 |
+
}
|
46 |
+
|
47 |
+
function fdump( $file ) {
|
48 |
+
header("Content-Type: application/octet-stream;");
|
49 |
+
header("Content-Transfer-Encoding: binary");
|
50 |
+
@ob_end_clean();
|
51 |
+
if ( !file_exists( $file ) || !is_readable( $file ) )
|
52 |
+
die( "no such file" );
|
53 |
+
if ( !is_file( $file ) && !is_link( $file ) )
|
54 |
+
die( "can only dump files" );
|
55 |
+
$fp = @fopen( $file, 'rb' );
|
56 |
+
if ( !$fp )
|
57 |
+
die( "could not open file" );
|
58 |
+
while ( !feof( $fp ) )
|
59 |
+
echo @fread( $fp, 8192 );
|
60 |
+
@fclose( $fp );
|
61 |
+
die();
|
62 |
+
}
|
63 |
+
|
64 |
+
function stat( $file, $md5=true, $sha1=true ) {
|
65 |
+
$rval = array();
|
66 |
+
foreach ( stat( $file ) as $i => $v ) {
|
67 |
+
if ( is_numeric( $i ) )
|
68 |
+
continue;
|
69 |
+
$rval[$i] = $v;
|
70 |
+
}
|
71 |
+
$rval['type'] = filetype( $file );
|
72 |
+
if ( $rval['type'] == 'file' ) {
|
73 |
+
if ( $md5 )
|
74 |
+
$rval['md5'] = md5_file( $file );
|
75 |
+
if ( $sha1 )
|
76 |
+
$rval['sha1'] = sha1_file( $file );
|
77 |
+
}
|
78 |
+
$rval['path'] = str_replace( $this->dir, '', $file );
|
79 |
+
return $rval;
|
80 |
+
}
|
81 |
+
|
82 |
+
function ls( $what, $md5=false, $sha1=false, $limit=null, $offset=null ) {
|
83 |
+
clearstatcache();
|
84 |
+
$path = realpath($this->dir . $what);
|
85 |
+
if ( is_file($path) )
|
86 |
+
return $this->stat( $path, $md5, $sha1 );
|
87 |
+
if ( is_dir($path) ) {
|
88 |
+
$entries = array();
|
89 |
+
$current = 0;
|
90 |
+
$offset = (int)$offset;
|
91 |
+
$limit = $offset + (int)$limit;
|
92 |
+
foreach ( (array)$this->scan_dir( $path ) as $i ) {
|
93 |
+
$current++;
|
94 |
+
if ( $offset >= $current )
|
95 |
+
continue;
|
96 |
+
if ( $limit && $limit < $current )
|
97 |
+
break;
|
98 |
+
$entries[] = $this->stat( $i, $md5, $sha1 );
|
99 |
+
}
|
100 |
+
return $entries;
|
101 |
+
}
|
102 |
+
}
|
103 |
+
|
104 |
+
function validate( $file ) {
|
105 |
+
$rpath = realpath( $this->dir.$file );
|
106 |
+
if ( !$rpath )
|
107 |
+
die( serialize( array( 'type' => 'null', 'path' => $file ) ) );
|
108 |
+
if ( is_dir( $rpath ) )
|
109 |
+
$rpath = "$rpath/";
|
110 |
+
if ( strpos( $rpath, $this->dir ) !== 0 )
|
111 |
+
return false;
|
112 |
+
return true;
|
113 |
+
}
|
114 |
+
|
115 |
+
function dir_examine( $subdir='', $recursive=true, $origin=false ) {
|
116 |
+
$res = array();
|
117 |
+
if ( !$subdir )
|
118 |
+
$subdir='/';
|
119 |
+
$dir = $this->dir . $subdir;
|
120 |
+
if ( $origin === false )
|
121 |
+
$origin = $this->dir . $subdir;
|
122 |
+
if ( is_file($dir) ) {
|
123 |
+
if ( $origin == $dir )
|
124 |
+
$name = str_replace( $this->dir, '/', $subdir );
|
125 |
+
else
|
126 |
+
$name = str_replace( $origin, '/', $dir );
|
127 |
+
$res[$name] = $this->stat( $dir.$entry );
|
128 |
+
return $res;
|
129 |
+
}
|
130 |
+
$d = dir( $dir );
|
131 |
+
if ( !$d )
|
132 |
+
return $res;
|
133 |
+
while ( false !== ( $entry = $d->read() ) ) {
|
134 |
+
$rpath = realpath( $dir.$entry );
|
135 |
+
$bname = basename( $rpath );
|
136 |
+
if ( is_link( $dir.$entry ) )
|
137 |
+
continue;
|
138 |
+
if ( $entry == '.' || $entry == '..' || $entry == '...' )
|
139 |
+
continue;
|
140 |
+
if ( !$this->validate( $subdir.$entry ) )
|
141 |
+
continue;
|
142 |
+
$name = str_replace( $origin, '/', $dir.$entry );
|
143 |
+
$res[$name] = $this->stat( $dir.$entry );
|
144 |
+
if ( $recursive && is_dir( $this->dir.$subdir.'/'.$entry ) ) {
|
145 |
+
$res = array_merge( $res, $this->dir_examine( $subdir.$entry.'/', $recursive, $origin ) );
|
146 |
+
}
|
147 |
+
}
|
148 |
+
return $res;
|
149 |
+
}
|
150 |
+
|
151 |
+
function dir_checksum( $base, &$list, $recursive=true ) {
|
152 |
+
if ( $list == null )
|
153 |
+
$list = array();
|
154 |
+
|
155 |
+
if ( 0 !== strpos( $base, $this->dir ) )
|
156 |
+
$base = $this->dir . rtrim( $base, '/' );
|
157 |
+
|
158 |
+
$shortbase = substr( $base, strlen( $this->dir ) );
|
159 |
+
if ( !$shortbase )
|
160 |
+
$shortbase = '/';
|
161 |
+
$stat = stat( $base );
|
162 |
+
$directories = array();
|
163 |
+
$files = (array)$this->scan_dir( $base );
|
164 |
+
array_push( $files, $base );
|
165 |
+
foreach ( $files as $file ) {
|
166 |
+
if ( $file !== $base && @is_dir( $file ) ) {
|
167 |
+
$directories[] = $file;
|
168 |
+
continue;
|
169 |
+
}
|
170 |
+
$stat = @stat( $file );
|
171 |
+
if ( !$stat )
|
172 |
+
continue;
|
173 |
+
$shortstat = array();
|
174 |
+
foreach( $this->keys as $key ) {
|
175 |
+
if ( isset( $stat[$key] ) )
|
176 |
+
$shortstat[$key] = $stat[$key];
|
177 |
+
}
|
178 |
+
$list[$shortbase][basename( $file )] = $shortstat;
|
179 |
+
}
|
180 |
+
$list[$shortbase] = md5( serialize( $list[$shortbase] ) );
|
181 |
+
if ( !$recursive )
|
182 |
+
return $list;
|
183 |
+
foreach ( $directories as $dir ) {
|
184 |
+
$this->dir_checksum( $dir, $list, $recursive );
|
185 |
+
}
|
186 |
+
return $list;
|
187 |
+
}
|
188 |
+
|
189 |
+
function scan_dir( $path ) {
|
190 |
+
$files = array();
|
191 |
+
$dh = opendir( $path );
|
192 |
+
|
193 |
+
while ( false !== ( $file = readdir( $dh ) ) ) {
|
194 |
+
if ( $file == '.' || $file == '..' ) continue;
|
195 |
+
$files[] = "$path/$file";
|
196 |
+
}
|
197 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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class VaultPress_Hotfixes {
|
4 |
+
function VaultPress_Hotfixes() {
|
5 |
+
$this->__construct();
|
6 |
+
}
|
7 |
+
|
8 |
+
function __construct() {
|
9 |
+
global $wp_version;
|
10 |
+
|
11 |
+
if ( version_compare( $wp_version, '3.0.2', '<' ) )
|
12 |
+
add_filter( 'query', array( $this, 'r16625' ) );
|
13 |
+
|
14 |
+
if ( defined( 'XMLRPC_REQUEST' ) && XMLRPC_REQUEST && version_compare( $wp_version, '3.0.3', '<' ) )
|
15 |
+
add_action( 'xmlrpc_call', array( $this, 'r16803' ) );
|
16 |
+
|
17 |
+
if ( version_compare( $wp_version, '3.0.4', '<' ) ) {
|
18 |
+
add_filter( 'pre_kses', array( $this, 'r17172_wp_kses' ), 1, 3 );
|
19 |
+
add_filter( 'clean_url', array( $this, 'r17172_esc_url' ), 1, 3 );
|
20 |
+
}
|
21 |
+
|
22 |
+
if ( version_compare( $wp_version, '3.1.3', '<' ) ) {
|
23 |
+
add_filter( 'sanitize_file_name', array( $this, 'r17990' ) );
|
24 |
+
|
25 |
+
if ( !empty( $_POST ) )
|
26 |
+
$this->r17994( $_POST );
|
27 |
+
// Protect add_meta, update_meta used by the XML-RPC API
|
28 |
+
add_filter( 'wp_xmlrpc_server_class', create_function( '$class', 'return \'VaultPress_XMLRPC_Server_r17994\';' ) );
|
29 |
+
|
30 |
+
// clean post_mime_type and guid (r17994)
|
31 |
+
add_filter( 'pre_post_mime_type', array( $this, 'r17994_sanitize_mime_type' ) );
|
32 |
+
add_filter( 'post_mime_type', array( $this, 'r17994_sanitize_mime_type' ) );
|
33 |
+
add_filter( 'pre_post_guid', 'esc_url_raw' );
|
34 |
+
add_filter( 'post_guid', 'esc_url' );
|
35 |
+
}
|
36 |
+
|
37 |
+
if ( version_compare( $wp_version, '3.1.4', '<' ) ) {
|
38 |
+
add_filter( 'wp_insert_post_data', array( $this, 'r18368' ), 1, 2 );
|
39 |
+
|
40 |
+
// Add click jacking protection
|
41 |
+
// login_init does not exist before 17826.
|
42 |
+
$action = isset( $_REQUEST['action'] ) ? $_REQUEST['action'] : 'login';
|
43 |
+
add_action( 'login_form_' . $action, array( $this, 'r17826_send_frame_options_header' ), 10, 0 );
|
44 |
+
add_action( 'admin_init', array( $this, 'r17826_send_frame_options_header' ), 10, 0 );
|
45 |
+
|
46 |
+
add_filter( 'sanitize_option_WPLANG', array( $this, 'r18346_sanitize_lang_on_save' ) );
|
47 |
+
add_filter( 'sanitize_option_new_admin_email', array( $this, 'r18346_sanitize_admin_email_on_save' ) );
|
48 |
+
}
|
49 |
+
add_filter( 'option_new_admin_email', array( $this, 'r18346_sanitize_admin_email' ) );
|
50 |
+
}
|
51 |
+
|
52 |
+
function r16625( $query ) {
|
53 |
+
// Hotfixes: http://core.trac.wordpress.org/changeset/16625
|
54 |
+
|
55 |
+
// Punt as fast as possible if this isn't an UPDATE
|
56 |
+
if ( substr( $query, 0, 6 ) != "UPDATE" )
|
57 |
+
return $query;
|
58 |
+
global $wpdb;
|
59 |
+
|
60 |
+
// Determine what the prefix of the bad query would look like and punt if this query doesn't match
|
61 |
+
$badstring = "UPDATE $wpdb->posts SET to_ping = TRIM(REPLACE(to_ping, '";
|
62 |
+
if ( substr( $query, 0, strlen( $badstring ) ) != $badstring )
|
63 |
+
return $query;
|
64 |
+
|
65 |
+
// Pull the post_id which is the last thing in the origin query, after a space, no quotes
|
66 |
+
$post_id = array_pop( explode( " ", $query ) );
|
67 |
+
|
68 |
+
// Chop off the beginning and end of the original query to get our unsanitized $tb_ping
|
69 |
+
$tb_ping = substr(
|
70 |
+
$query,
|
71 |
+
strlen( $badstring ),
|
72 |
+
(
|
73 |
+
strlen( $query ) - (
|
74 |
+
strlen( $badstring ) + strlen( sprintf( "', '')) WHERE ID = %d", $post_id ) )
|
75 |
+
)
|
76 |
+
)
|
77 |
+
);
|
78 |
+
|
79 |
+
// Return the fixed query
|
80 |
+
return $wpdb->prepare( "UPDATE $wpdb->posts SET to_ping = TRIM(REPLACE(to_ping, %s, '')) WHERE ID = %d", $tb_ping, $post_id );
|
81 |
+
}
|
82 |
+
|
83 |
+
function r16803( $xmlrpc_method ) {
|
84 |
+
// Hotfixes: http://core.trac.wordpress.org/changeset/16803
|
85 |
+
global $wp_xmlrpc_server;
|
86 |
+
// Pretend that we are an xmlrpc method, freshly called
|
87 |
+
$args = $wp_xmlrpc_server->message->params;
|
88 |
+
$error_code = 401;
|
89 |
+
switch( $xmlrpc_method ) {
|
90 |
+
case 'metaWeblog.newPost':
|
91 |
+
$content_struct = $args[3];
|
92 |
+
$publish = isset( $args[4] ) ? $args[4] : 0;
|
93 |
+
if ( !empty( $content_struct['post_type'] ) ) {
|
94 |
+
if ( $content_struct['post_type'] == 'page' ) {
|
95 |
+
if ( $publish || 'publish' == $content_struct['page_status'] )
|
96 |
+
$cap = 'publish_pages';
|
97 |
+
else
|
98 |
+
$cap = 'edit_pages';
|
99 |
+
$error_message = __( 'Sorry, you are not allowed to publish pages on this site.' );
|
100 |
+
} elseif ( $content_struct['post_type'] == 'post' ) {
|
101 |
+
if ( $publish || 'publish' == $content_struct['post_status'] )
|
102 |
+
$cap = 'publish_posts';
|
103 |
+
else
|
104 |
+
$cap = 'edit_posts';
|
105 |
+
$error_message = __( 'Sorry, you are not allowed to publish posts on this site.' );
|
106 |
+
} else {
|
107 |
+
$error_message = __( 'Invalid post type.' );
|
108 |
+
}
|
109 |
+
} else {
|
110 |
+
if ( $publish || 'publish' == $content_struct['post_status'] )
|
111 |
+
$cap = 'publish_posts';
|
112 |
+
else
|
113 |
+
$cap = 'edit_posts';
|
114 |
+
$error_message = __( 'Sorry, you are not allowed to publish posts on this site.' );
|
115 |
+
}
|
116 |
+
if ( current_user_can( $cap ) )
|
117 |
+
return true;
|
118 |
+
break;
|
119 |
+
case 'metaWeblog.editPost':
|
120 |
+
$post_ID = (int) $args[0];
|
121 |
+
$content_struct = $args[3];
|
122 |
+
$publish = $args[4];
|
123 |
+
$cap = ( $publish ) ? 'publish_posts' : 'edit_posts';
|
124 |
+
$error_message = __( 'Sorry, you are not allowed to publish posts on this site.' );
|
125 |
+
if ( !empty( $content_struct['post_type'] ) ) {
|
126 |
+
if ( $content_struct['post_type'] == 'page' ) {
|
127 |
+
if ( $publish || 'publish' == $content_struct['page_status'] )
|
128 |
+
$cap = 'publish_pages';
|
129 |
+
else
|
130 |
+
$cap = 'edit_pages';
|
131 |
+
$error_message = __( 'Sorry, you are not allowed to publish pages on this site.' );
|
132 |
+
} elseif ( $content_struct['post_type'] == 'post' ) {
|
133 |
+
if ( $publish || 'publish' == $content_struct['post_status'] )
|
134 |
+
$cap = 'publish_posts';
|
135 |
+
else
|
136 |
+
$cap = 'edit_posts';
|
137 |
+
$error_message = __( 'Sorry, you are not allowed to publish posts on this site.' );
|
138 |
+
} else {
|
139 |
+
$error_message = __( 'Invalid post type.' );
|
140 |
+
}
|
141 |
+
} else {
|
142 |
+
if ( $publish || 'publish' == $content_struct['post_status'] )
|
143 |
+
$cap = 'publish_posts';
|
144 |
+
else
|
145 |
+
$cap = 'edit_posts';
|
146 |
+
$error_message = __( 'Sorry, you are not allowed to publish posts on this site.' );
|
147 |
+
}
|
148 |
+
if ( current_user_can( $cap ) )
|
149 |
+
return true;
|
150 |
+
break;
|
151 |
+
case 'mt.publishPost':
|
152 |
+
$post_ID = (int) $args[0];
|
153 |
+
if ( current_user_can( 'publish_posts' ) && current_user_can( 'edit_post', $post_ID ) )
|
154 |
+
return true;
|
155 |
+
$error_message = __( 'Sorry, you cannot edit this post.' );
|
156 |
+
break;
|
157 |
+
case 'blogger.deletePost':
|
158 |
+
$post_ID = (int) $args[1];
|
159 |
+
if ( current_user_can( 'delete_post', $post_ID ) )
|
160 |
+
return true;
|
161 |
+
$error_message = __( 'Sorry, you do not have the right to delete this post.' );
|
162 |
+
break;
|
163 |
+
case 'wp.getPageStatusList':
|
164 |
+
if ( current_user_can( 'edit_pages' ) )
|
165 |
+
return true;
|
166 |
+
$error_code = 403;
|
167 |
+
$error_message = __( 'You are not allowed access to details about this site.' );
|
168 |
+
break;
|
169 |
+
case 'wp.deleteComment':
|
170 |
+
case 'wp.editComment':
|
171 |
+
$comment_ID = (int) $args[3];
|
172 |
+
if ( !$comment = get_comment( $comment_ID ) )
|
173 |
+
return true; // This will be handled in the calling function explicitly
|
174 |
+
if ( current_user_can( 'edit_post', $comment->comment_post_ID ) )
|
175 |
+
return true;
|
176 |
+
$error_code = 403;
|
177 |
+
$error_message = __( 'You are not allowed to moderate comments on this site.' );
|
178 |
+
break;
|
179 |
+
default:
|
180 |
+
return true;
|
181 |
+
}
|
182 |
+
// If we are here then this was a handlable xmlrpc call and the capability checks above all failed
|
183 |
+
// ( otherwise they would have returned to the do_action from the switch statement above ) so it's
|
184 |
+
// time to exit with whatever error we've determined is the problem (thus short circuiting the
|
185 |
+
// original XMLRPC method call, and enforcing the above capability checks -- with an ax. We'll
|
186 |
+
// mimic the behavior from the end of IXR_Server::serve()
|
187 |
+
$r = new IXR_Error( $error_code, $error_message );
|
188 |
+
$resultxml = $r->getXml();
|
189 |
+
$xml = <<<EOD
|
190 |
+
<methodResponse>
|
191 |
+
<params>
|
192 |
+
<param>
|
193 |
+
<value>
|
194 |
+
$resultxml
|
195 |
+
</value>
|
196 |
+
</param>
|
197 |
+
</params>
|
198 |
+
</methodResponse>
|
199 |
+
EOD;
|
200 |
+
$wp_xmlrpc_server->output( $xml );
|
201 |
+
// For good measure...
|
202 |
+
die();
|
203 |
+
}
|
204 |
+
|
205 |
+
function r17172_esc_url( $url, $original_url, $_context ) {
|
206 |
+
$url = $original_url;
|
207 |
+
if ( '' == $url )
|
208 |
+
return $url;
|
209 |
+
$url = preg_replace('|[^a-z0-9-~+_.?#=!&;,/:%@$\|*\'()\\x80-\\xff]|i', '', $url);
|
210 |
+
$strip = array('%0d', '%0a', '%0D', '%0A');
|
211 |
+
$url = _deep_replace($strip, $url);
|
212 |
+
$url = str_replace(';//', '://', $url);
|
213 |
+
if ( strpos($url, ':') === false &&
|
214 |
+
substr( $url, 0, 1 ) != '/' && substr( $url, 0, 1 ) != '#' && !preg_match('/^[a-z0-9-]+?\.php/i', $url) )
|
215 |
+
$url = 'http://' . $url;
|
216 |
+
// Replace ampersands and single quotes only when displaying.
|
217 |
+
if ( 'display' == $_context ) {
|
218 |
+
$url = wp_kses_normalize_entities( $url );
|
219 |
+
$url = str_replace( '&', '&', $url );
|
220 |
+
$url = str_replace( "'", ''', $url );
|
221 |
+
}
|
222 |
+
|
223 |
+
$protocols = array ('http', 'https', 'ftp', 'ftps', 'mailto', 'news', 'irc', 'gopher', 'nntp', 'feed', 'telnet', 'mms', 'rtsp', 'svn');
|
224 |
+
if ( VaultPress_kses::wp_kses_bad_protocol( $url, $protocols ) != $url )
|
225 |
+
return '';
|
226 |
+
return $url;
|
227 |
+
}
|
228 |
+
|
229 |
+
function r17172_wp_kses( $string, $html, $protocols ) {
|
230 |
+
return VaultPress_kses::wp_kses( $string, $html, $protocols );
|
231 |
+
}
|
232 |
+
|
233 |
+
// http://core.trac.wordpress.org/changeset/17990
|
234 |
+
function r17990( $filename ) {
|
235 |
+
$parts = explode('.', $filename);
|
236 |
+
$filename = array_shift($parts);
|
237 |
+
$extension = array_pop($parts);
|
238 |
+
$mimes = get_allowed_mime_types();
|
239 |
+
|
240 |
+
// Loop over any intermediate extensions. Munge them with a trailing underscore if they are a 2 - 5 character
|
241 |
+
// long alpha string not in the extension whitelist.
|
242 |
+
foreach ( (array) $parts as $part) {
|
243 |
+
$filename .= '.' . $part;
|
244 |
+
|
245 |
+
if ( preg_match("/^[a-zA-Z]{2,5}\d?$/", $part) ) {
|
246 |
+
$allowed = false;
|
247 |
+
foreach ( $mimes as $ext_preg => $mime_match ) {
|
248 |
+
$ext_preg = '!^(' . $ext_preg . ')$!i';
|
249 |
+
if ( preg_match( $ext_preg, $part ) ) {
|
250 |
+
$allowed = true;
|
251 |
+
break;
|
252 |
+
}
|
253 |
+
}
|
254 |
+
if ( !$allowed )
|
255 |
+
$filename .= '_';
|
256 |
+
}
|
257 |
+
}
|
258 |
+
$filename .= '.' . $extension;
|
259 |
+
return $filename;
|
260 |
+
}
|
261 |
+
|
262 |
+
/*
|
263 |
+
* Hotfixes: http://core.trac.wordpress.org/changeset/18368
|
264 |
+
*/
|
265 |
+
function r18368( $post, $raw_post ) {
|
266 |
+
if ( isset( $post['filter'] ) || isset ( $raw_post['filter'] ) ) {
|
267 |
+
unset( $post['filter'], $raw_post['filter'] ); // to ensure the post is properly sanitized
|
268 |
+
$post = sanitize_post($post, 'db');
|
269 |
+
}
|
270 |
+
if ( empty( $post['ID'] ) )
|
271 |
+
unset( $post['ID'] ); // sanitize_post
|
272 |
+
unset( $post['filter'] ); // sanitize_post
|
273 |
+
return $post;
|
274 |
+
}
|
275 |
+
|
276 |
+
/**
|
277 |
+
* Protect WordPress internal metadata.
|
278 |
+
*
|
279 |
+
* The post data is passed as a parameter to (unit) test this method.
|
280 |
+
* @param $post_data|array the $_POST array.
|
281 |
+
*/
|
282 |
+
function r17994( &$post_data ) {
|
283 |
+
// Protect admin-ajax add_meta
|
284 |
+
$metakeyselect = isset( $post_data['metakeyselect'] ) ? stripslashes( trim( $post_data['metakeyselect'] ) ) : '';
|
285 |
+
$metakeyinput = isset( $post_data['metakeyinput'] ) ? stripslashes( trim( $post_data['metakeyinput'] ) ) : '';
|
286 |
+
|
287 |
+
if ( ( $metakeyselect && '_' == $metakeyselect[0] ) || ( $metakeyinput && '_' == $metakeyinput[0] ) ) {
|
288 |
+
unset( $_POST['metakeyselect'], $_POST['metakeyinput'] );
|
289 |
+
}
|
290 |
+
|
291 |
+
// Protect admin-ajax update_meta
|
292 |
+
if ( isset( $post_data['meta'] ) ) {
|
293 |
+
foreach ( (array)$post_data['meta'] as $mid => $value ) {
|
294 |
+
$key = stripslashes( $post_data['meta'][$mid]['key'] );
|
295 |
+
if ( $key && '_' == $key[0] )
|
296 |
+
unset( $post_data['meta'][$mid] );
|
297 |
+
}
|
298 |
+
}
|
299 |
+
}
|
300 |
+
|
301 |
+
function r17994_sanitize_mime_type( $mime_type ) {
|
302 |
+
$sani_mime_type = preg_replace( '/[^\-*.a-zA-Z0-9\/+]/', '', $mime_type );
|
303 |
+
return apply_filters( 'sanitize_mime_type', $sani_mime_type, $mime_type );
|
304 |
+
}
|
305 |
+
|
306 |
+
function r17826_send_frame_options_header() {
|
307 |
+
@header( 'X-Frame-Options: SAMEORIGIN' );
|
308 |
+
}
|
309 |
+
|
310 |
+
function r18346_sanitize_admin_email_on_save($value) {
|
311 |
+
$value = sanitize_email( $value );
|
312 |
+
if ( !is_email( $value ) ) {
|
313 |
+
$value = get_option( 'new_admin_email' ); // Resets option to stored value in the case of failed sanitization
|
314 |
+
if ( function_exists( 'add_settings_error' ) )
|
315 |
+
add_settings_error( 'new_admin_email', 'invalid_admin_email', __( 'The email address entered did not appear to be a valid email address. Please enter a valid email address.' ) );
|
316 |
+
}
|
317 |
+
return $value;
|
318 |
+
}
|
319 |
+
|
320 |
+
function r18346_sanitize_admin_email( $value ) {
|
321 |
+
return sanitize_email( $value ); // Is it enough ?
|
322 |
+
}
|
323 |
+
|
324 |
+
function r18346_sanitize_lang_on_save( $value ) {
|
325 |
+
$value = $this->r18346_sanitize_lang( $value ); // sanitize the new value.
|
326 |
+
if ( empty( $value ) )
|
327 |
+
$value = get_option( 'WPLANG' );
|
328 |
+
return $value;
|
329 |
+
}
|
330 |
+
|
331 |
+
function r18346_sanitize_lang( $value ) {
|
332 |
+
$allowed = apply_filters( 'available_languages', get_available_languages() ); // add a filter to unit test
|
333 |
+
if ( !empty( $value ) && !in_array( $value, $allowed ) )
|
334 |
+
return false;
|
335 |
+
else
|
336 |
+
return $value;
|
337 |
+
}
|
338 |
+
}
|
339 |
+
|
340 |
+
$needs_class_fix = version_compare( $wp_version, '3.1', '>=') && version_compare( $wp_version, '3.1.3', '<' );
|
341 |
+
if ( defined( 'XMLRPC_REQUEST' ) && XMLRPC_REQUEST && $needs_class_fix ) {
|
342 |
+
include_once( ABSPATH . WPINC . '/class-IXR.php' );
|
343 |
+
include_once( ABSPATH . WPINC . '/class-wp-xmlrpc-server.php' );
|
344 |
+
|
345 |
+
class VaultPress_XMLRPC_Server_r17994 extends wp_xmlrpc_server {
|
346 |
+
function set_custom_fields( $post_id, $fields ) {
|
347 |
+
foreach( $fields as $k => $meta ) {
|
348 |
+
$key = stripslashes( trim( $meta['key'] ) );
|
349 |
+
if ( $key && '_' == $key[0] )
|
350 |
+
unset( $fields[$k] );
|
351 |
+
}
|
352 |
+
parent::set_custom_fields( $post_id, $fields );
|
353 |
+
}
|
354 |
+
}
|
355 |
+
}
|
356 |
+
|
357 |
+
class VaultPress_kses {
|
358 |
+
static function wp_kses($string, $allowed_html, $allowed_protocols = array ()) {
|
359 |
+
$string = wp_kses_no_null($string);
|
360 |
+
$string = wp_kses_js_entities($string);
|
361 |
+
$string = wp_kses_normalize_entities($string);
|
362 |
+
return VaultPress_kses::wp_kses_split($string, $allowed_html, $allowed_protocols);
|
363 |
+
}
|
364 |
+
|
365 |
+
static function wp_kses_split($string, $allowed_html, $allowed_protocols) {
|
366 |
+
global $pass_allowed_html, $pass_allowed_protocols;
|
367 |
+
$pass_allowed_html = $allowed_html;
|
368 |
+
$pass_allowed_protocols = $allowed_protocols;
|
369 |
+
return preg_replace_callback( '%((<!--.*?(-->|$))|(<[^>]*(>|$)|>))%', 'VaultPress_kses::_vp_kses_split_callback', $string );
|
370 |
+
}
|
371 |
+
|
372 |
+
static function _vp_kses_split_callback( $match ) {
|
373 |
+
global $pass_allowed_html, $pass_allowed_protocols;
|
374 |
+
return VaultPress_kses::wp_kses_split2( $match[1], $pass_allowed_html, $pass_allowed_protocols );
|
375 |
+
}
|
376 |
+
|
377 |
+
static function wp_kses_split2($string, $allowed_html, $allowed_protocols) {
|
378 |
+
$string = wp_kses_stripslashes($string);
|
379 |
+
|
380 |
+
if (substr($string, 0, 1) != '<')
|
381 |
+
return '>';
|
382 |
+
# It matched a ">" character
|
383 |
+
|
384 |
+
if (preg_match('%^<!--(.*?)(-->)?$%', $string, $matches)) {
|
385 |
+
$string = str_replace(array('<!--', '-->'), '', $matches[1]);
|
386 |
+
while ( $string != $newstring = VaultPress_kses::wp_kses($string, $allowed_html, $allowed_protocols) )
|
387 |
+
$string = $newstring;
|
388 |
+
if ( $string == '' )
|
389 |
+
return '';
|
390 |
+
// prevent multiple dashes in comments
|
391 |
+
$string = preg_replace('/--+/', '-', $string);
|
392 |
+
// prevent three dashes closing a comment
|
393 |
+
$string = preg_replace('/-$/', '', $string);
|
394 |
+
return "<!--{$string}-->";
|
395 |
+
}
|
396 |
+
# Allow HTML comments
|
397 |
+
|
398 |
+
if (!preg_match('%^<\s*(/\s*)?([a-zA-Z0-9]+)([^>]*)>?$%', $string, $matches))
|
399 |
+
return '';
|
400 |
+
# It's seriously malformed
|
401 |
+
|
402 |
+
$slash = trim($matches[1]);
|
403 |
+
$elem = $matches[2];
|
404 |
+
$attrlist = $matches[3];
|
405 |
+
|
406 |
+
if (!@isset($allowed_html[strtolower($elem)]))
|
407 |
+
return '';
|
408 |
+
# They are using a not allowed HTML element
|
409 |
+
|
410 |
+
if ($slash != '')
|
411 |
+
return "<$slash$elem>";
|
412 |
+
# No attributes are allowed for closing elements
|
413 |
+
|
414 |
+
return VaultPress_kses::wp_kses_attr("$slash$elem", $attrlist, $allowed_html, $allowed_protocols);
|
415 |
+
}
|
416 |
+
|
417 |
+
static function wp_kses_attr($element, $attr, $allowed_html, $allowed_protocols) {
|
418 |
+
# Is there a closing XHTML slash at the end of the attributes?
|
419 |
+
|
420 |
+
$xhtml_slash = '';
|
421 |
+
if (preg_match('%\s*/\s*$%', $attr))
|
422 |
+
$xhtml_slash = ' /';
|
423 |
+
|
424 |
+
# Are any attributes allowed at all for this element?
|
425 |
+
|
426 |
+
if (@ count($allowed_html[strtolower($element)]) == 0)
|
427 |
+
return "<$element$xhtml_slash>";
|
428 |
+
|
429 |
+
# Split it
|
430 |
+
|
431 |
+
$attrarr = VaultPress_kses::wp_kses_hair($attr, $allowed_protocols);
|
432 |
+
|
433 |
+
# Go through $attrarr, and save the allowed attributes for this element
|
434 |
+
# in $attr2
|
435 |
+
|
436 |
+
$attr2 = '';
|
437 |
+
|
438 |
+
foreach ($attrarr as $arreach) {
|
439 |
+
if (!@ isset ($allowed_html[strtolower($element)][strtolower($arreach['name'])]))
|
440 |
+
continue; # the attribute is not allowed
|
441 |
+
|
442 |
+
$current = $allowed_html[strtolower($element)][strtolower($arreach['name'])];
|
443 |
+
if ($current == '')
|
444 |
+
continue; # the attribute is not allowed
|
445 |
+
|
446 |
+
if (!is_array($current))
|
447 |
+
$attr2 .= ' '.$arreach['whole'];
|
448 |
+
# there are no checks
|
449 |
+
|
450 |
+
else {
|
451 |
+
# there are some checks
|
452 |
+
$ok = true;
|
453 |
+
foreach ($current as $currkey => $currval)
|
454 |
+
if (!wp_kses_check_attr_val($arreach['value'], $arreach['vless'], $currkey, $currval)) {
|
455 |
+
$ok = false;
|
456 |
+
break;
|
457 |
+
}
|
458 |
+
|
459 |
+
if ( strtolower($arreach['name']) == 'style' ) {
|
460 |
+
$orig_value = $arreach['value'];
|
461 |
+
|
462 |
+
$value = safecss_filter_attr($orig_value);
|
463 |
+
|
464 |
+
if ( empty($value) )
|
465 |
+
continue;
|
466 |
+
|
467 |
+
$arreach['value'] = $value;
|
468 |
+
|
469 |
+
$arreach['whole'] = str_replace($orig_value, $value, $arreach['whole']);
|
470 |
+
}
|
471 |
+
|
472 |
+
if ($ok)
|
473 |
+
$attr2 .= ' '.$arreach['whole']; # it passed them
|
474 |
+
} # if !is_array($current)
|
475 |
+
} # foreach
|
476 |
+
|
477 |
+
# Remove any "<" or ">" characters
|
478 |
+
|
479 |
+
$attr2 = preg_replace('/[<>]/', '', $attr2);
|
480 |
+
|
481 |
+
return "<$element$attr2$xhtml_slash>";
|
482 |
+
}
|
483 |
+
|
484 |
+
static function wp_kses_hair($attr, $allowed_protocols) {
|
485 |
+
$attrarr = array ();
|
486 |
+
$mode = 0;
|
487 |
+
$attrname = '';
|
488 |
+
$uris = array('xmlns', 'profile', 'href', 'src', 'cite', 'classid', 'codebase', 'data', 'usemap', 'longdesc', 'action');
|
489 |
+
|
490 |
+
# Loop through the whole attribute list
|
491 |
+
|
492 |
+
while (strlen($attr) != 0) {
|
493 |
+
$working = 0; # Was the last operation successful?
|
494 |
+
|
495 |
+
switch ($mode) {
|
496 |
+
case 0 : # attribute name, href for instance
|
497 |
+
|
498 |
+
if (preg_match('/^([-a-zA-Z]+)/', $attr, $match)) {
|
499 |
+
$attrname = $match[1];
|
500 |
+
$working = $mode = 1;
|
501 |
+
$attr = preg_replace('/^[-a-zA-Z]+/', '', $attr);
|
502 |
+
}
|
503 |
+
|
504 |
+
break;
|
505 |
+
|
506 |
+
case 1 : # equals sign or valueless ("selected")
|
507 |
+
|
508 |
+
if (preg_match('/^\s*=\s*/', $attr)) # equals sign
|
509 |
+
{
|
510 |
+
$working = 1;
|
511 |
+
$mode = 2;
|
512 |
+
$attr = preg_replace('/^\s*=\s*/', '', $attr);
|
513 |
+
break;
|
514 |
+
}
|
515 |
+
|
516 |
+
if (preg_match('/^\s+/', $attr)) # valueless
|
517 |
+
{
|
518 |
+
$working = 1;
|
519 |
+
$mode = 0;
|
520 |
+
if(FALSE === array_key_exists($attrname, $attrarr)) {
|
521 |
+
$attrarr[$attrname] = array ('name' => $attrname, 'value' => '', 'whole' => $attrname, 'vless' => 'y');
|
522 |
+
}
|
523 |
+
$attr = preg_replace('/^\s+/', '', $attr);
|
524 |
+
}
|
525 |
+
|
526 |
+
break;
|
527 |
+
|
528 |
+
case 2 : # attribute value, a URL after href= for instance
|
529 |
+
|
530 |
+
if (preg_match('%^"([^"]*)"(\s+|/?$)%', $attr, $match))
|
531 |
+
# "value"
|
532 |
+
{
|
533 |
+
$thisval = $match[1];
|
534 |
+
if ( in_array(strtolower($attrname), $uris) )
|
535 |
+
$thisval = VaultPress_kses::wp_kses_bad_protocol($thisval, $allowed_protocols);
|
536 |
+
|
537 |
+
if(FALSE === array_key_exists($attrname, $attrarr)) {
|
538 |
+
$attrarr[$attrname] = array ('name' => $attrname, 'value' => $thisval, 'whole' => "$attrname=\"$thisval\"", 'vless' => 'n');
|
539 |
+
}
|
540 |
+
$working = 1;
|
541 |
+
$mode = 0;
|
542 |
+
$attr = preg_replace('/^"[^"]*"(\s+|$)/', '', $attr);
|
543 |
+
break;
|
544 |
+
}
|
545 |
+
|
546 |
+
if (preg_match("%^'([^']*)'(\s+|/?$)%", $attr, $match))
|
547 |
+
# 'value'
|
548 |
+
{
|
549 |
+
$thisval = $match[1];
|
550 |
+
if ( in_array(strtolower($attrname), $uris) )
|
551 |
+
$thisval = VaultPress_kses::wp_kses_bad_protocol($thisval, $allowed_protocols);
|
552 |
+
|
553 |
+
if(FALSE === array_key_exists($attrname, $attrarr)) {
|
554 |
+
$attrarr[$attrname] = array ('name' => $attrname, 'value' => $thisval, 'whole' => "$attrname='$thisval'", 'vless' => 'n');
|
555 |
+
}
|
556 |
+
$working = 1;
|
557 |
+
$mode = 0;
|
558 |
+
$attr = preg_replace("/^'[^']*'(\s+|$)/", '', $attr);
|
559 |
+
break;
|
560 |
+
}
|
561 |
+
|
562 |
+
if (preg_match("%^([^\s\"']+)(\s+|/?$)%", $attr, $match))
|
563 |
+
# value
|
564 |
+
{
|
565 |
+
$thisval = $match[1];
|
566 |
+
if ( in_array(strtolower($attrname), $uris) )
|
567 |
+
$thisval = VaultPress_kses::wp_kses_bad_protocol($thisval, $allowed_protocols);
|
568 |
+
|
569 |
+
if(FALSE === array_key_exists($attrname, $attrarr)) {
|
570 |
+
$attrarr[$attrname] = array ('name' => $attrname, 'value' => $thisval, 'whole' => "$attrname=\"$thisval\"", 'vless' => 'n');
|
571 |
+
}
|
572 |
+
# We add quotes to conform to W3C's HTML spec.
|
573 |
+
$working = 1;
|
574 |
+
$mode = 0;
|
575 |
+
$attr = preg_replace("%^[^\s\"']+(\s+|$)%", '', $attr);
|
576 |
+
}
|
577 |
+
|
578 |
+
break;
|
579 |
+
} # switch
|
580 |
+
|
581 |
+
if ($working == 0) # not well formed, remove and try again
|
582 |
+
{
|
583 |
+
$attr = wp_kses_html_error($attr);
|
584 |
+
$mode = 0;
|
585 |
+
}
|
586 |
+
} # while
|
587 |
+
|
588 |
+
if ($mode == 1 && FALSE === array_key_exists($attrname, $attrarr))
|
589 |
+
# special case, for when the attribute list ends with a valueless
|
590 |
+
# attribute like "selected"
|
591 |
+
$attrarr[$attrname] = array ('name' => $attrname, 'value' => '', 'whole' => $attrname, 'vless' => 'y');
|
592 |
+
|
593 |
+
return $attrarr;
|
594 |
+
}
|
595 |
+
|
596 |
+
static function wp_kses_bad_protocol($string, $allowed_protocols) {
|
597 |
+
$string = wp_kses_no_null($string);
|
598 |
+
$string2 = $string.'a';
|
599 |
+
|
600 |
+
while ($string != $string2) {
|
601 |
+
$string2 = $string;
|
602 |
+
$string = VaultPress_kses::wp_kses_bad_protocol_once($string, $allowed_protocols);
|
603 |
+
} # while
|
604 |
+
|
605 |
+
return $string;
|
606 |
+
}
|
607 |
+
|
608 |
+
static function wp_kses_bad_protocol_once($string, $allowed_protocols) {
|
609 |
+
$string2 = preg_split( '/:|�*58;|�*3a;/i', $string, 2 );
|
610 |
+
if ( isset($string2[1]) && ! preg_match('%/\?%', $string2[0]) )
|
611 |
+
$string = VaultPress_kses::wp_kses_bad_protocol_once2( $string2[0], $allowed_protocols ) . trim( $string2[1] );
|
612 |
+
|
613 |
+
return $string;
|
614 |
+
}
|
615 |
+
|
616 |
+
static function wp_kses_bad_protocol_once2( $string, $allowed_protocols ) {
|
617 |
+
$string2 = wp_kses_decode_entities($string);
|
618 |
+
$string2 = preg_replace('/\s/', '', $string2);
|
619 |
+
$string2 = wp_kses_no_null($string2);
|
620 |
+
$string2 = strtolower($string2);
|
621 |
+
|
622 |
+
$allowed = false;
|
623 |
+
foreach ( (array) $allowed_protocols as $one_protocol ) {
|
624 |
+
if ( strtolower($one_protocol) != $string2 )
|
625 |
+
continue;
|
626 |
+
$allowed = true;
|
627 |
+
break;
|
628 |
+
}
|
629 |
+
|
630 |
+
if ($allowed)
|
631 |
+
return "$string2:";
|
632 |
+
else
|
633 |
+
return '';
|
634 |
+
}
|
635 |
+
|
636 |
+
}
|
class.vaultpress-ixr-ssl-client.php
ADDED
@@ -0,0 +1,132 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
// don't call the file directly
|
4 |
+
if ( !defined( 'ABSPATH' ) )
|
5 |
+
return;
|
6 |
+
|
7 |
+
if ( !class_exists( 'IXR_Client' ) )
|
8 |
+
include_once( ABSPATH . WPINC . '/class-IXR.php' );
|
9 |
+
|
10 |
+
class VaultPress_IXR_SSL_Client extends IXR_Client {
|
11 |
+
var $ssl = false;
|
12 |
+
function VaultPress_IXR_SSL_Client( $server, $path = false, $port = 80, $timeout = false ) {
|
13 |
+
$this->IXR_Client( $server, $path, $port, $timeout );
|
14 |
+
}
|
15 |
+
function ssl( $port=443 ) {
|
16 |
+
if ( !extension_loaded( 'openssl' ) )
|
17 |
+
return;
|
18 |
+
|
19 |
+
$this->ssl = true;
|
20 |
+
if ( $port )
|
21 |
+
$this->port = $port;
|
22 |
+
}
|
23 |
+
function query() {
|
24 |
+
$args = func_get_args();
|
25 |
+
$method = array_shift($args);
|
26 |
+
$request = new IXR_Request($method, $args);
|
27 |
+
$length = $request->getLength();
|
28 |
+
$xml = $request->getXml();
|
29 |
+
$r = "\r\n";
|
30 |
+
$request = "POST {$this->path} HTTP/1.0$r";
|
31 |
+
|
32 |
+
$this->headers['Host'] = preg_replace( '#^ssl://#', '', $this->server );
|
33 |
+
$this->headers['Content-Type'] = 'text/xml';
|
34 |
+
$this->headers['User-Agent'] = $this->useragent;
|
35 |
+
$this->headers['Content-Length'] = $length;
|
36 |
+
|
37 |
+
if ( class_exists( 'WP_Http' ) ) {
|
38 |
+
$args = array(
|
39 |
+
'method' => 'POST',
|
40 |
+
'body' => $xml,
|
41 |
+
'headers' => $this->headers,
|
42 |
+
'sslverify' => false,
|
43 |
+
);
|
44 |
+
if ( $this->timeout )
|
45 |
+
$args['timeout'] = $this->timeout;
|
46 |
+
|
47 |
+
$http = new WP_Http();
|
48 |
+
if ( $this->ssl )
|
49 |
+
$url = sprintf( 'https://%s%s', $this->server, $this->path );
|
50 |
+
else
|
51 |
+
$url = sprintf( 'http://%s%s', $this->server, $this->path );
|
52 |
+
|
53 |
+
$result = $http->request( $url, $args );
|
54 |
+
if ( is_wp_error( $result ) ) {
|
55 |
+
foreach( $result->errors as $type => $messages ) {
|
56 |
+
$this->error = new IXR_Error(
|
57 |
+
-32702,
|
58 |
+
sprintf( 'WP_Http error: %s, %s', $type, $messages[0] )
|
59 |
+
);
|
60 |
+
break;
|
61 |
+
}
|
62 |
+
return false;
|
63 |
+
} else if ( $result['response']['code'] > 299 || $result['response']['code'] < 200 ) {
|
64 |
+
$this->error = new IXR_Error(
|
65 |
+
-32701,
|
66 |
+
sprintf( 'Server rejected request (HTTP response: %s %s)', $result['response']['code'], $result['response']['message'])
|
67 |
+
);
|
68 |
+
return false;
|
69 |
+
}
|
70 |
+
// Now parse what we've got back
|
71 |
+
$this->message = new IXR_Message( $result['body'] );
|
72 |
+
} else {
|
73 |
+
foreach( $this->headers as $header => $value ) {
|
74 |
+
$request .= "{$header}: {$value}{$r}";
|
75 |
+
}
|
76 |
+
$request .= $r;
|
77 |
+
|
78 |
+
$request .= $xml;
|
79 |
+
// Now send the request
|
80 |
+
if ( $this->ssl )
|
81 |
+
$host = 'ssl://'.$this->server;
|
82 |
+
else
|
83 |
+
$host = $this->server;
|
84 |
+
if ($this->timeout) {
|
85 |
+
$fp = @fsockopen( $host, $this->port, $errno, $errstr, $this->timeout );
|
86 |
+
} else {
|
87 |
+
$fp = @fsockopen( $host, $this->port, $errno, $errstr );
|
88 |
+
}
|
89 |
+
if (!$fp) {
|
90 |
+
$this->error = new IXR_Error( -32300, "Transport error - could not open socket: $errno $errstr" );
|
91 |
+
return false;
|
92 |
+
}
|
93 |
+
fputs( $fp, $request );
|
94 |
+
|
95 |
+
$contents = '';
|
96 |
+
$gotFirstLine = false;
|
97 |
+
$gettingHeaders = true;
|
98 |
+
|
99 |
+
while ( !feof($fp) ) {
|
100 |
+
$line = fgets( $fp, 4096 );
|
101 |
+
if ( !$gotFirstLine ) {
|
102 |
+
// Check line for '200'
|
103 |
+
if ( strstr($line, '200') === false ) {
|
104 |
+
$this->error = new IXR_Error( -32301, 'transport error - HTTP status code was not 200' );
|
105 |
+
return false;
|
106 |
+
}
|
107 |
+
$gotFirstLine = true;
|
108 |
+
}
|
109 |
+
if ( trim($line) == '' ) {
|
110 |
+
$gettingHeaders = false;
|
111 |
+
}
|
112 |
+
if ( !$gettingHeaders ) {
|
113 |
+
$contents .= trim( $line );
|
114 |
+
}
|
115 |
+
}
|
116 |
+
// Now parse what we've got back
|
117 |
+
$this->message = new IXR_Message( $contents );
|
118 |
+
}
|
119 |
+
if ( !$this->message->parse() ) {
|
120 |
+
// XML error
|
121 |
+
$this->error = new IXR_Error( -32700, 'parse error. not well formed' );
|
122 |
+
return false;
|
123 |
+
}
|
124 |
+
// Is the message a fault?
|
125 |
+
if ( $this->message->messageType == 'fault' ) {
|
126 |
+
$this->error = new IXR_Error( $this->message->faultCode, $this->message->faultString );
|
127 |
+
return false;
|
128 |
+
}
|
129 |
+
// Message must be OK
|
130 |
+
return true;
|
131 |
+
}
|
132 |
+
}
|
readme.txt
ADDED
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
=== VaultPress ===
|
2 |
+
Contributors: automattic, aldenta, apokalyptik, briancolinger, shaunandrews, xknown
|
3 |
+
Tags: security, malware, virus, backups, scanning
|
4 |
+
Requires at least: 2.9.2
|
5 |
+
Tested up to: 3.2.1
|
6 |
+
Stable tag: 1.0
|
7 |
+
|
8 |
+
VaultPress is a subscription service offering realtime backup, automated security scanning, and support from WordPress experts.
|
9 |
+
|
10 |
+
== Description ==
|
11 |
+
|
12 |
+
[VaultPress](http://vaultpress.com/?utm_source=plugin-readme&utm_medium=description&utm_campaign=1.0) is a real-time backup and security scanning service designed and built by [Automattic](http://automattic.com/), the same company that operates 25+ million sites on WordPress.com.
|
13 |
+
|
14 |
+
[wpvideo TxdSIdpO]
|
15 |
+
|
16 |
+
For more information, check out [VaultPress.com](http://vaultpress.com/).
|
17 |
+
|
18 |
+
== Installation ==
|
19 |
+
|
20 |
+
1. Search for VaultPress in the WordPress.org plugin directory and click install. Or, upload the files to your `wp-content/vaultpress/` folder.
|
21 |
+
2. Visit `wp-admin/plugins.php` and activate the VaultPress plugin.
|
22 |
+
3. Head to `wp-admin/admin.php?page=vaultpress` and enter your site’s registration key. You can purchase your registration key at [VaultPress.com](http://vaultpress.com/plugin/?utm_source=plugin-readme&utm_medium=installation&utm_campaign=1.0)
|
23 |
+
|
24 |
+
You can find more detailed instructions at [http://vaultpress.com/help/](http://vaultpress.com/help/install-vaultpress/?utm_source=plugin-readme&utm_medium=description&utm_campaign=1.0)
|
25 |
+
|
26 |
+
== Frequently Asked Questions ==
|
27 |
+
|
28 |
+
View our full list of FAQs at [http://vaultpress.com/help/faq/](http://vaultpress.com/help/faq/?utm_source=plugin-readme&utm_medium=faq&utm_campaign=1.0)
|
29 |
+
|
30 |
+
= What’s included in each VaultPress plan? =
|
31 |
+
|
32 |
+
All plans include Realtime Backups, Downloadable Archives for Restoring, Vitality Statistics, and the Activity Log.
|
33 |
+
|
34 |
+
The Basic plan provides access to disaster recovery and support services.
|
35 |
+
|
36 |
+
The Premium plan provides priority recovery and support services, along with site migration assistance. The Premium plan provides automated security scanning of Core, Theme, and Plugin files.
|
37 |
+
|
38 |
+
The Enterprise members receive top priority for support services and migration assistance. Along with security scanning, Enterprise members receive complimentary security consulting and performance auditing.
|
39 |
+
|
40 |
+
Update-to-date pricing and features can always be found on the [Plans & Pricing](http://vaultpress.com/plugin/?utm_source=plugin-readme&utm_medium=installation&utm_campaign=1.0) page.
|
41 |
+
|
42 |
+
= How many sites can I protect with VaultPress? =
|
43 |
+
|
44 |
+
A VaultPress subscription is for a single WordPress site. You can purchase additional subscriptions for each of your WordPress sites, and manage them all with in one place.
|
45 |
+
|
46 |
+
= Does VaultPress work with WordPress 3.0 Multisite installs? =
|
47 |
+
|
48 |
+
With our 1.0 release, VaultPress now supports Multisite installs. Each site will require its own subscription.
|
49 |
+
|
50 |
+
== Changelog ==
|
51 |
+
|
52 |
+
= 1.0 =
|
53 |
+
* First public release!
|
vaultpress.php
ADDED
@@ -0,0 +1,1828 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/*
|
3 |
+
* Plugin Name: VaultPress
|
4 |
+
* Plugin URI: http://vaultpress.com/?utm_source=plugin-uri&utm_medium=plugin-description&utm_campaign=1.0
|
5 |
+
* Description: Protect your content, themes, plugins, and settings with <strong>realtime backup</strong> and <strong>automated security scanning</strong> from <a href="http://vaultpress.com/?utm_source=wp-admin&utm_medium=plugin-description&utm_campaign=1.0" rel="nofollow">VaultPress</a>. Activate, enter your registration key, and never worry again. <a href="http://vaultpress.com/help/?utm_source=wp-admin&utm_medium=plugin-description&utm_campaign=1.0" rel="nofollow">Need some help?</a>
|
6 |
+
* Version: 1.2.7
|
7 |
+
* Author: Automattic
|
8 |
+
* Author URI: http://vaultpress.com/?utm_source=author-uri&utm_medium=plugin-description&utm_campaign=1.0
|
9 |
+
* License: GPL2+
|
10 |
+
* Text Domain: vaultpress
|
11 |
+
* Domain Path: /languages/
|
12 |
+
*/
|
13 |
+
|
14 |
+
// don't call the file directly
|
15 |
+
if ( !defined( 'ABSPATH' ) )
|
16 |
+
return;
|
17 |
+
|
18 |
+
class VaultPress {
|
19 |
+
var $option_name = 'vaultpress';
|
20 |
+
var $db_version = 2;
|
21 |
+
var $plugin_version = '1.2.7';
|
22 |
+
|
23 |
+
function VaultPress() {
|
24 |
+
$this->__construct();
|
25 |
+
}
|
26 |
+
|
27 |
+
function __construct() {
|
28 |
+
register_activation_hook( __FILE__, array( $this, 'activate' ) );
|
29 |
+
register_deactivation_hook( __FILE__, array( $this, 'deactivate' ) );
|
30 |
+
|
31 |
+
$options = get_option( $this->option_name );
|
32 |
+
if ( !is_array( $options ) )
|
33 |
+
$options = array();
|
34 |
+
|
35 |
+
$defaults = array(
|
36 |
+
'db_version' => 0,
|
37 |
+
'key' => '',
|
38 |
+
'secret' => '',
|
39 |
+
'connection' => false,
|
40 |
+
'service_ips' => false
|
41 |
+
);
|
42 |
+
|
43 |
+
$this->options = wp_parse_args( $options, $defaults );
|
44 |
+
$this->reset_pings();
|
45 |
+
|
46 |
+
$this->upgrade();
|
47 |
+
|
48 |
+
if ( is_admin() )
|
49 |
+
$this->add_admin_actions_and_filters();
|
50 |
+
|
51 |
+
if ( $this->is_registered() )
|
52 |
+
$this->add_listener_actions_and_filters();
|
53 |
+
}
|
54 |
+
|
55 |
+
function &init() {
|
56 |
+
static $instance = false;
|
57 |
+
|
58 |
+
if ( !$instance ) {
|
59 |
+
$instance = new VaultPress();
|
60 |
+
}
|
61 |
+
|
62 |
+
return $instance;
|
63 |
+
}
|
64 |
+
|
65 |
+
function activate( $network_wide ) {
|
66 |
+
$type = $network_wide ? 'network' : 'single';
|
67 |
+
$this->update_option( 'activated', $type );
|
68 |
+
|
69 |
+
// force a connection check after an activation
|
70 |
+
$this->clear_connection();
|
71 |
+
}
|
72 |
+
|
73 |
+
function deactivate() {
|
74 |
+
if ( $this->is_registered() )
|
75 |
+
$this->contact_service( 'plugin_status', array( 'vp_plugin_status' => 'deactivated' ) );
|
76 |
+
}
|
77 |
+
|
78 |
+
function upgrade() {
|
79 |
+
$current_db_version = $this->get_option( 'db_version' );
|
80 |
+
|
81 |
+
if ( $current_db_version < 1 ) {
|
82 |
+
$this->options['connection'] = get_option( 'vaultpress_connection' );
|
83 |
+
$this->options['key'] = get_option( 'vaultpress_key' );
|
84 |
+
$this->options['secret'] = get_option( 'vaultpress_secret' );
|
85 |
+
$this->options['service_ips'] = get_option( 'vaultpress_service_ips' );
|
86 |
+
|
87 |
+
// remove old options
|
88 |
+
$old_options = array(
|
89 |
+
'vaultpress_connection',
|
90 |
+
'vaultpress_hostname',
|
91 |
+
'vaultpress_key',
|
92 |
+
'vaultpress_secret',
|
93 |
+
'vaultpress_service_ips',
|
94 |
+
'vaultpress_timeout',
|
95 |
+
'vp_allow_remote_execution',
|
96 |
+
'vp_debug_request_signing',
|
97 |
+
'vp_disable_firewall',
|
98 |
+
);
|
99 |
+
|
100 |
+
foreach ( $old_options as $option )
|
101 |
+
delete_option( $option );
|
102 |
+
|
103 |
+
$this->options['db_version'] = $this->db_version;
|
104 |
+
$this->update_options();
|
105 |
+
}
|
106 |
+
|
107 |
+
if ( $current_db_version < 2 ) {
|
108 |
+
$this->delete_option( 'timeout' );
|
109 |
+
$this->delete_option( 'disable_firewall' );
|
110 |
+
$this->update_option( 'db_version', $this->db_version );
|
111 |
+
$this->clear_connection();
|
112 |
+
}
|
113 |
+
}
|
114 |
+
|
115 |
+
function get_option( $key ) {
|
116 |
+
if ( 'hostname' == $key ) {
|
117 |
+
if ( defined( 'VAULTPRESS_HOSTNAME' ) )
|
118 |
+
return VAULTPRESS_HOSTNAME;
|
119 |
+
else
|
120 |
+
return 'vaultpress.com';
|
121 |
+
}
|
122 |
+
|
123 |
+
if ( 'timeout' == $key ) {
|
124 |
+
if ( defined( 'VAULTPRESS_TIMEOUT' ) )
|
125 |
+
return VAULTPRESS_TIMEOUT;
|
126 |
+
else
|
127 |
+
return 60;
|
128 |
+
}
|
129 |
+
|
130 |
+
if ( 'disable_firewall' == $key ) {
|
131 |
+
if ( defined( 'VAULTPRESS_DISABLE_FIREWALL' ) )
|
132 |
+
return VAULTPRESS_DISABLE_FIREWALL;
|
133 |
+
else
|
134 |
+
return false;
|
135 |
+
}
|
136 |
+
|
137 |
+
if ( isset( $this->options[$key] ) )
|
138 |
+
return $this->options[$key];
|
139 |
+
|
140 |
+
return false;
|
141 |
+
}
|
142 |
+
|
143 |
+
function update_option( $key, $value ) {
|
144 |
+
$this->options[$key] = $value;
|
145 |
+
$this->update_options();
|
146 |
+
}
|
147 |
+
|
148 |
+
function delete_option( $key ) {
|
149 |
+
unset( $this->options[$key] );
|
150 |
+
$this->update_options();
|
151 |
+
}
|
152 |
+
|
153 |
+
function update_options() {
|
154 |
+
update_option( $this->option_name, $this->options );
|
155 |
+
}
|
156 |
+
|
157 |
+
function admin_init() {
|
158 |
+
if ( !current_user_can( 'manage_options' ) )
|
159 |
+
return;
|
160 |
+
|
161 |
+
load_plugin_textdomain( 'vaultpress', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
|
162 |
+
}
|
163 |
+
|
164 |
+
function admin_head() {
|
165 |
+
if ( !current_user_can( 'manage_options' ) )
|
166 |
+
return;
|
167 |
+
|
168 |
+
if ( $activated = $this->get_option( 'activated' ) ) {
|
169 |
+
if ( 'network' == $activated ) {
|
170 |
+
add_action( 'network_admin_notices', array( $this, 'activated_notice' ) );
|
171 |
+
} else {
|
172 |
+
foreach ( array( 'user_admin_notices', 'admin_notices' ) as $filter )
|
173 |
+
add_action( $filter, array( $this, 'activated_notice' ) );
|
174 |
+
}
|
175 |
+
}
|
176 |
+
|
177 |
+
// ask the user to connect their site w/ VP
|
178 |
+
if ( !$this->is_registered() ) {
|
179 |
+
foreach ( array( 'user_admin_notices', 'admin_notices' ) as $filter )
|
180 |
+
add_action( $filter, array( $this, 'connect_notice' ) );
|
181 |
+
|
182 |
+
// if we have an error make sure to let the user know about it
|
183 |
+
} else {
|
184 |
+
$error_code = $this->get_option( 'connection_error_code' );
|
185 |
+
if ( !empty( $error_code ) ) {
|
186 |
+
foreach ( array( 'user_admin_notices', 'admin_notices' ) as $filter )
|
187 |
+
add_action( $filter, array( $this, 'error_notice' ) );
|
188 |
+
}
|
189 |
+
}
|
190 |
+
?>
|
191 |
+
|
192 |
+
<style type="text/css">
|
193 |
+
#toplevel_page_vaultpress div.wp-menu-image {
|
194 |
+
background: url(<?php echo esc_url( $this->server_url() ); ?>images/vp-icon-sprite.png?20111216) center top no-repeat;
|
195 |
+
}
|
196 |
+
|
197 |
+
.admin-color-classic #toplevel_page_vaultpress div.wp-menu-image {
|
198 |
+
background-position: center -28px;
|
199 |
+
}
|
200 |
+
|
201 |
+
#toplevel_page_vaultpress.current div.wp-menu-image,
|
202 |
+
#toplevel_page_vaultpress:hover div.wp-menu-image {
|
203 |
+
background-position: center bottom;
|
204 |
+
}
|
205 |
+
</style>
|
206 |
+
|
207 |
+
<?php
|
208 |
+
|
209 |
+
}
|
210 |
+
|
211 |
+
function admin_menu() {
|
212 |
+
// if Jetpack is loaded then we need to wait for that menu to be added
|
213 |
+
if ( class_exists( 'Jetpack' ) )
|
214 |
+
add_action( 'jetpack_admin_menu', array( $this, 'load_menu' ) );
|
215 |
+
else
|
216 |
+
$this->load_menu();
|
217 |
+
}
|
218 |
+
|
219 |
+
function load_menu() {
|
220 |
+
if ( class_exists( 'Jetpack' ) ) {
|
221 |
+
$hook = add_submenu_page( 'jetpack', 'VaultPress', 'VaultPress', 'manage_options', 'vaultpress', array( $this, 'ui' ) );
|
222 |
+
} else {
|
223 |
+
$hook = add_menu_page( 'VaultPress', 'VaultPress', 'manage_options', 'vaultpress', array( $this, 'ui' ), 'div' );
|
224 |
+
}
|
225 |
+
|
226 |
+
add_action( "load-$hook", array( $this, 'ui_load' ) );
|
227 |
+
add_action( 'admin_print_styles', array( $this, 'admin_styles' ) );
|
228 |
+
}
|
229 |
+
|
230 |
+
function admin_styles() {
|
231 |
+
// force the cache to bust every day
|
232 |
+
wp_enqueue_style( 'vaultpress', $this->server_url() . 'css/plugin.css' , false, date( 'Ymd' ) );
|
233 |
+
}
|
234 |
+
|
235 |
+
function server_url() {
|
236 |
+
if ( !isset( $this->_server_url ) ) {
|
237 |
+
$scheme = is_ssl() ? 'https' : 'http';
|
238 |
+
$this->_server_url = sprintf( '%s://%s/', $scheme, $this->get_option( 'hostname' ) );
|
239 |
+
}
|
240 |
+
|
241 |
+
return $this->_server_url;
|
242 |
+
}
|
243 |
+
|
244 |
+
// show message if plugin is activated but not connected to VaultPress
|
245 |
+
function connect_notice() {
|
246 |
+
if ( isset( $_GET['page'] ) && 'vaultpress' == $_GET['page'] )
|
247 |
+
return;
|
248 |
+
|
249 |
+
$message = sprintf(
|
250 |
+
__( 'You must enter your registration key before VaultPress can back up and secure your site. <a href="%1$s">Register VaultPress</a>', 'vaultpress' ),
|
251 |
+
admin_url( 'admin.php?page=vaultpress' )
|
252 |
+
);
|
253 |
+
$this->ui_message( $message, 'notice', __( 'VaultPress needs your attention!', 'vaultpress' ) );
|
254 |
+
}
|
255 |
+
|
256 |
+
// show message after activation
|
257 |
+
function activated_notice() {
|
258 |
+
if ( 'network' == $this->get_option( 'activated' ) ) {
|
259 |
+
$message = sprintf(
|
260 |
+
__( 'Each site will need to be registered with VaultPress separately. You can purchase new keys from your <a href="%1$s">VaultPress Dashboard</a>.', 'vaultpress' ),
|
261 |
+
'https://dashboard.vaultpress.com/'
|
262 |
+
);
|
263 |
+
$this->ui_message( $message, 'activated', __( 'VaultPress has been activated across your network!', 'vaultpress' ) );
|
264 |
+
|
265 |
+
// key and secret already exist in db
|
266 |
+
} elseif ( $this->is_registered() ) {
|
267 |
+
if ( $this->check_connection() ) {
|
268 |
+
$message = sprintf(
|
269 |
+
__( 'VaultPress has been registered and is currently backing up your site. <a href="%1$s">View Backup Status</a>', 'vaultpress' ),
|
270 |
+
admin_url( 'admin.php?page=vaultpress' )
|
271 |
+
);
|
272 |
+
$this->ui_message( $message, 'registered', __( 'VaultPress has been activated!', 'vaultpress' ) );
|
273 |
+
}
|
274 |
+
}
|
275 |
+
|
276 |
+
$this->delete_option( 'activated' );
|
277 |
+
}
|
278 |
+
|
279 |
+
function error_notice() {
|
280 |
+
$error_message = $this->get_option( 'connection_error_message' );
|
281 |
+
|
282 |
+
// link to the VaultPress page if we're not already there
|
283 |
+
if ( !isset( $_GET['page'] ) || 'vaultpress' != $_GET['page'] )
|
284 |
+
$error_message .= ' ' . sprintf( '<a href="%s">%s</a>', admin_url( 'admin.php?page=vaultpress' ), __( 'Visit the VaultPress page' ) );
|
285 |
+
|
286 |
+
if ( !empty( $error_message ) )
|
287 |
+
$this->ui_message( $error_message, 'error' );
|
288 |
+
}
|
289 |
+
|
290 |
+
function ui() {
|
291 |
+
if ( !empty( $_GET['error'] ) ) {
|
292 |
+
$this->error_notice();
|
293 |
+
$this->clear_connection();
|
294 |
+
}
|
295 |
+
|
296 |
+
if ( !$this->is_registered() ) {
|
297 |
+
$this->ui_register();
|
298 |
+
return;
|
299 |
+
}
|
300 |
+
|
301 |
+
$status = $this->contact_service( 'status' );
|
302 |
+
if ( !$status ) {
|
303 |
+
$error_code = $this->get_option( 'connection_error_code' );
|
304 |
+
if ( 0 == $error_code )
|
305 |
+
$this->ui_fatal_error();
|
306 |
+
else
|
307 |
+
$this->ui_register();
|
308 |
+
return;
|
309 |
+
}
|
310 |
+
|
311 |
+
$ticker = $this->contact_service( 'ticker' );
|
312 |
+
if ( is_array( $ticker ) && isset( $ticker['faultCode'] ) ) {
|
313 |
+
$this->error_notice();
|
314 |
+
$this->ui_register();
|
315 |
+
return;
|
316 |
+
}
|
317 |
+
|
318 |
+
$this->ui_main();
|
319 |
+
}
|
320 |
+
|
321 |
+
function ui_load() {
|
322 |
+
if ( !current_user_can( 'manage_options' ) )
|
323 |
+
return;
|
324 |
+
|
325 |
+
// run code that might be updating the registration key
|
326 |
+
if ( isset( $_POST['action'] ) && 'register' == $_POST['action'] ) {
|
327 |
+
check_admin_referer( 'vaultpress_register' );
|
328 |
+
|
329 |
+
// reset the connection info so messages don't cross
|
330 |
+
$this->clear_connection();
|
331 |
+
|
332 |
+
$registration_key = trim( $_POST[ 'registration_key' ] );
|
333 |
+
if ( empty( $registration_key ) ) {
|
334 |
+
$this->update_option( 'connection_error_code', 1 );
|
335 |
+
$this->update_option(
|
336 |
+
'connection_error_message',
|
337 |
+
sprintf(
|
338 |
+
__( '<strong>That\'s not a valid registration key.</strong> Head over to the <a href="%1$s" title="Sign in to your VaultPress Dashboard">VaultPress Dashboard</a> to find your key.', 'vaultpress' ),
|
339 |
+
'https://dashboard.vaultpress.com/'
|
340 |
+
)
|
341 |
+
);
|
342 |
+
wp_redirect( admin_url( 'admin.php?page=vaultpress&error=true' ) );
|
343 |
+
exit();
|
344 |
+
}
|
345 |
+
|
346 |
+
// try to register the plugin
|
347 |
+
$nonce = wp_create_nonce( 'vp_register_' . $registration_key );
|
348 |
+
$args = array( 'registration_key' => $registration_key, 'nonce' => $nonce );
|
349 |
+
$response = $this->contact_service( 'register', $args );
|
350 |
+
|
351 |
+
// we received an error from the VaultPress servers
|
352 |
+
if ( !empty( $response['faultCode'] ) ) {
|
353 |
+
$this->update_option( 'connection_error_code', $response['faultCode'] );
|
354 |
+
$this->update_option( 'connection_error_message', $response['faultString'] );
|
355 |
+
wp_redirect( admin_url( 'admin.php?page=vaultpress&error=true' ) );
|
356 |
+
exit();
|
357 |
+
}
|
358 |
+
|
359 |
+
// make sure the returned data looks valid
|
360 |
+
if ( empty( $response['key'] ) || empty( $response['secret'] ) || empty( $response['nonce'] ) || $nonce != $response['nonce'] ) {
|
361 |
+
$this->update_option( 'connection_error_code', 1 );
|
362 |
+
$this->update_option( 'connection_error_message', sprintf( __( 'There was a problem trying to register your subscription. Please try again. If you’re still having issues please <a href="%1$s">contact the VaultPress Safekeepers</a>.', 'vaultpress' ), 'http://vaultpress.com/contact/' ) );
|
363 |
+
wp_redirect( admin_url( 'admin.php?page=vaultpress&error=true' ) );
|
364 |
+
exit();
|
365 |
+
}
|
366 |
+
|
367 |
+
// need to update these values in the db so the servers can try connecting to the plugin
|
368 |
+
$this->update_option( 'key', $response['key'] );
|
369 |
+
$this->update_option( 'secret', $response['secret'] );
|
370 |
+
if ( $this->check_connection( true ) ) {
|
371 |
+
wp_redirect( admin_url( 'admin.php?page=vaultpress' ) );
|
372 |
+
exit();
|
373 |
+
}
|
374 |
+
|
375 |
+
// reset the key and secret
|
376 |
+
$this->update_option( 'key', '' );
|
377 |
+
$this->update_option( 'secret', '' );
|
378 |
+
wp_redirect( admin_url( 'admin.php?page=vaultpress&error=true' ) );
|
379 |
+
exit();
|
380 |
+
}
|
381 |
+
}
|
382 |
+
|
383 |
+
function ui_register() {
|
384 |
+
?>
|
385 |
+
<div id="vp-wrap" class="wrap">
|
386 |
+
<div id="vp-head">
|
387 |
+
<h2>VaultPress<a href="https://dashboard.vaultpress.com/" class="vp-visit-dashboard" target="_blank"><?php _e( 'Visit Dashboard', 'vaultpress' ); ?></a></h2>
|
388 |
+
</div>
|
389 |
+
|
390 |
+
<div id="vp_registration">
|
391 |
+
<div class="vp_view-plans">
|
392 |
+
<h1><?php _e( 'The VaultPress plugin <strong>requires a monthly subscription</strong>.', 'vaultpress' ); ?></h1>
|
393 |
+
<p><?php _e( 'Get realtime backups, automated security scanning, and support from WordPress experts.', 'vaultpress' ); ?></p>
|
394 |
+
<p class="vp_plans-btn"><a href="https://vaultpress.com/plugin/?utm_source=plugin-unregistered&utm_medium=view-plans-and-pricing&utm_campaign=1.0-plugin"><strong><?php _e( 'View plans and pricing »', 'vaultpress' ); ?></strong></a></p>
|
395 |
+
</div>
|
396 |
+
|
397 |
+
<div class="vp_register-plugin">
|
398 |
+
<h3><?php _e( 'Already have a VaultPress account?', 'vaultpress' ); ?></h3>
|
399 |
+
<p><?php _e( 'Paste your registration key below:', 'vaultpress' ); ?></p>
|
400 |
+
<form method="post" action="">
|
401 |
+
<fieldset>
|
402 |
+
<textarea placeholder="<?php echo esc_attr( __( 'Enter your key here...', 'vaultpress' ) ); ?>" name="registration_key"></textarea>
|
403 |
+
<button><strong><?php _e( 'Register ', 'vaultpress' ); ?></strong></button>
|
404 |
+
<input type="hidden" name="action" value="register" />
|
405 |
+
<?php wp_nonce_field( 'vaultpress_register' ); ?>
|
406 |
+
</fieldset>
|
407 |
+
</form>
|
408 |
+
</div>
|
409 |
+
</div>
|
410 |
+
</div>
|
411 |
+
<?php
|
412 |
+
}
|
413 |
+
|
414 |
+
function ui_main() {
|
415 |
+
?>
|
416 |
+
<div id="vp-wrap" class="wrap">
|
417 |
+
<?php
|
418 |
+
$response = base64_decode( $this->contact_service( 'plugin_ui' ) );
|
419 |
+
echo $response;
|
420 |
+
?>
|
421 |
+
</div>
|
422 |
+
<?php
|
423 |
+
}
|
424 |
+
|
425 |
+
function ui_fatal_error() {
|
426 |
+
?>
|
427 |
+
<div id="vp-wrap" class="wrap">
|
428 |
+
<h2>VaultPress</h2>
|
429 |
+
|
430 |
+
<p><?php printf( __( 'Yikes! We’ve run into a serious issue and can’t connect to %1$s.', 'vaultpress' ), esc_html( $this->get_option( 'hostname' ) ) ); ?></p>
|
431 |
+
<p><?php printf( __( 'Please make sure that your website is accessible via the Internet. If you’re still having issues please <a href="%1$s">contact the VaultPress Safekeepers</a>.', 'vaultpress' ), 'http://vaultpress.com/contact/' ); ?></p>
|
432 |
+
</div>
|
433 |
+
<?php
|
434 |
+
}
|
435 |
+
|
436 |
+
function ui_message( $message, $type = 'notice', $heading = '' ) {
|
437 |
+
if ( empty( $heading ) ) {
|
438 |
+
switch ( $type ) {
|
439 |
+
case 'error':
|
440 |
+
$heading = __( 'Oops... there seems to be a problem.', 'vaultpress' );
|
441 |
+
break;
|
442 |
+
|
443 |
+
case 'success':
|
444 |
+
$heading = __( 'Yay! Things look good.', 'vaultpress' );
|
445 |
+
break;
|
446 |
+
|
447 |
+
default:
|
448 |
+
$heading = __( 'VaultPress needs your attention!', 'vaultpress' );
|
449 |
+
break;
|
450 |
+
}
|
451 |
+
}
|
452 |
+
?>
|
453 |
+
<div id="vp-notice" class="vp-<?php echo $type; ?> updated">
|
454 |
+
<div class="vp-message">
|
455 |
+
<h3><?php echo $heading; ?></h3>
|
456 |
+
<p><?php echo $message; ?></p>
|
457 |
+
</div>
|
458 |
+
</div>
|
459 |
+
<?php
|
460 |
+
}
|
461 |
+
|
462 |
+
function get_config( $key ) {
|
463 |
+
$val = get_option( $key );
|
464 |
+
if ( $val )
|
465 |
+
return $val;
|
466 |
+
switch( $key ) {
|
467 |
+
case '_vp_config_option_name_ignore':
|
468 |
+
$val = $this->get_option_name_ignore( true );
|
469 |
+
update_option( '_vp_config_option_name_ignore', $val );
|
470 |
+
break;
|
471 |
+
}
|
472 |
+
return $val;
|
473 |
+
}
|
474 |
+
|
475 |
+
// Option name patterns to ignore
|
476 |
+
function get_option_name_ignore( $return_defaults = false ) {
|
477 |
+
$defaults = array(
|
478 |
+
'vaultpress',
|
479 |
+
'cron',
|
480 |
+
'wpsupercache_gc_time',
|
481 |
+
'rewrite_rules',
|
482 |
+
'akismet_spam_count',
|
483 |
+
'/_transient_/',
|
484 |
+
'/^_vp_/',
|
485 |
+
);
|
486 |
+
if ( $return_defaults )
|
487 |
+
return $defaults;
|
488 |
+
$ignore_names = $this->get_config( '_vp_config_option_name_ignore' );
|
489 |
+
return array_unique( array_merge( $defaults, $ignore_names ) );
|
490 |
+
}
|
491 |
+
|
492 |
+
###
|
493 |
+
### Section: Backup Notification Hooks
|
494 |
+
###
|
495 |
+
|
496 |
+
// Handle Handle Notifying VaultPress of Options Activity At this point the options table has already been modified
|
497 |
+
//
|
498 |
+
// Note: we handle deleted, instead of delete because VaultPress backs up options by name (which are unique,) that
|
499 |
+
// means that we do not need to resolve an id like we would for, say, a post.
|
500 |
+
function option_handler( $option_name ) {
|
501 |
+
global $wpdb;
|
502 |
+
// Step 1 -- exclusionary rules, don't send these options to vaultpress, because they
|
503 |
+
// either change constantly and/or are inconsequential to the blog itself and/or they
|
504 |
+
// are specific to the VaultPress plugin process and we want to avoid recursion
|
505 |
+
$should_ping = true;
|
506 |
+
$ignore_names = $this->get_option_name_ignore();
|
507 |
+
foreach( (array)$ignore_names as $val ) {
|
508 |
+
if ( $val{0} == '/' ) {
|
509 |
+
if ( preg_match( $val, $option_name ) )
|
510 |
+
$should_ping = false;
|
511 |
+
} else {
|
512 |
+
if ( $val == $option_name )
|
513 |
+
$should_ping = false;
|
514 |
+
}
|
515 |
+
if ( !$should_ping )
|
516 |
+
break;
|
517 |
+
}
|
518 |
+
if ( $should_ping )
|
519 |
+
$this->add_ping( 'db', array( 'option' => $option_name ) );
|
520 |
+
|
521 |
+
// Step 2 -- If WordPress is about to kick off a some "cron" action, we need to
|
522 |
+
// flush vaultpress, because the "remote" cron threads done via http fetch will
|
523 |
+
// be happening completely inside the window of this thread. That thread will
|
524 |
+
// be expecting touched and accounted for tables
|
525 |
+
if ( $option_name == '_transient_doing_cron' )
|
526 |
+
$this->do_pings();
|
527 |
+
|
528 |
+
return $option_name;
|
529 |
+
}
|
530 |
+
|
531 |
+
// Handle Notifying VaultPress of Comment Activity
|
532 |
+
function comment_action_handler( $comment_id ) {
|
533 |
+
if ( !is_array( $comment_id ) ) {
|
534 |
+
if ( wp_get_comment_status( $comment_id ) != 'spam' )
|
535 |
+
$this->add_ping( 'db', array( 'comment' => $comment_id ) );
|
536 |
+
} else {
|
537 |
+
foreach ( $comment_id as $id ) {
|
538 |
+
if ( wp_get_comment_status( $comment_id ) != 'spam' )
|
539 |
+
$this->add_ping( 'db', array( 'comment' => $id) );
|
540 |
+
}
|
541 |
+
}
|
542 |
+
}
|
543 |
+
|
544 |
+
// Handle Notifying VaultPress of Theme Switches
|
545 |
+
function theme_action_handler( $theme ) {
|
546 |
+
$this->add_ping( 'themes', array( 'theme' => get_option( 'stylesheet' ) ) );
|
547 |
+
}
|
548 |
+
|
549 |
+
// Handle Notifying VaultPress of Upload Activity
|
550 |
+
function upload_handler( $file ) {
|
551 |
+
$this->add_ping( 'uploads', array( 'upload' => str_replace( $this->resolve_upload_path(), '', $file['file'] ) ) );
|
552 |
+
return $file;
|
553 |
+
}
|
554 |
+
|
555 |
+
// Handle Notifying VaultPress of Plugin Activation/Deactivation
|
556 |
+
function plugin_action_handler( $plugin='' ) {
|
557 |
+
$this->add_ping( 'plugins', array( 'name' => $plugin ) );
|
558 |
+
}
|
559 |
+
|
560 |
+
// Handle Notifying VaultPress of User Edits
|
561 |
+
function userid_action_handler( $user_or_id ) {
|
562 |
+
if ( is_object($user_or_id) )
|
563 |
+
$userid = intval( $user_or_id->ID );
|
564 |
+
else
|
565 |
+
$userid = intval( $user_or_id );
|
566 |
+
if ( !$userid )
|
567 |
+
return;
|
568 |
+
$this->add_ping( 'db', array( 'user' => $userid ) );
|
569 |
+
}
|
570 |
+
|
571 |
+
// Handle Notifying VaultPress of term changes
|
572 |
+
function term_handler( $term_id, $tt_id=null ) {
|
573 |
+
$this->add_ping( 'db', array( 'term' => $term_id ) );
|
574 |
+
if ( $tt_id )
|
575 |
+
$this->term_taxonomy_handler( $tt_id );
|
576 |
+
}
|
577 |
+
|
578 |
+
// Handle Notifying VaultPress of term_taxonomy changes
|
579 |
+
function term_taxonomy_handler( $tt_id ) {
|
580 |
+
$this->add_ping( 'db', array( 'term_taxonomy' => $tt_id ) );
|
581 |
+
}
|
582 |
+
// add(ed)_term_taxonomy handled via the created_term hook, the term_taxonomy_handler is called by the term_handler
|
583 |
+
|
584 |
+
// Handle Notifying VaultPress of term_taxonomy changes
|
585 |
+
function term_taxonomies_handler( $tt_ids ) {
|
586 |
+
foreach( (array)$tt_ids as $tt_id ) {
|
587 |
+
$this->term_taxonomy_handler( $tt_id );
|
588 |
+
}
|
589 |
+
}
|
590 |
+
|
591 |
+
// Handle Notifying VaultPress of term_relationship changes
|
592 |
+
function term_relationship_handler( $object_id, $term_id ) {
|
593 |
+
$this->add_ping( 'db', array( 'term_relationship' => array( 'object_id' => $object_id, 'term_taxonomy_id' => $term_id ) ) );
|
594 |
+
}
|
595 |
+
|
596 |
+
// Handle Notifying VaultPress of term_relationship changes
|
597 |
+
function term_relationships_handler( $object_id, $term_ids ) {
|
598 |
+
foreach ( (array)$term_ids as $term_id ) {
|
599 |
+
$this->term_relationship_handler( $object_id, $term_id );
|
600 |
+
}
|
601 |
+
}
|
602 |
+
|
603 |
+
// Handle Notifying VaultPress of term_relationship changes
|
604 |
+
function set_object_terms_handler( $object_id, $terms, $tt_ids ) {
|
605 |
+
$this->term_relationships_handler( $object_id, $tt_ids );
|
606 |
+
}
|
607 |
+
|
608 |
+
// Handle Notifying VaultPress of UserMeta changes
|
609 |
+
function usermeta_action_handler( $umeta_id, $user_id, $meta_key, $meta_value='' ) {
|
610 |
+
$this->add_ping( 'db', array( 'usermeta' => $umeta_id ) );
|
611 |
+
}
|
612 |
+
|
613 |
+
// Handle Notifying VaultPress of Post Changes
|
614 |
+
function post_action_handler($post_id) {
|
615 |
+
if ( current_filter() == 'delete_post' )
|
616 |
+
return $this->add_ping( 'db', array( 'post' => $post_id ), 'delete_post' );
|
617 |
+
return $this->add_ping( 'db', array( 'post' => $post_id ), 'edit_post' );
|
618 |
+
}
|
619 |
+
|
620 |
+
// Handle Notifying VaultPress of Link Changes
|
621 |
+
function link_action_handler( $link_id ) {
|
622 |
+
$this->add_ping( 'db', array( 'link' => $link_id ) );
|
623 |
+
}
|
624 |
+
|
625 |
+
// Handle Notifying VaultPress of Commentmeta Changes
|
626 |
+
function commentmeta_insert_handler( $meta_id, $comment_id=null ) {
|
627 |
+
if ( empty( $comment_id ) || wp_get_comment_status( $comment_id ) != 'spam' )
|
628 |
+
$this->add_ping( 'db', array( 'commentmeta' => $meta_id ) );
|
629 |
+
}
|
630 |
+
|
631 |
+
function commentmeta_modification_handler( $object_id, $meta_key, $meta_value, $meta_id ) {
|
632 |
+
if ( !is_array( $meta_id ) )
|
633 |
+
return $this->add_ping( 'db', array( 'commentmeta' => $meta_id ) );
|
634 |
+
foreach ( $meta_id as $id ) {
|
635 |
+
$this->add_ping( 'db', array( 'commentmeta' => $id ) );
|
636 |
+
}
|
637 |
+
}
|
638 |
+
|
639 |
+
// Handle Notifying VaultPress of PostMeta changes via newfangled metadata functions
|
640 |
+
function postmeta_insert_handler( $meta_id, $post_id, $meta_key, $meta_value='' ) {
|
641 |
+
$this->add_ping( 'db', array( 'postmeta' => $meta_id ) );
|
642 |
+
}
|
643 |
+
|
644 |
+
function postmeta_modification_handler( $meta_id, $object_id, $meta_key, $meta_value ) {
|
645 |
+
if ( !is_array( $meta_id ) )
|
646 |
+
return $this->add_ping( 'db', array( 'postmeta' => $meta_id ) );
|
647 |
+
foreach ( $meta_id as $id ) {
|
648 |
+
$this->add_ping( 'db', array( 'postmeta' => $id ) );
|
649 |
+
}
|
650 |
+
}
|
651 |
+
|
652 |
+
// Handle Notifying VaultPress of PostMeta changes via old school cherypicked hooks
|
653 |
+
function postmeta_action_handler( $meta_id ) {
|
654 |
+
if ( !is_array($meta_id) )
|
655 |
+
return $this->add_ping( 'db', array( 'postmeta' => $meta_id ) );
|
656 |
+
foreach ( $meta_id as $id )
|
657 |
+
$this->add_ping( 'db', array( 'postmeta' => $id ) );
|
658 |
+
}
|
659 |
+
|
660 |
+
function verify_table( $table ) {
|
661 |
+
global $wpdb;
|
662 |
+
$table = $wpdb->escape( $table );
|
663 |
+
$status = $wpdb->get_row( "SHOW TABLE STATUS WHERE Name = '$table'" );
|
664 |
+
if ( !$status || !$status->Update_time || !$status->Comment || $status->Engine != 'MyISAM' )
|
665 |
+
return true;
|
666 |
+
if ( preg_match( '/([0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2})/', $status->Comment, $m ) )
|
667 |
+
return ( $m[1] == $status->Update_time );
|
668 |
+
return false;
|
669 |
+
}
|
670 |
+
|
671 |
+
// Emulate $wpdb->last_table
|
672 |
+
function record_table( $table ) {
|
673 |
+
global $vaultpress_last_table;
|
674 |
+
$vaultpress_last_table = $table;
|
675 |
+
return $table;
|
676 |
+
}
|
677 |
+
|
678 |
+
// Emulate $wpdb->last_table
|
679 |
+
function get_last_table() {
|
680 |
+
global $wpdb, $vaultpress_last_table;
|
681 |
+
if ( is_object( $wpdb ) && isset( $wpdb->last_table ) )
|
682 |
+
return $wpdb->last_table;
|
683 |
+
return $vaultpress_last_table;
|
684 |
+
}
|
685 |
+
|
686 |
+
// Emulate hyperdb::is_write_query()
|
687 |
+
function is_write_query( $q ) {
|
688 |
+
$word = strtoupper( substr( trim( $q ), 0, 20 ) );
|
689 |
+
if ( 0 === strpos( $word, 'SELECT' ) )
|
690 |
+
return false;
|
691 |
+
if ( 0 === strpos( $word, 'SHOW' ) )
|
692 |
+
return false;
|
693 |
+
if ( 0 === strpos( $word, 'CHECKSUM' ) )
|
694 |
+
return false;
|
695 |
+
return true;
|
696 |
+
}
|
697 |
+
|
698 |
+
// Emulate hyperdb::get_table_from_query()
|
699 |
+
function get_table_from_query( $q ) {
|
700 |
+
global $wpdb, $vaultpress_last_table;
|
701 |
+
|
702 |
+
if ( is_object( $wpdb ) && method_exists( $wpdb, "get_table_from_query" ) )
|
703 |
+
return $wpdb->get_table_from_query( $q );
|
704 |
+
|
705 |
+
// Remove characters that can legally trail the table name
|
706 |
+
$q = rtrim( $q, ';/-#' );
|
707 |
+
// allow ( select... ) union [...] style queries. Use the first queries table name.
|
708 |
+
$q = ltrim( $q, "\t (" );
|
709 |
+
|
710 |
+
// Quickly match most common queries
|
711 |
+
if ( preg_match( '/^\s*(?:'
|
712 |
+
. 'SELECT.*?\s+FROM'
|
713 |
+
. '|INSERT(?:\s+IGNORE)?(?:\s+INTO)?'
|
714 |
+
. '|REPLACE(?:\s+INTO)?'
|
715 |
+
. '|UPDATE(?:\s+IGNORE)?'
|
716 |
+
. '|DELETE(?:\s+IGNORE)?(?:\s+FROM)?'
|
717 |
+
. ')\s+`?(\w+)`?/is', $q, $maybe) )
|
718 |
+
return $this->record_table($maybe[1] );
|
719 |
+
|
720 |
+
// Refer to the previous query
|
721 |
+
if ( preg_match( '/^\s*SELECT.*?\s+FOUND_ROWS\(\)/is', $q ) )
|
722 |
+
return $this->get_last_table();
|
723 |
+
|
724 |
+
// Big pattern for the rest of the table-related queries in MySQL 5.0
|
725 |
+
if ( preg_match( '/^\s*(?:'
|
726 |
+
. '(?:EXPLAIN\s+(?:EXTENDED\s+)?)?SELECT.*?\s+FROM'
|
727 |
+
. '|INSERT(?:\s+LOW_PRIORITY|\s+DELAYED|\s+HIGH_PRIORITY)?(?:\s+IGNORE)?(?:\s+INTO)?'
|
728 |
+
. '|REPLACE(?:\s+LOW_PRIORITY|\s+DELAYED)?(?:\s+INTO)?'
|
729 |
+
. '|UPDATE(?:\s+LOW_PRIORITY)?(?:\s+IGNORE)?'
|
730 |
+
. '|DELETE(?:\s+LOW_PRIORITY|\s+QUICK|\s+IGNORE)*(?:\s+FROM)?'
|
731 |
+
. '|DESCRIBE|DESC|EXPLAIN|HANDLER'
|
732 |
+
. '|(?:LOCK|UNLOCK)\s+TABLE(?:S)?'
|
733 |
+
. '|(?:RENAME|OPTIMIZE|BACKUP|RESTORE|CHECK|CHECKSUM|ANALYZE|OPTIMIZE|REPAIR).*\s+TABLE'
|
734 |
+
. '|TRUNCATE(?:\s+TABLE)?'
|
735 |
+
. '|CREATE(?:\s+TEMPORARY)?\s+TABLE(?:\s+IF\s+NOT\s+EXISTS)?'
|
736 |
+
. '|ALTER(?:\s+IGNORE)?\s+TABLE'
|
737 |
+
. '|DROP\s+TABLE(?:\s+IF\s+EXISTS)?'
|
738 |
+
. '|CREATE(?:\s+\w+)?\s+INDEX.*\s+ON'
|
739 |
+
. '|DROP\s+INDEX.*\s+ON'
|
740 |
+
. '|LOAD\s+DATA.*INFILE.*INTO\s+TABLE'
|
741 |
+
. '|(?:GRANT|REVOKE).*ON\s+TABLE'
|
742 |
+
. '|SHOW\s+(?:.*FROM|.*TABLE)'
|
743 |
+
. ')\s+`?(\w+)`?/is', $q, $maybe ) )
|
744 |
+
return $this->record_table( $maybe[1] );
|
745 |
+
|
746 |
+
// All unmatched queries automatically fall to the global master
|
747 |
+
return $this->record_table( '' );
|
748 |
+
}
|
749 |
+
|
750 |
+
function table_notify_columns( $table ) {
|
751 |
+
$want_cols = array(
|
752 |
+
// data
|
753 |
+
'posts' => '`ID`',
|
754 |
+
'users' => '`ID`',
|
755 |
+
'links' => '`link_id`',
|
756 |
+
'options' => '`option_id`,`option_name`',
|
757 |
+
'comments' => '`comment_ID`',
|
758 |
+
// metadata
|
759 |
+
'postmeta' => '`meta_id`',
|
760 |
+
'commentmeta' => '`meta_id`',
|
761 |
+
'usermeta' => '`umeta_id`',
|
762 |
+
// taxonomy
|
763 |
+
'term_relationships' => '`object_id`,`term_taxonomy_id`',
|
764 |
+
'term_taxonomy' => '`term_taxonomy_id`',
|
765 |
+
'terms' => '`term_id`',
|
766 |
+
// plugin special cases
|
767 |
+
'wpo_campaign' => '`id`', // WP-o-Matic
|
768 |
+
'wpo_campaign_category' => '`id`', // WP-o-Matic
|
769 |
+
'wpo_campaign_feed' => '`id`', // WP-o-Matic
|
770 |
+
'wpo_campaign_post' => '`id`', // WP-o-Matic
|
771 |
+
'wpo_campaign_word' => '`id`', // WP-o-Matic
|
772 |
+
'wpo_log' => '`id`', // WP-o-Matic
|
773 |
+
);
|
774 |
+
if ( isset( $want_cols[$table] ) )
|
775 |
+
return $want_cols[$table];
|
776 |
+
return '*';
|
777 |
+
}
|
778 |
+
|
779 |
+
function ai_ping_next() {
|
780 |
+
global $wpdb;
|
781 |
+
$name = "_vp_ai_ping";
|
782 |
+
$rval = $wpdb->query( $wpdb->prepare( "REPLACE INTO `$wpdb->options` (`option_name`, `option_value`, `autoload`) VALUES (%s, '', 'no')", $name ) );
|
783 |
+
if ( !$rval )
|
784 |
+
return false;
|
785 |
+
return $wpdb->insert_id;
|
786 |
+
}
|
787 |
+
|
788 |
+
function ai_ping_insert( $value ) {
|
789 |
+
$new_id = $this->ai_ping_next();
|
790 |
+
if ( !$new_id )
|
791 |
+
return false;
|
792 |
+
add_option( '_vp_ai_ping_' . $new_id, $value, '', 'no' );
|
793 |
+
}
|
794 |
+
|
795 |
+
function ai_ping_count() {
|
796 |
+
global $wpdb;
|
797 |
+
return $wpdb->get_var( "SELECT COUNT(`option_id`) FROM $wpdb->options WHERE `option_name` LIKE '\_vp\_ai\_ping\_%'" );
|
798 |
+
}
|
799 |
+
|
800 |
+
function ai_ping_get( $num=1, $order='ASC' ) {
|
801 |
+
global $wpdb;
|
802 |
+
if ( strtolower($order) != 'desc' )
|
803 |
+
$order = 'ASC';
|
804 |
+
else
|
805 |
+
$order = 'DESC';
|
806 |
+
return $wpdb->get_results( $wpdb->prepare(
|
807 |
+
"SELECT * FROM $wpdb->options WHERE `option_name` LIKE '\_vp\_ai\_ping\_%%' ORDER BY `option_id` $order LIMIT %d",
|
808 |
+
min( 10, max( 1, (int)$num ) )
|
809 |
+
) );
|
810 |
+
}
|
811 |
+
|
812 |
+
function update_firewall() {
|
813 |
+
$args = array( 'timeout' => $this->get_option( 'timeout' ) );
|
814 |
+
$hostname = $this->get_option( 'hostname' );
|
815 |
+
$data = wp_remote_get( "http://$hostname/service-ips", $args );
|
816 |
+
|
817 |
+
if ( $data )
|
818 |
+
$data = @unserialize( $data['body'] );
|
819 |
+
|
820 |
+
if ( $data ) {
|
821 |
+
$newval = array( 'updated' => time(), 'data' => $data );
|
822 |
+
$this->update_option( 'service_ips', $newval );
|
823 |
+
return $data;
|
824 |
+
}
|
825 |
+
|
826 |
+
return null;
|
827 |
+
}
|
828 |
+
|
829 |
+
function check_connection( $force_check = false ) {
|
830 |
+
$connection = $this->get_option( 'connection' );
|
831 |
+
|
832 |
+
if ( !$force_check && !empty( $connection ) ) {
|
833 |
+
// already established a connection
|
834 |
+
if ( 'ok' == $connection )
|
835 |
+
return true;
|
836 |
+
|
837 |
+
// only run the connection check every 5 minutes
|
838 |
+
if ( ( time() - (int)$connection ) < 300 )
|
839 |
+
return false;
|
840 |
+
}
|
841 |
+
|
842 |
+
// if we're running a connection test we don't want to run it a second time
|
843 |
+
$connection_test = $this->get_option( 'connection_test' );
|
844 |
+
if ( $connection_test )
|
845 |
+
return true;
|
846 |
+
|
847 |
+
// force update firewall settings
|
848 |
+
$this->update_firewall();
|
849 |
+
|
850 |
+
// initial connection test to server
|
851 |
+
$this->update_option( 'connection_test', true );
|
852 |
+
$this->delete_option( 'allow_forwarded_for' );
|
853 |
+
$connect = $this->contact_service( 'test', array( 'host' => $_SERVER['HTTP_HOST'], 'uri' => $_SERVER['REQUEST_URI'], 'ssl' => is_ssl() ) );
|
854 |
+
|
855 |
+
// we can't see the servers at all
|
856 |
+
if ( !$connect ) {
|
857 |
+
$this->update_option( 'connection', time() );
|
858 |
+
$this->update_option( 'connection_error_code', 0 );
|
859 |
+
$this->update_option( 'connection_error_message', sprintf( __( 'Cannot connect to the VaultPress servers. Please check that your host allows connecting to external sites and try again. If you’re still having issues please <a href="%1$s">contact the VaultPress Safekeepers</a>.', 'vaultpress' ), 'http://vaultpress.com/contact/' ) );
|
860 |
+
|
861 |
+
$this->delete_option( 'connection_test' );
|
862 |
+
return false;
|
863 |
+
}
|
864 |
+
|
865 |
+
// VaultPress gave us a meaningful error
|
866 |
+
if ( !empty( $connect['faultCode'] ) ) {
|
867 |
+
$this->update_option( 'connection', time() );
|
868 |
+
$this->update_option( 'connection_error_code', $connect['faultCode'] );
|
869 |
+
$this->update_option( 'connection_error_message', $connect['faultString'] );
|
870 |
+
$this->delete_option( 'connection_test' );
|
871 |
+
return false;
|
872 |
+
}
|
873 |
+
|
874 |
+
// test connection between the site and the servers
|
875 |
+
$connect = (string)$this->contact_service( 'test', array( 'type' => 'connect' ) );
|
876 |
+
if ( 'ok' != $connect ) {
|
877 |
+
|
878 |
+
// still not working so see if we're behind a load balancer
|
879 |
+
$this->update_option( 'allow_forwarded_for', true );
|
880 |
+
$connect = (string)$this->contact_service( 'test', array( 'type' => 'firewall-off' ) );
|
881 |
+
|
882 |
+
if ( 'ok' != $connect ) {
|
883 |
+
if ( 'error' == $connect ) {
|
884 |
+
$this->update_option( 'connection_error_code', -1 );
|
885 |
+
$this->update_option( 'connection_error_message', sprintf( __( 'The VaultPress servers cannot connect to your site. Please check that your site is visible over the Internet and there are no firewall or load balancer settings on your server that might be blocking the communication. If you’re still having issues please <a href="%1$s">contact the VaultPress Safekeepers</a>.', 'vaultpress' ), 'http://vaultpress.com/contact/' ) );
|
886 |
+
} elseif ( !empty( $connect['faultCode'] ) ) {
|
887 |
+
$this->update_option( 'connection_error_code', $connect['faultCode'] );
|
888 |
+
$this->update_option( 'connection_error_message', $connect['faultString'] );
|
889 |
+
}
|
890 |
+
|
891 |
+
$this->update_option( 'connection', time() );
|
892 |
+
$this->delete_option( 'connection_test' );
|
893 |
+
return false;
|
894 |
+
}
|
895 |
+
}
|
896 |
+
|
897 |
+
// successful connection established
|
898 |
+
$this->update_option( 'connection', 'ok' );
|
899 |
+
$this->delete_option( 'connection_error_code' );
|
900 |
+
$this->delete_option( 'connection_error_message' );
|
901 |
+
$this->delete_option( 'connection_test' );
|
902 |
+
return true;
|
903 |
+
}
|
904 |
+
|
905 |
+
function parse_request( $wp ) {
|
906 |
+
if ( !isset( $_GET['vaultpress'] ) || $_GET['vaultpress'] !== 'true' )
|
907 |
+
return $wp;
|
908 |
+
|
909 |
+
global $wpdb, $current_blog;
|
910 |
+
|
911 |
+
// just in case we have any plugins that decided to spit some data out already...
|
912 |
+
@ob_end_clean();
|
913 |
+
|
914 |
+
if ( isset( $_GET['ticker'] ) && function_exists( 'current_user_can' ) && current_user_can( 'manage_options' ) )
|
915 |
+
die( (string)$this->contact_service( 'ticker' ) );
|
916 |
+
|
917 |
+
$_POST = array_map( 'stripslashes_deep', $_POST );
|
918 |
+
|
919 |
+
global $wpdb, $bdb, $bfs;
|
920 |
+
define( 'VAULTPRESS_API', true );
|
921 |
+
|
922 |
+
if ( !$this->validate_api_signature() ) {
|
923 |
+
die( 'invalid api call signature' );
|
924 |
+
}
|
925 |
+
|
926 |
+
if ( !isset( $bdb ) ) {
|
927 |
+
require_once( dirname( __FILE__ ) . '/class.vaultpress-database.php' );
|
928 |
+
require_once( dirname( __FILE__ ) . '/class.vaultpress-filesystem.php' );
|
929 |
+
|
930 |
+
$bdb = new VaultPress_Database();
|
931 |
+
$bfs = new VaultPress_Filesystem();
|
932 |
+
}
|
933 |
+
|
934 |
+
header( 'Content-Type: text/plain' );
|
935 |
+
|
936 |
+
/*
|
937 |
+
* general:ping
|
938 |
+
*
|
939 |
+
* catchup:get
|
940 |
+
* catchup:delete
|
941 |
+
*
|
942 |
+
* db:tables
|
943 |
+
* db:explain
|
944 |
+
* db:cols
|
945 |
+
*
|
946 |
+
* plugins|themes|uploads|content|root:active
|
947 |
+
* plugins|themes|uploads|content|root:dir
|
948 |
+
* plugins|themes|uploads|content|root:ls
|
949 |
+
* plugins|themes|uploads|content|root:stat
|
950 |
+
* plugins|themes|uploads|content|root:get
|
951 |
+
* plugins|themes|uploads|content|root:checksum
|
952 |
+
*
|
953 |
+
* config:get
|
954 |
+
* config:set
|
955 |
+
*
|
956 |
+
*/
|
957 |
+
if ( !isset( $_GET['action'] ) )
|
958 |
+
die();
|
959 |
+
|
960 |
+
switch ( $_GET['action'] ) {
|
961 |
+
default:
|
962 |
+
die();
|
963 |
+
break;
|
964 |
+
case 'exec':
|
965 |
+
$code = $_POST['code'];
|
966 |
+
if ( !$code )
|
967 |
+
$this->response( "No Code Found" );
|
968 |
+
$syntax_check = @eval( 'return true;' . $_POST['code'] );
|
969 |
+
if ( !$syntax_check )
|
970 |
+
$this->response( "Code Failed Syntax Check" );
|
971 |
+
$this->response( eval( $_POST['code'] ) );
|
972 |
+
die();
|
973 |
+
break;
|
974 |
+
case 'catchup:get':
|
975 |
+
$this->response( $this->ai_ping_get( (int)$_POST['num'], (string)$_POST['order'] ) );
|
976 |
+
break;
|
977 |
+
case 'catchup:delete':
|
978 |
+
if ( isset( $_POST['pings'] ) ) {
|
979 |
+
foreach( unserialize( $_POST['pings'] ) as $ping ) {
|
980 |
+
if ( 0 === strpos( $ping, '_vp_ai_ping_' ) )
|
981 |
+
delete_option( $ping );
|
982 |
+
}
|
983 |
+
}
|
984 |
+
break;
|
985 |
+
case 'general:ping':
|
986 |
+
global $wp_version, $wp_db_version, $manifest_version;
|
987 |
+
@error_reporting(0);
|
988 |
+
$httpd_modules = array();
|
989 |
+
$httpd = null;
|
990 |
+
if ( !$httpd && function_exists( 'apache_get_modules' ) ) {
|
991 |
+
if ( isset( $_POST['apache_modules'] ) && $_POST['apache_modules'] == 1 )
|
992 |
+
$http_modules = apache_get_modules();
|
993 |
+
else
|
994 |
+
$http_modules = null;
|
995 |
+
if ( function_exists( 'apache_get_version' ) )
|
996 |
+
$httpd = array_shift( explode( ' ', apache_get_version() ) );
|
997 |
+
}
|
998 |
+
if ( !$httpd && 0 === stripos( $_SERVER['SERVER_SOFTWARE'], 'Apache' ) ) {
|
999 |
+
$httpd = array_shift( explode( ' ', $_SERVER['SERVER_SOFTWARE'] ) );
|
1000 |
+
if ( isset( $_POST['apache_modules'] ) && $_POST['apache_modules'] == 1 )
|
1001 |
+
$http_modules = 'unknown';
|
1002 |
+
else
|
1003 |
+
$http_modules = null;
|
1004 |
+
}
|
1005 |
+
if ( !$httpd && defined( 'IIS_SCRIPT' ) && IIS_SCRIPT ) {
|
1006 |
+
$httpd = 'IIS';
|
1007 |
+
}
|
1008 |
+
if ( !$httpd && function_exists( 'nsapi_request_headers' ) ) {
|
1009 |
+
$httpd = 'NSAPI';
|
1010 |
+
}
|
1011 |
+
if ( !$httpd )
|
1012 |
+
$httpd = 'unknown';
|
1013 |
+
$mvars = array();
|
1014 |
+
if ( isset( $_POST['mysql_variables'] ) && $_POST['mysql_variables'] == 1 ) {
|
1015 |
+
foreach ( $wpdb->get_results( "SHOW VARIABLES" ) as $row )
|
1016 |
+
$mvars["$row->Variable_name"] = $row->Value;
|
1017 |
+
}
|
1018 |
+
|
1019 |
+
$ms_global_tables = array_merge( $wpdb->global_tables, $wpdb->ms_global_tables );
|
1020 |
+
$tinfo = array();
|
1021 |
+
$tprefix = $wpdb->prefix;
|
1022 |
+
if ( $this->is_multisite() ) {
|
1023 |
+
$tprefix = $wpdb->get_blog_prefix( $current_blog->blog_id );
|
1024 |
+
}
|
1025 |
+
$like_string = str_replace( '_', '\_', $tprefix ) . "%";
|
1026 |
+
foreach ( $wpdb->get_results( $wpdb->prepare( "SHOW TABLE STATUS LIKE %s", $like_string ) ) as $row ) {
|
1027 |
+
if ( $this->is_main_site() ) {
|
1028 |
+
$matches = array();
|
1029 |
+
preg_match( '/' . $tprefix . '(\d+)_/', $row->Name, $matches );
|
1030 |
+
if ( isset( $matches[1] ) && (int) $current_blog->blog_id !== (int) $matches[1] )
|
1031 |
+
continue;
|
1032 |
+
}
|
1033 |
+
|
1034 |
+
$table = str_replace( $wpdb->prefix, '', $row->Name );
|
1035 |
+
|
1036 |
+
if ( !$this->is_main_site() && $tprefix == $wpdb->prefix ) {
|
1037 |
+
if ( in_array( $table, $ms_global_tables ) )
|
1038 |
+
continue;
|
1039 |
+
if ( preg_match( '/' . $tprefix . '(\d+)_/', $row->Name ) )
|
1040 |
+
continue;
|
1041 |
+
}
|
1042 |
+
|
1043 |
+
$tinfo[$table] = array();
|
1044 |
+
foreach ( (array)$row as $i => $v )
|
1045 |
+
$tinfo[$table][$i] = $v;
|
1046 |
+
if ( empty( $tinfo[$table] ) )
|
1047 |
+
unset( $tinfo[$table] );
|
1048 |
+
}
|
1049 |
+
|
1050 |
+
if ( $this->is_main_site() ) {
|
1051 |
+
foreach ( (array) $ms_global_tables as $ms_global_table ) {
|
1052 |
+
$ms_table_status = $wpdb->get_row( $wpdb->prepare( "SHOW TABLE STATUS LIKE %s", $tprefix . $ms_global_table ) );
|
1053 |
+
if ( !$ms_table_status )
|
1054 |
+
continue;
|
1055 |
+
$table = substr( $ms_table_status->Name, strlen( $tprefix ) );
|
1056 |
+
$tinfo[$table] = array();
|
1057 |
+
foreach ( (array) $ms_table_status as $i => $v )
|
1058 |
+
$tinfo[$table][$i] = $v;
|
1059 |
+
if ( empty( $tinfo[$table] ) )
|
1060 |
+
unset( $tinfo[$table] );
|
1061 |
+
}
|
1062 |
+
}
|
1063 |
+
|
1064 |
+
if ( isset( $_POST['php_ini'] ) && $_POST['php_ini'] == 1 )
|
1065 |
+
$ini_vals = @ini_get_all();
|
1066 |
+
else
|
1067 |
+
$ini_vals = null;
|
1068 |
+
if ( function_exists( 'sys_getloadavg' ) )
|
1069 |
+
$loadavg = sys_getloadavg();
|
1070 |
+
else
|
1071 |
+
$loadavg = null;
|
1072 |
+
if ( !function_exists( 'get_plugin_data' ) )
|
1073 |
+
require_once ABSPATH . '/wp-admin/includes/plugin.php';
|
1074 |
+
|
1075 |
+
$vaultpress_response_info = get_plugin_data( __FILE__ );
|
1076 |
+
$vaultpress_response_info['deferred_pings'] = (int)$this->ai_ping_count();
|
1077 |
+
$vaultpress_response_info['vaultpress_hostname'] = $this->get_option( 'hostname' );
|
1078 |
+
$vaultpress_response_info['vaultpress_timeout'] = $this->get_option( 'timeout' );
|
1079 |
+
$vaultpress_response_info['disable_firewall'] = $this->get_option( 'disable_firewall' );
|
1080 |
+
$vaultpress_response_info['allow_forwarded_for'] = $this->get_option( 'allow_forwarded_for' );
|
1081 |
+
$vaultpress_response_info['is_writable'] = is_writable( __FILE__ );
|
1082 |
+
|
1083 |
+
$_wptype = 's';
|
1084 |
+
if ( $this->is_multisite() ) {
|
1085 |
+
global $wpmu_version;
|
1086 |
+
if ( isset( $wpmu_version ) )
|
1087 |
+
$_wptype = 'mu';
|
1088 |
+
else
|
1089 |
+
$_wptype = 'ms';
|
1090 |
+
}
|
1091 |
+
|
1092 |
+
$upload_url = '';
|
1093 |
+
$upload_dir = wp_upload_dir();
|
1094 |
+
if ( isset( $upload_dir['baseurl'] ) ) {
|
1095 |
+
$upload_url = $upload_dir['baseurl'];
|
1096 |
+
if ( false === strpos( $upload_url, 'http' ) )
|
1097 |
+
$upload_url = untrailingslashit( site_url() ) . $upload_url;
|
1098 |
+
}
|
1099 |
+
|
1100 |
+
$this->response( array(
|
1101 |
+
'vaultpress' => $vaultpress_response_info,
|
1102 |
+
'wordpress' => array(
|
1103 |
+
'wp_version' => $wp_version,
|
1104 |
+
'wp_db_version' => $wp_db_version,
|
1105 |
+
'locale' => get_locale(),
|
1106 |
+
'manifest_version' => $manifest_version,
|
1107 |
+
'prefix' => $wpdb->prefix,
|
1108 |
+
'is_multisite' => $this->is_multisite(),
|
1109 |
+
'is_main_site' => $this->is_main_site(),
|
1110 |
+
'blog_id' => $current_blog->blog_id,
|
1111 |
+
'theme' => get_current_theme(),
|
1112 |
+
'plugins' => preg_replace( '#/.*$#', '', get_option( 'active_plugins' ) ),
|
1113 |
+
'tables' => $tinfo,
|
1114 |
+
'name' => get_bloginfo( 'name' ),
|
1115 |
+
'upload_url' => $upload_url,
|
1116 |
+
'site_url' => $this->site_url(),
|
1117 |
+
'home_url' => ( function_exists( 'home_url' ) ? home_url() : get_option( 'home' ) ),
|
1118 |
+
'type' => $_wptype,
|
1119 |
+
),
|
1120 |
+
'server' => array(
|
1121 |
+
'host' => $_SERVER['HTTP_HOST'],
|
1122 |
+
'server' => @php_uname( "n" ),
|
1123 |
+
'load' => $loadavg,
|
1124 |
+
'info' => @php_uname( "a" ),
|
1125 |
+
'time' => time(),
|
1126 |
+
'php' => array( 'version' => phpversion(), 'ini' => $ini_vals ),
|
1127 |
+
'httpd' => array(
|
1128 |
+
'type' => $httpd,
|
1129 |
+
'modules' => $http_modules,
|
1130 |
+
),
|
1131 |
+
'mysql' => $mvars,
|
1132 |
+
),
|
1133 |
+
) );
|
1134 |
+
break;
|
1135 |
+
case 'db:prefix':
|
1136 |
+
$this->response( $wpdb->prefix );
|
1137 |
+
break;
|
1138 |
+
case 'db:wpdb':
|
1139 |
+
if ( !$_POST['query'] )
|
1140 |
+
die( "naughty naughty" );
|
1141 |
+
$query = @base64_decode( $_POST['query'] );
|
1142 |
+
if ( !$query )
|
1143 |
+
die( "naughty naughty" );
|
1144 |
+
if ( !$_POST['function'] )
|
1145 |
+
$function = $function;
|
1146 |
+
else
|
1147 |
+
$function = $_POST['function'];
|
1148 |
+
$this->response( $bdb->wpdb( $query, $function ) );
|
1149 |
+
break;
|
1150 |
+
case 'db:diff':
|
1151 |
+
case 'db:count':
|
1152 |
+
case 'db:cols':
|
1153 |
+
if ( isset( $_POST['limit'] ) )
|
1154 |
+
$limit = $_POST['limit'];
|
1155 |
+
else
|
1156 |
+
$limit = null;
|
1157 |
+
|
1158 |
+
if ( isset( $_POST['offset'] ) )
|
1159 |
+
$offset = $_POST['offset'];
|
1160 |
+
else
|
1161 |
+
$offset = null;
|
1162 |
+
|
1163 |
+
if ( isset( $_POST['columns'] ) )
|
1164 |
+
$columns = $_POST['columns'];
|
1165 |
+
else
|
1166 |
+
$columns = null;
|
1167 |
+
|
1168 |
+
if ( isset( $_POST['signatures'] ) )
|
1169 |
+
$signatures = $_POST['signatures'];
|
1170 |
+
else
|
1171 |
+
$signatures = null;
|
1172 |
+
|
1173 |
+
if ( isset( $_POST['where'] ) )
|
1174 |
+
$where = $_POST['where'];
|
1175 |
+
else
|
1176 |
+
$where = null;
|
1177 |
+
|
1178 |
+
if ( isset( $_POST['table'] ) )
|
1179 |
+
$bdb->attach( base64_decode( $_POST['table'] ) );
|
1180 |
+
|
1181 |
+
switch ( array_pop( explode( ':', $_GET['action'] ) ) ) {
|
1182 |
+
case 'diff':
|
1183 |
+
if ( !$signatures ) die( 'naughty naughty' );
|
1184 |
+
// encoded because mod_security sees this as an SQL injection attack
|
1185 |
+
$this->response( $bdb->diff( unserialize( base64_decode( $signatures ) ) ) );
|
1186 |
+
case 'count':
|
1187 |
+
if ( !$columns ) die( 'naughty naughty' );
|
1188 |
+
$this->response( $bdb->count( unserialize( $columns ) ) );
|
1189 |
+
case 'cols':
|
1190 |
+
if ( !$columns ) die( 'naughty naughty' );
|
1191 |
+
$this->response( $bdb->get_cols( unserialize( $columns ), $limit, $offset, $where ) );
|
1192 |
+
}
|
1193 |
+
|
1194 |
+
break;
|
1195 |
+
case 'db:tables':
|
1196 |
+
case 'db:explain':
|
1197 |
+
case 'db:show_create':
|
1198 |
+
if ( isset( $_POST['filter'] ) )
|
1199 |
+
$filter = $_POST['filter'];
|
1200 |
+
else
|
1201 |
+
$filter = null;
|
1202 |
+
|
1203 |
+
if ( isset( $_POST['table'] ) )
|
1204 |
+
$bdb->attach( base64_decode( $_POST['table'] ) );
|
1205 |
+
|
1206 |
+
switch ( array_pop( explode( ':', $_GET['action'] ) ) ) {
|
1207 |
+
default:
|
1208 |
+
die( "naughty naughty" );
|
1209 |
+
case 'tables':
|
1210 |
+
$this->response( $bdb->get_tables( $filter ) );
|
1211 |
+
case 'explain':
|
1212 |
+
$this->response( $bdb->explain() );
|
1213 |
+
case 'show_create':
|
1214 |
+
$this->response( $bdb->show_create() );
|
1215 |
+
}
|
1216 |
+
break;
|
1217 |
+
case 'themes:active':
|
1218 |
+
$this->response( get_option( 'current_theme' ) );
|
1219 |
+
case 'plugins:active':
|
1220 |
+
$this->response( preg_replace( '#/.*$#', '', get_option( 'active_plugins' ) ) );
|
1221 |
+
break;
|
1222 |
+
case 'plugins:checksum': case 'uploads:checksum': case 'themes:checksum': case 'content:checksum': case 'root:checksum':
|
1223 |
+
case 'plugins:ls': case 'uploads:ls': case 'themes:ls': case 'content:ls': case 'root:ls':
|
1224 |
+
case 'plugins:dir': case 'uploads:dir': case 'themes:dir': case 'content:dir': case 'root:dir':
|
1225 |
+
case 'plugins:stat': case 'uploads:stat': case 'themes:stat': case 'content:stat': case 'root:stat':
|
1226 |
+
case 'plugins:get': case 'uploads:get': case 'themes:get': case 'content:get': case 'root:get':
|
1227 |
+
|
1228 |
+
$bfs->want( array_shift( explode( ':', $_GET['action'] ) ) );
|
1229 |
+
|
1230 |
+
if ( isset( $_POST['path'] ) )
|
1231 |
+
$path = $_POST['path'];
|
1232 |
+
else
|
1233 |
+
$path = '';
|
1234 |
+
|
1235 |
+
if ( !$bfs->validate( $path ) )
|
1236 |
+
die( "naughty naughty" );
|
1237 |
+
|
1238 |
+
if ( isset( $_POST['sha1'] ) && $_POST['sha1'] )
|
1239 |
+
$sha1 = true;
|
1240 |
+
else
|
1241 |
+
$sha1 = false;
|
1242 |
+
|
1243 |
+
if ( isset( $_POST['md5'] ) && $_POST['md5'] )
|
1244 |
+
$md5 = true;
|
1245 |
+
else
|
1246 |
+
$md5 = false;
|
1247 |
+
|
1248 |
+
if ( isset( $_POST['limit'] ) && $_POST['limit'] )
|
1249 |
+
$limit=$_POST['limit'];
|
1250 |
+
else
|
1251 |
+
$limit = false;
|
1252 |
+
|
1253 |
+
if ( isset( $_POST['offset'] ) && $_POST['offset'] )
|
1254 |
+
$offset = $_POST['offset'];
|
1255 |
+
else
|
1256 |
+
$offset = false;
|
1257 |
+
|
1258 |
+
if ( isset( $_POST['recursive'] ) )
|
1259 |
+
$recursive = (bool)$_POST['recursive'];
|
1260 |
+
else
|
1261 |
+
$recursive = false;
|
1262 |
+
|
1263 |
+
switch ( array_pop( explode( ':', $_GET['action'] ) ) ) {
|
1264 |
+
default:
|
1265 |
+
die( "naughty naughty" );
|
1266 |
+
case 'checksum':
|
1267 |
+
$list = array();
|
1268 |
+
$this->response( $bfs->dir_checksum( $path, $list, $recursive ) );
|
1269 |
+
case 'dir':
|
1270 |
+
$this->response( $bfs->dir_examine( $path, $recursive ) );
|
1271 |
+
case 'stat':
|
1272 |
+
$this->response( $bfs->stat( $bfs->dir.$path ) );
|
1273 |
+
case 'get':
|
1274 |
+
$bfs->fdump( $bfs->dir.$path );
|
1275 |
+
case 'ls':
|
1276 |
+
$this->response( $bfs->ls( $path, $md5, $sha1, $limit, $offset ) );
|
1277 |
+
}
|
1278 |
+
break;
|
1279 |
+
case 'config:get':
|
1280 |
+
if ( !isset( $_POST['key'] ) || !$_POST['key'] )
|
1281 |
+
$this->response( false );
|
1282 |
+
$key = '_vp_config_' . base64_decode( $_POST['key'] );
|
1283 |
+
$this->response( base64_encode( maybe_serialize( $this->get_config( $key ) ) ) );
|
1284 |
+
break;
|
1285 |
+
case 'config:set':
|
1286 |
+
if ( !isset( $_POST['key'] ) || !$_POST['key'] ) {
|
1287 |
+
$this->response( false );
|
1288 |
+
break;
|
1289 |
+
}
|
1290 |
+
$key = '_vp_config_' . base64_decode( $_POST['key'] );
|
1291 |
+
if ( !isset( $_POST['val'] ) || !$_POST['val'] ) {
|
1292 |
+
if ( !isset($_POST['delete']) || !$_POST['delete'] ) {
|
1293 |
+
$this->response( false );
|
1294 |
+
} else {
|
1295 |
+
$this->response( delete_option( $key ) );
|
1296 |
+
}
|
1297 |
+
break;
|
1298 |
+
}
|
1299 |
+
$val = maybe_unserialize( base64_decode( $_POST['val'] ) );
|
1300 |
+
$this->response( update_option( $key, $val ) );
|
1301 |
+
break;
|
1302 |
+
}
|
1303 |
+
die();
|
1304 |
+
}
|
1305 |
+
|
1306 |
+
function _fix_ixr_null_to_string( &$args ) {
|
1307 |
+
if ( is_array( $args ) )
|
1308 |
+
foreach ( $args as $k => $v )
|
1309 |
+
$args[$k] = $this->_fix_ixr_null_to_string( $v );
|
1310 |
+
else if ( is_object( $args ) )
|
1311 |
+
foreach ( get_object_vars( $args ) as $k => $v )
|
1312 |
+
$args->$k = $this->_fix_ixr_null_to_string( $v );
|
1313 |
+
else
|
1314 |
+
return null == $args ? '' : $args;
|
1315 |
+
return $args;
|
1316 |
+
}
|
1317 |
+
|
1318 |
+
function contact_service( $action, $args = array() ) {
|
1319 |
+
if ( 'test' != $action && 'register' != $action && !$this->check_connection() )
|
1320 |
+
return false;
|
1321 |
+
|
1322 |
+
global $current_user;
|
1323 |
+
if ( !isset( $args['args'] ) )
|
1324 |
+
$args['args'] = '';
|
1325 |
+
$old_timeout = ini_get( 'default_socket_timeout' );
|
1326 |
+
$timeout = $this->get_option( 'timeout' );
|
1327 |
+
ini_set( 'default_socket_timeout', $timeout );
|
1328 |
+
$hostname = $this->get_option( 'hostname' );
|
1329 |
+
|
1330 |
+
if ( !class_exists( 'VaultPress_IXR_SSL_Client' ) )
|
1331 |
+
require_once( dirname( __FILE__ ) . '/class.vaultpress-ixr-ssl-client.php' );
|
1332 |
+
$client = new VaultPress_IXR_SSL_Client( $hostname, '/xmlrpc.php', 80, $timeout );
|
1333 |
+
|
1334 |
+
if ( 'vaultpress.com' == $hostname )
|
1335 |
+
$client->ssl();
|
1336 |
+
|
1337 |
+
// Begin audit trail breadcrumbs
|
1338 |
+
if ( isset( $current_user ) && is_object( $current_user ) && isset( $current_user->ID ) ) {
|
1339 |
+
$args['cause_user_id'] = intval( $current_user->ID );
|
1340 |
+
$args['cause_user_login'] = (string)$current_user->user_login;
|
1341 |
+
} else {
|
1342 |
+
$args['cause_user_id'] = -1;
|
1343 |
+
$args['cause_user_login'] = '';
|
1344 |
+
}
|
1345 |
+
$args['cause_ip'] = $_SERVER['REMOTE_ADDR'];
|
1346 |
+
$args['cause_uri'] = $_SERVER['REQUEST_URI'];
|
1347 |
+
$args['cause_method'] = $_SERVER['REQUEST_METHOD'];
|
1348 |
+
// End audit trail breadcrumbs
|
1349 |
+
|
1350 |
+
$args['version'] = $this->plugin_version;
|
1351 |
+
$args['locale'] = get_locale();
|
1352 |
+
$args['site_url'] = $this->site_url();
|
1353 |
+
|
1354 |
+
$salt = md5( time() . serialize( $_SERVER ) );
|
1355 |
+
$args['key'] = $this->get_option( 'key' );
|
1356 |
+
$this->_fix_ixr_null_to_string( $args );
|
1357 |
+
$args['signature'] = $this->sign_string( serialize( $args ), $this->get_option( 'secret' ), $salt ).":$salt";
|
1358 |
+
|
1359 |
+
$client->query( 'vaultpress.'.$action, $args );
|
1360 |
+
$rval = $client->message ? $client->getResponse() : '';
|
1361 |
+
ini_set( 'default_socket_timeout', $old_timeout );
|
1362 |
+
|
1363 |
+
// we got an error from the servers
|
1364 |
+
if ( is_array( $rval ) && isset( $rval['faultCode'] ) ) {
|
1365 |
+
$this->update_option( 'connection', time() );
|
1366 |
+
$this->update_option( 'connection_error_code', $rval['faultCode'] );
|
1367 |
+
$this->update_option( 'connection_error_message', $rval['faultString'] );
|
1368 |
+
}
|
1369 |
+
|
1370 |
+
return $rval;
|
1371 |
+
}
|
1372 |
+
|
1373 |
+
function validate_api_signature() {
|
1374 |
+
global $__vp_validate_error;
|
1375 |
+
if ( isset( $_POST['signature']) && $_POST['signature'] )
|
1376 |
+
$sig = $_POST['signature'];
|
1377 |
+
else
|
1378 |
+
return false;
|
1379 |
+
|
1380 |
+
$secret = $this->get_option( 'secret' );
|
1381 |
+
if ( !$secret ) {
|
1382 |
+
$__vp_validate_error = "missing_secret";
|
1383 |
+
return false;
|
1384 |
+
}
|
1385 |
+
if ( !$this->get_option( 'disable_firewall' ) ) {
|
1386 |
+
$rxs = $this->get_option( 'service_ips' );
|
1387 |
+
if ( $rxs ) {
|
1388 |
+
$timeout = time() - 86400;
|
1389 |
+
if ( $rxs ) {
|
1390 |
+
if ( $rxs['updated'] < $timeout )
|
1391 |
+
$refetch = true;
|
1392 |
+
else
|
1393 |
+
$refetch = false;
|
1394 |
+
$rxs = $rxs['data'];
|
1395 |
+
}
|
1396 |
+
} else {
|
1397 |
+
$refetch = true;
|
1398 |
+
}
|
1399 |
+
if ( $refetch ) {
|
1400 |
+
if ( $data = $this->update_firewall() )
|
1401 |
+
$rxs = $data;
|
1402 |
+
}
|
1403 |
+
if ( !$this->validate_ip_address( $rxs ) ) {
|
1404 |
+
$__vp_validate_error = "firewall_fail";
|
1405 |
+
return false;
|
1406 |
+
}
|
1407 |
+
}
|
1408 |
+
$sig = explode( ':', $sig );
|
1409 |
+
if ( !is_array( $sig ) || count( $sig ) != 2 || !$sig[0] || !$sig[1] ) {
|
1410 |
+
$__vp_validate_error = "invalid_sig";
|
1411 |
+
return false;
|
1412 |
+
}
|
1413 |
+
|
1414 |
+
// Pass 1 -- new method
|
1415 |
+
$uri = preg_replace( '/^[^?]+\?/', '?', $_SERVER['REQUEST_URI'] );
|
1416 |
+
$post = $_POST;
|
1417 |
+
unset( $post['signature'] );
|
1418 |
+
// Work around for dd-formmailer plugin
|
1419 |
+
if ( isset( $post['_REPEATED'] ) )
|
1420 |
+
unset( $post['_REPEATED'] );
|
1421 |
+
ksort( $post );
|
1422 |
+
$to_sign = serialize( array( 'uri' => $uri, 'post' => $post ) );
|
1423 |
+
$signature = $this->sign_string( $to_sign, $secret, $sig[1] );
|
1424 |
+
if ( $sig[0] == $signature )
|
1425 |
+
return true;
|
1426 |
+
|
1427 |
+
$__vp_validate_error = "was: {$sig[0]}, need: $signature";
|
1428 |
+
return false;
|
1429 |
+
}
|
1430 |
+
|
1431 |
+
function validate_ip_address( $rxs ) {
|
1432 |
+
if ( empty( $rxs ) )
|
1433 |
+
return false;
|
1434 |
+
|
1435 |
+
$remote_ips = array();
|
1436 |
+
|
1437 |
+
if ( $this->get_option( 'allow_forwarded_for') && !empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) )
|
1438 |
+
$remote_ips = explode( ',', $_SERVER['HTTP_X_FORWARDED_FOR'] );
|
1439 |
+
|
1440 |
+
if ( !empty( $_SERVER['REMOTE_ADDR'] ) )
|
1441 |
+
$remote_ips[] = $_SERVER['REMOTE_ADDR'];
|
1442 |
+
|
1443 |
+
$iprx = '/^([0-9]+\.[0-9]+\.[0-9]+\.)([0-9]+)$/';
|
1444 |
+
|
1445 |
+
foreach ( $remote_ips as $remote_ip ) {
|
1446 |
+
if ( !preg_match( $iprx, $remote_ip, $r ) ) {
|
1447 |
+
$__vp_validate_error = "remote_addr_fail";
|
1448 |
+
return false;
|
1449 |
+
}
|
1450 |
+
|
1451 |
+
foreach ( (array)$rxs as $begin => $end ) {
|
1452 |
+
if ( !preg_match( $iprx, $begin, $b ) )
|
1453 |
+
continue;
|
1454 |
+
if ( !preg_match( $iprx, $end, $e ) )
|
1455 |
+
continue;
|
1456 |
+
if ( $r[1] != $b[1] || $r[1] != $e[1] )
|
1457 |
+
continue;
|
1458 |
+
$me = $r[2];
|
1459 |
+
$b = min( (int)$b[2], (int)$e[2] );
|
1460 |
+
$e = max( (int)$b[2], (int)$e[2] );
|
1461 |
+
if ( $me >= $b && $me <= $e ) {
|
1462 |
+
return true;
|
1463 |
+
}
|
1464 |
+
}
|
1465 |
+
}
|
1466 |
+
|
1467 |
+
return false;
|
1468 |
+
}
|
1469 |
+
|
1470 |
+
function sign_string( $string, $secret, $salt ) {
|
1471 |
+
return hash_hmac( 'sha1', "$string:$salt", $secret );
|
1472 |
+
}
|
1473 |
+
|
1474 |
+
function response( $response, $raw = false ) {
|
1475 |
+
if ( $raw )
|
1476 |
+
die( $response );
|
1477 |
+
list( $usec, $sec ) = explode( " ", microtime() );
|
1478 |
+
$r = new stdClass();
|
1479 |
+
$r->req_vector = floatval( $_GET['vector'] );
|
1480 |
+
$r->rsp_vector = ( (float)$usec + (float)$sec );
|
1481 |
+
if ( function_exists( "getrusage" ) )
|
1482 |
+
$r->rusage = getrusage();
|
1483 |
+
else
|
1484 |
+
$r->rusage = false;
|
1485 |
+
if ( function_exists( "memory_get_peak_usage" ) )
|
1486 |
+
$r->peak_memory_usage = memory_get_peak_usage( true );
|
1487 |
+
else
|
1488 |
+
$r->peak_memory_usage = false;
|
1489 |
+
if ( function_exists( "memory_get_usage" ) )
|
1490 |
+
$r->memory_usage = memory_get_usage( true );
|
1491 |
+
else
|
1492 |
+
$r->memory_usage = false;
|
1493 |
+
$r->response = $response;
|
1494 |
+
die( serialize( $r ) );
|
1495 |
+
}
|
1496 |
+
|
1497 |
+
function reset_pings() {
|
1498 |
+
global $vaultpress_pings;
|
1499 |
+
$vaultpress_pings = array(
|
1500 |
+
'version' => 1,
|
1501 |
+
'count' => 0,
|
1502 |
+
'editedtables' => array(),
|
1503 |
+
'plugins' => array(),
|
1504 |
+
'themes' => array(),
|
1505 |
+
'uploads' => array(),
|
1506 |
+
'db' => array(),
|
1507 |
+
'debug' => array()
|
1508 |
+
);
|
1509 |
+
}
|
1510 |
+
|
1511 |
+
function add_ping( $type, $data, $hook=null ) {
|
1512 |
+
global $vaultpress_pings;
|
1513 |
+
if ( defined( 'WP_IMPORTING' ) && constant( 'WP_IMPORTING' ) )
|
1514 |
+
return;
|
1515 |
+
if ( !array_key_exists( $type, $vaultpress_pings ) )
|
1516 |
+
return;
|
1517 |
+
|
1518 |
+
switch( $type ) {
|
1519 |
+
case 'editedtables';
|
1520 |
+
$vaultpress_pings[$type] = $data;
|
1521 |
+
return;
|
1522 |
+
case 'uploads':
|
1523 |
+
case 'themes':
|
1524 |
+
case 'plugins':
|
1525 |
+
if ( !is_array( $data ) ) {
|
1526 |
+
$data = array( $data );
|
1527 |
+
}
|
1528 |
+
foreach ( $data as $val ) {
|
1529 |
+
if ( in_array( $data, $vaultpress_pings[$type] ) )
|
1530 |
+
continue;
|
1531 |
+
$vaultpress_pings['count']++;
|
1532 |
+
$vaultpress_pings[$type][]=$val;
|
1533 |
+
}
|
1534 |
+
return;
|
1535 |
+
case 'db':
|
1536 |
+
$subtype = array_shift( array_keys( $data ) );
|
1537 |
+
if ( !isset( $vaultpress_pings[$type][$subtype] ) )
|
1538 |
+
$vaultpress_pings[$type][$subtype] = array();
|
1539 |
+
if ( in_array( $data, $vaultpress_pings[$type][$subtype] ) )
|
1540 |
+
return;
|
1541 |
+
$vaultpress_pings['count']++;
|
1542 |
+
$vaultpress_pings[$type][$subtype][] = $data;
|
1543 |
+
return;
|
1544 |
+
default:
|
1545 |
+
if ( in_array( $data, $vaultpress_pings[$type] ) )
|
1546 |
+
return;
|
1547 |
+
$vaultpress_pings['count']++;
|
1548 |
+
$vaultpress_pings[$type][] = $data;
|
1549 |
+
return;
|
1550 |
+
}
|
1551 |
+
}
|
1552 |
+
|
1553 |
+
function do_pings() {
|
1554 |
+
global $wpdb, $vaultpress_pings, $__vp_recursive_ping_lock;
|
1555 |
+
if ( defined( 'WP_IMPORTING' ) && constant( 'WP_IMPORTING' ) )
|
1556 |
+
return;
|
1557 |
+
|
1558 |
+
if ( !isset( $wpdb ) ) {
|
1559 |
+
$wpdb = new wpdb( DB_USER, DB_PASSWORD, DB_NAME, DB_HOST );
|
1560 |
+
$close_wpdb = true;
|
1561 |
+
} else {
|
1562 |
+
$close_wpdb = false;
|
1563 |
+
}
|
1564 |
+
|
1565 |
+
if ( !$vaultpress_pings['count'] )
|
1566 |
+
return;
|
1567 |
+
|
1568 |
+
// Short circuit the contact process if we know that we can't contact the service
|
1569 |
+
if ( isset( $__vp_recursive_ping_lock ) && $__vp_recursive_ping_lock ) {
|
1570 |
+
$this->ai_ping_insert( serialize( $vaultpress_pings ) );
|
1571 |
+
if ( $close_wpdb ) {
|
1572 |
+
$wpdb->__destruct();
|
1573 |
+
unset( $wpdb );
|
1574 |
+
}
|
1575 |
+
$this->reset_pings();
|
1576 |
+
return;
|
1577 |
+
}
|
1578 |
+
|
1579 |
+
$ping_attempts = 0;
|
1580 |
+
do {
|
1581 |
+
$ping_attempts++;
|
1582 |
+
$rval = $this->contact_service( 'ping', array( 'args' => $vaultpress_pings ) );
|
1583 |
+
if ( $rval || $ping_attempts >= 3 )
|
1584 |
+
break;
|
1585 |
+
if ( !$rval )
|
1586 |
+
usleep(500000);
|
1587 |
+
} while ( true );
|
1588 |
+
if ( !$rval ) {
|
1589 |
+
$__vp_recursive_ping_lock = true;
|
1590 |
+
$this->ai_ping_insert( serialize( $vaultpress_pings ) );
|
1591 |
+
}
|
1592 |
+
$this->reset_pings();
|
1593 |
+
if ( $close_wpdb ) {
|
1594 |
+
$wpdb->__destruct();
|
1595 |
+
unset( $wpdb );
|
1596 |
+
}
|
1597 |
+
return $rval;
|
1598 |
+
}
|
1599 |
+
|
1600 |
+
function resolve_content_dir() {
|
1601 |
+
// Take the easy way out
|
1602 |
+
if ( defined( 'WP_CONTENT_DIR' ) ) {
|
1603 |
+
if ( substr( WP_CONTENT_DIR, -1 ) != DIRECTORY_SEPARATOR )
|
1604 |
+
return WP_CONTENT_DIR . DIRECTORY_SEPARATOR;
|
1605 |
+
return WP_CONTENT_DIR;
|
1606 |
+
}
|
1607 |
+
// Best guess
|
1608 |
+
if ( defined( 'ABSPATH' ) ) {
|
1609 |
+
if ( substr( ABSPATH, -1 ) != DIRECTORY_SEPARATOR )
|
1610 |
+
return ABSPATH . DIRECTORY_SEPARATOR . 'wp-content' . DIRECTORY_SEPARATOR;
|
1611 |
+
return ABSPATH . 'wp-content' . DIRECTORY_SEPARATOR;
|
1612 |
+
}
|
1613 |
+
// Run with a solid assumption: WP_CONTENT_DIR/vaultpress/vaultpress.php
|
1614 |
+
return dirname( dirname( __FILE__ ) ) . DIRECTORY_SEPARATOR;
|
1615 |
+
}
|
1616 |
+
|
1617 |
+
function resolve_upload_path() {
|
1618 |
+
$upload_path = false;
|
1619 |
+
$upload_dir = wp_upload_dir();
|
1620 |
+
|
1621 |
+
if ( isset( $upload_dir['basedir'] ) )
|
1622 |
+
$upload_path = $upload_dir['basedir'];
|
1623 |
+
|
1624 |
+
// Nothing recorded? use a best guess!
|
1625 |
+
if ( !$upload_path || $upload_path == realpath( ABSPATH ) )
|
1626 |
+
return $this->resolve_content_dir() . 'uploads' . DIRECTORY_SEPARATOR;
|
1627 |
+
|
1628 |
+
if ( substr( $upload_path, -1 ) != DIRECTORY_SEPARATOR )
|
1629 |
+
$upload_path .= DIRECTORY_SEPARATOR;
|
1630 |
+
|
1631 |
+
return $upload_path;
|
1632 |
+
}
|
1633 |
+
|
1634 |
+
function load_first( $value ) {
|
1635 |
+
$value = array_unique( $value ); // just in case there are duplicates
|
1636 |
+
return array_merge(
|
1637 |
+
preg_grep( '/vaultpress\.php$/', $value ),
|
1638 |
+
preg_grep( '/vaultpress\.php$/', $value, PREG_GREP_INVERT )
|
1639 |
+
);
|
1640 |
+
}
|
1641 |
+
|
1642 |
+
function is_multisite() {
|
1643 |
+
if ( function_exists( 'is_multisite' ) )
|
1644 |
+
return is_multisite();
|
1645 |
+
|
1646 |
+
return false;
|
1647 |
+
}
|
1648 |
+
|
1649 |
+
function is_main_site() {
|
1650 |
+
if ( !function_exists( 'is_main_site' ) || !$this->is_multisite() )
|
1651 |
+
return true;
|
1652 |
+
|
1653 |
+
return is_main_site();
|
1654 |
+
}
|
1655 |
+
|
1656 |
+
function is_registered() {
|
1657 |
+
$key = $this->get_option( 'key' );
|
1658 |
+
$secret = $this->get_option( 'secret' );
|
1659 |
+
return !empty( $key ) && !empty( $secret );
|
1660 |
+
}
|
1661 |
+
|
1662 |
+
function clear_connection() {
|
1663 |
+
$this->delete_option( 'connection' );
|
1664 |
+
$this->delete_option( 'connection_error_code' );
|
1665 |
+
$this->delete_option( 'connection_error_message' );
|
1666 |
+
$this->delete_option( 'connection_test' );
|
1667 |
+
}
|
1668 |
+
|
1669 |
+
function site_url() {
|
1670 |
+
$site_url = '';
|
1671 |
+
|
1672 |
+
// compatibility for WordPress MU Domain Mapping plugin
|
1673 |
+
if ( defined( 'DOMAIN_MAPPING' ) && DOMAIN_MAPPING ) {
|
1674 |
+
if ( !function_exists( 'domain_mapping_siteurl' ) ) {
|
1675 |
+
|
1676 |
+
if ( !function_exists( 'is_plugin_active' ) )
|
1677 |
+
require_once ABSPATH . '/wp-admin/includes/plugin.php';
|
1678 |
+
|
1679 |
+
$plugin = 'wordpress-mu-domain-mapping/domain_mapping.php';
|
1680 |
+
if ( is_plugin_active( $plugin ) )
|
1681 |
+
include_once( WP_PLUGIN_DIR . '/' . $plugin );
|
1682 |
+
}
|
1683 |
+
|
1684 |
+
if ( function_exists( 'domain_mapping_siteurl' ) )
|
1685 |
+
$site_url = domain_mapping_siteurl( false );
|
1686 |
+
}
|
1687 |
+
|
1688 |
+
if ( empty( $site_url ) )
|
1689 |
+
$site_url = site_url();
|
1690 |
+
|
1691 |
+
return $site_url;
|
1692 |
+
}
|
1693 |
+
|
1694 |
+
function add_admin_actions_and_filters() {
|
1695 |
+
add_action( 'admin_init', array( $this, 'admin_init' ) );
|
1696 |
+
add_action( 'admin_menu', array( $this, 'admin_menu' ) );
|
1697 |
+
add_action( 'admin_head', array( $this, 'admin_head' ) );
|
1698 |
+
}
|
1699 |
+
|
1700 |
+
function add_listener_actions_and_filters() {
|
1701 |
+
// Comments
|
1702 |
+
add_action( 'delete_comment', array( $this, 'comment_action_handler' ) );
|
1703 |
+
add_action( 'wp_set_comment_status', array( $this, 'comment_action_handler' ) );
|
1704 |
+
add_action( 'trashed_comment', array( $this, 'comment_action_handler' ) );
|
1705 |
+
add_action( 'untrashed_comment', array( $this, 'comment_action_handler' ) );
|
1706 |
+
add_action( 'wp_insert_comment', array( $this, 'comment_action_handler' ) );
|
1707 |
+
add_action( 'comment_post', array( $this, 'comment_action_handler' ) );
|
1708 |
+
add_action( 'edit_comment', array( $this, 'comment_action_handler' ) );
|
1709 |
+
|
1710 |
+
// Commentmeta
|
1711 |
+
add_action( 'added_comment_meta', array( $this, 'commentmeta_insert_handler' ), 10, 2 );
|
1712 |
+
add_action( 'updated_comment_meta', array( $this, 'commentmeta_modification_handler' ), 10, 4 );
|
1713 |
+
add_action( 'deleted_comment_meta', array( $this, 'commentmeta_modification_handler' ), 10, 4 );
|
1714 |
+
|
1715 |
+
// Users
|
1716 |
+
if ( $this->is_main_site() ) {
|
1717 |
+
add_action( 'user_register', array( $this, 'userid_action_handler' ) );
|
1718 |
+
add_action( 'password_reset', array( $this, 'userid_action_handler' ) );
|
1719 |
+
add_action( 'profile_update', array( $this, 'userid_action_handler' ) );
|
1720 |
+
add_action( 'user_register', array( $this, 'userid_action_handler' ) );
|
1721 |
+
add_action( 'deleted_user', array( $this, 'userid_action_handler' ) );
|
1722 |
+
}
|
1723 |
+
|
1724 |
+
// Usermeta
|
1725 |
+
if ( $this->is_main_site() ) {
|
1726 |
+
add_action( 'added_usermeta', array( $this, 'usermeta_action_handler' ), 10, 4 );
|
1727 |
+
add_action( 'update_usermeta', array( $this, 'usermeta_action_handler' ), 10, 4 );
|
1728 |
+
add_action( 'delete_usermeta', array( $this, 'usermeta_action_handler' ), 10, 4 );
|
1729 |
+
}
|
1730 |
+
|
1731 |
+
// Posts
|
1732 |
+
add_action( 'delete_post', array( $this, 'post_action_handler' ) );
|
1733 |
+
add_action( 'trash_post', array( $this, 'post_action_handler' ) );
|
1734 |
+
add_action( 'untrash_post', array( $this, 'post_action_handler' ) );
|
1735 |
+
add_action( 'edit_post', array( $this, 'post_action_handler' ) );
|
1736 |
+
add_action( 'save_post', array( $this, 'post_action_handler' ) );
|
1737 |
+
add_action( 'wp_insert_post', array( $this, 'post_action_handler' ) );
|
1738 |
+
add_action( 'edit_attachment', array( $this, 'post_action_handler' ) );
|
1739 |
+
add_action( 'add_attachment', array( $this, 'post_action_handler' ) );
|
1740 |
+
add_action( 'delete_attachment', array( $this, 'post_action_handler' ) );
|
1741 |
+
add_action( 'private_to_published', array( $this, 'post_action_handler' ) );
|
1742 |
+
add_action( 'wp_restore_post_revision', array( $this, 'post_action_handler' ) );
|
1743 |
+
|
1744 |
+
// Postmeta
|
1745 |
+
add_action( 'added_post_meta', array( $this, 'postmeta_insert_handler' ), 10, 4 );
|
1746 |
+
add_action( 'update_post_meta', array( $this, 'postmeta_modification_handler' ), 10, 4 );
|
1747 |
+
add_action( 'updated_post_meta', array( $this, 'postmeta_modification_handler' ), 10, 4 );
|
1748 |
+
add_action( 'delete_post_meta', array( $this, 'postmeta_modification_handler' ), 10, 4 );
|
1749 |
+
add_action( 'deleted_post_meta', array( $this, 'postmeta_modification_handler' ), 10, 4 );
|
1750 |
+
add_action( 'added_postmeta', array( $this, 'postmeta_action_handler' ) );
|
1751 |
+
add_action( 'update_postmeta', array( $this, 'postmeta_action_handler' ) );
|
1752 |
+
add_action( 'delete_postmeta', array( $this, 'postmeta_action_handler' ) );
|
1753 |
+
|
1754 |
+
// Links
|
1755 |
+
add_action( 'edit_link', array( $this, 'link_action_handler' ) );
|
1756 |
+
add_action( 'add_link', array( $this, 'link_action_handler' ) );
|
1757 |
+
add_action( 'delete_link', array( $this, 'link_action_handler' ) );
|
1758 |
+
|
1759 |
+
// Taxonomy
|
1760 |
+
add_action( 'created_term', array( $this, 'term_handler' ), 2 );
|
1761 |
+
add_action( 'edited_terms', array( $this, 'term_handler' ), 2 );
|
1762 |
+
add_action( 'delete_term', array( $this, 'term_handler' ), 2 );
|
1763 |
+
add_action( 'edit_term_taxonomy', array( $this, 'term_taxonomy_handler' ) );
|
1764 |
+
add_action( 'delete_term_taxonomy', array( $this, 'term_taxonomy_handler' ) );
|
1765 |
+
add_action( 'edit_term_taxonomies', array( $this, 'term_taxonomies_handler' ) );
|
1766 |
+
add_action( 'add_term_relationship', array( $this, 'term_relationship_handler' ), 10, 2 );
|
1767 |
+
add_action( 'delete_term_relationships', array( $this, 'term_relationships_handler' ), 10, 2 );
|
1768 |
+
add_action( 'set_object_terms', array( $this, 'set_object_terms_handler' ), 10, 3 );
|
1769 |
+
|
1770 |
+
// Files
|
1771 |
+
if ( $this->is_main_site() ) {
|
1772 |
+
add_action( 'switch_theme', array( $this, 'theme_action_handler' ) );
|
1773 |
+
add_action( 'activate_plugin', array( $this, 'plugin_action_handler' ) );
|
1774 |
+
add_action( 'deactivate_plugin', array( $this, 'plugin_action_handler' ) );
|
1775 |
+
}
|
1776 |
+
add_action( 'wp_handle_upload', array( $this, 'upload_handler' ) );
|
1777 |
+
|
1778 |
+
// Options
|
1779 |
+
add_action( 'deleted_option', array( $this, 'option_handler' ), 1 );
|
1780 |
+
add_action( 'updated_option', array( $this, 'option_handler' ), 1 );
|
1781 |
+
add_action( 'added_option', array( $this, 'option_handler' ), 1 );
|
1782 |
+
|
1783 |
+
// Report back to VaultPress
|
1784 |
+
add_action( 'shutdown', array( $this, 'do_pings' ) );
|
1785 |
+
|
1786 |
+
// VaultPress likes being first in line
|
1787 |
+
add_filter( 'pre_update_option_active_plugins', array( $this, 'load_first' ) );
|
1788 |
+
}
|
1789 |
+
}
|
1790 |
+
|
1791 |
+
$vaultpress = VaultPress::init();
|
1792 |
+
|
1793 |
+
if ( isset( $_GET['vaultpress'] ) && $_GET['vaultpress'] ) {
|
1794 |
+
if ( !function_exists( 'wp_magic_quotes' ) ) {
|
1795 |
+
// If already slashed, strip.
|
1796 |
+
if ( get_magic_quotes_gpc() ) {
|
1797 |
+
$_GET = stripslashes_deep( $_GET );
|
1798 |
+
$_POST = stripslashes_deep( $_POST );
|
1799 |
+
$_COOKIE = stripslashes_deep( $_COOKIE );
|
1800 |
+
}
|
1801 |
+
|
1802 |
+
// Escape with wpdb.
|
1803 |
+
$_GET = add_magic_quotes( $_GET );
|
1804 |
+
$_POST = add_magic_quotes( $_POST );
|
1805 |
+
$_COOKIE = add_magic_quotes( $_COOKIE );
|
1806 |
+
$_SERVER = add_magic_quotes( $_SERVER );
|
1807 |
+
|
1808 |
+
// Force REQUEST to be GET + POST. If SERVER, COOKIE, or ENV are needed, use those superglobals directly.
|
1809 |
+
$_REQUEST = array_merge( $_GET, $_POST );
|
1810 |
+
} else {
|
1811 |
+
wp_magic_quotes();
|
1812 |
+
}
|
1813 |
+
|
1814 |
+
if ( !function_exists( 'wp_get_current_user' ) )
|
1815 |
+
include ABSPATH . '/wp-includes/pluggable.php';
|
1816 |
+
|
1817 |
+
// TODO: this prevents some error notices but do we need it? is there a better way to check capabilities/logged in user/etc?
|
1818 |
+
if ( function_exists( 'wp_cookie_constants' ) && !defined( 'AUTH_COOKIE' ) )
|
1819 |
+
wp_cookie_constants();
|
1820 |
+
|
1821 |
+
$vaultpress->parse_request( null );
|
1822 |
+
|
1823 |
+
die();
|
1824 |
+
}
|
1825 |
+
|
1826 |
+
// only load hotfixes if it's not a VP request
|
1827 |
+
require_once( dirname( __FILE__ ) . '/class.vaultpress-hotfixes.php' );
|
1828 |
+
$hotfixes = new VaultPress_Hotfixes();
|