Skip to content

Commit

Permalink
magic methods, some works on modules (doc, methods)
Browse files Browse the repository at this point in the history
  • Loading branch information
jvntetlkhuiuefshfe committed Feb 4, 2013
1 parent adc9183 commit a949140
Show file tree
Hide file tree
Showing 7 changed files with 197 additions and 91 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
var
var/*
php/cookie.txt
*cookie.txt

43 changes: 33 additions & 10 deletions php/lib/Dhcp.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,32 @@
Dhcp : Serveur DHCP : Fonctions permettant d'interagir avec le serveur DHCP.
dhcp.status_get
dhcp.leases_get
dhcp.sleases_get
dhcp.config_get -> params
dhcp.config_set (params)
dhcp.slease_add (mac, ip, comment)
dhcp.slease_del (mac)
dhcp.status_get : Retourne l'état du serveur dhcp.
dhcp.leases_get : Retourne la liste des baux DHCP courants.
dhcp.sleases_get : Retourne la liste des baux statiques configurés.
dhcp.config_get -> dhcp-config : récupère la configuration du serveur DHCP
dhcp.config_set (dhcp-config) : Modifie la configuration du serveur DHCP
dhcp.slease_add (mac, ip, comment) : ajoute un bail statique
dhcp.slease_del (mac) : Supprime un bail statique
dhcp-config:
[enabled] => bool
[sticky_assign] => bool
[ip_range] => Array
(
[0] => ip-start
[1] => ip-end
)
[netmask] => net-mask
[gateway] => ip
[always_broadcast] => bool
[dns] => Array
(
[0] => ip1
)
*/

class Dhcp {
Expand Down Expand Up @@ -39,8 +58,12 @@ public function config_get(){
public function config_set($params){
return $this->fb->exec('dhcp.config_set', $params);
}

# dhcp.slease_add (mac, ip, comment)
# dhcp.slease_del (mac)

public function slease_add($mac, $ip, $comment){
return $this->fb->exec('dhcp.slease_add', array($mac, $ip, $comment));
}
public function slease_del($mac){
return $this->fb->exec('dhcp.slease_del', $mac);
}
}
?>
38 changes: 27 additions & 11 deletions php/lib/Ftp.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,22 @@

/* author : Marc Quinton, février 2013, licence : http://fr.wikipedia.org/wiki/WTFPL
FTP
FTP : Fonctions permettant d'interagir avec le serveur FTP.
Types :
ftp_config
enabled booléen Le serveur est activé ou non.
allow_anonymous booléen Les connections anonymes sont autorisées en lecture seule.
allow_anonymous_write booléen De plus, les invitées ont le droit d'écrire.
Méthodes
- ftp.get_config () Récupére la configuration du serveur ftp.
retour: Un objet de type ftp_config.
ftp-config
- enabled booléen Le serveur est activé ou non.
- allow_anonymous booléen Les connections anonymes sont autorisées en lecture seule.
- allow_anonymous_write booléen De plus, les invitées ont le droit d'écrire.
Méthodes:
ftp.get_config (config:ftp-config) Récupére la configuration du serveur ftp.
ftp.set_config (config:ftp-config) Change la configuration du serveur ftp.
- ftp.set_config (cfg) Change la configuration du serveur ftp.
- paramêtres en entrée:
- cfg ftp_config
*/

Expand All @@ -34,5 +36,19 @@ public function set_config($cfg){
}
}

/*
usage :
$freebox = new Mafreebox('http://mafreebox.freebox.fr', 'freebox', 'mon.mdp');
print_r($cnf = $freebox->ftp->get_config());
# $cnf['enabled'] = 1;
# $cnf['allow_anonymous'] = 1;
# $cnf['allow_anonymous_write'] = 1;
# $cnf['password'] = '123456';
$cnf = $freebox->ftp->get_config($cnf);
*/

