From c31d8e9959efade437fb0a661f6f44329cc74664 Mon Sep 17 00:00:00 2001 From: Simon Date: Tue, 19 Apr 2011 15:43:00 +0200 Subject: Code autoformatiert --- application/controllers/ResourceController.php | 122 ++++++++++++------------- 1 file changed, 59 insertions(+), 63 deletions(-) (limited to 'application/controllers/ResourceController.php') diff --git a/application/controllers/ResourceController.php b/application/controllers/ResourceController.php index bf9de06..91cd290 100644 --- a/application/controllers/ResourceController.php +++ b/application/controllers/ResourceController.php @@ -21,27 +21,27 @@ class ResourceController extends Zend_Controller_Action { $this->_helper->layout->disableLayout(); $this->_helper->viewRenderer->setNoRender(); - + $session = new Application_Model_Session(); $sm = new Application_Model_SessionMapper(); - + //TODO Error Messages if something failed $alpha = $this->_request->getParam('alpha'); $apikey = $this->_request->getParam('apikey'); - + if($apikey != ""){ $membershipMapper = new Application_Model_MembershipMapper(); $this->membership = new Application_Model_Membership(); $rightrolesMapper = new Application_Model_RightRolesMapper(); - $rightroles = new Application_Model_RightRoles(); + $rightroles = new Application_Model_RightRoles(); @list($this->membership) = $membershipMapper->findBy(array('apikey' => $apikey)); if($this->membership == null){ - header('HTTP/1.0 401 Member not found'); + header('HTTP/1.0 401 Member not found'); die(); } @list($rightroles) = $rightrolesMapper->findBy(array('rightID' => '55', 'roleID' => $this->membership->getRoleID())); if($rightroles == null){ - header('HTTP/1.0 403 No Right to Create Bootos'); + header('HTTP/1.0 403 No Right to Create Bootos'); die(); } } @@ -49,23 +49,24 @@ class ResourceController extends Zend_Controller_Action $bootmenuentryID = $this->_request->getParam('bootmenuentryID'); $this->page = $this->_request->getParam('page'); - if(!is_numeric($bootmenuentryID)) + if(!is_numeric($bootmenuentryID)){ $this->_redirect('/user/bootmenu/index/page/'.$this->page.'/json/error'); - + } + $bootmenuentry = new Application_Model_BootMenuEntries(); $bootmenuentryMapper = new Application_Model_BootMenuEntriesMapper(); $bootosMapper = new Application_Model_BootOsMapper(); $bootmenuentryMapper->find($bootmenuentryID, $bootmenuentry); - + $session->setBootosID($bootmenuentry->getBootosID()) ->setBootmenuentryID($bootmenuentry->getID()) ->setTime(time()) ->setMembershipID($bootosMapper->find($bootmenuentry->getBootmenuID())->getMembershipID()) ->setIp($_SERVER['REMOTE_ADDR']) ->setAlphasessionID('0'); - - $this->thisSession = $session; - + + $this->thisSession = $session; + } elseif($alpha != ""){ $alphasessionID = $alpha; @@ -79,15 +80,15 @@ class ResourceController extends Zend_Controller_Action public function indexAction() { - - + + } - + public function addbootosAction() { $apikey = $this->_request->getParam('apikey'); if($apikey == ""){ - header('HTTP/1.0 400 No API-Key'); + header('HTTP/1.0 400 No API-Key'); die(); } @@ -96,10 +97,10 @@ class ResourceController extends Zend_Controller_Action header('HTTP/1.0 400 Title must be set'); die(); } - + $bootos = new Application_Model_BootOs(); $bootosMapper = new Application_Model_BootOsMapper(); - + $bootos->setOptions($params); $bootos->setGroupID($this->membership->getGroupID()); $bootos->setSource($_SERVER['REMOTE_ADDR']); @@ -109,16 +110,16 @@ class ResourceController extends Zend_Controller_Action $bootos->setCreated(time()); $bootos->setPublic('-1'); $bootosID = $bootosMapper->save($bootos); - + print_a($bootos); - $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); - + $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(isset($_FILES['config'])){ move_uploaded_file($_FILES['config']['tmp_name'], $configpath."config.tgz"); } @@ -128,9 +129,9 @@ class ResourceController extends Zend_Controller_Action if(isset($_FILES['init'])){ move_uploaded_file($_FILES['init']['tmp_name'], $initpath."initramfs"); } - + header('HTTP/1.0 201 Bootos created'); - + } public function getinitramfsAction() @@ -139,19 +140,18 @@ class ResourceController extends Zend_Controller_Action $bootosID = $this->thisSession->getBootosID(); if(is_dir("../resources/bootos/$bootosID/initramfs/") && is_numeric($bootosID)){ - 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="initramfs"'); header('Pragma: no-cache'); header('Expires: 0'); - + // create file. chdir("../resources/bootos/$bootosID/initramfs/"); $initname = array_pop(scandir("./")); - + header("Content-Length: ".filesize(getcwd()."/".$initname)); - + passthru( "cat ".$initname); }else{ header('HTTP/1.0 404 Not Found'); @@ -160,29 +160,28 @@ class ResourceController extends Zend_Controller_Action public function getconfigAction() { - + $bootmenuentryID = $this->thisSession->getBootmenuentryID(); $bootmenuentry = new Application_Model_BootMenuEntries(); $bmm = new Application_Model_BootMenuEntriesMapper(); $bmm->find($bootmenuentryID,$bootmenuentry); - + $configID = $bootmenuentry->getConfigID(); if(is_dir("../resources/config/$configID/")){ - + 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="default.tgz"'); header('Pragma: no-cache'); header('Expires: 0'); - + if($this->thisSession->getMembershipID() != null){ $path_userconf = "../resources/config/$configID/".$this->thisSession->getMembershipID()."/"; - - if(!is_dir($path_userconf)){ + if(!is_dir($path_userconf)){ $person = new Application_Model_Person(); $personMapper = new Application_Model_PersonMapper(); $membershipMapper = new Application_Model_MembershipMapper(); @@ -190,7 +189,7 @@ class ResourceController extends Zend_Controller_Action $person = $personMapper->find($personID); $loginname = strtolower($person->getName()); $loginname = preg_replace("!\s!","",$loginname); - + mkdir($path_userconf ,0777, true); exec("tar -C $path_userconf -xvf ../resources/config/$configID/default.tgz"); exec("cp ../resources/config/loginfiles/* $path_userconf/rootfs/etc/"); @@ -205,70 +204,68 @@ class ResourceController extends Zend_Controller_Action passthru( "tar cz *"); }else { chdir("../resources/config/$configID/"); - passthru( "cat default.tgz"); - } + passthru( "cat default.tgz"); + } }else{ header('HTTP/1.0 404 Not Found'); - } + } } public function getkernelAction() { - + $bootosID = $this->thisSession->getBootosID(); if(is_dir("../resources/bootos/$bootosID/kernel/") && is_numeric($bootosID)){ - 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="kernel"'); header('Pragma: no-cache'); header('Expires: 0'); - + // create the gzipped tarfile. chdir("../resources/bootos/$bootosID/kernel/"); $kernelname = array_pop(scandir("./")); - + header("Content-Length: ".filesize(getcwd()."/".$kernelname)); - + passthru( "cat ". $kernelname); }else{ header('HTTP/1.0 404 Not Found'); } - + } public function getkclAction() { - + $bmeID = $this->thisSession->getBootmenuentryID(); if(is_numeric($bmeID)){ - $bmemapper = new Application_Model_BootMenuEntriesMapper(); $bme = new Application_Model_BootMenuEntries(); $bootosmapper = new Application_Model_BootOsMapper(); $bmemapper->find($bmeID,$bme); - + header('Content-Type: text/html'); $content_disp = ( ereg('MSIE ([0-9].[0-9]{1,2})', $_SERVER['HTTP_USER_AGENT']) == 'IE') ? 'inline' : 'attachment'; header('Content-Disposition: ' . $content_disp . '; filename="kcl.txt"'); header('Pragma: no-cache'); header('Expires: 0'); - + $kcl = $bootosmapper->find($bme->getBootosID())->getDefaultkcl(); - - if($bme->getKcl() && $kcl != null){ + + if($bme->getKcl() && $kcl != null){ $result = $kcl . " alpha=" . $this->_request->getParam('alpha') . " file=http://".$_SERVER['HTTP_HOST']."/resource/getconfig/alpha/".$this->_request->getParam('alpha')."/file/default.tgz ".$bme->getKclappend(); }else{ $result = "alpha=" . $this->_request->getParam('alpha') . " file=http://".$_SERVER['HTTP_HOST']."/resource/getconfig/alpha/".$this->_request->getParam('alpha')."/file/default.tgz ".$bme->getKclappend(); } - + header("Content-Length: ".(strlen($result))); - + echo $result; - + } @@ -280,7 +277,7 @@ class ResourceController extends Zend_Controller_Action // after selecting the BootOS it will be saved in session // so getkclAction, getkernelAction, getconfigAction and getinitramfsAction // can be called with session-identifier - + $return_val = array( 'info' => 'This function is for debugging purpose only', @@ -289,20 +286,19 @@ class ResourceController extends Zend_Controller_Action 'kcl' => $this->generateURL('getkcl', 'alpha', $this->thisSession->getAlphasessionID(), "kcl.txt"), 'config' => $this->generateURL('getconfig', 'alpha', $this->thisSession->getAlphasessionID(), 'default.tgz') ); - + $result = $return_val; $result2 = "
| info: | ".$result['info']." |
| kernel: | ".$result['kernel']." |
| initramfs: | ".$result['initramfs']." |
| kcl: | ".$result['kcl']." |
| config: | ".$result['config']." |