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

Last change on this file since 425 was 417, checked in by Kris Deugau, 14 years ago

/trunk

Rearrangements and tweaks toward releaseability:

  • Add Makefile to install halfway-sanely
  • Add .spec file
  • Shuffle "use IPDB;" and "use MyIPDB;" lines so that we can automagically insert a suitable "use lib..." line during 'make install'
  • Check copyright statements
  • Clear up some defaults, and place a number of "constants" in IPDB/MyIPDB rather than having them hardcoded all over the place (Still need to think of a sane way to do this for ipdb.psql's alloctype preseeding)
  • Tweak $VERSION identifier in IPDB.pm so it can be defined in the Makefile
  • Clean up some dangling bits from repository history conversion, remove unneeded "use ..." statements
  • Tweak rWHOIS export script to use more globals and "constants" from (My)IPDB.pm, and more Perl internals than system()-equivalents. Add a few fixme comments for longer-term flexibility improvements.
  • Property svn:executable set to *
  • Property svn:keywords set to Date Rev Author
File size: 1.7 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: 2010-06-30 21:48:03 +0000 (Wed, 30 Jun 2010) $
7# SVN revision $Rev: 417 $
8# Last update by $Author: kdeugau $
9###
10# Copyright (C) 2007-2010 - Kris Deugau
11
12use strict;
13use warnings;
14use DBI;
15
16# don't remove! required for GNU/FHS-ish install from tarball
17##uselib##
18
19use MyIPDB;
20
21my $ip_dbh;
22my $errstr;
23($ip_dbh,$errstr) = connectDB_My;
24if (!$ip_dbh) {
25 die "Database error: $errstr\n";
26}
27initIPDBGlobals($ip_dbh);
28
29my %userhash;
30my $passfile = "/var/www/ipdb.example.com/ip/.htpasswd";
31
32die ".htpasswd error: file is empty!\n"
33 if -z $passfile;
34
35die ".htpasswd error: file seems too small: ".(-s $passfile)."\n"
36 if (-s $passfile <3000);
37
38open HTPASS, "<$passfile";
39
40my $sth = $ip_dbh->prepare("select count(*) from users where username=?");
41my $sth2;
42while (<HTPASS>) {
43 chomp;
44 my ($user,$pass) = split /:/;
45 $sth->execute($user);
46 my @data = $sth->fetchrow_array();
47 my $sql;
48 if ($data[0] == 0) {
49 $sql = "insert into users (username,password) values ('$user','$pass')";
50 print "new user: $user\n";
51 } else {
52 $sql = "update users set password='$pass' where username='$user'";
53 }
54 $sth2 = $ip_dbh->prepare($sql);
55 $sth2->execute or print "error executing $sql: ".$DBI::errstr."\n";
56 $userhash{$user} = $pass;
57}
58
59# and now to delete users that have been removed
60$sth = $ip_dbh->prepare("select username,acl from users order by username");
61$sth2 = $ip_dbh->prepare("delete from users where username=?");
62$sth->execute;
63while (my @data = $sth->fetchrow_array()) {
64 if (!$userhash{$data[0]}) {
65 print "deleting $data[0] (acl $data[1])\n";
66 $sth2->execute($data[0])
67 or print "error deleting $data[0]: ".$DBI::errstr."\n";
68 }
69}
Note: See TracBrowser for help on using the repository browser.