Skip to content

Commit

Permalink
update version
Browse files Browse the repository at this point in the history
increace js protection
exclude js code to external js file
  • Loading branch information
davydovct committed Jul 9, 2018
1 parent 5de2766 commit 0609d7e
Show file tree
Hide file tree
Showing 10 changed files with 414 additions and 78 deletions.
38 changes: 12 additions & 26 deletions 2.3.x/install.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<modification>
<name>Antispam by Cleantalk</name>
<version>1.4</version>
<version>1.5</version>
<author>Cleantalk Inc.</author>
<link>https://cleantalk.org/</link>
<code>antispambycleantalk</code>
Expand Down Expand Up @@ -124,50 +124,36 @@
<operation>
<search><![CDATA[<div class="buttons">]]></search>
<add position="before"><![CDATA[<input type="hidden" name="ct_checkjs" id="ct_checkjs" value="0" />]]></add>
</operation>
<operation>
<search><![CDATA[<script type="text/javascript"><!--]]></search>
<add position="after"><![CDATA[var date = new Date(); document.getElementById("ct_checkjs").value = date.getFullYear();]]></add>
</operation>
</operation>
</file>
<file path="catalog/view/theme/*/template/checkout/register.tpl">
<operation>
<search><![CDATA[<input type="button" value="<?php echo $button_continue; ?>" id="button-register" data-loading-text="<?php echo $text_loading; ?>" class="btn btn-primary" />]]></search>
<add position="after"><![CDATA[<input type="hidden" name="ct_checkjs" id="ct_checkjs" value="0" />]]></add>
</operation>
<operation>
<search><![CDATA[<script type="text/javascript"><!--]]></search>
<add position="after"><![CDATA[var date = new Date(); document.getElementById("ct_checkjs").value = date.getFullYear();]]></add>
</operation>
</operation>
</file>
<file path="catalog/view/theme/*/template/checkout/guest.tpl">
<operation>
<search><![CDATA[<input type="button" value="<?php echo $button_continue; ?>" id="button-guest" data-loading-text="<?php echo $text_loading; ?>" class="btn btn-primary" />]]></search>
<add position="after"><![CDATA[<input type="hidden" name="ct_checkjs" id="ct_checkjs" value="0" />]]></add>
</operation>
<operation>
<search><![CDATA[<script type="text/javascript"><!--]]></search>
<add position="after"><![CDATA[var date = new Date(); document.getElementById("ct_checkjs").value = date.getFullYear();]]></add>
</operation>
</operation>
</file>
<file path="catalog/view/theme/*/template/product/product.tpl">
<operation>
<search><![CDATA[<div class="buttons clearfix">]]></search>
<add position="before"><![CDATA[<input type="hidden" name="ct_checkjs" id="ct_checkjs" value="0" />]]></add>
</operation>
<operation>
<search><![CDATA[<script type="text/javascript"><!--]]></search>
<add position="after"><![CDATA[var date = new Date(); document.getElementById("ct_checkjs").value = date.getFullYear();]]></add>
</operation>
</operation>
</file>
<file path="catalog/view/theme/*/template/information/contact.tpl">
<operation>
<search><![CDATA[<div class="buttons">]]></search>
<add position="before"><![CDATA[<input type="hidden" name="ct_checkjs" id="ct_checkjs" value="0" />]]></add>
</operation>
</file>
<file path="catalog/view/theme/*/template/common/header.tpl">
<operation>
<search><![CDATA[<?php foreach ($scripts as $script) { ?>]]></search>
<add position="before"><![CDATA[<script src="catalog/view/javascript/antispambycleantalk.js?v=1.5" type="text/javascript"></script>]]></add>
</operation>
<operation>
<search><![CDATA[<?php echo $footer; ?>]]></search>
<add position="before"><![CDATA[<script type="text/javascript">var date = new Date(); document.getElementById("ct_checkjs").value = date.getFullYear();</script>]]></add>
</operation>
</file>
</file>
</modification>
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

class CleantalkFuncs
{
const ENGINE = 'opencart-14';
const ENGINE = 'opencart-15';

private $ct_access_key = '';

Expand Down Expand Up @@ -67,6 +67,13 @@ public function onSpamCheck($content_type, $data)
'fields_number' => sizeof($data),
'REFFERRER_PREVIOUS' => isset($_COOKIE['apbct_prev_referer']) ? $_COOKIE['apbct_prev_referer'] : null,
'cookies_enabled' => $this->apbctCookiesTest(),
'mouse_cursor_positions' => isset($_COOKIE['apbct_pointer_data']) ? json_decode(stripslashes($_COOKIE['apbct_pointer_data']), true) : null,
'js_timezone' => isset($_COOKIE['apbct_timezone']) ? $_COOKIE['apbct_timezone'] : null,
'key_press_timestamp' => isset($_COOKIE['apbct_fkp_timestamp']) ? $_COOKIE['apbct_fkp_timestamp'] : null,
'page_set_timestamp' => isset($_COOKIE['apbct_ps_timestamp']) ? $_COOKIE['apbct_ps_timestamp'] : null,
'form_visible_inputs' => !empty($_COOKIE['apbct_visible_fields_count']) ? $_COOKIE['apbct_visible_fields_count'] : null,
'apbct_visible_fields' => !empty($_COOKIE['apbct_visible_fields']) ? $_COOKIE['apbct_visible_fields'] : null,

));
$post_info = json_encode(array(
'comment_type' => $content_type,
Expand Down
119 changes: 119 additions & 0 deletions 2.3.x/upload/catalog/view/javascript/antispambycleantalk.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
var ct_date = new Date(),
ctTimeMs = new Date().getTime(),
ctMouseEventTimerFlag = true, //Reading interval flag
ctMouseData = [],
ctMouseDataCounter = 0;

function ctSetCookieSec(c_name, value) {
document.cookie = c_name + "=" + encodeURIComponent(value) + "; path=/";
}

function apbct_attach_event_handler(elem, event, callback){
if(typeof window.addEventListener == "function") elem.addEventListener(event, callback);
else elem.attachEvent(event, callback);
}

function apbct_remove_event_handler(elem, event, callback){
if(typeof window.removeEventListener == "function") elem.removeEventListener(event, callback);
else elem.detachEvent(event, callback);
}

ctSetCookieSec("apbct_ps_timestamp", Math.floor(new Date().getTime()/1000));
ctSetCookieSec("apbct_fkp_timestamp", "0");
ctSetCookieSec("apbct_pointer_data", "0");
ctSetCookieSec("apbct_timezone", "0");

setTimeout(function(){
ctSetCookieSec("apbct_timezone", ct_date.getTimezoneOffset()/60*(-1));
},1000);

//Writing first key press timestamp
var ctFunctionFirstKey = function output(event){
var KeyTimestamp = Math.floor(new Date().getTime()/1000);
ctSetCookieSec("ct_fkp_timestamp", KeyTimestamp);
ctKeyStopStopListening();
}

//Reading interval
var ctMouseReadInterval = setInterval(function(){
ctMouseEventTimerFlag = true;
}, 150);

//Writting interval
var ctMouseWriteDataInterval = setInterval(function(){
ctSetCookieSec("apbct_pointer_data", JSON.stringify(ctMouseData));
}, 1200);

//Logging mouse position each 150 ms
var ctFunctionMouseMove = function output(event){
if(ctMouseEventTimerFlag == true){

ctMouseData.push([
Math.round(event.pageY),
Math.round(event.pageX),
Math.round(new Date().getTime() - ctTimeMs)
]);

ctMouseDataCounter++;
ctMouseEventTimerFlag = false;
if(ctMouseDataCounter >= 50){
ctMouseStopData();
}
}
}

//Stop mouse observing function
function ctMouseStopData(){
apbct_remove_event_handler(window, "mousemove", ctFunctionMouseMove);
clearInterval(ctMouseReadInterval);
clearInterval(ctMouseWriteDataInterval);
}

//Stop key listening function
function ctKeyStopStopListening(){
apbct_remove_event_handler(window, "mousedown", ctFunctionFirstKey);
apbct_remove_event_handler(window, "keydown", ctFunctionFirstKey);
}

apbct_attach_event_handler(window, "mousemove", ctFunctionMouseMove);
apbct_attach_event_handler(window, "mousedown", ctFunctionFirstKey);
apbct_attach_event_handler(window, "keydown", ctFunctionFirstKey);

// Ready function
function apbct_ready(){
ctSetCookieSec("apbct_visible_fields", 0);
ctSetCookieSec("apbct_visible_fields_count", 0);
if (document.getElementById("ct_checkjs"))
document.getElementById("ct_checkjs").value = ct_date.getFullYear();
setTimeout(function(){
for(var i = 0; i < document.forms.length; i++){
var form = document.forms[i];
form.onsubmit_prev = form.onsubmit;
form.onsubmit = function(event){
this.visible_fields = '';
this.visible_fields_count = this.elements.length;
for(var j = 0; j < this.elements.length; j++){
var elem = this.elements[j];
if( getComputedStyle(elem).display == "none" ||
getComputedStyle(elem).visibility == "hidden" ||
getComputedStyle(elem).width == "0" ||
getComputedStyle(elem).heigth == "0" ||
getComputedStyle(elem).opacity == "0" ||
elem.getAttribute("type") == "hidden" ||
elem.getAttribute("type") == "submit"
){
this.visible_fields_count--;
}else{
this.visible_fields += (this.visible_fields == "" ? "" : " ") + elem.getAttribute("name");
}
}
ctSetCookieSec("apbct_visible_fields", this.visible_fields);
ctSetCookieSec("apbct_visible_fields_count", this.visible_fields_count);
if(this.onsubmit_prev instanceof Function){
this.onsubmit_prev.call(this, event);
}
}
}
}, 1000);
}
apbct_attach_event_handler(window, "DOMContentLoaded", apbct_ready);
36 changes: 11 additions & 25 deletions 2.x - 2.2.x/install.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<modification>
<name>Antispam by Cleantalk</name>
<version>1.4</version>
<version>1.5</version>
<author>Cleantalk Inc.</author>
<link>https://cleantalk.org/</link>
<code>antispambycleantalk</code>
Expand Down Expand Up @@ -124,50 +124,36 @@
<operation>
<search><![CDATA[<div class="buttons">]]></search>
<add position="before"><![CDATA[<input type="hidden" name="ct_checkjs" id="ct_checkjs" value="0" />]]></add>
</operation>
<operation>
<search><![CDATA[<script type="text/javascript"><!--]]></search>
<add position="after"><![CDATA[var date = new Date(); document.getElementById("ct_checkjs").value = date.getFullYear();]]></add>
</operation>
</operation>
</file>
<file path="catalog/view/theme/*/template/checkout/register.tpl">
<operation>
<search><![CDATA[<input type="button" value="<?php echo $button_continue; ?>" id="button-register" data-loading-text="<?php echo $text_loading; ?>" class="btn btn-primary" />]]></search>
<add position="after"><![CDATA[<input type="hidden" name="ct_checkjs" id="ct_checkjs" value="0" />]]></add>
</operation>
<operation>
<search><![CDATA[<script type="text/javascript"><!--]]></search>
<add position="after"><![CDATA[var date = new Date(); document.getElementById("ct_checkjs").value = date.getFullYear();]]></add>
</operation>
</operation>
</file>
<file path="catalog/view/theme/*/template/checkout/guest.tpl">
<operation>
<search><![CDATA[<input type="button" value="<?php echo $button_continue; ?>" id="button-guest" data-loading-text="<?php echo $text_loading; ?>" class="btn btn-primary" />]]></search>
<add position="after"><![CDATA[<input type="hidden" name="ct_checkjs" id="ct_checkjs" value="0" />]]></add>
</operation>
<operation>
<search><![CDATA[<script type="text/javascript"><!--]]></search>
<add position="after"><![CDATA[var date = new Date(); document.getElementById("ct_checkjs").value = date.getFullYear();]]></add>
</operation>
</operation>
</file>
<file path="catalog/view/theme/*/template/product/product.tpl">
<operation>
<search><![CDATA[<div class="buttons clearfix">]]></search>
<add position="before"><![CDATA[<input type="hidden" name="ct_checkjs" id="ct_checkjs" value="0" />]]></add>
</operation>
<operation>
<search><![CDATA[<script type="text/javascript"><!--]]></search>
<add position="after"><![CDATA[var date = new Date(); document.getElementById("ct_checkjs").value = date.getFullYear();]]></add>
</operation>
</file>
<file path="catalog/view/theme/*/template/information/contact.tpl">
<operation>
<search><![CDATA[<div class="buttons">]]></search>
<add position="before"><![CDATA[<input type="hidden" name="ct_checkjs" id="ct_checkjs" value="0" />]]></add>
</operation>
</file>
<file path="catalog/view/theme/*/template/common/header.tpl">
<operation>
<search><![CDATA[<?php foreach ($scripts as $script) { ?>]]></search>
<add position="before"><![CDATA[<script src="catalog/view/javascript/antispambycleantalk.js?v=1.5" type="text/javascript"></script>]]></add>
</operation>
<operation>
<search><![CDATA[<?php echo $footer; ?>]]></search>
<add position="before"><![CDATA[<script type="text/javascript">var date = new Date(); document.getElementById("ct_checkjs").value = date.getFullYear();</script>]]></add>
</operation>
</file>
</file>
</modification>
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

class CleantalkFuncs
{
const ENGINE = 'opencart-14';
const ENGINE = 'opencart-15';

private $ct_access_key = '';

Expand Down Expand Up @@ -67,6 +67,13 @@ public function onSpamCheck($content_type, $data)
'fields_number' => sizeof($data),
'REFFERRER_PREVIOUS' => isset($_COOKIE['apbct_prev_referer']) ? $_COOKIE['apbct_prev_referer'] : null,
'cookies_enabled' => $this->apbctCookiesTest(),
'mouse_cursor_positions' => isset($_COOKIE['apbct_pointer_data']) ? json_decode(stripslashes($_COOKIE['apbct_pointer_data']), true) : null,
'js_timezone' => isset($_COOKIE['apbct_timezone']) ? $_COOKIE['apbct_timezone'] : null,
'key_press_timestamp' => isset($_COOKIE['apbct_fkp_timestamp']) ? $_COOKIE['apbct_fkp_timestamp'] : null,
'page_set_timestamp' => isset($_COOKIE['apbct_ps_timestamp']) ? $_COOKIE['apbct_ps_timestamp'] : null,
'form_visible_inputs' => !empty($_COOKIE['apbct_visible_fields_count']) ? $_COOKIE['apbct_visible_fields_count'] : null,
'apbct_visible_fields' => !empty($_COOKIE['apbct_visible_fields']) ? $_COOKIE['apbct_visible_fields'] : null,

));
$post_info = json_encode(array(
'comment_type' => $content_type,
Expand Down
Loading

0 comments on commit 0609d7e

Please sign in to comment.