Waihangahia he whaiaronga wāhitau WEB PHP + LDAP

Ko te mea i puta he kaupapa nui (te ahua) he maha nga tari mamao me te maha o nga kaiwhakamahi. Ko nga tari katoa e hono ana ki tetahi whatunga me te rohe noa, i tautuhia ia tari i roto i te Active Directory (i muri nei ka kiia ko AD) hei Waehanga Whakahaere (OU), i hangaia kee nga kaiwhakamahi.

He mea tika kia whai waahi nga kaiwhakamahi ki te tere me te ngawari ki te tiki i nga korero whakapiri a te kaimahi e hiahiatia ana mai i te AD, me nga kaiwhakahaere punaha koreutu mai i te mahinga o te whakatika i tetahi konae tuhinga e mahi ana i te waahi o te pukapuka wahitau.

Kaore he whiringa pai kua rite mo te whakaoti rapanga, na me mahi nga mea katoa me oku ringa me oku upoko.

Me timata me te mea tuatahi me whakatau koe he aha te whakamahi, he maamaa - me waatea te raarangi whakamutunga ki nga kaiwhakamahi katoa o te rohe ma te tirotiro. Ko te mea tuatahi ka puta ki te hinengaro ko te PHP me te ldap, ka whakamahia e matou. Ki taku whakaaro ko te painga nui o te whakamahi i te PHP he ngawari noa iho - ka taea e tetahi kaiwhakahaere punaha ahakoa te iti o te mohio ki te whakarereke i te waehere, mena e tika ana, me te kore e tino uaua.

Na, me timata. Tuatahi, me whakarite nga tawhā mo te hono ki te rohe:

$srv ="SERVER";
$srv_domain ="DOMAIN.COM";
$srv_login ="USERNAME@".$srv_domain; 
$srv_password ="PASSWORD";

Ko te waahi e whai ake nei ko te whakatau ko wai te OU ka rapua e matou mo nga kaiwhakamahi. Ka mahia tenei ma te haukoti i nga uara mai i te $_GET['wahi']. Hei tauira, ki te haere te kaiwhakamahi ki te wahitau server/index.php?place=tuatahi, katahi te taurangi $wahi ka tohua te uara tuatahi.

$place = (@$_GET['place']);
$doscript=true;
switch($place){ 
case "first" :
	$dn ="OU=ou1,OU=DOMAIN,dc=DOMAIN,dc=COM";			
	break;
case "second":
	$dn ="OU=ou2,OU=DOMAIN,dc=DOMAIN,dc=COM";			
	break;
	//здесь можно добавить ещё условий.
default:
	$doscript=false; 
	break;
}
if (!$doscript) include "main_table.html";

Taurangi $tuhinga e hiahiatia ana ki te penapena i te uara - ahakoa kua tautuhia e matou te OU e rapu ai matou mo nga kaiwhakamahi, kaore ranei. Mena karekau he whakataetae kua whakarārangihia i roto i te “switch-case”, katahi ka $doscript=false, ko te waahanga matua o te tuhinga ka kore e mahia, ka whakaatuhia te wharangi timatanga “main_table.html” (Ka korerotia e ahau ki a koe mo i te mutunga rawa).

Mena kua tautuhia e matou he OU, ka haere tonu matou ki etahi atu mahi: ka timata matou ki te tuhi i tetahi wharangi whaiaronga mo te kaiwhakamahi:

