Created
June 5, 2009 21:48
-
-
Save badboy/124531 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
require "core.php"; | |
function errorExit($message) | |
{ | |
header("Content-type: text/xml"); | |
echo <<<EOF | |
<?xml version="1.0" encoding="utf-8"?> | |
<response> | |
<error>1</error> | |
<message>{$message}</message> | |
</response> | |
EOF; | |
exit; | |
} | |
if(!isset($_GET['id'])) | |
errorExit('I need the article ID'); | |
if(!isset($_POST['url'])) | |
errorExit('You must give a perma link to your article'); | |
if(!isset($_POST['excerpt'])) | |
errorExit('You must give a excerpt of your article'); | |
if(!isset($_POST['blog_name'])) | |
errorExit('You must give the name of your blog'); | |
$id = $_GET['id']; | |
$url = htmlspecialchars($_POST['url']); | |
$excerpt = $_POST['excerpt']; | |
$blog_name = htmlspecialchars($_POST['blog_name']); | |
$comment = ''; | |
if(strlen($excerpt) > 255) | |
{ | |
$comment = '(...) ' . substr($excerpt, 0, 243) . ' (...)'; | |
} | |
else | |
$comment = $excerpt; | |
$p = $Blog->getnewsbyid($id); | |
if(!$p) errorExit('Article not found'); | |
$p = $p->fetch_object(); | |
if(!$p) errorExit('Article not found'); | |
$mytitle = $p->title; | |
$myurl = $Blog->rootpath.'/'.$p->id.'/'.$Blog->shorttext($mytitle); | |
##errorExit($myurl); | |
#if(strpos($comment, $myurl) !== false) errorExit('Go away, spammer'); | |
$comment = strip_tags($comment); | |
$comment = nl2br($comment); | |
if(isset($_POST['title'])) | |
{ | |
$title = htmlspecialchars($_POST['title']); | |
$comment = "<strong>{$title}</strong><br />" . $comment; | |
} | |
/* | |
* catching possible trackback spam | |
* this is just a dirty work-around | |
* to log some more attacks | |
* the trackback will be saved anyway ;) | |
*/ | |
$ua = $_SERVER['HTTP_USER_AGENT']; | |
$ip = $_SERVER['REMOTE_ADDR']; | |
$date = date('d.m.Y - H:i'); | |
$blocked_ips = array('83.233.30.32', '89.248.160.248'); | |
$spam_word = 'casino'; | |
if(stristr($blog_name, $spam_word) || stristr($comment, $spam_word)) | |
{ | |
$fp = @fopen('trackback_spam.log', 'a'); | |
$blocked = in_array($ip, $blocked_ips); | |
if($fp) | |
{ | |
@fwrite($fp, "- ({$date}) possible Trackback Spam:\n"); | |
@fwrite($fp, " Name: {$blog_name}\n"); | |
@fwrite($fp, " User-Agent: {$ua}\n"); | |
@fwrite($fp, " IP: {$ip}\n"); | |
if($blocked) @fwrite($fp, " -- BLOCKED --\n"); | |
@fclose($fp); | |
} | |
if($blocked) die("no spam allowed!"); | |
} | |
// trackback spam logger END | |
if($Blog->save_comment($id, $blog_name, '', $url, $comment, false)) | |
{ | |
header("Content-type: text/xml"); | |
echo <<<EOF | |
<?xml version="1.0" encoding="utf-8"?> | |
<response> | |
<error>0</error> | |
</response> | |
EOF; | |
} | |
else | |
{ | |
errorExit('Trackback cannot be saved'); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment