From 67a7819629ed4c7f96078598d8c797ee9a8dea3f Mon Sep 17 00:00:00 2001
From: Benedikt Kroening <benedikt.kroening@open-xchange.com>
Date: Fri, 25 Oct 2019 15:05:10 +0200
Subject: [PATCH] Added install template, added tokenlogin test page

---
 config/frontend/tokenlogin.html               | 88 +++++++++++++++++++
 docker/singlenode/Dockerfile                  |  4 +-
 features/README.md                            |  2 +
 features/documentconverter.sh                 |  1 -
 ...cumentconverter.sh => install-template.sh} | 76 +++++++++++-----
 5 files changed, 147 insertions(+), 24 deletions(-)
 create mode 100644 config/frontend/tokenlogin.html
 rename setup/{install-documentconverter.sh => install-template.sh} (50%)
 mode change 100755 => 100644

diff --git a/config/frontend/tokenlogin.html b/config/frontend/tokenlogin.html
new file mode 100644
index 0000000..13ff7e7
--- /dev/null
+++ b/config/frontend/tokenlogin.html
@@ -0,0 +1,88 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
+<html>
+<head>
+<meta http-equiv="content-type" content="text/html; charset=UTF-8">
+<meta http-equiv="cache-control" content="no-cache">
+<title>Login</title>
+<script type="text/javascript">
+function uuid() {
+    function hex(len, x) {
+        if (x === undefined) x = Math.random();
+        var s = new Array(len);
+        for (var i = 0; i < len; i++) {
+            x *= 16;
+            var digit = x & 15;
+            s[i] = digit + (digit < 10 ? 48 : 87); // '0' and 'a' - 10
+        }
+        return String.fromCharCode.apply(String, s);
+    }
+    return [hex(8), "-", hex(4), "-4", hex(3), "-", hex(4, 0.5 + Math.random() / 4), "-", hex(12)].join("");
+}
+
+window.addEventListener("load", function () {
+  function sendData() {
+    var XHR = new XMLHttpRequest();
+    var target = "";
+
+    // Bind the FormData object and the form element
+    var FD = new FormData(form);
+    // enhance with clientToken
+    static_uuid = uuid();
+    FD.append('clientToken', static_uuid);
+    FD.append('jsonResponse', true);
+
+    // Define what happens on successful data submission
+    XHR.addEventListener("load", function(event) {
+      // successful login; now redirect into the session
+      var response=JSON.parse(event.target.responseText);
+      // check for errors
+      if (response.error || !response.url) {
+        error_message.innerHTML = response.error;
+      } else {
+        // finally point to the target
+        window.location.replace(target + response.url + "&clientToken=" + static_uuid);
+      }
+    });
+
+    // Define what happens in case of error
+    XHR.addEventListener("error", function(event) {
+      alert('Oops! Something went wrong.');
+    });
+
+    // Set up our request
+    XHR.open("POST", target + "/appsuite/api/login?action=tokenLogin&authId=" + uuid());
+
+    // The data sent is what the user provided in the form
+    XHR.send(new URLSearchParams(FD));
+  }
+
+  // Access the form element...
+  var form = document.getElementById("myForm");
+  var error_message = document.getElementById("error");
+
+  // ...and take over its submit event.
+  form.addEventListener("submit", function (event) {
+    event.preventDefault();
+
+    sendData();
+  });
+});
+</script>
+</head>
+
+<body>
+    <form id='myForm'>
+            <label for="login">Username: </label>
+            <input type="text" name="login" id="login"><br>
+            <label for="password">Password:  </label>
+            <input type="password" name="password" id="password"><br>
+            <input type="submit" value="Login">
+            <!-- autologin=true could be leading to unexpected results if there still is a valid session associated with the used browser -->
+            <input type="hidden" name="autologin" value="false">
+            <input type="hidden" name="client" value="open-xchange-appsuite">
+            <input type="hidden" name="version" value="Sample Loginpage">
+            <input type="hidden" name="uiWebPath" value="/appsuite/">
+    </form>
+    <div id='error' />
+</body>
+</html>
\ No newline at end of file
diff --git a/docker/singlenode/Dockerfile b/docker/singlenode/Dockerfile
index 4802c5c..03d5aef 100644
--- a/docker/singlenode/Dockerfile
+++ b/docker/singlenode/Dockerfile
@@ -67,7 +67,9 @@ ENV INSTALL_DOCUMENTCONVERTER=${ARG_INSTALL_DOCUMENTCONVERTER}
 ENV INSTALL_TYPE=${ARG_INSTALL_TYPE}
 
 ADD . /ox-installer
