add twig for admin setup page

This commit is contained in:
Ysolyne Gresille
2012-07-05 18:30:14 +02:00
parent ba1fe7a10a
commit ec48880c25
5 changed files with 253 additions and 363 deletions

View File

@@ -292,116 +292,6 @@ class setup
);
}
public function check_mod_auth_token()
{
$registry = registry::get_instance();
if ($registry->get('GV_h264_streaming') !== true) {
return;
}
?>
<h1>mod_auth_token configuration </h1>
<ul class="setup">
<?php
$fileName = $registry->get('GV_mod_auth_token_directory_path') . '/test_mod_auth_token.txt'; // The file to access
touch($fileName);
$url = $registry->get('GV_ServerName') . p4file::apache_tokenize($fileName);
if (http_query::getHttpCodeFromUrl($url) == 200)
echo '<li>' . _('mod_auth_token correctement configure') . '</li>';
else
echo '<li class="blocker">' . _('mod_auth_token mal configure') . '</li>';
?>
</ul>
<?php
}
public function check_apache()
{
$registry = registry::get_instance();
?>
<h2>Apache Server mods avalaibility</h2>
<p>
<?php
echo _('Attention, seul le test de l\'activation des mods est effectue, leur bon fonctionnement ne l\'est pas ')
?>
</p>
<ul id="apache_mods_checker" class="setup">
<li class="blocker">
<a href="#" onclick="check_apache_mod(this,'rewrite');return false;">mod_rewrite (required)</a>
</li>
<li class="blocker">
<a href="#" onclick="check_apache_mod(this,'xsendfile');return false;">mod_xsendfile (optionnal)</a>
<?php
if ($registry->get('GV_modxsendfile')) {
?>
<div class="infos"><img style="vertical-align:middle" src="/skins/icons/alert.png"/> <?php echo _('Attention, veuillez verifier la configuration xsendfile, actuellement activee dans le setup'); ?></div>
<?php } ?>
</li>
<li class="blocker">
<a href="#" onclick="check_apache_mod(this,'authtoken');return false;">mod_auth_token (optionnal)</a>
<?php
if ($registry->get('GV_h264_streaming')) {
?>
<div class="infos"><img style="vertical-align:middle" src="/skins/icons/alert.png"/> <?php echo _('Attention, veuillez verifier la configuration h264_streaming, actuellement activee dans le setup'); ?></div>
<?php } ?>
</li>
<li class="blocker">
<a href="#" onclick="check_apache_mod(this,'h264');return false;">mod_h264_streaming (optionnal)</a>
<?php
if ($registry->get('GV_h264_streaming')) {
?>
<div class="infos"><img style="vertical-align:middle" src="/skins/icons/alert.png"/> <?php echo _('Attention, veuillez verifier la configuration h264_streaming, actuellement activee dans le setup'); ?></div>
<?php } ?>
</li>
</ul>
<style type="text/css">
#apache_mods_checker div.infos{
display:none;
}
#apache_mods_checker .blocker div.infos{
display:block;
}
</style>
<script type="text/javascript">
$(document).ready(function(){
$('#apache_mods_checker a').trigger('click');
});
function check_apache_mod(el,mod)
{
var url = '/admin/test-';
switch (mod) {
case 'rewrite':
url += 'rewrite';
break;
case 'xsendfile':
url += 'xsendfile';
break;
case 'authtoken':
url += 'authtoken';
break;
case 'h264':
url += 'h264';
break;
}
$.get(url, function(data) {
if(data == '1')
$(el).closest('li').removeClass('blocker');
else
$(el).closest('li').addClass('blocker');
});
}
</script>
<?php
}
public static function check_phrasea()
{
@@ -541,31 +431,6 @@ class setup
return new Setup_ConstraintsIterator($constraints);
}
function check_cache_memcache()
{
$Core = \bootstrap::getCore();
echo '<h2>' . _('setup:: Serveur Memcached') . '</h2>';
echo '<ul class="setup">';
$registry = registry::get_instance();
if ($Core->getCache()->isServer()) {
$stats = $Core->getCache()->getStats();
echo '<li>' . sprintf(_('setup::Serveur actif sur %s'), $registry->get('GV_cache_server_host') . ':' . $registry->get('GV_cache_server_port')) . '</li>';
echo "<table>";
foreach ($stats as $name => $stat) {
echo "<tr class='even'><td>" . $name . "</td><td> " . $stat . "</td></tr>";
}
echo "</table>";
} else {
echo '<li class="non-blocker">' . sprintf(_('setup::Aucun serveur memcached rattache.')) . '</li>';
}
echo '</ul>';
}
public static function check_cache_opcode()
{
@@ -637,28 +502,6 @@ class setup
return new Setup_ConstraintsIterator($constraints);
}
public static function check_sphinx_search()
{
$registry = registry::get_instance();
try {
$engine = new searchEngine_adapter($registry);
$status = $engine->get_status();
echo '<h2>' . _('setup::Etat du moteur de recherche') . '</h2>';
echo '<ul class="setup">';
foreach ($status as $value) {
echo '<li>' . sprintf('%s : %s', $value[0], $value[1]) . '</li>';
}
echo '</ul>';
} catch (Exception $e) {
echo '<h2>' . _('setup::Sphinx confguration') . '</h2>';
echo '<ul class="setup">';
echo '<li class="blocker">' . $e->getMessage() . '</li>';
echo '</ul>';
}
}
/**
*

View File

@@ -0,0 +1,198 @@
{% macro board_sub_section(sub_section_title, constraints_type) %}
<h2>{{ sub_section_title }}</h2>
<ul class="setup">
{% for constraint in constraints_type %}
<li class="{% if not constraint.is_ok() %}{% if constraint.is_blocker() %}blocker{% else %}non-blocker{% endif %}{% else %}good-enough{% endif %}">
{{ constraint.get_message() }}
</li>
{% endfor %}
</ul>
{% endmacro %}
<style type="text/css">
.ui-autocomplete {
max-height: 200px;
overflow-y: auto;
/* prevent horizontal scrollbar */
overflow-x: hidden;
/* add padding to account for vertical scrollbar */
padding-right: 20px;
}
/* IE 6 doesn't support max-height
* we use height instead, but this forces the menu to always be this tall
*/
* html .ui-autocomplete {
height: 200px;
}
.ui-autocomplete-loading { background: white url('/skins/icons/ui-anim_basic_16x16.gif') right center no-repeat; }
</style>
<script type="text/javascript">
$(document).ready(function(){
var container = $('#right-ajax');
$( ".admin_adder", container ).autocomplete({
source: "/admin/users/typeahead/search/",
minLength: 2,
select: function( event, ui ) {
var form = $('#admin_adder');
$('input.new[name="admins[]"]', form).val(ui.item.id);
form.submit();
}
}).data( "autocomplete" )._renderItem = function( ul, item ) {
var email = item.email ? '<br/>'+item.email : '';
var login = item.login != item.name ? " ("+ item.login +")" : '';
return $( "<li></li>" )
.data( "item.autocomplete", item )
.append( "<a>" + item.name + login + email + "</a>" )
.appendTo( ul );
};
});
</script>
{% if cache_flushed %}
<div>
{% trans 'all caches services have been flushed' %}
</div>
{% endif %}
<div class="board_section">
<h1>{% trans 'setup:: administrateurs de l\'application' %}</h1>
<form id="admin_adder" action="sitestruct.php" method="post">
<ul>
{% for usr_id, usr_login in admins %}
<li>
<label class="checkbox" for="adm_{{ usr_id }}">
<input type="checkbox" id="adm_{{ usr_id }}" name="admins[]" value="{{ usr_id }}" checked />
{{ usr_login }}
</label>
</li>
{% endfor %}
</ul>
<label>{% trans 'setup:: ajouter un administrateur de l\'application' %} :</label>
<input class="admin_adder input-large" />
<input type="hidden" class="new" name="admins[]" />
<input type="submit" class="btn btn-warning" value="{% trans 'boutton::valider' %}" />
</form>
<h2>{% trans 'setup:: Reinitialisation des droits admins' %}</h2>
<form id="admin_reset" action="sitestruct.php" method="post">
<input type="hidden" name="sudo" value="1" />
<input type="submit" class="btn btn-warning" value="{% trans 'boutton::reinitialiser' %}" />
</form>
</div>
<div class="board_section">
<h1 style="margin-bottom: 0;">{% trans 'setup:: Reglages generaux' %}</h1>
<h2 style="margin-top: 0; font-style: italic;">{% trans 'setup::Votre configuration' %}</h2>
<div class="section_left">
<h2>{% trans 'setup::Tests d\'envois d\'emails' %}</h2>
<form id="mail_checker" method="post" action="/admin/sitestruct.php" target="_self">
<label>Email : </label><input name="email" type="text" />
<input type="submit" class="btn btn-warning" value="{% trans 'boutton::valider' %}"/>
{% if email_status %}
<p>{% trans 'result : ' %}{{ email_status }}</p>
{% endif %}
</form>
{% for constraint in php_version_constraints %}
<h2>{{ constraint.get_name() }}</h2>
<ul class="setup">
<li class="{% if constraint.is_ok() %}good-enough{% else %}blocker{% endif %}">
{{ constraint.get_message() }}
</li>
</ul>
{% endfor %}
{% set sub_section_title %}
{% trans 'setup::Filesystem configuration' %}
{% endset %}
{{ _self.board_sub_section(sub_section_title, writability_constraints) }}
{% set sub_section_title %}
{% trans 'setup::Executables' %}
{% endset %}
{{ _self.board_sub_section(sub_section_title, binaries_constraints) }}
{% set sub_section_title %}
{% trans 'setup::PHP extensions' %}
{% endset %}
{{ _self.board_sub_section(sub_section_title, php_extension_constraints) }}
{% set sub_section_title %}
{% trans 'setup::Serveur de cache' %}
{% endset %}
{{ _self.board_sub_section(sub_section_title, cache_constraints) }}
</div>
<div class="section_right">
{% set sub_section_title %}
{% trans 'Phrasea Module' %}
{% endset %}
{{ _self.board_sub_section(sub_section_title, phrasea_constraints) }}
{% set sub_section_title %}
{% trans 'setup::Serveur de cache' %}
{% endset %}
{{ _self.board_sub_section(sub_section_title, cache_opcode_constraints) }}
<h2>{% trans 'setup:: Serveur Memcached' %}</h2>
<ul class="setup">
{% if core.getCache().isServer() %}
{% set stats = core.getCache().getStats() %}
<li>{% trans 'setup::Serveur actif sur %s' %} {{registry.get('GV_cache_server_host')}} : {{registry.get('GV_cache_server_port')}}</li>
<table>
{% for name, stat in stats%}
<tr class="even"><td>{{ name }}</td><td> {{ stat }}</td></tr>
{% endfor %}
</table>
{% else %}
<li class="non-blocker">{% trans 'setup::Aucun serveur memcached rattache.' %}</li>
{% endif %}
</ul>
{% if core.getCache().isServer() %}
<form id="cache_flusher" method="post" action="sitestruct.php">
<input type="hidden" name="flush_cache" value="1"/>
<input type="submit" id="flush_button" class="btn btn-warning" value="Flush All Caches" />
</form>
{% endif %}
<h2>{% trans 'OPCode cache' %}</h2>
<ul class="setup">
{% if core['OpcodeCache'].getName() == 'array' %}
<li class="non-blocker">{% trans 'Array opcode cache is activated, but phrasea strongly recommand the use of APC or Xcache in production' %}</li>
{% else %}
<li>{{ core['OpcodeCache'].getName() }}</li>
{% endif %}
</ul>
{% if search_engine_status %}
<h2>{% trans 'setup::Etat du moteur de recherche' %}</h2>
<ul class="setup">
{% for value in search_engine_status %}
<li>{{ value[0] }} : {{ value[1] }}</li>
{% endfor %}
</ul>
{% else %}
<h2>{% trans 'setup::Sphinx confguration' %}</h2>
<ul class="setup">
<li class="blocker">{% trans 'Search Engine not available' %}</li>
</ul>
{% endif %}
{% set sub_section_title %}
{% trans 'PHP Configuration' %}
{% endset %}
{{ _self.board_sub_section(sub_section_title, php_configuration_constraints) }}
</div>
</div>

