3 # $Id: svc_acct.import,v 1.4 1999-03-24 00:43:38 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.4 1999-03-24 00:43:38 ivan
21 # die if no relevant services
23 # Revision 1.3 1998/12/10 07:23:16 ivan
24 # use FS::Conf, need user (for datasrc)
26 # Revision 1.2 1998/10/13 12:07:51 ivan
27 # Assigns password from the shadow file for RADIUS password "UNIX"
31 use vars qw(%part_svc);
34 use FS::UID qw(adminsuidsetup datasrc);
35 use FS::Record qw(qsearch);
39 my $user = shift or die &usage;
42 my($spooldir)="/usr/local/etc/freeside/export.". datasrc;
44 $FS::svc_acct::nossh_hack = 1;
48 %part_svc=map { $_->svcpart, $_ } qsearch('part_svc',{'svcdb'=>'svc_acct'});
50 die "No services with svcdb svc_acct!\n" unless %part_svc;
52 print "\n\n", &menu_svc, "\n", <<END;
53 Most accounts probably have entries in passwd and users (with Port-Limit
56 my($ppp_svcpart)=&getpart;
58 print "\n\n", &menu_svc, "\n", <<END;
59 Some accounts have entries in passwd and users, but with Port-Limit 2 (or
62 my($isdn_svcpart)=&getpart;
64 print "\n\n", &menu_svc, "\n", <<END;
65 Some accounts might have entries in users only (Port-Limit 1)
67 my($oppp_svcpart)=&getpart;
69 print "\n\n", &menu_svc, "\n", <<END;
70 Some accounts might have entries in users only (Port-Limit >= 2)
72 my($oisdn_svcpart)=&getpart;
74 print "\n\n", &menu_svc, "\n", <<END;
75 POP mail accounts have entries in passwd only, and have a particular shell.
77 print "Enter that shell: ";
78 my($pop_shell)=&getvalue;
79 my($popmail_svcpart)=&getpart;
81 print "\n\n", &menu_svc, "\n", <<END;
82 Everything else in passwd is a shell account.
84 my($shell_svcpart)=&getpart;
87 Enter the location and name of your _user_ passwd file, for example
88 "mail.isp.com:/etc/passwd" or "nis.isp.com:/etc/global/passwd"
91 my($loc_passwd)=&getvalue;
92 iscp("root\@$loc_passwd", "$spooldir/passwd.import");
95 Enter the location and name of your _user_ shadow file, for example
96 "mail.isp.com:/etc/shadow" or "bsd.isp.com:/etc/master.passwd"
99 my($loc_shadow)=&getvalue;
100 iscp("root\@$loc_shadow", "$spooldir/shadow.import");
103 Enter the location and name of your radius "users" file, for example
104 "radius.isp.com:/etc/raddb/users"
107 my($loc_users)=&getvalue;
108 iscp("root\@$loc_users", "$spooldir/users.import");
111 ( join "\n", map "$_: ".$part_svc{$_}->svc, sort keys %part_svc ). "\n";
114 print "Enter part number, or 0 for none: ";
118 my($x)=scalar(<STDIN>);
127 open(PASSWD,"<$spooldir/passwd.import");
128 open(SHADOW,"<$spooldir/shadow.import");
129 open(USERS,"<$spooldir/users.import");
131 my(%upassword,%ip,%allparam);
132 my(%param,$username);
137 /^(\w+)\s+Password\s+=\s+"([^"]+)"(,\s+Expiration\s+=\s+"([^"]*")\s*)?$/
138 or die "1Unexpected line in users.import: $_";
139 my($password,$expiration);
140 ($username,$password,$expiration)=(lc($1),$2,$4);
141 $password = '' if $password eq 'UNIX';
142 $upassword{$username}=$password;
145 die "2Unexpected line in users.import: $_";
150 $ip{$username}=$param{'radius_Framed_IP_Address'}||'0e0';
151 delete $param{'radius_Framed_IP_Address'};
152 $allparam{$username}={ %param };
154 } elsif ( /^\s+([\w\-]+)\s=\s"?([\w\.\-\s]+)"?,?\s*$/ ) {
155 my($attribute,$value)=($1,$2);
156 $attribute =~ s/\-/_/g;
157 $param{'radius_'.$attribute}=$value;
159 die "3Unexpected line in users.import: $_";
163 #? incase there isn't a terminating blank line ?
164 $ip{$username}=$param{'radius_Framed_IP_Address'}||'0e0';
165 delete $param{'radius_Framed_IP_Address'};
166 $allparam{$username}={ %param };
171 my($username,$password)=split(/:/);
172 $password{$username}=$password;
177 my($username,$x,$uid,$gid,$finger,$dir,$shell)=split(/:/);
178 my($password)=$upassword{$username} || $password{$username};
180 my($maxb)=${$allparam{$username}}{'radius_Port_Limit'};
182 if ( exists $upassword{$username} ) {
184 $svcpart = $isdn_svcpart
185 } elsif ( ! $maxb || $maxb == 1 ) {
186 $svcpart = $ppp_svcpart
188 die "Illegal Port-Limit in users ($username)!\n";
190 } elsif ( $shell eq $pop_shell ) {
191 $svcpart = $popmail_svcpart;
193 $svcpart = $shell_svcpart;
196 my($svc_acct) = create FS::svc_acct ({
197 'svcpart' => $svcpart,
198 'username' => $username,
199 'password' => $password,
205 'slipip' => $ip{$username},
206 %{$allparam{$username}},
209 $error=$svc_acct->insert;
210 die $error if $error;
212 delete $allparam{$username};
213 delete $upassword{$username};
217 foreach $username ( keys %upassword ) {
218 my($password)=$upassword{$username};
220 my($maxb)=${$allparam{$username}}{'radius_Port_Limit'} || 0;
223 $svcpart = $oisdn_svcpart
224 } elsif ( ! $maxb || $maxb == 1 ) {
225 $svcpart = $oppp_svcpart
227 die "Illegal Port-Limit in users!\n";
230 my($svc_acct) = create FS::svc_acct ({
231 'svcpart' => $svcpart,
232 'username' => $username,
233 'password' => $password,
234 'slipip' => $ip{$username},
235 %{$allparam{$username}},
238 $error=$svc_acct->insert;
239 die $error, if $error;
241 delete $allparam{$username};
242 delete $upassword{$username};
248 die "Usage:\n\n svc_acct.export user\n";