recommend HTML::Mason
[freeside.git] / FS / bin / freeside-adduser
1 #!/usr/bin/perl -w
2 #
3 # $Id: freeside-adduser,v 1.8 2002-09-27 05:36:29 ivan Exp $
4
5 use strict;
6 use vars qw($opt_h $opt_b $opt_c $opt_s);
7 use Fcntl qw(:flock);
8 use Getopt::Std;
9
10 my $FREESIDE_CONF = "/usr/local/etc/freeside";
11
12 getopts("bch:s:");
13 die &usage if $opt_c && ! $opt_h;
14 my $user = shift or die &usage;
15
16 if ( $opt_h ) {
17   my @args = ( 'htpasswd' );
18   push @args, '-b' if $opt_b;
19   push @args, '-c' if $opt_c;
20   push @args, $opt_h, $user;
21   push @args, shift if $opt_b;
22   system(@args) == 0 or die "htpasswd failed: $?";
23 }
24
25 my $secretfile = $opt_s || 'secrets';
26
27 open(MAPSECRETS,">>$FREESIDE_CONF/mapsecrets")
28   and flock(MAPSECRETS,LOCK_EX)
29     or die "can't open $FREESIDE_CONF/mapsecrets: $!";
30 print MAPSECRETS "$user $secretfile\n";
31 close MAPSECRETS or die "can't close $FREESIDE_CONF/mapsecrets: $!";
32
33 sub usage {
34   die "Usage:\n\n  freeside-adduser [ -h htpasswd_file [ -c ] [ -b ] ] [ -s secretfile ] username"
35 }
36
37 =head1 NAME
38
39 freeside-adduser - Command line interface to add (freeside) users.
40
41 =head1 SYNOPSIS
42
43   freeside-adduser [ -h htpasswd_file [ -c ] ] [ -s secretfile ] username
44
45 =head1 DESCRIPTION
46
47 Adds a user to the Freeside billing system.  This is for adding users (internal
48 sales/tech folks) to the web interface, not for adding customer accounts.
49
50   -h: Also call htpasswd for this user with the given filename
51
52   -c: Passed to htpasswd(1)
53
54   -s: Specify an alternate secret file
55
56   -b: same as htpasswd(1), probably insecure, not recommended
57
58 =head1 SEE ALSO
59
60 L<htpasswd>(1), base Freeside documentation
61
62 =cut
63