3 # $Id: svc_acct.import,v 1.7 1999-07-08 02:32:26 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.7 1999-07-08 02:32:26 ivan
21 # import fix, noticed by Ben Leibig and Joel Griffiths
23 # Revision 1.6 1999/07/08 01:49:00 ivan
24 # updates to avoid -w warnings from Joel Griffiths <griff@aver-computer.com>
26 # Revision 1.5 1999/03/25 08:42:19 ivan
27 # import stuff uses Term::Query and spits out (some kinds of) nonsensical input
29 # Revision 1.4 1999/03/24 00:43:38 ivan
30 # die if no relevant services
32 # Revision 1.3 1998/12/10 07:23:16 ivan
33 # use FS::Conf, need user (for datasrc)
35 # Revision 1.2 1998/10/13 12:07:51 ivan
36 # Assigns password from the shadow file for RADIUS password "UNIX"
40 use vars qw(%part_svc);
42 use Term::Query qw(query);
44 use FS::UID qw(adminsuidsetup datasrc);
45 use FS::Record qw(qsearch);
49 my $user = shift or die &usage;
52 my($spooldir)="/usr/local/etc/freeside/export.". datasrc;
54 $FS::svc_acct::nossh_hack = 1;
58 %part_svc=map { $_->svcpart, $_ } qsearch('part_svc',{'svcdb'=>'svc_acct'});
60 die "No services with svcdb svc_acct!\n" unless %part_svc;
62 print "\n\n", &menu_svc, "\n", <<END;
63 Most accounts probably have entries in passwd and users (with Port-Limit
66 my($ppp_svcpart)=&getpart;
68 print "\n\n", &menu_svc, "\n", <<END;
69 Some accounts have entries in passwd and users, but with Port-Limit 2 (or
72 my($isdn_svcpart)=&getpart;
74 print "\n\n", &menu_svc, "\n", <<END;
75 Some accounts might have entries in users only (Port-Limit 1)
77 my($oppp_svcpart)=&getpart;
79 print "\n\n", &menu_svc, "\n", <<END;
80 Some accounts might have entries in users only (Port-Limit >= 2)
82 my($oisdn_svcpart)=&getpart;
84 print "\n\n", &menu_svc, "\n", <<END;
85 POP mail accounts have entries in passwd only, and have a particular shell.
87 my($pop_shell)=&getvalue("Enter that shell:");
88 my($popmail_svcpart)=&getpart;
90 print "\n\n", &menu_svc, "\n", <<END;
91 Everything else in passwd is a shell account.
93 my($shell_svcpart)=&getpart;
96 Enter the location and name of your _user_ passwd file, for example
97 "mail.isp.com:/etc/passwd" or "nis.isp.com:/etc/global/passwd"
99 my($loc_passwd)=&getvalue(":");
100 iscp("root\@$loc_passwd", "$spooldir/passwd.import");
103 Enter the location and name of your _user_ shadow file, for example
104 "mail.isp.com:/etc/shadow" or "bsd.isp.com:/etc/master.passwd"
106 my($loc_shadow)=&getvalue(":");
107 iscp("root\@$loc_shadow", "$spooldir/shadow.import");
110 Enter the location and name of your radius "users" file, for example
111 "radius.isp.com:/etc/raddb/users"
113 my($loc_users)=&getvalue(":");
114 iscp("root\@$loc_users", "$spooldir/users.import");
117 ( join "\n", map "$_: ".$part_svc{$_}->svc, sort keys %part_svc ). "\n";
120 $^W=0; # Term::Query isn't -w-safe
121 my $return = query "Enter part number:", 'irk', [ keys %part_svc ];
127 $^W=0; # Term::Query isn't -w-safe
128 my $return = query $prompt, '';
137 open(PASSWD,"<$spooldir/passwd.import");
138 open(SHADOW,"<$spooldir/shadow.import");
139 open(USERS,"<$spooldir/users.import");
141 my(%upassword,%ip,%allparam);
142 my(%param,$username);
147 /^(\w+)\s+Password\s+=\s+"([^"]+)"(,\s+Expiration\s+=\s+"([^"]*")\s*)?$/
148 or die "1Unexpected line in users.import: $_";
149 my($password,$expiration);
150 ($username,$password,$expiration)=(lc($1),$2,$4);
151 $password = '' if $password eq 'UNIX';
152 $upassword{$username}=$password;
155 die "2Unexpected line in users.import: $_";
160 if ( defined $param{'radius_Framed_IP_Address'} ) {
161 $ip{$username} = $param{'radius_Framed_IP_Address'};
162 delete $param{'radius_Framed_IP_Address'};
164 $ip{$username} = '0e0';
166 $allparam{$username}={ %param };
168 } elsif ( /^\s+([\w\-]+)\s=\s"?([\w\.\-\s]+)"?,?\s*$/ ) {
169 my($attribute,$value)=($1,$2);
170 $attribute =~ s/\-/_/g;
171 $param{'radius_'.$attribute}=$value;
173 die "3Unexpected line in users.import: $_";
177 #? incase there isn't a terminating blank line ?
178 if ( defined $param{'radius_Framed_IP_Address'} ) {
179 $ip{$username} = $param{'radius_Framed_IP_Address'};
180 delete $param{'radius_Framed_IP_Address'};
182 $ip{$username} = '0e0';
184 $allparam{$username}={ %param };
189 my($username,$password)=split(/:/);
190 $password{$username}=$password;
195 my($username,$x,$uid,$gid,$finger,$dir,$shell)=split(/:/);
196 my($password)=$upassword{$username} || $password{$username};
198 my($maxb)=${$allparam{$username}}{'radius_Port_Limit'};
200 if ( exists $upassword{$username} ) {
202 $svcpart = $isdn_svcpart
203 } elsif ( ! $maxb || $maxb == 1 ) {
204 $svcpart = $ppp_svcpart
206 die "Illegal Port-Limit in users ($username)!\n";
208 } elsif ( $shell eq $pop_shell ) {
209 $svcpart = $popmail_svcpart;
211 $svcpart = $shell_svcpart;
214 my($svc_acct) = new FS::svc_acct ({
215 'svcpart' => $svcpart,
216 'username' => $username,
217 'password' => $password,
223 'slipip' => $ip{$username},
224 %{$allparam{$username}},
227 $error=$svc_acct->insert;
228 die $error if $error;
230 delete $allparam{$username};
231 delete $upassword{$username};
235 foreach $username ( keys %upassword ) {
236 my($password)=$upassword{$username};
238 my($maxb)=${$allparam{$username}}{'radius_Port_Limit'} || 0;
241 $svcpart = $oisdn_svcpart
242 } elsif ( ! $maxb || $maxb == 1 ) {
243 $svcpart = $oppp_svcpart
245 die "Illegal Port-Limit in users!\n";
248 my($svc_acct) = new FS::svc_acct ({
249 'svcpart' => $svcpart,
250 'username' => $username,
251 'password' => $password,
252 'slipip' => $ip{$username},
253 %{$allparam{$username}},
256 $error=$svc_acct->insert;
257 die $error, if $error;
259 delete $allparam{$username};
260 delete $upassword{$username};
266 die "Usage:\n\n svc_acct.export user\n";