Add Parental Control API

Finalize all features :D
This commit is contained in:
alphayax 2016-06-09 21:18:55 +02:00
parent 479d6dc048
commit 702a0d52b9
10 changed files with 488 additions and 4 deletions

View File

@ -16,11 +16,12 @@ Implementation PHP de l'API de la freebox (dans sa version 3).
## Prérequis
Ce projet est basé sur **composer**. Pensez à installer les dependences :)
Ce projet est basé sur **composer**.
Pensez à installer les dependences :)
## Fonctionnalités
Jusqu'a présent, les fonctionalités suivantes ont été implémentées :
L'intégralité des fonctionnalités de l'API Freebox (v3) sont implémentées :
- AirMedia
- Call
@ -93,6 +94,9 @@ Jusqu'a présent, les fonctionalités suivantes ont été implémentées :
- BSS
- Planning
- Mac Filter
- Parental Control
- Filter
- Planning
## Utilisation

View File

@ -39,5 +39,5 @@
- ~~VPN Client [UNSTABLE]~~
- ~~Storage~~
- ~~Storage API [UNSTABLE]~~
- Parental filter
- Parental Control
- ~~Parental filter~~
- ~~Parental Control~~

View File

@ -0,0 +1,17 @@
<?php
/// Require Composer AutoLoader
require_once '../../vendor/autoload.php';
/// Define our application
$App = new \alphayax\freebox\utils\Application( 'com.alphayax.freebox.filter', 'PHP API Example (Parental control)', '1.0.0');
$App->authorize();
$App->openSession();
$FilterService = new \alphayax\freebox\api\v3\services\ParentalControl\Filter( $App);
$Config = $FilterService->getConfiguration();
print_r( $Config);
$Filters = $FilterService->getAll();
print_r( $Filters);

View File

@ -0,0 +1,196 @@
<?php
namespace alphayax\freebox\api\v3\models\ParentalControl;
use alphayax\freebox\api\v3\Model;
use alphayax\freebox\api\v3\symbols;
/**
* Class Filter
* @package alphayax\freebox\api\v3\models\ParentalControl
*/
class Filter extends Model {
/** @var int (Read-only) : filter id */
protected $id;
/** @var string[] : the list of mac addresses the rule should be applied to */
protected $macs;
/** @var string[] (Read-only) : the list of hostnames associated with macs */
protected $hosts;
/** @var string (Read-only) : only filled for old rules, you cannot set a rule with an IP */
protected $ip;
/** @var string : a description for this rule */
protected $desc;
/** @var bool : is set to true, the rule will not use the planning and will always stay in the forced_mode */
protected $forced;
/**
* @var string : The filter policy to use when forced is set to true
* @see symbols\ParentalControl\FilterState
*/
protected $forced_mode;
/** @var int : if != 0 the rule will not use the planning for the next tmp_mode_expire seconds */
protected $tmp_mode_expire;
/**
* @var string : the filter policy to use when tmp_mode_expire is != 0
* @see symbols\ParentalControl\FilterState
*/
protected $tmp_mode;
/**
* @var string (Read-only)
* @see symbols\ParentalControl\SchedulingMode
*/
protected $scheduling_mode;
/**
* @var string (Read-only)
* @see symbols\ParentalControl\FilterState
*/
protected $filter_state;
/** @var int (Read-only) : current index used in planning to compute filter_state (only relevant when scheduling_mode is planning) */
protected $current_mapping_idx;
/** @var int (Read-only) : seconds until next filter_state change 0 means filter_state wont change */
protected $next_change;
/**
* @return int
*/
public function getId() {
return $this->id;
}
/**
* @return \string[]
*/
public function getMacs() {
return $this->macs;
}
/**
* @param \string[] $macs
*/
public function setMacs($macs) {
$this->macs = $macs;
}
/**
* @return \string[] (Read-only)
*/
public function getHosts() {
return $this->hosts;
}
/**
* @return string
*/
public function getIp() {
return $this->ip;
}
/**
* @return string
*/
public function getDesc() {
return $this->desc;
}
/**
* @param string $desc
*/
public function setDesc($desc) {
$this->desc = $desc;
}
/**
* @return boolean
*/
public function isForced() {
return $this->forced;
}
/**
* @param boolean $forced
*/
public function setForced($forced) {
$this->forced = $forced;
}
/**
* @return string
*/
public function getForcedMode() {
return $this->forced_mode;
}
/**
* @param string $forced_mode
*/
public function setForcedMode($forced_mode) {
$this->forced_mode = $forced_mode;
}
/**
* @return int
*/
public function getTmpModeExpire() {
return $this->tmp_mode_expire;
}
/**
* @param int $tmp_mode_expire
*/
public function setTmpModeExpire($tmp_mode_expire) {
$this->tmp_mode_expire = $tmp_mode_expire;
}
/**
* @return string
*/
public function getTmpMode() {
return $this->tmp_mode;
}
/**
* @param string $tmp_mode
*/
public function setTmpMode($tmp_mode) {
$this->tmp_mode = $tmp_mode;
}
/**
* @return string
*/
public function getSchedulingMode() {
return $this->scheduling_mode;
}
/**
* @return string
*/
public function getFilterState() {
return $this->filter_state;
}
/**
* @return int
*/
public function getCurrentMappingIdx() {
return $this->current_mapping_idx;
}
/**
* @return int
*/
public function getNextChange() {
return $this->next_change;
}
}

