/var/www/(Del)hsihk.com/wp-content/plugins/backupbuddy/classes/_rollback_undo.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
<?php
/* BackupBuddy script to undo a database rollback procedure if it has failed.
 * Access this script in your web browser to undo a rollback.
 *
 * @author Dustin Bolton, January 2014.
 * @url http://ithemes.com
 *
 * NOTES:
 *     -- This will only seek out wp-config.php in the current DIR or up one level. If this file is not in the root then it is innert.
 *     -- No user-editable variables within. No user-submitted data is used for any processing.
 */

// DIE if accessing this file directly in BackupBuddy.
if ( false === striposbasename__FILE__ ), '-' ) ) {
    die();
}
?>

<style>
    body {
        font-family: "Open Sans",sans-serif;
        font-weight: lighter;
    }
    h1 {
        color: #444;
    }
</style>

<script>
    var win = window.dialogArguments || opener || parent || top;
    win.window.scrollTo(0,0);
</script>

<?php
$abspath 
rtrimdirname__FILE__ ), '\\/' ) . '/';
define'ABSPATH'$abspath );


if ( ! isset( 
$_GET['confirm'] ) || ( '1' != $_GET['confirm'] ) ) { // Do rollback since user confirmed.
    
echo 'Are you sure you want to undo these latest database changes? <a href="?confirm=1">Click here to confirm.</a>';
    echo 
'<br><br>';
    echo 
'If you do not want to undo the changes you may safely delete this file, ' basename__FILE__ ) . '.';
    die();
}


// Determine database connection information and connect to DB.
$configFile '';
if ( ! 
file_existsABSPATH 'wp-config.php' ) ) { // Normal config file not found so warn or see if parent config may exist.
    
$parentConfig =  dirnameABSPATH ) . '/wp-config.php';
    if ( @
file_exists$parentConfig ) ) { // Parent config exists so offer it as an option or possibly use it if user has selected to do so.
        
if ( pb_backupbuddy::_GET'parent_config' ) == 'true' ) { // User opted to use parent config.
            
$configFile $parentConfig;
        }
    }
    unset( 
$parentConfig );
} else { 
// Use normal config file.
    
$configFile ABSPATH 'wp-config.php';
}
if ( 
'' == $configFile ) {
    die( 
'Error #4534434: wp-config.php file not found.' );
}
// Read in wp-config.php file contents.
$configContents file_get_contents$configFile );
if ( 
false === $configContents ) {
    
pb_backupbuddy::alert'Error: Unable to read wp-config.php configuration file.' );
    return;
}

// Grab database settings from wp-config.php contents.
$databaseSettings = array();
preg_match'/define\([\s]*(\'|")DB_NAME(\'|"),[\s]*(\'|")(.*)(\'|")[\s]*\);/i'$configContents$matches );
$databaseSettings['name'] = $matches[4];
preg_match'/define\([\s]*(\'|")DB_USER(\'|"),[\s]*(\'|")(.*)(\'|")[\s]*\);/i'$configContents$matches );
$databaseSettings['username'] = $matches[4];
preg_match'/define\([\s]*(\'|")DB_PASSWORD(\'|"),[\s]*(\'|")(.*)(\'|")[\s]*\);/i'$configContents$matches );
$databaseSettings['password'] = $matches[4];
preg_match'/define\([\s]*(\'|")DB_HOST(\'|"),[\s]*(\'|")(.*)(\'|")[\s]*\);/i'$configContents$matches );
$databaseSettings['host'] = $matches[4];
preg_match'/\$table_prefix[\s]*=[\s]*(\'|")(.*)(\'|");/i'$configContents$matches );
$databaseSettings['prefix'] = $matches[2];
// Connect to DB.
@mysql_connect$databaseSettings['host'], $databaseSettings['username'], $databaseSettings['password'] ) or die( 'Error #45543434: Unable to connect to database based on wp-config.php settings.' );
@
mysql_select_db$databaseSettings['name'] ) or die( 'Error #5484584: Unable to select database based on wp-config.php settings.' );

$serial str_replace'.php'''str_replace'backupbuddy_rollback_undo-'''basename__FILE__ ) ) );



// Enable Maintenance Mode if not already.
if ( ! file_existsABSPATH '.maintenance' ) ) {
    @
file_put_contentsABSPATH '.maintenance'"<?php die( 'Site undergoing maintenance.' ); ?>" );
}



// Find tables matching temp OLD (original live tables) prefix.
$tempPrefix 'BBold-' substr$serial0) . '_';
$sql "SELECT table_name FROM information_schema.tables WHERE table_name LIKE '" str_replace'_''\_'$tempPrefix ) . "%' AND table_schema = DATABASE()";
if ( 
false === ( $tempTables mysql_query$sql ) ) ) {
    echo 
'Error #89294: `' mysql_error() . '` in SQL `' $sql '`.<br>';
    die();
}

// Loop through all BBold-SERIAL_ tables, renaming them back to live, deleting collisions as they occur.
while( $tempTable mysql_fetch_row$tempTables ) ) {
    
$nonTempName str_replace$tempPrefix''$tempTable[0] );

    
// CHECK if $nonTempName table exists in db. If it does then DROP the table.
    
if ( false === ( $result mysql_query"SELECT table_name FROM information_schema.tables WHERE table_name LIKE '" str_replace'_''\_'$nonTempName ) . "%' AND table_schema = DATABASE()" ) ) ) {
        echo 
'Error #89294: `' mysql_error() . '`.<br>';
    }
    if ( 
mysql_num_rows$result ) > ) { // WordPress EXISTS already. Collision.
        
if ( false === mysql_query("DROP TABLE `" mysql_real_escape_string$nonTempName ) . "`") ) {
            echo 
'Error #24873: `' mysql_error() . '`.<br>';
        }
    }
    unset( 
$result );

    
// RENAME $tempTable to $nonTempName
    
$sql "RENAME TABLE `" mysql_real_escape_string$tempTable[0] ) . "` TO `" mysql_real_escape_string$nonTempName ) . "`";
    
//echo $sql . '<br>';
    
$result mysql_query$sql );
    if ( 
false === $result ) { // Failed.
        
echo 'Error #54924: `' mysql_error() . '`.<br>';
    }
}



// Drop any remaining temporary just-imported tables.
$tempPrefix 'BBnew-' substr$serial0) . '_';
$sql "SELECT table_name FROM information_schema.tables WHERE table_name LIKE '" str_replace'_''\_'$tempPrefix ) . "%' AND table_schema = DATABASE()";
if ( 
false === ( $tempTables mysql_query$sql ) ) ) {
    echo 
'Error #89294: `' mysql_error() . '` in SQL `' $sql '`.<br>';
    die();
}
// Loop through all BBnew-SERIAL_ tables, dropping.
while( $tempTable mysql_fetch_row$tempTables ) ) {
    if ( 
false === mysql_query("DROP TABLE `" mysql_real_escape_string$tempTable[0] ) . "`") ) {
        echo 
'Error #24873: `' mysql_error() . '`.<br>';
    }
}



// Turn OFF maintenance mode.
if ( file_existsABSPATH '.maintenance' ) ) {
    @
unlinkABSPATH '.maintenance' );
}
echo 
'<h3>Database Changes Reversed</h3>';
echo 
'The procedure was successfully cancelled & reversed. Your site should now function as before the changes were initiated. You may safely delete this file.';


// Delete this script.
@unlink__FILE__ );


?>
<script>
    var win = window.dialogArguments || opener || parent || top;
    win.pb_status_undourl( '' ); // Hide box.
</script>