| @@ -14,8 +14,9 @@ | ||
| 14 | 14 | |
| 15 | 15 | class WPDA_Settings_Drives extends WPDA_Settings { |
| 16 | 16 | |
| 17 | 17 | private $drives = null; |
| 18 | + private $canSftp = false; | |
| 18 | 19 | |
| 19 | 20 | private function get_drive( $drive_type ) { |
| 20 | 21 | |
| 21 | 22 | if ( is_array( $this->drives ) ) { |
| @@ -226,8 +227,12 @@ | ||
| 226 | 227 | } |
| 227 | 228 | |
| 228 | 229 | protected function add_content() { |
| 229 | 230 | |
| 231 | + if ( function_exists('ftp_ssl_connect') ) { | |
| 232 | + $this->canSftp = true; | |
| 233 | + } | |
| 234 | + | |
| 230 | 235 | if ( isset( $_POST['action'] ) ) { |
| 231 | 236 | $action = sanitize_text_field( wp_unslash( $_POST['action'] ) ); // input var okay. |
| 232 | 237 | |
| 233 | 238 | // Security check. |
| @@ -821,8 +826,41 @@ | ||
| 821 | 826 | ); |
| 822 | 827 | } |
| 823 | 828 | } |
| 824 | 829 | |
| 830 | + function ftpOnClick(event) { | |
| 831 | + if ( | |
| 832 | + jQuery(event.target) | |
| 833 | + .closest('fieldset') | |
| 834 | + .find('.form-control-details:visible') | |
| 835 | + .length === 0 | |
| 836 | + ) { | |
| 837 | + jQuery(event.target) | |
| 838 | + .attr('title', 'Hide FTP Server details'); | |
| 839 | + jQuery(event.target) | |
| 840 | + .removeClass('dashicons-visibility') | |
| 841 | + .addClass('dashicons-hidden'); | |
| 842 | + jQuery(event.target) | |
| 843 | + .closest('fieldset') | |
| 844 | + .find('.form-control-details') | |
| 845 | + .css('display', 'block'); | |
| 846 | + jQuery(event.target) | |
| 847 | + .closest('fieldset') | |
| 848 | + .find('a.form-control-details') | |
| 849 | + .css('display', 'flex'); | |
| 850 | + } else { | |
| 851 | + jQuery(event.target) | |
| 852 | + .attr('title', 'Show FTP Server details'); | |
| 853 | + jQuery(event.target) | |
| 854 | + .removeClass('dashicons-hidden') | |
| 855 | + .addClass('dashicons-visibility'); | |
| 856 | + jQuery(event.target) | |
| 857 | + .closest('fieldset') | |
| 858 | + .find('.form-control-details') | |
| 859 | + .hide(); | |
| 860 | + } | |
| 861 | + } | |
| 862 | + | |
| 825 | 863 | function ftpContainer( |
| 826 | 864 | isNew, |
| 827 | 865 | driveName = '', |
| 828 | 866 | isChecked = false, |
| @@ -834,8 +872,21 @@ | ||
| 834 | 872 | passive = false, |
| 835 | 873 | timeout = 90, |
| 836 | 874 | directory = '/' |
| 837 | 875 | ) { |
| 876 | + const canSftp = <?php echo $this->canSftp ? 'true' : 'false'; ?>; | |
| 877 | + if (!canSftp) { | |
| 878 | + ssl = false; | |
| 879 | + } | |
| 880 | + const sftpMessage = !canSftp | |
| 881 | + ? `<div class="form-control form-control-details"> | |
| 882 | + <label></label> | |
| 883 | + <span style="line-height:1.6;margin-bottom:10px;"> | |
| 884 | + <span class="dashicons dashicons-warning"></span> This server does not support SSL, ftp_ssl_connect is currently not available. (<a href="https://www.php.net/manual/en/function.ftp-ssl-connect.php" target="_blank">Read More...</a>) | |
| 885 | + </span> | |
| 886 | + </div>` | |
| 887 | + : ""; | |
| 888 | + | |
| 838 | 889 | jQuery("#ftp_container").append(` |
| 839 | 890 | <fieldset class="wpda_fieldset${isNew ? ' wpda-is-new' : ''}"> |
| 840 | 891 | |
| 841 | 892 | <div class="form-control"> |
| @@ -853,9 +904,9 @@ | ||
| 853 | 904 | </label> |
| 854 | 905 | |
| 855 | 906 | <div> |
| 856 | 907 | <a href="javascript:void(0)" |
| 857 | - onclick="jQuery(this).closest('fieldset').find('.form-control-details').show(); jQuery(this).closest('fieldset').find('.form-control-details').css('display', 'block'); jQuery(this).closest('fieldset').find('a.form-control-details').css('display', 'flex'); jQuery(this).closest('fieldset').find('.form-control-icons').hide();" | |
| 908 | + onclick="ftpOnClick(event)" | |
| 858 | 909 | style="text-decoration:none;${isNew ? 'display:none;' : ''}" |
| 859 | 910 | class="wpda_tooltip form-control-icons" |
| 860 | 911 | title="Show FTP Server details"> |
| 861 | 912 | <span class="dashicons dashicons-visibility" style="font-size:18px;"></span> |
| @@ -861,16 +912,8 @@ | ||
| 861 | 912 | <span class="dashicons dashicons-visibility" style="font-size:18px;"></span> |
| 862 | 913 | </a> |
| 863 | 914 | |
| 864 | 915 | <a href="javascript:void(0)" |
| 865 | - onclick="jQuery(this).closest('fieldset').find('.form-control-details').hide(); jQuery(this).closest('fieldset').find('.form-control-icons').show();" | |
| 866 | - style="text-decoration:none;${isNew ? 'display:none;' : ''}" | |
| 867 | - class="wpda_tooltip form-control-details" | |
| 868 | - title="Show FTP Server details"> | |
| 869 | - <span class="dashicons dashicons-hidden" style="font-size:18px;"></span> | |
| 870 | - </a> | |
| 871 | - | |
| 872 | - <a href="javascript:void(0)" | |
| 873 | 916 | onclick="if (confirm('Are you sure you want to delete this FTP Server? This action cannot be undone!')) { jQuery(this).closest('fieldset').remove(); deleteDrive('${driveName}'); }" |
| 874 | 917 | style="text-decoration:none;" |
| 875 | 918 | class="wpda_tooltip" |
| 876 | 919 | title="Delete FTP Server"> |
| @@ -903,9 +946,9 @@ | ||
| 903 | 946 | <div class="form-control form-control-details"> |
| 904 | 947 | <div></div> |
| 905 | 948 | <div> |
| 906 | 949 | <label> |
| 907 | - <input type="checkbox" name="ftp_ssl[]" ${ssl ? 'checked' : ''} /> | |
| 950 | + <input type="checkbox" name="ftp_ssl[]" ${ssl ? 'checked' : ''} <?php echo $this->canSftp ? '' : 'disabled="disabled"'; ?> /> | |
| 908 | 951 | SSL |
| 909 | 952 | </label> |
| 910 | 953 | |
| 911 | 954 | <label> |
| @@ -913,8 +956,9 @@ | ||
| 913 | 956 | Passive |
| 914 | 957 | </label> |
| 915 | 958 | </div> |
| 916 | 959 | </div> |
| 960 | + ${sftpMessage} | |
| 917 | 961 | |
| 918 | 962 | <div class="form-control form-control-details"> |
| 919 | 963 | <label>Timeout</label> |
| 920 | 964 | <input type="number" name="ftp_timeout[]" value="${timeout}" /> |
| @@ -923,9 +967,8 @@ | ||
| 923 | 967 | <div class="form-control form-control-details"> |
| 924 | 968 | <label>Directory</label> |
| 925 | 969 | <input type="text" name="ftp_directory[]" value="${directory}" /> |
| 926 | 970 | </div> |
| 927 | - | |
| 928 | 971 | </fieldset> |
| 929 | 972 | `); |
| 930 | 973 | } |
| 931 | 974 | |
| @@ -958,21 +1001,13 @@ | ||
| 958 | 1001 | </label> |
| 959 | 1002 | |
| 960 | 1003 | <div> |
| 961 | 1004 | <a href="javascript:void(0)" |
| 962 | - onclick="jQuery(this).closest('fieldset').find('.form-control-details').show(); jQuery(this).closest('fieldset').find('.form-control-details').css('display', 'block'); jQuery(this).closest('fieldset').find('a.form-control-details').css('display', 'flex'); jQuery(this).closest('fieldset').find('.form-control-icons').hide();" | |
| 1005 | + onclick="ftpOnClick(event)" | |
| 963 | 1006 | style="text-decoration:none;${isNew ? 'display:none;' : ''}" |
| 964 | 1007 | class="wpda_tooltip form-control-icons" |
| 965 | 1008 | title="Show FTP Server details"> |
| 966 | 1009 | <span class="dashicons dashicons-visibility" style="font-size:18px;"></span> |
| 967 | - </a> | |
| 968 | - | |
| 969 | - <a href="javascript:void(0)" | |
| 970 | - onclick="jQuery(this).closest('fieldset').find('.form-control-details').hide(); jQuery(this).closest('fieldset').find('.form-control-icons').show();" | |
| 971 | - style="text-decoration:none;${isNew ? 'display:none;' : ''}" | |
| 972 | - class="wpda_tooltip form-control-details" | |
| 973 | - title="Show FTP Server details"> | |
| 974 | - <span class="dashicons dashicons-hidden" style="font-size:18px;"></span> | |
| 975 | 1010 | </a> |
| 976 | 1011 | |
| 977 | 1012 | <a href="javascript:void(0)" |
| 978 | 1013 | onclick="if (confirm('Are you sure you want to delete this SFTP Server? This action cannot be undone!')) { jQuery(this).closest('fieldset').remove(); deleteDrive('${driveName}'); }" |