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'); } } 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); } $groupMapper = new Application_Model_GroupMapper(); $personMapper = new Application_Model_PersonMapper(); $groupID = $this->membership->getGroupID(); //TODO ACL Darf er BootOsMenu sehen? if(false) $this->_redirect('/user/index'); $configMapper = new Application_Model_ConfigMapper(); $this->view->bootoslist = $this->bootosMapper->findBy("groupID", $groupID); $this->view->update = array(); // Pagination $perpage = 5; $req_page = $this->_request->getParam('page'); $all = count($this->view->bootoslist); $numpages = ceil($all/$perpage); if($req_page < 0 || !is_numeric($req_page) ) $req_page = 0; if($req_page >= $numpages) $req_page = $numpages-1; $startitem = $req_page * $perpage; $pagination = new Pbs_Pagination(); $this->view->pagination = $pagination->pagination('/user/bootos/index',$req_page,$numpages); $this->view->page = $req_page; $this->view->bootoslist = array_slice($this->view->bootoslist,$startitem,$perpage); $update = $this->_request->getParam('checkupdate'); if(count($this->view->bootoslist)>0){ foreach ($this->view->bootoslist as $bootos){ $this->view->update[$bootos->getID()] = $update && $this->checkupdateAction($bootos); $bootos->setGroupID("[".$bootos->getGroupID()."] ".$groupMapper->find($bootos->getGroupID())->getTitle()); $bootos->setMembershipID("[".$bootos->getMembershipID()."] ".$personMapper->find($this->membershipMapper->find($bootos->getMembershipID())->getPersonID())->getFirstname()); $bootos->setConfigID("[".$bootos->getConfigID()."] ".$configMapper->find($bootos->getConfigID())->getTitle()); } } } public function createbootosAction() { $page = $this->_request->getParam('page'); //TODO ACL Darf er BootISOs erstellen? if(false) $this->_redirect('/user/bootos/index/page/'.$page.'/addresult/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["createbootos"])){ $bootosForm = new user_Form_Bootos(array('action' => 'createbootos', 'groupdepth' => $childgroups, 'configlist'=>$configlist, 'rights' => 'all')); } else { $bootosForm = new user_Form_Bootos(array('action' => 'createbootos', 'groupdepth' => $childgroups, 'configlist'=>$configlist, 'rights' => 'all'),$_POST); if ($bootosForm->isValid($_POST)) { $bootos = new Application_Model_BootOs($_POST); $bootos->setMembershipID($this->membership->getID()); $bootos->setGroupID($this->membership->getGroupID()); $bootos->setCreated(time()); try { $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 = $this->bootosMapper->save($bootos); $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"); }catch(Zend_Exception $e) { echo "Caught exception: " . get_class($e) . "
"; echo "Message: " . $e->getMessage() . "
"; $this->_redirect('/user/bootos/index/page/'.$page.'/addresult/error'); //TODO Delete File & delete bootiso from DB } $this->_redirect('/user/bootos/index/page/'.$page.'/addresult/ok'); } } $this->view->bootosForm = $bootosForm; } public function checkupdateAction($bootos) { $page = $this->_request->getParam('page'); //TODO ACL Is he allowed to update Preboots? if(false) $this->_redirect('/user/preboot/index/page/'.$page.'/updateresult/forbidden'); $bootosID = $bootos->getID(); if(is_file("../resources/bootos/$bootosID/kernel/kernel") && is_file("../resources/bootos/$bootosID/initramfs/initramfs")){ $kernelolddate = filemtime("../resources/bootos/".$bootosID."/kernel/kernel"); $initolddate = filemtime("../resources/bootos/".$bootosID."/initramfs/initramfs"); } else { $pbsNotifier = new Pbs_Notifier(); $this->view->notification = $pbsNotifier->notify('There are updates available','ok'); return true; } 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)))); $initdate = strtotime(trim(str_replace('Last-Modified:', '', array_pop($initdate)))); //print_a($bootos->getPath_kernel(),$kerneldate,$kernelolddate,$initname,$initdate,$initolddate); if($kerneldate > $kernelolddate || $initdate > $initolddate){ $this->view->notification = $pbsNotifier->notify('There are updates available','ok'); return true; }else{ return false; } } public function updatebootosAction() { $page = $this->_request->getParam('page'); //TODO ACL Is he allowed to update Preboots? if(false) $this->_redirect('/user/bootiso/index/page/'.$page.'/updateresult/forbidden'); $bootosID = $this->_request->getParam('bootosID'); if (!is_numeric($bootosID)) $this->_redirect('/user/bootos/index/page/'.$page.'/updateresult/forbidden'); $bootos = $this->bootosMapper->find($bootosID); if($this->membership->getGroupID() != $bootos->getGroupID()) $this->_redirect('/user/bootos/index/page/'.$page.'/updateresult/forbidden'); $initpath = "../resources/bootos/".$bootosID."/initramfs/"; $kernelpath = "../resources/bootos/".$bootosID."/kernel/"; $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/page/'.$page.'/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/index/page/'.$page.'/updateresult/ok'); } public function editbootosAction() { $page = $this->_request->getParam('page'); //TODO ACL Is he allowed to edit Preboots? if(false) $this->_redirect('/user/bootos/index/page/'.$page.'/modifyresult/forbidden'); $bootosID = $this->_request->getParam('bootosID'); if (!is_numeric($bootosID)) $this->_redirect('/user/bootos/index/page/'.$page.'/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"])){ $bootos = new Application_Model_BootOs(); $bootos = $this->bootosMapper->find($bootosID); if($this->membership->getGroupID() != $bootos->getGroupID()) $this->_redirect('/user/bootos/index/page/'.$page.'/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('action' => 'editbootos', 'groupdepth' => $childgroups, 'configlist'=>$configlist, 'rights' => 'meta'),$_POST); if ($bootosForm->isValid($_POST)) { $bootosold = new Application_Model_BootOs(); $this->bootosMapper->find($bootosID, $bootosold); $bootos = new Application_Model_BootOs($_POST); $bootos->setMembershipID($this->membership->getID()); $bootos->setGroupID($this->membership->getGroupID()); $bootos->setCreated(time()); if($bootos->getConfigID() == '') $bootos->setConfigID(NULL); $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/page/'.$page.'/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/page/'.$page.'/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 { $this->bootosMapper->save($bootos); }catch(Zend_Exception $e) { echo "Caught exception: " . get_class($e) . "
"; echo "Message: " . $e->getMessage() . "
"; $this->_redirect('/user/bootos/index/page/'.$page.'/modifyresult/error'); //TODO Delete Folder + Preboot } $this->_redirect('/user/bootos/index/page/'.$page.'/modifyresult/ok'); } } $this->view->bootosForm = $bootosForm; } public function deletebootosAction() { $page = $this->_request->getParam('page'); //TODO ACL Is he allowed to delete Bootos? if(false) $this->_redirect('/user/bootos/index/page/'.$page.'/deleteresult/forbidden'); try{ $bootosID = $this->_request->getParam('bootosID'); if (!is_numeric($bootosID)) $this->_redirect('/user/bootos/index/page/'.$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/'.$page.'/deleteresult/forbidden'); $this->bootosMapper->delete($bootos); exec("rm -r ../resources/bootos/".$bootosID); }catch(Zend_Exception $e){ echo "Caught exception: " . get_class($e) . "
"; echo "Message: " . $e->getMessage() . "
"; $this->_redirect('/user/bootos/index/page/'.$page.'/deleteresult/error'); } $this->_redirect('/user/bootos/index/page/'.$page.'/deleteresult/ok'); } }