Jump to content

Recommended Posts

Hope someone can help me with this. Here is what I am trying to do... I am using a wordpress plugin that authenticates to Active Directory, however when the user logs in I need the php page to check for the group the user belongs to and if they are part of a particular group they will have certain access on the site. Here is the part of the code that I am using which does not seem to work, when they login it does not detect the group that they are in...

 

$str = shell_exec('./grouptestfull.php -u'.$LoggedInUsername);

 

calls grouptestfull.php which is this...

 

#!/usr/bin/php -q 
<?php 
/* 
Version 1 - inital version 
*/ 

error_reporting(0); 

$arguments = getopt("u:"); 
//print_r($arguments); 

print $arguments['u']; 
//print grouptestfull($loggedinusersusername); 

echo grouptestfull($arguments['u']); 

function grouptestfull($gtfusernamein) 
{ 
    // clear the flags 
    $validhr = false; 
    $validinf = false; 
    $validroot = false; 

    //print "username as receved by function ".$gtfusernamein."<br>"; 
    $gtfusername = "";  
    $gtfusername = $gtfusernamein.""; 

    //print "processed username ".$gtfusername."<br><hr>"; 
    include("adLDAP.php"); 
    try 
    { 
     $gtfadldapedit = new adLDAP(); 
    } 
    catch (adLDAPException $e)  
    { 
     echo $e; exit(); 
    } 

    //check group membership 
    if(($gtfadldapedit->user_ingroup($gtfusername."","SD.HR"))) 
    { 
        $validhr = true; 
    } 

    if(($gtfadldapedit->user_ingroup($gtfusername."","SD.INF"))) 
    { 
        $validinf = true; 
    } 
     
    if(($gtfadldapedit->user_ingroup($gtfusername."","SD.ROOT"))) 
    { 
        $validroot = true; 
    } 
     
    //sort and return highest lvl group membership 
    if ($validroot) 
    { 
        return "validroot"; 
    } 
    else 
    { 
        if ($validinf) 
        { 
            return "validinf"; 
        }     
        if ($validhr) 
        { 
            return "validhr"; 
        } 
        else 
        { 
            //return ""; 
        } 
    } 
}      
?>  

 

I get no errors in the php error log, but just can't figure out why this is not working.

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/259894-not-sure-why-this-is-not-working/
Share on other sites

This doesn't seem right, but I have to ask questions to be sure:

 

//print "username as receved by function ".$gtfusernamein."<br>"; 
    $gtfusername = "";  
    $gtfusername = $gtfusernamein.""; 

 

Why not just do this instead and what is the point of the "" at the end?

 

$gtfusername = $gtfusernamein;

 

Also, just to be sure, from reading your print text, I don't understand if you are saying this is a function ($gtfusernamein) or it is just a statement. Because the way you have $gtfusernamein now, it is a variable. If it is to be a function, then it should be this instead gtfusernamein().

  • 2 weeks later...
  • 2 weeks later...

Thanks for the reply, I tried that and still does not seem to work. The code was given to me by someone so not sure why it was done this way. Any suggestions on making this work would be great.

 

mabey when you set repto_error(0); to 1 mabey it will show youre error?

  • 2 weeks later...

I turned on error reporting and don't get any errors. I was able to add some additional tests to the script and when doing so it always returns "null" and does not determine what group the users is in. Here is the new code I am using... any help would be appreciated.

 


<?php

ini_set('display_errors', 1);    
error_reporting (E_ALL); 

$arguments = getopt("u");

echo grouptestfull($arguments['u']);

function grouptestfull($user)
{

require_once(dirname(__FILE__) . '/adLDAP.php');
$adldap = new adLDAP();


try {
  	     $ldap_db = new adLDAP();
   	    }
catch (adLDAPException $e) 
    {
    	     echo $e; exit();
    	    }
// clear the flags

$validhr = false;
$validinf = false;
$validroot = false;
//check group


if(($ldap_db->user_ingroup($user,"SD.HR", true)))
{
echo "\nvalidhr\n";
$validhr = true;

}

if(($ldap_db->user_ingroup($user,"SD.INF", true)))
{
echo "\nvalidinf\n";
$validinf = true;
}

if(($ldap_db->user_ingroup($user,"SD.ROOT", true)))
{
echo "\nvalidroot\n";
$validroot = true;
}

//sort and return highest lvl group membership
if ($validroot)
{

return "validroot";
echo "validroot"; //for testing only
}
else
{
echo "GOT HERE1"; //for testing only
if ($validinf)
	{

		return "validinf";
		echo "validinf"; //for testing only
	}
	else
	{
		if ($validhr)
			{
				;
				return "validhr";
				echo "Validhr"; //for testing only
			}
			else
			{
				echo "null"; //for testing only
				return "";
			}
	}
}

}  
echo "GOT HERE2";   //for testing only
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.