~ubuntu-branches/ubuntu/wily/ldap-account-manager/wily

« back to all changes in this revision

Viewing changes to lib/modules/freeRadius.inc

  • Committer: Package Import Robot
  • Author(s): Roland Gruber
  • Date: 2015-03-31 18:56:30 UTC
  • mfrom: (1.2.27)
  • Revision ID: package-import@ubuntu.com-20150331185630-z7wvaw3la13snxxa
Tags: 4.9-1
new upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
<?php
2
2
/*
3
 
$Id: freeRadius.inc 5351 2014-04-20 12:59:36Z gruberroland $
 
3
$Id: freeRadius.inc 5531 2015-03-08 20:09:18Z gruberroland $
4
4
 
5
5
  This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
6
 
  Copyright (C) 2011 - 2014  Roland Gruber
 
6
  Copyright (C) 2011 - 2015  Roland Gruber
7
7
 
8
8
  This program is free software; you can redistribute it and/or modify
9
9
  it under the terms of the GNU General Public License as published by
38
38
        private static $monthList = array('01' => 'Jan', '02' => 'Feb', '03' => 'Mar', '04' => 'Apr', '05' => 'May',
39
39
                        '06' => 'Jun', '07' => 'Jul', '08' => 'Aug', '09' => 'Sep', '10' => 'Oct', '11' => 'Nov', '12' => 'Dec'
40
40
                );
 
41
                
 
42
        /** cache for profile DNs */
 
43
        private $profileCache = null;
41
44
        
42
45
        
