WP-DBManager - Version 2.72

Version Description

N/A

Download this release

Release Info

Developer GamerZ
Plugin Icon WP-DBManager
Version 2.72
Comparing to
See all releases

Code changes from version 2.71 to 2.72

database-backup.php CHANGED
@@ -42,24 +42,24 @@ if(!empty($_POST['do'])) {
42
  if($gzip == 1) {
43
  $backup['filename'] = $backup['date'].'_-_'.DB_NAME.'.sql.gz';
44
  $backup['filepath'] = $backup['path'].'/'.$backup['filename'];
45
- $backup['command'] = $brace.$backup['mysqldumppath'].$brace.' --force --host="'.$backup['host'].'" --user="'.DB_USER.'" --password="'.$backup['password'].'"'.$backup['port'].$backup['sock'].$backup['charset'].' --add-drop-table --skip-lock-tables '.DB_NAME.' | gzip > '.$brace.$backup['filepath'].$brace;
46
  } else {
47
  $backup['filename'] = $backup['date'].'_-_'.DB_NAME.'.sql';
48
  $backup['filepath'] = $backup['path'].'/'.$backup['filename'];
49
- $backup['command'] = $brace.$backup['mysqldumppath'].$brace.' --force --host="'.$backup['host'].'" --user="'.DB_USER.'" --password="'.$backup['password'].'"'.$backup['port'].$backup['sock'].$backup['charset'].' --add-drop-table --skip-lock-tables '.DB_NAME.' > '.$brace.$backup['filepath'].$brace;
50
  }
51
  $error = execute_backup($backup['command']);
52
  if(!is_writable($backup['path'])) {
53
- $text = '<font color="red">'.sprintf(__('Database Failed To Backup On \'%s\'. Backup Folder Not Writable.', 'wp-dbmanager'), $current_date).'</font>';
54
  } elseif(filesize($backup['filepath']) == 0) {
55
  unlink($backup['filepath']);
56
- $text = '<font color="red">'.sprintf(__('Database Failed To Backup On \'%s\'. Backup File Size Is 0KB.', 'wp-dbmanager'), $current_date).'</font>';
57
  } elseif(!is_file($backup['filepath'])) {
58
- $text = '<font color="red">'.sprintf(__('Database Failed To Backup On \'%s\'. Invalid Backup File Path.', 'wp-dbmanager'), $current_date).'</font>';
59
  } elseif($error) {
60
- $text = '<font color="red">'.sprintf(__('Database Failed To Backup On \'%s\'.', 'wp-dbmanager'), $current_date).'</font>';
61
  } else {
62
- $text = '<font color="green">'.sprintf(__('Database Backed Up Successfully On \'%s\'.', 'wp-dbmanager'), $current_date).'</font>';
63
  }
64
  break;
65
  }
@@ -82,41 +82,56 @@ $stats_function_disabled = 0;
82
  <p>
83
  <?php _e('Checking Backup Folder', 'wp-dbmanager'); ?> <span dir="ltr">(<strong><?php echo stripslashes($backup['path']); ?></strong>)</span> ...<br />
84
  <?php
85
- if(@is_dir(stripslashes($backup['path']))) {
86
- echo '<font color="green">'.__('Backup folder exists', 'wp-dbmanager').'</font><br />';
87
  $status_count++;
88
  } else {
89
- echo '<font color="red">'.sprintf(__('Backup folder does NOT exist. Please create \'backup-db\' folder in \'%s\' folder and CHMOD it to \'777\' or change the location of the backup folder under DB Option.', 'wp-dbmanager'), WP_CONTENT_DIR).'</font><br />';
90
- }
91
- if(@is_writable(stripslashes($backup['path']))) {
92
- echo '<font color="green">'.__('Backup folder is writable', 'wp-dbmanager').'</font>';
93
- $status_count++;
94
- } else {
95
- echo '<font color="red">'.__('Backup folder is NOT writable. Please CHMOD it to \'777\'.', 'wp-dbmanager').'</font>';
 
 
 
 
 
96
  }
97
  ?>
98
  </p>
99
  <p>
100
  <?php
101
- if(@file_exists(stripslashes($backup['mysqldumppath']))) {
102
- echo __('Checking MYSQL Dump Path', 'wp-dbmanager').' <span dir="ltr">(<strong>'.stripslashes($backup['mysqldumppath']).'</strong>)</span> ...<br />';
103
- echo '<font color="green">'.__('MYSQL dump path exists.', 'wp-dbmanager').'</font>';
104
  $status_count++;
105
  } else {
106
- echo __('Checking MYSQL Dump Path', 'wp-dbmanager').' ...<br />';
107
- echo '<font color="red">'.__('MYSQL dump path does NOT exist. Please check your mysqldump path under DB Options. If uncertain, contact your server administrator.', 'wp-dbmanager').'</font>';
 
 
 
 
 
 
108
  }
109
  ?>
110
  </p>
111
  <p>
112
  <?php
113
- if(@file_exists(stripslashes($backup['mysqlpath']))) {
114
- echo __('Checking MYSQL Path', 'wp-dbmanager').' <span dir="ltr">(<strong>'.stripslashes($backup['mysqlpath']).'</strong>)</span> ...<br />';
115
- echo '<font color="green">'.__('MYSQL path exists.', 'wp-dbmanager').'</font>';
116
  $status_count++;
117
  } else {
118
- echo __('Checking MYSQL Path', 'wp-dbmanager').' ...<br />';
119
- echo '<font color="red">'.__('MYSQL path does NOT exist. Please check your mysql path under DB Options. If uncertain, contact your server administrator.', 'wp-dbmanager').'</font>';
 
 
 
 
 
 
120
  }
121
  ?>
122
  </p>
@@ -124,22 +139,22 @@ $stats_function_disabled = 0;
124
  <?php _e('Checking PHP Functions', 'wp-dbmanager'); ?> <span dir="ltr">(<strong>passthru()</strong>, <strong>system()</strong> <?php _e('and', 'wp-dbmanager'); ?> <strong>exec()</strong>)</span> ...<br />
125
  <?php
126
  if(function_exists('passthru')) {
127
- echo '<font color="green"><span dir="ltr">passthru()</span> '.__('enabled', 'wp-dbmanager').'.</font><br />';
128
  $status_count++;
129
  } else {
130
- echo '<font color="red"><span dir="ltr">passthru()</span> '.__('disabled', 'wp-dbmanager').'.</font><br />';
131
  $stats_function_disabled++;
132
  }
133
  if(function_exists('system')) {
134
- echo '<font color="green"><span dir="ltr">system()</span> '.__('enabled', 'wp-dbmanager').'.</font><br />';
135
  } else {
136
- echo '<font color="red"><span dir="ltr">system()</span> '.__('disabled', 'wp-dbmanager').'.</font><br />';
137
  $stats_function_disabled++;
138
  }
139
  if(function_exists('exec')) {
140
- echo '<font color="green"><span dir="ltr">exec()</span> '.__('enabled', 'wp-dbmanager').'.</font>';
141
  } else {
142
- echo '<font color="red"><span dir="ltr">exec()</span> '.__('disabled', 'wp-dbmanager').'.</font>';
143
  $stats_function_disabled++;
144
  }
