From 03b4da383449c290ea01723095d1a87fa257fea5 Mon Sep 17 00:00:00 2001 From: michael pereira Date: Tue, 29 Mar 2011 10:59:15 +0200 Subject: Preboot User Controller fertig, ACL fehlt noch --- application/models/GroupMapper.php | 1 + application/models/PreBootMapper.php | 12 +- .../modules/user/controllers/FilterController.php | 4 +- .../modules/user/controllers/IndexController.php | 1 + .../modules/user/controllers/PrebootController.php | 369 +++++++++++++++++++++ application/modules/user/forms/Preboot.php | 56 ++++ application/modules/user/layouts/user.phtml | 1 + .../user/views/scripts/preboot/createpreboot.phtml | 4 + .../user/views/scripts/preboot/editpreboot.phtml | 4 + .../modules/user/views/scripts/preboot/index.phtml | 61 ++++ 10 files changed, 510 insertions(+), 3 deletions(-) create mode 100644 application/modules/user/controllers/PrebootController.php create mode 100644 application/modules/user/forms/Preboot.php create mode 100644 application/modules/user/views/scripts/preboot/createpreboot.phtml create mode 100644 application/modules/user/views/scripts/preboot/editpreboot.phtml create mode 100644 application/modules/user/views/scripts/preboot/index.phtml (limited to 'application') diff --git a/application/models/GroupMapper.php b/application/models/GroupMapper.php index 331a61c..fa458d1 100644 --- a/application/models/GroupMapper.php +++ b/application/models/GroupMapper.php @@ -68,6 +68,7 @@ class Application_Model_GroupMapper public function find($id,Application_Model_Group $group = null) { + $return = false; if($group == null){ $return = true; } diff --git a/application/models/PreBootMapper.php b/application/models/PreBootMapper.php index db6d99f..6053b19 100644 --- a/application/models/PreBootMapper.php +++ b/application/models/PreBootMapper.php @@ -14,11 +14,21 @@ class Application_Model_PreBootMapper ->where($criteria . ' = ?', $value); $stmt = $select->query(); $result = $stmt->fetchAll(); - return $result; + + $entries = array(); + foreach ($result as $row) { + + $entry = new Application_Model_PreBoot($row); + $entry->setID($row['prebootID']); + $entries[] = $entry; + } + + return $entries; }catch (Zend_Exception $e) { echo "Error message 2: " . $e->getMessage() . "\n"; } } + public function setDbTable($dbTable) { diff --git a/application/modules/user/controllers/FilterController.php b/application/modules/user/controllers/FilterController.php index 70aa60b..d49e68f 100644 --- a/application/modules/user/controllers/FilterController.php +++ b/application/modules/user/controllers/FilterController.php @@ -316,11 +316,11 @@ class User_FilterController extends Zend_Controller_Action $this->view->editfilterform = $editfilterform; } else{ - $this->_redirect('/user/filter/index/moodifyresult/forbidden'); + $this->_redirect('/user/filter/index/modifyresult/forbidden'); } }catch (Zend_Exception $e) { echo "Error message 2: " . $e->getMessage() . "\n"; - $this->_redirect('/user/filter/index/moodifyresult/error'); + $this->_redirect('/user/filter/index/modifyresult/error'); } } else{ try{ diff --git a/application/modules/user/controllers/IndexController.php b/application/modules/user/controllers/IndexController.php index f795b16..f786eb7 100644 --- a/application/modules/user/controllers/IndexController.php +++ b/application/modules/user/controllers/IndexController.php @@ -9,6 +9,7 @@ class User_IndexController extends Zend_Controller_Action public function indexAction() { + if (!Zend_Auth::getInstance()->hasIdentity()) { $this->view->text = 'Your not logged in, please log in first here.'; } diff --git a/application/modules/user/controllers/PrebootController.php b/application/modules/user/controllers/PrebootController.php new file mode 100644 index 0000000..e1e67a5 --- /dev/null +++ b/application/modules/user/controllers/PrebootController.php @@ -0,0 +1,369 @@ +hasIdentity()) { + $userIDsNamespace = Zend_Session::namespaceGet('userIDs'); + if($userIDsNamespace['membershipID'] ==''){ + $pbsNotifier = new Pbs_Notifier(); + echo $pbsNotifier->notify('No membershipID set','forbidden'); + } + + $this->prebootMapper = new Application_Model_PreBootMapper(); + + $this->membershipMapper = new Application_Model_MembershipMapper(); + $this->membership = new Application_Model_Membership(); + $this->membershipMapper->find($userIDsNamespace['membershipID'],$this->membership); + + $this->db = Zend_Db_Table::getDefaultAdapter(); + } else { + $this->_helper->redirector('login', 'auth'); + } + } + + + public function indexAction() + { + $result = $this->_request->getParam('addresult'); + if($result != ""){ + $pbsNotifier = new Pbs_Notifier(); + $this->view->notification = $pbsNotifier->notify('create',$result); + } + $result = $this->_request->getParam('deleteresult'); + if($result != ""){ + $pbsNotifier = new Pbs_Notifier(); + $this->view->notification = $pbsNotifier->notify('delete',$result); + } + $result = $this->_request->getParam('modifyresult'); + if($result != ""){ + $pbsNotifier = new Pbs_Notifier(); + $this->view->notification = $pbsNotifier->notify('modify',$result); + } + $result = $this->_request->getParam('updateresult'); + if($result != ""){ + $pbsNotifier = new Pbs_Notifier(); + $this->view->notification = $pbsNotifier->notify('update',$result); + } + + $groupMapper = new Application_Model_GroupMapper(); + $personMapper = new Application_Model_PersonMapper(); + + $groupID = $this->membership->getGroupID(); + + //TODO ACL Darf er PrebootMenu sehen? + if(false) + $this->_redirect('/user/index'); + + $this->view->prebootlist = $this->prebootMapper->findBy("groupID", $groupID); + + $this->view->update = array(); + + $update = $this->_request->getParam('checkupdate'); + + foreach ($this->view->prebootlist as $preboot){ + $this->view->update[$preboot->getID()] = $update && $this->checkupdateAction($preboot); + $preboot->setGroupID("[".$preboot->getGroupID()."] ".$groupMapper->find($preboot->getGroupID())->getTitle()); + $preboot->setMembershipID("[".$preboot->getMembershipID()."] ".$personMapper->find($this->membershipMapper->find($preboot->getMembershipID())->getPersonID())->getFirstname()); + } + } + + public function createprebootAction() + { + + //TODO ACL Is he allowed to create Preboots? + if(false) + $this->_redirect('/user/preboot/index/addresult/forbidden'); + + if (!isset($_POST["createpreboot"])){ + $prebootForm = new user_Form_Preboot(array('action' => 'createpreboot')); + } else { + + $prebootForm = new user_Form_Preboot(array('action' => 'createpreboot'),$_POST); + + if ($prebootForm->isValid($_POST)) { + + $preboot = new Application_Model_PreBoot($_POST); + $preboot->setMembershipID($this->membership->getID()); + $preboot->setGroupID($this->membership->getGroupID()); + + try { + + $path_tmp = "../resources/bootmedium/"; + mkdir($path_tmp ,0777, true); + + $hash = md5(microtime(1)); + exec("wget -O '".$path_tmp."preboot.zip".$hash."' ".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; + } + + $prebootID = $this->prebootMapper->save($preboot); + + $path_preboot = "../resources/bootmedium/$prebootID/"; + mkdir($path_preboot ,0777, true); + + exec("mv ../resources/bootmedium/preboot.zip$hash ../resources/bootmedium/$prebootID/preboot.zip"); + + }catch(Zend_Exception $e) + { + echo "Caught exception: " . get_class($e) . "
"; + echo "Message: " . $e->getMessage() . "
"; + $this->_redirect('/user/preboot/index/addresult/error'); + //TODO Delete folder + preboot + + } + $this->_redirect('/user/preboot/index/addresult/ok'); + } + } + + $this->view->prebootForm = $prebootForm; + } + + public function checkupdateAction($preboot) + { + + //TODO ACL Is he allowed to update Preboots? + if(false) + $this->_redirect('/user/preboot/index/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 + $prebootolddate = false; + + //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() + { + //TODO ACL Is he allowed to update Preboots? + if(false) + $this->_redirect('/user/preboot/index/updateresult/forbidden'); + + $prebootID = $this->_request->getParam('prebootID'); + if (!is_numeric($prebootID)) + $this->_redirect('/user/preboot/index/updateresult/forbidden'); + + + $preboot = new Application_Model_PreBoot(); + $this->prebootMapper->find($prebootID,$preboot); + + if($this->membership->getGroupID() != $preboot->getGroupID()) + $this->_redirect('/user/preboot/index/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/modifyresult/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) . "
"; + echo "Message: " . $e->getMessage() . "
"; + $this->_redirect('/user/preboot/index/modifyresult/error'); + //TODO Delete Folder + Preboot + } + + $this->_redirect('/user/preboot/index/modifyresult/ok'); + } + + public function editprebootAction() + { + //TODO ACL Is he allowed to edit Preboots? + if(false) + $this->_redirect('/user/preboot/index/modifyresult/forbidden'); + + $prebootID = $this->_request->getParam('prebootID'); + + if (!is_numeric($prebootID)) + $this->_redirect('/user/preboot/index/modifyresult/forbidden'); + + if (!isset($_POST["editpreboot"])){ + + $preboot = new Application_Model_PreBoot(); + $this->prebootMapper->find($prebootID, $preboot); + + if($this->membership->getGroupID() != $preboot->getGroupID()) + $this->_redirect('/user/preboot/index/modifyresult/forbidden'); + + $prebootForm = new user_Form_Preboot(array('action' => 'editpreboot')); + $prebootForm->populate($preboot->toArray()); + + }else{ + + //TODO ACL Is he allowed to edit Preboots? + if(false) + $this->_redirect('/user/preboot/index/modifyresult/forbidden'); + + $prebootForm = new user_Form_Preboot(array('action' => 'editpreboot'),$_POST); + + if ($prebootForm->isValid($_POST)) { + + $prebootold = new Application_Model_PreBoot(); + $this->prebootMapper->find($prebootID, $prebootold); + + $preboot = new Application_Model_PreBoot($_POST); + $preboot->setMembershipID($this->membership->getID()); + $preboot->setGroupID($this->membership->getGroupID()); + + if($this->membership->getGroupID() != $preboot->getGroupID()) + $this->_redirect('/user/preboot/index/modifyresult/forbidden'); + + $preboot->setMembershipID($this->membership->getID()); + $preboot->setGroupID($this->membership->getGroupID()); + $preboot->setID($prebootID); + + $path_preboot = "../resources/bootmedium/$prebootID/"; + + if($preboot->getPath_preboot() != $prebootold->getPath_preboot()){ + + //TODO ACL Is he allowed to edit the Preboot Path? + if(false) + $this->_redirect('/user/preboot/index/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) . "
"; + echo "Message: " . $e->getMessage() . "
"; + $this->_redirect('/user/preboot/index/modifyresult/error'); + } + } + + try { + + $this->prebootMapper->save($preboot); + + }catch(Zend_Exception $e){ + echo "Caught exception: " . get_class($e) . "
"; + echo "Message: " . $e->getMessage() . "
"; + $this->_redirect('/user/preboot/index/modifyresult/error'); + //TODO Delete Folder + Preboot + } + + $this->_redirect('/user/preboot/index/modifyresult/ok'); + } + } + + $this->view->prebootForm = $prebootForm; + } + + public function deleteprebootAction() + { + + //TODO ACL Is he allowed to delete Preboots? + if(false) + $this->_redirect('/user/preboot/index/deleteresult/forbidden'); + + try{ + $prebootID = $this->_request->getParam('prebootID'); + if (!is_numeric($prebootID)) + $this->_redirect('/user/preboot/index/deleteresult/forbidden'); + + $preboot = new Application_Model_PreBoot(); + $this->prebootMapper->find($prebootID, $preboot); + + if($this->membership->getGroupID() != $preboot->getGroupID()) + $this->_redirect('/user/preboot/index/deleteresult/forbidden'); + + $this->prebootMapper->delete($preboot); + exec("rm -r ../resources/bootmedium/".$prebootID); + }catch(Zend_Exception $e){ + echo "Caught exception: " . get_class($e) . "
"; + echo "Message: " . $e->getMessage() . "
"; + $this->_redirect('/user/preboot/index/deleteresult/error'); + } + $this->_redirect('/user/preboot/index/deleteresult/ok'); + } + + +} + + + diff --git a/application/modules/user/forms/Preboot.php b/application/modules/user/forms/Preboot.php new file mode 100644 index 0000000..d46ae9c --- /dev/null +++ b/application/modules/user/forms/Preboot.php @@ -0,0 +1,56 @@ +action = $action; + + } + + public function init() + { + $this->setName($this->action); + $this->setMethod('post'); + + $this->addElement('text', 'title', array( + 'filters' => array('StringTrim'), + 'validators' => array( + array('StringLength', false, array(0, 50)), + ), + 'required' => true, + 'label' => 'Title:', + )); + + $this->addElement('text', 'path_preboot', array( + 'filters' => array('StringTrim'), + 'validators' => array( + array('StringLength', false, array(0, 240)), + ), + 'required' => true, + 'size' => 50, + 'label' => 'Path to Preboot:', + )); + + if($this->action == "createpreboot") + $label = "Create Preboot"; + else + $label = "Edit Preboot"; + + $this->addElement('submit', $this->action, array( + 'required' => false, + 'ignore' => true, + 'label' => $label, + )); + + $this->addElement('button', 'Cancel', array( + 'onclick' => 'self.location="/user/preboot"' + )); + + } + + +} + diff --git a/application/modules/user/layouts/user.phtml b/application/modules/user/layouts/user.phtml index c7f54dc..83b1c49 100644 --- a/application/modules/user/layouts/user.phtml +++ b/application/modules/user/layouts/user.phtml @@ -30,6 +30,7 @@ echo $this->headScript()."\n"; + diff --git a/application/modules/user/views/scripts/preboot/createpreboot.phtml b/application/modules/user/views/scripts/preboot/createpreboot.phtml new file mode 100644 index 0000000..3690cfb --- /dev/null +++ b/application/modules/user/views/scripts/preboot/createpreboot.phtml @@ -0,0 +1,4 @@ +prebootForm; +echo $this->prebootForm; +?> diff --git a/application/modules/user/views/scripts/preboot/editpreboot.phtml b/application/modules/user/views/scripts/preboot/editpreboot.phtml new file mode 100644 index 0000000..3690cfb --- /dev/null +++ b/application/modules/user/views/scripts/preboot/editpreboot.phtml @@ -0,0 +1,4 @@ +prebootForm; +echo $this->prebootForm; +?> diff --git a/application/modules/user/views/scripts/preboot/index.phtml b/application/modules/user/views/scripts/preboot/index.phtml new file mode 100644 index 0000000..21ff310 --- /dev/null +++ b/application/modules/user/views/scripts/preboot/index.phtml @@ -0,0 +1,61 @@ +

Preboot

+notification != ''){echo $this->notification;} ?> +formButton('checkupdate', 'Check for Updates', array( + 'onclick' => 'self.location="/user/preboot/index/checkupdate/true"', + 'class' => 'updatebutton', + ))?> +formButton('createpreboot', 'Create PreBoot', array( + 'onclick' => 'self.location="/user/preboot/createpreboot"', + 'class' => 'addbutton'))?> + + + + + + + + + + prebootlist)==0) + echo "
IDTitleGroupIDMembershipIDPreboot PathActions
There are no Preboot entries to display." ?> + prebootlist as $preboot): ?> + + escape($preboot->getID()); ?> + escape($preboot->getTitle()); ?> + escape($preboot->getGroupID()); ?> + escape($preboot->getMembershipID()); ?> + escape($preboot->getPath_preboot()); ?> + update[$preboot->getID()]==true): ?> + Updates available + + No updates available + + Edit Preboot + Delete Preboot + + + \ No newline at end of file -- cgit v1.2.3-55-g7522 From 8a616c5e6d2a56b2aee5a10d68c27b99458a2c77 Mon Sep 17 00:00:00 2001 From: michael pereira Date: Tue, 29 Mar 2011 11:21:38 +0200 Subject: merges --- .zfproject.xml | 3 +- .../modules/user/controllers/IndexController.php | 3 +- application/modules/user/layouts/user.phtml | 32 +--------------------- 3 files changed, 5 insertions(+), 33 deletions(-) (limited to 'application') diff --git a/.zfproject.xml b/.zfproject.xml index 262f79c..c7a4807 100644 --- a/.zfproject.xml +++ b/.zfproject.xml @@ -316,6 +316,7 @@ + @@ -331,9 +332,9 @@ - + diff --git a/application/modules/user/controllers/IndexController.php b/application/modules/user/controllers/IndexController.php index f786eb7..1e15768 100644 --- a/application/modules/user/controllers/IndexController.php +++ b/application/modules/user/controllers/IndexController.php @@ -21,8 +21,9 @@ class User_IndexController extends Zend_Controller_Action '/user/config' => 'Create your own Configuration', '/user/bootmenu' => 'Create your Bootmenu', ); + $this->view->links = $links; } - $this->view->links = $links; + } diff --git a/application/modules/user/layouts/user.phtml b/application/modules/user/layouts/user.phtml index 35f0b22..e09df87 100644 --- a/application/modules/user/layouts/user.phtml +++ b/application/modules/user/layouts/user.phtml @@ -19,36 +19,6 @@ echo $this->headScript()."\n";
-<<<<<<< HEAD - -
-
@@ -62,6 +32,7 @@ echo $this->headScript()."\n"; + @@ -75,7 +46,6 @@ echo $this->headScript()."\n"; Membership >>>>>> d7af4710c133f5cfaf830c9ef617bac9730a77d3 ?> -- cgit v1.2.3-55-g7522