#!/bin/bash
#
#########################################################################################
# Script: 		make_http_https.sh
# Description: 	Enable Application and Report https communication
# Author: 		ABS Laundry Business Solutions
# Version: 		9.09.02
#### Changelog of script ################################################################
# Date        Author    Version 	Change    
# 26-May-2025 RAY	    9.09.02 	Enable Application Server https
# 01-Jun-2025 RAY       9.09.02     ABSSolute Server - Standardization & hot redeploy - TS-839
#########################################################################################

### Called as follows:
### HandleCustomProperties_app $ABSM_ENVIRONMENT $ABSM_SERVERNAME $ABSM_SERVICE $ABSM_TYPE $ABSM_SLOT $ABSM_LOCAL_HOME $ABSM_REMOTE_HOME $ABSM_USER $ABSM_PWD $ABSM_ORATNS $ABSM_ORAHOME $ABSM_DBSERVERNAME $ABSM_DBDRIVERTYPE $ABSM_DBPORTNUMBER $ABSM_HEAPSPACE $ABSM_STATIONNR $ABSM_GFUSER $ABSM_GFPASWRD $ABSM_GFDOMAIN $ABSM_WEBCONTEXT $ABSM_WEBNAME $ABSM_WEBLIB $ABSM_CONNAPPSRV $ABSM_CONNAPPSLOT $ABSM_CONNREPSRV $ABSM_CONNREPSLOT $ABSM_USENATIVE $ABSM_EXCLUDECUSTREP $ABSM_WEB_VERSION $ABSM_CLIENTDISTR_SRV $ABSM_CLIENTDISTR_DIR $ABSM_USER2 $ABSM_PWD2 $ABSM_STATIONNR2 $ABSM_INET_KEY

