C:\xampp\htdocs\landing\wp-content\plugins\better-wp-security\core\modules\backup\settings-page.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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
<?php

final class ITSEC_Backup_Settings_Page extends ITSEC_Module_Settings_Page {
    private 
$script_version 1;


    public function 
__construct() {
        
$this->id 'backup';
        
$this->title __'Database Backups''better-wp-security' );
        
$this->description __'Create backups of your site\'s database. The backups can be created manually and on a schedule.''better-wp-security' );
        
$this->type 'recommended';

        
parent::__construct();
    }

    public function 
enqueue_scripts_and_styles() {
        
wp_enqueue_script'jquery-multi-select'plugins_url'js/jquery.multi-select.js'__FILE__ ), array( 'jquery' ), $this->script_versiontrue );

        
$vars = array(
            
'default_backup_location' => ITSEC_Modules::get_default$this->id'location' ),
            
'available_tables_label'  => __'Tables for Backup''better-wp-security' ),
            
'excluded_tables_label'   => __'Excluded Tables''better-wp-security' ),
            
'creating_backup_text'    => __'Creating Backup...''better-wp-security' ),
        );

        
wp_enqueue_script'itsec-backup-settings-page-script'plugins_url'js/settings-page.js'__FILE__ ), array( 'jquery''jquery-multi-select' ), $this->script_versiontrue );
        
wp_localize_script'itsec-backup-settings-page-script''itsec_backup'$vars );

        
wp_enqueue_style'itsec-backup-settings-page-style'plugins_url'css/settings-page.css'__FILE__ ), array(), $this->script_version );
    }

    public function 
handle_ajax_request$data ) {
        global 
$itsec_backup;

        if ( ! isset( 
$itsec_backup ) ) {
            require_once( 
'class-itsec-backup.php' );
            
$itsec_backup = new ITSEC_Backup();
            
$itsec_backup->run();
        }

        
$result $itsec_backup->do_backuptrue );
        
$message '';

        if ( 
is_wp_error$result ) ) {
            
$errors ITSEC_Response::get_error_strings$result );

            foreach ( 
$errors as $error ) {
                
$message .= '<div class="error inline"><p><strong>' $error '</strong></p></div>';
            }
        } else if ( 
is_array$result ) ) {
            
$message '<div class="updated fade inline"><p><strong>' $result['message'] . '</strong></p></div>';
        } else {
            
$message '<div class="error inline"><p><strong>' sprintf__'The backup request returned an unexpected response. It returned a response of type <code>%1$s</code>.''better-wp-security' ), gettype$result ) ) . '</strong></p></div>';
        }

        
ITSEC_Response::set_response$message );
    }

    protected function 
render_description$form ) {

?>
    <p><?php _e'One of the best ways to protect yourself from an attack is to have access to a database backup of your site. If something goes wrong, you can get your site back by restoring the database from a backup and replacing the files with fresh ones. Use the button below to create a backup of your database for this purpose. You can also schedule automated backups and download or delete previous backups.''better-wp-security' ); ?></p>
<?php

    
}

    protected function 
render_settings$form ) {
        
$settings $form->get_options();


        
$methods = array(
            
=> __'Save Locally and Email''better-wp-security' ),
            
=> __'Email Only''better-wp-security' ),
            
=> __'Save Locally Only''better-wp-security' ),
        );

        
$excludes $this->get_excludable_tables$settings );

