/var/www/(Del)hsihk.com/wp-content/plugins/backupbuddy/destinations/ftp/_manage.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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
<?php
// Authored by Skyler Moore.

pb_backupbuddy::$ui->title'FTP' );

// FTP connection information
$ftp_server $destination['address'];
$ftp_username $destination['username'];
$ftp_password $destination['password'];
$ftp_directory = (string)$destination['path'];
$ftps $destination['ftps'];
if ( !empty( 
$ftp_directory ) ) {
    
$ftp_directory $ftp_directory '/';
}
if ( isset( 
$destination['active_mode'] ) && ( $destination['active_mode'] == '0' ) ) {
    
$active false;
} else {
    
$active true;
}

$port '21';
if ( 
strstr$ftp_server':' ) ) {
    
$server_params explode':'$ftp_server );
    
$ftp_server $server_params[0];
    
$port $server_params[1];
}

// Delete ftp backups
if ( !empty( $_POST['delete_file'] ) ) {
    
    
pb_backupbuddy::verify_nonce();
    
    
$delete_count 0;
    if ( !empty( 
$_POST['files'] ) && is_array$_POST['files'] ) ) {
        
        
        
// Connect to server.
        
if ( $ftps == '1' ) { // Connect with FTPs.
            
if ( function_exists'ftp_ssl_connect' ) ) {
                
$conn_id ftp_ssl_connect$ftp_server$port );
                if ( 
$conn_id === false ) {
                    
pb_backupbuddy::status'details',  'Unable to connect to FTPS  (check address/FTPS support).''error' );
                    return 
false;
                } else {
                    
pb_backupbuddy::status'details',  'Connected to FTPs.' );
                }
            } else {
                
pb_backupbuddy::status'details',  'Your web server doesnt support FTPS in PHP.''error' );
                return 
false;
            }
        } else { 
// Connect with FTP (normal).
            
if ( function_exists'ftp_connect' ) ) {
                
$conn_id ftp_connect$ftp_server$port );
                if ( 
$conn_id === false ) {
                    
pb_backupbuddy::status'details',  'ERROR: Unable to connect to FTP (check address).''error' );
                    return 
false;
                } else {
                    
pb_backupbuddy::status'details',  'Connected to FTP.' );
                }
            } else {
                
pb_backupbuddy::status'details',  'Your web server doesnt support FTP in PHP.''error' );
                return 
false;
            }
        }
        
        
        
// login with username and password
        
$login_result ftp_login$conn_id$ftp_username$ftp_password );
        
        if ( 
$active === true ) {
            
// do nothing, active is default.
            
pb_backupbuddy::status'details''Active FTP mode based on settings.' );
        } elseif ( 
$active === false ) {
            
// Turn passive mode on.
            
pb_backupbuddy::status'details''Passive FTP mode based on settings.' );
            
ftp_pasv$conn_idtrue );
        } else {
            
pb_backupbuddy::status'error''Unknown FTP active/passive mode: `' $active '`.' );
        }
        
        
ftp_chdir$conn_id, (string)$ftp_directory );
        
        
// loop through and delete ftp backup files
        
foreach ( $_POST['files'] as $backup ) {
            
// try to delete backup
            
if ( ftp_delete$conn_id,  $backup ) ) {
                
$delete_count++;
            }
        }
    
        
// close this connection
        
ftp_close$conn_id );
    }
    if ( 
$delete_count ) {
        
pb_backupbuddy::alertsprintf_n'Deleted %d file.''Deleted %d files.'$delete_count'it-l10n-backupbuddy' ), $delete_count ) );
    } else {
        
pb_backupbuddy::alert__('No backups were deleted.''it-l10n-backupbuddy' ) );
    }
    echo 
'<br>';
}

// Copy ftp backups to the local backup files
if ( !empty( $_GET['cpy_file'] ) ) {
    
pb_backupbuddy::alert'The remote file is now being copied to your local backups. If the backup gets marked as bad during copying, please wait a bit then click the `Refresh` icon to rescan after the transfer is complete.' );
    echo 
