3 # $Id: freeside-adduser,v 1.9 2006-04-09 20:36:06 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 open(MAPSECRETS,"<$FREESIDE_CONF/mapsecrets")
17 or die "can't open $FREESIDE_CONF/mapsecrets: $!";
18 while (<MAPSECRETS>) {
19 /^(\S+) / or die "unparsable line in mapsecrets: $_";
20 die "user $user already exists\n" if $user eq $1;
25 my @args = ( 'htpasswd' );
26 push @args, '-b' if $opt_b;
27 push @args, '-c' if $opt_c;
28 push @args, $opt_h, $user;
29 push @args, shift if $opt_b;
30 system(@args) == 0 or die "htpasswd failed: $?";
33 my $secretfile = $opt_s || 'secrets';
35 open(MAPSECRETS,">>$FREESIDE_CONF/mapsecrets")
36 and flock(MAPSECRETS,LOCK_EX)
37 or die "can't open $FREESIDE_CONF/mapsecrets: $!";
38 print MAPSECRETS "$user $secretfile\n";
39 close MAPSECRETS or die "can't close $FREESIDE_CONF/mapsecrets: $!";
42 die "Usage:\n\n freeside-adduser [ -h htpasswd_file [ -c ] [ -b ] ] [ -s secretfile ] username"
47 freeside-adduser - Command line interface to add (freeside) users.
51 freeside-adduser [ -h htpasswd_file [ -c ] ] [ -s secretfile ] username
55 Adds a user to the Freeside billing system. This is for adding users (internal
56 sales/tech folks) to the web interface, not for adding customer accounts.
58 -h: Also call htpasswd for this user with the given filename
60 -c: Passed to htpasswd(1)
62 -s: Specify an alternate secret file
64 -b: same as htpasswd(1), probably insecure, not recommended
68 L<htpasswd>(1), base Freeside documentation