r2119 - include handler name into sendfile "ok" message
[racktables] / gateways / sendfile / main
1 #!/bin/sh
2
3 # This is a RackTables gateway for arbitrary file export. File contents doesn't
4 # matter here and will only be somehow sent to the remote host for further
5 # processing.
6 #
7 # The only supported command is:
8 #
9 # * submit <username> <endpoint> <handler name> <data file name>: send the file
10 #
11 # Handler name can be any string used to distinguish different file processors.
12 # The temporary file will be passed to a script in current directory, if it exists.
13 # Script name is "<handlername>.install"
14
15 user=
16 endpoint=
17 cfgfile=
18 MYDIR=`dirname $0`
19
20 do_submit()
21 {
22 user=`echo $args | cut -s -d' ' -f1`
23 endpoint=`echo $args | cut -s -d' ' -f2`
24 handler=`echo $args | cut -s -d' ' -f3`
25 cfgfile=`echo $args | cut -s -d' ' -f4`
26 # sanity checks
27 if [ -z "$user" -o -z "$endpoint" -o -z "$handler" -o -z "$cfgfile" ]; then
28 echo 'ERR!invalid arguments'
29 return
30 fi
31 if [ ! -f "$cfgfile" ]; then
32 echo "ERR!File $cfgfile is missing."
33 return
34 fi
35 if [ ! -x "$MYDIR/$handler.install" ]; then
36 echo "ERR!Cannot execute $MYDIR/$handler.install"
37 return
38 fi
39 "$MYDIR/$handler.install" $user $endpoint $cfgfile
40 ret=$?
41 if [ $ret = 0 ]; then
42 echo "OK!"
43 else
44 echo "ERR!File handler returned code $ret"
45 fi
46 }
47
48 # main loop
49 while read cmd args; do
50 case $cmd in
51 submit)
52 do_submit $args
53 ;;
54 *)
55 echo "ERR!unknown command $cmd"
56 esac
57 done
58
59 exit 0