#!/bin/sh

BIN_GET_KEY_VALUE="/bin/get_key_value"
CONFIG_PATH="/etc/ssh/sshd_config"

CIPHERS=`cat $CONFIG_PATH | grep Ciphers | grep -v "\#" | sed 's/Ciphers /"/g' | sed 's/,/", "/g' | sed 's/\n*.$/"/g'`
if [ "$CIPHERS" == "" ]; then
    CIPHERS="\"aes128-ctr\", \"aes128-gcm@openssh.com\", \"aes192-ctr\", \"aes256-ctr\", \"aes256-gcm@openssh.com\", \"chacha20-poly1305@openssh.com\""
fi 
KEX_AKGORITHMS=`cat $CONFIG_PATH | grep KexAlgorithms | sed 's/KexAlgorithms /"/g' | sed 's/,/", "/g' | sed 's/\n*.$/"/g'`
if [ "$KEX_AKGORITHMS" == "" ]; then
    KEX_AKGORITHMS="\"curve25519-sha256@libssh.org\", \"diffie-hellman-group-exchange-sha256\", \"diffie-hellman-group14-sha1\", \"ecdh-sha2-nistp256\", \"ecdh-sha2-nistp384\", \"ecdh-sha2-nistp521\""
fi
MACS=`cat $CONFIG_PATH | grep MACs | sed 's/MACs /"/g' | sed 's/,/", "/g' | sed 's/\n*.$/"/g'`
if [ "$MACS" == "" ]; then
    MACS="\"hmac-sha1\", \"hmac-sha1-etm@openssh.com\", \"hmac-sha2-256\", \"hmac-sha2-256-etm@openssh.com\", \"hmac-sha2-512\", \"hmac-sha2-512-etm@openssh.com\", \"umac-128-etm@openssh.com\", \"umac-128@openssh.com\", \"umac-64-etm@openssh.com\", \"umac-64@openssh.co\""
fi
ENCRYPT_MODE="$CIPHERS, $KEX_AKGORITHMS, $MACS"

/usr/syno/sbin/synoservice --is-enabled ssh-shell 2>&1 > /dev/null
if [ $? = 1 ]; then
    SSH_ENABLE="yes"
else
    SSH_ENABLE="no"
fi

/usr/syno/sbin/synoservice --is-enabled telnetd 2>&1 > /dev/null
if [ $? = 1 ]; then
    TELNET_ENABLE="yes"
else
    TELNET_ENABLE="no"
fi

echo -n "{"

echo -n \"telnet_enable\":\"$TELNET_ENABLE\",
echo -n \"ssh_enable\":\"$SSH_ENABLE\",
echo -n \"ssh_encrypt_mode\":[$ENCRYPT_MODE],

# let version be the last one msg
echo -n \"collector_version\":1

echo "}"



