Add VPN client API
This commit is contained in:
parent
a904a63039
commit
7dfe3790cf
|
@ -73,6 +73,7 @@ Jusqu'a présent, les fonctionalités suivantes ont été implémentées :
|
|||
- AV
|
||||
- IGD
|
||||
- VPN
|
||||
- Client
|
||||
- Server
|
||||
|
||||
|
||||
|
|
2
TODO.md
2
TODO.md
|
@ -36,7 +36,7 @@
|
|||
- Wi-Fi
|
||||
- ~~System~~
|
||||
- ~~VPN Server [UNSTABLE]~~
|
||||
- VPN Client [UNSTABLE]
|
||||
- ~~VPN Client [UNSTABLE]~~
|
||||
- Storage
|
||||
- Storage API [UNSTABLE]
|
||||
- Parental filter
|
||||
|
|
|
@ -27,3 +27,16 @@ $CnxService = new \alphayax\freebox\api\v3\services\config\VPN\Server\Connection
|
|||
$connections = $CnxService->getAll();
|
||||
print_r( $connections);
|
||||
*/
|
||||
|
||||
/*
|
||||
$VPNClientService = new \alphayax\freebox\api\v3\services\config\VPN\Client\Config( $App);
|
||||
$VPNClientConfigurations = $VPNClientService->getAll();
|
||||
print_r( $VPNClientConfigurations);
|
||||
|
||||
$VPNClientStatus = new \alphayax\freebox\api\v3\services\config\VPN\Client\Status( $App);
|
||||
$VPNStatus = $VPNClientStatus->getStatus();
|
||||
print_r( $VPNStatus);
|
||||
|
||||
$VPNLogs = $VPNClientStatus->getLogs();
|
||||
print_r( $VPNLogs);
|
||||
*/
|
|
@ -0,0 +1,101 @@
|
|||
<?php
|
||||
namespace alphayax\freebox\api\v3\models\VPN\Client\Config;
|
||||
use alphayax\freebox\api\v3\Model;
|
||||
|
||||
/**
|
||||
* Class ClientConfig
|
||||
* @package alphayax\freebox\api\v3\models\VPN\Client\Config
|
||||
*/
|
||||
class ClientConfig extends Model {
|
||||
|
||||
/** @var string (Read-only) : VPN config id */
|
||||
protected $id;
|
||||
|
||||
/** @var string : VPN description */
|
||||
protected $description;
|
||||
|
||||
/**
|
||||
* @var string : VPN server type
|
||||
* @see alphayax\freebox\api\v3\symbols\VPN\ServerConfig\Type
|
||||
**/
|
||||
protected $type;
|
||||
|
||||
/** @var bool : is this configuration active. Only one configuration is active at a time. */
|
||||
protected $active;
|
||||
|
||||
/** @var PPTPConfig : only available when type is PPTP */
|
||||
protected $conf_pptp;
|
||||
|
||||
/**
|
||||
* ServerConfig constructor.
|
||||
* @param array $properties_x
|
||||
*/
|
||||
public function __construct( array $properties_x){
|
||||
parent::__construct( $properties_x);
|
||||
$this->initProperty( 'conf_pptp' , PPTPConfig::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getId() {
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getDescription() {
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $description
|
||||
*/
|
||||
public function setDescription( $description) {
|
||||
$this->description = $description;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getType() {
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $type
|
||||
*/
|
||||
public function setType( $type) {
|
||||
$this->type = $type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return boolean
|
||||
*/
|
||||
public function isActive() {
|
||||
return $this->active;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param boolean $active
|
||||
*/
|
||||
public function setActive( $active) {
|
||||
$this->active = $active;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \alphayax\freebox\api\v3\models\VPN\Client\Config\PPTPConfig
|
||||
*/
|
||||
public function getConfPptp() {
|
||||
return $this->conf_pptp;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \alphayax\freebox\api\v3\models\VPN\Client\Config\PPTPConfig $conf_pptp
|
||||
*/
|
||||
public function setConfPptp( $conf_pptp) {
|
||||
$this->conf_pptp = $conf_pptp;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,98 @@
|
|||
<?php
|
||||
namespace alphayax\freebox\api\v3\models\VPN\Client\Config;
|
||||
use alphayax\freebox\api\v3\Model;
|
||||
|
||||
/**
|
||||
* Class PPTPConfig
|
||||
* @package alphayax\freebox\api\v3\models\VPN\Client\Config
|
||||
*/
|
||||
class PPTPConfig extends Model {
|
||||
|
||||
/** @var string : remote host IP or name */
|
||||
protected $remote_host;
|
||||
|
||||
/** @var string : VPN username */
|
||||
protected $username;
|
||||
|
||||
/** @var string (Write-only) : VPN password */
|
||||
protected $password;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
* @see alphayax\freebox\api\v3\symbols\VPN\PPTPConfig\Mppe
|
||||
*/
|
||||
protected $mppe;
|
||||
|
||||
/** @var bool[] : allowed authentication methods */
|
||||
protected $allowed_auth = [
|
||||
'eap' => false,
|
||||
'pap' => false,
|
||||
'chap' => false,
|
||||
'mschapv' => false,
|
||||
'mschapv2' => false,
|
||||
];
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getRemoteHost() {
|
||||
return $this->remote_host;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $remote_host
|
||||
*/
|
||||
public function setRemoteHost($remote_host) {
|
||||
$this->remote_host = $remote_host;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getUsername() {
|
||||
return $this->username;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $username
|
||||
*/
|
||||
public function setUsername($username) {
|
||||
$this->username = $username;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $password
|
||||
*/
|
||||
public function setPassword($password) {
|
||||
$this->password = $password;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getMppe() {
|
||||
return $this->mppe;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $mppe
|
||||
*/
|
||||
public function setMppe($mppe) {
|
||||
$this->mppe = $mppe;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \bool[]
|
||||
*/
|
||||
public function getAllowedAuth() {
|
||||
return $this->allowed_auth;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \bool[] $allowed_auth
|
||||
*/
|
||||
public function setAllowedAuth($allowed_auth) {
|
||||
$this->allowed_auth = $allowed_auth;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,94 @@
|
|||
<?php
|
||||
namespace alphayax\freebox\api\v3\models\VPN\Client;
|
||||
use alphayax\freebox\api\v3\Model;
|
||||
|
||||
/**
|
||||
* Class IpInfo
|
||||
* @package alphayax\freebox\api\v3\models\VPN\Client
|
||||
*/
|
||||
class IpInfo extends Model {
|
||||
|
||||
/** @var bool (Read-only) : is the configuration valid */
|
||||
protected $config_valid;
|
||||
|
||||
/** @var array (Read-only) : assigned IP and netmask */
|
||||
protected $ip_mask;
|
||||
|
||||
/** @var string (Read-only) : provided domain */
|
||||
protected $domain;
|
||||
|
||||
/** @var string IPv4 (Read-only) : provided gateway */
|
||||
protected $gateway;
|
||||
|
||||
/** @var array of ipv4 (Read-only) : list of dns servers */
|
||||
protected $dns;
|
||||
|
||||
/**
|
||||
* @var string (Read-only) : ip_mask source
|
||||
* @see Provider
|
||||
*/
|
||||
protected $provider;
|
||||
|
||||
/** @var array (Read-only) : list of provided routes */
|
||||
protected $routes;
|
||||
|
||||
/** @var array (Read-only) : DHCP status information */
|
||||
protected $dhcp;
|
||||
|
||||
/**
|
||||
* @return boolean
|
||||
*/
|
||||
public function isConfigValid() {
|
||||
return $this->config_valid;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getIpMask() {
|
||||
return $this->ip_mask;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getDomain() {
|
||||
return $this->domain;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getGateway() {
|
||||
return $this->gateway;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getDns() {
|
||||
return $this->dns;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getProvider() {
|
||||
return $this->provider;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getRoutes() {
|
||||
return $this->routes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getDhcp() {
|
||||
return $this->dhcp;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
<?php
|
||||
namespace alphayax\freebox\api\v3\models\VPN\Client;
|
||||
use alphayax\freebox\api\v3\Model;
|
||||
|
||||
/**
|
||||
* Class Stats
|
||||
* @package alphayax\freebox\api\v3\models\VPN\Client
|
||||
*/
|
||||
class Stats extends Model {
|
||||
|
||||
/** @var int (Read-only) : current upload rate (in byte/s) */
|
||||
protected $rate_up;
|
||||
|
||||
/** @var int (Read-only) : current download rate (in byte/s) */
|
||||
protected $rate_down;
|
||||
|
||||
/** @var int (Read-only) : total bytes uploaded */
|
||||
protected $bytes_up;
|
||||
|
||||
/** @var int (Read-only) : total bytes downloaded */
|
||||
protected $bytes_down;
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getRateUp() {
|
||||
return $this->rate_up;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getRateDown() {
|
||||
return $this->rate_down;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getBytesUp() {
|
||||
return $this->bytes_up;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getBytesDown() {
|
||||
return $this->bytes_down;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,151 @@
|
|||
<?php
|
||||
namespace alphayax\freebox\api\v3\models\VPN\Client;
|
||||
use alphayax\freebox\api\v3\Model;
|
||||
|
||||
/**
|
||||
* Class Status
|
||||
* @package alphayax\freebox\api\v3\models\VPN\Client
|
||||
*/
|
||||
class Status extends Model {
|
||||
|
||||
/** @var bool (Read-only) : is VPN client enabled */
|
||||
protected $enabled;
|
||||
|
||||
/** @var string (Read-only) : active VPN id */
|
||||
protected $active_vpn;
|
||||
|
||||
/** @var string (Read-only) : active VPN description */
|
||||
protected $active_vpn_description;
|
||||
|
||||
/**
|
||||
* @var string (Read-only) : active VPN type
|
||||
* @see alphayax\freebox\api\v3\symbols\VPN\Server\Type
|
||||
*/
|
||||
protected $type;
|
||||
|
||||
/**
|
||||
* @var string (Read-only)
|
||||
* @see \alphayax\freebox\api\v3\symbols\VPN\ClientStatus\State
|
||||
*/
|
||||
protected $state;
|
||||
|
||||
/** @var int (Read-only) : timestamp of last successfull connection */
|
||||
protected $last_up;
|
||||
|
||||
/** @var int (Read-only) : timestamp of last connection attempt */
|
||||
protected $last_try;
|
||||
|
||||
/** @var int (Read-only) : seconds left until next connection attempt */
|
||||
protected $next_try;
|
||||
|
||||
/**
|
||||
* @var string (Read-only)
|
||||
* none no error
|
||||
* internal internal error
|
||||
* authentication_failed wrong credentials
|
||||
* auth_failed wrong credentials
|
||||
* resolv_failed invalid host name
|
||||
* connect_timeout connection timeout
|
||||
* connect_failed connection failed
|
||||
* setup_control_failed PPTP session negociation failure
|
||||
* setup_call_failed PPTP session failure
|
||||
* protocol protocol error
|
||||
* remote_terminated connection closed by remote peer
|
||||
* remote_disconnect connection closed by remote peer
|
||||
*/
|
||||
protected $last_error;
|
||||
|
||||
/** @var Stats (Read-only) : connection statistics */
|
||||
protected $stats;
|
||||
|
||||
/** @var IpInfo (Read-only) : connection IPv4 information */
|
||||
protected $IPv4;
|
||||
|
||||
/**
|
||||
* Status constructor.
|
||||
* @param array $properties_x
|
||||
*/
|
||||
public function __construct( array $properties_x){
|
||||
parent::__construct( $properties_x);
|
||||
$this->initProperty( 'stats', Stats::class);
|
||||
$this->initProperty( 'IPv4' , IpInfo::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return boolean
|
||||
*/
|
||||
public function isEnabled() {
|
||||
return $this->enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getActiveVpn() {
|
||||
return $this->active_vpn;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getActiveVpnDescription() {
|
||||
return $this->active_vpn_description;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getType() {
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getState() {
|
||||
return $this->state;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getLastUp() {
|
||||
return $this->last_up;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getLastTry() {
|
||||
return $this->last_try;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getNextTry() {
|
||||
return $this->next_try;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getLastError() {
|
||||
return $this->last_error;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \alphayax\freebox\api\v3\models\VPN\Client\Stats
|
||||
*/
|
||||
public function getStats() {
|
||||
return $this->stats;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \alphayax\freebox\api\v3\models\VPN\Client\IpInfo
|
||||
*/
|
||||
public function getIPv4() {
|
||||
return $this->IPv4;
|
||||
}
|
||||
|
||||
}
|
|
@ -17,9 +17,9 @@ class PPTPConfig extends Model {
|
|||
|
||||
/** @var bool[] : allowed authentication methods */
|
||||
protected $allowed_auth = [
|
||||
'pap' => null,
|
||||
'chap' => null,
|
||||
'mschapv2' => null,
|
||||
'pap' => false,
|
||||
'chap' => false,
|
||||
'mschapv2' => false,
|
||||
];
|
||||
|
||||
/**
|
||||
|
|
|
@ -0,0 +1,77 @@
|
|||
<?php
|
||||
namespace alphayax\freebox\api\v3\services\config\VPN\Client;
|
||||
use alphayax\freebox\api\v3\Service;
|
||||
use alphayax\freebox\api\v3\models;
|
||||
|
||||
/**
|
||||
* Class Config
|
||||
* @package alphayax\freebox\api\v3\services\config\VPN\Client
|
||||
*/
|
||||
class Config extends Service {
|
||||
|
||||
const API_VPN_CLIENT_CONFIG = '/api/v3/vpn_client/config/';
|
||||
|
||||
/**
|
||||
* Get VPN Client configuration list
|
||||
* @return models\VPN\Client\Config\ClientConfig[]
|
||||
*/
|
||||
public function getAll(){
|
||||
$rest = $this->getAuthService( self::API_VPN_CLIENT_CONFIG);
|
||||
$rest->GET();
|
||||
|
||||
return $rest->getResultAsArray( models\VPN\Client\Config\ClientConfig::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $configId
|
||||
* @return models\VPN\Client\Config\ClientConfig
|
||||
*/
|
||||
public function getFromId( $configId) {
|
||||
$rest = $this->getAuthService( self::API_VPN_CLIENT_CONFIG . $configId);
|
||||
$rest->GET();
|
||||
|
||||
return $rest->getResult( models\VPN\Client\Config\ClientConfig::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param models\VPN\Client\Config\ClientConfig $config
|
||||
* @return models\VPN\Client\Config\ClientConfig
|
||||
*/
|
||||
public function add( models\VPN\Client\Config\ClientConfig $config) {
|
||||
$rest = $this->getAuthService( self::API_VPN_CLIENT_CONFIG);
|
||||
$rest->POST( $config->toArray());
|
||||
|
||||
return $rest->getResult( models\VPN\Client\Config\ClientConfig::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param models\VPN\Client\Config\ClientConfig $config
|
||||
* @return models\VPN\Client\Config\ClientConfig
|
||||
*/
|
||||
public function delete( models\VPN\Client\Config\ClientConfig $config) {
|
||||
return $this->deleteFromId( $config->getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $configId
|
||||
* @return models\VPN\Client\Config\ClientConfig
|
||||
*/
|
||||
public function deleteFromId( $configId) {
|
||||
$rest = $this->getAuthService( self::API_VPN_CLIENT_CONFIG . $configId);
|
||||
$rest->DELETE();
|
||||
|
||||
return $rest->getSuccess();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param models\VPN\Client\Config\ClientConfig $config
|
||||
* @return models\VPN\Client\Config\ClientConfig
|
||||
*/
|
||||
public function update( models\VPN\Client\Config\ClientConfig $config) {
|
||||
$rest = $this->getAuthService( self::API_VPN_CLIENT_CONFIG. $config->getId());
|
||||
$rest->PUT( $config->toArray());
|
||||
|
||||
return $rest->getResult( models\VPN\Client\Config\ClientConfig::class);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
namespace alphayax\freebox\api\v3\services\config\VPN\Client;
|
||||
use alphayax\freebox\api\v3\Service;
|
||||
use alphayax\freebox\api\v3\models;
|
||||
|
||||
/**
|
||||
* Class Status
|
||||
* @package alphayax\freebox\api\v3\services\config\VPN\Client
|
||||
*/
|
||||
class Status extends Service {
|
||||
|
||||
const API_VPN_CLIENT_STATUS = '/api/v3/vpn_client/status';
|
||||
const API_VPN_CLIENT_LOGS = '/api/v3/vpn_client/log';
|
||||
|
||||
/**
|
||||
* Get the VPN client status
|
||||
* @return models\VPN\Client\Status
|
||||
*/
|
||||
public function getStatus(){
|
||||
$rest = $this->getAuthService( self::API_VPN_CLIENT_STATUS);
|
||||
$rest->GET();
|
||||
|
||||
return $rest->getResult( models\VPN\Client\Status::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the VPN client Logs
|
||||
* @return models\VPN\Client\Status
|
||||
*/
|
||||
public function getLogs(){
|
||||
$rest = $this->getAuthService( self::API_VPN_CLIENT_LOGS);
|
||||
$rest->GET();
|
||||
|
||||
return $rest->getResult();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
namespace alphayax\freebox\api\v3\symbols\VPN\ClientStatus;
|
||||
|
||||
/**
|
||||
* Symbol State
|
||||
* @package alphayax\freebox\api\v3\symbols\VPN\ClientStatus
|
||||
*/
|
||||
interface State {
|
||||
|
||||
/** waiting for wan connection */
|
||||
const WAITING_WAN = 'waiting_wan';
|
||||
|
||||
/** connection is initializing */
|
||||
const GOING_UP = 'going_up';
|
||||
|
||||
/** connection is active */
|
||||
const UP = 'up';
|
||||
|
||||
/** connection is about to become inactive */
|
||||
const GOING_DOWN = 'going_down';
|
||||
|
||||
/** connection is inactive */
|
||||
const DOWN = 'down';
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
namespace alphayax\freebox\api\v3\symbols\VPN\IpInfo;
|
||||
|
||||
/**
|
||||
* Symbol Provider
|
||||
* @package alphayax\freebox\api\v3\symbols\VPN\IpInfo
|
||||
* @see alphayax\freebox\api\v3\models\VPN\Client\IpInfo
|
||||
*/
|
||||
interface Provider {
|
||||
|
||||
/** none */
|
||||
const NONE = 'none';
|
||||
/** static IP configuration */
|
||||
const STATIC_ = 'static';
|
||||
/** ppp */
|
||||
const PPP = 'ppp';
|
||||
/** DHCP server */
|
||||
const DHCP = 'dhcp';
|
||||
}
|
Loading…
Reference in New Issue