diff --git a/exemple/config/LAN.php b/exemple/config/LAN.php new file mode 100644 index 0000000..8eb04a5 --- /dev/null +++ b/exemple/config/LAN.php @@ -0,0 +1,31 @@ +authorize(); +$App->openSession(); + +// Lan Config +$LanConfig = new \alphayax\freebox\api\v3\services\config\LAN\LAN( $App); +$a = $LanConfig->getConfiguration(); +print_r( $a); + +// Lan Browser +$LanBrowser = new \alphayax\freebox\api\v3\services\config\LAN\Browser($App); +$LanInterfaces = $LanBrowser->getBrowsableInterfaces(); +print_r( $LanInterfaces); + +/** @var \alphayax\freebox\api\v3\models\LAN\LanInterface $LanInterface1 */ +$LanInterface1 = $LanInterfaces[0]; + +$LanHosts = $LanBrowser->getHostsFromInterface( $LanInterfaces[0]); +print_r( $LanHosts); + +$LanHost1 = $LanBrowser->getHostFromId( $LanInterface1->getName(), $LanHosts[0]->getId()); +print_r( $LanHost1); + +$wol_status = $LanBrowser->wakeOnLan( $LanInterface1, $LanHost1); +print_r( $wol_status); diff --git a/freebox/api/v3/models/LAN/LanHost.php b/freebox/api/v3/models/LAN/LanHost.php new file mode 100644 index 0000000..f59542e --- /dev/null +++ b/freebox/api/v3/models/LAN/LanHost.php @@ -0,0 +1,177 @@ +initPropertyArray( 'l2ident' , LanHostL2Ident::class); + $this->initPropertyArray( 'names' , LanHostName::class); + $this->initPropertyArray( 'l3connectivities', LanHostL3Connectivity::class); + } + + /** + * @return string + */ + public function getId() { + return $this->id; + } + + /** + * @return string + */ + public function getPrimaryName() { + return $this->primary_name; + } + + /** + * @param string $primary_name + */ + public function setPrimaryName( $primary_name){ + $this->primary_name = $primary_name; + } + + /** + * @return string + */ + public function getHostType() { + return $this->host_type; + } + + /** + * @param string $host_type + */ + public function setHostType( $host_type) { + $this->host_type = $host_type; + } + + /** + * @return boolean + */ + public function isPrimaryNameManual() { + return $this->primary_name_manual; + } + + /** + * @return LanHostL2Ident[] + */ + public function getL2ident() { + return $this->l2ident; + } + + /** + * @return string + */ + public function getVendorName() { + return $this->vendor_name; + } + + /** + * @return boolean + */ + public function isPersistent() { + return $this->persistent; + } + + /** + * @param boolean $persistent + */ + public function setPersistent($persistent) { + $this->persistent = $persistent; + } + + /** + * @return boolean + */ + public function isReachable() { + return $this->reachable; + } + + /** + * @return int + */ + public function getLastTimeReachable() { + return $this->last_time_reachable; + } + + /** + * @return boolean + */ + public function isActive() { + return $this->active; + } + + /** + * @return int + */ + public function getLastActivity() { + return $this->last_activity; + } + + /** + * @return LanHostName[] + */ + public function getNames() { + return $this->names; + } + + /** + * @return LanHostL3Connectivity[] + */ + public function getL3connectivities() { + return $this->l3connectivities; + } + +} diff --git a/freebox/api/v3/models/LAN/LanHostL2Ident.php b/freebox/api/v3/models/LAN/LanHostL2Ident.php new file mode 100644 index 0000000..237ff7e --- /dev/null +++ b/freebox/api/v3/models/LAN/LanHostL2Ident.php @@ -0,0 +1,34 @@ +id; + } + + /** + * @return string + */ + public function getType() { + return $this->type; + } + +} diff --git a/freebox/api/v3/models/LAN/LanHostL3Connectivity.php b/freebox/api/v3/models/LAN/LanHostL3Connectivity.php new file mode 100644 index 0000000..5d263f1 --- /dev/null +++ b/freebox/api/v3/models/LAN/LanHostL3Connectivity.php @@ -0,0 +1,74 @@ +addr; + } + + /** + * @return string + */ + public function getAf() { + return $this->af; + } + + /** + * @return boolean + */ + public function isActive() { + return $this->active; + } + + /** + * @return boolean + */ + public function isReachable() { + return $this->reachable; + } + + /** + * @return int + */ + public function getLastActivity() { + return $this->last_activity; + } + + /** + * @return int + */ + public function getLastTimeReachable() { + return $this->last_time_reachable; + } + +} diff --git a/freebox/api/v3/models/LAN/LanHostName.php b/freebox/api/v3/models/LAN/LanHostName.php new file mode 100644 index 0000000..a8b5a83 --- /dev/null +++ b/freebox/api/v3/models/LAN/LanHostName.php @@ -0,0 +1,31 @@ +name; + } + + /** + * @return string + */ + public function getSource() { + return $this->source; + } + +} diff --git a/freebox/api/v3/models/LAN/LanInterface.php b/freebox/api/v3/models/LAN/LanInterface.php new file mode 100644 index 0000000..32035de --- /dev/null +++ b/freebox/api/v3/models/LAN/LanInterface.php @@ -0,0 +1,31 @@ +name; + } + + /** + * @return int + */ + public function getHostCount() { + return $this->host_count; + } + +} diff --git a/freebox/api/v3/models/LanConfig.php b/freebox/api/v3/models/LanConfig.php new file mode 100644 index 0000000..f2eadb0 --- /dev/null +++ b/freebox/api/v3/models/LanConfig.php @@ -0,0 +1,117 @@ +ip; + } + + /** + * @param string $ip + */ + public function setIp( $ip){ + $this->ip = $ip; + } + + /** + * @return string + */ + public function getName(){ + return $this->name; + } + + /** + * @param string $name + */ + public function setName( $name){ + $this->name = $name; + } + + /** + * @return string + */ + public function getNameDns(){ + return $this->name_dns; + } + + /** + * @param string $name_dns + */ + public function setNameDns( $name_dns){ + $this->name_dns = $name_dns; + } + + /** + * @return string + */ + public function getNameMdns(){ + return $this->name_mdns; + } + + /** + * @param string $name_mdns + */ + public function setNameMdns( $name_mdns){ + $this->name_mdns = $name_mdns; + } + + /** + * @return string + */ + public function getNameNetbios(){ + return $this->name_netbios; + } + + /** + * @param string $name_netbios + */ + public function setNameNetbios( $name_netbios){ + $this->name_netbios = $name_netbios; + } + + /** + * @return string + */ + public function getMode(){ + return $this->mode; + } + + /** + * @param string $mode + */ + public function setMode( $mode){ + $this->mode = $mode; + } + +} diff --git a/freebox/api/v3/services/config/LAN/Browser.php b/freebox/api/v3/services/config/LAN/Browser.php new file mode 100644 index 0000000..bad30e9 --- /dev/null +++ b/freebox/api/v3/services/config/LAN/Browser.php @@ -0,0 +1,107 @@ +getAuthService( self::API_LAN_BROWSER_INTERFACES); + $rest->GET(); + + $LanInterface_xs = $rest->getCurlResponse()['result']; + $LanInterfaces = []; + foreach( $LanInterface_xs as $LanInterface_x) { + $LanInterfaces[] = new LanInterface( $LanInterface_x); + } + return $LanInterfaces; + } + + /** + * @param LanInterface $lanInterface + * @return LanHost[] + * @throws \Exception + */ + public function getHostsFromInterface( LanInterface $lanInterface){ + return $this->getHostsFromInterfaceName( $lanInterface->getName()); + } + + /** + * @param string $lanInterfaceId + * @return LanHost[] + * @throws \Exception + */ + public function getHostsFromInterfaceName( $lanInterfaceId){ + $service = sprintf( self::API_LAN_BROWSER_INTERFACE, $lanInterfaceId); + $rest = $this->getAuthService( $service); + $rest->GET(); + + $LanHost_xs = $rest->getCurlResponse()['result']; + $LanHosts = []; + foreach( $LanHost_xs as $LanHost_x) { + $LanHosts[] = new LanHost( $LanHost_x); + } + return $LanHosts; + } + + /** + * @param string $lanInterfaceId + * @param string $hostId + * @return LanHost + */ + public function getHostFromId( $lanInterfaceId, $hostId){ + $service = sprintf( self::API_LAN_BROWSER_HOST, $lanInterfaceId, $hostId); + echo $service; + $rest = $this->getAuthService( $service); + $rest->GET(); + + return new LanHost( $rest->getCurlResponse()['result']); + } + + /** + * @param LanHost $LanHost + * @param string $lanInterfaceId + * @return LanHost + */ + public function updateHostFromInterfaceId( LanHost $LanHost, $lanInterfaceId){ + $service = sprintf( self::API_LAN_BROWSER_HOST, $lanInterfaceId, $LanHost->getId()); + $rest = $this->getAuthService( $service); + $rest->PUT( $LanHost->toArray()); + + return new LanHost( $rest->getCurlResponse()['result']); + } + + /** + * Send Wake ok Lan packet to an host + * @param LanInterface $lanInterface + * @param LanHost $lanHost + * @param string $password + * @return bool + */ + public function wakeOnLan( LanInterface $lanInterface, LanHost $lanHost, $password = ''){ + $service = sprintf( self::API_WAKE_ON_LAN, $lanInterface->getName()); + $rest = $this->getAuthService( $service); + $rest->PUT([ + 'mac' => $lanHost->getId(), + 'password' => $password, + ]); + + return (bool) $rest->getCurlResponse()['result']; + } + +} diff --git a/freebox/api/v3/services/config/LAN/LAN.php b/freebox/api/v3/services/config/LAN/LAN.php new file mode 100644 index 0000000..b2fda4f --- /dev/null +++ b/freebox/api/v3/services/config/LAN/LAN.php @@ -0,0 +1,38 @@ +getAuthService( self::API_LAN_CONFIG); + $rest->GET(); + + return new LanConfig( $rest->getCurlResponse()['result']); + } + + /** + * @param LanConfig $new_LanConfig + * @return LanConfig + * @throws \Exception + */ + public function setConfiguration( LanConfig $new_LanConfig){ + $rest = $this->getAuthService( self::API_LAN_CONFIG); + $rest->PUT( $new_LanConfig->toArray()); + + return new LanConfig( $rest->getCurlResponse()['result']); + } + +} diff --git a/freebox/api/v3/symbols/Lan/LanHostL2IdentType.php b/freebox/api/v3/symbols/Lan/LanHostL2IdentType.php new file mode 100644 index 0000000..109455c --- /dev/null +++ b/freebox/api/v3/symbols/Lan/LanHostL2IdentType.php @@ -0,0 +1,13 @@ +