Skip to content

Commit

Permalink
Merge branch 'feature/jaswsinc' into 000000-dev
Browse files Browse the repository at this point in the history
  • Loading branch information
raamdev committed Mar 30, 2015
2 parents 7ec648a + f10b0b4 commit 33cc1a5
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 24 deletions.
9 changes: 8 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
# Server config files.
*.admins text
*.cfg text
*.cnf text
*.conf text
*.htaccess text
*.htaccess-apache text
Expand All @@ -31,8 +32,14 @@
# CSS/JavaScript files.
*.css text
*.js text
*.css.map text
*.js.map text
*.json text

# Applescript files.
*.applescript text
*.scpt binary

# PHP scripts/files.
*.inc text
*.php text
Expand Down Expand Up @@ -140,4 +147,4 @@
*.dll binary
*.exe binary
*.sh text
*.so binary
*.so binary
19 changes: 14 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,15 @@
*~
*.bak

# Node
node_modules/
npm-debug.log

# SASS
.sass-cache/

# IntelliJ
.idea/
*.iml
*.ipr
*.iws

Expand Down Expand Up @@ -49,10 +55,13 @@ Icon?
# Amazon Web Services
.elasticbeanstalk/

# For shell glob patterns. This includes GIT files too. We simply maintain this list together with `.gitignore`.
# .~*;*~;*.bak;.idea;*.iml;*.ipr;*.iws;*.sublime-workspace;*.sublime-project;.git;.gitignore;.gitattributes;CVS;.cvsignore;.svn;_svn;.bzr;.bzrignore;.hg;.hgignore;SCCS;RCS;$RECYCLE.BIN;Desktop.ini;Thumbs.db;ehthumbs.db;.Spotlight-V100;.AppleDouble;.LSOverride;.DS_Store;.Trashes;.elasticbeanstalk
# Vagrant
.vagrant/

# For shell glob patterns. This includes Git files too. We simply maintain this list together with `.gitignore`.
# .~*;*~;*.bak;node_modules;npm-debug.log;.idea;*.ipr;*.iws;*.sublime-workspace;*.sublime-project;.git;.gitignore;.gitattributes;CVS;.cvsignore;.svn;_svn;.bzr;.bzrignore;.hg;.hgignore;SCCS;RCS;$RECYCLE.BIN;Desktop.ini;Thumbs.db;ehthumbs.db;.Spotlight-V100;.AppleDouble;.LSOverride;.DS_Store;.Trashes;._*;.elasticbeanstalk;.vagrant

# This list is for IntelliJ IDEA / PhpStorm `File Types` configuration. Some files we actually WANT to work with as part of a project.
# .idea;*.iml;*.ipr;*.iws;*.sublime-workspace;*.sublime-project;.git;CVS;.svn;_svn;.bzr;.hg;SCCS;RCS;$RECYCLE.BIN;Desktop.ini;Thumbs.db;ehthumbs.db;.Spotlight-V100;.AppleDouble;.LSOverride;.DS_Store;.Trashes;._*
# .sass-cache;.idea;*.ipr;*.iws;*.sublime-workspace;*.sublime-project;.git;CVS;.svn;_svn;.bzr;.hg;SCCS;RCS;$RECYCLE.BIN;Desktop.ini;Thumbs.db;ehthumbs.db;.Spotlight-V100;.AppleDouble;.LSOverride;.DS_Store;.Trashes;._*;.vagrant

