/var/www/(Del)hsihk.com/wp-content/plugins/bruteprotect/admin/pro/updater/update.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
<?php
/**
 * Updates the given assets (plugins, themes, core) and outputs the result to JSON
 *
 * Responds to a bruteprotect api call of 'bp_update'
 *
 * @package Bruteprotect
 * @since 2.0
 */

//make sure this site is opted in for remote update
$privacy_opt_in get_site_option'brute_privacy_opt_in' );
if ( !isset( 
$privacy_opt_in'remote_updates' ] ) ) {
    
$response = array( 'error' => true'message' => 'Site has not enabled remote plugin updating' );
    echo 
json_encode$response );
    exit;
}


//run our logic to make sure that this is legit
if ( !verify_bp_nonce$bruteprotect_host$_POST ) && == ) {
    
$response = array( 'error' => true'message' => 'Could not verify nonce' );
    echo 
json_encode$response );
    exit;
}
if ( !isset( 
$_POST'user_id' ] ) ) {
    
$response = array( 'error' => true'message' => 'User does not have the capability to perform this update' );
    echo 
json_encode$response );
    exit;
}
if ( 
$_POST'user_id' ] != 'auto' ) {
    if ( !
user_can$_POST'user_id' ], 'update_plugins' ) ) {
        
$response = array( 'error' => true'message' => 'User does not have the capability to perform this update' );
        echo 
json_encode$response );
        exit;
    }
}

/**
 * Updates the given list of plugins.
 *
 * Accepts an array of plugin paths such as 'bruteprotect/bruteprotect.php'
 * Returns a detailed array showing the status of each plugin and a log of messages output during the process
 *
 * @param array $plugins
 *
 * @return array
 */
function bruteprotect_bulk_update_plugins$plugins )
{
    
$skin = new Automatic_Upgrader_Skin();
    
$upgrader = new Plugin_Upgrader$skin );
    
$results $upgrader->bulk_upgrade$plugins );
    
$messages $upgrader->skin->get_upgrade_messages();
    
$o'results' ] = $results;
    
$o'messages' ] = $messages;

    return 
$o;
}

/**
 * Updates the given list of themes.
 *
 * Accepts an array of theme slugs such as 'twentyfourteen'
 * Returns a detailed array showing the status of each theme and a log of messages output during the process
 *
 * @param array $themes
 *
 * @return array
 */
function bruteprotect_bulk_update_themes$themes )
{
    
$skin = new Automatic_Upgrader_Skin();
    
$upgrader = new Theme_Upgrader$skin );
    
$results $upgrader->bulk_upgrade$themes );
    
$messages $upgrader->skin->get_upgrade_messages();
    
$o'results' ] = $results;
    
$o'messages' ] = $messages;

    return 
$o;
}

/**
 * Updates wordpress core to the given version.
 *
 * Returns the new version on success, and a Wp_error object on failure
 *
 * @param string $version
 *
 * @return string|object
 */
function bruteprotect_update_core$version )
{
    
$locale get_locale();
    
$update find_core_update$version$locale );
    
$skin = new Automatic_Upgrader_Skin();
    
$upgrader = new Core_Upgrader$skin );
    
$results $upgrader->upgrade$update );

    return 
$results;
}

include_once 
ABSPATH 'wp-admin/includes/class-wp-upgrader.php';
include_once 
ABSPATH 'wp-admin/includes/file.php';
include_once 
ABSPATH 'wp-admin/includes/misc.php';
include_once 
ABSPATH 'wp-admin/includes/plugin.php';
include_once 
ABSPATH 'wp-admin/includes/theme.php';
include_once 
ABSPATH 'wp-admin/includes/update.php';
$update_error false;
$overview '';
$response = array(
    
'message' => array()
);

if ( !empty( 
$_POST'core' ] ) ) {
    
$core bruteprotect_update_core$_POST'core' ] );
    if ( 
is_wp_error$core ) ) {
        
$update_error true;
        
$error_message $core->get_error_message();
        
$response'message' ][ 'core' ] = array(
            
'error'   => true,
            
'message' => $error_message,
        );
        
$overview .= 'WordPress core update failed. ';
    } else {
        
$response'message' ][ 'core' ] = array(
            
'error'   => false,
            
'message' => 'WordPress was updated to version ' $core '.',
        );
        
$overview .= 'WordPress core update complete. ';
    }
}

if ( !empty( 
$_POST'plugins' ] ) ) {
    
$plugins json_decodestripslashes$_POST'plugins_json' ] ) );
    
$num_plugins count$plugins );
    if ( 
$num_plugins ) {
        
$success_count_plugins 0;
        
$fail_count_plugins 0;
        
$result_plugins = array();


        
$bulk bruteprotect_bulk_update_plugins$plugins );
        foreach ( 
$bulk'results' ] as $path => $result ) {
            if ( 
is_array$result ) ) {
                
$success_count_plugins++;
                
$results_plugins[ ] = array( 'status' => true'path' => $path );
            } else {
                
$fail_count_plugins++;
                
$results_plugins[ ] = array( 'status' => false'path' => $path );
                
$update_error true;
            }
        }
        
$updatelog_plugins $bulk'messages' ];
        
$overview .= $num_plugins ' plugin update';
        if ( 
$num_plugins ) {
            
$overview .= 's';
        }
        
$overview .= ' attempted: ' $success_count_plugins ' ';
        if ( 
$success_count_plugins == ) {
            
$overview .= 'was';
        } else {
            
$overview .= 'were';
        }
        
$overview .= ' successful, ' $fail_count_plugins ' failed. ';
        
$response'message' ][ 'plugins' ] = array(
            
'results' => $results_plugins,
            
'log'     => $updatelog_plugins,
        );
    }

}

if ( !empty( 
$_POST'themes' ] ) ) {
    
$themes json_decodestripslashes$_POST'themes_json' ] ) );
    
$num_themes count$themes );

    if ( 
$num_themes ) {
        
$success_count_themes 0;
        
$fail_count_themes 0;
        
$result_themes = array();


        
$bulk bruteprotect_bulk_update_themes$themes );
        foreach ( 
$bulk'results' ] as $path => $result ) {
            if ( 
is_array$result ) ) {
                
$success_count_themes++;
                
$results_themes[ ] = array( 'status' => true'path' => $path );
            } else {
                
$fail_count_themes++;
                
$results_themes[ ] = array( 'status' => false'path' => $path );
                
$update_error true;
            }
        }
        
$updatelog_themes $bulk'messages' ];
        
$overview .= $num_themes ' theme update';
        if ( 
$num_themes ) {
            
$overview .= 's';
        }
        
$overview .= ' attempted: ' $success_count_themes ' ';
        if ( 
$success_count_themes == ) {
            
$overview .= 'was';
        } else {
            
$overview .= 'were';
        }
        
$overview .= ' successful, ' $fail_count_themes ' failed.';
        
$response'message' ][ 'themes' ] = array(
            
'results' => $results_themes,
            
'log'     => $updatelog_themes,
        );
    }
}

$response'error' ] = $update_error;
$response'message' ][ 'overview' ] = $overview;

echo 
json_encode$response );

exit;