Commit a97234d6 authored by Côme Chilliet's avatar Côme Chilliet
Browse files

Fixes #5271 Added a Password tab to dashboard listing used password methods

parent 60575034
<?php
/*
This code is part of FusionDirectory (http://www.fusiondirectory.org)
Copyright (C) 2016-2017 FusionDirectory project
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/
class dashboardPassword extends simplePlugin
{
static function plInfo()
{
return array(
'plShortName' => _('Passwords'),
'plDescription' => _('Statistics about passwords'),
'plObjectType' => array('dashboard'),
'plProvidedAcls' => array()
);
}
static function getAttributesInfo()
{
return array(
'pwds' => array(
'name' => _('Passwords statistics'),
'attrs' => array(new FakeAttribute('pwds_stats')),
'template' => get_template_path('pwd_stats.tpl', TRUE, dirname(__FILE__)),
),
);
}
function __construct ($dn = NULL, $object = NULL, $parent = NULL, $mainTab = FALSE)
{
parent::__construct($dn, $object, $parent, $mainTab);
$this->pwds_stats = $this->computeStats();
}
function computeStats ()
{
global $config;
$defaultMethod = $config->get_cfg_value('passwordDefaultHash', 'ssha');
$forceDefault = ($config->get_cfg_value('forcePasswordDefaultHash', 'FALSE') == 'TRUE');
$users = objects::ls('user', 'userPassword');
$nb_accounts = count($users);
$nb_locked_accounts = 0;
$methods_stats = array();
foreach ($users as $dn => $userPassword) {
if (!empty($userPassword)) {
if (preg_match("/^\{[^\}]+\}!/", $userPassword)) {
$nb_locked_accounts++;
}
$method = passwordMethod::get_method($userPassword);
$methodClass = get_class($method);
if (!isset($methods_stats[$methodClass])) {
$methods_stats[$methodClass] = array(
'nb' => 0,
'name' => $method->get_hash()
);
if ($method->get_hash() == $defaultMethod) {
$methods_stats[$methodClass]['style'] = 'default';
} elseif ($method->get_hash() == 'clear') {
$methods_stats[$methodClass]['style'] = 'clear';
} elseif ($forceDefault) {
$methods_stats[$methodClass]['style'] = 'forbidden';
} else {
$methods_stats[$methodClass]['style'] = 'none';
}
}
$methods_stats[$methodClass]['nb']++;
}
}
return array(
'methods' => $methods_stats,
'nb' => $nb_accounts,
'img' => 'geticon.php?context=types&icon=user&size=16',
'locked_accounts' => array(
'nb' => $nb_locked_accounts,
'img' => 'geticon.php?context=status&icon=object-locked&size=16'
),
);
}
}
?>
......@@ -66,18 +66,10 @@ class dashboardUsers extends simplePlugin
{
global $config;
/* User statistics */
$nb_accounts = objects::count('user');
$ldap = $config->get_ldap_link();
$ldap->cd($config->current['BASE']);
$ldap->search('(objectClass=inetOrgPerson)', array('userPassword'));
$nb_accounts = $ldap->count();
$nb_locked_accounts = 0;
while ($attrs = $ldap->fetch()) {
if (isset($attrs['userPassword'][0]) && preg_match("/^\{[^\}]/", $attrs['userPassword'][0])) {
if (preg_match("/^[^\}]*+\}!/", $attrs['userPassword'][0])) {
$nb_locked_accounts++;
}
}
}
$ldap->search('(&(objectClass=inetOrgPerson)(objectClass=gosaMailAccount))', array('cn'));
$nb_mail_accounts = $ldap->count();
$ldap->search('(&(objectClass=inetOrgPerson)(objectClass=posixAccount))', array('cn'));
......@@ -93,7 +85,6 @@ class dashboardUsers extends simplePlugin
),
'nb' => $nb_accounts,
'img' => 'geticon.php?context=types&icon=user&size=16',
'locked_accounts' => array('nb' => $nb_locked_accounts, 'img' => "geticon.php?context=status&icon=object-locked&size=16"),
);
}
......
......@@ -7,7 +7,7 @@
{t count=$attributes.groups_stats.nb 1=$attributes.groups_stats.nb plural="There are %1 groups:"}There is 1 group:{/t}
<ul>
{foreach from=$attributes.groups_stats.groups item=g}
<li style="list-style-image:url({$g.img})">
<li style="list-style-image:url({$g.img|escape})">
{if $g.nb > 0}
{t count=$g.nb 1=$g.name 2=$g.nb plural="%2 are %1 groups"}One of them is a %1 group{/t}
{else}
......
<div id="{$sectionId}" class="plugin-section">
<span class="legend">
{$section}
</span>
<div>
<img src="{$attributes.pwds_stats.img|escape}" alt="user icon"/>
{t count=$attributes.pwds_stats.nb 1=$attributes.pwds_stats.nb plural="There are %1 users:"}There is 1 user:{/t}
<ul>
{foreach from=$attributes.pwds_stats.methods item=method}
{if $method.nb > 0}
{if $method.style == "default"}
<li style="color:green;">
{elseif $method.style == "clear"}
<li style="color:red;">
{elseif $method.style == "forbidden"}
<li style="color:red;">
{else}
<li>
{/if}
{t count=$method.nb 1=$method.name 2=$method.nb plural="%2 of them use %1 method"}One of them use %1 method{/t}
</li>
{/if}
{/foreach}
<li style="list-style-image:url({$attributes.pwds_stats.locked_accounts.img|escape})">
{if $attributes.pwds_stats.locked_accounts.nb > 0}
{t count=$attributes.pwds_stats.locked_accounts.nb 1=$attributes.pwds_stats.locked_accounts.nb plural="%1 of them are locked"}One of them is locked{/t}
{else}
{t}None of them is locked{/t}
{/if}
</li>
</ul>
</div>
</div>
......@@ -7,7 +7,7 @@
{t count=$attributes.users_stats.nb 1=$attributes.users_stats.nb plural="There are %1 users:"}There is 1 user:{/t}
<ul>
{foreach from=$attributes.users_stats.accounts item=acc}
<li style="list-style-image:url({$acc.img})">
<li style="list-style-image:url({$acc.img|escape})">
{if $acc.nb > 0}
{t count=$acc.nb 1=$acc.name 2=$acc.nb plural="%2 of them have a %1 account"}One of them have a %1 account{/t}
{else}
......@@ -15,13 +15,6 @@
{/if}
</li>
{/foreach}
<li style="list-style-image:url({$attributes.users_stats.locked_accounts.img})">
{if $attributes.users_stats.locked_accounts.nb > 0}
{t count=$attributes.users_stats.locked_accounts.nb 1=$attributes.users_stats.locked_accounts.nb plural="%1 of them are locked"}One of them is locked{/t}
{else}
{t}None of them is locked{/t}
{/if}
</li>
</ul>
</div>
</div>
Supports Markdown
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