From: cvs2git Date: Sat, 23 Feb 2002 11:56:56 +0000 (+0000) Subject: This commit was manufactured by cvs2svn to create tag 'freeside_1_4_0pre11'. X-Git-Tag: freeside_1_4_0pre11 X-Git-Url: http://git.freeside.biz/gitweb/?a=commitdiff_plain;h=1ea22e45aa22e2138ff947a9afeab1acac1b9394;hp=80ba0c074354875c288c143721af08a0a5d02e42;p=freeside.git This commit was manufactured by cvs2svn to create tag 'freeside_1_4_0pre11'. --- diff --git a/CREDITS b/CREDITS index 87c79a779..f3396284a 100644 --- a/CREDITS +++ b/CREDITS @@ -1,14 +1,96 @@ Thanks to Matt Simerson of MichWeb Inc. for documentation -and pre-release testing. Without his help the documentation in the first +and pre-release testing. Without his help the documentation in 1.0.0 release would have consisted of a single screenfull of text. +(To clear up some misunderstanding, Matt did not write the current +documentation.) -# Steve Cleff did the default background image and is also -# the creator of Freeside's mascot, Snakeman. +Steve Cleff did the default background image in 1.0.x and +is also the creator of Freeside's elusive mascot, Snakeman, who we hope will +make an appearance in an upcoming version. -Jerry St. Pierre did the "SISD" graphic. +Jerry St. Pierre did the "SISD" graphic used in +1.0.x and most of 1.1.x. + +Mark Norris of Urban Design, Inc. did the red "S" +logo for later 1.1.x versions and 1.2.x Brian McCane? contributed PostgreSQL support, HTML style enhancements and many, many bugfixes. -Everything else is my (Ivan Kohler ) fault. +Cerkit contributed rsync support and desynced hosts. +His changes will hopefully be included in an upcoming version. + +CompleteHOST, Inc. (http://www.completehost.com) funded the development of the +following features: + - Multiple, separate databases and configurations on one box. + - Per-customer pricing (custom packages) + - Internationalization wrt addresses (cust_main, cust_main_county) +Thanks! + +Mark Williamson and Roger Mangraviti + contributed state/provence listings for Australia. + +Peter Wemm sent in a bunch of bugfixes for the 1.2 +release. + +Greg Kuhnert sent some documentation updates. + +Joel Griffiths contribued many bugfixes as well as +the print-batch script. + +NetLoud funded the development of the following +features: + - IEAK support for the signup server + - Pre-payment support + +NetAcces.Net (not netaccess.net) funded the development of the following +features: + - DNS tracking and export to BIND configuration files + - Web site virtual host tracking and export to Apache configuration files + +Kristian Hoffmann contributed Netscape CCK +autoconfiguration support for the signup server, lots of great mailing +lists posts which I shamelessly made into documentation, fixes to get rid of +the embarassing and non-database-normal "owed" field, and many other things +I'm forgetting. + +Jeff Finucane send in a bunch of bugfixes (for the sendmail +export, cancel-unaudited.cgi), patches to support billing date modification, +and probably other things too (sorry if I forgot them). And yet even more +bug squashing, thanks! *and* he single-handedly implemented all the necessary +work to get rid of svc_acct_sm and the "default domain" thanks!! and rewrote +the financials! wow, thanks jeff! and contributed financial reports! + +Kenny Elliott contributed ICRADIUS radreply table support, +allowing attributes with ICRADIUS, helped fix many bugs, and some +other stuff I can't recall (sorry). + +Stephen Amadei contribued portability cleanups for the +low-level DBI stuff. + +Jason Spence contributed admin.html and other +documentation, autocapnames javascript, bugfixes & other neat stuff I can't +remember. + +Brad Dameron contributed code to do configurable state +and referral defaults. + +Surf and Sip, Inc., sponsored a long-requested +feature - the session monitor and time-based prepaid cards. +Matt Peterson and Mack ? tested +the new features and contributed many bugfixes. + +Landel Telecom sponsored shipping addresses and +customer notes, as well as an update of the CP provisioning. + +nikotel, Inc. sponsored the inclusion of +customer-to-customer referrals in the web interface and signup server. + +Three Bubba's Innanet sponsored expedited check entry, +the "similar names warning" feature, and a number of other enhancements. + +Dave Burgess sent in a bunch of fixes and small changes +and will doubtless send more once he's got his tree under control. + +Everything else is my (Ivan Kohler ) fault. diff --git a/FS/Changes b/FS/Changes new file mode 100644 index 000000000..c94ef10f5 --- /dev/null +++ b/FS/Changes @@ -0,0 +1,5 @@ +Revision history for Perl extension FS. + +0.01 Wed Aug 4 00:13:45 1999 + - original version; created by h2xs 1.19 + diff --git a/FS/FS.pm b/FS/FS.pm new file mode 100644 index 000000000..60831ecd5 --- /dev/null +++ b/FS/FS.pm @@ -0,0 +1,199 @@ +package FS; + +use strict; +use vars qw($VERSION); + +$VERSION = '0.01'; + +1; +__END__ + +=head1 NAME + +FS - Freeside Perl modules + +=head1 SYNOPSIS + +Freeside perl modules and CLI utilities. + +=head2 Utility classes + +L - Freeside configuration values + +L - Freeside configuration option meta-data. + +L - User class (not yet OO) + +L - Non OO-subroutines for the web interface. + +=head2 Database record classes + +L - Database record base class + +L - POP (Point of Presence, not Post +Office Protocol) class + +L - Local calling area class + +L - Referral class + +L - Locale (tax rate) class + +L - Service base class + +L - Account (shell, RADIUS, POP3) class + +L - Domain class + +L - DNS zone entries + +L - Mail forwarding class + +L - (Depreciated) Vitual mail alias class + +L - Web virtual host class. + +L - Service definition class + +L - Column constraint class + +L - External provisioning export class + +L - Export option class + +L - Package (billing item) definition class + +L - Class linking package (billing item) +definitions (see L) with service definitions +(see L) + +L - Agent (reseller) class + +L - Agent type class + +L - Class linking agent types (see +L) with package (billing item) definitions +(see L) + +L - Service class + +L - Package (billing item) class + +L - Customer class + +L - Invoice destination +class + +L - Invoice class + +L - Invoice line item class + +L - Invoice event definition class + +L - Completed invoice event class + +L - Payment class + +L - Payment application class + +L - Credit class + +L - Refund class + +L - Refund application class + +L - Credit invoice application class + +L - Credit card transaction queue class + +L - Prepaid "calling card" credit class. + +L - Network Access Server class + +L - NAS port class + +L - User login session class + +L - Job queue + +L - Job arguments + +=head1 Remote API modules + +L + +L + +L + +=head2 Command-line utilities + +L + +L + +L + +L + +L + +=head2 User Interface classes (under (stalled) development; not yet usable) + +L - User-interface base class + +L - Gtk user-interface class + +L - CGI (HTML) user-interface class + +L - agent table user-interface class + +=head2 Notes + +To quote perl(1), "If you're intending to read these straight through for the +first time, the suggested order will tend to reduce the number of forward +references." + +If you've never used OO modules before, +http://www.cpan.org/doc/FMTEYEWTK/easy_objects.html might help you out. + +=head1 DESCRIPTION + +Freeside is a billing and administration package for Internet Service +Providers. + +The Freeside home page is at . + +The main documentation is in httemplate/docs. + +=head1 SUPPORT + +A mailing list for users is available. Send a blank message to + to subscribe. + +A mailing list for developers is available. It is intended to be lower volume +and higher SNR than the users list. Send a blank message to + to subscribe. + +Commercial support is available; see +. + +=head1 AUTHOR + +Primarily Ivan Kohler , with help from many kind folks. + +See the CREDITS file in the Freeside distribution for a (hopefully) complete +list and the individal files for details. + +=head1 SEE ALSO + +perl(1), main Freeside documentation in htdocs/docs/ + +=head1 BUGS + +Those modules which would be useful separately should be pulled out, +renamed appropriately and uploaded to CPAN. So far: DBIx::DBSchema, Net::SSH +and Net::SCP... + +=cut + diff --git a/FS/FS/CGI.pm b/FS/FS/CGI.pm new file mode 100644 index 000000000..190c0aa37 --- /dev/null +++ b/FS/FS/CGI.pm @@ -0,0 +1,314 @@ +package FS::CGI; + +use strict; +use vars qw(@EXPORT_OK @ISA @header); +use Exporter; +use CGI; +use URI::URL; +#use CGI::Carp qw(fatalsToBrowser); +use FS::UID; + +@ISA = qw(Exporter); +@EXPORT_OK = qw(header menubar idiot eidiot popurl table itable ntable + small_custview myexit); + +=head1 NAME + +FS::CGI - Subroutines for the web interface + +=head1 SYNOPSIS + + use FS::CGI qw(header menubar idiot eidiot popurl); + + print header( 'Title', '' ); + print header( 'Title', menubar('item', 'URL', ... ) ); + + idiot "error message"; + eidiot "error message"; + + $url = popurl; #returns current url + $url = popurl(3); #three levels up + +=head1 DESCRIPTION + +Provides a few common subroutines for the web interface. + +=head1 SUBROUTINES + +=over 4 + +=item header TITLE, MENUBAR + +Returns an HTML header. + +=cut + +sub header { + my($title,$menubar,$etc)=@_; #$etc is for things like onLoad= etc. + #use Carp; + $etc = '' unless defined $etc; + + my $x = < + + + $title + + + + + + + + $title + +

