Validate domain names #48
|
@ -410,6 +410,104 @@ class TextInputFormField extends FormField {
|
|||
}
|
||||
}
|
||||
|
||||
class DomainInputFormField extends FormField {
|
||||
protected $mandatory = NULL;
|
||||
protected $textsize = NULL;
|
||||
|
||||
public function __construct($label, $mandatory=TRUE) {
|
||||
parent::__construct($label);
|
||||
$this->mandatory = $mandatory;
|
||||
$this->textsize = $textsize;
|
||||
}
|
||||
|
||||
public function verify($set_error) {
|
||||
if($this->mandatory && (!strlen($this->value))) {
|
||||
if($set_error) $this->error = 'Champ obligatoire';
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!preg_match("/^[a-z0-9-.]+\.[a-z0-9-]{2,}$/i", $this->value)) {
|
||||
if($set_error) $this->error = 'Ceci n\'est pas un nom de domaine';
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
public function getInputHTML() {
|
||||
$input = '';
|
||||
$input .= '<input type="text" id="'.$this->name.'"';
|
||||
$input .= ' name="'.$this->name.'" value="'.htmlspecialchars($this->value,ENT_QUOTES).'"';
|
||||
$input .= ' maxlength="'.$this->textsize[1].'" size="'.$this->textsize[0].'" ';
|
||||
if($this->read_only) { $input .= 'readonly="readonly="'; }
|
||||
if($this->disabled) { $input .= 'disabled="disabled="'; }
|
||||
$input .= '/>';
|
||||
return $input;
|
||||
}
|
||||
|
||||
public function __toString() {
|
||||
$out = '';
|
||||
$out .= "<p>\n";
|
||||
$out .= $this->getLabelHTML();
|
||||
$out .= $this->getInputHTML();
|
||||
$out .= $this->getErrorHTML();
|
||||
$out .= "</p>\n\n";
|
||||
return $out;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class DomainListInputFormField extends FormField {
|
||||
protected $mandatory = NULL;
|
||||
protected $textsize = NULL;
|
||||
|
||||
public function __construct($label, $mandatory=TRUE) {
|
||||
parent::__construct($label);
|
||||
$this->mandatory = $mandatory;
|
||||
$this->textsize = $textsize;
|
||||
}
|
||||
|
||||
public function verify($set_error) {
|
||||
if($this->mandatory && (!strlen($this->value))) {
|
||||
if($set_error) $this->error = 'Champ obligatoire';
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if(strlen($this->value)){
|
||||
$list = explode(',', $this->value);
|
||||
foreach ($list as $value) {
|
||||
if (!preg_match("/^[a-z0-9-.]+\.[a-z0-9-]{2,}$/i", $value)) {
|
||||
if($set_error) $this->error = 'Ceci n\'est pas un nom de domaine';
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
public function getInputHTML() {
|
||||
$input = '';
|
||||
$input .= '<input type="text" id="'.$this->name.'"';
|
||||
$input .= ' name="'.$this->name.'" value="'.htmlspecialchars($this->value,ENT_QUOTES).'"';
|
||||
$input .= ' maxlength="'.$this->textsize[1].'" size="'.$this->textsize[0].'" ';
|
||||
if($this->read_only) { $input .= 'readonly="readonly="'; }
|
||||
if($this->disabled) { $input .= 'disabled="disabled="'; }
|
||||
$input .= '/>';
|
||||
return $input;
|
||||
}
|
||||
|
||||
public function __toString() {
|
||||
$out = '';
|
||||
$out .= "<p>\n";
|
||||
$out .= $this->getLabelHTML();
|
||||
$out .= $this->getInputHTML();
|
||||
$out .= $this->getErrorHTML();
|
||||
$out .= "</p>\n\n";
|
||||
return $out;
|
||||
}
|
||||
}
|
||||
|
||||
class DateInputFormField extends TextInputFormField {
|
||||
public function __construct($label, $mandatory=TRUE) {
|
||||
parent::__construct($label, $mandatory, array(7, 10));
|
||||
|
|
|
@ -251,8 +251,8 @@ function web_add_cluster($form, $admin_mail) {
|
|||
/* Construction du formulaire d'ajout */
|
||||
$form = new FormPage("Ajout d'un compte web", FALSE);
|
||||
$form->addField('username', new TextInputFormField("Nom d'utilisateur", TRUE, array(20,16)));
|
||||
$form->addField('domain', new TextInputFormField("Nom de domaine", TRUE));
|
||||
$form->addField('domain_alias', new TextInputFormField("Alias (séparés par une virgule)", FALSE));
|
||||
$form->addField('domain', new DomainInputFormField("Nom de domaine", TRUE));
|
||||
$form->addField('domain_alias', new DomainListInputFormField("Alias (séparés par une virgule, sans espaces)", FALSE));
|
||||
$form->addField('password_random',
|
||||
new CheckboxInputFormField("Mot de passe aléatoire ?", FALSE));
|
||||
$form->getField('password_random')->setValue(TRUE);
|
||||
|
|
|
@ -104,7 +104,7 @@ if (isset($_GET['del']) ) {
|
|||
include_once EVOADMIN_BASE . '../tpl/menu.tpl.php';
|
||||
|
||||
$form = new FormPage("Ajout d'un alias", FALSE);
|
||||
$form->addField('domain_alias', new TextInputFormField("Alias", FALSE));
|
||||
$form->addField('domain_alias', new DomainInputFormField("Alias", TRUE));
|
||||
|
||||
if (!empty($_POST)) {
|
||||
$form->isCurrentPage(TRUE);
|
||||
|
@ -205,6 +205,17 @@ if (isset($_GET['del']) ) {
|
|||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
print "<h2>Ajout d'un serveralias</h2><hr>";
|
||||
print "<form name=\"form-add\" id=\"form-add\" action=\"\" method=\"POST\">";
|
||||
print " <fieldset>";
|
||||
print " <legend>Ajout d'un serveralias</legend>";
|
||||
print $form;
|
||||
print " <p><input type=\"submit\" value=\"Créer\"/></p>";
|
||||
print " </fieldset>";
|
||||
print "</form>";
|
||||
|
||||
}
|
||||
} else {
|
||||
print "<h2>Ajout d'un serveralias</h2><hr>";
|
||||
print "<form name=\"form-add\" id=\"form-add\" action=\"\" method=\"POST\">";
|
||||
|
|
Loading…
Reference in a new issue