HandleCustomProperties_app_https()
{
  ABSM_ENVIRONMENT="${1}"
  ABSM_SERVERNAME="${2}"  
  ABSM_SERVICE="${3}"
  ABSM_TYPE="${4}"
  ABSM_SLOT="${5}"
  ABSM_LOCAL_HOME="${6}"
  ABSM_REMOTE_HOME="${7}"
  ABSM_USER="${8}"
  ABSM_PWD="${9}"
  ABSM_ORATNS="${10}"
  ABSM_ORAHOME="${11}"
  ABSM_DBSERVERNAME="${12}"
  ABSM_DBDRIVERTYPE="${13}"
  ABSM_DBPORTNUMBER="${14}"
  ABSM_HEAPSPACE="${15}"
  ABSM_STATIONNR="${16}"
  ABSM_GFUSER="${17}"
  ABSM_GFPASWRD="${18}"
  ABSM_GFDOMAIN="${19}"
  ABSM_WEBCONTEXT="${20}"
  ABSM_WEBNAME="${21}"
  ABSM_WEBLIB="${22}"
  ABSM_CONNAPPSRV="${23}"
  ABSM_CONNAPPSLOT="${24}"
  ABSM_CONNREPSRV="${25}"
  ABSM_CONNREPSLOT="${26}"
  ABSM_USENATIVE="${27}"
  ABSM_EXCLUDECUSTREP="${28}"
  ABSM_WEB_VERSION="${29}"
  ABSM_CLIENTDISTR_SRV="${30}"
  ABSM_CLIENTDISTR_DIR="${31}"
  ABSM_USER2="${32}"
  ABSM_PWD2="${33}"
  ABSM_STATIONNR2="${34}"
  ABSM_INET_KEY="${35}"

  # make sure the slot length is 2 characters. This is necessary to determine the correct portnumbers
  [ ${#ABSM_SLOT} == "1" ] && ABSM_SLOT="0"${ABSM_SLOT}
  
  # Application Server HTTPS Port
  V_NSAPPSERVERHTTPSPORT="5"${ABSM_SLOT}"17"
  
  # Application Properties reference - HTTP/HTTPS
  APP_PROPERTY_01="server.port"
  APP_PROPERTY_11="server.port="
  APP_PROPERTY_21="server.port="
  APP_PROPERTY_02="server.ssl.enabled"
  APP_PROPERTY_12="server.ssl.enabled="
  APP_PROPERTY_22="server.ssl.enabled=false"
  APP_PROPERTY_03="server.ssl.bundle"
  APP_PROPERTY_13="server.ssl.bundle="
  APP_PROPERTY_23="server.ssl.bundle=absbundle"
  APP_PROPERTY_04="spring.ssl.bundle.jks.absbundle.keystore.type"
  APP_PROPERTY_14="spring.ssl.bundle.jks.absbundle.keystore.type="
  APP_PROPERTY_24="spring.ssl.bundle.jks.absbundle.keystore.type=PKCS12"
  APP_PROPERTY_05="spring.ssl.bundle.jks.absbundle.keystore.location"
  APP_PROPERTY_15="spring.ssl.bundle.jks.absbundle.keystore.location="
  APP_PROPERTY_25="spring.ssl.bundle.jks.absbundle.keystore.location=file:../Config/certificate.p12"
  APP_PROPERTY_06="spring.ssl.bundle.jks.absbundle.keystore.password"
  APP_PROPERTY_16="spring.ssl.bundle.jks.absbundle.keystore.password="
  APP_PROPERTY_26="spring.ssl.bundle.jks.absbundle.keystore.password=changeit"
  APP_PROPERTY_07="spring.ssl.bundle.jks.absbundle.key.alias"
  APP_PROPERTY_17="spring.ssl.bundle.jks.absbundle.key.alias="
  APP_PROPERTY_27="spring.ssl.bundle.jks.absbundle.key.alias=abssolute laundry business solutions"
  APP_PROPERTY_08="spring.ssl.bundle.jks.absbundle.reload-on-update"
  APP_PROPERTY_18="spring.ssl.bundle.jks.absbundle.reload-on-update="
  APP_PROPERTY_28="spring.ssl.bundle.jks.absbundle.reload-on-update=false"
  
  # Application Property file location
  APP_PROPERTIES_FILE="${ABSM_LOCAL_HOME}/Server/Config/application.properties"
  
  grep '^ *'$1"[[:blank:]]" ${ABSMENUCUSTOMCONFIG} | sort -k2,2 -k3,3 -k4,4 | while read CUST_ENVIRONMENT CUST_TYPE CUST_FILE CUST_PROPERTY CUST_VALUE
  do
    unset CUSTOMFILE
	if [ ${CUST_TYPE} == "app" -a ${CUST_FILE} == "application.properties" ]
    then
	  CUSTOMFILE=${APP_PROPERTIES_FILE}
      if [ ${ABS_ROOTSERVER} == ${ABSM_SERVERNAME} ]
      then
	    dos2unix -q ${CUSTOMFILE}
		case ${CUST_PROPERTY} in
		  ${APP_PROPERTY_02})
		    sed -i "/^${APP_PROPERTY_12}/ c\\${APP_PROPERTY_12}${CUST_VALUE}" ${CUSTOMFILE}
            ;;
		  ${APP_PROPERTY_03})
            sed -i "/^${APP_PROPERTY_13}/ c\\${APP_PROPERTY_13}${CUST_VALUE}" ${CUSTOMFILE}
            ;;
		  ${APP_PROPERTY_04})
		    sed -i "/^${APP_PROPERTY_14}/ c\\${APP_PROPERTY_14}${CUST_VALUE}" ${CUSTOMFILE}
            ;;
		  ${APP_PROPERTY_05})
		    sed -i "/^${APP_PROPERTY_15}/ c\\${APP_PROPERTY_15}${CUST_VALUE}" ${CUSTOMFILE}
            ;;
		  ${APP_PROPERTY_06})
		    sed -i "/^${APP_PROPERTY_16}/ c\\${APP_PROPERTY_16}${CUST_VALUE}" ${CUSTOMFILE}
            ;;
		  ${APP_PROPERTY_07})
		    sed -i "/^${APP_PROPERTY_17}/ c\\${APP_PROPERTY_17}${CUST_VALUE}" ${CUSTOMFILE}
            ;;
		  ${APP_PROPERTY_08})
		    sed -i "/^${APP_PROPERTY_18}/ c\\${APP_PROPERTY_18}${CUST_VALUE}" ${CUSTOMFILE}
            ;;
		  *) ;;
        esac		
      else
	    ssh -n -q $2 "dos2unix -q ${CUSTOMFILE}"
		case ${CUST_PROPERTY} in
		  ${APP_PROPERTY_02})
			ssh -n -q $2 "sed -i '/^${APP_PROPERTY_12}/ c\\${APP_PROPERTY_12}${CUST_VALUE}' ${CUSTOMFILE}"
            ;;
		  ${APP_PROPERTY_03})
		    ssh -n -q $2 "sed -i '/^${APP_PROPERTY_13}/ c\\${APP_PROPERTY_13}${CUST_VALUE}' ${CUSTOMFILE}"
            ;;
		  ${APP_PROPERTY_04})
		    ssh -n -q $2 "sed -i '/^${APP_PROPERTY_14}/ c\\${APP_PROPERTY_14}${CUST_VALUE}' ${CUSTOMFILE}"
            ;;
		  ${APP_PROPERTY_05})
		    ssh -n -q $2 "sed -i '/^${APP_PROPERTY_15}/ c\\${APP_PROPERTY_15}${CUST_VALUE}' ${CUSTOMFILE}"
            ;;
		  ${APP_PROPERTY_06})
		    ssh -n -q $2 "sed -i '/^${APP_PROPERTY_16}/ c\\${APP_PROPERTY_16}${CUST_VALUE}' ${CUSTOMFILE}"
            ;;
		  ${APP_PROPERTY_07})
		    ssh -n -q $2 "sed -i '/^${APP_PROPERTY_17}/ c\\${APP_PROPERTY_17}${CUST_VALUE}' ${CUSTOMFILE}"
            ;;
		  ${APP_PROPERTY_08})
		    ssh -n -q $2 "sed -i '/^${APP_PROPERTY_18}/ c\\${APP_PROPERTY_18}${CUST_VALUE}' ${CUSTOMFILE}"
            ;;
		  *) ;;
        esac
	  fi
    fi
  done
}

