64
64
});
65
65
66
66
function generateKey(type) {
67
- var pubSection = "<section class='pubKey'>";
68
- var privSection = "<section class='privKey'>";
69
- var endingSection = "</section>";
70
-
71
67
$.ajax({
72
68
url: "<?php echo $ CONFIG ["site " ]["prefix " ]; ?> /js/ajax/ssh_generate.php?type=" + type,
73
69
success: function(result) {
74
- var pubKey = result.substr(result.indexOf(pubSection) + pubSection.length,
75
- result.indexOf(endingSection) - result.indexOf(pubSection) - pubSection.length);
76
- var privKey = result.substr(result.indexOf(privSection) + privSection.length,
77
- result.indexOf(endingSection, result.indexOf(endingSection) + 1) -
78
- result.indexOf(privSection) - privSection.length);
79
- $("input[type=hidden][name=gen_key]").val(pubKey);
80
- downloadFile(privKey, "privkey." + type); // Force download of private key
81
-
70
+ success: function(outputJsonStr) {
71
+ const output = JSON.parse(outputJsonStr);
72
+ $("input[type=hidden][name=gen_key]").val(output.pubkey);
73
+ downloadFile(output.privkey, `privkey.${type}`); // Force download of private key
82
74
$("#newKeyform").submit();
83
75
}
84
76
});
@@ -104,8 +96,7 @@ function generateKey(type) {
104
96
key: key
105
97
},
106
98
success: function(result) {
107
- const res = result.replace(key, "");
108
- if (res == "true") {
99
+ if (result == "true") {
109
100
$("input[id=add-key]").prop("disabled", false);
110
101
$("textarea[name=key]").css("box-shadow", "none");
111
102
} else {
0 commit comments