else if ($doscript) {
{echo "
<!DOCTYPE html> 
<html xmlns='http://www.w3.org/1999/xhtml'>
<head>
<link rel='shortcut icon' href='ico.png'>
<meta charset='windows-1251/ '>

Ka whakauruhia e matou nga momo ahua kia pai ake te ahua (ae, ka taea te whakauru hei konae css, engari ko etahi momo putanga o IE kaore e pai ki te whakaae ki nga momo kua whakaritea penei, na me tuhi tika koe ki roto i te tuhinga):

<style>
	*{text-align: center; font-family:tahoma; font-size:14px;}
	a{text-decoration: none; color: #000;}
	a:hover{text-decoration: underline; color: #0059FF;}
	#bold{text-decoration: none; font-weight: 600;font-size:20px;}
	#table,tr,td{border-style:solid;border-width:1px;	border-collapse:collapse;padding:5px; height:22px;border-color:#7d7d7d;}
	/* Нечетные строки */#table tbody tr:nth-child(odd){background: #fff;}
	/* Четные строки */   #table tbody tr:nth-child(even){background: #F7F7F7;}	
	#noborder{border-width: 0 px; border-style: none;}	
	#sp30px{text-indent: 30px;text-align: justify;}
	#smallsize{font-family:tahoma; text-indent: 5px; text-align:left; font-size:12px;}
	#top {background: #ffffff;
		text-align: center;
		left:0;
		top:0px;
		table-layout: fixed;
		border-style:solid;
		border-width:0px;
		border-collapse:collapse;
		padding:0px;
		height:22px;
		border: 0px;
		z-index: 99999;
		display:block;
		width:80px;
		opacity: 0.6;
		filter: alpha(Opacity=60);
		height:100%;
		position:fixed;}
	#top:hover{background: #afafaf;opacity: 100;filter: alpha(Opacity=100);text-decoration: none;color: #000000;}
	.smalltext{padding-top: 1px;
		padding-bottom: 1px;
		text-align: bottom;
		font-family:tahoma;
		color: #a0a0a0;
		line-height: 7px;
		font-size: 10px;}
	.smalltext:hover{color: #0000ff;}		
	.transition-rotate {position: relative;
		z-index: 2;
		margin: 0 auto;
		padding: 5px;
		text-align: center;
		max-width: 500px;
		cursor: pointer;
		transition: 0.1s linear;}
	.transition-rotate:hover {-webkit-transform: rotate(-2deg);	transform: rotate(-2deg);}
	#lineheight{
		text-align: left;
		line-height: 1px;
		text-decoration: none;
		font-weight: 600;
		font-size:20px;}
</style>

Kua oti i a maatau nga momo, inaianei ka tuhia e matou te taitara o te ripa ka tuhia he hononga pai ki te hoki ki te wharangi matua:

<title>Adressbook of «YourMegaCompanyName»</title>	
</head>
<body style='background-color:#ffffff;'>";
}
echo "
<table id='top'><tr><td id='top'>
<a href='index.php?place=main' id='top' >
<br><br><br>
<img src='back_to_main.png' alt='' border='0' width='75' height='60'/>
<p>На главную</p></a>
</td></tr></table>
";

Ka tautuhia e matou nga whiriwhiringa rapu ma te AD ka whiwhi raraunga mo te OU:

$filter ="(&(objectcategory=user)(!(userAccountControl:1.2.840.113556.1.4.803:=2)))"; //все пользователи, кроме отключенных.
$filter2 ="(objectCategory=OrganizationalUnit)"; // для получения информации о OU
$ds=ldap_connect($srv);   
if ($ds) { 
    $r=ldap_bind($ds,$srv_login,$srv_password);;     
	ldap_set_option($ds,LDAP_OPT_REFERRALS, 0);
	ldap_set_option($ds,LDAP_OPT_PROTOCOL_VERSION,3);
	$sr=ldap_search($ds,$dn ,$filter );   
    ldap_sort($ds,$sr, "givenname");
    $info = ldap_get_entries($ds, $sr); 
    $sr2=ldap_search($ds,$dn ,$filter2 );   
    $placeinfo = ldap_get_entries($ds, $sr2); 
$PlaceName = $placeinfo[0]["l"][0];  			// name of place
$PlaceAddres = $placeinfo[0]["street"][0];		// address of place
$PlaceMail = $placeinfo[0]["description"][0]; 	// mail of place
$PlacePhone = $placeinfo[0]["st"][0]; 		// phone of plase

I muri mai ka hoahoatia e matou te tihi o te wharangi:

echo"<table align='center' height = '80'>
	<td id='noborder' ><div id='lineheight'>". $PlaceName ."</div></td></tr>
	<tr><td id='noborder' >". $PlaceAddres ."</td></tr>
    </table>
<table align='center' id='table'>
	<tr><td width='35' bgcolor = #f0f0e4>  № </td>
	<td width='300' bgcolor = #f0f0e4> Name </td>
	<td width='250' bgcolor = #f0f0e4> E-mail </td>
	<td width='60' bgcolor = #f0f0e4> Phone </td>
	<td width='150' bgcolor = #f0f0e4> Mobile </td></tr>
	<tr><td></td><td> Данные OU </td><td>";
echo "<div class='transition-rotate'><a href=mailto:" . $PlaceMail .">" . $PlaceMail ." </a></div>";
echo "</td><td width='150'> " . $PlacePhone ." </td><td> - </td></tr>";

I muri mai, ka whiwhi me te tukatuka i nga raraunga kaiwhakamahi i roto i te kopikopiko, i te mea hei huna i etahi (hei tauira, ratonga), ka uru noa tatou ki te "huna" ki te mara "ruma" i roto i nga korero a nga kaiwhakamahi i AD, kaore nga kaiwhakamahi penei. ka whakaaturia ki te whaiaronga:

for ($i=0; $i<$info["count"];$i++) { 
$UserHide = $info[$i]["physicaldeliveryofficename"][0];
if ($UserHide != 'hide') {
$UserName = $info[$i]["cn"][0];                //Имя пользователя
$UserPosition = $info[$i]["title"][0]; 		// Должность
$UserMail = $info[$i]["mail"][0];			//mail
if (!$UserMail)) $UserMail = "-";                  //если нет данных о ящике в AD, то отображаем прочерк
$UserIpPhone = $info[$i]["ipphone"][0];		//ip phone
	if (!$UserIpPhone) $UserIpPhone = "-";    //если нет данных о ящике в AD, то отображаем прочерк
$UserMobile = $info[$i]["mobile"][0];		//mobile
	if (!$UserMobile) $UserMobile = "-";     //если нет данных о ящике в AD, то отображаем прочерк

Ma te ara, ki te hiahia koe ki te tiki i te uara o tetahi atu huanga, kia mahara (he mea nui tenei):
i roto i te tono ka tukuna e matou te ingoa huanga pūriki reta, ki te kore ka kore e mahi.

Na ka whakauru i nga raraunga kua riro ki te ripanga:

    echo "<tr>
	<td>". $n+=1 ."</td>
	<td> ". $UserName ."<br> <div class='smalltext'>". $UserPosition ."</div></td><td>"; //	Имя пользователя и должность 
	if ($UserMail !='-') echo "<div class='transition-rotate'><a href=mailto:'$UserMail'>$UserMail  </a></div>";    // если у пользователя есть e-mail создаём ссылку на отправку письма
	else echo "-"; //если нет e-mail - ставим прочерк.
 	echo "<td> ". $UserIpPhone ." </td>
 	<td> ". $UserMobile ." </td></tr>";
	}
}
echo "</table>";

I muri mai, ka kati i te hononga ldap, ka whakaatu ranei i tetahi panui mo te kore e taea te hono atu ki te tūmau:

ldap_close($ds); 
} 
else echo "<h4>Unable to connect to LDAP server</h4>"; 
echo '<br><br><br></body></html>';}

Ko te kōnae "main_table.html" mai i roto he wharangi html ngawari me nga hononga, me te ahua penei:

<head>
<link rel="shortcut icon" href="ico.png"/>
<meta charset="windows-1251"/>
<title>Adressbook of «YourMegaCompanyName»</title>
</head>
<body style='background-color:#ffffff;'>
<center><a href=index.php><IMG border="none" src="logo.png"/></a></center>
<center><b>Places and offices</b></center>
<br>
<table border="0" width="450" bgcolor="#dddddd" align="center" valign="middle" CELLSPACING="0">

<tr id="space"><td></td></tr>
<tr><td align="left" id="abz"><a href="index.php?place=ou1">OU1</a></td></tr>
<tr id="space"><td></td></tr>
<tr><td align="left" id="abz"><a href="index.php?place=ou2">OU2</a></td></tr>

</table></body></html>

Mena ka awhina taku waehere ki tetahi, ka koa ahau, whakamahia!

Ka taea hoki e koe te whakatika noa kia rite ki taau e hiahia ana (whakapai ake/kino) me te tohatoha i nga huarahi katoa.

Mauruuru koe mo to aro!

Source: will.com

Tāpiri i te kōrero