summaryrefslogtreecommitdiffstats
path: root/ldap-site-mngmt/webinterface/rbs/rbservice_change.php
blob: 5f82ac264a5862f3b6f7c90fe33f95f97ae5ae37 (plain) (blame)
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
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
<?php
include('../standard_header.inc.php');
$syntax = new Syntaxcheck;

$rbscn = "RBS_".$_POST['rbscn'];
$oldrbscn = "RBS_".$_POST['oldrbscn'];
$rbsoffer = $_POST['rbsoffer'];
$oldrbsoffer = $_POST['oldrbsoffer'];

$tftpserverip = $_POST['tftpserverip'];
$oldtftpserverip = $_POST['oldtftpserverip'];
$nfsserverip = $_POST['nfsserverip'];
$oldnfsserverip = $_POST['oldnfsserverip'];
$nbdserverip = $_POST['nbdserverip'];
$oldnbdserverip = $_POST['oldnbdserverip'];

$tftpserver = $_POST['tftpserver'];
$nfsserver = $_POST['nfsserver'];
$nbdserver = $_POST['nbdserver'];
$oldtftpserverdn = $_POST['oldtftpserverdn'];
$oldnfsserverdn = $_POST['oldnfsserverdn'];
$oldnbdserverdn = $_POST['oldnbdserverdn'];

$delfsuri = $_POST['delfsuri'];
$addfsuri = $_POST['addfsuri'];

$fstype = $_POST['fstype'];
$fsip = $_POST['fsip'];
$fspath = $_POST['fspath'];

$initbootfile = $_POST['initbootfile'];
$oldinitbootfile = $_POST['oldinitbootfile'];

$host_array = get_hosts($auDN,array("dn","hostname","ipaddress"));

$rbsDN = $_POST['rbsdn'];
$nodeDN = "cn=rbs,".$auDN;

$mnr = $_POST['mnr'];
$sbmnr = $_POST['sbmnr'];
$mcnr = $_POST['mcnr'];

# sosntige Attribute
$attribs = $_POST['attribs'];
if (count($attribs) != 0){
	foreach (array_keys($attribs) as $key){
		$atts[$key] = htmlentities($attribs[$key]);
	}
}
#print_r($atts); echo "<br><br>";
$oldattribs = $_POST['oldattribs'];
if (count($oldattribs) != 0){
	foreach (array_keys($oldattribs) as $key){
		$oldatts[$key] = htmlentities($oldattribs[$key]);
	}
}
#print_r($oldatts); echo "<br><br>";

 
echo "
<html>
<head>
	<title>Computers Management</title>
	<link rel='stylesheet' href='../styles.css' type='text/css'>
</head>
<body>
<table border='0' cellpadding='30' cellspacing='0'> 
<tr><td>";

##############################################
# RBS CN (DN) 

if ( $oldrbscn == $rbscn ){
	# $mesg = "keine Aenderung<br>";
}

if ( $oldrbscn != "" && $rbscn != "" && $oldrbscn != $rbscn ){
	echo "RBS Name aendern<br>";
	# hier noch Syntaxcheck
	# Formulareingaben anpassen
	$exprbs = explode(" ",$rbscn);
	foreach ($exprbs as $word){$expuc[] = ucfirst($word);}
	$rbscn = implode(" ",$expuc);
	$rbscn = preg_replace ( '/\s+([0-9A-Z])/', '$1', $rbscn);
	
	$newrbsDN = "cn=".$rbscn.",".$nodeDN;
	print_r($newrbsDN); echo "<br><br>";
	
	if(move_subtree($rbsDN, $newrbsDN)){
		adjust_rbs_dn($newrbsDN, $rbsDN);
		$rbsDN = $newrbsDN;
		$mesg = "RBS Name erfolgreich ge&auml;ndert<br><br>";
	}else{
		$mesg = "Fehler beim &auml;ndern des RBS Namen!<br><br>";
	}
}

