diff --git a/common.php b/common.php index aa1fbd7..833fab7 100644 --- a/common.php +++ b/common.php @@ -203,6 +203,45 @@ function gracefuldeath_html($error) { echo "ERROR: " . $error; } +function gracefuldeath_httpcode($code) { + $explanation = "An error has occured on the server and the request could not be processed"; + if (!isset($code)) + $code = 404; + switch($code) { + case 400: + $code = "400 Bad Request"; + $explanation = "The request was missing a required parameter and could not be processed"; + break; + case 404: + $code = "404 Not Found"; + $explanation = "The requested resource was not found or never existed"; + break; + case 410: + $code = "410 Gone"; + $explanation = "The requested content does not exist, it may have expired, been deleted, or you may have an out-of-date link"; + break; + case 417: + $code = "417 Expectation Failed"; + $explanation = "The user specified in the request was not found or never existed"; + break; + } + header($_SERVER["SERVER_PROTOCOL"] . $code); + echo "
"; + echo ""; + echo "HTTP error: " . $code . " | ";
+ echo "
" . $explanation . "
";
+ echo "Go Home";
+ echo "";
+ die;
+}
+
function gracefuldeath_later($message) {
global $error_message;
$error_message = $message;
diff --git a/download.php b/download.php
index 8010e34..5ad0113 100644
--- a/download.php
+++ b/download.php
@@ -5,7 +5,7 @@ include("common.php");
$sharehandle = $_SERVER['QUERY_STRING'];
if (!isset($sharehandle) || $sharehandle == "")
- gracefuldeath_html("content request not specified!");
+ gracefuldeath_httpcode(400);
//handle Facebook
if (strpos($sharehandle, "&fbclid")) {
@@ -20,17 +20,18 @@ if (count($shareparts) > 1) {
$contentid = $shareparts[1];
if (!is_dir("data/" . $username)) {
- gracefuldeath_html("user does not exist!");
+ gracefuldeath_httpcode(417);
}
//Make sure the file exists and can be loaded
- $jsondata = get_share_data($username, $config['readonlykey'], 'gracefuldeath_html');
+ $jsondata = get_share_data($username, $config['readonlykey'], 'gracefuldeath_httpcode');
+ $found = false;
foreach ($jsondata['shares'] as $share => $value) {
//print_r($value);
if ($contentid == $value['guid'])
{
-
- $client = strtolower($_SERVER['HTTP_USER_AGENT']);
+ $found = true;
+ $client = strtolower($_SERVER['HTTP_USER_AGENT']);
if (strpos($client, "hpwos") || strpos($client, "webos") || strpos($client, "android")) {
echo '';
} else {
@@ -46,8 +47,11 @@ if (count($shareparts) > 1) {
}
}
}
+ if (!$found) {
+ gracefuldeath_httpcode(410);
+ }
} else {
- gracefuldeath_html("content request malformed!");
+ gracefuldeath_httpcode(400);
}
?>
diff --git a/i.php b/i.php
index cc16fce..ae17e4d 100644
--- a/i.php
+++ b/i.php
@@ -3,7 +3,7 @@
// This endpoint supports returning the binary data of an image share that can be the source of an HTML img element
include("common.php");
-if (isset($_GET["size"]))
+if (isset($_GET["size"])) //TODO: Accepted but not used at this time
$imgSize = $_GET["size"];
if (isset($_GET['img']) && $_GET['img'] != "") {
$sharehandle = $_GET['img'];
@@ -12,8 +12,7 @@ if (isset($_GET['img']) && $_GET['img'] != "") {
$sharehandle = $_SERVER['QUERY_STRING'];
}
if (!isset($sharehandle)) { //Deal with no usable request
- header($_SERVER["SERVER_PROTOCOL"] . " 400 Bad Request");
- die;
+ gracefuldeath_httpcode(400);
}
$sharehandle = base64url_decode($sharehandle);
@@ -23,22 +22,27 @@ if (count($shareparts) > 1) {
$contentid = $shareparts[1];
if (!is_dir("data/" . $username)) {
- gracefuldeath_html("user does not exist!");
+ gracefuldeath_httpcode(417);
}
//Make sure the file exists and can be loaded
- $jsondata = get_share_data($username, $config['readonlykey'], 'gracefuldeath_html');
+ $jsondata = get_share_data($username, $config['readonlykey'], 'gracefuldeath_httpcode');
+ $found = false;
foreach ($jsondata['shares'] as $share => $value) {
//print_r($value);
if ($contentid == $value['guid'])
{
+ $found = true;
header('Content-Type '. $value['contenttype']);
$fp = fopen($value['content'], 'rb');
fpassthru($fp);
}
}
+ if (!$found) {
+ gracefuldeath_httpcode(410);
+ }
} else {
- gracefuldeath_html("content request malformed!");
+ gracefuldeath_httpcode(400);
}
?>
diff --git a/index.php b/index.php
index 1743d2b..ad5cf8c 100644
--- a/index.php
+++ b/index.php
@@ -20,7 +20,7 @@
//Show appropriate instructions for platform
$client = strtolower($_SERVER['HTTP_USER_AGENT']);
if (strpos($client, "hpwos") || strpos($client, "webos")) {
- echo "Welcome webOS User! This sharing service was made for you in mind, but the web front-end doesn't work on your current device. Instead, you can download the native webOS App called Share Space, that works on Touchpad, Pre and all the other webOS phones!";
+ echo "Welcome webOS User! This sharing service was made with you in mind, but this web front-end doesn't work on your current device. Instead, you can download the native webOS App called Share Space, that works on Touchpad, Pre and all the other webOS phones!";
} else {
echo "The Share Service is a file sharing web app for retro devices -- but it works with modern devices too! You can create an account where you can share pictures or text with others, or they can share with you!";
}
diff --git a/ithumb.php b/ithumb.php
index 46ca06c..4f4a735 100644
--- a/ithumb.php
+++ b/ithumb.php
@@ -15,8 +15,7 @@ if (isset($_GET['itemid']) && $_GET['itemid'] != "") {
$itemid = $_SERVER['QUERY_STRING'];
}
if (!isset($itemid)) { //Deal with no usable request
- header($_SERVER["SERVER_PROTOCOL"] . " 400 Bad Request");
- die;
+ gracefuldeath_httpcode(400);
}
$sharehandle = base64url_decode($itemid);
@@ -26,14 +25,16 @@ if (count($shareparts) > 1) {
$contentid = $shareparts[1];
if (!is_dir("data/" . $username)) {
- gracefuldeath_html("user does not exist!");
+ gracefuldeath_httpcode(417);
}
//Make sure the file exists and can be loaded
- $jsondata = get_share_data($username, $config['readonlykey'], 'gracefuldeath_html');
+ $jsondata = get_share_data($username, $config['readonlykey'], 'gracefuldeath_httpcode');
+ $found = false;
foreach ($jsondata['shares'] as $share => $value) {
if ($contentid == $value['guid'])
{
+ $found = true;
//Prepare the cache name
$cacheID = "thumb-" . $value['guid'];
$path = "data/" . $username;
@@ -54,9 +55,12 @@ if (count($shareparts) > 1) {
exit;
}
}
+ if (!$found) {
+ gracefuldeath_httpcode(410);
+ }
} else {
- gracefuldeath_html("content request malformed!");
+ gracefuldeath_httpcode(400);
}
//Function to resize common image formats
diff --git a/t.php b/t.php
index 790c9aa..deb072f 100644
--- a/t.php
+++ b/t.php
@@ -5,7 +5,7 @@ include("common.php");
$sharehandle = $_SERVER['QUERY_STRING'];
if (!isset($sharehandle) || $sharehandle == "")
- graceful_death("content request not specified!");
+ gracefuldeath_httpcode(400);
if (strpos($sharehandle, "&fbclid")) {
$sharehandle = str_replace("%3D", "=", $sharehandle);
@@ -20,15 +20,17 @@ if (count($shareparts) > 1) {
$contentid = $shareparts[1];
if (!is_dir("data/" . $username)) {
- gracefuldeath_html("user does not exist!");
+ gracefuldeath_httpcode(417);
}
//Make sure the file exists and can be loaded
- $jsondata = get_share_data($username, $config['readonlykey'], 'gracefuldeath_html');
+ $jsondata = get_share_data($username, $config['readonlykey'], 'gracefuldeath_httpcode');
+ $found = false;
foreach ($jsondata['shares'] as $share => $value) {
//print_r($value);
if ($contentid == $value['guid'])
{
+ $found = true;
if ($value['contenttype'] == "application/json") {
header('Content-Type: application/json');
print_r(json_encode($value['content'], JSON_PRETTY_PRINT));
@@ -39,9 +41,12 @@ if (count($shareparts) > 1) {
}
}
}
+ if (!$found) {
+ gracefuldeath_httpcode(410);
+ }
} else {
- gracefuldeath_html("content request malformed!");
+ gracefuldeath_httpcode(400);
}
diff --git a/tthumb.php b/tthumb.php
index 58a2a0e..8ba2406 100644
--- a/tthumb.php
+++ b/tthumb.php
@@ -1,7 +1,6 @@
1) {
$contentid = $shareparts[1];
if (!is_dir("data/" . $username)) {
- gracefuldeath_html("user does not exist!");
+ gracefuldeath_httpcode(417);
}
//Make sure the file exists and can be loaded
- $jsondata = get_share_data($username, $config['readonlykey'], 'gracefuldeath_html');
+ $jsondata = get_share_data($username, $config['readonlykey'], 'gracefuldeath_httpcode');
+ $found = false;
foreach ($jsondata['shares'] as $share => $value) {
if ($contentid == $value['guid'])
{
+ $found = true;
if ($value['contenttype'] == "application/json") {
$usetext = json_encode($value['content']);
}
@@ -64,9 +64,12 @@ if (count($shareparts) > 1) {
}
}
}
+ if (!$found) {
+ gracefuldeath_httpcode(410);
+ }
} else {
- gracefuldeath_html("content request malformed!");
+ gracefuldeath_httpcode(400);
}
//Function to make an image square out of text