?>
48 changes: 20 additions & 28 deletions php/lib/Mafreebox.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@
$url = '';
$file = '';
$freebox->download()->http_add($file, $url));
$freebox->download->http_add($file, $url));
# rebooter la freebox
$freebox->system()->reboot();
$freebox->system->reboot();
?>
Expand Down Expand Up @@ -69,11 +69,12 @@ class Mafreebox {

private $cookie;

protected $dhcp;
protected $download;
protected $ftp;
protected $system;
protected $phone;
protected $modules = array();
# protected $dhcp;
# protected $download;
# protected $ftp;
# protected $system;
# protected $phone;

/**
* Constructeur classique
Expand All @@ -89,13 +90,12 @@ public function __construct($uri, $login, $password) {

// Connexion automatique puis récupération du cookie.
$this->cookies = $this->login($this->login, $this->password);

# sub-classes for each services.
$this->dhcp = new Dhcp($this);
$this->download = new Download($this);
$this->ftp = new Ftp($this);
$this->system = new System($this);
$this->phone = new Phone($this);

$this->modules['dhcp'] = new Dhcp($this);
$this->modules['download'] = new Download($this);
$this->modules['ftp'] = new Ftp($this);
$this->modules['system'] = new System($this);
$this->modules['phone'] = new Phone($this);
}

/**
Expand Down Expand Up @@ -188,20 +188,12 @@ public function debug(){
# ...
}

public function dhcp(){
return $this->dhcp;
}
public function download(){
return $this->download;
}
public function ftp(){
return $this->ftp;
}
public function system(){
return $this->system;
}
public function phone(){
return $this->phone;
# allow magic acces : $freebox->module->method()
public function __get($name){
if(array_key_exists($name, $this->modules))
return $this->modules[$name];
else
throw new Exception ("module $name does't exists");
}
}
/* Subclasses with all JSON services.
Expand Down
61 changes: 55 additions & 6 deletions php/lib/Phone.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,61 @@
Phone : Téléphonie : Contrôle de la ligne téléphonique analogique et de la base DECT.
phone.status
phone.fxs_ring
phone.dect_paging
phone.dect_registration_set
phone.dect_params_set
phone.dect_delete
methods :
phone.status : Récupère l'état du matériel et de la ligne téléphonique.
phone.fxs_ring(active:bool) : Active/désactive la sonnerie du combiné de la ligne analogique.
phone.dect_paging(active:bool) : Active la recherche (sonnerie) de satellites DECT.
phone.dect_registration_set(active:bool) : Active ou désactive l'association de la base DECT de la freebox.
phone.dect_params_set(params) : Modifie les réglages d'enregistrement dect DECT
phone.dect_delete(id): Supprime les associations de tous les satellites de la base DECT de la freebox.
data types :
fxs-status:
- initializing En cours d'initialisation.
- working Fonctionnement normal.
- error Problème logiciel ou matériel empêchant la ligne de fonctionner.
mgcp-status:
- waiting Attend l'activation de la connexion internet, ou d'une configuration valide pour pouvoir se connecter aux serveurs.
- connecting En cours de connexion aux serveurs.
- working Fonctionnement normal.
- error Une erreur empêche la ligne de fonctionner (serveurs injoignable, mauvaise configuration, ...)
dect-params:
- enabled] => bool
- nemo_mode] =>
- ring_on_off] => bool
- eco_mode] =>
- pin] => 1234 (code pin)
- registration =>
- ring_type => int
phone-status :
(
[mgcp] => Array (ligne VOIP)
(
[status] => mgp-status
)
[fxs] => Array (ligne analogique)
(
[is_ringing] => boold
[hook] => on|off (état du combiné)
[status] => fxs-status
[gain_tx] => int
[gain_rx] => int
)
[dects] => Array (liste des téléphones DECT déclarés)
(
)
[dect] => dect-params
)
*/

class Phone {
Expand Down
3 changes: 3 additions & 0 deletions php/lib/System.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ public function uptime_get(){
public function mac_address_get(){
return $this->fb->exec('systeme.mac_address_get');
}
public function serial_get(){
return $this->fb->exec('systeme.serial');
}
public function reboot($timeout){
return $this->fb->exec('systeme.reboot', $timeout);
}
Expand Down
92 changes: 56 additions & 36 deletions php/test-mafreebox.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,23 +50,11 @@ function file_rotate($file, $count, $dir='var/'){
$config = array(
'url' => 'http://mafreebox.freebox.fr/',
'user' => 'freebox',
'password' => '123456'
'password' => '123456' # your password
);

$freebox = new Mafreebox($config['url'], $config['user'], $config['password']);

print_r($freebox->exec('conn.status')); exit(0);
# print_r($freebox->exec('system.fw_release_get')); exit(0);
# print_r($freebox->reboot()); exit(0);
# print_r($freebox->exec( 'fs.list', array('/'))); exit(0);
# print_r($freebox->exec( 'fs.list', array('/Disque dur/'))); exit(0);

// Listons le contenu du disque dur interne de la Freebox.
# $contenu = $freebox->exec( 'fs.list', array('/Disque dur/Enregistrements') );
# print_r($contenu);

# print_r($freebox->exec( 'conn.logs' ));


/*
period = {hour|day|week}
Expand Down Expand Up @@ -108,43 +96,75 @@ function rrd_hourly($freebox){
rrd_weekly($freebox);
break;

case 'test':
case 'debug':
# $freebox->debug();
# print_r($freebox->dhcp()->status_get());
# print_r($freebox->dhcp()->leases_get());
# print_r($freebox->dhcp()->sleases_get());
# print_r($freebox->download()->_list());


case 'json':
case 'json-exec':
case 'exec':
print_r($freebox->exec('conn.status'));
break;

case 'dhcp':
print_r($cnf = $freebox->dhcp->config_get());
# print_r($cnf = $freebox->dhcp->config_set($cnf));
print_r($freebox->dhcp->status_get());
print_r($freebox->dhcp->leases_get());
print_r($freebox->dhcp->sleases_get());
break;

case 'system':
print_r($freebox->system->uptime_get());
print_r($freebox->system->mac_address_get());
print_r($freebox->system->fw_release_get());
# print_r($freebox->phone->reboot($timeout=60));
break;

case 'phone':
# print_r($freebox->phone->fxs_ring(true)); sleep (3);
# var_dump($freebox->phone->fxs_ring(false));
print_r($freebox->phone->status());
break;

case 'ftp':
print_r($cnf = $freebox->ftp->get_config());
# $cnf['enabled'] = 1;
# $cnf['allow_anonymous'] = 1;
# $cnf['allow_anonymous_write'] = 1;
# $cnf['password'] = '123456';
# $cnf = $freebox->ftp->get_config($cnf);
break;

case 'download':

print_r($freebox->download->_list());

$args = array(
'max_up' => 90,
'download_dir' => '/Disque dur/Téléchargements',
'max_dl' => 2234,
'max_peer' => 240,
'seed_ratio' => 2
);
# print_r($freebox->download()->http_add('ubuntu.iso', 'ftp://ftp.free.fr/mirrors/ftp.ubuntu.com/releases/12.10/ubuntu-12.10-desktop-i386.iso'));
print_r($freebox->download()->_list());
# print_r($freebox->download->http_add('ubuntu.iso', 'ftp://ftp.free.fr/mirrors/ftp.ubuntu.com/releases/12.10/ubuntu-12.10-desktop-i386.iso'));
print_r($freebox->download->_list());
$id = 849;
$type='http';
# print_r($freebox->download()->stop($type, $id));
# print_r($freebox->download()->start($type, $id));
# print_r($freebox->download()->remove($type, $id));
# print_r($freebox->download->stop($type, $id));
# print_r($freebox->download->start($type, $id));
# print_r($freebox->download->remove($type, $id));
$url = 'http://ftp.free.fr/mirrors/ftp.ubuntu.com/releases/12.10/ubuntu-12.10-desktop-armhf%2bomap4.img.torrent';
print_r($freebox->download()->torrent_add($url));
print_r($freebox->download->torrent_add($url));

# print_r($freebox->download()->config_get());
# print_r($freebox->download()->config_set($args));
# print_r($freebox->download->config_get());
# print_r($freebox->download->config_set($args));
break;

# print_r($cfg = $freebox->ftp()->get_config());
# print_r($freebox->ftp()->set_config($cfg));
case 'test':
case 'debug':
# $freebox->debug();

# print_r($freebox->system()->uptime_get());
# print_r($freebox->system()->mac_address_get());
# print_r($freebox->system()->fw_release_get());

# print_r($freebox->phone()->fxs_ring(false));

# print_r($cfg = $freebox->ftp->get_config());
# print_r($freebox->ftp->set_config($cfg));

break;
}
Expand Down

0 comments on commit a949140

Please sign in to comment.