21 include_once(dirname(__FILE__) .
'/vm.class.php');
42 $this->IP =
variable_get(
'lxc_ip',
'',
"IP address of the Alternc's LXC server. If empty, no LXC server.", array(
'desc' =>
'IP address',
'type' =>
'ip'));
43 $this->PORT =
variable_get(
'lxc_port',
'6504',
"Port of the Alternc's LXC server", array(
'desc' =>
'Port',
'type' =>
'integer'));
44 $this->KEY =
variable_get(
'lxc_key',
'',
"Shared key with the Alternc's LXC server", array(
'desc' =>
'Shared key',
'type' =>
'string'));
45 $this->maxtime =
variable_get(
'lxc_maxtime',
'4',
"How many hours do we allow to have a server before shutting it down", array(
'desc' =>
'Max time',
'type' =>
'integer'));
57 'title' => _(
"Console access"),
71 $msg->log(
"lxc",
"alternc_del_member");
72 $db->query(
"DELETE FROM vm_history WHERE uid= ?", array(
$cuid));
86 $fp = @fsockopen($this->IP, $this->PORT, $errno,
$errstr, $this->TIMEOUT);
88 $this->error[] =
'Unable to connect';
92 $params[
'server'] = $L_FQDN;
95 $moreparams =
$hooks->invoke(
"lxc_params", array($params));
96 foreach ($moreparams as
$p) {
97 foreach (
$p as $k => $v) {
102 $message = serialize($params);
103 if (fwrite($fp, $message .
"\n") < 0) {
104 $this->error[] =
'Unable to send data';
107 $resp = fgets($fp, 8192);
110 $data = @unserialize($resp);
112 if (isset($data[
'error']) && $data[
'error'] > 0) {
113 $this->error[] = $data[
'msg'];
128 if ($this->
getvm() !== FALSE) {
129 $msg->raise(
"ERROR",
'lxc', _(
'VM already started'));
135 $pass = $pass ? $pass :
$mem->user[
'pass'];
138 $message = array(
'action' =>
'start',
'login' =>
$login,
'pass' => $pass,
'uid' =>
$uid);
139 $message[
'mysql_host'] = $mysql->dbus->Host;
142 if (
$res === FALSE) {
145 $data = unserialize(
$res);
146 $error = (int) $data[
'error'];
147 $hostname = $data[
'hostname'];
148 $message = $data[
'msg'];
149 $date_start =
'NOW()';
153 $msg->raise(
"ERROR",
'lxc', _($message));
156 $db->query(
"INSERT INTO vm_history (ip,date_start,uid,serialized_object) VALUES (?, ?, ?, ?);", array($hostname, $date_start,
$uid,
$res));
169 $message = array(
'action' =>
'get',
'login' =>
$login);
174 return unserialize(
$res);
182 $vm = $this->
getvm();
186 if ($this->
sendMessage(array(
'action' =>
'stop',
'vm' => $vm[
'vm'])) === FALSE) {
variable_get($name, $default=null, $createit_comment=null)
Return a persistent variable.
Manage AlternC's virtual machine (Containers) start/stop using our own inetd-based protocol.
m_lxc()
Constructor, initialize the class informations from AlternC's variables.
hook_menu()
HOOK: add the "Console Access" to AlternC's main menu.
start($login=FALSE, $pass=FALSE, $uid=FALSE)
START a Virtual Machine on the remote VM manager for user $login having hashed password $pass and uid...
stop()
Stop the currently running VM.
hook_admin_del_member()
HOOK: remove VM history for AlternC account.
sendMessage($params)
Send a message to a remote VM manager instance $params are the parameters to send as serialized data ...