PluginProbe
WebTotem Security / 2.4.21
WebTotem Security v2.4.21
3.0.1 3.0.0 trunk 1.0 1.1 1.2 1.3 1.3.1 1.3.2 1.3.3 2.0 2.1 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 2.2.1 2.2.2 2.2.3 2.2.4 All 109 releases
wt-security / src / Common.php

Common.php in WebTotem Security 2.4.21, at src/Common.php

227 lines 9.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if (!defined('WEBTOTEM_INIT') || WEBTOTEM_INIT !== true) {
4 if (!headers_sent()) {
5 header('HTTP/1.1 403 Forbidden');
6 }
7 die("Protected By WebTotem!");
8 }
9
10 if (defined('WEBTOTEM')) {
11
12 /**
13 * Define which javascript and css files will be loaded in the header of the plugin pages.
14 */
15 $_page = WebTotemRequest::get('page');
16 if(strpos($_page, 'wtotem') === 0) {
17 add_action('admin_enqueue_scripts', 'WebTotemInterface::enqueueScripts', 1);
18 }
19
20
21 add_filter('pre_current_active_plugins', 'WebTotemInterface::registerDeletePrompt');
22
23 /** Define role of current user */
24 add_action('init', 'WebTotem::getUserRole');
25
26 /** Execute pre-checks before every page */
27 add_action('init', 'WebTotemInterface::startupChecks');
28
29 /** Attach HTTP request handlers for the AJAX requests */
30 add_action('wp_ajax_nopriv_wtotem_ajax', 'wtotem_public_ajax_callback');
31 add_action('wp_ajax_wtotem_ajax', 'wtotem_ajax_callback');
32
33 if(WebTotemOption::isActivated()){
34 if(WebTotemCaptcha::isEnabled() or WebTotemLogin::anyTwoFactorActivated()){
35 /** Login Page */
36 add_action('login_enqueue_scripts', 'WebTotemInterface::loginEnqueueScripts');
37 }
38
39 /** Add authenticate filter */
40 add_filter('authenticate', 'WebTotemInterface::wt_authenticate', 25, 3);
41
42 /** Add lostpassword filter */
43 add_action('lostpassword_errors', 'WebTotemInterface::wt_lost_password', 1, 2);
44
45 /** Add site or new sites if it is multisite */
46 add_action( 'wp_insert_site', 'WebTotemInterface::addNewSite' );
47 }
48
49 if (WebTotemOption::getPluginSettings('hide_wp_version')) {
50 /** Restore readme file before WP update, then after update hide readme file */
51 add_filter('update_feedback', 'WebTotemInterface::restoreReadmeWhenUpdating');
52
53 /** Remove the WordPress generator meta-tag from the source code. */
54 remove_action('wp_head', 'wp_generator');
55 }
56
57 /** User Profile */
58 global $pagenow;
59 if ( 'profile.php' === $pagenow or 'user-edit.php' === $pagenow) {
60 add_action( 'admin_enqueue_scripts', 'WebTotemInterface::enqueueScripts', 1);
61 add_action( 'show_user_profile', 'WebTotemInterface::add2faProfileForm');
62 add_action( 'edit_user_profile', 'WebTotemInterface::add2faProfileForm' );
63 }
64
65 /** Launch of the daily cron. */
66 add_action( 'wp', 'webtotem_add_cron_' );
67 function webtotem_add_cron_() {
68 if( ! wp_next_scheduled( 'webtotem_daily_cron' ) ) {
69 wp_schedule_event( time(), 'daily', 'webtotem_daily_cron' );
70 }
71 }
72
73 add_action( 'webtotem_daily_cron', 'WtotemDailyCron' );
74
75 function WtotemDailyCron(){
76 WebTotemOption::setOptions(['scan_init' => 1]);
77 }
78
79 /** Launch of the minute cron. */
80 if(WebTotemOption::getOption('scan_init')){
81
82 // Register the n minute interval
83 add_filter( 'cron_schedules', 'cron_add_some_min' );
84 function cron_add_some_min( $schedules ) {
85 $schedules['some_min'] = array(
86 'interval' => 60,
87 'display' => __('Every few minutes', 'wtotem'),
88 );
89 return $schedules;
90 }
91
92 // Registering an event
93 add_action( 'wp', 'wtotem_step_cron' );
94 function wtotem_step_cron() {
95 if( ! wp_next_scheduled( 'wtotem_step_init_cron' ) ) {
96 wp_schedule_event( time(), 'some_min', 'wtotem_step_init_cron' );
97 }
98 }
99
100 // Linking the function to the cron event/task
101 add_action( 'wtotem_step_init_cron', 'WebTotemScan::initialize' );
102 }
103
104 /**
105 * List an associative array with the sub-pages of this plugin.
106 *
107 * @return array List of sub-pages of this plugin.
108 */
109 function wtotemPages() {
110 if( WebTotem::isMultiSite() ) {
111 $pages['wtotem_all_sites'] = [ 'title' => __('All sites', 'wtotem'), 'slug' => 'wtotem'];
112 }
113 $slug = WebTotem::isMultiSite() ? 'wtotem_' : 'wtotem';
114
115 $pages['wtotem_dashboard'] = [ 'title' => __('Dashboard', 'wtotem'), 'slug' => $slug];
116 $pages['wtotem_firewall'] = [ 'title' => __('Firewall', 'wtotem'), 'slug' => $slug];
117 if(!WebTotem::isMultiSite() or is_super_admin()) {
118 $pages['wtotem_antivirus'] = [ 'title' => __('Antivirus', 'wtotem'), 'slug' => $slug];
119 $pages['wtotem_settings'] = [ 'title' => __('Settings', 'wtotem'), 'slug' => $slug];
120 }
121 $pages['wtotem_reports'] = [ 'title' => __('Reports', 'wtotem'), 'slug' => $slug];
122 $pages['wtotem_documentation'] = [ 'title' => __('Documentation', 'wtotem'), 'slug' => 'wtotem'];
123 $pages['wtotem_wpscan'] = [ 'title' => __('WP scan', 'wtotem'), 'slug' => 'wtotem'];
124
125 return $pages;
126 }
127
128 if (function_exists('add_action')) {
129 /**
130 * Display extension menu and submenu items in the correct interface.
131 *
132 * @return void
133 */
134 function wtotemAddMenu() {
135
136 $page = ! WebTotemOption::isActivated() ? 'activation' : ( WebTotem::isMultiSite() ? 'all_sites' : 'dashboard' );
137
138 add_menu_page(
139 __('WebTotem', 'wtotem'),
140 __('WebTotem', 'wtotem'),
141 'manage_options',
142 'wtotem',
143 'wtotem_' . $page . '_page',
144 WebTotem::getImagePath('logo_17x17_w.png')
145 );
146
147 if(WebTotemOption::isActivated()){
148 $pages = wtotemPages();
149 foreach ($pages as $sub_page_function => $sub_page) {
150 add_submenu_page(
151 $sub_page['slug'],
152 $sub_page['title'],
153 $sub_page['title'],
154 'manage_options',
155 $sub_page_function,
156 $sub_page_function . '_page'
157 );
158 }
159
160 } else {
161 add_submenu_page(
162 'wtotem',
163 __('Activation', 'wtotem'),
164 __('Activation', 'wtotem'),
165 'manage_options',
166 'wtotem_activation',
167 'wtotem_activation_page'
168 );
169 }
170 }
171
172 /* Attach HTTP request handlers for the internal plugin pages */
173 if(WebTotem::isMultiSite()){
174 add_action('network_admin_menu', 'wtotemAddMenu');
175 }
176 add_action('admin_menu', 'wtotemAddMenu');
177 }
178
179 /**
180 * Event hooks.
181 *
182 */
183 if (class_exists('WebTotemEventListener')) {
184
185 add_action('add_user_to_blog', 'WebTotemEventListener::hookAddUserToBlog', 50, 4);
186
187 add_action('add_user_to_blog', 'WebTotemEventListener::hookAddUserToBlog', 50, 4);
188 add_action('remove_user_from_blog', 'WebTotemEventListener::hookRemoveUserFromBlog', 50, 2);
189 add_action('login_form_resetpass', 'WebTotemEventListener::hookLoginFormResetpass', 50, 5);
190 add_action('profile_update', 'WebTotemEventListener::hookProfileUpdate', 50, 5);
191 add_action('retrieve_password', 'WebTotemEventListener::hookRetrievePassword', 50, 5);
192 add_action('user_register', 'WebTotemEventListener::hookUserRegister', 50, 5);
193 add_action('deleted_user', 'WebTotemEventListener::hookUserDelete', 50, 3);
194 add_action('wp_login', 'WebTotemEventListener::hookLoginSuccess', 50, 5);
195 add_action('wp_login_failed', 'WebTotemEventListener::hookLoginFailure', 50, 5);
196 add_action('add_link', 'WebTotemEventListener::hookLinkAdd', 50, 5);
197 add_action('edit_link', 'WebTotemEventListener::hookLinkEdit', 50, 5);
198 add_action('create_category', 'WebTotemEventListener::hookCategoryCreate', 50, 5);
199 add_action('publish_post', 'WebTotemEventListener::hookPublishPost', 50, 5);
200 add_action('transition_post_status', 'WebTotemEventListener::hookPostStatus', 50, 3);
201 add_action('xmlrpc_publish_post', 'WebTotemEventListener::hookPublishPostXMLRPC', 50, 5);
202 add_action('before_delete_post', 'WebTotemEventListener::hookPostBeforeDelete', 50, 5);
203 add_action('delete_post', 'WebTotemEventListener::hookPostDelete', 50, 5);
204 add_action('wp_trash_post', 'WebTotemEventListener::hookPostTrash', 50, 5);
205 add_action('publish_page', 'WebTotemEventListener::hookPublishPage', 50, 5);
206 add_action('add_attachment', 'WebTotemEventListener::hookAttachmentAdd', 50, 5);
207 add_action('activated_plugin', 'WebTotemEventListener::hookPluginActivate', 50, 2);
208 add_action('deactivated_plugin', 'WebTotemEventListener::hookPluginDeactivate', 50, 2);
209 add_action('switch_theme', 'WebTotemEventListener::hookThemeSwitch', 50, 5);
210
211 add_action('admin_init', 'WebTotemEventListener::hookCoreUpdate');
212 add_action('admin_init', 'WebTotemEventListener::hookOptionsManagement');
213 add_action('admin_init', 'WebTotemEventListener::hookPluginDelete');
214 add_action('admin_init', 'WebTotemEventListener::hookPluginEditor');
215 add_action('admin_init', 'WebTotemEventListener::hookPluginInstall');
216 add_action('admin_init', 'WebTotemEventListener::hookPluginUpdate');
217 add_action('admin_init', 'WebTotemEventListener::hookThemeDelete');
218 add_action('admin_init', 'WebTotemEventListener::hookThemeEditor');
219 add_action('admin_init', 'WebTotemEventListener::hookThemeInstall');
220 add_action('admin_init', 'WebTotemEventListener::hookThemeUpdate');
221 add_action('admin_init', 'WebTotemEventListener::hookWidgetAdd');
222 add_action('admin_init', 'WebTotemEventListener::hookWidgetDelete');
223
224 }
225
226 }
227