|
69 | 69 | $USER->setSSHKeys($keys, $OPERATOR); // Update user keys |
70 | 70 | break; |
71 | 71 | case "loginshell": |
72 | | - if ($_POST["shellSelect"] == "Custom") { |
73 | | - $USER->setLoginShell($_POST["shell"], $OPERATOR); |
74 | | - } else { |
75 | | - $USER->setLoginShell($_POST["shellSelect"], $OPERATOR); |
76 | | - } |
| 72 | + $USER->setLoginShell($_POST["shellSelect"], $OPERATOR); |
77 | 73 | break; |
78 | 74 | case "pi_request": |
79 | 75 | if (!$USER->isPI()) { |
|
210 | 206 | foreach ($CONFIG["loginshell"]["shell"] as $shell) { |
211 | 207 | echo "<option>$shell</option>"; |
212 | 208 | } |
213 | | -echo "<option id='customLoginSelectorOption'>Custom</option>"; |
214 | 209 | ?> |
215 | 210 | </select> |
216 | | -<?php |
217 | | -echo " |
218 | | - <input |
219 | | - id='customLoginBox' |
220 | | - type='text' |
221 | | - placeholder='Enter login shell path (ie. /bin/bash)' |
222 | | - name='shell' |
223 | | - /> |
224 | | -"; |
225 | | -?> |
226 | 211 | <br> |
227 | 212 | <input id='submitLoginShell' type='submit' value='Set Login Shell' /> |
228 | 213 | <label id='labelSubmitLoginShell'> <!-- value set by JS --> </label> |
|
266 | 251 | openModal("Add New Key", `${sitePrefix}/panel/modal/new_key.php`); |
267 | 252 | }); |
268 | 253 |
|
269 | | - var defaultShellSelected = false; |
270 | 254 | $("#loginSelector option").each(function(i, e) { |
271 | 255 | if ($(this).val() == ldapLoginShell) { |
272 | 256 | $(this).prop("selected", true); |
273 | | - defaultShellSelected = true; |
274 | 257 | } |
275 | 258 | }); |
276 | | - if (!defaultShellSelected) { |
277 | | - $("#customLoginBox").val(ldapLoginShell); |
278 | | - $("#customLoginSelectorOption").prop("selected", true); |
279 | | - } |
280 | | - |
281 | | - function showOrHideCustomLoginBox() { |
282 | | - var customBox = $("#customLoginBox"); |
283 | | - if($("#loginSelector").val() == "Custom") { |
284 | | - customBox.show(); |
285 | | - } else { |
286 | | - customBox.hide(); |
287 | | - } |
288 | | - } |
289 | | - $("#loginSelector").change(showOrHideCustomLoginBox); |
290 | | - showOrHideCustomLoginBox(); |
291 | | - |
292 | | - function getNewLoginShell() { |
293 | | - var loginSelectorVal = $("#loginSelector").val(); |
294 | | - if (loginSelectorVal != "Custom") { |
295 | | - return loginSelectorVal; |
296 | | - } |
297 | | - return $("#customLoginBox").val(); |
298 | | - } |
299 | | - |
300 | | - function isLoginShellValid(x) { |
301 | | - if (/^\s|\s$/.test(x)) { |
302 | | - return [false, "must not have leading or trailing whitespace"]; |
303 | | - } |
304 | | - if (x.length === 0) { |
305 | | - return [false, "must not be empty"]; |
306 | | - } |
307 | | - if (!(/^[\x00-\x7F]*$/.test(x))) { |
308 | | - return [false, "must only contain ASCII characters"]; |
309 | | - } |
310 | | - return [true, ""]; |
311 | | - } |
312 | | - |
313 | | - function enableOrDisableCustomLoginBoxHighlight() { |
314 | | - if ( |
315 | | - ($("#customLoginSelectorOption").prop("selected") == true) && |
316 | | - !isLoginShellValid($("#customLoginBox").val()) |
317 | | - ) { |
318 | | - $("#customLoginBox").css("box-shadow", "0 0 0 0.3rem rgba(220, 53, 69, 0.25)"); |
319 | | - } else { |
320 | | - $("#customLoginBox").css("box-shadow", "none"); |
321 | | - } |
322 | | - } |
323 | | - $("#customLoginBox").on("input", enableOrDisableCustomLoginBoxHighlight); |
324 | | - $("#loginSelector").change(enableOrDisableCustomLoginBoxHighlight); |
325 | | - enableOrDisableCustomLoginBoxHighlight(); |
326 | 259 |
|
327 | 260 | function enableOrDisableSubmitLoginShell() { |
328 | | - var newLoginShell = getNewLoginShell(); |
329 | | - isValidArr = isLoginShellValid(newLoginShell); |
330 | | - isValid = isValidArr[0]; |
331 | | - isValidReason = isValidArr[1]; |
332 | | - if (!isValid) { |
| 261 | + if ($("#loginSelector").val() == ldapLoginShell) { |
333 | 262 | $("#submitLoginShell").prop("disabled", true); |
334 | | - $("#labelSubmitLoginShell").text(`(invalid login shell: ${isValidReason})`); |
335 | | - return; |
336 | | - } |
337 | | - if (newLoginShell == ldapLoginShell) { |
338 | | - $("#submitLoginShell").prop("disabled", true); |
339 | | - $("#labelSubmitLoginShell").text("(no change)"); |
340 | | - return; |
| 263 | + } else { |
| 264 | + $("#submitLoginShell").prop("disabled", false); |
341 | 265 | } |
342 | | - $("#submitLoginShell").prop("disabled", false); |
343 | | - $("#labelSubmitLoginShell").text(""); |
344 | 266 | } |
345 | | - $("#customLoginBox").on("input", enableOrDisableSubmitLoginShell); |
346 | 267 | $("#loginSelector").change(enableOrDisableSubmitLoginShell); |
347 | 268 | enableOrDisableSubmitLoginShell() |
348 | 269 | </script> |
|
0 commit comments