Mercurial > hg > Members > shoshi > webvirt
view app/controllers/vncviewer_controller.php @ 1:eb4fee3d9bb8
added StoragePools management functions (storage_controller)
author | Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 27 Jul 2011 00:00:25 +0900 |
parents | 261e66bd5a0c |
children |
line wrap: on
line source
<?php class VncviewerController extends AppController { public $uses = null; public $name = "Vncviewer"; public static $ERROR_TABLE = array( 0 => "uuid is required to process this action", 1 => "vnc is not supported.", 2 => "domain is inactive.", ); public function exec() { if(!isset($this->params['url']['uuid'])){ $this->redirect(array("action" => "error","?" => array("e" => 0)),200,true); } $con = WebVirtUtil::GetConnection(); $dom = libvirt_domain_lookup_by_uuid_string($con,$this->params['url']['uuid']); $info = libvirt_domain_get_info($dom); if($info["state"] != VIR_DOMAIN_RUNNING){ $this->redirect(array("action" => "error","?" => array("e" => 2)),200,true); } $xml = simplexml_load_string(libvirt_domain_get_xml_desc($dom,null)); $port = -1; foreach($xml->devices->graphics as $graphic){ $attributes = $graphic->attributes(); if(strcmp($attributes->type,"vnc") == 0 && strcmp($attributes->listen,"127.0.0.1") != 0){ $port = (int)$attributes->port; } } if($port != -1){ $hostname = $_SERVER["SERVER_NAME"]; $this->set("hostname",$hostname); $this->set("port",$port); }else{ $this->redirect(array("action" => "error","?" => array("e" => 1)),200,true); } } public function error() { if(isset($this->params["url"]["e"])){ $e = (int)$this->params["url"]["e"]; $this->set("content",self::$ERROR_TABLE[$e]); } } } ?>