PluginProbe
WebTotem Security / 2.4.26
WebTotem Security v2.4.26
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.26, at src/Common.php

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