### Called as follows:
### HandleCustomProperties_rep $ABSM_ENVIRONMENT $ABSM_SERVERNAME $ABSM_SERVICE $ABSM_TYPE $ABSM_SLOT $ABSM_LOCAL_HOME $ABSM_REMOTE_HOME $ABSM_USER $ABSM_PWD $ABSM_ORATNS $ABSM_ORAHOME $ABSM_DBSERVERNAME $ABSM_DBDRIVERTYPE $ABSM_DBPORTNUMBER $ABSM_HEAPSPACE $ABSM_STATIONNR $ABSM_GFUSER $ABSM_GFPASWRD $ABSM_GFDOMAIN $ABSM_WEBCONTEXT $ABSM_WEBNAME $ABSM_WEBLIB $ABSM_CONNAPPSRV $ABSM_CONNAPPSLOT $ABSM_CONNREPSRV $ABSM_CONNREPSLOT $ABSM_USENATIVE $ABSM_EXCLUDECUSTREP $ABSM_WEB_VERSION $ABSM_CLIENTDISTR_SRV $ABSM_CLIENTDISTR_DIR $ABSM_USER2 $ABSM_PWD2 $ABSM_STATIONNR2 $ABSM_INET_KEY

HandleCustomProperties_rep_https()
{
  ABSM_ENVIRONMENT="${1}"
  ABSM_SERVERNAME="${2}"  
  ABSM_SERVICE="${3}"
  ABSM_TYPE="${4}"
  ABSM_SLOT="${5}"
  ABSM_LOCAL_HOME="${6}"
  ABSM_REMOTE_HOME="${7}"
  ABSM_USER="${8}"
  ABSM_PWD="${9}"
  ABSM_ORATNS="${10}"
  ABSM_ORAHOME="${11}"
  ABSM_DBSERVERNAME="${12}"
  ABSM_DBDRIVERTYPE="${13}"
  ABSM_DBPORTNUMBER="${14}"
  ABSM_HEAPSPACE="${15}"
  ABSM_STATIONNR="${16}"
  ABSM_GFUSER="${17}"
  ABSM_GFPASWRD="${18}"
  ABSM_GFDOMAIN="${19}"
  ABSM_WEBCONTEXT="${20}"
  ABSM_WEBNAME="${21}"
  ABSM_WEBLIB="${22}"
  ABSM_CONNAPPSRV="${23}"
  ABSM_CONNAPPSLOT="${24}"
  ABSM_CONNREPSRV="${25}"
  ABSM_CONNREPSLOT="${26}"
  ABSM_USENATIVE="${27}"
  ABSM_EXCLUDECUSTREP="${28}"
  ABSM_WEB_VERSION="${29}"
  ABSM_CLIENTDISTR_SRV="${30}"
  ABSM_CLIENTDISTR_DIR="${31}"
  ABSM_USER2="${32}"
  ABSM_PWD2="${33}"
  ABSM_STATIONNR2="${34}"
  ABSM_INET_KEY="${35}"

  # make sure the slot length is 2 characters. This is necessary to determine the correct portnumbers
  [ ${#ABSM_SLOT} == "1" ] && ABSM_SLOT="0"${ABSM_SLOT}
  
  # Report Server HTTPS Port
  V_NSREPORTSERVERHTTPSPORT="5"${ABSM_SLOT}"22"
  
  # HTTP/HTTPS Properties
  REP_PROPERTY_10="listener.port="
  REP_PROPERTY_20="# listener.port="
  REP_PROPERTY_30="listener.port"
  REP_PROPERTY_11="# listener.ssl.port="
  REP_PROPERTY_21="listener.ssl.port="
  REP_PROPERTY_31="listener.ssl.port"
  REP_PROPERTY_12="# listener.connectiontype=secure"
  REP_PROPERTY_22="listener.connectiontype="
  REP_PROPERTY_32="listener.connectiontype"
  REP_PROPERTY_13="# listener.ssl.certificate=Config/certificate.crt"
  REP_PROPERTY_23="listener.ssl.certificate="
  REP_PROPERTY_33="listener.ssl.certificate"
  REP_PROPERTY_14="# listener.ssl.privatekey=Config/certificate.key"
  REP_PROPERTY_24="listener.ssl.privatekey="
  REP_PROPERTY_34="listener.ssl.privatekey"

  # Crystal Clear property file location
  REP_PROPERTIES_FILE="${ABSM_LOCAL_HOME}/Reportserver/Config/crystalclear.properties"
  
  # Main
  grep '^ *'$1"[[:blank:]]" ${ABSMENUCUSTOMCONFIG} | sort -k2,2 -k3,3 -k4,4 | while read CUST_ENVIRONMENT CUST_TYPE CUST_FILE CUST_PROPERTY CUST_VALUE
  do
    unset CUSTOMFILE
	if [ ${CUST_TYPE} == "rep" -a ${CUST_FILE} == "crystalclear.properties" ]
    then
	  CUSTOMFILE=${REP_PROPERTIES_FILE}
      if [ ${ABS_ROOTSERVER} == ${ABSM_SERVERNAME} ]
      then
	    dos2unix -q ${CUSTOMFILE}
		case ${CUST_PROPERTY} in
		  ${REP_PROPERTY_32})
		    sed -i "/^${REP_PROPERTY_10}/ c\\${REP_PROPERTY_20}" ${CUSTOMFILE}
			sed -i "/^${REP_PROPERTY_11}/ c\\${REP_PROPERTY_21}${V_NSREPORTSERVERHTTPSPORT}" ${CUSTOMFILE}
			sed -i "/^${REP_PROPERTY_12}/ c\\${REP_PROPERTY_22}${CUST_VALUE}" ${CUSTOMFILE}
            ;;
		  ${REP_PROPERTY_33})
		    sed -i "s|${REP_PROPERTY_13}|${REP_PROPERTY_13:2}|" ${CUSTOMFILE}
            sed -i "/^${REP_PROPERTY_23}/ c\\${REP_PROPERTY_23}${CUST_VALUE}" ${CUSTOMFILE}
            ;;
		  ${REP_PROPERTY_34})
		    sed -i "s|${REP_PROPERTY_14}|${REP_PROPERTY_14:2}|" ${CUSTOMFILE}
            sed -i "/^${REP_PROPERTY_24}/ c\\${REP_PROPERTY_24}${CUST_VALUE}" ${CUSTOMFILE}
            ;;
		  *) ;;
        esac			
      else
	    ssh -n -q $2 "dos2unix -q ${CUSTOMFILE}"
		case ${CUST_PROPERTY} in
		  ${REP_PROPERTY_32})
		    ssh -n -q $2 "sed -i '/^${REP_PROPERTY_10}/ c\\${REP_PROPERTY_20}' ${CUSTOMFILE}"
			ssh -n -q $2 "sed -i '/^${REP_PROPERTY_11}/ c\\${REP_PROPERTY_21}${V_NSREPORTSERVERHTTPSPORT}' ${CUSTOMFILE}"
			ssh -n -q $2 "sed -i '/^${REP_PROPERTY_12}/ c\\${REP_PROPERTY_22}${CUST_VALUE}' ${CUSTOMFILE}"
            ;;
		  ${REP_PROPERTY_33})
		    ssh -n -q $2 "sed -i 's|${REP_PROPERTY_13}|${REP_PROPERTY_13:2}|' ${CUSTOMFILE}"
            ssh -n -q $2 "sed -i '/^${REP_PROPERTY_13}/ c\\${REP_PROPERTY_23}${CUST_VALUE}' ${CUSTOMFILE}"
            ;;
		  ${REP_PROPERTY_34})
		    ssh -n -q $2 "sed -i 's|${REP_PROPERTY_14}|${REP_PROPERTY_14:2}|' ${CUSTOMFILE}"
            ssh -n -q $2 "sed -i '/^${REP_PROPERTY_14}/ c\\${REP_PROPERTY_24}${CUST_VALUE}' ${CUSTOMFILE}"
            ;;
		  *) ;;
        esac
	  fi
    fi
  done
}

