From 5558b052f03c08df0648fd4af68662c09f31b676 Mon Sep 17 00:00:00 2001 From: Anshul Saha Date: Tue, 14 Feb 2023 18:57:04 -0500 Subject: [PATCH 1/9] added ajax call; updated account.php --- webroot/js/ajax/ssh_validate.php | 14 ++++++++++++++ webroot/panel/account.php | 20 ++++++++++++++++++-- webroot/panel/modal/new_key.php | 24 +++++++++++++++++++++++- 3 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 webroot/js/ajax/ssh_validate.php diff --git a/webroot/js/ajax/ssh_validate.php b/webroot/js/ajax/ssh_validate.php new file mode 100644 index 00000000..23987260 --- /dev/null +++ b/webroot/js/ajax/ssh_validate.php @@ -0,0 +1,14 @@ +alert('Invalid SSH Key. Try again.');"; + if ($_SERVER['REQUEST_METHOD'] == "POST") { switch ($_POST["form_type"]) { case "addKey": @@ -13,10 +17,22 @@ switch ($_POST["add_type"]) { case "paste": - array_push($added_keys, $_POST["key"]); + try{ + PublicKeyLoader::load($_POST["key"], $password = false); + array_push($added_keys, $_POST["key"]); + } catch (Exception $e) { + echo $invalid_ssh_dialogue; + } break; case "import": - array_push($added_keys, file_get_contents($_FILES['keyfile']['tmp_name'])); + $keyfile = $_FILES["keyfile"]["tmp_name"]; + $key = file_get_contents($keyfile); + try{ + PublicKeyLoader::load($key, $password = false); + array_push($added_keys, $key); + } catch (Exception $e) { + echo $invalid_ssh_dialogue; + } break; case "generate": array_push($added_keys, $_POST["gen_key"]); diff --git a/webroot/panel/modal/new_key.php b/webroot/panel/modal/new_key.php index 9f63d736..96ada521 100644 --- a/webroot/panel/modal/new_key.php +++ b/webroot/panel/modal/new_key.php @@ -32,7 +32,7 @@
- +