<?php
define('mysql_host',"192.168.0.74");
define('mysql_user',"root");
define('mysql_pass',"mailvision");
define('mysql_schema',"mvstatus");
function execute_ssh_command($host, $port, $user, $pass_or_key, $cmd){
$connection=null;
if(is_readable($pass_or_key)){
$connection = ssh2_connect($host, $port,array('hostkey'=>'ssh-rsa'));
if (!ssh2_auth_pubkey_file($connection,$user,"$pass_or_key.pub",$pass_or_key)){
return false;
}
}
else {
$connection = ssh2_connect($host, $port);
if (ssh2_auth_password($connection, $user, $pass_or_key)===FALSE) {
return false;
}
}
$stream = ssh2_exec($connection, $cmd);
stream_set_blocking($stream, true);
return stream_get_contents($stream);
}
function get_machine_from_db(){
$connection=mysql_connect(mysql_host,mysql_user,mysql_pass);
mysql_select_db(mysql_schema,$connection);
$query = "SELECT * FROM machine";
$result=mysql_query($query,$connection);
$machines=array();
while($machine=mysql_fetch_array($result)){
$id=$machine['id'];
$query = "SELECT * FROM service where machine_id = '$id'";
$result2=mysql_query($query,$connection);
while($service=mysql_fetch_array($result2)){
$machine['services'][]=$service;
}
$machines[$id]=$machine;
}
mysql_close($connection);
return $machines;
}
function getService($service_id){
$connection=mysql_connect(mysql_host,mysql_user,mysql_pass);
mysql_select_db(mysql_schema,$connection);
$query = "SELECT * FROM service WHERE id='$service_id' LIMIT 1";
$result=mysql_query($query,$connection);
$service=mysql_fetch_array($result);
$m_id=$service['machine_id'];
$query = "SELECT * FROM machine WHERE id='$m_id'";
$result=mysql_query($query,$connection);
$machine=mysql_fetch_array($result);
$service['machine']=$machine;
return $service;
}
?>