8
0
UserOnline/copy_this/modules/d3usersonline/views/d3_oxcmp_utils_usersonline.php

140 Zeilen
4.9 KiB
PHP

2011-10-19 22:05:36 +02:00
<?php
/**
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @author Aggrosoft, D<EFBFBD> Data Development
*/
2011-10-19 22:53:23 +02:00
class d3_oxcmp_utils_usersonline extends d3_oxcmp_utils_usersonline_parent
2011-10-19 22:05:36 +02:00
{
protected $_iExpTime = 600; // (in seconds)
protected $_sUserIpHash = null;
protected $_remoteAddr = null;
protected $_httpClientIp = null;
protected $_httpXForwardedFor = null;
protected $_httpXForwarded = null;
protected $_httpForwardedFor = null;
protected $_httpForwarded = null;
protected $_httpVia = null;
protected $_httpXComingFrom = null;
protected $_httpComingFrom = null;
protected $_proxyIp = null;
protected $_directIp = null;
public function init()
{
$this->blIsComponent = true;
parent::init();
}
public function render()
{
$ret = parent::render();
//WE ARE NOT ALLOWED TO STORE THE REAL IP
$this->_sUserIpHash = md5($this->_getTrueIP());
$this->utime = time();
2011-10-19 22:53:23 +02:00
$oUserOnline = oxNew('d3usersonline');
2011-10-19 22:05:36 +02:00
$oUserOnline->clearOldItems($this->_iExpTime);
$iUserExist = $oUserOnline->getActUserItem($this->_sUserIpHash);
2012-06-14 15:25:27 +02:00
if ($iUserExist > 0) {
2011-10-19 22:05:36 +02:00
$oUserOnline->setActTimeVisit($this->_sUserIpHash);
2012-06-14 15:25:27 +02:00
} else {
2011-10-19 22:05:36 +02:00
$oUserOnline->insertActUser($this->_sUserIpHash);
2012-06-14 15:25:27 +02:00
}
2011-10-19 22:05:36 +02:00
2012-06-14 15:25:27 +02:00
$this->getParent()->addTplParam('aUsersOnline', $oUserOnline->getUserCount());
2011-10-19 22:05:36 +02:00
return $ret;
}
private function _getIpData($sTargetVarName, $sDataName)
{
2012-06-14 15:25:27 +02:00
if (empty($this->{$sTargetVarName}))
2011-10-19 22:05:36 +02:00
{
if (!empty($_SERVER) && isset($_SERVER[$sDataName]))
$this->{$sTargetVarName} = $_SERVER[$sDataName];
else if (!empty($_ENV) && isset($_ENV[$sDataName]))
$this->{$sTargetVarName} = $_ENV[$sDataName];
else if (@getenv($sDataName))
$this->{$sTargetVarName} = getenv($sDataName);
}
}
private function _getTrueIP()
{
2012-06-14 15:25:27 +02:00
$this->_getIpData('_remoteAddr', 'REMOTE_ADDR');
$this->_getIpData('_httpClientIp', 'HTTP_CLIENT_IP');
$this->_getIpData('_httpXForwardedFor', 'HTTP_X_FORWARDED_FOR');
$this->_getIpData('_httpXForwarded', 'HTTP_X_FORWARDED');
$this->_getIpData('_httpForwardedFor', 'HTTP_FORWARDED_FOR');
$this->_getIpData('_httpForwarded', 'HTTP_FORWARDED');
$this->_getIpData('_httpVia', 'HTTP_VIA');
$this->_getIpData('_httpXComingFrom', 'HTTP_X_COMING_FROM');
$this->_getIpData('_httpComingFrom', 'HTTP_COMING_FROM');
2011-10-19 22:05:36 +02:00
// Gets the default ip sent by the user
if (!empty($this->_remoteAddr))
$this->_directIp = $this->_remoteAddr;
// Gets the proxy ip sent by the user
if (!empty($this->_httpXForwardedFor))
$this->_proxyIp = $this->_httpXForwardedFor;
else if (!empty($this->_httpXForwarded))
$this->_proxyIp = $this->_httpXForwarded;
else if (!empty($this->_httpForwardedFor))
$this->_proxyIp = $this->_httpForwardedFor;
else if (!empty($this->_httpForwarded))
$this->_proxyIp = $this->_httpForwarded;
else if (!empty($this->_httpVia))
$this->_proxyIp = $this->_httpVia;
else if (!empty($this->_httpXComingFrom))
$this->_proxyIp = $this->_httpXComingFrom;
else if (!empty($this->_httpComingFrom))
$this->_proxyIp = $this->_httpComingFrom;
// Returns the true IP if it has been found, else ...
2012-06-14 15:25:27 +02:00
if (empty($this->_proxyIp))
2011-10-19 22:05:36 +02:00
{
// True IP without proxy
return $this->_directIp;
2012-06-14 15:25:27 +02:00
}
else
2011-10-19 22:05:36 +02:00
{
2012-06-14 15:25:27 +02:00
$isIp = ereg('^([0-9]{1,3}.){3,3}[0-9]{1,3}', $this->_proxyIp, $regs);
2011-10-19 22:05:36 +02:00
2012-06-14 15:25:27 +02:00
if ($isIp && (count($regs) > 0))
2011-10-19 22:05:36 +02:00
{
// True IP behind a proxy
return $regs[0];
2012-06-14 15:25:27 +02:00
}
else
2011-10-19 22:05:36 +02:00
{
2012-06-14 15:25:27 +02:00
if (empty($this->_httpClientIp))
2011-10-19 22:05:36 +02:00
{
// Can't define IP: there is a proxy but we don't have
// information about the true IP
return "(unbekannt) " . $this->_proxyIp;
2012-06-14 15:25:27 +02:00
}
else
2011-10-19 22:05:36 +02:00
{
// better than nothing
return $this->_httpClientIp;
}
}
}
}
}