PluginProbe
WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards / 5.5.84
WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards v5.5.84
5.5.84 5.5.83 5.5.82 5.5.81 5.5.80 5.5.79 5.5.77 5.5.76 5.5.75 5.5.73 5.5.72 5.5.22 5.5.23 5.5.29 5.5.3 5.5.31 5.5.32 5.5.34 5.5.35 5.5.36 5.5.37 5.5.4 5.5.40 5.5.41 5.5.42 All 160 releases
← All changes | WPDataAccess/Utilities/WPDA_Remote_Database.php +197 -81 5.5.355.5.84 View file →
@@ -1,6 +1,7 @@
1 1 <?php
2 2
3 +// phpcs:disable WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing -- verified on page
3 4 namespace WPDataAccess\Utilities;
4 5
5 6 use WPDataAccess\API\WPDA_Tree;
6 7 use WPDataAccess\Connection\WPDADB;
@@ -25,9 +26,8 @@
25 26 wp_enqueue_script( 'jquery-ui-tooltip' );
26 27 wp_enqueue_script( 'jquery-ui-autocomplete' );
27 28 if ( isset( $_REQUEST['page'] ) ) {
28 29 $this->page = sanitize_text_field( wp_unslash( $_REQUEST['page'] ) );
29 - // input var okay.
30 30 }
31 31 $this->user_can_create_db = WPDA_Dictionary_Access::can_create_db();
32 32 if ( WPDA::current_user_is_admin() ) {
33 33 if ( isset( $_REQUEST['action'] ) ) {
@@ -37,8 +37,10 @@
37 37 } elseif ( 'drop_db' === $_REQUEST['action'] ) {
38 38 $this->drop_db();
39 39 } elseif ( 'edit_db' === $_REQUEST['action'] ) {
40 40 $this->edit_db();
41 + } elseif ( 'toggle_db' === $_REQUEST['action'] ) {
42 + $this->toggle_db();
41 43 }
42 44 }
43 45 }
44 46 }
@@ -50,9 +52,9 @@
50 52 if ( isset( $_REQUEST['database_location'] ) && 'local' === $_REQUEST['database_location'] ) {
51 53 // Add local database
52 54 if ( !isset( $_REQUEST['local_database'] ) ) {
53 55 $msg = new WPDA_Message_Box(array(
54 - 'message_text' => sprintf( __( 'Cannot create database [missing argument]', 'wp-data-access' ) ),
56 + 'message_text' => __( 'Cannot create database [missing argument]', 'wp-data-access' ),
55 57 'message_type' => 'error',
56 58 'message_is_dismissible' => false,
57 59 ));
58 60 $msg->box();
@@ -58,67 +60,63 @@
58 60 $msg->box();
59 61 return;
60 62 }
61 63 $database = str_replace( '`', '', sanitize_text_field( wp_unslash( $_REQUEST['local_database'] ) ) );
62 - // input var okay.
63 64 global $wpdb;
64 - if ( false === $wpdb->query( $wpdb->prepare(
65 - 'create database `%1s`',
66 - // phpcs:ignore WordPress.DB.PreparedSQLPlaceholders
67 - array(WPDA::remove_backticks( $database ))
68 - ) ) ) {
65 + // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQLPlaceholders, WordPress.DB.DirectDatabaseQuery.SchemaChange
66 + if ( false === $wpdb->query( $wpdb->prepare( 'create database `%1s`', array(WPDA::remove_backticks( $database )) ) ) ) {
69 67 // db call ok; no-cache ok.
68 + // phpcs:disable WordPress.WP.I18n.MissingTranslatorsComment
70 69 $msg = new WPDA_Message_Box(array(
71 - 'message_text' => sprintf( __( 'Error creating database `%s`', 'wp-data-access' ), $database ),
70 + 'message_text' => sprintf( __( 'Error creating database `%s`', 'wp-data-access' ), esc_attr( $database ) ),
72 71 'message_type' => 'error',
73 72 'message_is_dismissible' => false,
74 73 ));
74 + // phpcs:enable WordPress.WP.I18n.MissingTranslatorsComment
75 75 $msg->box();
76 76 } else {
77 + // phpcs:disable WordPress.WP.I18n.MissingTranslatorsComment
78 + // phpcs:disable WordPress.Security.ValidatedSanitizedInput
77 79 $msg = new WPDA_Message_Box(array(
78 - 'message_text' => sprintf( __( 'Database `%s` created', 'wp-data-access' ), $database ),
80 + 'message_text' => sprintf( __( 'Database `%s` created', 'wp-data-access' ), esc_attr( $database ) ),
79 81 ));
82 + // phpcs:enable WordPress.Security.ValidatedSanitizedInput
83 + // phpcs:enable WordPress.WP.I18n.MissingTranslatorsComment
80 84 $msg->box();
81 85 $this->switch_schema_name = $database;
82 86 }
87 + // phpcs:enable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQLPlaceholders, WordPress.DB.DirectDatabaseQuery.SchemaChange
83 88 } else {
84 89 // Add remote database
85 90 $database = ( isset( $_REQUEST['remote_database'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['remote_database'] ) ) : '' );
86 - // input var okay.
87 91 if ( false !== WPDADB::get_remote_database( $database ) ) {
92 + // phpcs:disable WordPress.WP.I18n.MissingTranslatorsComment
88 93 $msg = new WPDA_Message_Box(array(
89 - 'message_text' => sprintf( __( 'Remote database connection already exists', 'wp-data-access' ) ),
94 + 'message_text' => __( 'Remote database connection already exists', 'wp-data-access' ),
90 95 'message_type' => 'error',
91 96 'message_is_dismissible' => false,
92 97 ));
98 + // phpcs:enable WordPress.WP.I18n.MissingTranslatorsComment
93 99 $msg->box();
94 100 return;
95 101 }
96 102 $host = ( isset( $_REQUEST['remote_host'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['remote_host'] ) ) : '' );
97 - // input var okay.
98 103 $user = ( isset( $_REQUEST['remote_user'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['remote_user'] ) ) : '' );
99 - // input var okay.
104 + // phpcs:disable WordPress.Security.ValidatedSanitizedInput
100 105 $passwd = ( isset( $_REQUEST['remote_passwd'] ) ? wp_unslash( $_REQUEST['remote_passwd'] ) : '' );
101 - // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
106 + // Cannot use sanitize_text_field on password field!
107 + // phpcs:enable WordPress.Security.ValidatedSanitizedInput
102 108 $port = ( isset( $_REQUEST['remote_port'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['remote_port'] ) ) : '' );
103 - // input var okay.
104 109 $schema = ( isset( $_REQUEST['remote_schema'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['remote_schema'] ) ) : '' );
105 - // input var okay.
106 110 $ssl = ( isset( $_REQUEST['remote_ssl'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['remote_ssl'] ) ) : 'off' );
107 - // input var okay.
108 111 $ssl_key = ( isset( $_REQUEST['remote_client_key'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['remote_client_key'] ) ) : '' );
109 - // input var okay.
110 112 $ssl_cert = ( isset( $_REQUEST['remote_client_certificate'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['remote_client_certificate'] ) ) : '' );
111 - // input var okay.
112 113 $ssl_ca = ( isset( $_REQUEST['remote_ca_certificate'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['remote_ca_certificate'] ) ) : '' );
113 - // input var okay.
114 114 $ssl_path = ( isset( $_REQUEST['remote_certificate_path'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['remote_certificate_path'] ) ) : '' );
115 - // input var okay.
116 115 $ssl_cipher = ( isset( $_REQUEST['remote_specified_cipher'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['remote_specified_cipher'] ) ) : '' );
117 - // input var okay.
118 116 if ( '' === $database || '' === $host || '' === $user || '' === $schema ) {
119 117 $msg = new WPDA_Message_Box(array(
120 - 'message_text' => sprintf( __( 'Cannot add remote database connection [missing argument]', 'wp-data-access' ) ),
118 + 'message_text' => __( 'Cannot add remote database connection [missing argument]', 'wp-data-access' ),
121 119 'message_type' => 'error',
122 120 'message_is_dismissible' => false,
123 121 ));
124 122 $msg->box();
@@ -125,9 +123,9 @@
125 123 return;
126 124 }
127 125 if ( 'rdb:' === $database ) {
128 126 $msg = new WPDA_Message_Box(array(
129 - 'message_text' => sprintf( __( 'Invalid database name [enter a valid database name, for example rdb:remotedb]', 'wp-data-access' ) ),
127 + 'message_text' => __( 'Invalid database name [enter a valid database name, for example rdb:remotedb]', 'wp-data-access' ),
130 128 'message_type' => 'error',
131 129 'message_is_dismissible' => false,
132 130 ));
133 131 $msg->box();
@@ -147,17 +145,19 @@
147 145 $ssl_path,
148 146 $ssl_cipher
149 147 ) ) {
150 148 $msg = new WPDA_Message_Box(array(
151 - 'message_text' => sprintf( __( 'Cannot add remote database connection', 'wp-data-access' ) ),
149 + 'message_text' => __( 'Cannot add remote database connection', 'wp-data-access' ),
152 150 'message_type' => 'error',
153 151 'message_is_dismissible' => false,
154 152 ));
155 153 $msg->box();
156 154 } else {
155 + // phpcs:disable WordPress.WP.I18n.MissingTranslatorsComment
157 156 $msg = new WPDA_Message_Box(array(
158 - 'message_text' => sprintf( __( 'Remote database connection `%s` added', 'wp-data-access' ), $database ),
157 + 'message_text' => sprintf( __( 'Remote database connection `%s` added', 'wp-data-access' ), esc_attr( $database ) ),
159 158 ));
159 + // phpcs:enable WordPress.WP.I18n.MissingTranslatorsComment
160 160 $msg->box();
161 161 $this->switch_schema_name = $database;
162 162 }
163 163 }
@@ -162,8 +162,54 @@
162 162 }
163 163 }
164 164 }
165 165
166 + private function toggle_db() {
167 + if ( !$this->check_wpnonce( 'wpda-toggle-db-from-data-explorer-' . WPDA::get_current_user_login(), '_wpnoncetoggledb' ) ) {
168 + return;
169 + }
170 + if ( !isset( $_REQUEST['database'], $_REQUEST['disabled'] ) ) {
171 + $msg = new WPDA_Message_Box(array(
172 + 'message_text' => __( 'Cannot drop database [missing argument]', 'wp-data-access' ),
173 + 'message_type' => 'error',
174 + 'message_is_dismissible' => false,
175 + ));
176 + $msg->box();
177 + return;
178 + }
179 + global $wpdb;
180 + $database = str_replace( '`', '', sanitize_text_field( wp_unslash( $_REQUEST['database'] ) ) );
181 + $disabled = $_REQUEST['disabled'] === 'true';
182 + if ( 'rdb:' === substr( $database, 0, 4 ) ) {
183 + // Toogle remote database
184 + // phpcs:disable WordPress.WP.I18n.MissingTranslatorsComment
185 + if ( false === WPDADB::get_remote_database( $database, true ) ) {
186 + $msg = new WPDA_Message_Box(array(
187 + 'message_text' => sprintf( __( 'Cannot disable remote database connection `%s` [remote database connection not found]', 'wp-data-access' ), esc_attr( $database ) ),
188 + 'message_type' => 'error',
189 + 'message_is_dismissible' => false,
190 + ));
191 + $msg->box();
192 + } else {
193 + if ( false === WPDADB::dis_remote_database( $database, $disabled ) ) {
194 + $msg = new WPDA_Message_Box(array(
195 + 'message_text' => sprintf( __( 'Cannot disable remote database connection `%s`', 'wp-data-access' ), esc_attr( $database ) ),
196 + 'message_type' => 'error',
197 + 'message_is_dismissible' => false,
198 + ));
199 + $msg->box();
200 + } else {
201 + $msg = new WPDA_Message_Box(array(
202 + 'message_text' => sprintf( __( 'Remote database connection `%s` disabled', 'wp-data-access' ), esc_attr( $database ) ),
203 + ));
204 + $msg->box();
205 + $this->switch_schema_name = $wpdb->dbname;
206 + }
207 + }
208 + // phpcs:enable WordPress.WP.I18n.MissingTranslatorsComment
209 + }
210 + }
211 +
166 212 private function drop_db() {
167 213 if ( !$this->check_wpnonce( 'wpda-drop-db-from-data-explorer-' . WPDA::get_current_user_login(), '_wpnoncedropdb' ) ) {
168 214 return;
169 215 }
@@ -168,9 +214,9 @@
168 214 return;
169 215 }
170 216 if ( !isset( $_REQUEST['database'] ) ) {
171 217 $msg = new WPDA_Message_Box(array(
172 - 'message_text' => sprintf( __( 'Cannot drop database [missing argument]', 'wp-data-access' ) ),
218 + 'message_text' => __( 'Cannot drop database [missing argument]', 'wp-data-access' ),
173 219 'message_type' => 'error',
174 220 'message_is_dismissible' => false,
175 221 ));
176 222 $msg->box();
@@ -177,14 +223,14 @@
177 223 return;
178 224 }
179 225 global $wpdb;
180 226 $database = str_replace( '`', '', sanitize_text_field( wp_unslash( $_REQUEST['database'] ) ) );
181 - // input var okay.
182 227 if ( 'rdb:' === substr( $database, 0, 4 ) ) {
183 228 // Delete remote database
229 + // phpcs:disable WordPress.WP.I18n.MissingTranslatorsComment
184 230 if ( false === WPDADB::get_remote_database( $database ) ) {
185 231 $msg = new WPDA_Message_Box(array(
186 - 'message_text' => sprintf( __( 'Cannot delete remote database connection `%s` [remote database connection not found]', 'wp-data-access' ), $database ),
232 + 'message_text' => sprintf( __( 'Cannot delete remote database connection `%s` [remote database connection not found]', 'wp-data-access' ), esc_attr( $database ) ),
187 233 'message_type' => 'error',
188 234 'message_is_dismissible' => false,
189 235 ));
190 236 $msg->box();
@@ -190,9 +236,9 @@
190 236 $msg->box();
191 237 } else {
192 238 if ( false === WPDADB::del_remote_database( $database ) ) {
193 239 $msg = new WPDA_Message_Box(array(
194 - 'message_text' => sprintf( __( 'Cannot delete remote database connection `%s`', 'wp-data-access' ), $database ),
240 + 'message_text' => sprintf( __( 'Cannot delete remote database connection `%s`', 'wp-data-access' ), esc_attr( $database ) ),
195 241 'message_type' => 'error',
196 242 'message_is_dismissible' => false,
197 243 ));
198 244 $msg->box();
@@ -197,14 +243,15 @@
197 243 ));
198 244 $msg->box();
199 245 } else {
200 246 $msg = new WPDA_Message_Box(array(
201 - 'message_text' => sprintf( __( 'Remove database `%s` deleted', 'wp-data-access' ), $database ),
247 + 'message_text' => sprintf( __( 'Remote database connection `%s` deleted', 'wp-data-access' ), esc_attr( $database ) ),
202 248 ));
203 249 $msg->box();
204 250 $this->switch_schema_name = $wpdb->dbname;
205 251 }
206 252 }
253 + // phpcs:enable WordPress.WP.I18n.MissingTranslatorsComment
207 254 } else {
208 255 // Drop local database
209 256 if ( $wpdb->dbname === $database ) {
210 257 $msg = new WPDA_Message_Box(array(
@@ -223,16 +270,14 @@
223 270 ));
224 271 $msg->box();
225 272 return;
226 273 }
227 - if ( false === $wpdb->query( $wpdb->prepare(
228 - 'drop database `%1s`',
229 - // phpcs:ignore WordPress.DB.PreparedSQLPlaceholders
230 - array(WPDA::remove_backticks( $database ))
231 - ) ) ) {
274 + // phpcs:disable WordPress.WP.I18n.MissingTranslatorsComment
275 + // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQLPlaceholders, WordPress.DB.DirectDatabaseQuery.SchemaChange, WordPress.DB.PreparedSQLPlaceholders.UnquotedComplexPlaceholder
276 + if ( false === $wpdb->query( $wpdb->prepare( 'drop database `%1s`', array(WPDA::remove_backticks( $database )) ) ) ) {
232 277 // db call ok; no-cache ok.
233 278 $msg = new WPDA_Message_Box(array(
234 - 'message_text' => sprintf( __( 'Error dropping database `%s`', 'wp-data-access' ), $database ),
279 + 'message_text' => sprintf( __( 'Error dropping database `%s`', 'wp-data-access' ), esc_attr( $database ) ),
235 280 'message_type' => 'error',
236 281 'message_is_dismissible' => false,
237 282 ));
238 283 $msg->box();
@@ -237,13 +282,15 @@
237 282 ));
238 283 $msg->box();
239 284 } else {
240 285 $msg = new WPDA_Message_Box(array(
241 - 'message_text' => sprintf( __( 'Database `%s` dropped', 'wp-data-access' ), $database ),
286 + 'message_text' => sprintf( __( 'Database `%s` dropped', 'wp-data-access' ), esc_attr( $database ) ),
242 287 ));
243 288 $msg->box();
244 289 $this->switch_schema_name = $wpdb->dbname;
245 290 }
291 + // phpcs:enable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQLPlaceholders, WordPress.DB.DirectDatabaseQuery.SchemaChange, WordPress.DB.PreparedSQLPlaceholders.UnquotedComplexPlaceholder
292 + // phpcs:enable WordPress.WP.I18n.MissingTranslatorsComment
246 293 }
247 294 }
248 295
249 296 private function edit_db() {
@@ -251,9 +298,9 @@
251 298 return;
252 299 }
253 300 if ( !isset( $_REQUEST['edit_remote_database'] ) ) {
254 301 $msg = new WPDA_Message_Box(array(
255 - 'message_text' => sprintf( __( 'Cannot update remote database connection [missing argument]', 'wp-data-access' ) ),
302 + 'message_text' => __( 'Cannot update remote database connection [missing argument]', 'wp-data-access' ),
256 303 'message_type' => 'error',
257 304 'message_is_dismissible' => false,
258 305 ));
259 306 $msg->box();
@@ -259,16 +306,16 @@
259 306 $msg->box();
260 307 return;
261 308 }
262 309 $database = sanitize_text_field( wp_unslash( $_REQUEST['edit_remote_database'] ) );
263 - // input var okay.
310 + // phpcs:disable WordPress.Security.ValidatedSanitizedInput
264 311 $database_old = sanitize_text_field( wp_unslash( $_REQUEST['edit_remote_database_old'] ) );
265 - // input var okay.
312 + // phpcs:enable WordPress.Security.ValidatedSanitizedInput
266 313 if ( $database !== $database_old ) {
267 314 // Update database connection name
268 315 if ( false === WPDADB::get_remote_database( $database_old ) ) {
269 316 $msg = new WPDA_Message_Box(array(
270 - 'message_text' => sprintf( __( 'Cannot update remote database connection [remote database connection not found]', 'wp-data-access' ) ),
317 + 'message_text' => __( 'Cannot update remote database connection [remote database connection not found]', 'wp-data-access' ),
271 318 'message_type' => 'error',
272 319 'message_is_dismissible' => false,
273 320 ));
274 321 $msg->box();
@@ -277,9 +324,9 @@
277 324 } else {
278 325 // Update database connection information
279 326 if ( false === WPDADB::get_remote_database( $database ) ) {
280 327 $msg = new WPDA_Message_Box(array(
281 - 'message_text' => sprintf( __( 'Cannot update remote database connection [remote database connection not found]', 'wp-data-access' ) ),
328 + 'message_text' => __( 'Cannot update remote database connection [remote database connection not found]', 'wp-data-access' ),
282 329 'message_type' => 'error',
283 330 'message_is_dismissible' => false,
284 331 ));
285 332 $msg->box();
@@ -286,32 +333,24 @@
286 333 return;
287 334 }
288 335 }
289 336 $host = ( isset( $_REQUEST['edit_remote_host'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['edit_remote_host'] ) ) : '' );
290 - // input var okay.
291 337 $user = ( isset( $_REQUEST['edit_remote_user'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['edit_remote_user'] ) ) : '' );
292 - // input var okay.
338 + // Cannot use sanitize_text_field on password field!
339 + // phpcs:disable WordPress.Security.ValidatedSanitizedInput
293 340 $passwd = ( isset( $_REQUEST['edit_remote_passwd'] ) ? wp_unslash( $_REQUEST['edit_remote_passwd'] ) : '' );
294 - // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
341 + // phpcs:enable WordPress.Security.ValidatedSanitizedInput
295 342 $port = ( isset( $_REQUEST['edit_remote_port'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['edit_remote_port'] ) ) : '' );
296 - // input var okay.
297 343 $schema = ( isset( $_REQUEST['edit_remote_schema'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['edit_remote_schema'] ) ) : '' );
298 - // input var okay.
299 344 $ssl = ( isset( $_REQUEST['edit_remote_ssl'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['edit_remote_ssl'] ) ) : 'off' );
300 - // input var okay.
301 345 $ssl_key = ( isset( $_REQUEST['edit_remote_client_key'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['edit_remote_client_key'] ) ) : '' );
302 - // input var okay.
303 346 $ssl_cert = ( isset( $_REQUEST['edit_remote_client_certificate'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['edit_remote_client_certificate'] ) ) : '' );
304 - // input var okay.
305 347 $ssl_ca = ( isset( $_REQUEST['edit_remote_ca_certificate'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['edit_remote_ca_certificate'] ) ) : '' );
306 - // input var okay.
307 348 $ssl_path = ( isset( $_REQUEST['edit_remote_certificate_path'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['edit_remote_certificate_path'] ) ) : '' );
308 - // input var okay.
309 349 $ssl_cipher = ( isset( $_REQUEST['edit_remote_specified_cipher'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['edit_remote_specified_cipher'] ) ) : '' );
310 - // input var okay.
311 350 if ( '' === $database || '' === $host || '' === $user || '' === $schema ) {
312 351 $msg = new WPDA_Message_Box(array(
313 - 'message_text' => sprintf( __( 'Cannot edit remote database connection [missing arguments]', 'wp-data-access' ) ),
352 + 'message_text' => __( 'Cannot edit remote database connection [missing arguments]', 'wp-data-access' ),
314 353 'message_type' => 'error',
315 354 'message_is_dismissible' => false,
316 355 ));
317 356 $msg->box();
@@ -332,18 +371,22 @@
332 371 $ssl_ca,
333 372 $ssl_path,
334 373 $ssl_cipher
335 374 ) ) {
375 + // phpcs:disable WordPress.WP.I18n.MissingTranslatorsComment
336 376 $msg = new WPDA_Message_Box(array(
337 - 'message_text' => sprintf( __( 'Cannot update remote database connection `%s`', 'wp-data-access' ), $database ),
377 + 'message_text' => sprintf( __( 'Cannot update remote database connection `%s`', 'wp-data-access' ), esc_attr( $database ) ),
338 378 'message_type' => 'error',
339 379 'message_is_dismissible' => false,
340 380 ));
381 + // phpcs:enable WordPress.WP.I18n.MissingTranslatorsComment
341 382 $msg->box();
342 383 } else {
384 + // phpcs:disable WordPress.WP.I18n.MissingTranslatorsComment
343 385 $msg = new WPDA_Message_Box(array(
344 - 'message_text' => sprintf( __( 'Remote database connection `%s` updated', 'wp-data-access' ), $database ),
386 + 'message_text' => sprintf( __( 'Remote database connection `%s` updated', 'wp-data-access' ), esc_attr( $database ) ),
345 387 ));
388 + // phpcs:enable WordPress.WP.I18n.MissingTranslatorsComment
346 389 $msg->box();
347 390 if ( $database !== $database_old ) {
348 391 $this->switch_schema_name = $database;
349 392 }
@@ -411,8 +454,11 @@
411 454
412 455 <?php
413 456 $this->drop_database();
414 457 ?>
458 + <?php
459 + $this->toggle_database();
460 + ?>
415 461
416 462 <?php
417 463 $this->js();
418 464 $this->css();
@@ -419,9 +465,9 @@
419 465 }
420 466
421 467 private function manage_databases() {
422 468 $tree = new WPDA_Tree();
423 - $dbs = $tree->get_dbs();
469 + $dbs = $tree->get_dbs( true );
424 470 $this->rdb = array();
425 471 $mdbs = array(
426 472 '' => '',
427 473 );
@@ -432,9 +478,9 @@
432 478 // Admins can manage local and remote database only.
433 479 $mdbs[$db['dbs']] = $db['dbs_type'];
434 480 if ( 'remote' === $db['dbs_type'] ) {
435 481 // Store remote database info.
436 - $this->rdb[$db['dbs']] = WPDADB::get_remote_database( $db['dbs'] );
482 + $this->rdb[$db['dbs']] = WPDADB::get_remote_database( $db['dbs'], true );
437 483 }
438 484 }
439 485 }
440 486 }
@@ -441,9 +487,9 @@
441 487 ?>
442 488
443 489 <h3 class="wpda_db_title">
444 490 <?php
445 - echo __( 'Manage Databases', 'wp-data-access' );
491 + esc_html_e( 'Manage Databases', 'wp-data-access' );
446 492 ?>
447 493 </h3>
448 494
449 495 <?php
@@ -458,15 +504,15 @@
458 504 ?>
459 505 <div class="restyle_link">
460 506 <strong>NOTE</strong>
461 507 Please activate your Premium Data Services access <a href="options-general.php?page=wpdataaccess&tab=pds">here</a> to remotely connect to foreign DBMSs and remote files.
462 - <a href="https://wpdataaccess.com/docs/remote-connection-wizard/remote-wizard/" class="restyle_link" target="_blank">(read more...)</a>
508 + <a href="https://docs.remote.wpdataaccess.com/pds/remote-wizard.html" class="restyle_link" target="_blank">(read more...)</a>
463 509 </div>
464 510 <?php
465 511 }
466 512
467 513 private function no_database() {
468 - echo __( 'No manageable local databases or remote database connections found', 'wp-data-access' );
514 + esc_html_e( 'No manageable local databases or remote database connections found', 'wp-data-access' );
469 515 }
470 516
471 517 private function list_databases( $dbs ) {
472 518 ?>
@@ -476,9 +522,9 @@
476 522 <label for="edit_remote_database" class="database_item_label">Select database:</label>
477 523 <select id="manage_db_selection">
478 524 <?php
479 525 foreach ( $dbs as $db => $db_type ) {
480 - echo "<option value='{$db}' data-type='{$db_type}'>{$db}</option>";
526 + echo '<option value="' . esc_attr( $db ) . '" data-type="' . esc_attr( $db_type ) . '">' . esc_attr( $db ) . '</option>';
481 527 }
482 528 ?>
483 529 </select>
484 530
@@ -487,10 +533,10 @@
487 533 style="display: none"
488 534 href="javascript:void(0)"
489 535 style="vertical-align:middle;"
490 536 title="<?php
491 - echo __( "Create function wpda_get_wp_user_id() to access the WordPress user ID from database views", 'wp-data-access' );
492 - ?>">&nbsp;</a>
537 + esc_html_e( "Create function wpda_get_wp_user_id() to access the WordPress user ID from database views", 'wp-data-access' );
538 + ?>"></a>
493 539
494 540 </div>
495 541
496 542 <?php
@@ -505,11 +551,11 @@
505 551 <label for="edit_local_database" class="database_item_label">Database name:</label>
506 552 <input type="text" name="edit_local_database" id="edit_local_database" readonly>
507 553 <a href="javascript:void(0)"
508 554 id="edit_local_database_action"
509 - class="button button-primary"><i
510 - class="fas fa-trash wpda_icon_on_button"></i> Drop database
511 - </a>
555 + title="Drop Database"
556 + class="button button-secondary wpda_tooltip"><i
557 + class="fas fa-trash wpda_icon_on_button"></i></a>
512 558 </div>
513 559
514 560 <?php
515 561 }
@@ -532,16 +578,38 @@
532 578 id="edit_remote_database">
533 579 <input type="hidden"
534 580 name="edit_remote_database_old"
535 581 id="edit_remote_database_old">
536 - <a href="javascript:void(0)"
537 - id="remote_local_database_action"
538 - class="button button-secondary"><i
539 - class="fas fa-trash wpda_icon_on_button"></i> Drop database
540 - </a>
582 + <a href="javascript:void(0)"
583 + id="disable_remote_database"
584 + style="display: none"
585 + title="Disable Remote Connection"
586 + class="button button-secondary wpda_tooltip"><i
587 + class="fas fa-ban wpda_icon_on_button"></i></a>
588 + <a href="javascript:void(0)"
589 + id="enable_remote_database"
590 + style="display: none"
591 + title="Enabled Remote Connection"
592 + class="button button-secondary wpda_tooltip"><i
593 + class="fas fa-check wpda_icon_on_button"></i></a>
594 + <a href="javascript:void(0)"
595 + id="remote_local_database_action"
596 + title="Drop Database"
597 + class="button button-secondary wpda_tooltip"><i
598 + class="fas fa-trash wpda_icon_on_button"></i></a>
541 599 </div>
542 600
543 - <div>
601 + <div
602 + id="remote_connection_is_disabled"
603 + style="display: none"
604 + >
605 + <label class="database_item_label"></label>
606 + <span style="color: red; line-height: 30px">
607 + This remote database connection is currently disabled.
608 + </span>
609 + </div>
610 +
611 + <div>
544 612 <label for="edit_remote_host" class="database_item_label">MySQL host:</label>
545 613 <input type="text"
546 614 name="edit_remote_host"
547 615 id="edit_remote_host">
@@ -662,15 +730,15 @@
662 730 ?>
663 731
664 732 <h3 class="wpda_db_title">
665 733 <?php
666 - echo __( 'Create local database', 'wp-data-access' );
734 + esc_html_e( 'Create local database', 'wp-data-access' );
667 735 ?>
668 736 </h3>
669 737
670 738 <?php
671 739 if ( !$this->user_can_create_db ) {
672 - echo __( 'You are not authorized to create local databases', 'wp-data-access' );
740 + esc_html_e( 'You are not authorized to create local databases', 'wp-data-access' );
673 741 } else {
674 742 ?>
675 743
676 744 <form method="post"
@@ -710,9 +778,9 @@
710 778 onsubmit="return createdb_validate_form_remote();">
711 779
712 780 <h3 class="wpda_db_title">
713 781 <?php
714 - echo __( 'Create remote database connection', 'wp-data-access' );
782 + esc_html_e( 'Create remote database connection', 'wp-data-access' );
715 783 ?>
716 784 </h3>
717 785
718 786 <div>
@@ -817,9 +885,9 @@
817 885 <a href="javascript:void(0)"
818 886 onclick="jQuery(this).closest('form').submit()"
819 887 class="button button-primary"><i
820 888 class="fas fa-cloud-upload wpda_icon_on_button"></i> <?php
821 - echo __( 'Save', 'wp-data-access' );
889 + esc_html_e( 'Save', 'wp-data-access' );
822 890 ?>
823 891 </a>
824 892 <a href="javascript:void(0)"
825 893 onclick="jQuery('#wpda_manage_databases').hide()"
@@ -824,9 +892,9 @@
824 892 <a href="javascript:void(0)"
825 893 onclick="jQuery('#wpda_manage_databases').hide()"
826 894 class="button button-secondary"><i
827 895 class="fas fa-times-circle wpda_icon_on_button"></i> <?php
828 - echo __( 'Cancel', 'wp-data-access' );
896 + esc_html_e( 'Cancel', 'wp-data-access' );
829 897 ?>
830 898 </a>
831 899 </div>
832 900
@@ -850,8 +918,27 @@
850 918
851 919 <?php
852 920 }
853 921
922 + private function toggle_database() {
923 + ?>
924 +
925 + <form id="wpda_form_toggle_db"
926 + method="post" action="?page=<?php
927 + echo esc_attr( $this->page );
928 + ?>"
929 + >
930 + <input type="hidden" name="database" id="toggle_database">
931 + <input type="hidden" name="action" value="toggle_db">
932 + <input type="hidden" name="disabled" id="toggle_database_value">
933 + <?php
934 + wp_nonce_field( 'wpda-toggle-db-from-data-explorer-' . WPDA::get_current_user_login(), '_wpnoncetoggledb', false );
935 + ?>
936 + </form>
937 +
938 + <?php
939 + }
940 +
854 941 private function js() {
855 942 ?>
856 943
857 944 <script>
@@ -1023,8 +1110,17 @@
1023 1110 jQuery("#edit_remote_ca_certificate").val(rdb.ssl_ca)
1024 1111 jQuery("#edit_remote_certificate_path").val(rdb.ssl_path)
1025 1112 jQuery("#edit_remote_specified_cipher").val(rdb.ssl_cipher)
1026 1113
1114 + if (rdb.disabled === true) {
1115 + jQuery("#enable_remote_database").show();
1116 + jQuery("#disable_remote_database").hide();
1117 + jQuery("#remote_connection_is_disabled").show();
1118 + } else {
1119 + jQuery("#disable_remote_database").show();
1120 + jQuery("#enable_remote_database").hide();
1121 + }
1122 +
1027 1123 if (rdb.ssl === "on") {
1028 1124 jQuery('#edit_remote_database_block_ssl').show();
1029 1125 } else {
1030 1126 jQuery('#edit_remote_database_block_ssl').hide();
@@ -1049,9 +1145,9 @@
1049 1145
1050 1146 jQuery("#manage_db_create_wp_user_access").on('click', function() {
1051 1147 const selectedDatabase = jQuery("#manage_db_selection").val()
1052 1148 wpda_dbinit_admin( selectedDatabase, '<?php
1053 - echo wp_create_nonce( 'wpda_dbinit_admin_' . WPDA::get_current_user_login() );
1149 + echo esc_attr( wp_create_nonce( 'wpda_dbinit_admin_' . WPDA::get_current_user_login() ) );
1054 1150 ?>' )
1055 1151 })
1056 1152
1057 1153 jQuery("#edit_local_database_action").on('click', function () {
@@ -1066,8 +1162,22 @@
1066 1162 jQuery("#drop_database").val(jQuery("#edit_remote_database").val())
1067 1163 jQuery("#wpda_form_drop_db").submit();
1068 1164 }
1069 1165 })
1166 +
1167 + jQuery("#disable_remote_database").on('click', function() {
1168 + if (confirm('Are you sure you want to disable this database?')) {
1169 + jQuery("#toggle_database").val(jQuery("#edit_remote_database").val())
1170 + jQuery("#toggle_database_value").val(true);
1171 + jQuery("#wpda_form_toggle_db").submit();
1172 + }
1173 + })
1174 +
1175 + jQuery("#enable_remote_database").on('click', function() {
1176 + jQuery("#toggle_database").val(jQuery("#edit_remote_database").val())
1177 + jQuery("#toggle_database_value").val(false);
1178 + jQuery("#wpda_form_toggle_db").submit();
1179 + })
1070 1180 });
1071 1181
1072 1182 var wpda_rdb = <?php
1073 1183 echo json_encode( $this->rdb );
@@ -1159,8 +1269,12 @@
1159 1269 color: #2271b1;
1160 1270 text-decoration: none;
1161 1271 font-weight: 700;
1162 1272 }
1273 +
1274 + #manage_db_create_wp_user_access:before {
1275 + line-height: 28px;
1276 + }
1163 1277 </style>
1164 1278
1165 1279 <?php
1166 1280 }
@@ -1165,4 +1279,6 @@
1165 1279 <?php
1166 1280 }
1167 1281
1168 1282 }
1283 +
1284 +// phpcs:enable WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing