source: trunk/cgi-bin/access-pwd-update.pl@ 397

Last change on this file since 397 was 380, checked in by Kris Deugau, 17 years ago

/trunk

Merge bugfixes/updates from /branches/stable r317 through r379

  • Property svn:executable set to *
  • Property svn:keywords set to Date Rev Author
File size: 1.3 KB
Line 
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: 2008-01-22 21:11:01 +0000 (Tue, 22 Jan 2008) $
7# SVN revision $Rev: 380 $
8# Last update by $Author: kdeugau $
9###
10# Copyright (C) 2007 - Kris Deugau
11
12use strict;
13use warnings;
14use DBI;
15use MyIPDB;
16
17my $ip_dbh;
18my $errstr;
19($ip_dbh,$errstr) = connectDB_My;
20if (!$ip_dbh) {
21 die "Database error: $errstr\n";
22}
23initIPDBGlobals($ip_dbh);
24
25my %userhash;
26
27open HTPASS, "</var/www/ipdb.example.com/ip/.htpasswd";
28
29my $sth = $ip_dbh->prepare("select count(*) from users where username=?");
30
31while (<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}
46my @userlist = @{ $ip_dbh->selectall_arrayref("select username from users") };
47$sth = $ip_dbh->prepare("delete from users where username=?");
48foreach 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.