# We also need to update the WebSharks™ Core `dirs_files::ignore()` method if this changes.
# We also need to update the WebSharks™ Core `dirs_files::ignore()` method if this changes.
40 changes: 22 additions & 18 deletions zencache/includes/share.php
Original file line number Diff line number Diff line change
Expand Up @@ -989,6 +989,7 @@ public function has_a_cacheable_status()
* @return string Real IP address, else `unknown` on failure.
*
* @note This supports both IPv4 and IPv6 addresses.
* @note See my tests against this here: http://3v4l.org/fVWUp
*/
public function current_ip()
{
Expand All @@ -998,11 +999,9 @@ public function current_ip()
static::$static[__FUNCTION__] = ''; // Initialize.
$ip = &static::$static[__FUNCTION__];

$_s = $_SERVER; // Copy of current `$_SERVER` vars.

if($this->apply_filters(__METHOD__.'_prioritize_remote_addr', FALSE))
if(($REMOTE_ADDR = $this->valid_public_ip($_s['REMOTE_ADDR'])))
return ($ip = $REMOTE_ADDR);
if(!empty($_SERVER['REMOTE_ADDR']) && $this->apply_filters(__METHOD__.'_prioritize_remote_addr', FALSE))
if(($_valid_public_ip = $this->valid_public_ip($_SERVER['REMOTE_ADDR'])))
return ($ip = $_valid_public_ip);

$sources = array(
'HTTP_CF_CONNECTING_IP',
Expand All @@ -1018,36 +1017,41 @@ public function current_ip()
$sources = $this->apply_filters(__METHOD__.'_sources', $sources);

foreach($sources as $_source) // Try each of these; in order.
if(!isset($$_source) && ($$_source = $this->valid_public_ip($_s[$_source])))
return ($ip = $$_source); // A valid, public IPv4 or IPv6 address.
unset($_source); // Housekeeping.
{
if(!empty($_SERVER[$_source])) // Does the source key exist at all?
if(($_valid_public_ip = $this->valid_public_ip($_SERVER[$_source])))
return ($ip = $_valid_public_ip); // A valid public IPv4 or IPv6 address.
}
unset($_source, $_valid_public_ip); // Housekeeping.

if(!empty($_s['REMOTE_ADDR']) && is_string($_s['REMOTE_ADDR']))
return ($ip = strtolower($_s['REMOTE_ADDR']));
if(!empty($_SERVER['REMOTE_ADDR']) && is_string($_SERVER['REMOTE_ADDR']))
return ($ip = strtolower($_SERVER['REMOTE_ADDR']));

return ($ip = 'unknown'); // Not possible.
}

/**
* Gets a valid/public IP address.
*
* @param string $possible_ips A single IP, or a possible comma-delimited list of IPs.
* Pass by reference to avoid PHP notices while checking multiple sources.
* @param string $list_of_possible_ips A single IP, or a comma-delimited list of IPs.
*
* @return string A valid/public IP address (if one is found), else an empty string.
*
* @note This supports both IPv4 and IPv6 addresses.
* @note See my tests against this here: http://3v4l.org/fVWUp
*/
public function valid_public_ip(&$possible_ips)
public function valid_public_ip($list_of_possible_ips)
{
if(!$possible_ips || !is_string($possible_ips))
if(!$list_of_possible_ips || !is_string($list_of_possible_ips))
return ''; // Empty or invalid data.

foreach(preg_split('/[\s;,]+/', trim($possible_ips), NULL, PREG_SPLIT_NO_EMPTY) as $_possible_ip)
if(($_possible_ip = filter_var(strtolower($_possible_ip), FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)))
return $_possible_ip; // A valid, public IPv4 or IPv6 address.
unset($_possible_ip); // Housekeeping.
if(!($list_of_possible_ips = trim($list_of_possible_ips)))
return ''; // Not possible; i.e., empty string.

foreach(preg_split('/[\s;,]+/', $list_of_possible_ips, NULL, PREG_SPLIT_NO_EMPTY) as $_possible_ip)
if(($_valid_public_ip = filter_var(strtolower($_possible_ip), FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)))
return $_valid_public_ip; // A valid public IPv4 or IPv6 address.
unset($_possible_ip, $_valid_public_ip); // Housekeeping.

return ''; // Default return value.
}
Expand Down

0 comments on commit 33cc1a5

Please sign in to comment.