-RUN /ox-installer/ox-installer.sh --docker --config /ox-installer/docker/singlenode/config 
+
+RUN /ox-installer/ox-installer.sh --docker --config /ox-installer/docker/singlenode/config
+
 RUN chsh -s /bin/bash open-xchange && \ 
     echo PATH=$PATH:/opt/open-xchange/sbin/ >> ~/.bashrc && \
     mkdir /var/run/apache2 && \
diff --git a/features/README.md b/features/README.md
index ab9b39c..6380009 100755
--- a/features/README.md
+++ b/features/README.md
@@ -1,2 +1,4 @@
 # Optional features for later use
 These scripts are used for quickly installing/enabling specific features for the installed OX instance
+
+
diff --git a/features/documentconverter.sh b/features/documentconverter.sh
index 9f87a09..ca60506 100755
--- a/features/documentconverter.sh
+++ b/features/documentconverter.sh
@@ -126,7 +126,6 @@ if [ "$INSTALL_DOCUMENTCONVERTER" = true ] ; then
     PACKAGES="readerengine open-xchange-documentconverter-server open-xchange-documentconverter-api "
     installPackages ${PACKAGES}
 
-    # TODO: docker supervisor service file
     restartService open-xchange-documentconverter-server
     sleep 5
   fi
diff --git a/setup/install-documentconverter.sh b/setup/install-template.sh
old mode 100755
new mode 100644
similarity index 50%
rename from setup/install-documentconverter.sh
rename to setup/install-template.sh
index a9969d4..a4cabd2
--- a/setup/install-documentconverter.sh
+++ b/setup/install-template.sh
@@ -28,31 +28,63 @@ SCRIPT_DIR="$( cd "$(dirname "$0")" ; pwd -P)"
 source ${SCRIPT_DIR}/../lib/common.bash
 source ${SCRIPT_DIR}/../lib/setup.bash
 
-if [[ -z "${AS_DOCUMENTCONVERTER_API_VERSION}" ]] || [[ -z "${AS_DOCUMENTCONVERTER_VERSION}" ]] && [[ "${INSTALL_DOCUMENTCONVERTER}" = true  ]]; then
-    echo ""
-    echo "WARNING: There is no documentconverter repo specified in setup/versions even though it is set for installation".
-    echo ""
-    sleep 5
+INSTALL_FOO=false
+INSTALL_BAR=false
+
+## Help text
+show_usage() {
+echo -n "
+    --foo
+    --bar <value>
+
+"
+}
+
+### reading config from command line; overriding defaults
+POSITIONAL=()
+while [[ $# -gt 0 ]]
+do
+key="$1"
+
+case $key in
+    -h|--help)
+    show_usage
     exit 0
+    shift
+    ;;
+    --debug)
+    echo "WARNING: Debug flag set (--debug)"
+    set -x
+    shift
+    ;;
+    --foo) # non value argument
+    INSTALL_FOO=true
+    shift
+    ;;
+    --bar) # argument with value 
+    INSTALL_BAR=true
+    BAR_VAL=$2
+    shift
+    shift
+    ;;
+    *) # unknown option
+    echo "Unknonwn option: $1"
+    POSITIONAL+=("$1") # save it in an array for later
+    shift 
+    ;;
+esac
+done
+set -- "${POSITIONAL[@]}" # restore positional parameters
+
+
+# 
+if [[ "${INSTALL_FOO}" = true  ]]; then
+    PACKAGES="${PACKAGES} "
 fi
 
-# NOTE:
 # 
-PACKAGES="open-xchange-documentconverter-server open-xchange-documentconverter-api "
-#open-xchange-documents-collaboration # comes with 7.10.3+
+if [[ "${INSTALL_BAR}" = true  ]]; then
+    PACKAGES="${PACKAGES} "
+fi
 
 installPackages ${PACKAGES}
-
-# if [[ "${INSTALL_TYPE}" != "docker" ]]; then
-
-#     echo ""
-#     # Post-install actions
-#     # if [[ "${DIST}" == "DebianJessie" ]]; then
-#     #     echo "Nothing to do here..."
-#     #     #update-alternatives --set java /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java 2>/dev/null
-#     # elif [[ "${DIST}" == "CENTOS7" ]] || [[ "${DIST}" == "RHEL7" ]] || [[ "${DIST}" == "SLES12" ]]; then
-#     #     chkconfig open-xchange on
-#     # elif [[ "${DIST}" == "CENTOS6" ]] || [[ "${DIST}" == "RHEL6" ]]; then
-#     #     chkconfig --level 345 open-xchange on
-#     # fi
-# fi
-- 
GitLab