forked from opendcim/openDCIM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconflicts.php
344 lines (314 loc) · 12.6 KB
/
conflicts.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
<?php
$devMode = true;
require_once('db.inc.php');
require_once('facilities.inc.php');
$user=new User();
$user->UserID=$_SERVER['REMOTE_USER'];
$user->GetUserRights($facDB);
if(!$user->SiteAdmin){
// No soup for you.
header('Location: '.redirect());
exit;
}
if(isset($_POST['DeviceID']) && isset($_POST['power'])){
if(isset($_POST['con']) && isset($_POST['pduid'])){
$pwrConnection=new PowerConnection();
$pwrConnection->DeviceID=$_POST['DeviceID'];
$pwrConnection->PDUID=$_POST['pduid'];
$pwrConnection->PDUPosition=$_POST['con'];
$pwrConnection->DeviceConnNumber=$_POST['power'];
if(isset($_POST['e'])){
$pwrConnection->CreateConnection($facDB);
}else{
$pwrConnection->RemoveConnection($facDB);
}
echo 'ok';
}else{
$dev=new Device();
$pwrConnection=new PowerConnection();
$pdu=new PowerDistribution();
$dev->DeviceID=$_POST['DeviceID'];
$dev->GetDevice($facDB);
$pwrConnection->DeviceID=($dev->ParentDevice>0)?$dev->ParentDevice:$dev->DeviceID;
$pwrCords=$pwrConnection->GetConnectionsByDevice($facDB);
print "<span>Server Name: $dev->Label</span><span># Power Supplies: $dev->PowerSupplyCount</span><div class=\"table border\">\n <div><div>"._('Power Strip')."</div><div>"._('Plug #')."</div><div>"._('Power Supply')."</div></div>";
foreach($pwrCords as $cord){
$pdu->PDUID=$cord->PDUID;
$pdu->GetPDU($facDB);
print " <div><div data=\"$pdu->PDUID\"><a href=\"power_pdu.php?pduid=$pdu->PDUID\">$pdu->Label</a></div><div><a href=\"power_connection.php?pdu=$pdu->PDUID&conn=$cord->PDUPosition\">$cord->PDUPosition</a></div><div".(($cord->DeviceConnNumber==$_POST['power'])?' class="bold"':' class="disabled"').">$cord->DeviceConnNumber</div></div>\n";
}
print "</div>";
}
exit;
}
if(isset($_POST['EndpointDeviceID'])){
$networkPatches=new SwitchConnection();
$networkPatches->EndpointDeviceID=$_POST['EndpointDeviceID'];
if(isset($_POST['SwitchDeviceID']) && isset($_POST['SwitchPortNumber'])){
$networkPatches->SwitchDeviceID=$_POST['SwitchDeviceID'];
$networkPatches->SwitchPortNumber=$_POST['SwitchPortNumber'];
if(isset($_POST['EndpointPort'])){ // Update Connection
$networkPatches->GetSwitchPortConnector($facDB);
$networkPatches->EndpointPort=$_POST['EndpointPort'];
$networkPatches->UpdateConnection($facDB);
print "ok";
}else{ // Delete Connection
$networkPatches->RemoveConnection($facDB);
print "ok";
}
}else{
$patchList=$networkPatches->GetEndpointConnections($facDB);
$tmpDev=new Device();
$tmpDev->DeviceID=$networkPatches->EndpointDeviceID;
$tmpDev->GetDevice($facDB);
print "<span>Server Name: <a href=\"devices.php?deviceid=$tmpDev->DeviceID\">$tmpDev->Label</a></span><span># Data Ports: $tmpDev->Ports</span><div class=\"table border\">\n <div><div>"._('Switch')."</div><div>"._('Switch Port')."</div><div>"._('Device Port')."</div><div>"._('Notes')."</div></div>\n";
foreach($patchList as $patchConn){
$tmpDev->DeviceID=$patchConn->SwitchDeviceID;
$tmpDev->GetDevice($facDB);
print "\t\t\t\t<div><div data=\"$patchConn->SwitchDeviceID\"><a href=\"devices.php?deviceid=$patchConn->SwitchDeviceID\">$tmpDev->Label</a></div><div><a href=\"changepatch.php?switchid=$patchConn->SwitchDeviceID&portid=$patchConn->SwitchPortNumber\">$patchConn->SwitchPortNumber</a></div><div>$patchConn->EndpointPort</div><div>$patchConn->Notes</div></div>\n";
}
print "</div><!-- END div.table -->\n";
}
exit;
}
$body="";
// This will only have a conflict if someone hand entered data. These will be unique cases that we should look at by hand.
$sql="SELECT PDUID, CONCAT(PDUID,'-',PDUPosition) AS KEY1, COUNT(PDUID) AS Count FROM fac_PowerConnection GROUP BY KEY1 HAVING (COUNT(KEY1)>1) ORDER BY PDUID ASC;";
$results=mysql_query($sql, $facDB);
if(mysql_num_rows($results)>0){
$body.="<p>This is a problem that will need a custom fix. Please email the output below to [email protected]</p>";
while($row=mysql_fetch_array($results)){
$body.=print_r($row, TRUE);
}
$conflicts+=0;
}else{
$body.="<p>No collisions detected for Power Connections (PDUID,PDUPosition)</p>\n";
$conflicts+=1;
}
$sql="SELECT DeviceID, CONCAT(DeviceID,'-',DeviceConnNumber) AS KEY2, DeviceConnNumber, COUNT(DeviceID) AS Count FROM fac_PowerConnection GROUP BY KEY2 HAVING (COUNT(KEY2)>1) ORDER BY DeviceID ASC;";
$results=mysql_query($sql, $facDB);
if(mysql_num_rows($results)>0){
$body.="<p>The list below are devices that have multiple connections to the same power supply.</p>";
$body.='<div class="table border power"><div><div>DeviceID</div><div>KEY2</div><div>Count</div></div>';
while($row=mysql_fetch_array($results)){
$body.="<div><div>{$row['DeviceID']}</div><div data={$row['DeviceConnNumber']}>{$row['KEY2']}</div><div>{$row['Count']}</div></div>";
}
$body.='</div>';
$conflicts+=0;
}else{
$body.="No collisions detected for Power Connections (DeviceID,DeviceConnNumber)<br>\n";
$conflicts+=1;
}
// Check for duplicated switch ports same as initial power check this should only have a conflict and hand altered data.
$sql="SELECT SwitchDeviceID, CONCAT(SwitchDeviceID,'-',SwitchPortNumber) AS KEY1, COUNT(SwitchDeviceID) AS Count FROM fac_SwitchConnection GROUP BY KEY1 HAVING (COUNT(KEY1)>1) ORDER BY SwitchDeviceID ASC;";
$results=mysql_query($sql, $facDB);
if(mysql_num_rows($results)>0){
$body.="<p>This is a problem that will need a custom fix. Please email the output below to [email protected]</p>";
while($row=mysql_fetch_array($results)){
$body.=print_r($row, TRUE);
}
$conflicts+=0;
}else{
$body.="<p>No collisions detected for Switch Connections (SwitchDeviceID,SwitchPortNumber)</p>\n";
$conflicts+=1;
}
$sql="SELECT SwitchDeviceID, SwitchPortNumber, EndpointDeviceID, EndpointPort, CONCAT(EndpointDeviceID,'-',EndpointPort) AS KEY2, COUNT(EndpointDeviceID) AS Count FROM fac_SwitchConnection GROUP BY KEY2 HAVING (COUNT(KEY2)>1) ORDER BY EndpointDeviceID ASC;";
$results=mysql_query($sql, $facDB);
if(mysql_num_rows($results)>0){
$body.="<p>The list below are devices that have multiple connections to the same network card.</p>";
$body.='<div class="table border network"><div><div>DeviceID</div><div>KEY2</div><div>Count</div></div>';
while($row=mysql_fetch_array($results)){
$body.="<div><div>{$row['EndpointDeviceID']}</div><div>{$row['KEY2']}</div><div data=\"{$row['EndpointPort']}\">{$row['Count']}</div></div>";
}
$body.='</div>';
$conflicts+=0;
}else{
$body.="<p>No collisions detected for Switch Connections (EndpointDeviceID,EndpointPort)</p>\n";
$conflicts+=1;
}
if($conflicts==4){
header('Location: '.redirect("install.php"));
exit;
}
?>
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>openDCIM Data Center Inventory</title>
<link rel="stylesheet" href="css/inventory.php" type="text/css">
<!--[if lt IE 9]>
<link rel="stylesheet" href="css/ie.css" type="text/css" />
<![endif]-->
<script type="text/javascript" src="scripts/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('.power > div:first-child ~ div, .network > div:first-child ~ div').each(function(){
$(this).append('<div>edit</div>');
});
$('.power > div:first-child ~ div > div:last-child').each(function(){
var editbox=$(this);
var devid=$(this).prev().prev().prev().text();
var ps=$(this).prev().prev().attr('data');
$(this).click(function(){
$.ajax({
type: 'POST',
url: 'conflicts.php',
data: 'DeviceID='+devid+'&power='+ps,
success: function(edit){
editbox.unbind('click');
var pduid;
var con;
// get an edit form
editbox.html(edit);
editbox.find('.table > div:first-child ~ div > div:last-child').each(function(){
if($(this).hasClass('bold')){
var p=$(this).prev();
var row=$(this).parent();
$(this).after('<div>Edit</div>');
$(this).next().click(function(){
$(this).prev().html('<input value="'+$(this).prev().text()+'"></input>');
$(this).prev().children('input').change(function(){
// issue ajax update command then change this back from an input to plain text
var par=$(this).parent();
pduid=p.prev().attr('data');
con=p.text();
ps=$(this).val();
$.ajax({
type: 'POST',
url: 'conflicts.php',
data: 'DeviceID='+devid+'&power='+ps+'&pduid='+pduid+'&con='+con+'&e=1',
success: function(data){
if(data=='ok'){
par.text(ps);
// row.remove();
}
}
});
});
});
}
});
editbox.find('.table > div:first-child ~ div > div:last-child').each(function(){
if($(this).prev().hasClass('bold')){
var p=$(this).prev();
var row=$(this).parent();
$(this).after('<div>Delete</div>');
$(this).next().click(function(){
pduid=p.prev().prev().attr('data');
con=p.prev().text();
$.ajax({
type: 'POST',
url: 'conflicts.php',
data: 'DeviceID='+devid+'&power='+ps+'&pduid='+pduid+'&con='+con,
success: function(data){
if(data=='ok'){
row.remove();
}
}
});
});
}
});
}
});
});
});
$('.network > div:first-child ~ div > div:last-child').each(function(){
var editbox=$(this);
var devid=$(this).prev().prev().prev().text();
var dp=$(this).prev().attr('data');
$(this).click(function(){
$.ajax({
type: 'POST',
url: 'conflicts.php',
data: 'EndpointDeviceID='+devid,
success: function(edit){
editbox.unbind('click');
var sw;
var sp;
// get an edit form
editbox.html(edit);
editbox.find('.table > div:first-child ~ div > div:nth-child(3)').each(function(){
var nic=$(this);
if(nic.text()==dp){
var row=$(this).parent();
row.append('<div>Edit</div>');
$(this).next().next().click(function(){
sw=row.find('div:first-child').attr('data');
sp=$(this).prev().prev().prev().text();
nic.html('<input value="'+nic.text()+'"></input>');
nic.children('input').change(function(){
var change=$(this).val();
$.ajax({
type: 'POST',
url: 'conflicts.php',
data: 'EndpointDeviceID='+devid+'&SwitchDeviceID='+sw+'&SwitchPortNumber='+sp+'&EndpointPort='+$(this).val(),
success: function(data){
if(data=='ok'){
nic.text(change);
}
}
});
});
});
}
});
editbox.find('.table > div:first-child ~ div > div:nth-child(3)').each(function(){
if($(this).text()==dp){
var row=$(this).parent();
row.append('<div>Delete</div>');
row.find('div:last-child').click(function(){
sw=row.find('div:first-child').attr('data');
sp=row.find('div:nth-child(2)').text();
$.ajax({
type: 'POST',
url: 'conflicts.php',
data: 'EndpointDeviceID='+devid+'&SwitchDeviceID='+sw+'&SwitchPortNumber='+sp,
success: function(data){
if(data=='ok'){
row.remove();
}
}
});
});
}
});
}
});
});
});
});
</script>
<style type="text/css">
div.table > div > div {vertical-align: top;}
.bold {font-weight: bold;}
.disabled {background-color: lightGrey; font-style: italic;}
.disabled:after {
content: " - ok";
}
.center > div > p { max-width: 400px;}
.center > div > hr ~ p { display: list-item; }
</style>
</head>
<body>
<div id="header"></div>
<div class="page index">
<?php
include( 'sidebar.inc.php' );
?>
<div class="main">
<h2><?php echo $config->ParameterArray['OrgName']; ?></h2>
<div class="center"><div>
<p>The tables below show devices that are currently sharing resources and will need to be resolved before the new database update can be applied.</p>
<p>The Key in each table is made up of the DeviceID and the ID of resource that is currently being shared incorrectly.</p>
<p>Click "edit" in each row to display the records that are in conflict. Either use the word "Delete" to remove the connection outright or use the "Edit" option to change the value in the box.</p>
<p>After you have finished making changes <a href="conflicts.php">reload this page</a> until there are no conflicts remaing. It will then automatically put you back to the installer and finish applying the update.</p>
<hr>
<?php echo $body; ?>
<!-- CONTENT GOES HERE -->
</div></div>
</div><!-- END div.main -->
</div><!-- END div.page -->
</body>
</html>