summaryrefslogtreecommitdiffstats
path: root/application/controllers/ResourceController.php
blob: 5459877cdcf23677353fa66927abb91217961aa5 (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
<?php

class ResourceController extends Zend_Controller_Action
{

	private $thisSession;
	private $page;

	public function init()
	{
		$this->_helper->layout->disableLayout();
		$this->_helper->viewRenderer->setNoRender();
		
		$session = new Application_Model_Session();
		$sm = new Application_Model_SessionMapper();
		
		$bootmenuentryID = $this->_request->getParam('bootmenuentryID');
		//TODO Error Messages if something failed
		if(!isset($bootmenuentryID)){
			$alphasessionID = $this->_request->getParam('alpha');
			$result = $sm->findBy('alphasessionID',$alphasessionID);
			# print_a($result);
			$this->thisSession = $session->setOptions($result[0]);
			$this->thisSession->setID($result[0]['sessionID']);
		}
		else{
			$this->page = $this->_request->getParam('page');
			$bootmenuentryID = $this->_request->getParam('bootmenuentryID');
			if(!is_numeric($bootmenuentryID))
				$this->_redirect('/user/bootmenu/index/page/'.$this->page.'/json/error');
			
			$bootmenuentry = new Application_Model_BootMenuEntries();
			$bootmenuentryMapper = new Application_Model_BootMenuEntriesMapper();
			
			$bootmenuentryMapper->find($bootmenuentryID, $bootmenuentry);
			
			$n = new Pbs_Session();
			
			$session->setBootosID($bootmenuentry->getBootosID())
			->setBootmenuentryID($bootmenuentry->getID())
			->setTime(time())
			->setIp($_SERVER['REMOTE_ADDR']);
			
		    $this->thisSession = $n->createSession($session);
		}
			
	}

	public function indexAction()
	{
		 
		 
	}

	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("./"));
			
			passthru( "cat ".$initname);
		}
	}

	public function getconfigAction()
	{
		$bootmenuentryID = $this->thisSession->getBootmenuentryID();

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

	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("./"));
			
			passthru( "cat ". $kernelname);
		}
	}

	public function getkclAction()
	{
		$bmeID = $this->thisSession->getBootmenuentryID();

		if(is_numeric($bmeID)){
			
			$bmemapper = new Application_Model_BootMenuEntriesMapper();
			$bme = new Application_Model_BootMenuEntries();
			$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');
			
			if($bme->getKcl() != null)
				$result = $bme->getKcl() . " alpha=" . $this->_request->getParam('alpha') . " " . $bme->getKclappend();
			else 
				$result = " alpha=" . $this->_request->getParam('alpha') . " " .$bme->getKclappend();
			
			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

		header('Content-Type: application/json');
		$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->thisSession->getAlphasessionID()
		);
		
		
		$this->_redirect('/user/bootmenu/index/page/'.$this->page.'/json/'.json_encode($return_val));	 
		

	}

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

}