| 
									
										
										
										
											2004-11-01 16:53:04 +00:00
										 |  |  | <?php | 
					
						
							|  |  |  | /* | 
					
						
							|  |  |  | $Id$ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-27 18:47:12 +00:00
										 |  |  |   This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) | 
					
						
							| 
									
										
										
										
											2012-02-04 15:56:31 +00:00
										 |  |  |   Copyright (C) 2004 - 2012  Roland Gruber | 
					
						
							| 
									
										
										
										
											2004-11-01 16:53:04 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   This program is free software; you can redistribute it and/or modify | 
					
						
							|  |  |  |   it under the terms of the GNU General Public License as published by | 
					
						
							|  |  |  |   the Free Software Foundation; either version 2 of the License, or | 
					
						
							|  |  |  |   (at your option) any later version. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   This program is distributed in the hope that it will be useful, | 
					
						
							|  |  |  |   but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							|  |  |  |   GNU General Public License for more details. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   You should have received a copy of the GNU General Public License | 
					
						
							|  |  |  |   along with this program; if not, write to the Free Software | 
					
						
							|  |  |  |   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  | * Provides MAC addresses for hosts. | 
					
						
							|  |  |  | * | 
					
						
							|  |  |  | * @package modules | 
					
						
							|  |  |  | * @author Roland Gruber | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  | * Provides MAC addresses for hosts. | 
					
						
							|  |  |  | * | 
					
						
							|  |  |  | * @package modules | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | class ieee802Device extends baseModule { | 
					
						
							| 
									
										
										
										
											2006-08-13 12:58:19 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-11-01 16:53:04 +00:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	* Returns meta data that is interpreted by parent class | 
					
						
							|  |  |  | 	* | 
					
						
							|  |  |  | 	* @return array array with meta data | 
					
						
							| 
									
										
										
										
											2008-02-03 14:28:28 +00:00
										 |  |  | 	*  | 
					
						
							|  |  |  | 	* @see baseModule::get_metaData() | 
					
						
							| 
									
										
										
										
											2004-11-01 16:53:04 +00:00
										 |  |  | 	*/ | 
					
						
							|  |  |  | 	function get_metaData() { | 
					
						
							|  |  |  | 		$return = array(); | 
					
						
							| 
									
										
										
										
											2007-11-19 18:42:03 +00:00
										 |  |  | 		// icon
 | 
					
						
							| 
									
										
										
										
											2007-12-01 12:34:52 +00:00
										 |  |  | 		$return['icon'] = 'network-wired.png'; | 
					
						
							| 
									
										
										
										
											2004-11-01 16:53:04 +00:00
										 |  |  | 		// manages host accounts
 | 
					
						
							|  |  |  | 		$return["account_types"] = array("host"); | 
					
						
							|  |  |  | 		// alias name
 | 
					
						
							|  |  |  | 		$return["alias"] = _("MAC address"); | 
					
						
							|  |  |  | 		// module dependencies
 | 
					
						
							| 
									
										
										
										
											2005-01-10 10:41:38 +00:00
										 |  |  | 		$return['dependencies'] = array('depends' => array(), 'conflicts' => array()); | 
					
						
							| 
									
										
										
										
											2006-04-05 15:48:27 +00:00
										 |  |  | 		// managed object classes
 | 
					
						
							|  |  |  | 		$return['objectClasses'] = array('ieee802Device'); | 
					
						
							| 
									
										
										
										
											2006-05-13 08:55:31 +00:00
										 |  |  | 		// managed attributes
 | 
					
						
							|  |  |  | 		$return['attributes'] = array('macAddress'); | 
					
						
							| 
									
										
										
										
											2004-11-01 16:53:04 +00:00
										 |  |  | 		// help Entries
 | 
					
						
							|  |  |  | 		$return['help'] = array( | 
					
						
							|  |  |  | 			'mac' => array( | 
					
						
							| 
									
										
										
										
											2012-02-04 15:56:31 +00:00
										 |  |  | 				"Headline" => _("MAC address"), 'attr' => 'macAddress', | 
					
						
							| 
									
										
										
										
											2004-11-01 16:53:04 +00:00
										 |  |  | 				"Text" => _("This is the MAC address of the network card of the device (e.g. 00:01:02:DE:EF:18).") | 
					
						
							|  |  |  | 			), | 
					
						
							|  |  |  | 			'macList' => array( | 
					
						
							| 
									
										
										
										
											2012-02-04 15:56:31 +00:00
										 |  |  | 				"Headline" => _("MAC address list"), 'attr' => 'macAddress', | 
					
						
							| 
									
										
										
										
											2004-11-01 16:53:04 +00:00
										 |  |  | 				"Text" => _("This is a comma separated list of MAC addresses.") | 
					
						
							|  |  |  | 			)); | 
					
						
							|  |  |  | 		// upload fields
 | 
					
						
							|  |  |  | 		$return['upload_columns'] = array( | 
					
						
							|  |  |  | 			array( | 
					
						
							|  |  |  | 				'name' => 'ieee802Device_mac', | 
					
						
							|  |  |  | 				'description' => _('MAC address'), | 
					
						
							|  |  |  | 				'help' => 'macList', | 
					
						
							|  |  |  | 				'example' => '00:01:02:DE:EF:18' | 
					
						
							|  |  |  | 			) | 
					
						
							|  |  |  | 		); | 
					
						
							|  |  |  | 		// available PDF fields
 | 
					
						
							|  |  |  | 		$return['PDF_fields'] = array( | 
					
						
							| 
									
										
										
										
											2012-02-08 19:12:00 +00:00
										 |  |  | 			'macAddress' => _('MAC addresses') | 
					
						
							| 
									
										
										
										
											2004-11-01 16:53:04 +00:00
										 |  |  | 		); | 
					
						
							|  |  |  | 		return $return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	* This function fills the error message array with messages | 
					
						
							|  |  |  | 	*/ | 
					
						
							|  |  |  | 	function load_Messages() { | 
					
						
							|  |  |  | 		$this->messages['mac'][0] = array('ERROR', 'MAC address is invalid!');  // third array value is set dynamically
 | 
					
						
							|  |  |  | 		$this->messages['mac'][1] = array('ERROR', _('Account %s:') . ' ieee802Device_mac', 'MAC address is invalid!'); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2006-08-13 12:58:19 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-11-01 16:53:04 +00:00
										 |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2007-11-03 14:17:19 +00:00
										 |  |  | 	 * Returns the HTML meta data for the main account page. | 
					
						
							|  |  |  | 	 *  | 
					
						
							| 
									
										
										
										
											2010-09-18 11:37:22 +00:00
										 |  |  | 	 * @return htmlElement HTML meta data | 
					
						
							| 
									
										
										
										
											2007-11-03 14:17:19 +00:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2006-08-13 12:58:19 +00:00
										 |  |  | 	function display_html_attributes() { | 
					
						
							| 
									
										
										
										
											2010-09-18 11:37:22 +00:00
										 |  |  | 		$return = new htmlTable(); | 
					
						
							|  |  |  | 		$macCount = 0; | 
					
						
							| 
									
										
										
										
											2004-11-01 16:53:04 +00:00
										 |  |  | 		// list current MACs
 | 
					
						
							| 
									
										
										
										
											2010-09-18 11:37:22 +00:00
										 |  |  | 		if (isset($this->attributes['macAddress'])) { | 
					
						
							|  |  |  | 			$macCount = sizeof($this->attributes['macAddress']); | 
					
						
							|  |  |  | 			for ($i = 0; $i < sizeof($this->attributes['macAddress']); $i++) { | 
					
						
							|  |  |  | 				$return->addElement(new htmlOutputText(_('MAC address'))); | 
					
						
							|  |  |  | 				$macInput = new htmlInputField('macAddress' . $i, $this->attributes['macAddress'][$i]); | 
					
						
							|  |  |  | 				$macInput->setFieldSize(17); | 
					
						
							|  |  |  | 				$macInput->setFieldMaxLength(17); | 
					
						
							|  |  |  | 				$return->addElement($macInput); | 
					
						
							|  |  |  | 				$return->addElement(new htmlButton('delMAC' . $i, 'del.png', true)); | 
					
						
							|  |  |  | 				$return->addElement(new htmlHelpLink('mac'), true); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2004-11-01 16:53:04 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		// input box for new MAC
 | 
					
						
							| 
									
										
										
										
											2010-09-18 11:37:22 +00:00
										 |  |  | 		$return->addElement(new htmlOutputText(_('New MAC address'))); | 
					
						
							|  |  |  | 		$newMacInput = new htmlInputField('macAddress', ''); | 
					
						
							|  |  |  | 		$newMacInput->setFieldSize(17); | 
					
						
							|  |  |  | 		$newMacInput->setFieldMaxLength(17); | 
					
						
							|  |  |  | 		$return->addElement($newMacInput); | 
					
						
							|  |  |  | 		$return->addElement(new htmlButton('addMAC', 'add.png', true)); | 
					
						
							|  |  |  | 		$return->addElement(new htmlHelpLink('mac')); | 
					
						
							|  |  |  | 		$return->addElement(new htmlHiddenInput('mac_number', $macCount)); | 
					
						
							| 
									
										
										
										
											2004-11-01 16:53:04 +00:00
										 |  |  | 		return $return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2005-09-07 12:58:34 +00:00
										 |  |  | 	* Processes user input of the primary module page. | 
					
						
							|  |  |  | 	* It checks if all input values are correct and updates the associated LDAP attributes. | 
					
						
							| 
									
										
										
										
											2004-11-01 16:53:04 +00:00
										 |  |  | 	* | 
					
						
							| 
									
										
										
										
											2005-09-07 12:58:34 +00:00
										 |  |  | 	* @return array list of info/error messages | 
					
						
							| 
									
										
										
										
											2004-11-01 16:53:04 +00:00
										 |  |  | 	*/ | 
					
						
							| 
									
										
										
										
											2006-08-13 12:58:19 +00:00
										 |  |  | 	function process_attributes() { | 
					
						
							| 
									
										
										
										
											2006-05-13 08:55:31 +00:00
										 |  |  | 		$errors = array(); | 
					
						
							| 
									
										
										
										
											2004-11-01 16:53:04 +00:00
										 |  |  | 		$this->attributes['macAddress'] = array(); | 
					
						
							|  |  |  | 		// check old MACs
 | 
					
						
							| 
									
										
										
										
											2006-08-13 12:58:19 +00:00
										 |  |  | 		if (isset($_POST['mac_number'])) { | 
					
						
							|  |  |  | 			for ($i = 0; $i < $_POST['mac_number']; $i++) { | 
					
						
							|  |  |  | 				if (isset($_POST['delMAC' . $i])) continue; | 
					
						
							|  |  |  | 				if (isset($_POST['macAddress' . $i]) && ($_POST['macAddress' . $i] != "")) { | 
					
						
							| 
									
										
										
										
											2004-11-01 16:53:04 +00:00
										 |  |  | 					// check if address has correct format
 | 
					
						
							| 
									
										
										
										
											2006-08-13 12:58:19 +00:00
										 |  |  | 					if (!get_preg($_POST['macAddress' . $i], 'macAddress')) { | 
					
						
							| 
									
										
										
										
											2004-11-01 16:53:04 +00:00
										 |  |  | 						$message = $this->messages['mac'][0]; | 
					
						
							| 
									
										
										
										
											2006-08-13 12:58:19 +00:00
										 |  |  | 						$message[] = $_POST['macAddress' . $i]; | 
					
						
							| 
									
										
										
										
											2006-08-16 17:42:35 +00:00
										 |  |  | 						$errors[] = $message; | 
					
						
							| 
									
										
										
										
											2004-11-01 16:53:04 +00:00
										 |  |  | 					} | 
					
						
							| 
									
										
										
										
											2006-08-13 12:58:19 +00:00
										 |  |  | 					$this->attributes['macAddress'][] = $_POST['macAddress' . $i]; | 
					
						
							| 
									
										
										
										
											2004-11-01 16:53:04 +00:00
										 |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		// check new MAC
 | 
					
						
							| 
									
										
										
										
											2006-08-13 12:58:19 +00:00
										 |  |  | 		if (isset($_POST['macAddress']) && ($_POST['macAddress'] != "")) { | 
					
						
							| 
									
										
										
										
											2004-11-01 16:53:04 +00:00
										 |  |  | 			// check if address has correct format
 | 
					
						
							| 
									
										
										
										
											2006-08-13 12:58:19 +00:00
										 |  |  | 			if (get_preg($_POST['macAddress'], 'macAddress')) { | 
					
						
							|  |  |  | 				$this->attributes['macAddress'][] = $_POST['macAddress']; | 
					
						
							| 
									
										
										
										
											2004-11-01 16:53:04 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			else { | 
					
						
							|  |  |  | 					$message = $this->messages['mac'][0]; | 
					
						
							| 
									
										
										
										
											2006-08-13 12:58:19 +00:00
										 |  |  | 					$message[] = $_POST['macAddress']; | 
					
						
							| 
									
										
										
										
											2006-08-16 17:42:35 +00:00
										 |  |  | 					$errors[] = $message; | 
					
						
							| 
									
										
										
										
											2004-11-01 16:53:04 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		$this->attributes['macAddress'] = array_unique($this->attributes['macAddress']); | 
					
						
							| 
									
										
										
										
											2006-05-13 08:55:31 +00:00
										 |  |  | 		return $errors; | 
					
						
							| 
									
										
										
										
											2004-11-01 16:53:04 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	* In this function the LDAP account is built up. | 
					
						
							|  |  |  | 	* | 
					
						
							|  |  |  | 	* @param array $rawAccounts list of hash arrays (name => value) from user input | 
					
						
							|  |  |  | 	* @param array $ids list of IDs for column position (e.g. "posixAccount_uid" => 5) | 
					
						
							| 
									
										
										
										
											2012-07-15 12:05:47 +00:00
										 |  |  | 	* @param array $partialAccounts list of hash arrays (name => value) which are later added to LDAP | 
					
						
							| 
									
										
										
										
											2010-02-15 20:21:44 +00:00
										 |  |  | 	* @param array $selectedModules list of selected account modules | 
					
						
							| 
									
										
										
										
											2004-11-01 16:53:04 +00:00
										 |  |  | 	* @return array list of error messages if any | 
					
						
							|  |  |  | 	*/ | 
					
						
							| 
									
										
										
										
											2010-02-15 20:21:44 +00:00
										 |  |  | 	function build_uploadAccounts($rawAccounts, $ids, &$partialAccounts, $selectedModules) { | 
					
						
							| 
									
										
										
										
											2004-11-01 16:53:04 +00:00
										 |  |  | 		$messages = array(); | 
					
						
							|  |  |  | 		for ($i = 0; $i < sizeof($rawAccounts); $i++) { | 
					
						
							|  |  |  | 			// add object class
 | 
					
						
							|  |  |  | 			if (!in_array("ieee802Device", $partialAccounts[$i]['objectClass'])) $partialAccounts[$i]['objectClass'][] = "ieee802Device"; | 
					
						
							|  |  |  | 			// add MACs
 | 
					
						
							|  |  |  | 			if ($rawAccounts[$i][$ids['ieee802Device_mac']] != "") { | 
					
						
							|  |  |  | 				$macs = explode(',', $rawAccounts[$i][$ids['ieee802Device_mac']]); | 
					
						
							|  |  |  | 				// check format
 | 
					
						
							|  |  |  | 				for ($m = 0; $m < sizeof($macs); $m++) { | 
					
						
							|  |  |  | 					if (get_preg($macs[$m], 'macAddress')) { | 
					
						
							|  |  |  | 						$partialAccounts[$i]['macAddress'][] = $macs[$m]; | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 					else { | 
					
						
							|  |  |  | 						$errMsg = $this->messages['mac'][1]; | 
					
						
							|  |  |  | 						array_push($errMsg, array($i)); | 
					
						
							|  |  |  | 						$messages[] = $errMsg; | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		return $messages; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2005-10-09 18:05:32 +00:00
										 |  |  | 	* Returns the PDF entries for this module. | 
					
						
							| 
									
										
										
										
											2006-08-13 12:58:19 +00:00
										 |  |  | 	* | 
					
						
							| 
									
										
										
										
											2005-10-09 18:05:32 +00:00
										 |  |  | 	* @return array list of possible PDF entries | 
					
						
							| 
									
										
										
										
											2004-11-01 16:53:04 +00:00
										 |  |  | 	*/ | 
					
						
							|  |  |  | 	function get_pdfEntries() { | 
					
						
							|  |  |  | 		$return = array(); | 
					
						
							|  |  |  | 		if (sizeof($this->attributes['macAddress']) > 0) { | 
					
						
							| 
									
										
										
										
											2012-02-08 19:12:00 +00:00
										 |  |  | 			$return['ieee802Device_macAddress'][0] = '<block><key>' . _('MAC addresses') . '</key><value>' . implode(', ', $this->attributes['macAddress']) . '</value></block>'; | 
					
						
							| 
									
										
										
										
											2004-11-01 16:53:04 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		return $return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ?>
 |