fix get ip in nginx reverse proxy

pull/13/head
JMcn 2019-01-12 00:05:00 +08:00
parent 77d5f82296
commit 63e652caf1
1 changed files with 19 additions and 1 deletions

View File

@ -22,7 +22,7 @@ $D['version'] = '1.0.0';
$D['model'] = get_device_model();
$D['user'] = @get_current_user();
$D['hostname'] = gethostname();
$D['hostip'] = ('/'==DIRECTORY_SEPARATOR) ? $_SERVER['SERVER_ADDR'] : @gethostbyname($_SERVER['SERVER_NAME']);
$D['hostip'] = get_device_ip();
$D['yourip'] = $_SERVER['REMOTE_ADDR'];
$D['uname'] = @php_uname();
$D['os'] = explode(" ", php_uname());
@ -56,6 +56,24 @@ else{
$D['cpu']['model'] = '';
}
function get_device_ip() {
$getIp = ('/'==DIRECTORY_SEPARATOR) ? $_SERVER['SERVER_ADDR'] : @gethostbyname($_SERVER['SERVER_NAME']);
if($getIp=='127.0.0.1'){
$eth0_command="ifconfig eth0 | grep 'inet ' | cut -d: -f2 | awk '{ print $2}'";
$eth0_ip = shell_exec($eth0_command);
if($eth0_ip==''){
$wlan0_command="ifconfig wlan0 | grep 'inet ' | cut -d: -f2 | awk '{ print $2}'";
$wlan0_ip = shell_exec($wlan0_command);
return $wlan0_ip;
}
else {
return $eth0_ip;
}
} else {
return $getIp;
}
}
function get_device_model(){
return ['name' => 'Raspberry Pi', 'id' => 'raspberry-pi'];
}