make_app_http()
{
  ABSM_ENVIRONMENT="${1}"
  ABSM_SERVERNAME="${2}"  
  ABSM_SERVICE="${3}"
  ABSM_TYPE="${4}"
  ABSM_SLOT="${5}"
  ABSM_LOCAL_HOME="${6}"
  ABSM_REMOTE_HOME="${7}"
  ABSM_USER="${8}"
  ABSM_PWD="${9}"
  ABSM_ORATNS="${10}"
  ABSM_ORAHOME="${11}"
  ABSM_DBSERVERNAME="${12}"
  ABSM_DBDRIVERTYPE="${13}"
  ABSM_DBPORTNUMBER="${14}"
  ABSM_HEAPSPACE="${15}"
  ABSM_STATIONNR="${16}"
  ABSM_GFUSER="${17}"
  ABSM_GFPASWRD="${18}"
  ABSM_GFDOMAIN="${19}"
  ABSM_WEBCONTEXT="${20}"
  ABSM_WEBNAME="${21}"
  ABSM_WEBLIB="${22}"
  ABSM_CONNAPPSRV="${23}"
  ABSM_CONNAPPSLOT="${24}"
  ABSM_CONNREPSRV="${25}"
  ABSM_CONNREPSLOT="${26}"
  ABSM_USENATIVE="${27}"
  ABSM_EXCLUDECUSTREP="${28}"
  ABSM_WEB_VERSION="${29}"
  ABSM_CLIENTDISTR_SRV="${30}"
  ABSM_CLIENTDISTR_DIR="${31}"
  ABSM_USER2="${32}"
  ABSM_PWD2="${33}"
  ABSM_STATIONNR2="${34}"
  ABSM_INET_KEY="${35}"

  # make sure the slot length is 2 characters. This is necessary to determine the correct portnumbers
  [ ${#ABSM_SLOT} == "1" ] && ABSM_SLOT="0"${ABSM_SLOT}
  
  # Application Server HTTPS Port
  V_NSAPPSERVERHTTPSPORT="5"${ABSM_SLOT}"17"
  
  # Application Properties reference - HTTP/HTTPS
  APP_PROPERTY_01="server.port"
  APP_PROPERTY_11="server.port="
  APP_PROPERTY_21="server.port="
  APP_PROPERTY_02="server.ssl.enabled"
  APP_PROPERTY_12="server.ssl.enabled="
  APP_PROPERTY_22="server.ssl.enabled=false"
  APP_PROPERTY_03="server.ssl.bundle"
  APP_PROPERTY_13="server.ssl.bundle="
  APP_PROPERTY_23="server.ssl.bundle=absbundle"
  APP_PROPERTY_04="spring.ssl.bundle.jks.absbundle.keystore.type"
  APP_PROPERTY_14="spring.ssl.bundle.jks.absbundle.keystore.type="
  APP_PROPERTY_24="spring.ssl.bundle.jks.absbundle.keystore.type=PKCS12"
  APP_PROPERTY_05="spring.ssl.bundle.jks.absbundle.keystore.location"
  APP_PROPERTY_15="spring.ssl.bundle.jks.absbundle.keystore.location="
  APP_PROPERTY_25="spring.ssl.bundle.jks.absbundle.keystore.location=file:../Config/certificate.p12"
  APP_PROPERTY_06="spring.ssl.bundle.jks.absbundle.keystore.password"
  APP_PROPERTY_16="spring.ssl.bundle.jks.absbundle.keystore.password="
  APP_PROPERTY_26="spring.ssl.bundle.jks.absbundle.keystore.password=changeit"
  APP_PROPERTY_07="spring.ssl.bundle.jks.absbundle.key.alias"
  APP_PROPERTY_17="spring.ssl.bundle.jks.absbundle.key.alias="
  APP_PROPERTY_27="spring.ssl.bundle.jks.absbundle.key.alias=abssolute laundry business solutions"
  APP_PROPERTY_08="spring.ssl.bundle.jks.absbundle.reload-on-update"
  APP_PROPERTY_18="spring.ssl.bundle.jks.absbundle.reload-on-update="
  APP_PROPERTY_28="spring.ssl.bundle.jks.absbundle.reload-on-update=false"
  
  # Application Property file location
  APP_PROPERTIES_FILE="${ABSM_LOCAL_HOME}/Server/Config/application.properties"
  
   grep '^ *'$1"[[:blank:]]" ${ABSMENUCUSTOMCONFIG} | sort -k2,2 -k3,3 -k4,4 | while read CUST_ENVIRONMENT CUST_TYPE CUST_FILE CUST_PROPERTY CUST_VALUE
   do
    unset CUSTOMFILE
	if [ ${CUST_TYPE} == "app" -a ${CUST_FILE} == "application.properties" ]
    then
	  CUSTOMFILE=${APP_PROPERTIES_FILE}
      if [ ${ABS_ROOTSERVER} == ${ABSM_SERVERNAME} ]
      then
	    dos2unix -q ${CUSTOMFILE}
		case ${CUST_PROPERTY} in
		  ${APP_PROPERTY_02})
		    sed -i "/^${APP_PROPERTY_12}/ c\\${APP_PROPERTY_12}${CUST_VALUE}" ${CUSTOMFILE}
            ;;
		  ${APP_PROPERTY_03})
            sed -i "/^${APP_PROPERTY_13}/ c\\${APP_PROPERTY_13}${CUST_VALUE}" ${CUSTOMFILE}
            ;;
		  ${APP_PROPERTY_04})
		    sed -i "/^${APP_PROPERTY_14}/ c\\${APP_PROPERTY_14}${CUST_VALUE}" ${CUSTOMFILE}
            ;;
		  ${APP_PROPERTY_05})
		    sed -i "/^${APP_PROPERTY_15}/ c\\${APP_PROPERTY_15}${CUST_VALUE}" ${CUSTOMFILE}
            ;;
		  ${APP_PROPERTY_06})
		    sed -i "/^${APP_PROPERTY_16}/ c\\${APP_PROPERTY_16}${CUST_VALUE}" ${CUSTOMFILE}
            ;;
		  ${APP_PROPERTY_07})
		    sed -i "/^${APP_PROPERTY_17}/ c\\${APP_PROPERTY_17}${CUST_VALUE}" ${CUSTOMFILE}
            ;;
		  ${APP_PROPERTY_08})
		    sed -i "/^${APP_PROPERTY_18}/ c\\${APP_PROPERTY_18}${CUST_VALUE}" ${CUSTOMFILE}
            ;;
		  *) ;;
        esac			
      else
	    ssh -n -q $2 "dos2unix -q ${CUSTOMFILE}"
		case ${CUST_PROPERTY} in
		  ${APP_PROPERTY_02})
			ssh -n -q $2 "sed -i '/^${APP_PROPERTY_12}/ c\\${APP_PROPERTY_12}${CUST_VALUE}' ${CUSTOMFILE}"
            ;;
		  ${APP_PROPERTY_03})
		    ssh -n -q $2 "sed -i '/^${APP_PROPERTY_13}/ c\\${APP_PROPERTY_13}${CUST_VALUE}' ${CUSTOMFILE}"
            ;;
		  ${APP_PROPERTY_04})
		    ssh -n -q $2 "sed -i '/^${APP_PROPERTY_14}/ c\\${APP_PROPERTY_14}${CUST_VALUE}' ${CUSTOMFILE}"
            ;;
		  ${APP_PROPERTY_05})
		    ssh -n -q $2 "sed -i '/^${APP_PROPERTY_15}/ c\\${APP_PROPERTY_15}${CUST_VALUE}' ${CUSTOMFILE}"
            ;;
		  ${APP_PROPERTY_06})
		    ssh -n -q $2 "sed -i '/^${APP_PROPERTY_16}/ c\\${APP_PROPERTY_16}${CUST_VALUE}' ${CUSTOMFILE}"
            ;;
		  ${APP_PROPERTY_07})
		    ssh -n -q $2 "sed -i '/^${APP_PROPERTY_17}/ c\\${APP_PROPERTY_17}${CUST_VALUE}' ${CUSTOMFILE}"
            ;;
		  ${APP_PROPERTY_08})
		    ssh -n -q $2 "sed -i '/^${APP_PROPERTY_18}/ c\\${APP_PROPERTY_18}${CUST_VALUE}' ${CUSTOMFILE}"
            ;;
		  *) ;;
        esac
	  fi
    fi
  done
}

