session monitor
[freeside.git] / bin / fs-setup
1 #!/usr/bin/perl -Tw
2 #
3 # $Id: fs-setup,v 1.29 2000-11-07 15:00:37 ivan Exp $
4 #
5 # ivan@sisd.com 97-nov-8,9
6 #
7 # agent_type and type_pkgs added.
8 # (index need to be declared, & primary keys shoudln't have mysql syntax)
9 # ivan@sisd.com 97-nov-13
10 #
11 # pulled modified version back out of register.cgi ivan@sisd.com 98-feb-21
12 #
13 # removed extraneous sample data ivan@sisd.com 98-mar-23
14 #
15 # gained the big hash from dbdef.pm, dbdef.pm usage rewrite ivan@sisd.com
16 # 98-apr-19 - 98-may-11 plus
17 #
18 # finished up ivan@sisd.com 98-jun-1
19 #
20 # part_svc fields are all forced NULL, not the opposite
21 # hmm: also are forced varchar($char_d) as fixed '0' for things like
22 # uid is Not Good.  will this break anything else?
23 # ivan@sisd.com 98-jun-29
24 #
25 # ss is 11 chars ivan@sisd.com 98-jul-20
26 #
27 # setup of arbitrary radius fields ivan@sisd.com 98-aug-9
28 #
29 # ouch, removed index on company name that wasn't supposed to be there
30 # ivan@sisd.com 98-sep-4
31 #
32 # fix radius attributes ivan@sisd.com 98-sep-27
33 #
34 # $Log: fs-setup,v $
35 # Revision 1.29  2000-11-07 15:00:37  ivan
36 # session monitor
37 #
38 # Revision 1.28  2000/10/30 10:47:26  ivan
39 # nas.last can't be defined NULL if indexed
40 #
41 # Revision 1.26  2000/07/06 08:57:27  ivan
42 # support for radius check attributes (except importing).  poorly documented.
43 #
44 # Revision 1.25  2000/06/29 12:00:49  ivan
45 # support for pre-encrypted md5 passwords.
46 #
47 # Revision 1.24  2000/03/02 07:44:07  ivan
48 # typo forgot closing '
49 #
50 # Revision 1.23  2000/02/03 05:16:52  ivan
51 # beginning of DNS and Apache support
52 #
53 # Revision 1.22  2000/01/31 05:22:23  ivan
54 # prepaid "internet cards"
55 #
56 # Revision 1.21  2000/01/30 06:03:26  ivan
57 # postgres 6.5 finally supports decimal(10,2)
58 #
59 # Revision 1.20  2000/01/28 22:53:33  ivan
60 # track full phone number
61 #
62 # Revision 1.19  1999/07/29 08:50:35  ivan
63 # wrong type for cust_pay_batch.exp
64 #
65 # Revision 1.18  1999/04/15 22:46:30  ivan
66 # TT isn't a state!
67 #
68 # Revision 1.17  1999/04/14 07:58:39  ivan
69 # export getsecrets from FS::UID instead of calling it explicitly
70 #
71 # Revision 1.16  1999/02/28 19:44:16  ivan
72 # constructors s/create/new/ pointed out by "Bao C. Ha" <bao@hacom.net>
73 #
74 # Revision 1.15  1999/02/27 21:06:21  ivan
75 # cust_main.paydate should be varchar(10), not @date_type ; problem reported
76 # by Ben Leibig <leibig@colorado.edu>
77 #
78 # Revision 1.14  1999/02/07 09:59:14  ivan
79 # more mod_perl fixes, and bugfixes Peter Wemm sent via email
80 #
81 # Revision 1.13  1999/02/04 06:09:23  ivan
82 # add AU provences
83 #
84 # Revision 1.12  1999/02/03 10:42:27  ivan
85 # *** empty log message ***
86 #
87 # Revision 1.11  1999/01/17 03:11:52  ivan
88 # remove preliminary completehost changes
89 #
90 # Revision 1.10  1998/12/16 06:05:38  ivan
91 # add table cust_main_invoice
92 #
93 # Revision 1.9  1998/12/15 04:36:29  ivan
94 # s/croak/die/; #oops
95 #
96 # Revision 1.8  1998/12/15 04:33:27  ivan
97 # dies if it isn't running as the freeside user
98 #
99 # Revision 1.7  1998/11/18 09:01:31  ivan
100 # i18n! i18n!
101 #
102 # Revision 1.6  1998/11/15 13:18:02  ivan
103 # remove debugging
104 #
105 # Revision 1.5  1998/11/15 09:43:03  ivan
106 # update for new config file syntax, new adminsuidsetup
107 #
108 # Revision 1.4  1998/10/22 15:51:23  ivan
109 # also varchar with no length specified - postgresql fix broke mysql.
110 #
111 # Revision 1.3  1998/10/22 15:46:28  ivan
112 # now smallint is illegal, so remove that too.
113 #
114
115 #to delay loading dbdef until we're ready
116 BEGIN { $FS::Record::setup_hack = 1; }
117
118 use strict;
119 use DBI;
120 use FS::dbdef;
121 use FS::UID qw(adminsuidsetup datasrc checkeuid getsecrets);
122 use FS::Record;
123 use FS::cust_main_county;
124
125 die "Not running uid freeside!" unless checkeuid();
126
127 my $user = shift or die &usage;
128 getsecrets($user);
129
130 #needs to match FS::Record
131 my($dbdef_file) = "/usr/local/etc/freeside/dbdef.". datasrc;
132
133 ###
134
135 print "\nEnter the maximum username length: ";
136 my($username_len)=&getvalue;
137
138 print "\n\n", <<END, ":";
139 Freeside tracks the RADIUS attributes User-Name, check attribute Password and
140 reply attribute Framed-IP-Address for each user.  You can specify additional
141 check and reply attributes.  First enter any additional RADIUS check attributes
142 you need to track for each user, separated by whitespace.
143 END
144 my @check_attributes = map { s/\-/_/g; $_; } split(" ",&getvalue);
145
146 print "\n\n", <<END, ":";
147 Now enter any additional reply attributes you need to track for each user,
148 separated by whitespace.
149 END
150 my @attributes = map { s/\-/_/g; $_; } split(" ",&getvalue);
151
152 sub getvalue {
153   my($x)=scalar(<STDIN>);
154   chop $x;
155   $x;
156 }
157
158 ###
159
160 my($char_d) = 80; #default maxlength for text fields
161
162 #my(@date_type)  = ( 'timestamp', '', ''     );
163 my(@date_type)  = ( 'int', 'NULL', ''     );
164 my(@perl_type) = ( 'varchar', 'NULL', 255  ); 
165 my @money_type = ( 'decimal',   '', '10,2' );
166
167 ###
168 # create a dbdef object from the old data structure
169 ###
170
171 my(%tables)=&tables_hash_hack;
172
173 #turn it into objects
174 my($dbdef) = new FS::dbdef ( map {  
175   my(@columns);
176   while (@{$tables{$_}{'columns'}}) {
177     my($name,$type,$null,$length)=splice @{$tables{$_}{'columns'}}, 0, 4;
178     push @columns, new FS::dbdef_column ( $name,$type,$null,$length );
179   }
180   FS::dbdef_table->new(
181     $_,
182     $tables{$_}{'primary_key'},
183     #FS::dbdef_unique->new(@{$tables{$_}{'unique'}}),
184     #FS::dbdef_index->new(@{$tables{$_}{'index'}}),
185     FS::dbdef_unique->new($tables{$_}{'unique'}),
186     FS::dbdef_index->new($tables{$_}{'index'}),
187     @columns,
188   );
189 } (keys %tables) );
190
191 #add radius attributes to svc_acct
192
193 my($svc_acct)=$dbdef->table('svc_acct');
194
195 my($attribute);
196 foreach $attribute (@attributes) {
197   $svc_acct->addcolumn ( new FS::dbdef_column (
198     'radius_'. $attribute,
199     'varchar',
200     'NULL',
201     $char_d,
202   ));
203 }
204
205 foreach $attribute (@check_attributes) {
206   $svc_acct->addcolumn( new FS::dbdef_column (
207     'rc_'. $attribute,
208     'varchar',
209     'NULL',
210     $char_d,
211   ));
212 }
213
214 #make part_svc table (but now as object)
215
216 my($part_svc)=$dbdef->table('part_svc');
217
218 #because of svc_acct_pop
219 #foreach (grep /^svc_/, $dbdef->tables) { 
220 #foreach (qw(svc_acct svc_acct_sm svc_charge svc_domain svc_wo)) {
221 foreach (qw(svc_acct svc_acct_sm svc_domain svc_www)) {
222   my($table)=$dbdef->table($_);
223   my($col);
224   foreach $col ( $table->columns ) {
225     next if $col =~ /^svcnum$/;
226     $part_svc->addcolumn( new FS::dbdef_column (
227       $table->name. '__' . $table->column($col)->name,
228       'varchar', #$table->column($col)->type, 
229       'NULL',
230       $char_d, #$table->column($col)->length,
231     ));
232     $part_svc->addcolumn ( new FS::dbdef_column (
233       $table->name. '__'. $table->column($col)->name . "_flag",
234       'char',
235       'NULL',
236       1,
237     ));
238   }
239 }
240
241 #important
242 $dbdef->save($dbdef_file);
243 &FS::Record::reload_dbdef($dbdef_file);
244
245 ###
246 # create 'em
247 ###
248
249 my($dbh)=adminsuidsetup $user;
250
251 #create tables
252 $|=1;
253
254 my($table);
255 foreach  ($dbdef->tables) {
256   my($table)=$dbdef->table($_);
257   print "Creating $_...";
258
259   my($statement);
260
261   #create table
262   foreach $statement ($table->sql_create_table(datasrc)) {
263     #print $statement, "\n"; 
264     $dbh->do( $statement )
265       or die "CREATE error: ",$dbh->errstr, "\ndoing statement: $statement";
266   }
267
268   print "\n";
269 }
270
271 #not really sample data (and shouldn't default to US)
272
273 #cust_main_county
274
275 #USPS state codes
276 foreach ( qw(
277 AL AK AS AZ AR CA CO CT DC DE FM FL GA GU HI ID IL IN IA KS KY LA
278 ME MH MD MA MI MN MS MO MT NC ND NE NH NJ NM NV NY MP OH OK OR PA PW PR RI 
279 SC SD TN TX UT VT VI VA WA WV WI WY AE AA AP
280 ) ) {
281   my($cust_main_county)=new FS::cust_main_county({
282     'state' => $_,
283     'tax'   => 0,
284     'country' => 'US',
285   });  
286   my($error);
287   $error=$cust_main_county->insert;
288   die $error if $error;
289 }
290
291 #AU "offical" state codes ala mark.williamson@ebbs.com.au (Mark Williamson)
292 foreach ( qw(
293 VIC NSW NT QLD TAS ACT WA SA
294 ) ) {
295   my($cust_main_county)=new FS::cust_main_county({
296     'state' => $_,
297     'tax'   => 0,
298     'country' => 'AU',
299   });  
300   my($error);
301   $error=$cust_main_county->insert;
302   die $error if $error;
303 }
304
305 #ISO 2-letter country codes (same as country TLDs) except US and AU
306 foreach ( qw(
307 AF AL DZ AS AD AO AI AQ AG AR AM AW AT AZ BS BH BD BB BY BE BZ BJ BM BT BO
308 BA BW BV BR IO BN BG BF BI KH CM CA CV KY CF TD CL CN CX CC CO KM CG CK CR CI
309 HR CU CY CZ DK DJ DM DO TP EC EG SV GQ ER EE ET FK FO FJ FI FR FX GF PF TF GA
310 GM GE DE GH GI GR GL GD GP GU GT GN GW GY HT HM HN HK HU IS IN ID IR IQ IE IL
311 IT JM JP JO KZ KE KI KP KR KW KG LA LV LB LS LR LY LI LT LU MO MK MG MW MY MV
312 ML MT MH MQ MR MU YT MX FM MD MC MN MS MA MZ MM NA NR NP NL AN NC NZ NI NE NG
313 NU NF MP NO OM PK PW PA PG PY PE PH PN PL PT PR QA RE RO RU RW KN LC VC WS SM
314 ST SA SN SC SL SG SK SI SB SO ZA GS ES LK SH PM SD SR SJ SZ SE CH SY TW TJ TZ
315 TH TG TK TO TT TN TR TM TC TV UG UA AE GB UM UY UZ VU VA VE VN VG VI WF EH
316 YE YU ZR ZM ZW
317 ) ) {
318   my($cust_main_county)=new FS::cust_main_county({
319     'tax'   => 0,
320     'country' => $_,
321   });  
322   my($error);
323   $error=$cust_main_county->insert;
324   die $error if $error;
325 }
326
327 $dbh->disconnect or die $dbh->errstr;
328
329 sub usage {
330   die "Usage:\n  fs-setup user\n"; 
331 }
332
333 ###
334 # Now it becomes an object.  much better.
335 ###
336 sub tables_hash_hack {
337
338   #note that s/(date|change)/_$1/; to avoid keyword conflict.
339   #put a kludge in FS::Record to catch this or? (pry need some date-handling
340   #stuff anyway also)
341
342   my(%tables)=( #yech.}
343
344     'agent' => {
345       'columns' => [
346         'agentnum', 'int',            '',     '',
347         'agent',    'varchar',           '',     $char_d,
348         'typenum',  'int',            '',     '',
349         'freq',     'int',       'NULL', '',
350         'prog',     @perl_type,
351       ],
352       'primary_key' => 'agentnum',
353       'unique' => [ [] ],
354       'index' => [ ['typenum'] ],
355     },
356
357     'agent_type' => {
358       'columns' => [
359         'typenum',   'int',  '', '',
360         'atype',     'varchar', '', $char_d,
361       ],
362       'primary_key' => 'typenum',
363       'unique' => [ [] ],
364       'index' => [ [] ],
365     },
366
367     'type_pkgs' => {
368       'columns' => [
369         'typenum',   'int',  '', '',
370         'pkgpart',   'int',  '', '',
371       ],
372       'primary_key' => '',
373       'unique' => [ ['typenum', 'pkgpart'] ],
374       'index' => [ ['typenum'] ],
375     },
376
377     'cust_bill' => {
378       'columns' => [
379         'invnum',    'int',  '', '',
380         'custnum',   'int',  '', '',
381         '_date',     @date_type,
382         'charged',   @money_type,
383         'owed',      @money_type,
384         'printed',   'int',  '', '',
385       ],
386       'primary_key' => 'invnum',
387       'unique' => [ [] ],
388       'index' => [ ['custnum'] ],
389     },
390
391     'cust_bill_pkg' => {
392       'columns' => [
393         'pkgnum',  'int', '', '',
394         'invnum',  'int', '', '',
395         'setup',   @money_type,
396         'recur',   @money_type,
397         'sdate',   @date_type,
398         'edate',   @date_type,
399       ],
400       'primary_key' => '',
401       'unique' => [ ['pkgnum', 'invnum'] ],
402       'index' => [ ['invnum'] ],
403     },
404
405     'cust_credit' => {
406       'columns' => [
407         'crednum',  'int', '', '',
408         'custnum',  'int', '', '',
409         '_date',    @date_type,
410         'amount',   @money_type,
411         'credited', @money_type,
412         'otaker',   'varchar', '', 8,
413         'reason',   'varchar', '', 255,
414       ],
415       'primary_key' => 'crednum',
416       'unique' => [ [] ],
417       'index' => [ ['custnum'] ],
418     },
419
420     'cust_main' => {
421       'columns' => [
422         'custnum',  'int',  '',     '',
423         'agentnum', 'int',  '',     '',
424 #        'titlenum', 'int',  'NULL',   '',
425         'last',     'varchar', '',     $char_d,
426 #        'middle',   'varchar', 'NULL', $char_d,
427         'first',    'varchar', '',     $char_d,
428         'ss',       'char', 'NULL', 11,
429         'company',  'varchar', 'NULL', $char_d,
430         'address1', 'varchar', '',     $char_d,
431         'address2', 'varchar', 'NULL', $char_d,
432         'city',     'varchar', '',     $char_d,
433         'county',   'varchar', 'NULL', $char_d,
434         'state',    'varchar', 'NULL', $char_d,
435         'zip',      'varchar', '',     10,
436         'country',  'char', '',     2,
437         'daytime',  'varchar', 'NULL', 20,
438         'night',    'varchar', 'NULL', 20,
439         'fax',      'varchar', 'NULL', 12,
440         'payby',    'char', '',     4,
441         'payinfo',  'varchar', 'NULL', 16,
442         #'paydate',  @date_type,
443         'paydate',  'varchar', 'NULL', 10,
444         'payname',  'varchar', 'NULL', $char_d,
445         'tax',      'char', 'NULL', 1,
446         'otaker',   'varchar', '',     8,
447         'refnum',   'int',  '',     '',
448       ],
449       'primary_key' => 'custnum',
450       'unique' => [ [] ],
451       #'index' => [ ['last'], ['company'] ],
452       'index' => [ ['last'], ],
453     },
454
455     'cust_main_invoice' => {
456       'columns' => [
457         'destnum',  'int',  '',     '',
458         'custnum',  'int',  '',     '',
459         'dest',     'varchar', '',  $char_d,
460       ],
461       'primary_key' => 'destnum',
462       'unique' => [ [] ],
463       'index' => [ ['custnum'], ],
464     },
465
466     'cust_main_county' => { #county+state+country are checked off the
467                             #cust_main_county for validation and to provide
468                             # a tax rate.
469       'columns' => [
470         'taxnum',   'int',   '',    '',
471         'state',    'varchar',  'NULL',    $char_d,
472         'county',   'varchar',  'NULL',    $char_d,
473         'country',  'char',  '', 2, 
474         'tax',      'real',  '',    '', #tax %
475       ],
476       'primary_key' => 'taxnum',
477       'unique' => [ [] ],
478   #    'unique' => [ ['taxnum'], ['state', 'county'] ],
479       'index' => [ [] ],
480     },
481
482     'cust_pay' => {
483       'columns' => [
484         'paynum',   'int',    '',   '',
485         'invnum',   'int',    '',   '',
486         'paid',     @money_type,
487         '_date',    @date_type,
488         'payby',    'char',   '',     4, # CARD/BILL/COMP, should be index into
489                                          # payment type table.
490         'payinfo',  'varchar',   'NULL', 16,  #see cust_main above
491         'paybatch', 'varchar',   'NULL', $char_d, #for auditing purposes.
492       ],
493       'primary_key' => 'paynum',
494       'unique' => [ [] ],
495       'index' => [ ['invnum'] ],
496     },
497
498     'cust_pay_batch' => { #what's this used for again?  list of customers
499                           #in current CARD batch? (necessarily CARD?)
500       'columns' => [
501         'invnum',   'int',    '',   '',
502         'custnum',   'int',    '',   '',
503         'last',     'varchar', '',     $char_d,
504         'first',    'varchar', '',     $char_d,
505         'address1', 'varchar', '',     $char_d,
506         'address2', 'varchar', 'NULL', $char_d,
507         'city',     'varchar', '',     $char_d,
508         'state',    'varchar', '',     $char_d,
509         'zip',      'varchar', '',     10,
510         'country',  'char', '',     2,
511         'trancode', 'int', '', '',
512         'cardnum',  'varchar', '',     16,
513         #'exp',      @date_type,
514         'exp',      'varchar', '',     11,
515         'payname',  'varchar', 'NULL', $char_d,
516         'amount',   @money_type,
517       ],
518       'primary_key' => '',
519       'unique' => [ [] ],
520       'index' => [ ['invnum'], ['custnum'] ],
521     },
522
523     'cust_pkg' => {
524       'columns' => [
525         'pkgnum',    'int',    '',   '',
526         'custnum',   'int',    '',   '',
527         'pkgpart',   'int',    '',   '',
528         'otaker',    'varchar', '', 8,
529         'setup',     @date_type,
530         'bill',      @date_type,
531         'susp',      @date_type,
532         'cancel',    @date_type,
533         'expire',    @date_type,
534       ],
535       'primary_key' => 'pkgnum',
536       'unique' => [ [] ],
537       'index' => [ ['custnum'] ],
538     },
539
540     'cust_refund' => {
541       'columns' => [
542         'refundnum',    'int',    '',   '',
543         'crednum',      'int',    '',   '',
544         '_date',        @date_type,
545         'refund',       @money_type,
546         'otaker',       'varchar',   '',   8,
547         'reason',       'varchar',   '',   $char_d,
548         'payby',        'char',   '',     4, # CARD/BILL/COMP, should be index
549                                              # into payment type table.
550         'payinfo',      'varchar',   'NULL', 16,  #see cust_main above
551       ],
552       'primary_key' => 'refundnum',
553       'unique' => [ [] ],
554       'index' => [ ['crednum'] ],
555     },
556
557     'cust_svc' => {
558       'columns' => [
559         'svcnum',    'int',    '',   '',
560         'pkgnum',    'int',    '',   '',
561         'svcpart',   'int',    '',   '',
562       ],
563       'primary_key' => 'svcnum',
564       'unique' => [ [] ],
565       'index' => [ ['svcnum'], ['pkgnum'], ['svcpart'] ],
566     },
567
568     'part_pkg' => {
569       'columns' => [
570         'pkgpart',    'int',    '',   '',
571         'pkg',        'varchar',   '',   $char_d,
572         'comment',    'varchar',   '',   $char_d,
573         'setup',      @perl_type,
574         'freq',       'int', '', '',  #billing frequency (months)
575         'recur',      @perl_type,
576       ],
577       'primary_key' => 'pkgpart',
578       'unique' => [ [] ],
579       'index' => [ [] ],
580     },
581
582 #    'part_title' => {
583 #      'columns' => [
584 #        'titlenum',   'int',    '',   '',
585 #        'title',      'varchar',   '',   $char_d,
586 #      ],
587 #      'primary_key' => 'titlenum',
588 #      'unique' => [ [] ],
589 #      'index' => [ [] ],
590 #    },
591
592     'pkg_svc' => {
593       'columns' => [
594         'pkgpart',    'int',    '',   '',
595         'svcpart',    'int',    '',   '',
596         'quantity',   'int',    '',   '',
597       ],
598       'primary_key' => '',
599       'unique' => [ ['pkgpart', 'svcpart'] ],
600       'index' => [ ['pkgpart'] ],
601     },
602
603     'part_referral' => {
604       'columns' => [
605         'refnum',   'int',    '',   '',
606         'referral', 'varchar',   '',   $char_d,
607       ],
608       'primary_key' => 'refnum',
609       'unique' => [ [] ],
610       'index' => [ [] ],
611     },
612
613     'part_svc' => {
614       'columns' => [
615         'svcpart',    'int',    '',   '',
616         'svc',        'varchar',   '',   $char_d,
617         'svcdb',      'varchar',   '',   $char_d,
618       ],
619       'primary_key' => 'svcpart',
620       'unique' => [ [] ],
621       'index' => [ [] ],
622     },
623
624     #(this should be renamed to part_pop)
625     'svc_acct_pop' => {
626       'columns' => [
627         'popnum',    'int',    '',   '',
628         'city',      'varchar',   '',   $char_d,
629         'state',     'varchar',   '',   $char_d,
630         'ac',        'char',   '',   3,
631         'exch',      'char',   '',   3,
632         'loc',       'char',   'NULL',   4, #NULL for legacy purposes
633       ],
634       'primary_key' => 'popnum',
635       'unique' => [ [] ],
636       'index' => [ [] ],
637     },
638
639     'svc_acct' => {
640       'columns' => [
641         'svcnum',    'int',    '',   '',
642         'username',  'varchar',   '',   $username_len, #unique (& remove dup code)
643         '_password', 'varchar',   '',   50, #13 for encryped pw's plus ' *SUSPENDED* (mp5 passwords can be 34)
644         'popnum',    'int',    'NULL',   '',
645         'uid',       'int', 'NULL',   '',
646         'gid',       'int', 'NULL',   '',
647         'finger',    'varchar',   'NULL',   $char_d,
648         'dir',       'varchar',   'NULL',   $char_d,
649         'shell',     'varchar',   'NULL',   $char_d,
650         'quota',     'varchar',   'NULL',   $char_d,
651         'slipip',    'varchar',   'NULL',   15, #four TINYINTs, bah.
652       ],
653       'primary_key' => 'svcnum',
654       'unique' => [ [] ],
655       'index' => [ ['username'] ],
656     },
657
658     'svc_acct_sm' => {
659       'columns' => [
660         'svcnum',    'int',    '',   '',
661         'domsvc',    'int',    '',   '',
662         'domuid',    'int', '',   '',
663         'domuser',   'varchar',   '',   $char_d,
664       ],
665       'primary_key' => 'svcnum',
666       'unique' => [ [] ],
667       'index' => [ ['domsvc'], ['domuid'] ], 
668     },
669
670     #'svc_charge' => {
671     #  'columns' => [
672     #    'svcnum',    'int',    '',   '',
673     #    'amount',    @money_type,
674     #  ],
675     #  'primary_key' => 'svcnum',
676     #  'unique' => [ [] ],
677     #  'index' => [ [] ],
678     #},
679
680     'svc_domain' => {
681       'columns' => [
682         'svcnum',    'int',    '',   '',
683         'domain',    'varchar',    '',   $char_d,
684       ],
685       'primary_key' => 'svcnum',
686       'unique' => [ ['domain'] ],
687       'index' => [ [] ],
688     },
689
690     'domain_record' => {
691       'columns' => [
692         'recnum',    'int',     '',  '',
693         'svcnum',    'int',     '',  '',
694         'reczone',   'varchar', '',  $char_d,
695         'recaf',     'char',    '',  2,
696         'rectype',   'char',    '',  5,
697         'recdata',   'varchar', '',  $char_d,
698       ],
699       'primary_key' => 'recnum',
700       'unique'      => [ [] ],
701       'index'       => [ ['svcnum'] ],
702     },
703
704     'svc_www' => {
705       'columns' => [
706         'svcnum',   'int',    '',  '',
707         'recnum',   'int',    '',  '',
708         'usersvc',  'int',    '',  '',
709       ],
710       'primary_key' => 'svcnum',
711       'unique'      => [ [] ],
712       'index'       => [ [] ],
713     },
714
715     #'svc_wo' => {
716     #  'columns' => [
717     #    'svcnum',    'int',    '',   '',
718     #    'svcnum',    'int',    '',   '',
719     #    'svcnum',    'int',    '',   '',
720     #    'worker',    'varchar',   '',   $char_d,
721     #    '_date',     @date_type,
722     #  ],
723     #  'primary_key' => 'svcnum',
724     #  'unique' => [ [] ],
725     #  'index' => [ [] ],
726     #},
727
728     'prepay_credit' => {
729       'columns' => [
730         'prepaynum',   'int',     '',   '',
731         'identifier',  'varchar', '', $char_d,
732         'amount',      @money_type,
733       ],
734       'primary_key' => 'prepaynum',
735       'unique'      => [ ['identifier'] ],
736       'index'       => [ [] ],
737     },
738
739     'port' => {
740       'columns' => [
741         'portnum',  'int',     '',   '',
742         'ip',       'varchar', NULL, 15,
743         'nasport'   'int',     NULL, '',
744         'nasnum',   'int',     '',   '',
745       ],
746       'primary_key' => 'portnum',
747       'unique'      => [],
748       'index'       => [],
749     },
750
751     'nas' => {
752       'columns' => [
753         'nasnum',   'int',     '',    '',
754         'nas',      'varchar', '',    $char_d,
755         'nasip',    'varchar', '',    15,
756         'nasfqdn',  'varchar', '',    $char_d,
757         'last',     @date_type,
758       ],
759       'primary_key' => 'nasnum',
760       'unique'      => [ [ 'nas' ], [ 'nasip' ] ],
761       'index'       => [ [ 'last' ] ],
762     },
763
764     'session' => {
765       'columns' => [
766         'sessionnum', 'int',       '',   '',
767         'portnum',    'int',       '',   '',
768         'svcnum',     'int',       '',   '',
769         'login',      @date_type,
770         'logout',     @date_type,
771       ],
772       'primary_key' => 'sessionnum',
773       'unique'      => [],
774       'index'       => [ [ 'portnum' ] ],
775     },
776
777   );
778
779   %tables;
780
781 }
782