/tests/canoo/tests/testcases/level0/2.8.2/plug-ins/plugins/deliveryLimitations/Client/Ip.delivery.php

https://github.com/orchestra-io/sample-openx · PHP · 86 lines · 39 code · 9 blank · 38 comment · 16 complexity · 640bffb74c34b4a3c70a21132cdfcf66 MD5 · raw file

  1. <?php
  2. /*
  3. +---------------------------------------------------------------------------+
  4. | OpenX v${RELEASE_MAJOR_MINOR} |
  5. | =======${RELEASE_MAJOR_MINOR_DOUBLE_UNDERLINE} |
  6. | |
  7. | Copyright (c) 2003-2009 OpenX Limited |
  8. | For contact details, see: http://www.openx.org/ |
  9. | |
  10. | This program is free software; you can redistribute it and/or modify |
  11. | it under the terms of the GNU General Public License as published by |
  12. | the Free Software Foundation; either version 2 of the License, or |
  13. | (at your option) any later version. |
  14. | |
  15. | This program is distributed in the hope that it will be useful, |
  16. | but WITHOUT ANY WARRANTY; without even the implied warranty of |
  17. | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
  18. | GNU General Public License for more details. |
  19. | |
  20. | You should have received a copy of the GNU General Public License |
  21. | along with this program; if not, write to the Free Software |
  22. | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
  23. +---------------------------------------------------------------------------+
  24. $Id: Ip.delivery.php 33995 2009-03-18 23:04:15Z chris.nutting $
  25. */
  26. /**
  27. * @package OpenXPlugin
  28. * @subpackage DeliveryLimitations
  29. * @author Chris Nutting <chris@m3.net>
  30. * @author Andrzej Swedrzynski <andrzej.swedrzynski@m3.net>
  31. */
  32. require_once MAX_PATH . '/lib/max/Delivery/limitations.delivery.php';
  33. /**
  34. * Check to see if this impression contains the valid IP Address.
  35. *
  36. * @param string $limitation The IP address limitation
  37. * @param string $op The operator (either '==' or '!=')
  38. * @param array $aParams An array of additional parameters to be checked
  39. * @return boolean Whether this impression's IP address passes this limitation's test.
  40. */
  41. function MAX_checkClient_Ip($limitation, $op, $aParams = array())
  42. {
  43. if ($limitation == '') {
  44. return true;
  45. }
  46. if (empty($aParams)) {
  47. $aParams = $_SERVER;
  48. }
  49. $ip = $aParams['REMOTE_ADDR'];
  50. if ($limitation == '')
  51. return (true);
  52. if (!strpos($limitation, '/')) {
  53. $net = explode('.', $limitation);
  54. for ($i=0;$i<sizeof($net);$i++) {
  55. if ($net[$i] == '*') {
  56. $net[$i] = 0;
  57. $mask[$i] = 0;
  58. } else {
  59. $mask[$i] = 255;
  60. }
  61. }
  62. $pnet = pack('C4', $net[0], $net[1], $net[2], $net[3]);
  63. $pmask = pack('C4', $mask[0], $mask[1], $mask[2], $mask[3]);
  64. } else {
  65. list ($net, $mask) = explode('/', $limitation);
  66. $net = explode('.', $net);
  67. $pnet = pack('C4', $net[0], $net[1], $net[2], $net[3]);
  68. $mask = explode('.', $mask);
  69. $pmask = pack('C4', $mask[0], $mask[1], $mask[2], $mask[3]);
  70. }
  71. $ip = explode('.', $ip);
  72. $phost = pack('C4', $ip[0], $ip[1], $ip[2], $ip[3]);
  73. $expression = ($limitation == "*" || ($phost & $pmask) == $pnet);
  74. $op = $op == '==';
  75. return ($expression == $op);
  76. }
  77. ?>