summaryrefslogtreecommitdiffstats
path: root/application/modules/user/controllers/BootosController.php
diff options
context:
space:
mode:
authormichael pereira2011-03-30 17:23:30 +0200
committermichael pereira2011-03-30 17:23:30 +0200
commita29a04821929e737a436b842e519845d0d29da94 (patch)
treea855b6cc3bfbff0399eba5c22a540dcf90932626 /application/modules/user/controllers/BootosController.php
parentFBGui angepasst (button) (diff)
downloadpbs2-a29a04821929e737a436b842e519845d0d29da94.tar.gz
pbs2-a29a04821929e737a436b842e519845d0d29da94.tar.xz
pbs2-a29a04821929e737a436b842e519845d0d29da94.zip
Bootos & Bootiso
Diffstat (limited to 'application/modules/user/controllers/BootosController.php')
-rw-r--r--application/modules/user/controllers/BootosController.php95
1 files changed, 53 insertions, 42 deletions
diff --git a/application/modules/user/controllers/BootosController.php b/application/modules/user/controllers/BootosController.php
index 8daa96c..ecc29d7 100644
--- a/application/modules/user/controllers/BootosController.php
+++ b/application/modules/user/controllers/BootosController.php
@@ -83,41 +83,48 @@ class user_BootosController extends Zend_Controller_Action
//TODO ACL Darf er BootISOs erstellen?
if(false)
- $this->_redirect('/user/bootiso/index/addresult/forbidden');
+ $this->_redirect('/user/bootos/index/addresult/forbidden');
- $groupMapper = new Application_Model_GroupMapper();
- $configMapper = new Application_Model_ConfigMapper();
+ $groupID = $this->membership->getGroupID();
+
+ $groupgroupsMapper = new Application_Model_GroupGroupsMapper();
+ $childgroups = count($groupgroupsMapper->getChildGroups($groupID));
+
+ $configMapper = new Application_Model_ConfigMapper();
+ $configlist = $configMapper->findBy("groupID", $groupID);
if (!isset($_POST["createbootos"])){
- try{
- $createbootosForm = new user_Form_BootosCreate(array('grouplist' => $groupmapper->fetchAll() ,'configlist'=>$configmapper->fetchAll()));
- }catch(Zend_Exception $e){
- print_a($e);
- }
+ $bootosForm = new user_Form_Bootos(array('action' => 'createbootos', 'groupdepth' => $childgroups, 'configlist'=>$configlist, 'rights' => 'all'));
} else {
- $createbootosForm = new user_Form_BootosCreate(array('grouplist' => $groupmapper->fetchAll() ,'configlist'=>$configmapper->fetchAll()),$_POST);
+ $bootosForm = new user_Form_Bootos(array('action' => 'createbootos', 'groupdepth' => $childgroups, 'configlist'=>$configlist, 'rights' => 'all'),$_POST);
- if ($createbootosForm->isValid($_POST)) {
+ if ($bootosForm->isValid($_POST)) {
$bootos = new Application_Model_BootOs($_POST);
- $bootos->setMembershipID('1');
- if($bootos->getConfigID() == '')
- $bootos->setConfigID(NULL);
- $bootosmapper = new Application_Model_BootOsMapper();
+ $bootos->setMembershipID($this->membership->getID());
+ $bootos->setGroupID($this->membership->getGroupID());
$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;
+
+ $path_tmp = "../resources/bootos/";
+ mkdir($path_tmp ,0777, true);
+
+ $hash = md5(microtime(1));
+ exec("wget -O '".$path_tmp."kernel".$hash."' ".escapeshellcmd($bootos->getPath_kernel())." 2>&1 | grep 'saved'", $status);
+ exec("wget -O '".$path_tmp."initramfs".$hash."' ".escapeshellcmd($bootos->getPath_init())." 2>&1 | grep 'saved'", $status2);
+
+ if(!array_pop($status) || !array_pop($status2)){
+ $this->view->bootosForm = $bootosForm;
+ $pbsNotifier = new Pbs_Notifier();
+ echo $pbsNotifier->notify('The Resource was not found on the specified path','error');
+
return;
}
- $bootosID = $bootosmapper->save($bootos);
+ $bootosID = $this->bootosMapper->save($bootos);
$initpath = "../resources/bootos/".$bootosID."/initramfs/";
$kernelpath = "../resources/bootos/".$bootosID."/kernel/";
@@ -125,45 +132,49 @@ class user_BootosController extends Zend_Controller_Action
mkdir($initpath ,0777, true);
mkdir($kernelpath ,0777, true);
- exec("wget -O '".$kernelpath."kernel' ".$bootos->getPath_kernel());
- exec("wget -O '".$initpath."initramfs' ".$bootos->getPath_init());
-
-
+ exec("mv ../resources/bootos/kernel$hash $kernelpath"."kernel");
+ exec("mv ../resources/bootos/initramfs$hash $initpath"."initramfs");
}catch(Zend_Exception $e)
{
echo "Caught exception: " . get_class($e) . "<br/>";
echo "Message: " . $e->getMessage() . "<br/>";
+ $this->_redirect('/user/bootos/index/addresult/error');
+ //TODO Delete File & delete bootiso from DB
}
- $this->_redirect('/user/bootos');
+ $this->_redirect('/user/bootos/index/addresult/ok');
}
}
- $this->view->createbootosForm = $createbootosForm;
+ $this->view->bootosForm = $bootosForm;
}
public function checkupdateAction($bootos)
{
+
+ //TODO ACL Is he allowed to update Preboots?
+ if(false)
+ $this->_redirect('/user/preboot/index/updateresult/forbidden');
+
+ $bootosID = $bootos->getID();
+
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);
+ if(is_file("../resources/bootmedium/$bootosID/kernel") && is_file("../resources/bootmedium/$bootosID/initramfs")){
+ $kernelolddate = filemtime("../resources/bootos/".$bootosID."/kernel/kernel");
+ $initolddate = filemtime("../resources/bootos/".$bootosID."/initramfs/initramfs");
+ }
else
- $initolddate = false;
+ {
+ $kernelolddate = false;
+ $initolddate = false;
+ }
//print_a($kernelname,$kerneldate,$kernelolddate,$initname,$initdate,$initolddate);
@@ -205,13 +216,13 @@ class user_BootosController extends Zend_Controller_Action
$bootosmapper = new Application_Model_BootOsMapper();
$bootos = $bootosmapper->find($bootosID);
- $editbootosForm = new user_Form_BootosEdit(array('grouplist' => $groupmapper->fetchAll() ,'configlist'=>$configmapper->fetchAll()));
- $editbootosForm->populate($bootos->toArray());
+ $bootosForm = new user_Form_Bootos(array('grouplist' => $groupmapper->fetchAll() ,'configlist'=>$configmapper->fetchAll()));
+ $bootosForm->populate($bootos->toArray());
}
}else{
- $editbootosForm = new user_Form_BootosEdit(array('grouplist' => $groupmapper->fetchAll() ,'configlist'=>$configmapper->fetchAll()),$_POST);
+ $bootosForm = new user_Form_Bootos(array('grouplist' => $groupmapper->fetchAll() ,'configlist'=>$configmapper->fetchAll()),$_POST);
- if ($editbootosForm->isValid($_POST)) {
+ if ($bootosForm->isValid($_POST)) {
//TODO: Check for new URL and download new files.
$bootos = new Application_Model_BootOs($_POST);
@@ -235,7 +246,7 @@ class user_BootosController extends Zend_Controller_Action
}
- $this->view->editbootosForm = $editbootosForm;
+ $this->view->bootosForm = $bootosForm;
}