Integrating UMRA with a Web System using PHP
First you will have to create a simple UMRA script called “AD – Get All Users” (for example) which queries active directory for all user accounts in the domain. It places the list of accounts in a table, which can be referenced by the table’s variable. You can see on the left hand side of the screen is a list of a few actions UMRA can perform. You might notice that this whole process of querying AD and creating the list is done in one step – the Generate generic table action.The generic table can be configured by double-clicking on the Generate Generic Table script action and activating the necessary tabs.
In the LDAP binding tab I changed the option to a manual Binding string and input the variables which I will be passing in through my PHP code (%DomainController% and %Domain%).
In the LDAP Filter tab I had initially used the example drop down list and selected the “All Users” example. This produced the LDAP search filter within the text box. This search filter can be modified further or can be created manually without using the example.
I specified the attributes which I wanted UMRA to pull back from Active Directory and even applied a conversion for the accountExpires attribute, which is a 100 nanosecond value, to obtain a valid date-time value for UMRA.
In order to test the query you will have to provide values in the Variable list tab. Testing the generic table is not required.
Integrating the UMRA All Users table with PHP
Once the UMRA project has been configured and tested, you may now call it using the COM object provided by the UMRA Automation module. The COM object allows you to use almost any programming language in Windows to access your project. In this case we use PHP, but we could have set this up in VBScript, JScript, ASP, ASP.Net, even Java.Below is the code for the PHP file. Copy this to your website, change the variable values and access the file. You will see a preformatted array of your users. You can change the way this displays by modifying the code below.
<?php
session_start(); // start up your PHP session!
//start up UMRA if it's not already started
$appconf;
if(!isset($appconf['UMRA'])){
$appconf['UMRA']=new COM("UMRAcom.UMRA") or die("Cannot start UMRA for you. ".
"The UMRA DLL may not be registered.");
}
//set some variables for later use
$appconf['UMRA_Server'] = 'localhost'; //the name of the UMRA server
$appconf['UMRA_Port'] = 56814;
$appconf['DC'] = 'systemDC1'; //the domain controller that you will talk to
$appconf['DomainFQDN'] = 'dev.domain.local'; //the FQDN of the domain
$appconf['DomainLDAP'] = 'DC=DEV,DC=DOMAIN,DC=LOCAL'; //the root OU of the domain
$appconf['DBName'] = 'ADManagementSuite'; //the name of your database, UMRA will use this
$appconf['DBTablePrefix'] = ''; //this might be used, but currently isn't
$appconf['DBServerName'] = 'dbservername'; //database server for UMRA logging
//this is on a Windows box, but we are running Apache for MySQL and PHP.
//I know PHP runs in IIS too, but I like the Web Developer Server Suite, so there you go.
$appconf['rootDirectoryLocation'] = 'C:/www/vhosts/localhost/ADManagementSuite/';
$appconf['URLRoot'] = 'http://localhost/ADManagementSuite/';
//if we could not connect then die ($retval should === 0)
$retval = $appconf['UMRA']->Connect($appconf['UMRA_Server'],$appconf['UMRA_Port']))
if(($retval != 0){
die("Error: ".$retval."<br />Could not connect to UMRA server.");
}
//setup UMRA to use the variables we set above.
$appconf['UMRA']->SetVariableText("%DomainController%",$appconf['DC']);
$appconf['UMRA']->SetVariableText("%Domain%",$appconf['DomainLDAP']);
//Execute the script get a list of all users in the Active Directory domain
$appconf['UMRA']->ExecuteProjectScript("AD - Get All Users");
//create the table object which would hold the table from UMRA
$usersDT = new COM("UMRAcom.UmraDataTable");
//get the table from UMRA
$appconf['UMRA']->GetVariableDataTable("%M_Users%",$usersDT);
//format the table object to be a PHP array, for later use.
$usersArray = UMRADataTable::getArrayFromDT($usersDT);
/*
You can do whatever you want with the $usersArray now.
Most people would display it as a list or in a table of some sort.
Below this code is a support class. This would usually go into another
file, but for the purposes here I just included it at the bottom.
*/
echo "<pre>";
print_r($usersArray);
echo "</pre>";
/**
* Class UMRADataTable is a static class intended to process a
* UMRADataTable to a PHP-compatible format (like an array).
* This is not necessary to have since the UMRADataTable can be read by
* PHP, but it's handy to reformat the datatable to make it easier to sort.
*/
class UMRADataTable{
function UMRADataTable(){}
function __contruct(){}
public static function getArrayFromDT($dt){
if(($rows = $dt->GetRowCount()) > 0){
$row = 0;
$outArr = array();
while($row < $rows){
$colRetVal = 0;
$col = 0;
while($colRetVal == 0){
$cellval = "";
$colRetVal = $dt->GetCellText($row, $col, $cellval);
if($colRetVal == 0){
$outArr[$row][$col++] = $cellval;
}
}
$row++;
}
return $outArr;
}else{
return array();
}
}
}
?>