Add setup checker

This commit is contained in:
Starbeamrainbowlabs 2018-03-09 16:51:04 +00:00
parent ea1534a50e
commit 04b63eb281
Signed by: sbrl
GPG Key ID: 1BE5172E637709C2
1 changed files with 32 additions and 0 deletions

32
Actions/Setup.php Normal file
View File

@ -0,0 +1,32 @@
<?php
namespace Sandpiper\Actions;
class index extends \Sandpiper\AbstractAction
{
public function __construct()
{
}
public function handle() {
global $settings;
$uri_root = dirname("http://" . $_SERVER["HTTP_HOST"] . $_SERVER["SCRIPT_NAME"]);
$toml_response_code = $this->get_response_code("$uri_root/settings.toml");
if($toml_response_code >= 200 && $toml_response_code < 300)
send_error(503, "Error: The settings file is visible from the web!");
header("content-type: text/plain");
exit("Your setup looks ok :-)");
}
protected function get_response_code($url) {
stream_context_set_default([ 'http' => [ 'method' => 'HEAD' ] ]);
$headers = get_headers($url);
return intval(explode(" ", $headers[0])[1]);
}
}