if ( $oldrbscn != "" && $rbscn == "" ){
	echo "Gruppenname loeschen!<br> 
			Dieses ist Teil des DN, Sie werden den RBS komplett l&ouml;schen<br><br>";
	echo "Wollen Sie den RBS Dienst <b>".$oldrbscn."</b> wirklich l&ouml;schen?<br><br>
			<form action='rbservice_delete.php' method='post'>
				Falls ja:<br><br>
				<input type='hidden' name='dn' value='".$pxeDN."'>
				<input type='hidden' name='name' value='".$oldrbscn."'>
				<input type='Submit' name='apply' value='l&ouml;schen' class='small_loginform_button'><br><br>
			</form>
			<form action='".$url."' method='post'>
				Falls, nein:<br><br>
				<input type='Submit' name='apply' value='zur&uuml;ck' class='small_loginform_button'>
			</form>";
			$seconds = 600;
}


#####################################
# Offer ändern 

if ( $rbsoffer != "none" && $rbsoffer == $oldrbsoffer ){
	$mesg = "Sie haben die gleiche Abteilung ausgew&auml;hlt<br>
				Keine &Auml;nderung!";
}

if ( $rbsoffer != "none" && $rbsoffer != $oldrbsoffer ){
	$entryoffer ['rbsofferdn'] = $rbsoffer;
	if(ldap_mod_replace($ds,$rbsDN,$entryoffer)){
		$mesg = "RBS Offer erfolgreich ge&auml;ndert<br><br>";
	}
	else{
		$mesg = "Fehler beim &auml;ndern des RBS Offers!<br><br>";
	}
} 


#####################################
# Server ändern über IP Feld


if ( $tftpserverip != "" && $tftpserverip != $oldtftpserverip ){
	
	if ($syntax->check_ip_syntax($tftpserverip)){
		$tftpserverip = htmlentities($tftpserverip);
		
		$mesg .= "Suche nach dem Rechner mit IP ".$tftpserverip." :<br>";
		foreach ($host_array as $host){
			$hostipexp = explode('_',$host['ipaddress']);
			$hostip = $hostipexp[0];
			if ($tftpserverip == $hostip){
				$entrytftp ['tftpserverip'] = $tftpserverip;			
				if (ldap_mod_replace($ds,$rbsDN,$entrytftp)){
				   adjust_dhcpnextserver($tftpserverip, $rbsDN);
					$mesg .= "Treffer: Rechner ".$host['hostname']."<br>TFTP Server erfolgreich ge&auml;ndert<br>";
				}else{
					$mesg .= "Fehler beim  &auml;ndern des TFTP Servers!<br>";
				}
				break;
			}else{
				 $mesg .= "Rechner ".$host['hostname'].":  keine &Uuml;bereinstimmung mit eingegebener IP ".$tftpserverip."!<br>";
			}
		}
	}
	else{
		$mesg .= "Falsche IP Syntax!<br>";
	}
}

#######################################
# Fileserver URI anlegen

if ( $addfsuri[1] != "" ){
   # tests: ipsyntax, und spezifische URI-Syntax-Checks...
   if( $syntax->check_ip_syntax($addfsuri[1]) ){
      
      $newfsuri = $addfsuri[0]."://".$addfsuri[1].$addfsuri[2];
      echo "FS URI <b>".$newfsuri."</b> anlegen<br>";
      
      $entryfsadd ['fileserveruri'] = $newfsuri;
      if(ldap_mod_add($ds,$rbsDN,$entryfsadd)){
			$mesg = "FS URI erfolgreich eingetragen<br><br>";
		}else{
			$mesg = "Fehler beim eintragen der FS URI<br><br>";
		}
	}
	else{echo "Falsche IP Syntax<br><br>";}
}

#####################################
# Fileserver URIs löschen
if ( count($delfsuri) != 0 ){
	echo "Fileserver URI l&ouml;schen<br>";
	
	$i = 0;
	foreach ($delfsuri as $fsuri){
		$entry['fileserveruri'][$i] = $fsuri;
		$i++;
	}
	#print_r($entry); echo "<br><br>";
	
	if ($result = ldap_mod_del($ds,$rbsDN,$entry)){
		$mesg = "Zu l&ouml;schende Fileserver URIs erfolgreich gel&ouml;scht<br><br>";
	}else{
		$mesg = "Fehler beim l&ouml;schen der Fileserver URIs<br><br>";
	}
} 

