git.shiar.nl
/
sc2-widget
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
73d1bf9
)
html headers before wrapper errors
author
Mischa POSLAWSKY
<perl@shiar.org>
Wed, 22 May 2019 16:42:06 +0000
(18:42 +0200)
committer
Mischa POSLAWSKY
<perl@shiar.org>
Wed, 22 May 2019 22:00:49 +0000
(
00:00
+0200)
widget.php
patch
|
blob
|
history
diff --git
a/widget.php
b/widget.php
index e5aa32617a8872cb5f7f091c6ad9b60ebc01ba92..eec063774ea0932f227c4d48f5f02f935a82a49d 100644
(file)
--- a/
widget.php
+++ b/
widget.php
@@
-1,12
+1,30
@@
<?php
<?php
+function error($message, $status = 500)
+{
+ http_response_code($status);
+ if ($page = @fopen('widget.html', 'r')) {
+ # copy static page contents until page body
+ while (!feof($page)) {
+ print $line = fgets($page);
+ if (preg_match('/<body\b/', $line)) break;
+ }
+ }
+ else {
+ print '<html><body>';
+ }
+ print "<p>$message</p>\n";
+ print "</body>\n</html>\n";
+ exit;
+}
+
$request = trim($_SERVER['PATH_INFO'], '/');
if (!file_exists("$request.json")) {
if (!is_numeric($request)) {
$request = trim($_SERVER['PATH_INFO'], '/');
if (!file_exists("$request.json")) {
if (!is_numeric($request)) {
-
die("unknown profile request $request"
);
+
error("Unknown profile request <q>$request</q>", 400
);
}
system("./getsc2clan $request | sponge $request.json", $exitcode);
if ($exitcode) {
}
system("./getsc2clan $request | sponge $request.json", $exitcode);
if ($exitcode) {
-
die("no results for profile id $request from Blizzard"
);
+
error("No results for profile id $request from Blizzard", 503
);
}
}
require('widget.html');
}
}
require('widget.html');