This commit is contained in:
firebadnofire 2025-06-30 17:09:10 +00:00
parent b98f71b0cb
commit ba2d29cac0
Signed by: firebadnofire
SSH key fingerprint: SHA256:u6FSE3IO4HH22JiYojmJ8jsN6d1Khaf/iEAiy7HobaU
2 changed files with 48 additions and 6 deletions

View file

@ -4,4 +4,10 @@ centralized ssh pub key repo
To push a key to the repo, the following may be used:
`curl -X POST -F "text=Hello World" -F "password=SuperSecretPassword" https://archuser.org/ssh/api.php`
`curl -X POST -d "text=ssh-rsa AAAA..." -d "password=SuperSecretPassword" https://archuser.org/ssh/api.php`
To delete a line from the repo, use the following:
`curl -X POST -d "delete_line=0" -d "password=SuperSecretPassword" https://archuser.org/ssh/api.php`
With `delete_line=0` equating to the first line of `authorized_keys.txt`

46
api.php
View file

@ -1,15 +1,16 @@
<?php
// Configuration
$password = "SuperSecretPassword"; // Change this!
$appendFile = "data.txt";
$appendFile = "authorized_keys.txt";
// Get posted data
$inputText = $_POST['text'] ?? null;
$inputPassword = $_POST['password'] ?? null;
$deleteLine = isset($_POST['delete_line']) ? intval($_POST['delete_line']) : null;
if (!$inputText || !$inputPassword) {
if (!$inputPassword) {
http_response_code(400);
echo "Missing 'text' or 'password' parameter.";
echo "Missing 'password' parameter.";
exit;
}
@ -20,7 +21,43 @@ if ($inputPassword !== $password) {
exit;
}
// Append text to file
// Handle deletion
if ($deleteLine !== null) {
if (!file_exists($appendFile)) {
http_response_code(404);
echo "File not found.";
exit;
}
$lines = file($appendFile, FILE_IGNORE_NEW_LINES);
if ($deleteLine < 0 || $deleteLine >= count($lines)) {
http_response_code(400);
echo "Invalid line number.";
exit;
}
// Remove specified line
array_splice($lines, $deleteLine, 1);
// Save back to file
$result = file_put_contents($appendFile, implode(PHP_EOL, $lines) . PHP_EOL);
if ($result === false) {
http_response_code(500);
echo "Failed to update file.";
exit;
}
echo "Line deleted successfully.";
exit;
}
// Handle appending
if (!$inputText) {
http_response_code(400);
echo "Missing 'text' parameter for appending.";
exit;
}
$fileHandle = fopen($appendFile, "a");
if ($fileHandle === false) {
http_response_code(500);
@ -32,4 +69,3 @@ fwrite($fileHandle, $inputText . PHP_EOL);
fclose($fileHandle);
echo "Text appended successfully.";