C:\xampp\htdocs\landing\wp-content\plugins\better-wp-security\core\modules\file-change\setup.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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
<?php

if ( ! class_exists'ITSEC_File_Change_Setup' ) ) {

    class 
ITSEC_File_Change_Setup {

        private
            
$defaults;

        public function 
__construct() {

            
add_action'itsec_modules_do_plugin_activation', array( $this'execute_activate' ) );
            
add_action'itsec_modules_do_plugin_deactivation', array( $this'execute_deactivate' ) );
            
add_action'itsec_modules_do_plugin_uninstall', array( $this'execute_uninstall' ) );
            
add_action'itsec_modules_do_plugin_upgrade', array( $this'execute_upgrade' ), null);

        }

        
/**
         * Execute module activation.
         *
         * @since 4.0
         *
         * @return void
         */
        
public function execute_activate() {
        }

        
/**
         * Execute module deactivation
         *
         * @return void
         */
        
public function execute_deactivate() {

            
wp_clear_scheduled_hook'itsec_file_check' );

            
ITSEC_Core::get_scheduler()->unschedule_single'file-change'null );
            
ITSEC_Core::get_scheduler()->unschedule_single'file-change-fast'null );
        }

        
/**
         * Execute module uninstall
         *
         * @return void
         */
        
public function execute_uninstall() {

            
$this->execute_deactivate();

            
delete_site_option'itsec_file_change' );
            
delete_site_option'itsec_local_file_list' );
            
delete_site_option'itsec_local_file_list_0' );
            
delete_site_option'itsec_local_file_list_1' );
            
delete_site_option'itsec_local_file_list_2' );
            
delete_site_option'itsec_local_file_list_3' );
            
delete_site_option'itsec_local_file_list_4' );
            
delete_site_option'itsec_local_file_list_5' );
            
delete_site_option'itsec_local_file_list_6' );
            
delete_site_option'itsec_file_change_warning' );

            require_once( 
dirname__FILE__ ) . '/scanner.php' );

            
ITSEC_Lib_Distributed_Storage::clear_group'file-change-progress' );
            
ITSEC_Lib_Distributed_Storage::clear_group'file-list' );
            
delete_site_optionITSEC_File_Change_Scanner::DESTROYED );
        }

        
/**
         * Execute module upgrade
         *
         * @return void
         */
        
public function execute_upgrade$itsec_old_version ) {

            if ( 
$itsec_old_version 4000 ) {

                global 
$itsec_bwps_options;

                
$current_options get_site_option'itsec_file_change' );

                
// Don't do anything if settings haven't already been set, defaults exist in the module system and we prefer to use those
                
if ( false !== $current_options ) {

                    
$current_options['enabled']      = isset( $itsec_bwps_options['id_fileenabled'] ) && $itsec_bwps_options['id_fileenabled'] == true false;
                    
$current_options['email']        = isset( $itsec_bwps_options['id_fileemailnotify'] ) && $itsec_bwps_options['id_fileemailnotify'] == false true;
                    
$current_options['notify_admin'] = isset( $itsec_bwps_options['id_filedisplayerror'] ) && $itsec_bwps_options['id_filedisplayerror'] == false true;
                    
$current_options['method']       = isset( $itsec_bwps_options['id_fileincex'] ) && $itsec_bwps_options['id_fileincex'] == false true;

                    if ( isset( 
$itsec_bwps_options['id_specialfile'] ) && ! is_array$itsec_bwps_options['id_specialfile'] ) && strlen$itsec_bwps_options['id_specialfile'] ) > ) {

                        
$current_options['file_list'] .= explodePHP_EOL$itsec_bwps_options['id_specialfile'] );

                    }

                    
