|
33 | 33 | if (jsonMsg.Ports) {
|
34 | 34 | const validKeys = ['Name', 'SerialNumber', 'IsOpen', 'VendorID', 'ProductID'];
|
35 | 35 | if (jsonMsg.Network) {
|
36 |
| - printMsg = "<b>Network Ports</b>:<br>"+JSON.stringify(jsonMsg.Ports, validKeys, 2); |
| 36 | + printMsg = "Network Ports:\n"+JSON.stringify(jsonMsg.Ports, validKeys, 2); |
37 | 37 | } else {
|
38 |
| - printMsg = "<b>Serial Ports</b>:<br>"+JSON.stringify(jsonMsg.Ports, validKeys, 2); |
| 38 | + printMsg = "Serial Ports:\n"+JSON.stringify(jsonMsg.Ports, validKeys, 2); |
39 | 39 | }
|
40 | 40 | } else if (Object.keys(jsonMsg).length !== 0) {
|
41 | 41 | printMsg = JSON.stringify(jsonMsg, undefined, 2);
|
42 | 42 | }
|
| 43 | + |
| 44 | + // when parsing JSON we're escaping some html charaters like "&<>", we want to show their |
| 45 | + // original value in the log |
| 46 | + function decode(str) { |
| 47 | + let txt = new DOMParser().parseFromString(str, "text/html"); |
| 48 | + return txt.documentElement.textContent; |
| 49 | + } |
| 50 | + printMsg = decode(printMsg); |
| 51 | + |
43 | 52 | messages.push(printMsg);
|
44 | 53 | if (messages.length > MESSAGES_MAX_COUNT) {
|
45 | 54 | messages.shift();
|
46 | 55 | }
|
47 |
| - log.textContent = messages.join('<br><br>'); |
| 56 | + log.textContent = messages.join('\n\n'); |
48 | 57 | if (autoscroll.checked) {
|
49 | 58 | log.scrollTop = log.scrollHeight - log.clientHeight;
|
50 | 59 | }
|
|
60 | 69 | return false;
|
61 | 70 | }
|
62 | 71 | socket.emit('command', input.val());
|
| 72 | + input.val(''); |
63 | 73 | });
|
64 | 74 |
|
65 | 75 | $('#export').click(function() {
|
66 | 76 | var link = document.createElement('a');
|
67 | 77 | link.setAttribute('download', 'agent-log.txt');
|
68 |
| - var text = log.innerHTML.replace(/<br>/g, '\n'); |
69 |
| - text = text.replace(/<b>|<\/b>/g, ''); |
| 78 | + var text = log.textContent; |
70 | 79 | link.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
|
71 | 80 | link.click();
|
72 | 81 | });
|
|
83 | 92 | socket = io('http://{{$}}');
|
84 | 93 | }
|
85 | 94 | socket.on('disconnect', function(evt) {
|
86 |
| - appendLog($('<div><b>Connection closed.</b></div>')) |
| 95 | + appendLog('Connection closed.') |
87 | 96 | });
|
88 | 97 | socket.on('message', function(evt) {
|
89 | 98 | appendLog(evt);
|
90 | 99 | });
|
91 | 100 | } else {
|
92 |
| - appendLog($('<div><b>Your browser does not support WebSockets.</b></div>')) |
| 101 | + appendLog('Your browser does not support WebSockets.') |
93 | 102 | }
|
94 |
| - |
| 103 | + |
95 | 104 | $("#input").focus();
|
96 | 105 | });
|
97 | 106 | </script>
|
|
101 | 110 | height: 100%;
|
102 | 111 | }
|
103 | 112 |
|
104 |
| -body { |
| 113 | +body { |
105 | 114 | margin: 0px;
|
106 | 115 | padding: 0px;
|
107 | 116 | background: #F8F9F9;
|
|
111 | 120 |
|
112 | 121 | #container {
|
113 | 122 | display: flex;
|
114 |
| - flex-direction: column; |
| 123 | + flex-direction: column; |
115 | 124 | height: 100vh;
|
116 | 125 | width: 100%;
|
117 | 126 | }
|
|
126 | 135 | overflow-y: auto;
|
127 | 136 | }
|
128 | 137 |
|
129 |
| -#footer { |
130 |
| - display: flex; |
| 138 | +#footer { |
| 139 | + display: flex; |
131 | 140 | flex-wrap: wrap;
|
132 | 141 | align-items: flex-start;
|
133 | 142 | justify-content: space-between;
|
134 |
| - margin: 0px 15px 0px; |
| 143 | + margin: 0px 15px 0px; |
135 | 144 | }
|
136 | 145 |
|
137 |
| -#form { |
| 146 | +#form { |
138 | 147 | display: flex;
|
139 | 148 | flex-grow: 1;
|
140 | 149 | margin-bottom: 15px;
|
|
145 | 154 | }
|
146 | 155 |
|
147 | 156 | #secondary-controls div {
|
148 |
| - display: inline-block; |
149 |
| - padding: 10px 15px; |
| 157 | + display: inline-block; |
| 158 | + padding: 10px 15px; |
150 | 159 | }
|
151 | 160 |
|
152 | 161 | #autoscroll,
|
|
169 | 178 | box-shadow: 0 4px #95a5a6;
|
170 | 179 | margin-bottom: 4px;
|
171 | 180 | color: #000;
|
172 |
| - cursor: pointer; |
| 181 | + cursor: pointer; |
173 | 182 | font-size: 14px;
|
174 | 183 | letter-spacing: 1.28px;
|
175 | 184 | line-height: normal;
|
|
181 | 190 | }
|
182 | 191 |
|
183 | 192 | .button:hover {
|
184 |
| - box-shadow: 0 2px #95a5a6; |
| 193 | + box-shadow: 0 2px #95a5a6; |
185 | 194 | outline: none;
|
186 | 195 | transform: translateY(2px);
|
187 | 196 | }
|
188 | 197 |
|
189 | 198 | .button:active {
|
190 |
| - box-shadow: none; |
| 199 | + box-shadow: none; |
191 | 200 | transform: translateY(4px);
|
192 | 201 | }
|
193 | 202 |
|
194 | 203 | .textfield {
|
195 | 204 | background-color: #dae3e3;
|
196 | 205 | width: auto;
|
197 |
| - height: auto; |
| 206 | + height: auto; |
198 | 207 | padding: 10px 8px;
|
199 | 208 | margin-left: 8px;
|
200 | 209 | vertical-align: top;
|
|
0 commit comments