3
$Id: windowsHost.inc 4907 2013-05-10 16:20:37Z gruberroland $
5
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
6
Copyright (C) 2013 Roland Gruber
8
This program is free software; you can redistribute it and/or modify
9
it under the terms of the GNU General Public License as published by
10
the Free Software Foundation; either version 2 of the License, or
11
(at your option) any later version.
13
This program is distributed in the hope that it will be useful,
14
but WITHOUT ANY WARRANTY; without even the implied warranty of
15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
GNU General Public License for more details.
18
You should have received a copy of the GNU General Public License
19
along with this program; if not, write to the Free Software
20
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24
* Manages Windows AD (e.g. Samba 4) hosts.
27
* @author Roland Gruber
31
* Manages Windows AD (e.g. Samba 4) hosts.
35
class windowsHost extends baseModule {
38
* Returns meta data that is interpreted by parent class
40
* @return array array with meta data
42
* @see baseModule::get_metaData()
44
public function get_metaData() {
47
$return['icon'] = 'samba.png';
48
// manages host accounts
49
$return["account_types"] = array('host');
50
// this is a base module
51
$return["is_base"] = true;
53
$return["RDN"] = array("cn" => "high");
55
$return["ldap_filter"] = array('and' => "", 'or' => '(objectClass=computer)');
57
$return["alias"] = _("Windows");
58
// module dependencies
59
$return['dependencies'] = array('depends' => array(), 'conflicts' => array());
60
// managed object classes
61
$return['objectClasses'] = array('computer', 'securityPrincipal');
63
$return['attributes'] = array('cn', 'description', 'location', 'sAMAccountName', 'managedBy', 'operatingSystem', 'operatingSystemVersion', 'dNSHostName');
65
$return['help'] = array(
67
"Headline" => _('Host name'), 'attr' => 'cn, sAMAccountName',
68
"Text" => _('Please enter the host name.')
70
'description' => array(
71
"Headline" => _('Description'), 'attr' => 'description',
72
"Text" => _('Please enter a descriptive text for this host.')
75
"Headline" => _('Location'), 'attr' => 'location',
76
"Text" => _('This is the host\'s location (e.g. Munich, server room 3).')
79
"Headline" => _('Managed by'), 'attr' => 'managedBy',
80
"Text" => _('The host is managed by this contact person.')
84
$return['upload_columns'] = array(
86
'name' => 'windowsHost_name',
87
'description' => _('Host name'),
89
'example' => _('PC01'),
93
'name' => 'windowsHost_description',
94
'description' => _('Description'),
95
'help' => 'description',
98
'name' => 'windowsHost_location',
99
'description' => _('Location'),
100
'help' => 'location',
101
'example' => _('MyCity'),
104
'name' => 'windowsHost_managedBy',
105
'description' => _('Managed by'),
106
'help' => 'managedBy',
107
'example' => 'cn=user1,o=test',
110
// available PDF fields
111
$return['PDF_fields'] = array(
112
'cn' => _('Host name'),
113
'description' => _('Description'),
114
'location' => _('Location'),
115
'managedBy' => _('Managed by'),
121
* This function fills the $messages variable with output messages from this module.
123
public function load_Messages() {
124
$this->messages['cn'][0] = array('ERROR', _('Host name'), _('Host name contains invalid characters. Valid characters are: a-z, A-Z, 0-9 and .-_ !'));
125
$this->messages['cn'][1] = array('ERROR', _('Account %s:') . ' windowsHost_cn', _('Host name contains invalid characters. Valid characters are: a-z, A-Z, 0-9 and .-_ !'));
129
* Returns the HTML meta data for the main account page.
131
* @return htmlElement HTML meta data
133
public function display_html_attributes() {
134
$container = new htmlTable();
135
$this->addSimpleInputTextField($container, 'cn', _('Host name'), true);
136
$this->addSimpleInputTextField($container, 'description', _('Description'), false);
137
$this->addSimpleInputTextField($container, 'location', _('Location'), false);
139
$container->addElement(new htmlOutputText(_('Managed by')));
141
if (isset($this->attributes['managedBy'][0])) {
142
$managedBy = $this->attributes['managedBy'][0];
144
$container->addElement(new htmlOutputText(getAbstractDN($managedBy)));
145
$container->addElement(new htmlHelpLink('managedBy'), true);
146
$container->addElement(new htmlOutputText(''));
147
$managedByButtons = new htmlGroup();
148
$managedByButtons->addElement(new htmlAccountPageButton(get_class($this), 'managedBy', 'edit', _('Change')));
149
if (isset($this->attributes['managedBy'][0])) {
150
$managedByButtons->addElement(new htmlSpacer('5px', null));
151
$managedByButtons->addElement(new htmlAccountPageButton(get_class($this), 'attributes', 'removeManagedBy', _('Remove')));
153
$container->addElement($managedByButtons, true);
158
* Processes user input of the primary module page.
159
* It checks if all input values are correct and updates the associated LDAP attributes.
161
* @return array list of info/error messages
163
public function process_attributes() {
166
$this->attributes['cn'][0] = $_POST['cn'];
167
$this->attributes['sAMAccountName'][0] = $_POST['cn'] . '$';
168
if (!get_preg($_POST['cn'], 'hostname')) {
169
$return[] = $this->messages['cn'][0];
172
$this->attributes['description'][0] = $_POST['description'];
174
$this->attributes['location'][0] = $_POST['location'];
176
if (isset($_POST['form_subpage_' . get_class($this) . '_attributes_removeManagedBy'])) {
177
unset($this->attributes['managedBy']);
179
if ($this->getAccountContainer()->isNewAccount) {
180
$this->attributes['userAccountControl'][0] = 4128; // machine trust account, no password required
186
* This function will create the meta HTML code to show a page to change the member attribute.
188
* @return htmlElement HTML meta data
190
function display_html_managedBy() {
191
$return = new htmlTable();
192
// show possible managers
194
$filter = get_ldap_filter('user');
195
$entries = searchLDAPByFilter($filter, array('dn'), array('user'));
196
for ($i = 0; $i < sizeof($entries); $i++) {
197
$entries[$i] = $entries[$i]['dn'];
200
usort($entries, 'compareDN');
201
for ($i = 0; $i < sizeof($entries); $i++) {
202
$options[getAbstractDN($entries[$i])] = $entries[$i];
205
if (isset($this->attributes['managedBy'][0])) {
206
$selected = array($this->attributes['managedBy'][0]);
207
if (!in_array($selected[0], $options)) {
208
$options[getAbstractDN($selected[0])] = $selected[0];
211
$membersSelect = new htmlSelect('managedBy', $options, $selected);
212
$membersSelect->setHasDescriptiveElements(true);
213
$membersSelect->setRightToLeftTextDirection(true);
214
$membersSelect->setSortElements(false);
215
$membersSelect->setTransformSingleSelect(false);
216
$return->addElement($membersSelect, true);
217
$buttonTable = new htmlTable();
218
$buttonTable->addElement(new htmlAccountPageButton(get_class($this), 'attributes', 'set', _('Change')));
219
$buttonTable->addElement(new htmlAccountPageButton(get_class($this), 'attributes', 'cancel', _('Cancel')));
220
$return->addElement($buttonTable);
225
* Processes user input of the members page.
226
* It checks if all input values are correct and updates the associated LDAP attributes.
228
* @return array list of info/error messages
230
function process_managedBy() {
232
if (isset($_POST['form_subpage_' . get_class($this) . '_attributes_set'])) {
233
$this->attributes['managedBy'][] = $_POST['managedBy'];
239
* In this function the LDAP account is built up.
241
* @param array $rawAccounts list of hash arrays (name => value) from user input
242
* @param array $ids list of IDs for column position (e.g. "posixAccount_uid" => 5)
243
* @param array $partialAccounts list of hash arrays (name => value) which are later added to LDAP
244
* @param array $selectedModules list of selected account modules
245
* @return array list of error messages if any
247
public function build_uploadAccounts($rawAccounts, $ids, &$partialAccounts, $selectedModules) {
249
for ($i = 0; $i < sizeof($rawAccounts); $i++) {
251
if (!in_array('computer', $partialAccounts[$i]['objectClass'])) $partialAccounts[$i]['objectClass'][] = 'computer';
252
// cn + sAMAccountName
253
if ($rawAccounts[$i][$ids['windowsHost_name']] != "") {
254
if (get_preg($rawAccounts[$i][$ids['windowsHost_name']], 'hostname')) {
255
$partialAccounts[$i]['cn'] = $rawAccounts[$i][$ids['windowsHost_name']];
256
$partialAccounts[$i]['sAMAccountName'] = $rawAccounts[$i][$ids['windowsHost_name']] . '$';
259
$errMsg = $this->messages['cn'][1];
260
array_push($errMsg, array($i));
265
if ($rawAccounts[$i][$ids['windowsHost_description']] != "") {
266
$partialAccounts[$i]['description'] = $rawAccounts[$i][$ids['windowsHost_description']];
269
if ($rawAccounts[$i][$ids['windowsHost_location']] != "") {
270
$partialAccounts[$i]['location'] = $rawAccounts[$i][$ids['windowsHost_location']];
273
if ($rawAccounts[$i][$ids['windowsHost_managedBy']] != "") {
274
$partialAccounts[$i]['managedBy'] = $rawAccounts[$i][$ids['windowsHost_managedBy']];
276
// machine trust account, no password required
277
$partialAccounts[$i]['userAccountControl'][0] = 4128;
283
* Returns a list of PDF entries
285
public function get_pdfEntries() {
287
$this->addSimplePDFField($return, 'cn', _('Host name'));
288
$this->addSimplePDFField($return, 'description', _('Description'));
289
$this->addSimplePDFField($return, 'location', _('Location'));
292
if (isset($this->attributes['managedBy'][0])) {
293
$managedBy = getAbstractDN($this->attributes['managedBy'][0]);
294
$return[get_class($this) . '_managedBy'] = array('<block><key>' . _('Managed by') . '</key><value>' . $managedBy . '</value></block>');