'<br>';
    
pb_backupbuddy::status'details',  'Scheduling Cron for creating ftp copy.' );
    
backupbuddy_core::schedule_single_eventtime(), pb_backupbuddy::cron_tag'process_ftp_copy' ), array( $_GET['cpy_file'], $ftp_server$ftp_username$ftp_password$ftp_directory$port$ftps ) );
    
spawn_crontime() + 150 ); // Adds > 60 seconds to get around once per minute cron running limit.
    
update_option'_transient_doing_cron'); // Prevent cron-blocking for next item.
}


// Connect to server
if ( $ftps == '1' ) { // Connect with FTPs.
    
if ( function_exists'ftp_ssl_connect' ) ) {
        
$conn_id ftp_ssl_connect$ftp_server$port );
        if ( 
$conn_id === false ) {
            
pb_backupbuddy::status'details',  'Unable to connect to FTPS  `' $ftp_server '` on port `' $port '` (check address/FTPS support and that server can connect to this address via this port).''error' );
            return 
false;
        } else {
            
pb_backupbuddy::status'details',  'Connected to FTPs.' );
        }
    } else {
        
pb_backupbuddy::status'details',  'Your web server doesnt support FTPS in PHP.''error' );
        return 
false;
    }
} else { 
// Connect with FTP (normal).
    
if ( function_exists'ftp_connect' ) ) {
        
$conn_id ftp_connect$ftp_server$port );
        if ( 
$conn_id === false ) {
            
pb_backupbuddy::status'details',  'ERROR: Unable to connect to FTP server `' $ftp_server '` on port `' $port '` (check address and that server can connect to this address via this port).''error' );
            return 
false;
        } else {
            
pb_backupbuddy::status'details',  'Connected to FTP.' );
        }
    } else {
        
pb_backupbuddy::status'details',  'Your web server doesnt support FTP in PHP.''error' );
        return 
false;
    }
}


// Login with username and password
$login_result ftp_login$conn_id$ftp_username$ftp_password );


if ( 
$active === true ) {
    
// do nothing, active is default.
    
pb_backupbuddy::status'details''Active FTP mode based on settings.' );
} elseif ( 
$active === false ) {
    
// Turn passive mode on.
    
pb_backupbuddy::status'details''Passive FTP mode based on settings.' );
    
ftp_pasv$conn_idtrue );
} else {
    
pb_backupbuddy::status'error''Unknown FTP active/passive mode: `' $active '`.' );
}


// Get contents of the current directory
ftp_chdir$conn_id$ftp_directory );
$contents ftp_nlist$conn_id'' );

// Create array of backups and sizes
$backups = array();
$got_modified false;
foreach ( 
$contents as $backup ) {
    
// check if file is backup
    
$pos strpos$backup'backup-' );
    if ( 
$pos !== FALSE ) {
        
$mod_time ftp_mdtm$conn_id$ftp_directory $backup );
        if ( 
$mod_time > -) {
            
$got_modified true;
        }
        
$backups[] = array(
            
'file' => $backup,
            
'size' => ftp_size$conn_id$ftp_directory $backup ),
            
'modified' => $mod_time,
        );
        
    }
}
    
// close this connection
ftp_close$conn_id );


if ( 
$got_modified === true ) { // FTP server supports sorting by modified date.
    // Custom sort function for multidimension array usage.
    
function backupbuddy_number_sort$a,$b ) {
        return 
$a['modified']<$b['modified'];
    }
    
// Sort by modified using custom sort function above.
    
usort$backups'backupbuddy_number_sort' );
}


$urlPrefix pb_backupbuddy::ajax_url'remoteClient' ) . '&destination_id=' htmlentitiespb_backupbuddy::_GET'destination_id' ) );


