From a4a3640f4ee97eb8b397914fff0cafaa8c9f2ef6 Mon Sep 17 00:00:00 2001 From: michael pereira Date: Fri, 22 Apr 2011 11:33:07 +0200 Subject: controller fixes --- .../modules/user/controllers/BootisoController.php | 49 ++--- .../modules/user/controllers/BootosController.php | 204 ++++++--------------- .../modules/user/controllers/PrebootController.php | 27 +-- application/modules/user/forms/Bootos.php | 34 +++- .../modules/user/views/scripts/bootiso/index.phtml | 8 +- .../modules/user/views/scripts/bootos/index.phtml | 26 --- .../modules/user/views/scripts/preboot/index.phtml | 1 + 7 files changed, 122 insertions(+), 227 deletions(-) (limited to 'application/modules/user') diff --git a/application/modules/user/controllers/BootisoController.php b/application/modules/user/controllers/BootisoController.php index e83a2c5..f1cf37a 100644 --- a/application/modules/user/controllers/BootisoController.php +++ b/application/modules/user/controllers/BootisoController.php @@ -135,33 +135,39 @@ class user_BootisoController extends Zend_Controller_Action $this->_helper->layout->disableLayout(); $this->_helper->viewRenderer->setNoRender(true); - - //ACL Darf er BootISOs downloaden? if(!Pbs_Acl::checkRight('bdld')) - $this->_redirect('/user/bootiso/index/page/'.$this->page.'/downloadresult/forbidden'); + $this->_redirect('/user/bootiso/index/page/'.$this->page.'/downloadresult/forbidden'); $bootisoID = $this->_request->getParam('bootisoID'); if(!is_numeric($bootisoID)) - $this->_redirect('/user/bootiso/index/page/'.$this->page.'/downloadresult/forbidden'); - - $prebootID = $this->bootisoMapper->find($bootisoID)->getPrebootID(); + $this->_redirect('/user/bootiso/index/page/'.$this->page.'/downloadresult/forbidden'); + $bootiso = $this->bootisoMapper->find($bootisoID); + $prebootID = $bootiso->getPrebootID(); if(!is_dir("../resources/bootmedium/$prebootID/")) - $this->_redirect('/user/bootiso/index/page/'.$this->page.'/downloadresult/404'); - + $this->_redirect('/user/bootiso/index/page/'.$this->page.'/downloadresult/404'); + + $zip = new ZipArchive(); + $res = $zip->open("../resources/bootmedium/$prebootID/preboot.zip"); + if($res === true){ + $rootdir = $zip->getNameIndex(0); + $zip->addFromString($rootdir."build/rootfs/tmp/serial", $bootiso->getSerialnumber()); + $zip->close(); + } + chdir("../resources/bootmedium/$prebootID/"); - header("X-Sendfile: $bootisoID".".zip"); + header("X-Sendfile: preboot.zip"); header('Content-Type: application/x-gzip'); $content_disp = ( ereg('MSIE ([0-9].[0-9]{1,2})', $_SERVER['HTTP_USER_AGENT']) == 'IE') ? 'inline' : 'attachment'; header('Content-Disposition: ' . $content_disp . '; filename="preboot.zip"'); header('Pragma: no-cache'); header('Expires: 0'); - $handle = fopen($bootisoID.".zip", 'r'); + $handle = fopen("preboot.zip", 'r'); $chunk_size = 8192; while ($chunk = fread($handle, $chunk_size)) { echo $chunk; @@ -205,21 +211,8 @@ class user_BootisoController extends Zend_Controller_Action $bootiso->setGroupID($this->membership->getGroupID()); $bootiso->setCreated(time()); - $prebootID = $bootiso->getPrebootID(); - try { - $bootisoID = $this->bootisoMapper->save($bootiso); - - copy("../resources/bootmedium/$prebootID/preboot.zip", "../resources/bootmedium/$prebootID/$bootisoID".".zip"); - $zip = new ZipArchive(); - $res = $zip->open("../resources/bootmedium/$prebootID/$bootisoID".".zip"); - if($res === true){ - $rootdir = $zip->getNameIndex(0); - $zip->addFromString($rootdir."build/rootfs/tmp/serial", $bootiso->getSerialnumber()); - $zip->close(); - } - }catch(Zend_Exception $e) { echo "Caught exception: " . get_class($e) . "
"; @@ -294,16 +287,8 @@ class user_BootisoController extends Zend_Controller_Action $this->_redirect('/user/bootiso/index/page/'.$this->page.'/modifyresult/forbidden'); } - try { - $zip = new ZipArchive(); - $res = $zip->open("../resources/bootmedium/$prebootID/$bootisoID".".zip"); - if($res === true){ - $rootdir = $zip->getNameIndex(0); - $zip->addFromString($rootdir."build/rootfs/serial", $bootiso->getSerialnumber()); - $zip->close(); - } - + $this->bootisoMapper->save($bootiso); }catch(Zend_Exception $e) diff --git a/application/modules/user/controllers/BootosController.php b/application/modules/user/controllers/BootosController.php index 06eb60c..92dcc5f 100644 --- a/application/modules/user/controllers/BootosController.php +++ b/application/modules/user/controllers/BootosController.php @@ -86,15 +86,13 @@ class user_BootosController extends Zend_Controller_Action $this->view->bootoslist = array_reverse($this->view->bootoslist); - $this->view->update = array(); $update = $this->_request->getParam('checkupdate'); $groupMapper = new Application_Model_GroupMapper(); if(count($this->view->bootoslist)>0){ foreach ($this->view->bootoslist as $bootos){ - $this->view->update[$bootos->getID()] = $update && $this->checkupdateAction($bootos); if($bootos->getDefaultkcl() == null) - $bootos->setDefaultkcl("none (edit Bootos to set KCL)"); + $bootos->setDefaultkcl("none (edit Bootos to set KCL)"); $bootos->setGroupID("[".$bootos->getGroupID()."] ".$groupMapper->find($bootos->getGroupID())->getTitle()); $bootos->setCreated(date(Zend_Registry::get('dateformat'),$bootos->getCreated())); $bootos->setExpires(date(Zend_Registry::get('dateformat'),$bootos->getExpires())); @@ -133,7 +131,7 @@ class user_BootosController extends Zend_Controller_Action //ACL Darf er BootISOs erstellen? if(!Pbs_Acl::checkRight('boc')) - $this->_redirect('/user/bootos/index/page/'.$this->page.'/addresult/forbidden'); + $this->_redirect('/user/bootos/index/page/'.$this->page.'/addresult/forbidden'); $groupID = $this->membership->getGroupID(); @@ -158,27 +156,18 @@ class user_BootosController extends Zend_Controller_Action $bootos->setGroupID($this->membership->getGroupID()); $bootos->setCreated(time()); + $bootos->setSource($_SERVER['REMOTE_ADDR']); try { - $path_tmp = "../resources/bootos/"; - mkdir($path_tmp ,0777, true); - - $hash = md5(microtime(1)); - exec("wget -O '".$path_tmp."kernel".$hash."' ".escapeshellcmd($bootos->getPath_kernel())." 2>&1 | grep 'saved'", $status); - exec("wget -O '".$path_tmp."initramfs".$hash."' ".escapeshellcmd($bootos->getPath_init())." 2>&1 | grep 'saved'", $status2); - exec("wget -O '".$path_tmp."default".$hash."' ".escapeshellcmd($bootos->getPath_config())." 2>&1 | grep 'saved'", $status3); - - if(!array_pop($status) && $bootos->getPath_kernel() != null || !array_pop($status2) && $bootos->getPath_init() != null || !array_pop($status3) && $bootos->getPath_config() != null ){ - $this->view->bootosForm = $bootosForm; - $pbsNotifier = new Pbs_Notifier(); - echo $pbsNotifier->notify('The Resource was not found on the specified path','error'); - - return; - } - $bootosID = $this->bootosMapper->save($bootos); + if( $_FILES['kernel']['size'] == 0 && $_FILES['kernel']['name'] != '' || + $_FILES['init']['size'] == 0 && $_FILES['init']['name'] != '' || + $_FILES['config']['size'] == 0 && $_FILES['config']['name'] != '' ){ + $this->_redirect('/user/preboot/index/page/'.$this->page.'/addresult/file'); + } + $initpath = "../resources/bootos/".$bootosID."/initramfs/"; $kernelpath = "../resources/bootos/".$bootosID."/kernel/"; $configpath = "../resources/bootos/".$bootosID."/config/"; @@ -187,9 +176,15 @@ class user_BootosController extends Zend_Controller_Action mkdir($kernelpath ,0777, true); mkdir($configpath ,0777, true); - exec("mv ../resources/bootos/kernel$hash $kernelpath"."kernel"); - exec("mv ../resources/bootos/initramfs$hash $initpath"."initramfs"); - exec("mv ../resources/bootos/config$hash $configpath"."default.tgz"); + if($_FILES['kernel']['name'] != ''){ + move_uploaded_file($_FILES['kernel']['tmp_name'], $kernelpath."kernel"); + } + if($_FILES['init']['name'] != ''){ + move_uploaded_file($_FILES['init']['tmp_name'], $initpath."initramfs"); + } + if($_FILES['config']['name'] != ''){ + move_uploaded_file($_FILES['config']['tmp_name'], $configpath."default.tgz"); + } }catch(Zend_Exception $e) @@ -208,89 +203,10 @@ class user_BootosController extends Zend_Controller_Action $this->view->bootosForm = $bootosForm; } - public function checkupdateAction($bootos) - { - - //ACL Is he allowed to update Preboots? - if(!Pbs_Acl::checkRight('bou')) - $this->_redirect('/user/preboot/index/page/'.$this->page.'/updateresult/forbidden'); - - $bootosID = $bootos->getID(); - - if(is_file("../resources/bootos/$bootosID/kernel/kernel") && is_file("../resources/bootos/$bootosID/initramfs/initramfs") && is_file("../resources/bootos/$bootosID/config/config.tgz")){ - $kernelolddate = filemtime("../resources/bootos/".$bootosID."/kernel/kernel"); - $initolddate = filemtime("../resources/bootos/".$bootosID."/initramfs/initramfs"); - $configolddate = filemtime("../resources/bootos/".$bootosID."/config/default.tgz"); - - } - else - { - $pbsNotifier = new Pbs_Notifier(); - $this->view->notification = $pbsNotifier->notify('There are updates available','ok'); - return true; - } - - exec("wget --server-response --spider '".escapeshellcmd($bootos->getPath_kernel())."' 2>&1 | grep 'Last-Modified:'", $kerneldate); - exec("wget --server-response --spider '".escapeshellcmd($bootos->getPath_init())."' 2>&1 | grep 'Last-Modified:'", $initdate); - exec("wget --server-response --spider '".escapeshellcmd($bootos->getPath_config())."' 2>&1 | grep 'Last-Modified:'", $configdate); - - $kerneldate = strtotime(trim(str_replace('Last-Modified:', '', array_pop($kerneldate)))); - $initdate = strtotime(trim(str_replace('Last-Modified:', '', array_pop($initdate)))); - $configdate = strtotime(trim(str_replace('Last-Modified:', '', array_pop($configdate)))); - - //print_a($bootos->getPath_kernel(),$kerneldate,$kernelolddate,$initname,$initdate,$initolddate); - - if($kerneldate > $kernelolddate || $initdate > $initolddate || $configdate > $configolddate){ - $this->view->notification = $pbsNotifier->notify('There are updates available','ok'); - return true; - }else{ - return false; - } - - } - - public function updatebootosAction() - { - - //ACL Is he allowed to update Preboots? - if(!Pbs_Acl::checkRight('bou')) - $this->_redirect('/user/bootiso/index/page/'.$this->page.'/updateresult/forbidden'); - - $bootosID = $this->_request->getParam('bootosID'); - if (!is_numeric($bootosID)) - $this->_redirect('/user/bootos/index/page/'.$this->page.'/updateresult/forbidden'); - - $bootos = $this->bootosMapper->find($bootosID); - - if($this->membership->getGroupID() != $bootos->getGroupID()) - $this->_redirect('/user/bootos/index/page/'.$this->page.'/updateresult/forbidden'); - - $initpath = "../resources/bootos/".$bootosID."/initramfs/"; - $kernelpath = "../resources/bootos/".$bootosID."/kernel/"; - $configpath = "../resources/bootos/".$bootosID."/config/"; - $path_tmp = "../resources/bootos/"; - - $hash = md5(microtime(1)); - exec("wget -O '".$path_tmp."kernel".$hash."' ".escapeshellcmd($bootos->getPath_kernel())." 2>&1 | grep 'saved'", $status); - exec("wget -O '".$path_tmp."initramfs".$hash."' ".escapeshellcmd($bootos->getPath_init())." 2>&1 | grep 'saved'", $status2); - exec("wget -O '".$path_tmp."config".$hash."' ".escapeshellcmd($bootos->getPath_config())." 2>&1 | grep 'saved'", $status3); - - if(!array_pop($status) || !array_pop($status2) || !array_pop($status3)){ - $this->_redirect('/user/bootos/index/page/'.$this->page.'/updateresult/404'); - //TODO Delete Files in tmp - } - - exec("mv ../resources/bootos/kernel$hash $kernelpath"."kernel"); - exec("mv ../resources/bootos/initramfs$hash $initpath"."initramfs"); - exec("mv ../resources/bootos/config$hash $initpath"."default.tgz"); - - $this->_redirect('/user/bootos/index/page/'.$this->page.'/updateresult/ok'); - } - public function editbootosAction() { - //ACL Is he allowed to edit Preboots? + //ACL Is he allowed to edit Bootos? if(!Pbs_Acl::checkRight('boe') && !Pbs_Acl::checkRight('boem')) $this->_redirect('/user/bootos/index/page/'.$this->page.'/modifyresult/forbidden'); @@ -329,58 +245,58 @@ class user_BootosController extends Zend_Controller_Action $bootos = new Application_Model_BootOs($_POST); $bootos->setGroupID($this->membership->getGroupID()); + $bootos->setSource($bootosold->getSource()); $bootos->setCreated(time()); $bootos->setID($bootosID); - if( $bootos->getSource() != $bootosold->getSource() || - $bootos->getDistro() != $bootosold->getDistro() || - $bootos->getDistroversion() != $bootosold->getDistroversion() || - $bootos->getShare() != $bootosold->getShare() || - $bootos->getShortname() != $bootosold->getShortname() || - $bootos->getDefaultkcl() != $bootosold->getDefaultkcl() || - $bootos->getExpires() != $bootosold->getExpires() || - $bootos->getPublic() != $bootosold->getPublic() ){ - //ACL Is he allowed to edit this? - if(!Pbs_Acl::checkRight('boe')) - $this->_redirect('/user/bootos/index/page/'.$this->page.'/modifyresult/forbidden'); - } - - if($bootos->getPath_config() != $bootosold->getPath_config() || $bootos->getPath_kernel() != $bootosold->getPath_kernel() || $bootos->getPath_init() != $bootosold->getPath_init()){ - //ACL Is he allowed to edit the Kernel/Init Path? - if(!Pbs_Acl::checkRight('boe')) - $this->_redirect('/user/bootos/index/page/'.$this->page.'/modifyresult/forbidden'); - - $path_tmp = "../resources/bootos/"; - - - $hash = md5(microtime(1)); - exec("wget -O '".$path_tmp."kernel".$hash."' ".escapeshellcmd($bootos->getPath_kernel())." 2>&1 | grep 'saved'", $status); - exec("wget -O '".$path_tmp."initramfs".$hash."' ".escapeshellcmd($bootos->getPath_init())." 2>&1 | grep 'saved'", $status2); - exec("wget -O '".$path_tmp."config".$hash."' ".escapeshellcmd($bootos->getPath_config())." 2>&1 | grep 'saved'", $status3); - - if(!array_pop($status) && $bootos->getPath_kernel() != null || !array_pop($status2) && $bootos->getPath_init() != null || !array_pop($status3) && $bootos->getPath_config() != null ){ - $this->view->bootosForm = $bootosForm; - $pbsNotifier = new Pbs_Notifier(); - echo $pbsNotifier->notify('The Resource was not found on the specified path','error'); - - return; + try { + + if( $bootos->getDistro() != $bootosold->getDistro() || + $bootos->getDistroversion() != $bootosold->getDistroversion() || + $bootos->getShare() != $bootosold->getShare() || + $bootos->getShortname() != $bootosold->getShortname() || + $bootos->getDefaultkcl() != $bootosold->getDefaultkcl() || + $bootos->getExpires() != $bootosold->getExpires() || + $bootos->getPublic() != $bootosold->getPublic() ){ + //ACL Is he allowed to edit this? + if(!Pbs_Acl::checkRight('boe')) + $this->_redirect('/user/bootos/index/page/'.$this->page.'/modifyresult/forbidden'); } - + + if($_FILES['kernel']['name'] != '' || $_FILES['init']['name'] != '' || $_FILES['config']['name'] != ''){ + //ACL Is he allowed to edit the Kernel/Init Path? + if(!Pbs_Acl::checkRight('boe')) + $this->_redirect('/user/bootos/index/page/'.$this->page.'/modifyresult/forbidden'); + } + + if( $_FILES['kernel']['size'] == 0 && $_FILES['kernel']['name'] != '' || + $_FILES['init']['size'] == 0 && $_FILES['init']['name'] != '' || + $_FILES['config']['size'] == 0 && $_FILES['config']['name'] != '' ){ + $this->_redirect('/user/bootos/index/page/'.$this->page.'/addresult/file'); + } + $initpath = "../resources/bootos/".$bootosID."/initramfs/"; $kernelpath = "../resources/bootos/".$bootosID."/kernel/"; $configpath = "../resources/bootos/".$bootosID."/config/"; - + mkdir($initpath ,0777, true); mkdir($kernelpath ,0777, true); mkdir($configpath ,0777, true); - - exec("mv ../resources/bootos/kernel$hash $kernelpath"."kernel"); - exec("mv ../resources/bootos/initramfs$hash $initpath"."initramfs"); - exec("mv ../resources/bootos/config$hash $initpath"."default.tgz"); - - } + + + if($_FILES['kernel']['name'] != ''){ + $bootos->setSource($_SERVER['REMOTE_ADDR']); + move_uploaded_file($_FILES['kernel']['tmp_name'], $kernelpath."kernel"); + } + if($_FILES['init']['name'] != ''){ + $bootos->setSource($_SERVER['REMOTE_ADDR']); + move_uploaded_file($_FILES['init']['tmp_name'], $initpath."initramfs"); + } + if($_FILES['config']['name'] != ''){ + $bootos->setSource($_SERVER['REMOTE_ADDR']); + move_uploaded_file($_FILES['config']['tmp_name'], $configpath."default.tgz"); + } - try { $this->bootosMapper->save($bootos); }catch(Zend_Exception $e) diff --git a/application/modules/user/controllers/PrebootController.php b/application/modules/user/controllers/PrebootController.php index a2bbc48..b0b1077 100644 --- a/application/modules/user/controllers/PrebootController.php +++ b/application/modules/user/controllers/PrebootController.php @@ -124,14 +124,8 @@ class User_PrebootController extends Zend_Controller_Action if($_FILES['preboot']['size'] == 0 && $_FILES['preboot']['name'] != ''){ $this->_redirect('/user/preboot/index/page/'.$this->page.'/addresult/file'); } - - list($preboot) = $this->prebootMapper->findBy(array('groupid' => $groupID, 'title' => $_POST['title'])); - if($preboot != null){ - header('HTTP/1.0 400 Preboot already exists'); - die(); - } - + $preboot = new Application_Model_PreBoot($_POST); $preboot->setGroupID($groupID); @@ -143,7 +137,7 @@ class User_PrebootController extends Zend_Controller_Action $prebootpath = "../resources/bootmedium/".$prebootID."/"; mkdir($prebootpath ,0777, true); - if(isset($_FILES['preboot'])){ + if($_FILES['preboot']['name'] != ''){ move_uploaded_file($_FILES['preboot']['tmp_name'], $prebootpath."preboot.zip"); } @@ -201,14 +195,25 @@ class User_PrebootController extends Zend_Controller_Action $preboot = new Application_Model_PreBoot($_POST); $preboot->setGroupID($this->membership->getGroupID()); $preboot->setID($prebootID); - $preboot->setSource($source); + $preboot->setSource($prebootold->getSource()); $preboot->setCreated(time()); - + + if($_FILES['preboot']['name'] != ''){ + //ACL Is he allowed to edit other than Metadata? + if(!Pbs_Acl::checkRight('pre')) + $this->_redirect('/user/preboot/index/page/'.$this->page.'/modifyresult/forbidden'); + } + + if($_FILES['preboot']['size'] == 0 && $_FILES['preboot']['name'] != ''){ + $this->_redirect('/user/preboot/index/page/'.$this->page.'/addresult/file'); + } + $prebootpath = "../resources/bootmedium/$prebootID/"; mkdir($prebootpath ,0777, true); - if(isset($_FILES['preboot'])){ + if($_FILES['preboot']['name'] != ''){ + $preboot->setSource($source); move_uploaded_file($_FILES['preboot']['tmp_name'], $prebootpath."preboot.zip"); } diff --git a/application/modules/user/forms/Bootos.php b/application/modules/user/forms/Bootos.php index d9cd24f..c4b1c70 100644 --- a/application/modules/user/forms/Bootos.php +++ b/application/modules/user/forms/Bootos.php @@ -42,6 +42,11 @@ class user_Form_Bootos extends Zend_Form $meta = true; else $meta = null; + + if($this->action == 'editbootos') + $filereq = false; + else + $filereq = true; $this->addElement('text', 'title', array( 'filters' => array('StringTrim'), @@ -75,16 +80,6 @@ class user_Form_Bootos extends Zend_Form 'label' => 'Default-KCL:', )); - $this->addElement('text', 'source', array( - 'filters' => array('StringTrim'), - 'validators' => array( - array('StringLength', false, array(0, 140)), - ), - 'required' => false, - 'readOnly' => $meta, - 'label' => 'Source:', - )); - $this->addElement('text', 'distro', array( 'filters' => array('StringTrim'), 'validators' => array( @@ -125,6 +120,25 @@ class user_Form_Bootos extends Zend_Form 'label' => 'Share:', )); + $this->addElement('file', 'kernel', array( + 'required' => $filereq, + 'readOnly' => $meta, + 'label' => 'Kernel:', + )); + + $this->addElement('file', 'init', array( + 'required' => $filereq, + 'readOnly' => $meta, + 'label' => 'Initramfs:', + )); + + $this->addElement('file', 'config', array( + 'validators' => array(array('Extension', false, array('tgz'))), + 'required' => $filereq, + 'readOnly' => $meta, + 'label' => 'Config:', + )); + $date = new DateTime(); $date->add(new DateInterval('P1Y')); $this->addElement('text', 'expires', array( diff --git a/application/modules/user/views/scripts/bootiso/index.phtml b/application/modules/user/views/scripts/bootiso/index.phtml index 70c6a3b..cd94f9a 100644 --- a/application/modules/user/views/scripts/bootiso/index.phtml +++ b/application/modules/user/views/scripts/bootiso/index.phtml @@ -19,6 +19,7 @@
prebootID
title
+
description
groupID
created
expires
@@ -79,15 +80,14 @@ $bootiso->setGroupID(preg_replace("!^\[[0-9]+\]\s!",'',$bootiso->getGroupID())); } ?>
escape($bootiso->getTitle()); ?>
-
escape($bootiso->getGroupID()); ?> - - - Serialnumber: escape($bootiso->getSerialnumber()); ?> - +
escape($bootiso->getGroupID())." - ".$this->escape($bootiso->getDescription()); ?>
escape($bootiso->getID()); ?>
+ +
escape($bootiso->getSerialnumber()); ?>
escape($bootiso->getPrebootID()); ?>
diff --git a/application/modules/user/views/scripts/bootos/index.phtml b/application/modules/user/views/scripts/bootos/index.phtml index c39ac05..f01cccd 100644 --- a/application/modules/user/views/scripts/bootos/index.phtml +++ b/application/modules/user/views/scripts/bootos/index.phtml @@ -4,13 +4,6 @@
Here you can see all available BootOs you can select to start. Before you can boot one of these you have to add it to your BootMenu.
searchform; ?> - - -formButton('checkupdate', 'Check for Updates', array( - 'onclick' => 'self.location="/user/bootos/index/page/'.$this->page.'/checkupdate/true"', - 'class' => 'updatebutton', - ))?> - formButton('createbootos', 'Create BootOS', array( 'onclick' => 'self.location="/user/bootos/createbootos/page/'.$this->page.'"', @@ -21,10 +14,7 @@
bootosID
public
-
path_kernel
defaultkcl
-
path_init
-
path_config
distro
distroversion
share
@@ -50,22 +40,6 @@
- - update[$bootos->getID()]==true): ?> - Updates available - - No updates available - -