# HG changeset patch # User Shoshi TAMAKI # Date 1313487096 -32400 # Node ID c3adb28473d66702adaf6751b3479fe6104c1f15 # Parent 7201fd354bdf9afb5e1584a4ccf8107abe317c5f modified icon feature diff -r 7201fd354bdf -r c3adb28473d6 app/controllers/icon_controller.php --- a/app/controllers/icon_controller.php Sun Aug 14 23:52:31 2011 +0900 +++ b/app/controllers/icon_controller.php Tue Aug 16 18:31:36 2011 +0900 @@ -8,19 +8,31 @@ public function index() { + $this->autoRender = false; $icon_dir = "../icon"; //relative path without slash - $this->autoRender = false; $icon_default = "/default.png"; //file name must include slash $icon_file = $icon_default; - if(isset($this->params["url"]["uuid"])){ - $icon_file = "/".$this->params["url"]["uuid"]."png"; + if(isset($_GET["uuid"])){ + $uuid = $_GET["uuid"]; + if($this->IsUUID($uuid)){ + $icon_file = "/".$uuid.".png"; + }else{ + $this->RenderError("Invalid UUID."); + return; + } } $icon = @file_get_contents($icon_dir.$icon_file); if($icon === FALSE){ //failed to get icon - $icon = file_get_contents($icon_dir.$icon_default); + $icon = @file_get_contents($icon_dir.$icon_default); + if($icon === FALSE){ + //print error code here. + $err = error_get_last(); + $this->RenderErorr($err["message"]); + return; + } } header("Content-Type: image/png"); @@ -29,10 +41,99 @@ public function EditIcon() { + if(!isset($this->params["url"]["uuid"])){ + $this->set("content","Domain ID is required."); + $this->render("error"); + return; + } + + $uuid = $this->params["url"]["uuid"]; + if(!$this->IsUUID($uuid)){ + $this->RenderError("Invalid UUID."); + } + + $this->autoRender = true; + + $this->set("max_size",ini_get("post_max_size")); + $this->set("uuid",$uuid); + } + + public function DeleteIcon() + { + $this->autoRender = true; + + if(!isset($_POST["uuid"])){ + $this->RenderError("Domain ID is required."); + return; + } + + $uuid = $_POST["uuid"]; + if($this->IsUUID($uuid)){ + $this->RenderError("Invalid UUID."); + return; + } + + $icon_name = "../icon/".$_POST["uuid"].".png"; + $result = @unlink($icon_name); + if(!$result){ + $err = error_get_last(); + $this->RenderError($err["message"]); + } } public function SaveIcon() { + if(!isset($_POST["uuid"])){ + $this->set("content","Domain ID is required."); + $this->render("error"); + return; + } + + $uuid = $_POST["uuid"]; + if(!$this->IsUUID($uuid)){ + $this->RenderErorr("Invalid UUID"); + } + + $this->set("uuid",$uuid); + $tmp_name = $_FILES["icon"]["tmp_name"]; + + if(is_uploaded_file($tmp_name) === FALSE){ + $this->RenderError("Failed to upload file"); + return; + } + + $img = @imagecreatefrompng($tmp_name); + if($img === FALSE){ + $this->RenderError("Failed to create image from uploaded file"); + return; + } + + $width = 81; + $height = 81; + $resized_img = @imagecreatetruecolor($width,$height); + @imagecopyresampled($resized_img,$img,0,0,0,0,$width,$height,imagesx($img),imagesy($img)); + + $target_name = "../icon/".$_POST["uuid"].".png"; + if(@imagepng($resized_img,$target_name) === FALSE){ + $this->RenderError("Failed to save image"); + return; + } + + $this->autoRender = true; + } + + public function RenderError($_msg) + { + $this->set("content",$_msg); + $this->render("error"); + } + + public function IsUUID($_uuid) + { + if(preg_match("/[a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12}/",$_uuid)){ + return true; + } + return false; } } diff -r 7201fd354bdf -r c3adb28473d6 app/tmp/cache/persistent/cake_core_default_ja --- a/app/tmp/cache/persistent/cake_core_default_ja Sun Aug 14 23:52:31 2011 +0900 +++ b/app/tmp/cache/persistent/cake_core_default_ja Tue Aug 16 18:31:36 2011 +0900 @@ -1,2 +1,2 @@ -1313333340 +1313486890 a:1:{s:11:"LC_MESSAGES";a:0:{}} diff -r 7201fd354bdf -r c3adb28473d6 app/tmp/cache/persistent/cake_core_dir_map --- a/app/tmp/cache/persistent/cake_core_dir_map Sun Aug 14 23:52:31 2011 +0900 +++ b/app/tmp/cache/persistent/cake_core_dir_map Tue Aug 16 18:31:36 2011 +0900 @@ -1,2 +1,2 @@ -1313333340 +1313486895 a:7:{s:35:"/home/shoshi/work/webvirt/cake/libs";a:25:{i:0;s:35:"/home/shoshi/work/webvirt/cake/libs";i:1;s:41:"/home/shoshi/work/webvirt/cake/libs/cache";i:2;s:46:"/home/shoshi/work/webvirt/cake/libs/controller";i:3;s:57:"/home/shoshi/work/webvirt/cake/libs/controller/components";i:4;s:39:"/home/shoshi/work/webvirt/cake/libs/log";i:5;s:41:"/home/shoshi/work/webvirt/cake/libs/model";i:6;s:51:"/home/shoshi/work/webvirt/cake/libs/model/behaviors";i:7;s:53:"/home/shoshi/work/webvirt/cake/libs/model/datasources";i:8;s:57:"/home/shoshi/work/webvirt/cake/libs/model/datasources/dbo";i:9;s:40:"/home/shoshi/work/webvirt/cake/libs/view";i:10;s:49:"/home/shoshi/work/webvirt/cake/libs/view/elements";i:11;s:55:"/home/shoshi/work/webvirt/cake/libs/view/elements/email";i:12;s:60:"/home/shoshi/work/webvirt/cake/libs/view/elements/email/html";i:13;s:60:"/home/shoshi/work/webvirt/cake/libs/view/elements/email/text";i:14;s:47:"/home/shoshi/work/webvirt/cake/libs/view/errors";i:15;s:48:"/home/shoshi/work/webvirt/cake/libs/view/helpers";i:16;s:48:"/home/shoshi/work/webvirt/cake/libs/view/layouts";i:17;s:54:"/home/shoshi/work/webvirt/cake/libs/view/layouts/email";i:18;s:59:"/home/shoshi/work/webvirt/cake/libs/view/layouts/email/html";i:19;s:59:"/home/shoshi/work/webvirt/cake/libs/view/layouts/email/text";i:20;s:51:"/home/shoshi/work/webvirt/cake/libs/view/layouts/js";i:21;s:52:"/home/shoshi/work/webvirt/cake/libs/view/layouts/rss";i:22;s:52:"/home/shoshi/work/webvirt/cake/libs/view/layouts/xml";i:23;s:46:"/home/shoshi/work/webvirt/cake/libs/view/pages";i:24;s:50:"/home/shoshi/work/webvirt/cake/libs/view/scaffolds";}s:41:"/home/shoshi/work/webvirt/app/controllers";a:2:{i:0;s:41:"/home/shoshi/work/webvirt/app/controllers";i:1;s:52:"/home/shoshi/work/webvirt/app/controllers/components";}s:35:"/home/shoshi/work/webvirt/app/views";a:23:{i:0;s:35:"/home/shoshi/work/webvirt/app/views";i:1;s:42:"/home/shoshi/work/webvirt/app/views/create";i:2;s:42:"/home/shoshi/work/webvirt/app/views/define";i:3;s:44:"/home/shoshi/work/webvirt/app/views/elements";i:4;s:50:"/home/shoshi/work/webvirt/app/views/elements/email";i:5;s:55:"/home/shoshi/work/webvirt/app/views/elements/email/html";i:6;s:55:"/home/shoshi/work/webvirt/app/views/elements/email/text";i:7;s:52:"/home/shoshi/work/webvirt/app/views/elements/storage";i:8;s:42:"/home/shoshi/work/webvirt/app/views/errors";i:9;s:43:"/home/shoshi/work/webvirt/app/views/helpers";i:10;s:40:"/home/shoshi/work/webvirt/app/views/icon";i:11;s:43:"/home/shoshi/work/webvirt/app/views/layouts";i:12;s:49:"/home/shoshi/work/webvirt/app/views/layouts/email";i:13;s:54:"/home/shoshi/work/webvirt/app/views/layouts/email/html";i:14;s:54:"/home/shoshi/work/webvirt/app/views/layouts/email/text";i:15;s:46:"/home/shoshi/work/webvirt/app/views/layouts/js";i:16;s:47:"/home/shoshi/work/webvirt/app/views/layouts/rss";i:17;s:47:"/home/shoshi/work/webvirt/app/views/layouts/xml";i:18;s:41:"/home/shoshi/work/webvirt/app/views/pages";i:19;s:45:"/home/shoshi/work/webvirt/app/views/scaffolds";i:20;s:44:"/home/shoshi/work/webvirt/app/views/shutdown";i:21;s:43:"/home/shoshi/work/webvirt/app/views/storage";i:22;s:45:"/home/shoshi/work/webvirt/app/views/vncviewer";}s:40:"/home/shoshi/work/webvirt/cake/libs/view";a:16:{i:0;s:40:"/home/shoshi/work/webvirt/cake/libs/view";i:1;s:49:"/home/shoshi/work/webvirt/cake/libs/view/elements";i:2;s:55:"/home/shoshi/work/webvirt/cake/libs/view/elements/email";i:3;s:60:"/home/shoshi/work/webvirt/cake/libs/view/elements/email/html";i:4;s:60:"/home/shoshi/work/webvirt/cake/libs/view/elements/email/text";i:5;s:47:"/home/shoshi/work/webvirt/cake/libs/view/errors";i:6;s:48:"/home/shoshi/work/webvirt/cake/libs/view/helpers";i:7;s:48:"/home/shoshi/work/webvirt/cake/libs/view/layouts";i:8;s:54:"/home/shoshi/work/webvirt/cake/libs/view/layouts/email";i:9;s:59:"/home/shoshi/work/webvirt/cake/libs/view/layouts/email/html";i:10;s:59:"/home/shoshi/work/webvirt/cake/libs/view/layouts/email/text";i:11;s:51:"/home/shoshi/work/webvirt/cake/libs/view/layouts/js";i:12;s:52:"/home/shoshi/work/webvirt/cake/libs/view/layouts/rss";i:13;s:52:"/home/shoshi/work/webvirt/cake/libs/view/layouts/xml";i:14;s:46:"/home/shoshi/work/webvirt/cake/libs/view/pages";i:15;s:50:"/home/shoshi/work/webvirt/cake/libs/view/scaffolds";}s:52:"/home/shoshi/work/webvirt/app/controllers/components";a:1:{i:0;s:52:"/home/shoshi/work/webvirt/app/controllers/components";}s:57:"/home/shoshi/work/webvirt/cake/libs/controller/components";a:1:{i:0;s:57:"/home/shoshi/work/webvirt/cake/libs/controller/components";}s:43:"/home/shoshi/work/webvirt/app/views/helpers";a:1:{i:0;s:43:"/home/shoshi/work/webvirt/app/views/helpers";}} diff -r 7201fd354bdf -r c3adb28473d6 app/tmp/cache/persistent/cake_core_file_map --- a/app/tmp/cache/persistent/cake_core_file_map Sun Aug 14 23:52:31 2011 +0900 +++ b/app/tmp/cache/persistent/cake_core_file_map Tue Aug 16 18:31:36 2011 +0900 @@ -1,2 +1,2 @@ -1313333340 -a:5:{s:4:"Core";a:7:{s:6:"Router";s:46:"/home/shoshi/work/webvirt/cake/libs/router.php";s:13:"ClassRegistry";s:54:"/home/shoshi/work/webvirt/cake/libs/class_registry.php";s:12:"Overloadable";s:52:"/home/shoshi/work/webvirt/cake/libs/overloadable.php";s:8:"Security";s:48:"/home/shoshi/work/webvirt/cake/libs/security.php";s:4:"l10n";s:44:"/home/shoshi/work/webvirt/cake/libs/l10n.php";s:9:"Multibyte";s:49:"/home/shoshi/work/webvirt/cake/libs/multibyte.php";s:4:"i18n";s:44:"/home/shoshi/work/webvirt/cake/libs/i18n.php";}s:10:"Controller";a:5:{s:9:"Component";s:60:"/home/shoshi/work/webvirt/cake/libs/controller/component.php";s:10:"Controller";s:61:"/home/shoshi/work/webvirt/cake/libs/controller/controller.php";s:13:"AppController";s:65:"/home/shoshi/work/webvirt/cake/libs/controller/app_controller.php";s:15:"PagesController";s:62:"/home/shoshi/work/webvirt/app/controllers/pages_controller.php";s:14:"IconController";s:61:"/home/shoshi/work/webvirt/app/controllers/icon_controller.php";}s:4:"View";a:2:{s:6:"Helper";s:51:"/home/shoshi/work/webvirt/cake/libs/view/helper.php";s:4:"View";s:49:"/home/shoshi/work/webvirt/cake/libs/view/view.php";}s:9:"Component";a:1:{s:16:"SessionComponent";s:69:"/home/shoshi/work/webvirt/cake/libs/controller/components/session.php";}s:6:"Helper";a:4:{s:9:"AppHelper";s:63:"/home/shoshi/work/webvirt/cake/libs/view/helpers/app_helper.php";s:13:"SessionHelper";s:60:"/home/shoshi/work/webvirt/cake/libs/view/helpers/session.php";s:10:"HtmlHelper";s:57:"/home/shoshi/work/webvirt/cake/libs/view/helpers/html.php";s:10:"FormHelper";s:57:"/home/shoshi/work/webvirt/cake/libs/view/helpers/form.php";}} +1313486895 +a:5:{s:4:"Core";a:7:{s:6:"Router";s:46:"/home/shoshi/work/webvirt/cake/libs/router.php";s:13:"ClassRegistry";s:54:"/home/shoshi/work/webvirt/cake/libs/class_registry.php";s:12:"Overloadable";s:52:"/home/shoshi/work/webvirt/cake/libs/overloadable.php";s:8:"Security";s:48:"/home/shoshi/work/webvirt/cake/libs/security.php";s:4:"l10n";s:44:"/home/shoshi/work/webvirt/cake/libs/l10n.php";s:9:"Multibyte";s:49:"/home/shoshi/work/webvirt/cake/libs/multibyte.php";s:4:"i18n";s:44:"/home/shoshi/work/webvirt/cake/libs/i18n.php";}s:10:"Controller";a:5:{s:9:"Component";s:60:"/home/shoshi/work/webvirt/cake/libs/controller/component.php";s:10:"Controller";s:61:"/home/shoshi/work/webvirt/cake/libs/controller/controller.php";s:13:"AppController";s:65:"/home/shoshi/work/webvirt/cake/libs/controller/app_controller.php";s:14:"IconController";s:61:"/home/shoshi/work/webvirt/app/controllers/icon_controller.php";s:15:"PagesController";s:62:"/home/shoshi/work/webvirt/app/controllers/pages_controller.php";}s:4:"View";a:2:{s:6:"Helper";s:51:"/home/shoshi/work/webvirt/cake/libs/view/helper.php";s:4:"View";s:49:"/home/shoshi/work/webvirt/cake/libs/view/view.php";}s:9:"Component";a:1:{s:16:"SessionComponent";s:69:"/home/shoshi/work/webvirt/cake/libs/controller/components/session.php";}s:6:"Helper";a:4:{s:9:"AppHelper";s:63:"/home/shoshi/work/webvirt/cake/libs/view/helpers/app_helper.php";s:13:"SessionHelper";s:60:"/home/shoshi/work/webvirt/cake/libs/view/helpers/session.php";s:10:"HtmlHelper";s:57:"/home/shoshi/work/webvirt/cake/libs/view/helpers/html.php";s:10:"FormHelper";s:57:"/home/shoshi/work/webvirt/cake/libs/view/helpers/form.php";}} diff -r 7201fd354bdf -r c3adb28473d6 app/tmp/cache/persistent/cake_core_object_map --- a/app/tmp/cache/persistent/cake_core_object_map Sun Aug 14 23:52:31 2011 +0900 +++ b/app/tmp/cache/persistent/cake_core_object_map Tue Aug 16 18:31:36 2011 +0900 @@ -1,2 +1,2 @@ -1313333340 +1313486895 a:1:{s:6:"plugin";a:0:{}} diff -r 7201fd354bdf -r c3adb28473d6 app/tmp/logs/debug.log --- a/app/tmp/logs/debug.log Sun Aug 14 23:52:31 2011 +0900 +++ b/app/tmp/logs/debug.log Tue Aug 16 18:31:36 2011 +0900 @@ -91,3 +91,7 @@ 2011-07-26 23:49:04 Notice: Notice (8): Undefined index: name in [/var/www/html/webvirt/app/views/elements/storage/volumeinfotable.ctp, line 11] 2011-07-26 23:49:04 Notice: Notice (8): Undefined index: path in [/var/www/html/webvirt/app/views/elements/storage/volumeinfotable.ctp, line 13] 2011-07-26 23:50:26 Notice: Notice (8): Undefined variable: vname in [/var/www/html/webvirt/app/controllers/storage_controller.php, line 197] +2011-08-16 16:54:48 Notice: Notice (8): Undefined index: upfile in [/home/shoshi/work/webvirt/app/controllers/icon_controller.php, line 62] +2011-08-16 16:55:26 Notice: Notice (8): Undefined variable: uuid in [/home/shoshi/work/webvirt/app/views/icon/save_icon.ctp, line 4] +2011-08-16 17:01:05 Notice: Notice (8): Undefined variable: uuid in [/home/shoshi/work/webvirt/app/views/icon/save_icon.ctp, line 4] +2011-08-16 17:13:41 Notice: Notice (8): Undefined variable: uuid in [/home/shoshi/work/webvirt/app/views/icon/save_icon.ctp, line 4] diff -r 7201fd354bdf -r c3adb28473d6 app/tmp/logs/error.log --- a/app/tmp/logs/error.log Sun Aug 14 23:52:31 2011 +0900 +++ b/app/tmp/logs/error.log Tue Aug 16 18:31:36 2011 +0900 @@ -93,3 +93,8 @@ 2011-08-14 23:47:18 Warning: Warning (2): file_get_contents(../icon/6d913328-7529-321c-1d71-5d54af65bf65png) [function.file-get-contents]: failed to open stream: No such file or directory in [/home/shoshi/work/webvirt/app/controllers/icon_controller.php, line 20] 2011-08-14 23:47:32 Warning: Warning (2): file_get_contents(../icon/6d913328-7529-321c-1d71-5d54af65bf65png) [function.file-get-contents]: failed to open stream: No such file or directory in [/home/shoshi/work/webvirt/app/controllers/icon_controller.php, line 20] 2011-08-14 23:48:18 Warning: Warning (2): file_get_contents(../icon/6d913328-7529-321c-1d71-5d54af65bf65png) [function.file-get-contents]: failed to open stream: No such file or directory in [/home/shoshi/work/webvirt/app/controllers/icon_controller.php, line 20] +2011-08-16 16:58:19 Warning: Warning (2): file_get_contents(../icon/6d913328-7529-321c-1d71-5d54af65bf65png) [function.file-get-contents]: failed to open stream: No such file or directory in [/home/shoshi/work/webvirt/app/controllers/icon_controller.php, line 20] +2011-08-16 16:58:19 Warning: Warning (2): file_get_contents(../icon/dbb4b16f-9787-5402-c284-d1b7fa6b09e6png) [function.file-get-contents]: failed to open stream: No such file or directory in [/home/shoshi/work/webvirt/app/controllers/icon_controller.php, line 20] +2011-08-16 16:58:26 Warning: Warning (2): file_get_contents(../icon/dbb4b16f-9787-5402-c284-d1b7fa6b09e6png) [function.file-get-contents]: failed to open stream: No such file or directory in [/home/shoshi/work/webvirt/app/controllers/icon_controller.php, line 20] +2011-08-16 16:58:37 Warning: Warning (2): file_get_contents(../icon/dbb4b16f-9787-5402-c284-d1b7fa6b09e6png) [function.file-get-contents]: failed to open stream: No such file or directory in [/home/shoshi/work/webvirt/app/controllers/icon_controller.php, line 20] +2011-08-16 16:59:34 Warning: Warning (2): file_get_contents(../icon/dbb4b16f-9787-5402-c284-d1b7fa6b09e6png) [function.file-get-contents]: failed to open stream: No such file or directory in [/home/shoshi/work/webvirt/app/controllers/icon_controller.php, line 20] diff -r 7201fd354bdf -r c3adb28473d6 app/views/icon/delete_icon.ctp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/views/icon/delete_icon.ctp Tue Aug 16 18:31:36 2011 +0900 @@ -0,0 +1,2 @@ +

