Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
gruberroland committed Aug 29, 2024
1 parent 51c709c commit 4db1286
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 82 deletions.
18 changes: 8 additions & 10 deletions lam/lib/modules/courierMailAccount.inc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

use LAM\TYPES\ConfiguredType;
use \LAM\TYPES\TypeManager;
use LAM\TYPES\TypeManager;

/*
* This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Expand Down Expand Up @@ -64,9 +64,7 @@ class courierMailAccount extends baseModule {
* @return boolean true if module fits
*/
public function can_manage() {
return in_array($this->get_scope(), [
'user'
]);
return $this->get_scope() === 'user';
}

/**
Expand Down Expand Up @@ -148,7 +146,7 @@ class courierMailAccount extends baseModule {
];
// profile options
$profileContainer = new htmlResponsiveRow();
$profileContainer->add(new htmlResponsiveInputCheckbox('courierMailAccount_addExt', false, _('Automatically add this extension'), 'autoAdd'), 12);
$profileContainer->add(new htmlResponsiveInputCheckbox('courierMailAccount_addExt', false, _('Automatically add this extension'), 'autoAdd'));
$return['profile_options'] = $profileContainer;
// PDF fields
$return['PDF_fields'] = [
Expand Down Expand Up @@ -291,21 +289,21 @@ class courierMailAccount extends baseModule {
$return->addField($tempTable);
// check boxes for account access control
$disableimap = isset($this->attributes['disableimap'][0]) && ($this->attributes['disableimap'][0] != 0);
$return->add(new htmlResponsiveInputCheckbox('disableimap', $disableimap, _('Disable IMAP access'), 'disableimap'), 12);
$return->add(new htmlResponsiveInputCheckbox('disableimap', $disableimap, _('Disable IMAP access'), 'disableimap'));
$disablepop3 = isset($this->attributes['disablepop3'][0]) && ($this->attributes['disablepop3'][0] != 0);
$return->add(new htmlResponsiveInputCheckbox('disablepop3', $disablepop3, _('Disable POP3 access'), 'disablepop3'), 12);
$return->add(new htmlResponsiveInputCheckbox('disablepop3', $disablepop3, _('Disable POP3 access'), 'disablepop3'));
$disablewebmail = isset($this->attributes['disablewebmail'][0]) && ($this->attributes['disablewebmail'][0] != 0);
$return->add(new htmlResponsiveInputCheckbox('disablewebmail', $disablewebmail, _('Disable webmail access'), 'disablewebmail'), 12);
$return->add(new htmlResponsiveInputCheckbox('disablewebmail', $disablewebmail, _('Disable webmail access'), 'disablewebmail'));
$disableshared = isset($this->attributes['disableshared'][0]) && ($this->attributes['disableshared'][0] != 0);
$return->add(new htmlResponsiveInputCheckbox('disableshared', $disableshared, _('Disable shared folder access'), 'disableshared'), 12);
$return->add(new htmlResponsiveInputCheckbox('disableshared', $disableshared, _('Disable shared folder access'), 'disableshared'));
// remove extension
$return->addVerticalSpacer('2rem');
$remButton = new htmlButton('remObjectClass', _('Remove Courier mail extension'));
$remButton->setCSSClasses(['lam-danger']);
$return->add($remButton, 12, 12, 12, 'text-center');
}
else {
$return->add(new htmlButton('addObjectClass', _('Add Courier mail extension')), 12);
$return->add(new htmlButton('addObjectClass', _('Add Courier mail extension')));
}
return $return;
}
Expand Down
41 changes: 20 additions & 21 deletions lam/lib/modules/ddns.inc
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class ddns extends baseModule {
* @return boolean true if module fits
*/
public function can_manage() {
return in_array($this->get_scope(), ['dhcp']);
return $this->get_scope() === 'dhcp';
}

