get rid of all the htpasswd stuff in freeside-adduser
[freeside.git] / FS / bin / freeside-adduser
1 #!/usr/bin/perl -w
2
3 use strict;
4 use vars qw($opt_s $opt_g $opt_n);
5 use Fcntl qw(:flock);
6 use Getopt::Std;
7
8 my $FREESIDE_CONF = "/usr/local/etc/freeside";
9
10 getopts("s:g:n");
11 my $user = shift or die &usage;
12
13 if ( $opt_s ) {
14
15   #if ( -e "$FREESIDE_CONF/mapsecrets" ) {
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;
21   #  }
22   #  close MAPSECRETS;
23   #}
24
25   open(MAPSECRETS,">>$FREESIDE_CONF/mapsecrets")
26     and flock(MAPSECRETS,LOCK_EX)
27       or die "can't open $FREESIDE_CONF/mapsecrets: $!";
28   print MAPSECRETS "$user $opt_s\n";
29   close MAPSECRETS or die "can't close $FREESIDE_CONF/mapsecrets: $!";
30
31 }
32
33 ###
34
35 exit if $opt_n;
36
37 ###
38
39 use FS::UID qw(adminsuidsetup);
40 use FS::CurrentUser;
41 use FS::access_user;
42 use FS::access_usergroup;
43
44 $FS::CurrentUser::upgrade_hack = 1;
45 #adminsuidsetup $rootuser;
46 adminsuidsetup $user;
47
48 my $access_user = new FS::access_user {
49   'username'  => $user,
50   '_password' => 'notyet',
51   'first'     => 'Firstname', # $opt_f || 
52   'last'      => 'Lastname',  # $opt_l || 
53 };
54 my $au_error = $access_user->insert;
55 die $au_error if $au_error;
56
57 if ( $opt_g ) {
58
59   my $access_usergroup = new FS::access_usergroup {
60     'usernum'  => $access_user->usernum,
61     'groupnum' => $opt_g,
62   };
63   my $aug_error = $access_usergroup->insert;
64   die $aug_error if $aug_error;
65
66 }
67
68 ###
69
70 sub usage {
71   die "Usage:\n\n  freeside-adduser [ -n ] [ -s ] [ -g groupnum ] username [ password ]"
72 }
73
74 =head1 NAME
75
76 freeside-adduser - Command line interface to add (freeside) users.
77
78 =head1 SYNOPSIS
79
80   freeside-adduser [ -n ] [ -s ] [ -g groupnum ] username [ password ]
81
82 =head1 DESCRIPTION
83
84 Adds a user to the Freeside billing system.  This is for adding users (internal
85 sales/tech folks) to the web interface, not for adding customer accounts.
86
87 This functionality is now available in the web interface as well, under
88 B<Configuration | Employees | View/Edit employees>.
89
90   -g: initial groupnum
91
92   Development/multi-DB options:
93
94   -s: alternate secrets file
95
96   -n: no ACL added, for bootstrapping
97
98 =head1 NOTE
99
100 No explicit htpasswd options are available in 1.7 - passwordsa are now
101 maintained automatically.
102
103 =head1 SEE ALSO
104
105 Base Freeside documentation
106
107 =cut
108