I have implemented a object model, which should be extensible enough to implement different providers for managing IIS.
Method Description
- Get Retrieves a value for a named property from the object.
- GetDataPaths Retrieves the paths to all locations of a metabase property subordinate to a specified starting path.
- GetEx Retrieves a value or values for a named single-valued or multivalued property of the object.
- GetInfo Reloads the object with property values that exist in the metabase.
- GetPropertyAttribObj Retrieves an object that contains the property’s attributes. This object can then be used to etrieve individual attributes of ADSI properties.
- Put Sets the value for a named property of an object.
- PutEx Sets the value or values for a named single-valued or multivalued property of the object.
- SetInfo Writes the object property values to the metabase.
This was writen quite some time ago, however I will publish it as it simple works.
<?php
/**
* @package IIS
* @version $Id: IIS.php,v 0.1 2004/05/28 11:51:28 Andrew M. Johnstone Exp $
* @Copyright © 2003-2004 Andrew M. Johnstone (andrew@ajohnstone.com)
*/
class IIS { // extends COM { // extending Com dies()…
/**
* COM Object Parameters
* @var array
* @access public
*/
public $param=array(
‘Provider’ => ‘IIS’,
‘MachineName’ => null, // . or localhost or computername
‘ObjectPath’ => null
);
/**
* COM Object
* @var object
* @access public
*/
public $Com=null;
public function
__construct($command=null, $MachineName=‘localhost’, $ObjectPath=‘’) {
if (!isset(
$this->param[‘MachineName’])) $this->param[‘MachineName’]=$MachineName;
if (!isset(
$this->param[‘ObjectPath’])) $this->param[‘ObjectPath’]=$ObjectPath;
switch(
$command) {
case
‘Start’ : $this->StartServer(); break;
case
‘Continue’ : $this->ContinueServer(); break;
case
‘Pause’ : $this->PauseServer(); break;
case
‘Stop’ : $this->StopServer(); break;
}
try {
$this->Com = new Com(“{$this->param[Provider]}://{$this->param[MachineName]}{$this->param[ObjectPath]}”);
} catch (
com_exception $e) {
die(
“TERMINATED:: n”. print_r($e));
} catch (
Exception $e) {
die(
“TERMINATED:: n”. print_r($e));
}
}
public function
__destruct() { unset($this->Com); }
public function
__call($_callee) {
try {
switch(
$_callee) {
case
‘Start’ : return $this->Com->Start();
case
‘Continue’ : return $this->Com->Continue();
case
‘Pause’ : return $this->Com->Pause();
case
‘Stop’ : return $this->Com->Stop();
}
} catch (
exception $e) { var_dump($e); }
}
/**
* Display IIS Structure
* @var object
* @var int
* @access public
*/
public function DisplayTree($Obj, $Level) { //Recursive
if ( ($Obj->Class == “IIsWebServer”) Or ($Obj->Class == “IIsFtpServer”)) {
print
“{$Obj->Name} - {$Obj->ServerComment}n”;
} else {
print
“{$Obj->Name}n”;
}
foreach (
$Obj as $CurrentObj) $this->DisplayTree($CurrentObj, $Level+1);
}
/**
* @WakeUp & Think;)
*
*/
public function DisplayNode($MachineName=‘localhost’, $ObjectPath=null) {
$this->param[‘ObjectPath’]=$ObjectPath;
$this->param[‘MachineName’]=$MachineName;
switch(
$this->Com->Class) {
case
“IIsComputer” :
return array(
‘MemoryCacheSize’=>$this->Com->MemoryCacheSize,
‘MaxBandwidth’=>$this->Com->MaxBandWidth
);
case
“IIsWebVirtualDir” :
return array(
‘Path’=>$this->Com->path,
‘Defaultdocument’=>$this->Com->DefaultDoc,
‘UNCUserName’=>$this->Com->UNCUserName,
‘Directorybrowsing’=>$this->Com->EnableDirBrowsing,
‘ReadAccess’=>$this->Com->AccessRead,
‘WriteAccess’=>$this->Com->AccessWrite,
);
case
“IIsFtpVirtualDir” :
return array(
‘Path’=>$this->Com->path,
‘UNCUserName’=>$this->Com->UNCUserName,
‘ReadAccess’=>$this->Com->AccessRead,
‘WriteAccess’=>$this->Com->AccessWrite,
);
case
“IIsWebService” :
return array(
‘DirectoryBrowsing’=>$this->Com->EnableDirBrowsing,
‘DefaultDocument’=>$this->Com->DefaultDoc,
‘ScriptAccess’=>$this->Com->AccessScript,
‘ExecuteAccess’=>$this->Com->AccessExecute
);
case
“IIsFtpService” :
return array(
‘EnablePortAttack’=>$this->Com->EnablePortAttack,
‘LowerCaseFiles’=>$this->Com->LowerCaseFiles
);
case
“IIsWebServer” :
return array(
‘1stBinding’=>$this->Com->ServerBindings(0,0),
‘State’=>$this->ServerState($this->Com->ServerState),
‘KeyType’=>$this->Com->KeyType
);
case
“IIsFtpServer” :
return array(
‘State’=>$this->ServerState($this->Com->ServerState),
‘GreetingMessage’=>$this->Com->GreetingMessage,
‘ExitMessage’=>$this->Com->ExitMessage,
‘MaxClients Message’=>$this->Com->MaxClientsMessage,
‘AnonymousOnly’=>$this->Com->AnonymousOnly,
);
case (
“IIsWebService” or “IIsFTPService” or ‘IIsWebServer’ or ‘IIsFTPServer’) :
return array(
‘ServerComment’=>$this->Com->ServerComment,
‘AnonymousUserName’=>$this->Com->AnonymousUserName,
‘DefaultLogonDomain’=>$this->Com->DefaultLogonDomain,
‘MaxConnections’=>$this->Com->MaxConnections,
‘ConnectionTimeout’=>$this->Com->ConnectionTimeout,
‘ReadAccess’=>$this->Com->AccessRead,
‘WriteAccess’=>$this->Com->AccessWrite,
‘Log’=>$this->Com->DontLog,
);
}
}
/**
* Strut
* @var int
* @access public
* @return string
*/
public function ServerState($StateVal) {
switch (
$StateVal) {
case
1 : return ‘Starting’;
case
2 : return ‘Started’;
case
3 : return ‘Stopping’;
case
4 : return ‘Stopped’;
case
5 : return ‘Pausing’;
case
6 : return ‘Paused’;
case
7 : return ‘Continuing’;
default: return
‘Unknown!’;
}
}
/**
* Backups Located at %systemroot%system32inetsrvMetaBack
* @var (bool)$Force (Overwrite)
*/
public function backupMetaBase($Name=null, $Version=-1, $Force=0) {
$Name=(!isset($Name))? ‘Created - Backup ‘.time () : ‘Custom Backup - ‘. $Name;
$this->param[‘ObjectPath’]=null;
$this->param[‘MachineName’]=‘localhost’;
//parent::__construct();
try {
$this->Com->Backup($Name, $Version, $Force);
} catch (
com_exception $e) {
print_r($e);
}
}
/**
* Backups Located at %systemroot%system32inetsrvMetaBack
*/
public function restoreMetaBase($Name=null, $Version=-2) {
$Flag=0;
$this->param[‘ObjectPath’]=null;
$this->param[‘MachineName’]=‘localhost’;
//parent::__construct();
try {
// NOTE: ** All IIS services will be stopped by this method, then restarted!
$this->Com->Restore($Name, $Version, $Flag);; // NOTE: for restoration, Flag MUST be 0
} catch (com_exception $e) {
print_r($e);
}
}
}
class
IISWeb extends IIS {
public function
__construct() { }
public function
FindWeb($MachineName=‘localhost’, $WebName=null) {
$this->param[‘ObjectPath’]=‘’;///W3svc
$this->param[‘MachineName’]=$MachineName;
parent::__construct();
//View Scope
foreach ($this->Com as $obj) echo $obj->Name . “n”;
/**
* print $this->Com->W3svc->1;
*
* —
*
* $this->Com->IISADMIN
* $this->Com->Logging
* $this->Com->W3SVC
* $this->Com->MimeMap
* $this->Com->MSFTPSVC
* $this->Com->SmtpSvc
* $this->Com->EventManager
*/
}
public function
mkWebDir() {} // @Stub
public function rmWebDir() {} // @Stub
public function chAccess() { /* OBJ->Put */ } // @Stub
}
/***************** *****************/
$IIS = new IIS();
//$IIS->Start();
//$IIS->Stop();
//$IIS->Pause();
//$IIS->Continue();
//print_r( $IIS->DisplayNode() );
$IISWeb = new IISWeb();
//$IISWeb->FindWeb();
//$IISWeb->DisplayTree(new Com("IIS://localhost"), 0);
$IIS->backupMetaBase();
?>