summaryrefslogblamecommitdiffstats
path: root/application/controllers/ResourceController.php
blob: fe564fcbda2b7d3e03453c174b1f66ac52e69d79 (plain) (tree)
1
2
3
4
5
6
7





                                                       
                                                                                             















                                                                

                                                                  
                                                                                   
                                             







                                                                        

                                                                                                


                                                                                                                               
                                                                                                           













                                                                          
                
                                                          
                                                                                   
                                             












                                                                         
                                                
                                                                                             


                                                                                                                               
                                                                                                        



                                                                  
                                                                       







                                                    
          
                                                          
                                                                                   
                                               









                                                                        
                                                                                             


                                                                                                                               
                                                                                                        












                                                                       
          
                                                              

                                                                             








                                                                        





                                                                           




                                                                                                                       
                                                        







                                            




                                                                                   



                                                                  
                       
 




                                                                                                        

                                              





                                                                                                                                                

                                                              





                                                                                                        









                                                                               











 
<?php

class ResourceController extends Zend_Controller_Action
{

	private $startval = 878923467;
	private $pass = array('lsfks_!$fks', 'un!fr€iburg', '0pen$lx_rulez', 'rand0mText');
	
    public function init()
    {
    	
    }

    public function indexAction()
    {
    	
    	
    }

