on-demand vs. automatic cards & checks: added DCRD and DCHK payment types
[freeside.git] / FS / bin / freeside-deluser
1 #!/usr/bin/perl -w
2
3 use strict;
4 use vars qw($opt_h);
5 use Fcntl qw(:flock);
6 use Getopt::Std;
7
8 my $FREESIDE_CONF = "/usr/local/etc/freeside";
9
10 getopts("h:");
11 my $user = shift or die &usage;
12
13 if ( $opt_h ) {
14   open(HTPASSWD,"<$opt_h")
15     and flock(HTPASSWD,LOCK_EX)
16       or die "can't open $opt_h: $!";
17   open(HTPASSWD_TMP,">$opt_h.tmp") or die "can't open $opt_h.tmp: $!";
18   while (<HTPASSWD>) {
19     print HTPASSWD_TMP $_ unless /^$user:/;
20   }
21   close HTPASSWD_TMP;
22   rename "$opt_h.tmp", "$opt_h" or die $!;
23   flock(HTPASSWD,LOCK_UN);
24   close HTPASSWD;
25 }
26
27 open(MAPSECRETS,"<$FREESIDE_CONF/mapsecrets")
28   and flock(MAPSECRETS,LOCK_EX)
29     or die "can't open $FREESIDE_CONF/mapsecrets: $!";
30 open(MAPSECRETS_TMP,">>$FREESIDE_CONF/mapsecrets.tmp")
31   or die "can't open $FREESIDE_CONF/mapsecrets.tmp: $!";
32 while (<MAPSECRETS>) {
33   print MAPSECRETS_TMP $_ unless /^$user\s/;
34 }
35 close MAPSECRETS_TMP;
36 rename "$FREESIDE_CONF/mapsecrets.tmp", "$FREESIDE_CONF/mapsecrets" or die $!;
37 flock(MAPSECRETS,LOCK_UN);
38 close MAPSECRETS;
39
40 sub usage {
41   die "Usage:\n\n  freeside-deluser [ -h htpasswd_file ] username"
42 }
43
44 =head1 NAME
45
46 freeside-deluser - Command line interface to add (freeside) users.
47
48 =head1 SYNOPSIS
49
50   freeside-deluser [ -h htpasswd_file ] username
51
52 =head1 DESCRIPTION
53
54 Adds a user to the Freeside billing system.  This is for adding users (internal
55 sales/tech folks) to the web interface, not for adding customer accounts.
56
57   -h: Also delete from the given htpasswd filename
58
59 =head1 SEE ALSO
60
61 L<freeside-adduser>, L<htpasswd>(1), base Freeside documentation
62
63 =cut
64