-
Notifications
You must be signed in to change notification settings - Fork 0
/
xfreerdp-gui
executable file
·218 lines (193 loc) · 7.49 KB
/
xfreerdp-gui
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
#!/bin/bash
get_user_input() {
user_input=$(zenity \
--forms \
--title="XFreeRDP GUI" \
--text="Enter the following values:" \
--add-entry="Window Name:" \
--add-entry="IP address:" \
--add-entry="Port:" \
--add-entry="Username:" \
--add-password="Password:" \
--separator="/delimiter/" \
--forms-date-format="%Y-%m-%d %H:%M:%S" \
--ok-label="Continue" \
--cancel-label="Exit" \
2>/dev/null)
if [ $? -ne 0 ]; then
exit 1
fi
RDP_WINDOW_NAME=$(echo "$user_input" | awk -F "/delimiter/" '{print $1}')
RDP_IP=$(echo "$user_input" | awk -F "/delimiter/" '{print $2}')
RDP_PORT=$(echo "$user_input" | awk -F "/delimiter/" '{print $3}')
RDP_USERNAME=$(echo "$user_input" | awk -F "/delimiter/" '{print $4}')
RDP_PASSWORD=$(echo "$user_input" | awk -F "/delimiter/" '{print $5}')
}
get_feature_flags() {
user_flags_input=$(zenity \
--list \
--title="XFreeRDP GUI - Select Features" \
--text="Select the Features to enable:" \
--checklist \
--print-column=2 \
--column="-" \
--column="Flag" \
--column="Description" \
--separator="/delimiter/" \
--ok-label="Continue" \
--cancel-label="Exit" \
TRUE " +dynamic-resolution" "Update resolution on Resize" \
TRUE " +window-drag" "Enable full window drag" \
TRUE " +home-drive" "Enable Redirect user home as share" \
TRUE " +auto-reconnect" "Enable Automatic reconnection" \
TRUE " +clipboard" "Enable Clipboard redirection" \
TRUE " +offscreen-cache" "Enable Offscreen Bitmap Cache" \
TRUE " +multitouch" "Enable Redirect multitouch input" \
TRUE " -heartbeat" "Disable Support heartbeat PDUs" \
TRUE " +gestures" "Enable Consumption of multitouch input" \
TRUE " +aero" "Enable Desktop composition" \
TRUE " +bitmap-cache" "Enable Bitmap caching" \
TRUE " +disp" "Enable Display control" \
TRUE " +sound" "Listen remote desktop sound locally" \
TRUE " +microphone" "Allow remote desktop to use local microphone" \
TRUE " +video" "Redirect Multimedia Video" \
2>/dev/null)
if [ $? -ne 0 ]; then
exit 1
fi
RDP_FLAGS=$(echo "$user_flags_input" | awk -F "/delimiter/" '{ for(i=1; i<=NF; i++) { sub(/^[ \t]+/, "", $i); sub(/[ \t]+$/, "", $i); print $i } }')
RDP_FLAGS=$(echo "$RDP_FLAGS" | tr '\n' ' ')
RDP_FLAGS=$(echo "$RDP_FLAGS" | sed 's/ *$//g')
}
ask_to_save() {
zenity --question --title="Save Values?" --text="Do you want to save these values?" --ok-label="Save" --cancel-label="Don't Save"
if [ $? -eq 0 ]; then
SAVE="True"
else
SAVE="False"
fi
}
print_array_as_array() {
local array=("$@")
value="(\n"
for i in "${array[@]}"; do
value="$value\"$i\"\n"
done
value="$value)"
echo "$value"
}
save_to_file() {
mkdir -p ~/.XFreeRDP-GUI
local current_max_index=$(ls ~/.XFreeRDP-GUI | grep -E "^saved-connection-[0-9]+$" | sed 's/^saved-connection-//g' | sort -n | tail -n 1)
local new_index=$((current_max_index + 1))
echo -e "RDP_WINDOW_NAME=\"$RDP_WINDOW_NAME\"\nRDP_IP=$RDP_IP\nRDP_PORT=$RDP_PORT\nRDP_USERNAME=\"$RDP_USERNAME\"\nRDP_PASSWORD=\"$RDP_PASSWORD\"\nRDP_FLAGS=$(print_array_as_array $RDP_FLAGS)" > ~/.XFreeRDP-GUI/saved-connection-$new_index
FREERDP_GUI_CONNECTION_INDEX=$new_index
}
check_saved_file() {
[ -d ~/.XFreeRDP-GUI ] && [ "$(ls -A ~/.XFreeRDP-GUI)" ] && [ -f ~/.XFreeRDP-GUI/recent ]
}
read_latest_saved_values() {
local current_max_index=$(ls ~/.XFreeRDP-GUI | grep -E "^saved-connection-[0-9]+$" | sed 's/^saved-connection-//g' | sort -n | tail -n 1)
source ~/.XFreeRDP-GUI/saved-connection-$current_max_index
FREERDP_GUI_CONNECTION_INDEX=$current_max_index
}
read_recent_connection_saved_values() {
source ~/.XFreeRDP-GUI/recent
source ~/.XFreeRDP-GUI/saved-connection-$FREERDP_GUI_CONNECTION_INDEX
}
read_saved_connection_by_index() {
source ~/.XFreeRDP-GUI/saved-connection-$1
}
get_saved_connecton_index() {
local saved_connections=()
for i in $(ls ~/.XFreeRDP-GUI | grep -E "^saved-connection-[0-9]+$" | sed 's/^saved-connection-//g' | sort -n); do
source ~/.XFreeRDP-GUI/saved-connection-$i
saved_connections+=(FALSE "$i" "$RDP_WINDOW_NAME" "$RDP_IP" "$RDP_PORT" "$RDP_USERNAME")
unset RDP_WINDOW_NAME
unset RDP_IP
unset RDP_PORT
unset RDP_USERNAME
unset RDP_PASSWORD
unset RDP_FLAGS
done
choice=$(zenity \
--list \
--radiolist \
--title="XFreeRDP GUI - Select Connection" \
--text="Select the connection to use:" \
--print-column=2 \
--column="-" \
--column="ID" \
--column="Name" \
--column="IP" \
--column="Port" \
--column="Username" \
--separator="/delimiter/" \
--ok-label="Continue" \
--cancel-label="Exit" \
"${saved_connections[@]}" \
2>/dev/null)
if [ $? -ne 0 ]; then
exit 1
fi
FREERDP_GUI_CONNECTION_INDEX=$choice
}
get_rdp_command() {
echo "xfreerdp $1 +t:\"$2\" +v:$3 +port:$4 +u:\"$5\" +p:\"$6\""
}
main() {
if [ "$1" == "--help" ]; then
echo "XFreeRDP GUI"
echo "Launches XFreeRDP connection configuration GUI."
echo "Provided by: NightmareGaurav [https://www.github.com/NightmareGaurav]"
echo ""
echo "Usage: xfreerdp-gui [OPTION]"
echo ""
echo "Options (optional):"
echo " <NONE> Launch the GUI."
echo " --help Display this help message."
echo " --latest Seamlessly Use the most recently saved connection."
echo " --recent Seamlessly Use the most recently used connection."
echo " --saved Open a list of saved connections to choose from."
echo ""
echo "Example:"
echo " xfreerdp-gui --saved-recent-connection"
exit 0
elif [ "$1" == "--latest" ] && check_saved_file; then
read_latest_saved_values
SAVE="N/A"
elif [ "$1" == "--recent" ] && check_saved_file; then
read_recent_connection_saved_values
SAVE="N/A"
elif [ "$1" == "--saved" ] && check_saved_file; then
get_saved_connecton_index
read_saved_connection_by_index "$FREERDP_GUI_CONNECTION_INDEX"
SAVE="N/A"
else
get_user_input
get_feature_flags
ask_to_save
if [ "$SAVE" == "True" ]; then
if check_saved_file; then
zenity --question --title="Warning" --text="This action will replace previously saved values.\n\nDo you want to proceed?" --ok-label="Replace" --cancel-label="Don't Save"
if [ $? -eq 0 ]; then
save_to_file
fi
else
save_to_file
fi
fi
fi
RDP_COMMAND=$(get_rdp_command "${RDP_FLAGS[*]}" "$RDP_WINDOW_NAME" "$RDP_IP" "$RDP_PORT" "$RDP_USERNAME" "$RDP_PASSWORD")
echo "[*] Saved: $SAVE"
echo "[*] Window Name: $RDP_WINDOW_NAME"
echo "[*] IP: $RDP_IP"
echo "[*] Port: $RDP_PORT"
echo "[*] Username: $RDP_USERNAME"
echo "[*] Password: $RDP_PASSWORD"
echo "[*] Flags: ${RDP_FLAGS[*]}"
echo "[*] Executing Command: $RDP_COMMAND"
echo -e "FREERDP_GUI_CONNECTION_INDEX=$FREERDP_GUI_CONNECTION_INDEX" > ~/.XFreeRDP-GUI/recent
eval "$RDP_COMMAND"
}
main "$1"