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

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

/branches/stable

Commit various tweaks/fugbixes/enhancements to access-pwd-update.pl

  • Property svn:executable set to *
  • Property svn:keywords set to Date Rev Author
File size: 1.7 KB
RevLine 
[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: 2008-06-09 19:05:47 +0000 (Mon, 09 Jun 2008) $
7# SVN revision $Rev: 386 $
8# Last update by $Author: kdeugau $
9###
[386]10# Copyright (C) 2007,2008 - Kris Deugau
[373]11
12use strict;
13use warnings;
14use DBI;
[386]15use lib '/var/www/ipdb.example.com/ip/cgi-bin/';
[373]16use MyIPDB;
17
18my $ip_dbh;
19my $errstr;
20($ip_dbh,$errstr) = connectDB_My;
21if (!$ip_dbh) {
22 die "Database error: $errstr\n";
23}
24initIPDBGlobals($ip_dbh);
25
26my %userhash;
[386]27my $passfile = "/var/www/ipdb.example.com/ip/.htpasswd";
[373]28
[386]29die ".htpasswd error: file is empty!\n"
30 if -z $passfile;
[373]31
[386]32die ".htpasswd error: file seems too small: ".(-s $passfile)."\n"
33 if (-s $passfile <3000);
34
35open HTPASS, "<$passfile";
36
[373]37my $sth = $ip_dbh->prepare("select count(*) from users where username=?");
[386]38my $sth2;
[373]39while (<HTPASS>) {
40 chomp;
41 my ($user,$pass) = split /:/;
42 $sth->execute($user);
43 my @data = $sth->fetchrow_array();
44 my $sql;
45 if ($data[0] == 0) {
46 $sql = "insert into users (username,password) values ('$user','$pass')";
[386]47 print "new user: $user\n";
[373]48 } else {
49 $sql = "update users set password='$pass' where username='$user'";
50 }
[386]51 $sth2 = $ip_dbh->prepare($sql);
[373]52 $sth2->execute or print "error executing $sql: ".$DBI::errstr."\n";
53 $userhash{$user} = $pass;
54}
[386]55
56# and now to delete users that have been removed
57$sth = $ip_dbh->prepare("select username,acl from users order by username");
58$sth2 = $ip_dbh->prepare("delete from users where username=?");
59$sth->execute;
60while (my @data = $sth->fetchrow_array()) {
61 if (!$userhash{$data[0]}) {
62 print "deleting $data[0] (acl $data[1])\n";
63 $sth2->execute($data[0])
64 or print "error deleting $data[0]: ".$DBI::errstr."\n";
65 }
[373]66}
Note: See TracBrowser for help on using the repository browser.