PluginProbe
Loginizer / 1.9.3
Loginizer v1.9.3
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.9.3, at main/ajax.php

205 lines 5.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('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_social_alert', 'loginizer_dismiss_social_alert');
12 add_action('wp_ajax_loginizer_dismiss_newsletter', 'loginizer_dismiss_newsletter');
13 add_action('wp_ajax_loginizer_failed_login_export', 'loginizer_failed_login_export');
14 add_action('wp_ajax_loginizer_export', 'loginizer_export');
15 add_action('wp_ajax_loginizer_social_order', 'loginizer_social_order');
16 add_action('wp_ajax_loginizer_dismiss_license_alert', 'loginizer_dismiss_license_alert');
17
18
19 // ----- FUNCTIONS ------//
20
21 function loginizer_dismiss_csrf(){
22
23 // Some AJAX security
24 check_ajax_referer('loginizer_admin_ajax', 'nonce');
25
26 if(!current_user_can('manage_options')){
27 wp_die('Sorry, but you do not have permissions to change settings.');
28 }
29
30 update_option('loginizer_csrf_promo_time', (0 - time()));
31 echo 1;
32 wp_die();
33 }
34
35 function loginizer_dismiss_social_alert(){
36
37 // Some AJAX security
38 check_ajax_referer('loginizer_admin_ajax', 'nonce');
39
40 if(!current_user_can('manage_options')){
41 wp_send_json_error('Sorry, but you do not have permissions to change settings.');
42 }
43
44 update_option('loginizer_social_login_url', wp_login_url());
45
46 wp_send_json_success();
47 }
48
49 function loginizer_dismiss_backuply(){
50
51 // Some AJAX security
52 check_ajax_referer('loginizer_admin_ajax', 'nonce');
53
54 if(!current_user_can('manage_options')){
55 wp_die('Sorry, but you do not have permissions to change settings.');
56 }
57
58 update_option('loginizer_backuply_promo_time', (0 - time()));
59 echo 1;
60 wp_die();
61 }
62
63 function loginizer_dismiss_newsletter(){
64
65 // Some AJAX security
66 check_ajax_referer('loginizer_admin_ajax', 'nonce');
67
68 if(!current_user_can('manage_options')){
69 wp_die('Sorry, but you do not have permissions to change settings.');
70 }
71
72 update_option('loginizer_dismiss_newsletter', time());
73 echo 1;
74 wp_die();
75 }
76
77 //Export Failed Login Attempts
78 function loginizer_failed_login_export(){
79
80 global $wpdb;
81 // Some AJAX security
82 check_ajax_referer('loginizer_admin_ajax', 'nonce');
83
84 if(!current_user_can('manage_options')){
85 wp_die('Sorry, but you do not have permissions to change settings.');
86 }
87
88 $csv_array = lz_selectquery("SELECT * FROM `".$wpdb->prefix."loginizer_logs` ORDER BY `time` DESC", 1);
89 $filename = 'loginizer-failed-login-attempts';
90
91 if(empty($csv_array)){
92 echo -1;
93 echo __('No data to export', 'loginizer');
94 wp_die();
95 }
96
97 header('Content-Type: text/csv; charset=utf-8');
98 header('Content-Disposition: attachment; filename='.$filename.'.csv');
99
100 $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');
101
102 $file = fopen("php://output","w");
103
104 fputcsv($file, array_values($allowed_fields));
105
106 foreach($csv_array as $failed_attempts){
107
108 $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']);
109 fputcsv($file, $row);
110 }
111
112
113 fclose($file);
114
115 wp_die();
116
117 }
118
119 // Export CSV
120 function loginizer_export(){
121
122 // Some AJAX security
123 check_ajax_referer('loginizer_admin_ajax', 'nonce');
124
125 if(!current_user_can('manage_options')){
126 wp_die('Sorry, but you do not have permissions to change settings.');
127 }
128
129 $lz_csv_type = lz_optpost('lz_csv_type');
130
131 switch($lz_csv_type){
132
133 case 'blacklist':
134 $csv_array = get_option('loginizer_blacklist');
135 $filename = 'loginizer-blacklist';
136 break;
137
138 case 'whitelist':
139 $csv_array = get_option('loginizer_whitelist');
140 $filename = 'loginizer-whitelist';
141 break;
142 }
143
144 if(empty($csv_array)){
145 echo -1;
146 echo __('No data to export', 'loginizer');
147 wp_die();
148 }
149
150 header('Content-Type: text/csv; charset=utf-8');
151 header('Content-Disposition: attachment; filename='.$filename.'.csv');
152
153 $allowed_fields = array('start' => 'Start IP', 'end' => 'End IP', 'time' => 'Time');
154
155 $file = fopen("php://output","w");
156
157 fputcsv($file, array_values($allowed_fields));
158
159 foreach($csv_array as $ik => $iv){
160
161 $iv['start'] = $iv['start'];
162 $iv['end'] = $iv['end'];
163 $iv['time'] = date('d/m/Y', $iv['time']);
164
165 $row = array();
166 foreach($allowed_fields as $ak => $av){
167 $row[$ak] = $iv[$ak];
168 }
169
170 fputcsv($file, $row);
171 }
172
173 fclose($file);
174
175 wp_die();
176 }
177
178 function loginizer_social_order(){
179
180 // Some AJAX security
181 check_ajax_referer('loginizer_social_nonce', 'security');
182
183 if(!current_user_can('manage_options')){
184 wp_die(__('Sorry, but you do not have permissions to change settings.', 'loginizer'));
185 }
186
187 $order = map_deep(map_deep($_POST['order'], 'wp_unslash'), 'sanitize_text_field');
188
189 update_option('loginizer_social_order', array_flip($order));
190
191 wp_send_json_success();
192
193 }
194
195 function loginizer_dismiss_license_alert(){
196 // Some AJAX security
197 check_ajax_referer('loginizer_license_notice', 'security');
198
199 if(!current_user_can('manage_options')){
200 wp_die(__('Sorry, but you do not have permissions to change settings.', 'loginizer'));
201 }
202
203 update_option('loginizer_license_notice', (0 - time()), false);
204 die('DONE');
205 }