devices[$entry] = new NetworkInterface($entry); } $result = shell_exec('ip --json address show'); foreach(json_decode($result) AS $entry) { $device = $this->devices[$entry->ifname]; if(isset($entry->link_type)) { $device->setType($entry->link_type); } if(isset($entry->operstate)) { $device->setState(NetworkState::tryFromName($entry->operstate)); } if(isset($entry->address)) { $device->setAddress($entry->address); } if(isset($entry->broadcast)) { $device->setBroadcast($entry->broadcast); } if(isset($entry->flags)) { foreach($entry->flags AS $flag) { $device->addFlag($flag); } } if(isset($entry->addr_info)) { foreach($entry->addr_info AS $address) { $device->addAddress(new NetworkAddress($address)); } } } } public function getDevices() : array { return $this->devices; } public function hasDevices() : bool { return !empty($this->devices); } public function getHostname() : string { return trim(shell_exec('hostname')); } public function getPanelHostname() : string { return trim($_SERVER['HTTP_HOST']); } public function getIPAddress() : string { return trim($_SERVER['SERVER_ADDR']); } public function getDevice($id) : NetworkInterface | null { return $this->devices[$id]; } } class NetworkInterfaces { public static function get() : ?NetworkInterfacesFactory { return NetworkInterfacesFactory::getInstance(); } public static function getDevices() : array { return NetworkInterfacesFactory::getInstance()->getDevices(); } public static function getHostname() : string { return NetworkInterfacesFactory::getInstance()->getHostname(); } public static function getPanelHostname() : string { return NetworkInterfacesFactory::getInstance()->getPanelHostname(); } public static function getIPAddress() : string { return NetworkInterfacesFactory::getInstance()->getIPAddress(); } public static function getDevice($id) : NetworkInterface | null { return NetworkInterfacesFactory::getInstance()->getDevice($id); } } ?>