diff options
author | michael pereira | 2011-04-21 15:55:59 +0200 |
---|---|---|
committer | michael pereira | 2011-04-21 15:55:59 +0200 |
commit | 4d141b993337331b61945cc02c43cb15d89714e9 (patch) | |
tree | 38e42801af6fee086771eca48ff44d2b668f1986 | |
parent | config fix (diff) | |
download | pbs2-4d141b993337331b61945cc02c43cb15d89714e9.tar.gz pbs2-4d141b993337331b61945cc02c43cb15d89714e9.tar.xz pbs2-4d141b993337331b61945cc02c43cb15d89714e9.zip |
Preboot gefixt
-rw-r--r-- | application/controllers/ResourceController.php | 7 | ||||
-rw-r--r-- | application/models/PreBoot.php | 23 | ||||
-rw-r--r-- | application/models/PreBootMapper.php | 8 | ||||
-rw-r--r-- | application/modules/user/controllers/PrebootController.php | 153 | ||||
-rw-r--r-- | application/modules/user/forms/Bootos.php | 33 | ||||
-rw-r--r-- | application/modules/user/forms/Preboot.php | 11 | ||||
-rw-r--r-- | application/modules/user/views/scripts/bootos/index.phtml | 6 | ||||
-rw-r--r-- | application/modules/user/views/scripts/preboot/index.phtml | 1 | ||||
-rw-r--r-- | scripts/api_bootos_test.html (renamed from api_bootos_test.html) | 0 | ||||
-rw-r--r-- | scripts/api_preboot_test.html (renamed from api_preboot_test.html) | 0 |
10 files changed, 39 insertions, 203 deletions
diff --git a/application/controllers/ResourceController.php b/application/controllers/ResourceController.php index 3547818..4958f68 100644 --- a/application/controllers/ResourceController.php +++ b/application/controllers/ResourceController.php @@ -233,11 +233,10 @@ class ResourceController extends Zend_Controller_Action $params = $this->_request->getParams(); $source = $_SERVER['REMOTE_ADDR']; - if($params['title'] == ''){ - header('HTTP/1.0 400 Title must be set'); + if($params['title'] == '' || $_FILES['preboot']['name'] == ''){ + header('HTTP/1.0 400 Title and Preboot must be set'); die(); } - if($_FILES['preboot']['size'] == 0 && $_FILES['preboot']['name'] != ''){ header('HTTP/1.0 400 File must be larger than 0 bytes'); @@ -292,7 +291,7 @@ class ResourceController extends Zend_Controller_Action $params = $this->_request->getParams(); $source = $_SERVER['REMOTE_ADDR']; - if($params['title'] == ''){ + if($params['title'] == '' || $_FILES['preboot']['name'] == ''){ header('HTTP/1.0 400 Title must be set'); die(); } diff --git a/application/models/PreBoot.php b/application/models/PreBoot.php index 57a622d..34b4346 100644 --- a/application/models/PreBoot.php +++ b/application/models/PreBoot.php @@ -14,11 +14,12 @@ class Application_Model_PreBoot { protected $_prebootID; protected $_title; - protected $_path_preboot; protected $_membershipID; protected $_groupID; protected $_source; protected $_created; + protected $_description; + public function __construct(array $options = null) @@ -98,16 +99,6 @@ class Application_Model_PreBoot $this->_title = $_title; return $this; } - public function getPath_preboot() - { - return $this->_path_preboot; - } - - public function setPath_preboot($_path_preboot) - { - $this->_path_preboot = $_path_preboot; - return $this; - } public function getCreated() { return $this->_created; @@ -128,7 +119,15 @@ class Application_Model_PreBoot $this->_source = $_source; return $this; } - + public function getDescription() + { + return $this->_description; + } + public function setDescription($_description) + { + $this->_description = $_description; + return $this; + } /** * Returns current data as associative array using ReflectionClass * diff --git a/application/models/PreBootMapper.php b/application/models/PreBootMapper.php index 564fd49..b7b4104 100644 --- a/application/models/PreBootMapper.php +++ b/application/models/PreBootMapper.php @@ -86,7 +86,7 @@ class Application_Model_PreBootMapper public function save(Application_Model_PreBoot $preboot) { - $data = array('prebootID'=> $preboot->getID() ,'membershipID'=> $preboot->getMembershipID() ,'title'=> $preboot->getTitle() ,'path_preboot'=> $preboot->getPath_preboot() ,'groupID'=> $preboot->getGroupID(), 'created' => $preboot->getCreated(), 'source' => $preboot->getSource() ); + $data = array('prebootID'=> $preboot->getID() ,'membershipID'=> $preboot->getMembershipID() ,'title'=> $preboot->getTitle() ,'groupID'=> $preboot->getGroupID(), 'created' => $preboot->getCreated(), 'source' => $preboot->getSource(), 'description' => $preboot->getDescription()); if (null === ($id = $preboot->getID()) ) { unset($data['prebootID']); @@ -117,10 +117,10 @@ class Application_Model_PreBootMapper if($preboot == null){ $preboot = new Application_Model_PreBoot(); - $preboot->setID($row->prebootID)->setMembershipID($row->membershipID)->setTitle($row->title)->setPath_preboot($row->path_preboot)->setGroupID($row->groupID)->setSource($row->source)->setCreated($row->created); + $preboot->setID($row->prebootID)->setMembershipID($row->membershipID)->setTitle($row->title)->setGroupID($row->groupID)->setSource($row->source)->setCreated($row->created)->setDescription($row->description); return $preboot; }else{ - $preboot->setID($row->prebootID)->setMembershipID($row->membershipID)->setTitle($row->title)->setPath_preboot($row->path_preboot)->setGroupID($row->groupID)->setSource($row->source)->setCreated($row->created); + $preboot->setID($row->prebootID)->setMembershipID($row->membershipID)->setTitle($row->title)->setGroupID($row->groupID)->setSource($row->source)->setCreated($row->created)->setDescription($row->description); } } @@ -131,7 +131,7 @@ class Application_Model_PreBootMapper foreach ($resultSet as $row) { $entry = new Application_Model_PreBoot(); - $entry->setID($row->prebootID)->setMembershipID($row->membershipID)->setTitle($row->title)->setPath_preboot($row->path_preboot)->setGroupID($row->groupID)->setSource($row->source)->setCreated($row->created); + $entry->setID($row->prebootID)->setMembershipID($row->membershipID)->setTitle($row->title)->setGroupID($row->groupID)->setSource($row->source)->setCreated($row->created)->setDescription($row->description); $entries[] = $entry; } diff --git a/application/modules/user/controllers/PrebootController.php b/application/modules/user/controllers/PrebootController.php index 730debb..a2bbc48 100644 --- a/application/modules/user/controllers/PrebootController.php +++ b/application/modules/user/controllers/PrebootController.php @@ -152,111 +152,17 @@ class User_PrebootController extends Zend_Controller_Action { echo "Caught exception: " . get_class($e) . "<br/>"; echo "Message: " . $e->getMessage() . "<br/>"; - //$this->_redirect('/user/preboot/index/page/'.$this->page.'/addresult/error'); + $this->_redirect('/user/preboot/index/page/'.$this->page.'/addresult/error'); //TODO Delete folder + preboot in DB } - //$this->_redirect('/user/preboot/index/page/'.$this->page.'/addresult/ok'); + $this->_redirect('/user/preboot/index/page/'.$this->page.'/addresult/ok'); } } $this->view->prebootForm = $prebootForm; } - public function checkupdateAction($preboot) - { - - //ACL Is he allowed to update Preboots? - if(!Pbs_Acl::checkRight('pru')) - $this->_redirect('/user/preboot/index/page/'.$this->page.'/updateresult/forbidden'); - - $prebootID = $preboot->getID(); - exec("wget --server-response --spider ".escapeshellcmd($preboot->getPath_preboot())." 2>&1 | grep 'Last-Modified:'", $prebootdate); - - //print_a($prebootdate); - - $prebootdate = strtotime(trim(str_replace('Last-Modified:', '', array_pop($prebootdate)))); - - if(is_file("../resources/bootmedium/$prebootID/preboot.zip")){ - $prebootolddate = filemtime("../resources/bootmedium/".$prebootID."/preboot.zip"); - }else{ - $pbsNotifier = new Pbs_Notifier(); - $this->view->notification = $pbsNotifier->notify('There are updates available','ok'); - return true; - } - - //print_a($prebootname,$prebootdate,$prebootolddate); - - $pbsNotifier = new Pbs_Notifier(); - - if($prebootdate > $prebootolddate){ - $this->view->notification = $pbsNotifier->notify('There are updates available','ok'); - return true; - } - else - return false; - - } - - public function updateprebootAction() - { - //ACL Is he allowed to update Preboots? - if(!Pbs_Acl::checkRight('pru')) - $this->_redirect('/user/preboot/index/page/'.$this->page.'/updateresult/forbidden'); - - $prebootID = $this->_request->getParam('prebootID'); - if (!is_numeric($prebootID)) - $this->_redirect('/user/preboot/index/page/'.$this->page.'/updateresult/forbidden'); - - $preboot = new Application_Model_PreBoot(); - $this->prebootMapper->find($prebootID,$preboot); - - if($this->membership->getGroupID() != $preboot->getGroupID()) - $this->_redirect('/user/preboot/index/page/'.$this->page.'/updateresult/forbidden'); - - - $path_preboot = "../resources/bootmedium/$prebootID/"; - - exec("wget -O '".$path_preboot."preboot.zip' ".escapeshellcmd($preboot->getPath_preboot())." 2>&1 | grep 'saved'", $status); - - if(!array_pop($status)){ - $this->_redirect('/user/preboot/index/page/'.$this->page.'/updateresult/404'); - } - - try{ - $filelist = array(); - $filelist = scandir($path_preboot); - - $bootisoMapper = new Application_Model_BootIsoMapper(); - - //TODO Lock preboot - - foreach($filelist as $file){ - if($file == preg_match('![0-9]+\.zip!')){ - $bootisoID = str_replace('.zip', '', $file); - $serialnumber = $bootisoMapper->find($bootisoID)->getSerialnumber(); - - 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/serial", $serialnumber); - $zip->close(); - } - } - } - }catch(Zend_Exception $e) - { - echo "Caught exception: " . get_class($e) . "<br/>"; - echo "Message: " . $e->getMessage() . "<br/>"; - $this->_redirect('/user/preboot/index/page/'.$this->page.'/modifyresult/error'); - //TODO Delete Folder + Preboot - } - - $this->_redirect('/user/preboot/index/page/'.$this->page.'/modifyresult/ok'); - } - public function editprebootAction() { //ACL Is he allowed to edit Preboots? @@ -268,7 +174,6 @@ class User_PrebootController extends Zend_Controller_Action if (!is_numeric($prebootID)) $this->_redirect('/user/preboot/index/page/'.$this->page.'/modifyresult/forbidden'); - $preboot = new Application_Model_PreBoot(); $this->prebootMapper->find($prebootID, $preboot); @@ -291,56 +196,20 @@ class User_PrebootController extends Zend_Controller_Action if ($prebootForm->isValid($_POST)) { $prebootold = $preboot; - + $source = $_SERVER['REMOTE_ADDR']; + $preboot = new Application_Model_PreBoot($_POST); $preboot->setGroupID($this->membership->getGroupID()); $preboot->setID($prebootID); + $preboot->setSource($source); + $preboot->setCreated(time()); - $path_preboot = "../resources/bootmedium/$prebootID/"; + $prebootpath = "../resources/bootmedium/$prebootID/"; - if($preboot->getPath_preboot() != $prebootold->getPath_preboot()){ - - //ACL Is he allowed to edit the Preboot Path? - if(!Pbs_Acl::checkRight('pre')) - $this->_redirect('/user/preboot/index/page/'.$this->page.'/modifyresult/forbidden'); - - exec("wget -O '".$path_preboot."preboot.zip' ".escapeshellcmd($preboot->getPath_preboot()) ." 2>&1 | grep 'saved'" , $status); - if(!array_pop($status)){ - $this->view->prebootForm = $prebootForm; - $pbsNotifier = new Pbs_Notifier(); - echo $pbsNotifier->notify('The Resource was not found on the specified path','error'); - - return; - } - - try{ - $filelist = array(); - $filelist = scandir($path_preboot); - - $bootisoMapper = new Application_Model_BootIsoMapper(); - - //TODO Lock preboot - - foreach($filelist as $file){ - if(preg_match('![0-9]+\.zip!',$file)){ - $bootisoID = str_replace('.zip', '', $file); - $serialnumber = $bootisoMapper->find($bootisoID)->getSerialnumber(); - - 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/serial", $serialnumber); - $zip->close(); - } - } - } - }catch(Zend_Exception $e){ - echo "Caught exception: " . get_class($e) . "<br/>"; - echo "Message: " . $e->getMessage() . "<br/>"; - $this->_redirect('/user/preboot/index/page/'.$this->page.'/modifyresult/error'); - } + mkdir($prebootpath ,0777, true); + + if(isset($_FILES['preboot'])){ + move_uploaded_file($_FILES['preboot']['tmp_name'], $prebootpath."preboot.zip"); } try { diff --git a/application/modules/user/forms/Bootos.php b/application/modules/user/forms/Bootos.php index 1dd0d07..d9cd24f 100644 --- a/application/modules/user/forms/Bootos.php +++ b/application/modules/user/forms/Bootos.php @@ -63,39 +63,6 @@ class user_Form_Bootos extends Zend_Form 'label' => 'Description:', )); - $this->addElement('text', 'path_init', array( - 'filters' => array('StringTrim'), - 'validators' => array( - array('StringLength', false, array(0, 250)), - ), - 'required' => false, - 'size' => 50, - 'readOnly' => $meta, - 'label' => 'Init-Path:', - )); - - $this->addElement('text', 'path_kernel', array( - 'filters' => array('StringTrim'), - 'validators' => array( - array('StringLength', false, array(0, 250)), - ), - 'required' => false, - 'size' => 50, - 'readOnly' => $meta, - 'label' => 'Kernel-Path:', - )); - - $this->addElement('text', 'path_config', array( - 'filters' => array('StringTrim'), - 'validators' => array( - array('StringLength', false, array(0, 250)), - ), - 'required' => false, - 'size' => 50, - 'readOnly' => $meta, - 'label' => 'Config-Path:', - )); - $this->addElement('textarea', 'defaultkcl', array( 'filters' => array('StringTrim'), 'validators' => array( diff --git a/application/modules/user/forms/Preboot.php b/application/modules/user/forms/Preboot.php index 634b2b7..54dc216 100644 --- a/application/modules/user/forms/Preboot.php +++ b/application/modules/user/forms/Preboot.php @@ -33,6 +33,12 @@ class user_Form_Preboot extends Zend_Form else $meta = null; + if($this->action == 'editpreboot') + $filereq = false; + else + $filereq = true; + + $this->addElement('text', 'title', array( 'filters' => array('StringTrim'), 'validators' => array( @@ -45,7 +51,7 @@ class user_Form_Preboot extends Zend_Form $this->addElement('textarea', 'description', array( 'filters' => array('StringTrim'), 'validators' => array( - array('StringLength', false, array(0, 50)), + array('StringLength', false, array(0, 140)), ), 'required' => false, 'rows' => 5, @@ -54,7 +60,8 @@ class user_Form_Preboot extends Zend_Form )); $this->addElement('file', 'preboot', array( - 'required' => true, + 'validators' => array(array('Extension', false, array('zip'))), + 'required' => $filereq, 'readOnly' => $meta, 'label' => 'Preboot:', )); diff --git a/application/modules/user/views/scripts/bootos/index.phtml b/application/modules/user/views/scripts/bootos/index.phtml index c0f201e..c39ac05 100644 --- a/application/modules/user/views/scripts/bootos/index.phtml +++ b/application/modules/user/views/scripts/bootos/index.phtml @@ -100,12 +100,6 @@ <?php if(Pbs_Acl::checkRight('boai')): ?> <label>BootosID</label> <div class='item'><?php echo $this->escape($bootos->getID()); ?> </div> - <label>initPath</label> - <div class='item'><?php echo $this->escape($bootos->getPath_init()); ?> </div> - <label>kernelPath</label> - <div class='item'><?php echo $this->escape($bootos->getPath_kernel()); ?> </div> - <label>configPath</label> - <div class='item'><?php echo $this->escape($bootos->getPath_config()); ?> </div> <label>Default KCL</label> <div class='item'><?php echo $this->escape($bootos->getDefaultkcl()); ?> </div> <label>Source</label> diff --git a/application/modules/user/views/scripts/preboot/index.phtml b/application/modules/user/views/scripts/preboot/index.phtml index b714b75..415db2e 100644 --- a/application/modules/user/views/scripts/preboot/index.phtml +++ b/application/modules/user/views/scripts/preboot/index.phtml @@ -52,6 +52,7 @@ <?php endif; ?> </div> <div class='title'><?php echo $this->escape($preboot->getTitle()); ?></div> + <div class='subtitle'><?php echo $this->escape($preboot->getDescription()); ?></div> <div class='details'> <label>PrebootID</label> <div class='item'><?php echo $this->escape($preboot->getID()); ?></div> diff --git a/api_bootos_test.html b/scripts/api_bootos_test.html index e48fb21..e48fb21 100644 --- a/api_bootos_test.html +++ b/scripts/api_bootos_test.html diff --git a/api_preboot_test.html b/scripts/api_preboot_test.html index 5c3805b..5c3805b 100644 --- a/api_preboot_test.html +++ b/scripts/api_preboot_test.html |