Changeset 620603
- Timestamp:
- 11/03/2012 06:09:12 AM (13 years ago)
- Location:
- cbprotect/trunk
- Files:
-
- 2 edited
-
cbprotectclass.php (modified) (7 diffs)
-
js/click_bomb_check.js (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
cbprotect/trunk/cbprotectclass.php
r618891 r620603 3 3 class bombclick { 4 4 5 var $wpdb = null;5 var $wpdb = null; 6 6 var $clientip = null; 7 7 var $clickcount = null; 8 8 var $clientfound = null; 9 var $isblockedip = null;10 var $table_name = null;9 var $isblockedip = null; 10 var $table_name = null; 11 11 12 12 function __construct($dbcls=null) … … 14 14 if ($dbcls) $this->wpdb = $dbcls; 15 15 else $this->getdbo(); 16 $this->table_name = $this->wpdb->prefix."AD_CLICK";16 $this->table_name = $this->wpdb->prefix."AD_CLICK"; 17 17 $this->clientip = $this->getclientip(); 18 18 $this->clickcount = (isset($_POST['count']))?isset($_POST['count']):isset($_GET['count']); 19 19 $this->clientfound = $this->checkclient(); 20 20 } 21 22 21 23 22 24 function fs_get_wp_root_path()25 {26 $base = dirname(__FILE__);27 $path = false;28 23 29 if (@file_exists(dirname(dirname($base))."/wp-config.php")) 30 { 31 $path = dirname(dirname($base))."/"; 32 } 33 else 34 if (@file_exists(dirname(dirname(dirname($base)))."/wp-config.php")) 35 { 36 $path = dirname(dirname(dirname($base)))."/"; 37 } 38 else 39 $path = false; 24 function fs_get_wp_root_path() 25 { 26 $base = dirname(__FILE__); 27 $path = false; 40 28 41 if ($path != false) 42 { 43 $path = str_replace("\\", "/", $path); 44 } 45 return $path; 46 } 29 if (@file_exists(dirname(dirname($base))."/wp-config.php")) 30 { 31 $path = dirname(dirname($base))."/"; 32 } 33 else 34 if (@file_exists(dirname(dirname(dirname($base)))."/wp-config.php")) 35 { 36 $path = dirname(dirname(dirname($base)))."/"; 37 } 38 else 39 $path = false; 40 41 if ($path != false) 42 { 43 $path = str_replace("\\", "/", $path); 44 } 45 return $path; 46 } 47 47 48 48 function getdbo() { 49 49 if (!isset($wpdb)) { 50 50 $wp_root_path = $this->fs_get_wp_root_path(); 51 52 //include_once($wp_root_path . 'wp-config.php');53 51 include_once($wp_root_path . 'wp-load.php'); 54 52 include_once($wp_root_path .'wp-includes/wp-db.php'); … … 57 55 $this->wpdb = $wpdb; 58 56 } 59 57 60 58 61 59 function getclientip() { 62 $clientip = $_SERVER['REMOTE_ADDR']; //"222.4.4.1"; 63 return $clientip; 64 } 65 66 function getFirstClickTimeStamp() 67 { 68 $getresult = null; 69 $result = $this->wpdb->get_var( "SELECT CLICK_TIMESTAMP FROM ".esc_attr($this->table_name)." where IP_ADDRESS='".esc_attr($this->clientip)."' order by CLICK_TIMESTAMP asc limit 0,1"); 70 $fulldate = explode(" ",$result); 71 $date = $fulldate[0]; 72 $time = $fulldate[1]; 73 $firstclickdata[] = explode("-",$date); 74 $firstclickdata[] = explode(":",$time); 75 76 return $firstclickdata; 77 78 } 79 80 function dateDiff($start, $end) 81 { 82 83 $start_ts = strtotime($start); 84 85 $end_ts = strtotime($end); 86 87 $diff = $end_ts - $start_ts; 88 89 return round($diff / 86400); 90 91 } 92 93 60 $clientip = $_SERVER['REMOTE_ADDR']; 61 return $clientip; 62 } 63 64 function getFirstClickTimeStamp() 65 { 66 $getresult = null; 67 $result = $this->wpdb->get_var( "SELECT CLICK_TIMESTAMP FROM ".esc_attr($this->table_name)." where IP_ADDRESS='".esc_attr($this->clientip)."' order by CLICK_TIMESTAMP asc limit 0,1"); 68 $fulldate = explode(" ",$result); 69 $date = $fulldate[0]; 70 $time = $fulldate[1]; 71 $firstclickdata[] = explode("-",$date); 72 $firstclickdata[] = explode(":",$time); 73 74 return $firstclickdata; 75 76 } 77 78 function dateDiff($start, $end) 79 { 80 $start_ts = strtotime($start); 81 $end_ts = strtotime($end); 82 $diff = $end_ts - $start_ts; 83 return round($diff / 86400); 84 } 85 86 94 87 function checkclient() 95 88 { 96 97 89 $bannedperiod = get_option('cbprotect_ban_period'); 98 90 $daySpan = get_option('cbprotect_day_span'); … … 101 93 $clickdateimplode = implode("-",$clickfirstdate); 102 94 $clickdate = str_replace("-","",$clickdateimplode); 103 104 $currentdatedata = date('Y-m-d'); //date("2012-09-15");95 96 $currentdatedata = date('Y-m-d'); //date("2012-09-15"); 105 97 $currentdate = str_replace("-","",$currentdatedata); 106 98 $enddatedata = strtotime ( '+'.$bannedperiod.' day' , strtotime ( $clickdateimplode ) ) ; 107 99 $enddate = str_replace("-","",date ( 'Y-m-d' , $enddatedata )); 108 $endformat = date($enddate);109 110 $daysDiff = $this->dateDiff($clickdateimplode,$currentdatedata);111 112 $sql = "select IP_ADDRESS,BLOCKED from ".$this->table_name." where IP_ADDRESS='".$this->clientip."'";100 $endformat = date($enddate); 101 102 $daysDiff = $this->dateDiff($clickdateimplode,$currentdatedata); 103 104 $sql = "select IP_ADDRESS,BLOCKED from ".$this->table_name." where IP_ADDRESS='".$this->clientip."'"; 113 105 $results = $this->wpdb->get_results($sql); 114 106 115 107 if(empty($results)) 116 108 { … … 124 116 { 125 117 $clickip = $row->IP_ADDRESS; 126 127 if($daysDiff <= $daySpan)128 {129 $sqlquery = "select * from ".$this->table_name." where IP_ADDRESS ='".$clickip."' and CLICK_TIMESTAMP like '$clickdateimplode%'";130 $resultsql = $this->wpdb->get_results($sqlquery);131 }132 else if($daysDiff > $daySpan)133 {134 135 $sqlquery = "select * from ".$this->table_name." where IP_ADDRESS ='".$clickip."' and CLICK_TIMESTAMP like '$currentdatedata%'";136 $resultsql = $this->wpdb->get_results($sqlquery);137 }138 118 119 if($daysDiff <= $daySpan) 120 { 121 $sqlquery = "select * from ".$this->table_name." where IP_ADDRESS ='".$clickip."' and CLICK_TIMESTAMP like '$clickdateimplode%'"; 122 $resultsql = $this->wpdb->get_results($sqlquery); 123 } 124 else if($daysDiff > $daySpan) 125 { 126 127 $sqlquery = "select * from ".$this->table_name." where IP_ADDRESS ='".$clickip."' and CLICK_TIMESTAMP like '$currentdatedata%'"; 128 $resultsql = $this->wpdb->get_results($sqlquery); 129 } 130 139 131 $countresult = count($resultsql); 140 132 return $countresult; 141 133 142 134 } 143 135 } 144 136 145 137 } 146 138 … … 148 140 function updateclick() 149 141 { 150 $clickcount = get_option('cbprotect_click_threshold');142 $clickcount = get_option('cbprotect_click_threshold'); 151 143 $bannedperiod = get_option('cbprotect_ban_period'); 152 144 $daySpan = get_option('cbprotect_day_span'); 153 145 154 146 $clickdata = $this->getFirstClickTimeStamp(); 155 147 $clickfirstdate = $clickdata[0]; 156 $clickdateimplode = implode("-",$clickfirstdate);148 $clickdateimplode = implode("-",$clickfirstdate); 157 149 $clickdate = str_replace("-","",$clickdateimplode); 158 150 159 151 $currentdatedata = date('Y-m-d'); //date("2012-09-15"); 160 $currentdate = str_replace("-","",$currentdate1);152 $currentdate = str_replace("-","",$currentdate1); 161 153 $enddate = strtotime ( '+'.$bannedperiod.' day' , strtotime ( $clickdateimplode ) ) ; 162 154 $enddate = str_replace("-","",date ( 'Y-m-d' , $enddate )); 163 155 $endformat = date($enddate); 164 156 $daysDiff = $this->dateDiff($clickdateimplode,$currentdatedata); 165 157 166 158 if ($this->clientfound < $clickcount) 167 159 { … … 174 166 if (($this->clientfound >= $clickcount || $this->clickcount >= $clickcount)) { 175 167 $setfield = 'BLOCKED=1 '; 176 177 $sql = "UPDATE ".$this->table_name." SET ".$setfield." where IP_ADDRESS='".$this->clientip."'";178 $resultinsert = $this->wpdb->query($sql);168 169 $sql = "UPDATE ".$this->table_name." SET ".$setfield." where IP_ADDRESS='".$this->clientip."'"; 170 $resultinsert = $this->wpdb->query($sql); 179 171 } 180 172 } 181 182 173 174 183 175 return $resultinsert; 184 176 185 177 } 186 178 187 179 function clientdetail($preurl) { 188 180 $clientdetail = array( 189 "client_ip"=>$this->getclientip(),190 "clickcount"=>get_option('cbprotect_click_threshold'),191 "bannedperiod"=>get_option('cbprotect_ban_period'),192 "preurl" => $preurl,193 "firstclickdate" => $this->getFirstClickTimeStamp(),194 "updatedVisitCount" => $this->checkclient(),195 );181 "client_ip"=>$this->getclientip(), 182 "clickcount"=>get_option('cbprotect_click_threshold'), 183 "bannedperiod"=>get_option('cbprotect_ban_period'), 184 "preurl" => $preurl, 185 "firstclickdate" => $this->getFirstClickTimeStamp(), 186 "updatedVisitCount" => $this->checkclient(), 187 ); 196 188 return $clientdetail; 197 189 } 198 190 199 191 } 200 201 202 192 ?> -
cbprotect/trunk/js/click_bomb_check.js
r618891 r620603 1 1 var clientIP= client.client_ip; 2 //alert("clientIP"+clientIP);3 2 var maxclickcount = client.clickcount; 4 3 var bannedperiod = client.bannedperiod; 5 4 var preurl = client.preurl; 6 5 var firstclickdata = client.firstclickdate; 7 //alert("firstclickdata"+firstclickdata);8 6 var firstclickdate = firstclickdata[0][1]-1; 9 //alert(firstclickdate);10 7 var updatedVisitCount = parseInt(client.updatedVisitCount); 11 8 var jq = null; … … 13 10 var oneDay = 24*60*60*1000; // hours*minutes*seconds*milliseconds 14 11 var clickdate = new Date(firstclickdata[0][0],firstclickdate,firstclickdata[0][2],firstclickdata[1][0],firstclickdata[1][1],firstclickdata[1][2]); 15 //alert("clickdate"+clickdate);16 17 12 var currDate = new Date(); 18 19 13 var secondDate = clickdate.setTime(clickdate.getTime() + (bannedperiod * 24 * 60 * 60 * 1000)); 20 14 var endDate = new Date(secondDate); 21 //alert("endDate"+endDate);22 15 23 16 … … 25 18 { 26 19 var clientdata = {"clientIP":clientIP,"visitcount":updatedVisitCount}; 27 console.log(clientdata);28 20 if (clientdata.clientIP) { 29 console.log("The client IP has matched");30 21 updatedVisitCount = ++clientdata.visitcount; 31 //alert("in if updatedVisitCount"+updatedVisitCount);32 22 33 23 } else { … … 35 25 36 26 } 37 38 27 ajax_post(); 39 40 28 if (updatedVisitCount > maxclickcount) 41 29 { 42 //alert("in maxclick");43 44 console.log("Default click has been prevented");45 30 event.preventDefault(); 46 31 47 32 48 33 } 49 50 34 } 51 35 … … 75 59 jq = jQuery.noConflict(); 76 60 77 $("#cbprotect img").click(function(event) {61 $("#cbprotect").click(function(event) { 78 62 cbProtectProcess(event); 79 63
Note: See TracChangeset
for help on using the changeset viewer.