Changeset 399


Ignore:
Timestamp:
05/11/10 14:59:27 (14 years ago)
Author:
Kris Deugau
Message:

/trunk

Merge updates/bugfixes to access-pwd-update.pl from r386. See #13.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/cgi-bin/access-pwd-update.pl

    r380 r399  
    88# Last update by $Author$
    99###
    10 # Copyright (C) 2007 - Kris Deugau
     10# Copyright (C) 2007,2008 - Kris Deugau
    1111
    1212use strict;
    1313use warnings;
    1414use DBI;
     15use lib '/var/www/ipdb.example.com/ip/cgi-bin/';
    1516use MyIPDB;
    1617
     
    2425
    2526my %userhash;
     27my $passfile = "/var/www/ipdb.example.com/ip/.htpasswd";
    2628
    27 open HTPASS, "</var/www/ipdb.example.com/ip/.htpasswd";
     29die ".htpasswd error:  file is empty!\n"
     30        if -z $passfile;
     31
     32die ".htpasswd error:  file seems too small: ".(-s $passfile)."\n"
     33        if (-s $passfile <3000);
     34
     35open HTPASS, "<$passfile";
    2836
    2937my $sth = $ip_dbh->prepare("select count(*) from users where username=?");
    30 
     38my $sth2;
    3139while (<HTPASS>) {
    3240  chomp;
     
    3745  if ($data[0] == 0) {
    3846    $sql = "insert into users (username,password) values ('$user','$pass')";
     47    print "new user: $user\n";
    3948  } else {
    4049    $sql = "update users set password='$pass' where username='$user'";
    4150  }
    42   my $sth2 = $ip_dbh->prepare($sql);
     51  $sth2 = $ip_dbh->prepare($sql);
    4352  $sth2->execute or print "error executing $sql: ".$DBI::errstr."\n";
    4453  $userhash{$user} = $pass;
    4554}
    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";
     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  }
    5166}
Note: See TracChangeset for help on using the changeset viewer.