WP-DBManager - Version 2.02

Version Description

Download this release

Release Info

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

Version 2.02

.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,196 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ +----------------------------------------------------------------+
4
+ | |
5
+ | WordPress 2.0 Plugin: WP-DBManager 2.02 |
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
+
24
+ ### Form Processing
25
+ if($_POST['do']) {
26
+ // Decide What To Do
27
+ switch($_POST['do']) {
28
+ case 'Backup':
29
+ $gzip = intval($_POST['gzip']);
30
+ if($gzip == 1) {
31
+ $backup['filename'] = $backup['date'].'_-_'.DB_NAME.'.sql.gz';
32
+ $backup['filepath'] = $backup['path'].'/'.$backup['filename'];
33
+ $backup['command'] = $backup['mysqldumppath'].' --host='.DB_HOST.' --user='.DB_USER.' --password='.DB_PASSWORD.' --add-drop-table '.DB_NAME.' | gzip > '.$backup['filepath'];
34
+ } else {
35
+ $backup['filename'] = $backup['date'].'_-_'.DB_NAME.'.sql';
36
+ $backup['filepath'] = $backup['path'].'/'.$backup['filename'];
37
+ $backup['command'] = $backup['mysqldumppath'].' --host='.DB_HOST.' --user='.DB_USER.' --password='.DB_PASSWORD.' --add-drop-table '.DB_NAME.' > '.$backup['filepath'];
38
+ }
39
+ passthru($backup['command'], $error);
40
+ if(!is_writable($backup['path'])) {
41
+ $text = "<font color=\"red\">Database Failed To Backup On '".date('l, jS F Y @ H:i')."'. Backup Folder Not Writable</font>";
42
+ } elseif(filesize($backup['filepath']) == 0) {
43
+ unlink($backup['filepath']);
44
+ $text = "<font color=\"red\">Database Failed To Backup On '".date('l, jS F Y @ H:i')."'. Backup File Size Is 0KB</font>";
45
+ } elseif(!is_file($backup['filepath'])) {
46
+ $text = "<font color=\"red\">Database Failed To Backup On '".date('l, jS F Y @ H:i')."'. Invalid Backup File Path</font>";
47
+ } elseif($error) {
48
+ $text = "<font color=\"red\">Database Failed To Backup On '".date('l, jS F Y @ H:i')."'</font>";
49
+ } else {
50
+ $text = "<font color=\"green\">Database Backed Up Successfully On '".date('l, jS F Y @ H:i')."'</font>";
51
+ }
52
+ break;
53
+ }
54
+ }
55
+
56
+
57
+ ### Backup File Name
58
+ $backup['filename'] = $backup['date'].'_-_'.DB_NAME.'.sql';
59
+
60
+
61
+ ### MYSQL Base Dir
62
+ $mysql_basedir = $wpdb->get_row("SHOW VARIABLES LIKE 'basedir'");
63
+ $mysql_basedir = $mysql_basedir->Value;
64
+ if($mysql_basedir == '/') { $mysql_basedir = '/usr/'; }
65
+ $status_count = 0;
66
+ $stats_function_disabled = 0;
67
+ ?>
68
+ <?php if(!empty($text)) { echo '<!-- Last Action --><div id="message" class="updated fade"><p>'.$text.'</p></div>'; } ?>
69
+ <!-- Checking Backup Status -->
70
+ <div class="wrap">
71
+ <h2>Checking Backup Status</h2>
72
+ <p>
73
+ Checking Backup Folder (<b><?php echo $backup['path']; ?></b>) ...<br />
74
+ <?php
75
+ if(is_dir($backup['path'])) {
76
+ echo '<font color="green">Backup folder exists</font><br />';
77
+ $status_count++;
78
+ } else {
79
+ 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 />';
80
+ }
81
+ if(is_writable($backup['path'])) {
82
+ echo '<font color="green">Backup folder is writable</font>';
83
+ $status_count++;
84
+ } else {
85
+ echo '<font color="red">Backup folder is NOT writable. Please CHMOD it to \'777\'.</font>';
86
+ }
87
+ ?>
88
+ </p>
89
+ <p>
90
+ <?php
91
+ if(file_exists($mysql_basedir.'bin/'.$backup['mysqldumppath'])) {
92
+ echo 'Checking MYSQL Dump Path (<b>'.$mysql_basedir.'bin/'.$backup['mysqldumppath'].'</b>) ...<br />';
93
+ echo '<font color="green">MYSQL dump path exists.</font>';
94
+ $status_count++;
95
+ } else if(file_exists($backup['mysqldumppath'])) {
96
+ echo 'Checking MYSQL Dump Path (<b>'.$backup['mysqldumppath'].'</b>) ...<br />';
97
+ echo '<font color="green">MYSQL dump path exists.</font>';
98
+ $status_count++;
99
+ } else {
100
+ echo 'Checking MYSQL Dump Path ...<br />';
101
+ 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>';
102
+ }
103
+ ?>
104
+ </p>
105
+ <p>
106
+ <?php
107
+ if(file_exists($mysql_basedir.'bin/'.$backup['mysqlpath'])) {
108
+ echo 'Checking MYSQL Path (<b>'.$mysql_basedir.'bin/'.$backup['mysqlpath'].'</b>) ...<br />';
109
+ echo '<font color="green">MYSQL path exists.</font>';
110
+ $status_count++;
111
+ } else if(file_exists($backup['mysqlpath'])) {
112
+ echo 'Checking MYSQL Path (<b>'.$backup['mysqlpath'].'</b>) ...<br />';
113
+ echo '<font color="green">MYSQL path exists.</font>';
114
+ $status_count++;
115
+ } else {
116
+ echo 'Checking MYSQL Path ...<br />';
117
+ echo '<font color="red">MYSQL path does NOT exist. Please check your mysql path under DB Options. If uncertain, contact your server administrator.</font>';
118
+ }
119
+ ?>
120
+ </p>
121
+ <p>
122
+ Checking PHP Functions (<b>passthru()</b>, <b>system()</b> and <b>exec()</b>) ...<br />
123
+ <?php
124
+ if(function_exists('passthru')) {
125
+ echo '<font color="green">passthru() enabled.</font><br />';
126
+ $status_count++;
127
+ } else {
128
+ echo '<font color="red">passthru() disabled.</font><br />';
129
+ $stats_function_disabled++;
130
+ }
131
+ if(function_exists('system')) {
132
+ echo '<font color="green">system() enabled.</font><br />';
133
+ } else {
134
+ echo '<font color="red">system() disabled.</font><br />';
135
+ $stats_function_disabled++;
136
+ }
137
+ if(function_exists('exec')) {
138
+ echo '<font color="green">exec() enabled.</font>';
139
+ } else {
140
+ echo '<font color="red">exec() disabled.</font>';
141
+ $stats_function_disabled++;
142
+ }
143
+ ?>
144
+ </p>
145
+ <p>
146
+ <?php
147
+ if($status_count == 5) {
148
+ echo '<b><font color="green">Excellent. You Are Good To Go.</font></b>';
149
+ } else if($stats_function_disabled == 3) {
150
+ 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>';
151
+ } else {
152
+ echo '<b><font color="red">Please Rectify The Error Highlighted In Red Before Proceeding On.</font></b>';
153
+ }
154
+ ?>
155
+ </p>
156
+ <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>
157
+ </div>
158
+ <!-- Backup Database -->
159
+ <div class="wrap">
160
+ <h2>Backup Database</h2>
161
+ <form action="<?php echo $_SERVER['REQUEST_URI']; ?>" method="post">
162
+ <table width="100%" cellspacing="3" cellpadding="3" border="0">
163
+ <tr style='background-color: #eee'>
164
+ <th align="left" scope="row">Database Name:</th>
165
+ <td><?php echo DB_NAME; ?></td>
166
+ </tr>
167
+ <tr style='background-color: none'>
168
+ <th align="left" scope="row">Database Backup To:</th>
169
+ <td><?php echo $backup['path']; ?></td>
170
+ </tr>
171
+ <tr style='background-color: #eee'>
172
+ <th align="left" scope="row">Database Backup Date:</th>
173
+ <td><?php echo date('jS F Y', $backup['date']); ?></td>
174
+ </tr>
175
+ <tr style='background-color: none'>
176
+ <th align="left" scope="row">Database Backup File Name:</th>
177
+ <td><?php echo $backup['filename']; ?></td>
178
+ </tr>
179
+ <tr style='background-color: #eee'>
180
+ <th align="left" scope="row">Database Backup Type:</th>
181
+ <td>Full (Structure and Data)</td>
182
+ </tr>
183
+ <tr style='background-color: none'>
184
+ <th align="left" scope="row">MYSQL Dump Location:</th>
185
+ <td><?php echo $backup['mysqldumppath']; ?></td>
186
+ </tr>
187
+ <tr style='background-color: #eee'>
188
+ <th align="left" scope="row">GZIP Database Backup File?</th>
189
+ <td><input type="radio" name="gzip" value="1">Yes&nbsp;&nbsp;<input type="radio" name="gzip" value="0" checked="checked" />No</td>
190
+ </tr>
191
+ <tr>
192
+ <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>
193
+ </tr>
194
+ </table>
195
+ </form>
196
+ </div>
dbmanager/database-config.php ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ +----------------------------------------------------------------+
4
+ | |
5
+ | WordPress 2.0 Plugin: WP-DBManager 2.02 |
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
+ $backup = array();
30
+ $backup_options = get_settings('dbmanager_options');
31
+ $backup['date'] = current_time('timestamp');
32
+ $backup['mysqldumppath'] = $backup_options['mysqldumppath'];
33
+ $backup['mysqlpath'] = $backup_options['mysqlpath'];
34
+ $backup['path'] = $backup_options['path'];
35
+
36
+
37
+ ### Format Bytes Into KB/MB
38
+ function format_size($rawSize) {
39
+ if($rawSize / 1073741824 > 1)
40
+ return round($rawSize/1048576, 1) . ' GB';
41
+ else if ($rawSize / 1048576 > 1)
42
+ return round($rawSize/1048576, 1) . ' MB';
43
+ else if ($rawSize / 1024 > 1)
44
+ return round($rawSize/1024, 1) . ' KB';
45
+ else
46
+ return round($rawSize, 1) . ' bytes';
47
+ }
48
+
49
+
50
+ ### Get File Extension
51
+ function file_ext($file_name) {
52
+ return substr(strrchr($file_name, '.'), 1);
53
+ }
54
+
55
+
56
+ ### Check Folder Whether There Is Any File Inside
57
+ function is_emtpy_folder($folder){
58
+ if(is_dir($folder) ){
59
+ $handle = opendir($folder);
60
+ while( (gettype( $name = readdir($handle)) != 'boolean')){
61
+ $name_array[] = $name;
62
+ }
63
+ foreach($name_array as $temp)
64
+ $folder_content .= $temp;
65
+
66
+ if($folder_content == '...')
67
+ return true;
68
+ else
69
+ return false;
70
+ closedir($handle);
71
+ }
72
+ else
73
+ return true; // folder doesnt exist
74
+ }
75
+ ?>
dbmanager/database-empty.php ADDED
@@ -0,0 +1,97 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ +----------------------------------------------------------------+
4
+ | |
5
+ | WordPress 2.0 Plugin: WP-DBManager 2.02 |
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,207 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ +----------------------------------------------------------------+
4
+ | |
5
+ | WordPress 2.0 Plugin: WP-DBManager 2.02 |
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('../../../wp-config.php');
23
+ require(ABSPATH.'wp-admin/admin.php');
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 = date('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 = date('jS F Y', 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
+ header('Location: '.get_settings('siteurl').'/wp-content/plugins/dbmanager/database-manage.php?file='.$database_file);
120
+ } else {
121
+ $text = '<font color="red">No Backup Database File Selected</font>';
122
+ }
123
+ break;
124
+ case 'Delete':
125
+ if(!empty($database_file)) {
126
+ $nice_file_date = date('l, jS F Y @ H:i', substr($database_file, 0, 10));
127
+ if(is_file($backup['path'].'/'.$database_file)) {
128
+ if(!unlink($backup['path'].'/'.$database_file)) {
129
+ $text .= "<font color=\"red\">Unable To Delete Database Backup File On '$nice_file_date'</font><br />";
130
+ } else {
131
+ $text .= "<font color=\"green\">Database Backup File On '$nice_file_date' Deleted Successfully</font><br />";
132
+ }
133
+ } else {
134
+ $text = "<font color=\"red\">Invalid Database Backup File On '$nice_file_date'</font>";
135
+ }
136
+ } else {
137
+ $text = '<font color="red">No Backup Database File Selected</font>';
138
+ }
139
+ break;
140
+ }
141
+ }
142
+ ?>
143
+ <?php if(!empty($text)) { echo '<!-- Last Action --><div id="message" class="updated fade"><p>'.$text.'</p></div>'; } ?>
144
+ <!-- Manage Backup Database -->
145
+ <div class="wrap">
146
+ <h2>Manage Backup Database</h2>
147
+ <form action="<?php echo $_SERVER['REQUEST_URI']; ?>" method="post">
148
+ <table width="100%" cellspacing="3" cellpadding="3" border="0">
149
+ <tr>
150
+ <th align="left" scope="row" colspan="5">Choose A Backup Date To E-Mail, Restore, Download Or Delete</th>
151
+ </tr>
152
+ <tr>
153
+ <th align="left" scope="col">No.</th>
154
+ <th align="left" scope="col">Database File</th>
155
+ <th align="left" scope="col">Date/Time</th>
156
+ <th align="left" scope="col">Size</th>
157
+ <th align="left" scope="col">Select</th>
158
+ </tr>
159
+ <?php
160
+ if(!is_emtpy_folder($backup['path'])) {
161
+ if ($handle = opendir($backup['path'])) {
162
+ $database_files = array();
163
+ while (false !== ($file = readdir($handle))) {
164
+ if ($file != '.' && $file != '..' && (file_ext($file) == 'sql' || file_ext($file) == 'gz')) {
165
+ $database_files[] = $file;
166
+ }
167
+ }
168
+ closedir($handle);
169
+ for($i = (sizeof($database_files)-1); $i > -1; $i--) {
170
+ if($no%2 == 0) {
171
+ $style = 'style=\'background-color: #eee\'';
172
+ } else {
173
+ $style = 'style=\'background-color: none\'';
174
+ }
175
+ $no++;
176
+ $database_text = substr($database_files[$i], 13);
177
+ $date_text = date('l, jS F Y @ H:i', substr($database_files[$i], 0, 10));
178
+ $size_text = filesize($backup['path'].'/'.$database_files[$i]);
179
+ echo "<tr $style>\n<td>$no</td>";
180
+ echo "<td>$database_text</td>";
181
+ echo "<td>$date_text</td>";
182
+ echo '<td>'.format_size($size_text).'</td>';
183
+ echo "<td><input type=\"radio\" name=\"database_file\" value=\"$database_files[$i]\" /></td>\n</tr>\n";
184
+ $totalsize += $size_text;
185
+ }
186
+ } else {
187
+ echo '<tr><td align="center" colspan="5">There Are No Database Backup Files Available</td></tr>';
188
+ }
189
+ } else {
190
+ echo '<tr><td align="center" colspan="5">There Are No Database Backup Files Available</td></tr>';
191
+ }
192
+ ?>
193
+ </tr>
194
+ <tr>
195
+ <th align="left" colspan="3"><?php echo $no; ?> Backup File(s)</th>
196
+ <th align="left"><?php echo format_size($totalsize); ?></th>
197
+ <td>&nbsp;</td>
198
+ </tr>
199
+ <tr>
200
+ <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>
201
+ </tr>
202
+ <tr>
203
+ <td colspan="5" align="center"><input type="submit" name="do" value="Download" class="button" />&nbsp;&nbsp;<input type="submit" class="button" 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>
204
+ </tr>
205
+ </table>
206
+ </form>
207
+ </div>
dbmanager/database-manager.php ADDED
@@ -0,0 +1,102 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ +----------------------------------------------------------------+
4
+ | |
5
+ | WordPress 2.0 Plugin: WP-DBManager 2.02 |
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.02 |
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.02 |
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="150" 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.</font></p>
78
+ </form>
79
+ </div>
dbmanager/dbmanager.php ADDED
@@ -0,0 +1,133 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.02
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: Database Options
71
+ function dbmanager_options() {
72
+ global $wpdb;
73
+ $text = '';
74
+ $backup_options = array();
75
+ $backup_options = get_settings('dbmanager_options');
76
+ if($_POST['Submit']) {
77
+ $backup_options['mysqldumppath'] = trim($_POST['db_mysqldumppath']);
78
+ $backup_options['mysqlpath'] = trim($_POST['db_mysqlpath']);
79
+ $backup_options['path'] = trim($_POST['db_path']);
80
+ $update_db_options = update_option('dbmanager_options', $backup_options);
81
+ if($update_db_options) {
82
+ $text = '<font color="green">'.__('DB Options Updated').'</font>';
83
+ }
84
+ if(empty($text)) {
85
+ $text = '<font color="red">'.__('No DB Option Updated').'</font>';
86
+ }
87
+ }
88
+ ?>
89
+ <?php if(!empty($text)) { echo '<!-- Last Action --><div id="message" class="updated fade"><p>'.$text.'</p></div>'; } ?>
90
+ <!-- Database Options -->
91
+ <div class="wrap">
92
+ <h2>Database Options</h2>
93
+ <form action="<?php echo $_SERVER['REQUEST_URI']; ?>" method="post">
94
+ <table width="100%" cellspacing="3" cellpadding="3" border="0">
95
+ <tr>
96
+ <td valign="top"><b>Path To mysqldump:</b></td>
97
+ <td>
98
+ <input type="text" name="db_mysqldumppath" size="100" maxlength="100" value="<?php echo $backup_options['mysqldumppath']; ?>" /><br />The absolute path to mysqldump without trailing slash. If unsure, please email your server administrator about this.
99
+ </td>
100
+ </tr>
101
+ <tr>
102
+ <td valign="top"><b>Path To mysql:</b></td>
103
+ <td>
104
+ <input type="text" name="db_mysqlpath" size="100" maxlength="100" value="<?php echo $backup_options['mysqlpath']; ?>" /><br />The absolute path to mysql without trailing slash. If unsure, please email your server administrator about this.
105
+ </td>
106
+ </tr>
107
+ <tr>
108
+ <td valign="top"><b>Path To Backup:</b></td>
109
+ <td>
110
+ <input type="text" name="db_path" size="100" maxlength="100" value="<?php echo $backup_options['path']; ?>" />
111
+ <br />The absolute path to your database backup folder without trailing slash. Make sure the folder is writable.
112
+ </td>
113
+ </tr>
114
+ <tr>
115
+ <td width="100%" colspan="2">
116
+ <p class="submit"><input type="submit" name="Submit" value="<?php _e('Update Options'); ?> &raquo;" /></p>
117
+ </td>
118
+ </tr>
119
+ </table>
120
+ </form>
121
+ <p>
122
+ <b>Windows Server</b><br />
123
+ For mysqldump path, you can try '<b>mysqldump.exe</b>'.<br />
124
+ For mysql path, you can try '<b>mysql.exe</b>'.<br />
125
+ <br />
126
+ <b>Linux Server</b><br />
127
+ For mysqldump path, normally is just '<b>mysqldump</b>'.<br />
128
+ For mysql path, normally is just '<b>mysql</b>'.<br />
129
+ </p>
130
+ </div>
131
+ <?php
132
+ }
133
+ ?>
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,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ -> Upgrade Instructions For Version 1.0x To Version 2.02
2
+ ------------------------------------------------------------------
3
+ // Deactivate WP-DBManager plugin
4
+
5
+
6
+ // Delete these file if exists
7
+
8
+ Delete:
9
+ ------------------------------------------------------------------
10
+ wp-admin/database-manager.php
11
+ wp-content/plugins/dbmanager.php
12
+ ------------------------------------------------------------------
13
+
14
+
15
+ // Open wp-content/plugins folder
16
+
17
+ Put:
18
+ ------------------------------------------------------------------
19
+ Folder: dbmanager
20
+ ------------------------------------------------------------------
21
+
22
+
23
+ // Activate WP-DBManager Plugin
24
+
25
+
26
+ // Open wp-content/backup-db folder
27
+
28
+ Put:
29
+ ------------------------------------------------------------------
30
+ .htaccess
31
+ ------------------------------------------------------------------
32
+
33
+ Note:
34
+ ------------------------------------------------------------------
35
+ The script will automatically create a folder called 'backup-db'
36
+ in 'wp-content' folder if that folder is writable. If it is not created,
37
+ please create it and CHMOD it to 777
38
+ ------------------------------------------------------------------
readme.txt ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 -> 1st March 2006
10
+ --------------------------------------------------
11
+
12
+
13
+ // Version 2.02 (01-03-2006)
14
+ - NEW: Improved On 'manage_database' Capabilities
15
+ - NEW: Added GigaBytes To File Size
16
+ - NEW: Added ALTER Statement To Allowed Queries
17
+ - NEW: Able To Empty/Drop Tables
18
+ - NEW: Able To EMail Database Backup File
19
+ - NEW: Splitted database-manager.php Into Individual Files
20
+ - NEW: Merge Restore And Delete Backup Database
21
+ - NEW: Included .htaccess File To Protect Backup Folder
22
+ - NEW: Checking Of Backup Status
23
+ - FIXED: Using Old Method To Add Submenu
24
+ - FIXED: PHP Short Tags
25
+ - FIXED: Redirect Back To The Same Page Instead Of Manage Database Page After Submitting Form
26
+
27
+ // Version 2.01 (01-02-2006)
28
+ - NEW: Added 'manage_database' Capabilities To Administrator Role
29
+
30
+ // Version 2.00 (01-01-2006)
31
+ - NEW: Compatible With WordPress 2.0
32
+ - NEW: GPL License Added