- Timestamp:
- 12/07/22 17:11:28 (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/cgi-bin/access-pwd-update.pl
-
Property svn:keywords
changed from
Date Rev Author
toId
r906 r932 1 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$ 7 # SVN revision $Rev$ 8 # Last update by $Author$ 9 ### 10 # Copyright (C) 2007-2010 - Kris Deugau 2 # Update IPDB users table with user/password data from 5-minute cron'ed 3 # push from billing 4 ## 5 # $Id$ 6 # Copyright (C) 2007-2010,2017,2022 - Kris Deugau <kdeugau@deepnet.cx> 7 # 8 # This program is free software: you can redistribute it and/or modify 9 # it under the terms of the GNU General Public License as published by 10 # the Free Software Foundation, either version 3 of the License, or 11 # (at your option) any later version. 12 # 13 # This program is distributed in the hope that it will be useful, 14 # but WITHOUT ANY WARRANTY; without even the implied warranty of 15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 # GNU General Public License for more details. 17 # 18 # You should have received a copy of the GNU General Public License 19 # along with this program. If not, see <http://www.gnu.org/licenses/>. 20 ## 11 21 12 22 use strict; 13 23 use warnings; 14 24 use DBI; 25 use Getopt::Long; 15 26 16 27 # don't remove! required for GNU/FHS-ish install from tarball 17 28 ##uselib## 18 29 19 # push "the directory the script is in" into @INC 20 use FindBin; 21 use lib "$FindBin::RealBin/"; 30 # Taint-safe (ish) voodoo to push "the directory the script is in" into @INC. 31 use File::Spec (); 32 use File::Basename (); 33 my $path; 34 BEGIN { 35 $path = File::Basename::dirname(File::Spec->rel2abs($0)); 36 if ($path =~ /(.*)/) { 37 $path = $1; 38 } 39 } 40 use lib $path; 41 42 # Watch for longstanding senior staff deletes; these should make waves when removed 43 my %seniorstaff = map { $_ => 1 } qw (); 44 45 my $doadd = 0; 46 my $dodel = 0; 47 GetOptions( 48 "add|a" => \$doadd, 49 "delete|d" => \$dodel, 50 ); 22 51 23 52 use MyIPDB; … … 38 67 39 68 die ".htpasswd error: file seems too small: ".(-s $passfile)."\n" 40 if (-s $passfile < 3000);69 if (-s $passfile <500); 41 70 42 71 open HTPASS, "<$passfile"; 43 72 44 my $sth = $ip_dbh->prepare("select count(*) from users where username=?"); 45 my $sth2; 73 my $sth = $ip_dbh->prepare("SELECT count(*) FROM users WHERE username = ?"); 74 my $insert_user = $ip_dbh->prepare("INSERT INTO users (username) VALUES (?)"); 75 my $del_user = $ip_dbh->prepare("DELETE FROM users WHERE username = ?"); 76 46 77 while (<HTPASS>) { 47 78 chomp; 48 my ($user, $pass) = split /:/;79 my ($user,undef) = split /:/; 49 80 $sth->execute($user); 50 81 my @data = $sth->fetchrow_array(); 51 my $sql;52 82 if ($data[0] == 0) { 53 $sql = "insert into users (username,password) values ('$user','$pass')"; 54 print "new user: $user\n"; 55 } else { 56 $sql = "update users set password='$pass' where username='$user'"; 83 if ($doadd) { 84 $insert_user->execute($user) or print "error inserting $user: ".$DBI::errstr."\n"; 85 print "new user: $user\n"; 86 } else { 87 print "pending new user: $user\n"; 88 } 57 89 } 58 $sth2 = $ip_dbh->prepare($sql); 59 $sth2->execute or print "error executing $sql: ".$DBI::errstr."\n"; 60 $userhash{$user} = $pass; 90 $userhash{$user} = '!'; 61 91 } 62 92 63 93 # and now to delete users that have been removed 64 $sth = $ip_dbh->prepare("select username,acl from users order by username"); 65 $sth2 = $ip_dbh->prepare("delete from users where username=?"); 94 $sth = $ip_dbh->prepare("SELECT username,acl FROM users ORDER BY username"); 66 95 $sth->execute; 67 96 while (my @data = $sth->fetchrow_array()) { 68 97 if (!$userhash{$data[0]}) { 69 print "deleting $data[0] (acl $data[1])\n"; 70 $sth2->execute($data[0]) 71 or print "error deleting $data[0]: ".$DBI::errstr."\n"; 98 # safety net for senior key staff 99 if ($seniorstaff{$data[0]}) { 100 print "skipping delete of $data[0], update access-pwd-update.pl if they've really left\n"; 101 next; 102 } 103 if ($dodel) { 104 $del_user->execute($data[0]) or print "error deleting $data[0]: ".$DBI::errstr."\n"; 105 print "deleting $data[0] (acl $data[1])\n"; 106 } else { 107 print "pending user delete '$data[0]'\n"; 108 } 72 109 } 73 110 } -
Property svn:keywords
changed from
Note:
See TracChangeset
for help on using the changeset viewer.