summaryrefslogblamecommitdiffstats
path: root/application/controllers/ResourceController.php
blob: e65d1caf53c859eba668778fb6b3bb5367650b33 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
     









                                                                           




                                                       
                      
                            
                                  
                           


                              
                                                               
 

                                                            
 

                                                            
 
                                                         
                                                            
                                                              
                                                                                   
 







                                                                          
 

                                                                          

                                      



                                                                                             





                                                                                                                
 
                         
                 
                                  
                                                                                        

                                                                        
 
                                                          
                                                                                                         
                         
 

                                                                                             
                                                                                 
                                                                                     
 


                                                                            
                                              

                                                        


                                                      
                 






                                                                                               
                        



                                     

                        
         
 
                                         

                                         
 
                                                                                                                                          




                                                                         

                                                              
                                                          



                                                       
                                                  
 

                                                                                                                                                    

                              
 


                                                                                                                                                                                                                            
                 
 
                                                                     
                                                           
 
                                                                                                                                                                                                                                               


                                                                     
                 
                                                         
 
                                             

                                              


                                                         
                                          
 







                                                                           
                                                    
                                                                                                     
 
                 
                                                    

                                                                                                
                                                  
                                                                                               

                                                                 




                                                      





































































                                                                                                                                                                                                                                               
 

                                         
                                                                                                                                          
                                        
                                                                         







                                                              
 
                                                       
                                                           
                                                                     
                                                         


                                              

                                                         
 

                                                                      








                                                                                                



                                                                             
                                                          




                                           
                                                











                                                                                                                                          
                                                       
                                                                                   

                                                                       
                                                                              
                                                              
                                                        
 

                                                                      






                                                                                                       
                                 
 
                                                 
                                                                                  
                                                          

                                           
                          
         
 


                                                                                                                                          
                                                                         







                                                              
 




                                                                     


                                                         
                                                                                                                                                  






                                                                                      





                                                                













                                                                                                                                          





                                                                     
                                                                                                                                                  
                                                             
                                                                      
                                
                                                                                      





















                                                                                                                                          












                                                                                     

                                                                                                                                                          


                                           



                                                                   





                                                                     






                                                                                                                                          
 













                                                                                       
                                                

                                                               
                                              

                                                                           



                                                                     

                                                                    
                                                                                    



                                                                      

















                                                                                                           



                                                                               
                                                          




                                           








































                                                                                                                                                            





                                                                                                                                          
 










                                                                         
                                                             

                                                              
                                                                                                                                                      












                                                                                        
 
 

                                          
 
                                                                                                                                          



                                                                           
 




                                                              
 

                                                       
 

                                                                               

                              
 


                                                                                        
                 


                                                                       
 
                                                                                                                   



                                                                      
 
                                                           
 


                                               
                                             
 




                                                                         
                                                      



                                                                                                       

 
         
 

                                           
 
                                                                                                                                          



                                                                        
 




                                                              
 

                                                       
 
                                           


                                                                 
 


                                                                                        

                 



                                                                       
                                                                                                                   
 


                                                                 

                 
                                                    



                                               
                                                 
                                             
 


                                                                         
                                                     
                                                     

                                                                                                       
 
                                               

                                                      
 







                                                                                                
 




                                                                                                                                          
 


                                                                          
 
                                                                                    
 
                                                    

                                                         



                                         
         
                                                                            


                                                                         
 
                                                          
                                                              
 
                                                                    
 




                                                                                                                                          
 



                                                                               

                                                                                                        
 


                                                                        
                                                                                                                      
                                                                                                 
 

                                                   
 
                                                                                  




                                                                                                                                  



                                                                                      
                                                               
                                                
                                                   
                                                                     
                                                                    
                                 
 
                                                              
                                                                                      


                                                              
                                                                              
                                                                                   
                                              
                                                                                           
                                         
 
                                                                                 
                                                                                      
                                              
                                                                                             
                                         
 
                                                                        
                                                                                             
                                                                             
                                                                                                                            
                                              
                                                                                                        
                                         
 
                                                                                                        
 
                                                                                
                                                                                
                                                 
                                                     
                                                                                 
                                                                                                                                                                                           
                                                                                      
                                                                                                                                                                     



                                                                                       
                                                 

 

                                                                                                                        
 
                                                                   
 
                                         
                                 
                                           
 
                                                              
                                                 
                                                      
                                                        
 
                         

                                                         
                 



                                         
 


                                                                                             
 




                                                                                                                                          
 


                                                                       
 
                                                                                      
 
                                                       

                                                         
                 
 



                                      
 
 


                                                                  
 

                                                                                   
                                                                             
                                                      
 




                                                                                                                                          
 
                                                                                         

                                                           
                                                                                                                                                                                                                      
                              
                                                                                                                                                                                                              
                         
                                                
                                                                     
 
                                     
 










                                                                                           
 





                                                                                                                                         
                                                                                                                                    
                  
 





                                                                                                                                         

                                                                                                                                
                              

         


















                                                                                                                                           
                                                                      

                                                           


                                                                                  




                                                                                                                                                            

                         

                                                                                       
                                          












                                                                                                                                
                 




                                                                   


                                                                      



                                                                               
                                                                                              




                                                                                                             
                                                                                              





                                                                                                                





                                                                                                    



                                                                                                                                   


                                                                                                                                      




                                                                              





                                                  
                                                                             
                                                          




                                           
                                         




                                                                                                                                           





                                                              
 
                                                       
                                                                 


                                                                               
                                                           

                                              

                                                                       
                                                                




                                                                                                                                                            



                                                                                  















                                                                                                        
                                                                                                        








                                                                                                                                                   

                                                                                                   




                                                                                                                              
                         






                                                                           
                                                          




                                           






                                                              
                                                           
                                                                          






                                                                                                                                                         




























                                                                                                
                                                          



















                                                                                                                                           
                                                          
                                                                        






                                                                                                                                                           

















                                                                                            
                                                          




                                           






                                                              
                                                                             
















                                                                                        
                                                                                 
                                                          




                                           































































                                                                                                                                           
                                                          




                                           
                                         
                                                       
 
                                            





















                                                                                                                                                           
 
                                            
 
                                        
                                                                 















                                                                                           
                                                          




                                           






                                                              
                                                                            

                                                                                    
                                        


                                                                    
                                    










                                                                             
                                                                
                        
                                                                 





                                                 
                                                                                 
                                                          


                                           

         


                                                                      
                                      










                                                                                                                                         

                                                                               
                        



                                                                                                                        
 

                                                                         
                                                                                            
                                                                                
                                

                                                                                            
 

















                                                                                                                            


                         
                                       


                                                 
                                                                            
                                                          




                                           
                                                                              
                                                                                                                                                                    



                                                                    
 
