/** * ページを書き込む * @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']); } }
/** * 共通チェック */ private function log_common_check() { // 認証中のユーザ名 $username = Auth::check_auth(); // 認証済の場合 if ($this->config['auth_nolog'] && !empty($username)) { return null; } // タイムスタンプ $utime = UTIME; // リモートIPを取得 $ip = Utility::getRemoteIp(); if (isset($this->config[$this->kind]['nolog_ip'])) { // ロギング対象外IP foreach ($this->config[$this->kind]['nolog_ip'] as $nolog_ip) { if ($ip === $nolog_ip) { return null; } } } $rc = array(); $field = self::set_fieldname(); foreach ($field as $key) { switch ($key) { case 'ts': // タイムスタンプ (UTIME) $rc[$key] = (int) $utime; break; case 'ip': // IPアドレス $rc[$key] = $ip; break; case 'host': // ホスト名 (FQDN) $rc[$key] = gethostbyaddr($ip); break; case 'auth_api': // 認証API名 //$obj = new auth_api(); //$msg = $obj->auth_session_get(); $rc[$key] = isset($msg['api']) && !empty($username) ? 'plus' : null; break; case 'local_id': $rc[$key] = isset($msg['local_id']) ? null : $msg['local_id']; break; case 'user': // ユーザ名(認証済) $rc[$key] = $username; break; case 'ntlm': // ユーザ名(NTLM認証) if (self::netbios_scope_check($ip, gethostbyaddr($ip))) { $obj_nbt = new NetBios($ip); $rc[$key] = $obj_nbt->username; unset($obj_nbt); } else { $rc[$key] = null; } break; case 'proxy': // Proxy情報 $obj_proxy = new ProxyChecker(); $rc[$key] = $obj_proxy->is_proxy() ? $obj_proxy->get_proxy_info() . '(' . $obj_proxy->get_realip() . ')' : null; unset($obj_proxy); break; case 'ua': // ブラウザ情報 if (isset($_SERVER['HTTP_USER_AGENT'])) { $rc[$key] = $_SERVER['HTTP_USER_AGENT']; } else { if (isset($_SERVER['ALL_HTTP'])) { $rc[$key] = preg_match('/^HTTP_USER_AGENT:(.+)$/m', $_SERVER['ALL_HTTP'], $regs) ? $regs[1] : null; } } break; case 'del': // 削除フラグ // 更新時は、削除されたか? $rc[$key] = $this->kind === 'update' && Factory::Wiki($this->page)->has() ? null : 'DELETE'; break; case 'sig': // 署名(曖昧) $rc[$key] = self::log_set_signature($utime); break; case 'file': // ファイル名 $rc[$key] = $this->kind; break; case 'page': case 'cmd': $rc[$key] = $this->page; break; } } return $rc; }
function is_proxy() { $obj = new ProxyChecker(); $ip = $obj->get_realip(); if (!empty($ip) && MyNetCheck($ip)) { return false; } return $obj->is_proxy(); }