cache_antitheft.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. /**
  3. * [Discuz!] (C)2001-2099 Comsenz Inc.
  4. * This is NOT a freeware, use is subject to license terms
  5. *
  6. * $Id: cache_antitheft.php 32740 2013-03-05 08:32:47Z zhangguosheng $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. function build_cache_antitheft() {
  12. $antitheft = array();
  13. $antitheftsetting = C::t('common_setting')->fetch('antitheftsetting', true);
  14. foreach($antitheftsetting as $key => $_ips) {
  15. $antitheft[$key] = array();
  16. $_ips = explode("\n", $_ips);
  17. foreach($_ips as $_ip) {
  18. $_ip = trim($_ip);
  19. $_ipdata = explode('.', $_ip);
  20. if($_ipdata) {
  21. $_ipcount = count($_ipdata);
  22. if($_ipcount < 4) {
  23. $_max = null;
  24. switch ($_ipcount) {
  25. case 1:
  26. $_ipdata[1] = '0';
  27. $_max = '.255.255.255';
  28. case 2:
  29. $_ipdata[2] = '0';
  30. if(!$_ipdata[1]) $_ipdata[1] = '0';
  31. if(!isset($_max)) $_max = '.255.255';
  32. case 3:
  33. $_ipdata[3] = '0';
  34. if(!$_ipdata[2]) $_ipdata[2] = '0';
  35. if(!isset($_max)) $_max = '.255';
  36. }
  37. $_ipmin = implode('.', $_ipdata);
  38. $_ipmax = trim($_ip, '.').$_max;
  39. $_ipmin = ip2long($_ipmin);
  40. $_ipmin = $_ipmin < 0 ? sprintf('%u', $_ipmin) : $_ipmin;
  41. $_ipmax = ip2long($_ipmax);
  42. $_ipmax = $_ipmax < 0 ? sprintf('%u', $_ipmax) : $_ipmax;
  43. $antitheft[$key]['range'][] = array('min'=>$_ipmin, 'max'=>$_ipmax);
  44. } else {
  45. $_ip = ip2long($_ip);
  46. $_ip = $_ip < 0 ? sprintf('%u', $_ip) : $_ip;
  47. $antitheft[$key]['single'][] = $_ip;
  48. }
  49. }
  50. }
  51. }
  52. savecache('antitheft', $antitheft);
  53. }
  54. ?>