PluginProbe ʕ •ᴥ•ʔ
NinjaFirewall (WP Edition) – Advanced Security Plugin and Firewall / 4.8.8
NinjaFirewall (WP Edition) – Advanced Security Plugin and Firewall v4.8.8
4.9 4.8.8 4.8.7 4.8.6 trunk 4.5 4.5.1 4.5.10 4.5.11 4.5.2 4.5.3 4.5.4 4.5.5 4.5.6 4.5.7 4.5.8 4.5.9 4.6 4.6.1 4.7 4.7.1 4.7.2 4.7.3 4.7.4 4.7.5 4.8 4.8.1 4.8.2 4.8.3 4.8.4 4.8.5
ninjafirewall / lib / scheduled_tasks.php
ninjafirewall / lib Last commit date
share 9 years ago .htaccess 11 years ago anti_malware.php 5 years ago class-coupon.php 7 months ago class-email-sodium.php 1 month ago class-firewall-log.php 1 month ago class-helpers.php 9 months ago class-import-export.php 5 months ago class-ip.php 5 months ago class-nfw-database.php 7 months ago class-nfw-session.php 1 month ago class-php-session.php 1 year ago class-plugin-upgrade.php 1 month ago class_mail.php 1 month ago event_updates.php 11 months ago firewall.php 5 months ago fw_centlog.php 1 month ago fw_fileguard.php 5 months ago fw_livelog.php 1 year ago help.php 1 month ago helpers.php 1 month ago i18n-extra.php 1 month ago i18n.php 1 year ago index.html 13 years ago init_update.php 2 years ago install.php 1 year ago install_default.php 7 months ago loader.php 7 months ago mail_template_firewall.php 1 year ago mail_template_plugin.php 2 months ago scheduled_tasks.php 3 years ago settings_dashboard.php 2 months ago settings_dashboard_about.php 1 month ago settings_dashboard_statistics.php 2 months ago settings_event_notifications.php 2 months ago settings_events.php 2 months ago settings_firewall_options.php 2 months ago settings_firewall_policies.php 1 month ago settings_login_protection.php 2 months ago settings_logs.php 2 months ago settings_logs_firewall_log.php 1 month ago settings_logs_live_log.php 2 months ago settings_monitoring.php 1 month ago settings_monitoring_file_check.php 2 months ago settings_monitoring_file_guard.php 2 months ago settings_network.php 2 months ago settings_security_rules.php 2 months ago settings_security_rules_editor.php 2 months ago settings_security_rules_update.php 1 month ago sign.pub 7 years ago thickbox.php 4 years ago widget.php 3 years ago wpplus.php 5 months ago
scheduled_tasks.php
174 lines
1 <?php
2 /*
3 +---------------------------------------------------------------------+
4 | NinjaFirewall (WP Edition) |
5 | |
6 | (c) NinTechNet - https://nintechnet.com/ |
7 +---------------------------------------------------------------------+
8 | This program is free software: you can redistribute it and/or |
9 | modify it under the terms of the GNU General Public License as |
10 | published by the Free Software Foundation, either version 3 of |
11 | the License, or (at your option) any later version. |
12 | |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | GNU General Public License for more details. |
17 +---------------------------------------------------------------------+
18 */
19
20 if (! defined( 'NFW_ENGINE_VERSION' ) ) { die( 'Forbidden' ); }
21
22 // ---------------------------------------------------------------------
23 // Create scheduled tasks.
24
25 function nfw_create_scheduled_tasks( $task = 0 ) {
26
27 $nfw_options = nfw_get_option( 'nfw_options' );
28
29 // Return if NF was disabled from the "Options" page
30 if ( empty( $nfw_options['enabled'] ) ) {
31 return;
32 }
33
34
35 // File Check (optional)
36 if (! $task || $task == 'nfscanevent' ) {
37 if ( wp_next_scheduled('nfscanevent') ) {
38 wp_clear_scheduled_hook('nfscanevent');
39 }
40 if (! empty($nfw_options['sched_scan']) ) {
41 if ($nfw_options['sched_scan'] == 1) {
42 $schedtype = 'hourly';
43 } elseif ($nfw_options['sched_scan'] == 2) {
44 $schedtype = 'twicedaily';
45 } else {
46 $schedtype = 'daily';
47 }
48 wp_schedule_event( time() + 120, $schedtype, 'nfscanevent');
49 }
50 }
51
52
53 // Garbage Collector (always on)
54 if ( wp_next_scheduled( 'nfwgccron' ) ) {
55 wp_clear_scheduled_hook( 'nfwgccron' );
56 }
57 wp_schedule_event( time() + 30, 'hourly', 'nfwgccron' );
58
59
60 // Security rules update (optional)
61 if (! $task || $task == 'nfsecupdates' ) {
62 if ( wp_next_scheduled('nfsecupdates') ) {
63 wp_clear_scheduled_hook('nfsecupdates');
64 }
65 if (! empty($nfw_options['enable_updates']) ) {
66 if ($nfw_options['sched_updates'] == 1) {
67 $schedtype = 'hourly';
68 } elseif ($nfw_options['sched_updates'] == 2) {
69 $schedtype = 'twicedaily';
70 } else {
71 $schedtype = 'daily';
72 }
73 wp_schedule_event( time() + 60, $schedtype, 'nfsecupdates');
74 }
75 }
76
77
78 // Daily report (optional)
79 if (! $task || $task == 'nfdailyreport' ) {
80 if ( wp_next_scheduled('nfdailyreport') ) {
81 wp_clear_scheduled_hook('nfdailyreport');
82 }
83 if (! empty( $nfw_options['a_52'] ) ) {
84 wp_schedule_event( strtotime( date('Y-m-d 00:00:05', strtotime('+1 day')) ), 'daily', 'nfdailyreport');
85 }
86 }
87
88 }
89 // ---------------------------------------------------------------------
90 // Verify scheduled tasks, reactivate them if needed and write
91 // the incident to the error log.
92
93 function nfw_verify_scheduled_tasks() {
94
95 if ( defined('NFW_DONTVERIFYCRON') && NFW_DONTVERIFYCRON == true ) {
96 return;
97 }
98
99 $nfw_options = nfw_get_option( 'nfw_options' );
100
101 // Return if NF was disabled from the "Options" page
102 if ( empty( $nfw_options['enabled'] ) ) {
103 return;
104 }
105
106 $now = time();
107
108 // File Check (optional)
109 if (! empty($nfw_options['sched_scan']) && ! wp_next_scheduled('nfscanevent') ) {
110 if ($nfw_options['sched_scan'] == 1) {
111 $schedtype = 'hourly';
112 } elseif ($nfw_options['sched_scan'] == 2) {
113 $schedtype = 'twicedaily';
114 } else {
115 $schedtype = 'daily';
116 }
117 wp_schedule_event( $now + 120, $schedtype, 'nfscanevent');
118 nfw_log_error(
119 sprintf( __('Scheduled task has stopped, restarting it (%s)', 'ninjafirewall'), 'nfscanevent' )
120 );
121 }
122
123 // Garbage Collector (always on)
124 if (! wp_next_scheduled('nfwgccron') ) {
125 wp_schedule_event( $now + 30, 'hourly', 'nfwgccron' );
126 nfw_log_error(
127 sprintf( __('Scheduled task has stopped, restarting it (%s)', 'ninjafirewall'), 'nfwgccron' )
128 );
129 }
130
131 // Security rules update (optional)
132 if (! empty($nfw_options['enable_updates']) && ! wp_next_scheduled('nfsecupdates') ) {
133 if ($nfw_options['sched_updates'] == 1) {
134 $schedtype = 'hourly';
135 } elseif ($nfw_options['sched_updates'] == 2) {
136 $schedtype = 'twicedaily';
137 } else {
138 $schedtype = 'daily';
139 }
140 wp_schedule_event( $now + 60, $schedtype, 'nfsecupdates');
141 nfw_log_error(
142 sprintf( __('Scheduled task has stopped, restarting it (%s)', 'ninjafirewall'), 'nfsecupdates' )
143 );
144 }
145
146 // Daily report (optional)
147 if (! empty( $nfw_options['a_52'] ) && ! wp_next_scheduled('nfdailyreport') ) {
148 wp_schedule_event( strtotime( date('Y-m-d 00:00:05', strtotime('+1 day')) ), 'daily', 'nfdailyreport');
149 nfw_log_error(
150 sprintf( __('Scheduled task has stopped, restarting it (%s)', 'ninjafirewall'), 'nfdailyreport' )
151 );
152 }
153 }
154 // ---------------------------------------------------------------------
155 // Delete scheduled tasks.
156
157 function nfw_delete_scheduled_tasks() {
158
159 if ( wp_next_scheduled('nfscanevent') ) {
160 wp_clear_scheduled_hook('nfscanevent');
161 }
162 if ( wp_next_scheduled( 'nfwgccron' ) ) {
163 wp_clear_scheduled_hook( 'nfwgccron' );
164 }
165 if ( wp_next_scheduled('nfsecupdates') ) {
166 wp_clear_scheduled_hook('nfsecupdates');
167 }
168 if ( wp_next_scheduled('nfdailyreport') ) {
169 wp_clear_scheduled_hook('nfdailyreport');
170 }
171
172 }
173 // ---------------------------------------------------------------------
174 // EOF