diff options
| author | Sebastian Schmelzer | 2012-01-11 14:36:35 +0100 |
|---|---|---|
| committer | Sebastian Schmelzer | 2012-01-11 14:36:35 +0100 |
| commit | fca04a6dab252eb9e8c0a92ce3b7e14b32e68d1e (patch) | |
| tree | 6e6aaf749f34db8c7c7153c23ef85c57187430bb /application/modules/user/controllers/BootosController.php | |
| parent | API: mit addBootos kann man nun auch editieren (diff) | |
| download | pbs2-fca04a6dab252eb9e8c0a92ce3b7e14b32e68d1e.tar.gz pbs2-fca04a6dab252eb9e8c0a92ce3b7e14b32e68d1e.tar.xz pbs2-fca04a6dab252eb9e8c0a92ce3b7e14b32e68d1e.zip | |
format source files
Diffstat (limited to 'application/modules/user/controllers/BootosController.php')
| -rw-r--r-- | application/modules/user/controllers/BootosController.php | 690 |
1 files changed, 341 insertions, 349 deletions
diff --git a/application/modules/user/controllers/BootosController.php b/application/modules/user/controllers/BootosController.php index f7fad49..c428937 100644 --- a/application/modules/user/controllers/BootosController.php +++ b/application/modules/user/controllers/BootosController.php @@ -1,354 +1,346 @@ -<?php +<? php /* * Copyright (c) 2011 - OpenSLX GmbH, RZ Uni Freiburg - * This program is free software distributed under the GPL version 2. - * See http://gpl.openslx.org/ - * - * If you have any feedback please consult http://feedback.openslx.org/ and - * send your suggestions, praise, or complaints to feedback@openslx.org - * - * General information about OpenSLX can be found at http://openslx.org/ - */ - -class user_BootosController extends Zend_Controller_Action -{ - - protected $bootosMapper; - protected $membershipMapper; - protected $membership; - protected $page; - - public function init() - { - if (Zend_Auth::getInstance()->hasIdentity()) { - $userIDsNamespace = Zend_Session::namespaceGet('userIDs'); - if($userIDsNamespace['membershipID'] ==''){ - $this->_redirect('/user/index'); - } - - $this->bootosMapper = new Application_Model_BootOsMapper(); - $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'); - } - $this->page = $this->_request->getParam('page'); - } - - public function indexAction() - { - $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('updateresult'); - if($result != ""){ - $pbsNotifier = new Pbs_Notifier(); - $this->view->notification = $pbsNotifier->notify('update',$result); - } - - $groupID = $this->membership->getGroupID(); - - //ACL Darf er BootOs sehen? - if(!Pbs_Acl::checkRight('boai') && !Pbs_Acl::checkRight('boui')) - $this->_redirect('/user/index'); - - $groupgroupsMapper = new Application_Model_GroupGroupsMapper(); - - $parents = array(); - $this->view->bootoslist = array(); - $parents = $groupgroupsMapper->getParentGroups($groupID); - - foreach($parents as $k => $parent){ - foreach($parent as $p){ - $bootos = $this->bootosMapper->findBy(array("groupID" => $p)); - foreach ($bootos as $b) - if($b->getPublic() - $k >= 0 ) - $this->view->bootoslist[] = $b; - elseif($k == 0 && $b->getPublic() == -1 && Pbs_Acl::checkRight('boc')) - $this->view->bootoslist[] = $b; - } - } - - $this->view->bootoslist = array_reverse($this->view->bootoslist); - $this->view->resources = array(); - - $groupMapper = new Application_Model_GroupMapper(); - - if(count($this->view->bootoslist)>0){ - foreach ($this->view->bootoslist as $bootos){ - if($bootos->getDefaultkcl() == null) - $bootos->setDefaultkcl("none (edit Bootos to set KCL)"); - $this->view->resources[$bootos->getID()]['kernel'] = is_file("../resources/bootos/".$bootos->getID()."/kernel/kernel"); - $this->view->resources[$bootos->getID()]['initramfs'] = is_file("../resources/bootos/".$bootos->getID()."/initramfs/initramfs"); - $this->view->resources[$bootos->getID()]['config'] = is_file("../resources/bootos/".$bootos->getID()."/config/default.tgz"); - $bootos->setGroupID("[".$bootos->getGroupID()."] ".$groupMapper->find($bootos->getGroupID())->getTitle()); - $bootos->setCreated(date(Zend_Registry::get('dateformat'),$bootos->getCreated())); - $bootos->setExpires(date(Zend_Registry::get('dateformat'),$bootos->getExpires())); - } - } - - // Search - $search = $this->_request->getParam('search'); - $mySearch = new Pbs_Search(); - $mySearch->setSearchTerm($search); - $mySearch->setModule('bootos'); - if($search != ''){ - $this->view->search = $mySearch->getSearchTerm(); - $this->view->bootoslist = $mySearch->search($this->view->bootoslist); - } - $this->view->searchform = $mySearch->searchForm(); - - // Pagination - $pagination = new Pbs_Pagination(); - $pagination->setPerPage(10); - $pagination->setElement($this->view->bootoslist); - $pagination->setRequestPage($this->_request->getParam('page')); - $pagination->setPageUrl('/user/bootos/index'.((isset($this->view->search))?'/search/'.$this->view->search:'')); - $this->view->bootoslist = $pagination->getElements(); - - $this->view->pagination = $pagination->pagination(); - $this->view->page = $pagination->getRequestPage(); - - } - public function searchAction(){ - $this->_redirect('/user/bootos/index/search/'.($_GET['search'])); - } - - public function createbootosAction() - { - - //ACL Darf er BootISOs erstellen? - if(!Pbs_Acl::checkRight('boc')) - $this->_redirect('/user/bootos/index/page/'.$this->page.'/addresult/forbidden'); - - $groupID = $this->membership->getGroupID(); - - $groupgroupsMapper = new Application_Model_GroupGroupsMapper(); - $childgroups = count($groupgroupsMapper->getChildGroups($groupID)); - - if (!isset($_POST["createbootos"])){ - $bootosForm = new user_Form_Bootos(array( - 'action' => 'createbootos', - 'groupdepth' => $childgroups, - 'page' => $this->page)); - } else { - - $bootosForm = new user_Form_Bootos(array( - 'action' => 'createbootos', - 'groupdepth' => $childgroups, - 'page' => $this->page),$_POST); - - if ($bootosForm->isValid($_POST)) { - - $bootos = new Application_Model_BootOs($_POST); - - $bootos->setGroupID($this->membership->getGroupID()); - $bootos->setCreated(time()); - $bootos->setSource($_SERVER['REMOTE_ADDR']); - - try { - - $bootosID = $this->bootosMapper->save($bootos); - $bootos->setID($bootosID); - - if( $_FILES['kernel']['size'] == 0 && $_FILES['kernel']['name'] != '' || - $_FILES['init']['size'] == 0 && $_FILES['init']['name'] != '' || - $_FILES['config']['size'] == 0 && $_FILES['config']['name'] != '' ){ - $this->_redirect('/user/preboot/index/page/'.$this->page.'/addresult/file'); - } - - $initpath = "../resources/bootos/".$bootosID."/initramfs/"; - $kernelpath = "../resources/bootos/".$bootosID."/kernel/"; - $configpath = "../resources/bootos/".$bootosID."/config/"; - - mkdir($initpath ,0777, true); - mkdir($kernelpath ,0777, true); - mkdir($configpath ,0777, true); - - if($_FILES['kernel']['name'] != ''){ - move_uploaded_file($_FILES['kernel']['tmp_name'], $kernelpath."kernel"); - } - if($_FILES['init']['name'] != ''){ - move_uploaded_file($_FILES['init']['tmp_name'], $initpath."initramfs"); - } - if($_FILES['config']['name'] != ''){ - move_uploaded_file($_FILES['config']['tmp_name'], $configpath."default.tgz"); - $newconfig = new Pbs_NewConfig(); - $newconfig->createDefaultConfig($bootos); - } - - - }catch(Zend_Exception $e) - { - echo "Caught exception: " . get_class($e) . "<br/>"; - echo "Message: " . $e->getMessage() . "<br/>"; - $this->_redirect('/user/bootos/index/page/'.$this->page.'/addresult/error'); - //TODO Delete File & delete bootiso from DB - - } - - $this->_redirect('/user/bootos/index/page/'.$this->page.'/addresult/ok'); - } - } - - $this->view->bootosForm = $bootosForm; - } - - public function editbootosAction() - { - - //ACL Is he allowed to edit Bootos? - if(!Pbs_Acl::checkRight('boe') && !Pbs_Acl::checkRight('boem')) - $this->_redirect('/user/bootos/index/page/'.$this->page.'/modifyresult/forbidden'); - - $bootosID = $this->_request->getParam('bootosID'); - if (!is_numeric($bootosID)) - $this->_redirect('/user/bootos/index/page/'.$this->page.'/modifyresult/forbidden'); - - $groupID = $this->membership->getGroupID(); - - $groupgroupsMapper = new Application_Model_GroupGroupsMapper(); - $childgroups = count($groupgroupsMapper->getChildGroups($groupID)); - $bootos = new Application_Model_BootOs(); - $bootos = $this->bootosMapper->find($bootosID); - - if($this->membership->getGroupID() != $bootos->getGroupID()) - $this->_redirect('/user/bootos/index/page/'.$this->page.'/modifyresult/forbidden'); - - if (!isset($_POST["editbootos"])){ - - $bootosForm = new user_Form_Bootos(array( - 'action' => 'editbootos', - 'groupdepth' => $childgroups, - 'page' => $this->page)); - - $bootosForm->populate($bootos->toArray()); - - }else{ - $bootosForm = new user_Form_Bootos(array( - 'action' => 'editbootos', - 'groupdepth' => $childgroups, - 'page' => $this->page),$_POST); - - if ($bootosForm->isValid($_POST)) { - - $bootosold = $bootos; - - $bootos = new Application_Model_BootOs($_POST); - $bootos->setGroupID($this->membership->getGroupID()); - $bootos->setSource($bootosold->getSource()); - $bootos->setCreated(time()); - $bootos->setID($bootosID); - - try { - - if( $bootos->getDistro() != $bootosold->getDistro() || - $bootos->getDistroversion() != $bootosold->getDistroversion() || - $bootos->getShare() != $bootosold->getShare() || - $bootos->getShortname() != $bootosold->getShortname() || - $bootos->getDefaultkcl() != $bootosold->getDefaultkcl() || - $bootos->getExpires() != $bootosold->getExpires() || - $bootos->getPublic() != $bootosold->getPublic() ){ - //ACL Is he allowed to edit this? - if(!Pbs_Acl::checkRight('boe')) - $this->_redirect('/user/bootos/index/page/'.$this->page.'/modifyresult/forbidden'); - } - - if($_FILES['kernel']['name'] != '' || $_FILES['init']['name'] != '' || $_FILES['config']['name'] != ''){ - //ACL Is he allowed to edit the Kernel/Init Path? - if(!Pbs_Acl::checkRight('boe')) - $this->_redirect('/user/bootos/index/page/'.$this->page.'/modifyresult/forbidden'); - } - - if( $_FILES['kernel']['size'] == 0 && $_FILES['kernel']['name'] != '' || - $_FILES['init']['size'] == 0 && $_FILES['init']['name'] != '' || - $_FILES['config']['size'] == 0 && $_FILES['config']['name'] != '' ){ - $this->_redirect('/user/bootos/index/page/'.$this->page.'/addresult/file'); - } - - $initpath = "../resources/bootos/".$bootosID."/initramfs/"; - $kernelpath = "../resources/bootos/".$bootosID."/kernel/"; - $configpath = "../resources/bootos/".$bootosID."/config/"; - - mkdir($initpath ,0777, true); - mkdir($kernelpath ,0777, true); - mkdir($configpath ,0777, true); - - - if($_FILES['kernel']['name'] != ''){ - $bootos->setSource($_SERVER['REMOTE_ADDR']); - move_uploaded_file($_FILES['kernel']['tmp_name'], $kernelpath."kernel"); - } - if($_FILES['init']['name'] != ''){ - $bootos->setSource($_SERVER['REMOTE_ADDR']); - move_uploaded_file($_FILES['init']['tmp_name'], $initpath."initramfs"); - } - if($_FILES['config']['name'] != ''){ - $bootos->setSource($_SERVER['REMOTE_ADDR']); - move_uploaded_file($_FILES['config']['tmp_name'], $configpath."default.tgz"); - } - - $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/page/'.$this->page.'/modifyresult/error'); - //TODO Delete Folder + Preboot - } - - $this->_redirect('/user/bootos/index/page/'.$this->page.'/modifyresult/ok'); - } - - } - - $this->view->bootosForm = $bootosForm; - - } - - public function deletebootosAction() - { - //ACL Is he allowed to delete Bootos? - if(!Pbs_Acl::checkRight('bod')) - $this->_redirect('/user/bootos/index/page/'.$this->page.'/deleteresult/forbidden'); - - try{ - $bootosID = $this->_request->getParam('bootosID'); - if (!is_numeric($bootosID)) - $this->_redirect('/user/bootos/index/page/'.$this->page.'/deleteresult/forbidden'); - - $bootos = new Application_Model_BootOs(); - $this->bootosMapper->find($bootosID, $bootos); - - if($this->membership->getGroupID() != $bootos->getGroupID()) - $this->_redirect('/user/bootos/index/page/'.$this->page.'/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/page/'.$this->page.'/deleteresult/error'); - } - $this->_redirect('/user/bootos/index/page/'.$this->page.'/deleteresult/ok'); - } +* This program is free software distributed under the GPL version 2. +* See http://gpl.openslx.org/ +* +* If you have any feedback please consult http://feedback.openslx.org/ and +* send your suggestions, praise, or complaints to feedback@openslx.org +* +* General information about OpenSLX can be found at http://openslx.org/ +*/ + +class user_BootosController extends Zend_Controller_Action { + + protected $bootosMapper; + protected $membershipMapper; + protected $membership; + protected $page; + + public function init() { + if (Zend_Auth::getInstance()->hasIdentity()) { + $userIDsNamespace = Zend_Session::namespaceGet('userIDs'); + if($userIDsNamespace['membershipID'] == '') { + $this->_redirect('/user/index'); + } + + $this->bootosMapper = new Application_Model_BootOsMapper(); + $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'); + } + $this->page = $this->_request->getParam('page'); + } + + public function indexAction() { + $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('updateresult'); + if($result != "") { + $pbsNotifier = new Pbs_Notifier(); + $this->view->notification = $pbsNotifier->notify('update', $result); + } + + $groupID = $this->membership->getGroupID(); + + //ACL Darf er BootOs sehen? + if(!Pbs_Acl::checkRight('boai') && !Pbs_Acl::checkRight('boui')) + { $this->_redirect('/user/index'); } + + $groupgroupsMapper = new Application_Model_GroupGroupsMapper(); + + $parents = array(); + $this->view->bootoslist = array(); + $parents = $groupgroupsMapper->getParentGroups($groupID); + + foreach($parents as $k => $parent) { + foreach($parent as $p) { + $bootos = $this->bootosMapper->findBy(array("groupID" => $p)); + foreach ($bootos as $b) + if($b->getPublic() - $k >= 0 ) + { $this->view->bootoslist[] = $b; } + elseif($k == 0 && $b->getPublic() == -1 && Pbs_Acl::checkRight('boc')) + $this->view->bootoslist[] = $b; + } + } + + $this->view->bootoslist = array_reverse($this->view->bootoslist); + $this->view->resources = array(); + + $groupMapper = new Application_Model_GroupMapper(); + + if(count($this->view->bootoslist) > 0) { + foreach ($this->view->bootoslist as $bootos) { + if($bootos->getDefaultkcl() == null) + { $bootos->setDefaultkcl("none (edit Bootos to set KCL)"); } + $this->view->resources[$bootos->getID()]['kernel'] = is_file("../resources/bootos/".$bootos->getID()."/kernel/kernel"); + $this->view->resources[$bootos->getID()]['initramfs'] = is_file("../resources/bootos/".$bootos->getID()."/initramfs/initramfs"); + $this->view->resources[$bootos->getID()]['config'] = is_file("../resources/bootos/".$bootos->getID()."/config/default.tgz"); + $bootos->setGroupID("[".$bootos->getGroupID()."] ".$groupMapper->find($bootos->getGroupID())->getTitle()); + $bootos->setCreated(date(Zend_Registry::get('dateformat'), $bootos->getCreated())); + $bootos->setExpires(date(Zend_Registry::get('dateformat'), $bootos->getExpires())); + } + } + + // Search + $search = $this->_request->getParam('search'); + $mySearch = new Pbs_Search(); + $mySearch->setSearchTerm($search); + $mySearch->setModule('bootos'); + if($search != '') { + $this->view->search = $mySearch->getSearchTerm(); + $this->view->bootoslist = $mySearch->search($this->view->bootoslist); + } + $this->view->searchform = $mySearch->searchForm(); + + // Pagination + $pagination = new Pbs_Pagination(); + $pagination->setPerPage(10); + $pagination->setElement($this->view->bootoslist); + $pagination->setRequestPage($this->_request->getParam('page')); + $pagination->setPageUrl('/user/bootos/index'.((isset($this->view->search)) ? '/search/'.$this->view->search : '')); + $this->view->bootoslist = $pagination->getElements(); + + $this->view->pagination = $pagination->pagination(); + $this->view->page = $pagination->getRequestPage(); + + } + public function searchAction() { + $this->_redirect('/user/bootos/index/search/'.($_GET['search'])); + } + + public function createbootosAction() { + + //ACL Darf er BootISOs erstellen? + if(!Pbs_Acl::checkRight('boc')) + { $this->_redirect('/user/bootos/index/page/'.$this->page.'/addresult/forbidden'); } + + $groupID = $this->membership->getGroupID(); + + $groupgroupsMapper = new Application_Model_GroupGroupsMapper(); + $childgroups = count($groupgroupsMapper->getChildGroups($groupID)); + + if (!isset($_POST["createbootos"])) { + $bootosForm = new user_Form_Bootos(array( + 'action' => 'createbootos', + 'groupdepth' => $childgroups, + 'page' => $this->page)); + } else { + + $bootosForm = new user_Form_Bootos(array( + 'action' => 'createbootos', + 'groupdepth' => $childgroups, + 'page' => $this->page), $_POST); + + if ($bootosForm->isValid($_POST)) { + + $bootos = new Application_Model_BootOs($_POST); + + $bootos->setGroupID($this->membership->getGroupID()); + $bootos->setCreated(time()); + $bootos->setSource($_SERVER['REMOTE_ADDR']); + + try { + + $bootosID = $this->bootosMapper->save($bootos); + $bootos->setID($bootosID); + + if( $_FILES['kernel']['size'] == 0 && $_FILES['kernel']['name'] != '' || + $_FILES['init']['size'] == 0 && $_FILES['init']['name'] != '' || + $_FILES['config']['size'] == 0 && $_FILES['config']['name'] != '' ) { + $this->_redirect('/user/preboot/index/page/'.$this->page.'/addresult/file'); + } + + $initpath = "../resources/bootos/".$bootosID."/initramfs/"; + $kernelpath = "../resources/bootos/".$bootosID."/kernel/"; + $configpath = "../resources/bootos/".$bootosID."/config/"; + + mkdir($initpath , 0777, true); + mkdir($kernelpath , 0777, true); + mkdir($configpath , 0777, true); + + if($_FILES['kernel']['name'] != '') { + move_uploaded_file($_FILES['kernel']['tmp_name'], $kernelpath."kernel"); + } + if($_FILES['init']['name'] != '') { + move_uploaded_file($_FILES['init']['tmp_name'], $initpath."initramfs"); + } + if($_FILES['config']['name'] != '') { + move_uploaded_file($_FILES['config']['tmp_name'], $configpath."default.tgz"); + $newconfig = new Pbs_NewConfig(); + $newconfig->createDefaultConfig($bootos); + } + + + } catch(Zend_Exception $e) { + echo "Caught exception: " . get_class($e) . "<br/>"; + echo "Message: " . $e->getMessage() . "<br/>"; + $this->_redirect('/user/bootos/index/page/'.$this->page.'/addresult/error'); + //TODO Delete File & delete bootiso from DB + + } + + $this->_redirect('/user/bootos/index/page/'.$this->page.'/addresult/ok'); + } + } + + $this->view->bootosForm = $bootosForm; + } + + public function editbootosAction() { + + //ACL Is he allowed to edit Bootos? + if(!Pbs_Acl::checkRight('boe') && !Pbs_Acl::checkRight('boem')) + { $this->_redirect('/user/bootos/index/page/'.$this->page.'/modifyresult/forbidden'); } + + $bootosID = $this->_request->getParam('bootosID'); + if (!is_numeric($bootosID)) + { $this->_redirect('/user/bootos/index/page/'.$this->page.'/modifyresult/forbidden'); } + + $groupID = $this->membership->getGroupID(); + + $groupgroupsMapper = new Application_Model_GroupGroupsMapper(); + $childgroups = count($groupgroupsMapper->getChildGroups($groupID)); + $bootos = new Application_Model_BootOs(); + $bootos = $this->bootosMapper->find($bootosID); + + if($this->membership->getGroupID() != $bootos->getGroupID()) + { $this->_redirect('/user/bootos/index/page/'.$this->page.'/modifyresult/forbidden'); } + + if (!isset($_POST["editbootos"])) { + + $bootosForm = new user_Form_Bootos(array( + 'action' => 'editbootos', + 'groupdepth' => $childgroups, + 'page' => $this->page)); + + $bootosForm->populate($bootos->toArray()); + + } else { + $bootosForm = new user_Form_Bootos(array( + 'action' => 'editbootos', + 'groupdepth' => $childgroups, + 'page' => $this->page), $_POST); + + if ($bootosForm->isValid($_POST)) { + + $bootosold = $bootos; + + $bootos = new Application_Model_BootOs($_POST); + $bootos->setGroupID($this->membership->getGroupID()); + $bootos->setSource($bootosold->getSource()); + $bootos->setCreated(time()); + $bootos->setID($bootosID); + + try { + + if( $bootos->getDistro() != $bootosold->getDistro() || + $bootos->getDistroversion() != $bootosold->getDistroversion() || + $bootos->getShare() != $bootosold->getShare() || + $bootos->getShortname() != $bootosold->getShortname() || + $bootos->getDefaultkcl() != $bootosold->getDefaultkcl() || + $bootos->getExpires() != $bootosold->getExpires() || + $bootos->getPublic() != $bootosold->getPublic() ) { + //ACL Is he allowed to edit this? + if(!Pbs_Acl::checkRight('boe')) + { $this->_redirect('/user/bootos/index/page/'.$this->page.'/modifyresult/forbidden'); } + } + + if($_FILES['kernel']['name'] != '' || $_FILES['init']['name'] != '' || $_FILES['config']['name'] != '') { + //ACL Is he allowed to edit the Kernel/Init Path? + if(!Pbs_Acl::checkRight('boe')) + { $this->_redirect('/user/bootos/index/page/'.$this->page.'/modifyresult/forbidden'); } + } + + if( $_FILES['kernel']['size'] == 0 && $_FILES['kernel']['name'] != '' || + $_FILES['init']['size'] == 0 && $_FILES['init']['name'] != '' || + $_FILES['config']['size'] == 0 && $_FILES['config']['name'] != '' ) { + $this->_redirect('/user/bootos/index/page/'.$this->page.'/addresult/file'); + } + + $initpath = "../resources/bootos/".$bootosID."/initramfs/"; + $kernelpath = "../resources/bootos/".$bootosID."/kernel/"; + $configpath = "../resources/bootos/".$bootosID."/config/"; + + mkdir($initpath , 0777, true); + mkdir($kernelpath , 0777, true); + mkdir($configpath , 0777, true); + + + if($_FILES['kernel']['name'] != '') { + $bootos->setSource($_SERVER['REMOTE_ADDR']); + move_uploaded_file($_FILES['kernel']['tmp_name'], $kernelpath."kernel"); + } + if($_FILES['init']['name'] != '') { + $bootos->setSource($_SERVER['REMOTE_ADDR']); + move_uploaded_file($_FILES['init']['tmp_name'], $initpath."initramfs"); + } + if($_FILES['config']['name'] != '') { + $bootos->setSource($_SERVER['REMOTE_ADDR']); + move_uploaded_file($_FILES['config']['tmp_name'], $configpath."default.tgz"); + } + + $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/page/'.$this->page.'/modifyresult/error'); + //TODO Delete Folder + Preboot + } + + $this->_redirect('/user/bootos/index/page/'.$this->page.'/modifyresult/ok'); + } + + } + + $this->view->bootosForm = $bootosForm; + + } + + public function deletebootosAction() { + //ACL Is he allowed to delete Bootos? + if(!Pbs_Acl::checkRight('bod')) + { $this->_redirect('/user/bootos/index/page/'.$this->page.'/deleteresult/forbidden'); } + + try { + $bootosID = $this->_request->getParam('bootosID'); + if (!is_numeric($bootosID)) + { $this->_redirect('/user/bootos/index/page/'.$this->page.'/deleteresult/forbidden'); } + + $bootos = new Application_Model_BootOs(); + $this->bootosMapper->find($bootosID, $bootos); + + if($this->membership->getGroupID() != $bootos->getGroupID()) + { $this->_redirect('/user/bootos/index/page/'.$this->page.'/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/page/'.$this->page.'/deleteresult/error'); + } + $this->_redirect('/user/bootos/index/page/'.$this->page.'/deleteresult/ok'); + } } |
