Author: jfthomps
Date: Mon Nov 26 19:39:39 2012
New Revision: 1413799
URL: http://svn.apache.org/viewvc?rev=1413799&view=rev
Log:
VCL-451
Cannot add deleted computers
changed how this is done; added computer.datedeleted to database and changed
unique keys to be on that field and the hostname; did similar change for
eth0macaddress and eth1macaddress
computers.php:
-modified submitDeleteComputer - do not remove '-DELETED-<compid>' when
undeleting computers; set datedeleted to zeros when undeleting; removed
'-UNDELETED-<compid>' from hostname when deleting; set datedeleted to NOW when
deleting
-modified submitCompStateChange - set datedeleted = NOW and remove
'-UNDELETED-<compid> when deleting; removed setting notes = ''
-modified processComputerInput - added checks for mac address conflict
-modified processBulkComputerInput - restricted check for conflicting hostnames
to undeleted computers only
-modified checkForHostname - restricted check for conflicting hostnames to
undeleted computers only
-added checkForMACaddress
utils.php:
-modified getComputers - do not need to remove '-DELETED-<compid>' any more
-modified sortComputers - only need to replace UNDELETED, instead of
(UN)?DELETED
Modified:
vcl/branches/vcl-2.3-bugfixes/web/.ht-inc/computers.php
vcl/branches/vcl-2.3-bugfixes/web/.ht-inc/utils.php
Modified: vcl/branches/vcl-2.3-bugfixes/web/.ht-inc/computers.php
URL:
http://svn.apache.org/viewvc/vcl/branches/vcl-2.3-bugfixes/web/.ht-inc/computers.php?rev=1413799&r1=1413798&r2=1413799&view=diff
==============================================================================
--- vcl/branches/vcl-2.3-bugfixes/web/.ht-inc/computers.php (original)
+++ vcl/branches/vcl-2.3-bugfixes/web/.ht-inc/computers.php Mon Nov 26 19:39:39
2012
@@ -1697,8 +1697,7 @@ function submitDeleteComputer() {
$deleted = getContinuationVar("deleted");
$compdata = getComputers(0, 1, $compid);
if($deleted) {
- $newhostname = preg_replace('/-DELETED-[0-9]+$/', '',
$compdata[$compid]['hostname']);
- $newhostname = mysql_real_escape_string($newhostname);
+ $newhostname = $compdata[$compid]['hostname'];
$query = "SELECT id "
. "FROM computer "
. "WHERE hostname = '$newhostname' AND "
@@ -1708,6 +1707,7 @@ function submitDeleteComputer() {
$newhostname = "$newhostname-UNDELETED-$compid";
$query = "UPDATE computer "
. "SET deleted = 0, "
+ . "datedeleted = '0000-00-00 00:00:00', "
. "hostname = '$newhostname' ";
if($compdata[$compid]['type'] == 'virtualmachine')
$query .= ", stateid = 10 ";
@@ -1715,11 +1715,10 @@ function submitDeleteComputer() {
$qh = doQuery($query, 190);
}
else {
- $newhostname = preg_replace('/-(UN)?DELETED-[0-9]+$/', '',
$compdata[$compid]['hostname']);
- $newhostname = "$newhostname-DELETED-$compid";
- $newhostname = mysql_real_escape_string($newhostname);
+ $newhostname = preg_replace('/-UNDELETED-[0-9]+$/', '',
$compdata[$compid]['hostname']);
$query = "UPDATE computer "
. "SET deleted = 1, "
+ . "datedeleted = NOW(), "
. "vmhostid = NULL, "
. "hostname = '$newhostname' "
. "WHERE id = $compid";
@@ -3645,7 +3644,8 @@ function submitCompStateChange() {
$compids = implode(',', $data['computerids']);
$query = "UPDATE computer "
. "SET deleted = 1, "
- . "notes = '', "
+ . "datedeleted = NOW(), "
+ . "hostname = REPLACE(hostname,
CONCAT('-UNDELETED-', id), ''), "
. "vmhostid = NULL "
. "WHERE id IN ($compids)";
doQuery($query, 999);
@@ -3801,12 +3801,22 @@ function processComputerInput($checks=1)
$submitErrMsg[MACADDRERR2] = "Invalid MAC address. Must be
XX:XX:XX:XX:XX:XX "
. "with each pair of XX being from
00 to FF (inclusive)";
}
+ if(! ($submitErr & MACADDRERR2) &&
+ checkForMACaddress($return['eth0macaddress'], 0, $return['compid']))
{
+ $submitErr |= MACADDRERR2;
+ $submitErrMsg[MACADDRERR2] = "There is already a computer with this
MAC address.";
+ }
if(strlen($return['eth1macaddress']) &&
! preg_match('/^(([A-Fa-f0-9]){2}:){5}([A-Fa-f0-9]){2}$/',
$return["eth1macaddress"])) {
$submitErr |= MACADDRERR;
$submitErrMsg[MACADDRERR] = "Invalid MAC address. Must be
XX:XX:XX:XX:XX:XX "
. "with each pair of XX being from 00
to FF (inclusive)";
}
+ if(! ($submitErr & MACADDRERR) &&
+ checkForMACaddress($return['eth1macaddress'], 1, $return['compid']))
{
+ $submitErr |= MACADDRERR;
+ $submitErrMsg[MACADDRERR] = "There is already a computer with this
MAC address.";
+ }
/*if(! ($submitErr & IPADDRERR) &&
checkForIPaddress($return["ipaddress"], $return["compid"])) {
$submitErr |= IPADDRERR;
@@ -4103,7 +4113,8 @@ function processBulkComputerInput($check
}
$allhosts = implode("','", $checkhosts);
$query = "SELECT hostname FROM computer "
- . "WHERE hostname IN ('$allhosts')";
+ . "WHERE hostname IN ('$allhosts') AND "
+ . "deleted = 0";
$qh = doQuery($query);
$exists = array();
while($row = mysql_fetch_assoc($qh))
@@ -4178,7 +4189,38 @@ function processBulkComputerInput($check
////////////////////////////////////////////////////////////////////////////////
function checkForHostname($hostname, $compid) {
$query = "SELECT id FROM computer "
- . "WHERE hostname = '$hostname'";
+ . "WHERE hostname = '$hostname' AND "
+ . "deleted = 0";
+ if(! empty($compid))
+ $query .= " AND id != $compid";
+ $qh = doQuery($query, 101);
+ if(mysql_num_rows($qh))
+ return 1;
+ return 0;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+///
+/// \fn checkForMACaddress($mac, $num, $compid)
+///
+/// \param $mac - computer mac address
+/// \param $num - which mac address to check - 0 or 1
+/// \param $compid - a computer id to ignore
+///
+/// \return 1 if $mac/$num is already in the computer table, 0 if not
+///
+/// \brief checks for $mac being somewhere in the computer table except
+/// for $compid
+///
+////////////////////////////////////////////////////////////////////////////////
+function checkForMACaddress($mac, $num, $compid) {
+ if($num == 0)
+ $field = 'eth0macaddress';
+ else
+ $field = 'eth1macaddress';
+ $query = "SELECT id FROM computer "
+ . "WHERE $field = '$mac' AND "
+ . "deleted = 0";
if(! empty($compid))
$query .= " AND id != $compid";
$qh = doQuery($query, 101);
Modified: vcl/branches/vcl-2.3-bugfixes/web/.ht-inc/utils.php
URL:
http://svn.apache.org/viewvc/vcl/branches/vcl-2.3-bugfixes/web/.ht-inc/utils.php?rev=1413799&r1=1413798&r2=1413799&view=diff
==============================================================================
--- vcl/branches/vcl-2.3-bugfixes/web/.ht-inc/utils.php (original)
+++ vcl/branches/vcl-2.3-bugfixes/web/.ht-inc/utils.php Mon Nov 26 19:39:39 2012
@@ -7274,8 +7274,6 @@ function getComputers($sort=0, $included
$query .= "ORDER BY c.hostname";
$qh = doQuery($query, 180);
while($row = mysql_fetch_assoc($qh)) {
- if($includedeleted && $row['deleted'] == 1)
- $row['hostname']= preg_replace('/-DELETED-[0-9]+$/',
'', $row['hostname']);
$return[$row['id']] = $row;
}
if($sort) {
@@ -7551,8 +7549,8 @@ function sortComputers($a, $b) {
return -1;
}
- $a['hostname'] = preg_replace('/-(UN)?DELETED-[0-9]+$/', '',
$a['hostname']);
- $b['hostname'] = preg_replace('/-(UN)?DELETED-[0-9]+$/', '',
$b['hostname']);
+ $a['hostname'] = preg_replace('/-UNDELETED-[0-9]+$/', '',
$a['hostname']);
+ $b['hostname'] = preg_replace('/-UNDELETED-[0-9]+$/', '',
$b['hostname']);
# get hostname and first part of domain name
$tmp = explode('.', $a["hostname"]);