Ok, here is the new code
<?php
class abyss_user_accounts{
var $XMLfile = "";
var $XMLparser;
var $tag_is = array();
var $hosts_output = array();
function abyss_user_accounts($file){
$this->output = array();
$this->XMLfile = $file;
$this->Generate($this->XMLfile);
}
function abyss_user_accounts_for_host($host_id=-1){
//print "<pre>" .print_r($this->hosts_output, true). "</pre>";
if( $host_id == -1 ) return $this->hosts_output;
else{
if( isset($this->hosts_output[$host_id]) ){
if( empty($this->hosts_output[$host_id]) ) return "There are no users for host id #$host_id";
else return $this->hosts_output[$host_id];
}else return "There is no host with an id of $host_id";
}
}
function Generate($XMLfile){
if( $fp = @fopen($XMLfile,"r")){
$this->XMLparser = xml_parser_create();
xml_set_object($this->XMLparser, $this);
xml_parser_set_option($this->XMLparser, XML_OPTION_CASE_FOLDING, 0);
xml_parser_set_option($this->XMLparser, XML_OPTION_SKIP_WHITE, 1);
xml_set_element_handler($this->XMLparser, array(&$this, "startElement"), array(&$this, "endElement"));
xml_set_character_data_handler($this->XMLparser, array(&$this, "characterData"));
while( $data = fread($fp, 4096)){
if(! xml_parse($this->XMLparser, $data, feof($fp)) ){
die( sprintf("XML error: %s at line %d", xml_error_string(xml_get_error_code($this->XMLparser)), xml_get_current_line_number($this->XMLparser)));
}
}
xml_parser_free($this->XMLparser);
}else{
print "<br /><b>ERROR</b>: Could not open XML file ". $XMLfile ."<br />";
}
}
function startElement($parser, $name, $attrs){
$attnames = array_keys($attrs);
$tag_is = $this->tag_is;
//print ":".$name."<br />";
switch( $name ){
case "root" : if( empty($tag_is) ) $tag_is = array("root"); break;
case "server" : $tag_is[1] ="server"; break;
case "host" : $tag_is[2] = "host"; $this->add2output = false; break;
case "id" : $tag_is[3] = "id"; break;
case "users" : $tag_is[3] = "users"; $this->tmp_usr_arr = array(); break;
case "user" : $tag_is[4] = "user"; break;
case "name" : if( $tag_is[4] == "user" ) $tag_is[5] = "name"; break;
case "password" : if( $tag_is[4] == "user" ) $tag_is[5] = "password"; break;
}
$this->tag_is = $tag_is;
}
function endElement($parser, $name){
$tag_is = $this->tag_is;
switch( $name ){
case "root" : if( $tag_is[1] != "server" ) $tag_is = array(); break;
case "server" : $tag_is[1] =""; break;
case "host" : $tag_is[2] = ""; break;
case "id" : $tag_is[3] = ""; break;
case "users" : $tag_is[3] = ""; break;
case "user" : $tag_is[4] = ""; break;
case "name" : if( $tag_is[4] == "user" ) $tag_is[5] = ""; break;
case "password" : if( $tag_is[4] == "user" ) $tag_is[5] = ""; break;
}
$this->tag_is = $tag_is;
}
function characterData($parser, $data){
$data = trim($data);
$tag_is = $this->tag_is;
$hosts_output = $this->hosts_output;
if(! empty($data) )
if( $tag_is[0] == "root" )
if( $tag_is[1] == "server" )
if( $tag_is[2] == "host" )
if( $tag_is[3] == "users" ){
if( $tag_is[4] == "user" ){
if( $tag_is[5] == "name" ) $this->tmp_usr = $data;
else
if( $tag_is[5] == "password" ){
if( $this->add2output ) $hosts_output[$this->tmp_host_id][$this->tmp_usr] = $data;
else
if(! $this->add2output ) $this->tmp_usr_arr[$this->tmp_usr] = $data;
}
}
}else
if( $tag_is[3] == "id" ){
$this->tmp_host_id = $data;
if( empty($this->tmp_usr_arr) ){
$hosts_output[$this->tmp_host_id] = array();
$this->add2output = true;
}else{
$hosts_output[$this->tmp_host_id] = $this->tmp_usr_arr;
$this->add2output = false;
}
}
$this->hosts_output = $hosts_output;
}
}
// Add the path to your abyss.conf file.
$file = "C:\\Program Files\\Abyss Web Server\\abyss.conf";
//$file = "/home/anthony/projects/abyss.conf";
// Let's lookup the current Host so we know which Users to Pull.
$host_id = $_SERVER['INSTANCE_ID'];
//$host_id = -1;
$otpt = new abyss_user_accounts($file);
// This just assigns $output variable, the array of the accounts
$output = $otpt->abyss_user_accounts_for_host($host_id);
// Last but not least, output it!
print "<pre>" .print_r($output, true). "</pre>";
?>
Some notes:
use -1 for the host id to get a list of all users
more functionality can be added quite easily as the whole user list can be accessed