//echo '<h3>', __('Viewing', 'it-l10n-backupbuddy' ), ' `' . $destination['title'] . '` (' . $destination['type'] . ')</h3>';
?>
<div style="max-width: 950px;">
<form id="posts-filter" enctype="multipart/form-data" method="post" action="<?php echo $urlPrefix?>">
    <div class="tablenav">
        <div class="alignleft actions">
            <input type="submit" name="delete_file" value="<?php _e('Delete from FTP''it-l10n-backupbuddy' );?>" class="button-secondary delete" />
        </div>
    </div>
    <table class="widefat">
        <thead>
            <tr class="thead">
                <th scope="col" class="check-column"><input type="checkbox" class="check-all-entries" /></th>
                <?php
                    
echo '<th>'__('Backup File''it-l10n-backupbuddy' ), '</th>',
                         
'<th>'__('File Size',   'it-l10n-backupbuddy' ), '</th>',
                        
'<th>'__('Modified',   'it-l10n-backupbuddy' );
                        if ( 
$got_modified === true ) {
                            echo 
' <img src="'pb_backupbuddy::plugin_url(), '/images/sort_down.png" style="vertical-align: 0px;" title="'__('Sorted by modified''it-l10n-backupbuddy' ), '" />';
                        }
                        echo 
'</th>',
                         
'<th>'__('Actions',     'it-l10n-backupbuddy' ), '</th>';
                
?>
            </tr>
        </thead>
        <tfoot>
            <tr class="thead">
                <th scope="col" class="check-column"><input type="checkbox" class="check-all-entries" /></th>
                <?php
                    
echo '<th>'__('Backup File''it-l10n-backupbuddy' ), '</th>',
                         
'<th>'__('File Size',   'it-l10n-backupbuddy' ), '</th>',
                        
'<th>'__('Modified',   'it-l10n-backupbuddy' );
                        if ( 
$got_modified === true ) {
                            echo 
' <img src="'pb_backupbuddy::plugin_url(), '/images/sort_down.png" style="vertical-align: 0px;" title="'__('Sorted by modified''it-l10n-backupbuddy' ), '" />';
                        }
                        echo 
'</th><th>'__('Actions',     'it-l10n-backupbuddy' ), '</th>';
                
?>
            </tr>
        </tfoot>
        <tbody>
            <?php
            
// List FTP backups
            
if ( empty( $backups ) ) {
                echo 
'<tr><td colspan="5" style="text-align: center;"><i>'__('This directory does not have any backups.''it-l10n-backupbuddy' ), '</i></td></tr>';
            } else {
                
$file_count 0;
                foreach ( (array)
$backups as $backup ) {
                    
$file_count++;
                    
?>
                    <tr class="entry-row alternate">
                        <th scope="row" class="check-column"><input type="checkbox" name="files[]" class="entries" value="<?php echo $backup['file']; ?>" /></th>
                        <td>
                            <?php
                                
echo $backup['file'];
                            
?>
                        </td>
                        <td style="white-space: nowrap;">
                            <?php
                            
if ( $backup['modified'] > -) {
                                echo 
pb_backupbuddy::$format->datepb_backupbuddy::$format->localize_time$backup['modified'] ) );
                                echo 
'<br /><span class="description">(' pb_backupbuddy::$format->time_ago$backup['modified'] ) . ' '__('ago''it-l10n-backupbuddy' ), ')</span>';
                            } else {
                                echo 
'<span class="description">Unknown</span>';
                            }
                            
?>
                            
                        </td>
                        <td style="white-space: nowrap;">
                            <?php echo pb_backupbuddy::$format->file_size$backup['size'] ); ?>
                        </td>
                        <td>
                            <?php echo '<a href="' $urlPrefix '&#38;cpy_file=' $backup['file'] . '">Copy to local</a>'?>
                        </td>
                    </tr>
                    <?php
                
}
            }
            
?>
        </tbody>
    </table>
    <div class="tablenav">
        <div class="alignleft actions">
            <input type="submit" name="delete_file" value="<?php _e('Delete from FTP''it-l10n-backupbuddy' );?>" class="button-secondary delete" />
        </div>
    </div>
    
    <?php pb_backupbuddy::nonce(); ?>
</form><br />
</div>