Last change
on this file since 373 was 373, checked in by Kris Deugau, 17 years ago |
/branches/stable
Add script to munge user data into the users table based on an
externally-pushed .htpasswd
|
-
Property svn:executable
set to
*
|
File size:
1.3 KB
|
Rev | Line | |
---|
[373] | 1 | #!/usr/bin/perl
|
---|
| 2 | # Update IPDB users table with user/password data from 5-minute
|
---|
| 3 | # cron'ed push from billing
|
---|
| 4 | ###
|
---|
| 5 | # SVN revision info
|
---|
| 6 | # $Date$
|
---|
| 7 | # SVN revision $Rev$
|
---|
| 8 | # Last update by $Author$
|
---|
| 9 | ###
|
---|
| 10 | # Copyright (C) 2007 - Kris Deugau
|
---|
| 11 |
|
---|
| 12 | use strict;
|
---|
| 13 | use warnings;
|
---|
| 14 | use DBI;
|
---|
| 15 | use MyIPDB;
|
---|
| 16 |
|
---|
| 17 | my $ip_dbh;
|
---|
| 18 | my $errstr;
|
---|
| 19 | ($ip_dbh,$errstr) = connectDB_My;
|
---|
| 20 | if (!$ip_dbh) {
|
---|
| 21 | die "Database error: $errstr\n";
|
---|
| 22 | }
|
---|
| 23 | initIPDBGlobals($ip_dbh);
|
---|
| 24 |
|
---|
| 25 | my %userhash;
|
---|
| 26 |
|
---|
| 27 | open HTPASS, "</var/www/ipdb.example.com/ip/.htpasswd";
|
---|
| 28 |
|
---|
| 29 | my $sth = $ip_dbh->prepare("select count(*) from users where username=?");
|
---|
| 30 |
|
---|
| 31 | while (<HTPASS>) {
|
---|
| 32 | chomp;
|
---|
| 33 | my ($user,$pass) = split /:/;
|
---|
| 34 | $sth->execute($user);
|
---|
| 35 | my @data = $sth->fetchrow_array();
|
---|
| 36 | my $sql;
|
---|
| 37 | if ($data[0] == 0) {
|
---|
| 38 | $sql = "insert into users (username,password) values ('$user','$pass')";
|
---|
| 39 | } else {
|
---|
| 40 | $sql = "update users set password='$pass' where username='$user'";
|
---|
| 41 | }
|
---|
| 42 | my $sth2 = $ip_dbh->prepare($sql);
|
---|
| 43 | $sth2->execute or print "error executing $sql: ".$DBI::errstr."\n";
|
---|
| 44 | $userhash{$user} = $pass;
|
---|
| 45 | }
|
---|
| 46 | my @userlist = @{ $ip_dbh->selectall_arrayref("select username from users") };
|
---|
| 47 | $sth = $ip_dbh->prepare("delete from users where username=?");
|
---|
| 48 | foreach my $user (@userlist) {
|
---|
| 49 | $sth->execute if !$userhash{$user}
|
---|
| 50 | or print "error deleting $user: ".$DBI::errstr."\n";
|
---|
| 51 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.