source: locker/bin/webaccess @ 127

Last change on this file since 127 was 127, checked in by jbarnold, 17 years ago
old copies of locker software
  • Property svn:executable set to *
File size: 1.4 KB
RevLine 
[127]1#!/usr/bin/perl
2use strict;
3
4my ($op, $username) = @ARGV;
5
6if(defined $op and $op eq "reset") {
7        system("rm -f .htaccess .htpasswd");
8    print "\nDone.  All access restrictions removed.\n\n";
9        exit(0);
10}
11
12if(!defined $op or !defined $username or
13        ($op ne "allow" and $op ne "remove")) {
14        print "Usage: webaccess [allow username] [remove username] [reset]\n";
15        exit(0);
16}
17
18if($op eq "allow" or $op eq "remove") {
19        open(HTPASSWD, ".htpasswd");
20        open(TMP, ">.htpasswd_tmp");
21        while(my $line = <HTPASSWD>) {
22                print TMP "$line" unless($line =~ /$username\:/);
23        }
24        close(TMP);
25        close(HTPASSWD);
26        system("mv .htpasswd_tmp .htpasswd");
27}
28
29if($op eq "allow") {
30        my $password;
31        print "Enter new password for $username: ";
32        system("stty -echo");
33        chop($password = <STDIN>);
34        system("stty echo");
35        print "\n";
36
37        open(HTACCESS, ">.htaccess");
38        print HTACCESS <<ENDFILE;
39AuthUserFile $ENV{PWD}/.htpasswd
40AuthName Private
41AuthType Basic
42<Limit GET>
43require valid-user
44</Limit>
45ENDFILE
46        close(HTACCESS);
47        chmod(0777, ".htaccess");
48
49        my $salt = substr($username, 0, 2);
50        $password = crypt($password, $salt);
51
52        open(HTPASSWD, ">>.htpasswd");
53        print HTPASSWD "$username\:$password\n";
54        close(HTPASSWD);
55        chmod(0777, ".htpasswd");
56}
57
58print "\nDone.  New list of valid usernames:\n";
59open(HTPASSWD, ".htpasswd");
60while(my $line = <HTPASSWD>) {
61        $line =~ /(.*):/;
62        print "$1\n";
63}
64close(HTPASSWD);
65print "\n";
Note: See TracBrowser for help on using the repository browser.