From c31d8e9959efade437fb0a661f6f44329cc74664 Mon Sep 17 00:00:00 2001 From: Simon Date: Tue, 19 Apr 2011 15:43:00 +0200 Subject: Code autoformatiert --- .../modules/user/controllers/PrebootController.php | 590 ++++++++++----------- 1 file changed, 295 insertions(+), 295 deletions(-) (limited to 'application/modules/user/controllers/PrebootController.php') diff --git a/application/modules/user/controllers/PrebootController.php b/application/modules/user/controllers/PrebootController.php index ee2a684..f3eac39 100644 --- a/application/modules/user/controllers/PrebootController.php +++ b/application/modules/user/controllers/PrebootController.php @@ -12,22 +12,22 @@ class User_PrebootController extends Zend_Controller_Action { - + protected $prebootMapper; protected $membershipMapper; protected $membership; protected $page; - - public function init() - { - if (Zend_Auth::getInstance()->hasIdentity()) { + + public function init() + { + if (Zend_Auth::getInstance()->hasIdentity()) { $userIDsNamespace = Zend_Session::namespaceGet('userIDs'); if($userIDsNamespace['membershipID'] ==''){ $this->_redirect('/user/index'); } - + $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); @@ -35,14 +35,14 @@ class User_PrebootController extends Zend_Controller_Action $this->db = Zend_Db_Table::getDefaultAdapter(); } else { $this->_helper->redirector('login', 'auth'); - } - $this->page = $this->_request->getParam('page'); - } - - - public function indexAction() - { - $result = $this->_request->getParam('addresult'); + } + $this->page = $this->_request->getParam('page'); + } + + + public function indexAction() + { + $result = $this->_request->getParam('addresult'); if($result != ""){ $pbsNotifier = new Pbs_Notifier(); $this->view->notification = $pbsNotifier->notify('create',$result); @@ -57,272 +57,272 @@ class User_PrebootController extends Zend_Controller_Action $pbsNotifier = new Pbs_Notifier(); $this->view->notification = $pbsNotifier->notify('modify',$result); } - $result = $this->_request->getParam('updateresult'); + $result = $this->_request->getParam('updateresult'); if($result != ""){ $pbsNotifier = new Pbs_Notifier(); $this->view->notification = $pbsNotifier->notify('update',$result); } - - $groupID = $this->membership->getGroupID(); - - //ACL Darf er PrebootMenu sehen? - if(!Pbs_Acl::checkRight('pro')) - $this->_redirect('/user/index'); - - $this->view->prebootlist = $this->prebootMapper->findBy(array("groupID" => $groupID)); - - // Search + + $groupID = $this->membership->getGroupID(); + + //ACL Darf er PrebootMenu sehen? + if(!Pbs_Acl::checkRight('pro')) + $this->_redirect('/user/index'); + + $this->view->prebootlist = $this->prebootMapper->findBy(array("groupID" => $groupID)); + + // Search $search = $this->_request->getParam('search'); $mySearch = new Pbs_Search(); $mySearch->setSearchTerm($search); $mySearch->setModule('preboot'); if($search != ''){ - $this->view->search = $mySearch->getSearchTerm(); - $this->view->prebootlist = $mySearch->search($this->view->prebootlist); + $this->view->search = $mySearch->getSearchTerm(); + $this->view->prebootlist = $mySearch->search($this->view->prebootlist); } $this->view->searchform = $mySearch->searchForm(); - - // Pagination - $pagination = new Pbs_Pagination(); - $pagination->setPerPage(10); + + // Pagination + $pagination = new Pbs_Pagination(); + $pagination->setPerPage(10); $pagination->setElement($this->view->prebootlist); - $pagination->setRequestPage($this->_request->getParam('page')); + $pagination->setRequestPage($this->_request->getParam('page')); $pagination->setPageUrl('/user/preboot/index'.((isset($this->view->search))?'/search/'.$this->view->search:'')); - $this->view->prebootlist = $pagination->getElements(); - + $this->view->prebootlist = $pagination->getElements(); + $this->view->pagination = $pagination->pagination(); - $this->view->page = $pagination->getRequestPage(); - - $this->view->update = array(); - - $update = $this->_request->getParam('checkupdate'); - - foreach ($this->view->prebootlist as $preboot){ - $this->view->update[$preboot->getID()] = $update && $this->checkupdateAction($preboot); - } - } - - public function searchAction(){ + $this->view->page = $pagination->getRequestPage(); + + $this->view->update = array(); + + $update = $this->_request->getParam('checkupdate'); + + foreach ($this->view->prebootlist as $preboot){ + $this->view->update[$preboot->getID()] = $update && $this->checkupdateAction($preboot); + } + } + + public function searchAction(){ $this->_redirect('/user/preboot/index/search/'.($_GET['search'])); } - - public function createprebootAction() - { - - //ACL Is he allowed to create Preboots? - if(!Pbs_Acl::checkRight('prc')) - $this->_redirect('/user/preboot/index/page/'.$this->page.'/addresult/forbidden'); - - if (!isset($_POST["createpreboot"])){ - $prebootForm = new user_Form_Preboot(array( + + public function createprebootAction() + { + + //ACL Is he allowed to create Preboots? + if(!Pbs_Acl::checkRight('prc')) + $this->_redirect('/user/preboot/index/page/'.$this->page.'/addresult/forbidden'); + + if (!isset($_POST["createpreboot"])){ + $prebootForm = new user_Form_Preboot(array( 'action' => 'createpreboot', 'page' => $this->page)); - } else { - - $prebootForm = new user_Form_Preboot(array( + } else { + + $prebootForm = new user_Form_Preboot(array( 'action' => 'createpreboot', 'page' => $this->page),$_POST); - - if ($prebootForm->isValid($_POST)) { - - $preboot = new Application_Model_PreBoot($_POST); - $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'); + + if ($prebootForm->isValid($_POST)) { + + $preboot = new Application_Model_PreBoot($_POST); + $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/page/'.$this->page.'/addresult/error'); - //TODO Delete folder + preboot in DB - - } - $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){ + 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/page/'.$this->page.'/addresult/error'); + //TODO Delete folder + preboot in DB + + } + $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; - } - 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/"; - + } + + //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'); - } - + $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 - + + //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(); - } - } + $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/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? - if(!Pbs_Acl::checkRight('pre') && !Pbs_Acl::checkRight('prem')) - $this->_redirect('/user/preboot/index/page/'.$this->page.'/modifyresult/forbidden'); - - $prebootID = $this->_request->getParam('prebootID'); - - if (!is_numeric($prebootID)) - $this->_redirect('/user/preboot/index/page/'.$this->page.'/modifyresult/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.'/modifyresult/forbidden'); - - if (!isset($_POST["editpreboot"])){ - - $prebootForm = new user_Form_Preboot(array( + { + echo "Caught exception: " . get_class($e) . "
"; + echo "Message: " . $e->getMessage() . "
"; + $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? + if(!Pbs_Acl::checkRight('pre') && !Pbs_Acl::checkRight('prem')) + $this->_redirect('/user/preboot/index/page/'.$this->page.'/modifyresult/forbidden'); + + $prebootID = $this->_request->getParam('prebootID'); + + if (!is_numeric($prebootID)) + $this->_redirect('/user/preboot/index/page/'.$this->page.'/modifyresult/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.'/modifyresult/forbidden'); + + if (!isset($_POST["editpreboot"])){ + + $prebootForm = new user_Form_Preboot(array( 'action' => 'editpreboot', 'page' => $this->page)); - $prebootForm->populate($preboot->toArray()); - - }else{ - - $prebootForm = new user_Form_Preboot(array( + $prebootForm->populate($preboot->toArray()); + + }else{ + + $prebootForm = new user_Form_Preboot(array( 'action' => 'editpreboot', 'page' => $this->page),$_POST); - - if ($prebootForm->isValid($_POST)) { - - $prebootold = $preboot; - - $preboot = new Application_Model_PreBoot($_POST); - $preboot->setGroupID($this->membership->getGroupID()); - $preboot->setID($prebootID); - - $path_preboot = "../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(); + + if ($prebootForm->isValid($_POST)) { + + $prebootold = $preboot; + + $preboot = new Application_Model_PreBoot($_POST); + $preboot->setGroupID($this->membership->getGroupID()); + $preboot->setID($prebootID); + + $path_preboot = "../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(); + return; + } + + try{ + $filelist = array(); $filelist = scandir($path_preboot); $bootisoMapper = new Application_Model_BootIsoMapper(); - //TODO Lock preboot + //TODO Lock preboot foreach($filelist as $file){ if(preg_match('![0-9]+\.zip!',$file)){ @@ -330,70 +330,70 @@ class User_PrebootController extends Zend_Controller_Action $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(); - } - } + $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/page/'.$this->page.'/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/page/'.$this->page.'/modifyresult/error'); - //TODO Delete Folder + Preboot - } - + }catch(Zend_Exception $e){ + echo "Caught exception: " . get_class($e) . "
"; + echo "Message: " . $e->getMessage() . "
"; + $this->_redirect('/user/preboot/index/page/'.$this->page.'/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/page/'.$this->page.'/modifyresult/error'); + //TODO Delete Folder + Preboot + } + $this->_redirect('/user/preboot/index/page/'.$this->page.'/modifyresult/ok'); - } - } - - $this->view->prebootForm = $prebootForm; - } - - public function deleteprebootAction() - { - - //ACL Is he allowed to delete Preboots? - if(!Pbs_Acl::checkRight('prd')) - $this->_redirect('/user/preboot/index/page/'.$this->page.'/deleteresult/forbidden'); - - try{ - $prebootID = $this->_request->getParam('prebootID'); - if (!is_numeric($prebootID)) - $this->_redirect('/user/preboot/index/page/'.$this->page.'/deleteresult/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.'/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/page/'.$this->page.'/deleteresult/error'); - } - $this->_redirect('/user/preboot/index/page/'.$this->page.'/deleteresult/ok'); - } + } + } + + $this->view->prebootForm = $prebootForm; + } + + public function deleteprebootAction() + { + + //ACL Is he allowed to delete Preboots? + if(!Pbs_Acl::checkRight('prd')) + $this->_redirect('/user/preboot/index/page/'.$this->page.'/deleteresult/forbidden'); + + try{ + $prebootID = $this->_request->getParam('prebootID'); + if (!is_numeric($prebootID)) + $this->_redirect('/user/preboot/index/page/'.$this->page.'/deleteresult/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.'/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/page/'.$this->page.'/deleteresult/error'); + } + $this->_redirect('/user/preboot/index/page/'.$this->page.'/deleteresult/ok'); + } } - + -- cgit v1.2.3-55-g7522