#!/bin/bash function clearParams { mclient set $REGKEY/address "" mclient set $REGKEY/username "" mclient set $REGKEY/password "" mclient set $REGKEY/domain "" mclient set $REGKEY/authorizations/user/execution 0 mclient commit } function getRegKey { # Get Template_UDS for key in `mclient get root/ConnectionType/freerdp/connections | sed "s/dir //g"`; do val=`mclient get $key/label | sed "s/value //g"` if [ "$val" == "Template_UDS" ]; then REGKEY=$key fi done } function createUDSConnectionTemplate { TMPFILE=$(mktemp /tmp/udsexport.XXXXXX) cat > $TMPFILE << EOF UDS Template Profile root/ConnectionType/freerdp/connections/{ff064bd9-047a-45ec-b70f-04ab218186ff} t420 T7X62022 6.2.0 standard 0 bool 0 bool 0 number 3 number 2 number 3 number 3 number 0 string 0 string string string NLCR.1 rc4 string Template_UDS string password string 0 bool 443 number 1 bool password string Remote Computer string Remote Application string 0 bool full string 70 number 1024 number 768 number 1 bool 1 bool 1 bool 1 bool 0 bool 1 bool 1 bool 1 bool 0 number auto string 1 number 1 number 1 number 1 number 1 number 1 number 2 number 0 number 1 number 1 number 0 number 0 number 0 number 1 bool 6000 number 0 bool 30000 number 0 number 0 bool 0 bool 0 bool 0 bool 0 bool 0 bool 1 bool 0 number 1 bool 0 bool 0 bool EOF mclient import $TMPFILE rm $TMPFILE } ADDRESS= USERNAME= PASSWORD= DOMAIN= REGKEY= CLEAR=0 # Try to locate registry key for UDS Template getRegKey if [ "$REGKEY" == "" ]; then # Not found, create on based on our template createUDSConnectionTemplate getRegKey fi for param in $@; do if [ "/u:" == "${param:0:3}" ]; then USERNAME=${param:3} CLEAR=1 fi if [ "/p:" == "${param:0:3}" ]; then PASSWORD=${param:3} CLEAR=1 fi if [ "/d:" == "${param:0:3}" ]; then DOMAIN=${param:3} CLEAR=1 fi if [ "/v:" == "${param:0:3}" ]; then ADDRESS=${param:3} CLEAR=1 fi done if [ "$CLEAR" -eq 1 ]; then clearParams fi ID=`basename $REGKEY` RESPAWN=0 if [ "" != "$ADDRESS" ]; then mclient set $REGKEY/address "${ADDRESS}" RESPAWN=1 fi if [ "" != "$USERNAME" ]; then mclient set $REGKEY/username "${USERNAME}" RESPAWN=1 fi if [ "" != "$PASSWORD" ]; then mclient set $REGKEY/password "${PASSWORD}" RESPAWN=1 fi if [ "" != "$DOMAIN" ]; then mclient set $REGKEY/domain "${DOMAIN}" RESPAWN=1 fi if [ "$RESPAWN" -eq 1 ]; then mclient set $REGKEY/authorizations/user/execution 1 mclient commit exec $0 # Restart without command line fi process-connection $ID clearParams