2 # $Id: svc_acct.import,v 1.17 2001-08-19 10:25:44 ivan Exp $
5 use vars qw(%part_svc);
7 use Term::Query qw(query);
9 use FS::UID qw(adminsuidsetup datasrc);
10 use FS::Record qw(qsearch);
14 my $user = shift or die &usage;
17 push @FS::svc_acct::shells, qw(/bin/sync /sbin/shuddown /bin/halt); #others?
19 my($spooldir)="/usr/local/etc/freeside/export.". datasrc;
21 $FS::svc_acct::nossh_hack = 1;
25 %part_svc=map { $_->svcpart, $_ } qsearch('part_svc',{'svcdb'=>'svc_acct'});
27 die "No services with svcdb svc_acct!\n" unless %part_svc;
29 print "\n\n", &menu_svc, "\n", <<END;
30 Most accounts probably have entries in passwd and users (with Port-Limit
33 my($ppp_svcpart)=&getpart;
35 print "\n\n", &menu_svc, "\n", <<END;
36 Some accounts have entries in passwd and users, but with Port-Limit 2 (or
39 my($isdn_svcpart)=&getpart;
41 print "\n\n", &menu_svc, "\n", <<END;
42 Some accounts might have entries in users only (Port-Limit 1)
44 my($oppp_svcpart)=&getpart;
46 print "\n\n", &menu_svc, "\n", <<END;
47 Some accounts might have entries in users only (Port-Limit >= 2)
49 my($oisdn_svcpart)=&getpart;
51 print "\n\n", &menu_svc, "\n", <<END;
52 POP mail accounts have entries in passwd only, and have a particular shell.
54 my($pop_shell)=&getvalue("Enter that shell:");
55 my($popmail_svcpart)=&getpart;
57 print "\n\n", &menu_svc, "\n", <<END;
58 Everything else in passwd is a shell account.
60 my($shell_svcpart)=&getpart;
63 Enter the location and name of your _user_ passwd file, for example
64 "mail.isp.com:/etc/passwd" or "nis.isp.com:/etc/global/passwd"
66 my($loc_passwd)=&getvalue(":");
67 iscp("root\@$loc_passwd", "$spooldir/passwd.import");
70 Enter the location and name of your _user_ shadow file, for example
71 "mail.isp.com:/etc/shadow" or "bsd.isp.com:/etc/master.passwd"
73 my($loc_shadow)=&getvalue(":");
74 iscp("root\@$loc_shadow", "$spooldir/shadow.import");
77 Enter the location and name of your radius "users" file, for example
78 "radius.isp.com:/etc/raddb/users"
80 my($loc_users)=&getvalue(":");
81 iscp("root\@$loc_users", "$spooldir/users.import");
84 ( join "\n", map "$_: ".$part_svc{$_}->svc, sort keys %part_svc ). "\n";
87 $^W=0; # Term::Query isn't -w-safe
88 my $return = query "Enter part number:", 'irk', [ keys %part_svc ];
94 $^W=0; # Term::Query isn't -w-safe
95 my $return = query $prompt, '';
104 open(PASSWD,"<$spooldir/passwd.import");
105 open(SHADOW,"<$spooldir/shadow.import");
106 open(USERS,"<$spooldir/users.import");
108 my(%upassword,%ip,%allparam);
109 my(%param,$username);
115 /^(\w+)\s+(Auth-Type\s+=\s+Local,\s+)?Password\s+=\s+"([^"]+)"(,\s+Expiration\s+=\s+"([^"]*")\s*)?$/
116 or die "1Unexpected line in users.import: $_";
117 my($password,$expiration);
118 ($username,$password,$expiration)=(lc($1),$3,$5);
119 $password = '' if $password eq 'UNIX';
120 $upassword{$username}=$password;
123 die "2Unexpected line in users.import: $_";
128 if ( defined $param{'radius_Framed_IP_Address'} ) {
129 $ip{$username} = $param{'radius_Framed_IP_Address'};
130 delete $param{'radius_Framed_IP_Address'};
132 $ip{$username} = '0e0';
134 $allparam{$username}={ %param };
136 } elsif ( /^\s+([\w\-]+)\s=\s"?([\w\.\-\s]+)"?,?\s*$/ ) {
137 my($attribute,$value)=($1,$2);
138 $attribute =~ s/\-/_/g;
139 $param{'radius_'.$attribute}=$value;
141 die "3Unexpected line in users.import: $_";
145 #? incase there isn't a terminating blank line ?
146 if ( defined $param{'radius_Framed_IP_Address'} ) {
147 $ip{$username} = $param{'radius_Framed_IP_Address'};
148 delete $param{'radius_Framed_IP_Address'};
150 $ip{$username} = '0e0';
152 $allparam{$username}={ %param };
157 my($username,$password)=split(/:/);
158 #$password =~ s/^\!$/\*/;
159 #$password =~ s/\!+/\*SUSPENDED\* /;
160 $password{$username}=$password;
165 my($username,$x,$uid,$gid,$finger,$dir,$shell)=split(/:/);
166 my($password)=$upassword{$username} || $password{$username};
168 my($maxb)=${$allparam{$username}}{'radius_Port_Limit'};
170 if ( exists $upassword{$username} ) {
172 $svcpart = $isdn_svcpart
173 } elsif ( ! $maxb || $maxb == 1 ) {
174 $svcpart = $ppp_svcpart
176 die "Illegal Port-Limit in users ($username)!\n";
178 } elsif ( $shell eq $pop_shell ) {
179 $svcpart = $popmail_svcpart;
181 $svcpart = $shell_svcpart;
184 my($svc_acct) = new FS::svc_acct ({
185 'svcpart' => $svcpart,
186 'username' => $username,
187 '_password' => $password,
193 'slipip' => $ip{$username},
194 %{$allparam{$username}},
197 $error=$svc_acct->insert;
198 die $error if $error;
200 delete $allparam{$username};
201 delete $upassword{$username};
205 foreach $username ( keys %upassword ) {
206 my($password)=$upassword{$username};
208 my($maxb)=${$allparam{$username}}{'radius_Port_Limit'} || 0;
211 $svcpart = $oisdn_svcpart
212 } elsif ( ! $maxb || $maxb == 1 ) {
213 $svcpart = $oppp_svcpart
215 die "Illegal Port-Limit in users!\n";
218 my($svc_acct) = new FS::svc_acct ({
219 'svcpart' => $svcpart,
220 'username' => $username,
221 '_password' => $password,
222 'slipip' => $ip{$username},
223 %{$allparam{$username}},
226 $error=$svc_acct->insert;
227 die $error, if $error;
229 delete $allparam{$username};
230 delete $upassword{$username};
236 die "Usage:\n\n svc_acct.import user\n";