3 # ivan@sisd.com 98-mar-9
5 # changed 'password' field to '_password' because PgSQL 6.3 reserves this word
6 # bmccane@maxbaud.net 98-Apr-3
8 # generalized svcparts (still needs radius import) ivan@sisd.com 98-mar-23
10 # radius import, now an interactive script. still needs erpcd import?
11 # ivan@sisd.com 98-jun-24
13 # arbitrary radius attributes ivan@sisd.com 98-aug-9
15 # don't import /var/spool/freeside/conf/shells! ivan@sisd.com 98-aug-13
18 use vars qw(%part_svc);
21 use FS::UID qw(adminsuidsetup);
22 use FS::Record qw(qsearch);
27 #my($spooldir)="/var/spool/freeside/export";
28 my($spooldir)="unix/";
30 $FS::svc_acct::nossh_hack = 1;
34 %part_svc=map { $_->svcpart, $_ } qsearch('part_svc',{'svcdb'=>'svc_acct'});
36 print "\n\n", &menu_svc, "\n", <<END;
37 Most accounts probably have entries in passwd and users (with Port-Limit
40 my($ppp_svcpart)=&getpart;
42 print "\n\n", &menu_svc, "\n", <<END;
43 Some accounts have entries in passwd and users, but with Port-Limit 2 (or
46 my($isdn_svcpart)=&getpart;
48 print "\n\n", &menu_svc, "\n", <<END;
49 Some accounts might have entries in users only (Port-Limit 1)
51 my($oppp_svcpart)=&getpart;
53 print "\n\n", &menu_svc, "\n", <<END;
54 Some accounts might have entries in users only (Port-Limit >= 2)
56 my($oisdn_svcpart)=&getpart;
58 print "\n\n", &menu_svc, "\n", <<END;
59 POP mail accounts have entries in passwd only, and have a particular shell.
61 print "Enter that shell: ";
62 my($pop_shell)=&getvalue;
63 my($popmail_svcpart)=&getpart;
65 print "\n\n", &menu_svc, "\n", <<END;
66 Everything else in passwd is a shell account.
68 my($shell_svcpart)=&getpart;
71 Enter the location and name of your _user_ passwd file, for example
72 "mail.isp.com:/etc/passwd" or "nis.isp.com:/etc/global/passwd"
75 my($loc_passwd)=&getvalue;
76 iscp("root\@$loc_passwd", "$spooldir/passwd.import");
79 Enter the location and name of your _user_ shadow file, for example
80 "mail.isp.com:/etc/shadow" or "bsd.isp.com:/etc/master.passwd"
83 my($loc_shadow)=&getvalue;
84 iscp("root\@$loc_shadow", "$spooldir/shadow.import");
87 Enter the location and name of your radius "users" file, for example
88 "radius.isp.com:/etc/raddb/users"
91 my($loc_users)=&getvalue;
92 iscp("root\@$loc_users", "$spooldir/users.import");
95 ( join "\n", map "$_: ".$part_svc{$_}->svc, sort keys %part_svc ). "\n";
98 print "Enter part number, or 0 for none: ";
102 my($x)=scalar(<STDIN>);
111 open(PASSWD,"<$spooldir/passwd.import");
112 open(SHADOW,"<$spooldir/shadow.import");
113 open(USERS,"<$spooldir/users.import");
115 my(%upassword,%ip,%allparam);
116 my(%param,$username);
121 /^(\w+)\s+Password\s+=\s+"([^"]+)"(,\s+Expiration\s+=\s+"([^"]*")\s*)?$/
122 or die "1Unexpected line in users.import: $_";
123 my($password,$expiration);
124 ($username,$password,$expiration)=(lc($1),$2,$4);
125 $upassword{$username}=$password;
128 die "2Unexpected line in users.import: $_";
133 $ip{$username}=$param{'radius_Framed_IP_Address'}||'0e0';
134 delete $param{'radius_Framed_IP_Address'};
135 $allparam{$username}={ %param };
137 } elsif ( /^\s+([\w\-]+)\s=\s"?([\w\.\-\s]+)"?,?\s*$/ ) {
138 my($attribute,$value)=($1,$2);
139 $attribute =~ s/\-/_/g;
140 $param{'radius_'.$attribute}=$value;
142 die "3Unexpected line in users.import: $_";
146 #? incase there isn't a terminating blank line ?
147 $ip{$username}=$param{'radius_Framed_IP_Address'}||'0e0';
148 delete $param{'radius_Framed_IP_Address'};
149 $allparam{$username}={ %param };
154 my($username,$password)=split(/:/);
155 $password{$username}=$password;
160 my($username,$x,$uid,$gid,$finger,$dir,$shell)=split(/:/);
161 my($password)=$upassword{$username} || $password{$username};
163 my($maxb)=${$allparam{$username}}{'radius_Port_Limit'};
165 if ( exists $upassword{$username} ) {
167 $svcpart = $isdn_svcpart
168 } elsif ( ! $maxb || $maxb == 1 ) {
169 $svcpart = $ppp_svcpart
171 die "Illegal Port-Limit in users ($username)!\n";
173 } elsif ( $shell eq $pop_shell ) {
174 $svcpart = $popmail_svcpart;
176 $svcpart = $shell_svcpart;
179 my($svc_acct) = create FS::svc_acct ({
180 'svcpart' => $svcpart,
181 'username' => $username,
182 'password' => $password,
188 'slipip' => $ip{$username},
189 %{$allparam{$username}},
192 $error=$svc_acct->insert;
193 die $error if $error;
195 delete $allparam{$username};
196 delete $upassword{$username};
200 foreach $username ( keys %upassword ) {
201 my($password)=$upassword{$username};
203 my($maxb)=${$allparam{$username}}{'radius_Port_Limit'} || 0;
206 $svcpart = $oisdn_svcpart
207 } elsif ( ! $maxb || $maxb == 1 ) {
208 $svcpart = $oppp_svcpart
210 die "Illegal Port-Limit in users!\n";
213 my($svc_acct) = create FS::svc_acct ({
214 'svcpart' => $svcpart,
215 'username' => $username,
216 'password' => $password,
217 'slipip' => $ip{$username},
218 %{$allparam{$username}},
221 $error=$svc_acct->insert;
222 die $error, if $error;
224 delete $allparam{$username};
225 delete $upassword{$username};