3 # $Id: svc_acct.import,v 1.6 1999-07-08 01:49:00 ivan Exp $
5 # ivan@sisd.com 98-mar-9
7 # changed 'password' field to '_password' because PgSQL 6.3 reserves this word
8 # bmccane@maxbaud.net 98-Apr-3
10 # generalized svcparts (still needs radius import) ivan@sisd.com 98-mar-23
12 # radius import, now an interactive script. still needs erpcd import?
13 # ivan@sisd.com 98-jun-24
15 # arbitrary radius attributes ivan@sisd.com 98-aug-9
17 # don't import /var/spool/freeside/conf/shells! ivan@sisd.com 98-aug-13
19 # $Log: svc_acct.import,v $
20 # Revision 1.6 1999-07-08 01:49:00 ivan
21 # updates to avoid -w warnings from Joel Griffiths <griff@aver-computer.com>
23 # Revision 1.5 1999/03/25 08:42:19 ivan
24 # import stuff uses Term::Query and spits out (some kinds of) nonsensical input
26 # Revision 1.4 1999/03/24 00:43:38 ivan
27 # die if no relevant services
29 # Revision 1.3 1998/12/10 07:23:16 ivan
30 # use FS::Conf, need user (for datasrc)
32 # Revision 1.2 1998/10/13 12:07:51 ivan
33 # Assigns password from the shadow file for RADIUS password "UNIX"
37 use vars qw(%part_svc);
39 use Term::Query qw(query);
41 use FS::UID qw(adminsuidsetup datasrc);
42 use FS::Record qw(qsearch);
46 my $user = shift or die &usage;
49 my($spooldir)="/usr/local/etc/freeside/export.". datasrc;
51 $FS::svc_acct::nossh_hack = 1;
55 %part_svc=map { $_->svcpart, $_ } qsearch('part_svc',{'svcdb'=>'svc_acct'});
57 die "No services with svcdb svc_acct!\n" unless %part_svc;
59 print "\n\n", &menu_svc, "\n", <<END;
60 Most accounts probably have entries in passwd and users (with Port-Limit
63 my($ppp_svcpart)=&getpart;
65 print "\n\n", &menu_svc, "\n", <<END;
66 Some accounts have entries in passwd and users, but with Port-Limit 2 (or
69 my($isdn_svcpart)=&getpart;
71 print "\n\n", &menu_svc, "\n", <<END;
72 Some accounts might have entries in users only (Port-Limit 1)
74 my($oppp_svcpart)=&getpart;
76 print "\n\n", &menu_svc, "\n", <<END;
77 Some accounts might have entries in users only (Port-Limit >= 2)
79 my($oisdn_svcpart)=&getpart;
81 print "\n\n", &menu_svc, "\n", <<END;
82 POP mail accounts have entries in passwd only, and have a particular shell.
84 my($pop_shell)=&getvalue("Enter that shell:");
85 my($popmail_svcpart)=&getpart;
87 print "\n\n", &menu_svc, "\n", <<END;
88 Everything else in passwd is a shell account.
90 my($shell_svcpart)=&getpart;
93 Enter the location and name of your _user_ passwd file, for example
94 "mail.isp.com:/etc/passwd" or "nis.isp.com:/etc/global/passwd"
96 my($loc_passwd)=&getvalue(":");
97 iscp("root\@$loc_passwd", "$spooldir/passwd.import");
100 Enter the location and name of your _user_ shadow file, for example
101 "mail.isp.com:/etc/shadow" or "bsd.isp.com:/etc/master.passwd"
103 my($loc_shadow)=&getvalue(":");
104 iscp("root\@$loc_shadow", "$spooldir/shadow.import");
107 Enter the location and name of your radius "users" file, for example
108 "radius.isp.com:/etc/raddb/users"
110 my($loc_users)=&getvalue(":");
111 iscp("root\@$loc_users", "$spooldir/users.import");
114 ( join "\n", map "$_: ".$part_svc{$_}->svc, sort keys %part_svc ). "\n";
117 $^W=0; # Term::Query isn't -w-safe
118 query "Enter part number:", 'irk', [ keys %part_svc ];
123 $^W=0; # Term::Query isn't -w-safe
132 open(PASSWD,"<$spooldir/passwd.import");
133 open(SHADOW,"<$spooldir/shadow.import");
134 open(USERS,"<$spooldir/users.import");
136 my(%upassword,%ip,%allparam);
137 my(%param,$username);
142 /^(\w+)\s+Password\s+=\s+"([^"]+)"(,\s+Expiration\s+=\s+"([^"]*")\s*)?$/
143 or die "1Unexpected line in users.import: $_";
144 my($password,$expiration);
145 ($username,$password,$expiration)=(lc($1),$2,$4);
146 $password = '' if $password eq 'UNIX';
147 $upassword{$username}=$password;
150 die "2Unexpected line in users.import: $_";
155 if ( defined $param{'radius_Framed_IP_Address'} ) {
156 $ip{$username} = $param{'radius_Framed_IP_Address'};
157 delete $param{'radius_Framed_IP_Address'};
159 $ip{$username} = '0e0';
161 $allparam{$username}={ %param };
163 } elsif ( /^\s+([\w\-]+)\s=\s"?([\w\.\-\s]+)"?,?\s*$/ ) {
164 my($attribute,$value)=($1,$2);
165 $attribute =~ s/\-/_/g;
166 $param{'radius_'.$attribute}=$value;
168 die "3Unexpected line in users.import: $_";
172 #? incase there isn't a terminating blank line ?
173 if ( defined $param{'radius_Framed_IP_Address'} ) {
174 $ip{$username} = $param{'radius_Framed_IP_Address'};
175 delete $param{'radius_Framed_IP_Address'};
177 $ip{$username} = '0e0';
179 $allparam{$username}={ %param };
184 my($username,$password)=split(/:/);
185 $password{$username}=$password;
190 my($username,$x,$uid,$gid,$finger,$dir,$shell)=split(/:/);
191 my($password)=$upassword{$username} || $password{$username};
193 my($maxb)=${$allparam{$username}}{'radius_Port_Limit'};
195 if ( exists $upassword{$username} ) {
197 $svcpart = $isdn_svcpart
198 } elsif ( ! $maxb || $maxb == 1 ) {
199 $svcpart = $ppp_svcpart
201 die "Illegal Port-Limit in users ($username)!\n";
203 } elsif ( $shell eq $pop_shell ) {
204 $svcpart = $popmail_svcpart;
206 $svcpart = $shell_svcpart;
209 my($svc_acct) = new FS::svc_acct ({
210 'svcpart' => $svcpart,
211 'username' => $username,
212 'password' => $password,
218 'slipip' => $ip{$username},
219 %{$allparam{$username}},
222 $error=$svc_acct->insert;
223 die $error if $error;
225 delete $allparam{$username};
226 delete $upassword{$username};
230 foreach $username ( keys %upassword ) {
231 my($password)=$upassword{$username};
233 my($maxb)=${$allparam{$username}}{'radius_Port_Limit'} || 0;
236 $svcpart = $oisdn_svcpart
237 } elsif ( ! $maxb || $maxb == 1 ) {
238 $svcpart = $oppp_svcpart
240 die "Illegal Port-Limit in users!\n";
243 my($svc_acct) = new FS::svc_acct ({
244 'svcpart' => $svcpart,
245 'username' => $username,
246 'password' => $password,
247 'slipip' => $ip{$username},
248 %{$allparam{$username}},
251 $error=$svc_acct->insert;
252 die $error, if $error;
254 delete $allparam{$username};
255 delete $upassword{$username};
261 die "Usage:\n\n svc_acct.export user\n";