added integer comparison for profile options
This commit is contained in:
parent
db5e333b2e
commit
c420e1e201
|
@ -188,7 +188,7 @@ Returns the account type (user/group/host) of this module object.<br>
|
||||||
baseModule and should not be overwritten.</span><br>
|
baseModule and should not be overwritten.</span><br>
|
||||||
<br>
|
<br>
|
||||||
<h3>2.2. Class functions</h3>
|
<h3>2.2. Class functions</h3>
|
||||||
<h3>2.2.1. Constructor</h3>
|
<h3>2.2.1. init</h3>
|
||||||
<br>
|
<br>
|
||||||
<table cellpadding="2" cellspacing="2" border="0"
|
<table cellpadding="2" cellspacing="2" border="0"
|
||||||
style="text-align: left; width: 300px; height: 30px;">
|
style="text-align: left; width: 300px; height: 30px;">
|
||||||
|
@ -196,13 +196,13 @@ baseModule and should not be overwritten.</span><br>
|
||||||
<tr>
|
<tr>
|
||||||
<td
|
<td
|
||||||
style="vertical-align: top; background-color: rgb(204, 204, 204); text-align: center;"><span
|
style="vertical-align: top; background-color: rgb(204, 204, 204); text-align: center;"><span
|
||||||
style="font-weight: bold;">function <module name> ($base)</span><br>
|
style="font-weight: bold;">function init($base)</span><br>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
<br>
|
<br>
|
||||||
Every module needs a constructor that has an<span
|
Every module needs a initializing function that has an<span
|
||||||
style="font-style: italic;"> <span style="font-weight: bold;">account
|
style="font-style: italic;"> <span style="font-weight: bold;">account
|
||||||
container</span></span> as argument $base.<br>
|
container</span></span> as argument $base.<br>
|
||||||
With this account container you can interact with other modules and use
|
With this account container you can interact with other modules and use
|
||||||
|
@ -313,9 +313,8 @@ naming confilcts.<br>
|
||||||
<br>
|
<br>
|
||||||
This function checks the input for a new or modified account profile.<br>
|
This function checks the input for a new or modified account profile.<br>
|
||||||
<br>
|
<br>
|
||||||
<span style="font-weight: bold;">$scope</span> is the account type
|
<span style="font-weight: bold;"></span><span style="font-weight: bold;">$options</span>
|
||||||
("user", "group", "host" at this time).<br>
|
is an hash array
|
||||||
<span style="font-weight: bold;">$options</span> is an hash array
|
|
||||||
(option name => value) that contains the input. The option values
|
(option name => value) that contains the input. The option values
|
||||||
are all arrays containing one or more elements.<br>
|
are all arrays containing one or more elements.<br>
|
||||||
If the input data is invalid the return value is an array that contains
|
If the input data is invalid the return value is an array that contains
|
||||||
|
@ -603,6 +602,18 @@ determines how to check input</span></li>
|
||||||
<li style="font-weight: bold;">regex_i:<span
|
<li style="font-weight: bold;">regex_i:<span
|
||||||
style="font-weight: normal;"> check with regular expression from <span
|
style="font-weight: normal;"> check with regular expression from <span
|
||||||
style="font-style: italic;">regex</span> variable, case insensitive</span></li>
|
style="font-style: italic;">regex</span> variable, case insensitive</span></li>
|
||||||
|
<li style="font-weight: bold;"><span style="font-weight: normal;"><span
|
||||||
|
style="font-weight: bold;">int_greater:</span> integer value of <span
|
||||||
|
style="font-style: italic;">cmp_name1</span> must be
|
||||||
|
greater than the integer value from the option <span
|
||||||
|
style="font-style: italic;">cmp_name2</span></span></li>
|
||||||
|
<li style="font-weight: bold;"><span style="font-weight: normal;"><span
|
||||||
|
style="font-weight: bold;">int_greaterOrEqual:</span> integer value</span><span
|
||||||
|
style="font-weight: normal;"><span style="font-weight: normal;"> of <span
|
||||||
|
style="font-style: italic;">cmp_name1</span></span></span><span
|
||||||
|
style="font-weight: normal;">
|
||||||
|
must be greater or equal than the integer value from the option <span
|
||||||
|
style="font-style: italic;">cmp_name2</span></span></li>
|
||||||
</ul>
|
</ul>
|
||||||
<li style="font-weight: bold;">error_message:<span
|
<li style="font-weight: bold;">error_message:<span
|
||||||
style="font-weight: normal;"> message that is displayed if input value
|
style="font-weight: normal;"> message that is displayed if input value
|
||||||
|
@ -617,8 +628,19 @@ head, 2 => message text, 3 => additional variables)</span><span
|
||||||
style="font-weight: normal;"> regular expression string (only if <span
|
style="font-weight: normal;"> regular expression string (only if <span
|
||||||
style="font-style: italic;">type</span> is <span
|
style="font-style: italic;">type</span> is <span
|
||||||
style="font-style: italic;">regex</span>/<span
|
style="font-style: italic;">regex</span>/<span
|
||||||
style="font-style: italic;">regex_i</span>)</span><br>
|
style="font-style: italic;">regex_i</span>)</span></li>
|
||||||
</li>
|
<li style="font-weight: bold;"><span style="font-weight: normal;"><span
|
||||||
|
style="font-weight: normal;"><span style="font-weight: bold;">cmp_name1:</span>
|
||||||
|
name of first input
|
||||||
|
variable that is used for comparison (only if <span
|
||||||
|
style="font-style: italic;">type</span> is <span
|
||||||
|
style="font-style: italic;">int_greater/int_greaterOrEqual</span>)</span></span></li>
|
||||||
|
<li style="font-weight: bold;"><span style="font-weight: normal;"><span
|
||||||
|
style="font-weight: bold;">cmp_name2:</span> name of second input
|
||||||
|
variable that is used for comparison (only if <span
|
||||||
|
style="font-style: italic;">type</span> is <span
|
||||||
|
style="font-style: italic;">int_greater/int_greaterOrEqual</span>)<br>
|
||||||
|
</span></li>
|
||||||
<li><span style="font-weight: bold;">required:</span> <span
|
<li><span style="font-weight: bold;">required:</span> <span
|
||||||
style="font-style: italic;">true</span> or <span
|
style="font-style: italic;">true</span> or <span
|
||||||
style="font-style: italic;">false</span>, if this input field must be
|
style="font-style: italic;">false</span>, if this input field must be
|
||||||
|
|
|
@ -152,20 +152,53 @@ class baseModule {
|
||||||
if ($this->meta['profile_checks'][$identifiers[$i]]['required'] && ($options[$identifiers[$i]][0] == '')) {
|
if ($this->meta['profile_checks'][$identifiers[$i]]['required'] && ($options[$identifiers[$i]][0] == '')) {
|
||||||
$messages[] = $this->meta['profile_checks'][$identifiers[$i]]['required_message'];
|
$messages[] = $this->meta['profile_checks'][$identifiers[$i]]['required_message'];
|
||||||
}
|
}
|
||||||
// ignore empty fileds
|
|
||||||
if ($options[$identifiers[$i]][0] == '') continue;
|
|
||||||
// check by regular expression (case insensitive)
|
// check by regular expression (case insensitive)
|
||||||
if ($this->meta['profile_checks'][$identifiers[$i]]['type'] == 'regex_i') {
|
if ($this->meta['profile_checks'][$identifiers[$i]]['type'] == 'regex_i') {
|
||||||
|
// ignore empty fileds
|
||||||
|
if ($options[$identifiers[$i]][0] == '') continue;
|
||||||
if (! eregi($this->meta['profile_checks'][$identifiers[$i]]['regex'], $options[$identifiers[$i]][0])) {
|
if (! eregi($this->meta['profile_checks'][$identifiers[$i]]['regex'], $options[$identifiers[$i]][0])) {
|
||||||
$messages[] = $this->meta['profile_checks'][$identifiers[$i]]['error_message'];
|
$messages[] = $this->meta['profile_checks'][$identifiers[$i]]['error_message'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// check by regular expression (case sensitive)
|
// check by regular expression (case sensitive)
|
||||||
elseif ($this->meta['profile_checks'][$identifiers[$i]]['type'] == 'regex') {
|
elseif ($this->meta['profile_checks'][$identifiers[$i]]['type'] == 'regex') {
|
||||||
|
// ignore empty fileds
|
||||||
|
if ($options[$identifiers[$i]][0] == '') continue;
|
||||||
if (! ereg($this->meta['profile_checks'][$identifiers[$i]]['regex'], $options[$identifiers[$i]][0])) {
|
if (! ereg($this->meta['profile_checks'][$identifiers[$i]]['regex'], $options[$identifiers[$i]][0])) {
|
||||||
$messages[] = $this->meta['profile_checks'][$identifiers[$i]]['error_message'];
|
$messages[] = $this->meta['profile_checks'][$identifiers[$i]]['error_message'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// check by integer comparison (greater)
|
||||||
|
elseif ($this->meta['profile_checks'][$identifiers[$i]]['type'] == 'int_greater') {
|
||||||
|
// ignore if both fields are empty
|
||||||
|
if (($options[$this->meta['profile_checks'][$identifiers[$i]]['cmp_name1']][0] == '') && ($options[$this->meta['profile_checks'][$identifiers[$i]]['cmp_name2']][0] == '')) continue;
|
||||||
|
// print error message if only one field is empty
|
||||||
|
if (($options[$this->meta['profile_checks'][$identifiers[$i]]['cmp_name1']][0] == '') || ($options[$this->meta['profile_checks'][$identifiers[$i]]['cmp_name2']][0] == '')) {
|
||||||
|
$messages[] = $this->meta['profile_checks'][$identifiers[$i]]['error_message'];
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// compare
|
||||||
|
if (!(intval($options[$this->meta['profile_checks'][$identifiers[$i]]['cmp_name1']][0]) > intval($options[$this->meta['profile_checks'][$identifiers[$i]]['cmp_name2']][0]))) {
|
||||||
|
$messages[] = $this->meta['profile_checks'][$identifiers[$i]]['error_message'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// check by integer comparison (greater or equal)
|
||||||
|
elseif ($this->meta['profile_checks'][$identifiers[$i]]['type'] == 'int_greaterOrEqual') {
|
||||||
|
// ignore if both fields are empty
|
||||||
|
if (($options[$this->meta['profile_checks'][$identifiers[$i]]['cmp_name1']][0] == '') && ($options[$this->meta['profile_checks'][$identifiers[$i]]['cmp_name2']][0] == '')) continue;
|
||||||
|
// print error message if only one field is empty
|
||||||
|
if (($options[$this->meta['profile_checks'][$identifiers[$i]]['cmp_name1']][0] == '') || ($options[$this->meta['profile_checks'][$identifiers[$i]]['cmp_name2']][0] == '')) {
|
||||||
|
$messages[] = $this->meta['profile_checks'][$identifiers[$i]]['error_message'];
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// compare
|
||||||
|
if (!(intval($options[$this->meta['profile_checks'][$identifiers[$i]]['cmp_name1']][0]) >= intval($options[$this->meta['profile_checks'][$identifiers[$i]]['cmp_name2']][0]))) {
|
||||||
|
$messages[] = $this->meta['profile_checks'][$identifiers[$i]]['error_message'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
StatusMessage("ERROR", "Unsupported type!", $this->meta['profile_checks'][$identifiers[$i]]['type']);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $messages;
|
return $messages;
|
||||||
|
|
|
@ -124,6 +124,17 @@ class shadowAccount extends baseModule {
|
||||||
)),
|
)),
|
||||||
2 => array('kind' => 'help', 'value' => 'TODO'))
|
2 => array('kind' => 'help', 'value' => 'TODO'))
|
||||||
);
|
);
|
||||||
|
// profile checks
|
||||||
|
$return['profile_checks']['shadowAccount_shadowMin'] = array('type' => 'regex', 'regex' => $this->regex_number,
|
||||||
|
'error_message' => $this->messages['shadowMin']);
|
||||||
|
$return['profile_checks']['shadowAccount_shadowMax'] = array('type' => 'regex', 'regex' => $this->regex_number,
|
||||||
|
'error_message' => $this->messages['shadowMax']);
|
||||||
|
$return['profile_checks']['shadowAccount_cmp'] = array('type' => 'int_greater', 'cmp_name1' => 'shadowAccount_shadowMax',
|
||||||
|
'cmp_name2' => 'shadowAccount_shadowMin', 'error_message' => $this->messages['shadow_cmp']);
|
||||||
|
$return['profile_checks']['shadowAccount_shadowInactive'] = array('type' => 'regex', 'regex' => $this->regex_inactive,
|
||||||
|
'error_message' => $this->messages['inactive']);
|
||||||
|
$return['profile_checks']['shadowAccount_shadowWarning'] = array('type' => 'regex', 'regex' => $this->regex_number,
|
||||||
|
'error_message' => $this->messages['shadowWarning']);
|
||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -317,21 +328,6 @@ class shadowAccount extends baseModule {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks input values of account profiles.
|
|
||||||
*
|
|
||||||
* @return profile elements
|
|
||||||
*/
|
|
||||||
function check_profileOptions($options) {
|
|
||||||
$errors = array();
|
|
||||||
if (!ereg($this->regex_number, $options['shadowAccount_shadowMin'][0])) $errors[] = $this->messages['shadowMin'];
|
|
||||||
if (!ereg($this->regex_number, $options['shadowAccount_shadowMax'][0])) $errors[] = $this->messages['shadowMax'];
|
|
||||||
if ($options['shadowAccount_shadowMin'][0] > $options['shadowAccount_shadowMax'][0]) $errors[] = $this->messages['shadow_cmp'];
|
|
||||||
if (!ereg($this->regex_inactive, $options['shadowAccount_shadowInactive'][0])) $errors[] = $this->messages['inactive'];
|
|
||||||
if (!ereg($this->regex_number, $options['shadowAccount_shadowWarning'][0])) $errors[] = $this->messages['shadowWarning'];
|
|
||||||
return $errors;
|
|
||||||
}
|
|
||||||
|
|
||||||
function get_pdfFields($account_type="user") {
|
function get_pdfFields($account_type="user") {
|
||||||
return array( 'shadowLastChange',
|
return array( 'shadowLastChange',
|
||||||
'shadowWarning',
|
'shadowWarning',
|
||||||
|
|
Loading…
Reference in New Issue