From 0f098dc6a896ea931adfb357497fc97db46bd9d2 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Sun, 23 Oct 2011 12:24:14 +0000 Subject: [PATCH] FreeRadius --- lam/HISTORY | 3 +- lam/graphics/freeRadius.png | Bin 0 -> 2610 bytes lam/lib/modules/freeRadius.inc | 344 +++++++++++++++++++++++++++++++++ 3 files changed, 346 insertions(+), 1 deletion(-) create mode 100644 lam/graphics/freeRadius.png create mode 100644 lam/lib/modules/freeRadius.inc diff --git a/lam/HISTORY b/lam/HISTORY index eb377951..490f4a4b 100644 --- a/lam/HISTORY +++ b/lam/HISTORY @@ -2,10 +2,11 @@ November 2011 3.6.0 - support HTTP authentication for admin pages and self service - new modules -> authorizedServiceObject + -> FreeRadius - LAM Pro -> added password self reset feature -> Zarafa 7 support - -> Zarafa support for dynamic groups, adress lists and contacts + -> Zarafa support for dynamic groups, address lists and contacts -> Unix: group of names can be managed on user edit page - Fixed bugs: -> Unix: check for upper-case characters in user name (3416180) diff --git a/lam/graphics/freeRadius.png b/lam/graphics/freeRadius.png new file mode 100644 index 0000000000000000000000000000000000000000..b6d267aff1b17e11ad5e092145054beaf5a9d6de GIT binary patch literal 2610 zcmV-23eEM2P)(`0gwg?O)zxu3P_qU!q{jjWZRs_=ol4x3*p<5lzOH15~uD!S(MxhUfU1hkcXKLcrlhsO~>W zAQyd1F0NyCGKVQ|&6;A%oKh^J^O~Zo$_&NlGNoWs2Yd>@+V8Rec z0Z9`a0z3*RZtF($M4_t>;t@eeODmzHJzJ%yjzSw?)1W?zRIZON&Z1bPVd(~qe;-z8 zzaDO?fT^S4*3aS67O3fgxB$a|s19XA;I_$dxD!6Cg?$6yYlYSbtegjB1yJ7#8qnPj zjubaAx#BMEmJB2e6CyF5npm?;PlYbFn+6RXaP1{B4_*U%j#zST`3&|3VP*gh2cdt^ zN>0BQdSkG&0m=ff;tIH7I24V6ckTs`3wpz#dLXG;_R`$q^;3~Co|7QqHrZI#xq8`0 z;wh!qR8q2nVZhKl!DGLGN2kNCD0COY$Pj#54-TjGRHS9_I$&=D$}VW14(F3Kq3j>ehxSw?tqRc zDkJz>L3V&QAMD0aJ%=p}wXHbV0HY_scL(8~`QWIA=c_?Xgk|d?ONB4LvwYdJOD`DCa7?Ews z>u|v+_krdmsN^y#v4?TJgOHFw55kdcFueqpR9XPrf>7m$oHU9=ZCl* zem)i|i(tiGcy%{KIt(6K=(tHv4b&Po4MRyI#a&jF6n8+<27_TJoymN;3g`hn1i1x( zA71;+@_K+BC*fcp%*luIeQ?`IaC*R@f-Yd@(U2HPn?1g1|hS>LKRE4#ovGFJu>3cC2N? z?=FEycEGk;m^%@&J>YOdZZ=fqz!Q`Bph?pwJ6oD}+oj0*OuvtSMb@}#-aJHqPt(%?pyQCaUtOZWbh7y>dRr$Pc`)7u_7shN zm0x~q7&|8YC8EAi@%>|W>~t^3TL^X+R;>hr=g!p|nvm>=1AB+in)F`0a!mcx(}xq2 zZFBd3uHW6%D^1rV$?bGQVV23P3W@f9nl~RdzsWX}yJWxd`bRxxsD5`m`>&Tbt-tFl zcQx(|@a9?-?th2ik0t~-y9%i^*y`b(10zu!F|L~2Rxprhd;EgVO+6JQ)pr-Gj%3ov zl!UCCrrGbZ8QT55I_q9K$=VU^TTH{iFb(eeBv4I84yZm*)c@@sKtVo-006QA-g3A) zqn<=meX(?4i=xCv+;%X(@|hBa&ZtPF({$Qpu*;yE0!fp>pTp8a&T0_gwL`80RQrFM z(;xSSaUknl1OjX-IEx@#Oa5w+QO$1wmx3gp+35lZNdnbvz11e*l&pqSoOL??0g3et URHH`|`~Uy|07*qoM6N<$f(%sBVE_OC literal 0 HcmV?d00001 diff --git a/lam/lib/modules/freeRadius.inc b/lam/lib/modules/freeRadius.inc new file mode 100644 index 00000000..c2720dd6 --- /dev/null +++ b/lam/lib/modules/freeRadius.inc @@ -0,0 +1,344 @@ +autoAddObjectClasses = false; + } + + /** + * Returns meta data that is interpreted by parent class + * + * @return array array with meta data + * + * @see baseModule::get_metaData() + */ + function get_metaData() { + $return = array(); + // icon + $return['icon'] = 'freeRadius.png'; + // manages user accounts + $return["account_types"] = array("user"); + // alias name + $return["alias"] = _("FreeRadius"); + // module dependencies + $return['dependencies'] = array('depends' => array(array('posixAccount', 'inetOrgPerson')), 'conflicts' => array()); + // managed object classes + $return['objectClasses'] = array('radiusprofile'); + // managed attributes + $return['attributes'] = array('radiusFramedIPAddress', 'radiusFramedIPNetmask', 'radiusRealm'); + // help Entries + $return['help'] = array( + 'radiusFramedIPAddress' => array( + "Headline" => _("IP address"), + "Text" => _("This is the IP address for the user (e.g. 123.123.123.123).") + ), + 'radiusFramedIPNetmask' => array( + "Headline" => _("Net mask"), + "Text" => _("The net mask for the IP address.") + ), + 'radiusRealm' => array( + "Headline" => _("Realm"), + "Text" => _("The Radius realm of this account.") + ), + 'hiddenOptions' => array( + "Headline" => _("Hidden options"), + "Text" => _("The selected options will not be managed inside LAM. You can use this to reduce the number of displayed input fields.") + )); + // configuration settings + $configContainer = new htmlTable(); + $configContainerHead = new htmlTable(); + $configContainerHead->addElement(new htmlOutputText(_('Hidden options'))); + $configContainerHead->addElement(new htmlHelpLink('hiddenOptions')); + $configContainerOptions = new htmlTable(); + $configContainer->addElement($configContainerHead, true); + $configContainerOptions->addElement(new htmlTableExtendedInputCheckbox('freeRadius_hideRadiusFramedIPAddress', false, _('IP address'), null, false)); + $configContainerOptions->addElement(new htmlOutputText(' ')); + $configContainerOptions->addElement(new htmlTableExtendedInputCheckbox('freeRadius_hideRadiusFramedIPNetmask', false, _('Net mask'), null, false)); + $configContainerOptions->addElement(new htmlOutputText(' ')); + $configContainerOptions->addElement(new htmlTableExtendedInputCheckbox('freeRadius_hideRadiusRealm', false, _('Realm'), null, false)); + $configContainer->addElement($configContainerOptions, true); + $return['config_options']['all'] = $configContainer; + // profile settings + $profileElements = array(); + if (!$this->isBooleanConfigOptionSet('freeRadius_hideRadiusFramedIPNetmask')) { + $profileElements[] = new htmlTableExtendedInputField(_('Net mask'), 'freeRadius_radiusFramedIPNetmask', null, 'radiusFramedIPNetmask'); + $return['profile_checks']['freeRadius_radiusFramedIPNetmask'] = array( + 'type' => 'ext_preg', + 'regex' => 'ip', + 'error_message' => $this->messages['radiusFramedIPNetmask'][0]); + $return['profile_mappings']['freeRadius_radiusFramedIPNetmask'] = 'radiusFramedIPNetmask'; + } + if (!$this->isBooleanConfigOptionSet('freeRadius_hideRadiusRealm')) { + $profileElements[] = new htmlTableExtendedInputField(_('Realm'), 'freeRadius_radiusRealm', null, 'radiusRealm'); + $return['profile_checks']['freeRadius_radiusRealm'] = array( + 'type' => 'ext_preg', + 'regex' => 'DNSname', + 'error_message' => $this->messages['radiusRealm'][0]); + $return['profile_mappings']['freeRadius_radiusRealm'] = 'radiusRealm'; + } + if (sizeof($profileElements) > 0) { + $profileContainer = new htmlTable(); + for ($i = 0; $i < sizeof($profileElements); $i++) { + $profileContainer->addElement($profileElements[$i]); + $profileContainer->addNewLine(); + } + $return['profile_options'] = $profileContainer; + } + // upload fields + $return['upload_columns'] = array(); + if (!$this->isBooleanConfigOptionSet('freeRadius_hideRadiusFramedIPAddress')) { + $return['upload_columns'][] = array( + 'name' => 'freeRadius_radiusFramedIPAddress', + 'description' => _('IP address'), + 'help' => 'radiusFramedIPAddress', + 'example' => '123.123.123.123', + ); + } + if (!$this->isBooleanConfigOptionSet('freeRadius_hideRadiusFramedIPNetmask')) { + $return['upload_columns'][] = array( + 'name' => 'freeRadius_radiusFramedIPNetmask', + 'description' => _('Net mask'), + 'help' => 'radiusFramedIPNetmask', + 'example' => '255.255.255.0' + ); + } + if (!$this->isBooleanConfigOptionSet('freeRadius_hideRadiusRealm')) { + $return['upload_columns'][] = array( + 'name' => 'freeRadius_radiusRealm', + 'description' => _('Realm'), + 'help' => 'radiusRealm', + 'example' => _('company.com') + ); + } + // available PDF fields + $return['PDF_fields'] = array(); + if (!$this->isBooleanConfigOptionSet('freeRadius_hideRadiusFramedIPAddress')) { + $return['PDF_fields']['radiusFramedIPAddress'] = _('IP address'); + } + if (!$this->isBooleanConfigOptionSet('freeRadius_hideRadiusFramedIPNetmask')) { + $return['PDF_fields']['radiusFramedIPNetmask'] = _('Net mask'); + } + if (!$this->isBooleanConfigOptionSet('freeRadius_hideRadiusRealm')) { + $return['PDF_fields']['radiusRealm'] = _('Realm'); + } + return $return; + } + + /** + * This function fills the error message array with messages + */ + function load_Messages() { + $this->messages['radiusFramedIPAddress'][0] = array('ERROR', _('The IP address is invalid.')); + $this->messages['radiusFramedIPAddress'][1] = array('ERROR', _('Account %s:') . ' freeRadius_radiusFramedIPAddress', _('The IP address is invalid.')); + $this->messages['radiusFramedIPNetmask'][0] = array('ERROR', _('The net mask is invalid.')); + $this->messages['radiusFramedIPNetmask'][1] = array('ERROR', _('Account %s:') . ' freeRadius_radiusFramedIPNetmask', _('The net mask is invalid.')); + $this->messages['radiusRealm'][0] = array('ERROR', _('Please enter a valid realm.')); + $this->messages['radiusRealm'][1] = array('ERROR', _('Account %s:') . ' freeRadius_radiusRealm', _('Please enter a valid realm.')); + } + + /** + * Returns the HTML meta data for the main account page. + * + * @return htmlElement HTML meta data + */ + function display_html_attributes() { + $return = new htmlTable(); + if (in_array('radiusprofile', $this->attributes['objectClass'])) { + // IP address + if (!$this->isBooleanConfigOptionSet('freeRadius_hideRadiusFramedIPAddress')) { + $radiusFramedIPAddress = ''; + if (isset($this->attributes['radiusFramedIPAddress'][0])) { + $radiusFramedIPAddress = $this->attributes['radiusFramedIPAddress'][0]; + } + $return->addElement(new htmlTableExtendedInputField(_('IP address'), 'radiusFramedIPAddress', $radiusFramedIPAddress, 'radiusFramedIPAddress'), true); + } + // net mask + if (!$this->isBooleanConfigOptionSet('freeRadius_hideRadiusFramedIPNetmask')) { + $radiusFramedIPNetmask = ''; + if (isset($this->attributes['radiusFramedIPNetmask'][0])) { + $radiusFramedIPNetmask = $this->attributes['radiusFramedIPNetmask'][0]; + } + $return->addElement(new htmlTableExtendedInputField(_('Net mask'), 'radiusFramedIPNetmask', $radiusFramedIPNetmask, 'radiusFramedIPNetmask'), true); + } + // realm + if (!$this->isBooleanConfigOptionSet('freeRadius_hideRadiusRealm')) { + $radiusRealm = ''; + if (isset($this->attributes['radiusRealm'][0])) { + $radiusRealm = $this->attributes['radiusRealm'][0]; + } + $return->addElement(new htmlTableExtendedInputField(_('Realm'), 'radiusRealm', $radiusRealm, 'radiusRealm'), true); + } + // button to remove extension + $return->addElement(new htmlSpacer(null, '10px'), true); + $remButton = new htmlButton('remObjectClass', _('Remove FreeRadius extension')); + $remButton->colspan = 3; + $return->addElement($remButton); + } + else { + $return->addElement(new htmlButton('addObjectClass', _('Add FreeRadius extension'))); + } + return $return; + } + + /** + * Processes user input of the primary module page. + * It checks if all input values are correct and updates the associated LDAP attributes. + * + * @return array list of info/error messages + */ + function process_attributes() { + if (isset($_POST['addObjectClass'])) { + $this->attributes['objectClass'][] = 'radiusprofile'; + return array(); + } + elseif (isset($_POST['remObjectClass'])) { + $this->attributes['objectClass'] = array_delete(array('radiusprofile'), $this->attributes['objectClass']); + for ($i = 0; $i < sizeof($this->meta['attributes']); $i++) { + if (isset($this->attributes[$this->meta['attributes'][$i]])) { + unset($this->attributes[$this->meta['attributes'][$i]]); + } + } + return array(); + } + // skip processing if extension is not active + if (!in_array('radiusprofile', $this->attributes['objectClass'])) { + return array(); + } + $errors = array(); + // IP address + if (!$this->isBooleanConfigOptionSet('freeRadius_hideRadiusFramedIPAddress')) { + $this->attributes['radiusFramedIPAddress'][0] = $_POST['radiusFramedIPAddress']; + if (($_POST['radiusFramedIPAddress'] != '') && !get_preg($_POST['radiusFramedIPAddress'], 'ip')) { + $errors[] = $this->messages['radiusFramedIPAddress'][0]; + } + } + // net mask + if (!$this->isBooleanConfigOptionSet('freeRadius_hideRadiusFramedIPNetmask')) { + $this->attributes['radiusFramedIPNetmask'][0] = $_POST['radiusFramedIPNetmask']; + if (($_POST['radiusFramedIPNetmask'] != '') && !get_preg($_POST['radiusFramedIPNetmask'], 'ip')) { + $errors[] = $this->messages['radiusFramedIPNetmask'][0]; + } + } + // realm + if (!$this->isBooleanConfigOptionSet('freeRadius_hideRadiusRealm')) { + $this->attributes['radiusRealm'][0] = $_POST['radiusRealm']; + if (($_POST['radiusRealm'] != '') && !get_preg($_POST['radiusRealm'], 'DNSname')) { + $errors[] = $this->messages['radiusRealm'][0]; + } + } + return $errors; + } + + /** + * In this function the LDAP account is built up. + * + * @param array $rawAccounts list of hash arrays (name => value) from user input + * @param array $partialAccounts list of hash arrays (name => value) which are later added to LDAP + * @param array $ids list of IDs for column position (e.g. "posixAccount_uid" => 5) + * @param array $selectedModules list of selected account modules + * @return array list of error messages if any + */ + function build_uploadAccounts($rawAccounts, $ids, &$partialAccounts, $selectedModules) { + $errors = array(); + for ($i = 0; $i < sizeof($rawAccounts); $i++) { + // add object class + if (!in_array("radiusprofile", $partialAccounts[$i]['objectClass'])) $partialAccounts[$i]['objectClass'][] = "radiusprofile"; + // IP address + if ($rawAccounts[$i][$ids['freeRadius_radiusFramedIPAddress']] != "") { + if (get_preg($rawAccounts[$i][$ids['freeRadius_radiusFramedIPAddress']], 'ip')) { + $partialAccounts[$i]['radiusFramedIPAddress'] = $rawAccounts[$i][$ids['freeRadius_radiusFramedIPAddress']]; + } + else { + $errMsg = $this->messages['radiusFramedIPAddress'][1]; + array_push($errMsg, array($i)); + $errors[] = $errMsg; + } + } + // net mask + if ($rawAccounts[$i][$ids['freeRadius_radiusFramedIPNetmask']] != "") { + if (get_preg($rawAccounts[$i][$ids['freeRadius_radiusFramedIPNetmask']], 'ip')) { + $partialAccounts[$i]['radiusFramedIPNetmask'] = $rawAccounts[$i][$ids['freeRadius_radiusFramedIPNetmask']]; + } + else { + $errMsg = $this->messages['radiusFramedIPNetmask'][1]; + array_push($errMsg, array($i)); + $errors[] = $errMsg; + } + } + // realm + if ($rawAccounts[$i][$ids['freeRadius_radiusRealm']] != "") { + if (get_preg($rawAccounts[$i][$ids['freeRadius_radiusRealm']], 'DNSname')) { + $partialAccounts[$i]['radiusRealm'] = $rawAccounts[$i][$ids['freeRadius_radiusRealm']]; + } + else { + $errMsg = $this->messages['radiusRealm'][1]; + array_push($errMsg, array($i)); + $errors[] = $errMsg; + } + } + } + return $errors; + } + + /** + * Returns the PDF entries for this module. + * + * @return array list of possible PDF entries + */ + function get_pdfEntries() { + $return = array(); + if (isset($this->attributes['radiusFramedIPAddress'][0])) { + $return[get_class($this) . '_radiusFramedIPAddress'][0] = '' . _('IP address') . '' . $this->attributes['radiusFramedIPAddress'][0] . ''; + } + if (isset($this->attributes['radiusFramedIPNetmask'][0])) { + $return[get_class($this) . '_radiusFramedIPNetmask'][0] = '' . _('Net mask') . '' . $this->attributes['radiusFramedIPNetmask'][0] . ''; + } + if (isset($this->attributes['radiusRealm'][0])) { + $return[get_class($this) . '_radiusRealm'][0] = '' . _('Realm') . '' . $this->attributes['radiusRealm'][0] . ''; + } + return $return; + } + +} + + +?>