diff --git a/plugins/addons/dashboard/class_dashBoardPasswords.inc b/plugins/addons/dashboard/class_dashBoardPasswords.inc new file mode 100644 index 0000000000000000000000000000000000000000..c498733a1c1a3d38515322fb70d38a130bdfcc1f --- /dev/null +++ b/plugins/addons/dashboard/class_dashBoardPasswords.inc @@ -0,0 +1,99 @@ +<?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' + ), + ); + } +} +?> diff --git a/plugins/addons/dashboard/class_dashBoardUsers.inc b/plugins/addons/dashboard/class_dashBoardUsers.inc index 7c524ddfd2c303a7647a823292a90626825033df..c04c61075939cb0e217cb454547702b6b9682a40 100644 --- a/plugins/addons/dashboard/class_dashBoardUsers.inc +++ b/plugins/addons/dashboard/class_dashBoardUsers.inc @@ -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"), ); } diff --git a/plugins/addons/dashboard/groups_stats.tpl b/plugins/addons/dashboard/groups_stats.tpl index 10459eadf0f2abb8f32257c3ce3baf443b04f862..f7b7b69c2d66cd6cf6cb88bc9a2ececa06046d27 100644 --- a/plugins/addons/dashboard/groups_stats.tpl +++ b/plugins/addons/dashboard/groups_stats.tpl @@ -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} diff --git a/plugins/addons/dashboard/pwd_stats.tpl b/plugins/addons/dashboard/pwd_stats.tpl new file mode 100644 index 0000000000000000000000000000000000000000..fa830389da18919a9db2e0ea6adb56c2e0979e6e --- /dev/null +++ b/plugins/addons/dashboard/pwd_stats.tpl @@ -0,0 +1,33 @@ +<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> diff --git a/plugins/addons/dashboard/users_stats.tpl b/plugins/addons/dashboard/users_stats.tpl index b158efd44a7ef0c664fc7f472f653ffb56ba4f3f..2f963bdafe6fa7375aeea037377c96f5c0a252ab 100644 --- a/plugins/addons/dashboard/users_stats.tpl +++ b/plugins/addons/dashboard/users_stats.tpl @@ -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>