43
46
        /**
77
80
                // managed object classes
78
81
                $return['objectClasses'] = array('radiusprofile');
79
82
                // managed attributes
80
 
                $return['attributes'] = array('radiusFramedIPAddress', 'radiusFramedIPNetmask', 'radiusRealm', 'radiusGroupName', 'radiusExpiration', 'radiusIdleTimeout');
 
83
                $return['attributes'] = array('radiusFramedIPAddress', 'radiusFramedIPNetmask', 'radiusRealm', 'radiusGroupName',
 
84
                        'radiusExpiration', 'radiusIdleTimeout', 'dialupAccess', 'radiusProfileDn');
81
85
                // help Entries
82
86
                $return['help'] = array(
83
87
                        'radiusFramedIPAddress' => array(
108
112
                                "Headline" => _("Idle timeout"), 'attr' => 'radiusIdleTimeout',
109
113
                                "Text" => _("Specifies the maximum number of seconds that a connection can be idle before the session is terminated.")
110
114
                        ),
 
115
                        'dialupAccess' => array(
 
116
                                "Headline" => _("Enabled"), 'attr' => 'dialupAccess',
 
117
                                "Text" => _("Specifies if the user may authenticate with FreeRadius.")
 
118
                        ),
 
119
                        'profileDN' => array(
 
120
                                "Headline" => _("Profile DN"), 'attr' => 'radiusProfileDn',
 
121
                                "Text" => _('DN where Radius profile templates are stored.')
 
122
                        ),
 
123
                        'radiusProfileDn' => array(
 
124
                                "Headline" => _("Profile"), 'attr' => 'radiusProfileDn',
 
125
                                "Text" => _('Radius profile for this user.')
 
126
                        ),
111
127
                        'hiddenOptions' => array(
112
128
                                "Headline" => _("Hidden options"),
113
129
                                "Text" => _("The selected options will not be managed inside LAM. You can use this to reduce the number of displayed input fields.")
114
130
                        ));
115
 
                // configuration settings
116
 
                $configContainer = new htmlTable();
117
 
                $configContainerHead = new htmlTable();
118
 
                $configContainerHead->addElement(new htmlOutputText(_('Hidden options')));
119
 
                $configContainerHead->addElement(new htmlHelpLink('hiddenOptions'));
120
 
                $configContainerOptions = new htmlTable();
121
 
                $configContainer->addElement($configContainerHead, true);
122
 
                $configContainerOptions->addElement(new htmlTableExtendedInputCheckbox('freeRadius_hideRadiusFramedIPAddress', false, _('IP address'), null, false));
123
 
                $configContainerOptions->addElement(new htmlOutputText(' '));
124
 
                $configContainerOptions->addElement(new htmlTableExtendedInputCheckbox('freeRadius_hideRadiusFramedIPNetmask', false, _('Net mask'), null, false));
125
 
                $configContainerOptions->addElement(new htmlOutputText(' '));
126
 
                $configContainerOptions->addElement(new htmlTableExtendedInputCheckbox('freeRadius_hideRadiusRealm', false, _('Realm'), null, false));
127
 
                $configContainerOptions->addElement(new htmlOutputText(' '));
128
 
                $configContainerOptions->addElement(new htmlTableExtendedInputCheckbox('freeRadius_hideRadiusGroupName', false, _('Group names'), null, false));
129
 
                $configContainerOptions->addElement(new htmlOutputText(' '));
130
 
                $configContainerOptions->addElement(new htmlTableExtendedInputCheckbox('freeRadius_hideRadiusExpiration', false, _('Expiration date'), null, false));
131
 
                $configContainerOptions->addNewLine();
132
 
                $configContainerOptions->addElement(new htmlTableExtendedInputCheckbox('freeRadius_hideRadiusIdleTimeout', false, _('Idle timeout'), null, false));
133
 
                $configContainer->addElement($configContainerOptions, true);
134
 
                $return['config_options']['all'] = $configContainer;
135
131
                // profile settings
136
132
                $profileElements = array();
137
133
                if (!$this->isBooleanConfigOptionSet('freeRadius_hideRadiusFramedIPNetmask')) {
161
157
                                'error_message' => $this->messages['radiusIdleTimeout'][0]);
162
158
                        $return['profile_mappings']['freeRadius_radiusIdleTimeout'] = 'radiusIdleTimeout';
163
159
                }
 
160
                if (!$this->isBooleanConfigOptionSet('freeRadius_hideDialupAccess')) {
 
161
                        $enabledOptions = array('-' => '', _('Yes') => 'true', _('No') => 'false');
 
162
                        $dialupAccessSelect = new htmlTableExtendedSelect('freeRadius_dialupAccess', $enabledOptions, array('true'), _('Enabled'), 'dialupAccess');
 
163
                        $dialupAccessSelect->setHasDescriptiveElements(true);
 
164
                        $profileElements[] = $dialupAccessSelect;
 
165
                        $return['profile_mappings']['freeRadius_dialupAccess'] = 'dialupAccess';
 
166
                }
 
167
                if (!$this->isBooleanConfigOptionSet('freeRadius_hideRadiusProfileDn') && isLoggedIn()) {
 
168
                        $profileOptions = array('-' => '');
 
169
                        foreach ($this->getProfiles() as $dn) {
 
170
                                $profileOptions[getAbstractDN($dn)] = $dn;
 
171
                        }
 
172
                        $profileSelect = new htmlTableExtendedSelect('freeRadius_radiusProfileDn', $profileOptions, array(''), _('Profile'), 'radiusProfileDn');
 
173
                        $profileSelect->setHasDescriptiveElements(true);
 
174
                        $profileElements[] = $profileSelect;
 
175
                        $return['profile_mappings']['freeRadius_radiusProfileDn'] = 'radiusProfileDn';
 
176
                }
164
177
                if (sizeof($profileElements) > 0) {
165
178
                        $profileContainer = new htmlTable();
166
179
                        for ($i = 0; $i < sizeof($profileElements); $i++) {
219
232
                                'example' => '3600'
220
233
                        );
221
234
                }
 
235
                if (!$this->isBooleanConfigOptionSet('freeRadius_hideDialupAccess')) {
 
236
                        $return['upload_columns'][] = array(
 
237
                                'name' => 'freeRadius_dialupAccess',
 
238
                                'description' => _('Enabled'),
 
239
                                'help' => 'dialupAccess',
 
240
                                'example' => 'true',
 
241
                                'values' => 'true, false'
 
242
                        );
 
243
                }
 
244
                if (!$this->isBooleanConfigOptionSet('freeRadius_hideRadiusProfileDn')) {
 
245
                        $return['upload_columns'][] = array(
 
246
                                'name' => 'freeRadius_radiusProfileDn',
 
247
                                'description' => _('Profile'),
 
248
                                'help' => 'radiusProfileDn',
 
249
                                'example' => 'cn=profile,ou=radiusProfile,dc=example,dc=com'
 
250
                        );
 
251
                }
222
252
                // available PDF fields
223
253
                $return['PDF_fields'] = array();
224
254
                if (!$this->isBooleanConfigOptionSet('freeRadius_hideRadiusFramedIPAddress')) {
239
269
                if (!$this->isBooleanConfigOptionSet('freeRadius_hideRadiusIdleTimeout')) {
240
270
                        $return['PDF_fields']['radiusIdleTimeout'] = _('Idle timeout');
241
271
                }
 
272
                if (!$this->isBooleanConfigOptionSet('freeRadius_hideDialupAccess')) {
 
273
                        $return['PDF_fields']['dialupAccess'] = _('Enabled');
 
274
                }
 
275
                if (!$this->isBooleanConfigOptionSet('freeRadius_hideRadiusProfileDn')) {
 
276
                        $return['PDF_fields']['radiusProfileDn'] = _('Profile');
 
277
                }
242
278
                return $return;
243
279
        }
 
280
        
 
281
        /**
 
282
        * Returns a list of configuration options.
 
283
        * 
 
284
        * Calling this method does not require the existence of an enclosing {@link accountContainer}.<br>
 
285
        * <br>
 
286
        * The field names are used as keywords to load and save settings.
 
287
        * We recommend to use the module name as prefix for them (e.g. posixAccount_homeDirectory) to avoid naming conflicts.
 
288
        *
 
289
        * @param array $scopes account types (user, group, host)
 
290
        * @param array $allScopes list of all active account modules and their scopes (module => array(scopes))
 
291
        * @return mixed htmlElement or array of htmlElement
 
292
        * 
 
293
        * @see htmlElement
 
294
        */
 
