Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 2 additions & 1 deletion webroot/admin/ajax/get_page_contents.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@

$pageid = UnityHTTPD::getQueryParameter("pageid");
$page = $SQL->getPage($pageid);
echo $page["content"];
header('Content-Type: application/json; charset=utf-8');
echo jsonEncode(["content" => $page["content"]]);
3 changes: 2 additions & 1 deletion webroot/admin/content.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@
$("#pageForm > select[name=pageSel]").change(function(e) {
$.ajax({
url: `${url}?pageid=` + $(this).val(),
dataType: "json",
success: function(result) {
mainEditor.setData(result);
mainEditor.setData(result.content);
}});
});

Expand Down
17 changes: 5 additions & 12 deletions webroot/js/ajax/ssh_generate.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,13 @@
use phpseclib3\Crypt\EC;
use UnityWebPortal\lib\UnityHTTPD;

echo "<pre>";

$private = EC::createKey('Ed25519');
$public = $private->getPublicKey();

echo "<section class='pubKey'>";
echo $public->toString('OpenSSH');
echo "</section>";
echo "<section class='privKey'>";
$public_str = $public->toString('OpenSSH');
if (UnityHTTPD::getQueryParameter("type", false) == "ppk") {
echo $private->toString('PuTTY');
$private_str = $private->toString('PuTTY');
} else {
echo $private->toString('OpenSSH');
$private_str = $private->toString('OpenSSH');
}
echo "</section>";

echo "</pre>";
header('Content-Type: application/json; charset=utf-8');
echo jsonEncode(["public" => $public_str, "private" => $private_str]);
4 changes: 2 additions & 2 deletions webroot/js/ajax/ssh_validate.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

require_once __DIR__ . "/../../../vendor/autoload.php";
require_once __DIR__ . "/../../../resources/lib/utils.php";

echo testValidSSHKey($_POST["key"]) ? "true" : "false";
header('Content-Type: application/json; charset=utf-8');
echo jsonEncode(["is_valid" => testValidSSHKey($_POST["key"])]);
19 changes: 5 additions & 14 deletions webroot/panel/modal/new_key.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,21 +69,12 @@
});

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

$.ajax({
url: "<?php echo getURL("js/ajax/ssh_generate.php"); ?>?type=" + type,
dataType: "json",
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

$("input[type=hidden][name=gen_key]").val(result.public);
downloadFile(result.private, "privkey." + type); // Force download of private key
$("#newKeyform").submit();
}
});
Expand All @@ -104,13 +95,13 @@ function generateKey(type) {
var key = $(this).val();
$.ajax({
url: "<?php echo getURL("js/ajax/ssh_validate.php"); ?>",
dataType: "json",
type: "POST",
data: {
key: key
},
success: function(result) {
const res = result.replace(key, "");
if (res == "true") {
if (result.is_valid) {
$("input[id=add-key]").prop("disabled", false);
$("textarea[name=key]").css("box-shadow", "none");
} else {
Expand Down
Loading