|
186 | 186 | <hr> |
187 | 187 |
|
188 | 188 | <form action="" method="POST"> |
189 | | - |
190 | | - <input type="hidden" name="form_type" value="loginshell"> |
191 | | - |
192 | | - <select id="loginSelector" name= "shellSelect"> |
193 | | - |
194 | | - <option value="" disabled hidden>Select Login Shell...</option> |
195 | | - |
196 | | - <?php |
197 | | - $cur_shell = $USER->getLoginShell(); |
198 | | - $found_selector = false; |
199 | | - foreach ($CONFIG["loginshell"]["shell"] as $shell) { |
200 | | - if ($cur_shell == $shell) { |
201 | | - echo "<option selected>$shell</option>"; |
202 | | - $found_selector = true; |
203 | | - } else { |
204 | | - echo "<option>$shell</option>"; |
205 | | - } |
206 | | - } |
207 | | - |
208 | | - if ($found_selector) { |
209 | | - echo "<option value='custom'>Custom</option>"; |
210 | | - } else { |
211 | | - echo "<option value='custom' selected>Custom</option>"; |
212 | | - } |
213 | | - ?> |
214 | | - </select> |
215 | | - |
216 | | - <?php |
217 | | - |
218 | | - if ($found_selector) { |
219 | | - echo "<input id='customLoginBox' type='text' |
220 | | - placeholder='Enter login shell path (ie. /bin/bash)' name='shell'>"; |
221 | | - } else { |
222 | | - echo "<input id='customLoginBox' type='text' |
223 | | - placeholder='Enter login shell path (ie. /bin/bash)' name='shell' value='$cur_shell'>"; |
224 | | - } |
225 | | - |
226 | | - ?> |
227 | | - <br> |
228 | | - <input type='submit' value='Set Login Shell'> |
229 | | - |
| 189 | +<input type="hidden" name="form_type" value="loginshell"> |
| 190 | +<select id="loginSelector" name="shellSelect"> |
| 191 | +<?php |
| 192 | +foreach ($CONFIG["loginshell"]["shell"] as $shell) { |
| 193 | + echo "<option>$shell</option>"; |
| 194 | +} |
| 195 | +echo "<option id='customLoginSelectorOption' value='custom'>Custom</option>"; |
| 196 | +?> |
| 197 | +</select> |
| 198 | +<?php |
| 199 | +echo " |
| 200 | + <input |
| 201 | + id='customLoginBox' |
| 202 | + type='text' |
| 203 | + placeholder='Enter login shell path (ie. /bin/bash)' |
| 204 | + name='shell' |
| 205 | + > |
| 206 | +"; |
| 207 | +?> |
| 208 | +<br> |
| 209 | +<input id='submitLoginShell' type='submit' value='Set Login Shell'> |
230 | 210 | </form> |
231 | | - |
232 | 211 | <hr> |
233 | 212 |
|
234 | 213 | <h5>Account Deletion</h5> |
|
255 | 234 |
|
256 | 235 | <hr> |
257 | 236 |
|
258 | | - |
259 | 237 | <script> |
260 | | - $("button.btnAddKey").click(function() { |
261 | | - openModal("Add New Key", "<?php echo $CONFIG["site"]["prefix"]; ?>/panel/modal/new_key.php"); |
| 238 | + const sitePrefix = '<?php echo $CONFIG["site"]["prefix"]; ?>'; |
| 239 | + const ldapLoginShell = '<?php echo $USER->getLoginShell(); ?>'; |
| 240 | + |
| 241 | + var defaultShellSelected = false; |
| 242 | + $("#loginSelector option").each(function(i, e) { |
| 243 | + if ($(this).val() == ldapLoginShell) { |
| 244 | + $(this).attr("selected", true); |
| 245 | + defaultShellSelected = true; |
| 246 | + } |
262 | 247 | }); |
263 | | - |
264 | | - var customLoginBox = $("#customLoginBox"); |
265 | | - if (customLoginBox.val() == "") { |
266 | | - // login box is empty, so we hide it by default |
267 | | - // if the login box had a value, that means it would be a custom shell |
268 | | - // and should not hide by default |
269 | | - customLoginBox.hide(); |
| 248 | + if (!defaultShellSelected) { |
| 249 | + $("#customLoginBox").val(ldapLoginShell); |
| 250 | + $("#customLoginSelectorOption").attr("selected", true); |
270 | 251 | } |
271 | 252 |
|
272 | | - $("#loginSelector").change(function() { |
| 253 | + $("button.btnAddKey").click(function() { |
| 254 | + openModal("Add New Key", `${sitePrefix}/panel/modal/new_key.php`); |
| 255 | + }); |
| 256 | + |
| 257 | + function showOrHideCustomLoginBox() { |
273 | 258 | var customBox = $("#customLoginBox"); |
274 | | - if($(this).val() == "custom") { |
| 259 | + if($("#loginSelector").val() == "custom") { |
275 | 260 | customBox.show(); |
276 | 261 | } else { |
277 | 262 | customBox.hide(); |
278 | 263 | } |
279 | | - }); |
| 264 | + } |
| 265 | + $("#loginSelector").change(showOrHideCustomLoginBox); |
| 266 | + showOrHideCustomLoginBox(); |
280 | 267 |
|
281 | | - if ($("#loginSelector").val() == "custom") { |
282 | | - $("#customLoginBox").show(); |
| 268 | + function getNewLoginShell() { |
| 269 | + var loginSelectorVal = $("#loginSelector").val(); |
| 270 | + if (loginSelectorVal != "custom") { |
| 271 | + return loginSelectorVal; |
| 272 | + } |
| 273 | + return $("#customLoginBox").val(); |
| 274 | + } |
| 275 | + function isLoginShellValid(x) { |
| 276 | + if (x.trim().length === 0) { |
| 277 | + return false; |
| 278 | + } |
| 279 | + // only ascii characters allowed |
| 280 | + if (!(/^[\x00-\x7F]*$/.test(x))) { |
| 281 | + return false; |
| 282 | + } |
| 283 | + return true; |
| 284 | + } |
| 285 | + function enableOrDisableSubmitLoginShell() { |
| 286 | + var submitLoginShell = $("#submitLoginShell"); |
| 287 | + var newLoginShell = getNewLoginShell(); |
| 288 | + if (!isLoginShellValid(newLoginShell)) { |
| 289 | + submitLoginShell.attr("disabled", true); |
| 290 | + $("#customLoginBox").css("box-shadow", "0 0 0 0.3rem rgba(220, 53, 69, 0.25)"); |
| 291 | + return; |
| 292 | + } else { |
| 293 | + $("#customLoginBox").css("box-shadow", "none"); |
| 294 | + } |
| 295 | + if (newLoginShell == ldapLoginShell) { |
| 296 | + submitLoginShell.attr("disabled", true); |
| 297 | + return; |
| 298 | + } |
| 299 | + submitLoginShell.attr("disabled", false); |
283 | 300 | } |
| 301 | + $("#customLoginBox").on("input", enableOrDisableSubmitLoginShell); |
| 302 | + $("#loginSelector").change(enableOrDisableSubmitLoginShell); |
| 303 | + enableOrDisableSubmitLoginShell() |
284 | 304 | </script> |
285 | 305 |
|
286 | 306 | <style> |
|
0 commit comments