295
        public function get_configOptions($scopes, $allScopes) {
 
296
                $configContainer = new htmlTable();
 
297
                $configContainer->addElement(new htmlTableExtendedInputField(_('Profile DN'), 'freeRadius_profileDN', '', 'profileDN'), true);
 
298
                $configContainer->addVerticalSpace('10px');
 
299
                $configContainerHead = new htmlTable();
 
300
                $configContainerHead->colspan = 5;
 
301
                $configContainerHead->addElement(new htmlOutputText(_('Hidden options')));
 
302
                $configContainerHead->addElement(new htmlHelpLink('hiddenOptions'));
 
303
                $configContainerOptions = new htmlTable();
 
304
                $configContainerOptions->colspan = 5;
 
305
                $configContainer->addElement($configContainerHead, true);
 
306
                $configContainerOptions->addElement(new htmlTableExtendedInputCheckbox('freeRadius_hideRadiusFramedIPAddress', false, _('IP address'), null, false));
 
307
                $configContainerOptions->addElement(new htmlOutputText(' '));
 
308
                $configContainerOptions->addElement(new htmlTableExtendedInputCheckbox('freeRadius_hideRadiusFramedIPNetmask', false, _('Net mask'), null, false));
 
309
                $configContainerOptions->addElement(new htmlOutputText(' '));
 
310
                $configContainerOptions->addElement(new htmlTableExtendedInputCheckbox('freeRadius_hideRadiusRealm', false, _('Realm'), null, false));
 
311
                $configContainerOptions->addElement(new htmlOutputText(' '));
 
312
                $configContainerOptions->addElement(new htmlTableExtendedInputCheckbox('freeRadius_hideRadiusGroupName', false, _('Group names'), null, false));
 
313
                $configContainerOptions->addElement(new htmlOutputText(' '));
 
314
                $configContainerOptions->addElement(new htmlTableExtendedInputCheckbox('freeRadius_hideRadiusExpiration', false, _('Expiration date'), null, false));
 
315
                $configContainerOptions->addNewLine();
 
316
                $configContainerOptions->addElement(new htmlTableExtendedInputCheckbox('freeRadius_hideRadiusIdleTimeout', false, _('Idle timeout'), null, false));
 
317
                $configContainerOptions->addElement(new htmlOutputText(' '));
 
318
                $configContainerOptions->addElement(new htmlTableExtendedInputCheckbox('freeRadius_hideRadiusProfileDn', false, _('Profile'), null, false));
 
319
                $configContainerOptions->addElement(new htmlOutputText(' '));
 
320
                $configContainerOptions->addElement(new htmlTableExtendedInputCheckbox('freeRadius_hideDialupAccess', false, _('Enabled'), null, false));
 
321
                $configContainer->addElement($configContainerOptions, true);
 
322
                return $configContainer;
 
323
        }
244
324
 
