Mercurial > hg > Members > shoshi > webvirt
view app/controllers/vncviewer_controller.php @ 0:261e66bd5a0c
hg init
author | Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 24 Jul 2011 21:08:31 +0900 |
parents | |
children | eb4fee3d9bb8 |
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.", ); 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']); $xml = simplexml_load_string(libvirt_domain_get_xml_desc($dom)); $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"]; trigger_error(self::$ERROR_TABLE[$e]); } } } ?>