Commit 00439845 authored by Côme Bernigaud's avatar Côme Bernigaud Committed by Benoit Mortier
Browse files

Fixes #3620 systems part of dashboard should go into systems tab

Showing with 1 addition and 444 deletions
+1 -444
<?php
/*
* This code is part of FusionDirectory (http://www.fusiondirectory.org)
* Copyright (C) 2010 Antoine Gallavardin
* Copyright (C) 2011-2013 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
{
function __construct(&$config, $dn = NULL, $object = NULL)
{
parent::__construct($config, $dn, $object);
$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()
{
if (!class_available("dhcpService")) {
return array();
}
$ldap = $this->config->get_ldap_link();
$ldap->cd($this->config->current['BASE']);
$ldap->search("(objectClass=dhcpServer)", array("cn","dhcpServiceDN"));
$servers = array();
while ($attrs = $ldap->fetch()) {
$zones = array();
$ldap_zone = $this->config->get_ldap_link();
$ldap_zone->cd($attrs['dhcpServiceDN'][0]);
$ldap_zone->search("(objectClass=dhcpSubnet)", array("cn","dhcpNetMask"));
while ($attrs_zone = $ldap_zone->fetch()) {
$zones[] = $attrs_zone['cn'][0]."/".$attrs_zone['dhcpNetMask'][0];
}
$servers[] = array(
'name' => $attrs['cn'][0],
'link' => objects::link($attrs['dn'], 'server', 'service_serviceDHCP', $attrs, FALSE),
'zones' => $zones
);
}
return $servers;
}
function dns_infos()
{
if (!class_available("DNS")) {
return array();
}
$ldap = $this->config->get_ldap_link();
$ldap->cd($this->config->current['BASE']);
$ldap->search("(&(objectClass=dNSZone)(zoneName=*))", array("dn","zoneName"));
$servers = array();
while ($attrs = $ldap->fetch()) {
$dn = preg_replace("/^zoneName=[^,]+,/", "", $attrs['dn']);
if (preg_match("/^cn=/", $dn)) {
$cn = preg_replace("/^cn=([^,]+),.*$/", "$1", $dn);
if (!isset($servers[$dn])) {
$servers[$dn] = array(
'name' => $cn,
'link' => objects::link($dn, 'server', 'service_serviceDNS', $cn, FALSE),
'zones' => array()
);
}
$servers[$dn]['zones'][$attrs['zoneName'][0]] = $attrs['zoneName'][0];
} elseif (preg_match("/^zoneName=/", $dn)) {
$reverseName = preg_replace("/^zoneName=([^,]+),.*$/", "$1", $attrs['dn']);
$zoneName = preg_replace("/^zoneName=([^,]+),.*$/", "$1", $dn);
$dn = preg_replace("/^zoneName=[^,]+,/", "", $dn);
$IP = DNS::FlipIp(str_replace(DNS::getInAddrArpa(), "", $reverseName));
for ($dots = count(explode(".", $IP));$dots < 4;$dots++) {
$IP .= ".0";
}
$servers[$dn]['zones'][$zoneName] .= " ($IP)";
}
}
return array_values($servers);
}
static function getAttributesInfo()
{
return array(
'dhcp' => array(
'name' => _('DHCP'),
'attrs' => array(new FakeAttribute('dhcp_infos')),
'template' => get_template_path('network_dhcp.tpl', TRUE, dirname(__FILE__)),
),
'dns' => array(
'name' => _('DNS'),
'attrs' => array(new FakeAttribute('dns_infos')),
'template' => get_template_path('network_dhcp.tpl', TRUE, dirname(__FILE__)),
),
);
}
/* Return plugin informations for acl handling */
static function plInfo()
{
return array(
'plShortName' => _('Network'),
'plDescription' => _('Statistics and various informations'),
'plObjectType' => array('dashboard'),
'plProvidedAcls' => array()
);
}
}
?>
<?php
/*
* This code is part of FusionDirectory (http://www.fusiondirectory.org)
* Copyright (C) 2010 Antoine Gallavardin
* Copyright (C) 2011-2013 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;
function __construct(&$config, $dn = NULL, $object = NULL)
{
parent::__construct($config, $dn, $object);
$this->stats = array(
'systems' => $this->systems_stats(),
'argonaut' => $this->argonaut_stats(),
);
$this->pc_ids = $this->computer_ids_rules();
}
function systems_stats ()
{
$ldap = $this->config->get_ldap_link();
$ldap->cd($this->config->current['BASE']);
/* Statistics */
$stats = array(
array('name' => _('Workstations'),
'filter' => 'objectClass=gotoWorkstation',
'img' => 'geticon.php?context=devices&icon=computer&size=16'),
array('name' => _('Servers'),
'filter' => 'objectClass=goServer',
'img' => 'geticon.php?context=devices&icon=server&size=16'),
array('name' => _('Windows Workstations'),
'filter' => '(&(objectClass=sambaSamAccount)(uid=*$))',
'img' => 'geticon.php?context=devices&icon=computer-windows&size=16'),
array('name' => _('Terminals'),
'filter' => 'objectClass=gotoTerminal',
'img' => 'geticon.php?context=devices&icon=terminal&size=16'),
array('name' => _('Printers'),
'filter' => 'objectClass=gotoPrinter',
'img' => 'geticon.php?context=devices&icon=printer&size=16'),
array('name' => _('Phones'),
'filter' => 'objectClass=goFonHardware',
'img' => 'geticon.php?context=devices&icon=telephone&size=16'),
array('name' => _('Components'),
'filter' => 'objectClass=ieee802Device',
'img' => 'geticon.php?context=devices&icon=network-device&size=16'),
array('name' => _('Mobile phones'),
'filter' => 'objectClass=fdMobilePhone',
'img' => 'geticon.php?context=devices&icon=phone&size=16'),
);
$ldap->cd($this->config->current['BASE']);
foreach ($stats as &$stat) {
$ldap->search($stat['filter'], array("cn"));
$stat['nb'] = $ldap->count();
}
unset($stat);
return $stats;
}
function argonaut_stats ()
{
$ldap = $this->config->get_ldap_link();
$ldap->cd($this->config->current['BASE']);
$ldap->search("(objectClass=argonautServer)", array('cn','ipHostNumber','argonautProtocol','argonautPort'));
$nb_argonaut_server = $ldap->count();
$argonaut_server = array();
if ($nb_argonaut_server == 1) {
$attrs = $ldap->fetch();
foreach (array('cn','ipHostNumber','argonautProtocol','argonautPort') as $key) {
$argonaut_server[$key] = $attrs[$key][0];
}
$argonaut_server['link'] = objects::link($attrs['dn'], 'server', 'service_serviceArgonaut', $attrs);
}
$ldap->search("(objectClass=argonautClient)", array('cn'));
$nb_argonaut_clients = $ldap->count();
return array(
'nb_servers' => $nb_argonaut_server,
'server' => $argonaut_server,
'nb_clients' => $nb_argonaut_clients,
);
}
function computer_ids_rules ()
{
$ldap = $this->config->get_ldap_link();
$ldap->cd($this->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 = $this->config->get_cfg_value('dashboardPrefix', array('PC'));
if (!is_array($computer_ids_rules)) {
$computer_ids_rules = array($computer_ids_rules);
}
/* $get_cfg_value return the OU like ou=computer .. */
$winstation_ou = mb_substr($this->config->get_cfg_value('sambaMachineAccountRDN'), 3); //FIXME use get_ou
$nb_digits = $this->config->get_cfg_value('dashboardNumberOfDigit', 3);
/* running all the table */
foreach ($computer_ids_rules as $rule) {
/* aray initialization*/
$array_complete_list = array();
$array_real_list = array();
$unused_computer_ids = array();
/* 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 < pow(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 = "(&(|(objectClass=sambaSamAccount)(objectClass=GOhard))(cn=$prefix*)(|(ou:dn:=$winstation_ou)(ou:dn:=systems)))";
$ldap->search($request, array("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;
}
static function getAttributesInfo()
{
return array(
'stats' => array(
'name' => _('Statistics'),
'attrs' => array(new FakeAttribute('stats')),
'template' => get_template_path('systems_stats.tpl', TRUE, dirname(__FILE__)),
),
'pc_ids' => array(
'name' => _('Computer name to use by unit'),
'attrs' => array(new FakeAttribute('pc_ids')),
'template' => get_template_path('systems_pcids.tpl', TRUE, dirname(__FILE__)),
),
);
}
/* Return plugin informations for acl handling */
static function plInfo()
{
return array(
'plShortName' => _('Systems'),
'plDescription' => _('Statistics and informations about systems'),
'plIcon' => 'plugins/dashboard/images/icon.png',
'plObjectType' => array('dashboard'),
'plProvidedAcls' => array()
);
}
}
?>
<div class="plugin_section">
<span class="legend">
{t}Statistics{/t}
</span>
<div>
<ul>
{foreach from=$stats item=stat}
<li style="list-style-image:url({$stat.img})">
{$stat.nb} {$stat.name}
</li>
{/foreach}
</ul>
{if $nb_argonaut_server > 1}
<img src="images/small_warning.png" style="vertical-align:middle;margin-right:3px;" alt="warning"/>{t}There are several argonaut servers! (this is not yet supported){/t}
{elseif $nb_argonaut_server == 1}
{t 1=$argonaut_server.cn 2=$argonaut_server.ipHostNumber 3=$argonaut_server.argonautProtocol 4=$argonaut_server.argonautPort}There is an argonaut server running on %1 (%3://%2:%4){/t}<br/>
{if $nb_argonaut_clients > 0}
{t count=$nb_argonaut_clients 1=$nb_argonaut_clients plural="%1 systems are configured to run an argonaut client."}Only one system is configured to run an argonaut client.{/t}<br/>
{else}
{t}But no system is configured to run an argonaut client!{/t}<br/>
{/if}
{elseif $nb_argonaut_clients > 0}
<img src="images/small_warning.png" style="vertical-align:middle;margin-right:3px;" alt="warning"/>{t count=$nb_argonaut_clients 1=$nb_argonaut_clients plural="%1 systems are configured to run an argonaut client, but there is no argonaut server configured!"}A system is configured to run an argonaut client, but there is no argonaut server configured!{/t}<br/>
{/if}
</div>
</div>
<div class="plugin_section">
<span class="legend">
{t}Computer name to use by unit{/t}
</span>
<div>
<table style="border:1px solid #B0B0B0; width:100%; vertical-align:top; text-align:left;border-spacing:0;">
{$output_next_computer_ids}
</table>
</div>
</div>
<div id="{$sectionId}" class="plugin_section">
<span class="legend">
{$section}
</span>
<div>
{foreach from=$attributes item=infos}
<ul>
{foreach from=$infos item=server}
<li style="list-style-image:url(geticon.php?context=devices&icon=server&size=16)" id="server_{$server.name}">
{$server.link}
<ul>
{foreach from=$server.zones item=zone}
<li style="list-style:disc">
{$zone}
</li>
{/foreach}
</ul>
</li>
{/foreach}
</ul>
{/foreach}
</div>
</div>
<div id="{$sectionId}" class="plugin_section">
<span class="legend">
{$section}
</span>
<div>
<table style="border-collapse:collapse; border:1px solid #B0B0B0; width:100%; vertical-align:top; text-align:left;">
{$attributes.pc_ids}
</table>
</div>
</div>
<div id="{$sectionId}" class="plugin_section">
<span class="legend">
{$section}
</span>
<div>
<ul>
{foreach from=$attributes.stats.systems item=stat}
<li style="list-style-image:url({$stat.img})">
{$stat.nb} {$stat.name}
</li>
{/foreach}
</ul>
{if $attributes.stats.argonaut.nb_servers > 1}
<img src="images/small_warning.png" style="vertical-align:middle;margin-right:3px;" alt="warning"/>{t}There are several argonaut servers! (this is not yet supported){/t}
{elseif $attributes.stats.argonaut.nb_servers == 1}
{t escape=none 1=$attributes.stats.argonaut.server.link 2=$attributes.stats.argonaut.server.ipHostNumber 3=$attributes.stats.argonaut.server.argonautProtocol 4=$attributes.stats.argonaut.server.argonautPort}There is an argonaut server running on %1 (%3://%2:%4){/t}<br/>
{if $attributes.stats.argonaut.nb_clients > 0}
{t count=$attributes.stats.argonaut.nb_clients 1=$attributes.stats.argonaut.nb_clients plural="%1 systems are configured to run an argonaut client."}Only one system is configured to run an argonaut client.{/t}<br/>
{else}
{t}But no system is configured to run an argonaut client!{/t}<br/>
{/if}
{elseif $attributes.stats.argonaut.nb_clients > 0}
<img src="images/small_warning.png" style="vertical-align:middle;margin-right:3px;" alt="warning"/>{t count=$attributes.stats.argonaut.nb_clients 1=$attributes.stats.argonaut.nb_clients plural="%1 systems are configured to run an argonaut client, but there is no argonaut server configured!"}A system is configured to run an argonaut client, but there is no argonaut server configured!{/t}<br/>
{/if}
</div>
</div>
<?php <?php
/* /*
This code is part of FusionDirectory (http://www.fusiondirectory.org/) This code is part of FusionDirectory (http://www.fusiondirectory.org/)
Copyright (C) 2003-2010 Cajus Pollmeier Copyright (C) 2003-2010 Cajus Pollmeier
...@@ -26,11 +25,8 @@ class tabs_dashboard extends tabs ...@@ -26,11 +25,8 @@ class tabs_dashboard extends tabs
function __construct($config, $data, $dn = NULL, $category = 'dashboard', $copied_object = NULL) function __construct($config, $data, $dn = NULL, $category = 'dashboard', $copied_object = NULL)
{ {
foreach ($data as $key => $infos) { foreach ($data as $key => $infos) {
if (($infos['CLASS'] == 'dashboardSystems') && (!class_available('systemManagement'))) {
unset($data[$key]);
}
if (($infos['CLASS'] == 'dashboardNetwork') && if (($infos['CLASS'] == 'dashboardNetwork') &&
(!class_available('systemManagement') || !(class_available('dhcpService') || class_available('serviceDNS')))) { !(class_available('dhcpService') || class_available('serviceDNS'))) {
unset($data[$key]); unset($data[$key]);
} }
} }
......
  • bmortier @bmortier

    mentioned in issue #1205 (closed)

    By Côme Chilliet on 2017-09-02T15:17:56 (imported from GitLab)

    ·

    mentioned in issue #1205 (closed)

    By Côme Chilliet on 2017-09-02T15:17:56 (imported from GitLab)

    Toggle commit list
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