module HowTo
This commit is contained in:
parent
623daf5d93
commit
e8381a1661
|
@ -0,0 +1,314 @@
|
||||||
|
<!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>
|
|
@ -0,0 +1,109 @@
|
||||||
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Module HowTo - Basic concepts</title>
|
||||||
|
<link rel="stylesheet" type="text/css" href="style/layout.css">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div style="text-align: center;">
|
||||||
|
<h1>Module HowTo - Basic concepts<br>
|
||||||
|
</h1>
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
<div style="text-align: left;"><br>
|
||||||
|
<h2>1. Licensing</h2>
|
||||||
|
LAM is licensed under the <a href="http://www.gnu.org/licenses/gpl.txt">GNU
|
||||||
|
General Public License</a>. This means your plugins need a compatible
|
||||||
|
license.<br>
|
||||||
|
LAM is distributed with a copy of the GPL license.<br>
|
||||||
|
<br>
|
||||||
|
<h2>2. Naming and position in directory structure</h2>
|
||||||
|
<br>
|
||||||
|
Module names are usually named after the object class they manage.
|
||||||
|
However, you can use any name you want, it should be short and
|
||||||
|
containing only a-z and 0-9. The module name is only shown in the
|
||||||
|
configuration dialog, on all other pages LAM will show a provided <span
|
||||||
|
style="font-style: italic;">alias</span> name.<br>
|
||||||
|
All account modules are stored in <span style="font-weight: bold;">lib/modules</span>.
|
||||||
|
The filename must end with <span style="font-weight: bold;">.inc</span>
|
||||||
|
and the file must have the same name as its inside class.<br>
|
||||||
|
<br>
|
||||||
|
<span style="font-weight: bold; text-decoration: underline;">Example:</span>
|
||||||
|
Our example module will provide the <span style="font-weight: bold;">class
|
||||||
|
ieee802Devic</span><span style="font-style: italic; font-weight: bold;">e</span>,
|
||||||
|
therefore the file will be called <span style="font-weight: bold;">lib/modules/ieee802Devic</span><span
|
||||||
|
style="font-style: italic; font-weight: bold;">e.inc</span>.<span
|
||||||
|
style="font-style: italic;"></span><br>
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
<h2>3. Defining the class</h2>
|
||||||
|
All module classes have <span style="font-weight: bold;">baeModule</span>
|
||||||
|
as parent class. This provides common functionality and dummy functions
|
||||||
|
for all required class functions.<br>
|
||||||
|
<br>
|
||||||
|
<span style="font-weight: bold;">Example:</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>
|
||||||
|
* Provides MAC addresses for hosts.<br>
|
||||||
|
*<br>
|
||||||
|
* @package modules<br>
|
||||||
|
*/<span style="font-weight: bold;"><br>
|
||||||
|
class</span> <span style="color: rgb(255, 0, 0);">ieee802Device</span>
|
||||||
|
<span style="font-style: italic;">extends </span><span
|
||||||
|
style="font-weight: bold;">baseModule</span> {<br>
|
||||||
|
<br>
|
||||||
|
}<br>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<br>
|
||||||
|
<h2>4. Meta data</h2>
|
||||||
|
The module interface inludes a lot of required and optional functions.
|
||||||
|
Many of these functions do not need to be implemented directly in the
|
||||||
|
module, you can define <span style="font-weight: bold;">meta data</span>
|
||||||
|
for them and the <span style="font-weight: bold;">baseModule</span>
|
||||||
|
will do the rest.<br>
|
||||||
|
Providing <span style="font-weight: bold;">meta data</span> is
|
||||||
|
optional, you can implement the required functions in your class, too.<br>
|
||||||
|
<br>
|
||||||
|
The <span style="font-weight: bold;">baseModule</span> reads the <span
|
||||||
|
style="font-weight: bold;">meta data</span> by calling <span
|
||||||
|
style="font-weight: bold;">get_metaData()</span> in your class.<br>
|
||||||
|
<br>
|
||||||
|
<span style="font-weight: bold; text-decoration: underline;">Example:</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>
|
||||||
|
* Returns meta data that is interpreted by parent
|
||||||
|
class<br>
|
||||||
|
*<br>
|
||||||
|
* @return array array with meta data<br>
|
||||||
|
*/<br>
|
||||||
|
<span style="font-weight: bold;">function</span> <span
|
||||||
|
style="color: rgb(255, 0, 0);">get_metaData</span>() {<br>
|
||||||
|
$return = array();<br>
|
||||||
|
// manages host accounts<br>
|
||||||
|
$return["account_types"] =
|
||||||
|
array("host");<br>
|
||||||
|
}<br>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<br>
|
||||||
|
You will see this functions several times in the next parts of this
|
||||||
|
HowTo.<br>
|
||||||
|
<br>
|
||||||
|
<h2><span style="font-weight: bold;"></span></h2>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -0,0 +1,198 @@
|
||||||
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Module HowTo - General module options</title>
|
||||||
|
<link rel="stylesheet" type="text/css" href="style/layout.css">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div style="text-align: center;">
|
||||||
|
<h1>Module HowTo - General module options<br>
|
||||||
|
</h1>
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
<div style="text-align: left;"><br>
|
||||||
|
<h2>1. Account types<br>
|
||||||
|
</h2>
|
||||||
|
LAM currently provides three account types: <span
|
||||||
|
style="font-weight: bold;">users, groups, hosts<br>
|
||||||
|
</span>A module can manage one or more account types.<br>
|
||||||
|
<br>
|
||||||
|
The types are specified with <span style="font-weight: bold;">can_manage()</span>
|
||||||
|
or <span style="font-weight: bold;">meta['account_types']</span>.<br>
|
||||||
|
<br>
|
||||||
|
<span style="font-weight: bold; text-decoration: underline;">Example:</span><br
|
||||||
|
style="font-weight: bold; text-decoration: underline;">
|
||||||
|
<br>
|
||||||
|
Our <span style="font-style: italic;">ieee802Device</span>
|
||||||
|
module will be used only for host accounts.<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>
|
||||||
|
* Returns meta data that is interpreted by parent
|
||||||
|
class<br>
|
||||||
|
*<br>
|
||||||
|
* @return array array with meta data<br>
|
||||||
|
*/<br>
|
||||||
|
<span style="font-weight: bold;">function</span>
|
||||||
|
get_metaData() {<br>
|
||||||
|
$return = array();<br>
|
||||||
|
// manages host accounts<br>
|
||||||
|
<span style="color: rgb(255, 0, 0);">
|
||||||
|
$return["account_types"] = array("host");</span><br
|
||||||
|
style="color: rgb(255, 0, 0);">
|
||||||
|
return $return;<br>
|
||||||
|
}<br>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
<h2>2. Alias name</h2>
|
||||||
|
The module name is very limited, therefore every module has an <span
|
||||||
|
style="font-style: italic;">alias name</span>. This <span
|
||||||
|
style="font-style: italic;">alias name</span> has no limitations and
|
||||||
|
can be translated. It may contain special characters but make sure that
|
||||||
|
it does not contain HTML special characters like "<".<br>
|
||||||
|
The <span style="font-style: italic;">alias name </span>can be the
|
||||||
|
same for all managed <span style="font-style: italic;">account types</span>
|
||||||
|
or differ for each type.<br>
|
||||||
|
<br>
|
||||||
|
The <span style="font-style: italic;">alias name</span> is specified
|
||||||
|
with <span style="font-weight: bold;">get_alias()</span>
|
||||||
|
or <span style="font-weight: bold;">meta['alias']</span>.<br>
|
||||||
|
<br>
|
||||||
|
<span style="font-weight: bold; text-decoration: underline;">Example:</span><br
|
||||||
|
style="font-weight: bold; text-decoration: underline;">
|
||||||
|
<br>
|
||||||
|
Our <span style="font-style: italic;">ieee802Device</span>
|
||||||
|
module will get the alias MAC address.<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>
|
||||||
|
* Returns meta data that is interpreted by parent
|
||||||
|
class<br>
|
||||||
|
*<br>
|
||||||
|
* @return array array with meta data<br>
|
||||||
|
*/<br>
|
||||||
|
<span style="font-weight: bold;">function</span>
|
||||||
|
get_metaData() {<br>
|
||||||
|
$return = array();<br>
|
||||||
|
// manages host accounts<br>
|
||||||
|
<span style="color: rgb(255, 0, 0);">
|
||||||
|
</span>$return["account_types"] = array("host");<br
|
||||||
|
style="color: rgb(255, 0, 0);">
|
||||||
|
// alias name<br>
|
||||||
|
<span style="color: rgb(255, 0, 0);">
|
||||||
|
$return["alias"] = _("MAC address");</span><br
|
||||||
|
style="color: rgb(255, 0, 0);">
|
||||||
|
return $return;<br>
|
||||||
|
}<br>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
<h2>3. Dependencies</h2>
|
||||||
|
Modules can depend on eachother. This is useful if you need to access
|
||||||
|
attributes from other modules or the managed object classes of your
|
||||||
|
module are not structural.<br>
|
||||||
|
<br>
|
||||||
|
The dependencies are specified with <span style="font-weight: bold;">get_dependencies()</span>
|
||||||
|
or <span style="font-weight: bold;">meta['dependencies']</span>.<br>
|
||||||
|
<br>
|
||||||
|
<span style="font-weight: bold; text-decoration: underline;">Example:</span><br
|
||||||
|
style="font-weight: bold; text-decoration: underline;">
|
||||||
|
<br>
|
||||||
|
Our <span style="font-style: italic;">ieee802Device</span>
|
||||||
|
module depends on the account module (because it is the only structural
|
||||||
|
module at this time).<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>
|
||||||
|
* Returns meta data that is interpreted by parent
|
||||||
|
class<br>
|
||||||
|
*<br>
|
||||||
|
* @return array array with meta data<br>
|
||||||
|
*/<br>
|
||||||
|
<span style="font-weight: bold;">function</span>
|
||||||
|
get_metaData() {<br>
|
||||||
|
$return = array();<br>
|
||||||
|
// manages host accounts<br>
|
||||||
|
<span style="color: rgb(255, 0, 0);">
|
||||||
|
</span>$return["account_types"] = array("host");<br
|
||||||
|
style="color: rgb(255, 0, 0);">
|
||||||
|
// alias name<br>
|
||||||
|
$return["alias"] = _("MAC
|
||||||
|
address");<br>
|
||||||
|
// module dependencies<br>
|
||||||
|
<span style="color: rgb(255, 0, 0);">
|
||||||
|
$return['dependencies'] = array('depends' =>
|
||||||
|
array('account'), 'conflicts' => array());</span><br
|
||||||
|
style="color: rgb(255, 0, 0);">
|
||||||
|
return $return;<br>
|
||||||
|
}<br>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
<h2>4. Messages</h2>
|
||||||
|
There are many situations where you will display messages to the user.
|
||||||
|
The modules should define such messages at a common place to make it
|
||||||
|
easier to modify them without searching the complete file.<br>
|
||||||
|
The <span style="font-style: italic;">baseModule</span> offers the $<span
|
||||||
|
style="font-weight: bold;">messages</span> variable for this. It
|
||||||
|
should be filled by a function called <span style="font-weight: bold;">load_Messages()</span>.<br>
|
||||||
|
The <span style="font-style: italic;">baseModule</span> will
|
||||||
|
automatically check if you have implemented this function and call it
|
||||||
|
at construction time.<br>
|
||||||
|
<br>
|
||||||
|
<span style="font-weight: bold; text-decoration: underline;">Example:</span><br
|
||||||
|
style="font-weight: bold; text-decoration: underline;">
|
||||||
|
<br>
|
||||||
|
Now let our <span style="font-style: italic;">ieee802Device</span>
|
||||||
|
module define a message.<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 fills the error message array with
|
||||||
|
messages<br>
|
||||||
|
*/<br>
|
||||||
|
<span style="font-weight: bold;">function</span> <span
|
||||||
|
style="color: rgb(255, 0, 0);">load_Messages</span>() {<br>
|
||||||
|
$this->messages['mac'][0] =
|
||||||
|
array('ERROR', 'MAC address is invalid!'); // third array value
|
||||||
|
is set dynamically<br>
|
||||||
|
}<br>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
<h2><br>
|
||||||
|
</h2>
|
||||||
|
<h2></h2>
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
<span style="font-weight: bold;"></span>
|
||||||
|
<h2><span style="font-weight: bold;"></span></h2>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -0,0 +1,88 @@
|
||||||
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Module HowTo - Help entries</title>
|
||||||
|
<link rel="stylesheet" type="text/css" href="style/layout.css">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div style="text-align: center;">
|
||||||
|
<h1>Module HowTo - Help entries<br>
|
||||||
|
</h1>
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
<div style="text-align: left;"><br>
|
||||||
|
<h2>1. Defining help entries<br>
|
||||||
|
</h2>
|
||||||
|
Your module should provide help for all input fields and other
|
||||||
|
important things.<br>
|
||||||
|
The LAM help system defines an extra ID range for each module. So you
|
||||||
|
are free in defining your own IDs.<br>
|
||||||
|
<br>
|
||||||
|
The help entries are specified with <span style="font-weight: bold;">get_help()</span>
|
||||||
|
or <span style="font-weight: bold;">meta['help']</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 needs help entries for the MAC address.<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>
|
||||||
|
* Returns meta data that is interpreted by parent
|
||||||
|
class<br>
|
||||||
|
*<br>
|
||||||
|
* @return array array with meta data<br>
|
||||||
|
*/<br>
|
||||||
|
<span style="font-weight: bold;">function</span>
|
||||||
|
get_metaData() {<br>
|
||||||
|
$return = array();<br>
|
||||||
|
<span style="color: rgb(255, 0, 0);">
|
||||||
|
// help Entries</span><br
|
||||||
|
style="color: rgb(255, 0, 0);">
|
||||||
|
<span style="color: rgb(255, 0, 0);">
|
||||||
|
$return['help'] = array(</span><br
|
||||||
|
style="color: rgb(255, 0, 0);">
|
||||||
|
<span style="color: rgb(255, 0, 0);">
|
||||||
|
'mac' => array(</span><br
|
||||||
|
style="color: rgb(255, 0, 0);">
|
||||||
|
<span style="color: rgb(255, 0, 0);">
|
||||||
|
"Headline"
|
||||||
|
=> _("MAC address"),</span><br style="color: rgb(255, 0, 0);">
|
||||||
|
<span style="color: rgb(255, 0, 0);">
|
||||||
|
"Text" =>
|
||||||
|
_("This is the MAC address of the network card of the device (e.g.
|
||||||
|
00:01:02:DE:EF:18).")</span><br style="color: rgb(255, 0, 0);">
|
||||||
|
<span style="color: rgb(255, 0, 0);">
|
||||||
|
),</span><br
|
||||||
|
style="color: rgb(255, 0, 0);">
|
||||||
|
<span style="color: rgb(255, 0, 0);">
|
||||||
|
'macList' => array(</span><br
|
||||||
|
style="color: rgb(255, 0, 0);">
|
||||||
|
<span style="color: rgb(255, 0, 0);">
|
||||||
|
"Headline"
|
||||||
|
=> _("MAC address list"),</span><br style="color: rgb(255, 0, 0);">
|
||||||
|
<span style="color: rgb(255, 0, 0);">
|
||||||
|
"Text" =>
|
||||||
|
_("This is a comma separated list of MAC addresses.")</span><br
|
||||||
|
style="color: rgb(255, 0, 0);">
|
||||||
|
<span style="color: rgb(255, 0, 0);">
|
||||||
|
));</span><br
|
||||||
|
style="color: rgb(255, 0, 0);">
|
||||||
|
return $return;<br>
|
||||||
|
}<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>
|
|
@ -0,0 +1,55 @@
|
||||||
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>LAM module HowTo</title>
|
||||||
|
<link rel="stylesheet" type="text/css" href="style/layout.css">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div style="text-align: center;">
|
||||||
|
<h1>Module HowTo</h1>
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
<div style="text-align: left;">
|
||||||
|
<h2>Basic functions</h2>
|
||||||
|
<br>
|
||||||
|
</div>
|
||||||
|
<div style="text-align: left;">LAM can be easily extended to support
|
||||||
|
additional LDAP object classes and attributes.<br>
|
||||||
|
This document provides a step-by-step description to build an account
|
||||||
|
module. The <span style="font-style: italic;">ieee802Device</span>
|
||||||
|
module which provides MAC addresses for hosts is used as example.<br>
|
||||||
|
<br>
|
||||||
|
<h3><a href="mod_basics.htm">1. Basic concepts</a><br>
|
||||||
|
</h3>
|
||||||
|
<br>
|
||||||
|
<h3><a href="mod_general.htm">2. General module options</a></h3>
|
||||||
|
<br>
|
||||||
|
<h3><a href="mod_accountPages.htm">3. Account pages</a></h3>
|
||||||
|
<br>
|
||||||
|
<h3><a href="mod_help.htm">4. Help entries<br>
|
||||||
|
</a></h3>
|
||||||
|
<br>
|
||||||
|
<h3><a href="mod_pdf.htm">5. PDF output<br>
|
||||||
|
</a></h3>
|
||||||
|
<br>
|
||||||
|
<h3><a href="mod_upload.htm">6. File upload</a></h3>
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
<hr style="width: 100%; height: 2px;"><br>
|
||||||
|
<br>
|
||||||
|
<h2>Advanced functions</h2>
|
||||||
|
This part covers additional functionality of the modules which are only
|
||||||
|
needed by a minority of modules. The examples are taken from different
|
||||||
|
existing modules.<br>
|
||||||
|
<br>
|
||||||
|
<h3>1. Account profiles</h3>
|
||||||
|
<br>
|
||||||
|
<h3>2. Configuration options</h3>
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -0,0 +1,171 @@
|
||||||
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Module HowTo - File upload</title>
|
||||||
|
<link rel="stylesheet" type="text/css" href="style/layout.css">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div style="text-align: center;">
|
||||||
|
<h1>Module HowTo - File upload<br>
|
||||||
|
</h1>
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
<div style="text-align: left;"><br>
|
||||||
|
<h2>1. Defining upload columns<br>
|
||||||
|
</h2>
|
||||||
|
If you want to support account creation via file upload you have to
|
||||||
|
define columns in the CSV file.<br>
|
||||||
|
Each column has an non-translated identifier, a description, help entry
|
||||||
|
and several other values.<br>
|
||||||
|
<br>
|
||||||
|
The upload columns are specified with <span style="font-weight: bold;">get_uploadColumns()</span>
|
||||||
|
or <span style="font-weight: bold;">meta['upload_columns']</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 has only one attribute and therefore one column: the MAC address.<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>
|
||||||
|
* Returns meta data that is interpreted by parent
|
||||||
|
class<br>
|
||||||
|
*<br>
|
||||||
|
* @return array array with meta data<br>
|
||||||
|
*/<br>
|
||||||
|
<span style="font-weight: bold;">function</span>
|
||||||
|
get_metaData() {<br>
|
||||||
|
$return = array();<br>
|
||||||
|
// manages host accounts<br>
|
||||||
|
|
||||||
|
$return["account_types"] = array("host");<br>
|
||||||
|
// upload fields<br>
|
||||||
|
<span style="color: rgb(255, 0, 0);">
|
||||||
|
$return['upload_columns'] = array(</span><br
|
||||||
|
style="color: rgb(255, 0, 0);">
|
||||||
|
<span style="color: rgb(255, 0, 0);">
|
||||||
|
array(</span><br
|
||||||
|
style="color: rgb(255, 0, 0);">
|
||||||
|
<span style="color: rgb(255, 0, 0);">
|
||||||
|
'name' =>
|
||||||
|
'ieee802Device_mac',</span><br style="color: rgb(255, 0, 0);">
|
||||||
|
<span style="color: rgb(255, 0, 0);">
|
||||||
|
'description'
|
||||||
|
=> _('MAC address'),</span><br style="color: rgb(255, 0, 0);">
|
||||||
|
<span style="color: rgb(255, 0, 0);">
|
||||||
|
'help' =>
|
||||||
|
'mac',</span><br style="color: rgb(255, 0, 0);">
|
||||||
|
<span style="color: rgb(255, 0, 0);">
|
||||||
|
'example'
|
||||||
|
=> '00:01:02:DE:EF:18'</span><br style="color: rgb(255, 0, 0);">
|
||||||
|
<span style="color: rgb(255, 0, 0);">
|
||||||
|
)</span><br
|
||||||
|
style="color: rgb(255, 0, 0);">
|
||||||
|
<span style="color: rgb(255, 0, 0);">
|
||||||
|
);</span><br>
|
||||||
|
return $return;<br>
|
||||||
|
}<br>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
<h2>2. Building the accounts<br>
|
||||||
|
</h2>
|
||||||
|
When the user has uploaded the CSV file the modules have to transform
|
||||||
|
the input data to LDAP accounts.<br>
|
||||||
|
<br>
|
||||||
|
This is done with <span style="font-weight: bold;">build_uploadAccounts()</span>.
|
||||||
|
The function gets the input data and a list of LDAP accounts as
|
||||||
|
parameter.<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 LDAP attribute - <span style="font-style: italic;">'macAddress'</span>
|
||||||
|
- and the <span style="font-style: italic;">'ieee802Device'</span>
|
||||||
|
objectClass which is added to all accounts.<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>
|
||||||
|
* In this function the LDAP account is built up.<br>
|
||||||
|
*<br>
|
||||||
|
* @param array $rawAccounts list of hash arrays
|
||||||
|
(name => value) from user input<br>
|
||||||
|
* @param array $partialAccounts list of hash arrays
|
||||||
|
(name => value) which are later added to LDAP<br>
|
||||||
|
* @param array $ids list of IDs for column position
|
||||||
|
(e.g. "posixAccount_uid" => 5)<br>
|
||||||
|
* @return array list of error messages if any<br>
|
||||||
|
*/<br>
|
||||||
|
<span style="font-weight: bold;">function</span> <span
|
||||||
|
style="color: rgb(255, 0, 0);">build_uploadAccounts</span>($rawAccounts,
|
||||||
|
$ids, &$partialAccounts) {<br>
|
||||||
|
$messages = array();<br>
|
||||||
|
for ($i = 0; $i <
|
||||||
|
sizeof($rawAccounts); $i++) {<br>
|
||||||
|
// add object
|
||||||
|
class<br>
|
||||||
|
if
|
||||||
|
(!in_array("ieee802Device", $partialAccounts[$i]['objectClass']))
|
||||||
|
$partialAccounts[$i]['objectClass'][] = "ieee802Device";<br>
|
||||||
|
// add MACs<br>
|
||||||
|
if
|
||||||
|
($rawAccounts[$i][$ids['ieee802Device_mac']] != "") {<br>
|
||||||
|
|
||||||
|
$macs = explode(',',
|
||||||
|
$rawAccounts[$i][$ids['ieee802Device_mac']]);<br>
|
||||||
|
|
||||||
|
// check format<br>
|
||||||
|
|
||||||
|
for ($m = 0; $m < sizeof($macs); $m++) {<br>
|
||||||
|
|
||||||
|
if (get_preg($macs[$m],
|
||||||
|
'macAddress')) {<br>
|
||||||
|
|
||||||
|
|
||||||
|
$partialAccounts[$i]['macAddress'][] = $macs[$m];<br>
|
||||||
|
|
||||||
|
}<br>
|
||||||
|
|
||||||
|
else {<br>
|
||||||
|
|
||||||
|
$errMsg =
|
||||||
|
$this->messages['mac'][1];<br>
|
||||||
|
|
||||||
|
|
||||||
|
array_push($errMsg, array($i));<br>
|
||||||
|
|
||||||
|
$messages[] =
|
||||||
|
$errMsg;<br>
|
||||||
|
|
||||||
|
}<br>
|
||||||
|
|
||||||
|
}<br>
|
||||||
|
}<br>
|
||||||
|
}<br>
|
||||||
|
return $messages;<br>
|
||||||
|
}<br>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
<span style="font-weight: bold;"></span>
|
||||||
|
<h2><span style="font-weight: bold;"></span></h2>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
Reference in New Issue