示例#1
0
 public function testVerifyKey()
 {
     $response = "HTTP/1.0 200 OK\r\n" . "Content-type: text/plain; charset=utf-8\r\n" . "Content-length: 5\r\n" . "Server: LiteSpeed\r\n" . "Date: Tue, 06 Feb 2007 14:41:24 GMT\r\n" . "Connection: close\r\n" . "\r\n" . "valid";
     $this->adapter->setResponse($response);
     $this->assertTrue($this->akismet->verifyKey());
     $response = "HTTP/1.0 200 OK\r\n" . "Content-type: text/plain; charset=utf-8\r\n" . "Content-length: 7\r\n" . "Server: LiteSpeed\r\n" . "Date: Tue, 06 Feb 2007 14:41:24 GMT\r\n" . "Connection: close\r\n" . "\r\n" . "invalid";
     $this->adapter->setResponse($response);
     $this->assertFalse($this->akismet->verifyKey());
 }
示例#2
0
 /**
  * ページを書き込む
  * @param string $str 書き込むデーター
  * @param boolean $notimestamp タイムスタンプを更新するかのフラグ
  * @return void
  */
 public function set($str, $keeptimestamp = false)
 {
     global $use_spam_check, $_string, $vars, $_title, $whatsnew, $whatsdeleted;
     // roleのチェック
     if (Auth::check_role('readonly')) {
         return;
     }
     // Do nothing
     if (Auth::is_check_role(PKWK_CREATE_PAGE)) {
         Utility::dieMessage(sprintf($_strings['error_prohibit'], 'PKWK_READONLY'), 403);
     }
     // 簡易スパムチェック(不正なエンコードだった場合ここでエラー)
     if (isset($vars['encode_hint']) && $vars['encode_hint'] !== PKWK_ENCODING_HINT) {
         Utility::dump();
         Utility::dieMessage($_string['illegal_chars'], 403);
     }
     // ポカミス対策:配列だった場合文字列に変換
     if (is_array($str)) {
         $str = join("\n", $str);
     }
     // 入力データーを整形(※string型です)
     $postdata = Rules::make_str_rules($str);
     // 過去のデーターを取得
     $oldpostdata = self::has() ? self::get(TRUE) : '';
     // 差分を生成(ここでの差分データーはAkismetでも使う)
     $diff = new Diff($oldpostdata, $postdata);
     $diffobj = new LineDiff();
     $diffdata = $diffobj->str_compare($oldpostdata, $postdata);
     // ログイン済みもしくは、自動更新されるページである
     $has_not_permission = Auth::check_role('role_contents_admin');
     // 未ログインの場合、S25Rおよび、DNSBLチェック
     if ($has_not_permission) {
         $ip_filter = new IpFilter();
         //if ($ip_filter->isS25R()) Utility::dieMessage('S25R host is denied.');
         // 簡易スパムチェック
         if (Utility::isSpamPost()) {
             Utility::dump();
             Utility::dieMessage('Writing was limited. (Blocking SPAM)');
         }
         if (isset($use_spam_check['page_remote_addr']) && $use_spam_check['page_remote_addr'] !== 0) {
             // DNSBLチェック
             $listed = $ip_filter->checkHost();
             if ($listed !== false) {
                 Utility::dump('dnsbl');
                 Utility::dieMessage(sprintf($_strings['prohibit_dnsbl'], $listed), $_title['prohibit'], 400);
             }
         }
         if (isset($use_spam_check['page_contents']) && $use_spam_check['page_contents'] !== 0) {
             // URLBLチェック
             $reason = self::checkUriBl($diff);
             if ($reason !== false) {
                 Utility::dump($reason);
                 Utility::dieMessage($_strings['prohibit_uribl'], $_title['prohibit'], 400);
             }
         }
         // 匿名プロクシ
         if ($use_spam_check['page_write_proxy'] && ProxyChecker::is_proxy()) {
             Utility::dump('proxy');
             Utility::dieMessage($_strings['prohibit_proxy'], $_title['prohibit'], 400);
         }
         // Akismet
         global $akismet_api_key;
         if (isset($use_spam_check['akismet']) && $use_spam_check['akismet'] !== 0 && !empty($akismet_api_key)) {
             $akismet = new Akismet($akismet_api_key, Router::get_script_absuri());
             if ($akismet->verifyKey($akismet_api_key)) {
                 // 送信するデーターをセット
                 $akismet_post = array('user_ip' => REMOTE_ADDR, 'user_agent' => $_SERVER['HTTP_USER_AGENT'], 'comment_type' => 'comment', 'comment_author' => isset($vars['name']) ? $vars['name'] : 'Anonymous', 'comment_content' => $postdata);
                 //	if ($use_spam_check['akismet'] === 1){
                 //		// 差分のみをAkismetに渡す
                 //		foreach ($diff->getSes() as $key=>$line){
                 //			if ($key !== $diff::SES_ADD) continue;
                 //			$added_data[] = $line;
                 //		}
                 //		$akismet_post['comment_content'] = join("\n",$added_data);
                 //		unset($added_data);
                 //	}
                 if ($akismet->isSpam($akismet_post)) {
                     Utility::dump('akismet');
                     Utility::dieMessage($_strings['prohibit_akismet'], $_title['prohibit'], 400);
                 }
             } else {
                 Utility::dieMessage('Akismet API key does not valied.', 500);
             }
         }
         // captcha check
         if (isset($use_spam_check['captcha']) && $use_spam_check['captcha'] !== 0) {
             Captcha::check(false);
         }
     }
     // 現時点のページのハッシュを読む
     $old_digest = $this->wiki->has() ? $this->wiki->digest() : 0;
     // オリジナルが送られてきている場合、Wikiへの書き込みを中止し、競合画面を出す。
     // 現時点のページのハッシュと、送信されたページのハッシュを比較して異なる場合、
     // 自分が更新している間に第三者が更新した(=競合が起きた)と判断する。
     $collided = isset($vars['digest']) && $old_digest !== 0 && $vars['digest'] !== $old_digest;
     if ($collided && isset($vars['original'])) {
         return array('msg' => $_string['title_collided'], 'body' => $_string['msg_collided'] . Utility::showCollision($oldpostdata, $postdata, $vars['original']) . Utility::editForm($this->page, $postdata, false));
     }
     // add client info to diff
     // $diffdata[] = '// IP:"'. REMOTE_ADDR . '" TIME:"' . UTIME . '" REFERER:"' . $referer . '" USER_AGENT:"' . $user_agent. "\n";
     FileFactory::Diff($this->page)->set($diffdata);
     unset($oldpostdata, $diff, $diffdata);
     // Logging postdata (Plus!)
     if (self::POST_LOGGING === TRUE) {
         Utility::dump(self::POST_LOG_FILENAME);
     }
     // 入力が空の場合、削除とする
     if (empty($str)) {
         // Wikiページを削除
         $ret = $this->wiki->set('');
         Recent::set($this->page, true);
     } else {
         // Wikiを保存
         $ret = $this->wiki->set($postdata, $keeptimestamp);
         // 最終更新を更新
         Recent::set($this->page);
     }
     if ($this->page !== $whatsnew || $this->page !== $whatsdeleted || !$this->isHidden()) {
         // バックアップを更新
         Factory::Backup($this->page)->set();
         // 更新ログをつける
         LogFactory::factory('update', $this->page)->set();
         if (!$keeptimestamp && !empty($str)) {
             // weblogUpdates.pingを送信
             $ping = new Ping($this->page);
             $ping->send();
         }
     }
     // 簡易競合チェック
     if ($collided) {
         return array('msg' => $_string['title_collided'], 'body' => $_string['msg_collided_auto']);
     }
 }
