4 use vars qw(%part_svc);
7 use Term::Query qw(query);
8 use FS::UID qw(adminsuidsetup); #datasrc
9 use FS::Record qw(qsearch qsearchs);
13 my $user = shift or die &usage;
16 #push @FS::svc_acct::shells, qw(/bin/sync /sbin/shutdown /bin/halt /sbin/halt); #others?
18 $FS::svc_Common::noexport_hack = 1;
22 %part_svc=map { $_->svcpart, $_ } qsearch('part_svc',{'svcdb'=>'svc_acct'});
24 die "No services with svcdb svc_acct!\n" unless %part_svc;
26 print "\n\n", &menu_svc, "\n", <<END;
27 Enter part number to import.
29 my $sqlradius_svcpart = &getpart;
31 my $datasrc = &getvalue("\n\nEnter the DBI datasource:");
32 my $db_user = &getvalue("\n\nEnter the database user:");
33 my $db_pass = &getvalue("\n\nEnter the database password:");
36 ( join "\n", map "$_: ".$part_svc{$_}->svc, sort keys %part_svc ). "\n";
39 $^W=0; # Term::Query isn't -w-safe
40 my $return = query "Enter part number:", 'irk', [ keys %part_svc ];
46 $^W=0; # Term::Query isn't -w-safe
47 my $return = query $prompt, '';
56 my $dbh = DBI->connect( $datasrc, $db_user, $db_pass )
59 my $sth = $dbh->prepare('SELECT DISTINCT UserName FROM radcheck')
61 $sth->execute or die $sth->errstr;
64 while ( defined ( $row = $sth->fetchrow_arrayref ) ) {
65 my( $username ) = @$row;
67 my( $password, $group ) = ( '', '', '' );
69 my $rc_sth = $dbh->prepare(
70 'SELECT Attribute, Value'.
73 ) or die $dbh->errstr;
74 $rc_sth->execute($username) or die $rc_sth->errstr;
76 foreach my $rc_row ( @{$rc_sth->fetchall_arrayref} ) {
77 my($attribute, $value) = @$rc_row;
78 if ( $attribute =~ /^((Crypt|User)-)?Password$/ ) {
79 $password = $value unless $password && !$1;
85 my @svc_acct = grep { $_->cust_svc->svcpart == $sqlradius_svcpart }
86 qsearch('svc_acct', { 'username' => $username, } );
88 #print "$r_username / $realm: $password / $finger: ";
89 print "$username: $password: ";
90 if ( scalar(@svc_acct) == 0 ) {
93 } elsif ( scalar(@svc_acct) > 1 ) {
94 print "multiple matches found?!?!\n";
97 #print "correcting password and name\n";
98 print "correcting password\n";
101 my $svc_acct = $svc_acct[0];
102 #my $new = new FS::svc_acct { $svc_acct->hash, '_password' => $password, 'finger' => $finger };
103 my $new = new FS::svc_acct { $svc_acct->hash, '_password' => $password };
104 my $error = $new->replace($svc_acct);
105 #my $error = $new->check;
106 die "$username: $error" if $error;
111 die "Usage:\n\n sqlradius-norealm.reimport user\n";