#!/usr/bin/php
<?php
error_reporting(0);
$cnf_file=file_get_contents('/root/.my.cnf');
$error='';
if (preg_match('@user.*?=(.*)@',$cnf_file,$user)&&preg_match('@password.*?=(.*)@',$cnf_file,$password))
{
	$user[1]=trim($user[1]);
	$password[1]=str_replace('"','',trim($password[1]));
	
	$sql_link= mysqli_connect('localhost',$user[1], $password[1]);
	if (!$sql_link)
	{
		$error=mysqli_connect_error();
	}
}
else {
	$error='Check User and Password in file /root/.my.cnf';
}

$out=$error;

if (!$error)
{
$sql = mysqli_query($sql_link,"SHOW FULL PROCESSLIST");

	while ($rowclubs = mysqli_fetch_array($sql))
	{	
$color='';
if ($rowclubs['Time']>'0'){
	$color='color="red"';
	
}
if ($rowclubs['Command']=='Daemon'){continue;}

$out.='
<elem '.$color.'>
<Id>'.$rowclubs['Id'].'</Id>
<User>'.$rowclubs['User'].'</User>
<Host>'.$rowclubs['Host'].'</Host>
<DB>'.$rowclubs['db'].'</DB>
<Command>'.$rowclubs['Command'].'</Command>
<Time>'.$rowclubs['Time'].'</Time>
<State>'.$rowclubs['State'].'</State>
<Info>'.$rowclubs['Info'].'</Info>
</elem>';
	}
	
}

echo '<?xml version="1.0" encoding="UTF-8"?>
<doc lang="ru" notify="4" func="sqlstatus" favorite="no" favicon="favicon-ispmgr.ico" > 
<messages name="sqlstatus">
<msg name="title">SQL 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="Id" added="common">ID</msg>
<msg name="User" added="common"></msg>
<msg name="Host" added="common"></msg>
<msg name="DB" added="common"> </msg>
<msg name="Command" added="common"></msg>
<msg name="Time" added="common"> </msg>
<msg name="State" added="common"></msg>
<msg name="Info" 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="sqlstatus" type="list" key="name" mgr="ispmgr"> 
<coldata> 
<col type="data" name="Id" sort="digit" sorted="-1"/> 
<col type="data" name="User" sort="alpha" /> 
<col type="data" name="Host" sort="alpha" /> 
<col type="data" name="DB" sort="alpha" /> 
<col type="data" name="Command" sort="alpha" /> 
<col type="data" name="Time" sort="digit" /> 
<col type="data" name="State" sort="alpha" /> 
<col type="data" name="Info" sort="alpha" wrap="yes" /> 
</coldata> 
</metadata> 
<tparams>
<out>devel</out>
<func>sqlstatus</func>
</tparams>
<p_sort>Id</p_sort>
<p_order>desc</p_order>
'.$out.'

</doc>';
?>