make_rep_http()
{
  ABSM_ENVIRONMENT="${1}"
  ABSM_SERVERNAME="${2}"  
  ABSM_SERVICE="${3}"
  ABSM_TYPE="${4}"
  ABSM_SLOT="${5}"
  ABSM_LOCAL_HOME="${6}"
  ABSM_REMOTE_HOME="${7}"
  ABSM_USER="${8}"
  ABSM_PWD="${9}"
  ABSM_ORATNS="${10}"
  ABSM_ORAHOME="${11}"
  ABSM_DBSERVERNAME="${12}"
  ABSM_DBDRIVERTYPE="${13}"
  ABSM_DBPORTNUMBER="${14}"
  ABSM_HEAPSPACE="${15}"
  ABSM_STATIONNR="${16}"
  ABSM_GFUSER="${17}"
  ABSM_GFPASWRD="${18}"
  ABSM_GFDOMAIN="${19}"
  ABSM_WEBCONTEXT="${20}"
  ABSM_WEBNAME="${21}"
  ABSM_WEBLIB="${22}"
  ABSM_CONNAPPSRV="${23}"
  ABSM_CONNAPPSLOT="${24}"
  ABSM_CONNREPSRV="${25}"
  ABSM_CONNREPSLOT="${26}"
  ABSM_USENATIVE="${27}"
  ABSM_EXCLUDECUSTREP="${28}"
  ABSM_WEB_VERSION="${29}"
  ABSM_CLIENTDISTR_SRV="${30}"
  ABSM_CLIENTDISTR_DIR="${31}"
  ABSM_USER2="${32}"
  ABSM_PWD2="${33}"
  ABSM_STATIONNR2="${34}"
  ABSM_INET_KEY="${35}"

  # make sure the slot length is 2 characters. This is necessary to determine the correct portnumbers
  [ ${#ABSM_SLOT} == "1" ] && ABSM_SLOT="0"$ABSM_SLOT
  [ ${#ABSM_CONNAPPSLOT} == "1" ] && ABSM_CONNAPPSLOT="0"$ABSM_CONNAPPSLOT
  [ ${#ABSM_CONNREPSLOT} == "1" ] && ABSM_CONNREPSLOT="0"$ABSM_CONNREPSLOT

  # Crystal Clear property file location
  REP_PROPERTIES_FILE="${ABSM_LOCAL_HOME}/Reportserver/Config/crystalclear.properties"
  
  # Report Server HTTP Port
  V_NSREPORTSERVERHTTPPORT="5"${ABSM_SLOT}"22"

  # HTTP/HTTPS Properties
  REP_PROPERTY_10="listener.port="
  REP_PROPERTY_20="# listener.port="
  REP_PROPERTY_30="listener.port"
  REP_PROPERTY_11="# listener.ssl.port="
  REP_PROPERTY_21="listener.ssl.port="
  REP_PROPERTY_31="listener.ssl.port"
  REP_PROPERTY_12="# listener.connectiontype=secure"
  REP_PROPERTY_22="listener.connectiontype="
  REP_PROPERTY_32="listener.connectiontype"
  REP_PROPERTY_13="# listener.ssl.certificate=Config/certificate.crt"
  REP_PROPERTY_23="listener.ssl.certificate="
  REP_PROPERTY_33="listener.ssl.certificate"
  REP_PROPERTY_14="# listener.ssl.privatekey=Config/certificate.key"
  REP_PROPERTY_24="listener.ssl.privatekey="
  REP_PROPERTY_34="listener.ssl.privatekey"

  # Main
  grep '^ *'$1"[[:blank:]]" ${ABSMENUCUSTOMCONFIG} | sort -k2,2 -k3,3 -k4,4 | while read CUST_ENVIRONMENT CUST_TYPE CUST_FILE CUST_PROPERTY CUST_VALUE
  do
    unset CUSTOMFILE
	if [ ${CUST_TYPE} == "rep" -a ${CUST_FILE} == "crystalclear.properties" ]
    then
	  CUSTOMFILE=${REP_PROPERTIES_FILE}
      if [ ${ABS_ROOTSERVER} == ${ABSM_SERVERNAME} ]
      then
	    dos2unix -q ${CUSTOMFILE}
		case ${CUST_PROPERTY} in
		  ${REP_PROPERTY_32})
		    sed -i "s|${REP_PROPERTY_20}|${REP_PROPERTY_20:2}|" ${CUSTOMFILE}
		    sed -i "/^${REP_PROPERTY_10}/ c\\${REP_PROPERTY_10}${V_NSREPORTSERVERHTTPPORT}" ${CUSTOMFILE}
			sed -i "/^${REP_PROPERTY_21}/ c\\${REP_PROPERTY_11}" ${CUSTOMFILE}
			sed -i "/^${REP_PROPERTY_22}/ c\\${REP_PROPERTY_12}" ${CUSTOMFILE}
            ;;
		  ${REP_PROPERTY_33})
		    sed -i "/^${REP_PROPERTY_23}/ c\\${REP_PROPERTY_13}" ${CUSTOMFILE}            
            ;;
		  ${REP_PROPERTY_34})
            sed -i "/^${REP_PROPERTY_24}/ c\\${REP_PROPERTY_14}" ${CUSTOMFILE}
            ;;
		  *) ;;
        esac			
      else
	    ssh -n -q $2 "dos2unix -q ${CUSTOMFILE}"
		case ${CUST_PROPERTY} in
		  ${REP_PROPERTY_32})
		    ssh -n -q $2 "sed -i 's|${REP_PROPERTY_20}|${REP_PROPERTY_20:2}|' ${CUSTOMFILE}"
			ssh -n -q $2 "sed -i '/^${REP_PROPERTY_10}/ c\\${REP_PROPERTY_10}${V_NSREPORTSERVERHTTPPORT}' ${CUSTOMFILE}"
			ssh -n -q $2 "sed -i '/^${REP_PROPERTY_21}/ c\\${REP_PROPERTY_11}' ${CUSTOMFILE}"
            ssh -n -q $2 "sed -i '/^${REP_PROPERTY_22}/ c\\${REP_PROPERTY_12}' ${CUSTOMFILE}"
            ;;
		  ${REP_PROPERTY_33})
            ssh -n -q $2 "sed -i '/^${REP_PROPERTY_23}/ c\\${REP_PROPERTY_13}' ${CUSTOMFILE}"
            ;;
		  ${REP_PROPERTY_34})
            ssh -n -q $2 "sed -i '/^${REP_PROPERTY_24}/ c\\${REP_PROPERTY_14}' ${CUSTOMFILE}"
            ;;
		  *) ;;
        esac
	  fi
    fi
  done
}

