PluginProbe
WP Database Backup – Unlimited Database & Files Backup by Backup for WP / 6.11
WP Database Backup – Unlimited Database & Files Backup by Backup for WP v6.11
7.13 7.12 trunk 1.1 2.1.1 5.9 6.0 6.1 6.10 6.11 6.12 6.12.1 6.2 6.3 6.4 6.5 6.5.1 6.6 6.7 6.8 6.9 7.0 7.0.1 7.1 7.10 All 34 releases
wp-database-backup / includes / admin / Destination / SFTP / preflight.php

preflight.php in WP Database Backup – Unlimited Database & Files Backup by Backup for WP 6.11, at includes/admin/Destination/SFTP/preflight.php

61 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Destination file.
4 *
5 * @package wpdbbkp
6 */
7
8 if ( ! defined( 'ABSPATH' ) ) {
9 exit; // Exit if accessed directly.
10 }
11
12 /**
13 * Error checking.
14 *
15 * @param string $trouble - Trouble response.
16 */
17
18 require __DIR__ . '/vendor/autoload.php';
19 use phpseclib3\Net\SFTP;
20 use phpseclib3\Crypt\PublicKeyLoader;
21
22 function wpdbbkp_preflight_problem( $trouble ) {
23 $error_log = $trouble;
24 }
25 $wpdbbkp_sftp_details = get_option( 'wp_db_backup_sftp_details',array());
26
27 $host = isset($wpdbbkp_sftp_details['host'])?$wpdbbkp_sftp_details['host']:'';
28 $port = isset($wpdbbkp_sftp_details['port'])?$wpdbbkp_sftp_details['port']:22;
29 $user = isset($wpdbbkp_sftp_details['username'])?$wpdbbkp_sftp_details['username']:'';
30 $pass = isset($wpdbbkp_sftp_details['password'])?$wpdbbkp_sftp_details['password']:'';
31 $pkey = isset($wpdbbkp_sftp_details['sftp_key'])?base64_decode($wpdbbkp_sftp_details['sftp_key']):'';
32 $key_pass = isset($wpdbbkp_sftp_details['key_password'])?$wpdbbkp_sftp_details['key_password']:false;
33 $directory = isset($wpdbbkp_sftp_details['directory'])?$wpdbbkp_sftp_details['directory']:'';
34 $wpdbbkp_auth_type_ = isset($wpdbbkp_sftp_details[ 'auth_type' ])?$wpdbbkp_sftp_details[ 'auth_type' ]:'password';
35 $sftp = false;
36 if ( '' === $directory ) {
37 $directory = '/';
38 }
39 if ( $host ) {
40 // If in WP Dashboard or Admin Panels.
41 if ( is_admin() ) {
42 // If user has WP manage options permissions.
43 if ( current_user_can( 'manage_options' ) ) {
44 // Connect to host ONLY if the 2 security conditions are valid / met.
45 $sftp = new SFTP( $host , $port );
46 if ( ! $sftp ) {
47 return esc_html__('Could not connect to your SFTP server.','wpdbbkp').'<br />'.esc_html__('Please check your SFTP Host settings and try again (leave FTP Host BLANK for local backups).','wpdbbkp');
48 }
49 if($wpdbbkp_auth_type_=='key'){
50 $key = PublicKeyLoader::load($pkey,$key_pass);
51 $result = $sftp->login($user, $key);
52 }else{
53 $result = $sftp->login($user, $pass);
54 }
55 if ( ! $result ) {
56 return esc_html__('Could not log in to your FTP server.','wpdbbkp').'<br />'.esc_html__('Please check your SFTP Username and Password, then try again.','wpdbbkp').'<br />'.esc_html__('For local backups, please leave the FTP Host option BLANK.','wpdbbkp');
57 }
58 }
59 }
60 }
61