This repository has been archived by the owner on Dec 19, 2023. It is now read-only.
/
makecat
1976 lines (1666 loc) · 45.9 KB
/
makecat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/perl
#
# makecat = MiniVend catalog configurator
#
# Copyright 1996-1999 by Michael J. Heins <mikeh@minivend.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
sub dontwarn { $FindBin::RealBin; }
BEGIN {
eval {
require 5.004;
require FindBin;
1 and $VendRoot = "$FindBin::RealBin";
1 and $VendRoot =~ s/.bin$//;
};
($VendRoot = $ENV{MINIVEND_ROOT})
if defined $ENV{MINIVEND_ROOT};
$VendRoot = $VendRoot || '/home/minivend';
}
## END CONFIGURABLE VARIABLES
use lib "$VendRoot/lib";
$| = 1; select STDERR;
$| = 1; select STDOUT;
use Config;
use File::Find;
use File::Copy;
use File::Path;
use Vend::MakeCat;
use Vend::Util;
use Getopt::Long;
use IniConf;
#use strict;
my $Removeconfig;
my $Reconfigure = 0;
my $Configfile;
my $Cfg;
my $Logfile = 'makecat.log';
my $catalog_name;
my %Conf;
my $Inetmode;
my $Windows;
my $pid;
$Windows = 1 if $Config{osname} =~ /win32/i;
my $USAGE = <<EOF;
usage: $0 [options] [catalogname]
options:
-F Force make of catalog with defaults
-f Configuration file (default is $0.cfg)
-l File to log to (default makecat.log)
-r Reconfigure defaults
Defaults:
--basedir=directory Base directory for catalogs
--cgibase=url_fragment Base URL for link programs
--documentroot=directory The directory where HTML is based
--minivendgroup=group The default group files should be owned by
--minivenduser=username The user ID which runs MiniVend
--serverconf=filename Location of httpd.conf
--vendroot=filename Location of MiniVend software
--homedir=directory Use instead of \$HOME to set defaults
Required:
--catroot=directory Directory where MiniVend catalog files go
--cgidir=directory The directory the CGI link should go to
--servername=server Name of server (www.whatever.domain)
--cgiurl=url_fragment The path to the CGI link (no server name)
--demotype=template The template catalog (simple is the default)
--mailorderto=email Email address to send orders
Optional:
--catuser=username The user files should be owned by (if root)
--samplehtml=directory The directory where template HTML goes
--imagedir=directory The directory where template images go
--imageurl=url The URL to prefix images with
--nocfg Don't add to minivend.cfg
--nocopy Don't actually copy the files, just test
--norunning Don't add to running server
--reference Return hash of config as string (sets -F, no write)
--linkprogram=file Use file as link program instead of vlink/tlink
--linkmode=mode UNIX or INET (link program vlink or tlink)
--sampleurl=url URL to access HTML for catalog
--noumask Don't set umask
EOF
if (scalar @ARGV > 1) {
Getopt::Long::config(qw/permute/);
#Getopt::Long::config(qw/debug/);
my %optctl = (
'F' => \$Vend::MakeCat::Force,
'aliases' => \$Conf{aliases},
'basedir' => \$Conf{basedir},
'catalogname' => \$catalog_name,
'catroot' => \$Conf{catroot},
'catuser' => \$Conf{catuser},
'cgibase' => \$Conf{cgibase},
'cgidir' => \$Conf{cgidir},
'cgiurl' => \$Conf{cgiurl},
'demotype' => \$Conf{demotype},
'documentroot' => \$Conf{documentroot},
'f' => \$Configfile,
'homedir' => \$Conf{homedir},
'imagedir' => \$Conf{imagedir},
'imageurl' => \$Conf{imageurl},
'l' => \$Logfile,
'linkmode' => \$Conf{linkmode},
'linkprogram' => \$Conf{linkprogram},
'mailorderto' => \$Conf{mailorderto},
'minivendgroup' => \$Conf{minivendgroup},
'minivenduser' => \$Conf{minivenduser},
'nocfg' => \$Conf{nocfg},
'nocopy' => \$Conf{nocopy},
'norunning' => \$Conf{norunning},
'noumask' => \$Conf{noumask},
'r' => \$Reconfigure,
'reference' => \$Conf{reference},
'samplehtml' => \$Conf{samplehtml},
'sampleurl' => \$Conf{sampleurl},
'serverconf' => \$Conf{serverconf},
'servername' => \$Conf{servername},
'vendroot' => \$Conf{vendroot},
'<>' => sub {
my $arg = shift;
return unless $arg =~ /=/;
my ($opt, $val) = split /=/, $arg, 2;
$opt = lc $opt;
die "Can't set \U$opt\E twice.\n$USAGE\n"
if defined $Conf{$opt};
$Conf{$opt} = $val;
return;
},
);
my @options = ( qw/
F
aliases=s
basedir|base=s
catalogname|name=s
catroot|dir=s
catuser|user=s
cgibase=s
cgidir=s
cgiurl|script=s
demotype|template=s
documentroot=s
f
i
homedir=s
imagedir=s
imageurl=s
l=s
linkmode=s
linkprogram=s
mailorderto=s
minivendgroup|group=s
minivenduser|mvuser=s
nocfg
nocopy
norunning
r
reference
samplehtml|html=s
sampleurl=s
serverconf|conf=s
servername|server=s
vendroot|mvdir=s
<>
/ );
GetOptions(\%optctl, @options) or die "\n$USAGE\n";
}
$catalog_name = shift unless $catalog_name;
if(@ARGV) {
die <<EOF . "\n";
Extra command line arguments were found. (Did you specify
both --catalogname=name and one on the command line?)
$USAGE
EOF
}
unless($catalog_name) {
die "$USAGE\n" if $Vend::MakeCat::Force;
print <<EOF;
Select a short, mnemonic name for the catalog. This will be
used to set the defaults for naming the catalog, executable,
and directory, so you will have to type in this name frequently.
NOTE: This will be the name of 'vlink' or 'tlink', the link CGI
program. Depending on your CGI setup, it may also have the
extension .cgi added.
If you are doing the demo for the first time, you might use "simple".
EOF
$catalog_name = prompt ("Catalog name? ");
}
die "$USAGE\n" unless $catalog_name;
if($Conf{homedir}) {
die "Directory set with --homedir=$Conf{homedir} is not a directory.\n"
unless -d $Conf{homedir};
$ENV{HOME} = $Conf{homedir};
}
if($Conf{'reference'}) {
$Vend::MakeCat::Force =
$Conf{nocopy} =
$Conf{norunning} =
$Conf{nocfg} = 1;
$Logfile = $Windows ? 'nul:' : '/dev/null';
}
if ($Vend::MakeCat::Force) {
my $file = $Logfile || 'makecat.log';
open(LOGOUT, ">>$file") or die "write $file: $!\n";
select LOGOUT;
}
$Configfile = "$0.cfg" unless $Configfile;
my $Servername;
my $Servers;
my $Done_defaults;
print <<EOF;
makecat -- MiniVend catalog installation program.
*** We will be making a catalog named '$catalog_name'. ***
EOF
READCONFIG: {
my $cfgfile = "$catalog_name.cfg";
last READCONFIG unless -f $cfgfile;
open(READCONFIG, $cfgfile) or die "read $cfgfile: $!\n";
while(<READCONFIG>) {
next unless /^\s*[A-Z]\w*\s+\S/;
chomp;
($var, $val) = split " ", $_, 2;
$ENV{"MVC_$var"} = $val;
}
close READCONFIG;
}
my $CgiDefault = prefix('CGIDIR') || undef;
my $DocrootDefault = prefix('DOCUMENTROOT') || undef;
if ($Windows) {
$ENV{HOME} = $ENV{HOME} || $ENV{MINIVEND_ROOT}
|| prefix('VENDROOT') || '';
$CgiDefault = prefix('CGIDIR') || 'c:/webshare/scripts';
$CgiUrlDefault = prefix('CGIURL') || '/scripts';
$DocrootDefault = prefix('DOCUMENTROOT') || 'c:/webshare/wwwroot';
}
$ENV{MVC_ENCRYPTOR} = prefix('ENCRYPTOR') || 'none';
FINDDOCROOT: {
last FINDDOCROOT if defined $DocrootDefault;
for(qw/www html web web-public public_html public-html/) {
-d "$ENV{HOME}/$_" and -w _
and $DocrootDefault = "$ENV{HOME}/$_"
and last FINDDOCROOT;
}
for( glob("$ENV{HOME}/*html*"),
glob("$ENV{HOME}/*www*"),
glob("$ENV{HOME}/*web*")
)
{
-d $_ and -w _
and $DocrootDefault = $_
and last FINDDOCROOT;
}
for(
'/usr/local/etc/httpd/htdocs',
'/usr/local/apache/htdocs',
'/home/httpd/htdocs',
glob("/*/httpd/*docs"),
glob("/*web*/*docs"),
glob("/*/ns-home/docs"),
glob("/export/*/ns-home/http*/docs"),
glob("/usr/*/ns-home/http*/docs"),
glob("/home/*/ns-home/http*/docs")
)
{
-d $_ and -w _
and $DocrootDefault = $_
and last FINDDOCROOT;
}
$DocrootDefault = '';
}
FINDCGIDIR: {
last FINDCGIDIR if defined $CgiDefault;
for(qw/cgi-bin cgi cgibin web-scripts scripts cgiwrap cgi-wrap/) {
-d "$ENV{HOME}/$_" and -w _
and $CgiDefault = "$ENV{HOME}/$_"
and $CgiUrlDefault = "/$_"
and last FINDCGIDIR;
}
for( glob("$ENV{HOME}/*cgi*"), glob("$ENV{HOME}/*scripts*") ) {
-d $_ and -w _
and $CgiDefault = $_
and ($CgiUrlDefault = $_) =~ s:.*/:/:
and last FINDCGIDIR;
}
for(
'/usr/local/etc/httpd/cgi-bin',
'/usr/local/apache/cgi-bin',
'/home/httpd/cgi-bin',
glob("/*web*/cgi*"),
glob("/*/ns-home/cgi*"),
glob("/export/*/ns-home/http*/cgi*"),
glob("/usr/*/ns-home/http*/cgi*"),
glob("/home/*/ns-home/http*/cgi*"),
)
{
-d $_ and -w _
and $CgiDefault = $_
and ($CgiUrlDefault = $_) =~ s:.*/:/:
and last FINDCGIDIR;
}
$CgiDefault = $CgiUrlDefault = '';
}
my $isroot = 0;
if ($< == 0) {
$isroot = 1 unless $Windows;
}
$Conf{catalogname} = $catalog_name;
my %Initial;
my %IfRoot = (qw( permtype 1 minivenduser 1 minivendgroup 1 catuser 1));
my %Prefix = (
vendroot => $VendRoot,
basedir => sub {
return prefix('basedir', 1) if prefix('basedir', 1);
return "$Conf{vendroot}/catalogs"
if $Windows;
return "$ENV{HOME}/catalogs"
unless $isroot;
return "~/catalogs";
},
minivenduser => sub { return 'everybody' if $Windows;
get_id(); },
minivendgroup=> '',
servername => $Config{myhostname},
documentroot => $ENV{MVC_DOCUMENTROOT} || $DocrootDefault,
cgidir => $ENV{MVC_CGIDIR} || $CgiDefault,
cgibase => $ENV{MVC_CGIBASE} || $CgiUrlDefault,
demotype => $ENV{MVC_DEMOTYPE} || 'simple',
catuser => sub {
$ENV{MVC_CATUSER} ||
($isroot ? '' : $Conf{'minivenduser'})
},
mailorderto =>
sub { return 'webmaster' if $Windows;
if($Conf{servername} =~ s:(/~[^/]+)$:: ) {
$Tilde = $1;
}
$Conf{catuser} },
catroot => sub {
my $dir = prefix('basedir') . "/" . $catalog_name;
return $dir if $Windows;
my $userdir = (getpwnam($Conf{catuser}))[7];
$dir =~ s/^\~/$userdir/;
return $dir;
},
aliases => sub { return "/" . $catalog_name },
cgiurl => sub {
return $ENV{MVC_CGIURL} if $ENV{MVC_CGIURL};
my $url = '';
if ($Windows) {
$url .= $Conf{cgibase} . '/' .
$catalog_name . '.exe';
}
elsif ($Conf{cgibase} eq '') {
$url = $Tilde if defined $Tilde;
$url .= '/' .
$catalog_name .
'.cgi';
}
else {
$url .= $Conf{cgibase} . '/' . $catalog_name;
}
$url;
},
imagedir => sub {
return $ENV{MVC_IMAGEDIR} if $ENV{MVC_IMAGEDIR};
return prefix('samplehtml') . '/' . 'images'
},
imageurl => sub {
my $url = '';
return $ENV{MVC_IMAGEURL} if $ENV{MVC_IMAGEURL};
if(defined $Tilde) {
$url = $Tilde;
}
$url .= '/' . $catalog_name . '/' . 'images';
$url;
},
samplehtml => sub {
return $ENV{MVC_SAMPLEHTML} if $ENV{MVC_SAMPLEHTML};
$Conf{documentroot} . '/' . $catalog_name;
},
);
sub strip_trailing_slash {
my $url = shift;
$url =~ s:/+\s*$::;
return $url;
}
my %Postprocess = (
cgibase => \&strip_trailing_slash,
documentroot => \&strip_trailing_slash,
imagedir => \&strip_trailing_slash,
samplehtml => \&strip_trailing_slash,
catroot => \&strip_trailing_slash,
);
sub prefix {
my ($parm, $nodefault) = @_;
$parm = lc $parm;
return $Conf{$parm} if $Conf{$parm};
return $ENV{"MVC_\U$parm"} if $ENV{"MVC_\U$parm"};
return undef if $nodefault;
if(ref $Prefix{$parm}) {
return &{ $Prefix{$parm} };
}
else {
return $Prefix{$parm};
}
}
my %History = (
demotype => sub {
return('simple', 'flycat');
},
documentroot => sub {
if(defined $Servers->{$Servername}) {
return $Servers->{$Servername}->{documentroot}
if defined $Servers->{$Servername}->{documentroot};
}
else {
return (@_);
}
},
cgidir => sub {
if( defined $Servers->{$Servername} and
$Servers->{$Servername}->{scriptalias}
) {
my @return;
@return = values %{$Servers->{$Servername}{scriptalias}};
unshift @return, $ENV{MVC_CGIDIR} if $ENV{MVC_CGIDIR};
return @return;
}
return (@_);
},
cgibase => sub {
if(defined $Servers->{$Servername}) {
my $ref = $Servers->{$Servername}{scriptalias};
return @_ unless defined $ref;
if($Conf{cgidir}) {
my ($k,$v);
for (keys %$ref) {
$k = $_;
$v = $ref->{$_};
$v =~ s:[/\s]+$::;
next unless $v eq $Conf{cgidir};
$k =~ s:[/\s]+$::;
return $k;
}
}
else {
return keys %$ref;
}
}
return (@_);
},
mailorderto => sub {
my(@return) = @_;
if(defined $Servers->{$Servername}) {
push(@return, $Servers->{$Servername}->{serveradmin})
if defined $Servers->{$Servername}->{serveradmin};
}
return @return;
},
imagedir => sub {
my (@return) = @_;
if(defined $Servers->{$Servername}) {
push (@return,
values %{$Servers->{$Servername}->{alias}})
if defined $Servers->{$Servername}->{alias};
}
return @return;
},
permtype => sub {
my (@return) = @_;
push(@return, 'G', 'M', 'U');
return @return;
},
imageurl => sub {
my (@return) = @_;
if(defined $Servers->{$Servername}) {
push (@return,
keys %{$Servers->{$Servername}->{alias}})
if defined $Servers->{$Servername}->{alias};
}
return @return;
},
catuser => sub {
return 'everybody' if $Windows;
my @return = (@_);
my $u;
if(defined $Servers->{$Servername}) {
$nogood = $Servers->{$Servername}->{'user'}
if defined $Servers->{$Servername}->{'user'};
}
my @out;
while($u = getpwent) {
next if $u eq 'root';
next if $u eq $nogood;
push(@out, $u);
}
return (@return, sort @out);
},
minivenduser => sub {
return 'everybody' if $Windows;
my @return = (@_);
my $u;
if(defined $Servers->{$Servername}) {
$nogood = $Servers->{$Servername}->{'user'}
if defined $Servers->{$Servername}->{'user'};
}
my @out;
while($u = getpwent) {
next if $u eq 'root';
next if $u eq $nogood;
push(@out, $u);
}
return (@return, sort @out);
},
minivendgroup => sub {
return 'nogroup' if $Windows;
my (@return) = @_;
my $u;
if(defined $Servers->{$Servername}) {
$nogood = $Servers->{$Servername}->{'group'}
if defined $Servers->{$Servername}->{'group'};
}
my @out;
while($u = getgrent) {
next if $u eq 'root';
next if $u eq $nogood;
push(@out, $u);
}
return (@return, sort @out);
},
);
unless($isroot) {
@Prefix{qw(minivenduser minivendgroup)} = get_ids();
$Prefix{catuser} = $Prefix{minivenduser};
$Prefix{basedir} = "$ENV{HOME}/catalogs";
}
my($ask,$param);
unless (-f $Configfile) {
$Removeconfig = 1 if prefix('nocopy');
open(CFGFILE, ">$Configfile") or die "Can't write $Configfile: $!\n";
while(<DATA>) {
print CFGFILE $_;
}
close(CFGFILE) or die "Can't close $Configfile: $!\n";
print "\nNew configuration file '$Configfile'\n" ;
$Reconfigure = 1;
}
$Cfg = new IniConf -file => $Configfile, -nocase => 1;
die "Can't read config file $Configfile: $!\n" unless defined $Cfg;
my @parms;
unless($Reconfigure or $Cfg->val('base', 'vendroot')) {
$Reconfigure = 1;
}
CHECKEXIST: {
if(grep /^catalog $catalog_name$/i, $Cfg->Sections()) {
@parms = $Cfg->Parameters("catalog $catalog_name");
}
else {
@parms = ();
}
unless(@parms) {
@parms = $Cfg->Parameters('legalconfig');
undef $Cfg;
open(CFGFILE, ">>$Configfile") or die "Can't write $Configfile: $!\n";
print CFGFILE <<EOF;
# New catalog definition '$catalog_name' written by makecat
[catalog $catalog_name]
EOF
for(@parms) {
printf CFGFILE "%-19s =\n", $_;
}
close(CFGFILE) or die "Can't close $Configfile: $!\n";
$Cfg = new IniConf -file => $Configfile, -nocase => 1;
die "Can't read config file $Configfile: $!\n" unless defined $Cfg;
redo CHECKEXIST;
}
}
my @conf;
my @Servers;
FINDCONF: {
last FINDCONF if $Windows;
last FINDCONF if $Vend::MakeCat::Force;
last FINDCONF if $ENV{MVC_SERVERNAME};
my $httpdconf;
print <<EOF unless @conf;
If you are using the Apache or NCSA web server, MiniVend can set
some of the default parameters for you by reading the file.
If you use the Netscape Enterprise server or other non-NCSA HTTP server,
enter 'none' -- the information, if any, will not be useful.
EOF
if (defined $Vend::MakeCat::Prompt_sub) {
print <<EOF;
Try using the UP arrow at some of the prompts -- you have the
Term::ReadLine module installed, and MiniVend may find some
default values in your HTTP server configuration file. You can
cycle among them with the UP and DOWN arrows.
EOF
}
else {
print <<EOF;
This information may not be that useful to you, since you don't
have the Term::ReadLine module installed. If the default setting
presented is not correct, you will have to know the information.
C'est la vie.
EOF
}
if(@conf) {
# Skip doing this again
}
elsif($param = prefix('serverconf') || $Cfg->val('base', 'serverconf')) {
last FINDCONF if $param =~ /^none$/i;
@conf = split /\s+/, $param;
}
else {
if(findexe('locate')) {
@conf = findfiles('httpd.conf');
$Cfg->setval('base', 'serverconf', join(" ", @conf));
}
else {
print <<EOF;
MiniVend can look for Apache or NCSA HTTP server configuration
files for you by a slow method (using the system find
command). This may take as many as several minutes.
EOF
$ask = prompt("Find httpd.conf files? ", 'y');
@conf = findfiles('httpd.conf') if $ask =~ /^\s*y/i;
$Cfg->setval('base', 'serverconf', join(" ", @conf));
}
}
sethistory(@conf);
$httpdconf = prompt("Enter path to httpd.conf file: ", $conf[0]);
last FINDCONF if $httpdconf =~ /^none$/i;
if($httpdconf) {
$Servers = conf_parse_http($httpdconf);
unless (defined $Servers) {
print <<EOF;
The file '$httpdconf' was not parsed properly.
Error: $Vend::MakeCat::Error
You can edit the file and try again if you wish. (Don't worry if it
didn't work, you will have the opportunity to enter all of the proper
information manually.)
EOF
$ask = prompt("Try again? ", 'y');
last FINDCONF if $ask =~ /^\s*n/i;
redo FINDCONF;
}
else {
@Servers = sort keys %{$Servers};
}
}
}
##############
SETDEFAULTS: {
last SETDEFAULTS if $Done_defaults;
$Done_defaults = 1;
unless ($Reconfigure) {
my @parms = $Cfg->Parameters('base');
for(@parms) {
next if $Conf{$_} = prefix($_, 1);
$Conf{$_} = $Cfg->val('base', $_) || undef;
}
last SETDEFAULTS;
}
PERMS: {
unless ($isroot) {
print <<EOF unless $Windows;
This demo configuration sometimes requires root permissions,
depending on your ISP. It needs to copy a few files to the CGI
and HTML directories.
You must either have your own CGI directory, or be able to run
a CGI with an extension like '.cgi'.
If you will be operating only on directories owned by the
user you are running this as, you will be able to do
everything.
EOF
}
else {
last PERMS if prefix('permtype', 1);
print <<EOF;
You are the super-user. You can set the permissions to GROUP, MULTIPLE
GROUP, or USER mode for catalogs on this server.
MULTIPLE GROUP or GROUP is appropriate when multiple users will be running
catalogs on the same server.
MULTIPLE GROUP is the best way. Put each user in their own group, and
place the MiniVend user in that group. In this mode, only the user of
each catalog and the MiniVend server may read database and error files --
files that may contain sensitive information. If the user's default UMASK
is 2 on a UNIX system, then this the most troublefree mode of operation.
GROUP mode causes all files to be owned by the MiniVend user, with group
ownership set to the group the user belongs to. This allows the MiniVend
user and each individual user to read and write the files associated with
a catalog, but others in that group may read files from a catalog. This
may not be secure, and may cause problems when the user creates new
files that must be read/write to the MiniVend user.
USER mode is appropriate when only one user owns all catalogs running
on this server, and the MiniVend daemon is run by the same user.
M) MULTIPLE GROUP
G) GROUP
U) USER
EOF
sethistory("MULTIPLE GROUP", "GROUP", "USER");
$Conf{permtype} = prompt("Permission Mode? ", "M");
unless($Conf{permtype} =~ s/^\s*([mgu]).*/uc $1/ie) {
print "Must be one of M(ULTIPLE), G(ROUP), or U(SER).\n";
redo PERMS;
}
$Cfg->setval('base', 'permtype', $Conf{permtype});
}
} # END PERMS
print <<EOF;
Since there was no master configuration file, we will ask
some questions to help set initial defaults for making this
and future catalogs.
EOF
##############
DEFSERVER: {
last DEFSERVER unless @Servers;
print <<EOF if defined $Vend::MakeCat::Prompt_sub;
MiniVend can set many of the defaults for you if it knows the server
name that is going to be used.
Enter the default server that should be used. This is only a default, to
determine the *first* one that will be looked at -- you will be given
a choice of all available servers.
There is a "history" mechanism that will allow you to use the up
and down arrows on your terminal (assuming you have a standard terminal)
to cycle between possible choices. This should contain the available
servers.
EOF
sethistory(@Servers);
$Conf{servername} = prompt('Default server? ', $Servers[0]);
$Servername = $Conf{servername};
$Cfg->setval('base', 'servername', $Servername);
}
############
my @ask = $Cfg->val('global', 'askbase');
for('cgidir') {
next if $Conf{$_};
print <<EOF;
We need to know if all of your CGI programs are run as a file ending
in .cgi or some other extension, or whether you have your own personal
CGI directory.
EOF
$ask = prompt ("Do you have a CGI directory? ", 'y');
last if is_yes($ask);
$Prefix{cgidir} = prefix('documentroot');
}
my ($p, $i);
for ($i = 0; $i < scalar @ask; $i++) {
$p = $ask[$i];
my $hval;
$hval = prefix($p);
if (defined $History{$p}) {
@history = &{$History{$p}}(prefix($p));
$hval = $history[0];
sethistory(@history);
}
$val = prefix($p, 1) || $Cfg->val("base", $p) || $hval;
print "\n";
print description($p);
print "\n\n";
my $msg = pretty($p) . "? ";
$Conf{$p} = prompt ($msg, $val);
if($Conf{$p} eq '@') {
$i--;
$i = 0 if $i < 0;
redo;
}
if(defined $Postprocess{$p}) {
$Conf{$p} = &{$Postprocess{$p}}($Conf{$p});
}
}
for(@ask) {
$Cfg->setval('base', $_, $Conf{$_});
}
$Cfg->WriteConfig("$Configfile.new")
and rename "$Configfile.new", $Configfile;
print "######### END BASE CONFIGURATION #########\n\n";
}
#############
my $serv = prefix('servername') || 'www.yourdomain';
# Set server
print "######### BEGINNING CATALOG CONFIGURATION #########\n";
print <<EOF if defined $Vend::MakeCat::Prompt_sub;
During many of the following operations, defaults are placed in
a buffer for you. You may use the up and down arrows to toggle
between the defaults.
If you made a mistake on a *previous* entry and realize that
in a later one, if you enter ONLY an @ sign and press return you
should be returned to the previous step.
EOF
SETSERVER: {
sethistory(@Servers);
print description('servername');
$Servername = prefix('servername', 1) ||
$Cfg->val('base', 'servername') ||
prefix('servername');
$Servername =
$Conf{servername} =
prompt("Server name? ", ($Servername || $Servers[0]));
$Cfg->setval("catalog $catalog_name", 'servername', $Conf{servername});
}
@ask = $Cfg->val('global', 'askconfig');
for ($i = 0; $i < scalar @ask; $i++) {
$p = $ask[$i];
if (defined $History{$p}) {
@history = &{$History{$p}}(prefix($p));
sethistory(@history);
$val = prefix($p,1) ||
$Cfg->val("catalog $catalog_name", $p) ||
$history[0] ||
prefix($p);
}
else {
$val = prefix($p,1) ||
$Cfg->val("catalog $catalog_name", $p) ||
prefix($p);
}
if (! $isroot and defined $IfRoot{$p}) {
$Conf{$p} = $val;
next;
}
print "\n";
print description($p);
print "\n\n";
my $msg = pretty($p) . "? ";
$Conf{$p} = prompt ($msg, $val);
if($Conf{$p} eq '@') {
$Conf{$p} = $val;
$i--;
$i = 0 if $i < 0;
redo;
}
$Cfg->setval("catalog $catalog_name", $p, $Conf{$p});
}
if($Removeconfig) {
unlink $Configfile;