1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
|
<!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">
<link rel="shortcut icon" type="image/x-icon" href="images/favicon.ico"></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> * @param array $selectedModules list of selected account modules<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, $selectedModules) {<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>
|