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/BootisoController.php | 15 +++++ .../modules/dev/controllers/BootosController.php | 74 ++++++++++++++++++++-- .../modules/dev/controllers/ResourceController.php | 16 +++-- 3 files changed, 92 insertions(+), 13 deletions(-) (limited to 'application/modules/dev/controllers') diff --git a/application/modules/dev/controllers/BootisoController.php b/application/modules/dev/controllers/BootisoController.php index 2b0e624..86454cd 100644 --- a/application/modules/dev/controllers/BootisoController.php +++ b/application/modules/dev/controllers/BootisoController.php @@ -42,7 +42,22 @@ class dev_BootisoController extends Zend_Controller_Action $bootiso->setCreated(time()); 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) . "
"; 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() == '') diff --git a/application/modules/dev/controllers/ResourceController.php b/application/modules/dev/controllers/ResourceController.php index 653b70d..cbca8d0 100644 --- a/application/modules/dev/controllers/ResourceController.php +++ b/application/modules/dev/controllers/ResourceController.php @@ -33,14 +33,16 @@ class dev_ResourceController extends Zend_Controller_Action if(is_dir("../resources/bootos/$bootosID/initramfs/") && is_numeric($bootosID)){ header('Content-Type: application/x-gzip'); - $content_disp = ( ereg('MSIE ([0-9].[0-9]{1,2})', $HTTP_USER_AGENT) == 'IE') ? 'inline' : 'attachment'; + $content_disp = ( ereg('MSIE ([0-9].[0-9]{1,2})', $_SERVER['HTTP_USER_AGENT']) == 'IE') ? 'inline' : 'attachment'; header('Content-Disposition: ' . $content_disp . '; filename="initramfs"'); header('Pragma: no-cache'); header('Expires: 0'); // create file. chdir("../resources/bootos/$bootosID/initramfs/"); - passthru( "cat initramfs"); + $initname = array_pop(scandir("./")); + + passthru( "cat ".$initname); } } @@ -58,7 +60,7 @@ class dev_ResourceController extends Zend_Controller_Action if(is_dir("../resources/config/$configID/config/") && is_numeric($configID)){ header('Content-Type: application/x-gzip'); - $content_disp = ( ereg('MSIE ([0-9].[0-9]{1,2})', $HTTP_USER_AGENT) == 'IE') ? 'inline' : 'attachment'; + $content_disp = ( ereg('MSIE ([0-9].[0-9]{1,2})', $_SERVER['HTTP_USER_AGENT']) == 'IE') ? 'inline' : 'attachment'; header('Content-Disposition: ' . $content_disp . '; filename="config.tar.gz"'); header('Pragma: no-cache'); header('Expires: 0'); @@ -76,14 +78,16 @@ class dev_ResourceController extends Zend_Controller_Action if(is_dir("../resources/bootos/$bootosID/kernel/") && is_numeric($bootosID)){ header('Content-Type: application/x-gzip'); - $content_disp = ( ereg('MSIE ([0-9].[0-9]{1,2})', $HTTP_USER_AGENT) == 'IE') ? 'inline' : 'attachment'; + $content_disp = ( ereg('MSIE ([0-9].[0-9]{1,2})', $_SERVER['HTTP_USER_AGENT']) == 'IE') ? 'inline' : 'attachment'; header('Content-Disposition: ' . $content_disp . '; filename="kernel"'); header('Pragma: no-cache'); header('Expires: 0'); // create the gzipped tarfile. chdir("../resources/bootos/$bootosID/kernel/"); - passthru( "cat kernel"); + $kernelname = array_pop(scandir("./")); + + passthru( "cat ". $kernelname); } } @@ -98,7 +102,7 @@ class dev_ResourceController extends Zend_Controller_Action $bmemapper->find($bmeID,$bme); header('Content-Type: text/html'); - $content_disp = ( ereg('MSIE ([0-9].[0-9]{1,2})', $HTTP_USER_AGENT) == 'IE') ? 'inline' : 'attachment'; + $content_disp = ( ereg('MSIE ([0-9].[0-9]{1,2})', $_SERVER['HTTP_USER_AGENT']) == 'IE') ? 'inline' : 'attachment'; header('Content-Disposition: ' . $content_disp . '; filename="kcl.txt"'); header('Pragma: no-cache'); header('Expires: 0'); -- cgit v1.2.3-55-g7522