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);
60 if ( $oldAutoCommit ) {
61 dbh->commit or die dbh->errstr;
66 sub enable_encryption {
71 my $conf = new FS::Conf;
73 die "encryption key(s) already in place"
74 if $conf->exists('encryptionpublickey')
75 || $conf->exists('encryptionprivatekey');
78 my $rsa = Crypt::OpenSSL::RSA->generate_key($length);
80 $conf->set('encryption', 1);
81 $conf->set('encryptionmodule', 'Crypt::OpenSSL::RSA');
82 $conf->set('encryptionpublickey', $rsa->get_public_key_string );
83 $conf->set('encryptionprivatekey', $rsa->get_private_key_string );
87 sub populate_numbering {
88 eval "use FS::lata_Data;"; # this automatically populates the lata table, if unpopulated
89 eval "use FS::msa_Data;"; # this automatically populates the msa table, if unpopulated
92 sub populate_locales {
95 use FS::cust_main_county;
98 foreach my $country ( sort map uc($_), all_country_codes ) {
99 _add_country($country);
104 sub populate_addl_locales {
108 'FM' => 'Federated States of Micronesia',
109 'MH' => 'Marshall Islands',
111 'AA' => "Armed Forces Americas (except Canada)",
112 'AE' => "Armed Forces Europe / Canada / Middle East / Africa",
113 'AP' => "Armed Forces Pacific",
117 foreach my $country ( keys %addl ) {
118 foreach my $state ( keys %{ $addl{$country} } ) {
119 # $longname = $addl{$country}{$state};
120 _add_locale( 'country'=>$country, 'state'=>$state);
128 use Locale::SubCountry 1.42;
130 my( $country ) = shift;
132 my $subcountry = eval { new Locale::SubCountry($country) };
133 my @states = $subcountry ? $subcountry->all_codes : undef;
135 if ( !scalar(@states) || ( scalar(@states)==1 && !defined($states[0]) ) ) {
137 _add_locale( 'country'=>$country );
141 if ( $states[0] =~ /^(\d+|\w)$/ ) {
142 @states = map $subcountry->full_name($_), @states
145 foreach my $state ( @states ) {
146 _add_locale( 'country'=>$country, 'state'=>$state);
154 my $cust_main_county = new FS::cust_main_county( { 'tax'=>0, @_ });
155 my $error = $cust_main_county->insert;
156 die $error if $error;
159 sub populate_duplock {
161 return unless driver_name =~ /^mysql/i;
163 my $sth = dbh->prepare(
164 "INSERT INTO duplicate_lock ( lockname ) VALUES ( 'svc_acct' )"
165 ) or die dbh->errstr;
167 $sth->execute or die $sth->errstr;
171 sub populate_initial_data {
174 my $data = initial_data(%opt);
176 foreach my $table ( keys %$data ) {
178 #warn "popuilating $table\n";
180 my $class = "FS::$table";
184 $class->_populate_initial_data(%opt)
185 if $class->can('_populate_initial_data');
187 my @records = @{ $data->{$table} };
189 foreach my $record ( @records ) {
191 my $args = delete($record->{'_insert_args'}) || [];
192 my $object = $class->new( $record );
193 my $error = $object->insert( @$args );
194 die "error inserting record into $table: $error\n"
197 #my $pkey = $object->primary_key;
198 #my $pkeyvalue = $object->$pkey();
199 #warn " inserted $pkeyvalue\n";
210 #tie my %hash, 'Tie::DxHash',
211 tie my %hash, 'Tie::IxHash',
215 { 'username' => 'fs_bootstrap',
216 '_password' => 'changeme', #will trigger warning if you try to enable
218 'first' => 'Bootstrap',
225 { 'groupname' => 'Superuser' },
231 #XXX need default new-style billing events
233 # 'part_bill_event' => [
234 # { 'payby' => 'CARD',
235 # 'event' => 'Batch card',
237 # 'eventcode' => '$cust_bill->batch_card(%options);',
239 # 'plan' => 'batch-card',
241 # { 'payby' => 'BILL',
242 # 'event' => 'Send invoice',
244 # 'eventcode' => '$cust_bill->send();',
248 # { 'payby' => 'DCRD',
249 # 'event' => 'Send invoice',
251 # 'eventcode' => '$cust_bill->send();',
255 # { 'payby' => 'DCHK',
256 # 'event' => 'Send invoice',
258 # 'eventcode' => '$cust_bill->send();',
262 # { 'payby' => 'DCLN',
263 # 'event' => 'Suspend',
265 # 'eventcode' => '$cust_bill->suspend();',
267 # 'plan' => 'suspend',
269 # #{ 'payby' => 'DCLN',
270 # # 'event' => 'Retriable',
272 # # 'eventcode' => '$cust_bill_event->retriable();',
274 # # 'plan' => 'retriable',
278 #you must create a service definition. An example of a service definition
279 #would be a dial-up account or a domain. First, it is necessary to create a
280 #domain definition. Click on View/Edit service definitions and Add a new
281 #service definition with Table svc_domain (and no modifiers).
284 'svcdb' => 'svc_domain',
288 #Now that you have created your first service, you must create a package
289 #including this service which you can sell to customers. Zero, one, or many
290 #services are bundled into a package. Click on View/Edit package
291 #definitions and Add a new package definition which includes quantity 1 of
292 #the svc_domain service you created above.
294 { 'pkg' => 'System Domain',
295 'comment' => '(NOT FOR CUSTOMERS)',
299 'pkg_svc' => { 1 => 1 }, # XXX
300 'primary_svc' => 1, #XXX
309 #After you create your first package, then you must define who is able to
310 #sell that package by creating an agent type. An example of an agent type
311 #would be an internal sales representitive which sells regular and
312 #promotional packages, as opposed to an external sales representitive
313 #which would only sell regular packages of services. Click on View/Edit
314 #agent types and Add a new agent type.
316 { 'atype' => 'Internal' },
319 #Allow this agent type to sell the package you created above.
321 { 'typenum' => 1, #XXX
326 #After creating a new agent type, you must create an agent. Click on
327 #View/Edit agents and Add a new agent.
329 { 'agent' => 'Internal',
330 'typenum' => 1, # XXX
334 #Set up at least one Advertising source. Advertising sources will help you
335 #keep track of how effective your advertising is, tracking where customers
336 #heard of your service offerings. You must create at least one advertising
337 #source. If you do not wish to use the referral functionality, simply
338 #create a single advertising source only. Click on View/Edit advertising
339 #sources and Add a new advertising source.
341 { 'referral' => 'Internal', },
344 #Click on New Customer and create a new customer for your system accounts
345 #with billing type Complimentary. Leave the First package dropdown set to
348 { 'agentnum' => 1, #XXX
351 'last' => 'Accounts',
352 'address1' => '1234 System Lane',
353 'city' => 'Systemtown',
358 'payinfo' => 'system', #or something
359 'paydate' => '1/2037',
363 #From the Customer View screen of the newly created customer, order the
364 #package you defined above.
366 { 'custnum' => 1, #XXX
371 #From the Package View screen of the newly created package, choose
372 #(Provision) to add the customer's service for this new package.
373 #Add your own domain.
375 { 'domain' => $opt{'domain'},
378 'action' => 'N', #pseudo-field
382 #Go back to View/Edit service definitions on the main menu, and Add a new
383 #service definition with Table svc_acct. Select your domain in the domsvc
384 #Modifier. Set Fixed to define a service locked-in to this domain, or
385 #Default to define a service which may select from among this domain and
386 #the customer's domains.
402 sub populate_access {
405 use FS::access_right;
407 foreach my $rightname ( FS::AccessRight->default_superuser_rights ) {
408 my $access_right = new FS::access_right {
409 'righttype' => 'FS::access_group',
410 'rightobjnum' => 1, #$supergroup->groupnum,
411 'rightname' => $rightname,
413 my $ar_error = $access_right->insert;
414 die $ar_error if $ar_error;
417 #foreach my $agent ( qsearch('agent', {} ) ) {
418 my $access_groupagent = new FS::access_groupagent {
419 'groupnum' => 1, #$supergroup->groupnum,
420 'agentnum' => 1, #$agent->agentnum,
422 my $aga_error = $access_groupagent->insert;
423 die $aga_error if $aga_error;
428 sub populate_msgcat {
430 use FS::Record qw(qsearch);
433 foreach my $del_msgcat ( qsearch('msgcat', {}) ) {
434 my $error = $del_msgcat->delete;
435 die $error if $error;
438 my %messages = FS::msgcat::_legacy_messages();
440 foreach my $msgcode ( keys %messages ) {
441 foreach my $locale ( keys %{$messages{$msgcode}} ) {
442 my $msgcat = new FS::msgcat( {
443 'msgcode' => $msgcode,
445 'msg' => $messages{$msgcode}{$locale},
447 my $error = $msgcat->insert;
448 die $error if $error;