6969 });
7070
7171 function generateKey(type) {
72- var pubSection = "<section class='pubKey'>";
73- var privSection = "<section class='privKey'>";
74- var endingSection = "</section>";
75-
7672 $.ajax({
7773 url: "<?php echo getURL ("js/ajax/ssh_generate.php " ); ?> ?type=" + type,
74+ dataType: "json",
7875 success: function(result) {
79- var pubKey = result.substr(result.indexOf(pubSection) + pubSection.length,
80- result.indexOf(endingSection) - result.indexOf(pubSection) - pubSection.length);
81- var privKey = result.substr(result.indexOf(privSection) + privSection.length,
82- result.indexOf(endingSection, result.indexOf(endingSection) + 1) -
83- result.indexOf(privSection) - privSection.length);
84- $("input[type=hidden][name=gen_key]").val(pubKey);
85- downloadFile(privKey, "privkey." + type); // Force download of private key
86-
76+ $("input[type=hidden][name=gen_key]").val(result.public);
77+ downloadFile(result.private, "privkey." + type); // Force download of private key
8778 $("#newKeyform").submit();
8879 }
8980 });
@@ -104,13 +95,13 @@ function generateKey(type) {
10495 var key = $(this).val();
10596 $.ajax({
10697 url: "<?php echo getURL ("js/ajax/ssh_validate.php " ); ?> ",
98+ dataType: "json",
10799 type: "POST",
108100 data: {
109101 key: key
110102 },
111103 success: function(result) {
112- const res = result.replace(key, "");
113- if (res == "true") {
104+ if (result.is_valid) {
114105 $("input[id=add-key]").prop("disabled", false);
115106 $("textarea[name=key]").css("box-shadow", "none");
116107 } else {
0 commit comments