fix 'Can't call method "setup" on an undefined value' error when using into rates...
[freeside.git] / FS / bin / freeside-adduser
index 8f9d4a3..5304813 100644 (file)
@@ -5,7 +5,7 @@ use vars qw($opt_s $opt_g $opt_n);
 use Fcntl qw(:flock);
 use Getopt::Std;
 
-my $FREESIDE_CONF = "/usr/local/etc/freeside";
+my $FREESIDE_CONF = "%%%FREESIDE_CONF%%%";
 
 getopts("s:g:n");
 my $user = shift or die &usage;
@@ -22,11 +22,22 @@ if ( $opt_s ) {
   #  close MAPSECRETS;
   #}
 
-  open(MAPSECRETS,">>$FREESIDE_CONF/mapsecrets")
+  #insert new entry before a wildcard...
+  open(MAPSECRETS,"<$FREESIDE_CONF/mapsecrets")
     and flock(MAPSECRETS,LOCK_EX)
       or die "can't open $FREESIDE_CONF/mapsecrets: $!";
-  print MAPSECRETS "$user $opt_s\n";
+  open(NEW,">$FREESIDE_CONF/mapsecrets.new")
+    or die "can't open $FREESIDE_CONF/mapsecrets.new: $!";
+  while(<MAPSECRETS>) {
+    if ( /^\*\s/ ) {
+      print NEW "$user $opt_s\n";
+    }
+    print NEW $_;
+  }
   close MAPSECRETS or die "can't close $FREESIDE_CONF/mapsecrets: $!";
+  close NEW or die "can't close $FREESIDE_CONF/mapsecrets.new: $!";
+  rename("$FREESIDE_CONF/mapsecrets.new", "$FREESIDE_CONF/mapsecrets")
+    or die "can't move mapsecrets.new into place: $!";
 
 }
 
@@ -97,7 +108,7 @@ B<Configuration | Employees | View/Edit employees>.
 
 =head1 NOTE
 
-No explicit htpasswd options are available in 1.7 - passwordsa are now
+No explicit htpasswd options are available in 1.7 - passwords are now
 maintained automatically.
 
 =head1 SEE ALSO