diff options
6 files changed, 478 insertions, 4 deletions
diff --git a/application/models/BootIsoMapper.php b/application/models/BootIsoMapper.php index 397d393..52849b2 100644 --- a/application/models/BootIsoMapper.php +++ b/application/models/BootIsoMapper.php @@ -14,7 +14,16 @@ class Application_Model_BootIsoMapper ->where($criteria . ' = ?', $value); $stmt = $select->query(); $result = $stmt->fetchAll(); - return $result; + + $entries = array(); + foreach ($result as $row) { + $entry = new Application_Model_BootIso($row); + $entry->setID($row['bootisoID']); + $entries[] = $entry; + } + + return $entries; + }catch (Zend_Exception $e) { echo "Error message 2: " . $e->getMessage() . "\n"; } 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'); + } + } + + + + + + diff --git a/application/modules/user/forms/Bootiso.php b/application/modules/user/forms/Bootiso.php new file mode 100644 index 0000000..a7f9311 --- /dev/null +++ b/application/modules/user/forms/Bootiso.php @@ -0,0 +1,114 @@ +<?php + +class user_Form_Bootiso extends Zend_Form +{ + + private $prebootlist; + private $groupdepth; + private $action; + private $rights; + + public function setRights($rights){ + $this->rights = $rights; + } + public function setAction($action){ + $this->action = $action; + } + public function setPrebootlist($prebootlist){ + $this->prebootlist = $prebootlist; + } + public function setGroupdepth($groupdepth){ + $this->groupdepth = $groupdepth; + } + + + public function init() + { + $this->setName($this->action); + $this->setMethod('post'); + + if ($this->rights == 'meta') + $meta = true; + + $this->addElement('text', 'title', array( + 'filters' => array('StringTrim'), + 'validators' => array( + array('StringLength', false, array(0, 50)), + ), + 'required' => true, + 'label' => 'Title:', + )); + + $prebootfield = $this->createElement('select','prebootID'); + $prebootfield->setLabel('Preboot:'); + $prebootfield->setAttrib('readOnly', $meta); + + if(count($this->prebootlist)>0){ + foreach($this->prebootlist as $preboot => $p){ + $prebootfield->addMultiOption($p->getID(), $p->getTitle()); + } + } + $prebootfield->setRegisterInArrayValidator(false); + $this->addElement($prebootfield); + + $serial = time(); + for($i=2; $i<14; $i+=3) + $serial = substr($serial,0,$i) .'-'. substr($serial,$i,strlen($serial)); + + $this->addElement('text', 'serialnumber', array( + 'filters' => array('StringTrim'), + 'validators' => array( + array('StringLength', false, array(0, 50)), + ), + 'required' => true, + 'size' => 50, + 'label' => 'Serialnumber:', + 'readOnly' => $meta, + 'value' => $serial + )); + + $date = new DateTime(); + $date->add(new DateInterval('P1Y')); + $this->addElement('text', 'expires', array( + 'filters' => array('StringTrim'), + 'validators' => array( + array('StringLength', false, array(0, 50)), + ), + 'required' => false, + 'label' => 'Expires:', + 'readOnly' => $meta, + 'value' => $date->format('Y-m-d'), + )); + + $publicfield = $this->createElement('select','public'); + $publicfield->setLabel('Public:'); + $publicfield->addMultiOption(0, '0. Eigene Gruppe'); + $publicfield->setAttrib('readOnly', $meta); + + for($i=1; $i<$this->groupdepth; $i++){ + $publicfield->addMultiOption($i, "$i. Untergruppe"); + } + + $publicfield->setRegisterInArrayValidator(false); + $this->addElement($publicfield); + + if($this->action == "createbootiso") + $label = "Create Bootiso"; + else + $label = "Edit Bootiso"; + + $this->addElement('submit', $this->action, array( + 'required' => false, + 'ignore' => true, + 'label' => $label, + )); + + $this->addElement('button', 'Cancel', array( + 'onclick' => 'self.location="/user/bootiso"' + )); + + } + + +} + diff --git a/application/modules/user/views/scripts/bootiso/createbootiso.phtml b/application/modules/user/views/scripts/bootiso/createbootiso.phtml new file mode 100644 index 0000000..a577073 --- /dev/null +++ b/application/modules/user/views/scripts/bootiso/createbootiso.phtml @@ -0,0 +1,4 @@ +<?php +$this->bootisoForm; +echo $this->bootisoForm; +?> diff --git a/application/modules/user/views/scripts/bootiso/editbootiso.phtml b/application/modules/user/views/scripts/bootiso/editbootiso.phtml new file mode 100644 index 0000000..a577073 --- /dev/null +++ b/application/modules/user/views/scripts/bootiso/editbootiso.phtml @@ -0,0 +1,4 @@ +<?php +$this->bootisoForm; +echo $this->bootisoForm; +?> diff --git a/application/modules/user/views/scripts/bootiso/index.phtml b/application/modules/user/views/scripts/bootiso/index.phtml index 5d756d0..4e1d15d 100644 --- a/application/modules/user/views/scripts/bootiso/index.phtml +++ b/application/modules/user/views/scripts/bootiso/index.phtml @@ -1 +1,67 @@ -<br /><br /><center>View script for controller <b>Bootiso</b> and script/action name <b>index</b></center>
\ No newline at end of file +<h1>BootMedien</h1> +<?php if($this->notification != ''){echo $this->notification;} ?> +<?php echo $this->formButton('createbootiso', 'Create BootISO', array( + 'onclick' => 'self.location="/user/bootiso/createbootiso"', + 'class' => 'addbutton'))?> +<table> + <tr> + <th>ID</th> + <th>Title</th> + <th>GroupID</th> + <th>MembershipID</th> + <th>PrebootID</th> + <th>Serialnumber</th> + <th>Created</th> + <th>Expires</th> + <th>Public</th> + <th colspan=3>Actions</th> + </tr> + <?php if(count($this->bootisolist)==0) + echo "</table> There are no BootISO's entries to display." ?> + <?php foreach ($this->bootisolist as $bootiso): ?> + <tr class=entry> + <td><?php echo $this->escape($bootiso->getID()); ?></td> + <td><?php echo $this->escape($bootiso->getTitle()); ?></td> + <td><?php echo $this->escape($bootiso->getGroupID()); ?></td> + <td><?php echo $this->escape($bootiso->getMembershipID()); ?></td> + <td><?php echo "[" . $this->escape($bootiso->getPrebootID()) . "] " . $this->prebootlist[$bootiso->getID()]; ?></td> + <td><?php echo $this->escape($bootiso->getSerialnumber()); ?></td> + <td><?php echo $this->escape(date('Y-m-d H:i:s', $bootiso->getCreated())); ?></td> + <td><?php echo $this->escape($bootiso->getExpires()); ?></td> + <td><?php echo $this->escape($bootiso->getPublic()); ?></td> + <td class='action'><a href="<?php echo $this->url( + array( + 'module' => 'user', + 'controller' => 'bootiso', + 'action' => 'downloadbootiso', + 'prebootID' => $bootiso->getprebootID(), + 'bootisoID' => $bootiso->getID() + ), + 'default', + true, false) ?>"><img src='/media/img/download.png' alt='Download BootMedium' /></a></td> + <td class='action'><a href="<?php echo $this->url( + array( + 'module' => 'user', + 'controller' => 'bootiso', + 'action' => 'editbootiso', + 'bootisoID' => $bootiso->getID() + ), + 'default', + true, false) ?>"><img src='/media/img/edit.png' alt='Edit BootISO' /></a></td> + <td class='action'><a href="<?php echo $this->url( + array( + 'module' => 'user', + 'controller' => 'bootiso', + 'action' => 'deletebootiso', + 'bootisoID' => $bootiso->getID() + ), + 'default', + true) ?>"><img src='/media/img/delete.png' alt='Delete BootISO'/></a></td> + </tr> + <?php endforeach; ?> +</table> + + + + + |