Changeset 1029 -- 2009-07-24 14:27:46
- Comment
- [Add Tag:Release] sfMobileIPPlugin
Diffs
sfMobileIPPlugin/tags/0.0.6-beta/LICENSE
sfMobileIPPlugin/tags/0.0.6-beta/config/mobile_ips.yml
@@ -0,0 +1,160 @@
+docomo:
+ - 210.153.84.0/24
+ - 210.136.161.0/24
+ - 210.153.86.0/24
+ - 124.146.174.0/24
+ - 124.146.175.0/24
+ - 202.229.176.0/24
+ - 202.229.177.0/24
+ - 202.229.178.0/24
+
+ezweb:
+ - 210.230.128.224/28
+ - 121.111.227.160/27
+ - 61.117.1.0/28
+ - 219.108.158.0/27
+ - 219.125.146.0/28
+ - 61.117.2.32/29
+ - 61.117.2.40/29
+ - 219.108.158.40/29
+ - 219.125.148.0/25
+ - 222.5.63.0/25
+ - 222.5.63.128/25
+ - 222.5.62.128/25
+ - 59.135.38.128/25
+ - 219.108.157.0/25
+ - 219.125.145.0/25
+ - 121.111.231.0/25
+ - 121.111.227.0/25
+ - 118.152.214.192/26
+ - 118.159.131.0/25
+ - 118.159.133.0/25
+ - 121.111.227.0/25
+ - 118.159.132.160/27
+
+softbank:
+ - 123.108.236.0/24
+ - 123.108.237.0/27
+ - 202.179.204.0/24
+ - 202.253.96.224/27
+ - 210.146.7.192/26
+ - 210.146.60.192/26
+ - 210.151.9.128/26
+ - 210.175.1.128/25
+ - 211.8.159.128/25
+
+willcom:
+ - 61.198.128.0/24
+ - 61.198.129.0/24
+ - 61.198.130.0/24
+ - 61.198.131.0/24
+ - 61.198.132.0/24
+ - 61.198.133.0/24
+ - 61.198.134.0/24
+ - 61.198.135.0/24
+ - 61.198.136.0/24
+ - 61.198.137.0/24
+ - 61.198.138.100/32
+ - 61.198.138.101/32
+ - 61.198.138.102/32
+ - 61.198.138.103/32
+ - 61.198.139.0/29
+ - 61.198.139.128/27
+ - 61.198.139.160/28
+ - 61.198.140.0/24
+ - 61.198.141.0/24
+ - 61.198.142.0/24
+ - 61.198.143.0/24
+ - 61.198.160.0/24
+ - 61.198.161.0/24
+ - 61.198.162.0/24
+ - 61.198.163.0/24
+ - 61.198.164.0/24
+ - 61.198.165.0/24
+ - 61.198.166.0/24
+ - 61.198.168.0/24
+ - 61.198.169.0/24
+ - 61.198.170.0/24
+ - 61.198.171.0/24
+ - 61.198.172.0/24
+ - 61.198.173.0/24
+ - 61.198.174.0/24
+ - 61.198.175.0/24
+ - 61.198.248.0/24
+ - 61.198.249.0/24
+ - 61.198.250.0/24
+ - 61.198.251.0/24
+ - 61.198.252.0/24
+ - 61.198.253.0/24
+ - 61.198.254.0/24
+ - 61.198.255.0/24
+ - 61.204.0.0/24
+ - 61.204.2.0/24
+ - 61.204.3.0/25
+ - 61.204.3.128/25
+ - 61.204.4.0/24
+ - 61.204.5.0/24
+ - 61.204.6.0/25
+ - 61.204.6.128/25
+ - 61.204.7.0/25
+ - 61.204.92.0/24
+ - 61.204.93.0/24
+ - 61.204.94.0/24
+ - 61.204.95.0/24
+ - 125.28.0.0/24
+ - 125.28.1.0/24
+ - 125.28.11.0/24
+ - 125.28.12.0/24
+ - 125.28.13.0/24
+ - 125.28.14.0/24
+ - 125.28.15.0/24
+ - 125.28.16.0/24
+ - 125.28.17.0/24
+ - 125.28.2.0/24
+ - 125.28.3.0/24
+ - 125.28.4.0/24
+ - 125.28.5.0/24
+ - 125.28.6.0/24
+ - 125.28.7.0/24
+ - 125.28.8.0/24
+ - 210.168.246.0/24
+ - 210.168.247.0/24
+ - 210.169.92.0/24
+ - 210.169.93.0/24
+ - 210.169.94.0/24
+ - 210.169.95.0/24
+ - 210.169.96.0/24
+ - 210.169.97.0/24
+ - 210.169.98.0/24
+ - 210.169.99.0/24
+ - 211.126.192.128/25
+ - 211.18.232.0/24
+ - 211.18.233.0/24
+ - 211.18.234.0/24
+ - 211.18.235.0/24
+ - 211.18.236.0/24
+ - 211.18.237.0/24
+ - 211.18.238.0/24
+ - 211.18.239.0/24
+ - 219.108.10.0/24
+ - 219.108.11.0/24
+ - 219.108.12.0/24
+ - 219.108.13.0/24
+ - 219.108.14.0/24
+ - 219.108.15.0/24
+ - 219.108.4.0/24
+ - 219.108.5.0/24
+ - 219.108.6.0/24
+ - 219.108.7.0/24
+ - 219.108.8.0/24
+ - 219.108.9.0/24
+ - 221.119.0.0/24
+ - 221.119.1.0/24
+ - 221.119.2.0/24
+ - 221.119.3.0/24
+ - 221.119.4.0/24
+ - 221.119.5.0/24
+ - 221.119.6.0/24
+ - 221.119.7.0/24
+ - 221.119.8.0/24
+ - 221.119.9.0/24
sfMobileIPPlugin/tags/0.0.6-beta/config/config_handlers.yml
@@ -0,0 +1,2 @@
+config/mobile_ips.yml:
+ class: sfMobileIPConfigHandler
sfMobileIPPlugin/tags/0.0.6-beta/lib/sfMobileIP.class.php
@@ -0,0 +1,60 @@
+<?php
+/* vim: set expandtab tabstop=2 shiftwidth=2 softtabstop=2: */
+
+class sfMobileIP
+{
+ static public function carrier($addr = null)
+ {
+ if (!$addr) {
+ $addr = self::addr();
+ }
+
+ $ip = (double)(sprintf('%u', ip2long($addr)));
+ $ranges = self::ranges();
+ $min = -1;
+ $max = count($ranges);
+ while (true) {
+ $center = (int)floor(($min+$max)/2);
+ if ($center === $min) {
+ return 'pc';
+ }
+
+ $range =& $ranges[$center];
+
+ if ($ip < $range['network']) {
+ $max = $center;
+ } else if ($range['network'] <= $ip && $ip <= $range['broadcast']) {
+ return $range['carrier'];
+ } else {
+ $min = $center;
+ }
+ }
+ }
+
+ static protected function addr()
+ {
+ if (isset($_SERVER['REMOTE_ADDR'])) {
+ return $_SERVER['REMOTE_ADDR'];
+ }
+
+ return '127.0.0.1';
+ }
+
+ static protected function configFile()
+ {
+ $config_dir = sfConfig::get('sf_config_dir_name');
+ $config_file = $config_dir.DIRECTORY_SEPARATOR.'mobile_ips.yml';
+ return sfConfigCache::getInstance()->checkConfig($config_file);
+ }
+
+ static protected function ranges()
+ {
+ static $ranges = null;
+ if ($ranges) {
+ return $ranges;
+ }
+
+ $ranges = require_once(self::configFile());
+ return $ranges;
+ }
+}
sfMobileIPPlugin/tags/0.0.6-beta/lib/sfMobileIPConfigHandler.class.php
@@ -0,0 +1,67 @@
+<?php
+/* vim: set expandtab tabstop=2 shiftwidth=2 softtabstop=2: */
+
+class sfMobileIPConfigHandler extends sfYamlConfigHandler
+{
+ public function execute($configFiles)
+ {
+ $config = $this->parseYamls($configFiles);
+
+ // get all ip ranges
+ $ranges = array();
+ foreach ($config as $carrier => $carrier_ips) {
+ foreach ($carrier_ips as $cidr) {
+ $cidr = @Net_IPv4::parseAddress($cidr);
+ $ranges[] = array(
+ 'broadcast' => $this->ip2double($cidr->broadcast),
+ 'carrier' => $carrier,
+ 'network' => $this->ip2double($cidr->network));
+ }
+ }
+
+ // sort
+ usort($ranges, array($this, 'compareByNetwork'));
+
+ // unite sequent ip range
+ $l = count($ranges);
+ $cur =& $ranges[0];
+ for ($i = 1; $i < $l; $i++) {
+ $next =& $ranges[$i];
+ $condition = ($cur['broadcast']+1) === $next['network'] &&
+ $cur['carrier'] === $next['carrier'];
+ if ($condition) {
+ $cur['broadcast'] = $next['broadcast'];
+ unset($ranges[$i]);
+ } else {
+ $cur =& $ranges[$i];
+ }
+ }
+ $ranges = array_values($ranges);
+
+ // compile data
+ $retval = "<?php\n".
+ "// auto-generated by %s\n".
+ "// date: %s\n".
+ "return %s;\n";
+ $retval = sprintf($retval,
+ __CLASS__, date('Y/m/d H:i:s'), var_export($ranges, true));
+
+ return $retval;
+ }
+
+ protected function compareByNetwork($a, $b)
+ {
+ if ($a['network'] === $b['network']) {
+ return 0;
+ } else if ($a['network'] < $b['network']) {
+ return -1;
+ } else {
+ return 1;
+ }
+ }
+
+ protected function ip2double($addr)
+ {
+ return (double)(sprintf('%u', ip2long($addr)));
+ }
+}
sfMobileIPPlugin/tags/0.0.6-beta/package.xml
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<package packagerversion="1.7.1" version="2.0" xmlns="http://pear.php.net/dtd/package-2.0" xmlns:tasks="http://pear.php.net/dtd/tasks-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0 http://pear.php.net/dtd/tasks-1.0.xsd http://pear.php.net/dtd/package-2.0 http://pear.php.net/dtd/package-2.0.xsd">
+ <name>sfMobileIPPlugin</name>
+ <channel>pear.symfony-project.com</channel>
+ <summary>JP mobile ip detector</summary>
+ <description>Detect a carrier from an ip address</description>
+ <lead>
+ <name />
+ <user />
+ <email />
+ <active>yes</active>
+ </lead>
+ <date>2009-05-11</date>
+ <time>18:22:01</time>
+ <version>
+ <release>0.0.6</release>
+ <api>0.0.1</api>
+ </version>
+ <stability>
+ <release>beta</release>
+ <api>beta</api>
+ </stability>
+ <license uri="http://www.symfony-project.com/license">MIT license</license>
+ <notes>-</notes>
+ <contents>
+ <dir name="/">
+ <file md5sum="2ed4b9b22b01a98b23d5ea8c8ee4e5c1" name="lib/sfMobileIP.class.php" role="data" />
+ <file md5sum="3f9ea7819c4f7accf4126f37989fea0a" name="lib/sfMobileIPConfigHandler.class.php" role="data" />
+ <file md5sum="b29c9427cccb2ebacad644f8e9907877" name="config/config_handlers.yml" role="data" />
+ <file md5sum="294fcdd163efc4f70c3b77ccf322185b" name="config/mobile_ips.yml" role="data" />
+ <file md5sum="d41d8cd98f00b204e9800998ecf8427e" name="README" role="data" />
+ <file md5sum="d41d8cd98f00b204e9800998ecf8427e" name="LICENSE" role="data" />
+ </dir>
+ </contents>
+ <dependencies>
+ <required>
+ <php>
+ <min>5.1.0</min>
+ </php>
+ <pearinstaller>
+ <min>1.4.1</min>
+ </pearinstaller>
+ <package>
+ <name>symfony</name>
+ <channel>pear.symfony-project.com</channel>
+ <min>0.8.1</min>
+ <max>1.1.0</max>
+ <exclude>1.1.0</exclude>
+ </package>
+ </required>
+ </dependencies>
+ <phprelease />
+ <changelog />
+</package>
sfMobileIPPlugin/tags/0.0.6-beta/README