Icon::DeleteIcon

+

Icon was successfully deleted.

diff -r 7201fd354bdf -r c3adb28473d6 app/views/icon/edit_icon.ctp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/views/icon/edit_icon.ctp Tue Aug 16 18:31:36 2011 +0900 @@ -0,0 +1,14 @@ +

Icon::EditIcon

+

Current icon

+ +

Upload icon

+
+ + + +
+

Delete icon

+
+ + +
diff -r 7201fd354bdf -r c3adb28473d6 app/views/icon/error.ctp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/views/icon/error.ctp Tue Aug 16 18:31:36 2011 +0900 @@ -0,0 +1,3 @@ +

Icon::Error

+

+

Back

diff -r 7201fd354bdf -r c3adb28473d6 app/views/icon/save_icon.ctp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/views/icon/save_icon.ctp Tue Aug 16 18:31:36 2011 +0900 @@ -0,0 +1,4 @@ +

Icon::SaveIcon

+

Icon was successfully saved.

+

Current Icon

+ diff -r 7201fd354bdf -r c3adb28473d6 app/views/pages/display.ctp --- a/app/views/pages/display.ctp Sun Aug 14 23:52:31 2011 +0900 +++ b/app/views/pages/display.ctp Tue Aug 16 18:31:36 2011 +0900 @@ -24,6 +24,7 @@

Domains

" /> +">edit