PluginProbe
Loginizer / 1.8.2
Loginizer v1.8.2
2.1.0 2.0.9 2.0.8 1.9.8 1.9.9 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 trunk 1.0 1.0.1 1.0.2 1.1.0 1.1.1 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 All 74 releases
loginizer / main / ajax.php

ajax.php in Loginizer 1.8.2, at main/ajax.php

205 lines 5.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if(!defined('ABSPATH')){
4 die('Hacking Attempt!');
5 }
6
7
8 // ------- ACTIONS -------/
9 add_action('wp_ajax_loginizer_dismiss_csrf', 'loginizer_dismiss_csrf');
10 add_action('wp_ajax_loginizer_dismiss_backuply', 'loginizer_dismiss_backuply');
11 add_action('wp_ajax_loginizer_dismiss_newsletter', 'loginizer_dismiss_newsletter');
12 add_action('wp_ajax_loginizer_failed_login_export', 'loginizer_failed_login_export');
13 add_action('wp_ajax_loginizer_export', 'loginizer_export');
14 add_action('wp_ajax_loginizer_generate_sso', 'loginizer_generate_sso');
15 add_action('wp_ajax_loginizer_delete_sso', 'loginizer_delete_sso');
16
17
18 // ----- FUNCTIONS ------//
19
20 function loginizer_dismiss_csrf(){
21
22 // Some AJAX security
23 check_ajax_referer('loginizer_admin_ajax', 'nonce');
24
25 if(!current_user_can('manage_options')){
26 wp_die('Sorry, but you do not have permissions to change settings.');
27 }
28
29 update_option('loginizer_csrf_promo_time', (0 - time()));
30 echo 1;
31 wp_die();
32 }
33
34 function loginizer_dismiss_backuply(){
35
36 // Some AJAX security
37 check_ajax_referer('loginizer_admin_ajax', 'nonce');
38
39 if(!current_user_can('manage_options')){
40 wp_die('Sorry, but you do not have permissions to change settings.');
41 }
42
43 update_option('loginizer_backuply_promo_time', (0 - time()));
44 echo 1;
45 wp_die();
46 }
47
48 function loginizer_dismiss_newsletter(){
49
50 // Some AJAX security
51 check_ajax_referer('loginizer_admin_ajax', 'nonce');
52
53 if(!current_user_can('manage_options')){
54 wp_die('Sorry, but you do not have permissions to change settings.');
55 }
56
57 update_option('loginizer_dismiss_newsletter', time());
58 echo 1;
59 wp_die();
60 }
61
62 //Export Failed Login Attempts
63 function loginizer_failed_login_export(){
64
65 global $wpdb;
66 // Some AJAX security
67 check_ajax_referer('loginizer_admin_ajax', 'nonce');
68
69 if(!current_user_can('manage_options')){
70 wp_die('Sorry, but you do not have permissions to change settings.');
71 }
72
73 $csv_array = lz_selectquery("SELECT * FROM `".$wpdb->prefix."loginizer_logs` ORDER BY `time` DESC", 1);
74 $filename = 'loginizer-failed-login-attempts';
75
76 if(empty($csv_array)){
77 echo -1;
78 echo __('No data to export', 'loginizer');
79 wp_die();
80 }
81
82 header('Content-Type: text/csv; charset=utf-8');
83 header('Content-Disposition: attachment; filename='.$filename.'.csv');
84
85 $allowed_fields = array('ip' => 'IP', 'attempted_username' => 'Attempted Username', 'last_f_attemp' => 'Last Failed Attempt', 'f_attempts_count' => 'Failed Attempts Count', 'lockouts_count' => 'Lockouts Count', 'url_attacked' => 'URL Attacked');
86
87 $file = fopen("php://output","w");
88
89 fputcsv($file, array_values($allowed_fields));
90
91 foreach($csv_array as $failed_attempts){
92
93 $row = array($failed_attempts['ip'], $failed_attempts['username'], date('d/M/Y H:i:s P', $failed_attempts['time']), $failed_attempts['count'], $failed_attempts['lockout'], $failed_attempts['url']);
94 fputcsv($file, $row);
95 }
96
97
98 fclose($file);
99
100 wp_die();
101
102 }
103
104 // Export CSV
105 function loginizer_export(){
106
107 // Some AJAX security
108 check_ajax_referer('loginizer_admin_ajax', 'nonce');
109
110 if(!current_user_can('manage_options')){
111 wp_die('Sorry, but you do not have permissions to change settings.');
112 }
113
114 $lz_csv_type = lz_optpost('lz_csv_type');
115
116 switch($lz_csv_type){
117
118 case 'blacklist':
119 $csv_array = get_option('loginizer_blacklist');
120 $filename = 'loginizer-blacklist';
121 break;
122
123 case 'whitelist':
124 $csv_array = get_option('loginizer_whitelist');
125 $filename = 'loginizer-whitelist';
126 break;
127 }
128
129 if(empty($csv_array)){
130 echo -1;
131 echo __('No data to export', 'loginizer');
132 wp_die();
133 }
134
135 header('Content-Type: text/csv; charset=utf-8');
136 header('Content-Disposition: attachment; filename='.$filename.'.csv');
137
138 $allowed_fields = array('start' => 'Start IP', 'end' => 'End IP', 'time' => 'Time');
139
140 $file = fopen("php://output","w");
141
142 fputcsv($file, array_values($allowed_fields));
143
144 foreach($csv_array as $ik => $iv){
145
146 $iv['start'] = $iv['start'];
147 $iv['end'] = $iv['end'];
148 $iv['time'] = date('d/m/Y', $iv['time']);
149
150 $row = array();
151 foreach($allowed_fields as $ak => $av){
152 $row[$ak] = $iv[$ak];
153 }
154
155 fputcsv($file, $row);
156 }
157
158 fclose($file);
159
160 wp_die();
161 }
162
163 function loginizer_generate_sso(){
164
165 if(!wp_verify_nonce($_POST['security'], 'loginizer_nonce')){
166 wp_send_json_error(__('Security Check Failed!', 'loginizer'));
167 }
168
169 }
170
171 function loginizer_delete_sso(){
172
173 if(!wp_verify_nonce($_POST['security'], 'loginizer_nonce')){
174 wp_send_json_error(__('Security Check Failed!', 'loginizer'));
175 }
176
177 if(empty($_POST['sso_ids'])){
178 wp_send_json_error(__('Please select a SSO to delete.', 'loginizer'));
179 }
180
181 $sso_ids = map_deep($_POST['sso_ids'], 'sanitize_text_field');
182
183 if(empty($_POST['sso_ids'])){
184 wp_send_json_error(__('SSO IDs were malformed', 'loginizer'));
185 }
186
187 $sso_links = get_option('loginizer_sso_links', []);
188 $update_sso_links = false;
189
190 foreach($sso_ids as $sso_id){
191 delete_user_meta($sso_id, 'loginizer_sso_' . $sso_id);
192 delete_user_meta($sso_id, 'loginizer_sso_' . $sso_id . '_expires');
193
194 if(!empty($sso_links)){
195 unset($sso_links[$sso_id]);
196 $update_sso_links = true;
197 }
198 }
199
200 if(!empty($update_sso_links)){
201 update_option('loginizer_sso_links', $sso_links);
202 }
203
204 wp_send_json_success(__('SSO Links deleted successfully!', 'loginizer'));
205 }