if ( $nfsserverip != "" && $nfsserverip != $oldnfsserverip ){
	
	if ($syntax->check_ip_syntax($nfsserverip)){
		$nfsserverip = htmlentities($nfsserverip);
		
		$mesg .= "Suche nach dem Rechner mit IP ".$nfsserverip." :<br>";
		foreach ($host_array as $host){
			$hostipexp = explode('_',$host['ipaddress']);
			$hostip = $hostipexp[0];
			if ($nfsserverip == $hostip){
				$entrytnfs ['nfsserverip'] = $nfsserverip;			
				if (ldap_mod_replace($ds,$rbsDN,$entrytnfs)){
					$mesg .= "Treffer: Rechner ".$host['hostname']."<br>NFS Server erfolgreich ge&auml;ndert<br>";
				}else{
					$mesg .= "Fehler beim  &auml;ndern des NFS Servers!<br>";
				}
				break;
			}else{
				 $mesg .= "Rechner ".$host['hostname'].":  keine &Uuml;bereinstimmung mit eingegebener IP ".$nfsserverip."!<br>";
			}
		}
	}
	else{
		$mesg .= "Falsche IP Syntax!<br>";
	}
}

if ( $nbdserverip != "" && $nbdserverip != $oldnbdserverip ){
	
	if ($syntax->check_ip_syntax($nbdserverip)){
		$nbdserverip = htmlentities($nbdserverip);
		
		$mesg .= "Suche nach dem Rechner mit IP ".$nbdserverip." :<br>";
		foreach ($host_array as $host){
			$hostipexp = explode('_',$host['ipaddress']);
			$hostip = $hostipexp[0];
			if ($nbdserverip == $hostip){
				$entrytnbd ['nbdserverip'] = $nbdserverip;			
				if (ldap_mod_replace($ds,$rbsDN,$entrytnbd)){
					$mesg .= "Treffer: Rechner ".$host['hostname']."<br>NBD Server erfolgreich ge&auml;ndert<br>";
				}else{
					$mesg .= "Fehler beim  &auml;ndern des NBD Servers!<br>";
				}
				break;
			}else{
				 $mesg .= "Rechner ".$host['hostname'].":  keine &Uuml;bereinstimmung mit eingegebener IP ".$nbdserverip."!<br>";
			}
		}
	}
	else{
		$mesg .= "Falsche IP Syntax!<br>";
	}
}

#####################################
# Server ändern über Hostname 

if ($tftpserver != "none" && $tftpserver != $oldtftpserverdn){

	$host = get_host_ip($tftpserver);
	$hostipexp = explode('_',$host['ipaddress']);
	$hostip = $hostipexp[0];
	$entrytftp ['tftpserverip'] = $hostip;
	if (ldap_mod_replace($ds,$rbsDN,$entrytftp)){
	   adjust_dhcpnextserver($tftpserverip, $rbsDN);
		$mesg .= "TFTP Server erfolgreich ge&auml;ndert<br>";
	}else{
		$mesg .= "Fehler beim  &auml;ndern des TFTP Servers!<br>";
	}
	
}		

if ($nfsserver != "none" && $nfsserver != $oldnfsserverdn){

	$host = get_host_ip($nfsserver);
	$hostipexp = explode('_',$host['ipaddress']);
	$hostip = $hostipexp[0];
	$entrynfs ['nfsserverip'] = $hostip;
	if (ldap_mod_replace($ds,$rbsDN,$entrynfs)){
		$mesg .= "NFS Server erfolgreich ge&auml;ndert<br>";
	}else{
		$mesg .= "Fehler beim  &auml;ndern des NFS Servers!<br>";
	}
	
}		

if ($nbdserver != "none" && $nbdserver != $oldnbdserverdn){

	$host = get_host_ip($nbdserver);
	$hostipexp = explode('_',$host['ipaddress']);
	$hostip = $hostipexp[0];
	$entrytnbd ['nbdserverip'] = $hostip;
	if (ldap_mod_replace($ds,$rbsDN,$entrytnbd)){
		$mesg .= "NBD Server erfolgreich ge&auml;ndert<br>";
	}else{
		$mesg .= "Fehler beim  &auml;ndern des NBD Servers!<br>";
	}
	
}

#####################################
# Init Boot File

if ( $initbootfile == $oldinitbootfile ){
	# $mesg = "keine Aenderung<br>";
}