145
  ?>
@@ -147,11 +162,11 @@ $stats_function_disabled = 0;
147
  <p>
148
  <?php
149
  if($status_count == 5) {
150
- echo '<strong><font color="green">'.__('Excellent. You Are Good To Go.', 'wp-dbmanager').'</font></strong>';
151
  } else if($stats_function_disabled == 3) {
152
- echo '<strong><font color="red">'.__('I\'m sorry, your server administrator has disabled passthru(), system() and exec(), thus you cannot use this backup script. You may consider using the default WordPress database backup script instead.', 'wp-dbmanager').'</font></strong>';
153
  } else {
154
- echo '<strong><font color="red">'.__('Please Rectify The Error Highlighted In Red Before Proceeding On.', 'wp-dbmanager').'</font></strong>';
155
  }
156
  ?>
157
  </p>
42
  if($gzip == 1) {
43
  $backup['filename'] = $backup['date'].'_-_'.DB_NAME.'.sql.gz';
44
  $backup['filepath'] = $backup['path'].'/'.$backup['filename'];
45
+ $backup['command'] = escapeshellcmd( $brace.$backup['mysqldumppath'].$brace.' --force --host="'.$backup['host'].'" --user="'.DB_USER.'" --password="'.$backup['password'].'"'.$backup['port'].$backup['sock'].$backup['charset'].' --add-drop-table --skip-lock-tables '.DB_NAME ).' | gzip > '.escapeshellcmd( $brace.$backup['filepath'].$brace );
46
  } else {
47
  $backup['filename'] = $backup['date'].'_-_'.DB_NAME.'.sql';
48
  $backup['filepath'] = $backup['path'].'/'.$backup['filename'];
49
+ $backup['command'] = escapeshellcmd( $brace.$backup['mysqldumppath'].$brace.' --force --host="'.$backup['host'].'" --user="'.DB_USER.'" --password="'.$backup['password'].'"'.$backup['port'].$backup['sock'].$backup['charset'].' --add-drop-table --skip-lock-tables '.DB_NAME ).' > '.escapeshellcmd( $brace.$backup['filepath'].$brace );
50
  }
51
  $error = execute_backup($backup['command']);
52
  if(!is_writable($backup['path'])) {
53
+ $text = '<p style="color: red;">'.sprintf(__('Database Failed To Backup On \'%s\'. Backup Folder Not Writable.', 'wp-dbmanager'), $current_date).'</p>';
54
  } elseif(filesize($backup['filepath']) == 0) {
55
  unlink($backup['filepath']);
56
+ $text = '<p style="color: red;">'.sprintf(__('Database Failed To Backup On \'%s\'. Backup File Size Is 0KB.', 'wp-dbmanager'), $current_date).'</p>';
57
  } elseif(!is_file($backup['filepath'])) {
58
+ $text = '<p style="color: red;">'.sprintf(__('Database Failed To Backup On \'%s\'. Invalid Backup File Path.', 'wp-dbmanager'), $current_date).'</p>';
59
  } elseif($error) {
60
+ $text = '<p style="color: red;">'.sprintf(__('Database Failed To Backup On \'%s\'.', 'wp-dbmanager'), $current_date).'</p>';
61
  } else {
62
+ $text = '<p style="color: green;">'.sprintf(__('Database Backed Up Successfully On \'%s\'.', 'wp-dbmanager'), $current_date).'</p>';
63
  }
64
  break;
65
  }
82
  <p>
83
  <?php _e('Checking Backup Folder', 'wp-dbmanager'); ?> <span dir="ltr">(<strong><?php echo stripslashes($backup['path']); ?></strong>)</span> ...<br />
84
  <?php
85
+ if( realpath( $backup['path'] ) === false ) {
86
+ echo '<p style="color: red;">' . sprintf( __( '%s is not a valid backup path', 'wp-dbmanager' ), stripslashes( $backup['path'] ) ) . '</p>';
87
  $status_count++;
88
  } else {
89
+ if (@is_dir(stripslashes($backup['path']))) {
90
+ echo '<p style="color: green;">' . __('Backup folder exists', 'wp-dbmanager') . '</p>';
91
+ $status_count++;
92
+ } else {
93
+ echo '<p style="color: red;">' . sprintf(__('Backup folder does NOT exist. Please create \'backup-db\' folder in \'%s\' folder and CHMOD it to \'777\' or change the location of the backup folder under DB Option.', 'wp-dbmanager'), WP_CONTENT_DIR) . '</p>';
94
+ }
95
+ if (@is_writable(stripslashes($backup['path']))) {
96
+ echo '<p style="color: green;">' . __('Backup folder is writable', 'wp-dbmanager') . '</p>';
97
+ $status_count++;
98
+ } else {
99
+ echo '<p style="color: red;">' . __('Backup folder is NOT writable. Please CHMOD it to \'777\'.', 'wp-dbmanager') . '</p>';
100
+ }
101
  }
102
  ?>
103
  </p>
104
  <p>
105
  <?php
106
+ if( dbmanager_is_valid_path( $backup['mysqldumppath'] ) === 0 ) {
107
+ echo '<p style="color: red;">' . sprintf( __( '%s is not a valid backup mysqldump path', 'wp-dbmanager' ), stripslashes( $backup['mysqldumppath'] ) ) . '</p>';
 
108
  $status_count++;
109
  } else {
110
+ if (@file_exists(stripslashes($backup['mysqldumppath']))) {
111
+ echo __('Checking MYSQL Dump Path', 'wp-dbmanager') . ' <span dir="ltr">(<strong>' . stripslashes($backup['mysqldumppath']) . '</strong>)</span> ...<br />';
112
+ echo '<p style="color: green;">' . __('MYSQL dump path exists.', 'wp-dbmanager') . '</p>';
113
+ $status_count++;
114
+ } else {
115
+ echo __('Checking MYSQL Dump Path', 'wp-dbmanager') . ' ...<br />';
116
+ echo '<p style="color: red;">' . __('MYSQL dump path does NOT exist. Please check your mysqldump path under DB Options. If uncertain, contact your server administrator.', 'wp-dbmanager') . '</p>';
117
+ }
118
  }
119
  ?>
120
  </p>
121
  <p>
122
  <?php
123
+ if( dbmanager_is_valid_path( $backup['mysqlpath'] ) === 0 ) {
124
+ echo '<p style="color: red;">' . sprintf( __( '%s is not a valid backup mysql path', 'wp-dbmanager' ), stripslashes( $backup['mysqlpath'] ) ) . '</p>';
 
125
  $status_count++;
126
  } else {
127
+ if (@file_exists(stripslashes($backup['mysqlpath']))) {
128
+ echo __('Checking MYSQL Path', 'wp-dbmanager') . ' <span dir="ltr">(<strong>' . stripslashes($backup['mysqlpath']) . '</strong>)</span> ...<br />';
129
+ echo '<p style="color: green;">' . __('MYSQL path exists.', 'wp-dbmanager') . '</p>';
130
+ $status_count++;
131
+ } else {
132
+ echo __('Checking MYSQL Path', 'wp-dbmanager') . ' ...<br />';
133
+ echo '<p style="color: red;">' . __('MYSQL path does NOT exist. Please check your mysql path under DB Options. If uncertain, contact your server administrator.', 'wp-dbmanager') . '</p>';
134
+ }
135
  }
