function added for retreiving client ip address
This commit is contained in:
parent
7450b6c2b1
commit
4abd84d64e
1 changed files with 25 additions and 1 deletions
|
@ -37,7 +37,13 @@ class CBLogs
|
|||
global $db,$userquery;
|
||||
$a = $details_array;
|
||||
//$ip = $_SERVER['REMOTE_ADDR'];
|
||||
$ip = explode(' ',explode(':',explode('inet addr',explode('eth0',trim(`ifconfig`))[1])[1])[1])[0];
|
||||
$ipv = $this->get_local_ipv4();
|
||||
if($ipv['eth0']){
|
||||
$ip = $ipv['eth0'];
|
||||
}
|
||||
if($ipv['wlan0']){
|
||||
$ip = $ipv['wlan0'];
|
||||
}
|
||||
$agent = $_SERVER['HTTP_USER_AGENT'];
|
||||
$userid = getArrayValue($a, 'userid');
|
||||
$username = $a['username'];
|
||||
|
@ -87,6 +93,24 @@ class CBLogs
|
|||
);
|
||||
|
||||
}
|
||||
|
||||
function get_local_ipv4() {
|
||||
$out = split(PHP_EOL,shell_exec("/sbin/ifconfig"));
|
||||
$local_addrs = array();
|
||||
$ifname = 'unknown';
|
||||
foreach($out as $str) {
|
||||
$matches = array();
|
||||
if(preg_match('/^([a-z0-9]+)(:\d{1,2})?(\s)+Link/',$str,$matches)) {
|
||||
$ifname = $matches[1];
|
||||
if(strlen($matches[2])>0) {
|
||||
$ifname .= $matches[2];
|
||||
}
|
||||
} elseif(preg_match('/inet addr:((?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:[.](?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3})\s/',$str,$matches)) {
|
||||
$local_addrs[$ifname] = $matches[1];
|
||||
}
|
||||
}
|
||||
return $local_addrs;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue