source: branches/stable/cgi-bin/access-pwd-update.pl@ 375

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

/branches/stable

Forgot SVN properties on user update script

  • 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: 2007-12-11 20:27:18 +0000 (Tue, 11 Dec 2007) $
7# SVN revision $Rev: 374 $
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.