3 # $Id: svc_acct.import,v 1.3 1998-12-10 07:23:16 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.3 1998-12-10 07:23:16 ivan
21 # use FS::Conf, need user (for datasrc)
23 # Revision 1.2 1998/10/13 12:07:51 ivan
24 # Assigns password from the shadow file for RADIUS password "UNIX"
28 use vars qw(%part_svc);
31 use FS::UID qw(adminsuidsetup datasrc);
32 use FS::Record qw(qsearch);
36 my $user = shift or die &usage;
39 my($spooldir)="/usr/local/etc/freeside/export.". datasrc;
41 $FS::svc_acct::nossh_hack = 1;
45 %part_svc=map { $_->svcpart, $_ } qsearch('part_svc',{'svcdb'=>'svc_acct'});
47 print "\n\n", &menu_svc, "\n", <<END;
48 Most accounts probably have entries in passwd and users (with Port-Limit
51 my($ppp_svcpart)=&getpart;
53 print "\n\n", &menu_svc, "\n", <<END;
54 Some accounts have entries in passwd and users, but with Port-Limit 2 (or
57 my($isdn_svcpart)=&getpart;
59 print "\n\n", &menu_svc, "\n", <<END;
60 Some accounts might have entries in users only (Port-Limit 1)
62 my($oppp_svcpart)=&getpart;
64 print "\n\n", &menu_svc, "\n", <<END;
65 Some accounts might have entries in users only (Port-Limit >= 2)
67 my($oisdn_svcpart)=&getpart;
69 print "\n\n", &menu_svc, "\n", <<END;
70 POP mail accounts have entries in passwd only, and have a particular shell.
72 print "Enter that shell: ";
73 my($pop_shell)=&getvalue;
74 my($popmail_svcpart)=&getpart;
76 print "\n\n", &menu_svc, "\n", <<END;
77 Everything else in passwd is a shell account.
79 my($shell_svcpart)=&getpart;
82 Enter the location and name of your _user_ passwd file, for example
83 "mail.isp.com:/etc/passwd" or "nis.isp.com:/etc/global/passwd"
86 my($loc_passwd)=&getvalue;
87 iscp("root\@$loc_passwd", "$spooldir/passwd.import");
90 Enter the location and name of your _user_ shadow file, for example
91 "mail.isp.com:/etc/shadow" or "bsd.isp.com:/etc/master.passwd"
94 my($loc_shadow)=&getvalue;
95 iscp("root\@$loc_shadow", "$spooldir/shadow.import");
98 Enter the location and name of your radius "users" file, for example
99 "radius.isp.com:/etc/raddb/users"
102 my($loc_users)=&getvalue;
103 iscp("root\@$loc_users", "$spooldir/users.import");
106 ( join "\n", map "$_: ".$part_svc{$_}->svc, sort keys %part_svc ). "\n";
109 print "Enter part number, or 0 for none: ";
113 my($x)=scalar(<STDIN>);
122 open(PASSWD,"<$spooldir/passwd.import");
123 open(SHADOW,"<$spooldir/shadow.import");
124 open(USERS,"<$spooldir/users.import");
126 my(%upassword,%ip,%allparam);
127 my(%param,$username);
132 /^(\w+)\s+Password\s+=\s+"([^"]+)"(,\s+Expiration\s+=\s+"([^"]*")\s*)?$/
133 or die "1Unexpected line in users.import: $_";
134 my($password,$expiration);
135 ($username,$password,$expiration)=(lc($1),$2,$4);
136 $password = '' if $password eq 'UNIX';
137 $upassword{$username}=$password;
140 die "2Unexpected line in users.import: $_";
145 $ip{$username}=$param{'radius_Framed_IP_Address'}||'0e0';
146 delete $param{'radius_Framed_IP_Address'};
147 $allparam{$username}={ %param };
149 } elsif ( /^\s+([\w\-]+)\s=\s"?([\w\.\-\s]+)"?,?\s*$/ ) {
150 my($attribute,$value)=($1,$2);
151 $attribute =~ s/\-/_/g;
152 $param{'radius_'.$attribute}=$value;
154 die "3Unexpected line in users.import: $_";
158 #? incase there isn't a terminating blank line ?
159 $ip{$username}=$param{'radius_Framed_IP_Address'}||'0e0';
160 delete $param{'radius_Framed_IP_Address'};
161 $allparam{$username}={ %param };
166 my($username,$password)=split(/:/);
167 $password{$username}=$password;
172 my($username,$x,$uid,$gid,$finger,$dir,$shell)=split(/:/);
173 my($password)=$upassword{$username} || $password{$username};
175 my($maxb)=${$allparam{$username}}{'radius_Port_Limit'};
177 if ( exists $upassword{$username} ) {
179 $svcpart = $isdn_svcpart
180 } elsif ( ! $maxb || $maxb == 1 ) {
181 $svcpart = $ppp_svcpart
183 die "Illegal Port-Limit in users ($username)!\n";
185 } elsif ( $shell eq $pop_shell ) {
186 $svcpart = $popmail_svcpart;
188 $svcpart = $shell_svcpart;
191 my($svc_acct) = create FS::svc_acct ({
192 'svcpart' => $svcpart,
193 'username' => $username,
194 'password' => $password,
200 'slipip' => $ip{$username},
201 %{$allparam{$username}},
204 $error=$svc_acct->insert;
205 die $error if $error;
207 delete $allparam{$username};
208 delete $upassword{$username};
212 foreach $username ( keys %upassword ) {
213 my($password)=$upassword{$username};
215 my($maxb)=${$allparam{$username}}{'radius_Port_Limit'} || 0;
218 $svcpart = $oisdn_svcpart
219 } elsif ( ! $maxb || $maxb == 1 ) {
220 $svcpart = $oppp_svcpart
222 die "Illegal Port-Limit in users!\n";
225 my($svc_acct) = create FS::svc_acct ({
226 'svcpart' => $svcpart,
227 'username' => $username,
228 'password' => $password,
229 'slipip' => $ip{$username},
230 %{$allparam{$username}},
233 $error=$svc_acct->insert;
234 die $error, if $error;
236 delete $allparam{$username};
237 delete $upassword{$username};
243 die "Usage:\n\n svc_acct.export user\n";