From 19d1af16ad8a2fdaa5aa608693b81fa9502e162d Mon Sep 17 00:00:00 2001 From: michael pereira Date: Mon, 21 Mar 2011 10:49:32 +0100 Subject: Preboot Controller eingerichtet --- .../modules/dev/controllers/BootisoController.php | 57 ++++--- .../modules/dev/controllers/PrebootController.php | 170 +++++++++++++++++++++ 2 files changed, 209 insertions(+), 18 deletions(-) create mode 100644 application/modules/dev/controllers/PrebootController.php (limited to 'application/modules/dev/controllers') diff --git a/application/modules/dev/controllers/BootisoController.php b/application/modules/dev/controllers/BootisoController.php index 86454cd..7390c95 100644 --- a/application/modules/dev/controllers/BootisoController.php +++ b/application/modules/dev/controllers/BootisoController.php @@ -14,25 +14,57 @@ class dev_BootisoController extends Zend_Controller_Action $groupmapper = new Application_Model_GroupMapper(); $membershipmapper = new Application_Model_MembershipMapper(); $personmapper = new Application_Model_PersonMapper(); + $prebootmapper = new Application_Model_PreBootMapper(); $this->view->bootisolist = $bootisomapper->fetchAll(); + $this->view->prebootlist = array(); + foreach ($this->view->bootisolist as $bootiso){ + $this->view->prebootlist[$bootiso->getID()] = $prebootmapper->find($bootiso->getPrebootID())->getTitle(); $bootiso->setGroupID("[".$bootiso->getGroupID()."] ".$groupmapper->find($bootiso->getGroupID())->getTitle()); $bootiso->setMembershipID("[".$bootiso->getMembershipID()."] ".$personmapper->find($membershipmapper->find($bootiso->getMembershipID())->getPersonID())->getFirstname()); } + } + + public function downloadbootisoAction() + { + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + + $prebootID = $this->_request->getParams('prebootID'); + + // if(is_dir("../resources/bootmedium/$prebootID/") && is_numeric($prebootID)){ + + 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.tar.gz"'); + header('Pragma: no-cache'); + header('Expires: 0'); + + // create the gzipped tarfile. + chdir(APPLICATION_PATH . "/resources/bootmedium/$prebootID/"); + passthru( "tar cz ./"); + + $this->_redirect('/dev/bootiso'); + //} + + + + } public function createbootisoAction() { $groupmapper = new Application_Model_GroupMapper(); + $prebootmapper = new Application_Model_PreBootMapper(); if (!isset($_POST["createbootiso"])){ - $createbootisoForm = new dev_Form_BootisoCreate(array('grouplist' => $groupmapper->fetchAll())); + $createbootisoForm = new dev_Form_BootisoCreate(array('grouplist' => $groupmapper->fetchAll(),'prebootlist' => $prebootmapper->fetchAll())); } else { - $createbootisoForm = new dev_Form_BootisoCreate(array('grouplist' => $groupmapper->fetchAll()),$_POST); + $createbootisoForm = new dev_Form_BootisoCreate(array('grouplist' => $groupmapper->fetchAll(),'prebootlist' => $prebootmapper->fetchAll()),$_POST); if ($createbootisoForm->isValid($_POST)) { @@ -43,21 +75,8 @@ class dev_BootisoController extends Zend_Controller_Action try { - exec("wget --spider ".$bootiso->getPath_fbgui()." 2>&1 | grep 'Remote file exists.'", $exists_fbgui); - - if(!array_pop($exists_fbgui)){ - $this->view->createbootisoForm = $createbootisoForm; - return; - } - $bootisomapper->save($bootiso); - - $path_fbgui = "../resources/bootmedium/fbgui/"; - - exec("wget -P ".$path_fbgui." -N ".$bootiso->getPath_fbgui()); - - - + }catch(Zend_Exception $e) { echo "Caught exception: " . get_class($e) . "
"; @@ -75,6 +94,8 @@ class dev_BootisoController extends Zend_Controller_Action { $bootisoID = $this->_request->getParam('bootisoID'); $groupmapper = new Application_Model_GroupMapper(); + $prebootmapper = new Application_Model_PreBootMapper(); + if (!isset($_POST["editbootiso"])){ $bootisoID = $this->_request->getParam('bootisoID'); @@ -85,11 +106,11 @@ class dev_BootisoController extends Zend_Controller_Action $bootisomapper = new Application_Model_BootIsoMapper(); $bootisomapper->find($bootisoID, $bootiso); - $editbootisoForm = new dev_Form_BootisoEdit(array('grouplist' => $groupmapper->fetchAll())); + $editbootisoForm = new dev_Form_BootisoEdit(array('grouplist' => $groupmapper->fetchAll(),'prebootlist' => $prebootmapper->fetchAll())); $editbootisoForm->populate($bootiso->toArray()); } }else{ - $editbootisoForm = new dev_Form_BootisoEdit(array('grouplist' => $groupmapper->fetchAll()),$_POST); + $editbootisoForm = new dev_Form_BootisoEdit(array('grouplist' => $groupmapper->fetchAll(),'prebootlist' => $prebootmapper->fetchAll()),$_POST); if ($editbootisoForm->isValid($_POST)) { diff --git a/application/modules/dev/controllers/PrebootController.php b/application/modules/dev/controllers/PrebootController.php new file mode 100644 index 0000000..e319058 --- /dev/null +++ b/application/modules/dev/controllers/PrebootController.php @@ -0,0 +1,170 @@ +view->prebootlist = $prebootmapper->fetchAll(); + $this->view->update = array(); + + foreach ($this->view->prebootlist as $preboot){ + $this->view->update[$preboot->getID()] = $this->checkupdateAction($preboot); + $preboot->setGroupID("[".$preboot->getGroupID()."] ".$groupmapper->find($preboot->getGroupID())->getTitle()); + $preboot->setMembershipID("[".$preboot->getMembershipID()."] ".$personmapper->find($membershipmapper->find($preboot->getMembershipID())->getPersonID())->getFirstname()); + } + } + + public function createprebootAction() + { + $groupmapper = new Application_Model_GroupMapper(); + + if (!isset($_POST["createpreboot"])){ + $createprebootForm = new dev_Form_PrebootCreate(array('grouplist' => $groupmapper->fetchAll())); + } else { + + $createprebootForm = new dev_Form_PrebootCreate(array('grouplist' => $groupmapper->fetchAll()),$_POST); + + if ($createprebootForm->isValid($_POST)) { + + $preboot = new Application_Model_PreBoot($_POST); + $preboot->setMembershipID('1'); + $prebootmapper = new Application_Model_PreBootMapper(); + + try { + + exec("wget --spider ".$preboot->getPath_preboot()." 2>&1 | grep 'Remote file exists.'", $exists_preboot); + + if(!array_pop($exists_preboot)){ + $this->view->createprebootForm = $createprebootForm; + return; + } + + $prebootID = $prebootmapper->save($preboot); + + $path_preboot = "../resources/bootmedium/$prebootID/"; + + exec("wget -P ".$path_preboot." -r -nH --cut-dirs=1 -np -R '*.html*' -N ".$preboot->getPath_preboot()); + + + }catch(Zend_Exception $e) + { + echo "Caught exception: " . get_class($e) . "
"; + echo "Message: " . $e->getMessage() . "
"; + + } + $this->_redirect('/dev/preboot'); + } + } + + $this->view->createprebootForm = $createprebootForm; + } + + public function checkupdateAction($preboot) + { + exec("wget --server-response --spider ".escapeshellcmd($preboot->getPath_preboot())."changed 2>&1 | grep 'Last-Modified:'", $prebootdate); + + //print_a($prebootdate); + + $prebootdate = strtotime(trim(str_replace('Last-Modified:', '', array_pop($prebootdate)))); + $prebootname = array_pop(scandir("../resources/bootmedium/".$preboot->getID()."/")); + + if($prebootname != "." && $prebootname != "..") + $prebootolddate = filemtime("../resources/bootmedium/".$preboot->getID()."/".$prebootname); + else + $prebootolddate = false; + + //print_a($prebootname,$prebootdate,$prebootolddate); + + + if($prebootdate > $prebootolddate) + return true; + else + return false; + + } + + public function updateprebootAction() + { + $prebootID = $this->_request->getParam('prebootID'); + $prebootmapper = new Application_Model_PreBootMapper(); + $preboot = new Application_Model_PreBoot(); + $prebootmapper->find($prebootID,$preboot); + + $path_preboot = "../resources/bootmedium/$prebootID/"; + + exec("wget -P ".$path_preboot." -r -nH --cut-dirs=1 -np -R '*.html*' -N ".$preboot->getPath_preboot()); + + $this->_redirect('/dev/preboot'); + } + + public function editprebootAction() + { + $prebootID = $this->_request->getParam('prebootID'); + $groupmapper = new Application_Model_GroupMapper(); + + if (!isset($_POST["editpreboot"])){ + $prebootID = $this->_request->getParam('prebootID'); + if (!isset($prebootID) || !is_numeric($prebootID)){ + $this->_redirect('/dev/preboot'); + } else { + $preboot = new Application_Model_PreBoot(); + $prebootmapper = new Application_Model_PreBootMapper(); + $prebootmapper->find($prebootID, $preboot); + + $editprebootForm = new dev_Form_PrebootEdit(array('grouplist' => $groupmapper->fetchAll())); + $editprebootForm->populate($preboot->toArray()); + } + }else{ + $editprebootForm = new dev_Form_PrebootEdit(array('grouplist' => $groupmapper->fetchAll()),$_POST); + + if ($editprebootForm->isValid($_POST)) { + + $preboot = new Application_Model_PreBoot($_POST); + $preboot->setMembershipID('1'); + $prebootmapper = new Application_Model_PreBootMapper(); + $preboot->setID($prebootID); + + try { + $prebootmapper->save($preboot); + }catch(Zend_Exception $e) + { + echo "Caught exception: " . get_class($e) . "
"; + echo "Message: " . $e->getMessage() . "
"; + } + + $this->_redirect('/dev/preboot'); + } + + } + + $this->view->editprebootForm = $editprebootForm; + } + + public function deleteprebootAction() + { + $prebootID = $this->_request->getParam('prebootID'); + if (!isset($prebootID)){ + $this->_redirect('/dev/preboot'); + } else { + $preboot = new Application_Model_PreBoot(); + $preboot->setID($prebootID); + $prebootmapper = new Application_Model_PreBootMapper(); + $prebootmapper->delete($preboot); + } + $this->_redirect('/dev/preboot'); + } + + +} + -- cgit v1.2.3-55-g7522