示例#3
0
 /**
  * Validate the value so see if it's spam.
  *
  * @param string $value
  * @param null $context
  * @return bool
  */
 public function isValid($value, $context = null)
 {
     if (!is_array($value)) {
         $this->error(self::INVALID);
         return false;
     }
     $this->setValue($value);
     $akismet = new AkismetService($this->getApiKey(), $this->getBlog());
     if (!$akismet->verifyKey($this->getApiKey())) {
         throw new Exception\InvalidArgumentException('Invalid API key for Akismet');
     }
     $data = ['comment_type' => $this->getCommentType(), 'comment_author' => $context[$this->getCommentAuthor()], 'comment_author_email' => $context[$this->getCommentAuthorEmail()], 'comment_content' => $value, 'user_agent' => $this->getUserAgent(), 'user_ip' => $this->getUserIp()];
     if ($akismet->isSpam($data)) {
         $this->error(self::SPAM);
         return false;
     }
     return true;
 }
示例#4
0
 /**
  * Returns true if the given string is not spam
  *
  * @param array $value Should contain the following
  * user_ip
  * user_agent
  * comment_type
  * comment_author
  * comment_author_email
  * comment_content
  *
  * @return boolean
  */
 public function isValid($value)
 {
     if (!is_array($value)) {
         $this->error(self::INVALID);
         return false;
     }
     $this->setValue($value);
     $akismet = new Akismet($this->getApiKey(), $this->getUrl());
     if (!$akismet->verifyKey($this->getApiKey())) {
         throw new \Exception('Invalid API key for Akismet');
     }
     if ($akismet->isSpam($value)) {
         $this->error(self::SPAM);
         return false;
     } else {
         return true;
     }
 }