WP-DBManager - Version 2.04

Version Description

Download this release

Release Info

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

Version 2.04

.htaccess ADDED
@@ -0,0 +1,4 @@
 
 
 
 
1
+ <Files ~ ".*\..*">
2
+ order allow,deny
3
+ deny from all
4
+ </Files>
dbmanager/database-backup.php ADDED
@@ -0,0 +1,195 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ +----------------------------------------------------------------+
4
+ | |
5
+ | WordPress 2.0 Plugin: WP-DBManager 2.04 |
6
+ | Copyright (c) 2005 Lester "GaMerZ" Chan |
7
+ | |
8
+ | File Written By: |
9
+ | - Lester "GaMerZ" Chan |
10
+ | - http://www.lesterchan.net |
11
+ | |
12
+ | File Information: |
13
+ | - Database Backup |
14
+ | - wp-content/plugins/dbmanager/database-backup.php |
15
+ | |
16
+ +----------------------------------------------------------------+
17
+ */
18
+
19
+
20
+ ### Require Database Config
21
+ require('database-config.php');
22
+
23
+ ### Form Processing
24
+ if($_POST['do']) {
25
+ // Decide What To Do
26
+ switch($_POST['do']) {
27
+ case 'Backup':
28
+ $gzip = intval($_POST['gzip']);
29
+ if($gzip == 1) {
30
+ $backup['filename'] = $backup['date'].'_-_'.DB_NAME.'.sql.gz';
31
+ $backup['filepath'] = $backup['path'].'/'.$backup['filename'];
32
+ $backup['command'] = $backup['mysqldumppath'].' --host='.DB_HOST.' --user='.DB_USER.' --password='.DB_PASSWORD.' --add-drop-table '.DB_NAME.' | gzip > '.$backup['filepath'];
33
+ } else {
34
+ $backup['filename'] = $backup['date'].'_-_'.DB_NAME.'.sql';
35
+ $backup['filepath'] = $backup['path'].'/'.$backup['filename'];
36
+ $backup['command'] = $backup['mysqldumppath'].' --host='.DB_HOST.' --user='.DB_USER.' --password='.DB_PASSWORD.' --add-drop-table '.DB_NAME.' > '.$backup['filepath'];
37
+ }
38
+ passthru($backup['command'], $error);
39
+ if(!is_writable($backup['path'])) {
40
+ $text = "<font color=\"red\">Database Failed To Backup On '$current_date'. Backup Folder Not Writable.</font>";
41
+ } elseif(filesize($backup['filepath']) == 0) {
42
+ unlink($backup['filepath']);
43
+ $text = "<font color=\"red\">Database Failed To Backup On '$current_date'. Backup File Size Is 0KB.</font>";
44
+ } elseif(!is_file($backup['filepath'])) {
45
+ $text = "<font color=\"red\">Database Failed To Backup On '$current_date'. Invalid Backup File Path.</font>";
46
+ } elseif($error) {
47
+ $text = "<font color=\"red\">Database Failed To Backup On '$current_date'.</font>";
48
+ } else {
49
+ $text = "<font color=\"green\">Database Backed Up Successfully On '$current_date'.</font>";
50
+ }
51
+ break;
52
+ }
53
+ }
54
+
55
+
56
+ ### Backup File Name
57
+ $backup['filename'] = $backup['date'].'_-_'.DB_NAME.'.sql';
58
+
59
+
60
+ ### MYSQL Base Dir
61
+ $mysql_basedir = $wpdb->get_row("SHOW VARIABLES LIKE 'basedir'");
62
+ $mysql_basedir = $mysql_basedir->Value;
63
+ if($mysql_basedir == '/') { $mysql_basedir = '/usr/'; }
64
+ $status_count = 0;
65
+ $stats_function_disabled = 0;
66
+ ?>
67
+ <?php if(!empty($text)) { echo '<!-- Last Action --><div id="message" class="updated fade"><p>'.$text.'</p></div>'; } ?>
68
+ <!-- Checking Backup Status -->
69
+ <div class="wrap">
70
+ <h2>Checking Backup Status</h2>
71
+ <p>
72
+ Checking Backup Folder (<b><?php echo stripslashes($backup['path']); ?></b>) ...<br />
73
+ <?php
74
+ if(is_dir(stripslashes($backup['path']))) {
75
+ echo '<font color="green">Backup folder exists</font><br />';
76
+ $status_count++;
77
+ } else {
78
+ echo '<font color="red">Backup folder does NOT exist. Please create \'backup-db\' folder in \'wp-content\' folder and CHMOD it to \'777\' or change the location of the backup folder under DB Option.</font><br />';
79
+ }
80
+ if(is_writable(stripslashes($backup['path']))) {
81
+ echo '<font color="green">Backup folder is writable</font>';
82
+ $status_count++;
83
+ } else {
84
+ echo '<font color="red">Backup folder is NOT writable. Please CHMOD it to \'777\'.</font>';
85
+ }
86
+ ?>
87
+ </p>
88
+ <p>
89
+ <?php
90
+ if(file_exists($mysql_basedir.'bin/'.stripslashes($backup['mysqldumppath']))) {
91
+ echo 'Checking MYSQL Dump Path (<b>'.$mysql_basedir.'bin/'.stripslashes($backup['mysqldumppath']).'</b>) ...<br />';
92
+ echo '<font color="green">MYSQL dump path exists.</font>';
93
+ $status_count++;
94
+ } else if(file_exists(stripslashes($backup['mysqldumppath']))) {
95
+ echo 'Checking MYSQL Dump Path (<b>'.stripslashes($backup['mysqldumppath']).'</b>) ...<br />';
96
+ echo '<font color="green">MYSQL dump path exists.</font>';
97
+ $status_count++;
98
+ } else {
99
+ echo 'Checking MYSQL Dump Path ...<br />';
100
+ echo '<font color="red">MYSQL dump path does NOT exist. Please check your mysqldump path under DB Options. If uncertain, contact your server administrator.</font>';
101
+ }
102
+ ?>
103
+ </p>
104
+ <p>
105
+ <?php
106
+ if(file_exists($mysql_basedir.'bin/'.stripslashes($backup['mysqlpath']))) {
107
+ echo 'Checking MYSQL Path (<b>'.$mysql_basedir.'bin/'.stripslashes($backup['mysqlpath']).'</b>) ...<br />';
108
+ echo '<font color="green">MYSQL path exists.</font>';
109
+ $status_count++;
110
+ } else if(file_exists(stripslashes($backup['mysqlpath']))) {
111
+ echo 'Checking MYSQL Path (<b>'.stripslashes($backup['mysqlpath']).'</b>) ...<br />';
112
+ echo '<font color="green">MYSQL path exists.</font>';
113
+ $status_count++;
114
+ } else {
115
+ echo 'Checking MYSQL Path ...<br />';
116
+ echo '<font color="red">MYSQL path does NOT exist. Please check your mysql path under DB Options. If uncertain, contact your server administrator.</font>';
117
+ }
118
+ ?>
119
+ </p>
120
+ <p>
121
+ Checking PHP Functions (<b>passthru()</b>, <b>system()</b> and <b>exec()</b>) ...<br />
122
+ <?php
123
+ if(function_exists('passthru')) {
124
+ echo '<font color="green">passthru() enabled.</font><br />';
125
+ $status_count++;
126
+ } else {
127
+ echo '<font color="red">passthru() disabled.</font><br />';
128
+ $stats_function_disabled++;
129
+ }
130
+ if(function_exists('system')) {
131
+ echo '<font color="green">system() enabled.</font><br />';
132
+ } else {
133
+ echo '<font color="red">system() disabled.</font><br />';
134
+ $stats_function_disabled++;
135
+ }
136
+ if(function_exists('exec')) {
137
+ echo '<font color="green">exec() enabled.</font>';
138
+ } else {
139
+ echo '<font color="red">exec() disabled.</font>';
140
+ $stats_function_disabled++;
141
+ }
142
+ ?>
143
+ </p>
144
+ <p>
145
+ <?php
146
+ if($status_count == 5) {
147
+ echo '<b><font color="green">Excellent. You Are Good To Go.</font></b>';
148
+ } else if($stats_function_disabled == 3) {
149
+ echo '<b><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.</font></b>';
150
+ } else {
151
+ echo '<b><font color="red">Please Rectify The Error Highlighted In Red Before Proceeding On.</font></b>';
152
+ }
153
+ ?>
154
+ </p>
155
+ <p><i>Note: The checking of backup status is still undergoing testing, if you get a 'Good To Go' status but can't perform the backup or you get some errors but still can perform the backup, please drop me an <a href="mailto:gamerz84@hotmail.com?Subject=WP-DBManager: Checking Of Backup Status">email</a>.</i></p>
156
+ </div>
157
+ <!-- Backup Database -->
158
+ <div class="wrap">
159
+ <h2>Backup Database</h2>
160
+ <form action="<?php echo $_SERVER['REQUEST_URI']; ?>" method="post">
161
+ <table width="100%" cellspacing="3" cellpadding="3" border="0">
162
+ <tr style='background-color: #eee'>
163
+ <th align="left" scope="row">Database Name:</th>
164
+ <td><?php echo DB_NAME; ?></td>
165
+ </tr>
166
+ <tr style='background-color: none'>
167
+ <th align="left" scope="row">Database Backup To:</th>
168
+ <td><?php echo stripslashes($backup['path']); ?></td>
169
+ </tr>
170
+ <tr style='background-color: #eee'>
171
+ <th align="left" scope="row">Database Backup Date:</th>
172
+ <td><?php echo gmdate('l, jS F Y @ H:i', $backup['date']); ?></td>
173
+ </tr>
174
+ <tr style='background-color: none'>
175
+ <th align="left" scope="row">Database Backup File Name:</th>
176
+ <td><?php echo $backup['filename']; ?></td>
177
+ </tr>
178
+ <tr style='background-color: #eee'>
179
+ <th align="left" scope="row">Database Backup Type:</th>
180
+ <td>Full (Structure and Data)</td>
181
+ </tr>
182
+ <tr style='background-color: none'>
183
+ <th align="left" scope="row">MYSQL Dump Location:</th>
184
+ <td><?php echo stripslashes($backup['mysqldumppath']); ?></td>
185
+ </tr>
186
+ <tr style='background-color: #eee'>
187
+ <th align="left" scope="row">GZIP Database Backup File?</th>
188
+ <td><input type="radio" name="gzip" value="1" />Yes&nbsp;&nbsp;<input type="radio" name="gzip" value="0" checked="checked" />No</td>
189
+ </tr>
190
+ <tr>
191
+ <td colspan="2" align="center"><input type="submit" name="do" value="Backup" class="button" />&nbsp;&nbsp;<input type="button" name="cancel" Value="<?php _e('Cancel'); ?>" class="button" onclick="javascript:history.go(-1)" /></td>
192
+ </tr>
193
+ </table>
194
+ </form>
195
+ </div>
dbmanager/database-config.php ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ +----------------------------------------------------------------+
4
+ | |
5
+ | WordPress 2.0 Plugin: WP-DBManager 2.04 |
6
+ | Copyright (c) 2005 Lester "GaMerZ" Chan |
7
+ | |
8
+ | File Written By: |
9
+ | - Lester "GaMerZ" Chan |
10
+ | - http://www.lesterchan.net |
11
+ | |
12
+ | File Information: |
13
+ | - Database Config |
14
+ | - wp-content/plugins/dbmanager/database-config.php |
15
+ | |
16
+ +----------------------------------------------------------------+
17
+ */
18
+
19
+
20
+ ### Check Whether User Can Manage Database
21
+ if(!current_user_can('manage_database')) {
22
+ die('Access Denied');
23
+ }
24
+
25
+
26
+ ### Variables Variables Variables
27
+ $base_name = plugin_basename('dbmanager/database-manager.php');
28
+ $base_page = 'admin.php?page='.$base_name;
29
+ $current_date = gmdate('l, jS F Y @ H:i', (time() + (get_settings('gmt_offset') * 3600)));
30
+ $backup = array();
31
+ $backup_options = get_settings('dbmanager_options');
32
+ $backup['date'] = current_time('timestamp');
33
+ $backup['mysqldumppath'] = $backup_options['mysqldumppath'];
34
+ $backup['mysqlpath'] = $backup_options['mysqlpath'];
35
+ $backup['path'] = $backup_options['path'];
36
+
37
+
38
+ ### Format Bytes Into KB/MB
39
+ function format_size($rawSize) {
40
+ if($rawSize / 1073741824 > 1)
41
+ return round($rawSize/1048576, 1) . ' GB';
42
+ else if ($rawSize / 1048576 > 1)
43
+ return round($rawSize/1048576, 1) . ' MB';
44
+ else if ($rawSize / 1024 > 1)
45
+ return round($rawSize/1024, 1) . ' KB';
46
+ else
47
+ return round($rawSize, 1) . ' bytes';
48
+ }
49
+
50
+
51
+ ### Get File Extension
52
+ function file_ext($file_name) {
53
+ return substr(strrchr($file_name, '.'), 1);
54
+ }
55
+
56
+
57
+ ### Check Folder Whether There Is Any File Inside
58
+ function is_emtpy_folder($folder){
59
+ if(is_dir($folder) ){
60
+ $handle = opendir($folder);
61
+ while( (gettype( $name = readdir($handle)) != 'boolean')){
62
+ $name_array[] = $name;
63
+ }
64
+ foreach($name_array as $temp)
65
+ $folder_content .= $temp;
66
+
67
+ if($folder_content == '...')
68
+ return true;
69
+ else
70
+ return false;
71
+ closedir($handle);
72
+ }
73
+ else
74
+ return true; // folder doesnt exist
75
+ }
76
+ ?>
dbmanager/database-empty.php ADDED
@@ -0,0 +1,97 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ +----------------------------------------------------------------+
4
+ | |
5
+ | WordPress 2.0 Plugin: WP-DBManager 2.04 |
6
+ | Copyright (c) 2005 Lester "GaMerZ" Chan |
7
+ | |
8
+ | File Written By: |
9
+ | - Lester "GaMerZ" Chan |
10
+ | - http://www.lesterchan.net |
11
+ | |
12
+ | File Information: |
13
+ | - Database Empty |
14
+ | - wp-content/plugins/dbmanager/database-empty.php |
15
+ | |
16
+ +----------------------------------------------------------------+
17
+ */
18
+
19
+
20
+ ### Require Database Config
21
+ require('database-config.php');
22
+
23
+
24
+ ### Form Processing
25
+ if($_POST['do']) {
26
+ // Lets Prepare The Variables
27
+ $emptydrop = $_POST['emptydrop'];
28
+
29
+ // Decide What To Do
30
+ switch($_POST['do']) {
31
+ case 'Empty/Drop':
32
+ $empty_tables = array();
33
+ if(!empty($emptydrop)) {
34
+ foreach($emptydrop as $key => $value) {
35
+ if($value == 'empty') {
36
+ $empty_tables[] = $key;
37
+ } elseif($value == 'drop') {
38
+ $drop_tables .= ', '.$key;
39
+ }
40
+ }
41
+ } else {
42
+ $text = '<font color="red">No Tables Selected</font>';
43
+ }
44
+ $drop_tables = substr($drop_tables, 2);
45
+ if(!empty($empty_tables)) {
46
+ foreach($empty_tables as $empty_table) {
47
+ $empty_query = $wpdb->query("TRUNCATE $empty_table");
48
+ $text .= "<font color=\"green\">Table '$empty_table' Emptied</font><br />";
49
+ }
50
+ }
51
+ if(!empty($drop_tables)) {
52
+ $drop_query = $wpdb->query("DROP TABLE $drop_tables");
53
+ $text = "<font color=\"green\">Table(s) '$drop_tables' Dropped</font>";
54
+ }
55
+ break;
56
+ }
57
+ }
58
+
59
+
60
+ ### Show Tables
61
+ $tables = $wpdb->get_results("SHOW TABLES");
62
+ ?>
63
+ <?php if(!empty($text)) { echo '<!-- Last Action --><div id="message" class="updated fade"><p>'.$text.'</p></div>'; } ?>
64
+ <!-- Empty/Drop Tables -->
65
+ <div class="wrap">
66
+ <h2>Empty/Drop Tables</h2>
67
+ <form action="<?php echo $_SERVER['REQUEST_URI']; ?>" method="post">
68
+ <table width="100%" cellspacing="3" cellpadding="3" border="0">
69
+ <tr>
70
+ <th align="left" scope="col">Tables</th>
71
+ <th align="left" scope="col">Empty</th>
72
+ <th align="left" scope="col">Drop</th>
73
+ </tr>
74
+ <?php
75
+ foreach($tables as $dbtable) {
76
+ if($no%2 == 0) {
77
+ $style = 'style=\'background-color: #eee\'';
78
+ } else {
79
+ $style = 'style=\'background-color: none\'';
80
+ }
81
+ $no++;
82
+ $table_name = '$dbtable->Tables_in_'.DB_NAME;
83
+ eval("\$table_name = \"$table_name\";");
84
+ echo "<tr $style><th align=\"left\" scope=\"row\">$table_name</th>\n";
85
+ echo "<td><input type=\"radio\" name=\"emptydrop[$table_name]\" value=\"empty\" />&nbsp;Empty</td>";
86
+ echo "<td><input type=\"radio\" name=\"emptydrop[$table_name]\" value=\"drop\" />&nbsp;Drop</td></tr>";
87
+ }
88
+ ?>
89
+ <tr>
90
+ <td colspan="3">1. DROPPING a table means deleting the table. This action is not REVERSIBLE.<br />2. EMPTYING a table means all the rows in the table will be deleted. This action is not REVERSIBLE.</td>
91
+ </tr>
92
+ <tr>
93
+ <td colspan="3" align="center"><input type="submit" name="do" value="Empty/Drop" class="button" onclick="return confirm('You Are About To Empty Or Drop The Selected Databases.\nThis Action Is Not Reversible.\n\n Choose \'Cancel\' to stop, \'OK\' to delete.')" />&nbsp;&nbsp;<input type="button" name="cancel" Value="<?php _e('Cancel'); ?>" class="button" onclick="javascript:history.go(-1)" /></td>
94
+ </tr>
95
+ </table>
96
+ </form>
97
+ </div>
dbmanager/database-manage.php ADDED
@@ -0,0 +1,204 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ +----------------------------------------------------------------+
4
+ | |
5
+ | WordPress 2.0 Plugin: WP-DBManager 2.04 |
6
+ | Copyright (c) 2005 Lester "GaMerZ" Chan |
7
+ | |
8
+ | File Written By: |
9
+ | - Lester "GaMerZ" Chan |
10
+ | - http://www.lesterchan.net |
11
+ | |
12
+ | File Information: |
13
+ | - Database Restore |
14
+ | - wp-content/plugins/dbmanager/database-restore.php |
15
+ | |
16
+ +----------------------------------------------------------------+
17
+ */
18
+
19
+
20
+ ### Download Database
21
+ if(!empty($_GET['file'])) {
22
+ require_once('../../../wp-config.php');
23
+ auth_redirect();
24
+ if(strpos($_SERVER['HTTP_REFERER'], get_settings('siteurl').'/wp-admin/admin.php?page=dbmanager/database-manage.php') !== false) {
25
+ $backup_options = get_settings('dbmanager_options');
26
+ $file_path = $backup_options['path'].'/'.$_GET['file'];
27
+ header("Pragma: public");
28
+ header("Expires: 0");
29
+ header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
30
+ header("Content-Type: application/force-download");
31
+ header("Content-Type: application/octet-stream");
32
+ header("Content-Type: application/download");
33
+ header("Content-Disposition: attachment; filename=".basename($file_path).";");
34
+ header("Content-Transfer-Encoding: binary");
35
+ header("Content-Length: ".filesize($file_path));
36
+ @readfile($file_path);
37
+ }
38
+ exit();
39
+ }
40
+
41
+
42
+ ### Require Database Config
43
+ require('database-config.php');
44
+
45
+
46
+ ### Form Processing
47
+ if($_POST['do']) {
48
+ // Lets Prepare The Variables
49
+ $database_file = trim($_POST['database_file']);
50
+ $nice_file_date = gmdate('l, jS F Y @ H:i', substr($database_file, 0, 10));
51
+
52
+ // Decide What To Do
53
+ switch($_POST['do']) {
54
+ case 'Restore':
55
+ if(!empty($database_file)) {
56
+ if(stristr($database_file, '.gz')) {
57
+ $backup['command'] = 'gunzip < '.$backup['path'].'/'.$database_file.' | '.$backup['mysqlpath'].' --host='.DB_HOST.' --user='.DB_USER.' --password='.DB_PASSWORD.' '.DB_NAME;
58
+ } else {
59
+ $backup['command'] = $backup['mysqlpath'].' --host='.DB_HOST.' --user='.DB_USER.' --password='.DB_PASSWORD.' '.DB_NAME.' < '.$backup['path'].'/'.$database_file;
60
+ }
61
+ passthru($backup['command'], $error);
62
+ if($error) {
63
+ $text = "<font color=\"red\">Database On '$nice_file_date' Failed To Restore</font>";
64
+ } else {
65
+ $text = "<font color=\"green\">Database On '$nice_file_date' Restored Successfully</font>";
66
+ }
67
+ } else {
68
+ $text = '<font color="red">No Backup Database File Selected</font>';
69
+ }
70
+ break;
71
+ case 'E-Mail':
72
+ if(!empty($database_file)) {
73
+ // Get And Read The Database Backup File
74
+ $file_path = $backup['path'].'/'.$database_file;
75
+ $file_size = format_size(filesize($file_path));
76
+ $file_date = gmdate('l, jS F Y @ H:i', substr($database_file, 0, 10));
77
+ $file = fopen($file_path,'rb');
78
+ $file_data = fread($file,filesize($file_path));
79
+ fclose($file);
80
+ $file_data = chunk_split(base64_encode($file_data));
81
+ // Create Mail To, Mail Subject And Mail Header
82
+ if(!empty($_POST['email_to'])) {
83
+ $mail_to = trim($_POST['email_to']);
84
+ } else {
85
+ $mail_to = get_settings('admin_email');
86
+ }
87
+ $mail_subject = get_bloginfo('name').' Database Backup File For '.$file_date;
88
+ $mail_header = 'From: '.get_bloginfo('name').' Administrator <'.get_settings('admin_email').'>';
89
+ // MIME Boundary
90
+ $random_time = md5(time());
91
+ $mime_boundary = "==WP-DBManager- $random_time";
92
+ // Create Mail Header And Mail Message
93
+ $mail_header .= "\nMIME-Version: 1.0\n" .
94
+ "Content-Type: multipart/mixed;\n" .
95
+ " boundary=\"{$mime_boundary}\"";
96
+ $mail_message = "Website Name: ".get_bloginfo('name')."\nWebsite URL: ".get_bloginfo('siteurl')."\nBackup File Name: $database_file\nBackup File Date: $file_date\nBackup File Size: $file_size\n\nWith Regards,\n".get_bloginfo('name')." Administrator\n".get_bloginfo('siteurl');
97
+ $mail_message = "This is a multi-part message in MIME format.\n\n" .
98
+ "--{$mime_boundary}\n" .
99
+ "Content-Type: text/plain; charset=\"utf-8\"\n" .
100
+ "Content-Transfer-Encoding: 7bit\n\n".$mail_message."\n\n";
101
+ $mail_message .= "--{$mime_boundary}\n" .
102
+ "Content-Type: application/octet-stream;\n" .
103
+ " name=\"$database_file\"\n" .
104
+ "Content-Disposition: attachment;\n" .
105
+ " filename=\"$database_file\"\n" .
106
+ "Content-Transfer-Encoding: base64\n\n" .
107
+ $file_data."\n\n--{$mime_boundary}--\n";
108
+ if(mail($mail_to, $mail_subject, $mail_message, $mail_header)) {
109
+ $text .= "<font color=\"green\">Database Backup File For '$file_date' Successfully E-Mailed To '$mail_to'</font><br />";
110
+ } else {
111
+ $text = "<font color=\"red\">Unable To E-Mail Database Backup File For '$file_date' To '$mail_to'</font>";
112
+ }
113
+ } else {
114
+ $text = '<font color="red">No Backup Database File Selected</font>';
115
+ }
116
+ break;
117
+ case 'Download':
118
+ if(empty($database_file)) {
119
+ $text = '<font color="red">No Backup Database File Selected</font>';
120
+ }
121
+ break;
122
+ case 'Delete':
123
+ if(!empty($database_file)) {
124
+ $nice_file_date = gmdate('l, jS F Y @ H:i', substr($database_file, 0, 10));
125
+ if(is_file($backup['path'].'/'.$database_file)) {
126
+ if(!unlink($backup['path'].'/'.$database_file)) {
127
+ $text .= "<font color=\"red\">Unable To Delete Database Backup File On '$nice_file_date'</font><br />";
128
+ } else {
129
+ $text .= "<font color=\"green\">Database Backup File On '$nice_file_date' Deleted Successfully</font><br />";
130
+ }
131
+ } else {
132
+ $text = "<font color=\"red\">Invalid Database Backup File On '$nice_file_date'</font>";
133
+ }
134
+ } else {
135
+ $text = '<font color="red">No Backup Database File Selected</font>';
136
+ }
137
+ break;
138
+ }
139
+ }
140
+ ?>
141
+ <?php if(!empty($text)) { echo '<!-- Last Action --><div id="message" class="updated fade"><p>'.$text.'</p></div>'; } ?>
142
+ <!-- Manage Backup Database -->
143
+ <div class="wrap">
144
+ <h2>Manage Backup Database</h2>
145
+ <form action="<?php echo $_SERVER['REQUEST_URI']; ?>" method="post">
146
+ <table width="100%" cellspacing="3" cellpadding="3" border="0">
147
+ <tr>
148
+ <th align="left" scope="row" colspan="5">Choose A Backup Date To E-Mail, Restore, Download Or Delete</th>
149
+ </tr>
150
+ <tr>
151
+ <th align="left" scope="col">No.</th>
152
+ <th align="left" scope="col">Database File</th>
153
+ <th align="left" scope="col">Date/Time</th>
154
+ <th align="left" scope="col">Size</th>
155
+ <th align="left" scope="col">Select</th>
156
+ </tr>
157
+ <?php
158
+ if(!is_emtpy_folder($backup['path'])) {
159
+ if ($handle = opendir($backup['path'])) {
160
+ $database_files = array();
161
+ while (false !== ($file = readdir($handle))) {
162
+ if ($file != '.' && $file != '..' && (file_ext($file) == 'sql' || file_ext($file) == 'gz')) {
163
+ $database_files[] = $file;
164
+ }
165
+ }
166
+ closedir($handle);
167
+ for($i = (sizeof($database_files)-1); $i > -1; $i--) {
168
+ if($no%2 == 0) {
169
+ $style = 'style=\'background-color: #eee\'';
170
+ } else {
171
+ $style = 'style=\'background-color: none\'';
172
+ }
173
+ $no++;
174
+ $database_text = substr($database_files[$i], 13);
175
+ $date_text = gmdate('l, jS F Y @ H:i', substr($database_files[$i], 0, 10));
176
+ $size_text = filesize($backup['path'].'/'.$database_files[$i]);
177
+ echo "<tr $style>\n<td>$no</td>";
178
+ echo "<td>$database_text</td>";
179
+ echo "<td>$date_text</td>";
180
+ echo '<td>'.format_size($size_text).'</td>';
181
+ echo "<td><input type=\"radio\" name=\"database_file\" value=\"$database_files[$i]\" /></td>\n</tr>\n";
182
+ $totalsize += $size_text;
183
+ }
184
+ } else {
185
+ echo '<tr><td align="center" colspan="5">There Are No Database Backup Files Available</td></tr>';
186
+ }
187
+ } else {
188
+ echo '<tr><td align="center" colspan="5">There Are No Database Backup Files Available</td></tr>';
189
+ }
190
+ ?>
191
+ <tr>
192
+ <th align="left" colspan="3"><?php echo $no; ?> Backup File(s)</th>
193
+ <th align="left"><?php echo format_size($totalsize); ?></th>
194
+ <td>&nbsp;</td>
195
+ </tr>
196
+ <tr>
197
+ <td colspan="5">E-mail database backup file to: <input type="text" name="email_to" size="30" maxlength="50" value="<?php echo get_settings('admin_email'); ?>" />&nbsp;&nbsp;<input type="submit" name="do" value="E-Mail" class="button" /></td>
198
+ </tr>
199
+ <tr>
200
+ <td colspan="5" align="center"><input type="submit" name="do" value="Download" class="button" />&nbsp;&nbsp;<input type="submit" name="do" value="Restore" onclick="return confirm('You Are About To Restore A Database.\nThis Action Is Not Reversible.\nAny Data Inserted After The Backup Date Will Be Gone.\n\n Choose \'Cancel\' to stop, \'OK\' to restore.')" class="button" />&nbsp;&nbsp;<input type="submit" class="button" name="do" value="Delete" onclick="return confirm('You Are About To Delete The Selected Database Backup Files.\nThis Action Is Not Reversible.\n\n Choose \'Cancel\' to stop, \'OK\' to delete.')" />&nbsp;&nbsp;<input type="button" name="cancel" Value="<?php _e('Cancel'); ?>" class="button" onclick="javascript:history.go(-1)" /></td>
201
+ </tr>
202
+ </table>
203
+ </form>
204
+ </div>
dbmanager/database-manager.php ADDED
@@ -0,0 +1,102 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ +----------------------------------------------------------------+
4
+ | |
5
+ | WordPress 2.0 Plugin: WP-DBManager 2.04 |
6
+ | Copyright (c) 2005 Lester "GaMerZ" Chan |
7
+ | |
8
+ | File Written By: |
9
+ | - Lester "GaMerZ" Chan |
10
+ | - http://www.lesterchan.net |
11
+ | |
12
+ | File Information: |
13
+ | - Database Manager |
14
+ | - wp-content/plugins/dbmanager/database-manager.php |
15
+ | |
16
+ +----------------------------------------------------------------+
17
+ */
18
+
19
+
20
+ ### Require Database Config
21
+ require('database-config.php');
22
+
23
+
24
+ ### Get MYSQL Version
25
+ $sqlversion = $wpdb->get_var("SELECT VERSION() AS version");
26
+ ?>
27
+ <?php if(!empty($text)) { echo '<!-- Last Action --><div id="message" class="updated fade"><p>'.$text.'</p></div>'; } ?>
28
+ <!-- Database Information -->
29
+ <div class="wrap">
30
+ <h2>Database Information</h2>
31
+ <table width="100%" cellspacing="3" cellpadding="3" border="0">
32
+ <tr>
33
+ <th align="left" scope="col">Setting</th>
34
+ <th align="left" scope="col">Value</th>
35
+ </tr>
36
+ <tr>
37
+ <td>Database Host</td>
38
+ <td><?php echo DB_HOST; ?></td>
39
+ </tr>
40
+ <tr>
41
+ <td>Database Name</td>
42
+ <td><?php echo DB_NAME; ?></td>
43
+ </tr>
44
+ <tr>
45
+ <td>Database User</td>
46
+ <td><?php echo DB_USER; ?></td>
47
+ </tr>
48
+ <tr>
49
+ <td>Database Type</td>
50
+ <td>MYSQL</td>
51
+ </tr>
52
+ <tr>
53
+ <td>Database Version</td>
54
+ <td>v<?php echo $sqlversion; ?></td>
55
+ </tr>
56
+ </table>
57
+ </div>
58
+ <div class="wrap">
59
+ <h2>Tables Information</h2>
60
+ <table width="100%" cellspacing="3" cellpadding="3" border="0">
61
+ <tr>
62
+ <th align="left" scope="col">No.</th>
63
+ <th align="left" scope="col">Tables</th>
64
+ <th align="left" scope="col">Records</th>
65
+ <th align="left" scope="col">Data Usage</th>
66
+ <th align="left" scope="col">Index Usage</th>
67
+ <th align="left" scope="col">Overhead</th>
68
+ </tr>
69
+ <?php
70
+ // If MYSQL Version More Than 3.23, Get More Info
71
+ if($sqlversion >= '3.23') {
72
+ $tablesstatus = $wpdb->get_results("SHOW TABLE STATUS");
73
+ foreach($tablesstatus as $tablestatus) {
74
+ if($no%2 == 0) {
75
+ $style = 'style=\'background-color: #eee\'';
76
+ } else {
77
+ $style = 'style=\'background-color: none\'';
78
+ }
79
+ $no++;
80
+ echo "<tr $style>\n<td>$no</td>\n";
81
+ echo "<td>$tablestatus->Name</td>\n";
82
+ echo "<td>".number_format($tablestatus->Rows)."</td>\n";
83
+ echo "<td>".format_size($tablestatus->Data_length)."</td>\n";
84
+ echo "<td>".format_size($tablestatus->Index_length)."</td>\n";
85
+ echo "<td>".format_size($tablestatus->Data_free)."</td>\n";
86
+ $row_usage += $tablestatus->Rows;
87
+ $data_usage += $tablestatus->Data_length;
88
+ $index_usage += $tablestatus->Index_length;
89
+ $overhead_usage += $tablestatus->Data_free;
90
+ }
91
+ echo "<tr><th align=\"left\" scope=\"row\">Total:</th>\n";
92
+ echo "<th align=\"left\" scope=\"row\">$no Tables</th>\n";
93
+ echo "<th align=\"left\" scope=\"row\">".number_format($row_usage)."</th>\n";
94
+ echo "<th align=\"left\" scope=\"row\">".format_size($data_usage)."</th>\n";
95
+ echo "<th align=\"left\" scope=\"row\">".format_size($index_usage)."</th>";
96
+ echo "<th align=\"left\" scope=\"row\">".format_size($overhead_usage)."</th></tr>";
97
+ } else {
98
+ echo '<tr><td colspan="6" align="center"><b>Could Not Show Table Status Due To Your MYSQL Version Is Lower Than 3.23.</b></td></tr>';
99
+ }
100
+ ?>
101
+ </table>
102
+ </div>
dbmanager/database-optimize.php ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ +----------------------------------------------------------------+
4
+ | |
5
+ | WordPress 2.0 Plugin: WP-DBManager 2.04 |
6
+ | Copyright (c) 2005 Lester "GaMerZ" Chan |
7
+ | |
8
+ | File Written By: |
9
+ | - Lester "GaMerZ" Chan |
10
+ | - http://www.lesterchan.net |
11
+ | |
12
+ | File Information: |
13
+ | - Database Optimize |
14
+ | - wp-content/plugins/dbmanager/database-optimize.php |
15
+ | |
16
+ +----------------------------------------------------------------+
17
+ */
18
+
19
+
20
+ ### Require Database Config
21
+ require('database-config.php');
22
+
23
+
24
+ ### Form Processing
25
+ if($_POST['do']) {
26
+ // Lets Prepare The Variables
27
+ $optimize = $_POST['optimize'];
28
+
29
+ // Decide What To Do
30
+ switch($_POST['do']) {
31
+ case 'Optimize':
32
+ if(!empty($optimize)) {
33
+ foreach($optimize as $key => $value) {
34
+ if($value == 'yes') {
35
+ $tables_string .= ', '.$key;
36
+ }
37
+ }
38
+ } else {
39
+ $text = '<font color="red">No Tables Selected</font>';
40
+ }
41
+ $selected_tables = substr($tables_string, 2);
42
+ if(!empty($selected_tables)) {
43
+ $optimize2 = $wpdb->query("OPTIMIZE TABLE $selected_tables");
44
+ if(!$optimize2) {
45
+ $text = "<font color=\"red\">Table(s) '$selected_tables' NOT Optimized</font>";
46
+ } else {
47
+ $text = "<font color=\"green\">Table(s) '$selected_tables' Optimized</font>";
48
+ }
49
+ }
50
+ break;
51
+ }
52
+ }
53
+
54
+
55
+ ### Show Tables
56
+ $tables = $wpdb->get_results("SHOW TABLES");
57
+ ?>
58
+ <?php if(!empty($text)) { echo '<!-- Last Action --><div id="message" class="updated fade"><p>'.$text.'</p></div>'; } ?>
59
+ <!-- Optimize Database -->
60
+ <div class="wrap">
61
+ <h2>Optimize Database</h2>
62
+ <form action="<?php echo $_SERVER['REQUEST_URI']; ?>" method="post">
63
+ <table width="100%" cellspacing="3" cellpadding="3" border="0">
64
+ <tr>
65
+ <th align="left" scope="col">Tables</th>
66
+ <th align="left" scope="col">Options</th>
67
+ </tr>
68
+ <?php
69
+ foreach($tables as $dbtable) {
70
+ if($no%2 == 0) {
71
+ $style = 'style=\'background-color: #eee\'';
72
+ } else {
73
+ $style = 'style=\'background-color: none\'';
74
+ }
75
+ $no++;
76
+ $table_name = '$dbtable->Tables_in_'.DB_NAME;
77
+ eval("\$table_name = \"$table_name\";");
78
+ echo "<tr $style><th align=\"left\" scope=\"row\">$table_name</th>\n";
79
+ echo "<td><input type=\"radio\" name=\"optimize[$table_name]\" value=\"no\" />No&nbsp;&nbsp;<input type=\"radio\" name=\"optimize[$table_name]\" value=\"yes\" checked=\"checked\" />Yes</td></tr>";
80
+ }
81
+ ?>
82
+ <tr>
83
+ <td colspan="2" align="center">Database should be optimize once every month.</td>
84
+ </tr>
85
+ <tr>
86
+ <td colspan="2" align="center"><input type="submit" name="do" value="Optimize" class="button" />&nbsp;&nbsp;<input type="button" name="cancel" Value="<?php _e('Cancel'); ?>" class="button" onclick="javascript:history.go(-1)" /></td>
87
+ </tr>
88
+ </table>
89
+ </form>
90
+ </div>
dbmanager/database-run.php ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ +----------------------------------------------------------------+
4
+ | |
5
+ | WordPress 2.0 Plugin: WP-DBManager 2.04 |
6
+ | Copyright (c) 2005 Lester "GaMerZ" Chan |
7
+ | |
8
+ | File Written By: |
9
+ | - Lester "GaMerZ" Chan |
10
+ | - http://www.lesterchan.net |
11
+ | |
12
+ | File Information: |
13
+ | - Database Run Query |
14
+ | - wp-content/plugins/dbmanager/database-run.php |
15
+ | |
16
+ +----------------------------------------------------------------+
17
+ */
18
+
19
+
20
+ ### Require Database Config
21
+ require('database-config.php');
22
+
23
+
24
+ ### Form Processing
25
+ if($_POST['do']) {
26
+ // Decide What To Do
27
+ switch($_POST['do']) {
28
+ case 'Run':
29
+ $sql_queries2 = trim($_POST['sql_query']);
30
+ $totalquerycount = 0;
31
+ $successquery = 0;
32
+ if($sql_queries2) {
33
+ $sql_queries = array();
34
+ $sql_queries2 = explode("\n", $sql_queries2);
35
+ foreach($sql_queries2 as $sql_query2) {
36
+ $sql_query2 = trim(stripslashes($sql_query2));
37
+ $sql_query2 = preg_replace("/[\r\n]+/", '', $sql_query2);
38
+ if(!empty($sql_query2)) {
39
+ $sql_queries[] = $sql_query2;
40
+ }
41
+ }
42
+ if($sql_queries) {
43
+ foreach($sql_queries as $sql_query) {
44
+ if (preg_match("/^\\s*(insert|update|replace|delete|create|alter) /i",$sql_query)) {
45
+ $run_query = $wpdb->query($sql_query);
46
+ if(!$run_query) {
47
+ $text .= "<font color=\"red\">$sql_query</font><br />";
48
+ } else {
49
+ $successquery++;
50
+ $text .= "<font color=\"green\">$sql_query</font><br />";
51
+ }
52
+ $totalquerycount++;
53
+ } elseif (preg_match("/^\\s*(select|drop|show|grant) /i",$sql_query)) {
54
+ $text .= "<font color=\"red\">$sql_query</font><br />";
55
+ $totalquerycount++;
56
+ }
57
+ }
58
+ $text .= "<font color=\"blue\">$successquery/$totalquerycount Query(s) Executed Successfully</font>";
59
+ } else {
60
+ $text = "<font color=\"red\">Empty Query</font>";
61
+ }
62
+ } else {
63
+ $text = "<font color=\"red\">Empty Query</font>";
64
+ }
65
+ break;
66
+ }
67
+ }
68
+ ?>
69
+ <?php if(!empty($text)) { echo '<!-- Last Action --><div id="message" class="updated fade"><p>'.$text.'</p></div>'; } ?>
70
+ <!-- Run SQL Query -->
71
+ <div class="wrap">
72
+ <h2>Run SQL Query</h2>
73
+ <form action="<?php echo $_SERVER['REQUEST_URI']; ?>" method="post">
74
+ <p><b>Seperate Multiple Queries With A New Line</b><br /><font color="green">Use Only INSERT, UPDATE, REPLACE, DELETE, CREATE and ALTER statements.</font></p>
75
+ <p align="center"><textarea cols="120" rows="30" name="sql_query"></textarea></p>
76
+ <p align="center"><input type="submit" name="do" Value="Run" class="button" />&nbsp;&nbsp;<input type="button" name="cancel" Value="<?php _e('Cancel'); ?>" class="button" onclick="javascript:history.go(-1)" /></p>
77
+ <p>1. CREATE statement will return an error, which is perfectly normal due to the database class. To confirm that your table has been created check the Manage Database page.<br />2. UPDATE statement may return an error sometimes due to the newly updated value being the same as the previous value.<br />3. ALTER statement will return an error because there is no value returned.</p>
78
+ </form>
79
+ </div>
dbmanager/dbmanager.php ADDED
@@ -0,0 +1,156 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Plugin Name: WP-DBManager
4
+ Plugin URI: http://www.lesterchan.net/portfolio/programming.php
5
+ Description: Manages your Wordpress database. Allows you to optimizee, backup, restore, delete backup database and run selected queries.
6
+ Version: 2.04
7
+ Author: GaMerZ
8
+ Author URI: http://www.lesterchan.net
9
+ */
10
+
11
+
12
+ /* Copyright 2005 Lester Chan (email : gamerz84@hotmail.com)
13
+
14
+ This program is free software; you can redistribute it and/or modify
15
+ it under the terms of the GNU General Public License as published by
16
+ the Free Software Foundation; either version 2 of the License, or
17
+ (at your option) any later version.
18
+
19
+ This program is distributed in the hope that it will be useful,
20
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
21
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22
+ GNU General Public License for more details.
23
+
24
+ You should have received a copy of the GNU General Public License
25
+ along with this program; if not, write to the Free Software
26
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27
+ */
28
+
29
+
30
+ ### Function: Database Manager Menu
31
+ add_action('admin_menu', 'dbmanager_menu');
32
+ function dbmanager_menu() {
33
+ if (function_exists('add_menu_page')) {
34
+ add_menu_page(__('Database'), __('Database'), 'manage_database', 'dbmanager/database-manager.php');
35
+ }
36
+ if (function_exists('add_submenu_page')) {
37
+ add_submenu_page('dbmanager/database-manager.php', __('Backup DB'), __('Backup DB'), 'manage_database', 'dbmanager/database-backup.php');
38
+ add_submenu_page('dbmanager/database-manager.php', __('Manage Backup DB'), __('Manage Backup DB'), 'manage_database', 'dbmanager/database-manage.php');
39
+ add_submenu_page('dbmanager/database-manager.php', __('Optimize DB'), __('Optimize DB'), 'manage_database', 'dbmanager/database-optimize.php');
40
+ add_submenu_page('dbmanager/database-manager.php', __('Empty/Drop Tables'), __('Empty/Drop Tables'), 'manage_database', 'dbmanager/database-empty.php');
41
+ add_submenu_page('dbmanager/database-manager.php', __('Run SQL Query'), __('Run SQL Query'), 'manage_database', 'dbmanager/database-run.php');
42
+ add_submenu_page('dbmanager/database-manager.php', __('DB Options'), __('DB Options'), 'manage_database', 'dbmanager/dbmanager.php', 'dbmanager_options');
43
+ }
44
+ }
45
+
46
+
47
+ ### Function: Database Manager Role
48
+ add_action('activate_dbmanager/dbmanager.php', 'dbmanager_init');
49
+ function dbmanager_init() {
50
+ // Add Options
51
+ $backup_options = array();
52
+ $backup_options['mysqldumppath'] = 'mysqldump';
53
+ $backup_options['mysqlpath'] = 'mysql';
54
+ $backup_options['path'] = ABSPATH.'wp-content/backup-db';
55
+ add_option('dbmanager_options', $backup_options, 'WP-DBManager Options');
56
+
57
+ // Create Backup Folder
58
+ if(!is_dir(ABSPATH.'/wp-content/backup-db')) {
59
+ mkdir(ABSPATH.'/wp-content/backup-db');
60
+ }
61
+
62
+ // Set 'manage_database' Capabilities To Administrator
63
+ $role = get_role('administrator');
64
+ if(!$role->has_cap('manage_database')) {
65
+ $role->add_cap('manage_database');
66
+ }
67
+ }
68
+
69
+
70
+ ### Function: Download Database
71
+ add_action('init', 'download_database');
72
+ function download_database() {
73
+ if($_POST['do'] == 'Download' && !empty($_POST['database_file'])) {
74
+ if(strpos($_SERVER['HTTP_REFERER'], get_settings('siteurl').'/wp-admin/admin.php?page=dbmanager/database-manage.php') !== false) {
75
+ $backup_options = get_settings('dbmanager_options');
76
+ $file_path = $backup_options['path'].'/'.$_POST['database_file'];
77
+ header("Pragma: public");
78
+ header("Expires: 0");
79
+ header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
80
+ header("Content-Type: application/force-download");
81
+ header("Content-Type: application/octet-stream");
82
+ header("Content-Type: application/download");
83
+ header("Content-Disposition: attachment; filename=".basename($file_path).";");
84
+ header("Content-Transfer-Encoding: binary");
85
+ header("Content-Length: ".filesize($file_path));
86
+ @readfile($file_path);
87
+ }
88
+ exit();
89
+ }
90
+ }
91
+
92
+
93
+ ### Function: Database Options
94
+ function dbmanager_options() {
95
+ global $wpdb;
96
+ $text = '';
97
+ $backup_options = array();
98
+ $backup_options = get_settings('dbmanager_options');
99
+ if($_POST['Submit']) {
100
+ $backup_options['mysqldumppath'] = trim($_POST['db_mysqldumppath']);
101
+ $backup_options['mysqlpath'] = trim($_POST['db_mysqlpath']);
102
+ $backup_options['path'] = trim($_POST['db_path']);
103
+ $update_db_options = update_option('dbmanager_options', $backup_options);
104
+ if($update_db_options) {
105
+ $text = '<font color="green">'.__('DB Options Updated').'</font>';
106
+ }
107
+ if(empty($text)) {
108
+ $text = '<font color="red">'.__('No DB Option Updated').'</font>';
109
+ }
110
+ }
111
+ ?>
112
+ <?php if(!empty($text)) { echo '<!-- Last Action --><div id="message" class="updated fade"><p>'.$text.'</p></div>'; } ?>
113
+ <!-- Database Options -->
114
+ <div class="wrap">
115
+ <h2>Database Options</h2>
116
+ <form action="<?php echo $_SERVER['REQUEST_URI']; ?>" method="post">
117
+ <table width="100%" cellspacing="3" cellpadding="3" border="0">
118
+ <tr>
119
+ <td valign="top"><b>Path To mysqldump:</b></td>
120
+ <td>
121
+ <input type="text" name="db_mysqldumppath" size="100" maxlength="100" value="<?php echo stripslashes($backup_options['mysqldumppath']); ?>" /><br />The absolute path to mysqldump without trailing slash. If unsure, please email your server administrator about this.
122
+ </td>
123
+ </tr>
124
+ <tr>
125
+ <td valign="top"><b>Path To mysql:</b></td>
126
+ <td>
127
+ <input type="text" name="db_mysqlpath" size="100" maxlength="100" value="<?php echo stripslashes($backup_options['mysqlpath']); ?>" /><br />The absolute path to mysql without trailing slash. If unsure, please email your server administrator about this.
128
+ </td>
129
+ </tr>
130
+ <tr>
131
+ <td valign="top"><b>Path To Backup:</b></td>
132
+ <td>
133
+ <input type="text" name="db_path" size="100" maxlength="100" value="<?php echo stripslashes($backup_options['path']); ?>" />
134
+ <br />The absolute path to your database backup folder without trailing slash. Make sure the folder is writable.
135
+ </td>
136
+ </tr>
137
+ <tr>
138
+ <td width="100%" colspan="2">
139
+ <p class="submit"><input type="submit" name="Submit" value="<?php _e('Update Options'); ?> &raquo;" /></p>
140
+ </td>
141
+ </tr>
142
+ </table>
143
+ </form>
144
+ <p>
145
+ <b>Windows Server</b><br />
146
+ For mysqldump path, you can try '<b>mysqldump.exe</b>'.<br />
147
+ For mysql path, you can try '<b>mysql.exe</b>'.<br />
148
+ <br />
149
+ <b>Linux Server</b><br />
150
+ For mysqldump path, normally is just '<b>mysqldump</b>'.<br />
151
+ For mysql path, normally is just '<b>mysql</b>'.<br />
152
+ </p>
153
+ </div>
154
+ <?php
155
+ }
156
+ ?>
readme-install.txt ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ -> Installation Instructions
2
+ --------------------------------------------------
3
+ // Open wp-content/plugins folder
4
+
5
+ Put:
6
+ ------------------------------------------------------------------
7
+ Folder: dbmanager
8
+ ------------------------------------------------------------------
9
+
10
+
11
+ // Activate WP-DBManager Plugin
12
+
13
+
14
+ // Open wp-content/backup-db folder
15
+
16
+ Put:
17
+ ------------------------------------------------------------------
18
+ .htaccess
19
+ ------------------------------------------------------------------
20
+
21
+ Note:
22
+ ------------------------------------------------------------------
23
+ The script will automatically create a folder called 'backup-db'
24
+ in 'wp-content' folder if that folder is writable. If it is not created,
25
+ please create it and CHMOD it to 777
26
+ ------------------------------------------------------------------
readme-upgrade.txt ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ -> Upgrade Instructions For Version 2.02+ To Version 2.04
2
+ ------------------------------------------------------------------
3
+ // Open wp-content/plugins folder
4
+
5
+ Overwrite:
6
+ ------------------------------------------------------------------
7
+ Folder: dbmanager
8
+ ------------------------------------------------------------------
9
+
10
+
11
+
12
+
13
+
14
+ -> Upgrade Instructions For Version 1.0x To Version 2.02
15
+ ------------------------------------------------------------------
16
+ // Deactivate WP-DBManager plugin
17
+
18
+
19
+ // Delete these file if exists
20
+
21
+ Delete:
22
+ ------------------------------------------------------------------
23
+ wp-admin/database-manager.php
24
+ wp-content/plugins/dbmanager.php
25
+ ------------------------------------------------------------------
26
+
27
+
28
+ // Open wp-content/plugins folder
29
+
30
+ Put:
31
+ ------------------------------------------------------------------
32
+ Folder: dbmanager
33
+ ------------------------------------------------------------------
34
+
35
+
36
+ // Activate WP-DBManager Plugin
37
+
38
+
39
+ // Open wp-content/backup-db folder
40
+
41
+ Put:
42
+ ------------------------------------------------------------------
43
+ .htaccess
44
+ ------------------------------------------------------------------
45
+
46
+ Note:
47
+ ------------------------------------------------------------------
48
+ The script will automatically create a folder called 'backup-db'
49
+ in 'wp-content' folder if that folder is writable. If it is not created,
50
+ please create it and CHMOD it to 777
51
+ ------------------------------------------------------------------
readme.txt ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ -> Database Manager For WordPress 2.0
2
+ --------------------------------------------------
3
+ Author -> Lester 'GaMerZ' Chan
4
+ Email -> lesterch@singnet.com.sg
5
+ Website -> http://www.lesterchan.net/
6
+ Demo -> N/A
7
+ Documentation -> http://dev.wp-plugins.org/wiki/wp-dbmanager
8
+ Development -> http://dev.wp-plugins.org/browser/wp-dbmanager/
9
+ Updated -> 10th May 2006
10
+ --------------------------------------------------
11
+
12
+
13
+ // Version 2.04 (10-05-2006)
14
+ - FIXED: Unable To Download Backup DB Due To Header Sent Error
15
+ - FIXED: Some XHTML Code Fixes
16
+
17
+ // Version 2.03 (01-04-2006)
18
+ - FIXED: Run Query Box Too Big
19
+ - FIXED: Header Sent Error
20
+ - FIXED: Extra Slashes For Mysql/Mysql Dump Path
21
+ - FIXED: Mismatch Date Due To GMT
22
+
23
+ // Version 2.02 (01-03-2006)
24
+ - NEW: Improved On 'manage_database' Capabilities
25
+ - NEW: Added GigaBytes To File Size
26
+ - NEW: Added ALTER Statement To Allowed Queries
27
+ - NEW: Able To Empty/Drop Tables
28
+ - NEW: Able To EMail Database Backup File
29
+ - NEW: Splitted database-manager.php Into Individual Files
30
+ - NEW: Merge Restore And Delete Backup Database
31
+ - NEW: Included .htaccess File To Protect Backup Folder
32
+ - NEW: Checking Of Backup Status
33
+ - FIXED: Using Old Method To Add Submenu
34
+ - FIXED: PHP Short Tags
35
+ - FIXED: Redirect Back To The Same Page Instead Of Manage Database Page After Submitting Form
36
+
37
+ // Version 2.01 (01-02-2006)
38
+ - NEW: Added 'manage_database' Capabilities To Administrator Role
39
+
40
+ // Version 2.00 (01-01-2006)
41
+ - NEW: Compatible With WordPress 2.0
42
+ - NEW: GPL License Added