Skip to content

Commit

Permalink
remote calls, handle sfw
Browse files Browse the repository at this point in the history
  • Loading branch information
davydov committed Jun 4, 2019
1 parent a3814f5 commit 8e78d4a
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 48 deletions.
40 changes: 40 additions & 0 deletions CleanTalk/Base/CleanTalk.php
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ public static function getTemplateAddon() {
$ct_check_value = self::getCheckjsValue();
self::ctSetCookie();
self::ctSFWTest();
self::apbct_remote_call__perform();
$js_template = '<script>
var d = new Date(),
ctTimeMs = new Date().getTime(),
Expand Down Expand Up @@ -491,4 +492,43 @@ static public function ctSFWTest()
}
}

/**
* Cleantalk inner function - perform remote call
*/
static public function apbct_remote_call__perform() {

$remote_calls = array('close_renew_banner', 'sfw_update','sfw_send_logs','update_plugin','update_settings');

$remote_action = $_GET['spbc_remote_call_action'];
$auth_key = trim(XenForo_Application::getOptions()->get('cleantalk','apikey'));

if(array_key_exists($remote_action, $remote_calls_config)) {

if(strtolower($_GET['spbc_remote_call_token']) == strtolower(md5($auth_key))){

// Close renew banner
if($_GET['spbc_remote_call_action'] == 'close_renew_banner'){
die('OK');
// SFW update
}elseif($_GET['spbc_remote_call_action'] == 'sfw_update'){
$sfw = new CleantalkSFW();
$result = $sfw->sfw_update($auth_key);
die(empty($result['error']) ? 'OK' : 'FAIL '.json_encode(array('error' => $result['error_string'])));
// SFW send logs
}elseif($_GET['spbc_remote_call_action'] == 'sfw_send_logs'){
$sfw = new CleantalkSFW();
$result = $sfw->send_logs($auth_key);
die(empty($result['error']) ? 'OK' : 'FAIL '.json_encode(array('error' => $result['error_string'])));
// Update plugin
}elseif($_GET['spbc_remote_call_action'] == 'update_plugin'){
//add_action('wp', 'apbct_update', 1);
}else
die('FAIL '.json_encode(array('error' => 'UNKNOWN_ACTION_2')));
}else
die('FAIL '.json_encode(array('error' => 'WRONG_TOKEN')));
}else
die('FAIL '.json_encode(array('error' => 'UNKNOWN_ACTION')));

}

}
24 changes: 0 additions & 24 deletions CleanTalk/Base/lib/CleantalkHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,26 +245,7 @@ static public function api_method__get_api_key($email, $host, $platform, $agent

return $result;
}

/**
* Function gets information about renew notice
*
* @param string api_key
* @return type
*/
static public function api_method__notice_validate_key($api_key, $do_check = true)
{
$request = array(
'method_name' => 'notice_validate_key',
'auth_key' => $api_key,
);

$result = self::api_send_request($request);
$result = $do_check ? self::api_check_response($result, 'notice_validate_key') : $result;

return $result;
}

/**
* Function gets information about renew notice
*
Expand Down Expand Up @@ -523,11 +504,6 @@ static public function api_check_response($result, $method_name = null)

// Pathces for different methods

// mehod_name = notice_validate_key
if($method_name == 'notice_validate_key' && isset($result['valid'])){
return $result;
}

// Other methods
if(isset($result['data']) && is_array($result['data'])){
return $result['data'];
Expand Down
52 changes: 28 additions & 24 deletions CleanTalk/Base/lib/CleantalkSFW.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,32 +130,36 @@ public function sfw_update_logs($ip, $result){
public function sfw_update($ct_key){

$result = self::api_method__get_2s_blacklists_db($ct_key);

if(empty($result['error'])){

$this->unversal_query("TRUNCATE TABLE ".$this->table_prefix."cleantalk_sfw",true);

// Cast result to int
foreach($result as $value){
$value[0] = intval($value[0]);
$value[1] = intval($value[1]);
} unset($value);

$query="INSERT INTO ".$this->table_prefix."cleantalk_sfw VALUES ";
for($i=0, $arr_count = count($result); $i < $arr_count; $i++){
if($i == count($result)-1){
$query.="(".$result[$i][0].",".$result[$i][1].")";
}else{
$query.="(".$result[$i][0].",".$result[$i][1]."), ";
if ($result) {
if(empty($result['error'])){

$this->unversal_query("TRUNCATE TABLE ".$this->table_prefix."cleantalk_sfw",true);

// Cast result to int
foreach($result as $value){
$value[0] = intval($value[0]);
$value[1] = intval($value[1]);
} unset($value);

$query="INSERT INTO ".$this->table_prefix."cleantalk_sfw VALUES ";
for($i=0, $arr_count = count($result); $i < $arr_count; $i++){
if($i == count($result)-1){
$query.="(".$result[$i][0].",".$result[$i][1].")";
}else{
$query.="(".$result[$i][0].",".$result[$i][1]."), ";
}
}
}
$this->unversal_query($query,true);

return true;

}else{
return $result;
$this->unversal_query($query,true);

return true;

}else{
return $result;
}
} else {
error_log("ERROR GETTING SFW DATA");
}

}

/*
Expand Down

0 comments on commit 8e78d4a

Please sign in to comment.