136
  ?>
137
  </p>
139
  <?php _e('Checking PHP Functions', 'wp-dbmanager'); ?> <span dir="ltr">(<strong>passthru()</strong>, <strong>system()</strong> <?php _e('and', 'wp-dbmanager'); ?> <strong>exec()</strong>)</span> ...<br />
140
  <?php
141
  if(function_exists('passthru')) {
142
+ echo '<p style="color: green;"><span dir="ltr">passthru()</span> '.__('enabled', 'wp-dbmanager').'.</p>';
143
  $status_count++;
144
  } else {
145
+ echo '<p style="color: red;"><span dir="ltr">passthru()</span> '.__('disabled', 'wp-dbmanager').'.</p>';
146
  $stats_function_disabled++;
147
  }
148
  if(function_exists('system')) {
149
+ echo '<p style="color: green;"><span dir="ltr">system()</span> '.__('enabled', 'wp-dbmanager').'.</p>';
150
  } else {
151
+ echo '<p style="color: red;"><span dir="ltr">system()</span> '.__('disabled', 'wp-dbmanager').'.</p>';
152
  $stats_function_disabled++;
153
  }
154
  if(function_exists('exec')) {
155
+ echo '<p style="color: green;"><span dir="ltr">exec()</span> '.__('enabled', 'wp-dbmanager').'.</p>';
156
  } else {
157
+ echo '<p style="color: red;"><span dir="ltr">exec()</span> '.__('disabled', 'wp-dbmanager').'.</p>';
158
  $stats_function_disabled++;
159
  }
160
  ?>
162
  <p>
163
  <?php
164
  if($status_count == 5) {
165
+ echo '<strong><p style="color: green;">'.__('Excellent. You Are Good To Go.', 'wp-dbmanager').'</p></strong>';
166
  } else if($stats_function_disabled == 3) {
167
+ echo '<strong><p style="color: red;">'.__('I\'m sorry, your server administrator has disabled passthru(), system() and exec(), thus you cannot use this backup script. You may consider using the default WordPress database backup script instead.', 'wp-dbmanager').'</p></strong>';
168
  } else {
169
+ echo '<strong><p style="color: red;">'.__('Please Rectify The Error Highlighted In Red Before Proceeding On.', 'wp-dbmanager').'</p></strong>';
170
  }
171
  ?>
172
  </p>
database-empty.php CHANGED
@@ -37,18 +37,18 @@ if(!empty($_POST['do'])) {
37
  }
38
  }
39
  } else {
40
- $text = '<font color="red">'.__('No Tables Selected.', 'wp-dbmanager').'</font>';
41
  }
42
  $drop_tables = substr($drop_tables, 2);
43
  if(!empty($empty_tables)) {
44
  foreach($empty_tables as $empty_table) {
45
  $empty_query = $wpdb->query("TRUNCATE $empty_table");
46
- $text .= '<font color="green">'.sprintf(__('Table \'%s\' Emptied', 'wp-dbmanager'), $empty_table).'</font><br />';
47
  }
48
  }
49
  if(!empty($drop_tables)) {
50
  $drop_query = $wpdb->query("DROP TABLE $drop_tables");
51
- $text = '<font color="green">'.sprintf(__('Table(s) \'%s\' Dropped', 'wp-dbmanager'), $drop_tables).'</font>';
52
  }
53
  break;
54
  }
37
  }
38
  }
39
  } else {
40
+ $text = '<p style="color: red;">'.__('No Tables Selected.', 'wp-dbmanager').'</p>';
41
  }
42
  $drop_tables = substr($drop_tables, 2);
43
  if(!empty($empty_tables)) {
44
  foreach($empty_tables as $empty_table) {
45
  $empty_query = $wpdb->query("TRUNCATE $empty_table");
46
+ $text .= '<p style="color: green;">'.sprintf(__('Table \'%s\' Emptied', 'wp-dbmanager'), $empty_table).'</p>';
47
  }
48
  }
49
  if(!empty($drop_tables)) {
50
  $drop_query = $wpdb->query("DROP TABLE $drop_tables");
51
+ $text = '<p style="color: green;">'.sprintf(__('Table(s) \'%s\' Dropped', 'wp-dbmanager'), $drop_tables).'</p>';
52
  }
53
  break;
54
  }
database-manage.php CHANGED
@@ -44,18 +44,24 @@ if( !empty( $_POST['do'] ) ) {
44
  }
45
  }
46
  if(stristr($database_file, '.gz')) {
47
- $backup['command'] = 'gunzip < '.$brace.$backup['path'].'/'.$database_file.$brace.' | '.$brace.$backup['mysqlpath'].$brace.' --host="'.$backup['host'].'" --user="'.DB_USER.'" --password="'.$backup['password'].'"'.$backup['port'].$backup['sock'].$backup['charset'].' '.DB_NAME;
48
  } else {
49
- $backup['command'] = $brace.$backup['mysqlpath'].$brace.' --host="'.$backup['host'].'" --user="'.DB_USER.'" --password="'.$backup['password'].'"'.$backup['port'].$backup['sock'].$backup['charset'].' '.DB_NAME.' < '.$brace.$backup['path'].'/'.$database_file.$brace;
 
 
 
 
 
 
 
50
  }
51
- passthru($backup['command'], $error);
52
  if($error) {
53
- $text = '<font color="red">'.sprintf(__('Database On \'%s\' Failed To Restore', 'wp-dbmanager'), $nice_file_date).'</font>';
54
  } else {
55
- $text = '<font color="green">'.sprintf(__('Database On \'%s\' Restored Successfully', 'wp-dbmanager'), $nice_file_date).'</font>';
56
  }
57
  } else {
58
- $text = '<font color="red">'.__('No Backup Database File Selected', 'wp-dbmanager').'</font>';
59
  }
60
  break;
61
  case __('E-Mail', 'wp-dbmanager'):
@@ -63,38 +69,38 @@ if( !empty( $_POST['do'] ) ) {
63
  $to = ( !empty( $_POST['email_to'] ) ? sanitize_email( $_POST['email_to'] ) : get_option( 'admin_email' ) );
64
 
65
  if( dbmanager_email_backup( $to, $backup['path'].'/'.$database_file ) ) {
66
- $text .= '<font color="green">'.sprintf(__('Database Backup File For \'%s\' Successfully E-Mailed To \'%s\'', 'wp-dbmanager'), $nice_file_date, $to).'</font><br />';
67
  } else {
68
- $text = '<font color="red">'.sprintf(__('Unable To E-Mail Database Backup File For \'%s\' To \'%s\'', 'wp-dbmanager'), $nice_file_date, $to).'</font>';
69
  }
70
  } else {
71
- $text = '<font color="red">'.__('No Backup Database File Selected', 'wp-dbmanager').'</font>';
72
  }
73
  break;
74
  case __('Download', 'wp-dbmanager'):
75
  if(empty($database_file)) {
76
- $text = '<font color="red">'.__('No Backup Database File Selected', 'wp-dbmanager').'</font>';
77
  }
78
  break;
79
  case __('Delete', 'wp-dbmanager'):