toggle_repserver_sslconnection()
{
  # $1 - ABSM_USER 
  # $2 - ABSM_PWD 
  # $3 - ABSM_ORATNS
  # $4 - ABSM_ORAHOME
  # $5 - ABSM_DBSERVERNAME
  # $6 - ABSM_DBDRIVERTYPE
  # $7 - ABSM_DBPORTNUMBER
  # $8 - TARGET
  
  V_ABSM_USER=$1
  V_ABSM_PWD=$2
  V_ABSM_ORATNS=$3
  V_ABSM_ORAHOME=$4
  V_ABSM_DBSERVERNAME=$5
  V_ABSM_DBDRIVERTYPE=$6
  V_ABSM_DBPORTNUMBER=$7
  V_TARGET=$8

$V_ABSM_ORAHOME/bin/sqlplus -S "$V_ABSM_USER/$V_ABSM_PWD@//$V_ABSM_DBSERVERNAME:$V_ABSM_DBPORTNUMBER/$V_ABSM_ORATNS" <<EOF 2>&1> /dev/null
set termout off;
update databasesettings set REPSERVERSSLCONNECTION='$V_TARGET';
commit;
EOF

}

# Main
# $1 = environment
if [ ${ABSSOLUTENUMVERSION} -ge 90902 ]
then
  grep '^ *'$1"[[:blank:]]" ${ABSMENUGLOBALCONFIG} | sort -k2,2 -k5,5 -k4,4 | while read ABSM_ENVIRONMENT ABSM_SERVERNAME ABSM_SERVICE ABSM_TYPE ABSM_SLOT ABSM_LOCAL_HOME ABSM_REMOTE_HOME ABSM_USER ABSM_PWD ABSM_ORATNS ABSM_ORAHOME ABSM_DBSERVERNAME ABSM_DBDRIVERTYPE ABSM_DBPORTNUMBER ABSM_HEAPSPACE ABSM_STATIONNR ABSM_GFUSER ABSM_GFPASWRD ABSM_GFDOMAIN ABSM_WEBCONTEXT ABSM_WEBNAME ABSM_WEBLIB ABSM_CONNAPPSRV ABSM_CONNAPPSLOT ABSM_CONNREPSRV ABSM_CONNREPSLOT ABSM_USENATIVE ABSM_EXCLUDECUSTREP ABSM_WEB_VERSION ABSM_CLIENTDISTR_SRV ABSM_CLIENTDISTR_DIR ABSM_USER2 ABSM_PWD2 ABSM_STATIONNR2 ABSM_INET_KEY
  do
    if [ ${ABSM_SERVICE} == "https" ]
    then
      case ${ABSM_TYPE} in
        app)  HandleCustomProperties_app_https $ABSM_ENVIRONMENT $ABSM_SERVERNAME $ABSM_SERVICE $ABSM_TYPE $ABSM_SLOT $ABSM_LOCAL_HOME $ABSM_REMOTE_HOME $ABSM_USER $ABSM_PWD $ABSM_ORATNS $ABSM_ORAHOME $ABSM_DBSERVERNAME $ABSM_DBDRIVERTYPE $ABSM_DBPORTNUMBER $ABSM_HEAPSPACE $ABSM_STATIONNR $ABSM_GFUSER $ABSM_GFPASWRD $ABSM_GFDOMAIN $ABSM_WEBCONTEXT $ABSM_WEBNAME $ABSM_WEBLIB $ABSM_CONNAPPSRV $ABSM_CONNAPPSLOT $ABSM_CONNREPSRV $ABSM_CONNREPSLOT $ABSM_USENATIVE $ABSM_EXCLUDECUSTREP $ABSM_WEB_VERSION $ABSM_CLIENTDISTR_SRV $ABSM_CLIENTDISTR_DIR $ABSM_USER2 $ABSM_PWD2 $ABSM_STATIONNR2 $ABSM_INET_KEY
		      echo "Application Server ${ABSM_SERVERNAME} Slot ${ABSM_SLOT} has been updated."
			  ;;
        rep)  HandleCustomProperties_rep_https $ABSM_ENVIRONMENT $ABSM_SERVERNAME $ABSM_SERVICE $ABSM_TYPE $ABSM_SLOT $ABSM_LOCAL_HOME $ABSM_REMOTE_HOME $ABSM_USER $ABSM_PWD $ABSM_ORATNS $ABSM_ORAHOME $ABSM_DBSERVERNAME $ABSM_DBDRIVERTYPE $ABSM_DBPORTNUMBER $ABSM_HEAPSPACE $ABSM_STATIONNR $ABSM_GFUSER $ABSM_GFPASWRD $ABSM_GFDOMAIN $ABSM_WEBCONTEXT $ABSM_WEBNAME $ABSM_WEBLIB $ABSM_CONNAPPSRV $ABSM_CONNAPPSLOT $ABSM_CONNREPSRV $ABSM_CONNREPSLOT $ABSM_USENATIVE $ABSM_EXCLUDECUSTREP $ABSM_WEB_VERSION $ABSM_CLIENTDISTR_SRV $ABSM_CLIENTDISTR_DIR $ABSM_USER2 $ABSM_PWD2 $ABSM_STATIONNR2 $ABSM_INET_KEY
	          toggle_repserver_sslconnection $ABSM_USER $ABSM_PWD $ABSM_ORATNS $ABSM_ORAHOME $ABSM_DBSERVERNAME $ABSM_DBDRIVERTYPE $ABSM_DBPORTNUMBER Y
			  echo "Report Server ${ABSM_SERVERNAME} Slot ${ABSM_SLOT} has been updated."
			  ;;
		*)    export ABSMESSAGE="     Invalid Servive Type make_http_https.sh"; absmenu_log
		      ;;
      esac
    elif [ ${ABSM_SERVICE} == "http" ]
    then
      case ${ABSM_TYPE} in
        app)  make_app_http $ABSM_ENVIRONMENT $ABSM_SERVERNAME $ABSM_SERVICE $ABSM_TYPE $ABSM_SLOT $ABSM_LOCAL_HOME $ABSM_REMOTE_HOME $ABSM_USER $ABSM_PWD $ABSM_ORATNS $ABSM_ORAHOME $ABSM_DBSERVERNAME $ABSM_DBDRIVERTYPE $ABSM_DBPORTNUMBER $ABSM_HEAPSPACE $ABSM_STATIONNR $ABSM_GFUSER $ABSM_GFPASWRD $ABSM_GFDOMAIN $ABSM_WEBCONTEXT $ABSM_WEBNAME $ABSM_WEBLIB $ABSM_CONNAPPSRV $ABSM_CONNAPPSLOT $ABSM_CONNREPSRV $ABSM_CONNREPSLOT $ABSM_USENATIVE $ABSM_EXCLUDECUSTREP $ABSM_WEB_VERSION $ABSM_CLIENTDISTR_SRV $ABSM_CLIENTDISTR_DIR $ABSM_USER2 $ABSM_PWD2 $ABSM_STATIONNR2 $ABSM_INET_KEY
		      echo "Application Server ${ABSM_SERVERNAME} Slot ${ABSM_SLOT} has been updated."
			  ;;
        rep)  make_rep_http $ABSM_ENVIRONMENT $ABSM_SERVERNAME $ABSM_SERVICE $ABSM_TYPE $ABSM_SLOT $ABSM_LOCAL_HOME $ABSM_REMOTE_HOME $ABSM_USER $ABSM_PWD $ABSM_ORATNS $ABSM_ORAHOME $ABSM_DBSERVERNAME $ABSM_DBDRIVERTYPE $ABSM_DBPORTNUMBER $ABSM_HEAPSPACE $ABSM_STATIONNR $ABSM_GFUSER $ABSM_GFPASWRD $ABSM_GFDOMAIN $ABSM_WEBCONTEXT $ABSM_WEBNAME $ABSM_WEBLIB $ABSM_CONNAPPSRV $ABSM_CONNAPPSLOT $ABSM_CONNREPSRV $ABSM_CONNREPSLOT $ABSM_USENATIVE $ABSM_EXCLUDECUSTREP $ABSM_WEB_VERSION $ABSM_CLIENTDISTR_SRV $ABSM_CLIENTDISTR_DIR $ABSM_USER2 $ABSM_PWD2 $ABSM_STATIONNR2 $ABSM_INET_KEY
	          toggle_repserver_sslconnection $ABSM_USER $ABSM_PWD $ABSM_ORATNS $ABSM_ORAHOME $ABSM_DBSERVERNAME $ABSM_DBDRIVERTYPE $ABSM_DBPORTNUMBER N
			  echo "Report Server ${ABSM_SERVERNAME} Slot ${ABSM_SLOT} has been updated."
			  ;;
		*)    export ABSMESSAGE="     Invalid Servive Type make_http_https.sh"; absmenu_log
		      ;;
      esac
    else
      export ABSMESSAGE="     Invalid option make_http_https.sh"; absmenu_log
    fi
  done
  echo "Please restart server services for change to be effective."
else
  echo "HTTPS is relevant for ABSSolute version as from 9.09.02."
  export ABSMESSAGE="     HTTPS is relevant for ABSSolute version as from 9.09.02."; absmenu_log
fi