245
325
        /**
246
326
        * This function fills the error message array with messages
258
338
                $this->messages['radiusExpiration'][1] = array('ERROR', _('Account %s:') . ' freeRadius_radiusExpiration', _('The expiration date must be in format DD.MM.YYYY HH:MM.'));
259
339
                $this->messages['radiusIdleTimeout'][0] = array('ERROR', _('Please enter a numeric value for the idle timeout.'));
260
340
                $this->messages['radiusIdleTimeout'][1] = array('ERROR', _('Account %s:') . ' freeRadius_radiusIdleTimeout', _('Please enter a numeric value for the idle timeout.'));
 
341
                $this->messages['dialupAccess'][0] = array('ERROR', _('Account %s:') . ' freeRadius_dialupAccess', _('This value can only be "true" or "false".'));
 
342
                $this->messages['radiusProfileDn'][0] = array('ERROR', _('Account %s:') . ' freeRadius_radiusProfileDn', _('This is not a valid DN!'));
261
343
        }
262
344
 
263
345
        /**
302
384
                                $return->addElement($radiusExpirationList);
303
385
                                $return->addElement(new htmlHelpLink('radiusExpiration'), true);
304
386
                        }
 
387
                        // profile DN
 
388
                        if (!$this->isBooleanConfigOptionSet('freeRadius_hideRadiusProfileDn')) {
 
389
                                $profiles = array('-' => '-');
 
390
                                foreach ($this->getProfiles() as $dn) {
 
391
                                        $profiles[getAbstractDN($dn)] = $dn;
 
392
                                }
 
393
                                $profile = array();
 
394
                                if (!empty($this->attributes['radiusProfileDn'][0])) {
 
395
                                        $profile = $this->attributes['radiusProfileDn'];
 
396
                                        if (!in_array($this->attributes['radiusProfileDn'][0], $profiles)) {
 
397
                                                $profiles[getAbstractDN($this->attributes['radiusProfileDn'][0])] = $this->attributes['radiusProfileDn'][0];
 
398
                                        }
 
399
                                }
 
400
                                $profileSelect = new htmlTableExtendedSelect('radiusProfileDn', $profiles, $profile, _('Profile'), 'radiusProfileDn');
 
401
                                $profileSelect->setHasDescriptiveElements(true);
 
402
                                $return->addElement($profileSelect, true);
 
403
                        }
 
404
                        // enabled
 
405
                        if (!$this->isBooleanConfigOptionSet('freeRadius_hideDialupAccess')) {
 
406
                                $enabled = array('');
 
407
                                if (!empty($this->attributes['dialupAccess'][0])) {
 
408
                                        $enabled = array($this->attributes['dialupAccess'][0]);
 
409
                                        // value in LDAP may be anything other than "false" to count as "true"
 
410
                                        if (!in_array($this->attributes['dialupAccess'][0], array('true', 'false', 'TRUE', 'FALSE'))) {
 
411
                                                $enabled = array('true');
 
412
                                        }
 
413
                                }
 
414
                                $enabledOptions = array('-' => '', _('Yes') => 'true', _('No') => 'false');
 
415
                                $enabledSelect = new htmlTableExtendedSelect('dialupAccess', $enabledOptions, $enabled, _('Enabled'), 'dialupAccess');
 
416
                                $enabledSelect->setHasDescriptiveElements(true);
 
417
                                $return->addElement($enabledSelect, true);
 
418
                        }
305
419
                        // button to remove extension
306
420
                        $return->addElement(new htmlSpacer(null, '10px'), true);
307
421
                        $remButton = new htmlButton('remObjectClass', _('Remove FreeRadius extension'));
371
485
                                $errors[] = $this->messages['radiusIdleTimeout'][0];
372
486
                        }
373
487
                }
 
488
                // enabled
 
489
                if (!$this->isBooleanConfigOptionSet('freeRadius_hideDialupAccess')) {
 
490
                        if (!empty($this->attributes['dialupAccess']) && ($_POST['dialupAccess'] === '')) {
 
491
                                unset($this->attributes['dialupAccess']);
 
492
                        }
 
493
                        elseif ($_POST['dialupAccess'] === 'false') {
 
494
                                $this->attributes['dialupAccess'][0] = 'false';
 
495
                        }
 
496
                        elseif ($_POST['dialupAccess'] === 'true') {
 
497
                                $this->attributes['dialupAccess'][0] = 'true';
 
498
                        }
 
499
                }
 
500
                // profile DN
 
501
                if (!$this->isBooleanConfigOptionSet('freeRadius_hideRadiusProfileDn')) {
 
502
                        if (($_POST['radiusProfileDn'] == '-') && !empty($this->attributes['radiusProfileDn'])) {
 
503
                                unset($this->attributes['radiusProfileDn']);
 
504
                        }
 
505
                        elseif ($_POST['radiusProfileDn'] != '-') {
 
506
                                $this->attributes['radiusProfileDn'][0] = $_POST['radiusProfileDn'];
 
507
                        }
 
508
                }
374
509
                return $errors;
375
510
        }
376
511
        
523
658
                        // idle timeout
524
659
                        $this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'freeRadius_radiusIdleTimeout', 'radiusIdleTimeout',
525
660
                                'digit', $this->messages['radiusIdleTimeout'][1], $errors);
 
661
                        // enabled
 
662
                        if (!empty($rawAccounts[$i][$ids['freeRadius_dialupAccess']])) {
 
663
                                if (in_array($rawAccounts[$i][$ids['freeRadius_dialupAccess']], array('true', 'false'))) {
 
664
                                        $partialAccounts[$i]['dialupAccess'] = $rawAccounts[$i][$ids['freeRadius_dialupAccess']];
 
665
                                }
 
666
                                else {
 
667
                                        $errMsg = $this->messages['dialupAccess'][0];
 
668
                                        array_push($errMsg, array($i));
 
669
                                        $errors[] = $errMsg;
 
670
                                }
 
671
                        }
 
672
                        // profile DN
 
673
                        if (!empty($rawAccounts[$i][$ids['freeRadius_radiusProfileDn']])) {
 
674
                                if (get_preg($rawAccounts[$i][$ids['freeRadius_radiusProfileDn']], 'dn')) {
 
675
                                        $partialAccounts[$i]['radiusProfileDn'] = $rawAccounts[$i][$ids['freeRadius_radiusProfileDn']];
 
676
                                }
 
677
                                else {
 
678
                                        $errMsg = $this->messages['radiusProfileDn'][0];
 
679
                                        array_push($errMsg, array($i));
 
680
                                        $errors[] = $errMsg;
 
681
                                }
 
682
                        }
526
683
                }
527
684
                return $errors;
528
685
        }
529
686
 
530
687
        /**
531
 
        * Returns the PDF entries for this module.
532
 
        *
533
 
        * @return array list of possible PDF entries
534
 
        */
