1 |
#!/usr/bin/perl -w |
#!/usr/bin/suidperl -w |
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 |
# |
# |
8 |
|
|
9 |
use strict; |
use strict; |
10 |
use vars qw($Msgno); |
use vars qw($Msgno); |
11 |
|
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 SAP::Rfc; |
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"; |
$msgdir .= "$$"; # append PID to make it unique |
26 |
|
my $log = $config->{log} || die "config: no <log> defined"; |
27 |
my $rfc = new SAP::Rfc( |
|
28 |
ASHOST => 'cipkg', |
# open log and redirect die to it... |
29 |
USER => 'rfctest', |
open(LOG,">> $log") || warn "open log $log: $!"; |
30 |
PASSWD => 'dinamo', |
local $SIG{__DIE__} = sub { print LOG $_[0] ; die $_[0] }; |
|
LANG => 'HR', |
|
|
CLIENT => '200', |
|
|
SYSNR => '20', |
|
|
TRACE => '0' |
|
|
) || die "new: $!"; |
|
|
|
|
|
my $it = $rfc->discover("Z_ZDMM0123_SIGMA_RFC") || die "discover: $!"; |
|
|
|
|
|
$it->FILEPATH( "ZSIGMA" ); |
|
|
$it->PORT( "ZIDOC" ); |
|
|
|
|
|
# no user editable content beyond this point |
|
31 |
|
|
32 |
umask 022; # world readable |
umask 022; # world readable |
33 |
|
|
|
open(LOG,">> $log") || warn "log $log: $!"; |
|
|
|
|
|
$rfc->is_connected || die "not connected"; |
|
34 |
|
|
35 |
#------------------------------------------------------------ |
#------------------------------------------------------------ |
36 |
# dump_entity - dump an entity's file info |
# dump_entity - dump an entity's file info |
55 |
$new=~s/ +/_/g; |
$new=~s/ +/_/g; |
56 |
$new=~s/^.*\/([^\/]+)$/$1/g; |
$new=~s/^.*\/([^\/]+)$/$1/g; |
57 |
$new=~s/[^a-zA-Z._0-9]//g; |
$new=~s/[^a-zA-Z._0-9]//g; |
58 |
|
|
59 |
|
# never try to overwrite file |
60 |
|
my $suffix = ""; |
61 |
|
while (-e "$outdir/$new$suffix") { $suffix++; } |
62 |
|
$new .= $suffix; |
63 |
|
|
64 |
rename $file,"$outdir/$new" || die "move $file -> $outdir/$new: $!"; |
rename $file,"$outdir/$new" || die "move $file -> $outdir/$new: $!"; |
65 |
print LOG scalar localtime," $new\n"; |
print LOG scalar localtime," $new\n"; |
66 |
|
|
67 |
# now, call SAP rfc |
# now, call SAP rfc |
68 |
|
|
69 |
$it->FILENAME( "$new" ); |
# init SAP rfc |
70 |
|
# |
71 |
|
my $rfc = new SAP::Rfc( |
72 |
|
ASHOST => $config->{sap}->{ashost}, |
73 |
|
USER => $config->{sap}->{user}, |
74 |
|
PASSWD => $config->{sap}->{passwd}, |
75 |
|
LANG => $config->{sap}->{lang}, |
76 |
|
CLIENT => $config->{sap}->{client}, |
77 |
|
SYSNR => $config->{sap}->{sysnr}, |
78 |
|
TRACE => $config->{sap}->{trace} |
79 |
|
) || die "new: $!"; |
80 |
|
|
81 |
|
$rfc->is_connected || die "SAP rfc: not connected"; |
82 |
|
|
83 |
|
my $it = $rfc->discover($config->{sap}->{discover}) || die "discover: $!"; |
84 |
|
|
85 |
|
$it->FILEPATH( $config->{sap}->{filepath} ); |
86 |
|
$it->FILENAME( $new ); |
87 |
|
$it->PORT( $config->{sap}->{port} ); |
88 |
|
|
89 |
$rfc->callrfc( $it ); |
$rfc->callrfc( $it ); |
90 |
|
|
91 |
|
$rfc->close(); |
92 |
} |
} |
93 |
} |
} |
94 |
} |
} |
95 |
|
|
|
$rfc->close(); |
|
96 |
|
|
97 |
#------------------------------------------------------------ |
#------------------------------------------------------------ |
98 |
# main |
# main |