summaryrefslogtreecommitdiffstats
path: root/application/modules/dev/controllers/BootisoController.php
blob: 7ae4df9fde29c39625a7feecbce9e680d8204d6a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
<?php

class dev_BootisoController extends Zend_Controller_Action
{

    public function init()
    {
   		$db = Zend_Db_Table::getDefaultAdapter();
    }

    public function indexAction()
    {
    	$bootisomapper = new Application_Model_BootIsoMapper();
    	$groupmapper = new Application_Model_GroupMapper();
    	$membershipmapper = new Application_Model_MembershipMapper();
    	$personmapper = new Application_Model_PersonMapper();
    	$prebootmapper = new Application_Model_PreBootMapper(); 
    	
    	$this->view->bootisolist = $bootisomapper->fetchAll();
    	$this->view->prebootlist = array();
    	
    	    
    	foreach ($this->view->bootisolist as $bootiso){
    		  $this->view->prebootlist[$bootiso->getID()] = $prebootmapper->find($bootiso->getPrebootID())->getTitle();
    		  $bootiso->setGroupID("[".$bootiso->getGroupID()."] ".$groupmapper->find($bootiso->getGroupID())->getTitle());
    		  $bootiso->setMembershipID("[".$bootiso->getMembershipID()."] ".$personmapper->find($membershipmapper->find($bootiso->getMembershipID())->getPersonID())->getFirstname());
    	}
    
    }
    
    public function downloadbootisoAction()
    {
    	$this->_helper->layout->disableLayout();
		$this->_helper->viewRenderer->setNoRender(true);
		
    	$prebootID = $this->_request->getParam('prebootID');
    	$bootisoID = $this->_request->getParam('bootisoID');   	

    	if(is_dir("../resources/bootmedium/$prebootID/") && is_numeric($prebootID) && is_numeric($bootisoID)){
			 
    		chdir("../resources/bootmedium/$prebootID/");
    
    		header("X-Sendfile: $bootisoID".".zip");
			header('Content-Type: application/x-gzip');
			$content_disp = ( ereg('MSIE ([0-9].[0-9]{1,2})', $_SERVER['HTTP_USER_AGENT']) == 'IE') ? 'inline' : 'attachment';
			header('Content-Disposition:  ' . $content_disp . '; filename="preboot.zip"');
			header('Pragma: no-cache');
			header('Expires: 0');
			
			
    		$handle = fopen($bootisoID.".zip", 'r');
			$chunk_size = 8192;
			while ($chunk = fread($handle, $chunk_size)) {
				echo $chunk;
				ob_flush();
			}
						
    	}
    	
    	

    
    }

    public function createbootisoAction()
    {
    		$groupmapper = new Application_Model_GroupMapper();
    		$prebootmapper = new Application_Model_PreBootMapper();
    	
           	if (!isset($_POST["createbootiso"])){
    	        $createbootisoForm = new dev_Form_BootisoCreate(array('grouplist' => $groupmapper->fetchAll(),'prebootlist' => $prebootmapper->fetchAll()));
    		} else {
    			
    	        $createbootisoForm = new dev_Form_BootisoCreate(array('grouplist' => $groupmapper->fetchAll(),'prebootlist' => $prebootmapper->fetchAll()),$_POST);
    			    			
    		    if ($createbootisoForm->isValid($_POST)) {

    		    	$bootiso = new Application_Model_BootIso($_POST);
    		    	$bootiso->setMembershipID('1');
    		        $bootisomapper = new Application_Model_BootIsoMapper();
    		        $bootiso->setCreated(time()); 
    		        
    		        $prebootID = $bootiso->getPrebootID();
    		        
    		    	try {  
    		    		
    		            $bootisoID = $bootisomapper->save($bootiso);
    		            
    		            copy("../resources/bootmedium/$prebootID/preboot.zip", "../resources/bootmedium/$prebootID/$bootisoID".".zip");
    		            $zip = new ZipArchive();
    		            $res = $zip->open("../resources/bootmedium/$prebootID/$bootisoID".".zip");
    		            if($res === true){
    		            	$rootdir = $zip->getNameIndex(0);
							$zip->addFromString($rootdir."build/rootfs/tmp/serial", $bootiso->getSerialnumber());  
							$zip->close(); 		            	
    		            }
	
    		        }catch(Zend_Exception $e)
    		        {
    		            echo "Caught exception: " . get_class($e) . "<br/>";
    					echo "Message: " . $e->getMessage() . "<br/>";
    					
    		        }
					$this->_redirect('/dev/bootiso');
    		     }
    		}
    
            $this->view->createbootisoForm = $createbootisoForm;
    }

    public function editbootisoAction()
    {
    	$bootisoID = $this->_request->getParam('bootisoID');  	
    	$groupmapper = new Application_Model_GroupMapper();
    	$prebootmapper = new Application_Model_PreBootMapper();
    	
    	
    	if (!isset($_POST["editbootiso"])){
    		$bootisoID = $this->_request->getParam('bootisoID');
     		if (!isset($bootisoID) || !is_numeric($bootisoID)){
   				$this->_redirect('/dev/bootiso');
    		} else {
    		   $bootiso = new Application_Model_BootIso();
    		   $bootisomapper = new Application_Model_BootIsoMapper();
    		   $bootisomapper->find($bootisoID, $bootiso);
    		   
    		   $editbootisoForm = new dev_Form_BootisoEdit(array('grouplist' => $groupmapper->fetchAll(),'prebootlist' => $prebootmapper->fetchAll()));
    		   $editbootisoForm->populate($bootiso->toArray()); 
    		}
    	}else{
    		$editbootisoForm = new dev_Form_BootisoEdit(array('grouplist' => $groupmapper->fetchAll(),'prebootlist' => $prebootmapper->fetchAll()),$_POST);
    			    			
    		if ($editbootisoForm->isValid($_POST)) {

    			$bootiso = new Application_Model_BootIso($_POST);
    			$bootiso->setMembershipID('1');
    		    $bootisomapper = new Application_Model_BootIsoMapper();
    		    $bootiso->setCreated(time());
    		    $bootiso->setID($bootisoID);
    		    $prebootID = $bootiso->getPrebootID();
    		    
    		   	try {  
    		   		
    		   		
    		   	    $zip = new ZipArchive();
    		        $res = $zip->open("../resources/bootmedium/$prebootID/$bootisoID".".zip");
    		        if($res === true){
    		            $rootdir = $zip->getNameIndex(0);
						$zip->addFromString($rootdir."build/rootfs/serial", $bootiso->getSerialnumber());  
						$zip->close(); 		            	
    		        }
    		            
    		   		$bootisomapper->save($bootiso);
    		       	
    		    }catch(Zend_Exception $e)
    		    {
    		    	echo "Caught exception: " . get_class($e) . "<br/>";
    				echo "Message: " . $e->getMessage() . "<br/>";	
    		    }
    		    
				$this->_redirect('/dev/bootiso');
    		}
    			
    	}
    	
    	$this->view->editbootisoForm = $editbootisoForm;
    }

    public function deletebootisoAction()
    {
   		$bootisoID = $this->_request->getParam('bootisoID');
     	if (!isset($bootisoID)){
   			$this->_redirect('/dev/bootiso');
    	} else {
    		   $bootiso = new Application_Model_BootIso();
    		   $bootiso->setID($bootisoID);
    		   $bootisomapper = new Application_Model_BootIsoMapper();
    		   $bootisomapper->delete($bootiso);
    	}
    	$this->_redirect('/dev/bootiso');
    }


}