aws.php
3 months ago
backupbliss.php
3 months ago
dropbox.php
3 months ago
ftp.php
3 months ago
gdrive.php
3 months ago
wasabi.php
3 months ago
ftp.php
297 lines
| 1 | <?php |
| 2 | |
| 3 | // Namespace |
| 4 | namespace BMI\Plugin; |
| 5 | |
| 6 | use BMI\Plugin\Dashboard as Dashboard; |
| 7 | use Couchbase\ValueRecorder; |
| 8 | use Exception; |
| 9 | |
| 10 | // Exit on direct access |
| 11 | if ( ! defined( 'ABSPATH' ) ) { |
| 12 | exit; |
| 13 | } |
| 14 | |
| 15 | add_action( 'bmi_pro_ftp_template', function () { |
| 16 | |
| 17 | $host = get_option('bmi_pro_ftp_host'); |
| 18 | $port = get_option('bmi_pro_ftp_port'); |
| 19 | |
| 20 | // Get userName And Password |
| 21 | $username = get_option( 'bmi_pro_ftp_username', false ); |
| 22 | $password = get_option( 'bmi_pro_ftp_password', false ); |
| 23 | |
| 24 | $shouldBeConnected = true; |
| 25 | |
| 26 | try { |
| 27 | if ($host === false || $username === false || $password === false || !function_exists('ftp_connect')){ |
| 28 | throw new Exception( 'Unable to log in' ); |
| 29 | } |
| 30 | |
| 31 | $ftp = ftp_connect($host, $port); |
| 32 | |
| 33 | if (!$ftp){ |
| 34 | throw new Exception( 'Unable to log in' ); |
| 35 | } |
| 36 | |
| 37 | if (!@ftp_login($ftp, $username, $password)){ |
| 38 | throw new Exception( 'Unable to log in' ); |
| 39 | } |
| 40 | |
| 41 | ftp_pasv($ftp, true); |
| 42 | |
| 43 | } catch ( Exception $e ) { |
| 44 | $shouldBeConnected = false; |
| 45 | } |
| 46 | |
| 47 | if ( $shouldBeConnected ) { |
| 48 | ftp_close( $ftp ); |
| 49 | } |
| 50 | |
| 51 | |
| 52 | $isEnabled = Dashboard\bmi_get_config( 'STORAGE::EXTERNAL::FTP' ); |
| 53 | if ( $isEnabled === true || $isEnabled === 'true' ) { |
| 54 | $isEnabled = ' checked'; |
| 55 | } else { |
| 56 | $isEnabled = ''; |
| 57 | } |
| 58 | |
| 59 | ?> |
| 60 | <!-- External: FTP --> |
| 61 | <div class="tab2-item d-flex jst-sb ia-center<?php echo( ( $isEnabled == ' checked' ) ? ' activeList' : '' ); ?>"> |
| 62 | |
| 63 | <div class="d-flex ia-center"> |
| 64 | <svg fill="#000000" version="1.1" id="Capa_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" |
| 65 | width="45px" height="45px" viewBox="0 0 98.385 98.385" |
| 66 | xml:space="preserve"> |
| 67 | <g> |
| 68 | <g> |
| 69 | <path d="M61.838,54.803c-0.793,0-1.33,0.053-1.611,0.129v5.085c0.332,0.075,0.742,0.103,1.304,0.103 |
| 70 | c2.069,0,3.349-1.047,3.349-2.785C64.879,55.75,63.805,54.803,61.838,54.803z"/> |
| 71 | <path d="M53.155,31.677c-2.188-2.187-5.734-2.187-7.922,0L20.356,56.555c-2.188,2.188-2.188,5.734,0,7.923l24.876,24.875 |
| 72 | c2.188,2.188,5.734,2.188,7.922,0l24.877-24.877c1.051-1.05,1.641-2.476,1.641-3.961s-0.59-2.91-1.641-3.962L53.155,31.677z |
| 73 | M40.153,55.161h-6.618v3.937h6.184v3.168h-6.184v6.925h-3.884V51.967h10.502V55.161z M55.026,55.238h-4.703v13.951H46.44V55.238 |
| 74 | h-4.65v-3.271h13.236V55.238z M67.178,61.293c-1.33,1.229-3.322,1.815-5.621,1.815c-0.512,0-0.971-0.024-1.33-0.103v6.184h-3.857 |
| 75 | V52.198c1.201-0.205,2.889-0.358,5.264-0.358c2.401,0,4.139,0.461,5.289,1.405c1.1,0.845,1.814,2.274,1.814,3.962 |
| 76 | C68.736,58.918,68.2,60.349,67.178,61.293z"/> |
| 77 | <path d="M78.445,22.433c-0.545-0.039-1.046-0.318-1.366-0.762c-3.998-5.545-10.51-8.976-17.444-8.976 |
| 78 | c-0.502,0-1.004,0.018-1.506,0.053c-0.451,0.032-0.896-0.103-1.255-0.378c-4.198-3.229-9.314-4.979-14.675-4.979 |
| 79 | c-9.579,0-18.069,5.614-21.936,14.088c-0.266,0.583-0.816,0.985-1.452,1.065C8.221,23.867,0,32.926,0,43.869 |
| 80 | c0,9.697,6.46,17.908,15.301,20.574c-0.534-1.225-0.82-2.553-0.82-3.928c0-1.766,0.472-3.455,1.338-4.94 |
| 81 | c-4.343-2.114-7.351-6.559-7.351-11.706c0-7.182,5.843-13.024,13.025-13.024c0.363,0,0.719,0.029,1.074,0.059 |
| 82 | c2.069,0.159,3.943-1.183,4.447-3.19c1.752-6.979,7.996-11.854,15.184-11.854c4.107,0,7.994,1.586,10.944,4.466 |
| 83 | c1.009,0.984,2.439,1.401,3.82,1.114c0.879-0.182,1.777-0.275,2.672-0.275c5.027,0,9.519,2.826,11.719,7.377 |
| 84 | c0.772,1.6,2.464,2.553,4.232,2.371c0.44-0.045,0.879-0.066,1.307-0.066c7.183,0,13.025,5.843,13.025,13.024 |
| 85 | c0,5.147-3.008,9.591-7.351,11.706c0.866,1.484,1.338,3.173,1.338,4.938c0,1.376-0.287,2.705-0.821,3.931 |
| 86 | c8.842-2.666,15.301-10.877,15.301-20.575C98.387,32.542,89.575,23.229,78.445,22.433z"/> |
| 87 | </g> |
| 88 | </g> |
| 89 | </svg> |
| 90 | <span class="ml25 d-flex ia-center"> |
| 91 | <span class="title_whereStored"><?php esc_html_e( "FTP", 'backup-backup' ); ?></span> |
| 92 | </span> |
| 93 | </div> |
| 94 | |
| 95 | <div class="ia-center"> |
| 96 | <div class="b2 bmi-switch"><input type="checkbox" class="checkbox storage-checkbox"<?php echo esc_attr( $isEnabled ); ?> |
| 97 | data-toggle="storage-ftp-row" id="bmi-pro-storage-ftp-toggle"> |
| 98 | <div class="bmi-knobs"><span></span></div> |
| 99 | <div class="bmi-layer_str"></div> |
| 100 | </div> |
| 101 | </div> |
| 102 | |
| 103 | </div> |
| 104 | |
| 105 | <div class="bg_grey storage_target" |
| 106 | id="storage-ftp-row"<?php echo( ( $isEnabled == ' checked' ) ? '' : ' style="display: none;"' ); ?>> |
| 107 | <?php |
| 108 | $disabled_functions = explode( ',', ini_get( 'disable_functions' ) ); |
| 109 | $vA = ! in_array( 'curl_exec', $disabled_functions ); |
| 110 | $vB = ! in_array( 'curl_init', $disabled_functions ); |
| 111 | |
| 112 | if ( function_exists( 'curl_version' ) && function_exists( 'curl_exec' ) && function_exists( 'curl_init' ) && $vA && $vB ) { |
| 113 | ?> |
| 114 | |
| 115 | <div class="container-40 lh30 pt30"> |
| 116 | |
| 117 | <div class="d-flex"> |
| 118 | <div class="w270" style="margin-top: 23px;"><span>Backup directory path:</span></div> |
| 119 | |
| 120 | <div class="w100"> |
| 121 | <div class="w100 pos-r"> |
| 122 | <input id="bmip-ftp-backup-dir" class="input-ftpdrive_storage" type="text" autocomplete="off" |
| 123 | value="<?php echo esc_attr( sanitize_text_field(get_option('bmi_pro_ftp_backup_dir')) ); ?>" |
| 124 | placeholder="Directory_Name_Of_My_Backups_In_FTP" |
| 125 | <?php echo( ( $shouldBeConnected ) ? 'disabled' : '' ); ?>> |
| 126 | </div> |
| 127 | <div class="mt10"><span></span></div> |
| 128 | </div> |
| 129 | </div> |
| 130 | |
| 131 | <div class="d-flex"> |
| 132 | <div class="w270" style="margin-top: 23px;"><span>Host IP Address:</span></div> |
| 133 | <div> |
| 134 | <div class="w100 pos-r"> |
| 135 | <input id="bmip-ftp-host-ip" class="input-ftpdrive_storage" type="text" autocomplete="off" |
| 136 | value="<?php echo esc_attr( sanitize_text_field(get_option('bmi_pro_ftp_host')) ); ?>" |
| 137 | placeholder="192.168.100.100" required |
| 138 | <?php echo( ( $shouldBeConnected ) ? 'disabled' : '' ); ?>> |
| 139 | <span style="color: red" id="host-required-error" hidden="hidden">Please enter the Host IP.</span> |
| 140 | </div> |
| 141 | <div class="mt10"> |
| 142 | <span> |
| 143 | |
| 144 | </span> |
| 145 | </div> |
| 146 | </div> |
| 147 | </div> |
| 148 | |
| 149 | <div class="d-flex"> |
| 150 | <div class="w270" style="margin-top: 23px;"><span>Host Port:</span></div> |
| 151 | <div> |
| 152 | <div class="w100 pos-r"> |
| 153 | <input id="bmip-ftp-host-port" class="input-ftpdrive_storage" type="text" autocomplete="off" |
| 154 | value="<?php echo esc_attr( sanitize_text_field(get_option('bmi_pro_ftp_port', "21")) ); ?>" |
| 155 | placeholder="21" required |
| 156 | <?php echo( ( $shouldBeConnected ) ? 'disabled' : '' ); ?>> |
| 157 | <span style="color: red" id="host-port-required-error" hidden="hidden">Please enter the Host Port.</span> |
| 158 | </div> |
| 159 | <div class="mt10"> |
| 160 | <span> |
| 161 | |
| 162 | </span> |
| 163 | </div> |
| 164 | </div> |
| 165 | </div> |
| 166 | |
| 167 | <div class="d-flex"> |
| 168 | <div class="w270" style="margin-top: 23px;"><span>User Name:</span></div> |
| 169 | <div> |
| 170 | <div class="w100 pos-r"> |
| 171 | <input id="bmip-ftp-user-name" class="input-ftpdrive_storage" type="text" autocomplete="off" |
| 172 | value="<?php echo esc_attr( $username ); ?>" |
| 173 | placeholder="User Name" required |
| 174 | <?php echo( ( $shouldBeConnected ) ? 'disabled' : '' ); ?>> |
| 175 | <span style="color: red" id="username-required-error" hidden="hidden">Username is required.</span> |
| 176 | </div> |
| 177 | <div class="mt10"> |
| 178 | <span> |
| 179 | |
| 180 | </span> |
| 181 | </div> |
| 182 | </div> |
| 183 | </div> |
| 184 | |
| 185 | <?php if (!$shouldBeConnected):?> |
| 186 | <div class="d-flex"> |
| 187 | <div class="w270" style="margin-top: 23px;"><span>Password:</span></div> |
| 188 | <div> |
| 189 | <div class="w100 pos-r"> |
| 190 | <input id="bmip-ftp-password" name="bmip_ftp_password" class="input-ftpdrive_storage" type="password" autocomplete="off" |
| 191 | placeholder="Password" required> |
| 192 | <span style="color: red" id="password-required-error" hidden="hidden">Password is required.</span> |
| 193 | </div> |
| 194 | <div class="mt10"> |
| 195 | <span> |
| 196 | |
| 197 | </span> |
| 198 | </div> |
| 199 | </div> |
| 200 | </div> |
| 201 | <?php endif;?> |
| 202 | </div> |
| 203 | |
| 204 | <div id="ftpdrive-unauthenticated-box" |
| 205 | class="container-40 lh30 pt30 pb30" <?php echo( ( $shouldBeConnected ) ? 'style="display: none;"' : '' ); ?>> |
| 206 | |
| 207 | <div class="d-flex"> |
| 208 | <div class="w270" style="margin-top: 11px;"><span id="ftpdrive-not-authed-content-box">Current status: <b>Inactive</b></span> |
| 209 | </div> |
| 210 | <div> |
| 211 | <div class="w100 pos-r"> |
| 212 | <a href="#" id="ftp-connect-btn" |
| 213 | class="btn external-storage-btn-connection"><?php esc_html_e( "Connect", 'backup-backup' ); ?></a> |
| 214 | </div> |
| 215 | </div> |
| 216 | </div> |
| 217 | |
| 218 | <div class="d-flex"> |
| 219 | <blockquote class="bmi-ftpdrive-info"> |
| 220 | FTP external storage allows automated transfer of backup files to a remote FTP server. This enhances your backup safety by storing backups off-site. Configure FTP server details and set backup schedules. |
| 221 | </blockquote> |
| 222 | </div> |
| 223 | </div> |
| 224 | |
| 225 | <div id="ftpdrive-authenticated-box" |
| 226 | class="container-40 lh30 pt30 pb30" <?php echo( ( ! $shouldBeConnected ) ? 'style="display: none;"' : '' ); ?>> |
| 227 | |
| 228 | <div class="d-flex"> |
| 229 | <div class="w270" style="margin-top: 11px;"><span id="ftpdrive-authed-content-box">Current status: <b>Active</b></span> |
| 230 | </div> |
| 231 | <div> |
| 232 | <div class="w100 pos-r"> |
| 233 | <a href="#" id="ftp-disconnect-btn" |
| 234 | class="btn"><?php esc_html_e( "Disconnect", 'backup-backup' ); ?></a> |
| 235 | </div> |
| 236 | </div> |
| 237 | </div> |
| 238 | </div> |
| 239 | <?php |
| 240 | } else { |
| 241 | ?> |
| 242 | <div class="container-40 lh30 pt30 pb30"> |
| 243 | <div class="center"> |
| 244 | It seem like you don't have cURL extension (PHP module) installed on your server.<br/> |
| 245 | Without this module it's impossible to upload backups to FTP Server.<br/> |
| 246 | If you wish to use this feature, please enable cURL module. |
| 247 | </div> |
| 248 | </div> |
| 249 | <?php |
| 250 | } |
| 251 | ?> |
| 252 | </div> |
| 253 | <?php if ( function_exists( 'curl_version' ) && function_exists( 'curl_exec' ) && function_exists( 'curl_init' ) && $vA && $vB ) { |
| 254 | ?> |
| 255 | <script> |
| 256 | document.getElementById('ftp-connect-btn').addEventListener('click', function (e) { |
| 257 | var host = document.getElementById('bmip-ftp-host-ip').value; |
| 258 | var port = document.getElementById('bmip-ftp-host-port').value; |
| 259 | var username = document.getElementById('bmip-ftp-user-name').value; |
| 260 | var password = document.getElementById('bmip-ftp-password').value; |
| 261 | |
| 262 | var hostError = document.getElementById('host-required-error'); |
| 263 | var portError = document.getElementById('host-port-required-error'); |
| 264 | var usernameError = document.getElementById('username-required-error'); |
| 265 | var passwordError = document.getElementById('password-required-error'); |
| 266 | |
| 267 | function toggleErrorDisplay(element, condition) { |
| 268 | element.style.display = condition ? "block" : "none"; |
| 269 | } |
| 270 | |
| 271 | function validateHost(host) { |
| 272 | return host.trim() !== ''; |
| 273 | } |
| 274 | |
| 275 | function validatePort(port) { |
| 276 | return port.trim() !== '' && !isNaN(port) && Number(port) >= 0 && Number(port) <= 65535; |
| 277 | } |
| 278 | |
| 279 | function validateUsername(username) { |
| 280 | return username.trim() !== ''; |
| 281 | } |
| 282 | |
| 283 | function validatePassword(password) { |
| 284 | return password.trim() !== ''; |
| 285 | } |
| 286 | |
| 287 | toggleErrorDisplay(hostError, !validateHost(host)); |
| 288 | toggleErrorDisplay(portError, !validatePort(port)); |
| 289 | toggleErrorDisplay(usernameError, !validateUsername(username)); |
| 290 | toggleErrorDisplay(passwordError, !validatePassword(password)); |
| 291 | }); |
| 292 | </script> |
| 293 | <?php |
| 294 | } ?> |
| 295 | <?php |
| 296 | |
| 297 | } ); |