?>
    <div class="hide-if-no-js">
        <p><?php _e'Press the button below to create a database backup using the saved settings.''better-wp-security' ); ?></p>
        <p><?php $form->add_button'create_backup', array( 'value' => __'Create a Database Backup''better-wp-security' ), 'class' => 'button-primary' ) ); ?></p>
        <div id="itsec_backup_status"></div>
    </div>

    <table class="form-table itsec-settings-section">
        <tr>
            <th scope="row"><label for="itsec-backup-all_sites"><?php _e'Backup Full Database''better-wp-security' ); ?></label></th>
            <td>
                <?php $form->add_checkbox'all_sites' ); ?>
                <label for="itsec-backup-all_sites"><?php _e'Checking this box will have the backup script backup all tables in your database, even if they are not part of this WordPress site.''better-wp-security' ); ?></label>
            </td>
        </tr>
        <tr>
            <th scope="row"><label for="itsec-backup-method"><?php _e'Backup Method''better-wp-security' ); ?></label></th>
            <td>
                <?php $form->add_select'method'$methods ); ?>
                <br />
                <label for="itsec-backup-method"><?php _e'Backup Save Method''better-wp-security' ); ?></label>
                <p class="description"><?php _e'Select what we should do with your backup file. You can have it emailed to you, saved locally or both.''better-wp-security' ); ?></p>
            </td>
        </tr>
        <tr class="itsec-backup-method-file-content">
            <th scope="row"><label for="itsec-backup-location"><?php _e'Backup Location''better-wp-security' ); ?></label></th>
            <td>
                <?php $form->add_text'location', array( 'class' => 'large-text' ) ); ?>
                <label for="itsec-backup-location"><?php _e'The path on your machine where backup files should be stored.''better-wp-security' ); ?></label>
                <p class="description"><?php _e'This path must be writable by your website. For added security, it is recommended you do not include it in your website root folder.''better-wp-security' ); ?></p>
                <div class="hide-if-no-js">
                    <?php $form->add_button'reset_backup_location', array( 'value' => __'Restore Default Location''better-wp-security' ), 'class' => 'button-secondary' ) ); ?>
                </div>
            </td>
        </tr>
        <tr>
            <th scope="row"><label for="itsec-backup-retain"><?php _e'Backups to Retain''better-wp-security' ); ?></label></th>
            <td>
                <?php $form->add_text'retain', array( 'class' => 'small-text' ) ); ?>
                <label for="itsec-backup-retain"><?php _e'Backups''better-wp-security' ); ?></label>
                <p class="description"><?php _e'Limit the number of backups stored locally (on this server). Any older backups beyond this number will be removed. Setting to "0" will retain all backups.''better-wp-security' ); ?></p>
            </td>
        </tr>
        <tr>
            <th scope="row"><label for="itsec-backup-zip"><?php _e'Compress Backup Files''better-wp-security' ); ?></label></th>
            <td>
                <?php $form->add_checkbox'zip' ); ?>
                <label for="itsec-backup-zip"><?php _e'Zip Database Backups''better-wp-security' ); ?></label>
                <p class="description"><?php _e'You may need to turn this off if you are having problems with backups.''better-wp-security' ); ?></p>
            </td>
        </tr>
        <tr>
            <th scope="row"><label for="itsec-backup-exclude"><?php _e'Exclude Tables''better-wp-security' ); ?></label></th>
            <td>
                <label for="itsec-backup-exclude"><?php _e'Tables with data that does not need to be backed up''better-wp-security' ); ?></label>
                <?php $form->add_multi_select'exclude'$excludes ); ?>
            <p class="description"><?php _e'Some plugins can create log files in your database. While these logs might be handy for some functions, they can also take up a lot of space and, in some cases, even make backing up your database almost impossible. Select log tables above to exclude their data from the backup. Note: The table itself will be backed up, but not the data in the table.''better-wp-security' ); ?></p>
            </td>
        </tr>
        <tr>
            <th scope="row"><label for="itsec-backup-enabled"><?php _e'Schedule Database Backups''better-wp-security' ); ?></label></th>
            <td>
                <?php $form->add_checkbox'enabled', array( 'class' => 'itsec-settings-toggle' ) ); ?>
                <label for="itsec-backup-enabled"><?php _e'Enable Scheduled Database Backups''better-wp-security' ); ?></label>
            </td>
        </tr>
        <tr class="itsec-backup-enabled-content">
            <th scope="row"><label for="itsec-backup-interval"><?php _e'Backup Interval''better-wp-security' ); ?></label></th>
            <td>
                <?php $form->add_text'interval', array( 'class' => 'small-text' ) ); ?>
                <label for="itsec-backup-interval"><?php _e'Days''better-wp-security' ); ?></label>
                <p class="description"><?php _e'The number of days between database backups.''better-wp-security' ); ?></p>
            </td>
        </tr>
    </table>
<?php

    
}

    private function 
get_excludable_tables$settings ) {
        global 
$wpdb;

        
$ignored_tables = array(
            
'commentmeta',
            
'comments',
            
'links',
            
'options',
            
'postmeta',
            
'posts',
            
'term_relationships',
            
'term_taxonomy',
            
'terms',
            
'usermeta',
            
'users',
        );

        if ( 
$settings['all_sites'] ) {
            
$query 'SHOW TABLES';
        } else {
            
$query $wpdb->prepare'SHOW TABLES LIKE %s'"{$wpdb->base_prefix}%" );
        }

        
$tables $wpdb->get_results$queryARRAY_N );
        
$excludes = array();

        foreach ( 
$tables as $table ) {
            
$short_table substr$table[0], strlen$wpdb->prefix ) );

            if ( 
in_array$short_table$ignored_tables ) ) {
                continue;
            }

            
$excludes[$short_table] = $table[0];
        }

        return 
$excludes;
    }
}

new 
ITSEC_Backup_Settings_Page();
x

Windows NT KPTV 6.2 build 9200 (Windows Server 2012 Datacenter Edition) i586