Changeset 399
- Timestamp:
- 05/11/10 14:59:27 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/cgi-bin/access-pwd-update.pl
r380 r399 8 8 # Last update by $Author$ 9 9 ### 10 # Copyright (C) 2007 - Kris Deugau10 # Copyright (C) 2007,2008 - Kris Deugau 11 11 12 12 use strict; 13 13 use warnings; 14 14 use DBI; 15 use lib '/var/www/ipdb.example.com/ip/cgi-bin/'; 15 16 use MyIPDB; 16 17 … … 24 25 25 26 my %userhash; 27 my $passfile = "/var/www/ipdb.example.com/ip/.htpasswd"; 26 28 27 open HTPASS, "</var/www/ipdb.example.com/ip/.htpasswd"; 29 die ".htpasswd error: file is empty!\n" 30 if -z $passfile; 31 32 die ".htpasswd error: file seems too small: ".(-s $passfile)."\n" 33 if (-s $passfile <3000); 34 35 open HTPASS, "<$passfile"; 28 36 29 37 my $sth = $ip_dbh->prepare("select count(*) from users where username=?"); 30 38 my $sth2; 31 39 while (<HTPASS>) { 32 40 chomp; … … 37 45 if ($data[0] == 0) { 38 46 $sql = "insert into users (username,password) values ('$user','$pass')"; 47 print "new user: $user\n"; 39 48 } else { 40 49 $sql = "update users set password='$pass' where username='$user'"; 41 50 } 42 my$sth2 = $ip_dbh->prepare($sql);51 $sth2 = $ip_dbh->prepare($sql); 43 52 $sth2->execute or print "error executing $sql: ".$DBI::errstr."\n"; 44 53 $userhash{$user} = $pass; 45 54 } 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; 60 while (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 } 51 66 }
Note:
See TracChangeset
for help on using the changeset viewer.