Merge pull request #3106 from tractorcow/pulls/3.0/path-checking

Path resolution cleanup
This commit is contained in:
Ingo Schommer 2014-05-07 08:39:17 +12:00
commit ea1a0d16fc

View File

@ -184,25 +184,16 @@ class DevelopmentAdmin extends Controller {
public function generatesecuretoken() { public function generatesecuretoken() {
$generator = Injector::inst()->create('RandomGenerator'); $generator = Injector::inst()->create('RandomGenerator');
$token = $generator->randomToken('sha1'); $token = $generator->randomToken('sha1');
$body = <<<TXT
Generated new token. Please add the following code to your YAML configuration:
$path = $this->request->getVar('path'); Security:
if($path) { token: $token
if(file_exists(BASE_PATH . '/' . $path)) {
echo sprintf( TXT;
"Configuration file '%s' exists, can't merge. Please choose a new file.\n", $response = new SS_HTTPResponse($body);
BASE_PATH . '/' . $path $response->addHeader('Content-Type', 'text/plain');
); return $response;
exit(1);
}
$yml = "Security:\n token: $token";
Filesystem::makeFolder(dirname(BASE_PATH . '/' . $path));
file_put_contents(BASE_PATH . '/' . $path, $yml);
echo "Configured token in $path\n";
} else {
echo "Generated new token. Please add the following code to your YAML configuration:\n\n";
echo "Security:\n";
echo " token: $token\n";
}
} }
public function reset() { public function reset() {