    public function getinitramfsAction()
    {
        $this->_helper->layout->disableLayout();
        $this->_helper->viewRenderer->setNoRender();    	
		/*
		$bootosID = $this->_request->getParam('bootosID');
		$bootosID = $this->alphaID($bootosID, true, false, $this->pass[0]);
		$bootosID -= $this->startval;
		*/
		$alphasessionID = $this->_request->getParam('alpha');
		$session = new Application_Model_Session();
		$sm = new Application_Model_SessionMapper();
		$result = $sm->findBy('alphasessionID',$alphasessionID);
		# print_a($result);
		$thisSession = $result[0];
		$bootosID = $thisSession['bootosID'];

                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})', $HTTP_USER_AGENT) == 'IE') ? 'inline' : 'attachment';
        	        header('Content-Disposition:  ' . $content_disp . '; filename="initramfs.tar.gz"');
        	      	header('Pragma: no-cache');
        	      	header('Expires: 0');
        	                                		  
        	       	// create the gzipped tarfile.
        	       	chdir("../resources/bootos/$bootosID/initramfs/");
        	       	passthru( "tar cz ./");
                }
    }

    public function getconfigAction()
    {
    	
        $this->_helper->layout->disableLayout();
        $this->_helper->viewRenderer->setNoRender(); 
        /* 	
        $configID = $this->_request->getParam('configID');
		$configID = $this->alphaID($configID, true, false, $this->pass[1]);
		$configID -= $this->startval;
		*/
		$alphasessionID = $this->_request->getParam('alpha');
		$session = new Application_Model_Session();
		$sm = new Application_Model_SessionMapper();
		$result = $sm->findBy('alphasessionID',$alphasessionID);
		# print_a($result);
		$thisSession = $result[0];
		$bootmenuentryID = $thisSession['bootmenuentryID'];
		$bootmenuentry = new Application_Model_BootMenuEntries();
		$bmm = new Application_Model_BootMenuEntriesMapper();
		$bmm->find($bootmenuentryID,$bootmenuentry);
		# print_a($bootmenuentry);
		$configID = $bootmenuentry->getConfigID();
                                            	
                if(is_dir("../resources/config/$configID/config/") && is_numeric($configID)){
                                            		                         	    	
        	       	header('Content-Type: application/x-gzip');
        	        $content_disp = ( ereg('MSIE ([0-9].[0-9]{1,2})', $HTTP_USER_AGENT) == 'IE') ? 'inline' : 'attachment';
        	        header('Content-Disposition:  ' . $content_disp . '; filename="config.tar.gz"');
        	      	header('Pragma: no-cache');
        	      	header('Expires: 0');
        	                                		  
        	       	// create the gzipped tarfile.
        	       	chdir("../resources/config/$configID/config/");
        	       	passthru( "tar cz ./");
                }
    }

    public function getkernelAction()
    {
    	$this->_helper->layout->disableLayout();
        $this->_helper->viewRenderer->setNoRender();
        /*
        $bootosID = $this->_request->getParam('bootosID');
		$bootosID = $this->alphaID($bootosID, true, false, $this->pass[2]);
		$bootosID -= $this->startval;  
		*/
		$alphasessionID = $this->_request->getParam('alpha');
		$session = new Application_Model_Session();
		$sm = new Application_Model_SessionMapper();
		$result = $sm->findBy('alphasessionID',$alphasessionID);
		# print_a($result);
		$thisSession = $result[0];
		$bootosID = $thisSession['bootosID'];


                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})', $HTTP_USER_AGENT) == 'IE') ? 'inline' : 'attachment';
        	        header('Content-Disposition:  ' . $content_disp . '; filename="kernel.tar.gz"');
        	      	header('Pragma: no-cache');
        	      	header('Expires: 0');
        	                                		  
        	       	// create the gzipped tarfile.
        	       	chdir("../resources/bootos/$bootosID/kernel/");
        	       	passthru( "tar cz ./");
                }
    }

    public function getkclAction()
    {
    	$this->_helper->layout->disableLayout();
    	$this->_helper->viewRenderer->setNoRender();
    	/*
        $bmeID = $this->_request->getParam('bootmenuentryID');
		$bmeID = $this->alphaID($bmeID, true, false, $this->pass[3]);
		$bmeID -= $this->startval; 
        */
        $alphasessionID = $this->_request->getParam('alpha');
		$session = new Application_Model_Session();
		$sm = new Application_Model_SessionMapper();
		$result = $sm->findBy('alphasessionID',$alphasessionID);
		# print_a($result);
		$thisSession = $result[0];
		$bmeID = $thisSession['bootmenuentryID'];
		
        if(is_numeric($bmeID)){
        	$bmemapper = new Application_Model_BootMenuEntriesMapper();
			$bme = new Application_Model_BootMenuEntries();
			$bmemapper->find($bmeID,$bme);
			
			if($bme->getKcl() != null){
				header('Content-Type: text/html');
    	        $content_disp = ( ereg('MSIE ([0-9].[0-9]{1,2})', $HTTP_USER_AGENT) == 'IE') ? 'inline' : 'attachment';
    	        header('Content-Disposition:  ' . $content_disp . '; filename="kcl.txt"');
    	      	header('Pragma: no-cache');
    	      	header('Expires: 0');
				echo $bme->getKcl();   	
			}
	
        }

    }
    
    public function getbootmenuentryAction()
    {
    	// obsolete function (now only for debugging)
    	// after selecting the BootOS it will be saved in session
    	// so getkclAction, getkernelAction, getconfigAction and getinitramfsAction
    	// can be called with session-identifier
    	
    	$this->_helper->layout->disableLayout();
    	$this->_helper->viewRenderer->setNoRender();
    	
	    $bmeID = $this->_request->getParam('bootmenuentryID');
	    $bmeID = 4;

	    if(isset($_SESSION['alphasessionID'])){
		   	$sessionmapper = new Application_Model_SessionMapper();	   	
		   	$session = $sessionmapper->findBy('alphasessionID',$_SESSION['alphasessionID']);
		   	$session = $session[0];
		   	if($session['bootmenuentryID'] != null){		   		
		   		$return_val = 
		   			array(
		   					'info' => 'This function is for debugging purpose only',
		   					'kernel' => $this->generateURL('getkernel', 'alpha', $_SESSION['alphasessionID']), 
		   					'initramfs' => $this->generateURL('getinitramfs', 'alpha', $_SESSION['alphasessionID']),
		   					'kcl' => $this->generateURL('getkcl', 'alpha', $_SESSION['alphasessionID']),
		   					'config' => $_SESSION['alphasessionID']
		   			);		   		
		   		echo json_encode($return_val);
		   	}
		   	else{
		   		echo json_encode(
		   			array(	'info' => 'This function is for debugging purpose only',
		   					'error'=>'your session is out of date')
		   		);
		   	}
	    }
	    	
    }
    
    function generateURL($action, $varname, $varvalue){
   		$path = '/resource/'. $action .'/' . $varname .'/' . $varvalue;
   		$path = "http://" . $_SERVER['SERVER_NAME'] . $path;
    	return $path;
    }

}