| 1 | package VUser::Radius; | ||
| 2 | use warnings; | ||
| 3 | use strict; | ||
| 4 | |||
| 5 | # Copyright 2006 Randy Smith <perlstalker@vuser.org> | ||
| 6 | # $Id: Radius.pm,v 1.11 2007/09/21 14:31:05 perlstalker Exp $ | ||
| 7 | |||
| 8 | use VUser::Meta; | ||
| 9 | use VUser::Log; | ||
| 10 | use VUser::ResultSet; | ||
| 11 | use VUser::ExtLib qw(:config); | ||
| 12 | |||
| 13 | our $VERSION = '0.1.1'; | ||
| 14 | |||
| 15 | our $c_sec = 'Extension Radius'; | ||
| 16 | our %meta = ('username' => VUser::Meta->new('name' => 'username', | ||
| 17 | 'type' => 'string', | ||
| 18 | 'description' => 'User name'), | ||
| 19 | 'password' => VUser::Meta->new('name' => 'password', | ||
| 20 | 'type' => 'string', | ||
| 21 | 'description' => 'User\'s password'), | ||
| 22 | 'realm' => VUser::Meta->new('name' => 'realm', | ||
| 23 | 'type' => 'string', | ||
| 24 | 'description' => 'Realm for this user'), | ||
| 25 | 'attribute' => VUser::Meta->new('name' => 'realm', | ||
| 26 | 'type' => 'string', | ||
| 27 | 'description' => 'Attribute to set for this user'), | ||
| 28 | 'type' => VUser::Meta->new('name' => 'type', | ||
| 29 | 'type' => 'string', | ||
| 30 | 'description' => '\'check\' or \'reply\''), | ||
| 31 | 'value' => VUser::Meta->new('name' => 'value', | ||
| 32 | 'type' => 'string', | ||
| 33 | 'description' => 'Value of passed attribute') | ||
| 34 | ); | ||
| 35 | |||
| 36 | my $log; | ||
| 37 | |||
| 38 | sub init { | ||
| 39 | my $eh = shift; | ||
| 40 | my %cfg = @_; | ||
| 41 | |||
| 42 | if (defined $main::log) { | ||
| 43 | $log = $main::log; | ||
| 44 | } else { | ||
| 45 | $log = VUser::Log->new(\%cfg, 'vuser') | ||
| 46 | } | ||
| 47 | |||
| 48 | # Radius | ||
| 49 | $eh->register_keyword ('radius', 'Manage RADIUS users'); | ||
| 50 | |||
| 51 | # radius-adduser | ||
| 52 | $eh->register_action ('radius', 'adduser', 'Add a user to RADIUS'); | ||
| 53 | $eh->register_option ('radius', 'adduser', $meta{'username'}, 'req'); | ||
| 54 | $eh->register_option ('radius', 'adduser', $meta{'password'}, 'req'); | ||
| 55 | $eh->register_option ('radius', 'adduser', $meta{'realm'}); | ||
| 56 | |||
| 57 | # radius-rmuser | ||
| 58 | $eh->register_action ('radius', 'rmuser', 'Remove a user from RADIUS'); | ||
| 59 | $eh->register_option ('radius', 'rmuser', $meta{'username'}, 'req'); | ||
| 60 | $eh->register_option ('radius', 'rmuser', $meta{'realm'}); | ||
| 61 | |||
| 62 | # radius-moduser | ||
| 63 | $eh->register_action ('radius', 'moduser', 'Modify a RADIUS user'); | ||
| 64 | $eh->register_option ('radius', 'moduser', $meta{'username'}, 'req'); | ||
| 65 | $eh->register_option ('radius', 'moduser', $meta{'realm'}); | ||
| 66 | $eh->register_option ('radius', 'moduser', $meta{'username'}->new('name' => 'newusername')); | ||
| 67 | $eh->register_option ('radius', 'moduser', $meta{'password'}); | ||
| 68 | $eh->register_option ('radius', 'moduser', $meta{'realm'}->new('name' => 'newrealm')); | ||
| 69 | |||
| 70 | <<<<<<< Radius.pm | ||
| 71 | # radius-listusers | ||
| 72 | $eh->register_action ('radius', 'listusers', 'List RADIUS users'); | ||
| 73 | $eh->register_option ('radius', 'listusers', $meta{'username'}); | ||
| 74 | $eh->register_option ('radius', 'listusers', $meta{'realm'}); | ||
| 75 | |||
| 76 | # radius-userinfo | ||
| 77 | $eh->register_action ('radius', 'userinfo', 'List RADIUS user details'); | ||
| 78 | $eh->register_option ('radius', 'userinfo', $meta{'username'}, 'req'); | ||
| 79 | $eh->register_option ('radius', 'userinfo', $meta{'realm'}); | ||
| 80 | |||
| 81 | ======= | ||
| 82 | # radius-listusers | ||
| 83 | $eh->register_action ('radius', 'listusers', 'List all user accounts'); | ||
| 84 | |||
| 85 | # radius-userinfo | ||
| 86 | $eh->register_action ('radius', 'userinfo', 'Get details for a RADIUS user'); | ||
| 87 | $eh->register_option ('radius', 'userinfo', $meta{'username'}, 'req'); | ||
| 88 | $eh->register_option ('radius', 'userinfo', $meta{'realm'}); | ||
| 89 | |||
| 90 | >>>>>>> 1.8 | ||
| 91 | # radius-addattrib | ||
| 92 | $eh->register_action ('radius', 'addattrib', 'Add an attribute to a RADIUS user'); | ||
| 93 | $eh->register_option ('radius', 'addattrib', $meta{'username'}, 1); | ||
| 94 | $eh->register_option ('radius', 'addattrib', $meta{'realm'}); | ||
| 95 | $eh->register_option ('radius', 'addattrib', $meta{'attribute'}, 1); | ||
| 96 | $eh->register_option ('radius', 'addattrib', $meta{'value'}, 1); | ||
| 97 | |||
| 98 | # radius-modattrib | ||
| 99 | $eh->register_action ('radius', 'modattrib', 'Modify an attribute for a RADIUS user'); | ||
| 100 | $eh->register_option ('radius', 'modattrib', $meta{'username'}, 1); | ||
| 101 | $eh->register_option ('radius', 'modattrib', $meta{'realm'}); | ||
| 102 | $eh->register_option ('radius', 'modattrib', $meta{'attribute'}, 1); | ||
| 103 | $eh->register_option ('radius', 'modattrib', $meta{'value'}); | ||
| 104 | |||
| 105 | # radius-rmattrib | ||
| 106 | $eh->register_action ('radius', 'rmattrib', 'Remove an attribute from a RADIUS user'); | ||
| 107 | $eh->register_option ('radius', 'rmattrib', $meta{'username'}, 1); | ||
| 108 | $eh->register_option ('radius', 'rmattrib', $meta{'realm'}); | ||
| 109 | $eh->register_option ('radius', 'rmattrib', $meta{'attribute'}, 1); | ||
| 110 | <<<<<<< Radius.pm | ||
| 111 | |||
| 112 | # radius-listattrib | ||
| 113 | $eh->register_action ('radius', 'listattrib', 'List the attribute(s) for a RADIUS user'); | ||
| 114 | $eh->register_option ('radius', 'listattrib', $meta{'username'}, 1); | ||
| 115 | $eh->register_option ('radius', 'listattrib', $meta{'realm'}); | ||
| 116 | $eh->register_option ('radius', 'listattrib', $meta{'attribute'}); | ||
| 117 | ======= | ||
| 118 | |||
| 119 | # radius-listattrib | ||
| 120 | $eh->register_action ('radius', 'listattrib', 'List attributes for a RADIUS user'); | ||
| 121 | $eh->register_option ('radius', 'listattrib', $meta{'username'}, 1); | ||
| 122 | $eh->register_option ('radius', 'listattrib', $meta{'realm'}); | ||
| 123 | $eh->register_option ('radius', 'listattrib', $meta{'type'}, 1); | ||
| 124 | <<<<<<< Radius.pm | ||
| 125 | >>>>>>> 1.8 | ||
| 126 | ======= | ||
| 127 | |||
| 128 | # radius-allowedattribs | ||
| 129 | $eh->register_action ('radius', 'allowedattribs', 'List allowed attributes for RADIUS'); | ||
| 130 | $eh->register_task ('radius', 'allowedattribs', \&radius_allowedattribs); | ||
| 131 | >>>>>>> 1.10 | ||
| 132 | } | ||
| 133 | |||
| 134 | sub meta { return %meta; } | ||
| 135 | sub c_sec { return $c_sec; } | ||
| 136 | |||
| 137 | sub radius_allowedattribs { | ||
| 138 | my ($cfg, $opts, $action, $eh) = @_; | ||
| 139 | |||
| 140 | my @attribs = (); | ||
| 141 | |||
| 142 | my $rs = VUser::ResultSet->new(); | ||
| 143 | $rs->add_meta($meta{'attribute'}); | ||
| 144 | $rs->add_meta($meta{'type'}); | ||
| 145 | |||
| 146 | # Name[:check|reply] (defaults to 'reply') | ||
| 147 | my $values = strip_ws($cfg->{c_sec()}{'allowed attributes'}); | ||
| 148 | |||
| 149 | if (defined $values) { | ||
| 150 | my @attrib_pairs = split (/ /, $values); | ||
| 151 | foreach my $attrib_pair (@attrib_pairs) { | ||
| 152 | my ($attrib, $type) = split (':', $attrib_pair); | ||
| 153 | if (not defined ($type) | ||
| 154 | or ($type ne 'reply' and $type ne 'check')) { | ||
| 155 | $type = 'reply'; | ||
| 156 | } | ||
| 157 | $rs->add_data([$attrib, $type]); | ||
| 158 | } | ||
| 159 | } | ||
| 160 | return $rs; | ||
| 161 | } | ||
| 162 | |||
| 163 | 1; | ||
| 164 | |||
| 165 | __END__ |