/**
Expand Down Expand Up @@ -301,7 +301,7 @@ class ddns extends baseModule {
}

for ($i = 0; $i < sizeof($this->attributes['dhcpStatements']); $i++) {
if (substr($this->attributes['dhcpStatements'][$i], 0, 5) == 'zone ') {
if (str_starts_with($this->attributes['dhcpStatements'][$i], 'zone ')) {
unset($this->attributes['dhcpStatements'][$i]);
$this->attributes['dhcpStatements'] = array_values($this->attributes['dhcpStatements']);
$i--;
Expand Down Expand Up @@ -356,21 +356,21 @@ class ddns extends baseModule {
return $return;
}
// DHCP main settings
$return->add(new htmlResponsiveInputCheckbox('active', $this->isDynDNSActivated(), _('Activate DynDNS'), 'active'), 12);
$return->add(new htmlResponsiveInputCheckbox('insert_fixed', $this->addFixIPs(), _('Add fix IP addresses to DNS'), 'fixed_ips'), 12);
$return->add(new htmlResponsiveInputCheckbox('client_insert', $this->isIgnoreClientUpdates(), _('Disable client updates'), 'client_insert'), 12);
$return->add(new htmlResponsiveInputCheckbox('active', $this->isDynDNSActivated(), _('Activate DynDNS'), 'active'));
$return->add(new htmlResponsiveInputCheckbox('insert_fixed', $this->addFixIPs(), _('Add fix IP addresses to DNS'), 'fixed_ips'));
$return->add(new htmlResponsiveInputCheckbox('client_insert', $this->isIgnoreClientUpdates(), _('Disable client updates'), 'client_insert'));
$keyInput = new htmlResponsiveInputField(_('Path to key for DNS updates'), 'key_path', $this->getUpdateKey(), 'keypath');
$return->add($keyInput, 12);
$return->add($keyInput);
}
else {
// Account edit
if (!$this->check_if_ddns_is_enable()) {
$return->add(new htmlOutputText(_("DDNS is not activated. You can activate it in the DHCP settings (DDNS).")), 12);
$return->add(new htmlOutputText(_("DDNS is not activated. You can activate it in the DHCP settings (DDNS).")));
}
else {
// DNS server
$serverInput = new htmlResponsiveInputField(_('IP address of the DNS server'), 'ip', $this->getDNSServer(), 'dns');
$return->add($serverInput, 12);
$return->add($serverInput);

$zones = $this->getZoneNames();
$zone = '';
Expand All @@ -383,10 +383,10 @@ class ddns extends baseModule {
}
// zone name
$zoneInput = new htmlResponsiveInputField(_('Zone name'), 'zone', $zone, 'zone');
$return->add($zoneInput, 12);
$return->add($zoneInput);
// reverse zone name
$revZoneInput = new htmlResponsiveInputField(_('Reverse zone name'), 'zone_reverse', $revzone, 'zone_reverse');
$return->add($revZoneInput, 12);
$return->add($revZoneInput);
}
}

Expand Down Expand Up @@ -423,11 +423,10 @@ class ddns extends baseModule {
* @return String IP address
*/
private function getDNSServer() {
$return = null;
if (isset($this->attributes['dhcpStatements'][0])) {
for ($i = 0; $i < sizeof($this->attributes['dhcpStatements']); $i++) {
if (substr($this->attributes['dhcpStatements'][$i], 0, 5) == 'zone ') {
if (strpos($this->attributes['dhcpStatements'][$i], ' primary ') === false) {
if (str_starts_with($this->attributes['dhcpStatements'][$i], 'zone ')) {
if (!str_contains($this->attributes['dhcpStatements'][$i], ' primary ')) {
continue;
}
$parts = explode(". { primary ", $this->attributes['dhcpStatements'][$i]);
Expand All @@ -437,7 +436,7 @@ class ddns extends baseModule {
}
}
}
return $return;
return null;
}

/**
Expand All @@ -451,10 +450,10 @@ class ddns extends baseModule {
$revZone = '';
if (is_array($this->attributes['dhcpStatements'])) {
for ($i = 0; $i < sizeof($this->attributes['dhcpStatements']); $i++) {
if (substr($this->attributes['dhcpStatements'][$i], 0, 5) == 'zone ') {
if (str_starts_with($this->attributes['dhcpStatements'][$i], 'zone ')) {
$parts = explode(" ", substr($this->attributes['dhcpStatements'][$i], 5));
$value = substr(array_shift($parts), 0, -1);
if (strpos($value, 'in-addr.arpa') === false) {
if (!str_contains($value, 'in-addr.arpa')) {
$zone = $value;
}
else {
Expand Down Expand Up @@ -494,7 +493,7 @@ class ddns extends baseModule {
private function setDynDNSActivated($activated) {
if (is_array($this->attributes['dhcpStatements'])) {
for ($i = 0; $i < sizeof($this->attributes['dhcpStatements']); $i++) {
if (substr($this->attributes['dhcpStatements'][$i], 0, 18) == 'ddns-update-style ') {
if (str_starts_with($this->attributes['dhcpStatements'][$i], 'ddns-update-style ')) {
unset($this->attributes['dhcpStatements'][$i]);
$this->attributes['dhcpStatements'] = array_values($this->attributes['dhcpStatements']);
}
Expand Down Expand Up @@ -534,7 +533,7 @@ class ddns extends baseModule {
private function setFixIPs($add) {
if (is_array($this->attributes['dhcpStatements'])) {
for ($i = 0; $i < sizeof($this->attributes['dhcpStatements']); $i++) {
if (substr($this->attributes['dhcpStatements'][$i], 0, 21) == 'update-static-leases ') {
if (str_starts_with($this->attributes['dhcpStatements'][$i], 'update-static-leases ')) {
unset($this->attributes['dhcpStatements'][$i]);
$this->attributes['dhcpStatements'] = array_values($this->attributes['dhcpStatements']);
}
Expand Down Expand Up @@ -594,7 +593,7 @@ class ddns extends baseModule {
$return = null;
if (is_array($this->attributes['dhcpStatements'])) {
for ($i = 0; $i < sizeof($this->attributes['dhcpStatements']); $i++) {
if (substr($this->attributes['dhcpStatements'][$i], 0, 8) == 'include ') {
if (str_starts_with($this->attributes['dhcpStatements'][$i], 'include ')) {
$return = substr($this->attributes['dhcpStatements'][$i], 9, strlen($this->attributes['dhcpStatements'][$i]) - 10);
break;
}
Expand All @@ -613,7 +612,7 @@ class ddns extends baseModule {
$this->attributes['dhcpStatements'] = [];
}
for ($i = 0; $i < sizeof($this->attributes['dhcpStatements']); $i++) {
if (substr($this->attributes['dhcpStatements'][$i], 0, 8) == 'include ') {
if (str_starts_with($this->attributes['dhcpStatements'][$i], 'include ')) {
unset($this->attributes['dhcpStatements'][$i]);
$this->attributes['dhcpStatements'] = array_values($this->attributes['dhcpStatements']);
}
Expand Down Expand Up @@ -650,7 +649,7 @@ class ddns extends baseModule {
// principal name
if (!check_ip($rawAccounts[$i][$ids['ddns_DNSserver']])) {
$error = $this->messages['ip'][1];
array_push($error, [$i]);
$error[] = [$i];
$messages[] = $error;
}
else {
Expand Down
Loading

0 comments on commit 4db1286

Please sign in to comment.