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

<?php
namespace Sandpiper\Actions;
class Setup 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]);
}
}