+END + $x .= $menubar. "

" if $menubar; + $x; +} + +=item menubar ITEM, URL, ... + +Returns an HTML menubar. + +=cut + +sub menubar { #$menubar=menubar('Main Menu', '../', 'Item', 'url', ... ); + my($item,$url,@html); + while (@_) { + ($item,$url)=splice(@_,0,2); + push @html, qq!$item!; + } + join(' | ',@html); +} + +=item idiot ERROR + +This is depriciated. Don't use it. + +Sends an HTML error message. + +=cut + +sub idiot { + #warn "idiot depriciated"; + my($error)=@_; +# my $cgi = &FS::UID::cgi(); +# if ( $cgi->isa('CGI::Base') ) { +# no strict 'subs'; +# &CGI::Base::SendHeaders; +# } else { +# print $cgi->header( @FS::CGI::header ); +# } + print < + + Error processing your request + + + + + +
+

Error processing your request

+
+ Your request could not be processed because of the following error: +

$error + + +END + +} + +=item eidiot ERROR + +This is depriciated. Don't use it. + +Sends an HTML error message, then exits. + +=cut + +sub eidiot { + warn "eidiot depriciated"; + $HTML::Mason::Commands::r->send_http_header + if defined $HTML::Mason::Commands::r; + idiot(@_); + &myexit(); +} + +=item myexit + +You probably shouldn't use this; but if you must: + +If running under mod_perl, calles Apache::exit, otherwise, calls exit. + +=cut + +sub myexit { + if (exists $ENV{MOD_PERL}) { + + if ( defined $main::Response + && $main::Response->isa('Apache::ASP::Response') ) { #Apache::ASP + $main::Response->End(); + require Apache; + Apache::exit(); + } elsif ( defined $HTML::Mason::Commands::m ) { #Mason + #$HTML::Mason::Commands::m->flush_buffer(); + $HTML::Mason::Commands::m->abort(); + die "shouldn't fall through to here (mason \$m->abort didn't)"; + } else { + #??? well, it is $ENV{MOD_PERL} + warn "running under unknown mod_perl environment; trying Apache::exit()"; + require Apache; + Apache::exit(); + } + } else { + exit; + } +} + +=item popurl LEVEL + +Returns current URL with LEVEL levels of path removed from the end (default 0). + +=cut + +sub popurl { + my($up)=@_; + my $cgi = &FS::UID::cgi; + my $url = new URI::URL ( $cgi->isa('Apache') ? $cgi->uri : $cgi->url ); + my(@path)=$url->path_components; + splice @path, 0-$up; + $url->path_components(@path); + my $x = $url->as_string; + $x .= '/' unless $x =~ /\/$/; + $x; +} + +=item table + +Returns HTML tag for beginning a table. + +=cut + +sub table { + my $col = shift; + if ( $col ) { + qq!!; + } else { + '
'; + } +} + +=item itable + +Returns HTML tag for beginning an (invisible) table. + +=cut + +sub itable { + my $col = shift; + my $cellspacing = shift || 0; + if ( $col ) { + qq!
!; + } else { + qq!
!; + } +} + +=item ntable + +This is getting silly. + +=cut + +sub ntable { + my $col = shift; + my $cellspacing = shift || 0; + if ( $col ) { + qq!
!; + } else { + '
'; + } + +} + +=item small_custview CUSTNUM || CUST_MAIN_OBJECT, COUNTRYDEFAULT + +Sheesh. I should just switch to Mason. + +=cut + +sub small_custview { + use FS::Record qw(qsearchs); + use FS::cust_main; + + my $arg = shift; + my $countrydefault = shift || 'US'; + + my $cust_main = ref($arg) ? $arg + : qsearchs('cust_main', { 'custnum' => $arg } ) + or die "unknown custnum $arg"; + + my $html = 'Customer #'. $cust_main->custnum. ''. + ntable('#e8e8e8'). '
'. ntable("#cccccc",2). + '
Billing'. + $cust_main->getfield('last'). ', '. $cust_main->first. '
'; + + $html .= $cust_main->company. '
' if $cust_main->company; + $html .= $cust_main->address1. '
'; + $html .= $cust_main->address2. '
' if $cust_main->address2; + $html .= $cust_main->city. ', '. $cust_main->state. ' '. $cust_main->zip. '
'; + $html .= $cust_main->country. '
' + if $cust_main->country && $cust_main->country ne $countrydefault; + + $html .= '
'; + + if ( defined $cust_main->dbdef_table->column('ship_last') ) { + + my $pre = $cust_main->ship_last ? 'ship_' : ''; + + $html .= ''. ntable("#cccccc",2). + 'Service'. + $cust_main->get("${pre}last"). ', '. + $cust_main->get("${pre}first"). '
'; + $html .= $cust_main->get("${pre}company"). '
' + if $cust_main->get("${pre}company"); + $html .= $cust_main->get("${pre}address1"). '
'; + $html .= $cust_main->get("${pre}address2"). '
' + if $cust_main->get("${pre}address2"); + $html .= $cust_main->get("${pre}city"). ', '. + $cust_main->get("${pre}state"). ' '. + $cust_main->get("${pre}ship_zip"). '
'; + $html .= $cust_main->get("${pre}country"). '
' + if $cust_main->get("${pre}country") + && $cust_main->get("${pre}country") ne $countrydefault; + + $html .= ''; + } + + $html .= ''; + + $html; +} + +=back + +=head1 BUGS + +Not OO. + +Not complete. + +small_custview sooooo doesn't belong here. i should just switch to Mason. + +=head1 SEE ALSO + +L, L + +=cut + +1; + + diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm new file mode 100644 index 000000000..226702e5c --- /dev/null +++ b/FS/FS/Conf.pm @@ -0,0 +1,779 @@ +package FS::Conf; + +use vars qw($default_dir @config_items $DEBUG ); +use IO::File; +use FS::ConfItem; + +$DEBUG = 0; + +=head1 NAME + +FS::Conf - Freeside configuration values + +=head1 SYNOPSIS + + use FS::Conf; + + $conf = new FS::Conf "/config/directory"; + + $FS::Conf::default_dir = "/config/directory"; + $conf = new FS::Conf; + + $dir = $conf->dir; + + $value = $conf->config('key'); + @list = $conf->config('key'); + $bool = $conf->exists('key'); + + @config_items = $conf->config_items; + +=head1 DESCRIPTION + +Read and write Freeside configuration values. Keys currently map to filenames, +but this may change in the future. + +=head1 METHODS + +=over 4 + +=item new [ DIRECTORY ] + +Create a new configuration object. A directory arguement is required if +$FS::Conf::default_dir has not been set. + +=cut + +sub new { + my($proto,$dir) = @_; + my($class) = ref($proto) || $proto; + my($self) = { 'dir' => $dir || $default_dir } ; + bless ($self, $class); +} + +=item dir + +Returns the directory. + +=cut + +sub dir { + my($self) = @_; + my $dir = $self->{dir}; + -e $dir or die "FATAL: $dir doesn't exist!"; + -d $dir or die "FATAL: $dir isn't a directory!"; + -r $dir or die "FATAL: Can't read $dir!"; + -x $dir or die "FATAL: $dir not searchable (executable)!"; + $dir =~ /^(.*)$/; + $1; +} + +=item config + +Returns the configuration value or values (depending on context) for key. + +=cut + +sub config { + my($self,$file)=@_; + my($dir)=$self->dir; + my $fh = new IO::File "<$dir/$file" or return; + if ( wantarray ) { + map { + /^(.*)$/ + or die "Illegal line (array context) in $dir/$file:\n$_\n"; + $1; + } <$fh>; + } else { + <$fh> =~ /^(.*)$/ + or die "Illegal line (scalar context) in $dir/$file:\n$_\n"; + $1; + } +} + +=item exists + +Returns true if the specified key exists, even if the corresponding value +is undefined. + +=cut + +sub exists { + my($self,$file)=@_; + my($dir) = $self->dir; + -e "$dir/$file"; +} + +=item touch + +=cut + +sub touch { + my($self, $file) = @_; + my $dir = $self->dir; + unless ( $self->exists($file) ) { + warn "[FS::Conf] TOUCH $file\n" if $DEBUG; + system('touch', "$dir/$file"); + } +} + +=item set + +=cut + +sub set { + my($self, $file, $value) = @_; + my $dir = $self->dir; + $value =~ /^(.*)$/s; + $value = $1; + unless ( $self->config($file) eq $value ) { + warn "[FS::Conf] SET $file\n" if $DEBUG; +# warn "$dir" if is_tainted($dir); +# warn "$dir" if is_tainted($file); + chmod 0644, "$dir/$file"; + my $fh = new IO::File ">$dir/$file" or return; + chmod 0644, "$dir/$file"; + print $fh "$value\n"; + } +} +#sub is_tainted { +# return ! eval { join('',@_), kill 0; 1; }; +# } + +=item delete + +=cut + +sub delete { + my($self, $file) = @_; + my $dir = $self->dir; + if ( $self->exists($file) ) { + warn "[FS::Conf] DELETE $file\n"; + unlink "$dir/$file"; + } +} + +=item config_items + +Returns all of the possible configuration items as FS::ConfItem objects. See +L. + +=cut + +sub config_items { +# my $self = shift; + @config_items; +} + +=back + +=head1 BUGS + +Write access (touch, set, delete) should be documented. + +If this was more than just crud that will never be useful outside Freeside I'd +worry that config_items is freeside-specific and icky. + +=head1 SEE ALSO + +"Configuration" in the web interface (config/config.cgi). + +httemplate/docs/config.html + +=cut + +@config_items = map { new FS::ConfItem $_ } ( + + { + 'key' => 'address', + 'section' => 'depreciated', + 'description' => 'This configuration option is no longer used. See invoice_template instead.', + 'type' => 'text', + }, + + { + 'key' => 'apacheroot', + 'section' => 'apache', + 'description' => 'The directory containing Apache virtual hosts', + 'type' => 'text', + }, + + { + 'key' => 'apacheip', + 'section' => 'apache', + 'description' => 'The current IP address to assign to new virtual hosts', + 'type' => 'text', + }, + + { + 'key' => 'apachemachine', + 'section' => 'apache', + 'description' => 'A machine with the apacheroot directory and user home directories. The existance of this file enables setup of virtual host directories, and, in conjunction with the `home\' configuration file, symlinks into user home directories.', + 'type' => 'text', + }, + + { + 'key' => 'apachemachines', + 'section' => 'apache', + 'description' => 'Your Apache machines, one per line. This enables export of `/etc/apache/vhosts.conf\', which can be included in your Apache configuration via the Include directive.', + 'type' => 'textarea', + }, + + { + 'key' => 'bindprimary', + 'section' => 'BIND', + 'description' => 'Your BIND primary nameserver. This enables export of /var/named/named.conf and zone files into /var/named', + 'type' => 'text', + }, + + { + 'key' => 'bindsecondaries', + 'section' => 'BIND', + 'description' => 'Your BIND secondary nameservers, one per line. This enables export of /var/named/named.conf', + 'type' => 'textarea', + }, + + { + 'key' => 'business-onlinepayment', + 'section' => 'billing', + 'description' => 'Business::OnlinePayment 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.', + 'type' => 'textarea', + }, + + { + 'key' => 'bsdshellmachines', + 'section' => 'shell', + 'description' => 'Your BSD flavored shell (and mail) machines, one per line. This enables export of `/etc/passwd\' and `/etc/master.passwd\'.', + 'type' => 'textarea', + }, + + { + 'key' => 'countrydefault', + 'section' => 'UI', + 'description' => 'Default two-letter country code (if not supplied, the default is `US\')', + 'type' => 'text', + }, + + { + 'key' => 'cybercash3.2', + 'section' => 'billing', + 'description' => 'CyberCash Cashregister v3.2 support. Two lines: the full path and name of your merchant_conf file, and the transaction type (`mauthonly\' or `mauthcapture\').', + 'type' => 'textarea', + }, + + { + 'key' => 'cyrus', + 'section' => 'mail', + 'description' => 'Integration with Cyrus IMAP Server, three lines: IMAP server, admin username, and admin password. Cyrus::IMAP::Admin should be installed locally and the connection to the server secured.', + 'type' => 'textarea', + }, + + { + 'key' => 'cp_app', + 'section' => 'mail', + 'description' => 'Integration with Critial Path Account Provisioning Protocol, four lines: "host:port", username, password, and workgroup (for new users).', + 'type' => 'textarea', + }, + + { + 'key' => 'deletecustomers', + 'section' => 'UI', + '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.', + 'type' => 'checkbox', + }, + + { + 'key' => 'deletepayments', + 'section' => 'UI', + 'description' => 'Enable deletion of unclosed payments. Be very careful! Only delete payments that were data-entry errors, not adjustments.', + 'type' => 'checkbox', + }, + + { + 'key' => 'dirhash', + 'section' => 'shell', + '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:

  • 1: user -> /home/u/user
  • 2: user -> /home/u/s/user
  • -1: user -> /home/r/user
  • -2: user -> home/r/e/user
', + 'type' => 'text', + }, + + { + 'key' => 'disable_customer_referrals', + 'section' => 'UI', + 'description' => 'Disable new customer-to-customer referrals in the web interface', + 'type' => 'checkbox', + }, + + { + 'key' => 'domain', + 'section' => 'depreciated', + 'description' => 'Your domain name.', + 'type' => 'text', + }, + + { + 'key' => 'editreferrals', + 'section' => 'UI', + 'description' => 'Enable referral modification for existing customers', + 'type' => 'checkbox', + }, + + { + 'key' => 'emailinvoiceonly', + 'section' => 'billing', + 'description' => 'Disables postal mail invoices', + 'type' => 'checkbox', + }, + + { + 'key' => 'disablepostalinvoicedefault', + 'section' => 'billing', + 'description' => 'Disables postal mail invoices as the default option in the UI. Be careful not to setup customers which are not sent invoices. See emailinvoiceauto.', + 'type' => 'checkbox', + }, + + { + 'key' => 'emailinvoiceauto', + 'section' => 'billing', + 'description' => 'Automatically adds new accounts to the email invoice list upon customer creation', + 'type' => 'checkbox', + }, + + { + 'key' => 'erpcdmachines', + 'section' => '', + 'description' => 'Your ERPCD authenticaion machines, one per line. This enables export of `/usr/annex/acp_passwd\' and `/usr/annex/acp_dialup\'', + 'type' => 'textarea', + }, + + { + 'key' => 'hidecancelledpackages', + 'section' => 'UI', + 'description' => 'Prevent cancelled packages from showing up in listings (though they will still be in the database)', + 'type' => 'checkbox', + }, + + { + 'key' => 'hidecancelledcustomers', + 'section' => 'UI', + 'description' => 'Prevent customers with only cancelled packages from showing up in listings (though they will still be in the database)', + 'type' => 'checkbox', + }, + + { + 'key' => 'home', + 'section' => 'required', + 'description' => 'For new users, prefixed to username to create a directory name. Should have a leading but not a trailing slash.', + 'type' => 'text', + }, + + { + 'key' => 'icradiusmachines', + 'section' => 'radius', + 'description' => 'Turn this option on to enable radcheck and radreply table population - by default in the Freeside database, or in the database specified by the icradius_secrets config option (the radcheck and radreply tables needs to be created manually). You do not need to use MySQL for your Freeside database to export to an ICRADIUS/FreeRADIUS MySQL database with this option.
ADDITIONAL DEPRECATED FUNCTIONALITY (instead use MySQL replication or point icradius_secrets to the external database) - your ICRADIUS machines or FreeRADIUS (with MySQL authentication) machines, one per line. Machines listed in this file will have the radcheck table exported to them. Each line should contain four items, separted by whitespace: machine name, MySQL database name, MySQL username, and MySQL password. For example: "radius.isp.tld radius_db radius_user passw0rd"
', + 'type' => [qw( checkbox textarea )], + }, + + { + 'key' => 'icradius_mysqldest', + 'section' => 'radius', + 'description' => 'DEPRECATED (instead use MySQL replication or point icradius_secrets to the external database) - Destination directory for the MySQL databases, on the ICRADIUS/FreeRADIUS machines. Defaults to "/usr/local/var/".', + 'type' => 'text', + }, + + { + 'key' => 'icradius_mysqlsource', + 'section' => 'radius', + 'description' => 'DEPRECATED (instead use MySQL replication or point icradius_secrets to the external database) - Source directory for for the MySQL radcheck table files, on the Freeside machine. Defaults to "/usr/local/var/freeside".', + 'type' => 'text', + }, + + { + 'key' => 'icradius_secrets', + 'section' => 'radius', + 'description' => 'Optionally specifies a database for ICRADIUS/FreeRADIUS export. Three lines: DBI data source, username and password.', + 'type' => 'textarea', + }, + + { + 'key' => 'invoice_from', + 'section' => 'required', + 'description' => 'Return address on email invoices', + 'type' => 'text', + }, + + { + 'key' => 'invoice_template', + 'section' => 'required', + 'description' => 'Required template file for invoices. See the billing documentation for details.', + 'type' => 'textarea', + }, + + { + 'key' => 'lpr', + 'section' => 'required', + 'description' => 'Print command for paper invoices, for example `lpr -h\'', + 'type' => 'text', + }, + + { + 'key' => 'maildisablecatchall', + 'section' => 'depreciated', + 'description' => 'DEPRECIATED, now the default. Turning this option on used to disable the requirement that each virtual domain have a catch-all mailbox.', + 'type' => 'checkbox', + }, + + { + 'key' => 'money_char', + 'section' => '', + 'description' => 'Currency symbol - defaults to `$\'', + 'type' => 'text', + }, + + { + 'key' => 'mxmachines', + 'section' => 'BIND', + 'description' => 'MX entries for new domains, weight and machine, one per line, with trailing `.\'', + 'type' => 'textarea', + }, + + { + 'key' => 'nsmachines', + 'section' => 'BIND', + 'description' => 'NS nameservers for new domains, one per line, with trailing `.\'', + 'type' => 'textarea', + }, + + { + 'key' => 'nismachines', + 'section' => 'shell', + 'description' => 'Your NIS master (not slave master) machines, one per line. This enables export of `/etc/global/passwd\' and `/etc/global/shadow\'.', + 'type' => 'textarea', + }, + + { + 'key' => 'passwordmin', + 'section' => 'password', + 'description' => 'Minimum password length (default 6)', + 'type' => 'text', + }, + + { + 'key' => 'passwordmax', + 'section' => 'password', + 'description' => 'Maximum password length (default 8) (don\'t set this over 12 if you need to import or export crypt() passwords)', + 'type' => 'text', + }, + + { + 'key' => 'qmailmachines', + 'section' => 'mail', + 'description' => 'Your qmail machines, one per line. This enables export of `/var/qmail/control/virtualdomains\', `/var/qmail/control/recipientmap\', and `/var/qmail/control/rcpthosts\'. Setting this option (even if empty) also turns on user `.qmail-extension\' file maintenance in conjunction with the shellmachine option.', + 'type' => [qw( checkbox textarea )], + }, + + { + 'key' => 'radiusmachines', + 'section' => 'radius', + 'description' => 'Your RADIUS authentication machines, one per line. This enables export of `/etc/raddb/users\'.', + 'type' => 'textarea', + }, + + { + 'key' => 'referraldefault', + 'section' => 'UI', + 'description' => 'Default referral, specified by refnum', + 'type' => 'text', + }, + +# { +# 'key' => 'registries', +# 'section' => 'required', +# 'description' => 'Directory which contains domain registry information. Each registry is a directory.', +# }, + + { + 'key' => 'maxsearchrecordsperpage', + 'section' => 'UI', + 'description' => 'If set, number of search records to return per page.', + 'type' => 'text', + }, + + { + 'key' => 'sendmailconfigpath', + 'section' => 'mail', + 'description' => 'Sendmail configuration file path. Defaults to `/etc\'. Many newer distributions use `/etc/mail\'.', + 'type' => 'text', + }, + + { + 'key' => 'sendmailmachines', + 'section' => 'mail', + 'description' => 'Your sendmail machines, one per line. This enables export of `/etc/virtusertable\' and `/etc/sendmail.cw\'.', + 'type' => 'textarea', + }, + + { + 'key' => 'sendmailrestart', + 'section' => 'mail', + 'description' => 'If defined, the command which is run on sendmail machines after files are copied.', + 'type' => 'text', + }, + + { + 'key' => 'session-start', + 'section' => 'session', + '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: $ip, $nasip and $nasfqdn, 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.', + 'type' => 'text', + }, + + { + 'key' => 'session-stop', + 'section' => 'session', + '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: $ip, $nasip and $nasfqdn, 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.', + 'type' => 'text', + }, + + { + 'key' => 'shellmachine', + 'section' => 'shell', + 'description' => 'A single machine with user home directories mounted. This enables home directory creation, renaming and archiving/deletion. In conjunction with `qmailmachines\', it also enables `.qmail-extension\' file maintenance.', + 'type' => 'text', + }, + + { + 'key' => 'shellmachine-useradd', + 'section' => 'shell', + 'description' => 'The command(s) to run on shellmachine when an account is created. If the shellmachine option is set but this option is not, useradd -d $dir -m -s $shell -u $uid $username is the default. If this option is set but empty, cp -pr /etc/skel $dir; chown -R $uid.$gid $dir is the default instead. Otherwise the value is evaluated as a double-quoted perl string, with the following variables available: $username, $uid, $gid, $dir, and $shell.', + 'type' => [qw( checkbox text )], + }, + + { + 'key' => 'shellmachine-userdel', + 'section' => 'shell', + 'description' => 'The command(s) to run on shellmachine when an account is deleted. If the shellmachine option is set but this option is not, userdel $username is the default. If this option is set but empty, rm -rf $dir is the default instead. Otherwise the value is evaluated as a double-quoted perl string, with the following variables available: $username and $dir.', + 'type' => [qw( checkbox text )], + }, + + { + 'key' => 'shellmachine-usermod', + 'section' => 'shell', + 'description' => 'The command(s) to run on shellmachine when an account is modified. If the shellmachine option is set but this option is empty, [ -d $old_dir ] && mv $old_dir $new_dir || ( chmod u+t $old_dir; mkdir $new_dir; cd $old_dir; find . -depth -print | cpio -pdm $new_dir; chmod u-t $new_dir; chown -R $uid.$gid $new_dir; rm -rf $old_dir ) is the default. Otherwise the contents of the file are treated as a double-quoted perl string, with the following variables available: $old_dir, $new_dir, $uid and $gid.', + #'type' => [qw( checkbox text )], + 'type' => 'text', + }, + + { + 'key' => 'shellmachines', + 'section' => 'shell', + 'description' => 'Your Linux and System V flavored shell (and mail) machines, one per line. This enables export of `/etc/passwd\' and `/etc/shadow\' files.', + 'type' => 'textarea', + }, + + { + 'key' => 'shells', + 'section' => 'required', + '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.', + 'type' => 'textarea', + }, + + { + 'key' => 'showpasswords', + 'section' => 'UI', + 'description' => 'Display unencrypted user passwords in the web interface', + 'type' => 'checkbox', + }, + + { + 'key' => 'signupurl', + 'section' => 'UI', + 'description' => 'if you are using customer-to-customer referrals, and you enter the URL of your signup server CGI, the customer view screen will display a customized link to the signup server with the appropriate customer as referral', + 'type' => 'text', + }, + + { + 'key' => 'smtpmachine', + 'section' => 'required', + 'description' => 'SMTP relay for Freeside\'s outgoing mail', + 'type' => 'text', + }, + + { + 'key' => 'soadefaultttl', + 'section' => 'BIND', + 'description' => 'SOA default TTL for new domains.', + 'type' => 'text', + }, + + { + 'key' => 'soaemail', + 'section' => 'BIND', + 'description' => 'SOA email for new domains, in BIND form (`.\' instead of `@\'), with trailing `.\'', + 'type' => 'text', + }, + + { + 'key' => 'soaexpire', + 'section' => 'BIND', + 'description' => 'SOA expire for new domains', + 'type' => 'text', + }, + + { + 'key' => 'soamachine', + 'section' => 'BIND', + 'description' => 'SOA machine for new domains, with trailing `.\'', + 'type' => 'text', + }, + + { + 'key' => 'soarefresh', + 'section' => 'BIND', + 'description' => 'SOA refresh for new domains', + 'type' => 'text', + }, + + { + 'key' => 'soaretry', + 'section' => 'BIND', + 'description' => 'SOA retry for new domains', + 'type' => 'text', + }, + + { + 'key' => 'statedefault', + 'section' => 'UI', + 'description' => 'Default state or province (if not supplied, the default is `CA\')', + 'type' => 'text', + }, + + { + 'key' => 'radiusprepend', + 'section' => 'radius', + 'description' => 'The contents will be prepended to the top of the RADIUS users file (text exports only).', + 'type' => 'textarea', + }, + + { + 'key' => 'textradiusprepend', + 'section' => 'depreciated', + 'description' => 'DEPRECIATED, use RADIUS check attributes instead. This option will be removed soon. The contents will be prepended to the first line of a user\'s RADIUS entry in text exports.', + 'type' => 'text', + }, + + { + 'key' => 'unsuspendauto', + 'section' => 'billing', + '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', + 'type' => 'checkbox', + }, + + { + 'key' => 'usernamemin', + 'section' => 'username', + 'description' => 'Minimum username length (default 2)', + 'type' => 'text', + }, + + { + 'key' => 'usernamemax', + 'section' => 'username', + 'description' => 'Maximum username length', + 'type' => 'text', + }, + + { + 'key' => 'username-ampersand', + 'section' => 'username', + 'description' => 'Allow the ampersand character (&) in usernames. Be careful when using this option in conjunction with shellmachine-useradd and other configuration options which execute shell commands, as the ampersand will be interpreted by the shell if not quoted.', + 'type' => 'checkbox', + }, + + { + 'key' => 'username-letter', + 'section' => 'username', + 'description' => 'Usernames must contain at least one letter', + 'type' => 'checkbox', + }, + + { + 'key' => 'username-letterfirst', + 'section' => 'username', + 'description' => 'Usernames must start with a letter', + 'type' => 'checkbox', + }, + + { + 'key' => 'username-noperiod', + 'section' => 'username', + 'description' => 'Disallow periods in usernames', + 'type' => 'checkbox', + }, + + { + 'key' => 'username-uppercase', + 'section' => 'username', + 'description' => 'Allow uppercase characters in usernames', + 'type' => 'checkbox', + }, + + { + 'key' => 'username_policy', + 'section' => '', + 'description' => 'This file controls the mechanism for preventing duplicate usernames in passwd/radius files exported from svc_accts. This should be one of \'prepend domsvc\' \'append domsvc\' \'append domain\' or \'append @domain\'', + 'type' => 'select', + 'select_enum' => [ 'prepend domsvc', 'append domsvc', 'append domain', 'append @domain' ], + #'type' => 'text', + }, + + { + 'key' => 'vpopmailmachines', + 'section' => 'mail', + 'description' => 'Your vpopmail pop toasters, one per line. Each line is of the form "machinename vpopdir vpopuid vpopgid". For example: poptoaster.domain.tld /home/vpopmail 508 508 Note: vpopuid and vpopgid are values taken from the vpopmail machine\'s /etc/passwd', + 'type' => 'textarea', + }, + + { + 'key' => 'vpopmailrestart', + 'section' => 'mail', + 'description' => 'If defined, the shell commands to run on vpopmail machines after files are copied. An example can be found in eg/vpopmailrestart of the source distribution.', + 'type' => 'textarea', + }, + + { + 'key' => 'safe-part_pkg', + 'section' => 'UI', + 'description' => 'Validates package definition setup and recur expressions against a preset list. Useful for webdemos, annoying to powerusers.', + 'type' => 'checkbox', + }, + + { + 'key' => 'safe-part_bill_event', + 'section' => 'UI', + 'description' => 'Validates invoice event expressions against a preset list. Useful for webdemos, annoying to powerusers.', + 'type' => 'checkbox', + }, + + { + 'key' => 'show_ss', + 'section' => 'UI', + 'description' => 'Turns on display/collection of SS# in the web interface.', + 'type' => 'checkbox', + }, + + { + 'key' => 'agent_defaultpkg', + 'section' => 'UI', + 'description' => 'Setting this option will cause new packages to be available to all agent types by default.', + 'type' => 'checkbox', + }, + + { + 'key' => 'legacy_link', + 'section' => 'UI', + 'description' => 'Display options in the web interface to link legacy pre-Freeside services.', + 'type' => 'checkbox', + }, + +); + +1; + diff --git a/FS/FS/ConfItem.pm b/FS/FS/ConfItem.pm new file mode 100644 index 000000000..83295b4fa --- /dev/null +++ b/FS/FS/ConfItem.pm @@ -0,0 +1,63 @@ +package FS::ConfItem; + +=head1 NAME + +FS::ConfItem - Configutaion option meta-data. + +=head1 SYNOPSIS + + use FS::Conf; + @config_items = $conf->config_items; + + foreach $item ( @config_items ) { + $key = $item->key; + $section = $item->section; + $description = $item->description; + } + +=head1 DESCRIPTION + +=head1 METHODS + +=over 4 + +=item new + +=cut + +sub new { + my $proto = shift; + my $class = ref($proto) || $proto; + my $self = @_ ? shift : {}; + bless ($self, $class); +} + +=item key + +=item section + +=item description + +=cut + +sub AUTOLOAD { + my $self = shift; + my $field = $AUTOLOAD; + $field =~ s/.*://; + $self->{$field}; +} + +=back + +=head1 BUGS + +Terse docs. + +=head1 SEE ALSO + +L + +=cut + +1; + diff --git a/FS/FS/Record.pm b/FS/FS/Record.pm new file mode 100644 index 000000000..f30223351 --- /dev/null +++ b/FS/FS/Record.pm @@ -0,0 +1,1178 @@ +package FS::Record; + +use strict; +use vars qw( $dbdef_file $dbdef $setup_hack $AUTOLOAD @ISA @EXPORT_OK $DEBUG + $me ); +use subs qw(reload_dbdef); +use Exporter; +use Carp qw(carp cluck croak confess); +use File::CounterFile; +use Locale::Country; +use DBI qw(:sql_types); +use DBIx::DBSchema 0.19; +use FS::UID qw(dbh checkruid getotaker datasrc driver_name); +use FS::SearchCache; + +@ISA = qw(Exporter); +@EXPORT_OK = qw(dbh fields hfields qsearch qsearchs dbdef jsearch); + +$DEBUG = 0; +$me = '[FS::Record]'; + +#ask FS::UID to run this stuff for us later +$FS::UID::callback{'FS::Record'} = sub { + $File::CounterFile::DEFAULT_DIR = "/usr/local/etc/freeside/counters.". datasrc; + $dbdef_file = "/usr/local/etc/freeside/dbdef.". datasrc; + &reload_dbdef unless $setup_hack; #$setup_hack needed now? +}; + +=head1 NAME + +FS::Record - Database record objects + +=head1 SYNOPSIS + + use FS::Record; + use FS::Record qw(dbh fields qsearch qsearchs dbdef); + + $record = new FS::Record 'table', \%hash; + $record = new FS::Record 'table', { 'column' => 'value', ... }; + + $record = qsearchs FS::Record 'table', \%hash; + $record = qsearchs FS::Record 'table', { 'column' => 'value', ... }; + @records = qsearch FS::Record 'table', \%hash; + @records = qsearch FS::Record 'table', { 'column' => 'value', ... }; + + $table = $record->table; + $dbdef_table = $record->dbdef_table; + + $value = $record->get('column'); + $value = $record->getfield('column'); + $value = $record->column; + + $record->set( 'column' => 'value' ); + $record->setfield( 'column' => 'value' ); + $record->column('value'); + + %hash = $record->hash; + + $hashref = $record->hashref; + + $error = $record->insert; + #$error = $record->add; #deprecated + + $error = $record->delete; + #$error = $record->del; #deprecated + + $error = $new_record->replace($old_record); + #$error = $new_record->rep($old_record); #deprecated + + $value = $record->unique('column'); + + $error = $record->ut_float('column'); + $error = $record->ut_number('column'); + $error = $record->ut_numbern('column'); + $error = $record->ut_money('column'); + $error = $record->ut_text('column'); + $error = $record->ut_textn('column'); + $error = $record->ut_alpha('column'); + $error = $record->ut_alphan('column'); + $error = $record->ut_phonen('column'); + $error = $record->ut_anything('column'); + $error = $record->ut_name('column'); + + $dbdef = reload_dbdef; + $dbdef = reload_dbdef "/non/standard/filename"; + $dbdef = dbdef; + + $quoted_value = _quote($value,'table','field'); + + #depriciated + $fields = hfields('table'); + if ( $fields->{Field} ) { # etc. + + @fields = fields 'table'; #as a subroutine + @fields = $record->fields; #as a method call + + +=head1 DESCRIPTION + +(Mostly) object-oriented interface to database records. Records are currently +implemented on top of DBI. FS::Record is intended as a base class for +table-specific classes to inherit from, i.e. FS::cust_main. + +=head1 CONSTRUCTORS + +=over 4 + +=item new [ TABLE, ] HASHREF + +Creates a new record. It doesn't store it in the database, though. See +L<"insert"> for that. + +Note that the object stores this hash reference, not a distinct copy of the +hash it points to. You can ask the object for a copy with the I +method. + +TABLE can only be omitted when a dervived class overrides the table method. + +=cut + +sub new { + my $proto = shift; + my $class = ref($proto) || $proto; + my $self = {}; + bless ($self, $class); + + unless ( defined ( $self->table ) ) { + $self->{'Table'} = shift; + carp "warning: FS::Record::new called with table name ". $self->{'Table'}; + } + + my $hashref = $self->{'Hash'} = shift; + + foreach my $field ( $self->fields ) { + $hashref->{$field}='' unless defined $hashref->{$field}; + #trim the '$' and ',' from money fields for Pg (belong HERE?) + #(what about Pg i18n?) + if ( driver_name =~ /^Pg$/i + && $self->dbdef_table->column($field)->type eq 'money' ) { + ${$hashref}{$field} =~ s/^\$//; + ${$hashref}{$field} =~ s/\,//; + } + } + + $self->_cache($hashref, shift) if $self->can('_cache') && @_; + + $self; +} + +sub new_or_cached { + my $proto = shift; + my $class = ref($proto) || $proto; + my $self = {}; + bless ($self, $class); + + $self->{'Table'} = shift unless defined ( $self->table ); + + my $hashref = $self->{'Hash'} = shift; + my $cache = shift; + if ( defined( $cache->cache->{$hashref->{$cache->key}} ) ) { + my $obj = $cache->cache->{$hashref->{$cache->key}}; + $obj->_cache($hashref, $cache) if $obj->can('_cache'); + $obj; + } else { + $cache->cache->{$hashref->{$cache->key}} = $self->new($hashref, $cache); + } + +} + +sub create { + my $proto = shift; + my $class = ref($proto) || $proto; + my $self = {}; + bless ($self, $class); + if ( defined $self->table ) { + cluck "create constructor is depriciated, use new!"; + $self->new(@_); + } else { + croak "FS::Record::create called (not from a subclass)!"; + } +} + +=item qsearch TABLE, HASHREF, SELECT, EXTRA_SQL, CACHE_OBJ + +Searches the database for all records matching (at least) the key/value pairs +in HASHREF. Returns all the records found as `FS::TABLE' objects if that +module is loaded (i.e. via `use FS::cust_main;'), otherwise returns FS::Record +objects. + +###oops, argh, FS::Record::new only lets us create database fields. +#Normal behaviour if SELECT is not specified is `*', as in +#C!. + qq!