summaryrefslogtreecommitdiffstats
path: root/ldap-site-mngmt/webinterface/au/childau_add.php
blob: 89969882bcd97dc55130fe167fdab814eff28e64 (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
<?php

include('../standard_header.inc.php');

# $_POST form variables
$childou = $_POST['childou'];
$childcn = $_POST['childcn'];
$childdesc = $_POST['childdesc'];
$childdomain = $_POST['childdomain'];
$mainadmin = $_POST['adduser'];
$hosts = $_POST['addhost'];

$childou = htmlentities($childou);
$childcn = htmlentities($childcn);
$childdesc = htmlentities($childdesc);
$childdomainfull = htmlentities($childdomain).".".$domsuffix ;

/*
echo "AU dn:"; print_r($auDN); echo "<br>";
echo "ou:"; print_r($childou); echo "<br>";
echo "cn:"; print_r($childcn); echo "<br>";
echo "desc:"; print_r($childdesc); echo "<br>";
echo "domain:"; print_r($childdomainfull); echo "<br>";
echo "mainadmin:"; print_r($mainadmin); echo "<br><br>";
echo "hosts:"; print_r($hosts); echo "<br><br>";
*/

$seconds = 2;
# $url = 'new_child.php?ou='.$childou.'&cn='.$get_childcn.'&desc='.$get_childdesc.'&childdomain='.$childdomain;

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

if ( $childou != "" && $mainadmin != none && $mainadmin != "") {
	
	# Formulareingaben anpassen
	$expou = explode(" ",$childou);
	foreach ($expou as $word) {$expuc[] = ucfirst($word);}
	$childou = implode(" ",$expuc);
	$childou = preg_replace ( '/\s+([0-9A-Z])/', '$1', $childou);
	
	# AU Objekt anlegen
	$sisters = get_childau($auDN,array("ou"));
	$sister = 0;
	foreach ($sisters as $item) {
		if ($item['ou'] == $childou) {
			$mesg = "Es existiert bereits eine untergeordnete AU mit dem eingegebenen OU!<br>
				Bitte geben Sie einen anderen OU ein.<br><br>";
			$get_childcn = str_replace ( " ", "_", $childcn );
			$get_childdesc = str_replace ( " ", "_", $childdesc );
			$url = "new_child.php?ou=Hier_andere_OU_eingeben&cn=".$get_childcn."&desc=".$get_childdesc."&childdomain=".$childdomain;
			$sister = 1;
			break;
		}
	}
	if ($sister == 0) {
		
		$childDN = "ou=".$childou.",".$auDN;
		if (new_childau($childDN,$childou,$childcn,$childdesc,$mainadmin)) {
			
			# Objekete verschieben
			$i = array_search('none',$hosts);
			#print_r($i); echo "<br>";
			if ($i === 0 ) {array_splice($hosts, $i, 1);}
			#print_r($hosts ); echo "<br>";
			
			if (count($hosts) != 0) {
				foreach ($hosts as $host) {
					$exp = explode('_',$host);
					$hostDN = $exp[0];
					$hostname = $exp[1];
					print_r($hostDN); echo "<br>";
					print_r($hostname);  echo "<br><br>";
					# IP Adresse nicht verschieben (IPs werden später delegiert)
					$hoip = get_node_data($hostDN, array("ipaddress"));
					# print_r($hoip); echo "<br>";
					if ($hoip['ipaddress'] != "") {
						delete_ip_host($hostDN,$auDN);
					}
					if (move_subtree($hostDN, "hostname=".$hostname.",cn=computers,".$childDN)) {
						# bestimmte Attribute loeschen ...
						$newhostDN = "hostname=".$hostname.",cn=computers,".$childDN;
						$dhcp = get_node_data($newhostDN, array("dhcphlpcont"));
						# print_r($dhcp); echo "<br>";
						if ($dhcp['dhcphlpcont'] != "") {
							$entrydel ['dhcphlpcont'] = array();
							#$entrydel ['objectclass'] = "dhcpHost";
							# print_r($dhcphlpcont);
							ldap_mod_del($ds, "hostname=".$hostname.",cn=computers,".$childDN, $entrydel);
						}
					}
				}
			}
			
			# Domain anlegen falls erforderlich
			if (new_child_domain($childdomain, $childDN, $assocdom, $domDN)) {
				$mesg .= "<br>AU Domain erfolgreich eingetragen<br>";
			}
			else {
				$mesg .= "<br>Fehler beim eintragen der AU Domain<br>";
			}
					
			$mesg .= "<br>Untergeordnete AU erfolgreich angelegt<br>";
		}
		else {
			$mesg .= "<br>Fehler beim anlegen der untergeordneten AU<br>";
		}
		
		$url = 'au_childs.php';
	}
}


elseif ( $childou == "") {
	$get_childcn = str_replace ( " ", "_", $childcn );
	$get_childdesc = str_replace ( " ", "_", $childdesc );
	$mesg = "Sie haben den OU der neuen AU nicht angegeben. Dieser ist aber ein notwendiges Attribut.<br>
		Bitte geben Sie ihn an.<br><br>";
	$url = "new_child.php?ou=Hier_OU_eingeben&cn=".$get_childcn."&desc=".$get_childdesc."&childdomain=".$childdomain;
}

elseif ($mainadmin == "none" || $mainadmin == "") {
	$get_childcn = str_replace ( " ", "_", $childcn );
	$get_childdesc = str_replace ( " ", "_", $childdesc );
	$mesg = "Sie haben keinen MainAdmin f&uuml;r die neue AU gew&auml;hlt.<br>
				Bitte w&auml;hlen Sie einen MainAdmin.<br><br>";
	$url = 'new_child.php?ou='.$childou.'&cn='.$get_childcn.'&desc='.$get_childdesc.'&childdomain='.$childdomain;
}


$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>";

?>