summaryrefslogtreecommitdiffstats
path: root/application/modules/user/controllers
diff options
context:
space:
mode:
Diffstat (limited to 'application/modules/user/controllers')
-rw-r--r--application/modules/user/controllers/BootisoController.php281
1 files changed, 279 insertions, 2 deletions
diff --git a/application/modules/user/controllers/BootisoController.php b/application/modules/user/controllers/BootisoController.php
index 5f9dcdb..2642a8d 100644
--- a/application/modules/user/controllers/BootisoController.php
+++ b/application/modules/user/controllers/BootisoController.php
@@ -1,12 +1,27 @@
<?php
-class User_BootisoController extends Zend_Controller_Action
+class user_BootisoController extends Zend_Controller_Action
{
+ protected $bootisoMapper;
+ protected $membershipMapper;
+ protected $membership;
+
public function init()
{
if (Zend_Auth::getInstance()->hasIdentity()) {
+ $userIDsNamespace = Zend_Session::namespaceGet('userIDs');
+ if($userIDsNamespace['membershipID'] ==''){
+ $this->_redirect('/user/index');
+ }
+ $this->bootisoMapper = new Application_Model_BootIsoMapper();
+
+ $this->membershipMapper = new Application_Model_MembershipMapper();
+ $this->membership = new Application_Model_Membership();
+ $this->membershipMapper->find($userIDsNamespace['membershipID'],$this->membership);
+
+ $this->db = Zend_Db_Table::getDefaultAdapter();
} else {
$this->_helper->redirector('login', 'auth');
}
@@ -14,9 +29,271 @@ class User_BootisoController extends Zend_Controller_Action
public function indexAction()
{
- // action body
+ $result = $this->_request->getParam('addresult');
+ if($result != ""){
+ $pbsNotifier = new Pbs_Notifier();
+ $this->view->notification = $pbsNotifier->notify('create',$result);
+ }
+ $result = $this->_request->getParam('deleteresult');
+ if($result != ""){
+ $pbsNotifier = new Pbs_Notifier();
+ $this->view->notification = $pbsNotifier->notify('delete',$result);
+ }
+ $result = $this->_request->getParam('modifyresult');
+ if($result != ""){
+ $pbsNotifier = new Pbs_Notifier();
+ $this->view->notification = $pbsNotifier->notify('modify',$result);
+ }
+ $result = $this->_request->getParam('downloadresult');
+ if($result != ""){
+ $pbsNotifier = new Pbs_Notifier();
+ $this->view->notification = $pbsNotifier->notify('download',$result);
+ }
+
+
+ $groupMapper = new Application_Model_GroupMapper();
+ $personMapper = new Application_Model_PersonMapper();
+
+ $groupID = $this->membership->getGroupID();
+
+ //TODO ACL Darf er BootISOMenu sehen?
+ if(false)
+ $this->_redirect('/user/index');
+
+ $groupgroupsMapper = new Application_Model_GroupGroupsMapper();
+
+ $parents = array();
+ $this->view->bootisolist = array();
+ $parents = $groupgroupsMapper->getParentGroups($groupID);
+
+ foreach($parents as $k => $parent){
+ foreach($parent as $p){
+ $bootiso = $this->bootisoMapper->findBy("groupID", $p);
+ foreach ($bootiso as $b)
+ if($b->getPublic() - $k >= 0 )
+ $this->view->bootisolist[] = $b;
+ }
+ }
+
+ $this->view->bootisolist = array_reverse($this->view->bootisolist);
+
+ $prebootMapper = new Application_Model_PreBootMapper();
+ $this->view->prebootlist = array();
+
+ foreach ($this->view->bootisolist as $bootiso){
+ $this->view->prebootlist[$bootiso->getID()] = $prebootMapper->find($bootiso->getPrebootID())->getTitle();
+ $bootiso->setGroupID("[".$bootiso->getGroupID()."] ".$groupMapper->find($bootiso->getGroupID())->getTitle());
+ $bootiso->setMembershipID("[".$bootiso->getMembershipID()."] ".$personMapper->find($this->membershipMapper->find($bootiso->getMembershipID())->getPersonID())->getFirstname());
+ }
+
+ }
+
+ public function downloadbootisoAction()
+ {
+ $this->_helper->layout->disableLayout();
+ $this->_helper->viewRenderer->setNoRender(true);
+
+ //TODO ACL Darf er BootISOs downloaden?
+ if(false)
+ $this->_redirect('/user/bootiso/index/downloadresult/forbidden');
+
+ $prebootID = $this->_request->getParam('prebootID');
+ $bootisoID = $this->_request->getParam('bootisoID');
+
+ if(!is_dir("../resources/bootmedium/$prebootID/") || !is_numeric($prebootID) || !is_numeric($bootisoID))
+ $this->_redirect('/user/bootiso/index/downloadresult/forbidden');
+
+ chdir("../resources/bootmedium/$prebootID/");
+
+ header("X-Sendfile: $bootisoID".".zip");
+ header('Content-Type: application/x-gzip');
+ $content_disp = ( ereg('MSIE ([0-9].[0-9]{1,2})', $_SERVER['HTTP_USER_AGENT']) == 'IE') ? 'inline' : 'attachment';
+ header('Content-Disposition: ' . $content_disp . '; filename="preboot.zip"');
+ header('Pragma: no-cache');
+ header('Expires: 0');
+
+ $handle = fopen($bootisoID.".zip", 'r');
+ $chunk_size = 8192;
+ while ($chunk = fread($handle, $chunk_size)) {
+ echo $chunk;
+ ob_flush();
+ }
+
+ }
+
+ public function createbootisoAction()
+ {
+ //TODO ACL Darf er BootISOs erstellen?
+ if(false)
+ $this->_redirect('/user/bootiso/index/addresult/forbidden');
+
+ $groupgroupsMapper = new Application_Model_GroupGroupsMapper();
+ $groupID = $this->membership->getGroupID();
+
+ $groupgroupsMapper = new Application_Model_GroupGroupsMapper();
+ $childgroups = count($groupgroupsMapper->getChildGroups($groupID));
+
+ $prebootMapper = new Application_Model_PreBootMapper();
+ $prebootlist = $prebootMapper->findBy("groupID", $groupID);
+
+ if (!isset($_POST["createbootiso"])){
+ $bootisoForm = new user_Form_Bootiso(array('action' => 'createbootiso','prebootlist' => $prebootlist, 'groupdepth' => $childgroups));
+ } else {
+
+ $bootisoForm = new user_Form_Bootiso(array('action' => 'createbootiso','prebootlist' => $prebootlist, 'groupdepth' => $childgroups),$_POST);
+
+ if ($bootisoForm->isValid($_POST)) {
+
+ $bootiso = new Application_Model_BootIso($_POST);
+
+ $bootiso->setMembershipID($this->membership->getID());
+ $bootiso->setGroupID($this->membership->getGroupID());
+ $bootiso->setCreated(time());
+
+ $prebootID = $bootiso->getPrebootID();
+
+ try {
+
+ $bootisoID = $this->bootisoMapper->save($bootiso);
+
+ 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/tmp/serial", $bootiso->getSerialnumber());
+ $zip->close();
+ }
+
+ }catch(Zend_Exception $e)
+ {
+ echo "Caught exception: " . get_class($e) . "<br/>";
+ echo "Message: " . $e->getMessage() . "<br/>";
+ $this->_redirect('/user/bootiso/index/addresult/error');
+ //TODO Delete File & delete bootiso from DB
+
+ }
+ $this->_redirect('/user/bootiso/index/addresult/ok');
+ }
+ }
+
+ $this->view->bootisoForm = $bootisoForm;
+ }
+
+ public function editbootisoAction()
+ {
+ //TODO ACL Darf er BootISOs editieren?
+ if(false)
+ $this->_redirect('/user/bootiso/index/modifyresult/forbidden');
+
+ $bootisoID = $this->_request->getParam('bootisoID');
+ $groupID = $this->membership->getGroupID();
+
+ $prebootMapper = new Application_Model_PreBootMapper();
+ $prebootlist = $prebootMapper->findBy("groupID", $groupID);
+
+ $groupgroupsMapper = new Application_Model_GroupGroupsMapper();
+ $childgroups = count($groupgroupsMapper->getChildGroups($groupID));
+
+ 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);
+
+ if($this->membership->getGroupID() != $bootiso->getGroupID())
+ $this->_redirect('/user/bootiso/index/modifyresult/forbidden');
+
+ $bootisoForm = new user_Form_Bootiso(array('action' => 'editbootiso','prebootlist' => $prebootlist, 'groupdepth' => $childgroups, 'rights' => 'meta'));
+ $bootisoForm->populate($bootiso->toArray());
+
+ }else{
+ $bootisoForm = new user_Form_Bootiso(array('action' => 'editbootiso','prebootlist' => $prebootlist, 'groupdepth' => $childgroups, 'rights' => 'meta'),$_POST);
+
+ if ($bootisoForm->isValid($_POST)) {
+
+ $bootisoold = new Application_Model_BootIso();
+ $this->bootisoMapper->find($bootisoID, $bootisoold);
+
+
+ $bootiso = new Application_Model_BootIso($_POST);
+ $bootiso->setMembershipID($this->membership->getID());
+ $bootiso->setGroupID($this->membership->getGroupID());
+ $bootiso->setCreated(time());
+ $bootiso->setID($bootisoID);
+ $prebootID = $bootiso->getPrebootID();
+
+ if( $bootiso->getPrebootID() != $bootisoold->getPrebootID() ||
+ $bootiso->getExpires() != $bootisoold->getExpires() ||
+ $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');
+ }
+
+ try {
+ $zip = new ZipArchive();
+ $res = $zip->open("../resources/bootmedium/$prebootID/$bootisoID".".zip");
+ if($res === true){
+ $rootdir = $zip->getNameIndex(0);
+ $zip->addFromString($rootdir."build/rootfs/serial", $bootiso->getSerialnumber());
+ $zip->close();
+ }
+
+ $this->bootisoMapper->save($bootiso);
+
+ }catch(Zend_Exception $e)
+ {
+ echo "Caught exception: " . get_class($e) . "<br/>";
+ echo "Message: " . $e->getMessage() . "<br/>";
+ $this->_redirect('/user/bootiso/index/modifyresult/error');
+ //TODO Redo Serial in Files...
+ }
+
+ $this->_redirect('/user/bootiso/index/modifyresult/ok');
+ }
+
+ }
+
+ $this->view->bootisoForm = $bootisoForm;
}
+ public function deletebootisoAction()
+ {
+ //TODO ACL Darf er BootISOs löschen?
+ if(false)
+ $this->_redirect('/user/bootiso/index/deleteresult/forbidden');
+
+ try{
+ $bootisoID = $this->_request->getParam('bootisoID');
+ if (!is_numeric($bootisoID))
+ $this->_redirect('/user/bootiso/index/deleteresult/forbidden');
+
+ $bootiso = new Application_Model_BootIso();
+ $this->bootisoMapper->find($bootisoID,$bootiso);
+
+ if($this->membership->getGroupID() != $bootiso->getGroupID())
+ $this->_redirect('/user/bootiso/index/deleteresult/forbidden');
+
+ $this->bootisoMapper->delete($bootiso);
+
+ }catch(Zend_Exception $e){
+ echo "Caught exception: " . get_class($e) . "<br/>";
+ echo "Message: " . $e->getMessage() . "<br/>";
+ $this->_redirect('/user/bootiso/index/deleteresult/error');
+ }
+ $this->_redirect('/user/bootiso/index/deleteresult/ok');
+ }
+
}
+
+
+
+
+
+