80
  if(!empty($database_file)) {
81
  if(is_file($backup['path'].'/'.$database_file)) {
82
  if(!unlink($backup['path'].'/'.$database_file)) {
83
- $text .= '<font color="red">'.sprintf(__('Unable To Delete Database Backup File On \'%s\'', 'wp-dbmanager'), $nice_file_date).'</font><br />';
84
  } else {
85
- $text .= '<font color="green">'.sprintf(__('Database Backup File On \'%s\' Deleted Successfully', 'wp-dbmanager'), $nice_file_date).'</font><br />';
86
  }
87
  } else {
88
- $text = '<font color="red">'.sprintf(__('Invalid Database Backup File On \'%s\'', 'wp-dbmanager'), $nice_file_date).'</font>';
89
  }
90
  } else {
91
- $text = '<font color="red">'.__('No Backup Database File Selected', 'wp-dbmanager').'</font>';
92
  }
93
  break;
94
  }
95
  }
96
  ?>
97
- <?php if(!empty($text)) { echo '<!-- Last Action --><div id="message" class="updated fade"><p>'.$text.'</p></div>'; } ?>
98
  <!-- Manage Backup Database -->
99
  <form method="post" action="<?php echo admin_url('admin.php?page='.plugin_basename(__FILE__)); ?>">
100
  <?php wp_nonce_field('wp-dbmanager_manage'); ?>
44
  }
45
  }
46
  if(stristr($database_file, '.gz')) {
47
+ $backup['command'] = 'gunzip < '.escapeshellcmd( $brace.$backup['path'].'/'.$database_file.$brace ).' | '.escapeshellcmd( $brace.$backup['mysqlpath'].$brace.' --host="'.$backup['host'].'" --user="'.DB_USER.'" --password="'.$backup['password'].'"'.$backup['port'].$backup['sock'].$backup['charset'].' '.DB_NAME );
48
  } else {
49
+ $backup['command'] = escapeshellcmd( $brace.$backup['mysqlpath'].$brace.' --host="'.$backup['host'].'" --user="'.DB_USER.'" --password="'.$backup['password'].'"'.$backup['port'].$backup['sock'].$backup['charset'].' '.DB_NAME ).' < '.escapeshellcmd( $brace.$backup['path'].'/'.$database_file.$brace );
50
+ }
51
+ if( realpath( $backup['path'] ) === false ) {
52
+ $text = '<p style="color: red;">' . sprintf(__('%s is not a valid backup path', 'wp-dbmanager'), stripslashes( $backup['path'] ) ) . '</p>';
53
+ } else if( dbmanager_is_valid_path( $backup['mysqlpath'] ) === 0 ) {
54
+ $text = '<p style="color: red;">' . sprintf(__('%s is not a valid mysql path', 'wp-dbmanager'), stripslashes( $backup['mysqlpath'] ) ) . '</p>';
55
+ } else {
56
+ passthru( $backup['command'], $error );
57
  }
 
58
  if($error) {
59
+ $text = '<p style="color: red;">'.sprintf(__('Database On \'%s\' Failed To Restore', 'wp-dbmanager'), $nice_file_date).'</p>';
60
  } else {
61
+ $text = '<p style="color: green;">'.sprintf(__('Database On \'%s\' Restored Successfully', 'wp-dbmanager'), $nice_file_date).'</p>';
62
  }
63
  } else {
64
+ $text = '<p style="color: red;">'.__('No Backup Database File Selected', 'wp-dbmanager').'</p>';
65
  }
66
  break;
67
  case __('E-Mail', 'wp-dbmanager'):
69
  $to = ( !empty( $_POST['email_to'] ) ? sanitize_email( $_POST['email_to'] ) : get_option( 'admin_email' ) );
70
 
71
  if( dbmanager_email_backup( $to, $backup['path'].'/'.$database_file ) ) {
72
+ $text .= '<p style="color: green;">'.sprintf(__('Database Backup File For \'%s\' Successfully E-Mailed To \'%s\'', 'wp-dbmanager'), $nice_file_date, $to).'</p>';
73
  } else {
74
+ $text = '<p style="color: red;">'.sprintf(__('Unable To E-Mail Database Backup File For \'%s\' To \'%s\'', 'wp-dbmanager'), $nice_file_date, $to).'</p>';
75
  }
76
  } else {
77
+ $text = '<p style="color: red;">'.__('No Backup Database File Selected', 'wp-dbmanager').'</p>';
78
  }
79
  break;
80
  case __('Download', 'wp-dbmanager'):
81
  if(empty($database_file)) {
82
+ $text = '<p style="color: red;">'.__('No Backup Database File Selected', 'wp-dbmanager').'</p>';
83
  }
84
  break;
85
  case __('Delete', 'wp-dbmanager'):
86
  if(!empty($database_file)) {
87
  if(is_file($backup['path'].'/'.$database_file)) {
88
  if(!unlink($backup['path'].'/'.$database_file)) {
89
+ $text .= '<p style="color: red;">'.sprintf(__('Unable To Delete Database Backup File On \'%s\'', 'wp-dbmanager'), $nice_file_date).'</p>';
90
  } else {
91
+ $text .= '<p style="color: green;">'.sprintf(__('Database Backup File On \'%s\' Deleted Successfully', 'wp-dbmanager'), $nice_file_date).'</p>';
92
  }
93
  } else {
94
+ $text = '<p style="color: red;">'.sprintf(__('Invalid Database Backup File On \'%s\'', 'wp-dbmanager'), $nice_file_date).'</p>';
95
  }
96
  } else {
97
+ $text = '<p style="color: red;">'.__('No Backup Database File Selected', 'wp-dbmanager').'</p>';
98
  }
99
  break;
100
  }
101
  }
102
  ?>
103
+ <?php if(!empty($text)) { echo '<!-- Last Action --><div id="message" class="updated">'.$text.'</div>'; } ?>
104
  <!-- Manage Backup Database -->
105
  <form method="post" action="<?php echo admin_url('admin.php?page='.plugin_basename(__FILE__)); ?>">
106
  <?php wp_nonce_field('wp-dbmanager_manage'); ?>
database-optimize.php CHANGED
@@ -26,16 +26,16 @@ if(!empty($_POST['do'])) {
26
  }
27
  }
28
  } else {
29
- $text = '<font color="red">'.__('No Tables Selected', 'wp-dbmanager').'</font>';
30
  }
31
  $selected_tables = substr($tables_string, 3);
32
  $selected_tables .= '`';
33
  if(!empty($selected_tables)) {
34
  $optimize2 = $wpdb->query("OPTIMIZE TABLE $selected_tables");
35
  if(!$optimize2) {
36
- $text = '<font color="red">'.sprintf(__('Table(s) \'%s\' NOT Optimized', 'wp-dbmanager'), str_replace('`', '', $selected_tables)).'</font>';
37
  } else {
38
- $text = '<font color="green">'.sprintf(__('Table(s) \'%s\' Optimized', 'wp-dbmanager'), str_replace('`', '', $selected_tables)).'</font>';
39
  }
40
  }
41
  break;
26
  }
27
  }
28
  } else {
29
+ $text = '<p style="color: red;">'.__('No Tables Selected', 'wp-dbmanager').'</p>';
30
  }
