220 echo "</body> |
221 echo "</body> |
221 </html>\n"; |
222 </html>\n"; |
222 } |
223 } |
223 } |
224 } |
224 |
225 |
|
226 function login($target, $headl="") |
|
227 { |
|
228 /** zeigt Login-Form, prueft userid und passwort, leitet zu gewuenschter Seite weiter |
|
229 * Authentifizierung gegen LDAP |
|
230 * Parameter |
|
231 * $target Zieladresse |
|
232 * $headl Ueberschrift Loginform |
|
233 */ |
|
234 |
|
235 session_start(); |
|
236 if ($_SESSION["userid"]) |
|
237 { |
|
238 header("Location: $target"); |
|
239 exit; |
|
240 } |
|
241 |
|
242 |
|
243 |
|
244 $login = $_POST["login"]; |
|
245 $log = $_POST["log"]; |
|
246 |
|
247 if ($login) |
|
248 { |
|
249 include_once($_SERVER['DOCUMENT_ROOT'] ."/fhiiqm/inc/dbconnect.inc.php"); |
|
250 if (!isset($dbc) || !$dbc) $dbc = new dbconnection(); |
|
251 |
|
252 $stmt = $dbc -> stmtinit(); |
|
253 if (is_object($stmt)) |
|
254 { |
|
255 $stmt -> prepare("SELECT userid FROM userweb WHERE userid = ?"); |
|
256 $stmt -> bind_param('s',$log["user"]); |
|
257 $result = $stmt -> execute(); |
|
258 // $stmt -> store_result(); // wegen weiterer query dies oder $stmt -> free_result(); |
|
259 } |
|
260 if ($result) |
|
261 { |
|
262 $ldaphost = "ldap.rz-berlin.mpg.de"; // ldap server |
|
263 $ldapport = 389; // Die Portnummer ldap server |
|
264 $ldapconn = ldap_connect( $ldaphost, $ldapport ) |
|
265 or die( "Keine Verbindung zu {$ldaphost} möglich" ); |
|
266 $stmt->bind_result($userid); |
|
267 if ($stmt->fetch()) |
|
268 { |
|
269 $ldaprdn = "uid=" . $log["user"].",ou=people,dc=ppb,dc=rz-berlin,dc=mpg,dc=de"; |
|
270 $ldappwd = $log["pass"]; |
|
271 ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3); |
|
272 ldap_set_option($ldapconn, LDAP_OPT_REFERRALS, 0); |
|
273 if ($ldapbind = @ldap_bind($ldapconn, $ldaprdn, $ldappwd)) |
|
274 { |
|
275 ldap_close($ldapconn); |
|
276 $_SESSION = array(); |
|
277 $_SESSION["userid"] = $userid; |
|
278 |
|
279 // Recht |
|
280 $stmt -> free_result(); // wegen weiterer query |
|
281 $sql = "SELECT recht_ID FROM user_recht WHERE userid = '$userid'"; |
|
282 if ($res = $dbc -> queryObjectArray($sql)) |
|
283 { |
|
284 $arecht = array(); |
|
285 foreach ($res as $row) |
|
286 { $arecht[] = $row->recht_ID;} |
|
287 if (count($arecht)>0) |
|
288 $_SESSION["recht"] = $arecht; |
|
289 else |
|
290 $_SESSION["recht"] = null; |
|
291 } |
|
292 else |
|
293 { |
|
294 $_SESSION["recht"] = null; |
|
295 // echo "error_recht: " . $dbc->error . "<br />"; |
|
296 } |
|
297 // print_r($arecht); |
|
298 |
|
299 // Recht Produkt-Gruppe |
|
300 $sql = "SELECT prod_group_ID FROM user_prodgroup WHERE userid = '$userid'"; |
|
301 if ($re = $dbc -> queryObjectArray($sql)) |
|
302 { |
|
303 $pgrecht = array(); |
|
304 foreach ($re as $row) |
|
305 { $pgrecht[] = $row->prod_group_ID;} |
|
306 if (count($pgrecht)>0) |
|
307 $_SESSION["prodg"] = $pgrecht; |
|
308 else |
|
309 $_SESSION["prodg"] = null; |
|
310 } |
|
311 else |
|
312 $_SESSION["prodg"] = null; |
|
313 header("Location: $target"); |
|
314 exit; |
|
315 } |
|
316 else |
|
317 $err2 = "<br /><span class=\"red\">Passwort ist nicht korrekt</span>\n"; |
|
318 } |
|
319 else |
|
320 $err1 = "<br /><span class=\"red\">Username ist nicht korrekt</span>\n"; |
|
321 |
|
322 } |
|
323 } |
|
324 if ($err1 || $err2 || !$log) |
|
325 { |
|
326 ?> |
|
327 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
|
328 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> |
|
329 |
|
330 <head> |
|
331 <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> |
|
332 <link href="/fhiiqm/css/db.css" rel="STYLESHEET" type="TEXT/CSS" /> |
|
333 |
|
334 <title>Login fhiiqm</title> |
|
335 </head> |
|
336 |
|
337 <body onload="document.flogin.user.focus();"> |
|
338 <!-- <div class="float-r"><img src="img/document_mark_as_final.png" border="0" alt="Verträge" title="Verträge"/></div> --> |
|
339 |
|
340 <?php |
|
341 include ($_SERVER['DOCUMENT_ROOT'] ."/fhiiqm/form/login_form.inc.php"); |
|
342 echo "</body> |
|
343 </html>\n"; |
|
344 } |
|
345 } |
|
346 |
225 function duplicate_record ($table, $key_name, $key_value, $auto=1) |
347 function duplicate_record ($table, $key_name, $key_value, $auto=1) |
226 { |
348 { |
227 /** dupliziert Datensatz in table |
349 /** dupliziert Datensatz in table |
228 * Parameter |
350 * Parameter |
229 * $table Tabellenname |
351 * $table Tabellenname |
315 } |
437 } |
316 return $dbw; |
438 return $dbw; |
317 } |
439 } |
318 else |
440 else |
319 return 0; |
441 return 0; |
|
442 } |
|
443 |
|
444 function ldap_replace($sn,$gn,$title,$roomnr,$tel,$mail,$dep,$ag) |
|
445 { |
|
446 /** ersetzt bestehende Eintraege von LDAP-Objektklassen |
|
447 * erstellt weiteres Attribut zu Telefon und Arbeitsgruppe, falls erforderlich |
|
448 * |
|
449 * Parameter |
|
450 * $sn |
|
451 * $gn - givenName |
|
452 * $title |
|
453 * $roomnr - roomNumber |
|
454 * $tel[] - telephonNumber |
|
455 * $mail |
|
456 * $dep - departmentNumber |
|
457 * $ag[] - physicalDeliveryOfficeName |
|
458 * */ |
|
459 include_once($_SERVER['DOCUMENT_ROOT'] ."/fhiiqm/inc/conf.inc.php"); |
|
460 $ldaphost = "ldap.rz-berlin.mpg.de"; // Ihr ldap servers |
|
461 $ldapport = 389; // Die Portnummer ihres ldap servers |
|
462 global $ldapconn; |
|
463 global $ldapbd; |
|
464 |
|
465 // Verbindung zu LDAP |
|
466 if (!$ldapconn) $ldapconn = ldap_connect( $ldaphost, $ldapport ); |
|
467 ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3); |
|
468 ldap_set_option($ldapconn, LDAP_OPT_REFERRALS, 0); |
|
469 $ldapbd = @ldap_bind($ldapconn, $ldaprdn, $ldappwd); |
|
470 // echo "ldapbd=$ldapbd, ldaprdn=$ldaprdn<br />"; |
|
471 |
|
472 if ($ldapbd) |
|
473 { |
|
474 $base="ou=people,dc=ppb,dc=rz-berlin,dc=mpg,dc=de"; |
|
475 $uid = ldap_search_uid($sn,$gn); |
|
476 //Parameter abfragen |
|
477 if ($uid) |
|
478 { |
|
479 $dn = "uid=".$uid .",ou=people,dc=ppb,dc=rz-berlin,dc=mpg,dc=de"; |
|
480 // echo "dn-mod = $dn<br />"; |
|
481 $su = array("ä","ö","ü","ß","Ä","Ö","Ü"); |
|
482 $rp = array("ae","oe","ue","ss","Ae","Oe","Ue"); |
|
483 $gn = str_replace($su,$rp,$gn); |
|
484 $sn = str_replace($su,$rp,$sn); |
|
485 $entry["sn"] = $sn; |
|
486 $entry["givenName"] = $gn; |
|
487 if (isset($title) && $title) $entry["title"] = $title; |
|
488 if (isset($roomnr) && $roomnr) $entry["roomNumber"] = $roomnr; |
|
489 if (isset($mail) && $mail) $entry["mail"] = $mail; |
|
490 if (isset($dep) && $dep) $entry["departmentNumber"] = $dep; |
|
491 // print_r ($entry); echo "ldapconn=$ldapconn: single<br />"; |
|
492 $result1 = ldap_mod_replace($ldapconn, $dn, $entry); |
|
493 if (!$result1) |
|
494 { |
|
495 printf("LDAP-Fehlernummer replace: %s<br>\n", ldap_errno($ldapconn)); |
|
496 printf("LDAP-Fehler replace: %s<br>\n", ldap_error($ldapconn)); |
|
497 } |
|
498 |
|
499 if (is_array($tel) && $tel) |
|
500 { |
|
501 $entry2["telephoneNumber"] = array(); |
|
502 $result = ldap_mod_del($ldapconn, $dn, $entry2); |
|
503 if (!$result) |
|
504 { |
|
505 printf("LDAP-Fehlernummer del1: %s<br>\n", ldap_errno($ldapconn)); |
|
506 printf("LDAP-Fehler del1: %s<br>\n", ldap_error($ldapconn)); |
|
507 } |
|
508 foreach ($tel as $telf) |
|
509 if ($telf > "!") $entry2["telephoneNumber"][] = $telf; |
|
510 } |
|
511 if (is_array($ag) && $ag) |
|
512 { |
|
513 $entry3["physicalDeliveryOfficeName"] = array(); |
|
514 $result = ldap_mod_del($ldapconn, $dn, $entry3); |
|
515 if (!$result) |
|
516 { |
|
517 printf("LDAP-Fehlernummer del2: %s<br>\n", ldap_errno($ldapconn)); |
|
518 printf("LDAP-Fehler del2: %s<br>\n", ldap_error($ldapconn)); |
|
519 } |
|
520 foreach ($ag as $agr) |
|
521 if ($agr > "!") $entry2["physicalDeliveryOfficeName"][] = $agr; |
|
522 } |
|
523 // print_r ($entry2); echo ": multiple<br />"; |
|
524 $result2 = ldap_mod_add($ldapconn, $dn, $entry2); |
|
525 if (!$result2) |
|
526 { |
|
527 printf("LDAP-Fehlernummer add: %s<br>\n", ldap_errno($ldapconn)); |
|
528 printf("LDAP-Fehler add: %s<br>\n", ldap_error($ldapconn)); |
|
529 } |
|
530 |
|
531 $filter = "(uid=".$uid.")"; |
|
532 $afields = array ("uid","cn","givenName","sn","title","userPassword","mail","departmentNumber","telephoneNumber","roomNumber","physicalDeliveryOfficeName"); |
|
533 if (!($search=@ldap_search($ldapconn,$base,$filter,$afields))) die("Unable to search ldap server"); |
|
534 echo "<div align = 'center'>LDAP-Eintrag nach Änderung 1<br />"; |
|
535 $info = ldap_get_entries($ldapconn, $search); |
|
536 $bg1 = "#F8F8F8"; |
|
537 $bg2 = "#DEDFE1"; |
|
538 $bg = "#FFFFFF"; |
|
539 // print_r ($info); echo "<br /><br />"; |
|
540 |
|
541 echo "<table border='0' cellspacing='2' cellpadding='2'>\n |
|
542 <tr bgcolor='#68ACBF'><th>sn</th><th>givenName</th><th>cn</th><th>title</th><th>uid</th><th>userPassword</th><th>mail</th> |
|
543 <th>departmentNumber</th><th>telephoneNumber</th><th>roomNumber</th><th>physicalDeliveryOfficeName</th></tr>\n"; |
|
544 for ($i=0; $i<$info["count"]; $i++) |
|
545 { |
|
546 if ($bg == $bg1) $bg = $bg2; else $bg = $bg1; |
|
547 echo "<tr bgcolor='" . $bg . "'>"; |
|
548 echo "<td>". $info[$i]["sn"][0]."</td>"; |
|
549 echo "<td>". $info[$i]["givenname"][0]."</td>"; |
|
550 echo "<td>". $info[$i]["cn"][0]."</td>"; |
|
551 echo "<td>". $info[$i]["title"][0]."</td>"; |
|
552 echo "<td>". $info[$i]["uid"][0]."</td>"; |
|
553 echo "<td>". $info[$i]["userpassword"][0]."</td>"; |
|
554 echo "<td>". $info[$i]["mail"][0]."</td>"; |
|
555 echo "<td>". $info[$i]["departmentnumber"][0]."</td>"; |
|
556 $stel = ""; |
|
557 foreach ($info[$i]["telephonenumber"] as $tel) |
|
558 $stel .= $tel . ", "; |
|
559 echo "<td>". substr($stel,strpos($stel,",")+1,strlen(substr($stel,strpos($stel,",")+1))-2) . "</td>"; |
|
560 echo "<td>". $info[$i]["roomnumber"][0]."</td>"; |
|
561 $sag = ""; |
|
562 foreach ($info[$i]["physicaldeliveryofficename"] as $ag) |
|
563 $sag .= $ag . ", "; |
|
564 echo "<td>". substr($sag,strpos($sag,",")+1,strlen(substr($sag,strpos($sag,",")+1))-2) . "</td>"; |
|
565 echo "</tr>\n"; |
|
566 } |
|
567 echo "</table>"; |
|
568 echo "</div>\n"; |
|
569 |
|
570 if (!$result1 || !$result2) return 0; else return 1; |
|
571 } |
|
572 else |
|
573 { |
|
574 echo "Nutzer '".$gn ." " . $sn ."' konnte nicht identifiziert werden."; |
|
575 return 0; |
|
576 } |
|
577 } |
320 } |
578 } |
321 |
579 function ldap_search_uid($sn,$gn) |
|
580 { |
|
581 /** Suchrt uid des gegebenen Nutzers |
|
582 * |
|
583 * Parameter |
|
584 * $sn |
|
585 * $gn - givenName |
|
586 * */ |
|
587 |
|
588 include_once($_SERVER['DOCUMENT_ROOT'] ."/fhiiqm/inc/conf.inc.php"); |
|
589 $ldaphost = "ldap.rz-berlin.mpg.de"; // Ihr ldap servers |
|
590 $ldapport = 389; // Die Portnummer ihres ldap servers |
|
591 |
|
592 // Verbindung zu LDAP |
|
593 if (!$ldapconn) $ldapconn = ldap_connect( $ldaphost, $ldapport ); |
|
594 ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3); |
|
595 ldap_set_option($ldapconn, LDAP_OPT_REFERRALS, 0); |
|
596 if (!$ldapbd) $ldapbd = @ldap_bind($ldapconn, $ldaprdn, $ldappwd); |
|
597 |
|
598 if ($ldapbd) |
|
599 { |
|
600 $base="ou=people,dc=ppb,dc=rz-berlin,dc=mpg,dc=de"; |
|
601 $su = array("ä","ö","ü","ß","Ä","Ö","Ü"); |
|
602 $rp = array("ae","oe","ue","ss","Ae","Oe","Ue"); |
|
603 $afields = array ("uid"); |
|
604 $filter = "(cn=" . $gn . " " . $sn .")"; |
|
605 $search=@ldap_search($ldapconn,$base,$filter,$afields); |
|
606 if (!ldap_count_entries($ldapconn,$search)) |
|
607 { |
|
608 $gnr = str_replace($su,$rp,$gn); |
|
609 $snr = str_replace($su,$rp,$sn); |
|
610 $filter = "(cn=" . $gnr . " " . $snr .")"; |
|
611 $search=@ldap_search($ldapconn,$base,$filter,$afields); |
|
612 } |
|
613 if (!ldap_count_entries($ldapconn,$search)) |
|
614 |
|
615 { |
|
616 $gn = utf8_encode($gn); |
|
617 $sn = utf8_encode($sn); |
|
618 $filter = "(cn=" . $gn . " " . $sn .")"; |
|
619 $search=@ldap_search($ldapconn,$base,$filter,$afields); |
|
620 } |
|
621 if (ldap_count_entries($ldapconn,$search)) |
|
622 { |
|
623 $info = ldap_get_entries($ldapconn, $search); |
|
624 for ($i=0; $i<$info["count"]; $i++) |
|
625 $uid = $info[$i]["uid"][0]; |
|
626 } |
|
627 echo " $filter<br />"; |
|
628 if (isset($uid) && $uid) return $uid; |
|
629 else return null; |
|
630 } |
|
631 } |
322 ?> |
632 ?> |