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
|
<?php // Authored by Dustin Bolton - Summer 2013. // Incoming variables: $destination
//pb_backupbuddy::$ui->title( 'sFTP' );
require_once( pb_backupbuddy::plugin_path() . '/destinations/sftp/init.php' ); pb_backupbuddy_destination_sftp::_init();
// Delete sftp backups if ( pb_backupbuddy::_POST( 'bulk_action' ) == 'delete_backup' ) { pb_backupbuddy::verify_nonce(); $delete_count = 0; // Connect to server. $server = $destination['address']; $port = '22'; // Default sFTP port. if ( strstr( $server, ':' ) ) { // Handle custom sFTP port. $server_params = explode( ':', $server ); $server = $server_params[0]; $port = $server_params[1]; } pb_backupbuddy::status( 'details', 'Connecting to sFTP server...' ); $sftp = new Net_SFTP( $server, $port ); if ( ! $sftp->login( $destination['username'], $destination['password'] ) ) { pb_backupbuddy::status( 'error', 'Connection to sFTP server FAILED.' ); return false; } else { pb_backupbuddy::status( 'details', 'Success connecting to sFTP server.' ); } // Change to directory. pb_backupbuddy::status( 'details', 'Attempting to change into directory...' ); if ( true === $sftp->chdir( $destination['path'] ) ) { pb_backupbuddy::status( 'details', 'Changed into directory.' ); } else { pb_backupbuddy::status( 'error', 'Unable to change into specified path. Verify the path is correct with valid permissions.' ); return false; } // loop through and delete ftp backup files foreach( (array)pb_backupbuddy::_POST( 'items' ) as $backup ) { // try to delete backup if ( true === $sftp->delete( $backup ) ) { $delete_count++; } else { pb_backupbuddy::alert( 'Unable to delete file `' . $destination['path'] . '/' . $backup . '`.' ); } } if ( $delete_count > 0 ) { pb_backupbuddy::alert( sprintf( _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>'; }
// Connect to server. $server = $destination['address']; $port = '22'; // Default sFTP port. if ( strstr( $server, ':' ) ) { // Handle custom sFTP port. $server_params = explode( ':', $server ); $server = $server_params[0]; $port = $server_params[1]; } pb_backupbuddy::status( 'details', 'Connecting to sFTP server...' ); $sftp = new Net_SFTP( $server, $port ); if ( ! $sftp->login( $destination['username'], $destination['password'] ) ) { pb_backupbuddy::status( 'error', 'Connection to sFTP server FAILED.' ); return false; } else { pb_backupbuddy::status( 'details', 'Success connecting to sFTP server.' ); }
pb_backupbuddy::status( 'details', 'Attempting to create path (if it does not exist)...' ); if ( true === $sftp->mkdir( $destination['path'] ) ) { // Try to make directory. pb_backupbuddy::status( 'details', 'Directory created.' ); } else { pb_backupbuddy::status( 'details', 'Directory not created.' ); }
// List files. $files = $sftp->rawlist( $destination['path'] ); $backups = array(); $backup_list_temp = array(); foreach( $files as $filename => $file ) { if ( false === stristr( $filename, 'backup' ) ) { // only show backup files continue; } if ( stristr( $filename, '-db-' ) !== false ) { $backup_type = 'Database'; } elseif( stristr( $filename, '-full-' ) !== false ) { $backup_type = 'Full'; } else { $backup_type = 'Unknown'; } $last_modified = $file['mtime']; while( isset( $backup_list_temp[$last_modified] ) ) { // Avoid collisions. $last_modified += 0.1; } $backup_list_temp[$last_modified] = array( $filename, pb_backupbuddy::$format->date( pb_backupbuddy::$format->localize_time( $file['mtime'] ) ) . '<br /><span class="description">(' . pb_backupbuddy::$format->time_ago( $file['mtime'] ) . ' ago)</span>', pb_backupbuddy::$format->file_size( $file['size'] ), $backup_type ); }
krsort( $backup_list_temp ); $backup_list = array(); foreach( $backup_list_temp as $backup_item ) { $backup_list[ $backup_item[0] ] = $backup_item; //str_replace( 'db/', '', str_replace( 'full/', '', $backup_item ) ); } unset( $backup_list_temp );
//echo '<h3>', __('Viewing', 'it-l10n-backupbuddy' ), ' `' . $destination['title'] . '` (' . $destination['type'] . ')</h3>';
// Render table listing files. if ( count( $backup_list ) == 0 ) { echo '<b>'; _e( 'You have not completed sending any backups to this sFTP destination for this site yet.', 'it-l10n-backupbuddy' ); echo '</b>'; } else { pb_backupbuddy::$ui->list_table( $backup_list, array( 'action' => $urlPrefix . '&remote_path=' . htmlentities( pb_backupbuddy::_GET( 'remote_path' ) ), 'columns' => array( 'Backup File', 'Uploaded <img src="' . pb_backupbuddy::plugin_url() . '/images/sort_down.png" style="vertical-align: 0px;" title="Sorted most recent first">', 'File Size', 'Type' ), //'hover_actions' => array( 'copy' => 'Copy to Local' ), 'hover_action_column_key' => '0', 'bulk_actions' => array( 'delete_backup' => 'Delete' ), 'css' => 'width: 100%;', ) ); }
?>
|