4 use vars qw( @ISA @EXPORT_OK );
8 use Crypt::OpenSSL::RSA;
9 use FS::UID qw( dbh driver_name );
13 $FS::svc_domain::whois_hack = 1;
14 $FS::svc_domain::whois_hack = 1;
16 @ISA = qw( Exporter );
17 @EXPORT_OK = qw( create_initial_data enable_encryption );
21 FS::Setup - Database setup
29 Currently this module simply provides a place to store common subroutines for
40 sub create_initial_data {
43 my $oldAutoCommit = $FS::UID::AutoCommit;
44 local $FS::UID::AutoCommit = 0;
45 $FS::UID::AutoCommit = 0;
52 populate_initial_data(%opt);
62 if ( $oldAutoCommit ) {
63 dbh->commit or die dbh->errstr;
68 sub enable_encryption {
73 my $conf = new FS::Conf;
75 die "encryption key(s) already in place"
76 if $conf->exists('encryptionpublickey')
77 || $conf->exists('encryptionprivatekey');
80 my $rsa = Crypt::OpenSSL::RSA->generate_key($length);
82 $conf->set('encryption', 1);
83 $conf->set('encryptionmodule', 'Crypt::OpenSSL::RSA');
84 $conf->set('encryptionpublickey', $rsa->get_public_key_string );
85 $conf->set('encryptionprivatekey', $rsa->get_private_key_string );
89 sub populate_numbering {
90 eval "use FS::lata_Data;"; # this automatically populates the lata table, if unpopulated
91 eval "use FS::msa_Data;"; # this automatically populates the msa table, if unpopulated
94 sub populate_locales {
97 use FS::cust_main_county;
100 foreach my $country ( sort map uc($_), all_country_codes ) {
101 _add_country($country);
106 sub populate_addl_locales {
110 'FM' => 'Federated States of Micronesia',
111 'MH' => 'Marshall Islands',
113 'AA' => "Armed Forces Americas (except Canada)",
114 'AE' => "Armed Forces Europe / Canada / Middle East / Africa",
115 'AP' => "Armed Forces Pacific",
119 foreach my $country ( keys %addl ) {
120 foreach my $state ( keys %{ $addl{$country} } ) {
121 # $longname = $addl{$country}{$state};
122 _add_locale( 'country'=>$country, 'state'=>$state);
130 use Locale::SubCountry 1.42;
132 my( $country ) = shift;
134 my $subcountry = eval { new Locale::SubCountry($country) };
135 my @states = $subcountry ? $subcountry->all_codes : undef;
137 if ( !scalar(@states) || ( scalar(@states)==1 && !defined($states[0]) ) ) {
139 _add_locale( 'country'=>$country );
143 if ( $states[0] =~ /^(\d+|\w)$/ ) {
144 @states = map $subcountry->full_name($_), @states
147 foreach my $state ( @states ) {
148 _add_locale( 'country'=>$country, 'state'=>$state);
156 my $cust_main_county = new FS::cust_main_county( { 'tax'=>0, @_ });
157 my $error = $cust_main_county->insert;
158 die $error if $error;
161 sub populate_duplock {
163 return unless driver_name =~ /^mysql/i;
165 my $sth = dbh->prepare(
166 "INSERT INTO duplicate_lock ( lockname ) VALUES ( 'svc_acct' )"
167 ) or die dbh->errstr;
169 $sth->execute or die $sth->errstr;
173 sub populate_initial_data {
176 my $data = initial_data(%opt);
178 foreach my $table ( keys %$data ) {
180 #warn "popuilating $table\n";
182 my $class = "FS::$table";
186 $class->_populate_initial_data(%opt)
187 if $class->can('_populate_initial_data');
189 my @records = @{ $data->{$table} };
191 foreach my $record ( @records ) {
193 my $args = delete($record->{'_insert_args'}) || [];
194 my $object = $class->new( $record );
195 my $error = $object->insert( @$args );
196 die "error inserting record into $table: $error\n"
199 #my $pkey = $object->primary_key;
200 #my $pkeyvalue = $object->$pkey();
201 #warn " inserted $pkeyvalue\n";
212 #tie my %hash, 'Tie::DxHash',
213 tie my %hash, 'Tie::IxHash',
217 { 'username' => 'fs_bootstrap',
218 '_password' => 'changeme', #will trigger warning if you try to enable
220 'first' => 'Bootstrap',
227 { 'groupname' => 'Superuser' },
233 #XXX need default new-style billing events
235 # 'part_bill_event' => [
236 # { 'payby' => 'CARD',
237 # 'event' => 'Batch card',
239 # 'eventcode' => '$cust_bill->batch_card(%options);',
241 # 'plan' => 'batch-card',
243 # { 'payby' => 'BILL',
244 # 'event' => 'Send invoice',
246 # 'eventcode' => '$cust_bill->send();',
250 # { 'payby' => 'DCRD',
251 # 'event' => 'Send invoice',
253 # 'eventcode' => '$cust_bill->send();',
257 # { 'payby' => 'DCHK',
258 # 'event' => 'Send invoice',
260 # 'eventcode' => '$cust_bill->send();',
264 # { 'payby' => 'DCLN',
265 # 'event' => 'Suspend',
267 # 'eventcode' => '$cust_bill->suspend();',
269 # 'plan' => 'suspend',
271 # #{ 'payby' => 'DCLN',
272 # # 'event' => 'Retriable',
274 # # 'eventcode' => '$cust_bill_event->retriable();',
276 # # 'plan' => 'retriable',
280 #you must create a service definition. An example of a service definition
281 #would be a dial-up account or a domain. First, it is necessary to create a
282 #domain definition. Click on View/Edit service definitions and Add a new
283 #service definition with Table svc_domain (and no modifiers).
286 'svcdb' => 'svc_domain',
290 #Now that you have created your first service, you must create a package
291 #including this service which you can sell to customers. Zero, one, or many
292 #services are bundled into a package. Click on View/Edit package
293 #definitions and Add a new package definition which includes quantity 1 of
294 #the svc_domain service you created above.
296 { 'pkg' => 'System Domain',
297 'comment' => '(NOT FOR CUSTOMERS)',
301 'pkg_svc' => { 1 => 1 }, # XXX
302 'primary_svc' => 1, #XXX
311 #After you create your first package, then you must define who is able to
312 #sell that package by creating an agent type. An example of an agent type
313 #would be an internal sales representitive which sells regular and
314 #promotional packages, as opposed to an external sales representitive
315 #which would only sell regular packages of services. Click on View/Edit
316 #agent types and Add a new agent type.
318 { 'atype' => 'Internal' },
321 #Allow this agent type to sell the package you created above.
323 { 'typenum' => 1, #XXX
328 #After creating a new agent type, you must create an agent. Click on
329 #View/Edit agents and Add a new agent.
331 { 'agent' => 'Internal',
332 'typenum' => 1, # XXX
336 #Set up at least one Advertising source. Advertising sources will help you
337 #keep track of how effective your advertising is, tracking where customers
338 #heard of your service offerings. You must create at least one advertising
339 #source. If you do not wish to use the referral functionality, simply
340 #create a single advertising source only. Click on View/Edit advertising
341 #sources and Add a new advertising source.
343 { 'referral' => 'Internal', },
346 #Click on New Customer and create a new customer for your system accounts
347 #with billing type Complimentary. Leave the First package dropdown set to
350 { 'agentnum' => 1, #XXX
353 'last' => 'Accounts',
354 'address1' => '1234 System Lane',
355 'city' => 'Systemtown',
360 'payinfo' => 'system', #or something
361 'paydate' => '1/2037',
365 #From the Customer View screen of the newly created customer, order the
366 #package you defined above.
368 { 'custnum' => 1, #XXX
373 #From the Package View screen of the newly created package, choose
374 #(Provision) to add the customer's service for this new package.
375 #Add your own domain.
377 { 'domain' => $opt{'domain'},
380 'action' => 'N', #pseudo-field
384 #Go back to View/Edit service definitions on the main menu, and Add a new
385 #service definition with Table svc_acct. Select your domain in the domsvc
386 #Modifier. Set Fixed to define a service locked-in to this domain, or
387 #Default to define a service which may select from among this domain and
388 #the customer's domains.
404 sub populate_access {
407 use FS::access_right;
409 foreach my $rightname ( FS::AccessRight->default_superuser_rights ) {
410 my $access_right = new FS::access_right {
411 'righttype' => 'FS::access_group',
412 'rightobjnum' => 1, #$supergroup->groupnum,
413 'rightname' => $rightname,
415 my $ar_error = $access_right->insert;
416 die $ar_error if $ar_error;
419 #foreach my $agent ( qsearch('agent', {} ) ) {
420 my $access_groupagent = new FS::access_groupagent {
421 'groupnum' => 1, #$supergroup->groupnum,
422 'agentnum' => 1, #$agent->agentnum,
424 my $aga_error = $access_groupagent->insert;
425 die $aga_error if $aga_error;
430 sub populate_msgcat {
432 use FS::Record qw(qsearch);
435 foreach my $del_msgcat ( qsearch('msgcat', {}) ) {
436 my $error = $del_msgcat->delete;
437 die $error if $error;
440 my %messages = FS::msgcat::_legacy_messages();
442 foreach my $msgcode ( keys %messages ) {
443 foreach my $locale ( keys %{$messages{$msgcode}} ) {
444 my $msgcat = new FS::msgcat( {
445 'msgcode' => $msgcode,
447 'msg' => $messages{$msgcode}{$locale},
449 my $error = $msgcat->insert;
450 die $error if $error;