LABEL_CREATE_ANOTHER_ACCOUNT = _('Create another DHCP entry'); $this->LABEL_BACK_TO_ACCOUNT_LIST = _('Back to DHCP list'); } /** * {@inheritDoc} */ public function getAlias(): string { return _("DHCP"); } /** * {@inheritDoc} */ public function getDescription(): string { return _("DHCP administration"); } /** * {@inheritDoc} */ public function getIcon(): string { return 'world-color.svg'; } /** * {@inheritDoc} */ public function getListClassName(): string { return lamDHCPList::class; } /** * {@inheritDoc} */ public function getDefaultListAttributes(): string { return "#cn;#dhcpRange;#fixed_ips"; } /** * {@inheritDoc} */ public function getTitleBarTitle(accountContainer $container): ?string { // get attributes $attributes = null; if ($container->getAccountModule('dhcp_settings') != null) { $attributes = $container->getAccountModule('dhcp_settings')->getAttributes(); } // check if a common name is set if (isset($attributes['cn'][0])) { return htmlspecialchars($attributes['cn'][0]); } // new entry if ($container->isNewAccount) { return _("New DHCP"); } // fall back to default return parent::getTitleBarTitle($container); } /** * {@inheritDoc} */ public function getTitleBarSubtitle(accountContainer $container): string { // get attributes $attributes = null; if ($container->getAccountModule('dhcp_settings') != null) { $attributes = $container->getAccountModule('dhcp_settings')->getAttributes(); } if ($attributes == null) { return ''; } $subtitle = ''; // check if a description can be shown if (isset($attributes['dhcpComments'][0])) { $subtitle .= htmlspecialchars($attributes['dhcpComments'][0]); } return $subtitle; } } /** * Generates the list view. * * @package lists * @author Thomas Manninger * */ class lamDHCPList extends lamList { /** * Constructor * * @param ConfiguredType $type account type */ public function __construct(ConfiguredType $type) { parent::__construct($type); $this->labels = [ 'nav' => _("DHCP count: %s"), 'error_noneFound' => _("No DHCPs found!"), 'newEntry' => _("New DHCP"), 'dhcpDefaults' => _("DHCP settings"), 'deleteEntry' => _("Delete selected DHCP entries") ]; } /** * {@inheritDoc} * @see lamList::isFilterMatching() */ protected function isFilterMatching(&$data, $filterAttribute, $regex): bool { if ($filterAttribute === "fixed_ips") { if (empty($regex)) { return true; } $entries = searchLDAP($data['dn'], 'objectClass=dhcpHost', ['dhcpstatements', 'dhcphwaddress', 'cn']); if (count($entries) > 0) { foreach ($entries as $entry) { foreach ($entry as $attrValues) { if (!is_array($attrValues)) { continue; } foreach ($attrValues as $attrValue) { if (preg_match($regex, $attrValue)) { return true; } } if (!empty($entry['dhcpstatements'])) { $ip = fixed_ip::extractIP($entry['dhcpstatements']); if (!empty($ip) && preg_match($regex, $ip)) { return true; } } } } } return false; } elseif ($filterAttribute === "dhcprange") { if (isset($data['dhcprange'])) { foreach ($data['dhcprange'] as $range) { if (preg_match($regex, $range)) { return true; } } } $pooledRanges = searchLDAP($data['dn'], '(objectclass=dhcpPool)', ['dhcprange']); foreach ($pooledRanges as $pooledRange) { if (empty($pooledRange['dhcprange'])) { continue; } foreach ($pooledRange['dhcprange'] as $range) { if (preg_match($regex, $range)) { return true; } } } } return parent::isFilterMatching($data, $filterAttribute, $regex); } /** * {@inheritDoc} */ protected function addExtraInputElementsToTopArea(&$left, &$right): void { if (checkIfWriteAccessIsAllowed($this->type->getId())) { $dhcpButton = new htmlButton('dhcpDefaults', $this->labels['dhcpDefaults']); $dhcpButton->setCSSClasses(['fullwidth-mobile-only lam-secondary']); $left->addElement($dhcpButton); } } /** * {@inheritDoc} */ protected function listDoPost(): ?htmlElement { $fragment = parent::listDoPost(); if (isset($_POST['dhcpDefaults'])) { metaRefresh("../account/edit.php?type=" . $this->type->getId() . "&DN='" . $this->type->getSuffix() . "'"); die(); } else { return $fragment; } } }