Add setup checker
This commit is contained in:
parent
ea1534a50e
commit
04b63eb281
1 changed files with 32 additions and 0 deletions
32
Actions/Setup.php
Normal file
32
Actions/Setup.php
Normal 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]);
|
||||
}
|
||||
}
|
Reference in a new issue