Add some PHPDoc comments for ease of programming #87
|
@ -257,11 +257,17 @@ class FormPage {
|
||||||
class FormField {
|
class FormField {
|
||||||
protected $value = null;
|
protected $value = null;
|
||||||
protected $error = null;
|
protected $error = null;
|
||||||
|
/** @var string|null $label */
|
||||||
protected $label = null;
|
protected $label = null;
|
||||||
|
/** @var string|null $name */
|
||||||
protected $name = null;
|
protected $name = null;
|
||||||
|
/** @var string|null $css_class */
|
||||||
protected $css_class = null;
|
protected $css_class = null;
|
||||||
|
/** @var bool|null $read_only */
|
||||||
protected $read_only = null;
|
protected $read_only = null;
|
||||||
|
/** @var bool|null $disabled True if the field is supposed to be disabled */
|
||||||
protected $disabled = null;
|
protected $disabled = null;
|
||||||
|
/** @var array|null $storage */
|
||||||
private $storage = NULL;
|
private $storage = NULL;
|
||||||
|
|
||||||
protected function __construct($label) {
|
protected function __construct($label) {
|
||||||
|
|
|
@ -31,6 +31,12 @@ else {
|
||||||
$cache = $conf['cache'];
|
$cache = $conf['cache'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new domain (local only)
|
||||||
|
* @param FormPage $form
|
||||||
|
* @param string $admin_mail
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
function web_add($form, $admin_mail) {
|
function web_add($form, $admin_mail) {
|
||||||
global $conf;
|
global $conf;
|
||||||
|
|
||||||
|
@ -84,6 +90,12 @@ function web_add($form, $admin_mail) {
|
||||||
return array($exec_cmd, $exec_return, $exec_output);
|
return array($exec_cmd, $exec_return, $exec_output);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new domain (cluster only)
|
||||||
|
* @param FormPage $form
|
||||||
|
* @param string $admin_mail
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
function web_add_cluster($form, $admin_mail) {
|
function web_add_cluster($form, $admin_mail) {
|
||||||
global $cache;
|
global $cache;
|
||||||
global $conf;
|
global $conf;
|
||||||
|
|
|
@ -16,6 +16,12 @@
|
||||||
/**
|
/**
|
||||||
* Functions
|
* Functions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if a file exists and is readable and `die()` if it doesnt.
|
||||||
|
* @param string $file
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
function test_exist($file) {
|
function test_exist($file) {
|
||||||
if(!file_exists($file)) {
|
if(!file_exists($file)) {
|
||||||
die("Erreur, vous devez mettre en place le fichier $file !\n");
|
die("Erreur, vous devez mettre en place le fichier $file !\n");
|
||||||
|
@ -25,11 +31,20 @@ function test_exist($file) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Redirect the page to $path on the same HOST
|
||||||
|
* @param string $path
|
||||||
|
* @return never
|
||||||
|
*/
|
||||||
function http_redirect($path) {
|
function http_redirect($path) {
|
||||||
header('Location: '.$_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['HTTP_HOST'].$path);
|
header('Location: '.$_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['HTTP_HOST'].$path);
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $filename
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
function findexts ($filename)
|
function findexts ($filename)
|
||||||
{
|
{
|
||||||
$filename = strtolower($filename) ;
|
$filename = strtolower($filename) ;
|
||||||
|
@ -39,15 +54,26 @@ function findexts ($filename)
|
||||||
return $exts;
|
return $exts;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the user is a superadmin
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
function is_superadmin() {
|
function is_superadmin() {
|
||||||
global $conf;
|
global $conf;
|
||||||
if(!empty($_SESSION['user']) && in_array($_SESSION['user'], $conf['superadmin'])) {
|
if(!empty($_SESSION['user']) && in_array($_SESSION['user'], $conf['superadmin'])) {
|
||||||
return 1;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return 0;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute a command with sudo
|
||||||
|
* @param string $cmd The command that will be executed.
|
||||||
|
* @param array $output output of the command.
|
||||||
|
* @param int $return_var return status of the command.
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
function sudoexec($cmd, &$output, &$return_var) {
|
function sudoexec($cmd, &$output, &$return_var) {
|
||||||
global $conf;
|
global $conf;
|
||||||
|
|
||||||
|
@ -60,7 +86,8 @@ function sudoexec($cmd, &$output, &$return_var) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return TRUE is Evoadmin is installed in cluster mode.
|
* Check if Evoadmin is installed in cluster mode
|
||||||
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
function is_cluster_mode() {
|
function is_cluster_mode() {
|
||||||
global $conf;
|
global $conf;
|
||||||
|
@ -68,7 +95,8 @@ function is_cluster_mode() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return TRUE is Evoadmin is installed in multi-cluster mode.
|
* Check if Evoadmin is installed in multi-cluster mode.
|
||||||
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
function is_mcluster_mode() {
|
function is_mcluster_mode() {
|
||||||
global $conf;
|
global $conf;
|
||||||
|
@ -77,6 +105,8 @@ function is_mcluster_mode() {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load config file for the specified cluster.
|
* Load config file for the specified cluster.
|
||||||
|
* @param string $cluster
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
function load_config_cluster($cluster) {
|
function load_config_cluster($cluster) {
|
||||||
global $conf;
|
global $conf;
|
||||||
|
@ -87,8 +117,7 @@ function load_config_cluster($cluster) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return wether or not this evoadmin install is a multi PHP install
|
* Check if evoadmin install is a multi PHP install
|
||||||
*
|
|
||||||
* @return boolean - True when it's a multi PHP system
|
* @return boolean - True when it's a multi PHP system
|
||||||
*/
|
*/
|
||||||
function is_multiphp() {
|
function is_multiphp() {
|
||||||
|
@ -97,9 +126,9 @@ function is_multiphp() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Webadd
|
* Webadd
|
||||||
*
|
* @param string $command webadd command to run
|
||||||
* @return boolean - True when it's a multi PHP system
|
* @return array output from the command
|
||||||
*/
|
*/
|
||||||
function run_webadd_cmd($command) {
|
function run_webadd_cmd($command) {
|
||||||
global $conf;
|
global $conf;
|
||||||
|
@ -127,6 +156,11 @@ if (!(ini_set('include_path', ini_get('include_path')))) {
|
||||||
require_once 'PEAR.php';
|
require_once 'PEAR.php';
|
||||||
require_once 'Log.php';
|
require_once 'Log.php';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* (simply there to silence a warning)
|
||||||
|
* @var array $oriconf
|
||||||
|
* @var array $localconf
|
||||||
|
*/
|
||||||
// config files
|
// config files
|
||||||
// (here because need Log PEAR lib)
|
// (here because need Log PEAR lib)
|
||||||
test_exist('../conf/connect.php');
|
test_exist('../conf/connect.php');
|
||||||
|
|
|
@ -229,6 +229,12 @@ if ($action=="add") {
|
||||||
$_SESSION['error']=null;
|
$_SESSION['error']=null;
|
||||||
$_SESSION['form']=null;
|
$_SESSION['form']=null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Format Byte representation in human readable format (power of 1024)
|
||||||
|
* @param float|int $bytes
|
||||||
|
* @param int|null $precision
|
||||||
|
* @return string Human formatted amount of bytes
|
||||||
|
*/
|
||||||
function formatBytes($bytes, $precision = 2) {
|
function formatBytes($bytes, $precision = 2) {
|
||||||
$bytes *= 1024;
|
$bytes *= 1024;
|
||||||
$units = array('o', 'Ko', 'Mo', 'Go', 'To');
|
$units = array('o', 'Ko', 'Mo', 'Go', 'To');
|
||||||
|
@ -242,7 +248,9 @@ function formatBytes($bytes, $precision = 2) {
|
||||||
return round($bytes, $precision) . ' ' . $units[$pow];
|
return round($bytes, $precision) . ' ' . $units[$pow];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string[]
|
||||||
|
*/
|
||||||
function get_owner_list() {
|
function get_owner_list() {
|
||||||
$owner_list = array();
|
$owner_list = array();
|
||||||
|
|
||||||
|
|
34
lib/bdd.php
34
lib/bdd.php
|
@ -1,7 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @desc mini class to manipulate sqlite db for evocluster.
|
* mini class to manipulate sqlite db for evocluster.
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* <?php
|
* <?php
|
||||||
|
@ -43,7 +43,7 @@ class bdd {
|
||||||
private $db; /* resource of a created database */
|
private $db; /* resource of a created database */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @desc Open a sqlite database in rw mode. Create it if it doesn't exist.
|
* Open a sqlite database in rw mode. Create it if it doesn't exist.
|
||||||
* @param string $db_name Name of the sqlite database
|
* @param string $db_name Name of the sqlite database
|
||||||
*/
|
*/
|
||||||
public function open($db_name)
|
public function open($db_name)
|
||||||
|
@ -58,9 +58,9 @@ class bdd {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @desc Close the current database instance
|
* Close the current database instance
|
||||||
*
|
*
|
||||||
* Note: php close automatically the instance on exit
|
* Note: php automatically close the instance on exit
|
||||||
*/
|
*/
|
||||||
public function close()
|
public function close()
|
||||||
{
|
{
|
||||||
|
@ -68,7 +68,7 @@ class bdd {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @desc Install the table structure on a new sqlite database
|
* Install the table structure on a new sqlite database
|
||||||
* @param string $dn_name Name of the sqlite database
|
* @param string $dn_name Name of the sqlite database
|
||||||
*/
|
*/
|
||||||
public function create($db_name)
|
public function create($db_name)
|
||||||
|
@ -136,7 +136,7 @@ class bdd {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @desc Get the account id of an account_name
|
* Get the account id of an account_name
|
||||||
* @param string $account_name Name of the account
|
* @param string $account_name Name of the account
|
||||||
* @return int 0 if account_name doesn't exist,
|
* @return int 0 if account_name doesn't exist,
|
||||||
* id else
|
* id else
|
||||||
|
@ -159,8 +159,8 @@ class bdd {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @desc Get account
|
* Get account
|
||||||
* @param account name
|
* @param string $account_name account name
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function get_account($account_name)
|
public function get_account($account_name)
|
||||||
|
@ -183,7 +183,7 @@ class bdd {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @desc Check if account_name entry exists on table Accounts
|
* Check if account_name entry exists on table Accounts
|
||||||
* @param string $account_name Name of the account
|
* @param string $account_name Name of the account
|
||||||
* @return int 1 if it exists,
|
* @return int 1 if it exists,
|
||||||
* 0 else
|
* 0 else
|
||||||
|
@ -194,7 +194,7 @@ class bdd {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @desc Add an account to the table Accounts
|
* Add an account to the table Accounts
|
||||||
* @param array {
|
* @param array {
|
||||||
* 'name' => "$name",
|
* 'name' => "$name",
|
||||||
* 'domain' => "$domain",
|
* 'domain' => "$domain",
|
||||||
|
@ -236,7 +236,7 @@ class bdd {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @desc Add an alias to the table Serveralias
|
* Add an alias to the table Serveralias
|
||||||
* @param array {
|
* @param array {
|
||||||
* 'domain' => "$domain",
|
* 'domain' => "$domain",
|
||||||
* 'alias' => "$alias",
|
* 'alias' => "$alias",
|
||||||
|
@ -264,7 +264,7 @@ class bdd {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @desc Del an alias from the table Serveralias
|
* Delete an alias from the table Serveralias
|
||||||
* @param array {
|
* @param array {
|
||||||
* 'domain' => "$domain",
|
* 'domain' => "$domain",
|
||||||
* 'alias' => "$alias",
|
* 'alias' => "$alias",
|
||||||
|
@ -289,7 +289,7 @@ class bdd {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @desc Get the server id of a server_name
|
* Get the server id of a server_name
|
||||||
* @param string $server_name Name of the server
|
* @param string $server_name Name of the server
|
||||||
* @return int 0 if server_name doesn't exist,
|
* @return int 0 if server_name doesn't exist,
|
||||||
* id else
|
* id else
|
||||||
|
@ -312,7 +312,7 @@ class bdd {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @desc Check if server_name entry exists on table Servers
|
* Check if server_name entry exists on table Servers
|
||||||
* @param string $server_name Name of the server
|
* @param string $server_name Name of the server
|
||||||
* @return int 1 if it exists,
|
* @return int 1 if it exists,
|
||||||
* 0 else
|
* 0 else
|
||||||
|
@ -324,7 +324,7 @@ class bdd {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @desc Add an server to the table Servers
|
* Add an server to the table Servers
|
||||||
* @param array {
|
* @param array {
|
||||||
* 'name' => "$name",
|
* 'name' => "$name",
|
||||||
* }
|
* }
|
||||||
|
@ -353,7 +353,7 @@ class bdd {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @desc Add a role to the table Roles
|
* Add a role to the table Roles
|
||||||
* @param string $account_name
|
* @param string $account_name
|
||||||
* string $server_name
|
* string $server_name
|
||||||
* string $role master or slave
|
* string $role master or slave
|
||||||
|
@ -397,7 +397,7 @@ class bdd {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @desc List domains by server's role
|
* List domains by server's role
|
||||||
* @param none
|
* @param none
|
||||||
* @return list of array
|
* @return list of array
|
||||||
* example : Array (
|
* example : Array (
|
||||||
|
|
|
@ -1,5 +1,13 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a domain in BIND
|
||||||
|
* @param string $name Domain to add
|
||||||
|
* @param string $IP IP of web server for this domain
|
||||||
|
* @param bool $with_mxs Set to `true` if you wants to add MX records. Otherwise set to `false`.
|
||||||
|
* @param bool $gmail Set to `true` if the Google MXs are to be used by this domain as its MXs.
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
function domain_add($name, $IP, $with_mxs, $gmail=false) {
|
function domain_add($name, $IP, $with_mxs, $gmail=false) {
|
||||||
|
|
||||||
$exec_cmd = 'bind-add-ng.sh';
|
$exec_cmd = 'bind-add-ng.sh';
|
||||||
|
|
|
@ -10,7 +10,8 @@ class LetsEncrypt
|
||||||
const HTTP_CHALLENGE_URL = '/.well-known/acme-challenge/testfile';
|
const HTTP_CHALLENGE_URL = '/.well-known/acme-challenge/testfile';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* create the file used to test the HTTP challenge
|
* Create the file used to test the HTTP challenge
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
private function createFileHttpChallenge()
|
private function createFileHttpChallenge()
|
||||||
{
|
{
|
||||||
|
@ -19,7 +20,8 @@ class LetsEncrypt
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* delete the file used to test the HTTP challenge
|
* Delete the file used to test the HTTP challenge
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
private function deleteFileHttpChallenge()
|
private function deleteFileHttpChallenge()
|
||||||
{
|
{
|
||||||
|
@ -28,9 +30,9 @@ class LetsEncrypt
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* generate a CSR
|
* Generate a CSR
|
||||||
* @param string $vhost
|
* @param string $vhost
|
||||||
* @param Array $domains
|
* @param string[] $domains
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public function makeCsr($vhost, $domains)
|
public function makeCsr($vhost, $domains)
|
||||||
|
@ -69,7 +71,7 @@ class LetsEncrypt
|
||||||
/**
|
/**
|
||||||
* perform a cURL call on the remote resource
|
* perform a cURL call on the remote resource
|
||||||
* the cURL call follows redirections
|
* the cURL call follows redirections
|
||||||
* @param Array $domains list of domains
|
* @param array $domains list of domains
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public function checkRemoteResourceAvailability($domain)
|
public function checkRemoteResourceAvailability($domain)
|
||||||
|
@ -108,8 +110,8 @@ class LetsEncrypt
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Query the corresponding IP for each domain
|
* Query the corresponding IP for each domain
|
||||||
* @param Array $domains list of HTTP checked domains
|
* @param string[] $domains list of HTTP checked domains
|
||||||
* @return Array $valid_dns_domains list of valid domains
|
* @return array $valid_dns_domains list of valid domains
|
||||||
*/
|
*/
|
||||||
public function checkDNSValidity($domains)
|
public function checkDNSValidity($domains)
|
||||||
{
|
{
|
||||||
|
@ -133,7 +135,7 @@ class LetsEncrypt
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* check the presence of make-csr and evoacme binaries
|
* Check the presence of make-csr and evoacme binaries
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public function isEvoacmeInstalled()
|
public function isEvoacmeInstalled()
|
||||||
|
@ -151,7 +153,7 @@ class LetsEncrypt
|
||||||
/**
|
/**
|
||||||
* Retrieve the SSL certificate from the URL
|
* Retrieve the SSL certificate from the URL
|
||||||
* @param string $domain
|
* @param string $domain
|
||||||
* @return Array|false $cont list of parameters of the certificate, or false
|
* @return array|false $cont list of parameters of the certificate, or false
|
||||||
*/
|
*/
|
||||||
public function getCertificate($domain)
|
public function getCertificate($domain)
|
||||||
{
|
{
|
||||||
|
@ -164,8 +166,8 @@ class LetsEncrypt
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse the certificat arguments and extract data
|
* Parse the certificat arguments and extract data
|
||||||
* @param Array $certificateParameters certificat arguments
|
* @param array $certificateParameters certificat arguments
|
||||||
* @return Array $infosCert contains only the issuer, domains and expiration date
|
* @return array $infosCert contains only the issuer, domains and expiration date
|
||||||
*/
|
*/
|
||||||
public function parseCertificate($certificateParameters)
|
public function parseCertificate($certificateParameters)
|
||||||
{
|
{
|
||||||
|
@ -204,6 +206,12 @@ class LetsEncrypt
|
||||||
return ($timestampCertValidUntil > $currentDate) ? true : false;
|
return ($timestampCertValidUntil > $currentDate) ? true : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the requested domain is included in the certificate
|
||||||
|
* @param string $domainRequested
|
||||||
|
* @param string[]|string $san
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
public function isDomainIncludedInCert($domainRequested, $san)
|
public function isDomainIncludedInCert($domainRequested, $san)
|
||||||
{
|
{
|
||||||
$san = preg_replace('/DNS:| DNS:/', '', $san);
|
$san = preg_replace('/DNS:| DNS:/', '', $san);
|
||||||
|
|
Loading…
Reference in a new issue