Verified Commit 2235a453 authored by dockx thibault's avatar dockx thibault
Browse files

:sparkles: Feat(Dashboard) - suppression of dashboards components

Suppression of dashboard components.
Showing with 0 additions and 699 deletions
+0 -699
<?php
/*
This code is part of FusionDirectory (http://www.fusiondirectory.org)
Copyright (C) 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 dashboardOpsi extends simplePlugin
{
static function plInfo (): array
{
return [
'plShortName' => _('OPSI'),
'plDescription' => _('Statistics and information about OPSI'),
'plObjectType' => ['dashboard'],
'plProvidedAcls' => []
];
}
static function getAttributesInfo (): array
{
return [
'stats' => [
'name' => _('Statistics'),
'attrs' => [new FakeAttribute('stats')],
'template' => get_template_path('opsi_stats.tpl', TRUE, dirname(__FILE__)),
],
'profiles' => [
'name' => _('Profiles'),
'attrs' => [new FakeAttribute('profiles')],
'template' => get_template_path('opsi_profiles.tpl', TRUE, dirname(__FILE__)),
],
];
}
function __construct ($dn = NULL, $object = NULL, $parent = NULL, $mainTab = FALSE)
{
parent::__construct($dn, $object, $parent, $mainTab);
$this->stats = $this->main_stats();
$this->profiles = $this->profile_stats();
}
function main_stats ()
{
global $config;
$ldap = $config->get_ldap_link();
/* Statistics */
$stats = [
[
'name' => _('OPSI servers'),
'type' => 'server',
'filter' => '(objectClass=opsiServer)',
'img' => 'geticon.php?context=devices&icon=server&size=16'
],
[
'name' => _('OPSI clients'),
'type' => 'workstation',
'filter' => '(objectClass=opsiClient)',
'img' => 'geticon.php?context=devices&icon=computer&size=16'
],
[
'name' => _('OPSI groups'),
'type' => 'ogroup',
'filter' => '(objectClass=opsiClient)',
'img' => 'geticon.php?context=types&icon=resource-group&size=16'
],
];
foreach ($stats as &$stat) {
try {
$stat['nb'] = count(objects::ls($stat['type'], NULL, NULL, $stat['filter'], TRUE));
} catch (FusionDirectoryException $e) {
$stat['nb'] = 0;
$error = new FusionDirectoryError(
htmlescape(sprintf(
_('Statistics for OPSI could not be computed because of the following error: %s'),
$e->getMessage()
))
);
$error->display();
}
}
unset($stat);
return $stats;
}
function profile_stats ()
{
$profiles = objects::ls('opsiProfile', ['cn' => 1, 'fdOpsiServerDn' => 1, 'fdOpsiNetbootProduct' => 1, 'fdOpsiSoftwareList' => '*'], NULL, '', TRUE, 'subtree');
$id = 'profileStats';
$div = new divSelectBox('rows'.$id);
$smarty = get_smarty();
$div->setHeight(90);
$div->setHeaders([_('Profile'), _('Systems'), _('Groups')]);
foreach ($profiles as $dn => $profile) {
$fields = [
['string' => $profile['cn']],
['string' => objects::count('workstation', NULL, '(&(objectClass=opsiClient)(fdOpsiProfileDn='.$dn.'))', FALSE)],
['string' => objects::count('ogroup', NULL, '(&(objectClass=opsiClient)(fdOpsiProfileDn='.$dn.'))', FALSE)],
];
$div->addEntry($fields);
}
return $div->drawList();
}
}
<?php
/*
This code is part of FusionDirectory (http://www.fusiondirectory.org)
Copyright (C) 2014-2015 Dhatim
Copyright (C) 2014-2016 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 dashboardPpolicy extends simplePlugin
{
static function plInfo (): array
{
return [
'plShortName' => _('Ppolicy'),
'plDescription' => _('Statistics about ppolicy expired users'),
'plObjectType' => ['dashboard'],
'plPriority' => 12,
'plProvidedAcls' => []
];
}
static function getAttributesInfo (): array
{
return [
'expired_accounts' => [
'name' => _('Expired accounts'),
'attrs' => [new FakeAttribute('expired')],
'template' => get_template_path('users_accounts.tpl', TRUE, dirname(__FILE__)),
],
'locked_accounts' => [
'name' => _('Locked accounts'),
'attrs' => [new FakeAttribute('locked')],
'template' => get_template_path('ppolicy_locked_accounts.tpl', TRUE, dirname(__FILE__)),
],
];
}
function __construct ($dn = NULL, $object = NULL, $parent = NULL, $mainTab = FALSE)
{
parent::__construct($dn, $object, $parent, $mainTab);
$this->expiredAccountsColumns = [
'user' => [
'uid' => _('Login'),
'cn' => _('Name'),
'telephoneNumber' => _('Phone number'),
'expirationDate' => _('Expiration date'),
],
'manager' => [
'manager_cn' => _('Name'),
'manager_mail' => _('Email'),
'manager_phone' => _('Phone number'),
]
];
$this->compute_accounts_info();
}
function compute_accounts_info ()
{
global $config;
$ldap = $config->get_ldap_link();
$defaultMaxAge = NULL;
$ppolicydn = $config->get_cfg_value('ppolicyDefaultDn', '');
if (!empty($ppolicydn)) {
$ldap->cat($ppolicydn, ['pwdMaxAge']);
$policy = $ldap->fetch();
if (!$policy) {
$error = new SimplePluginError(
$this,
htmlescape(sprintf(
_('Default ppolicy "%s" could not be found in the LDAP!'),
$ppolicydn
))
);
$error->display();
} elseif (isset($policy['pwdMaxAge'][0])) {
$defaultMaxAge = $policy['pwdMaxAge'][0];
}
}
/* Fetch global value from configuration */
$next_expired_days = $config->get_cfg_value('dashboardExpiredAccountsDays', 15);
/* Convert it to seconds */
$next_expired_days_seconds = $next_expired_days * 24 * 60 * 60;
/* Ppolicy stores all dates in UTC */
$now = new DateTime('now', timezone::utc());
/* search all expired accounts */
$users = objects::ls('user', [
'dn' => 'raw',
'uid' => 'raw',
'cn' => 'raw',
'mail' => 'raw',
'telephoneNumber' => 'raw',
'manager' => 'raw',
'pwdChangedTime' => 1,
'pwdPolicySubentry' => 1,
'pwdAccountLockedTime' => 1,
], NULL, '(|(pwdAccountLockedTime=*)(pwdChangedTime=*))', TRUE);
$locked_users = [];
$expired_accounts = [];
$next_expired_accounts = [];
// ppolicies cache
$maxAges = [];
foreach ($users as $user) {
if (isset($user['pwdAccountLockedTime'])) {
$locked_user = dashboardUsers::get_user_infos($user);
$lockedTime = LdapGeneralizedTime::fromString($user['pwdAccountLockedTime']);
$lockedTime->setTimezone(timezone::getDefaultTimeZone());
$locked_user['pwdAccountLockedTime'] = $lockedTime->format('Y-m-d H:i:s');
$locked_users[] = $locked_user;
}
if (!isset($user['pwdChangedTime'])) {
continue;
}
$maxAge = NULL;
if (isset($user['pwdPolicySubentry'])) {
if (isset($maxAges[$user['pwdPolicySubentry']])) {
$maxAge = $maxAges[$user['pwdPolicySubentry']];
} else {
$ldap->cat($user['pwdPolicySubentry'], ['pwdMaxAge']);
$policy = $ldap->fetch();
if (!$policy) {
$error = new SimplePluginError(
$this,
htmlescape(sprintf(
_('Ppolicy "%s" set for user "%s" could not be found in the LDAP!'),
$ppolicydn,
$user['dn']
))
);
$error->display();
continue;
}
if (isset($policy['pwdMaxAge'][0])) {
$maxAge = $policy['pwdMaxAge'][0];
}
$maxAges[$user['pwdPolicySubentry']] = $maxAge;
}
} elseif ($defaultMaxAge !== NULL) {
$maxAge = $defaultMaxAge;
}
if (($maxAge === NULL) || ($maxAge <= 0)) {
/* No max age, it can’t be expired */
continue;
}
/* Build expiration date from pwdChangedTime and max age */
$expDate = LdapGeneralizedTime::fromString($user['pwdChangedTime']);
$expDate->setTimezone(timezone::utc());
$expDate->add(new DateInterval('PT'.$maxAge.'S'));
if ($expDate->getTimeStamp() < $now->getTimeStamp()) {
$expired_account = dashboardUsers::get_user_infos($user);
$expired_account['expirationDate'] = $expDate->format('d.m.Y');
$expired_accounts[] = $expired_account;
} elseif ($expDate->getTimeStamp() < ($now->getTimeStamp() + $next_expired_days_seconds)) {
$expired_account = dashboardUsers::get_user_infos($user);
$expired_account['expirationDate'] = $expDate->format('d.m.Y');
$next_expired_accounts[] = $expired_account;
}
}
uasort($expired_accounts, ['dashboardUsers','compareUsers']);
uasort($next_expired_accounts, ['dashboardUsers','compareUsers']);
$this->expired = [
'columns' => $this->expiredAccountsColumns,
'accounts' => $expired_accounts,
'accounts_next_days' => $next_expired_accounts,
'next_days' => $next_expired_days,
];
$this->locked = [
'accounts' => $locked_users,
];
}
}
<?php
/*
This code is part of FusionDirectory (http://www.fusiondirectory.org)
Copyright (C) 2010 Antoine Gallavardin
Copyright (C) 2011-2016 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 dashboardNetwork extends simplePlugin
{
static function plInfo (): array
{
return [
'plShortName' => _('Network'),
'plDescription' => _('Statistics and various information'),
'plObjectType' => ['dashboard'],
'plPriority' => 22,
'plProvidedAcls' => []
];
}
static function getAttributesInfo (): array
{
return [
'dhcp' => [
'name' => _('DHCP'),
'attrs' => [new FakeAttribute('dhcp_infos')],
'template' => get_template_path('network_dhcp.tpl', TRUE, dirname(__FILE__)),
],
'dns' => [
'name' => _('DNS'),
'attrs' => [new FakeAttribute('dns_infos')],
'template' => get_template_path('network_dhcp.tpl', TRUE, dirname(__FILE__)),
],
];
}
function __construct ($dn = NULL, $object = NULL, $parent = NULL, $mainTab = FALSE)
{
parent::__construct($dn, $object, $parent, $mainTab);
$this->dhcp_infos = $this->dhcp_infos();
if (empty($this->dhcp_infos)) {
unset($this->attributesInfo['dhcp']);
}
$this->dns_infos = $this->dns_infos();
if (empty($this->dns_infos)) {
unset($this->attributesInfo['dns']);
}
}
function dhcp_infos ()
{
global $config, $ui;
if (!class_available('dhcpService')) {
return [];
}
try {
$objects = objects::ls('server', ['cn' => 'raw', 'dhcpServiceDN' => 1], NULL, '(objectClass=dhcpServer)', TRUE);
} catch (FusionDirectoryException $e) {
$objects = [];
$error = new FusionDirectoryError(
htmlescape(sprintf(
_('Statistics for DHCP could not be computed because of the following error: %s'),
$e->getMessage()
)),
0,
$e
);
$error->display();
}
$servers = [];
foreach ($objects as $dn => $attrs) {
$zones = [];
if (strpos($ui->get_permissions($attrs['dhcpServiceDN'], 'dhcpConfiguration/dhcpSubnet', 'dhcpNetMask'), 'r') !== FALSE) {
$ldap_zone = $config->get_ldap_link();
$ldap_zone->cd($attrs['dhcpServiceDN']);
$ldap_zone->search('(objectClass=dhcpSubnet)', ['cn','dhcpNetMask']);
while ($attrs_zone = $ldap_zone->fetch()) {
$zones[] = [
'text' => $attrs_zone['cn'][0]."/".$attrs_zone['dhcpNetMask'][0]
];
}
}
$servers[] = [
'name' => $attrs['cn'][0],
'link' => objects::link($dn, 'server', 'service_serviceDHCP', $attrs, FALSE),
'zones' => $zones
];
}
return $servers;
}
function dns_infos ()
{
if (!class_available('dnsZone')) {
return [];
}
$servers = [];
$zones = objects::ls('dnsZone', ['zoneName' => 1, 'sOARecord' => 1], NULL, '', TRUE);
foreach ($zones as $zonedn => $zone) {
list ($fqdn) = explode(' ', $zone['sOARecord']);
$search = dnsManagement::findServerByFQDN($fqdn, $zonedn);
foreach ($search as $dn => $name) {
if (!isset($servers[$dn])) {
$servers[$dn] = [
'name' => $name,
'link' => objects::link($dn, 'server', 'tab_dnsHost', $name, FALSE),
'zones' => []
];
}
$servers[$dn]['zones'][] = [
'link' => objects::link($zonedn, 'dnsZone', '', $zone['zoneName'], FALSE)
];
}
}
return array_values($servers);
}
}
<?php
/*
This code is part of FusionDirectory (http://www.fusiondirectory.org)
Copyright (C) 2010 Antoine Gallavardin
Copyright (C) 2011-2016 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 dashboardSystems extends simplePlugin
{
/* default values */
var $default_start_computer_id = 0;
static function plInfo (): array
{
return [
'plShortName' => _('Systems'),
'plDescription' => _('Statistics and information about systems'),
'plObjectType' => ['dashboard'],
'plPriority' => 20,
'plProvidedAcls' => []
];
}
static function getAttributesInfo (): array
{
return [
'stats' => [
'name' => _('Statistics'),
'attrs' => [new FakeAttribute('stats')],
'template' => get_template_path('systems_stats.tpl', TRUE, dirname(__FILE__)),
],
'pc_ids' => [
'name' => _('Computer name to use by unit'),
'attrs' => [new FakeAttribute('pc_ids')],
'template' => get_template_path('systems_pcids.tpl', TRUE, dirname(__FILE__)),
],
];
}
function __construct ($dn = NULL, $object = NULL, $parent = NULL, $mainTab = FALSE)
{
parent::__construct($dn, $object, $parent, $mainTab);
$this->stats = [
'systems' => $this->systems_stats(),
'argonaut' => $this->argonaut_stats(),
];
$this->pc_ids = $this->computer_ids_rules();
}
protected function systems_stats ()
{
global $config;
$ldap = $config->get_ldap_link();
/* Statistics */
$stats = [
['name' => _('Workstations'),
'type' => 'workstation',
'img' => 'geticon.php?context=devices&icon=computer&size=16'
],
['name' => _('Servers'),
'type' => 'server',
'img' => 'geticon.php?context=devices&icon=server&size=16'
],
['name' => _('Windows Workstations'),
'type' => 'workstation',
'filter' => '(objectClass=sambaSamAccount)',
'img' => 'geticon.php?context=devices&icon=computer-windows&size=16'
],
['name' => _('Terminals'),
'type' => 'terminal',
'img' => 'geticon.php?context=devices&icon=terminal&size=16'
],
['name' => _('Printers'),
'type' => 'printer',
'img' => 'geticon.php?context=devices&icon=printer&size=16'
],
['name' => _('Phones'),
'type' => 'phone',
'img' => 'geticon.php?context=devices&icon=telephone&size=16'
],
['name' => _('Components'),
'type' => 'component',
'img' => 'geticon.php?context=devices&icon=network-device&size=16'
],
['name' => _('Mobile phones'),
'type' => 'mobilePhone',
'img' => 'geticon.php?context=devices&icon=phone&size=16'],
];
foreach ($stats as $key => &$stat) {
try {
$stat['nb'] = count(objects::ls($stat['type'], NULL, NULL, (isset($stat['filter']) ? $stat['filter'] : ''), TRUE));
if ($stat['nb'] == 0) {
unset($stats[$key]);
}
} catch (FusionDirectoryException $e) {
unset($stats[$key]);
$error = new FusionDirectoryError(
htmlescape(sprintf(
_('Statistics for type "%s" could not be computed because of the following error: %s'),
$stat['type'],
$e->getMessage()
)),
0,
$e
);
$error->display();
}
}
unset($stat);
return $stats;
}
protected function argonaut_stats ()
{
global $config, $ui;
if (!class_available('argonautServer')) {
return FALSE;
}
$argonaut_servers = objects::ls(
'server',
['cn' => 'raw','ipHostNumber' => 'raw','argonautProtocol' => 'raw','argonautPort' => 'raw'],
NULL,
'(objectClass=argonautServer)',
TRUE
);
$nb_argonaut_server = count($argonaut_servers);
$argonaut_server = [];
if ($nb_argonaut_server == 1) {
$attrs = reset($argonaut_servers);
foreach (['cn','ipHostNumber','argonautProtocol','argonautPort'] as $key) {
$argonaut_server[$key] = $attrs[$key][0];
}
$argonaut_server['link'] = objects::link(key($argonaut_servers), 'server', 'service_argonautServer', $attrs);
}
if (strpos($ui->get_permissions($config->current['BASE'], 'server/argonautClient', ''), 'r') === FALSE) {
$nb_argonaut_clients = 0;
} else {
$ldap = $config->get_ldap_link();
$ldap->cd($config->current['BASE']);
$ldap->search('(objectClass=argonautClient)', ['cn']);
$nb_argonaut_clients = $ldap->count();
}
return [
'nb_servers' => $nb_argonaut_server,
'server' => $argonaut_server,
'nb_clients' => $nb_argonaut_clients,
];
}
protected function computer_ids_rules ()
{
global $config;
$ldap = $config->get_ldap_link();
$ldap->cd($config->current['BASE']);
/* Begin of code for selecting next computer IDs
* Global variable is board_next_computer_ids_rule
* syntax is :
* 7 : nb total of digit
* LYP3 : prefix to use
* each prefix is followed by the first item flagged by an equal sign
* ex : "7;LYP0=3;LYP1=6;LYP2;LYP3"
* if to item is doned it's 0 by default
*
*/
$output_next_computer_ids = "";
$computer_ids_rules = $config->get_cfg_value('dashboardPrefix', ['PC']);
if (!is_array($computer_ids_rules)) {
$computer_ids_rules = [$computer_ids_rules];
}
$nb_digits = $config->get_cfg_value('dashboardNumberOfDigit', 3);
/* running all the table */
foreach ($computer_ids_rules as $rule) {
/* aray initialization*/
$array_complete_list = [];
$array_real_list = [];
$unused_computer_ids = [];
/* get computer ids configuration */
$config_ids = explode("=", $rule);
/* fist is is the prefix */
$prefix = $config_ids[0];
/* second (if specified) is the first item */
if (!isset($config_ids[1])) {
$start_id = $this->default_start_computer_id;
} else {
$start_id = $config_ids[1];
}
$output_next_computer_ids = $output_next_computer_ids.'<tr><th style="padding:4px;border:1px solid #BBB;">'.$prefix."</th>";
$nb_digits_suffix = $nb_digits - strlen($prefix);
/* generation of list of suffixe */
for ($d = $start_id;$d < (10 ** $nb_digits_suffix);$d++) {
/* padding : 34 on 4 digit become : 0034*/
$array_complete_list[] = str_pad($d, $nb_digits_suffix, "0", STR_PAD_LEFT);
}
/* request of all computer beginning by the prefix */
$request = '(&(cn='.$prefix.'*)(ou:dn:=systems))';
$ldap->search($request, ["cn"]);
while ($attrs = $ldap->fetch()) {
/* if a computer is a windows host, we have to delete the $ at the end */
$computer_id = str_replace("$", "", $attrs["cn"][0]);
$array_real_list[] = substr($computer_id, -$nb_digits_suffix);
}
/* make dfference between real and complete list */
$unused_computer_ids = array_diff($array_complete_list, $array_real_list);
asort($unused_computer_ids);
$unused_computer_ids = array_values($unused_computer_ids);
/* we take the 5 first */
for ($r = 0;$r <= 5;$r++) {
$output_next_computer_ids .= '<td style="padding:4px;border-bottom:1px solid #BBB;">'.$prefix.$unused_computer_ids[$r]."</td>";
}
$output_next_computer_ids .= "</tr>";
}
return $output_next_computer_ids;
}
}
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