spell checking

This commit is contained in:
Roland Gruber 2020-03-04 12:02:14 +01:00
parent 8894146c06
commit 51ed41f4fa
2 changed files with 26 additions and 27 deletions

View File

@ -13,6 +13,6 @@ script:
- phpunit - phpunit
- ls -l code-coverage/* - ls -l code-coverage/*
- sonar-scanner - sonar-scanner
- pip install codespell - pip install --user codespell
- cd lam - cd lam
- ./codespell.sh - ./codespell.sh

View File

@ -3,11 +3,10 @@ use \LAM\PDF\PDFTable;
use \LAM\PDF\PDFTableCell; use \LAM\PDF\PDFTableCell;
use \LAM\PDF\PDFTableRow; use \LAM\PDF\PDFTableRow;
/* /*
$Id$
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2008 Thomas Manninger Copyright (C) 2008 Thomas Manninger
2008 - 2018 Roland Gruber 2008 - 2020 Roland Gruber
This program is free software; you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
@ -49,11 +48,11 @@ class range extends baseModule {
/** ranges */ /** ranges */
public $ranges; public $ranges;
/** Range -> Function attibute_processed already running? */ /** Range -> Function attribute_processed already running? */
public $processed; public $processed;
/** For check, if IPs overlaped. */ /** For check, if IPs overlapped. */
public $overlaped; private $overlapped;
/** list of pools that currently exist in LDAP */ /** list of pools that currently exist in LDAP */
private $poolsOrig = array(); private $poolsOrig = array();
@ -135,8 +134,8 @@ class range extends baseModule {
* This function fills the error message array with messages. * This function fills the error message array with messages.
*/ */
public function load_Messages() { public function load_Messages() {
$this->messages['range_errors'][0] = array('ERROR', _('One or more errors occured. The invalid fields are marked.'), ''); $this->messages['range_errors'][0] = array('ERROR', _('One or more errors occurred. The invalid fields are marked.'), '');
$this->messages['add_range'][0] = array('ERROR', _('New range'), _('Adding the range failed because errors occured.')); $this->messages['add_range'][0] = array('ERROR', _('New range'), _('Adding the range failed because errors occurred.'));
$this->messages['drop_range'][0] = array('ERROR', _('Delete range'), _('It is not possible to delete all ranges.')); $this->messages['drop_range'][0] = array('ERROR', _('Delete range'), _('It is not possible to delete all ranges.'));
$this->messages['pool_cn'][0] = array('ERROR', _('Name'), _('Please enter a pool name.')); $this->messages['pool_cn'][0] = array('ERROR', _('Name'), _('Please enter a pool name.'));
$this->messages['pool_range'][0] = array('ERROR', _('Please enter at least one range for pool "%s".'), null); $this->messages['pool_range'][0] = array('ERROR', _('Please enter at least one range for pool "%s".'), null);
@ -185,27 +184,27 @@ class range extends baseModule {
/** /**
* *
* Checks if ranges are not overlaped. * Checks if ranges are not overlapped.
* *
* @param first ip * @param first ip
* @param second ip * @param second ip
* *
* @return not overlaped * @return bool not overlapped
* *
**/ **/
function isNotOverlapedRange($ip,$ipB) { private function isNotOverlappedRange($ip, $ipB) {
$ex = explode(".", $ip); $ex = explode(".", $ip);
$exB = explode(".", $ipB); $exB = explode(".", $ipB);
if(!is_array($this->overlaped)) { if(!is_array($this->overlapped)) {
$this->overlaped = array(); $this->overlapped = array();
} }
for($n=$ex[3];$n<=$exB[3];$n++) { for($n=$ex[3];$n<=$exB[3];$n++) {
if (in_array($n, $this->overlaped)) { if (in_array($n, $this->overlapped)) {
return false; return false;
} }
else { else {
$this->overlaped[] = $n; $this->overlapped[] = $n;
} }
} }
return true; return true;
@ -213,11 +212,11 @@ class range extends baseModule {
/** /**
* *
* Reset the overlaped_range() function * Reset the overlapped_range() function
* *
**/ **/
function reset_overlaped_range() { private function reset_overlapped_range() {
$this->overlaped = array(); $this->overlapped = array();
} }
/** /**
@ -318,7 +317,7 @@ class range extends baseModule {
$subnet = $this->getAccountContainer()->getAccountModule('dhcp_settings')->attributes['cn'][0]; $subnet = $this->getAccountContainer()->getAccountModule('dhcp_settings')->attributes['cn'][0];
$mask = $this->getAccountContainer()->getAccountModule('dhcp_settings')->getDHCPOption('subnet-mask'); $mask = $this->getAccountContainer()->getAccountModule('dhcp_settings')->getDHCPOption('subnet-mask');
$errorOccured = false; $errorOccured = false;
$this->reset_overlaped_range(); $this->reset_overlapped_range();
if ($this->getAccountContainer()->getAccountModule('dhcp_settings')->attributes['cn'][0]!="") { if ($this->getAccountContainer()->getAccountModule('dhcp_settings')->attributes['cn'][0]!="") {
foreach($this->ranges AS $id=>$arr) { foreach($this->ranges AS $id=>$arr) {
@ -349,8 +348,8 @@ class range extends baseModule {
} }
$this->ranges[$id]['range_end'] = $_POST['range_end_'.$id]; $this->ranges[$id]['range_end'] = $_POST['range_end_'.$id];
// Check if ip overlaped: // Check if ip overlapped:
if(!$this->isNotOverlapedRange($_POST['range_start_'.$id],$_POST['range_end_'.$id])) { if(!$this->isNotOverlappedRange($_POST['range_start_'.$id],$_POST['range_end_'.$id])) {
$errorOccured = true; $errorOccured = true;
} }
@ -409,9 +408,9 @@ class range extends baseModule {
$peer = trim($_POST['pool_peer_' . $index]); $peer = trim($_POST['pool_peer_' . $index]);
if (!empty($this->poolsNew[$index]['dhcpstatements'])) { if (!empty($this->poolsNew[$index]['dhcpstatements'])) {
// remove old peer setting // remove old peer setting
foreach ($this->poolsNew[$index]['dhcpstatements'] as $indexS => $stmt) { foreach ($this->poolsNew[$index]['dhcpstatements'] as $indexStmt => $stmt) {
if (strpos($stmt, 'failover peer "') === 0) { if (strpos($stmt, 'failover peer "') === 0) {
unset($this->poolsNew[$index]['dhcpstatements'][$indexS]); unset($this->poolsNew[$index]['dhcpstatements'][$indexStmt]);
break; break;
} }
} }
@ -435,7 +434,7 @@ class range extends baseModule {
$this->poolsNew[$index]['dhcprange'][$rIndex] = $from . ' ' . $to; $this->poolsNew[$index]['dhcprange'][$rIndex] = $from . ' ' . $to;
// check ranges // check ranges
if (!check_ip($from) || !check_ip($to) if (!check_ip($from) || !check_ip($to)
|| !$this->isNotOverlapedRange($from, $to) || !$this->isNotOverlappedRange($from, $to)
|| !range::check_subnet_range($from, $subnet, $mask) || !range::check_subnet_range($from, $subnet, $mask)
|| !range::check_subnet_range($to, $subnet, $mask) || !range::check_subnet_range($to, $subnet, $mask)
|| !$this->check_range($from, $to)) { || !$this->check_range($from, $to)) {
@ -488,7 +487,7 @@ class range extends baseModule {
if (!is_array($this->ranges)) { if (!is_array($this->ranges)) {
$this->ranges = array(); $this->ranges = array();
} }
$this->reset_overlaped_range(); $this->reset_overlapped_range();
$mask = $this->getAccountContainer()->getAccountModule('dhcp_settings')->getDHCPOption('subnet-mask'); $mask = $this->getAccountContainer()->getAccountModule('dhcp_settings')->getDHCPOption('subnet-mask');
$subnet = $this->getAccountContainer()->getAccountModule('dhcp_settings')->attributes['cn'][0]; $subnet = $this->getAccountContainer()->getAccountModule('dhcp_settings')->attributes['cn'][0];
foreach($this->ranges AS $id=>$arr) { foreach($this->ranges AS $id=>$arr) {
@ -501,7 +500,7 @@ class range extends baseModule {
$error = _("The range end needs to be greater than the range start."); $error = _("The range end needs to be greater than the range start.");
} elseif ($this->processed && !range::check_subnet_range($this->ranges[$id]['range_start'], $subnet, $mask)) { } elseif ($this->processed && !range::check_subnet_range($this->ranges[$id]['range_start'], $subnet, $mask)) {
$error = _("The IP does not match the subnet."); $error = _("The IP does not match the subnet.");
} elseif ($this->processed && !$this->isNotOverlapedRange($this->ranges[$id]['range_start'],$this->ranges[$id]['range_end']) ) { } elseif ($this->processed && !$this->isNotOverlappedRange($this->ranges[$id]['range_start'],$this->ranges[$id]['range_end']) ) {
$error = _("The range conflicts with another range."); $error = _("The range conflicts with another range.");
} }
} }
@ -581,7 +580,7 @@ class range extends baseModule {
elseif (!range::check_subnet_range($from, $subnet, $mask)) { elseif (!range::check_subnet_range($from, $subnet, $mask)) {
$message = _("The IP does not match the subnet."); $message = _("The IP does not match the subnet.");
} }
elseif (!$this->isNotOverlapedRange($from, $to)) { elseif (!$this->isNotOverlappedRange($from, $to)) {
$message = _("The range conflicts with another range."); $message = _("The range conflicts with another range.");
} }
} }