-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
268 lines (217 loc) · 11 KB
/
index.html
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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
<!DOCTYPE html>
<html lang="en" data-theme="dark">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>RDP File Editor</title>
<link rel="icon" type="image/png" href="rdp.png">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<!-- Vue 3 -->
<script src="https://unpkg.com/vue@3"></script>
<style>
.form-control {
box-shadow: none !important;
}
.rdptop {
transform: translateY(-55%);
text-shadow: -1px -1px 0 #fff, 1px -1px 0 #fff, -1px 1px 0 #fff, 1px 1px 0 #fff;
}
.rdpbottom {
transform: translateY(50%);
bottom: 0;
}
.almostright {
right: 0.6em;
}
.almostleft {
left: 0.6em;
}
.rdpicon {
height: 1.2em;
}
</style>
</head>
<body>
<div id="app" class="py-4 container-xl">
<div class="mb-5 text-center">
<p class="display-5"><img src="rdp.png" class="rdpicon"> RDP File Editor</p>
<span class="lead">Create and edit RDP files.</span>
</div>
<div class="position-relative mx-1">
<div class="position-absolute rdptop almostleft fw-bold text-success">RDP File</div>
<div class="position-absolute rdptop almostright">
</div>
<div class="position-absolute rdpbottom almostleft ">
<div class="btn btn-outline-secondary bg-white text-muted btn-sm me-2" @click="clickLoad()">Load</div>
<div class="btn btn-outline-secondary bg-white text-muted btn-sm" @click="resetOptions()">Reset</div>
</div>
<div class="position-absolute rdpbottom almostright">
<div class="btn btn-success btn-sm" @click="saveRdpFile()">Save</div>
</div>
<div class="font-monospace border p-4 mb-5">
<span v-html="formatDescription(rdpOutput())"></span>
</div>
</div>
<ul class="nav nav-tabs small">
<li class="nav-item" v-for="category, catKey in userRdpOptions">
<a class="nav-link" href="#"
:class="{active: selectedTab == catKey, 'fw-bold': selectedTab == catKey,'text-muted': selectedTab != catKey}"
@click="selectedTab = catKey">{{catKey}}</a>
</li>
</ul>
<div v-for="category, catKey in userRdpOptions" class="mt-3">
<div v-if="selectedTab == catKey" class="row">
<div v-for="option, key, index in category" class="col-md-6 col-xl-4">
<div
class="d-flex flex-column justify-content-between align-items-center border rounded bg-light p-1 m-1">
<div class="w-100 text-center btn" @click="expandedOption = expandedOption == key ? '' : key">
<span class="text-capitalize"
:class="{'text-primary': option.value != allRdpOptions[catKey][key].value}">{{ key }}</span></a>
</div>
<div class="w-100 text-center p-2 pt-0" v-if="expandedOption == key">
<div class="w-100 my-2 border rounded p-2 text-start bg-white">
<span class="small" v-html="formatDescription(option.description)"></span>
</div>
<div class="d-flex justify-content-around small my-3">
<span>Type: {{ fullType(option.type) }}</span>
<span>Default:
{{ allRdpOptions[catKey][key].value ? allRdpOptions[catKey][key].value : "(empty)" }}</span>
</div>
<div class="w-100 d-flex my-2">
<input class="form-control outline-0" v-model="option.value" placeholder="empty">
<button class="btn btn-danger ms-2"
@click="userRdpOptions[catKey][key].value = allRdpOptions[catKey][key].value">Reset</button>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="text-center small"><a href="https://github.com/kimmknight/rdpfileeditor">GitHub</a></div>
<input id="fileloadinput" class="d-none" type="file" accept=".rdp" @change="loadRdpFile($event)">
</div>
<!-- Vue script -->
<script>
// Vue application definition
const vueApp = {
// Data properties for the application
data() {
return {
allRdpOptions: {}, // Store all available RDP options
userRdpOptions: {}, // Store user-selected RDP options
expandedOption: "", // Track expanded option for display
selectedTab: "Connection", // Initially selected RDP option category
}
},
// Methods for handling data manipulation and user interactions
methods: {
// Deep copy function to create a copy of an object/array
deepCopy(arr) {
return JSON.parse(JSON.stringify(arr))
},
// Fetch RDP options from a JSON file
fetchOptions() {
fetch("rdpoptions.json")
.then((httpResponse) => httpResponse.json())
.then((responseData) => {
this.allRdpOptions = responseData
this.resetOptions()
})
},
// Reset user-selected options to default
resetOptions() {
this.userRdpOptions = this.deepCopy(this.allRdpOptions)
this.userRdpOptions["Connection"]["full address"].value = window.location.hostname
},
// Format option descriptions with line breaks
formatDescription(rawDescription) {
return rawDescription.replace(/\n/gm, "<br>")
},
// Convert short type codes to full type names
fullType(shortType) {
const types = {
"s": "Text",
"i": "Number",
"b": "Binary"
}
return types[shortType]
},
// Generate formatted RDP output string
rdpOutput() {
let outputString = ""; // Create a string to store the formatted output
// Compare and add lines for changed options to the output string
for (let catKey in this.userRdpOptions) {
for (let key in this.userRdpOptions[catKey]) {
if (this.userRdpOptions[catKey][key].value !== this.allRdpOptions[catKey][key].value) {
outputString +=
`${key}:${this.userRdpOptions[catKey][key].type}:${this.userRdpOptions[catKey][key].value}\n`;
}
}
}
return outputString;
},
// Save the generated RDP file
saveRdpFile() {
// Set the filename: The RemoteApp Name if specified, otherwise the Full Address, otherwise RDP File.rdp
let filename = "RDP File.rdp"
if (this.userRdpOptions["RemoteApp"]["remoteapplicationname"].value) {
filename = this.userRdpOptions["RemoteApp"]["remoteapplicationname"].value + ".rdp"
} else if (this.userRdpOptions["Connection"]["full address"].value) {
filename = this.userRdpOptions["Connection"]["full address"].value.replace(/\./gm, "-") +
".rdp"
}
// Get the RDP file content
const text = this.rdpOutput()
// Create a download link and trigger the download
let element = document.createElement('a');
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
element.setAttribute('download', filename);
element.style.display = 'none';
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
},
// Load an RDP file from the local filesystem
loadRdpFile(input) {
let file = input.target.files[0];
let reader = new FileReader();
reader.readAsText(file);
reader.onload = () => {
const result = reader.result;
const rdpFileLines = result.split("\n");
this.resetOptions();
for (rdpFileLine of rdpFileLines) {
if (rdpFileLine.match(/:/g) && rdpFileLine.match(/:/g).length === 2) {
const rdpFileOption = rdpFileLine.split(":");
for (let catKey in this.userRdpOptions) {
for (let key in this.userRdpOptions[catKey]) {
if (key == rdpFileOption[0]) {
this.userRdpOptions[catKey][key].value = rdpFileOption[2]
}
}
}
}
}
};
reader.onerror = function () {
console.log(reader.error);
};
},
// Activate the hidden input used for selecting an RDP file from the local filesystem
clickLoad() {
document.getElementById("fileloadinput").click()
},
},
// Lifecycle hook to fetch options when the component is mounted
mounted() {
this.fetchOptions()
}
}
// Create a Vue app and mount it to the #app element
const app = Vue.createApp(vueApp)
const vm = app.mount("#app")
</script>
</body>
</html>