View File

@ -0,0 +1,32 @@
<?php
namespace alphayax\freebox\api\v3\models\ParentalControl;
use alphayax\freebox\api\v3\Model;
use alphayax\freebox\api\v3\symbols;
/**
* Class FilterConfig
* @package alphayax\freebox\api\v3\models\ParentalControl
*/
class FilterConfig extends Model {
/**
* @var string
* @see symbols\ParentalControl\FilterState
*/
protected $default_filter_mode;
/**
* @return string
*/
public function getDefaultFilterMode() {
return $this->default_filter_mode;
}
/**
* @param string $default_filter_mode
*/
public function setDefaultFilterMode($default_filter_mode) {
$this->default_filter_mode = $default_filter_mode;
}
}

View File

@ -0,0 +1,59 @@
<?php
namespace alphayax\freebox\api\v3\models\ParentalControl;
use alphayax\freebox\api\v3\Model;
/**
* Class FilterPlanning
* @package alphayax\freebox\api\v3\models\ParentalControl
*/
class FilterPlanning extends Model {
/**
* @var int (Read-only) : planning resolution
* number of planning slots per day, e.g. 48 means that each slot represent 30 minutes
*/
protected $resolution;
/**
* @var string[] : list of custom day range
* Each custom day range represents a group of days for which you want to use a different planning than other week days.
* For instance a custom day range can contain the list of you children holidays each cdayranges can be a coma separated
* list of cdayranges, for instance :fr_bank_holidays,:fr_school_holidays_b”
*/
protected $cdayranges = [];
/**
* @var string[] (Read-only) : array of states for each corresponding planning slots.
* the array size is : (number of cdayranges + 7) * resolution
*/
protected $mapping = [];
/**
* @return int
*/
public function getResolution() {
return $this->resolution;
}
/**
* @return \string[]
*/
public function getCdayranges() {
return $this->cdayranges;
}
/**
* @param \string[] $cDayRanges
*/
public function setCdayranges( $cDayRanges) {
$this->cdayranges = $cDayRanges;
}
/**
* @return \string[] (Read-only)
*/
public function getMapping() {
return $this->mapping;
}
}

View File

