#!/bin/bash
#该脚本适用于CentOS与Ubuntu,其他系统可类似编写(该命令实现了USB、打印机以及语音的重定向,同时实现了本地机与远程机的互拷贝)
output=$(zenity --forms --title "" --text="信息" --separator="," --ok-label="确定" --cancel-label="取消" --add-entry="IP地址" --add-entry="端口号" --add-entry="域名" --add-entry="用户名" --add-password="密码")
if [ $? != 0 ];then
exit 1
fi
path=$(cd `dirname $0`; pwd)
user=$(whoami)
ip=$(awk -F, '{print $1}' <<<$output)
domain=$(awk -F, '{print $3}' <<<$output)
port=$(awk -F, '{print $2}' <<<$output)
username=$(awk -F, '{print $4}' <<<$output)
password=$(awk -F, '{print $5}' <<<$output)
type1=$(cat /etc/redhat-release|awk '{print $1}')
type2=$(lsb_release -a|grep Distributor|awk '{print $3}')
#检测ip格式是否正确
checkIp(){
if [[ $ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
FIELD1=$(echo $ip|cut -d. -f1)
FIELD2=$(echo $ip|cut -d. -f2)
FIELD3=$(echo $ip|cut -d. -f3)
FIELD4=$(echo $ip|cut -d. -f4)
if [ $FIELD1 -le 255 -a $FIELD2 -le 255 -a $FIELD3 -le 255 -a $FIELD4 -le 255 ]; then
echo "IP $ip available."
else
zenity --error --title "错误" --text="IP格式不正确" --width="200" --height="40" --ok-label="确定"
bash $path/client.sh
exit 0
fi
else
zenity --error --title "错误" --text="IP格式不正确" --width="200" --height="40" --ok-label="确定"
bash $path/client.sh
exit 0
fi
}
#port格式
checkData(){
[[ "$port" =~ ^[0-9]+$ ]] || zenity --error --title "错误" --text="端口格式不正确" --width="200" --height="40" --ok-label="确定"
[[ "$port" =~ ^[0-9]+$ ]] || bash $path/client.sh
[[ "$port" =~ ^[0-9]+$ ]] || exit 0
#用户名 密码
if [ -z $username ];then
zenity --error --title "错误" --text="用户名不能为空" --width="200" --height="40" --ok-label="确定"
bash $path/client.sh
exit 0
elif [ -z $password ];then
zenity --error --title "错误" --text="密码不能为空" --width="200" --height="40" --ok-label="确定"
bash $path/client.sh
exit 0
fi
}
theCentOS(){ //centos系统执行的内容
if [ -z $domain ];then
xfreerdp --no-nla -u $username -p $password --plugin rdpsnd --plugin cliprdr --plugin rdpdr --data printer --plugin rdpdr --data disk:${user}:/run/media/${user} -- ${ip}:${port}
exit 0
else
xfreerdp --no-nla -u $username -p $password -d $domain --plugin rdpsnd --plugin cliprdr --plugin rdpdr --data printer --plugin rdpdr --data disk:${user}:/run/media/${user} -- ${ip}:${port}
exit 0
fi
}
theUbuntu(){ //ubuntu执行的内容
if [ -z $domain ];then
rdesktop -u $username -p $password -r sound -r disk:USB=/media/${user} -r printer:mydeskjet -r clipboard:PRIMARYCLIPBOARD ${ip}:${port} &
exit 0
else
rdesktop -u $username -p $password -d $domain -r sound -r disk:USB=/media/${user} -r printer:mydeskjet -r clipboard:PRIMARYCLIPBOARD ${ip}:${port} &
exit 0
fi
}
checkIp
checkData
if [[ $type1 = CentOS || $type2 = CentOS ]];then
theCentOS
else
theUbuntu
fi