/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
- <?php
- /*
- * spam_filter.php
- *
- * Based on akismet_filter.php version 1.2
- * author Akio KONUMA konuma@ark-web.jp
- * link http://www.ark-web.jp/sandbox/wiki/190.html
- *
- * @authoer SATOH Kiyoshi (satoh at hakuba dot jp)
- * @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
- * @version 0.8.0
- * @license GPL v2 or (at your option) any later version
- */
- //// pukiwiki.ini.php¤Ê¤É¤Ç³Æ¥¹¥Ñ¥à¥Õ¥£¥ë¥¿¤ÎÍøÍѤȥե£¥ë¥¿Ëè¤Î»ØÄê¤ò¤¹¤ë
- // ÀßÄêÆâÍÆ¤Î̿̾µ¬Â§¤ÈÆâÍÆ
- // SPAM_FILTER_****_PLUGIN_NAME -> ¥Á¥§¥Ã¥¯ÂоݤȤ¹¤ë¥×¥é¥°¥¤¥ó̾¡£¥«¥ó¥Þ¶èÀÚ¤ê
- // SPAM_FILTER_****_REG -> ¥Þ¥Ã¥Á¤µ¤»¤ëÀµµ¬É½¸½
- // SPAM_FILTER_****_URLREG -> URL¤ò¼±Ê̤¹¤ë¤¿¤á¤ÎÀµµ¬É½¸½
- // SPAM_FILTER_****_WHITEREG -> ¥Þ¥Ã¥Á¤·¤Ê¤¯¤Æ¤è¤¤URL¥Û¥ï¥¤¥È¥ê¥¹¥È
- //// ¥¹¥Ñ¥à¤ÈȽÃǤ¹¤ë¾ò·ï¤ò»ØÄꤹ¤ë
- // »ØÄꤵ¤ì¤¿³Æ¼ï¥¹¥Ñ¥à¥Õ¥£¥ë¥¿¤òÁ´ÉôÄ̤俤éFALSE
- // ·Ú¤¤¥Õ¥£¥ë¥¿¤«¤é½ç¤Ë³Ý¤±¡¢false positive¤Î²ÄǽÀ¤¬¤¢¤ë¤â¤Î¤ÏÊ£¹ç¾ò·ï¤Ç³Ý¤±¤ë
- // ¢¨SPAM_FILTER_COND ÀßÄêÎã
- // ¢¨UserAgent¤¬libwwwÅù¡¢HTML¤ÎźÉÕ¥Õ¥¡¥¤¥ë¡¢</a>¥¿¥°Åù¤¬¤¢¤ë¡¢±Ñ¸ì¤Î¤ß¤ÇURL¤¬3¤Ä°Ê¾å¡¢URL¤ÎNS¤Î¥Ö¥é¥Ã¥¯¥ê¥¹¥È
- //define('SPAM_FILTER_COND', '#useragent() or #filename() or #atag() or (#onlyeng() and #urlnum()) or #urlnsbl()');
- // ¢¨¾åµ¾ò·ï¤Ë¥×¥é¥¹¡¢±Ñ¸ì¤Î¤ß¤Î¤È¤¤ÇURL¤¬¤¢¤ë¤È¤¤À¤±Akismet¤ÇÀººº
- //define('SPAM_FILTER_COND', '#useragent() or #filename() or #atag() or (#onlyeng() and #urlnum()) or #urlnsbl() or (#onlyeng() and #url() and #akismet())');
- // ¢¨¥Ç¥Õ¥©¥ë¥È¤Ç¤Ï¥Õ¥£¥ë¥¿¤Ê¤·
- define('SPAM_FILTER_COND', '');
- //// CAPTCHA¤Ç¤Î¥Á¥§¥Ã¥¯¤ò¤¹¤ë¾ò·ï¤ò»ØÄꤹ¤ë
- // ¢¨¥Ç¥Õ¥©¥ë¥È¤Ç¤Ï¥Õ¥£¥ë¥¿¤Ê¤·
- define('SPAM_FILTER_CAPTCHA_COND', '');
- //// ³Æ¥Õ¥£¥ë¥¿¶¦Ä̤ÇÀßÄê¤Ç¤¤ë»ØÄê
- // URL¤Ç¤Î¥Þ¥Ã¥Á¤Ç¼«¥É¥á¥¤¥ó¤Ê¤É¤Î̵»ë¤¹¤Ù¤URL
- define('SPAM_FILTER_WHITEREG', '/example\.(com|net|jp)/i');
- // URL¤òÃê½Ð¤¹¤ëºÝ¤ÎÀµµ¬É½¸½
- define('SPAM_FILTER_URLREG', '/(?:(?:https?|ftp|news):\/\/)[\w\/\@\$()!?&%#:;.,~\'=*+-]+/i');
- //// urlnsbl ¤Ê¤É¤Ç»È¤¦¡¢NS¤Î¼èÆÀ¤ò¤¹¤ë dns_get_ns ¤ÎÀßÄê
- // NS¤ò°ú¤¤¤¿·ë²Ì¤ò¤¢¤ëÄøÅÙ¥¥ã¥Ã¥·¥å¤·¤Æ¤ª¤¯
- define('SPAM_FILTER_DNSGETNS_CACHE_FILE', 'dns_get_ns.cache');
- // ¥¥ã¥Ã¥·¥å¤·¤Æ¤ª¤¯Æü¿ô
- define('SPAM_FILTER_DNSGETNS_CACHE_DAY', 30);
- // nslookup ¥³¥Þ¥ó¥É¤Ø¤Î¥Ñ¥¹ - PHP4¤Î¾ì¹ç¤Ê¤É¤ÇɬÍפȤʤë¾ì¹ç¤¬¤¢¤ë
- define('SPAM_FILTER_NSLOOKUP_PATH', '/usr/bin/nslookup');
- //// ipcountry ¤Ê¤É¤Ç»È¤¦¡¢IP¤«¤é¹ñ¥³¡¼¥É¤ò¼èÆÀ¤¹¤ë get_country_code ¤ÎÀßÄê
- // IP¥¢¥É¥ì¥¹ÂӤȹñ¾ðÊó¤Î½ñ¤«¤ì¤¿¥Õ¥¡¥¤¥ë̾
- define('SPAM_FILTER_IPCOUNTRY_FILE', 'delegated-apnic-latest');
- //// ngreg - ÆâÍÆ¤ÎÀµµ¬É½¸½¥Õ¥£¥ë¥¿
- // ¥³¥á¥ó¥ÈÃæ¤Çµö²Ä¤·¤Ê¤¤ÆâÍÆ¤ÎÀµµ¬É½¸½
- define('SPAM_FILTER_NGREG_REG', '');
- define('SPAM_FILTER_NGREG_PLUGIN_NAME', 'edit,comment,pcomment,article,bugtrack');
- //// url - ÆâÍÆ¤ËURL¤Ã¤Ý¤¤¤â¤Î¤¬´Þ¤Þ¤ì¤Æ¤¤¤ë¤«¥Á¥§¥Ã¥¯
- define('SPAM_FILTER_URL_REG', '/https?:/i');
- define('SPAM_FILTER_URL_PLUGIN_NAME', 'edit,comment,pcomment,article,bugtrack');
- //// atag - ÆâÍÆ¤Ë</A>¤ä[/URL]¤Î¤è¤¦¤Ê¥¢¥ó¥«¡¼¥¿¥°¤¬´Þ¤Þ¤ì¤Æ¤¤¤ë¤«¥Á¥§¥Ã¥¯
- define('SPAM_FILTER_ATAG_REG', '/<\/a>|\[\/url\]/i');
- define('SPAM_FILTER_ATAG_PLUGIN_NAME', 'edit,comment,pcomment,article,bugtrack');
- //// onlyeng - ÆâÍÆ¤¬È¾³Ñ±Ñ¿ô¤Î¤ß(ÆüËܸ줬Æþ¤Ã¤Æ¤¤¤Ê¤¤)¤«¥Á¥§¥Ã¥¯
- define('SPAM_FILTER_ONLYENG_REG', '/\A[!-~\n ]+\Z/');
- define('SPAM_FILTER_ONLYENG_PLUGIN_NAME', 'edit,comment,pcomment,article,bugtrack');
- //// urlnum - ÆâÍÆ¤Ë´Þ¤Þ¤ì¤Æ¤¤¤ëURL¤¬²¿¸Ä°Ê¾å¤«¥Á¥§¥Ã¥¯
- define('SPAM_FILTER_URLNUM_NUM', '3');
- define('SPAM_FILTER_URLNUM_WHITEREG', SPAM_FILTER_WHITEREG);
- define('SPAM_FILTER_URLNUM_URLREG', SPAM_FILTER_URLREG);
- define('SPAM_FILTER_URLNUM_PLUGIN_NAME', 'edit,comment,pcomment,article,bugtrack');
- //// ipunknown - ¥¯¥é¥¤¥¢¥ó¥È¤ÎIP¤¬µÕ°ú¤¤Ç¤¤ë¤«¥Á¥§¥Ã¥¯
- define('SPAM_FILTER_IPUNKNOWN_PLUGIN_NAME', 'edit,comment,pcomment,article,attach,bugtrack');
- //// ips25r - ¥¯¥é¥¤¥¢¥ó¥È¤ÎIP¤¬Æ°ÅªIP¤Ã¤Ý¤¤(S25R¤Ë¥Þ¥Ã¥Á¤¹¤ë)¤«¥Á¥§¥Ã¥¯
- // S25R¤ÎÀµµ¬É½¸½
- 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$/');
- define('SPAM_FILTER_IPS25R_PLUGIN_NAME', 'tb');
- //// ipbl - ¥¯¥é¥¤¥¢¥ó¥È¤ÎIP¤ä¥Û¥¹¥È̾¤Ë¤è¤ë¥Õ¥£¥ë¥¿
- // µö²Ä¤·¤Ê¤¤IP¤ä¥Û¥¹¥È̾¤ÎÀµµ¬É½¸½
- define('SPAM_FILTER_IPBL_REG', '');
- define('SPAM_FILTER_IPBL_PLUGIN_NAME', 'edit,comment,pcomment,article,attach,bugtrack');
- // ¥Û¥¹¥È̾¤¬¸«¤Ä¤±¤é¤ì¤Ê¤«¤Ã¤¿¤È¤¤Ë¤âµñÈݤ¹¤ë¾ì¹ç TRUE
- define('SPAM_FILTER_IPBL_UNKNOWN', FALSE);
- //// ipdnsbl - ¥¯¥é¥¤¥¢¥ó¥È¤ÎIP¤òDNSBL¤Ç¥Á¥§¥Ã¥¯
- define('SPAM_FILTER_IPDNSBL_DNS', 'niku.2ch.net,bsb.spamlookup.net,bl.spamcop.net,all.rbl.jp');
- define('SPAM_FILTER_IPDNSBL_PLUGIN_NAME', 'edit,comment,pcomment,article,attach,bugtrack');
- //// ipcountry - ¥¯¥é¥¤¥¢¥ó¥È¤ÎIP¤Î¹ñ¤ò¥Á¥§¥Ã¥¯
- // ¥Þ¥Ã¥Á¤µ¤»¤ë¹ñ¤ò»ØÄꤹ¤ëÀµµ¬É½¸½
- define('SPAM_FILTER_IPCOUNTRY_REG', '/(CN|KR|UA)/');
- define('SPAM_FILTER_IPCOUNTRY_PLUGIN_NAME', 'edit,comment,pcomment,article,attach,bugtrack');
- //// uaunknown - HTTP_USER_AGENT¤¬´ûÃÎ(pukiwiki.ini.php¤Ç$agents¤Ç»ØÄê)¤«¥Á¥§¥Ã¥¯
- define('SPAM_FILTER_UAUNKNOWN_PLUGIN_NAME', 'edit,comment,pcomment,article,attach,bugtrack');
- //// useragent - HTTP_USER_AGENT¤Ë¤è¤ë¥Õ¥£¥ë¥¿
- // µö²Ä¤·¤Ê¤¤HTTP_USER_AGENT¤ÎÀµµ¬É½¸½
- define('SPAM_FILTER_USERAGENT_REG', '/WWW-Mechanize|libwww/i');
- define('SPAM_FILTER_USERAGENT_PLUGIN_NAME', 'edit,comment,pcomment,article,attach,bugtrack');
- //// acceptlanguage - HTTP_ACCEPT_LANGUAGE¤Ë¤è¤ë¥Õ¥£¥ë¥¿
- // µö²Ä¤·¤Ê¤¤HTTP_ACCEPT_LANGUAGE¤ÎÀµµ¬É½¸½
- define('SPAM_FILTER_ACCEPTLANGUAGE_REG', '/cn|ru/i');
- define('SPAM_FILTER_ACCEPTLANGUAGE_PLUGIN_NAME', 'edit,comment,pcomment,article,attach,bugtrack');
- //// filename - ¥¢¥Ã¥×¥í¡¼¥É¥Õ¥¡¥¤¥ë̾¤Ë¤è¤ë¥Õ¥£¥ë¥¿
- // ¥¢¥Ã¥×¥í¡¼¥É¤òµö²Ä¤·¤Ê¤¤¥Õ¥¡¥¤¥ë̾¤ÎÀµµ¬É½¸½
- define('SPAM_FILTER_FILENAME_REG', '/\.html$|\.htm$/i');
- define('SPAM_FILTER_FILENAME_PLUGIN_NAME', 'attach');
- //// formname - ¸ºß¤·¤Ê¤¤¤Ï¤º¤Î¥Õ¥©¡¼¥àÆâÍÆ¤¬¤¢¤ë¤«¥Á¥§¥Ã¥¯
- // ¸ºß¤·¤Ê¤¤¤Ï¤º¤Î¥Õ¥©¡¼¥à̾¤Î»ØÄê¡¢¥«¥ó¥Þ¶èÀÚ¤ê
- define('SPAM_FILTER_FORMNAME_NAME', 'url,email');
- define('SPAM_FILTER_FORMNAME_PLUGIN_NAME', 'edit,comment,pcomment,article,bugtrack');
- //// urlbl - URL¤¬¥Ö¥é¥Ã¥¯¥ê¥¹¥È¤ËÆþ¤Ã¤Æ¤¤¤ë¤«³Îǧ
- // URL¤Î¥Ö¥é¥Ã¥¯¥ê¥¹¥È ¥Û¥¹¥È̾¤Ç¤âIP¤Ç¤â²Ä
- // ¢¨wikiwiki.jp¤Î¥Ö¥é¥Ã¥¯¥ê¥¹¥È¤ò»²¹Í
- // ¢¨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
- 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');
- define('SPAM_FILTER_URLBL_WHITEREG', SPAM_FILTER_WHITEREG);
- define('SPAM_FILTER_URLBL_URLREG', SPAM_FILTER_URLREG);
- define('SPAM_FILTER_URLBL_PLUGIN_NAME', 'edit,comment,pcomment,article');
- // IP¤¬¸«¤Ä¤±¤é¤ì¤Ê¤«¤Ã¤¿¤È¤¤Ë¤âµñÈݤ¹¤ë¾ì¹ç TRUE
- define('SPAM_FILTER_URLBL_UNKNOWN', FALSE);
- //// urlcountry - URL¤Î¥µ¡¼¥Ð¤Î¤¢¤ë¹ñ¤ò¥Á¥§¥Ã¥¯
- // ¥Þ¥Ã¥Á¤µ¤»¤ë¹ñ¤ò»ØÄꤹ¤ëÀµµ¬É½¸½
- define('SPAM_FILTER_URLCOUNTRY_REG', '/(CN|KR|UA)/');
- define('SPAM_FILTER_URLCOUNTRY_WHITEREG', SPAM_FILTER_WHITEREG);
- define('SPAM_FILTER_URLCOUNTRY_URLREG', SPAM_FILTER_URLREG);
- define('SPAM_FILTER_URLCOUNTRY_PLUGIN_NAME', 'edit,comment,pcomment,article');
- //// urldnsbl - URL¤¬DNSBL¤ËÆþ¤Ã¤Æ¤¤¤ë¤«³Îǧ
- // DNSBL¤Î¥ê¥¹¥È
- define('SPAM_FILTER_URLDNSBL_DNS', 'url.rbl.jp,rbl.bulkfeeds.jp,multi.surbl.org,list.uribl.com,bsb.spamlookup.net');
- define('SPAM_FILTER_URLDNSBL_WHITEREG', SPAM_FILTER_WHITEREG);
- define('SPAM_FILTER_URLDNSBL_URLREG', SPAM_FILTER_URLREG);
- define('SPAM_FILTER_URLDNSBL_PLUGIN_NAME', 'edit,comment,pcomment,article');
- //// urlnsbl - URL¤ÎNS¤¬¥Ö¥é¥Ã¥¯¥ê¥¹¥È¤ËÆþ¤Ã¤Æ¤¤¤ë¤«³Îǧ
- // URL¤ÎNS¤Î¥Ö¥é¥Ã¥¯¥ê¥¹¥È ¥Û¥¹¥È̾¤Ç¤âIP¤Ç¤â²Ä
- // ¢¨wikiwiki.jp¤Î¥Ö¥é¥Ã¥¯¥ê¥¹¥È¤ò»²¹Í
- // ¢¨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
- 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');
- define('SPAM_FILTER_URLNSBL_WHITEREG', SPAM_FILTER_WHITEREG);
- define('SPAM_FILTER_URLNSBL_URLREG', SPAM_FILTER_URLREG);
- define('SPAM_FILTER_URLNSBL_PLUGIN_NAME', 'edit,comment,pcomment,article');
- // NS¤¬¸«¤Ä¤±¤é¤ì¤Ê¤«¤Ã¤¿¤È¤¤Ë¤âµñÈݤ¹¤ë¾ì¹ç TRUE
- define('SPAM_FILTER_URLNSBL_NSUNKNOWN', FALSE);
- //// urlnscountry - URL¤ÎNS¤Î¹ñ¤ò¥Á¥§¥Ã¥¯
- // ¥Þ¥Ã¥Á¤µ¤»¤ë¹ñ¤ò»ØÄꤹ¤ëÀµµ¬É½¸½
- define('SPAM_FILTER_URLNSCOUNTRY_REG', '/(CN|KR|UA)/');
- define('SPAM_FILTER_URLNSCOUNTRY_WHITEREG', SPAM_FILTER_WHITEREG);
- define('SPAM_FILTER_URLNSCOUNTRY_URLREG', SPAM_FILTER_URLREG);
- define('SPAM_FILTER_URLNSCOUNTRY_PLUGIN_NAME', 'edit,comment,pcomment,article');
- // NS¤¬¸«¤Ä¤±¤é¤ì¤Ê¤«¤Ã¤¿¤È¤¤Ë¤âµñÈݤ¹¤ë¾ì¹ç TRUE
- define('SPAM_FILTER_URLNSCOUNTRY_NSUNKNOWN', FALSE);
- //// akismet - Akismet ¤Ë¤è¤ë¥Õ¥£¥ë¥¿
- // ¥¹¥Ñ¥à¥Á¥§¥Ã¥¯»þ¤Ë¤Ï̵»ë¤¹¤ëPost¥Ç¡¼¥¿¡£¥«¥ó¥Þ¶èÀÚ¤ê
- define('SPAM_FILTER_AKISMET_IGNORE_KEY', 'digest');
- // Akismet¤Ç¼èÆÀ¤¹¤ë¡£API¥¡¼
- define('SPAM_FILTER_AKISMET_API_KEY', '');
- define('SPAM_FILTER_AKISMET_PLUGIN_NAME', 'edit,comment,tracker,article');
- //// reCAPTCHA ¤ÎÀßÄê
- define('SPAM_FILTER_RECAPTCHA_PUBLICKEY', '');
- define('SPAM_FILTER_RECAPTCHA_PRIVATEKEY', '');
- define('SPAM_FILTER_IS_WINDOWS', (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN'));
- //// ¥¹¥Ñ¥à¥Õ¥£¥ë¥¿ËÜÂÎ
- // plugin.php ¤«¤é¸Æ¤Ð¤ì¤ë
- function spam_filter($plugin)
- {
- $spamfilter = new SpamFilter($_POST, $plugin);
- // CAPTCHA¤Ç¤Îǧ¾Ú¤¬Ä̤äƤ¤¤ë¾ì¹ç¤½¤Î¤Þ¤ÞÄ̤¹
- if ($spamfilter->captcha_check()) return;
- // µñÈݾò·ï¤Ë¹ç¤Ã¤Æ¤¤¤ë¾ì¹ç¡¢CAPTCHA¤Ç¤Îǧ¾Ú¤¹¤é¤»¤º½ªÎ»
- if ($spamfilter->is_spam())
- die_message( "Spam check failed. Plugin:". $spamfilter->plugin_name ." Match:". $spamfilter->message ."<br>\n" );
- // CAPTCHA¤¹¤ë¾ò·ï¤Ë¹ç¤Ã¤Æ¤¤¤ë¾ì¹ç¡¢CAPTCHA¤Îɽ¼¨
- if ($spamfilter->is_spam(SPAM_FILTER_CAPTCHA_COND))
- $spamfilter->captcha_show();
- }
- //// ¥¹¥Ñ¥à¥Õ¥£¥ë¥¿¥¯¥é¥¹
- // ¥Õ¥£¥ë¥¿ÍѤÎû¤¤´Ø¿ô̾¤Ç̾Á°¶õ´Ö¤ò±ø¤µ¤Ê¤¤¤¿¤á¥¯¥é¥¹¤Ç¤Þ¤È¤á¤¿¤â¤Î
- class SpamFilter
- {
- // ³Æ¥¹¥Ñ¥à¥Õ¥£¥ë¥¿¤Ç»²¾È¤¹¤ë¥Ç¡¼¥¿
- var $post_data; // Åê¹Æ¤µ¤ì¤¿ÆâÍÆ
- var $plugin_name; // ¸Æ¤Ó½Ð¤µ¤ì¤¿¥×¥é¥°¥¤¥ó̾
- var $message; // ¥¨¥é¡¼½ÐÎÏÍѤ˥ޥåÁ¤·¤¿¾ò·ï¤Ê¤É¤òÄɵ¤·¤Æ¤¤¤¯
- var $dns_get_ns_cache; // dns_get_ns¤Î¥¥ã¥Ã¥·¥åÍÑ
- function SpamFilter($post, $plugin)
- {
- $this->post_data = $post;
- $this->plugin_name = $plugin;
- $this->message = '';
- }
- // SPAM_FILTER_COND ¤Ç»ØÄꤵ¤ì¤¿¥¹¥Ñ¥à¥Õ¥£¥ë¥¿¤ò³Ý¤±¤ë
- function is_spam($cond = SPAM_FILTER_COND)
- {
- // read ¤È¡¢edit ¤Ç preview ¤Î¤È¤¤Ï¥Á¥§¥Ã¥¯³Ý¤±¤Ê¤¤
- global $vars;
- if ($this->plugin_name == 'read' ||
- $this->plugin_name == 'edit' && isset($vars['preview'])) return FALSE;
- // bugtrack ¤Î»þ¤Ï summary ¤È body ¤ò msg ¤È¤·¤Æ¥Á¥§¥Ã¥¯¤¹¤ë
- if ($this->plugin_name == 'bugtrack')
- $this->post_data['msg'] = $this->post_data['summary'] . $this->post_data['body'];
- // ¥Õ¥£¥ë¥¿¾ò·ï¤Î»ØÄ꤬¤Ê¤±¤ì¤Ð¤½¤Î¤Þ¤ÞÊÖ¤ë
- if (preg_match('/^\s*$/', $cond)) return FALSE;
- // ¥Þ¥Ã¥Á¤·¤¿¾ò·ï¤ò½ñ¤½Ð¤¹¥Ð¥Ã¥Õ¥¡¤ò¥¯¥ê¥¢
- $this->message = '';
- // ¥Õ¥£¥ë¥¿¾ò·ï¤òÀ°·Á¤·¤Æ¤«¤é¥Á¥§¥Ã¥¯³Ý¤±¤ë
- $cond = preg_replace('/#/', '$this->', $cond);
- $cond = 'return('. $cond .');';
- return eval( $cond );
- }
- function check_plugin($pluginnames)
- {
- $plugin_names = explode(",", $pluginnames);
- return in_array($this->plugin_name, $plugin_names);
- }
- // ÆâÍÆ¤ÎÀµµ¬É½¸½¥Á¥§¥Ã¥¯
- function ngreg($reg = SPAM_FILTER_NGREG_REG,
- $pluginnames = SPAM_FILTER_NGREG_PLUGIN_NAME)
- {
- if (!$this->check_plugin($pluginnames)) return FALSE;
- if (preg_match($reg, $this->post_data['msg'])) {
- $this->message .= 'ngreg ';
- return TRUE;
- }
- return FALSE;
- }
- // ÆâÍÆ¤Î¤ËURL¤¬´Þ¤Þ¤ì¤Æ¤¤¤ë¤«¥Á¥§¥Ã¥¯
- function url($reg = SPAM_FILTER_URL_REG,
- $pluginnames = SPAM_FILTER_URL_PLUGIN_NAME)
- {
- if (!$this->check_plugin($pluginnames)) return FALSE;
- if (preg_match($reg, $this->post_data['msg'])) {
- $this->message .= 'url ';
- return TRUE;
- }
- return FALSE;
- }
- // ÆâÍÆ¤Ë</A>¤ä[/URL]¤Î¤è¤¦¤Ê¥¢¥ó¥«¡¼¥¿¥°¤¬´Þ¤Þ¤ì¤Æ¤¤¤ë¤«¥Á¥§¥Ã¥¯
- function atag($reg = SPAM_FILTER_ATAG_REG,
- $pluginnames = SPAM_FILTER_ATAG_PLUGIN_NAME)
- {
- if (!$this->check_plugin($pluginnames)) return FALSE;
- if (preg_match($reg, $this->post_data['msg'])) {
- $this->message .= 'atag ';
- return TRUE;
- }
- return FALSE;
- }
- // ÆâÍÆ¤¬È¾³Ñ±Ñ¿ô¤Î¤ß(ÆüËܸ줬Æþ¤Ã¤Æ¤¤¤Ê¤¤)¤«¥Á¥§¥Ã¥¯
- function onlyeng($reg = SPAM_FILTER_ONLYENG_REG,
- $pluginnames = SPAM_FILTER_ONLYENG_PLUGIN_NAME)
- {
- if (!$this->check_plugin($pluginnames)) return FALSE;
- if (preg_match($reg, $this->post_data['msg'])) {
- $this->message .= 'onlyeng ';
- return TRUE;
- }
- return FALSE;
- }
- // ÆâÍÆ¤Ë´Þ¤Þ¤ì¤Æ¤¤¤ëURL¤¬²¿¸Ä°Ê¾å¤«¥Á¥§¥Ã¥¯
- function urlnum($num = SPAM_FILTER_URLNUM_NUM,
- $whitereg = SPAM_FILTER_URLNUM_WHITEREG,
- $urlreg = SPAM_FILTER_URLNUM_URLREG,
- $pluginnames = SPAM_FILTER_URLNUM_PLUGIN_NAME)
- {
- // die_message("in urlnum plugin_name". $this->plugin_name);
- if (!$this->check_plugin($pluginnames)) return FALSE;
- // ÆâÍÆÃæ¤ÎURL¤òÃê½Ð
- preg_match_all($urlreg, $this->post_data['msg'], $urls);
- foreach ($urls[0] as $url) {
- // ¥Û¥¹¥È̾¤¬¥Û¥ï¥¤¥È¥ê¥¹¥È¤Ë¤¢¤ë¾ì¹ç¤Ï̵»ë¤·¤Æ¼¡¤ÎURL¤Î¥Á¥§¥Ã¥¯¤Ø
- if (preg_match($whitereg, $url)) continue;
- // ¥Û¥ï¥¤¥È¥ê¥¹¥È¤Ë¥Þ¥Ã¥Á¤·¤Ê¤«¤Ã¤¿¤È¤¤Ï¥«¥¦¥ó¥È¥¢¥Ã¥×
- $link_count ++;
- }
- if ($link_count >= $num) {
- $this->message .= 'urlnum ';
- return TRUE;
- }
- return FALSE;
- }
- // ¥¯¥é¥¤¥¢¥ó¥È¤ÎIP¤¬µÕ°ú¤¤Ç¤¤ë¤«¥Á¥§¥Ã¥¯
- function ipunknown($pluginnames = SPAM_FILTER_IPUNKNOWN_PLUGIN_NAME)
- {
- if (!$this->check_plugin($pluginnames)) return FALSE;
- // IP¤¬ÀßÄꤵ¤ì¤Æ¤¤¤Ê¤¤¾ì¹ç¤ÏÄ´¤Ù¤é¤ì¤Ê¤¤¤Î¤ÇÄ̤¹
- if (empty($_SERVER['REMOTE_ADDR'])) return FALSE;
- $hostname = gethostbyaddr($_SERVER['REMOTE_ADDR']);
- if (empty($hostname)) {
- $this->message .= 'ipunknown ';
- return TRUE;
- }
- return FALSE;
- }
- // ¥¯¥é¥¤¥¢¥ó¥È¤ÎIP¤¬Æ°ÅªIP¤Ã¤Ý¤¤(S25R¤Ë¥Þ¥Ã¥Á¤¹¤ë)¤«¥Á¥§¥Ã¥¯
- function ips25r($reg = SPAM_FILTER_IPS25R_REG,
- $pluginnames = SPAM_FILTER_IPS25R_PLUGIN_NAME)
- {
- if (!$this->check_plugin($pluginnames)) return FALSE;
- // IP¤¬ÀßÄꤵ¤ì¤Æ¤¤¤Ê¤¤¾ì¹ç¤ÏÄ´¤Ù¤é¤ì¤Ê¤¤¤Î¤ÇÄ̤¹
- if (empty($_SERVER['REMOTE_ADDR'])) return FALSE;
- $hostname = gethostbyaddr($_SERVER['REMOTE_ADDR']);
- if (empty($hostname) || preg_match($reg, $hostname)) {
- $this->message .= 'ips25r ';
- return TRUE;
- }
- return FALSE;
- }
- // ¥¯¥é¥¤¥¢¥ó¥È¤ÎIP¤Î¥Á¥§¥Ã¥¯
- function ipbl($reg = SPAM_FILTER_IPBL_REG,
- $pluginnames = SPAM_FILTER_IPBL_PLUGIN_NAME)
- {
- if (!$this->check_plugin($pluginnames)) return FALSE;
- // IP¤¬ÀßÄꤵ¤ì¤Æ¤¤¤Ê¤¤¾ì¹ç¤ÏÄ´¤Ù¤é¤ì¤Ê¤¤¤Î¤ÇÄ̤¹
- if (empty($_SERVER['REMOTE_ADDR'])) return FALSE;
- $hostname = gethostbyaddr($_SERVER['REMOTE_ADDR']);
- if (preg_match($reg, $_SERVER['REMOTE_ADDR']) ||
- preg_match($reg, $hostname)) {
- $this->message .= 'ipbl ';
- return TRUE;
- }
- if (SPAM_FILTER_IPBL_UNKNOWN && empty($hostname)) {
- $this->message .= 'ipbl(unknown) ';
- return TRUE;
- }
- return FALSE;
- }
- // ¥¯¥é¥¤¥¢¥ó¥È¤ÎIP¤òDNSBL¤Ç¥Á¥§¥Ã¥¯
- function ipdnsbl($dnss = SPAM_FILTER_IPDNSBL_DNS,
- $pluginnames = SPAM_FILTER_IPDNSBL_PLUGIN_NAME)
- {
- if (!$this->check_plugin($pluginnames)) return FALSE;
- // IP¤¬ÀßÄꤵ¤ì¤Æ¤¤¤Ê¤¤¾ì¹ç¤ÏÄ´¤Ù¤é¤ì¤Ê¤¤¤Î¤ÇÄ̤¹
- if (empty($_SERVER['REMOTE_ADDR'])) return FALSE;
- $dns_hosts = explode(",", $dnss);
- $ip = $_SERVER['REMOTE_ADDR'];
- $revip = implode('.', array_reverse(explode('.', $ip)));
- foreach ($dns_hosts as $dns) {
- $lookup = $revip . '.' . $dns;
- $result = gethostbyname($lookup);
- if ($result != $lookup) {
- $this->message .= 'ipdnsbl ';
- return TRUE;
- }
- }
- return FALSE;
- }
- // ¥¯¥é¥¤¥¢¥ó¥È¤ÎIP¤Î¹ñ¤ò¥Á¥§¥Ã¥¯
- function ipcountry($reg = SPAM_FILTER_IPCOUNTRY_REG,
- $pluginnames = SPAM_FILTER_IPCOUNTRY_PLUGIN_NAME)
- {
- if (!$this->check_plugin($pluginnames)) return FALSE;
- // IP¤¬ÀßÄꤵ¤ì¤Æ¤¤¤Ê¤¤¾ì¹ç¤ÏÄ´¤Ù¤é¤ì¤Ê¤¤¤Î¤ÇÄ̤¹
- if (empty($_SERVER['REMOTE_ADDR'])) return FALSE;
- $country = $this->get_country_code( $_SERVER['REMOTE_ADDR'] );
- if (preg_match($reg, $country)) {
- $this->message .= 'ipcountry ';
- return TRUE;
- }
- return FALSE;
- }
- // HTTP_USER_AGENT¤¬´ûÃÎ(pukiwiki.ini.php¤Ç$agents¤Ç»ØÄê)¤«¥Á¥§¥Ã¥¯
- function uaunknown($pluginnames = SPAM_FILTER_UAUNKNOWN_PLUGIN_NAME)
- {
- global $agents;
- if (!$this->check_plugin($pluginnames)) return FALSE;
- // UserAgentÃͤ¬ÀßÄꤵ¤ì¤Æ¤¤¤Ê¤¤¾ì¹ç¤ÏµñÈÝ
- if (empty($_SERVER['HTTP_USER_AGENT'])) {
- $this->message .= 'uaunknown(empty) ';
- return TRUE;
- }
- // $agents¤ÎºÇ¸å¤Ë¤¢¤ëdefault¾ò·ï°Ê³°¤È¥Þ¥Ã¥Á¤µ¤»¤ë
- $agents_temp = $agents;
- array_pop( $agents_temp );
- foreach ($agents_temp as $agent) {
- // ¤É¤ì¤«¤ÎUA¤È¥Þ¥Ã¥Á¤·¤¿¤éÌäÂê¤Ê¤·
- if (preg_match($agent['pattern'], $_SERVER['HTTP_USER_AGENT'])) return FALSE;
- }
- // ¤É¤ÎUA¤È¤â¥Þ¥Ã¥Á¤·¤Ê¤«¤Ã¤¿
- $this->message .= 'uaunknown ';
- return TRUE;
- }
- // HTTP_USER_AGENT¤Î¥Á¥§¥Ã¥¯
- // ¢¨»ÈÍÑ¤Ë¤Ï HTTP_USER_AGENT ¤ò¾Ã¤µ¤Ê¤¤¤è¤¦ init.php ¤Ø¥Ñ¥Ã¥Á¤ÎɬÍפ¢¤ê
- function useragent($reg = SPAM_FILTER_USERAGENT_REG,
- $pluginnames = SPAM_FILTER_USERAGENT_PLUGIN_NAME)
- {
- if (!$this->check_plugin($pluginnames)) return FALSE;
- // UserAgentÃͤ¬ÀßÄꤵ¤ì¤Æ¤¤¤Ê¤¤¾ì¹ç¤ÏµñÈÝ
- if (empty($_SERVER['HTTP_USER_AGENT'])) {
- $this->message .= 'uaunknown(empty) ';
- return TRUE;
- }
- if (preg_match($reg, $_SERVER['HTTP_USER_AGENT'])) {
- $this->message .= 'useragent ';
- return TRUE;
- }
- return FALSE;
- }
- // HTTP_ACCEPT_LANGUAGE¤Î¥Á¥§¥Ã¥¯
- function acceptlanguage($reg = SPAM_FILTER_ACCEPTLANGUAGE_REG,
- $pluginnames = SPAM_FILTER_ACCEPTLANGUAGE_PLUGIN_NAME)
- {
- if (!$this->check_plugin($pluginnames)) return FALSE;
- // AcceptLanguageÃͤ¬ÀßÄꤵ¤ì¤Æ¤¤¤Ê¤¤¾ì¹ç¤ÏµñÈÝ
- if (empty($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
- $this->message .= 'alunknown(empty) ';
- return TRUE;
- }
- if (preg_match($reg, $_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
- $this->message .= 'acceptlanguage ';
- return TRUE;
- }
- return FALSE;
- }
- // ¥¢¥Ã¥×¥í¡¼¥É¥Õ¥¡¥¤¥ë̾¤Ë¤è¤ë¥Õ¥£¥ë¥¿
- function filename($reg = SPAM_FILTER_FILENAME_REG,
- $pluginnames = SPAM_FILTER_FILENAME_PLUGIN_NAME)
- {
- if (!$this->check_plugin($pluginnames)) return FALSE;
- if (isset($_FILES['attach_file'])) {
- $file = $_FILES['attach_file'];
- if (preg_match($reg, $file['name'])) {
- $this->message .= 'filename ';
- return TRUE;
- }
- }
- return FALSE;
- }
- // ¸ºß¤·¤Ê¤¤¤Ï¤º¤Î¥Õ¥©¡¼¥àÆâÍÆ¤¬¤¢¤ë¤«¥Á¥§¥Ã¥¯
- function formname($formnames = SPAM_FILTER_FORMNAME_NAME,
- $pluginnames = SPAM_FILTER_FORMNAME_PLUGIN_NAME)
- {
- if (!$this->check_plugin($pluginnames)) return FALSE;
- // »ØÄꤵ¤ì¤¿Ì¾Á°¤Î¥Õ¥©¡¼¥à¤ÎÆâÍÆ¤¬¤Ê¤Ë¤«¤¢¤ë¤«³Îǧ
- $form_names = explode(",", $formnames);
- foreach ($form_names as $name) {
- if (!empty($this->post_data["$name"])) {
- $this->message .= 'formname ';
- return TRUE;
- }
- }
- return FALSE;
- }
- // URL¤¬¥Ö¥é¥Ã¥¯¥ê¥¹¥È¤ËÆþ¤Ã¤Æ¤¤¤ë¤«³Îǧ
- function urlbl($reg = SPAM_FILTER_URLBL_REG,
- $whitereg = SPAM_FILTER_URLBL_WHITEREG,
- $urlreg = SPAM_FILTER_URLBL_URLREG,
- $pluginnames = SPAM_FILTER_URLBL_PLUGIN_NAME)
- {
- if (!$this->check_plugin($pluginnames)) return FALSE;
- // ÆâÍÆÃæ¤ÎURL¤òÃê½Ð
- preg_match_all($urlreg, $this->post_data['msg'], $urls);
- foreach ($urls[0] as $url) {
- // URL¤Î¥Û¥¹¥È̾¤«¤é¥É¥á¥¤¥ó¤òÆÀ¤ë
- $url_array = parse_url($url);
- $hostname = $url_array['host'];
- // ¥Û¥¹¥È̾¤¬¥Û¥ï¥¤¥È¥ê¥¹¥È¤Ë¤¢¤ë¾ì¹ç¤Ï̵»ë¤·¤Æ¼¡¤ÎURL¤Î¥Á¥§¥Ã¥¯¤Ø
- if (preg_match($whitereg, $hostname)) continue;
- // ¥Û¥¹¥È̾¤ò¥Ö¥é¥Ã¥¯¥ê¥¹¥È¤È¾È¤é¤·¹ç¤ï¤»
- if (preg_match($reg, $hostname)) {
- $this->message .= 'urlbl(name) ';
- return TRUE;
- }
- // ¥Û¥¹¥È̾¤ÎIP¤ò¥Ö¥é¥Ã¥¯¥ê¥¹¥È¤È¾È¤é¤·¹ç¤ï¤»
- if ($iplist = gethostbynamel($hostname)) {
- foreach ($iplist as $ip) {
- if (preg_match($reg, $ip)) {
- $this->message .= 'urlbl(ip) ';
- return TRUE;
- }
- }
- }
- else {
- // IP¤¬¸«¤Ä¤±¤é¤ì¤Ê¤«¤Ã¤¿¤È¤¤Ë¤âµñÈݤ¹¤ë¾ì¹ç
- if (SPAM_FILTER_URLBL_UNKNOWN) {
- $this->message .= 'urlbl(unknown) ';
- return TRUE;
- }
- }
- }
- return FALSE;
- }
- // URL¤Î¥µ¡¼¥Ð¤Î¤¢¤ë¹ñ¤ò¥Á¥§¥Ã¥¯
- function urlcountry($reg = SPAM_FILTER_URLCOUNTRY_REG,
- $whitereg = SPAM_FILTER_URLCOUNTRY_WHITEREG,
- $urlreg = SPAM_FILTER_URLCOUNTRY_URLREG,
- $pluginnames = SPAM_FILTER_URLCOUNTRY_PLUGIN_NAME)
- {
- if (!$this->check_plugin($pluginnames)) return FALSE;
- // ÆâÍÆÃæ¤ÎURL¤òÃê½Ð
- preg_match_all($urlreg, $this->post_data['msg'], $urls);
- foreach ($urls[0] as $url) {
- // URL¤Î¥Û¥¹¥È̾¤òÆÀ¤ë
- $url_array = parse_url($url);
- $hostname = $url_array['host'];
- // ¥Û¥¹¥È̾¤¬¥Û¥ï¥¤¥È¥ê¥¹¥È¤Ë¤¢¤ë¾ì¹ç¤Ï̵»ë¤·¤Æ¼¡¤ÎURL¤Î¥Á¥§¥Ã¥¯¤Ø
- if (preg_match($whitereg, $hostname)) continue;
- // ¥Û¥¹¥È̾¤ÎIP¤ò¥Ö¥é¥Ã¥¯¥ê¥¹¥È¤È¾È¤é¤·¹ç¤ï¤»
- if ($iplist = gethostbynamel($hostname)) {
- foreach ($iplist as $ip) {
- $country = $this->get_country_code( $ip );
- //$tmpmes .= $hostname . ' ' . $ip . ' ' . $country . ', ';
- if (preg_match($reg, $country)) {
- $this->message .= 'urlcountry ';
- return TRUE;
- }
- }
- }
- else {
- // IP¤¬¸«¤Ä¤±¤é¤ì¤Ê¤«¤Ã¤¿¤È¤¤Ë¤âµñÈݤ¹¤ë¾ì¹ç
- if (SPAM_FILTER_URLCOUNTRY_UNKNOWN) {
- $this->message .= 'urlcountry(unknown) ';
- return TRUE;
- }
- }
- }
- // die_message( "mes: $tmpmes" );
- return FALSE;
- }
- // URL¤¬DNSBL¤ËÆþ¤Ã¤Æ¤¤¤ë¤«³Îǧ
- function urldnsbl($dnss = SPAM_FILTER_URLDNSBL_DNS,
- $whitereg = SPAM_FILTER_URLDNSBL_WHITEREG,
- $urlreg = SPAM_FILTER_URLDNSBL_URLREG,
- $pluginnames = SPAM_FILTER_URLDNSBL_PLUGIN_NAME)
- {
- if (!$this->check_plugin($pluginnames)) return FALSE;
- $dns_hosts = explode(",", $dnss);
- // ÆâÍÆÃæ¤ÎURL¤òÃê½Ð
- preg_match_all($urlreg, $this->post_data['msg'], $urls);
- foreach ($urls[0] as $url) {
- // ¥Û¥¹¥È̾¤¬¥Û¥ï¥¤¥È¥ê¥¹¥È¤Ë¤¢¤ë¾ì¹ç¤Ï̵»ë¤·¤Æ¼¡¤ÎURL¤Î¥Á¥§¥Ã¥¯¤Ø
- if (preg_match($whitereg, $url)) continue;
- // URL¤Î¥Û¥¹¥È̾¤«¤é¥É¥á¥¤¥ó¤òÆÀ¤ë
- $url_array = parse_url($url);
- $hostname = $url_array['host'];
- // ¤É¤³¤«¤ÎDNSBL¤ËÅÐÏ¿¤µ¤ì¤Æ¤¿¤é
- foreach ($dns_hosts as $dns) {
- $lookup = $hostname . '.' . $dns;
- $result = gethostbyname($lookup);
- if ($result != $lookup) {
- $this->message .= 'urldnsbl ';
- return TRUE;
- }
- }
- }
- return FALSE;
- }
- // URL¤ÎNS¤¬¥Ö¥é¥Ã¥¯¥ê¥¹¥È¤ËÆþ¤Ã¤Æ¤¤¤ë¤«³Îǧ
- function urlnsbl($reg = SPAM_FILTER_URLNSBL_REG,
- $whitereg = SPAM_FILTER_URLNSBL_WHITEREG,
- $urlreg = SPAM_FILTER_URLNSBL_URLREG,
- $pluginnames = SPAM_FILTER_URLNSBL_PLUGIN_NAME)
- {
- if (!$this->check_plugin($pluginnames)) return FALSE;
- // ÆâÍÆÃæ¤ÎURL¤òÃê½Ð
- preg_match_all($urlreg, $this->post_data['msg'], $urls);
- foreach ($urls[0] as $url) {
- // URL¤Î¥Û¥¹¥È̾¤òÆÀ¤ë
- $url_array = parse_url($url);
- $hostname = $url_array['host'];
- // ¥Û¥¹¥È̾¤¬¥Û¥ï¥¤¥È¥ê¥¹¥È¤Ë¤¢¤ë¾ì¹ç¤Ï̵»ë¤·¤Æ¼¡¤ÎURL¤Î¥Á¥§¥Ã¥¯¤Ø
- if (preg_match($whitereg, $hostname)) continue;
- // ¥É¥á¥¤¥ó¤ÎNS¤òÆÀ¤ë
- if ($this->dns_get_ns($hostname, $nslist)) {
- // ¥É¥á¥¤¥ó¤ÎNS¤¬ÆÀ¤é¤ì¤¿¤éNS¥Ö¥é¥Ã¥¯¥ê¥¹¥È¤È¾È¤é¤·¹ç¤ï¤»
- foreach ($nslist as $ns) {
- if (preg_match($reg, $ns)) {
- $this->message .= 'urlnsbl(name) ';
- return TRUE;
- }
- // NS¤ÎIP¤ò¥Ö¥é¥Ã¥¯¥ê¥¹¥È¤È¾È¤é¤·¹ç¤ï¤»
- if ($iplist = gethostbynamel($ns)) {
- foreach ($iplist as $ip) {
- if (preg_match($reg, $ip)) {
- $this->message .= 'urlnsbl(ip) ';
- return TRUE;
- }
- }
- }
- }
- }
- else {
- // NS¤¬ÆÀ¤é¤ì¤Ê¤«¤Ã¤¿
- if (SPAM_FILTER_URLNSBL_NSUNKNOWN) {
- $this->message .= 'urlnsbl(unknown) ';
- return TRUE;
- }
- }
- }
- return FALSE;
- }
- // URL¤ÎNS¤Î¹ñ¤ò¥Á¥§¥Ã¥¯
- function urlnscountry($reg = SPAM_FILTER_URLNSCOUNTRY_REG,
- $whitereg = SPAM_FILTER_URLNSCOUNTRY_WHITEREG,
- $urlreg = SPAM_FILTER_URLNSCOUNTRY_URLREG,
- $pluginnames = SPAM_FILTER_URLNSCOUNTRY_PLUGIN_NAME)
- {
- if (!$this->check_plugin($pluginnames)) return FALSE;
- // ÆâÍÆÃæ¤ÎURL¤òÃê½Ð
- preg_match_all($urlreg, $this->post_data['msg'], $urls);
- foreach ($urls[0] as $url) {
- // URL¤Î¥Û¥¹¥È̾¤òÆÀ¤ë
- $url_array = parse_url($url);
- $hostname = $url_array['host'];
- // ¥Û¥¹¥È̾¤¬¥Û¥ï¥¤¥È¥ê¥¹¥È¤Ë¤¢¤ë¾ì¹ç¤Ï̵»ë¤·¤Æ¼¡¤ÎURL¤Î¥Á¥§¥Ã¥¯¤Ø
- if (preg_match($whitereg, $hostname)) continue;
- // ¥É¥á¥¤¥ó¤ÎNS¤òÆÀ¤ë
- if ($this->dns_get_ns($hostname, $nslist)) {
- // ¥É¥á¥¤¥ó¤ÎNS¤¬ÆÀ¤é¤ì¤¿¤é¤½¤Î¹ñ¤òÄ´¤Ù¤Æ¡¢¹ñ¥³¡¼¥É¤È¾È¤é¤·¹ç¤ï¤»
- foreach ($nslist as $ns) {
- $country = $this->get_country_code( gethostbyname($ns) );
- if (preg_match($reg, $country)) {
- $this->message .= 'urlnscountry ';
- return TRUE;
- }
- }
- }
- else {
- // NS¤¬ÆÀ¤é¤ì¤Ê¤«¤Ã¤¿
- if (SPAM_FILTER_URLNSBL_NSUNKNOWN) {
- $this->message .= 'urlnscountry(unknown) ';
- return TRUE;
- }
- }
- }
- return FALSE;
- }
- // Akismet ¤Ë¤è¤ë¥Á¥§¥Ã¥¯
- function akismet($pluginnames = SPAM_FILTER_AKISMET_PLUGIN_NAME)
- {
- // ¢¨º£¸åhttp://note.sonots.com/?PukiWiki%2Fakismet.inc.php»²¹Í¤Ë½¤Àµ¤¹¤ë
- if (!$this->check_plugin($pluginnames)) return FALSE;
- // akismet¥¯¥é¥¹¤ÎÆÉ¤ß¹þ¤ß
- require_once 'akismet.class.php';
- // Post¥Ç¡¼¥¿¤òÏ¢·ë¤¹¤ë¡£
- $ignore_post_keys = explode(",", SPAM_FILTER_AKISMET_IGNORE_KEY);
- foreach ($this->post_data as $key => $val) {
- // ignore_post_keys¤ËÀßÄꤵ¤ì¤Æ¤¤¤ëPost¥Ç¡¼¥¿¤ÏAkismet¤ËÁ÷¤é¤Ê¤¤
- if (!in_array($key, $ignore_post_keys)) {
- $body = $body . $val;
- }
- }
- // Akismet¤ËÁ÷¿®¤¹¤ë¥Ç¡¼¥¿¤òºîÀ®¤¹¤ë
- $comment = array();
- $comment['author'] = '';
- $comment['email'] = '';
- $comment['website'] = '';
- $comment['permalink'] = '';
- $comment['body'] = $body;
- $akismet = new Akismet(URL, SPAM_FILTER_AKISMET_API_KEY, $comment);
- if ($akismet->isSpam() == '1') {
- $this->message .= 'akismet ';
- return TRUE;
- }
- return FALSE;
- }
- // CAPTCHA¤Ç¤ÎÆþÎϤ¬¹ç¤Ã¤Æ¤¤¤ë¤«¥Á¥§¥Ã¥¯
- function captcha_check()
- {
- // reCAPTCHA ¤Ç¤Î¥Á¥§¥Ã¥¯
- if ($_POST["recaptcha_response_field"]) {
- $resp = recaptcha_check_answer (SPAM_FILTER_RECAPTCHA_PRIVATEKEY,
- $_SERVER["REMOTE_ADDR"],
- $_POST["recaptcha_challenge_field"],
- $_POST["recaptcha_response_field"]);
- if ($resp->is_valid) return TRUE;
- }
- return FALSE;
- }
- // CAPTCHA¤Ç¤ÎÆþÎϤòµá¤á¤ë
- function captcha_show()
- {
- // reCAPTCHA ¤Ç¤ÎCAPTCHA¤Îɽ¼¨
- global $vars;
- $page = $vars['page'];
- $form .= "<form action='' method='post'>\n";
- $form .= "²¼¤ÎÆó¤Ä¤Îñ¸ì¤òÆþÎϤ·¤Æ¤¯¤À¤µ¤¤¡£\n";
- $form .= recaptcha_get_html(SPAM_FILTER_RECAPTCHA_PUBLICKEY);
- foreach ($_POST as $key => $val) {
- if ($key == 'recaptcha_response_field' or
- $key == 'recaptcha_challenge_field') continue;
- $form .= ' <input type="hidden" name="' . $key . '" value="' . htmlspecialchars($val) . '" />' . "\n";
- }
- $form .= ' <input type="hidden" name="page" value="' . htmlspecialchars($page) . '" />' . "\n";
- $form .= ' <input type="submit" name="" value="ǧ¾Ú" /><br />' . "\n";
- $form .= '</form>' . "\n";
- die_message( "Spam check failed. Plugin:". $this->plugin_name ." Match:". $this->message ."<br>\n". $form );
- }
- // get DNS server for Windows XP SP2, Vista SP1
- function getDNSServer()
- {
- @exec('ipconfig /all', $ipconfig);
- //print_a($ipconfig, 'label:nameserver');
- foreach ($ipconfig as $line) {
- if (preg_match('/\s*DNS .+:\s+([\d\.]+)$/', $line, $nameservers)) {
- $nameserver = $nameservers[1];
- }
- }
- if (empty($nameserver)) {
- die_message('Can not lookup your DNS server');
- }
- //print_a($nameserver, 'label:nameserver');
- return $nameserver;
- }
-
- //// ¥Û¥¹¥È̾¤«¤éNS¤ò°ú¤¯¤¿¤á¤ÎÈÆÍÑ´Ø¿ô
- // hostname¤Î¥É¥á¥¤¥ó¤ÎNS¤ò¥ê¥¹¥È($ns_array)¤ËÊÖ¤¹
- // ÆÀ¤é¤ì¤Ê¤«¤Ã¤¿¾ì¹ç¤Ï´Ø¿ô¤ÎÊÖ¤êÃͤ¬FALSE
- // ¢¨PHP4¤Î¾ì¹ç¡¢nslookup ¥³¥Þ¥ó¥É¤¬»È¤¨¤ëɬÍפ¢¤ê
- function dns_get_ns( $hostname, &$ns_array )
- {
- // Åú¤¨¤òÊÖ¤¹¤È¤³¤í¤ò¥¯¥ê¥¢¤·¤Æ¤ª¤¯
- if (!empty($ns_array)) while (array_pop($ns_array));
- // ¤Þ¤À¥¥ã¥Ã¥·¥å¤¬¤Ê¤±¤ì¤Ð°ÊÁ°¤ËÆÀ¤¿·ë²Ì¤Î¥¥ã¥Ã¥·¥å¥Õ¥¡¥¤¥ë¤òÆÉ¤ß¹þ¤à
- if (empty($this->dns_get_ns_cache)) {
- $fp = fopen(DATA_HOME . SPAM_FILTER_DNSGETNS_CACHE_FILE, "a+")
- or die_message('Cannot read dns_get_ns cache file: '. SPAM_FILTER_DNSGETNS_CACHE_FILE ."\n");
- flock($fp, LOCK_SH);
- while ($csv = fgetcsv($fp, 1000, ",")) {
- $host = array_shift($csv);
- $time = $csv[0];
- if ($time + SPAM_FILTER_DNSGETNS_CACHE_DAY*24*60*60 < time())
- continue; // ¸Å¤¹¤®¤ë¾ðÊó¤Ï¼Î¤Æ¤ë
- $this->dns_get_ns_cache["$host"] = $csv;
- }
- flock($fp, LOCK_UN);
- fclose($fp);
- }
- // ¥¥ã¥Ã¥·¥å¤Î·ë²Ì¤ËÆþ¤Ã¤Æ¤ë¤Ê¤é¤½¤³¤«¤é·ë²Ì¤ò°ú¤¤¤ÆÊÖ¤¹
- $cache = $this->dns_get_ns_cache["$hostname"];
- if(!empty($cache)) {
- $time = array_shift($cache);
- foreach($cache as $ns) {
- $ns_array[] = $ns;
- }
- return TRUE;
- }
- // ¥Û¥¹¥È̾¤ò¾å¤«¤é°ì¤Ä¤Å¤Ä¸º¤é¤·¤ÆNS¤¬ÆÀ¤é¤ì¤ë¤Þ¤Ç»î¤¹
- // Îã: www.subdomain.example.com¢ªsubdomain.example.com¢ªexample.com
- $domain_array = explode(".", $hostname);
- $ns_found = FALSE;
- do {
- $domain = implode(".", $domain_array);
- // ´Ä¶¤Ç»È¤¨¤ë¼êÃʤ˹ç¤ï¤»¤Æ¥É¥á¥¤¥ó¤ÎNS¤òÆÀ¤ë
- if (function_exists('dns_get_record')) {
- // ÆâÉô´Ø¿ô dns_get_record »È¤¨¤ë¾ì¹ç
- $lookup = dns_get_record($domain, DNS_NS);
- if (!empty($lookup)) {
- foreach ($lookup as $record) {
- $ns_array[] = $record['target'];
- }
- $ns_found = TRUE;
- }
- }
- else if (include_once('Net/DNS.php')) {
- // PEAR¤ÎDNS¥¯¥é¥¹¤¬»È¤¨¤ë¾ì¹ç
- $resolver = new Net_DNS_Resolver();
- if (SPAM_FILTER_IS_WINDOWS) $resolver->nameservers[0] = $this->getDNSServer();
- $response = $resolver->query($domain, 'NS');
- if ($response) {
- foreach ($response->answer as $rr) {
- if ($rr->type == "NS") {
- $ns_array[] = $rr->nsdname;
- }
- else if ($rr->type == "CNAME") {
- // CNAME¤µ¤ì¤Æ¤ë¤È¤¤Ï¡¢¤½¤Ã¤Á¤òºÆµ¢¤Ç°ú¤¯
- $this->dns_get_ns($rr->rdatastr(), $ns_array);
- }
- }
- $ns_found = TRUE;
- }
- }
- else {
- // PEAR¤â»È¤¨¤Ê¤¤¾ì¹ç¡¢³°Éô¥³¥Þ¥ó¥Énslookup¤Ë¤è¤êNS¤ò¼èÆÀ
- is_executable(SPAM_FILTER_NSLOOKUP_PATH)
- or die_message("Cannot execute nslookup. see NSLOOKUP_PATH setting.\n");
- @exec(SPAM_FILTER_NSLOOKUP_PATH . " -type=ns " . $domain, $lookup);
- foreach ($lookup as $line) {
- if( preg_match('/\s*nameserver\s*=\s*(\S+)$/', $line, $ns) ||
- preg_match('/\s*origin\s*=\s*(\S+)$/', $line, $ns) ||
- preg_match('/\s*primary name server\s*=\s*(\S+)$/', $line, $ns) ) {
- $ns_array[] = $ns[1];
- $ns_found = TRUE;
- }
- }
- }
- } while (!$ns_found && array_shift($domain_array) != NULL);
- // NS¤¬°ú¤±¤Æ¤¤¤¿¤é¡¢·ë²Ì¤ò¥¥ã¥Ã¥·¥å¤ËÆþ¤ì¤ÆÊݸ
- if ($ns_found) {
- // ·ë²Ì¤ò¥¥ã¥Ã¥·¥å¤ËÅÐÏ¿
- $cache = $ns_array;
- array_unshift($cache, time()); // °ú¤¤¤¿»þ´Ö¤âÊÝ»ý
- $this->dns_get_ns_cache["$hostname"] = $cache;
- // ¥¥ã¥Ã¥·¥å¤ò¥Õ¥¡¥¤¥ë¤ËÊݸ
- $fp = fopen(DATA_HOME . SPAM_FILTER_DNSGETNS_CACHE_FILE, "w")
- or die_message("Cannot write dns_get_ns cache file: ". SPAM_FILTER_DNSGETNS_CACHE_FILE ."\n");
- flock($fp, LOCK_EX);
- foreach ($this->dns_get_ns_cache as $host=>$cachedata) {
- $csv = $host;
- foreach ($cachedata as $data) {
- $csv .= ",". $data;
- }
- $csv .= "\n";
- fputs($fp, $csv);
- }
- flock($fp, LOCK_UN);
- fclose($fp);
- }
- return $ns_found;
- }
- //// IP¥¢¥É¥ì¥¹¤«¤é¹ñ¥³¡¼¥É¤ò°ú¤¯¤¿¤á¤ÎÈÆÍÑ´Ø¿ô
- // IP¥¢¥É¥ì¥¹("10.1.2.3"¤ß¤¿¤¤¤Êʸ»úÎó)¤«¤éJP¤È¤«¤Î¹ñ¥³¡¼¥É¤òÊÖ¤¹
- // ÆÀ¤é¤ì¤Ê¤«¤Ã¤¿¾ì¹ç¤Ïempty('')¤òÊÖ¤¹
- // ¢¨APNIC¤ÎIP¥¨¥ê¥¢¤È¹ñ¤ÎÂбþ¥³¡¼¥É¥Õ¥¡¥¤¥ë¤¬É¬Í×
- // ¢¨¥¢¥á¥ê¥«¤ÎIP¤Ï¥ê¥¹¥È¤Ë̵¤¤¡©
- function get_country_code( $ip_string )
- {
- // ¤Þ¤À¹ñIP¥ê¥¹¥È¤òÆÉ¤ó¤Ç¤Ê¤±¤ì¤Ð¥Õ¥¡¥¤¥ë¤òÆÉ¤ß¹þ¤ó¤Ç¥¥ã¥Ã¥·¥å¤¹¤ë
- if (empty($this->get_country_code_cache)) {
- $fp = fopen( DATA_HOME . SPAM_FILTER_IPCOUNTRY_FILE, "r")
- or die_message('Cannot read country file: ' . SPAM_FILTER_IPCOUNTRY_FILE . "\n");
- while ($csv = fgetcsv($fp, 1000, "|")) {
- // IPv4¤À¤±Âбþ
- if ($csv[2] === "ipv4") {
- $country = $csv[1];
- $ipstring = $csv[3];
- $ipranges = explode(".", $ipstring);
- $iprange = ip2long($ipstring);
- $mask = 256*256*256*256 - $csv[4];
- $data = new country_data;
- $data->country = $country;
- $data->iprange = $iprange;
- $data->mask = $mask;
- // Class A¤ò¤Þ¤¿¤°»ØÄê¤Ï̵¤¤¤Î¤Ç¥È¥Ã¥×¤Î256¤Çʬ³ä¤·¤ÆÊÝ»ý
- $this->get_country_code_cache["$ipranges[0]"][] = $data;
- }
- }
- fclose($fp);
- }
- $ip = ip2long($ip_string);
- $ranges = explode(".", $ip_string);
- $country_code = '';
- foreach ($this->get_country_code_cache["$ranges[0]"] as $data) {
- if ( $data->iprange == ($ip & $data->mask) ) {
- $country_code = $data->country;
- break;
- }
- }
- return $country_code;
- }
- }
- // get_country_code ¤ÇÊÝ»ý¤·¤Æ¤¤¤ë¥Ç¡¼¥¿¹½Â¤
- class country_data
- {
- var $country;
- var $iprange;
- var $mask;
- }
- ?>