/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¤Ê¤É¤Ç³Æ¥¹¥Ñ¥à¥Õ¥£¥ë¥¿¤ÎÍøÍѤȥե£¥ë¥¿Ëè¤Î»ØÄê¤ò¤¹¤ë
  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¤Î²ÄǽÀ­¤¬¤¢¤ë¤â¤Î¤ÏÊ£¹ç¾ò·ï¤Ç³Ý¤±¤ë
  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. ?>