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