#!/bin/sh
#  $Id: UpgradeFrom_510000.sh 144933 2017-02-08 09:50:25Z justin.carveley@oracle.com $
#  Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
#  This software code contains proprietary information 
#  and should be treated as confidential.
#
#  Component: Installation/upgrade
#  Author: Jack Tams

FROM_VERSION=510000 TO_VERSION=520000

. ./util

# handy shortcut vars
TTA="${instdir}/bin/tarantella"
VIN="${instdir}/var/info"
VLG="${instdir}/var/log"
TSR="${instdir}/etc/templates/serverresources"
VSR="${instdir}/var/serverresources"
TSC="${TSR}/serverconfig"
VSC="${instdir}/var/serverconfig"
TSB="${TSC}/global/beans"
VSB="${VSC}/global/beans"
TC="tarantella.config"
T_C="--tarantella-config"

## Remove Obsolete Beans ##
for f in \
    securidmodel.properties \
    securidla.properties \
    enstosecurid.properties \
    com.sco.tta.server.securid.SecurIDUserModel.properties \
    com.sco.tta.server.securid.SecurIDService.properties \
    com.sco.tta.server.securid.SecurIDLoginAuthority.properties \
    com.sco.tta.server.login.CachePasswordLoginHandler.properties ; do
    rm -f ${TSB}/${f} ${VSB}/${f} 2>/dev/null
done


# New Local Property #
add_property "local/server.properties" "${TC}.server.securidpropdir" "%%INSTALLDIR%%/var/rsa"

## New Global Property ##
update_new_gprop "login-securid-timeout" "60000"
update_new_gprop "login-securid-searchens" "0"
update_new_gprop "login-securid-searchds" "0"
update_new_gprop "login-securid-allowprofile" "1"
update_new_gprop "ldap-securid-enabled" "0"
update_new_gprop "ad-securid-enabled" "0"

## Updated Global Properties ##
update_gprop "security-ciphers" "AES256-SHA"
update_gprop "xpeconfig-fontpath" "%%INSTALLDIR%%/X11/share/fonts/X11/misc,%%INSTALLDIR%%/X11/share/fonts/X11/TTF,%%INSTALLDIR%%/X11/share/fonts/X11/Type1,%%INSTALLDIR%%/X11/share/fonts/X11/OTF,%%INSTALLDIR%%/X11/share/fonts/X11/100dpi,%%INSTALLDIR%%/X11/share/fonts/X11/75dpi,%%INSTALLDIR%%/X11/share/fonts/X11/cyrillic,%%INSTALLDIR%%/X11/share/fonts/X11/ibm"
update_gprop "security-peerssl-ciphers" "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,TLS_RSA_WITH_AES_128_CBC_SHA"

## Update READ-ONLY Properties ##
change_property "local/xpe.properties" "${TC}.xpeconfig.xkb.basedir" "%%INSTALLDIR%%/X11/share/X11/xkb"
change_property "local/xpe.properties" "${TC}.xpeconfig.xkb.binarydir" "%%INSTALLDIR%%/X11/bin"
change_property "local/xpe.properties" "${TC}.xpeconfig.keyboard.macnumlock" "0"

## Passcache ##
## New Properties ##
update_new_gprop "passcache-default-scope" "0"
update_new_gprop "passcache-salt-length" "32"
update_new_gprop "passcache-upgrade-timeout" "500"
update_new_gprop "passcache-audit-on-disconnect" "0"

## scriptvars ,TTA_PASSCACHESCOPE=scottapasscachescope##
append_property "local/scottaapplication.properties" "tarantella.config.scottaapplication.scottascriptvars" "TTA_PasscacheScope=scottapasscachescope"
append_property "local/scottaxapplication.properties" "tarantella.config.scottaapplication.scottashellvars" "TTA_UNIXAUDIO_QUALITY=scottaunixaudioquality,TTA_UNIXAUDIOIN_ENABLED=oraclesgdunixaudioinenabled"
append_property "local/scottaxapplication.properties" "tarantella.config.scottaapplication.scottascriptvars" "TTA_AUTOPROVISION=ssoautoprovision"

## Unix Audio In ## 
add_property "global/audio.properties" "${TC}.unixaudioin.enabled" "0"

## Role-Based Admin ##
add_property "global/array.properties" "${TC}.array.allowsharedloginadmins" "0"

## Peer SOAP timeout ##
add_property "global/array.properties" "${TC}.array.peer.soap.timeout" "60000"

## Enable Audit Logging if it is not already on ##
current_log_filter=`get_value "--tarantella-config-server-logfilter"`
echo "Current log filter: ${current_log_filter}"

audit_filter="*\/*\/*auditinfo"
audit_logfile="audit%%PID%%.log"
audit_jslfile="audit%%PID%%.jsl"
set_audit_filter="t"

case "$current_log_filter" in
*\*/\*/\*auditinfo:*) 
   echo "The audit filter \"${audit_filter}\" is already enabled."
   set_audit_filter=""
   ;;
*${audit_logfile}*|*${audit_jslfile}*) 
   echo "Suggested audit files are in use: ${audit_logfile} ${audit_jslfile}"
   sfx=0
   set_audit_filter=""
   while [ $sfx -lt 100 ]
     do
      sfx=`expr $sfx + 1`

      audit_logfile="audit${sfx}_%%PID%%.log"
      audit_jslfile="audit${sfx}_%%PID%%.jsl"
      case "$current_log_filter" in
        *${audit_logfile}*|*${audit_jslfile}*)
           echo "Suggested audit files are in use: ${audit_logfile} ${audit_jslfile}"
           ;;
         *)
           set_audit_filter="t"
           break
           ;;
      esac
   done
   ;;
esac

if [ -n "$set_audit_filter" ]; then
   echo "Using audit files: ${audit_logfile} ${audit_jslfile}"
   append_property "global/array.properties" "tarantella.config.server.logfilter" ${audit_filter}:${audit_logfile}
   append_property "global/array.properties" "tarantella.config.server.logfilter" ${audit_filter}:${audit_jslfile}
fi
  
## SecurID Reconfiguration Message ##
[ -n "`${TTA} config list \"--login-securid\" | grep '1'`" ] && {
    #touch the file - picked up by post install banner to show appropriate message
    touch "${VLG}/upgrade-reconfigure-securid"
    #Disable
    ${TTA} config edit "--login-securid" "0"
}

exit 0
