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