#!/usr/bin/php
<?php
error_reporting(0);
function curl_gets($url){
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_HEADER, false);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
  curl_setopt($ch, CURLOPT_ENCODING, 1); 
  curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 5.0; Windows NT 5.0)');
  $data = curl_exec($ch);
  curl_close($ch);
  if (!preg_match('@Server MPM@smi',$data)) {return false;}
  
  $data=preg_replace('@<!DOCTYPE.*?</h1>@smi','',$data);
  $data=str_replace('</body></html>','',$data);
  
return $data;
}

if (!$out=curl_gets('http://127.0.0.1:8080/server-status'))
{
	if (!$out=curl_gets('http://127.0.0.1/server-status'))
	{
		$out='Apache is down...';
	}
}

echo '<?xml version="1.0" encoding="UTF-8"?>
<doc lang="ru" notify="4" favorite="no" func="apachestatus" favicon="favicon-ispmgr.ico" localdir="default/"> 
<messages name="apachestatus">
<msg name="title">Apache Status</msg>
<msg name="hint_name">  </msg>
<msg name="hint_value"></msg>
<msg name="short_new" added="common"></msg>
<msg name="short_delete" added="common"></msg>
<msg name="hint_delete" added="common"></msg>
<msg name="hint_new" added="common"></msg>
<msg name="name" added="common"></msg>
<msg name="value" added="common"></msg>
<msg name="hint_export">  CSV</msg>
<msg name="hint_selectall">   </msg>
<msg name="hint_reloadlist"> </msg>
<msg name="hint_print">   </msg>
<msg name="hint_autoupdate_stop">   </msg>
<msg name="hint_takefavorite">   </msg>
<msg name="hint_takeunfavorite">   </msg>
<msg name="msg_tsetting">  </msg>
</messages>

<metadata name="apachestatus" type="form" key="name" mgr="ispmgr"> 
      <form>
                <field fullwidth="yes" name="outhtml">
<htmldata name="outhtml" />
                </field>
        </form>
</metadata> 

<outhtml>
<![CDATA[
'.$out.'
  ]]>
</outhtml>

</doc>';
?>