Skip to content

replace strlen hack with json #164

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 10 additions & 12 deletions webroot/js/ajax/ssh_generate.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,18 @@

use phpseclib3\Crypt\RSA;

echo "<pre>";

$private = RSA::createKey(2048);
$public = $private->getPublicKey();

echo "<section class='pubKey'>";
echo $public->toString('OpenSSH');
echo "</section>";
echo "<section class='privKey'>";
if (isset($_GET["type"]) && $_GET["type"] == "ppk") {
echo $private->toString('PuTTY');
} else {
echo $private;
switch ($_GET["type"]) {
case "key":
break;
case "ppk":
$private = $private->toString("PuTTY");
break;
}
echo "</section>";

echo "</pre>";
echo json_encode([
"pubkey" => $public->toString('OpenSSH'),
"privkey" => $private
]);
19 changes: 5 additions & 14 deletions webroot/panel/modal/new_key.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,21 +64,13 @@
});

function generateKey(type) {
var pubSection = "<section class='pubKey'>";
var privSection = "<section class='privKey'>";
var endingSection = "</section>";

$.ajax({
url: "<?php echo $CONFIG["site"]["prefix"]; ?>/js/ajax/ssh_generate.php?type=" + type,
success: function(result) {
var pubKey = result.substr(result.indexOf(pubSection) + pubSection.length,
result.indexOf(endingSection) - result.indexOf(pubSection) - pubSection.length);
var privKey = result.substr(result.indexOf(privSection) + privSection.length,
result.indexOf(endingSection, result.indexOf(endingSection) + 1) -
result.indexOf(privSection) - privSection.length);
$("input[type=hidden][name=gen_key]").val(pubKey);
downloadFile(privKey, "privkey." + type); // Force download of private key

success: function(outputJsonStr) {
const output = JSON.parse(outputJsonStr);
$("input[type=hidden][name=gen_key]").val(output.pubkey);
downloadFile(output.privkey, `privkey.${type}`); // Force download of private key
$("#newKeyform").submit();
}
});
Expand All @@ -104,8 +96,7 @@ function generateKey(type) {
key: key
},
success: function(result) {
const res = result.replace(key, "");
if (res == "true") {
if (result == "true") {
$("input[id=add-key]").prop("disabled", false);
$("textarea[name=key]").css("box-shadow", "none");
} else {
Expand Down
Loading