3 # $Id: svc_acct.import,v 1.2 1998-10-13 12:07:51 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.2 1998-10-13 12:07:51 ivan
21 # Assigns password from the shadow file for RADIUS password "UNIX"
25 use vars qw(%part_svc);
28 use FS::UID qw(adminsuidsetup);
29 use FS::Record qw(qsearch);
34 #my($spooldir)="/var/spool/freeside/export";
35 my($spooldir)="unix/";
37 $FS::svc_acct::nossh_hack = 1;
41 %part_svc=map { $_->svcpart, $_ } qsearch('part_svc',{'svcdb'=>'svc_acct'});
43 print "\n\n", &menu_svc, "\n", <<END;
44 Most accounts probably have entries in passwd and users (with Port-Limit
47 my($ppp_svcpart)=&getpart;
49 print "\n\n", &menu_svc, "\n", <<END;
50 Some accounts have entries in passwd and users, but with Port-Limit 2 (or
53 my($isdn_svcpart)=&getpart;
55 print "\n\n", &menu_svc, "\n", <<END;
56 Some accounts might have entries in users only (Port-Limit 1)
58 my($oppp_svcpart)=&getpart;
60 print "\n\n", &menu_svc, "\n", <<END;
61 Some accounts might have entries in users only (Port-Limit >= 2)
63 my($oisdn_svcpart)=&getpart;
65 print "\n\n", &menu_svc, "\n", <<END;
66 POP mail accounts have entries in passwd only, and have a particular shell.
68 print "Enter that shell: ";
69 my($pop_shell)=&getvalue;
70 my($popmail_svcpart)=&getpart;
72 print "\n\n", &menu_svc, "\n", <<END;
73 Everything else in passwd is a shell account.
75 my($shell_svcpart)=&getpart;
78 Enter the location and name of your _user_ passwd file, for example
79 "mail.isp.com:/etc/passwd" or "nis.isp.com:/etc/global/passwd"
82 my($loc_passwd)=&getvalue;
83 iscp("root\@$loc_passwd", "$spooldir/passwd.import");
86 Enter the location and name of your _user_ shadow file, for example
87 "mail.isp.com:/etc/shadow" or "bsd.isp.com:/etc/master.passwd"
90 my($loc_shadow)=&getvalue;
91 iscp("root\@$loc_shadow", "$spooldir/shadow.import");
94 Enter the location and name of your radius "users" file, for example
95 "radius.isp.com:/etc/raddb/users"
98 my($loc_users)=&getvalue;
99 iscp("root\@$loc_users", "$spooldir/users.import");
102 ( join "\n", map "$_: ".$part_svc{$_}->svc, sort keys %part_svc ). "\n";
105 print "Enter part number, or 0 for none: ";
109 my($x)=scalar(<STDIN>);
118 open(PASSWD,"<$spooldir/passwd.import");
119 open(SHADOW,"<$spooldir/shadow.import");
120 open(USERS,"<$spooldir/users.import");
122 my(%upassword,%ip,%allparam);
123 my(%param,$username);
128 /^(\w+)\s+Password\s+=\s+"([^"]+)"(,\s+Expiration\s+=\s+"([^"]*")\s*)?$/
129 or die "1Unexpected line in users.import: $_";
130 my($password,$expiration);
131 ($username,$password,$expiration)=(lc($1),$2,$4);
132 $password = '' if $password eq 'UNIX';
133 $upassword{$username}=$password;
136 die "2Unexpected line in users.import: $_";
141 $ip{$username}=$param{'radius_Framed_IP_Address'}||'0e0';
142 delete $param{'radius_Framed_IP_Address'};
143 $allparam{$username}={ %param };
145 } elsif ( /^\s+([\w\-]+)\s=\s"?([\w\.\-\s]+)"?,?\s*$/ ) {
146 my($attribute,$value)=($1,$2);
147 $attribute =~ s/\-/_/g;
148 $param{'radius_'.$attribute}=$value;
150 die "3Unexpected line in users.import: $_";
154 #? incase there isn't a terminating blank line ?
155 $ip{$username}=$param{'radius_Framed_IP_Address'}||'0e0';
156 delete $param{'radius_Framed_IP_Address'};
157 $allparam{$username}={ %param };
162 my($username,$password)=split(/:/);
163 $password{$username}=$password;
168 my($username,$x,$uid,$gid,$finger,$dir,$shell)=split(/:/);
169 my($password)=$upassword{$username} || $password{$username};
171 my($maxb)=${$allparam{$username}}{'radius_Port_Limit'};
173 if ( exists $upassword{$username} ) {
175 $svcpart = $isdn_svcpart
176 } elsif ( ! $maxb || $maxb == 1 ) {
177 $svcpart = $ppp_svcpart
179 die "Illegal Port-Limit in users ($username)!\n";
181 } elsif ( $shell eq $pop_shell ) {
182 $svcpart = $popmail_svcpart;
184 $svcpart = $shell_svcpart;
187 my($svc_acct) = create FS::svc_acct ({
188 'svcpart' => $svcpart,
189 'username' => $username,
190 'password' => $password,
196 'slipip' => $ip{$username},
197 %{$allparam{$username}},
200 $error=$svc_acct->insert;
201 die $error if $error;
203 delete $allparam{$username};
204 delete $upassword{$username};
208 foreach $username ( keys %upassword ) {
209 my($password)=$upassword{$username};
211 my($maxb)=${$allparam{$username}}{'radius_Port_Limit'} || 0;
214 $svcpart = $oisdn_svcpart
215 } elsif ( ! $maxb || $maxb == 1 ) {
216 $svcpart = $oppp_svcpart
218 die "Illegal Port-Limit in users!\n";
221 my($svc_acct) = create FS::svc_acct ({
222 'svcpart' => $svcpart,
223 'username' => $username,
224 'password' => $password,
225 'slipip' => $ip{$username},
226 %{$allparam{$username}},
229 $error=$svc_acct->insert;
230 die $error, if $error;
232 delete $allparam{$username};
233 delete $upassword{$username};