<?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 ResourceController extends Zend_Controller_Action
{

	private $thisSession;
	private $page;
	private $membership;
	private $rightrolesMapper;
	private $db = null;

	public function init()
	{
		$this->db = Zend_Db_Table::getDefaultAdapter();

		$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');
		$this->rightrolesMapper = new Application_Model_RightRolesMapper();

		if($this->getRequest()->getActionName() == 'login') {
			$email = $this->_request->getParam('email');
			$password = $this->_request->getParam('password');

			if(!isset($email)) {
				header('HTTP/1.0 401 No email is set');
				die();
			}

			if(!isset($password)) {
				header('HTTP/1.0 401 No password is set');
				die();
			}
		} else {
			if($apikey != ""){
				$membershipMapper = new Application_Model_MembershipMapper();
				$this->membership = new Application_Model_Membership();

				list($this->membership) = $membershipMapper->findBy(array('apikey' => $apikey));
				if($this->membership == null){
					header('HTTP/1.0 401 Member not found');
					die();
				}

			}
		}
		if($alpha == "0"){
			$bootmenuentryID = $this->_request->getParam('bootmenuentryID');

			$this->page = $this->_request->getParam('page');

			if(!is_numeric($bootmenuentryID)){
				$this->_redirect('/user/bootmenu/index/page/'.$this->page.'/json/error');
			}

			$bootmenuentry = new Application_Model_BootMenuEntries();
			$bootmenuentryMapper = new Application_Model_BootMenuEntriesMapper();
			$bootmenuMapper = new Application_Model_BootMenuMapper();
			$bootmenuentryMapper->find($bootmenuentryID, $bootmenuentry);

			$session->setBootosID($bootmenuentry->getBootosID())
			->setBootmenuentryID($bootmenuentry->getID())
			->setTime(time())
			->setMembershipID('1')
			->setIp($_SERVER['REMOTE_ADDR'])
			->setAlphasessionID('0');

			$this->thisSession = $session;

		}
		elseif($alpha != ""){
			$alphasessionID = $alpha;
			$result = $sm->findBy(array('alphasessionID' => $alphasessionID),true);
			# print_a($result);
			$this->thisSession = $session->setOptions($result[0]);
			$this->thisSession->setID($result[0]['sessionID']);
		}
			
	}

	public function indexAction()
	{

			
	}

	//TODO Try/Catch + Metadata check
	public function addbootosAction()
	{

		list($rightroles) = $this->rightrolesMapper->findBy(array('rightID' => '55', 'roleID' => $this->membership->getRoleID()));
		if($rightroles == null){
			header('HTTP/1.0 403 No Right to Create Bootos');
			die();
		}
			
		$apikey = $this->_request->getParam('apikey');
		if($apikey == ""){
			header('HTTP/1.0 400 No API-Key');
			die();
		}
			
		$params = $this->_request->getParams();
		$source = $_SERVER['REMOTE_ADDR'];

		if($params['title'] == '' || $params['distro'] == '' || $params['distroversion'] == '' || $params['share']  == '' || $source == ''){
			header('HTTP/1.0 400 Title, Distro, Distroversion and Share must be set');
			die();
		}

		if($_FILES['config']['size'] == 0 && $_FILES['config']['name'] != '' || $_FILES['kernel']['size'] == 0  && $_FILES['kernel']['name'] != ''|| $_FILES['init']['size'] == 0 && $_FILES['init']['name'] != ''){
			header('HTTP/1.0 400 File must be larger than 0 bytes');
			die();
		}

		$bootosMapper = new Application_Model_BootOsMapper();
		$groupID = $this->membership->getGroupID();

		list($bootos) = $bootosMapper->findBy(array('groupid' => $groupID, 'title' => $params['title'], 'distro' => $params['distro'], 'distroversion' => $params['distroversion'], 'source' => $source, 'share' => $params['share']));
		if($bootos != null){
			header('HTTP/1.0 400 Bootos already exists');
			die();
		}
		$bootos = new Application_Model_BootOs();

		$bootos->setOptions($params);
		$bootos->setGroupID($groupID);
		$bootos->setSource($source);
		$bootos->setCreated(time());
		$bootos->setPublic('-1');
		$bootosID = $bootosMapper->save($bootos);
		$bootos->setID($bootosID);

		$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['config']['name'] != ''){
			move_uploaded_file($_FILES['config']['tmp_name'], $configpath."default.tgz");

		}
		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");
			$newconfig = new Pbs_NewConfig();
			$newconfig->createDefaultConfig($bootos);
		}

		header('HTTP/1.0 201 Bootos created');

	}

	public function editbootosAction()
	{

		list($rightroles) = $this->rightrolesMapper->findBy(array('rightID' => '58', 'roleID' => $this->membership->getRoleID()));
		if($rightroles == null){
			header('HTTP/1.0 403 No Right to Edit Bootos');
			die();
		}

		$apikey = $this->_request->getParam('apikey');
		if($apikey == ""){
			header('HTTP/1.0 400 No API-Key');
			die();
		}

		$params = $this->_request->getParams();
		$source = $_SERVER['REMOTE_ADDR'];

		if($params['title'] == '' || $params['distro'] == '' || $params['distroversion'] == '' || $params['share']  == '' || $source == ''){
			header('HTTP/1.0 400 Title, Distro, Distroversion and Share must be set');
			die();
		}

		$bootos = new Application_Model_BootOs();
		$bootosMapper = new Application_Model_BootOsMapper();
		$groupID = $this->membership->getGroupID();

		list($bootos) = $bootosMapper->findBy(array('groupid' => $groupID, 'title' => $params['title'], 'distro' => $params['distro'], 'distroversion' => $params['distroversion'], 'source' => $source, 'share' => $params['share']));

		if($bootos == null){
			header('HTTP/1.0 400 Bootos not found');
			die();
		}

		$bootosID = $bootos->getID();
		$bootossrc = $bootos->getSource();

		$bootos->setOptions($params);
		$bootos->setID($bootosID);
		$bootos->setGroupID($groupID);
		$bootos->setSource($bootossrc);
		$bootos->setCreated(time());
		$bootos->setPublic('-1');

		$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['config']['name'] != ''){
			$bootos->setSource($_SERVER['REMOTE_ADDR']);
			move_uploaded_file($_FILES['config']['tmp_name'], $configpath."default.tgz");
		}
		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");
		}

		$bootosMapper->save($bootos);

		header('HTTP/1.0 201 Bootos edited');
	}

	public function addfilterAction()
	{
		list($rightroles) = $this->rightrolesMapper->findBy(array('rightID' => '87', 'roleID' => $this->membership->getRoleID()));
		if($rightroles == null){
			header('HTTP/1.0 403 No Right to Create Filter');
			die();
		}
			
		$apikey = $this->_request->getParam('apikey');
		if($apikey == ""){
			header('HTTP/1.0 400 No API-Key');
			die();
		}

		$params = $this->_request->getParams();
		$groupID = $this->membership->getGroupID();
		$filterMapper = new Application_Model_FilterMapper();
		$filter = new Application_Model_Filter();
		$filter->setOptions($params);
		$filter->setGroupID($groupID);
		$filter->setCreated(time());
		$filterid = $filterMapper->save($filter);
		$filter->setID($filterid);

		$xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
		$xml .= "<xml>\n";
		$xml .= "\t<filter>\n";
		$xml .= "\t\t<id>" . $filter->getID() . "</id>\n";
		$xml .= "\t\t<bootmenuid>" . $filter->getBootmenuID() . "</bootmenuid>\n";
		$xml .= "\t\t<created>" . $filter->getCreated() . "</created>\n";
		$xml .= "\t\t<description>" . $filter->getDescription() . "</description>\n";
		$xml .= "\t\t<membershipid>" . $filter->getMembershipID() . "</membershipid>\n";
		$xml .= "\t\t<priority>" . $filter->getPriority() . "</priority>\n";
		$xml .= "\t\t<title>" . $filter->getTitle() . "</title>\n";
		$xml .= "\t</filter>\n";
		$xml .= "</xml>";

		header('Content-Type: text/xml');
		header('Content-Disposition: inline; filename="filter.xml"');
		header('Content-Length: ' . strlen($xml));
		header('Pragma: no-cache');
		header('Expires: 0');
		echo $xml;
	}

	public function addfilterentryAction() {
		list($rightroles) = $this->rightrolesMapper->findBy(array('rightID' => '87', 'roleID' => $this->membership->getRoleID()));
		if($rightroles == null){
			header('HTTP/1.0 403 No Right to Create Filter');
			die();
		}
			
		$apikey = $this->_request->getParam('apikey');
		if($apikey == ""){
			header('HTTP/1.0 400 No API-Key');
			die();
		}

		$params = $this->_request->getParams();
		$filterentriesMapper = new Application_Model_FilterEntriesMapper();
		$filterentries = new Application_Model_FilterEntries();
		$filterentries->setOptions($params);
		$filterentriesID = $filterentriesMapper->save($filterentries);
		$filterentries->setFilterID($filterentriesID);
		$filterentries->setID($filterentriesID);

		$xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
		$xml .= "<xml>\n";
		$xml .= "\t<filterentry>\n";
		$xml .= "\t\t<id>" . $filterentries->getID() . "</id>\n";
		$xml .= "\t\t<filterid>" . $filterentries->getFilterID() . "</filterid>\n";
		$xml .= "\t\t<filtertypeid>" . $filterentries->getFiltertypeID() . "</filtertypeid>\n";
		$xml .= "\t\t<filtervalue>" . $filterentries->getFiltervalue() . "</filtervalue>\n";
		$xml .= "\t\t<filtervalue2>" . $filterentries->getFiltervalue2() . "</filtervalue2>\n";
		$xml .= "\t</filterentry>\n";
		$xml .= "</xml>";

		header('Content-Type: text/xml');
		header('Content-Disposition: inline; filename="filterentry.xml"');
		header('Content-Length: ' . strlen($xml));
		header('Pragma: no-cache');
		header('Expires: 0');
		echo $xml;
	}

	public function deletefilterAction() {
		list($rightroles) = $this->rightrolesMapper->findBy(array('rightID' => '90', 'roleID' => $this->membership->getRoleID()));
		if($rightroles == null){
			header('HTTP/1.0 403 No Right to delete Filter');
			die();
		}
			
		$apikey = $this->_request->getParam('apikey');
		if($apikey == ""){
			header('HTTP/1.0 400 No API-Key');
			die();
		}

		$params = $this->_request->getParams();
		$groupID = $this->membership->getGroupID();
		$filterid = $params['filterid'];

		$filterMapper = new Application_Model_FilterMapper();
		$filter = new Application_Model_Filter();
		$filterMapper->find($filterid, $filter);
		if(isset($filter)) {
			if($filter->getMembershipID() == $this->membership->getID() || $filter->getGroupID() == $this->membership->getGroupID()) {
				$filterMapper->delete($filter);

				header('HTTP/1.0 201 Filter deleted');
			} else {
				header('HTTP/1.0 403 No Right to delete this Filter');
				die();
			}
		} else {
			header('HTTP/1.0 400 Filter not found');
			die();
		}
	}

	public function changefilterAction() {
		list($rightroles) = $this->rightrolesMapper->findBy(array('rightID' => '88', 'roleID' => $this->membership->getRoleID()));
		if($rightroles == null){
			header('HTTP/1.0 403 No Right to Create Filter');
			die();
		}
			
		$apikey = $this->_request->getParam('apikey');
		if($apikey == ""){
			header('HTTP/1.0 400 No API-Key');
			die();
		}

		$params = $this->_request->getParams();
		$filterMapper = new Application_Model_FilterMapper();
		$filterid = $params['filterid'];
		$filter = new Application_Model_Filter();
		$filterMapper->find($filterid, $filter);
		if($filter->getID) {
			$filter->setOptions($params);
			if($filter->getMembershipID() == $this->membership->getID() || $filter->getGroupID() == $this->membership->getGroupID()) {
				$filterMapper->save($filter);
				header('HTTP/1.0 201 Filter changed');
			} else {
				header('HTTP/1.0 403 No Right to change this Filter');
				die();
			}
		} else {
			header('HTTP/1.0 400 Filter not found');
			die();
		}
	}

	public function changefilterentryAction() {
		list($rightroles) = $this->rightrolesMapper->findBy(array('rightID' => '88', 'roleID' => $this->membership->getRoleID()));
		if($rightroles == null){
			header('HTTP/1.0 403 No Right to Create Filter');
			die();
		}
			
		$apikey = $this->_request->getParam('apikey');
		if($apikey == ""){
			header('HTTP/1.0 400 No API-Key');
			die();
		}

		$params = $this->_request->getParams();
		$filterentriesMapper = new Application_Model_FilterEntriesMapper();
		$filterentriesid = $params['filterentriesid'];
		$value1 = $params['value1'];
		$value2 = $params['value2'];

		if($filterentriesid) {
			$filterentries = new Application_Model_FilterEntries();
			$filterentriesMapper->find($filterentriesid, $filterentries);
			$filterid = $filterentries->getFilterID();
		} else {
			$oldvalue1 = $params['oldvalue1'];
			$oldvalue2 = $params['oldvalue2'];
			$filterid = $params['filterid'];
			$result = $filterentriesMapper->findBy(array('filtervalue' => $oldvalue1, 'filtervalue2' => $oldvalue2, 'filterID' => $filterid));
			$filterentries = $result[0];
		}

		if(isset($filterentries)) {
			$filterentries->setFiltervalue($value1);
			$filterentries->setFiltervalue2($value2);
			$filterentriesMapper->save($filterentries);
			header('HTTP/1.0 201 Filterentry changed');
		} else {
			header('HTTP/1.0 400 Filterentry not found');
			die();
		}
	}

	public function addbootmenuAction()
	{
		list($rightroles) = $this->rightrolesMapper->findBy(array('rightID' => '65', 'roleID' => $this->membership->getRoleID()));
		if($rightroles == null){
			header('HTTP/1.0 403 No Right to Create Bootmenus');
			die();
		}

		$apikey = $this->_request->getParam('apikey');
		if($apikey == ""){
			header('HTTP/1.0 400 No API-Key');
			die();
		}

		$params = $this->_request->getParams();
		$groupID = $this->membership->getGroupID();

		$bootmenuMapper = new Application_Model_BootMenuMapper();
		$bootmenuEntriesMapper = new Application_Model_BootMenuEntriesMapper();

		$bootmenu = new Application_Model_BootMenu();
		$bootmenu->setOptions($params);
		$bootmenu->setGroupID($groupID);
		$bootmenu->setCreated(time());
		$bootmenuid = $bootmenuMapper->save($bootmenu);
		$bootmenu->setID($bootmenuid);

		$bootmenuentries = new Application_Model_BootMenuEntries();
		$bootosMapper = new Application_Model_BootOsMapper();
		$bootos = new Application_Model_BootOs();
		$bootosMapper->find($params['bootosID'], $bootos);
		$params['title'] = $bootos->getTitle();
		$bootmenuentries->setOptions($params);
		$bootmenuentries->setBootmenuID($bootmenu->getID());
		$bootmenuentriesID = $bootmenuEntriesMapper->save($bootmenuentries);
		$bootmenuentries->setID($bootmenuentriesID);

		$xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
		$xml .= "<xml>\n";
		$xml .= "\t<bootmenu>\n";
		$xml .= "\t\t<id>" . $bootmenu->getID() . "</id>\n";
		$xml .= "\t\t<created>" . $bootmenu->getCreated() . "</created>\n";
		$xml .= "\t\t<groupid>" . $bootmenu->getGroupID() . "</groupid>\n";
		$xml .= "\t\t<membershipid>" . $bootmenu->getMembershipID() . "</membershipid>\n";
		$xml .= "\t\t<startcounter>" . $bootmenu->getStartcounter() . "</startcounter>\n";
		$xml .= "\t\t<defaultbootmenu>" . $bootmenu->getDefaultbootmenu() . "</defaultbootmenu>\n";
		$xml .= "\t\t<title>" . $bootmenu->getTitle() . "</title>\n";
		$xml .= "\t\t<bootmenuentry>\n";
		$xml .= "\t\t\t<id>" . $bootmenuentries->getID() . "</id>\n";
		$xml .= "\t\t\t<bootosid>" . $bootmenuentries->getBootosID() . "</bootosid>\n";
		$xml .= "\t\t\t<configid>" . $bootmenuentries->getConfigID() . "</configid>\n";
		$xml .= "\t\t\t<kcl>" . $bootmenuentries->getKcl() . "</kcl>\n";
		$xml .= "\t\t\t<kclappend>" . $bootmenuentries->getKclappend() . "</kclappend>\n";
		$xml .= "\t\t\t<order>" . $bootmenuentries->getOrder() . "</order>\n";
		$xml .= "\t\t\t<title>" . $bootmenuentries->getTitle() . "</title>\n";
		$xml .= "\t\t</bootmenuentry>\n";
		$xml .= "\t</bootmenu>\n";
		$xml .= "</xml>";

		header('Content-Type: text/xml');
		header('Content-Disposition: inline; filename="bootmenu.xml"');
		header('Content-Length: ' . strlen($xml));
		header('Pragma: no-cache');
		header('Expires: 0');
		echo $xml;
	}

	public function changebootmenuAction()
	{
		list($rightroles) = $this->rightrolesMapper->findBy(array('rightID' => '65', 'roleID' => $this->membership->getRoleID()));
		if($rightroles == null){
			header('HTTP/1.0 403 No Right to Create Bootmenus');
			die();
		}

		$apikey = $this->_request->getParam('apikey');
		if($apikey == ""){
			header('HTTP/1.0 400 No API-Key');
			die();
		}

		$params = $this->_request->getParams();
		$groupID = $this->membership->getGroupID();
		$bootmenuID = $params['bootmenuid'];

		$bootmenuMapper = new Application_Model_BootMenuMapper();
		$bootmenuEntriesMapper = new Application_Model_BootMenuEntriesMapper();

		$bootmenu = new Application_Model_BootMenu();
		$bootmenuMapper->find($bootmenuID, $bootmenu);
		if($bootmenu->getID()) {
			$newBootmenu = clone $bootmenu;
			$newBootmenu->setOptions($params);
			if($newBootmenu->getMembershipID() == $this->membership->getID() || $newBootmenu->getGroupID() == $this->membership->getGroupID()) {
				$bootmenMapper->save($newBootmenu);
				$bootmenuEntries = $bootmenuEntriesMapper->findBy(array('bootmenuID' => $bootmenuID));
				foreach($bootmenuEntries as $bootmenuEntry) {
					$bootmenuEntry->setOptions($params);
					$bootmenuEntriesMapper->save($bootmenuEntry);
				}
				header('HTTP/1.0 201 Bootmenu changed');
			} else {
				header('HTTP/1.0 403 No Right to change this Bootmenu');
				die();
			}
		}
	}

	public function deletebootmenuAction() {
		list($rightroles) = $this->rightrolesMapper->findBy(array('rightID' => '66', 'roleID' => $this->membership->getRoleID()));
		if($rightroles == null){
			header('HTTP/1.0 403 No Right to delete Bootmenus');
			die();
		}

		$apikey = $this->_request->getParam('apikey');
		if($apikey == ""){
			header('HTTP/1.0 400 No API-Key');
			die();
		}

		$params = $this->_request->getParams();
		$groupID = $this->membership->getGroupID();
		$bootmenuid = $params['bootmenuid'];

		$bootmenuMapper = new Application_Model_BootMenuMapper();
		$bootmenu = new Application_Model_BootMenu();
		$bootmenuMapper->find($bootmenuid, $bootmenu);
		if(isset($bootmenu)) {
			if($bootmenu->getMembershipID() == $this->membership->getID() || $bootmenu->getGroupID() == $this->membership->getGroupID()) {
				$bootmenuMapper->delete($bootmenu);

				header('HTTP/1.0 201 Bootmenu deleted');
			} else {
				header('HTTP/1.0 403 No Right to delete this Bootmenu');
				die();
			}
		} else {
			header('HTTP/1.0 400 Filter not found');
			die();
		}
	}



	public function addprebootAction()
	{

		list($rightroles) = $this->rightrolesMapper->findBy(array('rightID' => '40', 'roleID' => $this->membership->getRoleID()));
		if($rightroles == null){
			header('HTTP/1.0 403 No Right to Create Preboots');
			die();
		}

		$apikey = $this->_request->getParam('apikey');
		if($apikey == ""){
			header('HTTP/1.0 400 No API-Key');
			die();
		}

		$params = $this->_request->getParams();
		$source = $_SERVER['REMOTE_ADDR'];

		if($params['title'] == '' || $_FILES['preboot']['name'] == ''){
			header('HTTP/1.0 400 Title and Preboot must be set');
			die();
		}

		if($_FILES['preboot']['size'] == 0 && $_FILES['preboot']['name'] != ''){
			header('HTTP/1.0 400 File must be larger than 0 bytes');
			die();
		}

		$prebootMapper = new Application_Model_PreBootMapper();
		$groupID = $this->membership->getGroupID();

		list($preboot) = $prebootMapper->findBy(array('groupid' => $groupID, 'title' => $params['title']));
		if($preboot != null){
			header('HTTP/1.0 400 Preboot already exists');
			die();
		}

		$preboot = new Application_Model_PreBoot();

		$preboot->setOptions($params);
		$preboot->setGroupID($groupID);
		$preboot->setSource($source);
		$preboot->setCreated(time());

		$prebootID = $prebootMapper->save($preboot);

		$prebootpath = "../resources/bootmedium/".$prebootID."/";
		mkdir($prebootpath ,0777, true);

		if($_FILES['preboot']['name'] != '' ){
			move_uploaded_file($_FILES['preboot']['tmp_name'], $prebootpath."preboot.zip");
		}

		header('HTTP/1.0 201 Preboot created');


	}

	public function editprebootAction()
	{

		list($rightroles) = $this->rightrolesMapper->findBy(array('rightID' => '41', 'roleID' => $this->membership->getRoleID()));
		if($rightroles == null){
			header('HTTP/1.0 403 No Right to Edit Preboot');
			die();
		}

		$apikey = $this->_request->getParam('apikey');
		if($apikey == ""){
			header('HTTP/1.0 400 No API-Key');
			die();
		}

		$params = $this->_request->getParams();
		$source = $_SERVER['REMOTE_ADDR'];

		if($params['title'] == ''){
			header('HTTP/1.0 400 Title must be set');
			die();
		}

		if($_FILES['preboot']['size'] == 0 && $_FILES['preboot']['name'] != ''){
			header('HTTP/1.0 400 File must be larger than 0 bytes');
			die();
		}

		$prebootMapper = new Application_Model_PreBootMapper();
		$groupID = $this->membership->getGroupID();
		$preboot = new Application_Model_PreBoot();

		list($preboot) = $prebootMapper->findBy(array('groupid' => $groupID, 'title' => $params['title']));

		if($preboot == null){
			header('HTTP/1.0 400 Preboot not found');
			die();
		}

		$prebootsrc = $preboot->getSource();
		$prebootID = $preboot->getID();

		$preboot->setOptions($params);
		$preboot->setGroupID($groupID);
		$preboot->setSource($prebootsrc);
		$preboot->setCreated(time());

		$prebootpath = "../resources/bootmedium/".$prebootID."/";
		mkdir($prebootpath ,0777, true);

		if($_FILES['preboot']['name'] != ''){
			$preboot->setSource($source);
			move_uploaded_file($_FILES['preboot']['tmp_name'], $prebootpath."preboot.zip");
		}

		$prebootMapper->save($preboot);

		header('HTTP/1.0 201 Preboot edited');

	}

	public function getinitramfsAction()
	{

		$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');
		}
	}

	public function getconfigAction()
	{
		$bootmenuentryID = $this->thisSession->getBootmenuentryID();
		$bootmenuentry = new Application_Model_BootMenuEntries();
		$bmm = new Application_Model_BootMenuEntriesMapper();
		$bmm->find($bootmenuentryID,$bootmenuentry);

		$configID = $bootmenuentry->getConfigID();
		$bootosID = $this->thisSession->getBootosID();

		if(is_dir("../resources/bootos/$bootosID/config/")){

			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($configID == null){
				chdir("../resources/bootos/$bootosID/config/");
				passthru( "cat default.tgz");
			}else{
				$bootosuserMapper = new Application_Model_BootOsUserMapper();
				$bootosuser = $bootosuserMapper->findBy(array('configID' => $configID));

				$hash = md5(microtime(1));
				$tmp_conf = "../resources/config/$hash";
				mkdir($tmp_conf ,0777, true);
				exec("tar -C $tmp_conf -xf ../resources/bootos/$bootosID/config/default.tgz",$result);
				exec("tar -C $tmp_conf/rootfs/ -xf ../resources/config/etc.tgz");

				$username = '';
				$userpassword = '';

				if($this->thisSession->getMembershipID() != null){
					$person = new Application_Model_Person();
					$personMapper = new Application_Model_PersonMapper();
					$membershipMapper = new Application_Model_MembershipMapper();
					$personID = $membershipMapper->find($this->thisSession->getMembershipID())->getPersonID();
					$person = $personMapper->find($personID);
					$username = strtolower($person->getName());
					$username = preg_replace("!\s!","",$username);
					$userpassword = $person->getLoginPassword();
				}
				$anzUsers = count($bootosuser);
				$test = array();
				if($anzUsers <= 2){
					foreach($bootosuser as $user)
					$test[] = $user->getLogin();
				}

				$configView = new Zend_View();
				$f = fopen("$tmp_conf/initramfs/postinit.local", "a");

				foreach($bootosuser as $user){

					if($user->getLogin() == '%username%'){
						$configView->loginname = $username;
					}else{
						$configView->loginname = $user->getLogin();
					}

					if($user->getPassword() == '%password%'){
						$configView->password = $userpassword;
					}else{
						$configView->password = $user->getPassword();
					}

					if($user->getHometypeID() == 2){
						$configView->homepath = $user->getHomepath();
					}elseif($user->getHometypeID() == 1){
						$configView->homepath = "/media/openslx-stick/home/".$configView->loginname;
					}else{
						$configView->homepath = "/home/".$configView->loginname;
					}

					if($configView->loginname != '' && $configView->password != ''){

						if($user->getHometypeID() == 1){
							$configView->usb = true;
						}
						else{
							$configView->usb = false;
							if($anzUsers <= 2 && $user->getLogin() == 'kiosk' && in_array('%username%',$test) && $this->thisSession->getMembershipID() == null)
							$configView->autologin = true;
							elseif($anzUsers <= 2 && $user->getLogin() == '%username%'  && $this->thisSession->getMembershipID() != null)
							$configView->autologin = true;
							else
							$configView->autologin = false;

						}


						$configView->addScriptPath(APPLICATION_PATH.'/views/scripts/resource/');
						$config = $configView->render('getconfig.phtml');

						fputs($f, $config);

					}
				}
				fclose($f);

				// create the gzipped tarfile.
				chdir($tmp_conf);
				passthru( "tar cz *");
				exec("rm -rf ../$hash");

			}
		}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){
				$result = $kcl . " alpha=" . $this->_request->getParam('alpha') . " file=http://".$_SERVER['HTTP_HOST']."/c/".$this->_request->getParam('alpha')."/default.tgz ".$bme->getKclappend();
			}else{
				$result = "alpha=" . $this->_request->getParam('alpha') . " file=http://".$_SERVER['HTTP_HOST']."/c/".$this->_request->getParam('alpha')."/default.tgz ".$bme->getKclappend();
			}
			$result = trim($result);
			header("Content-Length: ".(strlen($result)));

			echo $result;


		}

	}

	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

		$return_val =
		array(
   			'info' => 'This function is for debugging purpose only',
   			'kernel' => $this->generateURL('getkernel', 'alpha', $this->thisSession->getAlphasessionID(), "kernel"), 
   			'initramfs' => $this->generateURL('getinitramfs', 'alpha', $this->thisSession->getAlphasessionID(), "initramfs"),
   			'kcl' => $this->generateURL('getkcl', 'alpha', $this->thisSession->getAlphasessionID(), "kcl.txt"),
   			'config' => $this->generateURL('getconfig', 'alpha', $this->thisSession->getAlphasessionID(), 'default.tgz')
		);

		$result = $return_val;
		$result2 = "<table class='json'>";
		$result2 .= "<tr><td><b>info</b>: </td><td>".$result['info']."</td></tr>";
		$result2 .= "<tr><td><b>kernel</b>:  </td><td><a href=".$result['kernel'].">".$result['kernel']."<a></td></tr>";
		$result2 .= "<tr><td><b>initramfs</b>:  </td><td><a href=".$result['initramfs'].">".$result['initramfs']."<a></td></tr>";
		$result2 .= "<tr><td><b>kcl</b>:  </td><td><a href=".$result['kcl'].">".$result['kcl']."<a></td></tr>";
		$result2 .= "<tr><td><b>config</b>:  </td><td><a href=".$result['config'].">".$result['config']."<a></td></tr>";
		$result2 .= "</table>";
		echo $result2;
	}

	public function getbootosAction() {
		list($rightroles1) = $this->rightrolesMapper->findBy(array('rightID' => '56', 'roleID' => $this->membership->getRoleID()));
		list($rightroles2) = $this->rightrolesMapper->findBy(array('rightID' => '57', 'roleID' => $this->membership->getRoleID()));
		if($rightroles1 == null && $rightroles2 == null){
			header('HTTP/1.0 403 No Right to Show Bootos');
			die();
		}

		$apikey = $this->_request->getParam('apikey');
		if($apikey == ""){
			header('HTTP/1.0 400 No API-Key');
			die();
		}

		$params = $this->_request->getParams();
		$source = $_SERVER['REMOTE_ADDR'];

		$bootos = new Application_Model_BootOs();
		$bootosMapper = new Application_Model_BootOsMapper();
		$configsMapper = new Application_Model_ConfigMapper();
		$groupID = $this->membership->getGroupID();

		if(isset($params['bootosid'])) {
			$bootos = array($bootosMapper->find($params['bootosid']));
			if($bootos[0]->getGroupID() != $groupID) {
				list($rightroles1) = $this->rightrolesMapper->findBy(array('rightID' => '110', 'roleID' => $this->membership->getRoleID()));
				if($rightroles1 == null){
					header('HTTP/1.0 403 No Right to Show this Bootos');
					die();
				}
			}
		} else {
			$groupgroupsMapper = new Application_Model_GroupGroupsMapper();
			$parents = array();
			$bootos = array();
			$parents = $groupgroupsMapper->getParentGroups($groupID);
			foreach($parents as $k => $parent) {
				foreach($parent as $p) {
					$results = $bootosMapper->findBy(array("groupID" => $p));
					foreach ($results as $result) {
						if($result->getPublic() - $k >= 0 ) {
							$bootos[] = $result;
						} else if($k == 0 && $result->getPublic() == -1 && Pbs_Acl::checkRight('boc')) {
							$bootos[] = $result;
						}
					}
				}
			}
		}

		if($bootos == null){
			header('HTTP/1.0 400 No Bootos was found');
			die();
		}

		$xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
		$xml .= "<xml>\n";
		$xml .= "\t<bootoslist>\n";
		foreach($bootos as $bootosobj) {
			$xml .= "\t\t<bootos>\n";
			$xml .= "\t\t\t<id>" . $bootosobj->getID() . "</id>\n";
			$xml .= "\t\t\t<groupid>" . $bootosobj->getGroupID() . "</groupid>\n";
			$xml .= "\t\t\t<membershipid>" . $bootosobj->getMembershipID() . "</membershipid>\n";
			$xml .= "\t\t\t<title>" . $bootosobj->getTitle() . "</title>\n";
			$xml .= "\t\t\t<defaultkcl>" . $bootosobj->getDefaultkcl() . "</defaultkcl>\n";
			$xml .= "\t\t\t<created>" . $bootosobj->getCreated() . "</created>\n";
			$xml .= "\t\t\t<description>" . $bootosobj->getDescription() . "</description>\n";
			$xml .= "\t\t\t<expires>" . $bootosobj->getExpires() . "</expires>\n";
			$xml .= "\t\t\t<public>" . $bootosobj->getPublic() . "</public>\n";
			$xml .= "\t\t\t<source>" . $bootosobj->getSource() . "</source>\n";
			$xml .= "\t\t\t<distro>" . $bootosobj->getDistro() . "</distro>\n";
			$xml .= "\t\t\t<distroversion>" . $bootosobj->getDistroversion() . "</distroversion>\n";
			$xml .= "\t\t\t<shortname>" . $bootosobj->getShortname() . "</shortname>\n";
			$xml .= "\t\t\t<share>" . $bootosobj->getShare() . "</share>\n";
			$xml .= "\t\t\t<configs>\n";
			$configs = $configsMapper->findBy(array('bootosID' => $bootosobj->getID()));
			if(is_array($configs)) {
				foreach($configs as $config) {
					if($config->getVisible()) {
						$xml .= "\t\t\t\t<config>\n";
						$xml .= "\t\t\t\t\t<configid>" . $config->getID() . "</configid>\n";
						$xml .= "\t\t\t\t\t<title>" . $config->getTitle() . "</title>\n";
						$xml .= "\t\t\t\t\t<description>" . $config->getDescription() . "</description>\n";
						$xml .= "\t\t\t\t\t<groupid>" . $config->getGroupID() . "</groupid>\n";
						$xml .= "\t\t\t\t\t<membershipid>" . $config->getMembershipID() . "</membershipid>\n";
						$xml .= "\t\t\t\t\t<created>" . $config->getCreated() . "</created>\n";
						$xml .= "\t\t\t\t\t<visible>" . $config->getVisible() . "</visible>\n";
						$xml .= "\t\t\t\t</config>\n";
					}
				}
			}
			$xml .= "\t\t\t</configs>\n";
			$xml .= "\t\t</bootos>\n";
		}
		$xml .= "\t</bootoslist>\n";
		$xml .= "</xml>";

		header('Content-Type: text/xml');
		header('Content-Disposition: inline; filename="bootos.xml"');
		header('Content-Length: ' . strlen($xml));
		header('Pragma: no-cache');
		header('Expires: 0');
		echo $xml;
	}

	public function getpoolAction() {
		list($rightroles1) = $this->rightrolesMapper->findBy(array('rightID' => '79', 'roleID' => $this->membership->getRoleID()));
		if($rightroles1 == null){
			header('HTTP/1.0 403 No Right to Show Pools');
			die();
		}

		$apikey = $this->_request->getParam('apikey');
		if($apikey == ""){
			header('HTTP/1.0 400 No API-Key');
			die();
		}

		$params = $this->_request->getParams();
		$poolMapper = new Application_Model_PoolMapper();
		$poolEntriesMapper = new Application_Model_PoolEntriesMapper();
		$clientMapper = new Application_Model_ClientMapper();
		$client = new Application_Model_Client();
		$groupID = $this->membership->getGroupID();

		if(isset($params['poolid'])) {
			$pool = array(new Application_Model_Pool());
			$poolMapper->find($params['poolid'], $pool[0]);
			if($pool[0]->getGroupID() != $groupID) {
				list($rightroles1) = $this->rightrolesMapper->findBy(array('rightID' => '109', 'roleID' => $this->membership->getRoleID()));
				if($rightroles1 == null){
					header('HTTP/1.0 403 No Right to Show this Pool');
					die();
				}
			}
		} else {
			$pool = $poolMapper->findBy(array('groupid' => $groupID));
		}

		if($pool == null){
			header('HTTP/1.0 400 No Pool was found');
			die();
		}

		$xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
		$xml .= "<xml>\n";
		$xml .= "\t<poollist>\n";
		foreach($pool as $poolobj) {
			$xml .= "\t\t<pool>\n";
			$xml .= "\t\t\t<id>" . $poolobj->getID() . "</id>\n";
			$xml .= "\t\t\t<groupid>" . $poolobj->getGroupID() . "</groupid>\n";
			$xml .= "\t\t\t<title>" . $poolobj->getTitle() . "</title>\n";
			$xml .= "\t\t\t<description>" . $poolobj->getDescription() . "</description>\n";
			$xml .= "\t\t\t<location>" . $poolobj->getLocation() . "</location>\n";
			$poolentries = $poolEntriesMapper->findBy(array('poolID' => $poolobj->getID()));
			list($rightroles2) = $this->rightrolesMapper->findBy(array('rightID' => '75', 'roleID' => $this->membership->getRoleID()));
			if($rightroles2 != null){
				$xml .= "\t\t\t<clients>\n";
				foreach($poolentries as $poolentry) {
					$clientMapper->find($poolentry->getClientID(), $client);
					$xml .= "\t\t\t\t<client>\n";
					$xml .= "\t\t\t\t\t<clientID>" . $client->getID() . "</clientID>\n";
					$xml .= "\t\t\t\t\t<groupID>" . $client->getGroupID() . "</groupID>\n";
					$xml .= "\t\t\t\t\t<macadress>" . $client->getMacadress() . "</macadress>\n";
					$xml .= "\t\t\t\t\t<ip>" . $client->getIp() . "</ip>\n";
					$xml .= "\t\t\t\t\t<ip6>" . $client->getIp6() . "</ip6>\n";
					$xml .= "\t\t\t\t\t<hardwarehash>" . $client->getHardwarehash() . "</hardwarehash>\n";
					$xml .= "\t\t\t\t\t<created>" . $client->getCreated() . "</created>\n";
					$xml .= "\t\t\t\t</client>\n";
				}
				$xml .= "\t\t\t</clients>\n";
			}
			$xml .= "\t\t</pool>\n";
		}
		$xml .= "\t</poollist>\n";
		$xml .= "</xml>";

		header('Content-Type: text/xml');
		header('Content-Disposition: inline; filename="pool.xml"');
		header('Content-Length: ' . strlen($xml));
		header('Pragma: no-cache');
		header('Expires: 0');
		echo $xml;
	}

	public function getpersonAction() {
		$apikey = $this->_request->getParam('apikey');
		if($apikey == ""){
			header('HTTP/1.0 400 No API-Key');
			die();
		}

		if($this->_request->getParam('personid')) {
			$personid = $this->_request->getParam('personid');
			if($personid != $this->membership->getPersonID()) {
				list($rightroles) = $this->rightrolesMapper->findBy(array('rightID' => '6', 'roleID' => $this->membership->getRoleID()));
				if($rightroles == null){
					header('HTTP/1.0 403 No Right to Show Details of other Person');
					die();
				}
			}
		} else {
			$personid = $this->membership->getPersonID();
		}

		$personMapper = new Application_Model_PersonMapper();
		$person = new Application_Model_Person();
		$personMapper->find($personid,$person);

		$xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
		$xml .= "<xml>\n";
		$xml .= "\t<person>\n";
		$xml .= "\t\t<id>" . $person->getID() . "</id>\n";
		$xml .= "\t\t<city>" . $person->getCity() . "</city>\n";
		$xml .= "\t\t<email>" . $person->getEmail() . "</email>\n";
		$xml .= "\t\t<firstname>" . $person->getFirstname() . "</firstname>\n";
		$xml .= "\t\t<housenumber>" . $person->getHousenumber() . "</housenumber>\n";
		$xml .= "\t\t<login>" . $person->getLogin() . "</login>\n";
		$xml .= "\t\t<logindate>" . $person->getLogindate() . "</logindate>\n";
		$xml .= "\t\t<name>" . $person->getName() . "</name>\n";
		$xml .= "\t\t<postalcode>" . $person->getPostalcode() . "</postalcode>\n";
		$xml .= "\t\t<registerdate>" . $person->getRegisterdate() . "</registerdate>\n";
		$xml .= "\t\t<street>" . $person->getStreet() . "</street>\n";
		$xml .= "\t\t<suspend>" . $person->getSuspend() . "</suspend>\n";
		$xml .= "\t\t<title>" . $person->getTitle() . "</title>\n";
		$xml .= "\t</person>\n";
		$xml .= "</xml>";

		header('Content-Type: text/xml');
		header('Content-Disposition: inline; filename="person.xml"');
		header('Content-Length: ' . strlen($xml));
		header('Pragma: no-cache');
		header('Expires: 0');
		echo $xml;
	}

	public function getgroupAction() {
		list($rightroles1) = $this->rightrolesMapper->findBy(array('rightID' => '79', 'roleID' => $this->membership->getRoleID()));
		if($rightroles1 == null){
			header('HTTP/1.0 403 No Right to Show Groups');
			die();
		}

		$apikey = $this->_request->getParam('apikey');
		if($apikey == ""){
			header('HTTP/1.0 400 No API-Key');
			die();
		}

		$groupMapper = new Application_Model_GroupMapper();

		if($this->_request->getParam('groupid')) {
			$groupid = $this->_request->getParam('groupid');
			if($groupid != $this->membership->getGroupID()) {
				list($rightroles2) = $this->rightrolesMapper->findBy(array('rightID' => '11', 'roleID' => $this->membership->getRoleID()));
				if($rightroles2 == null){
					header('HTTP/1.0 403 No Right to Show Details of other Group');
					die();
				}
			}
		} else {
			$groupid = $this->membership->getGroupID();
		}

		$group = new Application_Model_Group();
		$groupMapper->find($groupid, $group);

		$xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
		$xml .= "<xml>\n";
		$xml .= "\t<group>\n";
		$xml .= "\t\t<id>" . $group->getID() . "</id>\n";
		$xml .= "\t\t<description>" . $group->getDescription() . "</description>\n";
		$xml .= "\t\t<title>" . $group->getTitle() . "</title>\n";
		$xml .= "\t</group>\n";
		$xml .= "</xml>";

		header('Content-Type: text/xml');
		header('Content-Disposition: inline; filename="group.xml"');
		header('Content-Length: ' . strlen($xml));
		header('Pragma: no-cache');
		header('Expires: 0');
		echo $xml;
	}

	public function getmembershipAction() {
		$apikey = $this->_request->getParam('apikey');
		if($apikey == ""){
			header('HTTP/1.0 400 No API-Key');
			die();
		}

		$membershipMapper = new Application_Model_MembershipMapper();
		$membershipid = $this->membership->getID();
		$membership = new Application_Model_Membership();
		$membershipMapper->find($membershipid, $membership);

		$xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
		$xml .= "<xml>\n";
		$xml .= "\t<membership>\n";
		$xml .= "\t\t<id>" . $membership->getID() . "</id>\n";
		$xml .= "\t\t<apikey>" . $membership->getApikey() . "</apikey>\n";
		$xml .= "\t\t<groupid>" . $membership->getGroupID() . "</groupid>\n";
		$xml .= "\t\t<personid>" . $membership->getPersonID() . "</personid>\n";
		$xml .= "\t\t<roleid>" . $membership->getRoleID() . "</roleid>\n";
		$xml .= "\t\t<suspend>" . $membership->getSuspend() . "</suspend>\n";
		$xml .= "\t</membership>\n";
		$xml .= "</xml>";

		header('Content-Type: text/xml');
		header('Content-Disposition: inline; filename="membership.xml"');
		header('Content-Length: ' . strlen($xml));
		header('Pragma: no-cache');
		header('Expires: 0');
		echo $xml;
	}

	public function getclientAction() {
		list($rightroles1) = $this->rightrolesMapper->findBy(array('rightID' => '75', 'roleID' => $this->membership->getRoleID()));
		if($rightroles1 == null){
			header('HTTP/1.0 403 No Right to Show Groups');
			die();
		}

		$apikey = $this->_request->getParam('apikey');
		if($apikey == ""){
			header('HTTP/1.0 400 No API-Key');
			die();
		}

		$params = $this->_request->getParams();
		$clientid = $params['clientid'];
		$poolid = $params['poolid'];

		if(!isset($clientid)) {
			if(!isset($poolid)) {
				header('HTTP/1.0 400 No ID');
				die();
			}
		}

		$clientMapper = new Application_Model_ClientMapper();

		$clientlist = array();
		if($poolid) {
			$poolEntriesMapper = new Application_Model_PoolEntriesMapper();
			$poolentries = $poolEntriesMapper->findBy(array("poolID" => $poolid));
			foreach($poolentries as $entry) {
				$client = new Application_Model_Client();
				$clientMapper->find($entry->getClientID(), $client);
				$clientlist[] = $client;
			}
		} else if($clientid) {
			$client = new Application_Model_Client();
			$clientMapper->find($clientid, $client);
			$clientlist[] = $client;
		}

		$xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
		$xml .= "<xml>\n";
		$xml .= "\t<clientlist>\n";
		if(count($clientlist) > 0) {
			foreach($clientlist as $client) {
				$xml .= "\t\t<client>\n";
				$xml .= "\t\t\t<clientID>" . $client->getID() . "</clientID>\n";
				$xml .= "\t\t\t<groupID>" . $client->getGroupID() . "</groupID>\n";
				$xml .= "\t\t\t<macadress>" . $client->getMacadress() . "</macadress>\n";
				$xml .= "\t\t\t<ip>" . $client->getIp() . "</ip>\n";
				$xml .= "\t\t\t<ip6>" . $client->getIp6() . "</ip6>\n";
				$xml .= "\t\t\t<hardwarehash>" . $client->getHardwarehash() . "</hardwarehash>\n";
				$xml .= "\t\t\t<created>" . $client->getCreated() . "</created>\n";
				$xml .= "\t\t</client>\n";
			}
		} else {
			$xml .= "\t\tno clients\n";
		}
		$xml .= "\t</clientlist>\n";
		$xml .= "</xml>";

		header('Content-Type: text/xml');
		header('Content-Disposition: inline; filename="client.xml"');
		header('Content-Length: ' . strlen($xml));
		header('Pragma: no-cache');
		header('Expires: 0');
		echo $xml;
	}

	public function getroleAction() {
		$params = $this->_request->getParams();

		$apikey = $params['apikey'];
		if($apikey == ""){
			header('HTTP/1.0 400 No API-Key');
			die();
		}

		$roleMapper = new Application_Model_RoleMapper();

		if(isset($params['roleid'])) {
			$roleID = $params['roleid'];
			if($this->membership->getRoleID() != $roleID) {
				list($rightroles1) = $this->rightrolesMapper->findBy(array('rightID' => '24', 'roleID' => $this->membership->getRoleID()));
				if($rightroles1 == null){
					header('HTTP/1.0 403 No Right to Show Roles');
					die();
				}
			}
		} else {
			$roleID = $this->membership->getRoleID();
		}

		$role = new Application_Model_Role();
		$roleMapper->find($roleID, $role);

		$newRoleID = $role->getID();

		if(!isset($newRoleID)) {
			header('HTTP/1.0 400 No Role was found');
			die();
		}

		$xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
		$xml .= "<xml>\n";
		$xml .= "\t<role>\n";
		$xml .= "\t\t<id>" . $role->getID() . "</id>\n";
		$xml .= "\t\t<groupid>" . $role->getGroupID() . "</groupid>\n";
		$xml .= "\t\t<title>" . $role->getTitle() . "</title>\n";
		$xml .= "\t\t<description>" . $role->getDescription() . "</description>\n";
		$xml .= "\t\t<inheritance>" . $role->getInheritance() . "</inheritance>\n";
		$xml .= "\t</role>\n";
		$xml .= "</xml>";

		header('Content-Type: text/xml');
		header('Content-Disposition: inline; filename="role.xml"');
		header('Content-Length: ' . strlen($xml));
		header('Pragma: no-cache');
		header('Expires: 0');
		echo $xml;
	}

	public function checkrightAction() {
		$apikey = $this->_request->getParam('apikey');
		if($apikey == ""){
			header('HTTP/1.0 400 No API-Key');
			die();
		}

		$rightShortcut = $this->_request->getParam('rightshortcut');
		$rightMapper = new Application_Model_RightMapper();
		$result = $rightMapper->findBy(array('shortcut' => $rightShortcut));
		if(count($result) < 1) {
			header('HTTP/1.0 400 Wrong Right Shortcut');
			die();
		}
		$right = $result[0];

		$roleid = $this->membership->getRoleID();
		$rightid = $right->getID();
		$rightrolesMapper = new Application_Model_RightRolesMapper();
		$rightroles = $rightrolesMapper->find($roleid, $rightid);

		$xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
		$xml .= "<xml>\n";
		$xml .= "\t<checkright>\n";

		if(is_object($rightroles)) {
			$xml .= "\t\t<success>true</success>\n";
		} else {
			$xml .= "\t\t<success>false</success>\n";
		}

		$xml .= "\t</checkright>\n";
		$xml .= "</xml>";

		header('Content-Type: text/xml');
		header('Content-Disposition: inline; filename="checkright.xml"');
		header('Content-Length: ' . strlen($xml));
		header('Pragma: no-cache');
		header('Expires: 0');
		echo $xml;
	}

	public function loginAction() {
		$xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
		$xml .= "<xml>\n";
		$xml .= "\t<login>\n";

		$email = $this->_request->getParam('email');
		$password = $this->_request->getParam('password');

		$auth = Zend_Auth::getInstance();
		$adapter = new Zend_Auth_Adapter_DbTable( $this->db, 'pbs_person', 'email', 'password', 'MD5(CONCAT(?, password_salt))');
		$adapter->setIdentity($email);
		$adapter->setCredential($password);
		$result = $auth->authenticate($adapter);

		if(!$result->isValid()) {
			$xml .= "\t\t<success>false</success>\n";
			$xml .= "\t\t<error>wrong email or password</error>\n";
		} else {
			$personMapper = new Application_Model_PersonMapper();
			$result = $personMapper->findBy(array('email' => Zend_Auth::getInstance()->getIdentity()),true);
			$person = new Application_Model_Person($result[0]);
			$person->setID($result[0]['personID']);

			if($person->getSuspend()) {
				$xml .= "\t\t<success>false</success>\n";
				$xml .= "\t\t<personid>" . $person->getID() . "</personid>";
				$xml .= "\t\t<error>person suspended</error>\n";
			} else {
				$xml .= "\t\t<success>true</success>\n";
				$xml .= "\t\t<personid>" . $person->getID() . "</personid>";

				$membershipMapper = new Application_Model_MembershipMapper();
				$memberships = $membershipMapper->findBy(array('personID' => $person->getID()));
				$xml .= "\t\t<membershiplist>\n";
				if(is_array($memberships)) {
					foreach($memberships as $membership) {
						$xml .= "\t\t\t<membership>\n";
						$xml .= "\t\t\t\t<id>" . $membership->getID() . "</id>\n";
						$xml .= "\t\t\t\t<groupid>" . $membership->getGroupID() . "</groupid>\n";
						$xml .= "\t\t\t\t<roleid>" . $membership->getRoleID() . "</roleid>\n";
						$xml .= "\t\t\t\t<personid>" . $membership->getPersonID() . "</personid>\n";
						$xml .= "\t\t\t\t<suspend>" . $membership->getSuspend() . "</suspend>\n";
						$xml .= "\t\t\t\t<apikey>" . $membership->getApikey() . "</apikey>\n";
						$xml .= "\t\t\t</membership>\n";
					}
				} else {
					$xml .= "\t\t\t<error>no memberships founded</error>\n";
				}
				$xml .= "\t\t</membershiplist>\n";
			}
		}

		$xml .= "\t</login>\n";
		$xml .= "</xml>";

		header('Content-Type: text/xml');
		header('Content-Disposition: inline; filename="login.xml"');
		header('Content-Length: ' . strlen($xml));
		header('Pragma: no-cache');
		header('Expires: 0');
		echo $xml;
	}

	private function generateURL($action, $varname, $varvalue, $filename){
		$path = '/resource/'. $action .'/' . $varname .'/' . $varvalue .'/bootmenuentryID/'.$this->thisSession->getBootmenuentryID().'/file/' . $filename  ;
		$path = "http://" . $_SERVER['SERVER_NAME'] . $path;
		return $path;
	}

}