Project

General

Profile

patch20180129.txt

Marco Mambelli, 01/29/2018 03:24 PM

 
1
diff --git a/creation/web_base/glidein_lib.sh b/creation/web_base/glidein_lib.sh
2
index 95e76c74..11d8c0e5 100644
3
--- a/creation/web_base/glidein_lib.sh
4
+++ b/creation/web_base/glidein_lib.sh
5
@@ -1,5 +1,19 @@
6
 #!/bin/bash
7
 
8
+function sanitizedCat {
9
+    # This function prints the saniteized content of the file passed as argument.
10
+    # If the content is a number it just prints it, if it is an alphanumeric string it adds quotes
11
+    # and prints it, otherwise it prints "WrongFormat"
12
+    VAL=$(cat "$1")
13
+    if [[ $VAL =~ ^[0-9]+(.[0-9]+)?$ ]]; then
14
+        echo $VAL
15
+    elif [[ $VAL =~ ^[^\"\\]+$ ]]; then
16
+        echo \"$VAL\"
17
+    else
18
+        echo '"WrongFormat"'
19
+    fi
20
+}
21
+
22
 function getValueFromFileOrURL {
23
     # The function takes as an argument a filename and a variable name
24
     # The variable contains the url or the directory location of the file,
25
@@ -11,7 +25,7 @@ function getValueFromFileOrURL {
26
     VARNAME="$2"
27
     if [ -n "$VARNAME" ]; then
28
         if [ -f "$VARNAME/$FILENAME" ]; then
29
-            cat "$VARNAME/$FILENAME"
30
+            sanitizedCat "$VARNAME/$FILENAME"
31
             return
32
         else
33
             #check if shutdowntime job is a URL and wget it
34
@@ -22,7 +36,7 @@ function getValueFromFileOrURL {
35
                 TMPFILE=tmp_$(uuidgen)
36
                 wget -qO- $ADDRESS > $TMPFILE
37
                 if [ $? -eq 0 ]; then
38
-                    cat $TMPFILE
39
+                    sanitizedCat $TMPFILE
40
                     rm $TMPFILE
41
                     return
42
                 fi