-
Notifications
You must be signed in to change notification settings - Fork 27
/
interchange.PL
2679 lines (2293 loc) · 66.7 KB
/
interchange.PL
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
#$self = {
# INSTALLPRIVLIB => '/usr/local/interchange/lib',
# INSTALLARCHLIB => '/usr/local/interchange',
#};
use Config;
require 'scripts/initp.pl';
sub doit {
my ($key) = @_;
my $val;
if ($MV::Self->{RPMBUILDDIR} and $val = $MV::Self->{$key}) {
$val =~ s!^$MV::Self->{RPMBUILDDIR}/!/!;
return $val;
}
return $MV::Self->{$key} unless $key =~ /[a-z]/;
return $Config{$key};
}
DOIT: {
local ($/);
local($_) = <<'_EoP_';
#!/usr/bin/perl
##!~_~perlpath~_~
#
# Interchange version 4.5.x
#
# $Id: interchange.PL,v 1.3 2000-09-23 18:49:30 heins Exp $
#
# Copyright (C) 1996-2000 Akopia, Inc. <info@akopia.com>
#
# This program was originally based on Vend 0.2
# Copyright 1995 by Andrew M. Wilcox <awilcox@world.std.com>
#
# Portions from Vend 0.3
# Copyright 1995 by Andrew M. Wilcox <awilcox@world.std.com>
#
# See the file 'Changes' for information.
#
# 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., 59 Temple Place, Suite 330, Boston,
# MA 02111-1307 USA.
use lib '/usr/local/interchange/lib';
#use lib '~_~INSTALLPRIVLIB~_~';
use lib '/usr/local/interchange';
#use lib '~_~INSTALLARCHLIB~_~';
BEGIN {
$Vend::Foreground = 1;
($Global::VendRoot = $ENV{MINIVEND_ROOT})
if defined $ENV{MINIVEND_ROOT};
$Global::VendRoot = $Global::VendRoot || '/usr/local/interchange';
#$Global::VendRoot = $Global::VendRoot || '~_~INSTALLARCHLIB~_~';
if(-f "$Global::VendRoot/interchange.cfg") {
$Global::ExeName = 'interchange';
$Global::ConfigFile = 'interchange.cfg';
}
elsif(-f "$Global::VendRoot/minivend.cfg") {
$Global::ExeName = 'minivend';
$Global::ConfigFile = 'minivend.cfg';
}
elsif(-f "$Global::VendRoot/interchange.cfg.dist") {
$Global::ExeName = 'interchange';
$Global::ConfigFile = 'interchange.cfg';
}
$Global::InitialErrorFile = $Global::ErrorFile = "$Global::VendRoot/error.log";
if($^O =~ /win32/i) {
$Global::Windows = 1;
}
# Uncomment next line if you want to guarantee use of DB_File
#$ENV{MINIVEND_DBFILE} = 1;
# Uncomment next line if you want to guarantee use of GDBM and not DB_File
#$ENV{MINIVEND_GDBM} = 1;
# Uncomment next line if you want to use no DBM, sessions
# stored in files and databases in memory (or SQL)
#$ENV{MINIVEND_NODBM} = 1;
# Uncomment next line if you DON'T want to use DBI, can
# save a bit on code size
#$ENV{MINIVEND_NO_DBI} = 1;
# Uncomment next line if you want to use the Storable
# module for storing session data. It improves session performance
# to a good degree. We will also do a bit of auto-detect below.
#$ENV{MINIVEND_STORABLE} = 1;
# Uncomment next line if you want to use the Storable
# module for storing database data. It improves GBDM/DB_File performance
# to a good degree. We will also do a bit of auto-detect below.
#$ENV{MINIVEND_STORABLE_DB} = 1;
# Uncomment AND SET next line to set PGP path to somewhere besides
# the Interchange user path
#$ENV{PGPPATH} = '/usr/local/pgp';
# Use the Storable module for storing data in DBM files.
if (-f "$Global::VendRoot/_session_storable") {
$ENV{MINIVEND_STORABLE} = 1;
}
if (-f "$Global::VendRoot/_db_storable") {
$ENV{MINIVEND_STORABLE_DB} = 1;
}
# Interchange can use syslog via the "logger" command
# This prevents parsing of the value, default is syslog off
$Global::SysLog = '';
}
### END CONFIGURABLE VARIABLES
use vars qw($VERSION);
require Exporter;
BEGIN {
$VERSION = '4.5.6';
}
use strict;
use Fcntl;
# BSD, among others, defines sendmail to be in /usr/sbin, and
# we want to make sure the program is there. Insert the location
# of you sendmail binary (the configure script should do this)
$Global::SendMailLocation = ($Global::Windows and $Global::SendMailLocation) ||
(-x $Global::SendMailLocation and $Global::SendMailLocation) ||
(-x '/usr/lib/sendmail' and '/usr/lib/sendmail') ||
(-x '/usr/sbin/sendmail' and '/usr/sbin/sendmail') ||
'';
# '~_~sendmail~_~';
#select a DBM
BEGIN {
$Global::GDBM = $Global::DB_File =
# LDAP
$Global::LDAP =
# END LDAP
# SQL
$Global::DBI =
# END SQL
0;
# SQL
# This is for standard DBI
eval {
die if $ENV{MINIVEND_NODBI};
require DBI and $Global::DBI = 1
};
# END SQL
# LDAP
eval {
die if $ENV{MINIVEND_NOLDAP};
require Net::LDAP and $Global::LDAP = 1
};
# END LDAP
# Now can use any type of database
AUTO: {
last AUTO if
(defined $ENV{MINIVEND_DBFILE} and $Global::DB_File = 1);
last AUTO if
(defined $ENV{MINIVEND_NODBM});
eval {require GDBM_File and $Global::GDBM = 1};
last AUTO if
(defined $ENV{MINIVEND_GDBM} and $Global::GDBM = 1);
eval {require DB_File and $Global::DB_File = 1};
}
if($Global::GDBM) {
require Vend::Table::GDBM;
import GDBM_File;
$Global::GDBM = 1;
$Global::Default_database = 'GDBM'
unless defined $Global::Default_database;
}
if($Global::DB_File) {
require Vend::Table::DB_File;
import DB_File;
$Global::DB_File = 1;
$Global::Default_database = 'DB_FILE'
unless defined $Global::Default_database;
}
$Global::Default_database = 'MEMORY'
unless defined $Global::Default_database;
require Vend::Table::InMemory;
}
use Vend::Util;
use Vend::Server;
use Vend::Session;
use Vend::Config;
# You might try commenting out these lines and uncommenting the ones
# below to compact memory size
# NOAUTOUSE
#use Vend::Order;
#use Vend::Imagemap;
#use Vend::Error;
#use Vend::Control;
# END NOAUTOUSE
# You might try commenting out these lines and uncommenting the ones
# below to do development or test for strange problems
# AUTOUSE
use autouse 'Vend::Error' => qw/get_locale_message interaction_error do_lockout full_dump/;
use autouse 'Vend::Imagemap' => qw/action_map/;
use autouse 'Vend::Control' => qw/
signal_reconfig
signal_add
signal_remove
control_interchange
change_catalog_directive
change_global_directive
remove_catalog
add_catalog
change_catalog_directive
change_global_directive
/;
use autouse 'Vend::Order' => qw/
add_items
check_order
check_required
cyber_charge
encrypt_standard_cc
mail_order
onfly
route_order
validate_whole_cc
/;
# END AUTOUSE
# GLIMPSE
use Vend::Glimpse;
# END GLIMPSE
# TRACK
use Vend::Track;
# END TRACK
use Vend::Scan;
use Vend::TextSearch;
use Vend::DbSearch;
use Vend::Data;
use Vend::UserDB;
use Vend::Interpolate;
use Vend::Page;
use File::CounterFile;
if( ! $Global::Windows and $> == -1 || scalar(getpwuid($>)) eq 'nobody' ) {
warn errmsg("\aYou probably don't want to run as nobody!\n");
sleep 1;
warn errmsg("The security problems are on your head, though. Continuing...\n");
}
my $H;
sub http {
return $H;
}
sub response {
my ($output) = @_;
return 1 if $Vend::BuildingPages;
my $out = ref $output ? $output : \$output;
if (defined $Vend::CheckHTML) {
require Vend::External;
Vend::External::check_html($out);
}
$H->respond($out);
}
## DO ORDER
# Order an item with product code CODE.
sub do_order {
my($path) = @_;
my $code = $CGI::values{mv_arg};
#::logDebug("do_order: path=$path");
my $cart;
my $page;
# LEGACY
if($path =~ s:/(.*)::) {
$cart = $1;
if($cart =~ s:/(.*)::) {
$page = $1;
}
}
# END LEGACY
if(defined $CGI::values{mv_pc} and $CGI::values{mv_pc} =~ /_(\d+)/) {
$CGI::values{mv_order_quantity} = $1;
}
$CGI::values{mv_cartname} = $cart if $cart;
$CGI::values{mv_nextpage} = $page if $page;
# LEGACY
$CGI::values{mv_nextpage} = $CGI::values{mv_orderpage}
|| find_special_page('order')
if ! $CGI::values{mv_nextpage};
# END LEGACY
add_items($code);
return 1;
}
# Returns undef if interaction error
sub update_quantity {
return 1 unless defined $CGI::values{"quantity0"};
my($h, $i, $quantity, $modifier, $cart);
$cart = Vend::Cart::get_cart($CGI::values{mv_cartname});
if(ref $Vend::Cfg->{UseModifier}) {
foreach $h (@{$Vend::Cfg->{UseModifier}}) {
delete @{$::Values}{grep /^$h\d+$/, keys %$::Values};
foreach $i (0 .. $#$cart) {
#::logDebug("updating line $i modifiers: " . ::uneval($cart->[$i]));
$modifier = $CGI::values{"$h$i"} || undef;
if (defined($modifier)) {
$modifier =~ s/\0+/\0/g;
$modifier =~ s/\0$//;
$modifier =~ s/^\0//;
$modifier =~ s/\0/, /g;
$cart->[$i]->{$h} = $modifier;
$::Values->{"$h$i"} = $modifier;
delete $CGI::values{"$h$i"};
}
}
}
}
foreach $i (0 .. $#$cart) {
#::logDebug("updating line $i quantity: " . ::uneval($cart->[$i]));
$quantity = $CGI::values{"quantity$i"};
if (! defined $quantity) {
interaction_error("Variable '$quantity' not passed from form\n");
return undef;
}
elsif ($quantity =~ m/^\d*$/) {
$cart->[$i]->{'quantity'} = $quantity || 0;
}
elsif ($quantity =~ m/^[\d.]+$/
and $Vend::Cfg->{FractionalItems} ) {
$cart->[$i]->{'quantity'} = $quantity;
}
# This allows a multiple input of item quantity to
# pass -- FIRST ONE CONTROLS
elsif ($quantity =~ s/\0.*//) {
$CGI::values{"quantity$i"} = $quantity;
redo;
}
else {
my $item = $cart->[$i]->{'code'};
interaction_error("'$quantity' for item $item is not numeric\n");
return undef;
}
$::Values->{"quantity$i"} = delete $CGI::values{"quantity$i"};
}
#::logDebug("after update, cart is: " . ::uneval($cart));
# If the user has put in "0" for any quantity, delete that item
# from the order list.
Vend::Cart::toss_cart($cart);
#::logDebug("after toss, cart is: " . ::uneval($cart));
1;
}
sub set_db {
my ($base, $thing) = @_;
return ($base, $thing) unless $thing =~ /^(\w+):+(.*)/;
my $t = $1;
my $c = $2;
$Vend::WriteDatabase = 1 if $::Scratch->{mv_data_enable} =~ /\b$t\b/;
my $db = ::database_exists_ref($t);
return undef unless $db;
return ($db->ref(), $c);
}
## Update the user-entered fields.
sub update_data {
my($key,$value);
# Update a database record
# Check to see if this is allowed
if(! $::Scratch->{mv_data_enable}) {
logError(
"Attempted database update without permission, table=%s key=%s.",
$CGI::values{mv_data_table},
$CGI::values{$CGI::values{mv_data_key}},
);
return undef;
}
unless (defined $CGI::values{mv_data_table} and
defined $CGI::values{mv_data_key} ) {
logError("Attempted database operation without table, fields, or key.\n" .
"Table: '%s'\n" .
"Fields:'%s'\n" .
"Key: '%s'\n",
$CGI::values{mv_data_table},
$CGI::values{mv_data_fields},
$CGI::values{mv_data_key},
);
return undef;
}
my $function = lc (delete $CGI::values{mv_data_function});
if($function eq 'delete' and ! delete $CGI::values{mv_data_verify}) {
logError("update_data: DELETE without VERIFY, abort");
return undef;
}
my $table = $CGI::values{mv_data_table};
my $prikey = $CGI::values{mv_data_key};
my $decode = is_yes($CGI::values{mv_data_decode});
my ($ref, $db, $database);
$ref = $Vend::Cfg->{Database}->{$table} || '';
if (! $ref) {
logError("set: non-existent table %s", $table);
return undef;
}
$Vend::WriteDatabase{$table} = 1;
my $base_db = database_exists_ref($table)
or die "Not a defined database '$table': $!\n";
$base_db = $base_db->ref();
my @fields = grep $_ && $_ ne $prikey,
split /[\s\0,]+/, $CGI::values{mv_data_fields};
unshift(@fields, $prikey);
$function = 'update' unless $function;
my (%data);
for(@fields) {
$data{$_} = [];
}
while (($key, $value) = each %CGI::values) {
next unless defined $data{$key};
@{$data{$key}} = split /\0/, $value;
}
if (not defined $data{$prikey}) {
logError("No key '%s' in field specifier %s", $prikey, 'mv_data_fields');
return undef;
}
elsif ( ! @{$data{$prikey}}) {
logError("No key '%s' found for function='%s' table='%s'",
$prikey, $function, $CGI::values{mv_data_table},
);
return undef;
}
my ($query,$i);
my (@k);
my (@v);
my (@c);
#::logDebug("update_data:db=$db key=$prikey VALUES=" . ::uneval(\%CGI::values));
my $select_key;
for($i = 0; $i < @{$data{$prikey}}; $i++) {
@k = (); @v = ();
for(keys %data) {
next unless (length($value = $data{$_}->[$i]) || $CGI::values{mv_update_empty} );
push(@k, $_);
# LEGACY
HTML::Entities::decode($value) if $decode;
# END LEGACY
if(defined $CGI::values{"mv_data_filter_$_"}) {
$value = Vend::Interpolate::filter_value(
$CGI::values{"mv_data_filter_$_"},
$value,
$i,
);
}
$select_key = $value if $_ eq $prikey;
push(@v, $value);
}
if($function eq 'delete') {
$base_db->delete_record($select_key);
}
else {
my $field;
$key = $data{$prikey}->[$i];
while($field = shift @k) {
$value = shift @v;
next if $field eq $prikey;
my ($d, $f) = set_db($base_db, $field);
#::logDebug("update_data:db=$d key=$key field=$f value=$value");
$d->set_field($key, $f, $value);
}
}
}
if($CGI::values{mv_auto_export}) {
Vend::Data::export_database($table);
}
return;
}
# Parse the mv_click and mv_check special variables
sub parse_click {
my ($ref, $click, $extra) = @_;
my($codere) = '[\w-_#/.]+';
my $params;
#::logDebug("Looking for click $click");
if($params = $::Scratch->{$click}) {
# Do nothing, we found the click
#::logDebug("Found scratch click $click = |$params|");
}
elsif(defined ($params = $Vend::Cfg->{OrderProfileName}{$click}) ) {
# Do nothing, we found the click
$params = $Vend::Cfg->{OrderProfile}[$params];
#::logDebug("Found profile click $click = |$params|");
}
elsif(defined ($params = $Global::ProfilesName->{$click}) ) {
# Do nothing, we found the click
$params = $Global::Profiles->[$params];
#::logDebug("Found profile click $click = |$params|");
}
elsif($params = $::Scratch->{"mv_click $click"}) {
$::Scratch->{mv_click_arg} = $click;
}
elsif($params = $::Scratch->{mv_click}) {
$::Scratch->{mv_click_arg} = $click;
}
else {
#::logDebug("Found NO click $click");
return 1;
} # No click processor
my($var,$val,$parameter);
$params = interpolate_html($params);
my(@param) = split /\n+/, $params;
for(@param) {
next unless /\S/;
next if /^\s*#/;
s/^[\r\s]+//;
s/[\r\s]+$//;
$parameter = $_;
($var,$val) = split /[\s=]+/, $parameter, 2;
$val =~ s/&#(\d+);/chr($1)/ge;
$ref->{$var} = $val;
$extra->{$var} = $val
if defined $extra;
}
}
# This is the set of CGI-passed variables to ignore, in other words
# never set in the user session. If set in the mv_check pass, though,
# they will stick.
my %Ignore = qw(
mv_todo 1
mv_todo.submit.x 1
mv_todo.submit.y 1
mv_todo.return.x 1
mv_todo.return.y 1
mv_todo.checkout.x 1
mv_todo.checkout.y 1
mv_todo.todo.x 1
mv_todo.todo.y 1
mv_todo.map 1
mv_doit 1
mv_check 1
mv_click 1
mv_nextpage 1
mv_more_ip 1
mv_credit_card_number 1
);
sub update_values {
if( $Vend::Cfg->{CreditCardAuto} and $CGI::values{mv_credit_card_number} ) {
(
@{$::Values}{
qw/
mv_credit_card_valid
mv_credit_card_info
mv_credit_card_exp_month
mv_credit_card_exp_year
mv_credit_card_exp_all
mv_credit_card_type
mv_credit_card_reference
mv_credit_card_error
/ }
) = encrypt_standard_cc(\%CGI::values);
}
my ($key, $value);
while (($key, $value) = each %CGI::values) {
next if defined $Ignore{$key};
next if defined $Vend::Cfg->{FormIgnore}->{$key};
next if ($key =~ m/^quantity\d+$/);
# We add any checkbox ordered items, but don't update --
# we don't want to order them twice
$::Values->{$key} = $value;
}
}
sub update_user {
my($key,$value);
# Update the user-entered fields.
add_items() if defined $CGI::values{mv_order_item};
update_values();
if($CGI::values{mv_check}) {
my(@checks) = split /\s*[,\0]+\s*/, delete $CGI::values{mv_check};
my($check);
foreach $check (@checks) {
parse_click $::Values, $check, \%CGI::values;
}
}
check_save if defined $CGI::values{mv_save_session};
}
## DO PROCESS
sub do_click {
my($click, @clicks);
if(defined $CGI::values{mv_click}) {
@clicks = split /\s*[\0]+\s*/, $CGI::values{mv_click};
}
if(defined $CGI::values{mv_click_map}) {
my(@map) = split /\s*[\0]+\s*/, $CGI::values{mv_click_map};
foreach $click (@map) {
push (@clicks, $click)
if defined $CGI::values{"mv_click.$click.x"}
or defined $CGI::values{"$click.x"}
or $click = $CGI::values{"mv_click_$click"};
}
}
foreach $click (@clicks) {
parse_click \%CGI::values, $click;
}
return 1;
}
sub do_deliver {
my $file = $CGI::values{mv_data_file};
my $mode = $CGI::values{mv_acl_mode} || '';
if($::Scratch->{mv_deliver} ne $file
and
! Vend::UserDB::userdb(
'check_file_acl',
location => $file,
mode => $mode,
)
)
{
$Vend::StatusLine = "Status: 403\nContent-Type: text/html";
my $msg = get_locale_message(403, <<EOF);
<B>Authorization Required<B>
<P>
This server could not verify that you are authorized to access the document
requested.
EOF
::response($msg);
return 0;
}
if (! -f $file) {
$Vend::StatusLine = "Status: 404\nContent-Type: text/html";
my $msg = get_locale_message(404, <<EOF, $file);
<B>Not Found<B>
<P>
The requested file %s was not found on this server.
EOF
::response($msg);
return 0;
}
$Vend::StatusLine = "Content-Type: " .
($CGI::values{mv_content_type} || 'application/octet-stream');
::response( Vend::Util::readfile (
$CGI::values{mv_data_file},
$Global::NoAbsolute,
)
);
return 0;
}
my %form_action = (
search => \&do_search,
deliver => \&do_deliver,
submit =>
sub {
update_user();
update_quantity()
or return interaction_error("quantities");
my $ok;
my($missing,$next,$status,$final);
# Set shopping cart if necessary
# Vend::Items is tied, remember!
$Vend::Items = $CGI::values{mv_cartname}
if $CGI::values{mv_cartname};
CHECK_ORDER: {
# If the user sets this later, will be used
delete $Vend::Session->{mv_order_number};
if (defined $CGI::values{mv_order_profile}) {
($status,$final,$missing) =
check_order($CGI::values{mv_order_profile});
}
else {
$status = $final = 1;
}
my $provisional;
if ($status and defined $CGI::values{mv_order_route}) {
# This checks only route order profiles
#::logDebug("Routing order, pre-check");
($status, $provisional, $missing) = route_order(
$CGI::values{mv_order_route},
$Vend::Items,
'check',
);
}
$final = $provisional if ! $final;
#::logDebug("Routing status status=$status final=$final errors=$missing");
if($status) {
$CGI::values{mv_nextpage} = $::Values->{mv_successpage}
if $::Values->{mv_successpage};
$CGI::values{mv_nextpage} = $::Values->{mv_orderpage}
if ! $CGI::values{mv_nextpage};
}
else {
$CGI::values{mv_nextpage} = $::Values->{mv_failpage}
if $::Values->{mv_failpage};
$CGI::values{mv_nextpage} = find_special_page('needfield')
if ! $CGI::values{mv_nextpage};
undef $final;
}
return 1 unless $final;
my $order_no;
if (defined $CGI::values{mv_order_route}) {
# $ok will not be defined unless Route "supplant" was set
# $order_no will come back so we don't issue two of them
#::logDebug("Routing order");
($ok, $order_no) = route_order(
$CGI::values{mv_order_route},
$Vend::Items
);
}
my $mode = $CGI::values{mv_payment_mode};
if (! $ok and defined $Vend::Cfg->{ActionMap}{$mode}) {
($ok, $status) = $Vend::Cfg->{ActionMap}{$mode}->();
}
elsif(
$Vend::Cfg->{CyberCash}
and defined $CGI::values{mv_cyber_mode}
)
{
#::logDebug("Cyber charge");
$status = cyber_charge();
unless($status) {
$CGI::values->{mv_nextpage} = find_special_page('failed')
if ! $CGI::values->{mv_nextpage};
return 1;
}
}
# This function (followed down) now does the rudimentary
# backend ordering with AsciiTrack and the order report.
# If the "supplant" option was set in order routing it will
# not be used ($ok would have been defined)
# TRACK
$Vend::Track->finish_order ();
# END TRACK
#::logDebug("Order number=$order_no\n");
$ok = mail_order(undef, $order_no || undef) unless defined $ok;
#::logDebug("Order number=$order_no\n");
# Display a receipt if configured
if ($ok) {
eval {
display_special_page(
$::Values->{mv_order_receipt} ||
find_special_page('receipt')
);
};
if($@) {
my $msg = $@;
::logError(
'Display of receipt on order number %s failed: %s',
$::Values->{mv_order_number},
$msg,
);
}
}
else {
display_special_page(
find_special_page('failed'),
errmsg('Error transmitting order(%s): %s', $!, $@),
);
}
# Remove the items
@$Vend::Items = ();
put_session();
return 0;
}
},
refresh => sub {
update_quantity()
or return interaction_error("quantities");
# LEGACY
$CGI::values{mv_nextpage} = $CGI::values{mv_orderpage}
if $CGI::values{mv_orderpage};
# END LEGACY
$CGI::values{mv_nextpage} = $CGI::values{mv_orderpage}
|| find_special_page('order')
if ! $CGI::values{mv_nextpage};
update_user();
return 1;
},
set => sub {
update_user();
update_data();
return 1;
},
back => sub { return 1 },
return => sub {
update_user();
update_quantity()
or return interaction_error("quantities");
return 1;
},
cancel => sub {
put_session();
get_session();
init_session();
$CGI::values{mv_nextpage} = find_special_page('canceled')
if ! $CGI::values{mv_nextpage};
return 1;
},
);
$form_action{go} = $form_action{return};
# Process the completed order or search page.
sub do_process {
do_click();
my $todo = $CGI::values{mv_todo};
# Maybe we have an imagemap input, if not, use $doit
if ( ! defined $todo) {
if (defined $CGI::values{'mv_todo.x'}) {
my $x = $CGI::values{'mv_todo.x'};
my $y = $CGI::values{'mv_todo.y'};
my $map = $CGI::values{'mv_todo.map'};
$todo = Vend::Imagemap::action_map($x,$y,$map);
}
elsif (defined $CGI::values{'mv_todo.submit.x'}) {
$todo = 'submit';
}
elsif (defined $CGI::values{'mv_todo.checkout.x'}) {
$todo = 'checkout';
}
elsif (defined $CGI::values{'mv_todo.return.x'}) {
$todo = 'return';
}
else {
$todo = $CGI::values{mv_doit} if defined $CGI::values{mv_doit};
}
}
my ($sub, $status);
#Now determine the action on the todo
if (defined $Vend::Cfg->{FormAction}{$todo}) {
$sub = $Vend::Cfg->{FormAction}{$todo};
}
elsif (not $sub = $form_action{$todo} ) {
interaction_error("No action passed for processing\n");
return;
}
eval {
$status = $sub->($todo);
};
if($@) {
undef $status;
my $err = $@;
my $template = <<EOF;
Sorry, there was an error in processing this form action. Please
report the error or try again later.
EOF
$template .= "\n\nError: %s\n"
if $Global::DisplayErrors && $Vend::Cfg->{DisplayErrors}
;
$template = get_locale_message(500, $template, $err);
$template .= "($err)";
::response($template);
}
return $status;
}
sub config_named_catalog {
my ($cat_name, $source, $build) = @_;
my ($g,$c,$conf);
$g = $Global::Catalog{$cat_name};
unless (defined $g) {
logGlobal( "Can't find catalog '%s'" , $cat_name );
return undef;
}
$Vend::Log_suppress = 1;
logGlobal( "Config '%s' %s", $g->{'name'}, $source )
unless $Vend::Quiet;
undef $Vend::Log_suppress;
chdir $g->{'dir'}
or die "Couldn't change to $g->{'dir'}: $!\n";
$conf = $g->{'dir'} . '/etc';
eval {
$c = config($g->{'name'},
$g->{'dir'},
$conf,
$g->{'base'} || undef,
# OPTION_EXTENSION
# $Vend::CommandLine->{$g->{'name'}} || undef
# END OPTION_EXTENSION
);
};
if($@) {
my $msg = $@;
logGlobal( "%s config error: %s" , $g->{'name'}, $msg );
return undef;
}
return $c if defined $g->{'base'};
eval {
$Vend::Cfg = $c;
# STATICPAGE
READSTATIC: {
my $basedir = $c->{PageDir};
if ($c->{Static}) {
last READSTATIC if $c->{StaticDBM};
last READSTATIC if ! -f "$basedir/.static";
print "loading static page names..." unless $Vend::Quiet;
last READSTATIC if $c->{StaticDBM};
open STATICPAGE, "< $basedir/.static"
or warn <<EOF;
Couldn't read static page status file $basedir/.static: $!
EOF
while(<STATICPAGE>) {