public static function hookData() { $last_check = intval(\IPS\Settings::i()->cleantalk_last_check); $last_status = intval(\IPS\Settings::i()->cleantalk_last_status); $api_key = \IPS\Settings::i()->access_key; $result = ''; $html = ''; if (time() - $last_check > 86400 && $api_key != 0 && $api_key != '') { $data = array(); $data['auth_key'] = $api_key; $data['method_name'] = 'notice_validate_key'; if (!function_exists('sendRawRequest')) { require_once dirname($_SERVER['SCRIPT_FILENAME']) . "/../uploads/cleantalk.class.php"; require_once dirname($_SERVER['SCRIPT_FILENAME']) . "/../uploads/JSON.php"; } $result = sendRawRequest('https://api.cleantalk.org', $data); $result = json_decode(trim($result)); if (isset($result->valid)) { $new_status = intval($result->valid); \IPS\Settings::i()->cleantalk_last_status = $new_status; } else { $new_status = 0; } if ($new_status == 1 && $last_status == 0) { \IPS\Settings::i()->cleantalk_show_banner = 1; } \IPS\Settings::i()->cleantalk_last_check = time(); } if (isset($_COOKIE['cleantalk_close_banner'])) { \IPS\Settings::i()->cleantalk_show_banner = 0; } $show_banner = intval(\IPS\Settings::i()->cleantalk_show_banner); if ($show_banner == 1) { $html = "<div style='width:99%;background: #90EE90; padding:10px;border: 2px dashed green;margin:3px;font-size:16px;text-align:center;' id='cleantalk_banner'>Like antispam by CleanTalk? <a href='https://community.invisionpower.com/files/file/7706-anti-spam-ips4/' target='_blank'>Leave a review!</a><div style='float:right;margin-top:-5px;margin-right:-5px;'><a href=# style='text-decoration:none;font-size:14px;font-weight:600;' onclick='jQuery(\"#cleantalk_banner\").hide(\"slow\");document.cookie=\"cleantalk_close_banner = 1;\"'>X</a></div></div>"; } return array_merge_recursive(array('globalTemplate' => array(0 => array('selector' => '#acpPageHeader', 'type' => 'add_after', 'content' => $html))), parent::hookData()); }
function cleantalk_update_sfw() { global $wpdb; $wpdb->query("drop table if exists `" . $wpdb->base_prefix . "cleantalk_sfw`;"); $wpdb->query("CREATE TABLE IF NOT EXISTS `" . $wpdb->base_prefix . "cleantalk_sfw` (\n`network` int(11) unsigned NOT NULL,\n`mask` int(11) unsigned NOT NULL,\nINDEX ( `network` , `mask` )\n) ENGINE = MYISAM ;"); if (!function_exists('sendRawRequest')) { require_once 'inc/cleantalk.class.php'; } global $ct_options, $ct_data; if (isset($ct_options['spam_firewall'])) { $value = @intval($ct_options['spam_firewall']); } else { $value = 0; } if ($value == 1) { $data = array('auth_key' => $ct_options['apikey'], 'method_name' => '2s_blacklists_db'); $result = sendRawRequest('https://api.cleantalk.org/2.1', $data); $result = json_decode($result, true); if (!isset($result['error_no'])) { $result = $result['data']; $query = "INSERT INTO `" . $wpdb->base_prefix . "cleantalk_sfw` VALUES "; if (sizeof($result) > 10) { //$wpdb->query("TRUNCATE TABLE `".$wpdb->base_prefix."cleantalk_sfw`;"); for ($i = 0; $i < sizeof($result); $i++) { if ($i == sizeof($result) - 1) { $query .= "(" . $result[$i][0] . "," . $result[$i][1] . ");"; } else { $query .= "(" . $result[$i][0] . "," . $result[$i][1] . "), "; } } $wpdb->query($query); } } } }
/** * Function gets information about spam active networks * * @param string api_key * @return JSON/array */ public function get_2s_blacklists_db($api_key) { $request = array(); $request['method_name'] = '2s_blacklists_db'; $request['auth_key'] = $api_key; $url = 'https://api.cleantalk.org'; $result = sendRawRequest($url, $request); return $result; }
/** * Function gets information about renew notice * * @param string api_key * @return type */ function noticePaidTill($api_key) { $request = array(); $request['method_name'] = 'notice_paid_till'; $request['auth_key'] = $api_key; $url = 'https://api.cleantalk.org'; $result = sendRawRequest($url, $request); return $result; }
/** * After options update * @return array */ function ct_update_option($option_name) { global $show_ct_notice_online, $ct_notice_online_label, $ct_notice_trial_label, $trial_notice_showtime, $ct_options, $ct_data, $ct_server_timeout; $ct_options = ct_get_options(true); $ct_data = ct_get_data(true); if ($option_name !== 'cleantalk_settings') { return; } $api_key = $ct_options['apikey']; if (isset($_POST['cleantalk_settings']['apikey'])) { $api_key = trim($_POST['cleantalk_settings']['apikey']); $ct_options['apikey'] = $api_key; } if (@isset($_POST['cleantalk_settings']['spam_firewall']) && $_POST['cleantalk_settings']['spam_firewall'] == 1) { cleantalk_update_sfw(); } if (!ct_valid_key($api_key)) { return; } /*$ct_base_call_result = ct_base_call(array( 'message' => 'CleanTalk setup test', 'example' => null, 'sender_email' => '*****@*****.**', 'sender_nickname' => 'CleanTalk', 'post_info' => '', 'checkjs' => 1 ));*/ $key_valid = true; $app_server_error = false; $ct_data['testing_failed'] = 0; if (!function_exists('sendRawRequest')) { require_once 'cleantalk.class.php'; } $request = array(); $request['method_name'] = 'notice_validate_key'; $request['auth_key'] = $api_key; $url = 'https://api.cleantalk.org'; if (!function_exists('sendRawRequest')) { require_once 'cleantalk.class.php'; } $result = sendRawRequest($url, $request); if ($result) { $result = json_decode($result, true); if (isset($result['valid']) && $result['valid'] == 0) { $key_valid = false; $ct_data['testing_failed'] = 1; } } if (!$result || !isset($result['valid'])) { $app_server_error = true; $ct_data['testing_failed'] = 1; } update_option('cleantalk_data', $ct_data); if ($key_valid) { // Removes cookie for server errors if ($app_server_error) { setcookie($ct_notice_online_label, '', 1, '/'); // time 1 is exactly in past even clients time() is wrong unset($_COOKIE[$ct_notice_online_label]); } else { setcookie($ct_notice_online_label, (string) time(), strtotime("+14 days"), '/'); } setcookie($ct_notice_trial_label, '0', strtotime("+{$trial_notice_showtime} minutes"), '/'); } else { setcookie($ct_notice_online_label, 'BAD_KEY', 0, '/'); } }
public function send_logs() { global $ct_options, $ct_data; $ct_options = ct_get_options(); $ct_data = ct_get_data(); if (isset($ct_options['spam_firewall'])) { $value = @intval($ct_options['spam_firewall']); } else { $value = 0; } if ($value == 1 && isset($ct_data['sfw_log'])) { $sfw_log = $ct_data['sfw_log']; $data = array(); foreach ($sfw_log as $key => $value) { $data[] = array($key, $value['all'], $value['allow'], $value['datetime']); } $qdata = array('data' => json_encode($data), 'rows' => count($data), 'timestamp' => time()); if (!function_exists('sendRawRequest')) { require_once 'cleantalk.class.php'; } $result = sendRawRequest('https://api.cleantalk.org/?method_name=sfw_logs&auth_key=' . $ct_options['apikey'], $qdata); $result = json_decode($result); if (isset($result->data) && isset($result->data->rows)) { if ($result->data->rows == count($data)) { $ct_data['sfw_log'] = array(); update_option('cleantalk_data', $ct_data); } } } }
$ct_request->auth_key = $values['access_key']; $ct_request->sender_nickname = 'CleanTalk'; $ct_request->sender_ip = $_SERVER['REMOTE_ADDR']; $ct_request->sender_email = '*****@*****.**'; $ct_request->agent = 'ipboard4-18'; $ct_request->js_on = 1; $ct_request->message = 'This message is a test to check the connection to the CleanTalk servers.'; $ct_result = $ct->isAllowMessage($ct_request); $form->saveAsSettings(); if (\IPS\Settings::i()->cleantalk_sfw == 1) { $sql = "DROP TABLE IF EXISTS `cleantalk_sfw`"; $result = IPS\Db::i()->query($sql); $sql = "CREATE TABLE IF NOT EXISTS `cleantalk_sfw` (\n`network` int(11) unsigned NOT NULL,\n`mask` int(11) unsigned NOT NULL,\nINDEX ( `network` , `mask` )\n) ENGINE = MYISAM "; $result = IPS\Db::i()->query($sql); $data = array('auth_key' => $values['access_key'], 'method_name' => '2s_blacklists_db'); $result = sendRawRequest('https://api.cleantalk.org/2.1', $data, false); $result = json_decode($result, true); if (isset($result['data'])) { $result = $result['data']; $query = "INSERT INTO `cleantalk_sfw` VALUES "; for ($i = 0; $i < sizeof($result); $i++) { if ($i == sizeof($result) - 1) { $query .= "(" . $result[$i][0] . "," . $result[$i][1] . ")"; } else { $query .= "(" . $result[$i][0] . "," . $result[$i][1] . "), "; } } $result = IPS\Db::i()->query($query); } } return TRUE;
public function CleantalkTestMessage($key) { require_once 'lib/cleantalk.class.php'; $url = 'http://moderate.cleantalk.org/api2.0'; $dt = array('auth_key' => $_POST['cleantalk_authkey'], 'method_name' => 'send_feedback', 'feedback' => 0 . ':' . 'magento-121'); $result = sendRawRequest($url, $dt, true); return $result; }
/** * Calling by hook integrate_load_theme */ function cleantalk_load() { global $context, $user_info, $modSettings, $smcFunc; if (isset($context['template_layers']) && is_array($context['template_layers']) && in_array('body', $context['template_layers']) && ($user_info['is_guest'] || $user_info['posts'] == 0) && !cleantalk_is_valid_js()) { $context['html_headers'] .= cleantalk_print_js_input(); } if ($user_info['is_admin'] && isset($_POST['ct_del_user'])) { foreach ($_POST['ct_del_user'] as $key => $value) { $result = $smcFunc['db_query']('', 'delete from {db_prefix}members where id_member=' . intval($key), array()); $result = $smcFunc['db_query']('', 'delete from {db_prefix}topics where id_member_started=' . intval($key), array()); $result = $smcFunc['db_query']('', 'delete from {db_prefix}messages where id_member=' . intval($key), array()); } } if ($user_info['is_admin'] && isset($_POST['ct_delete_all'])) { $result = $smcFunc['db_query']('', 'select * from {db_prefix}members where ct_marked=1', array()); while ($row = $smcFunc['db_fetch_assoc']($result)) { $tmp = $smcFunc['db_query']('', 'delete from {db_prefix}topics where id_member_started=' . $row['id_member'], array()); $tmp = $smcFunc['db_query']('', 'delete from {db_prefix}messages where id_member=' . $row['id_member'], array()); } $result = $smcFunc['db_query']('', 'delete from {db_prefix}members where ct_marked=1', array()); } if (isset($context['template_layers']) && $context['template_layers'] === array('html', 'body') && array_key_exists('cleantalk_tell_others', $modSettings) && $modSettings['cleantalk_tell_others']) { // add "tell others" templates $context['template_layers'][] = 'cleantalk'; } if (isset($_POST['cleantalk_api_key'])) { $ct = new Cleantalk(); $ct->server_url = CT_SERVER_URL; $ct_request = new CleantalkRequest(); $ct_request->auth_key = cleantalk_get_api_key(); $ct_request->response_lang = 'en'; // SMF use any charset and language $ct_request->agent = CT_AGENT_VERSION; $ct_request->sender_email = '*****@*****.**'; $ip = isset($user_info['ip']) ? $user_info['ip'] : $_SERVER['REMOTE_ADDR']; $ct_request->sender_ip = $ct->ct_session_ip($ip); $ct_request->sender_nickname = 'CleanTalk'; $ct_request->message = 'This message is a test to check the connection to the CleanTalk servers.'; $ct_request->submit_time = 10; $ct_request->js_on = 1; $ct_result = $ct->isAllowMessage($ct_request); } if (isset($_POST['cleantalk_sfw']) && $_POST['cleantalk_sfw'] == 1) { global $smcFunc; $sql = "DROP TABLE IF EXISTS `cleantalk_sfw`"; $result = $smcFunc['db_query']('', $sql, array()); $sql = "CREATE TABLE IF NOT EXISTS `cleantalk_sfw` (\n`network` int(11) unsigned NOT NULL,\n`mask` int(11) unsigned NOT NULL,\nINDEX ( `network` , `mask` )\n) ENGINE = MYISAM "; $result = $smcFunc['db_query']('', $sql, array()); $data = array('auth_key' => cleantalk_get_api_key(), 'method_name' => '2s_blacklists_db'); $result = sendRawRequest('https://api.cleantalk.org/2.1', $data, false); $result = json_decode($result, true); if (isset($result['data'])) { $result = $result['data']; $query = "INSERT INTO `cleantalk_sfw` VALUES "; for ($i = 0; $i < sizeof($result); $i++) { if ($i == sizeof($result) - 1) { $query .= "(" . $result[$i][0] . "," . $result[$i][1] . ")"; } else { $query .= "(" . $result[$i][0] . "," . $result[$i][1] . "), "; } } $result = $smcFunc['db_query']('', $query, array()); } } if (isset($modSettings['cleantalk_sfw']) && $modSettings['cleantalk_sfw'] == 1) { $is_sfw_check = true; $ip = CleantalkGetIP(); $ip = array_unique($ip); $key = cleantalk_get_api_key(); for ($i = 0; $i < sizeof($ip); $i++) { if (isset($_COOKIE['ct_sfw_pass_key']) && $_COOKIE['ct_sfw_pass_key'] == md5($ip[$i] . $key)) { $is_sfw_check = false; if (isset($_COOKIE['ct_sfw_passed'])) { @setcookie('ct_sfw_passed', '0', 1, "/"); } } } if ($is_sfw_check) { include_once "cleantalk-sfw.class.php"; $sfw = new CleanTalkSFW(); $sfw->cleantalk_get_real_ip(); $sfw->check_ip(); if ($sfw->result) { $sfw->sfw_die(); } } } }
public static function onSkinAfterBottomScripts($skin, &$text) { global $wgCTShowLink, $wgCTSFW, $wgCTDataStoreFile, $wgCTAccessKey; /* SFW starts */ if ($wgCTSFW && file_exists($wgCTDataStoreFile)) { $settings = file_get_contents($wgCTDataStoreFile); include_once "cleantalk-sfw.class.php"; if ($settings) { $settings = json_decode($settings, true); if (!isset($settings['lastSFWUpdate'])) { $settings['lastSFWUpdate'] = 0; } if (time() - $settings['lastSFWUpdate'] > 30) { $dbr = wfGetDB(DB_MASTER); $dbr->query("DROP TABLE IF EXISTS `cleantalk_sfw`;"); $dbr->commit(); $dbr->query("CREATE TABLE IF NOT EXISTS `cleantalk_sfw` (\n\t\t`network` int(11) unsigned NOT NULL,\n\t\t`mask` int(11) unsigned NOT NULL,\n\t\tINDEX ( `network` , `mask` )\n\t\t) ENGINE = MYISAM ;"); $dbr->commit(); $data = array('auth_key' => $wgCTAccessKey, 'method_name' => '2s_blacklists_db'); $result = sendRawRequest('https://api.cleantalk.org/2.1', $data, false); $result = json_decode($result, true); if (isset($result['data'])) { $result = $result['data']; $query = "INSERT INTO `cleantalk_sfw` VALUES "; for ($i = 0; $i < sizeof($result); $i++) { if ($i == sizeof($result) - 1) { $query .= "(" . $result[$i][0] . "," . $result[$i][1] . ");"; } else { $query .= "(" . $result[$i][0] . "," . $result[$i][1] . "), "; } } $result = $dbr->query($query); $dbr->commit(); $settings['lastSFWUpdate'] = time(); $fp = fopen($wgCTDataStoreFile, 'w') or error_log('Could not open file:' . $wgCTDataStoreFile); fwrite($fp, json_encode($settings)); fclose($fp); } } /* Check IP here */ $is_sfw_check = true; $ip = CleantalkGetIP(); $ip = array_unique($ip); $key = $wgCTAccessKey; for ($i = 0; $i < sizeof($ip); $i++) { if (isset($_COOKIE['ct_sfw_pass_key']) && $_COOKIE['ct_sfw_pass_key'] == md5($ip[$i] . $key)) { $is_sfw_check = false; if (isset($_COOKIE['ct_sfw_passed'])) { @setcookie('ct_sfw_passed', '0', 1, "/"); } } } if ($is_sfw_check) { $sfw = new CleanTalkSFW(); $sfw->cleantalk_get_real_ip(); $sfw->check_ip(); if ($sfw->result) { $sfw->sfw_die(); } } /* Finish checking IP */ } } /* SFW ends */ if ($wgCTShowLink) { $text .= "<div style='width:100%;text-align:center;'><a href='https://cleantalk.org'>MediaWiki spam</a> blocked by CleanTalk.</div>"; } return true; }
public function send_logs() { $is_sfw = COption::GetOptionString('cleantalk.antispam', 'form_sfw', 0); $sfw_log = COption::GetOptionString('cleantalk.antispam', 'sfw_log', ''); if ($is_sfw == 1 && $sfw_log != '') { $sfw_log = json_decode($sfw_log, true); $data = array(); foreach ($sfw_log as $key => $value) { $data[] = array($key, $value['all'], $value['allow'], $value['datetime']); } $qdata = array('data' => json_encode($data), 'rows' => count($data), 'timestamp' => time()); if (!function_exists('sendRawRequest')) { require_once 'classes/general/cleantalk.class.php'; } $result = sendRawRequest('https://api.cleantalk.org/?method_name=sfw_logs&auth_key=' . $ct_options['apikey'], $qdata); $result = CleantalkAntispam::CleantalkSendRequest('https://api.cleantalk.org/?method_name=sfw_logs&auth_key=' . $key, $qdata, false); $result = json_decode($result); if (isset($result->data) && isset($result->data->rows)) { if ($result->data->rows == count($data)) { COption::SetOptionString('cleantalk.antispam', 'sfw_log', ''); } } } }