315 lines
13 KiB
HTML
315 lines
13 KiB
HTML
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||
|
<html>
|
||
|
<head>
|
||
|
<title>Module HowTo - Account pages</title>
|
||
|
<link rel="stylesheet" type="text/css" href="style/layout.css">
|
||
|
</head>
|
||
|
<body>
|
||
|
<div style="text-align: center;">
|
||
|
<h1>Module HowTo - Account pages<br>
|
||
|
</h1>
|
||
|
<br>
|
||
|
<br>
|
||
|
<div style="text-align: left;"><br>
|
||
|
<h2>1. Defining pages<br>
|
||
|
</h2>
|
||
|
You can define multiple subpages for your account page. Usually one
|
||
|
page is enough but you may display certain attribute settings on an
|
||
|
extra page (e.g. Unix group memberships are on a second page).<br>
|
||
|
<br>
|
||
|
The page names are set by <span style="font-weight: bold;">pages() </span>which
|
||
|
returns an array of names.<br>
|
||
|
<br>
|
||
|
<span style="font-weight: bold; text-decoration: underline;">Example:</span><br
|
||
|
style="font-weight: bold; text-decoration: underline;">
|
||
|
<br>
|
||
|
The
|
||
|
<span style="font-style: italic;">ieee802Device</span>
|
||
|
module needs only one page which is called <span
|
||
|
style="font-style: italic;">'attributes'</span>.<br>
|
||
|
<br>
|
||
|
<table style="width: 100%; text-align: left;" class="mod-code"
|
||
|
border="0" cellpadding="2" cellspacing="2">
|
||
|
<tbody>
|
||
|
<tr>
|
||
|
<td style="vertical-align: top;"> /**<br>
|
||
|
* This function returns a list of all account pages
|
||
|
in this module.<br>
|
||
|
*/<br>
|
||
|
<span style="font-weight: bold;">function</span> <span
|
||
|
style="color: rgb(255, 0, 0);">pages</span>() {<br>
|
||
|
return array('attributes');<br>
|
||
|
}<br>
|
||
|
</td>
|
||
|
</tr>
|
||
|
</tbody>
|
||
|
</table>
|
||
|
<br>
|
||
|
<br>
|
||
|
<h2>2. Page display</h2>
|
||
|
Now that you have defined your subpages you will need one function for
|
||
|
each page to display it. The function must return <span
|
||
|
style="font-style: italic;">meta HTML code</span> as defined in the <span
|
||
|
style="font-style: italic;">modules specification</span>.<br>
|
||
|
This function is called <span style="font-weight: bold;">display_html_<page
|
||
|
name>()</span> where <span style="font-style: italic;"><page
|
||
|
name></span> is the name of your subpage.<br>
|
||
|
<br>
|
||
|
<span style="font-weight: bold; text-decoration: underline;">Example:</span><br
|
||
|
style="font-weight: bold; text-decoration: underline;">
|
||
|
<br>
|
||
|
The
|
||
|
<span style="font-style: italic;">ieee802Device</span>
|
||
|
module has only one subpage called <span style="font-style: italic;">'attributes'</span>.<br>
|
||
|
<br>
|
||
|
The first half of the code displays the existing MAC addresses and the
|
||
|
second an input field for new values.<br>
|
||
|
The variable <span style="font-style: italic;">$this->attributes</span>
|
||
|
contains all LDAP attributes of an account.<br>
|
||
|
<br>
|
||
|
<table style="width: 100%; text-align: left;" class="mod-code"
|
||
|
border="0" cellpadding="2" cellspacing="2">
|
||
|
<tbody>
|
||
|
<tr>
|
||
|
<td style="vertical-align: top;"> /**<br>
|
||
|
* This function will create the meta HTML code to
|
||
|
show a page with all attributes.<br>
|
||
|
*<br>
|
||
|
* @param array $post HTTP-POST values<br>
|
||
|
*/<br>
|
||
|
<span style="font-weight: bold;">function</span> <span
|
||
|
style="color: rgb(255, 0, 0);">display_html_attributes</span>($post) {<br>
|
||
|
$return = array();<br>
|
||
|
// list current MACs<br>
|
||
|
for ($i = 0; $i <
|
||
|
sizeof($this->attributes['macAddress']); $i++) {<br>
|
||
|
$return[] =
|
||
|
array(<br>
|
||
|
|
||
|
0 => array('kind' => 'text', 'text' =>
|
||
|
_('MAC address')),<br>
|
||
|
|
||
|
1 => array('kind' => 'input', 'name' =>
|
||
|
'macAddress' . $i, 'type' => 'text', 'size' => '17', 'maxlength'
|
||
|
=> '17', 'value' => $this->attributes['macAddress'][$i]),<br>
|
||
|
|
||
|
2 => array('kind' => 'input', 'type' =>
|
||
|
'submit', 'name' => 'delMAC' . $i, 'value' => _("Remove")),<br>
|
||
|
|
||
|
3 => array('kind' => 'help', 'value' =>
|
||
|
'mac'));<br>
|
||
|
}<br>
|
||
|
// input box for new MAC<br>
|
||
|
$return[] = array(<br>
|
||
|
0 =>
|
||
|
array('kind' => 'text', 'text' => _('New MAC address')),<br>
|
||
|
1 =>
|
||
|
array('kind' => 'input', 'name' => 'macAddress', 'type' =>
|
||
|
'text', 'size' => '17', 'maxlength' => '17', 'value' => ''),<br>
|
||
|
2 =>
|
||
|
array('kind' => 'input', 'type' => 'submit', 'name' =>
|
||
|
'addMAC', 'value' => _("Add")),<br>
|
||
|
3 =>
|
||
|
array('kind' => 'help', 'value' => 'mac'),<br>
|
||
|
4 =>
|
||
|
array('kind' => 'input', 'type' => 'hidden', 'value' =>
|
||
|
sizeof($this->attributes['macAddress']), 'name' => 'mac_number'));<br>
|
||
|
return $return;<br>
|
||
|
}<br>
|
||
|
</td>
|
||
|
</tr>
|
||
|
</tbody>
|
||
|
</table>
|
||
|
<br>
|
||
|
<br>
|
||
|
<h2>3. Processing input data<br>
|
||
|
</h2>
|
||
|
Every time the user clicks on a submit button while your page is
|
||
|
displayed LAM will call a function in your module.<br>
|
||
|
This function is called <span style="font-weight: bold;">process_<page
|
||
|
name>()</span> where <span style="font-style: italic;"><page
|
||
|
name></span> is the name of your subpage.<br>
|
||
|
<br>
|
||
|
<span style="font-weight: bold; text-decoration: underline;">Example:</span><br
|
||
|
style="font-weight: bold; text-decoration: underline;">
|
||
|
<br>
|
||
|
The
|
||
|
<span style="font-style: italic;">ieee802Device</span>
|
||
|
module has only one subpage called <span style="font-style: italic;">'attributes'</span>
|
||
|
and therefore only <span style="font-style: italic;">process_attributes()</span>.<br>
|
||
|
<br>
|
||
|
The function checks the input fields and fills the LDAP attributes. If
|
||
|
all is ok it will enable the user to move to another module page.<br>
|
||
|
<br>
|
||
|
<table style="width: 100%; text-align: left;" class="mod-code"
|
||
|
border="0" cellpadding="2" cellspacing="2">
|
||
|
<tbody>
|
||
|
<tr>
|
||
|
<td style="vertical-align: top;"> /**<br>
|
||
|
* Write variables into object and do some regex
|
||
|
checks<br>
|
||
|
*<br>
|
||
|
* @param array $post HTTP-POST values<br>
|
||
|
*/<br>
|
||
|
<span style="font-weight: bold;">function</span> <span
|
||
|
style="color: rgb(255, 0, 0);">proccess_attributes</span>($post) {<br>
|
||
|
$this->triggered_messages =
|
||
|
array();<br>
|
||
|
|
||
|
$this->attributes['macAddress'] = array();<br>
|
||
|
// check old MACs<br>
|
||
|
if (isset($post['mac_number'])) {<br>
|
||
|
for ($i = 0;
|
||
|
$i < $post['mac_number']; $i++) {<br>
|
||
|
|
||
|
if (isset($post['delMAC' . $i])) continue;<br>
|
||
|
|
||
|
if (isset($post['macAddress' . $i]) &&
|
||
|
($post['macAddress' . $i] != "")) {<br>
|
||
|
|
||
|
// check if address has correct
|
||
|
format<br>
|
||
|
|
||
|
if (!get_preg($post['macAddress'
|
||
|
. $i], 'macAddress')) {<br>
|
||
|
|
||
|
$message =
|
||
|
$this->messages['mac'][0];<br>
|
||
|
|
||
|
$message[] =
|
||
|
$post['macAddress' . $i];<br>
|
||
|
|
||
|
|
||
|
$this->triggered_messages[] = array($message);<br>
|
||
|
|
||
|
}<br>
|
||
|
|
||
|
|
||
|
$this->attributes['macAddress'][] = $post['macAddress' . $i];<br>
|
||
|
|
||
|
}<br>
|
||
|
}<br>
|
||
|
}<br>
|
||
|
// check new MAC<br>
|
||
|
if (isset($post['macAddress'])
|
||
|
&& ($post['macAddress'] != "")) {<br>
|
||
|
// check if
|
||
|
address has correct format<br>
|
||
|
if
|
||
|
(get_preg($post['macAddress'], 'macAddress')) {<br>
|
||
|
|
||
|
$this->attributes['macAddress'][] =
|
||
|
$post['macAddress'];<br>
|
||
|
}<br>
|
||
|
else {<br>
|
||
|
|
||
|
$message =
|
||
|
$this->messages['mac'][0];<br>
|
||
|
|
||
|
$message[] = $post['macAddress'];<br>
|
||
|
|
||
|
$this->triggered_messages[] =
|
||
|
array($message);<br>
|
||
|
}<br>
|
||
|
}<br>
|
||
|
|
||
|
$this->attributes['macAddress'] =
|
||
|
array_unique($this->attributes['macAddress']);<br>
|
||
|
if
|
||
|
(sizeof($this->triggered_messages) > 0) {<br>
|
||
|
|
||
|
$this->inputCorrect = false;<br>
|
||
|
return
|
||
|
$this->triggered_messages;<br>
|
||
|
}<br>
|
||
|
else {<br>
|
||
|
|
||
|
$this->inputCorrect = true;<br>
|
||
|
return 0;<br>
|
||
|
}<br>
|
||
|
}<br>
|
||
|
</td>
|
||
|
</tr>
|
||
|
</tbody>
|
||
|
</table>
|
||
|
<br>
|
||
|
<br>
|
||
|
<h2>4. Defining that your module is ready for LDAP add/modify</h2>
|
||
|
Before a new account can be created or modified all modules are asked
|
||
|
if they are ready.<br>
|
||
|
There are two functions which control the module status. The <span
|
||
|
style="font-weight: bold;">module_ready()</span> function has to
|
||
|
return <span style="font-style: italic;">true</span> if the user may
|
||
|
move to another module page. If it is <span style="font-style: italic;">false</span>
|
||
|
the user will be redirected to your module page. The second function is
|
||
|
<span style="font-weight: bold;">module_complete()</span>. The user
|
||
|
cannot do the LDAP operation if one or modules return <span
|
||
|
style="font-style: italic;">false</span>.<br>
|
||
|
<br>
|
||
|
<span style="font-weight: bold; text-decoration: underline;">Example:</span><br
|
||
|
style="font-weight: bold; text-decoration: underline;">
|
||
|
<br>
|
||
|
The
|
||
|
<span style="font-style: italic;">ieee802Device</span>
|
||
|
module uses a global variable to store the status: <span
|
||
|
style="font-style: italic;">$this->inputCorrect</span>. It is set
|
||
|
in <span style="font-style: italic;">process_attributes()</span>. The
|
||
|
variable can be preset to <span style="font-style: italic;">true</span>
|
||
|
because the MAC address is optional.<br>
|
||
|
<br>
|
||
|
<table style="width: 100%; text-align: left;" class="mod-code"
|
||
|
border="0" cellpadding="2" cellspacing="2">
|
||
|
<tbody>
|
||
|
<tr>
|
||
|
<td style="vertical-align: top;"> /** used for
|
||
|
account pages, true if input data is correct */<br>
|
||
|
var $inputCorrect = true;<br>
|
||
|
<br>
|
||
|
/**<br>
|
||
|
* This function returns true if all needed settings
|
||
|
are done.<br>
|
||
|
*/<br>
|
||
|
function module_complete() {<br>
|
||
|
return $this->inputCorrect;<br>
|
||
|
}<br>
|
||
|
<br>
|
||
|
/**<br>
|
||
|
* Returns true if all settings on module page are
|
||
|
correct.<br>
|
||
|
*/<br>
|
||
|
function module_ready() {<br>
|
||
|
return $this->inputCorrect;<br>
|
||
|
}<br>
|
||
|
</td>
|
||
|
</tr>
|
||
|
</tbody>
|
||
|
</table>
|
||
|
<br>
|
||
|
<br>
|
||
|
<h2>5. Saving the LDAP attributes<br>
|
||
|
</h2>
|
||
|
<br>
|
||
|
<br>
|
||
|
<span style="font-weight: bold; text-decoration: underline;">Example:</span><br
|
||
|
style="font-weight: bold; text-decoration: underline;">
|
||
|
<br>
|
||
|
<br>
|
||
|
<br>
|
||
|
<table style="width: 100%; text-align: left;" class="mod-code"
|
||
|
border="0" cellpadding="2" cellspacing="2">
|
||
|
<tbody>
|
||
|
<tr>
|
||
|
<td style="vertical-align: top;"> <br>
|
||
|
</td>
|
||
|
</tr>
|
||
|
</tbody>
|
||
|
</table>
|
||
|
<br>
|
||
|
<br>
|
||
|
<span style="font-weight: bold;"></span>
|
||
|
<h2><span style="font-weight: bold;"></span></h2>
|
||
|
</div>
|
||
|
</div>
|
||
|
</body>
|
||
|
</html>
|