3 # $Id: freeside-adduser,v 1.10 2006-04-13 21:29:01 ivan Exp $
6 use vars qw($opt_h $opt_b $opt_c $opt_s);
10 my $FREESIDE_CONF = "/usr/local/etc/freeside";
13 die &usage if $opt_c && ! $opt_h;
14 my $user = shift or die &usage;
16 if ( -e "$FREESIDE_CONF/mapsecrets" ) {
17 open(MAPSECRETS,"<$FREESIDE_CONF/mapsecrets")
18 or die "can't open $FREESIDE_CONF/mapsecrets: $!";
19 while (<MAPSECRETS>) {
20 /^(\S+) / or die "unparsable line in mapsecrets: $_";
21 die "user $user already exists\n" if $user eq $1;
27 my @args = ( 'htpasswd' );
28 push @args, '-b' if $opt_b;
29 push @args, '-c' if $opt_c;
30 push @args, $opt_h, $user;
31 push @args, shift if $opt_b;
32 system(@args) == 0 or die "htpasswd failed: $?";
35 my $secretfile = $opt_s || 'secrets';
37 open(MAPSECRETS,">>$FREESIDE_CONF/mapsecrets")
38 and flock(MAPSECRETS,LOCK_EX)
39 or die "can't open $FREESIDE_CONF/mapsecrets: $!";
40 print MAPSECRETS "$user $secretfile\n";
41 close MAPSECRETS or die "can't close $FREESIDE_CONF/mapsecrets: $!";
44 die "Usage:\n\n freeside-adduser [ -h htpasswd_file [ -c ] [ -b ] ] [ -s secretfile ] username"
49 freeside-adduser - Command line interface to add (freeside) users.
53 freeside-adduser [ -h htpasswd_file [ -c ] ] [ -s secretfile ] username
57 Adds a user to the Freeside billing system. This is for adding users (internal
58 sales/tech folks) to the web interface, not for adding customer accounts.
60 -h: Also call htpasswd for this user with the given filename
62 -c: Passed to htpasswd(1)
64 -s: Specify an alternate secret file
66 -b: same as htpasswd(1), probably insecure, not recommended
70 L<htpasswd>(1), base Freeside documentation