PDA

View Full Version : API Help (PHP)



BMurtagh
05-23-2011, 03:19 PM
So i'm starting to develop a repo of API scripts to be used for our administration, but I'm having issues with PHP include() and now initiating the COM object of the API.

My working directory is: /opt/merak/html/iwc

Directory Structure:
./
./OLD
./list_admin
./disk_usage
./scripts
./images
./css
./includes

In the main iwc folder, I have my index.php and some navigation pages. Once one of these navigation pages are selected, I'm using include() and include a specific php page inside scripts/ to execute. When one of the scripts/ pages is include, it also initializes the API:

scripts/list_admin.php:
include("../includes/init_api.php");

My current workaround was to bring init_api.php in the same directory as the list_admin.php and update my include() string.

With my include lines updated, the error I'm receiving is related to initializing the COM object.


[23-May-2011 14:02:16] PHP Fatal error: Class 'COM' not found in /data/opt/merak/html/iwc/scripts/init_api.php on line 9I cannot figure out why this is happening.. Here is the code for the init.api.php file:


<?php

$acct_api_status = false;
$dom_api_status = false;
$stat_api_status = false;


// Load IW Account APIs
if ($acct_api = new COM("IceWarpServer.AccountObject")) {
$acct_api_status = true;
}

if ($dom_api = new COM("IceWarpServer.DomainObject")) {
$dom_api_status = true;
}

if ($stats_api = new COM("IceWarpServer.AccountObject")) {
$stat_api_status = true;
}

?>

BMurtagh
05-27-2011, 11:23 AM
Turns out COM Objects aren't supported on the Linux platform. IceWarp support sent another way to initialize the API on linux.


<?
/**
* Here are some examples for using IceWarp COM API with IceWarp webserver
* PHP engine
*
* for more info and object function list reffer to merak\api\classes.txt
* for the list of API variables reffer to merak\api\delphi\apiconst.pas
*
*
*
*/

echo "Start API example<br /><br />";

//
// Invoke Global API COM object - "IceWarpServer.APIObject"
//
if($base = icewarp_apiobjectcall(0, '', 'IceWarpServer.APIObject'))
{
echo "IceWarpServer.APIObject invoked<br /><br />";
}
else
{
echo "API couldn't be invoked";
return;
}

//
// Global API - "IceWarpServer.APIObject" usage
//
$domcount =icewarp_apiobjectcall( $base, 'GetDomainCount');
echo "Domain count: $domcount<br />\r\n";

$domlist = icewarp_apiobjectcall( $base, 'GetDomainList');
echo "Domain list: $domlist<br />\r\n";

$domainname = icewarp_apiobjectcall( $base, 'GetDomain', 0);
echo "First domain: $domainname<br />\r\n";
echo "<br />\r\n";

//
// Domain work - "IceWarpServer.DomainObject" usage
//
$dbase = icewarp_apiobjectcall(0, '', 'IceWarpServer.DomainObject');
icewarp_apiobjectcall( $dbase, 'Open', $domainname );

$domname = icewarp_apiobjectcall($dbase,'Name');
echo "Loaded domain: $domname<br />\r\n";

$accnum = icewarp_apiobjectcall($dbase,'GetAccountCount');
echo "Account count: $accnum<br />\r\n";

$acclist = icewarp_apiobjectcall($dbase,'GetAccountList');
echo "Account list: $acclist<br />\r\n";

$acc = icewarp_apiobjectcall($dbase,'GetAccount',0);
echo "First account: $acc<br />\r\n";
echo "<br />\r\n";

//
// Account work - "IceWarpServer.AccountObject" usage
//

$abase = icewarp_apiobjectcall(0, '', 'IceWarpServer.AccountObject');
icewarp_apiobjectcall( $abase, 'Open', $acc );

echo "Loaded account: $acc<br />\r\n";

// get account name and aliases using API variables
$accname = icewarp_apiobjectcall( $abase, 'GetProperty', 'U_Name' );
$accalias = icewarp_apiobjectcall( $abase, 'GetProperty', 'U_Alias' );
echo "Account: name \"$accname\", alias \"$accalias\"<br />\r\n";

$accdom = icewarp_apiobjectcall( $abase, 'Domain' );
echo "Account's domain: $accdom<br />\r\n";
echo "<br />\r\n";

icewarp_apiobjectcall($abase);
icewarp_apiobjectcall($dbase);
icewarp_apiobjectcall($base);

?>