";
if(strlen($error_msg)<1 && strlen($usr_token)>0 && $atb_token==$usr_token) {
$target=get_transient('atb_target_'.atb_cui());
if(get_transient('atb_prompt_mobile_'.atb_cui())!==false) if(strpos($target,'?')===false) $target.="?atb_mob=1"; else $target.="&atb_mob=1";
delete_transient('atb_prompt_mobile_'.atb_cui());
delete_transient('atb_target_'.atb_cui());
delete_transient("atb_flag_$ip:".atb_cui());
delete_transient('atb_token_'.atb_cui());
delete_transient('atb_sent_to_'.atb_cui());
atb_hit_page();
wp_redirect(atb_login_redirect($target)); exit;
} else {
sleep(3); // Slow down brute force attempts ?>
Two Factor Authentication
General
if($base!==$site) { // Fix AIOWPS Redirect bug
global $wpdb;
$get_config=atb_r("SELECT 1 FROM wp_atb_options WHERE option_name='match_redirect' AND option_value>0;");
if(!$get_config) return;
if(atb_is_path(basename(get_admin_url()))) wp_redirect(admin_url().$_SERVER['REQUEST_URI']); else wp_redirect(site_url().$_SERVER['REQUEST_URI']);
exit;
}
}
add_action('wp_loaded','atb_match_redirect',10);
//Redirect to HTTPS
function atb_https_redirect() {
if(empty($_SERVER['HTTPS'])) {
$get_config=atb_r("SELECT 1 FROM wp_atb_options WHERE option_name='https_redirect' AND option_value>0");
if(!$get_config) return;
if(isset($_SERVER['SERVER_NAME'])) header("Location: https://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']);
exit;
}
}
add_action('wp_loaded','atb_https_redirect',10);
// Compress PageHits
function atb_compress_hits() {
ignore_user_abort(true);
set_time_limit(300);
$ct=0;
set_transient('atb_compress_timeout',1,45);
if(!get_transient('atb_compress_max_days')) $max_days=180; else $max_days=get_transient('atb_compress_max_days');
$status="
";
for($x=$max_days;$x>=30;) {
$y=$x+10;
$r=atb_r("DELETE pg FROM wp_atb_pagehits pg
JOIN (
SELECT MAX(hit_id) as hit_id
FROM wp_atb_pagehits
WHERE userid<1
AND date =DATE_FORMAT(NOW(),'%Y-%m-%d')-INTERVAL $y DAY
GROUP BY LEFT(date,13),ip,userid,url,referrer
HAVING COUNT(ip)>1
ORDER BY hit_id ASC
LIMIT 2000
)mx ON mx.hit_id=pg.hit_id;");
$ct=$ct+intval($r);
if($x>30 && !get_transient('atb_compress_timeout')) {
if($max_days>30) set_transient('atb_compress_max_days',$max_days-20);
return $status."Range:$x-$max_days days
".number_format($ct)." hits compressed";
}
sleep(1);
$x=$x-10;
}
delete_transient('atb_compress_max_days');
if(!get_transient('atb_compress_optimized')) {
set_transient('atb_compress_optimized',1,259000); //every 3 days
atb_r("OPTIMIZE TABLE wp_atb_pagehits;");
return $status."Fully optimized.".number_format($ct)." hits compressed";
} else return $status."Max compression achieved.".number_format($ct)." hits compressed";
}
// PageHit Summary
function atb_view_summary($atb_version_type) {
if(get_transient('limit_img_size_kb_'.atb_cui())!==false) delete_transient('limit_img_size_kb_'.atb_cui());
$current_mth=current_time('Y-m-01');
$last_gen_mth=get_option('atb_mt_max');
if(!$last_gen_mth) $last_gen_mth=get_transient('atb_mt_max');
if(!$last_gen_mth) $last_gen_mth=$current_mth;
$mth=get_option('atb_mt');
if(!$mth) $mth=get_transient('atb_mt'); // Find Historical Month Stats
function atb_month_stat($params) {
$query="
SELECT DATE_FORMAT(CONCAT(month,'-01'),'%b %y') as month
,month as month_id,visitors
,ROUND(visitors/CASE WHEN month=DATE_FORMAT(NOW(),'%Y-%m') THEN DAY(NOW()) ELSE 30 END,0) as day_avg
FROM (
SELECT LEFT(date,7) as month,COUNT(DISTINCT ip) as visitors
FROM wp_atb_pagehits
WHERE date>NOW()-INTERVAL 400 DAY $params
AND url NOT LIKE '/wp-%'
GROUP BY LEFT(date,7)
)a
ORDER BY DATE_FORMAT(CONCAT(month,'-01'),'%y-%m');";
$mth=atb_r($query);
return $mth;
}
// Create Historical Month Stats
if(!$mth) {
$mth=atb_month_stat("AND date<'$current_mth'");
update_option('atb_mt',$mth,false);
update_option('atb_mt_max',$current_mth,false);
}
// Get Month Stats between last Gen Date and Month Begin
if(!$mth || $current_mth>$last_gen_mth) {
$mth_new=atb_month_stat("AND date>='$last_gen_mth' AND date<'$current_mth'");
if($mth && $mth_new) {
$mth=array_merge($mth,$mth_new); // Append Historical with Current
update_option('atb_mt',$mth,false);
update_option('atb_mt_max',$current_mth,false);
delete_transient('atb_mt');
delete_transient('atb_mt_max');
}
}
// Get Month Stats greater than Month Begin
$mth_new=atb_month_stat("AND date>='$current_mth'");
if(!$mth)$mth=$mth_new;
elseif($mth_new)$mth=array_merge($mth,$mth_new); // Append Historical with Today
$current_day=current_time('Y-m-d');
$last_gen_day=get_option('atb_dy_max');
if(!$last_gen_day) $last_gen_day=get_transient('atb_dy_max');
if(!$last_gen_day) $last_gen_day=$current_day;
$day=get_option('atb_dy');
if(!$day) $day=get_transient('atb_dy'); // Find Historical Day Stats
function atb_day_stat($params) {
$query="
SELECT DATE_FORMAT(date,'%a %D') as day
,date as date_id
,DATE_FORMAT(CONCAT(date,'-01'),'%b %y') as month,visitors
,visitors
FROM (
SELECT LEFT(date,10) as date,COUNT(DISTINCT ip) as visitors
FROM wp_atb_pagehits
WHERE date>NOW()-INTERVAL 400 DAY $params
AND url NOT LIKE '/wp-%'
GROUP BY LEFT(date,10)
)a
ORDER BY date;";
$day=atb_r($query);
return $day;
}
// Create Historical Day Stats
if(!$day) {
$day=atb_day_stat("AND date<'$current_day'");
update_option('atb_dy',$day,false);
update_option('atb_dy_max',$current_day,false);
}
// Get Day Stats between last Gen Date and Today
if(!$day || $current_day>$last_gen_day) {
$day_new=atb_day_stat("AND date>='$last_gen_day' AND date<'$current_day' ");
if($day && $day_new){ // Append Historical with Current
$day=array_merge($day,$day_new);
update_option('atb_dy',$day,false);
update_option('atb_dy_max',$current_day,false);
delete_transient('atb_dy');
delete_transient('atb_dy_max');
}
}
// Get Day Stats Today
$day_new=atb_day_stat("AND date>='$current_day'");
if(!$day) $day=$day_new;
elseif($day_new)$day=array_merge($day,$day_new); // Append Historical with Today
$max_visit_avg=0;
$max_visit_tot=0;
if($mth) foreach($mth as $mth_item) if($mth_item->day_avg>$max_visit_avg) {$max_visit_avg=$mth_item->day_avg; $max_visit_tot=$mth_item->visitors;} ?>