31
  $selected_tables = substr($tables_string, 3);
32
  $selected_tables .= '`';
33
  if(!empty($selected_tables)) {
34
  $optimize2 = $wpdb->query("OPTIMIZE TABLE $selected_tables");
35
  if(!$optimize2) {
36
+ $text = '<p style="color: red;">'.sprintf(__('Table(s) \'%s\' NOT Optimized', 'wp-dbmanager'), str_replace('`', '', $selected_tables)).'</p>';
37
  } else {
38
+ $text = '<p style="color: green;">'.sprintf(__('Table(s) \'%s\' Optimized', 'wp-dbmanager'), str_replace('`', '', $selected_tables)).'</p>';
39
  }
40
  }
41
  break;
database-repair.php CHANGED
@@ -27,16 +27,16 @@ if(!empty($_POST['do'])) {
27
  }
28
  }
29
  } else {
30
- $text = '<font color="red">'.__('No Tables Selected', 'wp-dbmanager').'</font>';
31
  }
32
  $selected_tables = substr($tables_string, 2);
33
  $selected_tables .= '`';
34
  if(!empty($selected_tables)) {
35
  $repair2 = $wpdb->query("REPAIR TABLE $selected_tables");
36
  if(!$repair2) {
37
- $text = '<font color="red">'.sprintf(__('Table(s) \'%s\' NOT Repaired', 'wp-dbmanager'), str_replace('`', '', $selected_tables)).'</font>';
38
  } else {
39
- $text = '<font color="green">'.sprintf(__('Table(s) \'%s\' Repaired', 'wp-dbmanager'), str_replace('`', '', $selected_tables)).'</font>';
40
  }
41
  }
42
  break;
27
  }
28
  }
29
  } else {
30
+ $text = '<p style="color: red;">'.__('No Tables Selected', 'wp-dbmanager').'</p>';
31
  }
32
  $selected_tables = substr($tables_string, 2);
33
  $selected_tables .= '`';
34
  if(!empty($selected_tables)) {
35
  $repair2 = $wpdb->query("REPAIR TABLE $selected_tables");
36
  if(!$repair2) {
37
+ $text = '<p style="color: red;">'.sprintf(__('Table(s) \'%s\' NOT Repaired', 'wp-dbmanager'), str_replace('`', '', $selected_tables)).'</p>';
38
  } else {
39
+ $text = '<p style="color: green;">'.sprintf(__('Table(s) \'%s\' Repaired', 'wp-dbmanager'), str_replace('`', '', $selected_tables)).'</p>';
40
  }
41
  }
42
  break;
database-run.php CHANGED
@@ -37,27 +37,30 @@ if(!empty($_POST['do'])) {
37
  }
38
  }
39
  if($sql_queries) {
40
- foreach($sql_queries as $sql_query) {
41
- if (preg_match("/^\\s*(insert|update|replace|delete|create|alter) /i",$sql_query)) {
42
- $run_query = $wpdb->query($sql_query);
43
- if(!$run_query) {
44
- $text .= "<span dir=\"ltr\"><font color=\"red\">$sql_query</font></span><br />";
 
 
 
 
 
 
45
  } else {
46
  $successquery++;
47
- $text .= "<span dir=\"ltr\"><font color=\"green\">$sql_query</font></span><br />";
48
  }
49
  $totalquerycount++;
50
- } elseif (preg_match("/^\\s*(select|drop|show|grant) /i",$sql_query)) {
51
- $text .= "<span dir=\"ltr\"><font color=\"red\">$sql_query</font></span><br />";
52
- $totalquerycount++;
53
  }
54
  }
55
- $text .= '<font color="blue">'.number_format_i18n($successquery).'/'.number_format_i18n($totalquerycount).' '.__('Query(s) Executed Successfully', 'wp-dbmanager').'</font>';
56
  } else {
57
- $text = '<font color="red">'.__('Empty Query', 'wp-dbmanager').'</font>';
58
  }
59
  } else {
60
- $text = '<font color="red">'.__('Empty Query', 'wp-dbmanager').'</font>';
61
  }
62
  break;
63
  }
@@ -72,7 +75,7 @@ if(!empty($_POST['do'])) {
72
  <br style="clear" />
73
  <div>
74
  <strong><?php _e('Seperate Multiple Queries With A New Line', 'wp-dbmanager'); ?></strong><br />
75
- <font color="green"><?php _e('Use Only INSERT, UPDATE, REPLACE, DELETE, CREATE and ALTER statements.', 'wp-dbmanager'); ?></font>
76
  </div>
77
  <table class="form-table">
78
  <tr>
37
  }
38
  }
39
  if($sql_queries) {
40
+ foreach( $sql_queries as $sql_query ) {
41
+ if ( preg_match( "/LOAD_FILE/i", $sql_query ) ) {
42
+ $text .= "<p style=\"color: red;\">$sql_query</p>";
43
+ $totalquerycount++;
44
+ } elseif( preg_match( "/^\\s*(select|drop|show|grant) /i", $sql_query ) ) {
45
+ $text .= "<p style=\"color: red;\">$sql_query</p>";
46
+ $totalquerycount++;
47
+ } else if ( preg_match( "/^\\s*(insert|update|replace|delete|create|alter) /i", $sql_query ) ) {
48
+ $run_query = $wpdb->query( $sql_query );
49
+ if( ! $run_query ) {
50
+ $text .= "<p style=\"color: red;\">$sql_query</p>";
51
  } else {
52
  $successquery++;
53
+ $text .= "<p style=\"color: green;\">$sql_query</p>";
54
  }
55
  $totalquerycount++;
 
 
 
56
  }
57
  }
58
+ $text .= '<p style="color: blue;">'.number_format_i18n($successquery).'/'.number_format_i18n($totalquerycount).' '.__('Query(s) Executed Successfully', 'wp-dbmanager').'</p>';
59
  } else {
60
+ $text = '<p style="color: red;">'.__('Empty Query', 'wp-dbmanager').'</p>';
61
  }
62
  } else {
63
+ $text = '<p style="color: red;">'.__('Empty Query', 'wp-dbmanager').'</p>';
64
  }
65
  break;
66
  }
75
  <br style="clear" />
76
  <div>
77
  <strong><?php _e('Seperate Multiple Queries With A New Line', 'wp-dbmanager'); ?></strong><br />
78
+ <p style="color: green;"><?php _e('Use Only INSERT, UPDATE, REPLACE, DELETE, CREATE and ALTER statements.', 'wp-dbmanager'); ?></p>
79
  </div>
80
  <table class="form-table">
81
  <tr>
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: http://lesterchan.net/site/donation/
4
  Tags: database, manage, wp-dbmanager, manager, table, optimize, backup, queries, query, drop, empty, tables, table, run, repair, cron, schedule, scheduling, automatic
5
  Requires at least: 3.9
6
  Tested up to: 4.0
7
- Stable tag: 2.71
8
 
9
  Manages your WordPress database.
10
 
@@ -26,7 +26,19 @@ Allows you to optimize database, repair database, backup database, restore datab
26
  = Donations =
27
  * I spent most of my free time creating, updating, maintaining and supporting these plugins, if you really love my plugins and could spare me a couple of bucks, I will really appericiate it. If not feel free to use it without any obligations.
