refactor freeside-init-config to module code, compare results of old/new code, have...
[freeside.git] / FS / FS / Conf.pm
1 package FS::Conf;
2
3 use vars qw($base_dir @config_items @base_items @card_types $DEBUG);
4 use IO::File;
5 use File::Basename;
6 use MIME::Base64;
7 use FS::ConfItem;
8 use FS::ConfDefaults;
9 use FS::Conf_compat17;
10 use FS::conf;
11 use FS::Record qw(qsearch qsearchs);
12 use FS::UID qw(dbh datasrc use_confcompat);
13
14 $base_dir = '%%%FREESIDE_CONF%%%';
15
16 $DEBUG = 0;
17
18 =head1 NAME
19
20 FS::Conf - Freeside configuration values
21
22 =head1 SYNOPSIS
23
24   use FS::Conf;
25
26   $conf = new FS::Conf;
27
28   $value = $conf->config('key');
29   @list  = $conf->config('key');
30   $bool  = $conf->exists('key');
31
32   $conf->touch('key');
33   $conf->set('key' => 'value');
34   $conf->delete('key');
35
36   @config_items = $conf->config_items;
37
38 =head1 DESCRIPTION
39
40 Read and write Freeside configuration values.  Keys currently map to filenames,
41 but this may change in the future.
42
43 =head1 METHODS
44
45 =over 4
46
47 =item new
48
49 Create a new configuration object.
50
51 =cut
52
53 sub new {
54   my($proto) = @_;
55   my($class) = ref($proto) || $proto;
56   my($self) = { 'base_dir' => $base_dir };
57   bless ($self, $class);
58 }
59
60 =item base_dir
61
62 Returns the base directory.  By default this is /usr/local/etc/freeside.
63
64 =cut
65
66 sub base_dir {
67   my($self) = @_;
68   my $base_dir = $self->{base_dir};
69   -e $base_dir or die "FATAL: $base_dir doesn't exist!";
70   -d $base_dir or die "FATAL: $base_dir isn't a directory!";
71   -r $base_dir or die "FATAL: Can't read $base_dir!";
72   -x $base_dir or die "FATAL: $base_dir not searchable (executable)!";
73   $base_dir =~ /^(.*)$/;
74   $1;
75 }
76
77 =item config KEY
78
79 Returns the configuration value or values (depending on context) for key.
80
81 =cut
82
83 sub _usecompat {
84   my ($self, $method) = (shift, shift);
85   warn "NO CONFIGURATION RECORDS FOUND -- USING COMPATIBILITY MODE"
86     if use_confcompat;
87   my $compat = new FS::Conf_compat17 ("$base_dir/conf." . datasrc);
88   $compat->$method(@_);
89 }
90
91 sub _config {
92   my($self,$name,$agent)=@_;
93   my $hashref = { 'name' => $name };
94   if (defined($agent) && $agent) {
95     $hashref->{agent} = $agent;
96   }
97   local $FS::Record::conf = undef;  # XXX evil hack prevents recursion
98   my $cv = FS::Record::qsearchs('conf', $hashref);
99   if (!$cv && exists($hashref->{agent})) {
100     delete($hashref->{agent});
101     $cv = FS::Record::qsearchs('conf', $hashref);
102   }
103   return $cv;
104 }
105
106 sub config {
107   my $self = shift;
108   return $self->_usecompat('config', @_) if use_confcompat;
109
110   my($name,$agent)=@_;
111   my $cv = $self->_config($name, $agent) or return;
112
113   if ( wantarray ) {
114     my $v = $cv->value;
115     chomp $v;
116     (split "\n", $v, -1);
117   } else {
118     (split("\n", $cv->value))[0];
119   }
120 }
121
122 =item config_binary KEY
123
124 Returns the exact scalar value for key.
125
126 =cut
127
128 sub config_binary {
129   my $self = shift;
130   return $self->_usecompat('config_binary', @_) if use_confcompat;
131
132   my($name,$agent)=@_;
133   my $cv = $self->_config($name, $agent) or return;
134   decode_base64($cv->value);
135 }
136
137 =item exists KEY
138
139 Returns true if the specified key exists, even if the corresponding value
140 is undefined.
141
142 =cut
143
144 sub exists {
145   my $self = shift;
146   return $self->_usecompat('exists', @_) if use_confcompat;
147
148   my($name,$agent)=@_;
149   defined($self->_config($name, $agent));
150 }
151
152 =item config_orbase KEY SUFFIX
153
154 Returns the configuration value or values (depending on context) for 
155 KEY_SUFFIX, if it exists, otherwise for KEY
156
157 =cut
158
159 sub config_orbase {
160   my $self = shift;
161   return $self->_usecompat('config_orbase', @_) if use_confcompat;
162
163   my( $name, $suffix ) = @_;
164   if ( $self->exists("${name}_$suffix") ) {
165     $self->config("${name}_$suffix");
166   } else {
167     $self->config($name);
168   }
169 }
170
171 =item touch KEY
172
173 Creates the specified configuration key if it does not exist.
174
175 =cut
176
177 sub touch {
178   my $self = shift;
179   return $self->_usecompat('touch', @_) if use_confcompat;
180
181   my($name, $agent) = @_;
182   $self->set($name, '', $agent);
183 }
184
185 =item set KEY VALUE
186
187 Sets the specified configuration key to the given value.
188
189 =cut
190
191 sub set {
192   my $self = shift;
193   return $self->_usecompat('set', @_) if use_confcompat;
194
195   my($name, $value, $agent) = @_;
196   $value =~ /^(.*)$/s;
197   $value = $1;
198
199   warn "[FS::Conf] SET $name\n" if $DEBUG;
200
201   my $old = FS::Record::qsearchs('conf', {name => $name, agent => $agent});
202   my $new = new FS::conf { $old ? $old->hash 
203                                 : ('name' => $name, 'agent' => $agent)
204                          };
205   $new->value($value);
206
207   my $error;
208   if ($old) {
209     $error = $new->replace($old);
210   } else {
211     $error = $new->insert;
212   }
213
214   die "error setting configuration value: $error \n"
215     if $error;
216
217 }
218
219 =item set_binary KEY VALUE
220
221 Sets the specified configuration key to an exact scalar value which
222 can be retrieved with config_binary.
223
224 =cut
225
226 sub set_binary {
227   my $self  = shift;
228   return if use_confcompat;
229
230   my($name, $value, $agent)=@_;
231   $self->set($name, encode_base64($value), $agent);
232 }
233
234 =item delete KEY
235
236 Deletes the specified configuration key.
237
238 =cut
239
240 sub delete {
241   my $self = shift;
242   return $self->_usecompat('delete', @_) if use_confcompat;
243
244   my($name, $agent) = @_;
245   if ( my $cv = FS::Record::qsearchs('conf', {name => $name, agent => $agent}) ) {
246     warn "[FS::Conf] DELETE $file\n";
247
248     my $oldAutoCommit = $FS::UID::AutoCommit;
249     local $FS::UID::AutoCommit = 0;
250     my $dbh = dbh;
251
252     my $error = $cv->delete;
253
254     if ( $error ) {
255       $dbh->rollback if $oldAutoCommit;
256       die "error setting configuration value: $error \n"
257     }
258
259     $dbh->commit or die $dbh->errstr if $oldAutoCommit;
260
261   }
262 }
263
264 =item import_config_item CONFITEM DIR 
265
266   Imports the item specified by the CONFITEM (see L<FS::ConfItem>) into
267 the database as a conf record (see L<FS::conf>).  Imports from the file
268 in the directory DIR.
269
270 =cut
271
272 sub import_config_item { 
273   my ($self,$item,$dir) = @_;
274   my $key = $item->key;
275   if ( -e "$dir/$key" && ! use_confcompat ) {
276     warn "Inserting $key\n" if $DEBUG;
277     local $/;
278     my $value = readline(new IO::File "$dir/$key");
279     if ($item->type eq 'binary') {
280       $self->set_binary($key, $value);
281     }else{
282       $self->set($key, $value);
283     }
284   }else {
285     warn "Not inserting $key\n" if $DEBUG;
286   }
287 }
288
289 =item verify_config_item CONFITEM DIR 
290
291   Compares the item specified by the CONFITEM (see L<FS::ConfItem>) in
292 the database to the legacy file value in DIR.
293
294 =cut
295
296 sub verify_config_item { 
297   return '' if use_confcompat;
298   my ($self,$item,$dir) = @_;
299   my $key = $item->key;
300   my $type = $item->type;
301
302   my $compat = new FS::Conf_compat17 $dir;
303   my $error = '';
304   
305   $error .= "$key fails existential comparison; "
306     if $self->exists($key) xor $compat->exists($key);
307
308   unless ($type eq 'binary') {
309     {
310       no warnings;
311       $error .= "$key fails scalar comparison; "
312         unless scalar($self->config($key)) eq scalar($compat->config($key));
313     }
314
315     my (@new) = $self->config($key);
316     my (@old) = $compat->config($key);
317     unless ( scalar(@new) == scalar(@old)) { 
318       $error .= "$key fails list comparison; ";
319     }else{
320       my $r=1;
321       foreach (@old) { $r=0 if ($_ cmp shift(@new)); }
322       $error .= "$key fails list comparison; "
323         unless $r;
324     }
325   }
326
327   if ($type eq 'binary') {
328     $error .= "$key fails binary comparison; "
329       unless scalar($self->config_binary($key)) eq scalar($compat->config_binary($key));
330   }
331
332   if ($error =~ /existential comparison/ && $item->section eq 'deprecated') {
333     my $proto;
334     for ( @config_items ) { $proto = $_; last if $proto->key eq $key;  }
335     unless ($proto->key eq $key) { 
336       warn "removed config item $error\n" if $DEBUG;
337       $error = '';
338     }
339   }
340
341   $error;
342 }
343
344 #item _orbase_items OPTIONS
345 #
346 #Returns all of the possible extensible config items as FS::ConfItem objects.
347 #See #L<FS::ConfItem>.  OPTIONS consists of name value pairs.  Possible
348 #options include
349 #
350 # dir - the directory to search for configuration option files instead
351 #       of using the conf records in the database
352 #
353 #cut
354
355 #quelle kludge
356 sub _orbase_items {
357   my ($self, %opt) = @_; 
358
359   my $listmaker = sub { my $v = shift;
360                         $v =~ s/_/!_/g;
361                         if ( $v =~ /\.(png|eps)$/ ) {
362                           $v =~ s/\./!_%./;
363                         }else{
364                           $v .= '!_%';
365                         }
366                         map { $_->name }
367                           FS::Record::qsearch( 'conf',
368                                                {},
369                                                '',
370                                                "WHERE name LIKE '$v' ESCAPE '!'"
371                                              );
372                       };
373
374   if (exists($opt{dir}) && $opt{dir}) {
375     $listmaker = sub { my $v = shift;
376                        if ( $v =~ /\.(png|eps)$/ ) {
377                          $v =~ s/\./_*./;
378                        }else{
379                          $v .= '_*';
380                        }
381                        map { basename $_ } glob($opt{dir}. "/$v" );
382                      };
383   }
384
385   ( map { 
386           my $proto;
387           my $base = $_;
388           for ( @config_items ) { $proto = $_; last if $proto->key eq $base;  }
389           die "don't know about $base items" unless $proto->key eq $base;
390
391           map { new FS::ConfItem { 
392                                    'key' => $_,
393                                    'section' => $proto->section,
394                                    'description' => 'Alternate ' . $proto->description . '  See the <a href="../docs/billing.html">billing documentation</a> for details.',
395                                    'type' => $proto->type,
396                                  };
397               } &$listmaker($base);
398         } @base_items,
399   );
400 }
401
402 =item config_items
403
404 Returns all of the possible global/default configuration items as
405 FS::ConfItem objects.  See L<FS::ConfItem>.
406
407 =cut
408
409 sub config_items {
410   my $self = shift; 
411   return $self->_usecompat('config_items', @_) if use_confcompat;
412
413   ( @config_items, $self->_orbase_items(@_) );
414 }
415
416 =back
417
418 =head1 SUBROUTINES
419
420 =over 4
421
422 =item init-config DIR
423
424 Imports the non-deprecated configuration items from DIR (1.7 compatible)
425 to conf records in the database.
426
427 =cut
428
429 sub init_config {
430   my $dir = shift;
431
432   {
433     local $FS::UID::use_confcompat = 0;
434     my $conf = new FS::Conf;
435     foreach my $item ( $conf->config_items(dir => $dir) ) {
436       $conf->import_config_item($item, $dir);
437       my $error = $conf->verify_config_item($item, $dir);
438       return $error if $error;
439     }
440   
441     my $compat = new FS::Conf_compat17 $dir;
442     foreach my $item ( $compat->config_items ) {
443       my $error = $conf->verify_config_item($item, $dir);
444       return $error if $error;
445     }
446   }
447
448   $FS::UID::use_confcompat = 0;
449   '';  #success
450 }
451
452 =back
453
454 =head1 BUGS
455
456 If this was more than just crud that will never be useful outside Freeside I'd
457 worry that config_items is freeside-specific and icky.
458
459 =head1 SEE ALSO
460
461 "Configuration" in the web interface (config/config.cgi).
462
463 httemplate/docs/config.html
464
465 =cut
466
467 #Business::CreditCard
468 @card_types = (
469   "VISA card",
470   "MasterCard",
471   "Discover card",
472   "American Express card",
473   "Diner's Club/Carte Blanche",
474   "enRoute",
475   "JCB",
476   "BankCard",
477   "Switch",
478   "Solo",
479 );
480
481 @base_items = qw (
482                    invoice_template
483                    invoice_latex
484                    invoice_latexreturnaddress
485                    invoice_latexfooter
486                    invoice_latexsmallfooter
487                    invoice_latexnotes
488                    invoice_html
489                    invoice_htmlreturnaddress
490                    invoice_htmlfooter
491                    invoice_htmlnotes
492                    logo.png
493                    logo.eps
494                  );
495
496 @config_items = map { new FS::ConfItem $_ } (
497
498   {
499     'key'         => 'address',
500     'section'     => 'deprecated',
501     'description' => 'This configuration option is no longer used.  See <a href="#invoice_template">invoice_template</a> instead.',
502     'type'        => 'text',
503   },
504
505   {
506     'key'         => 'alerter_template',
507     'section'     => 'billing',
508     'description' => 'Template file for billing method expiration alerts.  See the <a href="../docs/billing.html#invoice_template">billing documentation</a> for details.',
509     'type'        => 'textarea',
510   },
511
512   {
513     'key'         => 'apacheip',
514     'section'     => 'deprecated',
515     'description' => '<b>DEPRECATED</b>, add an <i>apache</i> <a href="../browse/part_export.cgi">export</a> instead.  Used to be the current IP address to assign to new virtual hosts',
516     'type'        => 'text',
517   },
518
519   {
520     'key'         => 'encryption',
521     'section'     => 'billing',
522     'description' => 'Enable encryption of credit cards.',
523     'type'        => 'checkbox',
524   },
525
526   {
527     'key'         => 'encryptionmodule',
528     'section'     => 'billing',
529     'description' => 'Use which module for encryption?',
530     'type'        => 'text',
531   },
532
533   {
534     'key'         => 'encryptionpublickey',
535     'section'     => 'billing',
536     'description' => 'Your RSA Public Key - Required if Encryption is turned on.',
537     'type'        => 'textarea',
538   },
539
540   {
541     'key'         => 'encryptionprivatekey',
542     'section'     => 'billing',
543     'description' => 'Your RSA Private Key - Including this will enable the "Bill Now" feature.  However if the system is compromised, a hacker can use this key to decode the stored credit card information.  This is generally not a good idea.',
544     'type'        => 'textarea',
545   },
546
547   {
548     'key'         => 'business-onlinepayment',
549     'section'     => 'billing',
550     'description' => '<a href="http://search.cpan.org/search?mode=module&query=Business%3A%3AOnlinePayment">Business::OnlinePayment</a> support, at least three lines: processor, login, and password.  An optional fourth line specifies the action or actions (multiple actions are separated with `,\': for example: `Authorization Only, Post Authorization\').    Optional additional lines are passed to Business::OnlinePayment as %processor_options.',
551     'type'        => 'textarea',
552   },
553
554   {
555     'key'         => 'business-onlinepayment-ach',
556     'section'     => 'billing',
557     'description' => 'Alternate <a href="http://search.cpan.org/search?mode=module&query=Business%3A%3AOnlinePayment">Business::OnlinePayment</a> support for ACH transactions (defaults to regular <b>business-onlinepayment</b>).  At least three lines: processor, login, and password.  An optional fourth line specifies the action or actions (multiple actions are separated with `,\': for example: `Authorization Only, Post Authorization\').    Optional additional lines are passed to Business::OnlinePayment as %processor_options.',
558     'type'        => 'textarea',
559   },
560
561   {
562     'key'         => 'business-onlinepayment-description',
563     'section'     => 'billing',
564     'description' => 'String passed as the description field to <a href="http://search.cpan.org/search?mode=module&query=Business%3A%3AOnlinePayment">Business::OnlinePayment</a>.  Evaluated as a double-quoted perl string, with the following variables available: <code>$agent</code> (the agent name), and <code>$pkgs</code> (a comma-separated list of packages for which these charges apply)',
565     'type'        => 'text',
566   },
567
568   {
569     'key'         => 'business-onlinepayment-email-override',
570     'section'     => 'billing',
571     'description' => 'Email address used instead of customer email address when submitting a BOP transaction.',
572     'type'        => 'text',
573   },
574
575   {
576     'key'         => 'countrydefault',
577     'section'     => 'UI',
578     'description' => 'Default two-letter country code (if not supplied, the default is `US\')',
579     'type'        => 'text',
580   },
581
582   {
583     'key'         => 'date_format',
584     'section'     => 'UI',
585     'description' => 'Format for displaying dates',
586     'type'        => 'select',
587     'select_hash' => [
588                        '%m/%d/%Y' => 'MM/DD/YYYY',
589                        '%Y/%m/%d' => 'YYYY/MM/DD',
590                      ],
591   },
592
593   {
594     'key'         => 'deletecustomers',
595     'section'     => 'UI',
596     'description' => 'Enable customer deletions.  Be very careful!  Deleting a customer will remove all traces that this customer ever existed!  It should probably only be used when auditing a legacy database.  Normally, you cancel all of a customers\' packages if they cancel service.',
597     'type'        => 'checkbox',
598   },
599
600   {
601     'key'         => 'deletepayments',
602     'section'     => 'billing',
603     'description' => 'Enable deletion of unclosed payments.  Really, with voids this is pretty much not recommended in any situation anymore.  Be very careful!  Only delete payments that were data-entry errors, not adjustments.  Optionally specify one or more comma-separated email addresses to be notified when a payment is deleted.',
604     'type'        => [qw( checkbox text )],
605   },
606
607   {
608     'key'         => 'deletecredits',
609     'section'     => 'deprecated',
610     'description' => '<B>DEPRECATED</B>, now controlled by ACLs.  Used to enable deletion of unclosed credits.  Be very careful!  Only delete credits that were data-entry errors, not adjustments.  Optionally specify one or more comma-separated email addresses to be notified when a credit is deleted.',
611     'type'        => [qw( checkbox text )],
612   },
613
614   {
615     'key'         => 'deleterefunds',
616     'section'     => 'billing',
617     'description' => 'Enable deletion of unclosed refunds.  Be very careful!  Only delete refunds that were data-entry errors, not adjustments.',
618     'type'        => 'checkbox',
619   },
620
621   {
622     'key'         => 'dirhash',
623     'section'     => 'shell',
624     'description' => 'Optional numeric value to control directory hashing.  If positive, hashes directories for the specified number of levels from the front of the username.  If negative, hashes directories for the specified number of levels from the end of the username.  Some examples: <ul><li>1: user -> <a href="#home">/home</a>/u/user<li>2: user -> <a href="#home">/home</a>/u/s/user<li>-1: user -> <a href="#home">/home</a>/r/user<li>-2: user -> <a href="#home">home</a>/r/e/user</ul>',
625     'type'        => 'text',
626   },
627
628   {
629     'key'         => 'disable_customer_referrals',
630     'section'     => 'UI',
631     'description' => 'Disable new customer-to-customer referrals in the web interface',
632     'type'        => 'checkbox',
633   },
634
635   {
636     'key'         => 'editreferrals',
637     'section'     => 'UI',
638     'description' => 'Enable advertising source modification for existing customers',
639     'type'       => 'checkbox',
640   },
641
642   {
643     'key'         => 'emailinvoiceonly',
644     'section'     => 'billing',
645     'description' => 'Disables postal mail invoices',
646     'type'       => 'checkbox',
647   },
648
649   {
650     'key'         => 'disablepostalinvoicedefault',
651     'section'     => 'billing',
652     'description' => 'Disables postal mail invoices as the default option in the UI.  Be careful not to setup customers which are not sent invoices.  See <a href ="#emailinvoiceauto">emailinvoiceauto</a>.',
653     'type'       => 'checkbox',
654   },
655
656   {
657     'key'         => 'emailinvoiceauto',
658     'section'     => 'billing',
659     'description' => 'Automatically adds new accounts to the email invoice list',
660     'type'       => 'checkbox',
661   },
662
663   {
664     'key'         => 'emailinvoiceautoalways',
665     'section'     => 'billing',
666     'description' => 'Automatically adds new accounts to the email invoice list even when the list contains email addresses',
667     'type'       => 'checkbox',
668   },
669
670   {
671     'key'         => 'exclude_ip_addr',
672     'section'     => '',
673     'description' => 'Exclude these from the list of available broadband service IP addresses. (One per line)',
674     'type'        => 'textarea',
675   },
676   
677   {
678     'key'         => 'hidecancelledpackages',
679     'section'     => 'UI',
680     'description' => 'Prevent cancelled packages from showing up in listings (though they will still be in the database)',
681     'type'        => 'checkbox',
682   },
683
684   {
685     'key'         => 'hidecancelledcustomers',
686     'section'     => 'UI',
687     'description' => 'Prevent customers with only cancelled packages from showing up in listings (though they will still be in the database)',
688     'type'        => 'checkbox',
689   },
690
691   {
692     'key'         => 'home',
693     'section'     => 'required',
694     'description' => 'For new users, prefixed to username to create a directory name.  Should have a leading but not a trailing slash.',
695     'type'        => 'text',
696   },
697
698   {
699     'key'         => 'invoice_from',
700     'section'     => 'required',
701     'description' => 'Return address on email invoices',
702     'type'        => 'text',
703   },
704
705   {
706     'key'         => 'invoice_template',
707     'section'     => 'required',
708     'description' => 'Required template file for invoices.  See the <a href="../docs/billing.html">billing documentation</a> for details.',
709     'type'        => 'textarea',
710   },
711
712   {
713     'key'         => 'invoice_html',
714     'section'     => 'billing',
715     'description' => 'Optional HTML template for invoices.  See the <a href="../docs/billing.html">billing documentation</a> for details.',
716
717     'type'        => 'textarea',
718   },
719
720   {
721     'key'         => 'invoice_htmlnotes',
722     'section'     => 'billing',
723     'description' => 'Notes section for HTML invoices.  Defaults to the same data in invoice_latexnotes if not specified.',
724     'type'        => 'textarea',
725   },
726
727   {
728     'key'         => 'invoice_htmlfooter',
729     'section'     => 'billing',
730     'description' => 'Footer for HTML invoices.  Defaults to the same data in invoice_latexfooter if not specified.',
731     'type'        => 'textarea',
732   },
733
734   {
735     'key'         => 'invoice_htmlreturnaddress',
736     'section'     => 'billing',
737     'description' => 'Return address for HTML invoices.  Defaults to the same data in invoice_latexreturnaddress if not specified.',
738     'type'        => 'textarea',
739   },
740
741   {
742     'key'         => 'invoice_latex',
743     'section'     => 'billing',
744     'description' => 'Optional LaTeX template for typeset PostScript invoices.  See the <a href="../docs/billing.html">billing documentation</a> for details.',
745     'type'        => 'textarea',
746   },
747
748   {
749     'key'         => 'invoice_latexnotes',
750     'section'     => 'billing',
751     'description' => 'Notes section for LaTeX typeset PostScript invoices.',
752     'type'        => 'textarea',
753   },
754
755   {
756     'key'         => 'invoice_latexfooter',
757     'section'     => 'billing',
758     'description' => 'Footer for LaTeX typeset PostScript invoices.',
759     'type'        => 'textarea',
760   },
761
762   {
763     'key'         => 'invoice_latexreturnaddress',
764     'section'     => 'billing',
765     'description' => 'Return address for LaTeX typeset PostScript invoices.',
766     'type'        => 'textarea',
767   },
768
769   {
770     'key'         => 'invoice_latexsmallfooter',
771     'section'     => 'billing',
772     'description' => 'Optional small footer for multi-page LaTeX typeset PostScript invoices.',
773     'type'        => 'textarea',
774   },
775
776   {
777     'key'         => 'invoice_email_pdf',
778     'section'     => 'billing',
779     'description' => 'Send PDF invoice as an attachment to emailed invoices.  By default, includes the plain text invoice as the email body, unless invoice_email_pdf_note is set.',
780     'type'        => 'checkbox'
781   },
782
783   {
784     'key'         => 'invoice_email_pdf_note',
785     'section'     => 'billing',
786     'description' => 'If defined, this text will replace the default plain text invoice as the body of emailed PDF invoices.',
787     'type'        => 'textarea'
788   },
789
790
791   { 
792     'key'         => 'invoice_default_terms',
793     'section'     => 'billing',
794     'description' => 'Optional default invoice term, used to calculate a due date printed on invoices.',
795     'type'        => 'select',
796     'select_enum' => [ '', 'Payable upon receipt', 'Net 0', 'Net 10', 'Net 15', 'Net 30', 'Net 45', 'Net 60' ],
797   },
798
799   {
800     'key'         => 'payment_receipt_email',
801     'section'     => 'billing',
802     'description' => 'Template file for payment receipts.  Payment receipts are sent to the customer email invoice destination(s) when a payment is received.  See the <a href="http://search.cpan.org/~mjd/Text-Template/lib/Text/Template.pm">Text::Template</a> documentation for details on the template substitution language.  The following variables are available: <ul><li><code>$date</code> <li><code>$name</code> <li><code>$paynum</code> - Freeside payment number <li><code>$paid</code> - Amount of payment <li><code>$payby</code> - Payment type (Card, Check, Electronic check, etc.) <li><code>$payinfo</code> - Masked credit card number or check number <li><code>$balance</code> - New balance</ul>',
803     'type'        => [qw( checkbox textarea )],
804   },
805
806   {
807     'key'         => 'lpr',
808     'section'     => 'required',
809     'description' => 'Print command for paper invoices, for example `lpr -h\'',
810     'type'        => 'text',
811   },
812
813   {
814     'key'         => 'lpr-postscript_prefix',
815     'section'     => 'billing',
816     'description' => 'Raw printer commands prepended to the beginning of postscript print jobs (evaluated as a double-quoted perl string - backslash escapes are available)',
817     'type'        => 'text',
818   },
819
820   {
821     'key'         => 'lpr-postscript_suffix',
822     'section'     => 'billing',
823     'description' => 'Raw printer commands added to the end of postscript print jobs (evaluated as a double-quoted perl string - backslash escapes are available)',
824     'type'        => 'text',
825   },
826
827   {
828     'key'         => 'money_char',
829     'section'     => '',
830     'description' => 'Currency symbol - defaults to `$\'',
831     'type'        => 'text',
832   },
833
834   {
835     'key'         => 'defaultrecords',
836     'section'     => 'BIND',
837     'description' => 'DNS entries to add automatically when creating a domain',
838     'type'        => 'editlist',
839     'editlist_parts' => [ { type=>'text' },
840                           { type=>'immutable', value=>'IN' },
841                           { type=>'select',
842                             select_enum=>{ map { $_=>$_ } qw(A CNAME MX NS TXT)} },
843                           { type=> 'text' }, ],
844   },
845
846   {
847     'key'         => 'passwordmin',
848     'section'     => 'password',
849     'description' => 'Minimum password length (default 6)',
850     'type'        => 'text',
851   },
852
853   {
854     'key'         => 'passwordmax',
855     'section'     => 'password',
856     'description' => 'Maximum password length (default 8) (don\'t set this over 12 if you need to import or export crypt() passwords)',
857     'type'        => 'text',
858   },
859
860   {
861     'key' => 'password-noampersand',
862     'section' => 'password',
863     'description' => 'Disallow ampersands in passwords',
864     'type' => 'checkbox',
865   },
866
867   {
868     'key' => 'password-noexclamation',
869     'section' => 'password',
870     'description' => 'Disallow exclamations in passwords (Not setting this could break old text Livingston or Cistron Radius servers)',
871     'type' => 'checkbox',
872   },
873
874   {
875     'key'         => 'referraldefault',
876     'section'     => 'UI',
877     'description' => 'Default referral, specified by refnum',
878     'type'        => 'text',
879   },
880
881 #  {
882 #    'key'         => 'registries',
883 #    'section'     => 'required',
884 #    'description' => 'Directory which contains domain registry information.  Each registry is a directory.',
885 #  },
886
887   {
888     'key'         => 'maxsearchrecordsperpage',
889     'section'     => 'UI',
890     'description' => 'If set, number of search records to return per page.',
891     'type'        => 'text',
892   },
893
894   {
895     'key'         => 'session-start',
896     'section'     => 'session',
897     'description' => 'If defined, the command which is executed on the Freeside machine when a session begins.  The contents of the file are treated as a double-quoted perl string, with the following variables available: <code>$ip</code>, <code>$nasip</code> and <code>$nasfqdn</code>, which are the IP address of the starting session, and the IP address and fully-qualified domain name of the NAS this session is on.',
898     'type'        => 'text',
899   },
900
901   {
902     'key'         => 'session-stop',
903     'section'     => 'session',
904     'description' => 'If defined, the command which is executed on the Freeside machine when a session ends.  The contents of the file are treated as a double-quoted perl string, with the following variables available: <code>$ip</code>, <code>$nasip</code> and <code>$nasfqdn</code>, which are the IP address of the starting session, and the IP address and fully-qualified domain name of the NAS this session is on.',
905     'type'        => 'text',
906   },
907
908   {
909     'key'         => 'shells',
910     'section'     => 'required',
911     'description' => 'Legal shells (think /etc/shells).  You probably want to `cut -d: -f7 /etc/passwd | sort | uniq\' initially so that importing doesn\'t fail with `Illegal shell\' errors, then remove any special entries afterwords.  A blank line specifies that an empty shell is permitted.',
912     'type'        => 'textarea',
913   },
914
915   {
916     'key'         => 'showpasswords',
917     'section'     => 'UI',
918     'description' => 'Display unencrypted user passwords in the backend (employee) web interface',
919     'type'        => 'checkbox',
920   },
921
922   {
923     'key'         => 'signupurl',
924     'section'     => 'UI',
925     'description' => 'if you are using customer-to-customer referrals, and you enter the URL of your <a href="../docs/signup.html">signup server CGI</a>, the customer view screen will display a customized link to the signup server with the appropriate customer as referral',
926     'type'        => 'text',
927   },
928
929   {
930     'key'         => 'smtpmachine',
931     'section'     => 'required',
932     'description' => 'SMTP relay for Freeside\'s outgoing mail',
933     'type'        => 'text',
934   },
935
936   {
937     'key'         => 'soadefaultttl',
938     'section'     => 'BIND',
939     'description' => 'SOA default TTL for new domains.',
940     'type'        => 'text',
941   },
942
943   {
944     'key'         => 'soaemail',
945     'section'     => 'BIND',
946     'description' => 'SOA email for new domains, in BIND form (`.\' instead of `@\'), with trailing `.\'',
947     'type'        => 'text',
948   },
949
950   {
951     'key'         => 'soaexpire',
952     'section'     => 'BIND',
953     'description' => 'SOA expire for new domains',
954     'type'        => 'text',
955   },
956
957   {
958     'key'         => 'soamachine',
959     'section'     => 'BIND',
960     'description' => 'SOA machine for new domains, with trailing `.\'',
961     'type'        => 'text',
962   },
963
964   {
965     'key'         => 'soarefresh',
966     'section'     => 'BIND',
967     'description' => 'SOA refresh for new domains',
968     'type'        => 'text',
969   },
970
971   {
972     'key'         => 'soaretry',
973     'section'     => 'BIND',
974     'description' => 'SOA retry for new domains',
975     'type'        => 'text',
976   },
977
978   {
979     'key'         => 'statedefault',
980     'section'     => 'UI',
981     'description' => 'Default state or province (if not supplied, the default is `CA\')',
982     'type'        => 'text',
983   },
984
985   {
986     'key'         => 'unsuspendauto',
987     'section'     => 'billing',
988     'description' => 'Enables the automatic unsuspension of suspended packages when a customer\'s balance due changes from positive to zero or negative as the result of a payment or credit',
989     'type'        => 'checkbox',
990   },
991
992   {
993     'key'         => 'unsuspend-always_adjust_next_bill_date',
994     'section'     => 'billing',
995     'description' => 'Global override that causes unsuspensions to always adjust the next bill date under any circumstances.  This is now controlled on a per-package bases - probably best not to use this option unless you are a legacy installation that requires this behaviour.',
996     'type'        => 'checkbox',
997   },
998
999   {
1000     'key'         => 'usernamemin',
1001     'section'     => 'username',
1002     'description' => 'Minimum username length (default 2)',
1003     'type'        => 'text',
1004   },
1005
1006   {
1007     'key'         => 'usernamemax',
1008     'section'     => 'username',
1009     'description' => 'Maximum username length',
1010     'type'        => 'text',
1011   },
1012
1013   {
1014     'key'         => 'username-ampersand',
1015     'section'     => 'username',
1016     'description' => 'Allow the ampersand character (&amp;) in usernames.  Be careful when using this option in conjunction with <a href="../browse/part_export.cgi">exports</a> which execute shell commands, as the ampersand will be interpreted by the shell if not quoted.',
1017     'type'        => 'checkbox',
1018   },
1019
1020   {
1021     'key'         => 'username-letter',
1022     'section'     => 'username',
1023     'description' => 'Usernames must contain at least one letter',
1024     'type'        => 'checkbox',
1025   },
1026
1027   {
1028     'key'         => 'username-letterfirst',
1029     'section'     => 'username',
1030     'description' => 'Usernames must start with a letter',
1031     'type'        => 'checkbox',
1032   },
1033
1034   {
1035     'key'         => 'username-noperiod',
1036     'section'     => 'username',
1037     'description' => 'Disallow periods in usernames',
1038     'type'        => 'checkbox',
1039   },
1040
1041   {
1042     'key'         => 'username-nounderscore',
1043     'section'     => 'username',
1044     'description' => 'Disallow underscores in usernames',
1045     'type'        => 'checkbox',
1046   },
1047
1048   {
1049     'key'         => 'username-nodash',
1050     'section'     => 'username',
1051     'description' => 'Disallow dashes in usernames',
1052     'type'        => 'checkbox',
1053   },
1054
1055   {
1056     'key'         => 'username-uppercase',
1057     'section'     => 'username',
1058     'description' => 'Allow uppercase characters in usernames',
1059     'type'        => 'checkbox',
1060   },
1061
1062   { 
1063     'key'         => 'username-percent',
1064     'section'     => 'username',
1065     'description' => 'Allow the percent character (%) in usernames.',
1066     'type'        => 'checkbox',
1067   },
1068
1069   {
1070     'key'         => 'safe-part_bill_event',
1071     'section'     => 'UI',
1072     'description' => 'Validates invoice event expressions against a preset list.  Useful for webdemos, annoying to powerusers.',
1073     'type'        => 'checkbox',
1074   },
1075
1076   {
1077     'key'         => 'show_ss',
1078     'section'     => 'UI',
1079     'description' => 'Turns on display/collection of social security numbers in the web interface.  Sometimes required by electronic check (ACH) processors.',
1080     'type'        => 'checkbox',
1081   },
1082
1083   {
1084     'key'         => 'show_stateid',
1085     'section'     => 'UI',
1086     'description' => "Turns on display/collection of driver's license/state issued id numbers in the web interface.  Sometimes required by electronic check (ACH) processors.",
1087     'type'        => 'checkbox',
1088   },
1089
1090   {
1091     'key'         => 'show_bankstate',
1092     'section'     => 'UI',
1093     'description' => "Turns on display/collection of state for bank accounts in the web interface.  Sometimes required by electronic check (ACH) processors.",
1094     'type'        => 'checkbox',
1095   },
1096
1097   { 
1098     'key'         => 'agent_defaultpkg',
1099     'section'     => 'UI',
1100     'description' => 'Setting this option will cause new packages to be available to all agent types by default.',
1101     'type'        => 'checkbox',
1102   },
1103
1104   {
1105     'key'         => 'legacy_link',
1106     'section'     => 'UI',
1107     'description' => 'Display options in the web interface to link legacy pre-Freeside services.',
1108     'type'        => 'checkbox',
1109   },
1110
1111   {
1112     'key'         => 'legacy_link-steal',
1113     'section'     => 'UI',
1114     'description' => 'Allow "stealing" an already-audited service from one customer (or package) to another using the link function.',
1115     'type'        => 'checkbox',
1116   },
1117
1118   {
1119     'key'         => 'queue_dangerous_controls',
1120     'section'     => 'UI',
1121     'description' => 'Enable queue modification controls on account pages and for new jobs.  Unless you are a developer working on new export code, you should probably leave this off to avoid causing provisioning problems.',
1122     'type'        => 'checkbox',
1123   },
1124
1125   {
1126     'key'         => 'security_phrase',
1127     'section'     => 'password',
1128     'description' => 'Enable the tracking of a "security phrase" with each account.  Not recommended, as it is vulnerable to social engineering.',
1129     'type'        => 'checkbox',
1130   },
1131
1132   {
1133     'key'         => 'locale',
1134     'section'     => 'UI',
1135     'description' => 'Message locale',
1136     'type'        => 'select',
1137     'select_enum' => [ qw(en_US) ],
1138   },
1139
1140   {
1141     'key'         => 'signup_server-payby',
1142     'section'     => '',
1143     'description' => 'Acceptable payment types for the signup server',
1144     'type'        => 'selectmultiple',
1145     'select_enum' => [ qw(CARD DCRD CHEK DCHK LECB PREPAY BILL COMP) ],
1146   },
1147
1148   {
1149     'key'         => 'signup_server-default_agentnum',
1150     'section'     => '',
1151     'description' => 'Default agent for the signup server',
1152     'type'        => 'select-sub',
1153     'options_sub' => sub { require FS::Record;
1154                            require FS::agent;
1155                            map { $_->agentnum => $_->agent }
1156                                FS::Record::qsearch('agent', { disabled=>'' } );
1157                          },
1158     'option_sub'  => sub { require FS::Record;
1159                            require FS::agent;
1160                            my $agent = FS::Record::qsearchs(
1161                              'agent', { 'agentnum'=>shift }
1162                            );
1163                            $agent ? $agent->agent : '';
1164                          },
1165   },
1166
1167   {
1168     'key'         => 'signup_server-default_refnum',
1169     'section'     => '',
1170     'description' => 'Default advertising source for the signup server',
1171     'type'        => 'select-sub',
1172     'options_sub' => sub { require FS::Record;
1173                            require FS::part_referral;
1174                            map { $_->refnum => $_->referral }
1175                                FS::Record::qsearch( 'part_referral', 
1176                                                     { 'disabled' => '' }
1177                                                   );
1178                          },
1179     'option_sub'  => sub { require FS::Record;
1180                            require FS::part_referral;
1181                            my $part_referral = FS::Record::qsearchs(
1182                              'part_referral', { 'refnum'=>shift } );
1183                            $part_referral ? $part_referral->referral : '';
1184                          },
1185   },
1186
1187   {
1188     'key'         => 'signup_server-default_pkgpart',
1189     'section'     => '',
1190     'description' => 'Default pakcage for the signup server',
1191     'type'        => 'select-sub',
1192     'options_sub' => sub { require FS::Record;
1193                            require FS::part_pkg;
1194                            map { $_->pkgpart => $_->pkg.' - '.$_->comment }
1195                                FS::Record::qsearch( 'part_pkg',
1196                                                     { 'disabled' => ''}
1197                                                   );
1198                          },
1199     'option_sub'  => sub { require FS::Record;
1200                            require FS::part_pkg;
1201                            my $part_pkg = FS::Record::qsearchs(
1202                              'part_pkg', { 'pkgpart'=>shift }
1203                            );
1204                            $part_pkg
1205                              ? $part_pkg->pkg.' - '.$part_pkg->comment
1206                              : '';
1207                          },
1208   },
1209
1210   {
1211     'key'         => 'show-msgcat-codes',
1212     'section'     => 'UI',
1213     'description' => 'Show msgcat codes in error messages.  Turn this option on before reporting errors to the mailing list.',
1214     'type'        => 'checkbox',
1215   },
1216
1217   {
1218     'key'         => 'signup_server-realtime',
1219     'section'     => '',
1220     'description' => 'Run billing for signup server signups immediately, and do not provision accounts which subsequently have a balance.',
1221     'type'        => 'checkbox',
1222   },
1223   {
1224     'key'         => 'signup_server-classnum2',
1225     'section'     => '',
1226     'description' => 'Package Class for first optional purchase',
1227     'type'        => 'select-sub',
1228     'options_sub' => sub { require FS::Record;
1229                            require FS::pkg_class;
1230                            map { $_->classnum => $_->classname }
1231                                FS::Record::qsearch('pkg_class', {} );
1232                          },
1233     'option_sub'  => sub { require FS::Record;
1234                            require FS::pkg_class;
1235                            my $pkg_class = FS::Record::qsearchs(
1236                              'pkg_class', { 'classnum'=>shift }
1237                            );
1238                            $pkg_class ? $pkg_class->classname : '';
1239                          },
1240   },
1241
1242   {
1243     'key'         => 'signup_server-classnum3',
1244     'section'     => '',
1245     'description' => 'Package Class for second optional purchase',
1246     'type'        => 'select-sub',
1247     'options_sub' => sub { require FS::Record;
1248                            require FS::pkg_class;
1249                            map { $_->classnum => $_->classname }
1250                                FS::Record::qsearch('pkg_class', {} );
1251                          },
1252     'option_sub'  => sub { require FS::Record;
1253                            require FS::pkg_class;
1254                            my $pkg_class = FS::Record::qsearchs(
1255                              'pkg_class', { 'classnum'=>shift }
1256                            );
1257                            $pkg_class ? $pkg_class->classname : '';
1258                          },
1259   },
1260
1261   {
1262     'key'         => 'backend-realtime',
1263     'section'     => '',
1264     'description' => 'Run billing for backend signups immediately.',
1265     'type'        => 'checkbox',
1266   },
1267
1268   {
1269     'key'         => 'declinetemplate',
1270     'section'     => 'billing',
1271     'description' => 'Template file for credit card decline emails.',
1272     'type'        => 'textarea',
1273   },
1274
1275   {
1276     'key'         => 'emaildecline',
1277     'section'     => 'billing',
1278     'description' => 'Enable emailing of credit card decline notices.',
1279     'type'        => 'checkbox',
1280   },
1281
1282   {
1283     'key'         => 'emaildecline-exclude',
1284     'section'     => 'billing',
1285     'description' => 'List of error messages that should not trigger email decline notices, one per line.',
1286     'type'        => 'textarea',
1287   },
1288
1289   {
1290     'key'         => 'cancelmessage',
1291     'section'     => 'billing',
1292     'description' => 'Template file for cancellation emails.',
1293     'type'        => 'textarea',
1294   },
1295
1296   {
1297     'key'         => 'cancelsubject',
1298     'section'     => 'billing',
1299     'description' => 'Subject line for cancellation emails.',
1300     'type'        => 'text',
1301   },
1302
1303   {
1304     'key'         => 'emailcancel',
1305     'section'     => 'billing',
1306     'description' => 'Enable emailing of cancellation notices.',
1307     'type'        => 'checkbox',
1308   },
1309
1310   {
1311     'key'         => 'require_cardname',
1312     'section'     => 'billing',
1313     'description' => 'Require an "Exact name on card" to be entered explicitly; don\'t default to using the first and last name.',
1314     'type'        => 'checkbox',
1315   },
1316
1317   {
1318     'key'         => 'enable_taxclasses',
1319     'section'     => 'billing',
1320     'description' => 'Enable per-package tax classes',
1321     'type'        => 'checkbox',
1322   },
1323
1324   {
1325     'key'         => 'require_taxclasses',
1326     'section'     => 'billing',
1327     'description' => 'Require a taxclass to be entered for every package',
1328     'type'        => 'checkbox',
1329   },
1330
1331   {
1332     'key'         => 'welcome_email',
1333     'section'     => '',
1334     'description' => 'Template file for welcome email.  Welcome emails are sent to the customer email invoice destination(s) each time a svc_acct record is created.  See the <a href="http://search.cpan.org/~mjd/Text-Template/lib/Text/Template.pm">Text::Template</a> documentation for details on the template substitution language.  The following variables are available<ul><li><code>$username</code> <li><code>$password</code> <li><code>$first</code> <li><code>$last</code> <li><code>$pkg</code></ul>',
1335     'type'        => 'textarea',
1336   },
1337
1338   {
1339     'key'         => 'welcome_email-from',
1340     'section'     => '',
1341     'description' => 'From: address header for welcome email',
1342     'type'        => 'text',
1343   },
1344
1345   {
1346     'key'         => 'welcome_email-subject',
1347     'section'     => '',
1348     'description' => 'Subject: header for welcome email',
1349     'type'        => 'text',
1350   },
1351   
1352   {
1353     'key'         => 'welcome_email-mimetype',
1354     'section'     => '',
1355     'description' => 'MIME type for welcome email',
1356     'type'        => 'select',
1357     'select_enum' => [ 'text/plain', 'text/html' ],
1358   },
1359
1360   {
1361     'key'         => 'welcome_letter',
1362     'section'     => '',
1363     'description' => 'Optional LaTex template file for a printed welcome letter.  A welcome letter is printed the first time a cust_pkg record is created.  See the <a href="http://search.cpan.org/~mjd/Text-Template/lib/Text/Template.pm">Text::Template</a> documentation and the billing documentation for details on the template substitution language.  A variable exists for each fieldname in the customer record (<code>$first, $last, etc</code>).  The following additional variables are available<ul><li><code>$payby</code> - a friendler represenation of the field<li><code>$payinfo</code> - the masked payment information<li><code>$expdate</code> - the time at which the payment method expires (a UNIX timestamp)<li><code>$returnaddress</code> - the invoice return address for this customer\'s agent</ul>',
1364     'type'        => 'textarea',
1365   },
1366
1367   {
1368     'key'         => 'warning_email',
1369     'section'     => '',
1370     'description' => 'Template file for warning email.  Warning emails are sent to the customer email invoice destination(s) each time a svc_acct record has its usage drop below a threshold or 0.  See the <a href="http://search.cpan.org/~mjd/Text-Template/lib/Text/Template.pm">Text::Template</a> documentation for details on the template substitution language.  The following variables are available<ul><li><code>$username</code> <li><code>$password</code> <li><code>$first</code> <li><code>$last</code> <li><code>$pkg</code> <li><code>$column</code> <li><code>$amount</code> <li><code>$threshold</code></ul>',
1371     'type'        => 'textarea',
1372   },
1373
1374   {
1375     'key'         => 'warning_email-from',
1376     'section'     => '',
1377     'description' => 'From: address header for warning email',
1378     'type'        => 'text',
1379   },
1380
1381   {
1382     'key'         => 'warning_email-cc',
1383     'section'     => '',
1384     'description' => 'Additional recipient(s) (comma separated) for warning email when remaining usage reaches zero.',
1385     'type'        => 'text',
1386   },
1387
1388   {
1389     'key'         => 'warning_email-subject',
1390     'section'     => '',
1391     'description' => 'Subject: header for warning email',
1392     'type'        => 'text',
1393   },
1394   
1395   {
1396     'key'         => 'warning_email-mimetype',
1397     'section'     => '',
1398     'description' => 'MIME type for warning email',
1399     'type'        => 'select',
1400     'select_enum' => [ 'text/plain', 'text/html' ],
1401   },
1402
1403   {
1404     'key'         => 'payby',
1405     'section'     => 'billing',
1406     'description' => 'Available payment types.',
1407     'type'        => 'selectmultiple',
1408     'select_enum' => [ qw(CARD DCRD CHEK DCHK LECB BILL CASH WEST MCRD COMP) ],
1409   },
1410
1411   {
1412     'key'         => 'payby-default',
1413     'section'     => 'UI',
1414     'description' => 'Default payment type.  HIDE disables display of billing information and sets customers to BILL.',
1415     'type'        => 'select',
1416     'select_enum' => [ '', qw(CARD DCRD CHEK DCHK LECB BILL CASH WEST MCRD COMP HIDE) ],
1417   },
1418
1419   {
1420     'key'         => 'paymentforcedtobatch',
1421     'section'     => 'UI',
1422     'description' => 'Causes per customer payment entry to be forced to a batch processor rather than performed realtime.',
1423     'type'        => 'checkbox',
1424   },
1425
1426   {
1427     'key'         => 'svc_acct-notes',
1428     'section'     => 'UI',
1429     'description' => 'Extra HTML to be displayed on the Account View screen.',
1430     'type'        => 'textarea',
1431   },
1432
1433   {
1434     'key'         => 'radius-password',
1435     'section'     => '',
1436     'description' => 'RADIUS attribute for plain-text passwords.',
1437     'type'        => 'select',
1438     'select_enum' => [ 'Password', 'User-Password' ],
1439   },
1440
1441   {
1442     'key'         => 'radius-ip',
1443     'section'     => '',
1444     'description' => 'RADIUS attribute for IP addresses.',
1445     'type'        => 'select',
1446     'select_enum' => [ 'Framed-IP-Address', 'Framed-Address' ],
1447   },
1448
1449   {
1450     'key'         => 'svc_acct-alldomains',
1451     'section'     => '',
1452     'description' => 'Allow accounts to select any domain in the database.  Normally accounts can only select from the domain set in the service definition and those purchased by the customer.',
1453     'type'        => 'checkbox',
1454   },
1455
1456   {
1457     'key'         => 'dump-scpdest',
1458     'section'     => '',
1459     'description' => 'destination for scp database dumps: user@host:/path',
1460     'type'        => 'text',
1461   },
1462
1463   {
1464     'key'         => 'dump-pgpid',
1465     'section'     => '',
1466     'description' => "Optional PGP public key user or key id for database dumps.  The public key should exist on the freeside user's public keyring, and the gpg binary and GnuPG perl module should be installed.",
1467     'type'        => 'text',
1468   },
1469
1470   {
1471     'key'         => 'cvv-save',
1472     'section'     => 'billing',
1473     'description' => 'Save CVV2 information after the initial transaction for the selected credit card types.  Enabling this option may be in violation of your merchant agreement(s), so please check them carefully before enabling this option for any credit card types.',
1474     'type'        => 'selectmultiple',
1475     'select_enum' => \@card_types,
1476   },
1477
1478   {
1479     'key'         => 'allow_negative_charges',
1480     'section'     => 'billing',
1481     'description' => 'Allow negative charges.  Normally not used unless importing data from a legacy system that requires this.',
1482     'type'        => 'checkbox',
1483   },
1484   {
1485       'key'         => 'auto_unset_catchall',
1486       'section'     => '',
1487       'description' => 'When canceling a svc_acct that is the email catchall for one or more svc_domains, automatically set their catchall fields to null.  If this option is not set, the attempt will simply fail.',
1488       'type'        => 'checkbox',
1489   },
1490
1491   {
1492     'key'         => 'system_usernames',
1493     'section'     => 'username',
1494     'description' => 'A list of system usernames that cannot be edited or removed, one per line.  Use a bare username to prohibit modification/deletion of the username in any domain, or username@domain to prohibit modification/deletetion of a specific username and domain.',
1495     'type'        => 'textarea',
1496   },
1497
1498   {
1499     'key'         => 'cust_pkg-change_svcpart',
1500     'section'     => '',
1501     'description' => "When changing packages, move services even if svcparts don't match between old and new pacakge definitions.",
1502     'type'        => 'checkbox',
1503   },
1504
1505   {
1506     'key'         => 'disable_autoreverse',
1507     'section'     => 'BIND',
1508     'description' => 'Disable automatic synchronization of reverse-ARPA entries.',
1509     'type'        => 'checkbox',
1510   },
1511
1512   {
1513     'key'         => 'svc_www-enable_subdomains',
1514     'section'     => '',
1515     'description' => 'Enable selection of specific subdomains for virtual host creation.',
1516     'type'        => 'checkbox',
1517   },
1518
1519   {
1520     'key'         => 'svc_www-usersvc_svcpart',
1521     'section'     => '',
1522     'description' => 'Allowable service definition svcparts for virtual hosts, one per line.',
1523     'type'        => 'textarea',
1524   },
1525
1526   {
1527     'key'         => 'selfservice_server-primary_only',
1528     'section'     => '',
1529     'description' => 'Only allow primary accounts to access self-service functionality.',
1530     'type'        => 'checkbox',
1531   },
1532
1533   {
1534     'key'         => 'card_refund-days',
1535     'section'     => 'billing',
1536     'description' => 'After a payment, the number of days a refund link will be available for that payment.  Defaults to 120.',
1537     'type'        => 'text',
1538   },
1539
1540   {
1541     'key'         => 'agent-showpasswords',
1542     'section'     => '',
1543     'description' => 'Display unencrypted user passwords in the agent (reseller) interface',
1544     'type'        => 'checkbox',
1545   },
1546
1547   {
1548     'key'         => 'global_unique-username',
1549     'section'     => 'username',
1550     'description' => 'Global username uniqueness control: none (usual setting - check uniqueness per exports), username (all usernames are globally unique, regardless of domain or exports), or username@domain (all username@domain pairs are globally unique, regardless of exports).  disabled turns off duplicate checking completely and is STRONGLY NOT RECOMMENDED unless you REALLY need to turn this off.',
1551     'type'        => 'select',
1552     'select_enum' => [ 'none', 'username', 'username@domain', 'disabled' ],
1553   },
1554
1555   {
1556     'key'         => 'svc_external-skip_manual',
1557     'section'     => 'UI',
1558     'description' => 'When provisioning svc_external services, skip manual entry of id and title fields in the UI.  Usually used in conjunction with an export that populates these fields (i.e. artera_turbo).',
1559     'type'        => 'checkbox',
1560   },
1561
1562   {
1563     'key'         => 'svc_external-display_type',
1564     'section'     => 'UI',
1565     'description' => 'Select a specific svc_external type to enable some UI changes specific to that type (i.e. artera_turbo).',
1566     'type'        => 'select',
1567     'select_enum' => [ 'generic', 'artera_turbo', ],
1568   },
1569
1570   {
1571     'key'         => 'ticket_system',
1572     'section'     => '',
1573     'description' => 'Ticketing system integration.  <b>RT_Internal</b> uses the built-in RT ticketing system (see the <a href="../docs/install-rt">integrated ticketing installation instructions</a>).   <b>RT_External</b> accesses an external RT installation in a separate database (local or remote).',
1574     'type'        => 'select',
1575     #'select_enum' => [ '', qw(RT_Internal RT_Libs RT_External) ],
1576     'select_enum' => [ '', qw(RT_Internal RT_External) ],
1577   },
1578
1579   {
1580     'key'         => 'ticket_system-default_queueid',
1581     'section'     => '',
1582     'description' => 'Default queue used when creating new customer tickets.',
1583     'type'        => 'select-sub',
1584     'options_sub' => sub {
1585                            my $conf = new FS::Conf;
1586                            if ( $conf->config('ticket_system') ) {
1587                              eval "use FS::TicketSystem;";
1588                              die $@ if $@;
1589                              FS::TicketSystem->queues();
1590                            } else {
1591                              ();
1592                            }
1593                          },
1594     'option_sub'  => sub { 
1595                            my $conf = new FS::Conf;
1596                            if ( $conf->config('ticket_system') ) {
1597                              eval "use FS::TicketSystem;";
1598                              die $@ if $@;
1599                              FS::TicketSystem->queue(shift);
1600                            } else {
1601                              '';
1602                            }
1603                          },
1604   },
1605
1606   {
1607     'key'         => 'ticket_system-custom_priority_field',
1608     'section'     => '',
1609     'description' => 'Custom field from the ticketing system to use as a custom priority classification.',
1610     'type'        => 'text',
1611   },
1612
1613   {
1614     'key'         => 'ticket_system-custom_priority_field-values',
1615     'section'     => '',
1616     'description' => 'Values for the custom field from the ticketing system to break down and sort customer ticket lists.',
1617     'type'        => 'textarea',
1618   },
1619
1620   {
1621     'key'         => 'ticket_system-custom_priority_field_queue',
1622     'section'     => '',
1623     'description' => 'Ticketing system queue in which the custom field specified in ticket_system-custom_priority_field is located.',
1624     'type'        => 'text',
1625   },
1626
1627   {
1628     'key'         => 'ticket_system-rt_external_datasrc',
1629     'section'     => '',
1630     'description' => 'With external RT integration, the DBI data source for the external RT installation, for example, <code>DBI:Pg:user=rt_user;password=rt_word;host=rt.example.com;dbname=rt</code>',
1631     'type'        => 'text',
1632
1633   },
1634
1635   {
1636     'key'         => 'ticket_system-rt_external_url',
1637     'section'     => '',
1638     'description' => 'With external RT integration, the URL for the external RT installation, for example, <code>https://rt.example.com/rt</code>',
1639     'type'        => 'text',
1640   },
1641
1642   {
1643     'key'         => 'company_name',
1644     'section'     => 'required',
1645     'description' => 'Your company name',
1646     'type'        => 'text',
1647   },
1648
1649   {
1650     'key'         => 'address2-search',
1651     'section'     => 'UI',
1652     'description' => 'Enable a "Unit" search box which searches the second address field',
1653     'type'        => 'checkbox',
1654   },
1655
1656   { 'key'         => 'referral_credit',
1657     'section'     => 'billing',
1658     'description' => "Enables one-time referral credits in the amount of one month <i>referred</i> customer's recurring fee (irregardless of frequency).",
1659     'type'        => 'checkbox',
1660   },
1661
1662   { 'key'         => 'selfservice_server-cache_module',
1663     'section'     => '',
1664     'description' => 'Module used to store self-service session information.  All modules handle any number of self-service servers.  Cache::SharedMemoryCache is appropriate for a single database / single Freeside server.  Cache::FileCache is useful for multiple databases on a single server, or when IPC::ShareLite is not available (i.e. FreeBSD).', #  _Database stores session information in the database and is appropriate for multiple Freeside servers, but may be slower.',
1665     'type'        => 'select',
1666     'select_enum' => [ 'Cache::SharedMemoryCache', 'Cache::FileCache', ], # '_Database' ],
1667   },
1668
1669   {
1670     'key'         => 'hylafax',
1671     'section'     => '',
1672     'description' => 'Options for a HylaFAX server to enable the FAX invoice destination.  They should be in the form of a space separated list of arguments to the Fax::Hylafax::Client::sendfax subroutine.  You probably shouldn\'t override things like \'docfile\'.  *Note* Only supported when using typeset invoices (see the invoice_latex configuration option).',
1673     'type'        => [qw( checkbox textarea )],
1674   },
1675
1676   {
1677     'key'         => 'svc_acct-usage_suspend',
1678     'section'     => 'billing',
1679     'description' => 'Suspends the package an account belongs to when svc_acct.seconds or a bytecount is decremented to 0 or below (accounts with an empty seconds and up|down|totalbytes value are ignored).  Typically used in conjunction with prepaid packages and freeside-sqlradius-radacctd.',
1680     'type'        => 'checkbox',
1681   },
1682
1683   {
1684     'key'         => 'svc_acct-usage_unsuspend',
1685     'section'     => 'billing',
1686     'description' => 'Unuspends the package an account belongs to when svc_acct.seconds or a bytecount is incremented from 0 or below to a positive value (accounts with an empty seconds and up|down|totalbytes value are ignored).  Typically used in conjunction with prepaid packages and freeside-sqlradius-radacctd.',
1687     'type'        => 'checkbox',
1688   },
1689
1690   {
1691     'key'         => 'svc_acct-usage_threshold',
1692     'section'     => 'billing',
1693     'description' => 'The threshold (expressed as percentage) of acct.seconds or acct.up|down|totalbytes at which a warning message is sent to a service holder.  Typically used in conjunction with prepaid packages and freeside-sqlradius-radacctd.  Defaults to 80.',
1694     'type'        => 'text',
1695   },
1696
1697   {
1698     'key'         => 'cust-fields',
1699     'section'     => 'UI',
1700     'description' => 'Which customer fields to display on reports by default',
1701     'type'        => 'select',
1702     'select_hash' => [ FS::ConfDefaults->cust_fields_avail() ],
1703   },
1704
1705   {
1706     'key'         => 'cust_pkg-display_times',
1707     'section'     => 'UI',
1708     'description' => 'Display full timestamps (not just dates) for customer packages.  Useful if you are doing real-time things like hourly prepaid.',
1709     'type'        => 'checkbox',
1710   },
1711
1712   {
1713     'key'         => 'svc_acct-edit_uid',
1714     'section'     => 'shell',
1715     'description' => 'Allow UID editing.',
1716     'type'        => 'checkbox',
1717   },
1718
1719   {
1720     'key'         => 'svc_acct-edit_gid',
1721     'section'     => 'shell',
1722     'description' => 'Allow GID editing.',
1723     'type'        => 'checkbox',
1724   },
1725
1726   {
1727     'key'         => 'zone-underscore',
1728     'section'     => 'BIND',
1729     'description' => 'Allow underscores in zone names.  As underscores are illegal characters in zone names, this option is not recommended.',
1730     'type'        => 'checkbox',
1731   },
1732
1733   {
1734     'key'         => 'echeck-nonus',
1735     'section'     => 'billing',
1736     'description' => 'Disable ABA-format account checking for Electronic Check payment info',
1737     'type'        => 'checkbox',
1738   },
1739
1740   {
1741     'key'         => 'voip-cust_cdr_spools',
1742     'section'     => '',
1743     'description' => 'Enable the per-customer option for individual CDR spools.',
1744     'type'        => 'checkbox',
1745   },
1746
1747   {
1748     'key'         => 'svc_forward-arbitrary_dst',
1749     'section'     => '',
1750     'description' => "Allow forwards to point to arbitrary strings that don't necessarily look like email addresses.  Only used when using forwards for weird, non-email things.",
1751     'type'        => 'checkbox',
1752   },
1753
1754   {
1755     'key'         => 'tax-ship_address',
1756     'section'     => 'billing',
1757     'description' => 'By default, tax calculations are done based on the billing address.  Enable this switch to calculate tax based on the shipping address instead.  Note: Tax reports can take a long time when enabled.',
1758     'type'        => 'checkbox',
1759   },
1760
1761   {
1762     'key'         => 'batch-enable',
1763     'section'     => 'billing',
1764     'description' => 'Enable credit card and/or ACH batching - leave disabled for real-time installations.',
1765     'type'        => 'checkbox',
1766   },
1767
1768   {
1769     'key'         => 'batch-default_format',
1770     'section'     => 'billing',
1771     'description' => 'Default format for batches.',
1772     'type'        => 'select',
1773     'select_enum' => [ 'csv-td_canada_trust-merchant_pc_batch',
1774                        'csv-chase_canada-E-xactBatch', 'BoM', 'PAP',
1775                        'ach-spiritone',
1776                     ]
1777   },
1778
1779   {
1780     'key'         => 'batch-fixed_format-CARD',
1781     'section'     => 'billing',
1782     'description' => 'Fixed (unchangeable) format for credit card batches.',
1783     'type'        => 'select',
1784     'select_enum' => [ 'csv-td_canada_trust-merchant_pc_batch', 'BoM', 'PAP' ,
1785                        'csv-chase_canada-E-xactBatch', 'BoM', 'PAP' ]
1786   },
1787
1788   {
1789     'key'         => 'batch-fixed_format-CHEK',
1790     'section'     => 'billing',
1791     'description' => 'Fixed (unchangeable) format for electronic check batches.',
1792     'type'        => 'select',
1793     'select_enum' => [ 'csv-td_canada_trust-merchant_pc_batch', 'BoM', 'PAP',
1794                        'ach-spiritone',
1795                      ]
1796   },
1797
1798   {
1799     'key'         => 'batch-increment_expiration',
1800     'section'     => 'billing',
1801     'description' => 'Increment expiration date years in batches until cards are current.  Make sure this is acceptable to your batching provider before enabling.',
1802     'type'        => 'checkbox'
1803   },
1804
1805   {
1806     'key'         => 'batchconfig-BoM',
1807     'section'     => 'billing',
1808     'description' => 'Configuration for Bank of Montreal batching, seven lines: 1. Origin ID, 2. Datacenter, 3. Typecode, 4. Short name, 5. Long name, 6. Bank, 7. Bank account',
1809     'type'        => 'textarea',
1810   },
1811
1812   {
1813     'key'         => 'batchconfig-PAP',
1814     'section'     => 'billing',
1815     'description' => 'Configuration for PAP batching, seven lines: 1. Origin ID, 2. Datacenter, 3. Typecode, 4. Short name, 5. Long name, 6. Bank, 7. Bank account',
1816     'type'        => 'textarea',
1817   },
1818
1819   {
1820     'key'         => 'batchconfig-csv-chase_canada-E-xactBatch',
1821     'section'     => 'billing',
1822     'description' => 'Gateway ID for Chase Canada E-xact batching',
1823     'type'        => 'text',
1824   },
1825
1826   {
1827     'key'         => 'payment_history-years',
1828     'section'     => 'UI',
1829     'description' => 'Number of years of payment history to show by default.  Currently defaults to 2.',
1830     'type'        => 'text',
1831   },
1832
1833   {
1834     'key'         => 'cust_main-use_comments',
1835     'section'     => 'UI',
1836     'description' => 'Display free form comments on the customer edit screen.  Useful as a scratch pad.',
1837     'type'        => 'checkbox',
1838   },
1839
1840   {
1841     'key'         => 'cust_main-disable_notes',
1842     'section'     => 'UI',
1843     'description' => 'Disable new style customer notes - timestamped and user identified customer notes.  Useful in tracking who did what.',
1844     'type'        => 'checkbox',
1845   },
1846
1847   {
1848     'key'         => 'cust_main_note-display_times',
1849     'section'     => 'UI',
1850     'description' => 'Display full timestamps (not just dates) for customer notes.',
1851     'type'        => 'checkbox',
1852   },
1853
1854   {
1855     'key'         => 'cust_main-ticket_statuses',
1856     'section'     => 'UI',
1857     'description' => 'Show tickets with these statuses on the customer view page.',
1858     'type'        => 'selectmultiple',
1859     'select_enum' => [qw( new open stalled resolved rejected deleted )],
1860   },
1861
1862   {
1863     'key'         => 'cust_main-max_tickets',
1864     'section'     => 'UI',
1865     'description' => 'Maximum number of tickets to show on the customer view page.',
1866     'type'        => 'text',
1867   },
1868
1869   {
1870     'key'         => 'cust_main-skeleton_tables',
1871     'section'     => '',
1872     'description' => 'Tables which will have skeleton records inserted into them for each customer.  Syntax for specifying tables is unfortunately a tricky perl data structure for now.',
1873     'type'        => 'textarea',
1874   },
1875
1876   {
1877     'key'         => 'cust_main-skeleton_custnum',
1878     'section'     => '',
1879     'description' => 'Customer number specifying the source data to copy into skeleton tables for new customers.',
1880     'type'        => 'text',
1881   },
1882
1883   {
1884     'key'         => 'cust_main-enable_birthdate',
1885     'section'     => 'UI',
1886     'descritpion' => 'Enable tracking of a birth date with each customer record',
1887     'type'        => 'checkbox',
1888   },
1889
1890   {
1891     'key'         => 'support-key',
1892     'section'     => '',
1893     'description' => 'A support key enables access to commercial services delivered over the network, such as the payroll module, access to the internal ticket system, priority support and optional backups.',
1894     'type'        => 'text',
1895   },
1896
1897   {
1898     'key'         => 'card-types',
1899     'section'     => 'billing',
1900     'description' => 'Select one or more card types to enable only those card types.  If no card types are selected, all card types are available.',
1901     'type'        => 'selectmultiple',
1902     'select_enum' => \@card_types,
1903   },
1904
1905   {
1906     'key'         => 'dashboard-toplist',
1907     'section'     => 'UI',
1908     'description' => 'List of items to display on the top of the front page',
1909     'type'        => 'textarea',
1910   },
1911
1912   {
1913     'key'         => 'impending_recur_template',
1914     'section'     => 'billing',
1915     'description' => 'Template file for alerts about looming first time recurrant billing.  See the <a href="http://search.cpan.org/~mjd/Text-Template.pm">Text::Template</a> documentation for details on the template substitition language.  Also see packages with a <a href="../browse/part_pkg.cgi">flat price plan</a>  The following variables are available<ul><li><code>$packages</code> allowing <code>$packages->[0]</code> thru <code>$packages->[n]</code> <li><code>$package</code> the first package, same as <code>$packages->[0]</code> <li><code>$recurdates</code> allowing <code>$recurdates->[0]</code> thru <code>$recurdates->[n]</code> <li><code>$recurdate</code> the first recurdate, same as <code>$recurdate->[0]</code> <li><code>$first</code> <li><code>$last</code></ul>',
1916 # <li><code>$payby</code> <li><code>$expdate</code> most likely only confuse
1917     'type'        => 'textarea',
1918   },
1919
1920   {
1921     'key'         => 'logo.png',
1922     'section'     => 'billing',  #? 
1923     'description' => 'An image to include in some types of invoices',
1924     'type'        => 'binary',
1925   },
1926
1927   {
1928     'key'         => 'logo.eps',
1929     'section'     => 'billing',  #? 
1930     'description' => 'An image to include in some types of invoices',
1931     'type'        => 'binary',
1932   },
1933
1934   {
1935     'key'         => 'selfservice-ignore_quantity',
1936     'section'     => '',
1937     'description' => 'Ignores service quantity restrictions in self-service context.  Strongly not recommended - just set your quantities correctly in the first place.',
1938     'type'        => 'checkbox',
1939   },
1940
1941   {
1942     'key'         => 'disable_setup_suspended_pkgs',
1943     'section'     => 'billing',
1944     'description' => 'Disables charging of setup fees for suspended packages.',
1945     'type'       => 'checkbox',
1946   },
1947
1948   {
1949     'key' => 'password-generated-allcaps',
1950     'section' => 'password',
1951     'description' => 'Causes passwords automatically generated to consist entirely of capital letters',
1952     'type' => 'checkbox',
1953   },
1954
1955   {
1956     'key'         => 'datavolume-forcemegabytes',
1957     'section'     => 'UI',
1958     'description' => 'All data volumes are expressed in megabytes',
1959     'type'        => 'checkbox',
1960   },
1961
1962   {
1963     'key'         => 'datavolume-significantdigits',
1964     'section'     => 'UI',
1965     'description' => 'number of significant digits to use to represent data volumes',
1966     'type'        => 'text',
1967   },
1968
1969   {
1970     'key'         => 'disable_void_after',
1971     'section'     => 'billing',
1972     'description' => 'Number of seconds after which freeside won\'t attempt to VOID a payment first when performing a refund.',
1973     'type'        => 'text',
1974   },
1975
1976   {
1977     'key'         => 'disable_line_item_date_ranges',
1978     'section'     => 'billing',
1979     'description' => 'Prevent freeside from automatically generating date ranges on invoice line items.',
1980     'type'        => 'checkbox',
1981   },
1982
1983 );
1984
1985 1;