1 |
#!/usr/bin/perl -w |
#!/usr/bin/suidperl |
2 |
|
|
3 |
# read e-mail from stdit (pipe from /etc/aliases) and call SAP rfc function |
# read e-mail from stdit (pipe from /etc/aliases) and call SAP rfc function |
4 |
# |
# |
11 |
use SAP::Rfc; |
use SAP::Rfc; |
12 |
use Digest::MD5 qw(md5_hex); |
use Digest::MD5 qw(md5_hex); |
13 |
use MIME::Parser; |
use MIME::Parser; |
14 |
|
use XML::Simple; |
15 |
|
use Data::Dumper; |
16 |
|
|
17 |
# configuration |
# read configuration from xml file |
18 |
|
my $config = XMLin(); |
19 |
|
|
20 |
# directory in which attachemnts will be left |
# directory in which attachemnts will be left |
21 |
my $outdir = "/var/autofs/data/export_sigma"; |
my $outdir = $config->{outdir} || die "config: on <outdir> defined"; |
22 |
# temporary directory (ON SAME FILESYSTEM AS $outdir -- we use rename!) |
# temporary directory (ON SAME FILESYSTEM AS $outdir -- we use rename!) |
23 |
# for extraction of *ALL* attachements |
# for extraction of *ALL* attachements |
24 |
my $msgdir = "/var/autofs/data/export_sigma/mime$$"; # temp |
my $msgdir = $config->{msgdir} || die "config: no <msgdir> defined"; |
25 |
my $log = "/data/sap_sigma/orders.log"; |
my $mntdir = $msgdir; |
26 |
|
$msgdir .="/mime"; |
27 |
|
$msgdir .= "$$"; # append PID to make it unique |
28 |
|
my $log = $config->{log} || die "config: no <log> defined"; |
29 |
|
|
30 |
# open log and redirect die to it... |
# open log and redirect die to it... |
31 |
open(LOG,">> $log") || warn "open log $log: $!"; |
open(LOG,">> $log") || warn "open log $log: $!"; |
32 |
local $SIG{__DIE__} = sub { print LOG $_[0] ; die $_[0] }; |
local $SIG{__DIE__} = sub { print LOG $_[0] ; die $_[0] }; |
33 |
|
|
|
# init SAP rfc |
|
|
# |
|
|
my $rfc = new SAP::Rfc( |
|
|
ASHOST => 'cipkg', |
|
|
USER => 'rfctest', |
|
|
PASSWD => 'dinamo', |
|
|
LANG => 'HR', |
|
|
CLIENT => '200', |
|
|
SYSNR => '20', |
|
|
TRACE => '0' |
|
|
) || die "new: $!"; |
|
|
|
|
|
|
|
|
# no user editable content beyond this point |
|
|
|
|
34 |
umask 022; # world readable |
umask 022; # world readable |
35 |
|
|
|
$rfc->is_connected || die "SAP rfc: not connected"; |
|
36 |
|
|
37 |
#------------------------------------------------------------ |
#------------------------------------------------------------ |
38 |
# dump_entity - dump an entity's file info |
# dump_entity - dump an entity's file info |
64 |
$new .= $suffix; |
$new .= $suffix; |
65 |
|
|
66 |
rename $file,"$outdir/$new" || die "move $file -> $outdir/$new: $!"; |
rename $file,"$outdir/$new" || die "move $file -> $outdir/$new: $!"; |
67 |
print LOG scalar localtime," $new\n"; |
my $prog = $0; |
68 |
|
$prog =~ s/^.*\/([^\/])+$/$1/g; |
69 |
|
print LOG scalar localtime," $prog $new\n"; |
70 |
|
|
71 |
# now, call SAP rfc |
# now, call SAP rfc |
72 |
|
|
73 |
my $it = $rfc->discover("Z_ZDMM0123_SIGMA_RFC") || die "discover: $!"; |
# init SAP rfc |
74 |
|
# |
75 |
|
my $rfc = new SAP::Rfc( |
76 |
|
ASHOST => $config->{sap}->{ashost}, |
77 |
|
USER => $config->{sap}->{user}, |
78 |
|
PASSWD => $config->{sap}->{passwd}, |
79 |
|
LANG => $config->{sap}->{lang}, |
80 |
|
CLIENT => $config->{sap}->{client}, |
81 |
|
SYSNR => $config->{sap}->{sysnr}, |
82 |
|
TRACE => $config->{sap}->{trace} |
83 |
|
) || die "new: $!"; |
84 |
|
|
85 |
|
$rfc->is_connected || die "SAP rfc: not connected"; |
86 |
|
|
87 |
|
my $it = $rfc->discover($config->{sap}->{discover}) || die "discover: $!"; |
88 |
|
|
89 |
|
foreach my $p ($config->{sap}->{params}) { |
90 |
|
foreach my $p_name (keys %{$p}) { |
91 |
|
$it->$p_name($p->{$p_name}); |
92 |
|
} |
93 |
|
} |
94 |
|
|
|
$it->FILEPATH( "ZSIGMA" ); |
|
95 |
$it->FILENAME( $new ); |
$it->FILENAME( $new ); |
|
$it->PORT( "ZIDOC" ); |
|
96 |
|
|
97 |
$rfc->callrfc( $it ); |
$rfc->callrfc( $it ); |
98 |
|
|
99 |
|
$rfc->close(); |
100 |
} |
} |
101 |
} |
} |
102 |
} |
} |
103 |
|
|
|
$rfc->close(); |
|
104 |
|
|
105 |
#------------------------------------------------------------ |
#------------------------------------------------------------ |
106 |
# main |
# main |
108 |
sub main { |
sub main { |
109 |
my $file; |
my $file; |
110 |
my $entity; |
my $entity; |
111 |
|
|
112 |
mkdir $msgdir,0755 || die "can't create $msgdir: $!"; |
chdir ($mntdir) || die "can't chdir to $mntdir: $!"; |
113 |
|
mkdir ($msgdir,0755) || die `id`."can't create $msgdir: $!"; |
114 |
die "problems with creation of directory $msgdir: $!" if (! -w $msgdir); |
die "problems with creation of directory $msgdir: $!" if (! -w $msgdir); |
115 |
|
|
116 |
my $parser = new MIME::Parser; |
my $parser = new MIME::Parser; |