4 use vars qw(%part_svc);
6 use Term::Query qw(query);
8 use FS::UID qw(adminsuidsetup datasrc);
9 use FS::Record qw(qsearch);
13 my $user = shift or die &usage;
16 push @FS::svc_acct::shells, qw(/bin/sync /sbin/shuddown /bin/halt); #others?
18 my($spooldir)="/usr/local/etc/freeside/export.". datasrc;
20 $FS::svc_acct::nossh_hack = 1;
24 %part_svc=map { $_->svcpart, $_ } qsearch('part_svc',{'svcdb'=>'svc_acct'});
26 die "No services with svcdb svc_acct!\n" unless %part_svc;
28 print "\n\n", &menu_svc, "\n", <<END;
29 Most accounts probably have entries in passwd and users (with Port-Limit
32 my($ppp_svcpart)=&getpart;
34 print "\n\n", &menu_svc, "\n", <<END;
35 Some accounts have entries in passwd and users, but with Port-Limit 2 (or
38 my($isdn_svcpart)=&getpart;
40 print "\n\n", &menu_svc, "\n", <<END;
41 Some accounts might have entries in users only (Port-Limit 1)
43 my($oppp_svcpart)=&getpart;
45 print "\n\n", &menu_svc, "\n", <<END;
46 Some accounts might have entries in users only (Port-Limit >= 2)
48 my($oisdn_svcpart)=&getpart;
50 print "\n\n", &menu_svc, "\n", <<END;
51 POP mail accounts have entries in passwd only, and have a particular shell.
53 my($pop_shell)=&getvalue("Enter that shell:");
54 my($popmail_svcpart)=&getpart;
56 print "\n\n", &menu_svc, "\n", <<END;
57 Everything else in passwd is a shell account.
59 my($shell_svcpart)=&getpart;
62 Enter the location and name of your _user_ passwd file, for example
63 "mail.isp.com:/etc/passwd" or "nis.isp.com:/etc/global/passwd"
65 my($loc_passwd)=&getvalue(":");
66 iscp("root\@$loc_passwd", "$spooldir/passwd.import");
69 Enter the location and name of your _user_ shadow file, for example
70 "mail.isp.com:/etc/shadow" or "bsd.isp.com:/etc/master.passwd"
72 my($loc_shadow)=&getvalue(":");
73 iscp("root\@$loc_shadow", "$spooldir/shadow.import");
76 Enter the location and name of your radius "users" file, for example
77 "radius.isp.com:/etc/raddb/users"
79 my($loc_users)=&getvalue(":");
80 iscp("root\@$loc_users", "$spooldir/users.import");
83 ( join "\n", map "$_: ".$part_svc{$_}->svc, sort keys %part_svc ). "\n";
86 $^W=0; # Term::Query isn't -w-safe
87 my $return = query "Enter part number:", 'irk', [ keys %part_svc ];
93 $^W=0; # Term::Query isn't -w-safe
94 my $return = query $prompt, '';
103 open(PASSWD,"<$spooldir/passwd.import");
104 open(SHADOW,"<$spooldir/shadow.import");
105 open(USERS,"<$spooldir/users.import");
107 my(%upassword,%ip,%allparam);
108 my(%param,$username);
114 /^(\w+)\s+(Auth-Type\s+=\s+Local,\s+)?Password\s+=\s+"([^"]+)"(,\s+Expiration\s+=\s+"([^"]*")\s*)?$/
115 or die "1Unexpected line in users.import: $_";
116 my($password,$expiration);
117 ($username,$password,$expiration)=(lc($1),$3,$5);
118 $password = '' if $password eq 'UNIX';
119 $upassword{$username}=$password;
122 die "2Unexpected line in users.import: $_";
127 if ( defined $param{'radius_Framed_IP_Address'} ) {
128 $ip{$username} = $param{'radius_Framed_IP_Address'};
129 delete $param{'radius_Framed_IP_Address'};
131 $ip{$username} = '0e0';
133 $allparam{$username}={ %param };
135 } elsif ( /^\s+([\w\-]+)\s=\s"?([\w\.\-\s]+)"?,?\s*$/ ) {
136 my($attribute,$value)=($1,$2);
137 $attribute =~ s/\-/_/g;
138 $param{'radius_'.$attribute}=$value;
140 die "3Unexpected line in users.import: $_";
144 #? incase there isn't a terminating blank line ?
145 if ( defined $param{'radius_Framed_IP_Address'} ) {
146 $ip{$username} = $param{'radius_Framed_IP_Address'};
147 delete $param{'radius_Framed_IP_Address'};
149 $ip{$username} = '0e0';
151 $allparam{$username}={ %param };
156 my($username,$password)=split(/:/);
157 #$password =~ s/^\!$/\*/;
158 #$password =~ s/\!+/\*SUSPENDED\* /;
159 $password{$username}=$password;
164 my($username,$x,$uid,$gid,$finger,$dir,$shell)=split(/:/);
165 my($password)=$upassword{$username} || $password{$username};
167 my($maxb)=${$allparam{$username}}{'radius_Port_Limit'};
169 if ( exists $upassword{$username} ) {
171 $svcpart = $isdn_svcpart
172 } elsif ( ! $maxb || $maxb == 1 ) {
173 $svcpart = $ppp_svcpart
175 die "Illegal Port-Limit in users ($username)!\n";
177 } elsif ( $shell eq $pop_shell ) {
178 $svcpart = $popmail_svcpart;
180 $svcpart = $shell_svcpart;
183 my($svc_acct) = new FS::svc_acct ({
184 'svcpart' => $svcpart,
185 'username' => $username,
186 '_password' => $password,
192 'slipip' => $ip{$username},
193 %{$allparam{$username}},
196 $error=$svc_acct->insert;
197 die $error if $error;
199 delete $allparam{$username};
200 delete $upassword{$username};
204 foreach $username ( keys %upassword ) {
205 my($password)=$upassword{$username};
207 my($maxb)=${$allparam{$username}}{'radius_Port_Limit'} || 0;
210 $svcpart = $oisdn_svcpart
211 } elsif ( ! $maxb || $maxb == 1 ) {
212 $svcpart = $oppp_svcpart
214 die "Illegal Port-Limit in users!\n";
217 my($svc_acct) = new FS::svc_acct ({
218 'svcpart' => $svcpart,
219 'username' => $username,
220 '_password' => $password,
221 'slipip' => $ip{$username},
222 %{$allparam{$username}},
225 $error=$svc_acct->insert;
226 die $error, if $error;
228 delete $allparam{$username};
229 delete $upassword{$username};
235 die "Usage:\n\n svc_acct.import user\n";