@ -0,0 +1,101 @@
<?php
namespace alphayax\freebox\api\v3\services\ParentalControl;
use alphayax\freebox\api\v3\models;
use alphayax\freebox\api\v3\Service;
use alphayax\freebox\api\v3\symbols;
/**
* Class Filter
* @package alphayax\freebox\api\v3\services\Storage
*/
class Filter extends Service {
const API_PARENTAL_CONFIG = '/api/v3/parental/config/';
const API_PARENTAL_FILTER = '/api/v3/parental/filter/';
/**
* @throws \Exception
* @return models\ParentalControl\FilterConfig
*/
public function getConfiguration(){
$rest = $this->getAuthService( self::API_PARENTAL_CONFIG);
$rest->GET();
return $rest->getResult( models\ParentalControl\FilterConfig::class);
}
/**
* @param models\ParentalControl\FilterConfig $filterConfig
* @return models\ParentalControl\FilterConfig
*/
public function setConfiguration( models\ParentalControl\FilterConfig $filterConfig){
$rest = $this->getAuthService( self::API_PARENTAL_CONFIG);
$rest->PUT( $filterConfig);
return $rest->getResult( models\ParentalControl\FilterConfig::class);
}
/**
* Get the list of disks
* @throws \Exception
* @return models\ParentalControl\Filter[]
*/
public function getAll(){
$rest = $this->getAuthService( self::API_PARENTAL_FILTER);
$rest->GET();
return $rest->getResultAsArray( models\ParentalControl\Filter::class);
}
/**
* @param int $filterId
* @return models\ParentalControl\Filter
*/
public function getFromId( $filterId){
$rest = $this->getAuthService( self::API_PARENTAL_FILTER . $filterId);
$rest->GET();
return $rest->getResult( models\ParentalControl\Filter::class);
}
/**
* @param models\ParentalControl\Filter $filter
* @return models\ParentalControl\Filter
*/
public function update( models\ParentalControl\Filter $filter){
$rest = $this->getAuthService( self::API_PARENTAL_FILTER . $filter->getId());
$rest->PUT( $filter);
return $rest->getResult( models\ParentalControl\Filter::class);
}
/**
* @param models\ParentalControl\Filter $filter
* @return bool
*/
public function delete( models\ParentalControl\Filter $filter){
return $this->deleteFromId( $filter->getId());
}
/**
* @param int $filterId
* @return bool
*/
public function deleteFromId( $filterId){
$rest = $this->getAuthService( self::API_PARENTAL_FILTER . $filterId);
$rest->DELETE();
return $rest->getSuccess();
}
/**
* @param models\ParentalControl\Filter $filter
* @return models\ParentalControl\Filter
*/
public function add( models\ParentalControl\Filter $filter){
$rest = $this->getAuthService( self::API_PARENTAL_FILTER);
$rest->POST( $filter);
return $rest->getResult( models\ParentalControl\Filter::class);
}
}

View File

@ -0,0 +1,39 @@
<?php
namespace alphayax\freebox\api\v3\services\ParentalControl;
use alphayax\freebox\api\v3\Service;
use alphayax\freebox\api\v3\models;
/**
* Class FilterPlanning
* @package alphayax\freebox\api\v3\services\ParentalControl
*/
class FilterPlanning extends Service {
const API_PARENTAL_FILTER_PLANNING = '/api/v3/parental/filter/%u/planning';
/**
* @param int $filterId
* @return models\ParentalControl\FilterPlanning
*/
public function getFromFilterId( $filterId) {
$service = sprintf( self::API_PARENTAL_FILTER_PLANNING, $filterId);
$rest = $this->getAuthService( $service);
$rest->GET();
return $rest->getResult( models\ParentalControl\FilterPlanning::class);
}
/**
* @param \alphayax\freebox\api\v3\models\ParentalControl\FilterPlanning $filterPlanning
* @param int $filterId
* @return \alphayax\freebox\api\v3\models\ParentalControl\FilterPlanning
*/
public function setFromFilterId( models\ParentalControl\FilterPlanning $filterPlanning, $filterId) {
$service = sprintf( self::API_PARENTAL_FILTER_PLANNING, $filterId);
$rest = $this->getAuthService( $service);
$rest->PUT( $filterPlanning);
return $rest->getResult( models\ParentalControl\FilterPlanning::class);
}
}

View File

@ -0,0 +1,18 @@
<?php
namespace alphayax\freebox\api\v3\symbols\ParentalControl;
/**
* Symbol FilterState
* @package alphayax\freebox\api\v3\symbols\ParentalControl
*/
interface FilterState {
/** access is allowed */
const ALLOWED = 'allowed';
/** access is denied */
const DENIED = 'denied';
/** access is granted only for HTTP and HTTPS traffic */
const WEB_ONLY = 'webonly';
}

View File

@ -0,0 +1,18 @@
<?php
namespace alphayax\freebox\api\v3\symbols\ParentalControl;
/**
* Symbol SchedulingMode
* @package alphayax\freebox\api\v3\symbols\ParentalControl
*/
interface SchedulingMode {
/** filter_state is forced to forced_mode */
const FORCED = 'forced';
/** filter_state is temporary set to tmp_mode for the next tmp_mode_expire seconds */
const TEMPORARY = 'temporary';
/** filter_state is set using the planning */
const PLANNING = 'planning';
}