Commit 5f97d7ae authored by root's avatar root

check write access

parent 82fb7471
......@@ -19,6 +19,16 @@ class InstallController extends Controller {
);
}
public function notwritableAction(Request $request) {
$im = $this->container->get('dj3c1t_app.install_manager');
return $this->render(
'Dj3c1tAppBundle:Install:notwritable.html.twig',
array(
"notWritable" => $im->checkWriteAccess(),
)
);
}
public function indexAction(Request $request) {
$im = $this->container->get('dj3c1t_app.install_manager');
if($im->isInstalled()) {
......
......@@ -2,6 +2,10 @@ install_requirements:
path: /install/requirements
defaults: { _controller: Dj3c1tAppBundle:Install:requirements }
install_notwritable:
path: /install/notwritable
defaults: { _controller: Dj3c1tAppBundle:Install:notwritable }
install:
path: /install
defaults: { _controller: Dj3c1tAppBundle:Install:index }
......
{% extends '::base.html.twig' %}
{% block header %}
{% endblock %}
{% block main %}
{{ parent() }}
{% set parametersFile = 'app/config/parameters.yml' %}
<div class="row">
<div class="col-xs-10 col-xs-offset-1">
{% if notWritable|length > 0 %}
<div class="alert alert-warning">
Certains fichiers ou dossiers ne sont pas accessibles en écriture
</div>
<p>Vérifiez que Php a le droit d'écrire dans les fichiers ou les dossiers suivant :</p>
<div class="panel panel-default">
<div class="panel-body">
<ul>
{% set parametersFileIsUnwritable = false %}
{% for file in notWritable %}
{% if file == parametersFile %}
{% set parametersFileIsUnwritable = true %}
{% endif %}
<li>{{ file }}{% if file == parametersFile %} (*){% endif %}</li>
{% endfor %}
</ul>
</div>
{% if parametersFileIsUnwritable %}
<div class="panel-footer">
<p>
(*) le fichier <strong>{{ parametersFile }}</strong>
doit être accessible en écriture au moins le temps de l'installation.
</p>
</div>
{% endif %}
</div>
<p>
<a class="btn btn-default pull-right" href="{{ path('install_notwritable') }}">
Rechargez cette page pour vérifier à nouveau
</a>
</p>
{% else %}
<div class="alert alert-success">
Les droits en écriture sur les fichiers les dossiers semblent corrects
</div>
<p>
<a class="btn btn-default pull-right" href="{{ path('homepage') }}">
Aller sur le site
</a>
</p>
{% endif %}
</div>
</div>
{% endblock %}
......@@ -18,12 +18,18 @@ use Dj3c1t\AppBundle\Entity\Role;
class InstallManager {
private $container;
protected $container;
private $parameters;
protected $parameters;
protected $rootDir;
protected $webDir;
public function __construct(Container $container) {
$this->container = $container;
$this->rootDir = dirname($this->container->get('kernel')->getRootDir());
$this->webDir = $this->container->getParameter('web_dir');
$this->parameters = array(
"database_host" => "",
"database_name" => "",
......@@ -36,6 +42,41 @@ class InstallManager {
);
}
public function isInstallRequest() {
return preg_match(
"/^install/",
$this->container->get('request_stack')->getMasterRequest()->get('_route')
);
}
public function isNotWritableRequest() {
return preg_match(
"/^install_notwritable/",
$this->container->get('request_stack')->getMasterRequest()->get('_route')
);
}
public function checkWriteAccess() {
$notWritable = array();
if(!is_writable($this->rootDir."/app/cache")) {
$notWritable[] = "app/cache";
}
if(!is_writable($this->rootDir."/app/logs")) {
$notWritable[] = "app/logs";
}
if($this->isInstallRequest() && !is_writable($this->rootDir."/app/config/parameters.yml")) {
$notWritable[] = "app/config/parameters.yml";
}
if(!is_writable($this->rootDir."/".$this->webDir)) {
$notWritable[] = $this->webDir;
}
$medias_dir = $this->rootDir."/".$this->webDir."/medias";
if(is_dir($medias_dir) && !is_writable($medias_dir)) {
$notWritable[] = $this->webDir."/medias";
}
return $notWritable;
}
public function getParameters() {
return $this->parameters;
}
......@@ -195,10 +236,9 @@ class InstallManager {
return true;
}
public function isInstallRequest() {
return preg_match(
"/^install/",
$this->container->get('request_stack')->getMasterRequest()->get('_route')
public function redirectToNotWritable() {
return new RedirectResponse(
$this->container->get('router')->generate('install_notwritable')
);
}
......
......@@ -17,6 +17,12 @@ class RequestListener {
public function onKernelRequest(GetResponseEvent $event) {
$im = $this->container->get('dj3c1t_app.install_manager');
if(!$im->isNotWritableRequest() && $im->checkWriteAccess()) {
$event->setResponse(
$im->redirectToNotWritable()
);
return;
}
if(!$im->isInstalled() && !$im->isInstallRequest()) {
$event->setResponse(
$im->redirectToInstall()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment