/var/www/(Del)hsihk.com/wp-content/plugins/backupbuddy/lib/updater/server.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
<?php

/*
Provides an easy to use interface for communicating with the iThemes updater server.
Written by Chris Jean for iThemes.com
Version 1.0.2

Version History
    1.0.0 - 2013-04-11 - Chris Jean
        Release ready
    1.0.1 - 2013-06-21 - Chris Jean
        Updated the http_build_query call to force a separator of & in order to avoid issues with servers that change the arg_separator.output php.ini value.
    1.0.2 - 2013-09-19 - Chris Jean
        Updated ithemes-updater-object to ithemes-updater-settings.
*/


class Ithemes_Updater_Server {
    private static 
$secure_server_url 'https://api.ithemes.com/updater';
    private static 
$insecure_server_url 'http://api.ithemes.com/updater';
    
    private static 
$password_iterations 8;
    
    
    public static function 
activate_package$username$password$packages ) {
        
$query = array(
            
'user' => $username
        
);
        
        
$data = array(
            
'auth_token' => self::get_password_hash$username$password ),
            
'packages'   => $packages,
        );
        
        return 
Ithemes_Updater_Server::request'package-activate'$query$data );
    }
    
    public static function 
deactivate_package$username$password$packages ) {
        
$query = array(
            
'user' => $username
        
);
        
        
$data = array(
            
'auth_token' => self::get_password_hash$username$password ),
            
'packages'   => $packages,
        );
        
        return 
Ithemes_Updater_Server::request'package-deactivate'$query$data );
    }
    
    public static function 
get_package_details$packages ) {
        
$query = array();
        
        
$data = array(
            
'packages' => $packages
        
);
        
        return 
Ithemes_Updater_Server::request'package-details'$query$data );
    }
    
    public static function 
request$action$query = array(), $data = array() ) {
        if ( isset( 
$data['auth_token'] ) )
            
$data['iterations'] = self::$password_iterations;
        
        
        
$default_query = array(
            
'wp'        => $GLOBALS['wp_version'],
            
'site'      => get_bloginfo'url' ),
            
'timestamp' => time(),
        );
        
        if ( 
is_multisite() )
            
$default_query['ms'] = 1;
        
        
$query array_merge$default_query$query );
        
$request "/$action/?" http_build_query$query'''&' );
        
        
$post_data = array(
            
'request' => json_encode$data ),
        );
        
        
$remote_post_args = array(
            
'timeout' => 10,
            
'body'    => $post_data,
        );
        
        
        
$options = array(
            
'use_ca_patch' => false,
            
'use_ssl'      => true,
        );
        
        
$patch_enabled $GLOBALS['ithemes-updater-settings']->get_option'use_ca_patch' );
        
        if ( 
$patch_enabled )
            
$GLOBALS['ithemes-updater-settings']->disable_ssl_ca_patch();
        
        
        
$response wp_remote_postself::$secure_server_url $request$remote_post_args );
        
        if ( 
is_wp_error$response ) ) {
            
$GLOBALS['ithemes-updater-settings']->enable_ssl_ca_patch();
            
$response wp_remote_postself::$secure_server_url $request$remote_post_args );
            
            if ( ! 
is_wp_error$response ) )
                
$options['use_ca_patch'] = true;
        }
        
        if ( 
is_wp_error$response ) ) {
            
$response wp_remote_postself::$insecure_server_url $request$remote_post_args );
            
            
$options['use_ssl'] = false;
        }
        
        
        if ( ! 
$options['use_ca_patch'] )
            
$GLOBALS['ithemes-updater-settings']->disable_ssl_ca_patch();
        
        
$GLOBALS['ithemes-updater-settings']->update_options$options );
        
        
        if ( 
is_wp_error$response ) )
            return 
$response;
        
        
        
$body json_decode$response['body'], true );
        
        if ( ! empty( 
$body['error'] ) )
            return new 
WP_Error$body['error']['type'], sprintf__'An error occurred when communicating with the iThemes update server: %s (%s)''it-l10n-backupbuddy' ), $body['error']['message'], $body['error']['code'] ) );
        
        
        return 
$body;
    }
    
    private static function 
get_password_hash$username$password ) {
        require_once( 
ABSPATH 'wp-includes/class-phpass.php');
        
        
$salted_password $password $username get_bloginfo'url' ) . $GLOBALS['wp_version'];
        
$salted_password substr$salted_password0maxstrlen$password ), 72 ) );
        
        
$wp_hasher = new PasswordHashself::$password_iterationstrue );
        
        return 
$wp_hasher->HashPassword$salted_password );
    }
}