summaryrefslogtreecommitdiffstats
path: root/application/modules
diff options
context:
space:
mode:
authormichael pereira2011-03-31 00:31:24 +0200
committermichael pereira2011-03-31 00:31:24 +0200
commit75057a1f80aba28e933580725c49de98c7e99155 (patch)
tree0ae293831bf5908d176cfddd047dfe9f7ea1a889 /application/modules
parentBootOS update (diff)
downloadpbs2-75057a1f80aba28e933580725c49de98c7e99155.tar.gz
pbs2-75057a1f80aba28e933580725c49de98c7e99155.tar.xz
pbs2-75057a1f80aba28e933580725c49de98c7e99155.zip
bootos controller fertig
Diffstat (limited to 'application/modules')
-rw-r--r--application/modules/user/controllers/BootisoController.php12
-rw-r--r--application/modules/user/controllers/BootosController.php183
-rw-r--r--application/modules/user/controllers/PrebootController.php4
3 files changed, 145 insertions, 54 deletions
diff --git a/application/modules/user/controllers/BootisoController.php b/application/modules/user/controllers/BootisoController.php
index 8f61838..b94404f 100644
--- a/application/modules/user/controllers/BootisoController.php
+++ b/application/modules/user/controllers/BootisoController.php
@@ -190,6 +190,9 @@ class user_BootisoController extends Zend_Controller_Action
$this->_redirect('/user/bootiso/index/modifyresult/forbidden');
$bootisoID = $this->_request->getParam('bootisoID');
+ if (!is_numeric($bootisoID))
+ $this->_redirect('/user/bootiso/index/modifyresult/forbidden');
+
$groupID = $this->membership->getGroupID();
$prebootMapper = new Application_Model_PreBootMapper();
@@ -200,9 +203,6 @@ class user_BootisoController extends Zend_Controller_Action
if (!isset($_POST["editbootiso"])){
- if (!is_numeric($bootisoID))
- $this->_redirect('/user/bootiso/index/modifyresult/forbidden');
-
$bootiso = new Application_Model_BootIso();
$this->bootisoMapper->find($bootisoID, $bootiso);
@@ -219,7 +219,6 @@ class user_BootisoController extends Zend_Controller_Action
$bootisoold = new Application_Model_BootIso();
$this->bootisoMapper->find($bootisoID, $bootisoold);
-
$bootiso = new Application_Model_BootIso($_POST);
$bootiso->setMembershipID($this->membership->getID());
@@ -233,10 +232,11 @@ class user_BootisoController extends Zend_Controller_Action
$bootiso->getPublic() != $bootisoold->getPublic() ||
$bootiso->getSerialnumber() != $bootisoold->getSerialnumber()){
//TODO ACL Is he allowed to edit other than Metadata?
- if(false)
- $this->_redirect('/user/preboot/index/modifyresult/forbidden');
+ if(true)
+ $this->_redirect('/user/bootiso/index/modifyresult/forbidden');
}
+
try {
$zip = new ZipArchive();
$res = $zip->open("../resources/bootmedium/$prebootID/$bootisoID".".zip");
diff --git a/application/modules/user/controllers/BootosController.php b/application/modules/user/controllers/BootosController.php
index a7b83ee..39341e9 100644
--- a/application/modules/user/controllers/BootosController.php
+++ b/application/modules/user/controllers/BootosController.php
@@ -166,6 +166,8 @@ class user_BootosController extends Zend_Controller_Action
}
else
{
+ $pbsNotifier = new Pbs_Notifier();
+ $this->view->notification = $pbsNotifier->notify('There are updates available','ok');
return true;
}
@@ -175,71 +177,148 @@ class user_BootosController extends Zend_Controller_Action
$kerneldate = strtotime(trim(str_replace('Last-Modified:', '', array_pop($kerneldate))));
$initdate = strtotime(trim(str_replace('Last-Modified:', '', array_pop($initdate))));
- print_a($bootos->getPath_kernel(),$kerneldate,$kernelolddate,$initname,$initdate,$initolddate);
+ //print_a($bootos->getPath_kernel(),$kerneldate,$kernelolddate,$initname,$initdate,$initolddate);
- if($kerneldate > $kernelolddate || $initdate > $initolddate)
+ if($kerneldate > $kernelolddate || $initdate > $initolddate){
+ $this->view->notification = $pbsNotifier->notify('There are updates available','ok');
return true;
- else
+ }else{
return false;
+ }
}
public function updatebootosAction()
{
+
+ //TODO ACL Is he allowed to update Preboots?
+ if(false)
+ $this->_redirect('/user/bootiso/index/updateresult/forbidden');
+
$bootosID = $this->_request->getParam('bootosID');
- $bootosmapper = new Application_Model_BootOsMapper();
- $bootos = $bootosmapper->find($bootosID);
+ if (!is_numeric($bootosID))
+ $this->_redirect('/user/bootos/index/updateresult/forbidden');
+
+ $bootos = $this->bootosMapper->find($bootosID);
+ if($this->membership->getGroupID() != $bootos->getGroupID())
+ $this->_redirect('/user/bootos/index/updateresult/forbidden');
+
$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());
+ $path_tmp = "../resources/bootos/";
+
+ $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->_redirect('/user/bootos/index/updateresult/404');
+ //TODO Delete Files in tmp
+ }
+
+ exec("mv ../resources/bootos/kernel$hash $kernelpath"."kernel");
+ exec("mv ../resources/bootos/initramfs$hash $initpath"."initramfs");
- $this->_redirect('/user/bootos');
+ $this->_redirect('/user/bootos/index/updateresult/ok');
}
public function editbootosAction()
{
+ //TODO ACL Is he allowed to edit Preboots?
+ if(false)
+ $this->_redirect('/user/bootos/index/modifyresult/forbidden');
+
$bootosID = $this->_request->getParam('bootosID');
- $groupmapper = new Application_Model_GroupMapper();
- $configmapper = new Application_Model_ConfigMapper();
+ if (!is_numeric($bootosID))
+ $this->_redirect('/user/bootos/index/modifyresult/forbidden');
+
+ $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["editbootos"])){
- $bootosID = $this->_request->getParam('bootosID');
- if (!isset($bootosID) || !is_numeric($bootosID)){
- $this->_redirect('/user/bootos');
- } else {
- $bootos = new Application_Model_BootOs();
- $bootosmapper = new Application_Model_BootOsMapper();
- $bootos = $bootosmapper->find($bootosID);
-
- $bootosForm = new user_Form_Bootos(array('grouplist' => $groupmapper->fetchAll() ,'configlist'=>$configmapper->fetchAll()));
- $bootosForm->populate($bootos->toArray());
- }
+
+ $bootos = new Application_Model_BootOs();
+ $bootos = $this->bootosMapper->find($bootosID);
+
+ if($this->membership->getGroupID() != $bootos->getGroupID())
+ $this->_redirect('/user/bootos/index/modifyresult/forbidden');
+
+ $bootosForm = new user_Form_Bootos(array('action' => 'editbootos', 'groupdepth' => $childgroups, 'configlist'=>$configlist, 'rights' => 'meta'));
+ $bootosForm->populate($bootos->toArray());
+
}else{
- $bootosForm = new user_Form_Bootos(array('grouplist' => $groupmapper->fetchAll() ,'configlist'=>$configmapper->fetchAll()),$_POST);
+ $bootosForm = new user_Form_Bootos(array('action' => 'editbootos', 'groupdepth' => $childgroups, 'configlist'=>$configlist, 'rights' => 'meta'),$_POST);
if ($bootosForm->isValid($_POST)) {
- //TODO: Check for new URL and download new files.
+ $bootosold = new Application_Model_BootOs();
+ $this->bootosMapper->find($bootosID, $bootosold);
+
$bootos = new Application_Model_BootOs($_POST);
- $bootos->setMembershipID('1');
- if($bootos->getConfigID() == '')
+ $bootos->setMembershipID($this->membership->getID());
+ $bootos->setGroupID($this->membership->getGroupID());
+ $bootos->setCreated(time());
+ if($bootos->getConfigID() == '')
$bootos->setConfigID(NULL);
- $bootosmapper = new Application_Model_BootOsMapper();
- $bootos->setCreated(time());
- $bootos->setID($bootosID);
-
+ $bootos->setID($bootosID);
+
+ if( $bootos->getConfigID() != $bootosold->getConfigID() ||
+ $bootos->getDefaultkcl() != $bootosold->getDefaultkcl() ||
+ $bootos->getExpires() != $bootosold->getExpires() ||
+ $bootos->getPublic() != $bootosold->getPublic() ){
+ //TODO ACL Is he allowed to edit this?
+ if(false)
+ $this->_redirect('/user/bootos/index/modifyresult/forbidden');
+ }
+
+ if($bootos->getPath_kernel() != $bootosold->getPath_kernel() || $bootos->getPath_init() != $bootosold->getPath_init()){
+ //TODO ACL Is he allowed to edit the Kernel/Init Path?
+ if(false)
+ $this->_redirect('/user/bootos/index/modifyresult/forbidden');
+
+ $path_tmp = "../resources/bootos/";
+
+ $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;
+ }
+
+ $initpath = "../resources/bootos/".$bootosID."/initramfs/";
+ $kernelpath = "../resources/bootos/".$bootosID."/kernel/";
+
+ mkdir($initpath ,0777, true);
+ mkdir($kernelpath ,0777, true);
+
+ exec("mv ../resources/bootos/kernel$hash $kernelpath"."kernel");
+ exec("mv ../resources/bootos/initramfs$hash $initpath"."initramfs");
+
+ }
+
try {
- $bootosmapper->save($bootos);
- }catch(Zend_Exception $e)
+ $this->bootosMapper->save($bootos);
+
+ }catch(Zend_Exception $e)
{
echo "Caught exception: " . get_class($e) . "<br/>";
echo "Message: " . $e->getMessage() . "<br/>";
+ $this->_redirect('/user/bootos/index/modifyresult/error');
+ //TODO Delete Folder + Preboot
}
- $this->_redirect('/user/bootos');
+ $this->_redirect('/user/bootos/index/modifyresult/ok');
}
}
@@ -250,20 +329,34 @@ class user_BootosController extends Zend_Controller_Action
public function deletebootosAction()
{
- $bootosID = $this->_request->getParam('bootosID');
- if (!isset($bootosID)){
- $this->_redirect('/user/bootos');
- } else {
- $bootos = new Application_Model_BootOs();
- $bootos->setID($bootosID);
- $bootosmapper = new Application_Model_BootOsMapper();
- $bootosmapper->delete($bootos);
+
+ //TODO ACL Is he allowed to delete Bootos?
+ if(false)
+ $this->_redirect('/user/bootos/index/deleteresult/forbidden');
+
+ try{
+ $bootosID = $this->_request->getParam('bootosID');
+ if (!is_numeric($bootosID))
+ $this->_redirect('/user/bootos/index/deleteresult/forbidden');
+
+ $bootos = new Application_Model_BootOs();
+ $this->bootosMapper->find($bootosID, $bootos);
+
+ if($this->membership->getGroupID() != $bootos->getGroupID())
+ $this->_redirect('/user/bootos/index/deleteresult/forbidden');
+
+ $this->bootosMapper->delete($bootos);
+ exec("rm -r ../resources/bootos/".$bootosID);
+
+ }catch(Zend_Exception $e){
+ echo "Caught exception: " . get_class($e) . "<br/>";
+ echo "Message: " . $e->getMessage() . "<br/>";
+ $this->_redirect('/user/bootos/index/deleteresult/error');
}
- $this->_redirect('/user/bootos');
-
+ $this->_redirect('/user/bootos/index/deleteresult/ok');
}
-
-
+
+
}
diff --git a/application/modules/user/controllers/PrebootController.php b/application/modules/user/controllers/PrebootController.php
index 716b9fa..4a0a95a 100644
--- a/application/modules/user/controllers/PrebootController.php
+++ b/application/modules/user/controllers/PrebootController.php
@@ -172,7 +172,6 @@ class User_PrebootController extends Zend_Controller_Action
if (!is_numeric($prebootID))
$this->_redirect('/user/preboot/index/updateresult/forbidden');
-
$preboot = new Application_Model_PreBoot();
$this->prebootMapper->find($prebootID,$preboot);
@@ -185,7 +184,7 @@ class User_PrebootController extends Zend_Controller_Action
exec("wget -O '".$path_preboot."preboot.zip' ".escapeshellcmd($preboot->getPath_preboot())." 2>&1 | grep 'saved'", $status);
if(!array_pop($status)){
- $this->_redirect('/user/preboot/index/modifyresult/404');
+ $this->_redirect('/user/preboot/index/updateresult/404');
}
try{
@@ -306,7 +305,6 @@ class User_PrebootController extends Zend_Controller_Action
}
try {
-
$this->prebootMapper->save($preboot);
}catch(Zend_Exception $e){