From fd0e66bf49af0bc56e68830b4c59294f0ec8c101 Mon Sep 17 00:00:00 2001 From: michael pereira Date: Fri, 18 Mar 2011 19:24:47 +0100 Subject: BootOs Update implementiert, BootISO anlegen und some fixes --- .../modules/dev/controllers/BootosController.php | 74 ++++++++++++++++++++-- 1 file changed, 67 insertions(+), 7 deletions(-) (limited to 'application/modules/dev/controllers/BootosController.php') diff --git a/application/modules/dev/controllers/BootosController.php b/application/modules/dev/controllers/BootosController.php index 36c1cf5..5f8aaf0 100644 --- a/application/modules/dev/controllers/BootosController.php +++ b/application/modules/dev/controllers/BootosController.php @@ -19,8 +19,11 @@ class dev_BootosController extends Zend_Controller_Action $configmapper = new Application_Model_ConfigMapper(); $this->view->bootoslist = $bootosmapper->fetchAll(); + $this->view->update = array(); + if(count($this->view->bootoslist)>0){ foreach ($this->view->bootoslist as $bootos){ + $this->view->update[$bootos->getID()] = $this->checkupdateAction($bootos); $bootos->setGroupID("[".$bootos->getGroupID()."] ".$groupmapper->find($bootos->getGroupID())->getTitle()); $bootos->setMembershipID("[".$bootos->getMembershipID()."] ".$personmapper->find($membershipmapper->find($bootos->getMembershipID())->getPersonID())->getFirstname()); $bootos->setConfigID("[".$bootos->getConfigID()."] ".$configmapper->find($bootos->getConfigID())->getTitle()); @@ -36,12 +39,12 @@ class dev_BootosController extends Zend_Controller_Action $configmapper = new Application_Model_ConfigMapper(); if (!isset($_POST["createbootos"])){ - try{ + try{ $createbootosForm = new dev_Form_BootosCreate(array('grouplist' => $groupmapper->fetchAll() ,'configlist'=>$configmapper->fetchAll())); - }catch(Zend_Exception $e){ - print_a($e); - } - } else { + }catch(Zend_Exception $e){ + print_a($e); + } + } else { $createbootosForm = new dev_Form_BootosCreate(array('grouplist' => $groupmapper->fetchAll() ,'configlist'=>$configmapper->fetchAll()),$_POST); @@ -55,13 +58,23 @@ class dev_BootosController extends Zend_Controller_Action $bootos->setCreated(time()); try { + exec("wget --spider ".$bootos->getPath_kernel()." 2>&1 | grep 'Remote file exists.'", $exists_kernel); + exec("wget --spider ".$bootos->getPath_init()." 2>&1 | grep 'Remote file exists.'" , $exists_init); + + if(!array_pop($exists_init) || !array_pop($exists_kernel)){ + $this->view->createbootosForm = $createbootosForm; + return; + } + $bootosID = $bootosmapper->save($bootos); $initpath = "../resources/bootos/".$bootosID."/initramfs/"; $kernelpath = "../resources/bootos/".$bootosID."/kernel/"; - + exec("wget -P ".$kernelpath." ".$bootos->getPath_kernel()); - exec("wget -P ".$initpath." ".$bootos->getPath_init()); + exec("wget -P ".$initpath." ".$bootos->getPath_init()); + + }catch(Zend_Exception $e) { @@ -76,6 +89,52 @@ class dev_BootosController extends Zend_Controller_Action $this->view->createbootosForm = $createbootosForm; } + + public function checkupdateAction($bootos) + { + exec("wget --server-response --spider '".escapeshellcmd($bootos->getPath_kernel())."' 2>&1 | grep 'Last-Modified:'", $kerneldate); + exec("wget --server-response --spider '".escapeshellcmd($bootos->getPath_init())."' 2>&1 | grep 'Last-Modified:'", $initdate); + + $kerneldate = strtotime(trim(str_replace('Last-Modified:', '', array_pop($kerneldate)))); + $kernelname = array_pop(scandir("../resources/bootos/".$bootos->getID()."/kernel/")); + + if($kernelname != "." && $kernelname != "..") + $kernelolddate = filemtime("../resources/bootos/".$bootos->getID()."/kernel/".$kernelname); + else + $kernelolddate = false; + + $initdate = strtotime(trim(str_replace('Last-Modified:', '', array_pop($initdate)))); + $initname = array_pop(scandir("../resources/bootos/".$bootos->getID()."/initramfs/")); + + if($initname != "." && $initname != "..") + $initolddate = filemtime("../resources/bootos/".$bootos->getID()."/initramfs/".$initname); + else + $initolddate = false; + + //print_a($kernelname,$kerneldate,$kernelolddate,$initname,$initdate,$initolddate); + + + if($kerneldate > $kernelolddate || $initdate > $initolddate) + return true; + else + return false; + + } + + public function updatebootosAction() + { + $bootosID = $this->_request->getParam('bootosID'); + $bootosmapper = new Application_Model_BootOsMapper(); + $bootos = $bootosmapper->find($bootosID); + + $initpath = "../resources/bootos/".$bootosID."/initramfs/"; + $kernelpath = "../resources/bootos/".$bootosID."/kernel/"; + + exec("wget -P ".$kernelpath." -N ".$bootos->getPath_kernel()); + exec("wget -P ".$initpath." -N ".$bootos->getPath_init()); + + $this->_redirect('/dev/bootos'); + } public function editbootosAction() { @@ -100,6 +159,7 @@ class dev_BootosController extends Zend_Controller_Action if ($editbootosForm->isValid($_POST)) { + //TODO: Check for new URL and download new files. $bootos = new Application_Model_BootOs($_POST); $bootos->setMembershipID('1'); if($bootos->getConfigID() == '') -- cgit v1.2.3-55-g7522