if ( $initbootfile != "" && $oldinitbootfile == "" ){
   $entrydelibf ['initbootfile'] = $initbootfile;
   if(ldap_mod_add($ds,$rbsDN,$entrydelibf)){
      adjust_dhcpfilename($initbootfile, $rbsDN, "add");
		$mesg = "Initial Boot File erfolgreich eingetragen<br><br>";
	}
	else{
		$mesg = "Fehler beim eintragen von Initial Boot File!<br><br>";
	}
}

if ( $initbootfile == "" && $oldinitbootfile != "" ){
   $entrydelibf ['initbootfile'] = array();
   if(ldap_mod_del($ds,$rbsDN,$entrydelibf)){
      adjust_dhcpfilename($initbootfile, $rbsDN, "delete");
		$mesg = "Initial Boot File erfolgreich gel&ouml;scht<br><br>";
	}
	else{
		$mesg = "Fehler beim l&ouml;schen von Initial Boot File!<br><br>";
	}
}

if ( $initbootfile != "" && $initbootfile != $oldinitbootfile ){
   $entryibf ['initbootfile'] = $initbootfile;
	if(ldap_mod_replace($ds,$rbsDN,$entryibf)){
	   adjust_dhcpfilename($initbootfile, $rbsDN, "replace");
		$mesg = "Initial Boot File erfolgreich ge&auml;ndert<br><br>";
	}
	else{
		$mesg = "Fehler beim &auml;ndern des Initial Boot Files!<br><br>";
	}
}



 
#####################################
# Restliche Attribute

$entryadd = array();
$entrymod = array();
$entrydel = array();

foreach (array_keys($atts) as $key){
	
	if ( $oldatts[$key] == $atts[$key] ){
	
	}
	if ( $oldatts[$key] == "" && $atts[$key] != "" ){
		# hier noch Syntaxcheck
		$entryadd[$key] = $atts[$key];
	}
	if ( $oldatts[$key] != "" && $atts[$key] != "" && $oldatts[$key] != $atts[$key] ){
		# hier noch Syntaxcheck
		$entrymod[$key] = $atts[$key];
	}
	if ( $oldatts[$key] != "" && $atts[$key] == "" ){
		# hier noch Syntaxcheck
		$entrydel[$key] = $oldatts[$key];
	}
}

#print_r($entryadd); echo "<br>";
#print_r($entrymod); echo "<br>";
#print_r($entrydel); echo "<br>";


if (count($entryadd) != 0 ){
	#print_r($entryadd); echo "<br>";
	#echo "neu anlegen<br>"; 
	foreach (array_keys($entryadd) as $key){
		$addatts .= "<b>".$key."</b>,";
	}
	if(ldap_mod_add($ds,$rbsDN,$entryadd)){
		$mesg = "Attribute ".$addatts." erfolgreich eingetragen<br><br>";
	}else{
		$mesg = "Fehler beim eintragen der Attribute ".$addatts."<br><br>";
	}
}

if (count($entrymod) != 0 ){
	#print_r($entrymod); echo "<br>";
	#echo "&auml;ndern<br>";
	foreach (array_keys($entrymod) as $key){
		$modatts .= "<b>".$key."</b>,";
	}
	if(ldap_mod_replace($ds,$rbsDN,$entrymod)){
		$mesg = "Attribute ".$modatts." erfolgreich geaendert<br><br>";
	}else{
		$mesg = "Fehler beim aendern der Attribute ".$modatts."<br><br>";
	}
}

if (count($entrydel) != 0 ){
	#print_r($entrydel); echo "<br>";
	#echo "l&ouml;schen<br>";
	foreach (array_keys($entrydel) as $key){
		$delatts .= "<b>".$key."</b>,";
	}
	if(ldap_mod_del($ds,$rbsDN,$entrydel)){
		$mesg = "Attribute ".$delatts." erfolgreich geloescht<br><br>";
	}else{
		$mesg = "Fehler beim loeschen der Attribute ".$delatts."<br><br>";
	}
}


$url = "rbservice.php?rbsdn=".$rbsDN."&mnr=".$mnr;
$seconds = 2;


$mesg .= "<br>Sie werden automatisch auf die vorherige Seite zur&uuml;ckgeleitet. <br>				
			Falls nicht, klicken Sie hier <a href=".$url." style='publink'>back</a>";
redirect($seconds, $url, $mesg, $addSessionId = TRUE);

echo "</td></tr></table></body>
</html>";
?>