This repository has been archived on 2019-06-21. You can view files and clone it, but cannot push or open issues or pull requests.
sandpiper/Actions/Setup.php

33 lines
761 B
PHP
Raw Permalink Normal View History

2018-03-09 16:51:04 +00:00
<?php
namespace Sandpiper\Actions;
2018-03-09 23:08:00 +00:00
class Setup extends \Sandpiper\AbstractAction
2018-03-09 16:51:04 +00:00
{
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]);
}
}