diff options
author | Sebastian Schmelzer | 2012-01-11 14:36:35 +0100 |
---|---|---|
committer | Sebastian Schmelzer | 2012-01-11 14:36:35 +0100 |
commit | fca04a6dab252eb9e8c0a92ce3b7e14b32e68d1e (patch) | |
tree | 6e6aaf749f34db8c7c7153c23ef85c57187430bb /application/modules/dev/controllers/PrebootController.php | |
parent | API: mit addBootos kann man nun auch editieren (diff) | |
download | pbs2-fca04a6dab252eb9e8c0a92ce3b7e14b32e68d1e.tar.gz pbs2-fca04a6dab252eb9e8c0a92ce3b7e14b32e68d1e.tar.xz pbs2-fca04a6dab252eb9e8c0a92ce3b7e14b32e68d1e.zip |
format source files
Diffstat (limited to 'application/modules/dev/controllers/PrebootController.php')
-rw-r--r-- | application/modules/dev/controllers/PrebootController.php | 373 |
1 files changed, 181 insertions, 192 deletions
diff --git a/application/modules/dev/controllers/PrebootController.php b/application/modules/dev/controllers/PrebootController.php index c3933c6..4936d2c 100644 --- a/application/modules/dev/controllers/PrebootController.php +++ b/application/modules/dev/controllers/PrebootController.php @@ -1,206 +1,195 @@ -<?php +<? php /* * Copyright (c) 2011 - OpenSLX GmbH, RZ Uni Freiburg - * This program is free software distributed under the GPL version 2. - * See http://gpl.openslx.org/ - * - * If you have any feedback please consult http://feedback.openslx.org/ and - * send your suggestions, praise, or complaints to feedback@openslx.org - * - * General information about OpenSLX can be found at http://openslx.org/ - */ - -class dev_PrebootController extends Zend_Controller_Action -{ - - public function init() - { - $db = Zend_Db_Table::getDefaultAdapter(); - } +* This program is free software distributed under the GPL version 2. +* See http://gpl.openslx.org/ +* +* If you have any feedback please consult http://feedback.openslx.org/ and +* send your suggestions, praise, or complaints to feedback@openslx.org +* +* General information about OpenSLX can be found at http://openslx.org/ +*/ + +class dev_PrebootController extends Zend_Controller_Action { + + public function init() { + $db = Zend_Db_Table::getDefaultAdapter(); + } - public function indexAction() - { - $prebootmapper = new Application_Model_PreBootMapper(); - $groupmapper = new Application_Model_GroupMapper(); - $membershipmapper = new Application_Model_MembershipMapper(); - $personmapper = new Application_Model_PersonMapper(); - - $this->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 indexAction() { + $prebootmapper = new Application_Model_PreBootMapper(); + $groupmapper = new Application_Model_GroupMapper(); + $membershipmapper = new Application_Model_MembershipMapper(); + $personmapper = new Application_Model_PersonMapper(); + + $this->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/"; - mkdir($path_preboot ,0777, true); - - exec("wget -O '".$path_preboot."preboot.zip' ".$preboot->getPath_preboot()); - - - }catch(Zend_Exception $e) - { - echo "Caught exception: " . get_class($e) . "<br/>"; - echo "Message: " . $e->getMessage() . "<br/>"; - - } - $this->_redirect('/dev/preboot'); - } - } - + } + + 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/"; + mkdir($path_preboot , 0777, true); + + exec("wget -O '".$path_preboot."preboot.zip' ".$preboot->getPath_preboot()); + + + } catch(Zend_Exception $e) { + echo "Caught exception: " . get_class($e) . "<br/>"; + echo "Message: " . $e->getMessage() . "<br/>"; + + } + $this->_redirect('/dev/preboot'); + } } - - public function checkupdateAction($preboot) - { - $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); - - - 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 -O '".$path_preboot."preboot.zip' ".$preboot->getPath_preboot()); - - $filelist = array(); - $filelist = scandir($path_preboot); - - $bootisoMapper = new Application_Model_BootIsoMapper(); - - foreach($filelist as $file){ - if($file == "." || $file == ".." || $file == "preboot.zip"){ - //do nothing - } - else{ - $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(); - } - } - } - - $this->_redirect('/dev/preboot'); + + $this->view->createprebootForm = $createprebootForm; + } + + public function checkupdateAction($preboot) { + $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); + + + 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 -O '".$path_preboot."preboot.zip' ".$preboot->getPath_preboot()); + + $filelist = array(); + $filelist = scandir($path_preboot); + + $bootisoMapper = new Application_Model_BootIsoMapper(); + + foreach($filelist as $file) { + if($file == "." || $file == ".." || $file == "preboot.zip") { + //do nothing + } else { + $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(); + } + } } - 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) . "<br/>"; - echo "Message: " . $e->getMessage() . "<br/>"; - } - - $this->_redirect('/dev/preboot'); - } - - } - - $this->view->editprebootForm = $editprebootForm; + $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) . "<br/>"; + echo "Message: " . $e->getMessage() . "<br/>"; + } + + $this->_redirect('/dev/preboot'); + } + } - 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'); + $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'); + } } |