r4254 Move "gateway" directory out of "wwwroot" and provide a mean to reconfigure
[racktables] / wwwroot / 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> [filename1] [filename2] [...]
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=$1
23 endpoint=$2
24 handler=$3
25 # 0 or more files
26 files=$4
27 # sanity checks
28 if [ -z "$user" -o -z "$endpoint" -o -z "$handler" ]; then
29 echo 'ERR!invalid arguments'
30 return
31 fi
32 for cfgfile in $files; do
33 if [ ! -f "$cfgfile" ]; then
34 echo "ERR!File $cfgfile is missing."
35 return
36 fi
37 done
38 if [ ! -x "$MYDIR/$handler.install" ]; then
39 echo "ERR!Cannot execute $MYDIR/$handler.install"
40 return
41 fi
42 "$MYDIR/$handler.install" "$user" "$endpoint" $files
43 ret=$?
44 if [ $ret = 0 ]; then
45 echo "OK!"
46 else
47 echo "ERR!Main dispatcher: handler '$handler' returned code $ret"
48 fi
49 }
50
51 # main loop
52 while read cmd arg1 arg2 arg3 arg4; do
53 case $cmd in
54 submit)
55 do_submit "$arg1" "$arg2" "$arg3" "$arg4"
56 ;;
57 *)
58 echo "ERR!unknown command $cmd"
59 esac
60 done
61
62 exit 0