Skip to content
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
4 changes: 4 additions & 0 deletions config.php.example
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@

const PUBSUB_SERVER = "wss://pubsub:8080";

// Token / key that needs to be in the request to fetch the pod
// count from the storage api
const POD_COUNT_KEY = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";

// Array of IPs that can be trusted. If they are in this list, they
// won't be locked out after failed login attempts;
const TRUSTED_IPS = [];
Expand Down
26 changes: 26 additions & 0 deletions lib/Routes/SolidStorageProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,31 @@ public static function respondToStorageNew() {
header("Content-type: application/json");
echo json_encode($responseData, JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR);
}

public static function respondToPodCount() {
$requestFactory = new ServerRequestFactory();
$rawRequest = $requestFactory->fromGlobals($_SERVER, $_GET, $_POST, $_COOKIE, $_FILES);

if (!defined('POD_COUNT_KEY')) {
header("HTTP/1.1 404 Not found");
exit();
}
if (!isset($_SERVER['HTTP_POD_COUNT_KEY'])) {
header("HTTP/1.1 404 Not found");
exit();
}
if ($_SERVER['HTTP_POD_COUNT_KEY'] !== POD_COUNT_KEY) {
header("HTTP/1.1 400 Bad Request");
exit();
}

$podCount = StorageServer::getPodCount();
$responseData = array(
"count" => $podCount
);
header("HTTP/1.1 200 OK");
header("Content-type: application/json");
echo json_encode($responseData, JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR);
}
}

14 changes: 14 additions & 0 deletions lib/StorageServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,20 @@ public static function createStorage($ownerWebId) {
];
}

public static function getPodCount() {
Db::connect();
$query = Db::$pdo->prepare(
'SELECT count(storage_id) as podCount FROM storage'
);
$query->execute();
$result = $query->fetchAll();

if (sizeof($result) === 1) {
return $result[0]['podCount'];
}
return false;
}

public static function storageIdExists($storageId) {
Db::connect();
$query = Db::$pdo->prepare(
Expand Down
4 changes: 4 additions & 0 deletions www/storage/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
switch($method) {
case "GET":
switch ($request) {
case "/api/podcount":
case "/api/podcount/":
SolidStorageProvider::respondToPodCount();
break;
default:
header($_SERVER['SERVER_PROTOCOL'] . " 404 Not found");
break;
Expand Down
Loading