View File

@@ -15,6 +15,7 @@
*/
/* @var $Core \Alchemy\Phrasea\Core */
$Core = require_once __DIR__ . "/../../lib/bootstrap.php";
$appbox = appbox::get_instance($Core);
$session = $appbox->get_session();
$registry = $appbox->get_registry();
@@ -23,66 +24,22 @@ $usr_id = $session->get_usr_id();
phrasea::headers();
$request = http_request::getInstance();
$parm = $request->get_parms("act", "p0", "p1", 'flush_cache', 'sudo', 'admins', 'email');
$user = User_Adapter::getInstance($session->get_usr_id(), $appbox);
if ( ! $user->is_admin()) {
phrasea::headers(403);
}
$request = http_request::getInstance();
$parm = $request->get_parms("act", "p0", "p1", 'flush_cache', 'sudo', 'admins', 'email');
$cache_flushed = false;
if ($parm['flush_cache']) {
$Core = \bootstrap::getCore();
$Core['CacheService']->flushAll();
$cache_flushed = true;
}
?>
<style type="text/css">
.ui-autocomplete {
max-height: 200px;
overflow-y: auto;
/* prevent horizontal scrollbar */
overflow-x: hidden;
/* add padding to account for vertical scrollbar */
padding-right: 20px;
}
/* IE 6 doesn't support max-height
* we use height instead, but this forces the menu to always be this tall
*/
* html .ui-autocomplete {
height: 200px;
}
.ui-autocomplete-loading { background: white url('/skins/icons/ui-anim_basic_16x16.gif') right center no-repeat; }
</style>
<script type="text/javascript">
$(document).ready(function(){
var container = $('#right-ajax');
$( ".admin_adder", container ).autocomplete({
source: "/admin/users/typeahead/search/",
minLength: 2,
select: function( event, ui ) {
var form = $('#admin_adder');
$('input.new[name="admins[]"]', form).val(ui.item.id);
form.submit();
}
}).data( "autocomplete" )._renderItem = function( ul, item ) {
var email = item.email ? '<br/>'+item.email : '';
var login = item.login != item.name ? " ("+ item.login +")" : '';
return $( "<li></li>" )
.data( "item.autocomplete", item )
.append( "<a>" + item.name + login + email + "</a>" )
.appendTo( ul );
};
});
</script>
<?php
if ($parm['sudo']) {
if ($parm['sudo'] == '1') {
User_Adapter::reset_sys_admins_rights();
@@ -108,162 +65,47 @@ if ($parm['admins']) {
}
}
if ($cache_flushed) {
?>
<div>
<?php echo _('all caches services have been flushed'); ?>
</div>
<?php
try {
$engine = new searchEngine_adapter($registry);
$search_engine_status = $engine->get_status();
} catch(Exception $e) {
$search_engine_status = null;
}
?>
<div class="board_section">
<h1><?php echo _('setup:: administrateurs de l\'application') ?></h1>
<form id="admin_adder" action="sitestruct.php" method="post">
<ul>
<?php
$admins = User_Adapter::get_sys_admins();
foreach ($admins as $usr_id => $usr_login) {
?>
<li>
<label class="checkbox" for="adm_<?php echo $usr_id ?>">
<input type="checkbox" id="adm_<?php echo $usr_id ?>" name="admins[]" value="<?php echo $usr_id ?>" checked />
<?php echo $usr_login; ?>
</label>
</li>
<?php
}
?>
</ul>
<label><?php echo _('setup:: ajouter un administrateur de l\'application') ?> :</label>
<input class="admin_adder input-large" />
<input type="hidden" class="new" name="admins[]" />
<input type="submit" class="btn btn-warning" value="<?php echo _('boutton::valider') ?>" />
</form>
<h2><?php echo _('setup:: Reinitialisation des droits admins') ?></h2>
<form id="admin_reset" action="sitestruct.php" method="post">
<input type="hidden" name="sudo" value="1" />
<input type="submit" class="btn btn-warning" value="<?php echo _('boutton::reinitialiser') ?>" />
</form>
</div>
<div class="board_section">
<h1 style="margin-bottom: 0;"><?php echo _('setup:: Reglages generaux') ?></h1>
<h2 style="margin-top: 0; font-style: italic;"><?php echo _('setup::Votre configuration') ?></h2>
<div class="section_left">
<h2><?php echo _('setup::Tests d\'envois d\'emails'); ?></h2>
<form id="mail_checker" method="post" action="/admin/sitestruct.php" target="_self">
<label>Email : </label><input name="email" type="text" />
<input type="submit" class="btn btn-warning" value="<?php echo _('boutton::valider'); ?>"/>
</form>
<?php
$php_version_constraints = setup::check_php_version();
$writability_constraints = setup::check_writability($registry);
$binaries_constraints = setup::check_binaries($registry);
$php_extension_constraints = setup::check_php_extension();
$cache_constraints = setup::check_cache_server();
$phrasea_constraints = setup::check_phrasea();
$cache_opcode_constraints = setup::check_cache_opcode();
$php_configuration_constraints = setup::check_php_configuration();
$email_status = null;
if ($parm['email']) {
echo 'result : ';
var_dump(mail::mail_test($parm['email']));
}
$php_constraints = setup::check_php_version();
foreach ($php_constraints as $php_constraint) {
echo '<h2>' . $php_constraint->get_name() . '</h2>';
echo '<ul class="setup">';
?>
<li class="<?php echo $php_constraint->is_ok() ? 'good-enough' : 'blocker'; ?>">
<?php echo $php_constraint->get_message(); ?>
</li>
<?php
echo '</ul>';
}
$php_constraints = setup::check_writability($registry);
echo '<h2>' . _('setup::Filesystem configuration') . '</h2>';
echo '<ul class="setup">';
foreach ($php_constraints as $constraint) {
?>
<li class="<?php echo ! $constraint->is_ok() ? ($constraint->is_blocker() ? 'blocker' : 'non-blocker') : 'good-enough'; ?>">
<?php echo $constraint->get_message(); ?>
</li>
<?php
}
echo '</ul>';
$php_constraints = setup::check_binaries($registry);
echo '<h2>' . _('setup::Executables') . '</h2>';
echo '<ul class="setup">';
foreach ($php_constraints as $constraint) {
?>
<li class="<?php echo ! $constraint->is_ok() ? ($constraint->is_blocker() ? 'blocker' : 'non-blocker') : 'good-enough'; ?>">
<?php echo $constraint->get_message(); ?>
</li>
<?php
}
echo '</ul>';
$php_constraints = setup::check_php_extension();
echo '<h2>' . _('setup::PHP extensions') . '</h2>';
echo '<ul class="setup">';
foreach ($php_constraints as $constraint) {
?>
<li class="<?php echo ! $constraint->is_ok() ? ($constraint->is_blocker() ? 'blocker' : 'non-blocker') : 'good-enough'; ?>">
<?php echo $constraint->get_message(); ?>
</li>
<?php
}
echo '</ul>';
$php_constraints = setup::check_cache_server();
echo '<h2>' . _('setup::Serveur de cache') . '</h2>';
echo '<ul class="setup">';
foreach ($php_constraints as $constraint) {
?>
<li class="<?php echo ! $constraint->is_ok() ? ($constraint->is_blocker() ? 'blocker' : 'non-blocker') : 'good-enough'; ?>">
<?php echo $constraint->get_message(); ?>
</li>
<?php
}
echo '</ul>';
?>
</div>
<div class="section_right">
<?php
$php_constraints = setup::check_phrasea();
echo '<h2>' . _('Phrasea Module') . '</h2>';
echo '<ul class="setup">';
foreach ($php_constraints as $constraint) {
?>
<li class="<?php echo ! $constraint->is_ok() ? ($constraint->is_blocker() ? 'blocker' : 'non-blocker') : 'good-enough'; ?>">
<?php echo $constraint->get_message(); ?>
</li>
<?php
}
echo '</ul>';
setup::check_apache();
setup::check_mod_auth_token();
setup::check_cache_opcode();
setup::check_cache_memcache();
if ($Core->getCache()->isServer()) {
?>
<form id="cache_flusher" method="post" action="sitestruct.php">
<input type="hidden" name="flush_cache" value="1"/>
<input type="submit" id="flush_button" class="btn btn-warning" value="Flush All Caches" />
</form>
<?php
}
echo '<h2>' . _('OPCode cache') . '</h2>';
echo '<ul class="setup">';
if ($Core['OpcodeCache']->getName() == 'array') {
echo '<li class="non-blocker">' . _('Array opcode cache is activated, but phrasea strongly recommand the use of APC or Xcache in production') . '</li>';
if(mail::mail_test($parm['email'])) {
$email_status = _('Mail sent');
} else {
echo '<li>' . $Core['OpcodeCache']->getName() . '</li>';
$email_status = _('Could not send email');
}
}
echo '</ul>';
setup::check_sphinx_search();
setup::check_php_configuration();
?>
</div>
$parameters = array(
'cache_flushed' => $cache_flushed,
'admins' => User_Adapter::get_sys_admins(),
'email_status' => $email_status,
'search_engine_status' => $search_engine_status,
'php_version_constraints' => $php_version_constraints,
'writability_constraints' => $writability_constraints,
'binaries_constraints' => $binaries_constraints,
'php_extension_constraints' => $php_extension_constraints,
'cache_constraints' => $cache_constraints,
'phrasea_constraints' => $phrasea_constraints,
'cache_opcode_constraints' => $cache_opcode_constraints,
'php_configuration_constraints' => $php_configuration_constraints,
);
</div>
$Core['Twig']->display('admin/dashboard.html.twig', $parameters);
return;

View File

@@ -208,8 +208,9 @@ div.switch_right.unchecked {
.board_section {
margin: 0 0 30px;
}
.board_section ul {
margin: 0 0 15px 15px;
.board_section ul,
.board_section #mail_checker {
margin: 0 0 20px 15px;
}
.board_section div[class^="section_"] {
width: 400px;
@@ -238,6 +239,9 @@ div.switch_right.unchecked {
.board_section div[class^="section_"] ul.setup li:hover {
background-color: #fffbcd;
}
.board_section div[class^="section_"] #cache_flusher {
margin: -10px 0 20px 0;
}
.board_section .section_left {
float: left;
}

View File

@@ -251,8 +251,8 @@ div.switch_right {
.board_section {
margin: 0 0 30px;
ul {
margin: 0 0 15px 15px;
ul, #mail_checker {
margin: 0 0 20px 15px;
}
div[class^="section_"] {
width: 400px;
@@ -280,6 +280,9 @@ div.switch_right {
}
}
}
#cache_flusher {
margin: -10px 0 20px 0;
}
}
.section_left {
float: left;