535
 
        function get_pdfEntries() {
 
688
         * Returns a list of possible PDF entries for this account.
 
689
         *
 
690
         * @param array $pdfKeys list of PDF keys that are included in document
 
691
         * @return list of PDF entries (array(<PDF key> => <PDF lines>))
 
692
         */
 
693
        function get_pdfEntries($pdfKeys) {
536
694
                $return = array();
537
695
                $this->addSimplePDFField($return, 'radiusFramedIPAddress', _('IP address'));
538
696
                $this->addSimplePDFField($return, 'radiusFramedIPNetmask', _('Net mask'));
539
697
                $this->addSimplePDFField($return, 'radiusRealm', _('Realm'));
540
698
                $this->addSimplePDFField($return, 'radiusGroupName', _('Group names'));
541
699
                $this->addSimplePDFField($return, 'radiusIdleTimeout', _('Idle timeout'));
 
700
                $this->addSimplePDFField($return, 'radiusProfileDn', _('Profile'));
542
701
                if (isset($this->attributes['radiusExpiration'][0])) {
543
 
                        $return[get_class($this) . '_radiusExpiration'][0] = '<block><key>' . _('Expiration date') . '</key><value>' . $this->formatExpirationDate($this->attributes['radiusExpiration'][0]) . '</value></block>';
 
702
                        $this->addPDFKeyValue($return, 'radiusExpiration', _('Expiration date'), $this->formatExpirationDate($this->attributes['radiusExpiration'][0]));
 
703
                }
 
704
                if (isset($this->attributes['dialupAccess'][0])) {
 
705
                        $enabled = _('Yes');
 
706
                        if (in_array($this->attributes['dialupAccess'][0], array('false', 'FALSE'))) {
 
707
                                $enabled = _('No');
 
708
                        }
 
709
                        $this->addPDFKeyValue($return, 'dialupAccess', _('Enabled'), $enabled);
544
710
                }
545
711
                return $return;
546
712
        }
604
770
                return $date;
605
771
        }
606
772
        
 
773
        /**
 
774
         * Returns a list of possible profile DNs.
 
775
         * 
 
776
         * @return array list of profile DNs
 
777
         */
 
778
        private function getProfiles() {
 
779
                if ($this->profileCache != null) {
 
780
                        return $this->profileCache;
 
781
                }
 
782
                if (empty($this->moduleSettings['freeRadius_profileDN'][0])) {
 
783
                        return array();
 
784
                }
 
785
                $list = searchLDAP($this->moduleSettings['freeRadius_profileDN'][0], '(objectClass=radiusProfile)', array('dn'));
 
786
                foreach ($list as $attr) {
 
787
                        $this->profileCache[] = $attr['dn'];
 
788
                }
 
789
                usort($this->profileCache, 'compareDN');
 
790
                return $this->profileCache;
 
791
        }
 
792
        
607
793
}
608
794
 
609
795