update_site_option'itsec_file_change'$current_options );

                }
            }

            if ( 
$itsec_old_version 4028 ) {

                if ( ! 
is_multisite() ) {

                    
$options = array(
                        
'itsec_local_file_list',
                        
'itsec_local_file_list_0',
                        
'itsec_local_file_list_1',
                        
'itsec_local_file_list_2',
                        
'itsec_local_file_list_3',
                        
'itsec_local_file_list_4',
                        
'itsec_local_file_list_5',
                        
'itsec_local_file_list_6',
                    );

                    foreach ( 
$options as $option ) {

                        
$list get_site_option$option );

                        if ( 
$list !== false ) {

                            
delete_site_option$option );
                            
add_option$option$list'''no' );

                        }

                    }

                }

            }

            if ( 
$itsec_old_version 4041 ) {
                
$current_options get_site_option'itsec_file_change' );

                
// If there are no current options, go with the new defaults by not saving anything
                
if ( is_array$current_options ) ) {
                    
// Make sure the new module is properly activated or deactivated
                    
if ( $current_options['enabled'] ) {
                        
ITSEC_Modules::activate'file-change' );
                    } else {
                        
ITSEC_Modules::deactivate'file-change' );
                    }

                    
// remove 'enabled' which isn't use in the new module
                    
unset( $current_options['enabled'] );

                    
// This used to be boolean. Attempt to migrate to new string, falling back to default
                    
if ( ! is_array$current_options['method'] ) ) {
                        
$current_options['method'] = ( $current_options['method'] ) ? 'exclude' 'include';
                    } elseif ( ! 
in_array$current_options['method'], array( 'include''exclude' ) ) ) {
                        
$current_options['method'] = 'exclude';
                    }

                    
ITSEC_Modules::set_settings'file-change'$current_options );
                }
            }

            if ( 
$itsec_old_version 4079 ) {
                
wp_clear_scheduled_hook'itsec_execute_file_check_cron' );
            }

            if ( 
$itsec_old_version 4088 ) {
                
$types    ITSEC_Modules::get_setting'file-change''types' );
                
$defaults = array( '.jpg''.jpeg''.png''.log''.mo''.po' );

                
sort$types );
                
sort$defaults );

                
$update false;

                if ( 
$types === $defaults ) {
                    
$update true;
                } else {
                    
$defaults[] = '.lock';

                    
sort$defaults );

                    if ( 
$types === $defaults ) {
                        
$update true;
                    }
                }

                if ( 
$update ) {
                    
ITSEC_Modules::set_setting'file-change''types'ITSEC_Modules::get_default'file-change''types' ) );
                }

                require_once( 
dirname__FILE__ ) . '/scanner.php' );

                
$options   = array(
                    
'itsec_local_file_list',
                    
'itsec_local_file_list_0',
                    
'itsec_local_file_list_1',
                    
'itsec_local_file_list_2',
                    
'itsec_local_file_list_3',
                    
'itsec_local_file_list_4',
                    
'itsec_local_file_list_5',
                    
'itsec_local_file_list_6',
                );
                
$file_list = array();

                
$home get_home_path();

                foreach ( 
$options as $option ) {
                    
$opt_list get_site_option$option );

                    if ( 
$opt_list && is_array$opt_list ) ) {
                        foreach ( 
$opt_list as $file => $attr ) {
                            
$file_list$home $file ] = $attr;
                        }
                    }
                }

                if ( 
$file_list ) {
                    
ITSEC_File_Change_Scanner::record_file_list$file_list );
                }

                
ITSEC_Core::get_scheduler()->unschedule'file-change' );
                
ITSEC_File_Change_Scanner::schedule_startfalse );
            }

            if ( 
$itsec_old_version 4090 ) {
                require_once( 
dirname__FILE__ ) . '/scanner.php' );

                
ITSEC_Core::get_scheduler()->unschedule_single'file-change'null );
                
ITSEC_Core::get_scheduler()->unschedule_single'file-change-fast'null );
                
ITSEC_Lib_Distributed_Storage::clear_group'file-change-progress' );

                
$file_list_option get_site_option'itsec_file_list' );

                if ( 
$file_list_option && ! empty( $file_list_option['files'] ) ) {
                    
$files end$file_list_option['files'] );
                    
$home  $file_list_option['home'];

                    if ( 
$home !== get_home_path() ) {
                        
$new_home get_home_path();

                        foreach ( 
$files as $file => $attr ) {
                            
$filesITSEC_Lib::replace_prefix$file$home$new_home ) ] = $attr;
                        }
                    }

                    
ITSEC_File_Change_Scanner::record_file_list$this->migrate_file_attr$files ) );
                }

                
delete_site_option'itsec_file_list' );

                if ( 
$latest_changes ITSEC_Modules::get_setting'file-change''latest_changes' ) ) {

                    if ( ! empty( 
$latest_changes['added'] ) && is_array$latest_changes['added'] ) ) {
                        
$latest_changes['added'] = $this->migrate_file_attr$latest_changes['added'] );
                    } else {
                        
$latest_changes['added'] = array();
                    }

                    if ( ! empty( 
$latest_changes['changed'] ) && is_array$latest_changes['changed'] ) ) {
                        
$latest_changes['changed'] = $this->migrate_file_attr$latest_changes['changed'] );
                    } else {
                        
$latest_changes['changed'] = array();
                    }

                    if ( ! empty( 
$latest_changes['removed'] ) && is_array$latest_changes['removed'] ) ) {
                        
$latest_changes['removed'] = $this->migrate_file_attr$latest_changes['removed'] );
                    } else {
                        
$latest_changes['removed'] = array();
                    }

                    
update_site_option'itsec_file_change_latest'$latest_changes );
                }

                
ITSEC_File_Change_Scanner::schedule_startfalse );
            } elseif ( 
$itsec_old_version 4091 ) {
                
$settings ITSEC_Modules::get_settings'file-change' );

                if ( 
array_key_exists'latest_changes'$settings ) ) {

                    if ( 
$latest_changes $settings['latest_changes'] ) {
                        
update_site_option'itsec_file_change_latest'$latest_changes );
                    }

                    unset( 
$settings['latest_changes'] );
                    
ITSEC_Modules::set_settings'file-change'$settings );
                }
            }

            if ( 
$itsec_old_version 4093 ) {
                require_once( 
dirname__FILE__ ) . '/scanner.php' );

                
ITSEC_Core::get_scheduler()->unschedule_single'file-change'null );
                
ITSEC_Core::get_scheduler()->unschedule_single'file-change-fast'null );
                
ITSEC_File_Change_Scanner::schedule_startfalse );
                
delete_site_option'itsec_file_change_scan_progress' );
            }

            if ( 
$itsec_old_version 4107 ) {
                
$options = array(
                    
'itsec_file_list',
                    
'itsec_local_file_list',
                    
'itsec_local_file_list_0',
                    
'itsec_local_file_list_1',
                    
'itsec_local_file_list_2',
                    
'itsec_local_file_list_3',
                    
'itsec_local_file_list_4',
                    
'itsec_local_file_list_5',
                    
'itsec_local_file_list_6',
                );

                foreach ( 
$options as $option ) {
                    
delete_site_option$option );
                }

                require_once( 
dirname__FILE__ ) . '/class-itsec-file-change.php' );
                require_once( 
dirname__FILE__ ) . '/scanner.php' );

                
ITSEC_Core::get_scheduler()->unschedule_single'file-change'null );
                
ITSEC_Core::get_scheduler()->unschedule_single'file-change-fast'null );
                
ITSEC_File_Change::make_progress_storage()->clear();
                
ITSEC_File_Change_Scanner::schedule_startfalse );
            }

            if ( 
$itsec_old_version 4114 ) {
                if ( ! 
ITSEC_Modules::get_setting'file-change''notify_admin' ) ) {
                    
ITSEC_Lib::load'highlighted-logs' );
                    
ITSEC_Lib_Highlighted_Logs::mute'file-change-report' );
                }
            }
        }

        
/**
         * Migrate file attributes to the shorter format.
         *
         * @param array $files
         *
         * @return array
         */
        
private function migrate_file_attr$files ) {

            
$changed = array();

            foreach ( 
$files as $file => $attr ) {
                
$migrated = array(
                    
'h' => $attr['h'],
                    
'd' => $attr['d'],
                );

                if ( isset( 
$attr['s'] ) ) {
                    
$migrated['s'] = $attr['s'];
                } elseif ( isset( 
$attr['severity'] ) ) {
                    
$migrated['s'] = $attr['severity'];
                }

                if ( isset( 
$attr['t'] ) ) {
                    
$migrated['t'] = $attr['t'];
                } elseif ( isset( 
$attr['type'] ) ) {
                    switch ( 
$attr['type'] ) {
                        case 
'added':
                            
$migrated['t'] = ITSEC_File_Change_Scanner::T_ADDED;
                            break;
                        case 
'changed':
                            
$migrated['t'] = ITSEC_File_Change_Scanner::T_CHANGED;
                            break;
                        case 
'removed':
                            
$migrated['t'] = ITSEC_File_Change_Scanner::T_REMOVED;
                            break;
                        default:
                            
$migrated['t'] = $attr['type'];
                            break;
                    }
                }

                if ( isset( 
$attr['p'] ) ) {
                    
$migrated['p'] = $attr['p'];
                } elseif ( isset( 
$attr['package'] ) ) {
                    
$migrated['p'] = $attr['package'];
                }

                
$changed$file ] = $migrated;
            }

            return 
$changed;
        }
    }
}

new 
ITSEC_File_Change_Setup();
x

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