source: client/shared/lib/httpd/api/LogCommand.sh @ f53877a

webconsole3
Last change on this file since f53877a was 6240405, checked in by jm.bardallo <juanmanuel.bardallo@…>, 7 years ago

Version inicial de la consola web 3.0, de momento funcionará paralelamente a la consola web antigua

  • Property mode set to 100644
File size: 2.5 KB
Line 
1#! /bin/bash -wT
2
3# (internal) routine to store POST data
4function cgi_get_POST_vars() {
5    # check content type
6    # FIXME: not sure if we could handle uploads with this..
7    #if [ "${CONTENT_TYPE}" != "application/x-www-form-urlencoded" ]; then
8    #    return
9    #fi
10    # save POST variables (only first time this is called)
11    [ -z "$QUERY_STRING_POST" \
12      -a "$REQUEST_METHOD" = "POST" -a ! -z "$CONTENT_LENGTH" ] && \
13        read -n $CONTENT_LENGTH QUERY_STRING_POST
14   
15    #echo $QUERY_STRING_POST
16    return
17}
18
19
20function cgi_decodevar() {
21    local url_encoded="${1//+/ }"
22    printf '%b' "${url_encoded//%/\\x}"
23}
24
25 
26# routine to get variables from http requests
27# usage: cgi_getvars method varname1 [.. varnameN]
28# method is either GET or POST or BOTH
29# the magic varible name ALL gets everything
30function cgi_getvars() {
31    [ $# -lt 2 ] && return
32    local q="" p k v s
33    # get query
34    case $1 in
35        GET)
36            [ ! -z "${QUERY_STRING}" ] && q="${QUERY_STRING}&"
37            ;;
38        POST)
39            cgi_get_POST_vars
40            [ ! -z "${QUERY_STRING_POST}" ] && q="${QUERY_STRING_POST}&"
41            ;;
42        BOTH)
43            [ ! -z "${QUERY_STRING}" ] && q="${QUERY_STRING}&"
44            cgi_get_POST_vars
45            [ ! -z "${QUERY_STRING_POST}" ] && q="${q}${QUERY_STRING_POST}&"
46
47
48            ;;
49    esac
50    shift
51    s=" $* "
52    # parse the query data
53    while [ ! -z "$q" ]; do
54        p="${q%%&*}"  # get first part of query string
55        k="${p%%=*}"  # get the key (variable name) from it
56        v="${p#*=}"   # get the value from it
57        q="${q#$p&*}" # strip first part from query string
58        # decode and evaluate var if requested
59        [ "$1" = "ALL" -o "${s/ $k /}" != "$s" ] && \
60            eval "$k=\"$(cgi_decodevar $v | sed 's/[\"\\\$]/\\&/g')\""
61       
62    done
63    return
64}
65
66function debug() {
67/bin/cat <<EOF
68Content-type: text/html
69
70
71<html>
72<head><title>Test</title></head>
73<body>
74<h1>Test for Bash CGI-Scripting</h1>
75<h2>POST values from Standard-In</h2>
76<pre>
77$(</dev/stdin)
78</pre>
79<h2>Values</h2>
80<pre>
81Auth: $AUTH
82Method: $METHOD
83id: $id
84script: $script
85redirect_uri: $redirect_uri
86</pre>
87<h2>Environment</h2>
88<pre>$(env)</pre>
89</body>
90</html
91EOF
92
93}
94
95AUTH=$HTTP_AUTHORIZATION
96METHOD=$REQUEST_METHOD
97
98#echo $AUTH
99#echo $METHOD
100#echo $CONTENT_LENGTH
101
102cgi_getvars BOTH ALL
103
104debug
105
106
107
108#exec >&-
109#exec 2>&-
110
111# Una vez comprobado que el request es correcto, ejecutamos los comandos y liberamos la conexion
112nohup /bin/bash -c "./ogAgent.sh $id \"$script\" \"$redirect_uri\"" &>/dev/null &
113
Note: See TracBrowser for help on using the repository browser.