PageRenderTime 27ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/spam_filter.php

https://github.com/stealthinu/pukiwiki_spam_filter
PHP | 1000 lines | 646 code | 151 blank | 203 comment | 124 complexity | 91f4e1608736f50e10e5a39efbde4598 MD5 | raw file
  1. <?php
  2. /*
  3. * spam_filter.php
  4. *
  5. * Based on akismet_filter.php version 1.2
  6. * author Akio KONUMA konuma@ark-web.jp
  7. * link http://www.ark-web.jp/sandbox/wiki/190.html
  8. *
  9. * @authoer SATOH Kiyoshi (satoh at hakuba dot jp)
  10. * @link http://miasa.info/index.php?%C8%FE%CB%E3Wiki%A4%C7%A5%B7%A5%B9%A5%C6%A5%E0%C5%AA%A4%CB%BD%A4%C0%B5%A4%B7%A4%C6%A4%A4%A4%EB%C5%C0
  11. * @version 0.8.0
  12. * @license GPL v2 or (at your option) any later version
  13. */
  14. //// pukiwiki.ini.php�ʤɤdzƥ��ѥ��ե��륿�����Ѥȥե��륿���λ����򤹤�
  15. // �������Ƥ�̿̾��§������
  16. // SPAM_FILTER_****_PLUGIN_NAME -> �����å��оݤȤ����ץ饰����̾�������޶��ڤ�
  17. // SPAM_FILTER_****_REG -> �ޥå�����������ɽ��
  18. // SPAM_FILTER_****_URLREG -> URL�����̤��뤿��������ɽ��
  19. // SPAM_FILTER_****_WHITEREG -> �ޥå����ʤ��Ƥ褤URL�ۥ磻�ȥꥹ��
  20. //// ���ѥ���Ƚ�Ǥ������������ꤹ��
  21. // ���ꤵ�줿�Ƽ凉�ѥ��ե��륿�������̤ä���FALSE
  22. // �ڤ��ե��륿�������˳ݤ���false positive�β�ǽ�����������Τ�ʣ�������dzݤ���
  23. // ��SPAM_FILTER_COND ������
  24. // ��UserAgent��libwww����HTML��ź�եե����롢</a>�����������롢�Ѹ��Τߤ�URL��3�İʾ塢URL��NS�Υ֥��å��ꥹ��
  25. //define('SPAM_FILTER_COND', '#useragent() or #filename() or #atag() or (#onlyeng() and #urlnum()) or #urlnsbl()');
  26. // ���嵭�����˥ץ饹���Ѹ��ΤߤΤȤ���URL�������Ȥ�����Akismet������
  27. //define('SPAM_FILTER_COND', '#useragent() or #filename() or #atag() or (#onlyeng() and #urlnum()) or #urlnsbl() or (#onlyeng() and #url() and #akismet())');
  28. // ���ǥե����ȤǤϥե��륿�ʤ�
  29. define('SPAM_FILTER_COND', '');
  30. //// CAPTCHA�ǤΥ����å��򤹤����������ꤹ��
  31. // ���ǥե����ȤǤϥե��륿�ʤ�
  32. define('SPAM_FILTER_CAPTCHA_COND', '');
  33. //// �ƥե��륿���̤������Ǥ�������
  34. // URL�ǤΥޥå��Ǽ��ɥᥤ���ʤɤ�̵�뤹�٤�URL
  35. define('SPAM_FILTER_WHITEREG', '/example\.(com|net|jp)/i');
  36. // URL�����Ф����ݤ�����ɽ��
  37. define('SPAM_FILTER_URLREG', '/(?:(?:https?|ftp|news):\/\/)[\w\/\@\$()!?&%#:;.,~\'=*+-]+/i');
  38. //// urlnsbl �ʤɤǻȤ���NS�μ����򤹤� dns_get_ns ������
  39. // NS�����������̤򤢤����٥����å��夷�Ƥ���
  40. define('SPAM_FILTER_DNSGETNS_CACHE_FILE', 'dns_get_ns.cache');
  41. // �����å��夷�Ƥ�������
  42. define('SPAM_FILTER_DNSGETNS_CACHE_DAY', 30);
  43. // nslookup ���ޥ��ɤؤΥѥ� - PHP4�ξ����ʤɤ�ɬ�פȤʤ����礬����
  44. define('SPAM_FILTER_NSLOOKUP_PATH', '/usr/bin/nslookup');
  45. //// ipcountry �ʤɤǻȤ���IP�����񥳡��ɤ��������� get_country_code ������
  46. // IP���ɥ쥹�Ӥȹ������ν񤫤줿�ե�����̾
  47. define('SPAM_FILTER_IPCOUNTRY_FILE', 'delegated-apnic-latest');
  48. //// ngreg - ���Ƥ�����ɽ���ե��륿
  49. // �����������ǵ��Ĥ��ʤ����Ƥ�����ɽ��
  50. define('SPAM_FILTER_NGREG_REG', '');
  51. define('SPAM_FILTER_NGREG_PLUGIN_NAME', 'edit,comment,pcomment,article,bugtrack');
  52. //// url - ���Ƥ�URL�äݤ����Τ��ޤޤ��Ƥ��뤫�����å�
  53. define('SPAM_FILTER_URL_REG', '/https?:/i');
  54. define('SPAM_FILTER_URL_PLUGIN_NAME', 'edit,comment,pcomment,article,bugtrack');
  55. //// atag - ���Ƥ�</A>��[/URL]�Τ褦�ʥ��󥫡��������ޤޤ��Ƥ��뤫�����å�
  56. define('SPAM_FILTER_ATAG_REG', '/<\/a>|\[\/url\]/i');
  57. define('SPAM_FILTER_ATAG_PLUGIN_NAME', 'edit,comment,pcomment,article,bugtrack');
  58. //// onlyeng - ���Ƥ�Ⱦ�ѱѿ��Τ�(���ܸ줬���äƤ��ʤ�)�������å�
  59. define('SPAM_FILTER_ONLYENG_REG', '/\A[!-~\n ]+\Z/');
  60. define('SPAM_FILTER_ONLYENG_PLUGIN_NAME', 'edit,comment,pcomment,article,bugtrack');
  61. //// urlnum - ���Ƥ˴ޤޤ��Ƥ���URL�����İʾ夫�����å�
  62. define('SPAM_FILTER_URLNUM_NUM', '3');
  63. define('SPAM_FILTER_URLNUM_WHITEREG', SPAM_FILTER_WHITEREG);
  64. define('SPAM_FILTER_URLNUM_URLREG', SPAM_FILTER_URLREG);
  65. define('SPAM_FILTER_URLNUM_PLUGIN_NAME', 'edit,comment,pcomment,article,bugtrack');
  66. //// ipunknown - ���饤�����Ȥ�IP���հ����Ǥ��뤫�����å�
  67. define('SPAM_FILTER_IPUNKNOWN_PLUGIN_NAME', 'edit,comment,pcomment,article,attach,bugtrack');
  68. //// ips25r - ���饤�����Ȥ�IP��ưŪIP�äݤ�(S25R�˥ޥå�����)�������å�
  69. // S25R������ɽ��
  70. define('SPAM_FILTER_IPS25R_REG', '/(^[^\.]*[0-9][^0-9\.]+[0-9])|(^[^\.]*[0-9]{5})|(^([^\.]+\.)?[0-9][^\.]*\.[^\.]+\..+\.[a-z])|(^[^\.]*[0-9]\.[^\.]*[0-9]-[0-9])|(^[^\.]*[0-9]\.[^\.]*[0-9]\.[^\.]+\..+\.)|(^(dhcp|dialup|ppp|adsl)[^\.]*[0-9])|\.(internetdsl|adsl|sdi)\.tpnet\.pl$/');
  71. define('SPAM_FILTER_IPS25R_PLUGIN_NAME', 'tb');
  72. //// ipbl - ���饤�����Ȥ�IP���ۥ���̾�ˤ����ե��륿
  73. // ���Ĥ��ʤ�IP���ۥ���̾������ɽ��
  74. define('SPAM_FILTER_IPBL_REG', '');
  75. define('SPAM_FILTER_IPBL_PLUGIN_NAME', 'edit,comment,pcomment,article,attach,bugtrack');
  76. // �ۥ���̾�����Ĥ������ʤ��ä��Ȥ��ˤ����ݤ������� TRUE
  77. define('SPAM_FILTER_IPBL_UNKNOWN', FALSE);
  78. //// ipdnsbl - ���饤�����Ȥ�IP��DNSBL�ǥ����å�
  79. define('SPAM_FILTER_IPDNSBL_DNS', 'niku.2ch.net,bsb.spamlookup.net,bl.spamcop.net,all.rbl.jp');
  80. define('SPAM_FILTER_IPDNSBL_PLUGIN_NAME', 'edit,comment,pcomment,article,attach,bugtrack');
  81. //// ipcountry - ���饤�����Ȥ�IP�ι��������å�
  82. // �ޥå��������������ꤹ������ɽ��
  83. define('SPAM_FILTER_IPCOUNTRY_REG', '/(CN|KR|UA)/');
  84. define('SPAM_FILTER_IPCOUNTRY_PLUGIN_NAME', 'edit,comment,pcomment,article,attach,bugtrack');
  85. //// uaunknown - HTTP_USER_AGENT������(pukiwiki.ini.php��$agents�ǻ���)�������å�
  86. define('SPAM_FILTER_UAUNKNOWN_PLUGIN_NAME', 'edit,comment,pcomment,article,attach,bugtrack');
  87. //// useragent - HTTP_USER_AGENT�ˤ����ե��륿
  88. // ���Ĥ��ʤ�HTTP_USER_AGENT������ɽ��
  89. define('SPAM_FILTER_USERAGENT_REG', '/WWW-Mechanize|libwww/i');
  90. define('SPAM_FILTER_USERAGENT_PLUGIN_NAME', 'edit,comment,pcomment,article,attach,bugtrack');
  91. //// acceptlanguage - HTTP_ACCEPT_LANGUAGE�ˤ����ե��륿
  92. // ���Ĥ��ʤ�HTTP_ACCEPT_LANGUAGE������ɽ��
  93. define('SPAM_FILTER_ACCEPTLANGUAGE_REG', '/cn|ru/i');
  94. define('SPAM_FILTER_ACCEPTLANGUAGE_PLUGIN_NAME', 'edit,comment,pcomment,article,attach,bugtrack');
  95. //// filename - ���åץ����ɥե�����̾�ˤ����ե��륿
  96. // ���åץ����ɤ����Ĥ��ʤ��ե�����̾������ɽ��
  97. define('SPAM_FILTER_FILENAME_REG', '/\.html$|\.htm$/i');
  98. define('SPAM_FILTER_FILENAME_PLUGIN_NAME', 'attach');
  99. //// formname - ¸�ߤ��ʤ��Ϥ��Υե��������Ƥ����뤫�����å�
  100. // ¸�ߤ��ʤ��Ϥ��Υե�����̾�λ��ꡢ�����޶��ڤ�
  101. define('SPAM_FILTER_FORMNAME_NAME', 'url,email');
  102. define('SPAM_FILTER_FORMNAME_PLUGIN_NAME', 'edit,comment,pcomment,article,bugtrack');
  103. //// urlbl - URL���֥��å��ꥹ�Ȥ����äƤ��뤫��ǧ
  104. // URL�Υ֥��å��ꥹ�� �ۥ���̾�Ǥ�IP�Ǥ���
  105. // ��wikiwiki.jp�Υ֥��å��ꥹ�Ȥ򻲹�
  106. // ��http://wikiwiki.jp/?%A5%D5%A5%A3%A5%EB%A5%BF%A5%EA%A5%F3%A5%B0%A5%C9%A5%E1%A5%A4%A5%F3%B5%DA%A4%D3%A5%A2%A5%C9%A5%EC%A5%B9
  107. define('SPAM_FILTER_URLBL_REG', '/(0451\.net|1\.sa3\.cn|1102213\.com|1234\.hao88cook\.com|1234564898\.h162\.1stxy\.cn|123lineage\.com|136136\.net|16isp\.com|17aa\.com|17tc\.com|18dmm\.com|18dmm\.com|18girl-av\.com|19800602\.com|1boo\.net|1gangmu\.com|1stxy\.cn|1stxy\.net|216\.168\.128\.126|2chjp\.com|453787\.com|500bb\.com|53dns\.com|56jb\.com|59\.36\.96\.140|5xuan\.com|60\.169\.0\.66|60\.171\.45\.134|66\.98\.212\.108|666\.lyzh\.com|6789\.hao88cook\.com|77276\.com|78xian\.com|84878679\.free\.psnic\.cn|853520\.com|8ycn\.com|92\.av366\.com|a\.2007ip\.com|a\.xiazaizhan\.cn|aaa-livedoor\.net|acyberhome\.com|adfka\.com|adult\.zu1\.ru|ahatena\.com|ahwlqy\.com|anemony\.info|angel\.hao88cook\.com|anyboard\.net|areaseo\.com|asdsdgh-jp\.com|askbigtits\.com|aspasp\.h162\.1stxy\.cn|aurasoul-visjp\.com|auto-mouse\.com|auto-mouse\.jp|avl\.lu|avtw1068\.com|baidu\.chinacainiao\.org|baidulink\.com|bailishidai\.com|bbs-qrcode\.com|bbs\.coocbbs\.com|bestinop\.org|beyondgame\.jsphome\.com|bibi520\.com|bibi520\.h20\.1stxy\.cn|bizcn\.com|blog-livedoor\.net|blogplaync\.com|bluell\.cn|blusystem\.com|bosja\.com|cash\.searchbot\.php|cashette\.com|casino\.online|cc\.wzxqy\.com|cetname\.com|cgimembera\.org|cglc\.org|chengzhibing\.com|china-beijing-cpa\.com|chinacainiao\.org|chinacu\.net|chnvip\.net|chouxiaoya\.org|city689\.com|cityhokkai\.com|cn7135\.cn|cnidc\.cn|conecojp\.net|coocbbs\.com|cool\.47555\.com|coolroge\.199\.53dns\.com|cpanel\.php|cyd\.org\.uk|d\.77276\.com|dcun\.cn|dfsm\.jino-net\.ru|dietnavi\.com|din-or\.com|dj5566\.org|djkkk66990\.com|dl\.gov\.cn|do\.77276\.com|down\.136136\.net|down\.eastrun\.net|down123\.net|dtg-gamania\.com|ee28\.cn|efnm\.w170\.bizcn\.com|emarealtor\.com|ff11-info\.com|ffxiforums\.net|fhy\.net|filthyloaded\.com|fizkult\.org|fly\.leryi\.com|fofje\.info|forumup\.us|forumup\.us|ftplin\.com|fxfqiao\.com|gamaniaech\.com|game-click\.com|game-fc2blog\.com|game-mmobbs\.com|game-oekakibbs\.com|game\.16isp\.com|game4enjoy\.net|game62chjp\.net|gamecent\.com|gameloto\.com|games-nifty\.com|gameslin\.net|gamesragnaroklink\.net|gamesroro\.com|gamet1\.com|gameurdr\.com|gameyoou\.com|gamshondamain\.net|ganecity\.com|gangnu\.com|gemnnammobbs\.com|gendama\.jp|geocitygame\.com|geocitylinks\.com|getamped-garm\.com|ggmm52\.com|ghostsoft\.info|girl-o\.com|gogogoo\.com|good1688\.com|goodclup\.com|google\.cn\.mmhk\.cn|grandchasse\.com|gsisdokf\.net|guoxuecn\.com|gwlz\.cn|hao88cook\.com|hao88cook\.xinwen365\.net|haveip\.com|heixiou\.com|hinokihome\.com\.tw|homepage3-nifty\.com|honda168\.net|hosetaibei\.com|hoyoo\.net|hyap98\.com|i5460\.net|i5460\.net|ic-huanao\.com|iframedollars\.biz|ii688\.com|itgozone\.com|ixbt\.com|izmena\.org|j4sb\.com|japan\.k15\.cn|japan213\.com|japangame1\.com|jdnx\.movie721\.cn|jinluandian\.com|joyjc\.com|joynu\.com|jp\.hao88cook\.com|jpgame666\.com|jpgamer\.net|jpgamermt\.com|jplin\.com|jplineage\.com|jplingood\.com|jplinux\.com|jplove888\.com|jpplay\.net|jpragnarokonline\.com|jprmthome\.com|js1988\.com|jsphome\.com|jswork\.jp|jtunes\.com|jtunes\.com|junkmetal\.info|junkmetal\.info|k15\.cn|kaihatu\.com|kanikuli\.net|kaukoo\.com|kele88\.com|kiev\.ua|kingbaba\.cc|kingrou\.w177\.west263\.cn|kingshi\.net|kingtt\.com|kmqe\.com|kortwpk\.com|korunowish\.com|kotonohax\.com|kulike\.com|kuronowish\.net|kyoukk\.com|la-ringtones\.com|lastlineage\.com|lele\.0451\.net|lin2-jp\.com|linainfo\.net|linbbs\.com|lindeliang-36248700\.15\.cnidc\.cn|lineagalink\.com|lineage-info\.com|lineage\.1102213\.com|lineage\.japan213\.com|lineage1bbs\.com|lineage2-ol\.com|lineage2\.japan213\.com|lineage2006\.com|lineage321\.com|lineagecojp\.com|lineagefirst\.com|lineageink\.com|lineagejp-game\.com|lineagejp-game\.com|lineagejp\.com|lineagekin\.com|lineagett\.com|lineinfo-jp\.com|linenew\.com|lingage\.com|lingamesjp\.com|linjp\.net|linkcetou\.com|linrmb\.com|linsssgame\.com|livedoor1\.com|lliinnss\.com|lovejpjp\.com|lovejptt\.com|lovetw\.webnow\.biz|lyadsl\.com|lyftp\.com|lyzh\.com|macauca\.org\.mo|mail\.8u8y\.com|maplestorfy\.com|micro36\.com|mm\.7mao\.com|mmhk\.cn|mogui\.k15\.cn|moguidage\.h81\.1stxy\.net|mojeforum\.net|monforum\.com|movie1945\.com|mumu\.8ycn\.com|nakosi\.com|navseh\.com|netgamelivedoor\.com|nobunaga\.1102213\.com|nothing-wiki\.com|okinawa\.usmc-mccs\.org|okwit\.com|omakase-net\.com|oulianyong\.com|pagead2\.googlesyndication\.com\.mmhk\.cn|pangzigame\.com|phpnet\.us|planetalanismorissette\.info|playerturbo\.com|playncsoft\.net|playsese\.com|plusintedia\.com|pointlink\.jp|potohihi\.com|ptxk\.com|puma163\.com|qbbd\.com|qianwanip\.cn|qiucong\.com|qq\.ee28\.cn|qq756\.com|quicktopic\.com|rabota\.inetbiznesman\.ru|ragnarok-bbs\.com|ragnarok-game\.com|ragnarok-sara\.com|ragnaroklink\.com|ragnarokonlina\.com|ragnarokonline1\.com|ragnarox\.mobi|rarbrc\.com|rb\.17aa\.com|rbtt1\.com|realitsen\.info|rik\.tag-host\.com|riro\.bibi520\.com|rit1\.bibi520\.com|rit2\.bibi520\.com|rmt-lineagecanopus\.com|rmt-navip\.com|rmt-ranloki\.com|rmt-trade\.com|ro-bot\.net|rogamesline\.com|rokonline-jp\.com|rootg\.org|roprice\.com|rormb\.com|s57\.cn|s678\.cn|scandius\.com|sepgon\.com|setsoul\.org|seun\.ru|seun\.ru|sf\.sf325\.com|shakiranudeworld\.info|shoopivdoor\.com|shoopivdoor\.w19\.cdnhost\.cn|skkustp\.itgozone\.com|skoro\.us|skybeisha\.com|slower-qth\.com|slower-qth\.com|stats\.dl\.gov\.cn|suniuqing\.com|suzukl668\.com|taiwanioke\.com|tankhaoz\.com|tbihome\.org|tesekl\.kmip\.net|thewildrose\.net|thtml\.com|tigermain\.w148\.bizcn\.com|tooplogui\.com|toyshop\.com\.tw|trade-land\.net|trans2424\.com|ttbbss123\.com|tulang1\.com|twabout\.com|twb1og\.net|twganwwko\.com|twguoyong\.com|twmsn-ga\.com|twsunkom\.com|twtaipei\.org|ubtop\.com|usmc-mccs\.org|vegas-webspace\.com|w666\.cn|watcheimpress\.com|watchsite\.nm\.ru|web\.77276\.com|webnow\.biz|wenyuan\.com\.cn|west263\.cn|wikiwiKi-game\.com|woowoo\.com\.cn|wowsquare\.com|wulgame\.com|www2\.cw988\.cn|xiaoshuowang\.com\.cn|xintao-01\.woowoo\.com\.cn|xinwen365\.net|xpills\.info|xulao\.com|xx\.wzxqy\.com|xx20062\.kele88\.com|xxlin\.com|xz\.llliao\.com|xzqx88\.com|yahoo-gamebbs\.com|yahoo\.chinacainiao\.org|yangjicook\.com|yingzhiyuan\.com|yohoojp\.com|youshini\.com|youtnwaht\.tw\.cn|youxigg\.com|yujinmp\.com|ywdgigkb-jp\.com|yzlin\.com|zaprosov\.com|zhangweijp\.com|zhangweijp\.w100\.okwit\.com|zhangwenbin-tian1\.14\.cnidc\.cn|zixinzhu\.cn|zn360\.com|zoo-sex\.com\.ua|ok8vs\.com|blog-ekndesign\.com|gamesmusic-realcgi\.net|homepage-nifty\.com|jpxpie6-7net\.com|irisdti-jp\.com|plusd-itmedia\.com|runbal-fc2web\.com|jklomo-jp\.com|d-jamesinfo\.com|deco030-cscblog\.com|ie6xp\.com|gomeodc\.com|vviccd520\.com|ipqwe\.com|mumy8\.com|okvs8\.com|p5ip\.com|plmq\.com|y8ne\.com|yyc8\.com|cityblog-fc2web\.com|extd-web\.com|gamegohi\.com|a-hatena\.com|ragnarok-search\.com|23styles\.com|ezbbsy\.com|livedoor-game\.com|m-phage\.com|yy14-kakiko\.com|lian-game\.com|ezbbs\.com|dentsu\.itgo\.com)/i');
  108. define('SPAM_FILTER_URLBL_WHITEREG', SPAM_FILTER_WHITEREG);
  109. define('SPAM_FILTER_URLBL_URLREG', SPAM_FILTER_URLREG);
  110. define('SPAM_FILTER_URLBL_PLUGIN_NAME', 'edit,comment,pcomment,article');
  111. // IP�����Ĥ������ʤ��ä��Ȥ��ˤ����ݤ������� TRUE
  112. define('SPAM_FILTER_URLBL_UNKNOWN', FALSE);
  113. //// urlcountry - URL�Υ����ФΤ������������å�
  114. // �ޥå��������������ꤹ������ɽ��
  115. define('SPAM_FILTER_URLCOUNTRY_REG', '/(CN|KR|UA)/');
  116. define('SPAM_FILTER_URLCOUNTRY_WHITEREG', SPAM_FILTER_WHITEREG);
  117. define('SPAM_FILTER_URLCOUNTRY_URLREG', SPAM_FILTER_URLREG);
  118. define('SPAM_FILTER_URLCOUNTRY_PLUGIN_NAME', 'edit,comment,pcomment,article');
  119. //// urldnsbl - URL��DNSBL�����äƤ��뤫��ǧ
  120. // DNSBL�Υꥹ��
  121. define('SPAM_FILTER_URLDNSBL_DNS', 'url.rbl.jp,rbl.bulkfeeds.jp,multi.surbl.org,list.uribl.com,bsb.spamlookup.net');
  122. define('SPAM_FILTER_URLDNSBL_WHITEREG', SPAM_FILTER_WHITEREG);
  123. define('SPAM_FILTER_URLDNSBL_URLREG', SPAM_FILTER_URLREG);
  124. define('SPAM_FILTER_URLDNSBL_PLUGIN_NAME', 'edit,comment,pcomment,article');
  125. //// urlnsbl - URL��NS���֥��å��ꥹ�Ȥ����äƤ��뤫��ǧ
  126. // URL��NS�Υ֥��å��ꥹ�� �ۥ���̾�Ǥ�IP�Ǥ���
  127. // ��wikiwiki.jp�Υ֥��å��ꥹ�Ȥ򻲹�
  128. // ��http://wikiwiki.jp/?%A5%D5%A5%A3%A5%EB%A5%BF%A5%EA%A5%F3%A5%B0%A5%C9%A5%E1%A5%A4%A5%F3%B5%DA%A4%D3%A5%A2%A5%C9%A5%EC%A5%B9
  129. define('SPAM_FILTER_URLNSBL_REG', '/(\.dnsfamily\.com|\.xinnet\.cn|\.xinnetdns\.com|\.bigwww\.com|\.4everdns\.com|\.myhostadmin\.net|\.dns\.com\.cn|\.hichina\.com|\.cnmsn\.net|\.focusdns\.com|\.cdncenter\.com|\.cnkuai\.cn|\.cnkuai\.com|\.cnolnic\.com|\.dnspod\.net|\.mywebserv\.com|216\.195\.58\.5[0-9])/i');
  130. define('SPAM_FILTER_URLNSBL_WHITEREG', SPAM_FILTER_WHITEREG);
  131. define('SPAM_FILTER_URLNSBL_URLREG', SPAM_FILTER_URLREG);
  132. define('SPAM_FILTER_URLNSBL_PLUGIN_NAME', 'edit,comment,pcomment,article');
  133. // NS�����Ĥ������ʤ��ä��Ȥ��ˤ����ݤ������� TRUE
  134. define('SPAM_FILTER_URLNSBL_NSUNKNOWN', FALSE);
  135. //// urlnscountry - URL��NS�ι��������å�
  136. // �ޥå��������������ꤹ������ɽ��
  137. define('SPAM_FILTER_URLNSCOUNTRY_REG', '/(CN|KR|UA)/');
  138. define('SPAM_FILTER_URLNSCOUNTRY_WHITEREG', SPAM_FILTER_WHITEREG);
  139. define('SPAM_FILTER_URLNSCOUNTRY_URLREG', SPAM_FILTER_URLREG);
  140. define('SPAM_FILTER_URLNSCOUNTRY_PLUGIN_NAME', 'edit,comment,pcomment,article');
  141. // NS�����Ĥ������ʤ��ä��Ȥ��ˤ����ݤ������� TRUE
  142. define('SPAM_FILTER_URLNSCOUNTRY_NSUNKNOWN', FALSE);
  143. //// akismet - Akismet �ˤ����ե��륿
  144. // ���ѥ������å����ˤ�̵�뤹��Post�ǡ����������޶��ڤ�
  145. define('SPAM_FILTER_AKISMET_IGNORE_KEY', 'digest');
  146. // Akismet�Ǽ������롣API����
  147. define('SPAM_FILTER_AKISMET_API_KEY', '');
  148. define('SPAM_FILTER_AKISMET_PLUGIN_NAME', 'edit,comment,tracker,article');
  149. //// reCAPTCHA ������
  150. define('SPAM_FILTER_RECAPTCHA_PUBLICKEY', '');
  151. define('SPAM_FILTER_RECAPTCHA_PRIVATEKEY', '');
  152. define('SPAM_FILTER_IS_WINDOWS', (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN'));
  153. //// ���ѥ��ե��륿����
  154. // plugin.php �����ƤФ���
  155. function spam_filter($plugin)
  156. {
  157. $spamfilter = new SpamFilter($_POST, $plugin);
  158. // CAPTCHA�Ǥ�ǧ�ڤ��̤äƤ������礽�Τޤ��̤�
  159. if ($spamfilter->captcha_check()) return;
  160. // ���ݾ����˹��äƤ������硢CAPTCHA�Ǥ�ǧ�ڤ��餻����λ
  161. if ($spamfilter->is_spam())
  162. die_message( "Spam check failed. Plugin:". $spamfilter->plugin_name ." Match:". $spamfilter->message ."<br>\n" );
  163. // CAPTCHA���������˹��äƤ������硢CAPTCHA��ɽ��
  164. if ($spamfilter->is_spam(SPAM_FILTER_CAPTCHA_COND))
  165. $spamfilter->captcha_show();
  166. }
  167. //// ���ѥ��ե��륿���饹
  168. // �ե��륿�Ѥ�û���ؿ�̾��̾�����֤������ʤ����᥯�饹�ǤޤȤ᤿����
  169. class SpamFilter
  170. {
  171. // �ƥ��ѥ��ե��륿�ǻ��Ȥ����ǡ���
  172. var $post_data; // ���Ƥ��줿����
  173. var $plugin_name; // �ƤӽФ��줿�ץ饰����̾
  174. var $message; // ���顼�����Ѥ˥ޥå����������ʤɤ��ɵ����Ƥ���
  175. var $dns_get_ns_cache; // dns_get_ns�Υ����å�����
  176. function SpamFilter($post, $plugin)
  177. {
  178. $this->post_data = $post;
  179. $this->plugin_name = $plugin;
  180. $this->message = '';
  181. }
  182. // SPAM_FILTER_COND �ǻ��ꤵ�줿���ѥ��ե��륿���ݤ���
  183. function is_spam($cond = SPAM_FILTER_COND)
  184. {
  185. // read �ȡ�edit �� preview �ΤȤ��ϥ����å��ݤ��ʤ�
  186. global $vars;
  187. if ($this->plugin_name == 'read' ||
  188. $this->plugin_name == 'edit' && isset($vars['preview'])) return FALSE;
  189. // bugtrack �λ��� summary �� body �� msg �Ȥ��ƥ����å�����
  190. if ($this->plugin_name == 'bugtrack')
  191. $this->post_data['msg'] = $this->post_data['summary'] . $this->post_data['body'];
  192. // �ե��륿�����λ��꤬�ʤ����Ф��Τޤ��֤�
  193. if (preg_match('/^\s*$/', $cond)) return FALSE;
  194. // �ޥå������������񤭽Ф��Хåե��򥯥ꥢ
  195. $this->message = '';
  196. // �ե��륿�������������Ƥ��������å��ݤ���
  197. $cond = preg_replace('/#/', '$this->', $cond);
  198. $cond = 'return('. $cond .');';
  199. return eval( $cond );
  200. }
  201. function check_plugin($pluginnames)
  202. {
  203. $plugin_names = explode(",", $pluginnames);
  204. return in_array($this->plugin_name, $plugin_names);
  205. }
  206. // ���Ƥ�����ɽ�������å�
  207. function ngreg($reg = SPAM_FILTER_NGREG_REG,
  208. $pluginnames = SPAM_FILTER_NGREG_PLUGIN_NAME)
  209. {
  210. if (!$this->check_plugin($pluginnames)) return FALSE;
  211. if (preg_match($reg, $this->post_data['msg'])) {
  212. $this->message .= 'ngreg ';
  213. return TRUE;
  214. }
  215. return FALSE;
  216. }
  217. // ���ƤΤ�URL���ޤޤ��Ƥ��뤫�����å�
  218. function url($reg = SPAM_FILTER_URL_REG,
  219. $pluginnames = SPAM_FILTER_URL_PLUGIN_NAME)
  220. {
  221. if (!$this->check_plugin($pluginnames)) return FALSE;
  222. if (preg_match($reg, $this->post_data['msg'])) {
  223. $this->message .= 'url ';
  224. return TRUE;
  225. }
  226. return FALSE;
  227. }
  228. // ���Ƥ�</A>��[/URL]�Τ褦�ʥ��󥫡��������ޤޤ��Ƥ��뤫�����å�
  229. function atag($reg = SPAM_FILTER_ATAG_REG,
  230. $pluginnames = SPAM_FILTER_ATAG_PLUGIN_NAME)
  231. {
  232. if (!$this->check_plugin($pluginnames)) return FALSE;
  233. if (preg_match($reg, $this->post_data['msg'])) {
  234. $this->message .= 'atag ';
  235. return TRUE;
  236. }
  237. return FALSE;
  238. }
  239. // ���Ƥ�Ⱦ�ѱѿ��Τ�(���ܸ줬���äƤ��ʤ�)�������å�
  240. function onlyeng($reg = SPAM_FILTER_ONLYENG_REG,
  241. $pluginnames = SPAM_FILTER_ONLYENG_PLUGIN_NAME)
  242. {
  243. if (!$this->check_plugin($pluginnames)) return FALSE;
  244. if (preg_match($reg, $this->post_data['msg'])) {
  245. $this->message .= 'onlyeng ';
  246. return TRUE;
  247. }
  248. return FALSE;
  249. }
  250. // ���Ƥ˴ޤޤ��Ƥ���URL�����İʾ夫�����å�
  251. function urlnum($num = SPAM_FILTER_URLNUM_NUM,
  252. $whitereg = SPAM_FILTER_URLNUM_WHITEREG,
  253. $urlreg = SPAM_FILTER_URLNUM_URLREG,
  254. $pluginnames = SPAM_FILTER_URLNUM_PLUGIN_NAME)
  255. {
  256. // die_message("in urlnum plugin_name". $this->plugin_name);
  257. if (!$this->check_plugin($pluginnames)) return FALSE;
  258. // ��������URL������
  259. preg_match_all($urlreg, $this->post_data['msg'], $urls);
  260. foreach ($urls[0] as $url) {
  261. // �ۥ���̾���ۥ磻�ȥꥹ�Ȥˤ���������̵�뤷�Ƽ���URL�Υ����å���
  262. if (preg_match($whitereg, $url)) continue;
  263. // �ۥ磻�ȥꥹ�Ȥ˥ޥå����ʤ��ä��Ȥ��ϥ������ȥ��å�
  264. $link_count ++;
  265. }
  266. if ($link_count >= $num) {
  267. $this->message .= 'urlnum ';
  268. return TRUE;
  269. }
  270. return FALSE;
  271. }
  272. // ���饤�����Ȥ�IP���հ����Ǥ��뤫�����å�
  273. function ipunknown($pluginnames = SPAM_FILTER_IPUNKNOWN_PLUGIN_NAME)
  274. {
  275. if (!$this->check_plugin($pluginnames)) return FALSE;
  276. // IP�����ꤵ���Ƥ��ʤ�������Ĵ�٤����ʤ��Τ��̤�
  277. if (empty($_SERVER['REMOTE_ADDR'])) return FALSE;
  278. $hostname = gethostbyaddr($_SERVER['REMOTE_ADDR']);
  279. if (empty($hostname)) {
  280. $this->message .= 'ipunknown ';
  281. return TRUE;
  282. }
  283. return FALSE;
  284. }
  285. // ���饤�����Ȥ�IP��ưŪIP�äݤ�(S25R�˥ޥå�����)�������å�
  286. function ips25r($reg = SPAM_FILTER_IPS25R_REG,
  287. $pluginnames = SPAM_FILTER_IPS25R_PLUGIN_NAME)
  288. {
  289. if (!$this->check_plugin($pluginnames)) return FALSE;
  290. // IP�����ꤵ���Ƥ��ʤ�������Ĵ�٤����ʤ��Τ��̤�
  291. if (empty($_SERVER['REMOTE_ADDR'])) return FALSE;
  292. $hostname = gethostbyaddr($_SERVER['REMOTE_ADDR']);
  293. if (empty($hostname) || preg_match($reg, $hostname)) {
  294. $this->message .= 'ips25r ';
  295. return TRUE;
  296. }
  297. return FALSE;
  298. }
  299. // ���饤�����Ȥ�IP�Υ����å�
  300. function ipbl($reg = SPAM_FILTER_IPBL_REG,
  301. $pluginnames = SPAM_FILTER_IPBL_PLUGIN_NAME)
  302. {
  303. if (!$this->check_plugin($pluginnames)) return FALSE;
  304. // IP�����ꤵ���Ƥ��ʤ�������Ĵ�٤����ʤ��Τ��̤�
  305. if (empty($_SERVER['REMOTE_ADDR'])) return FALSE;
  306. $hostname = gethostbyaddr($_SERVER['REMOTE_ADDR']);
  307. if (preg_match($reg, $_SERVER['REMOTE_ADDR']) ||
  308. preg_match($reg, $hostname)) {
  309. $this->message .= 'ipbl ';
  310. return TRUE;
  311. }
  312. if (SPAM_FILTER_IPBL_UNKNOWN && empty($hostname)) {
  313. $this->message .= 'ipbl(unknown) ';
  314. return TRUE;
  315. }
  316. return FALSE;
  317. }
  318. // ���饤�����Ȥ�IP��DNSBL�ǥ����å�
  319. function ipdnsbl($dnss = SPAM_FILTER_IPDNSBL_DNS,
  320. $pluginnames = SPAM_FILTER_IPDNSBL_PLUGIN_NAME)
  321. {
  322. if (!$this->check_plugin($pluginnames)) return FALSE;
  323. // IP�����ꤵ���Ƥ��ʤ�������Ĵ�٤����ʤ��Τ��̤�
  324. if (empty($_SERVER['REMOTE_ADDR'])) return FALSE;
  325. $dns_hosts = explode(",", $dnss);
  326. $ip = $_SERVER['REMOTE_ADDR'];
  327. $revip = implode('.', array_reverse(explode('.', $ip)));
  328. foreach ($dns_hosts as $dns) {
  329. $lookup = $revip . '.' . $dns;
  330. $result = gethostbyname($lookup);
  331. if ($result != $lookup) {
  332. $this->message .= 'ipdnsbl ';
  333. return TRUE;
  334. }
  335. }
  336. return FALSE;
  337. }
  338. // ���饤�����Ȥ�IP�ι��������å�
  339. function ipcountry($reg = SPAM_FILTER_IPCOUNTRY_REG,
  340. $pluginnames = SPAM_FILTER_IPCOUNTRY_PLUGIN_NAME)
  341. {
  342. if (!$this->check_plugin($pluginnames)) return FALSE;
  343. // IP�����ꤵ���Ƥ��ʤ�������Ĵ�٤����ʤ��Τ��̤�
  344. if (empty($_SERVER['REMOTE_ADDR'])) return FALSE;
  345. $country = $this->get_country_code( $_SERVER['REMOTE_ADDR'] );
  346. if (preg_match($reg, $country)) {
  347. $this->message .= 'ipcountry ';
  348. return TRUE;
  349. }
  350. return FALSE;
  351. }
  352. // HTTP_USER_AGENT������(pukiwiki.ini.php��$agents�ǻ���)�������å�
  353. function uaunknown($pluginnames = SPAM_FILTER_UAUNKNOWN_PLUGIN_NAME)
  354. {
  355. global $agents;
  356. if (!$this->check_plugin($pluginnames)) return FALSE;
  357. // UserAgent�ͤ����ꤵ���Ƥ��ʤ������ϵ���
  358. if (empty($_SERVER['HTTP_USER_AGENT'])) {
  359. $this->message .= 'uaunknown(empty) ';
  360. return TRUE;
  361. }
  362. // $agents�κǸ��ˤ���default�����ʳ��ȥޥå�������
  363. $agents_temp = $agents;
  364. array_pop( $agents_temp );
  365. foreach ($agents_temp as $agent) {
  366. // �ɤ줫��UA�ȥޥå������������ʤ�
  367. if (preg_match($agent['pattern'], $_SERVER['HTTP_USER_AGENT'])) return FALSE;
  368. }
  369. // �ɤ�UA�Ȥ��ޥå����ʤ��ä�
  370. $this->message .= 'uaunknown ';
  371. return TRUE;
  372. }
  373. // HTTP_USER_AGENT�Υ����å�
  374. // �����Ѥˤ� HTTP_USER_AGENT ���ä��ʤ��褦 init.php �إѥå���ɬ�פ���
  375. function useragent($reg = SPAM_FILTER_USERAGENT_REG,
  376. $pluginnames = SPAM_FILTER_USERAGENT_PLUGIN_NAME)
  377. {
  378. if (!$this->check_plugin($pluginnames)) return FALSE;
  379. // UserAgent�ͤ����ꤵ���Ƥ��ʤ������ϵ���
  380. if (empty($_SERVER['HTTP_USER_AGENT'])) {
  381. $this->message .= 'uaunknown(empty) ';
  382. return TRUE;
  383. }
  384. if (preg_match($reg, $_SERVER['HTTP_USER_AGENT'])) {
  385. $this->message .= 'useragent ';
  386. return TRUE;
  387. }
  388. return FALSE;
  389. }
  390. // HTTP_ACCEPT_LANGUAGE�Υ����å�
  391. function acceptlanguage($reg = SPAM_FILTER_ACCEPTLANGUAGE_REG,
  392. $pluginnames = SPAM_FILTER_ACCEPTLANGUAGE_PLUGIN_NAME)
  393. {
  394. if (!$this->check_plugin($pluginnames)) return FALSE;
  395. // AcceptLanguage�ͤ����ꤵ���Ƥ��ʤ������ϵ���
  396. if (empty($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
  397. $this->message .= 'alunknown(empty) ';
  398. return TRUE;
  399. }
  400. if (preg_match($reg, $_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
  401. $this->message .= 'acceptlanguage ';
  402. return TRUE;
  403. }
  404. return FALSE;
  405. }
  406. // ���åץ����ɥե�����̾�ˤ����ե��륿
  407. function filename($reg = SPAM_FILTER_FILENAME_REG,
  408. $pluginnames = SPAM_FILTER_FILENAME_PLUGIN_NAME)
  409. {
  410. if (!$this->check_plugin($pluginnames)) return FALSE;
  411. if (isset($_FILES['attach_file'])) {
  412. $file = $_FILES['attach_file'];
  413. if (preg_match($reg, $file['name'])) {
  414. $this->message .= 'filename ';
  415. return TRUE;
  416. }
  417. }
  418. return FALSE;
  419. }
  420. // ¸�ߤ��ʤ��Ϥ��Υե��������Ƥ����뤫�����å�
  421. function formname($formnames = SPAM_FILTER_FORMNAME_NAME,
  422. $pluginnames = SPAM_FILTER_FORMNAME_PLUGIN_NAME)
  423. {
  424. if (!$this->check_plugin($pluginnames)) return FALSE;
  425. // ���ꤵ�줿̾���Υե����������Ƥ��ʤˤ����뤫��ǧ
  426. $form_names = explode(",", $formnames);
  427. foreach ($form_names as $name) {
  428. if (!empty($this->post_data["$name"])) {
  429. $this->message .= 'formname ';
  430. return TRUE;
  431. }
  432. }
  433. return FALSE;
  434. }
  435. // URL���֥��å��ꥹ�Ȥ����äƤ��뤫��ǧ
  436. function urlbl($reg = SPAM_FILTER_URLBL_REG,
  437. $whitereg = SPAM_FILTER_URLBL_WHITEREG,
  438. $urlreg = SPAM_FILTER_URLBL_URLREG,
  439. $pluginnames = SPAM_FILTER_URLBL_PLUGIN_NAME)
  440. {
  441. if (!$this->check_plugin($pluginnames)) return FALSE;
  442. // ��������URL������
  443. preg_match_all($urlreg, $this->post_data['msg'], $urls);
  444. foreach ($urls[0] as $url) {
  445. // URL�Υۥ���̾�����ɥᥤ��������
  446. $url_array = parse_url($url);
  447. $hostname = $url_array['host'];
  448. // �ۥ���̾���ۥ磻�ȥꥹ�Ȥˤ���������̵�뤷�Ƽ���URL�Υ����å���
  449. if (preg_match($whitereg, $hostname)) continue;
  450. // �ۥ���̾���֥��å��ꥹ�ȤȾȤ餷���碌
  451. if (preg_match($reg, $hostname)) {
  452. $this->message .= 'urlbl(name) ';
  453. return TRUE;
  454. }
  455. // �ۥ���̾��IP���֥��å��ꥹ�ȤȾȤ餷���碌
  456. if ($iplist = gethostbynamel($hostname)) {
  457. foreach ($iplist as $ip) {
  458. if (preg_match($reg, $ip)) {
  459. $this->message .= 'urlbl(ip) ';
  460. return TRUE;
  461. }
  462. }
  463. }
  464. else {
  465. // IP�����Ĥ������ʤ��ä��Ȥ��ˤ����ݤ�������
  466. if (SPAM_FILTER_URLBL_UNKNOWN) {
  467. $this->message .= 'urlbl(unknown) ';
  468. return TRUE;
  469. }
  470. }
  471. }
  472. return FALSE;
  473. }
  474. // URL�Υ����ФΤ������������å�
  475. function urlcountry($reg = SPAM_FILTER_URLCOUNTRY_REG,
  476. $whitereg = SPAM_FILTER_URLCOUNTRY_WHITEREG,
  477. $urlreg = SPAM_FILTER_URLCOUNTRY_URLREG,
  478. $pluginnames = SPAM_FILTER_URLCOUNTRY_PLUGIN_NAME)
  479. {
  480. if (!$this->check_plugin($pluginnames)) return FALSE;
  481. // ��������URL������
  482. preg_match_all($urlreg, $this->post_data['msg'], $urls);
  483. foreach ($urls[0] as $url) {
  484. // URL�Υۥ���̾������
  485. $url_array = parse_url($url);
  486. $hostname = $url_array['host'];
  487. // �ۥ���̾���ۥ磻�ȥꥹ�Ȥˤ���������̵�뤷�Ƽ���URL�Υ����å���
  488. if (preg_match($whitereg, $hostname)) continue;
  489. // �ۥ���̾��IP���֥��å��ꥹ�ȤȾȤ餷���碌
  490. if ($iplist = gethostbynamel($hostname)) {
  491. foreach ($iplist as $ip) {
  492. $country = $this->get_country_code( $ip );
  493. //$tmpmes .= $hostname . ' ' . $ip . ' ' . $country . ', ';
  494. if (preg_match($reg, $country)) {
  495. $this->message .= 'urlcountry ';
  496. return TRUE;
  497. }
  498. }
  499. }
  500. else {
  501. // IP�����Ĥ������ʤ��ä��Ȥ��ˤ����ݤ�������
  502. if (SPAM_FILTER_URLCOUNTRY_UNKNOWN) {
  503. $this->message .= 'urlcountry(unknown) ';
  504. return TRUE;
  505. }
  506. }
  507. }
  508. // die_message( "mes: $tmpmes" );
  509. return FALSE;
  510. }
  511. // URL��DNSBL�����äƤ��뤫��ǧ
  512. function urldnsbl($dnss = SPAM_FILTER_URLDNSBL_DNS,
  513. $whitereg = SPAM_FILTER_URLDNSBL_WHITEREG,
  514. $urlreg = SPAM_FILTER_URLDNSBL_URLREG,
  515. $pluginnames = SPAM_FILTER_URLDNSBL_PLUGIN_NAME)
  516. {
  517. if (!$this->check_plugin($pluginnames)) return FALSE;
  518. $dns_hosts = explode(",", $dnss);
  519. // ��������URL������
  520. preg_match_all($urlreg, $this->post_data['msg'], $urls);
  521. foreach ($urls[0] as $url) {
  522. // �ۥ���̾���ۥ磻�ȥꥹ�Ȥˤ���������̵�뤷�Ƽ���URL�Υ����å���
  523. if (preg_match($whitereg, $url)) continue;
  524. // URL�Υۥ���̾�����ɥᥤ��������
  525. $url_array = parse_url($url);
  526. $hostname = $url_array['host'];
  527. // �ɤ�����DNSBL����Ͽ�����Ƥ���
  528. foreach ($dns_hosts as $dns) {
  529. $lookup = $hostname . '.' . $dns;
  530. $result = gethostbyname($lookup);
  531. if ($result != $lookup) {
  532. $this->message .= 'urldnsbl ';
  533. return TRUE;
  534. }
  535. }
  536. }
  537. return FALSE;
  538. }
  539. // URL��NS���֥��å��ꥹ�Ȥ����äƤ��뤫��ǧ
  540. function urlnsbl($reg = SPAM_FILTER_URLNSBL_REG,
  541. $whitereg = SPAM_FILTER_URLNSBL_WHITEREG,
  542. $urlreg = SPAM_FILTER_URLNSBL_URLREG,
  543. $pluginnames = SPAM_FILTER_URLNSBL_PLUGIN_NAME)
  544. {
  545. if (!$this->check_plugin($pluginnames)) return FALSE;
  546. // ��������URL������
  547. preg_match_all($urlreg, $this->post_data['msg'], $urls);
  548. foreach ($urls[0] as $url) {
  549. // URL�Υۥ���̾������
  550. $url_array = parse_url($url);
  551. $hostname = $url_array['host'];
  552. // �ۥ���̾���ۥ磻�ȥꥹ�Ȥˤ���������̵�뤷�Ƽ���URL�Υ����å���
  553. if (preg_match($whitereg, $hostname)) continue;
  554. // �ɥᥤ����NS������
  555. if ($this->dns_get_ns($hostname, $nslist)) {
  556. // �ɥᥤ����NS�������줿��NS�֥��å��ꥹ�ȤȾȤ餷���碌
  557. foreach ($nslist as $ns) {
  558. if (preg_match($reg, $ns)) {
  559. $this->message .= 'urlnsbl(name) ';
  560. return TRUE;
  561. }
  562. // NS��IP���֥��å��ꥹ�ȤȾȤ餷���碌
  563. if ($iplist = gethostbynamel($ns)) {
  564. foreach ($iplist as $ip) {
  565. if (preg_match($reg, $ip)) {
  566. $this->message .= 'urlnsbl(ip) ';
  567. return TRUE;
  568. }
  569. }
  570. }
  571. }
  572. }
  573. else {
  574. // NS���������ʤ��ä�
  575. if (SPAM_FILTER_URLNSBL_NSUNKNOWN) {
  576. $this->message .= 'urlnsbl(unknown) ';
  577. return TRUE;
  578. }
  579. }
  580. }
  581. return FALSE;
  582. }
  583. // URL��NS�ι��������å�
  584. function urlnscountry($reg = SPAM_FILTER_URLNSCOUNTRY_REG,
  585. $whitereg = SPAM_FILTER_URLNSCOUNTRY_WHITEREG,
  586. $urlreg = SPAM_FILTER_URLNSCOUNTRY_URLREG,
  587. $pluginnames = SPAM_FILTER_URLNSCOUNTRY_PLUGIN_NAME)
  588. {
  589. if (!$this->check_plugin($pluginnames)) return FALSE;
  590. // ��������URL������
  591. preg_match_all($urlreg, $this->post_data['msg'], $urls);
  592. foreach ($urls[0] as $url) {
  593. // URL�Υۥ���̾������
  594. $url_array = parse_url($url);
  595. $hostname = $url_array['host'];
  596. // �ۥ���̾���ۥ磻�ȥꥹ�Ȥˤ���������̵�뤷�Ƽ���URL�Υ����å���
  597. if (preg_match($whitereg, $hostname)) continue;
  598. // �ɥᥤ����NS������
  599. if ($this->dns_get_ns($hostname, $nslist)) {
  600. // �ɥᥤ����NS�������줿�餽�ι���Ĵ�٤ơ��񥳡��ɤȾȤ餷���碌
  601. foreach ($nslist as $ns) {
  602. $country = $this->get_country_code( gethostbyname($ns) );
  603. if (preg_match($reg, $country)) {
  604. $this->message .= 'urlnscountry ';
  605. return TRUE;
  606. }
  607. }
  608. }
  609. else {
  610. // NS���������ʤ��ä�
  611. if (SPAM_FILTER_URLNSBL_NSUNKNOWN) {
  612. $this->message .= 'urlnscountry(unknown) ';
  613. return TRUE;
  614. }
  615. }
  616. }
  617. return FALSE;
  618. }
  619. // Akismet �ˤ��������å�
  620. function akismet($pluginnames = SPAM_FILTER_AKISMET_PLUGIN_NAME)
  621. {
  622. // ������http://note.sonots.com/?PukiWiki%2Fakismet.inc.php���ͤ˽�������
  623. if (!$this->check_plugin($pluginnames)) return FALSE;
  624. // akismet���饹���ɤ߹���
  625. require_once 'akismet.class.php';
  626. // Post�ǡ�����Ϣ�뤹�롣
  627. $ignore_post_keys = explode(",", SPAM_FILTER_AKISMET_IGNORE_KEY);
  628. foreach ($this->post_data as $key => $val) {
  629. // ignore_post_keys�����ꤵ���Ƥ���Post�ǡ�����Akismet�������ʤ�
  630. if (!in_array($key, $ignore_post_keys)) {
  631. $body = $body . $val;
  632. }
  633. }
  634. // Akismet�����������ǡ�������������
  635. $comment = array();
  636. $comment['author'] = '';
  637. $comment['email'] = '';
  638. $comment['website'] = '';
  639. $comment['permalink'] = '';
  640. $comment['body'] = $body;
  641. $akismet = new Akismet(URL, SPAM_FILTER_AKISMET_API_KEY, $comment);
  642. if ($akismet->isSpam() == '1') {
  643. $this->message .= 'akismet ';
  644. return TRUE;
  645. }
  646. return FALSE;
  647. }
  648. // CAPTCHA�Ǥ����Ϥ����äƤ��뤫�����å�
  649. function captcha_check()
  650. {
  651. // reCAPTCHA �ǤΥ����å�
  652. if ($_POST["recaptcha_response_field"]) {
  653. $resp = recaptcha_check_answer (SPAM_FILTER_RECAPTCHA_PRIVATEKEY,
  654. $_SERVER["REMOTE_ADDR"],
  655. $_POST["recaptcha_challenge_field"],
  656. $_POST["recaptcha_response_field"]);
  657. if ($resp->is_valid) return TRUE;
  658. }
  659. return FALSE;
  660. }
  661. // CAPTCHA�Ǥ����Ϥ�������
  662. function captcha_show()
  663. {
  664. // reCAPTCHA �Ǥ�CAPTCHA��ɽ��
  665. global $vars;
  666. $page = $vars['page'];
  667. $form .= "<form action='' method='post'>\n";
  668. $form .= "�������Ĥ�ñ�������Ϥ��Ƥ���������\n";
  669. $form .= recaptcha_get_html(SPAM_FILTER_RECAPTCHA_PUBLICKEY);
  670. foreach ($_POST as $key => $val) {
  671. if ($key == 'recaptcha_response_field' or
  672. $key == 'recaptcha_challenge_field') continue;
  673. $form .= ' <input type="hidden" name="' . $key . '" value="' . htmlspecialchars($val) . '" />' . "\n";
  674. }
  675. $form .= ' <input type="hidden" name="page" value="' . htmlspecialchars($page) . '" />' . "\n";
  676. $form .= ' <input type="submit" name="" value="ǧ��" /><br />' . "\n";
  677. $form .= '</form>' . "\n";
  678. die_message( "Spam check failed. Plugin:". $this->plugin_name ." Match:". $this->message ."<br>\n". $form );
  679. }
  680. // get DNS server for Windows XP SP2, Vista SP1
  681. function getDNSServer()
  682. {
  683. @exec('ipconfig /all', $ipconfig);
  684. //print_a($ipconfig, 'label:nameserver');
  685. foreach ($ipconfig as $line) {
  686. if (preg_match('/\s*DNS .+:\s+([\d\.]+)$/', $line, $nameservers)) {
  687. $nameserver = $nameservers[1];
  688. }
  689. }
  690. if (empty($nameserver)) {
  691. die_message('Can not lookup your DNS server');
  692. }
  693. //print_a($nameserver, 'label:nameserver');
  694. return $nameserver;
  695. }
  696. //// �ۥ���̾����NS���������������Ѵؿ�
  697. // hostname�Υɥᥤ����NS���ꥹ��($ns_array)���֤�
  698. // �������ʤ��ä������ϴؿ����֤��ͤ�FALSE
  699. // ��PHP4�ξ��硢nslookup ���ޥ��ɤ��Ȥ���ɬ�פ���
  700. function dns_get_ns( $hostname, &$ns_array )
  701. {
  702. // �������֤��Ȥ����򥯥ꥢ���Ƥ���
  703. if (!empty($ns_array)) while (array_pop($ns_array));
  704. // �ޤ������å��夬�ʤ����а������������̤Υ����å����ե��������ɤ߹���
  705. if (empty($this->dns_get_ns_cache)) {
  706. $fp = fopen(DATA_HOME . SPAM_FILTER_DNSGETNS_CACHE_FILE, "a+")
  707. or die_message('Cannot read dns_get_ns cache file: '. SPAM_FILTER_DNSGETNS_CACHE_FILE ."\n");
  708. flock($fp, LOCK_SH);
  709. while ($csv = fgetcsv($fp, 1000, ",")) {
  710. $host = array_shift($csv);
  711. $time = $csv[0];
  712. if ($time + SPAM_FILTER_DNSGETNS_CACHE_DAY*24*60*60 < time())
  713. continue; // �Ť����������ϼΤƤ�
  714. $this->dns_get_ns_cache["$host"] = $csv;
  715. }
  716. flock($fp, LOCK_UN);
  717. fclose($fp);
  718. }
  719. // �����å����η��̤����äƤ��ʤ餽���������̤��������֤�
  720. $cache = $this->dns_get_ns_cache["$hostname"];
  721. if(!empty($cache)) {
  722. $time = array_shift($cache);
  723. foreach($cache as $ns) {
  724. $ns_array[] = $ns;
  725. }
  726. return TRUE;
  727. }
  728. // �ۥ���̾���夫�����ĤŤĸ��餷��NS�����������ޤǻ
  729. // ��: www.subdomain.example.com��subdomain.example.com��example.com
  730. $domain_array = explode(".", $hostname);
  731. $ns_found = FALSE;
  732. do {
  733. $domain = implode(".", $domain_array);
  734. // �Ķ��ǻȤ������ʤ˹��碌�ƥɥᥤ����NS������
  735. if (function_exists('dns_get_record')) {
  736. // �����ؿ� dns_get_record �Ȥ�������
  737. $lookup = dns_get_record($domain, DNS_NS);
  738. if (!empty($lookup)) {
  739. foreach ($lookup as $record) {
  740. $ns_array[] = $record['target'];
  741. }
  742. $ns_found = TRUE;
  743. }
  744. }
  745. else if (include_once('Net/DNS.php')) {
  746. // PEAR��DNS���饹���Ȥ�������
  747. $resolver = new Net_DNS_Resolver();
  748. if (SPAM_FILTER_IS_WINDOWS) $resolver->nameservers[0] = $this->getDNSServer();
  749. $response = $resolver->query($domain, 'NS');
  750. if ($response) {
  751. foreach ($response->answer as $rr) {
  752. if ($rr->type == "NS") {
  753. $ns_array[] = $rr->nsdname;
  754. }
  755. else if ($rr->type == "CNAME") {
  756. // CNAME�����Ƥ��Ȥ��ϡ����ä����Ƶ��ǰ���
  757. $this->dns_get_ns($rr->rdatastr(), $ns_array);
  758. }
  759. }
  760. $ns_found = TRUE;
  761. }
  762. }
  763. else {
  764. // PEAR���Ȥ��ʤ����硢�������ޥ���nslookup�ˤ���NS������
  765. is_executable(SPAM_FILTER_NSLOOKUP_PATH)
  766. or die_message("Cannot execute nslookup. see NSLOOKUP_PATH setting.\n");
  767. @exec(SPAM_FILTER_NSLOOKUP_PATH . " -type=ns " . $domain, $lookup);
  768. foreach ($lookup as $line) {
  769. if( preg_match('/\s*nameserver\s*=\s*(\S+)$/', $line, $ns) ||
  770. preg_match('/\s*origin\s*=\s*(\S+)$/', $line, $ns) ||
  771. preg_match('/\s*primary name server\s*=\s*(\S+)$/', $line, $ns) ) {
  772. $ns_array[] = $ns[1];
  773. $ns_found = TRUE;
  774. }
  775. }
  776. }
  777. } while (!$ns_found && array_shift($domain_array) != NULL);
  778. // NS�������Ƥ����顢���̤򥭥��å�������������¸
  779. if ($ns_found) {
  780. // ���̤򥭥��å�������Ͽ
  781. $cache = $ns_array;
  782. array_unshift($cache, time()); // ���������֤��ݻ�
  783. $this->dns_get_ns_cache["$hostname"] = $cache;
  784. // �����å������ե���������¸
  785. $fp = fopen(DATA_HOME . SPAM_FILTER_DNSGETNS_CACHE_FILE, "w")
  786. or die_message("Cannot write dns_get_ns cache file: ". SPAM_FILTER_DNSGETNS_CACHE_FILE ."\n");
  787. flock($fp, LOCK_EX);
  788. foreach ($this->dns_get_ns_cache as $host=>$cachedata) {
  789. $csv = $host;
  790. foreach ($cachedata as $data) {
  791. $csv .= ",". $data;
  792. }
  793. $csv .= "\n";
  794. fputs($fp, $csv);
  795. }
  796. flock($fp, LOCK_UN);
  797. fclose($fp);
  798. }
  799. return $ns_found;
  800. }
  801. //// IP���ɥ쥹�����񥳡��ɤ��������������Ѵؿ�
  802. // IP���ɥ쥹("10.1.2.3"�ߤ�����ʸ����)����JP�Ȥ��ι񥳡��ɤ��֤�
  803. // �������ʤ��ä�������empty('')���֤�
  804. // ��APNIC��IP���ꥢ�ȹ����б������ɥե����뤬ɬ��
  805. // �������ꥫ��IP�ϥꥹ�Ȥ�̵����
  806. function get_country_code( $ip_string )
  807. {
  808. // �ޤ���IP�ꥹ�Ȥ��ɤ��Ǥʤ����Хե��������ɤ߹����ǥ����å��夹��
  809. if (empty($this->get_country_code_cache)) {
  810. $fp = fopen( DATA_HOME . SPAM_FILTER_IPCOUNTRY_FILE, "r")
  811. or die_message('Cannot read country file: ' . SPAM_FILTER_IPCOUNTRY_FILE . "\n");
  812. while ($csv = fgetcsv($fp, 1000, "|")) {
  813. // IPv4�����б�
  814. if ($csv[2] === "ipv4") {
  815. $country = $csv[1];
  816. $ipstring = $csv[3];
  817. $ipranges = explode(".", $ipstring);
  818. $iprange = ip2long($ipstring);
  819. $mask = 256*256*256*256 - $csv[4];
  820. $data = new country_data;
  821. $data->country = $country;
  822. $data->iprange = $iprange;
  823. $data->mask = $mask;
  824. // Class A���ޤ���������̵���Τǥȥåפ�256��ʬ�䤷���ݻ�
  825. $this->get_country_code_cache["$ipranges[0]"][] = $data;
  826. }
  827. }
  828. fclose($fp);
  829. }
  830. $ip = ip2long($ip_string);
  831. $ranges = explode(".", $ip_string);
  832. $country_code = '';
  833. foreach ($this->get_country_code_cache["$ranges[0]"] as $data) {
  834. if ( $data->iprange == ($ip & $data->mask) ) {
  835. $country_code = $data->country;
  836. break;
  837. }
  838. }
  839. return $country_code;
  840. }
  841. }
  842. // get_country_code ���ݻ����Ƥ����ǡ�����¤
  843. class country_data
  844. {
  845. var $country;
  846. var $iprange;
  847. var $mask;
  848. }
  849. ?>