28
 
 
 
 
 
 
 
29
  == Changelog ==
 
 
 
 
 
 
30
  = Version 2.71 =
31
  * NEW: Bump to 4.0
32
 
@@ -51,7 +63,7 @@ Allows you to optimize database, repair database, backup database, restore datab
51
  * NEW: Added nonce To All Forms For Added Security
52
 
53
  = Version 2.61 (30-04-2011) =
54
- * FIXED: Checks File Extension And Sanitise File Name That Is Pass Through The URL When Downloading Database File. Props to [Joakim Jardenberg](http://jardenberg.se "Joakim Jardenberg"), [Jonas Nordstram](http://jonasnordstrom.se "Jonas Nordstr�m"), [Andreas Viklund](http://andreasviklund.com/ "Andreas Viklund")
55
 
56
  = Version 2.60 (01-12-2009) =
57
  * FIXED: Bug In Cron Backup On Windows Server
@@ -177,7 +189,7 @@ N/A
177
  = My database is not backed up / My backup file is 0Kb =
178
  * Ensure that your host allows you to access mysqldump. You can try to narrow the problem by Debugging via SSH:
179
  1. In `wp-dbmanager.php`
180
- 2. Find `check_backup_files();` on line 243
181
  3. Add below it `echo $command;`
182
  4. Go to `WP-Admin -> Database -> Backup`
183
  5. Click `Backup`
@@ -185,7 +197,6 @@ N/A
185
  7. Copy that line than run it in SSH
186
  8. If you need help on SSH contact your host or google for more info
187
 
188
-
189
  = What is the difference between WP-DBManager and WP-DB-Backup? =
190
  * WP-DBManager uses `mysqldump` application to generate the backup and `mysql` application to restore them via shell.
191
  * WP-DB-Backup uses PHP to generate the backup. In some cases WP-DB-Backup will work better for you because it requires less permissions. Not all host allows you to access mysqldump/mysql directly via shell.
4
  Tags: database, manage, wp-dbmanager, manager, table, optimize, backup, queries, query, drop, empty, tables, table, run, repair, cron, schedule, scheduling, automatic
5
  Requires at least: 3.9
6
  Tested up to: 4.0
7
+ Stable tag: 2.72
8
 
9
  Manages your WordPress database.
10
 
26
  = Donations =
27
  * I spent most of my free time creating, updating, maintaining and supporting these plugins, if you really love my plugins and could spare me a couple of bucks, I will really appericiate it. If not feel free to use it without any obligations.
28
 
29
+ = Disclaimer =
30
+ * Note that this plugin passes your datababase password via --password in the command line of mysqldump. This is convenient but as a trade off, it is insecure.
31
+ * On some systems, your password becomes visible to system status programs such as ps that may be invoked by other users to display command lines. MySQL clients typically overwrite the command-line password argument with zeros during their initialization sequence. However, there is still a brief interval during which the value is visible. Also, on some systems this overwriting strategy is ineffective and the password remains visible to ps. Source: [End-User Guidelines for Password Security](http://dev.mysql.com/doc/refman/5.5/en/password-security-user.html)
32
+ * If this is a concern to you, I recommend another database backup plugin called [WP-DB-Backup](https://wordpress.org/plugins/wp-db-backup/)
33
+ * To know about the difference between WP-DBManager and WP-DB-backup, checkout __What is the difference between WP-DBManager and WP-DB-Backup?__ in the [FAQ section](https://wordpress.org/plugins/wp-dbmanager/faq/).
34
+
35
  == Changelog ==
36
+ = Version 2.72 =
37
+ * FIXED: Uses escapeshellcmd() to escape shell commands. Props Larry W. Cashdollari.
38
+ * FIXED: Do not allow LOAD_FILE to be run. Props Larry W. Cashdollari.
39
+ * FIXED: Uses dbmanager_is_valid_path() to check for mysql and mysqldump path. Fixes arbitrary command injection using backup path. Props Larry W. Cashdollari.
40
+ * FIXED: Uses realpath() to check for backup path. Fixes arbitrary command injection using backup path. Props Larry W. Cashdollari.
41
+
42
  = Version 2.71 =
43
  * NEW: Bump to 4.0
44
 
63
  * NEW: Added nonce To All Forms For Added Security
64
 
65
  = Version 2.61 (30-04-2011) =
66
+ * FIXED: Checks File Extension And Sanitise File Name That Is Pass Through The URL When Downloading Database File. Props to [Joakim Jardenberg](http://jardenberg.se "Joakim Jardenberg"), [Jonas Nordstram](http://jonasnordstrom.se "Jonas Nordstram"), [Andreas Viklund](http://andreasviklund.com/ "Andreas Viklund")
67
 
68
  = Version 2.60 (01-12-2009) =
69
  * FIXED: Bug In Cron Backup On Windows Server
189
  = My database is not backed up / My backup file is 0Kb =
190
  * Ensure that your host allows you to access mysqldump. You can try to narrow the problem by Debugging via SSH:
191
  1. In `wp-dbmanager.php`
192
+ 2. Find `check_backup_files();` on line 210
193
  3. Add below it `echo $command;`
194
  4. Go to `WP-Admin -> Database -> Backup`
195
  5. Click `Backup`
197
  7. Copy that line than run it in SSH
198
  8. If you need help on SSH contact your host or google for more info
199
 
 
200
  = What is the difference between WP-DBManager and WP-DB-Backup? =
201
  * WP-DBManager uses `mysqldump` application to generate the backup and `mysql` application to restore them via shell.
202
  * WP-DB-Backup uses PHP to generate the backup. In some cases WP-DB-Backup will work better for you because it requires less permissions. Not all host allows you to access mysqldump/mysql directly via shell.
wp-dbmanager.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: WP-DBManager
4
  Plugin URI: http://lesterchan.net/portfolio/programming/php/
5
  Description: Manages your WordPress database. Allows you to optimize database, repair database, backup database, restore database, delete backup database , drop/empty tables and run selected queries. Supports automatic scheduling of backing up, optimizing and repairing of database.
6
- Version: 2.71
7
  Author: Lester 'GaMerZ' Chan
8
  Author URI: http://lesterchan.net
9
  Text Domain: wp-dbmanager
@@ -60,11 +60,9 @@ add_action('dbmanager_cron_backup', 'cron_dbmanager_backup');
60
  add_action('dbmanager_cron_optimize', 'cron_dbmanager_optimize');
61
  add_action('dbmanager_cron_repair', 'cron_dbmanager_repair');
62
  function cron_dbmanager_backup() {
63
- global $wpdb;
64
  $backup_options = get_option('dbmanager_options');
65
  $backup_email = stripslashes($backup_options['backup_email']);
66
  if(intval($backup_options['backup_period']) > 0) {
67
- $current_date = mysql2date(sprintf(__('%s @ %s', 'wp-dbmanager'), get_option('date_format'), get_option('time_format')), gmdate('Y-m-d H:i:s', current_time('timestamp')));
68
  $backup = array();
69
  $backup['date'] = current_time('timestamp');
70
  $backup['mysqldumppath'] = $backup_options['mysqldumppath'];
@@ -88,14 +86,14 @@ function cron_dbmanager_backup() {
88
  if(intval($backup_options['backup_gzip']) == 1) {
89
  $backup['filename'] = $backup['date'].'_-_'.DB_NAME.'.sql.gz';
90
  $backup['filepath'] = $backup['path'].'/'.$backup['filename'];
91
- $backup['command'] = $brace.$backup['mysqldumppath'].$brace.' --force --host="'.$backup['host'].'" --user="'.DB_USER.'" --password="'.$backup['password'].'"'.$backup['port'].$backup['sock'].' --add-drop-table --skip-lock-tables '.DB_NAME.' | gzip > '.$brace.$backup['filepath'].$brace;
92
  } else {
93
  $backup['filename'] = $backup['date'].'_-_'.DB_NAME.'.sql';
94
  $backup['filepath'] = $backup['path'].'/'.$backup['filename'];
95
- $backup['command'] = $brace.$backup['mysqldumppath'].$brace.' --force --host="'.$backup['host'].'" --user="'.DB_USER.'" --password="'.$backup['password'].'"'.$backup['port'].$backup['sock'].' --add-drop-table --skip-lock-tables '.DB_NAME.' > '.$brace.$backup['filepath'].$brace;
96
  }
97
  execute_backup($backup['command']);
98
- if( !empty( $backup_email ) )
99
  {
100
  dbmanager_email_backup( $backup_email, $backup['filepath'] );
101
  }
@@ -105,7 +103,6 @@ function cron_dbmanager_backup() {
105
  function cron_dbmanager_optimize() {
106
  global $wpdb;
107
  $backup_options = get_option('dbmanager_options');
108
- $optimize = intval($backup_options['optimize']);
109
  $optimize_period = intval($backup_options['optimize_period']);
110
  if($optimize_period > 0) {
111
  $optimize_tables = array();
@@ -120,7 +117,6 @@ function cron_dbmanager_optimize() {
120
  function cron_dbmanager_repair() {
121
  global $wpdb;
122
  $backup_options = get_option('dbmanager_options');
123
- $repair = intval($backup_options['repair']);
124
  $repair_period = intval($backup_options['repair_period']);
125
  if($repair_period > 0) {
126
  $repair_tables = array();
@@ -211,20 +207,34 @@ function detect_mysql() {
211
  function execute_backup($command) {
212
  $backup_options = get_option('dbmanager_options');
213
  check_backup_files();
214
- if(substr(PHP_OS, 0, 3) == 'WIN') {
 
 
 
 
 
 
 
 
 
215
  $writable_dir = $backup_options['path'];
216
  $tmpnam = $writable_dir.'/wp-dbmanager.bat';
217
- $fp = fopen($tmpnam, 'w');
218
- fwrite($fp, $command);
219
- fclose($fp);
220
- system($tmpnam.' > NUL', $error);
221
- unlink($tmpnam);
222
  } else {
223
- passthru($command, $error);
224
  }
225
  return $error;
226
  }
227
 
 
 
 
 
 
228
  ### Function: Email database backup
229
  function dbmanager_email_backup($to = '', $backup_file_path)
230
  {
@@ -467,6 +477,7 @@ function download_database() {
467
  function dbmanager_options() {
468
  $text = '';
469
  $backup_options = get_option('dbmanager_options');
 
470
  if(!empty($_POST['Submit'])) {
471
  check_admin_referer('wp-dbmanager_options');
472
  $backup_options['mysqldumppath'] = sanitize_text_field( $_POST['db_mysqldumppath'] );
@@ -486,29 +497,40 @@ function dbmanager_options() {
486
  $backup_options['repair_period'] = intval( $_POST['db_repair_period'] );
487
  $backup_options['hide_admin_notices'] = intval( $_POST['db_hide_admin_notices'] );
488
 
489
- $update_db_options = update_option('dbmanager_options', $backup_options);
490
- if($update_db_options) {
491
- $text = '<font color="green">'.__('Database Options Updated', 'wp-dbmanager').'</font>';
 
 
 
 
 
 
 
 
 
 
 
492
  }
493
- if(empty($text)) {
494
- $text = '<font color="red">'.__('No Database Option Updated', 'wp-dbmanager').'</font>';
495
  }
496
- wp_clear_scheduled_hook('dbmanager_cron_backup');
497
- if($backup_options['backup_period'] > 0) {
498
- if (!wp_next_scheduled('dbmanager_cron_backup')) {
499
- wp_schedule_event(time(), 'dbmanager_backup', 'dbmanager_cron_backup');
500
  }
501
  }
502
- wp_clear_scheduled_hook('dbmanager_cron_optimize');
503
- if($backup_options['optimize_period'] > 0) {
504
- if (!wp_next_scheduled('dbmanager_cron_optimize')) {
505
- wp_schedule_event(time(), 'dbmanager_optimize', 'dbmanager_cron_optimize');
506
  }
507
  }
508
- wp_clear_scheduled_hook('dbmanager_cron_repair');
509
- if($backup_options['repair_period'] > 0) {
510
- if (!wp_next_scheduled('dbmanager_cron_repair')) {
511
- wp_schedule_event(time(), 'dbmanager_repair', 'dbmanager_cron_repair');
512
  }
513
  }
514
  }
@@ -543,7 +565,7 @@ function dbmanager_options() {
543
  }
544
  /* ]]> */
545
  </script>
546
- <?php if(!empty($text)) { echo '<!-- Last Action --><div id="message" class="updated fade"><p>'.$text.'</p></div>'; } ?>
547
  <!-- Database Options -->
548
  <form method="post" action="<?php echo admin_url('admin.php?page='.plugin_basename(__FILE__)); ?>">
549
  <?php wp_nonce_field('wp-dbmanager_options'); ?>
3
  Plugin Name: WP-DBManager
4
  Plugin URI: http://lesterchan.net/portfolio/programming/php/
5
  Description: Manages your WordPress database. Allows you to optimize database, repair database, backup database, restore database, delete backup database , drop/empty tables and run selected queries. Supports automatic scheduling of backing up, optimizing and repairing of database.
6
+ Version: 2.72
7
  Author: Lester 'GaMerZ' Chan
8
  Author URI: http://lesterchan.net
9
  Text Domain: wp-dbmanager
60
  add_action('dbmanager_cron_optimize', 'cron_dbmanager_optimize');
61
  add_action('dbmanager_cron_repair', 'cron_dbmanager_repair');
62
  function cron_dbmanager_backup() {
 
63
  $backup_options = get_option('dbmanager_options');
64
  $backup_email = stripslashes($backup_options['backup_email']);
65
  if(intval($backup_options['backup_period']) > 0) {
 
66
  $backup = array();
67
  $backup['date'] = current_time('timestamp');
68
  $backup['mysqldumppath'] = $backup_options['mysqldumppath'];
86
  if(intval($backup_options['backup_gzip']) == 1) {
87
  $backup['filename'] = $backup['date'].'_-_'.DB_NAME.'.sql.gz';
88
  $backup['filepath'] = $backup['path'].'/'.$backup['filename'];
89
+ $backup['command'] = escapeshellcmd( $brace.$backup['mysqldumppath'].$brace.' --force --host="'.$backup['host'].'" --user="'.DB_USER.'" --password="'.$backup['password'].'"'.$backup['port'].$backup['sock'].' --add-drop-table --skip-lock-tables '.DB_NAME ). ' | gzip > '.escapeshellcmd( $brace.$backup['filepath'].$brace );
90
  } else {
91
  $backup['filename'] = $backup['date'].'_-_'.DB_NAME.'.sql';
92
  $backup['filepath'] = $backup['path'].'/'.$backup['filename'];
93
+ $backup['command'] = escapeshellcmd( $brace.$backup['mysqldumppath'].$brace.' --force --host="'.$backup['host'].'" --user="'.DB_USER.'" --password="'.$backup['password'].'"'.$backup['port'].$backup['sock'].' --add-drop-table --skip-lock-tables '.DB_NAME ). ' > '.escapeshellcmd( $brace.$backup['filepath'].$brace );
94
  }
95
  execute_backup($backup['command']);
96
+ if( ! empty( $backup_email ) )
97
  {
98
  dbmanager_email_backup( $backup_email, $backup['filepath'] );
99
  }
103
  function cron_dbmanager_optimize() {
104
  global $wpdb;
105
  $backup_options = get_option('dbmanager_options');
 
106
  $optimize_period = intval($backup_options['optimize_period']);
107
  if($optimize_period > 0) {
108
  $optimize_tables = array();
117
  function cron_dbmanager_repair() {
118
  global $wpdb;
119
  $backup_options = get_option('dbmanager_options');
 
120
  $repair_period = intval($backup_options['repair_period']);
121
  if($repair_period > 0) {
122
  $repair_tables = array();
207
  function execute_backup($command) {
208
  $backup_options = get_option('dbmanager_options');
209
  check_backup_files();
210
+
211
+ if( realpath( $backup_options['path'] ) === false ) {
212
+ return sprintf( __( '%s is not a valid backup path', 'wp-dbmanager' ), stripslashes( $backup_options['path'] ) );
213
+ } else if( dbmanager_is_valid_path( $backup_options['mysqldumppath'] ) === 0 ) {
214
+ return sprintf( __( '%s is not a valid mysqldump path', 'wp-dbmanager' ), stripslashes( $backup_options['mysqldumppath'] ) );
215
+ } else if( dbmanager_is_valid_path( $backup_options['mysqlpath'] ) === 0 ) {
216
+ return sprintf( __( '%s is not a valid mysql path', 'wp-dbmanager' ), stripslashes( $backup_options['mysqlpath'] ) );
217
+ }
218
+
219
+ if( substr( PHP_OS, 0, 3 ) === 'WIN' ) {
220
  $writable_dir = $backup_options['path'];
221
  $tmpnam = $writable_dir.'/wp-dbmanager.bat';
222
+ $fp = fopen( $tmpnam, 'w' );
223
+ fwrite ($fp, $command );
224
+ fclose( $fp );
225
+ system( $tmpnam.' > NUL', $error );
226
+ unlink( $tmpnam );
227
  } else {
228
+ passthru( $command, $error );
229
  }
230
  return $error;
231
  }
232
 
233
+ ### Function: Check for valid file path
234
+ function dbmanager_is_valid_path( $path ) {
235
+ return preg_match( '/^[^*?"<>|;]*$/', $path );
236
+ }
237
+
238
  ### Function: Email database backup
239
  function dbmanager_email_backup($to = '', $backup_file_path)
240
  {
477
  function dbmanager_options() {
478
  $text = '';
479
  $backup_options = get_option('dbmanager_options');
480
+ $old_backup_options = $backup_options;
481
  if(!empty($_POST['Submit'])) {
482
  check_admin_referer('wp-dbmanager_options');
483
  $backup_options['mysqldumppath'] = sanitize_text_field( $_POST['db_mysqldumppath'] );
497
  $backup_options['repair_period'] = intval( $_POST['db_repair_period'] );
498
  $backup_options['hide_admin_notices'] = intval( $_POST['db_hide_admin_notices'] );
499
 
500
+ if( realpath( $backup_options['path'] ) === false ) {
501
+ $text = '<div id="message" class="error"><p>' . sprintf( __( '%s is not a valid backup path', 'wp-dbmanager' ), stripslashes( $backup_options['path'] ) ) . '</p></div>';
502
+ $backup_options['path'] = $old_backup_options['path'];
503
+ } else if( dbmanager_is_valid_path( $backup_options['mysqldumppath'] ) === 0 ) {
504
+ $text = '<div id="message" class="error"><p>' . sprintf( __( '%s is not a valid mysqldump path', 'wp-dbmanager' ), stripslashes( $backup_options['mysqldumppath'] ) ) . '</p></div>';
505
+ $backup_options['mysqldumppath'] = $old_backup_options['mysqldumppath'];
506
+ } else if( dbmanager_is_valid_path( $backup_options['mysqlpath'] ) === 0 ) {
507
+ $text = '<div id="message" class="error"><p>' . sprintf( __( '%s is not a valid mysql path', 'wp-dbmanager' ), stripslashes( $backup_options['mysqlpath'] ) ) . '</p></div>';
508
+ $backup_options['mysqlpath'] = $old_backup_options['mysqlpath'];
509
+ }
510
+
511
+ $update_db_options = update_option( 'dbmanager_options', $backup_options );
512
+ if( $update_db_options ) {
513
+ $text = '<div id="message" class="updated"><p>' . __( 'Database Options Updated', 'wp-dbmanager' ) . '</p></div>';
514
  }
515
+ if( empty( $text ) ) {
516
+ $text = '<div id="message" class="error"><p>' . __( 'No Database Option Updated', 'wp-dbmanager' ) . '</p></div>';
517
  }
518
+ wp_clear_scheduled_hook( 'dbmanager_cron_backup' );
519
+ if( $backup_options['backup_period'] > 0 ) {
520
+ if ( ! wp_next_scheduled( 'dbmanager_cron_backup' ) ) {
521
+ wp_schedule_event( time(), 'dbmanager_backup', 'dbmanager_cron_backup' );
522
  }
523
  }
524
+ wp_clear_scheduled_hook( 'dbmanager_cron_optimize' );
525
+ if( $backup_options['optimize_period'] > 0 ) {
526
+ if ( ! wp_next_scheduled('dbmanager_cron_optimize' ) ) {
527
+ wp_schedule_event( time(), 'dbmanager_optimize', 'dbmanager_cron_optimize' );
528
  }
529
  }
530
+ wp_clear_scheduled_hook( 'dbmanager_cron_repair' );
531
+ if( $backup_options['repair_period'] > 0 ) {
532
+ if ( ! wp_next_scheduled( 'dbmanager_cron_repair' ) ) {
533
+ wp_schedule_event( time(), 'dbmanager_repair', 'dbmanager_cron_repair' );
534
  }
535
  }
536
  }
565
  }
566
  /* ]]> */
567
  </script>
568
+ <?php if( ! empty( $text ) ) { echo $text; } ?>
569
  <!-- Database Options -->
570
  <form method="post" action="<?php echo admin_url('admin.php?page='.plugin_basename(__FILE__)); ?>">
571
  <?php wp_nonce_field('wp-dbmanager_options'); ?>