Merge pull request 'Add some PHPDoc comments for ease of programming' (#87) from mtrossevin/evoadmin-web:doc-comments into unstable

Reviewed-on: #87
This commit is contained in:
Ludovic Poujol 2024-04-22 16:58:38 +02:00
commit 7d656d70a5
7 changed files with 114 additions and 38 deletions

View file

@ -257,11 +257,17 @@ class FormPage {
class FormField {
protected $value = null;
protected $error = null;
/** @var string|null $label */
protected $label = null;
/** @var string|null $name */
protected $name = null;
/** @var string|null $css_class */
protected $css_class = null;
/** @var bool|null $read_only */
protected $read_only = null;
/** @var bool|null $disabled True if the field is supposed to be disabled */
protected $disabled = null;
/** @var array|null $storage */
private $storage = NULL;
protected function __construct($label) {

View file

@ -31,6 +31,12 @@ else {
$cache = $conf['cache'];
}
/**
* Create a new domain (local only)
* @param FormPage $form
* @param string $admin_mail
* @return array
*/
function web_add($form, $admin_mail) {
global $conf;
@ -84,6 +90,12 @@ function web_add($form, $admin_mail) {
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) {
global $cache;
global $conf;

View file

@ -16,6 +16,12 @@
/**
* Functions
*/
/**
* Check if a file exists and is readable and `die()` if it doesnt.
* @param string $file
* @return void
*/
function test_exist($file) {
if(!file_exists($file)) {
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) {
header('Location: '.$_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['HTTP_HOST'].$path);
exit(0);
}
/**
* @param string $filename
* @return string
*/
function findexts ($filename)
{
$filename = strtolower($filename) ;
@ -39,15 +54,26 @@ function findexts ($filename)
return $exts;
}
/**
* Check if the user is a superadmin
* @return bool
*/
function is_superadmin() {
global $conf;
if(!empty($_SESSION['user']) && in_array($_SESSION['user'], $conf['superadmin'])) {
return 1;
return true;
} 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) {
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() {
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() {
global $conf;
@ -77,6 +105,8 @@ function is_mcluster_mode() {
/**
* Load config file for the specified cluster.
* @param string $cluster
* @return void
*/
function load_config_cluster($cluster) {
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
*/
function is_multiphp() {
@ -97,9 +126,9 @@ function is_multiphp() {
}
/**
* Webadd
*
* @return boolean - True when it's a multi PHP system
* Webadd
* @param string $command webadd command to run
* @return array output from the command
*/
function run_webadd_cmd($command) {
global $conf;
@ -127,6 +156,11 @@ if (!(ini_set('include_path', ini_get('include_path')))) {
require_once 'PEAR.php';
require_once 'Log.php';
/**
* (simply there to silence a warning)
* @var array $oriconf
* @var array $localconf
*/
// config files
// (here because need Log PEAR lib)
test_exist('../conf/connect.php');

View file

@ -229,6 +229,12 @@ if ($action=="add") {
$_SESSION['error']=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) {
$bytes *= 1024;
$units = array('o', 'Ko', 'Mo', 'Go', 'To');
@ -242,7 +248,9 @@ function formatBytes($bytes, $precision = 2) {
return round($bytes, $precision) . ' ' . $units[$pow];
}
/**
* @return string[]
*/
function get_owner_list() {
$owner_list = array();

View file

@ -1,7 +1,7 @@
<?php
/**
* @desc mini class to manipulate sqlite db for evocluster.
* mini class to manipulate sqlite db for evocluster.
*
* @example
* <?php
@ -43,7 +43,7 @@ class bdd {
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
*/
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()
{
@ -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
*/
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
* @return int 0 if account_name doesn't exist,
* id else
@ -159,8 +159,8 @@ class bdd {
}
/**
* @desc Get account
* @param account name
* Get account
* @param string $account_name account name
* @return array
*/
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
* @return int 1 if it exists,
* 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 {
* 'name' => "$name",
* '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 {
* 'domain' => "$domain",
* '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 {
* 'domain' => "$domain",
* '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
* @return int 0 if server_name doesn't exist,
* 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
* @return int 1 if it exists,
* 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 {
* '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
* string $server_name
* 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
* @return list of array
* example : Array (

View file

@ -1,5 +1,13 @@
<?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) {
$exec_cmd = 'bind-add-ng.sh';

View file

@ -10,7 +10,8 @@ class LetsEncrypt
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()
{
@ -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()
{
@ -28,9 +30,9 @@ class LetsEncrypt
}
/**
* generate a CSR
* Generate a CSR
* @param string $vhost
* @param Array $domains
* @param string[] $domains
* @return boolean
*/
public function makeCsr($vhost, $domains)
@ -69,7 +71,7 @@ class LetsEncrypt
/**
* perform a cURL call on the remote resource
* the cURL call follows redirections
* @param Array $domains list of domains
* @param array $domains list of domains
* @return boolean
*/
public function checkRemoteResourceAvailability($domain)
@ -108,8 +110,8 @@ class LetsEncrypt
/**
* Query the corresponding IP for each domain
* @param Array $domains list of HTTP checked domains
* @return Array $valid_dns_domains list of valid domains
* @param string[] $domains list of HTTP checked domains
* @return array $valid_dns_domains list of valid 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
*/
public function isEvoacmeInstalled()
@ -151,7 +153,7 @@ class LetsEncrypt
/**
* Retrieve the SSL certificate from the URL
* @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)
{
@ -167,8 +169,8 @@ class LetsEncrypt
/**
* Parse the certificat arguments and extract data
* @param Array $certificateParameters certificat arguments
* @return Array $infosCert contains only the issuer, domains and expiration date
* @param array $certificateParameters certificat arguments
* @return array $infosCert contains only the issuer, domains and expiration date
*/
public function parseCertificate($certificateParameters)
{
@ -207,6 +209,12 @@ class LetsEncrypt
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)
{
$san = preg_replace('/DNS:| DNS:/', '', $san);