Remote control plus générique

Multi mysql serveur compliant :)
This commit is contained in:
Alan Garcia 2013-04-22 13:37:48 +00:00
parent c1d2971463
commit c5357f6be2
2 changed files with 108 additions and 104 deletions

View File

@ -61,10 +61,13 @@ include_once("head.php");
echo "<table class='tedit'>"; echo "<table class='tedit'>";
echo "<tr><th>"._("Hostname")."</th><td>".$infos['serialized_object']['hostname']."</td></tr>"; echo "<tr><th>"._("Hostname")."</th><td>".$infos['serialized_object']['hostname']."</td></tr>";
echo "<tr><th>"._("Start time")."</th><td>".$infos['date_start']."</td></tr>"; echo "<tr><th>"._("Start time")."</th><td>".$infos['date_start']."</td></tr>";
echo "<tr><th>"._("Usefull command")."</th><td><pre>";
echo "ssh ".$mem->user['login']."@".$infos['serialized_object']['hostname']."\n";
echo "rsync ".$mem->user['login']."@".$infos['serialized_object']['hostname']."\n";
echo "</pre></td></tr>";
echo "<tr><td colspan='2'><a href='vm.php?action=stop'>"._("Click here to stop the machine")."</a></td></tr>"; echo "<tr><td colspan='2'><a href='vm.php?action=stop'>"._("Click here to stop the machine")."</a></td></tr>";
echo "</table>"; echo "</table>";
} // empty infos ?> } // empty infos ?>
</div> </div>

View File

@ -38,8 +38,7 @@ class m_lxc implements vm
} }
private function sendMessage($action, $user = FALSE, $password=FALSE, $uid=FALSE) private function sendMessage($params) {
{
$fp = fsockopen($this->IP, $this->PORT, $errno, $errstr, $this->TIMEOUT); $fp = fsockopen($this->IP, $this->PORT, $errno, $errstr, $this->TIMEOUT);
if (!$fp) if (!$fp)
{ {
@ -47,7 +46,7 @@ class m_lxc implements vm
return FALSE; return FALSE;
} }
$msg = sprintf("%s|%s|%s|%d\n", $action, $user, $password, $uid); $msg = sprintf("%s\n", serialize($params) );
if (fwrite ($fp, $msg) < 0) if (fwrite ($fp, $msg) < 0)
{ {
$this->error[] = 'Unable to send data'; $this->error[] = 'Unable to send data';
@ -58,7 +57,6 @@ class m_lxc implements vm
$resp = fgets($fp, 4096); $resp = fgets($fp, 4096);
fclose ($fp); fclose ($fp);
return $resp; return $resp;
if (stripos($resp, 'error') > 0) if (stripos($resp, 'error') > 0)
@ -76,7 +74,7 @@ class m_lxc implements vm
public function start($login = FALSE, $pass = FALSE, $uid = FALSE) public function start($login = FALSE, $pass = FALSE, $uid = FALSE)
{ {
global $mem, $db, $err; global $mem, $db, $err, $mysql;
if ($this->getvm() !== FALSE) if ($this->getvm() !== FALSE)
{ {
@ -84,11 +82,14 @@ class m_lxc implements vm
return FALSE; return FALSE;
} }
$user = $login ? $login : $mem->user['login']; $login = $login ? $login : $mem->user['login'];
$pass = $pass ? $pass : $mem->user['pass']; $pass = $pass ? $pass : $mem->user['pass'];
$uid = $uid ? $uid : $mem->user['uid']; $uid = $uid ? $uid : $mem->user['uid'];
$res = $this->sendMessage('start', $user, $pass, $uid); $msgg = array('action'=>'start', 'login'=>$login, 'pass' => $pass, 'uid'=> $uid);
$msgg['mysql_host'] = $mysql->dbus->Host;
$res = $this->sendMessage($msgg);
if ($res === FALSE) if ($res === FALSE)
return $this->error; return $this->error;
else else
@ -149,7 +150,7 @@ class m_lxc implements vm
$uid = $mem->user['uid']; $uid = $mem->user['uid'];
$vid = $vm['id']; $vid = $vm['id'];
if ($this->sendMessage('stop', $vm_id, FALSE, FALSE) === FALSE) if ($this->sendMessage(array('action' => 'stop', 'vm' => $vm_id)) === FALSE)
return FALSE; return FALSE;
return $db->query("UPDATE vm_history SET date_end = NOW() WHERE uid = '$uid' AND id = '$vid' LIMIT 1"); return $db->query("UPDATE vm_history SET date_end = NOW() WHERE uid = '$uid' AND id = '$vid' LIMIT 1");