Ankündigung

Einklappen
Keine Ankündigung bisher.

Ldap PC beschreibung ändern

Einklappen

Neue Werbung 2019

Einklappen
X
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

  • Ldap PC beschreibung ändern

    Guten Tag ich bräuchte bitte Hilfe sitze schon seit einigen Stunden an dem Problem und komme nicht weiter.

    Fehlermeldung:

    An error occurred. Error number 10: Referral
    SERVER-1
    mein Serverdddddd -> was über ide Eingabe übergeben wird
    mein Server -> ist der Oringinaleintrag

    Laut Apache2 Log

    ldap_modify(): Modify: Referral in /var/www/html/admin/edit.php on line 50, referer: http://10.10.10.102/admin/ldappclabel.php

    doch Ich sehe ihn nicht den Fehler.

    PHP-Code:
    <html>
    <head>
    </head>
    <body>

    <?php
    include '../config/db.php';
    include 
    '../datamy.php';
    $select=("SELECT `id`, `ldap_username`, `ldap_password`, `ldap_connection` FROM `system-ad` WHERE 1 ");
    $db_erg mysqli_query$db_link$select );
    if ( ! 
    $db_erg )
    {
      die(
    'Ungültige Abfrage: ' mysqli_error());
    }
     while (
    $row mysqli_fetch_array$db_ergMYSQLI_ASSOC))
    {
           
    $ldap_id=($row['id']);
          
    $ldap_username=($row['ldap_username']);
         
    $ldap_password=($row['ldap_password']);
        
    $ldap_connection=($row['ldap_connection']);
    }    

    $ldap_connection1 ldap_connect("$ldap_connection");


     function 
    ldapTimeToUnixTime($ldapTime) {
    $secsAfterADEpoch $ldapTime 10000000;
    $ADToUnixConverter = ((1970 1601) * 365 round((1970 1601) / 4)) * 86400;
    return 
    intval($secsAfterADEpoch $ADToUnixConverter);
    }

     if (
    FALSE === $ldap_connection1){
        
    // Uh-oh, something is wrong...
     
    echo 'Unable to connect to the ldap server';
    }

    // We have to set this option for the version of Active Directory we are using.
    ldap_set_option($ldap_connection1LDAP_OPT_PROTOCOL_VERSION3) or die('Unable to set LDAP protocol version');
    ldap_set_option($ldap_connection1LDAP_OPT_REFERRALS0); // We need this for doing an LDAP search.

    if (TRUE === ldap_bind($ldap_connection1$ldap_username$ldap_password))
    $Pc$_POST["rechner"];
    $dn "CN=$Pc,CN=Computer,CN=Configuration,DC=XXX,DC=XXX";


        
    $beschreibung["description"] = $_POST["label"];

    //    $result = ldap_mod_replace($ldap_connection1, $dn, $newuser);
    // modify data in the directory
    $result ldap_modify($ldap_connection1$dn$beschreibung);

    // if successful, display success message
    if ($result) {
        echo 
    "Entry with DN " $dn " modified in LDAP directory.";
    }
    // else display error
    else {
        echo 
    "An error occurred. Error number " ldap_errno($ldap_connection1) . ": " ldap_err2str(ldap_errno($ldap_connection1));
    }
    echo 
    $_POST['rechner'];
    echo 
    $_POST['label'];
    // all done? clean up
    ldap_close($ldap_connection1);

    ?> </head> </html>
    zum abfragen Benutze ich diesen eintrag und der Funktioniert

    PHP-Code:
    $select=("SELECT `id`, `ldap_username`, `ldap_password`, `ldap_connection` FROM `system-ad` WHERE 1 ");
    $db_erg = mysqli_query( $db_link, $select );
    if ( ! $db_erg )
    {
      die('Ungültige Abfrage: ' . mysqli_error());
    }
     while ($row = mysqli_fetch_array( $db_erg, MYSQLI_ASSOC))
    {
           $ldap_id=($row['id']);
          $ldap_username=($row['ldap_username']);
         $ldap_password=($row['ldap_password']);
        $ldap_connection=($row['ldap_connection']);
    }    
    $domain=$ldap_connection;
    $splitted=explode(".",$domain,2);
    //print_r($splitted);
    $host=$splitted[0];
    $domain=$splitted[1];
    $ldap_connection1 = ldap_connect("$ldap_connection");


     function ldapTimeToUnixTime($ldapTime) {
    $secsAfterADEpoch = $ldapTime / 10000000;
    $ADToUnixConverter = ((1970 - 1601) * 365 - 3 + round((1970 - 1601) / 4)) * 86400;
    return intval($secsAfterADEpoch - $ADToUnixConverter);
    }

     if (FALSE === $ldap_connection1){
        // Uh-oh, something is wrong...
     echo 'Unable to connect to the ldap server';
    }

    // We have to set this option for the version of Active Directory we are using.
    ldap_set_option($ldap_connection1, LDAP_OPT_PROTOCOL_VERSION, 3) or die('Unable to set LDAP protocol version');
    ldap_set_option($ldap_connection1, LDAP_OPT_REFERRALS, 0); // We need this for doing an LDAP search.

    if (TRUE === ldap_bind($ldap_connection1, $ldap_username, $ldap_password)){
     //Your domains DN to query

        $ldap_base_dn = "DC=$host,DC=$domain";

     //Get standard users and contacts
       $search_filter = '(|(objectCategory=computer)(objectCategory=schema)(objectsAMAccountName=samaccountname)(objectDescription=description)(objectOperatingSystem=operatingSystem)(objectOperatingSystemVersion=operatingsystemversion)(objectlastLogon=lastlogon)(objectlastLogoff=lastlogoff)(objectmemberOf=memberof)(objectmember=member))';

     //Connect to LDAP
     $result = ldap_search($ldap_connection1, $ldap_base_dn, $search_filter);

        if (FALSE !== $result){
     $entries = ldap_get_entries($ldap_connection1, $result);

     // Uncomment the below if you want to write all entries to debug somethingthing
     //var_dump($entries);

     //Create a table to display the output
     echo '<br>';
     echo '<table width="80%" border = "1"><tr bgcolor="#cccccc"><td>PC Name</td><td>Beschreibung</td><td>Operating System</td><td>Operating System Version</td><td>Letztes Logon</td><td>Letztes Logoff</td><td>Mitglied von</td></tr>';
     //For each account returned by the search


     for ($x=0; $x<$entries['count']; $x++){



     //Windows Usernaame
     $LDAP_samaccountname = "";

     if (!empty($entries[$x]['samaccountname'][0])) {
     $Samaccountname = $entries[$x]['samaccountname'][0];
     $LDAP_samaccountname = substr($Samaccountname,0, -1);
     if ($LDAP_samaccountname == "NULL"){
     $LDAP_samaccountname= "";
     }
     } else {
     //#There is no samaccountname s0 assume this is an AD contact record so generate a unique username

     //$LDAP_uSNCreated = $entries[$x]['usncreated'][0];
     //$LDAP_samaccountname= "COMPUTER_" . $LDAP_uSNCreated;
     }
     $Description = "";

     if (!empty($entries[$x]['description'][0])) {
     $Description = $entries[$x]['description'][0];
     if ($Description == "NULL"){
     $Description = "";
     }
     }
     $operatingSystem = "";
    if (!empty($entries[$x]['operatingsystem'][0])) {
     $operatingSystem = $entries[$x]['operatingsystem'][0];
     if ($operatingSystem == "NULL"){
     $operatingSystem = "";
     }
     }

     $OperatingSystemVersion = "";

     if (!empty($entries[$x]['operatingsystemversion'][0])) {
     $OperatingSystemVersion = $entries[$x]['operatingsystemversion'][0];
     if ($OperatingSystemVersion == "NULL"){
     $OperatingSystemVersion = "";
     }
     }

    $lastLogon = "";

     if (!empty($entries[$x]['lastlogon'][0])) {
    $lastLogon = $entries[$x]['lastlogon'][0];
    $unixTimestamp = ldapTimeToUnixTime($lastLogon);
    $lastLogon1 = date('d M Y H:i:s ',$unixTimestamp);
    if ($lastLogon == "NULL"){
     $lastLogon = "";
     }
    }

    $lastLogoff = "";

     if (!empty($entries[$x]['lastlogoff'][0])) {
    $lastLogoff = $entries[$x]['lastlogoff'][0];
    $unixTimestamp = ldapTimeToUnixTime($lastLogoff);
    echo date('d M Y H:i:s ',$unixTimestamp);
    if ($lastLogoff == "NULL"){
    $lastLogoff = "";
     }
    }

     $memberOf = "";

     if (!empty($entries[$x]['memberof'][0])) {
     $memberOf = $entries[$x]['memberof'][0];
     if ($memberOf == "NULL"){
     $memberOf = "";
     }
     }

    ?>
     <tr><form action="edit.php" method="post" target="">
    <td><strong><input type="Text" name="rechner" value="<?php echo $LDAP_samaccountname?>" size="20"></td>
    <td><input type="Text" name="label" value="<?php echo $Description?>" size="30" maxlength="30"></td>
    <td><input type="Text" name="" value="<?php echo $operatingSystem?>" size="30" maxlength=60"></td>
    <td><input type="Text" name="" value="<?php echo $OperatingSystemVersion?>" size="30" maxlength="30"></td>  
    <td><input type="Text" name="" value="<?php echo $lastLogon1?>" size="20" maxlength="15"></td>
    <td><input type="Text" name="" value="<?php echo $lastLogoff?>" size="20" maxlength="15"></td>
    <td><input type="Text" name="" value="<?php echo $memberOf?>" size="60" maxlength="60"></td>
    <td><input type="Submit" name="LogIn" value="aendern"></td>
    <td><input type="reset"></td>
    </tr>  
    </form></tr>
    <?php
    ......... geht noch Weiter!!

  • #2
    Was gibt https://www.php.net/manual/de/function.ldap-error.php aus?
    sorry, shift-taste kaputt

    Kommentar


    • #3
      Hallo Meister danke für deinen Tip

      ldap_error: Protocol error
      ldap_get_option: 0000202B: RefErr: DSID-031007EF, data 0, 1 access points ref 1: 'xxx.xxx'

      jetzt werde ich mal weiter schauen

      Kommentar


      • #4
        Nach langen hin und her habe ich es hin bekommen doch es Funktioniert nur in der OU Computers.
        was mache ich den wenn ich nicht Weis in welcher OU der PC ist

        kann ich nicht irgend wie die OU mir ausgeben lassen und dann beim ändern ergenzen

        PHP-Code:

         $ldap_connection1 
        ldap_connect("$ldap_connection");

         function 
        ldapTimeToUnixTime($ldapTime) {
        $secsAfterADEpoch $ldapTime 10000000;
        $ADToUnixConverter = ((1970 1601) * 365 round((1970 1601) / 4)) * 86400;
        return 
        intval($secsAfterADEpoch $ADToUnixConverter);
        }

        $domain=$ldap_connection;
        $splitted=explode(".",$domain,2);
        //print_r($splitted);
        $host=$splitted[0];
        $domain=$splitted[1];
        $ldap_connection1 ldap_connect("$ldap_connection");

         if (
        FALSE === $ldap_connection1){
            
        // Uh-oh, something is wrong...
         
        echo 'Unable to connect to the ldap server';
        }

        // We have to set this option for the version of Active Directory we are using.
        ldap_set_option($ldap_connection1LDAP_OPT_PROTOCOL_VERSION3) or die('Unable to set LDAP protocol version');
        ldap_set_option($ldap_connection1LDAP_OPT_REFERRALS0); // We need this for doing an LDAP search.

        if (TRUE === ldap_bind($ldap_connection1$ldap_username$ldap_password)){
        $Pc$_POST["rechner"];
        $label$_POST['label'];

        $dn =  "DC=$host,DC=$domain";

        $nur_dieses = array("ou");

        $sr=ldap_list($ldap_connection1$dn"ou=*"$nur_dieses);

        $info1 ldap_get_entries($ldap_connection1$sr);

        for (
        $i=0$i<$info1["count"]; $i++)
            echo 
        $info1[$i]["ou"][0] ;




        $sr=ldap_search($ldap_connection1$dn"cn=$Pc");


          echo 
        "Ergebnis der Suche ".$sr."<br />";

            echo 
        "Anzahl gefundenen Einträge ".ldap_count_entries($ldap_connection1,$sr)."<br />";

            echo 
        "Einträge holen ...<br />";
            
        $info ldap_get_entries($ldap_connection1$sr);
            echo 
        "Daten für ".$info["count"]." Items gefunden:<br />";

            for (
        $i=0;$i<$info["count"];$i++) {

               echo 
        "DN ist: "$info[$i]["dn"] ."<br />";
               echo 
        "erster cn Eintrag: "$info[$i]["cn"][0] ."<br />";
               echo 
        "erster Beschreibung Eintrag: "$info[$i]["description"][0] ."<br /><hr />";
            }
        /*  
        echo "Ergebnis der Änderung ".$sr."<br />";
        echo "ldap_error: " . ldap_error($ldap_connection1);
        ldap_get_option($ldap_connection1, LDAP_OPT_DIAGNOSTIC_MESSAGE, $err);
        echo "ldap_get_option: $err";
        */

        $dn1 =  "CN=$Pc,CN=Computers,DC=$host,DC=$domain";
        $lab[description][0]=$label;
        $sr=ldap_modify($ldap_connection1$dn1$lab);

        // all done? clean up
        ldap_close($ldap_connection1);
        }
        ?> </head> </html> 
        ich habe versucht mit diesem befehl das zu übernehmen aber geht leider nicht weil
        der Rechner noch mal in einer anderen angezeigt wird

        echo "erster cn Eintrag: ". $info[$i]["cn"][0] ."<br />";

        Ausgabe des Scriptes:
        OU Gruppen
        COOL-OBJECTS OU Gruppe
        Domain Controllers

        CN Gruppen
        Builtin
        Computers
        ForeignSecurityPrincipalsInfrastructureLostAndFoun dManaged
        Service
        AccountsNTDS
        QuotasProgram
        DataSystemUsersErgebnis der Suche Resource id #8

        Ergebnis der Suche Resource id #11
        Anzahl gefundenen Einträge 1
        Einträge holen ...
        Daten für 1 Items gefunden:
        DN ist: CN=T530-LENO,CN=Computers,DC=test,DC=local
        erster cn Eintrag: T530-LENO
        erster Beschreibung Eintrag: Mein PC Notbookfdsfs

        wie Kann ich das ändern das CN oder OU übernommen wird.
        hier
        $dn1 = "CN=$Pc,CN=Computers,DC=$host,DC=$domain";
        $lab[description][0]=$label;
        $sr=ldap_modify($ldap_connection1, $dn1, $lab);

        Ich suche ja den PC vorher mit dem Namen ich weis ja nicht wo er Ist ob in cn oder ou

        ldap_search($ldap_connection1, $dn, "cn=$Pc");

        wie kann ich das übernehmen


        "erster cn Eintrag: ". $info[$i]["dn"][0] ."<br />";

        beim suchforgang für Ldap modifiy als $dn1 dan wäre alles Gut.

        Domaincontroller ausgabe aber immer nur die 1 Ausgabe ist OK


        CN=SERVER-1,OU=Domain Controllers,DC=test,DC=local
        CN=T530-LENO,CN=Computers,DC=test,DC=local





        Kommentar


        • #5
          danke habs selber hin bekommen

          Kommentar

          Lädt...
          X