diff options
Diffstat (limited to 'application/modules/bootloader/controllers/EnvController.php')
-rw-r--r-- | application/modules/bootloader/controllers/EnvController.php | 218 |
1 files changed, 218 insertions, 0 deletions
diff --git a/application/modules/bootloader/controllers/EnvController.php b/application/modules/bootloader/controllers/EnvController.php new file mode 100644 index 0000000..aba575b --- /dev/null +++ b/application/modules/bootloader/controllers/EnvController.php @@ -0,0 +1,218 @@ +<?php + +class Bootloader_EnvController extends Zend_Controller_Action +{ + + private $_mmenus; + private $_mmenu_entries; + private $_mmenu_assignments; + private $_mmenu_assignment_iprules; + private $_mmenu_assignment_bmrules; + + + public function init() + { + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + + } + + public function indexAction() + { + } + + function _ip_netmask_check ($ip, $net, $mask) { + + if (empty($net) OR empty($mask)) return false; + + $ip_net = ip2long ($net); + $ip_mask = ~((1 << (32 - $mask)) - 1); + + $ip_ip = ip2long ($ip); + + $ip_ip_net = $ip_ip & $ip_mask; + + return ($ip_ip_net == $ip_net); + } + + public function getmenuAction() { + + $mid = $this->getRequest()->getParam('formedia'); + + $this->_mmenus = new Model_Menus(); + $this->_mmenu_entries = new Model_Menuentries(); + $this->_mmenu_assignments = new Model_Menuassignments(); + $this->_mmenu_assignment_iprules = new Model_Menuassignmentip(); + $this->_mmenu_assignment_bmrules = new Model_Menuassignmentbm(); + + $s = $this->_mmenu_assignments->select(Zend_Db_Table::SELECT_WITH_FROM_PART); + $s->setIntegrityCheck(false) + ->joinLeft(array('m' => 'menus'), 'm.id = menu_assignments.menu_id', + array('m_name' => 'name')) + ->joinLeft(array('i' => 'menu_assignment_iprules'), 'i.menu_assignment_rule = menu_assignments.id', + array('i_ip' => 'ip', + 'i_netmask' => 'netmask')) + ->joinLeft(array('b' => 'menu_assignment_bmrules'), 'b.menu_assignment_rule = menu_assignments.id', + array('b_bootmedia_id' => 'bootmedia_id')) + ->joinLeft(array('bm' => 'bootmedia'), 'bm.id = b.bootmedia_id', + array('b_name' => 'name', + 'b_identifier' => 'identifier')) + ->order(array('menu_id', 'i_netmask', 'b_bootmedia')); + $data = $this->_mmenu_assignments->fetchAll($s)->toArray(); + + foreach ($data as $d) { + if ($this->_ip_netmask_check($_SERVER['REMOTE_ADDR'], $d['i_ip'], $d['i_netmask'])) { + if ($pbs_id == $d['b_identifier']) $r[4][] = $d['menu_id']; + else $r[3][] = $d['menu_id']; + } else { + if ($pbs_id == $d['b_identifier']) $r[2][] = $d['menu_id']; + else $r[1][] = $d['menu_id']; + } + } + + for ($i = 4; $i>0; $i--) { + if (!empty($r[$i])) { + $r = array_shift($r[$i]); + break; + } + } + + $s = $this->_mmenu_entries->select(Zend_Db_Table::SELECT_WITH_FROM_PART); + $s->setIntegrityCheck(false) + ->where('menu_id = ?', $r) + ->joinLeft(array('s' => 'systems'), 's.id = menu_entries.system_id', + array('s_name' => 'name', + 's_append' => 'append', + 's_external_id' => 'external_id', + 's_source' => 'source')) + ->order('entry_order'); + $data = $this->_mmenu_entries->fetchAll($s)->toArray(); + + + $r = array(); + $c = 1; + $mapping = "\n case $(cat result) in "; + foreach ($data as $d) { + $r[] = "$c \"" . (($d['overwrite_caption'] == 1)? $d['alternative_caption'] : $d['s_name']) . "\""; + $m = "\n %s)"; + $m .= "\n echo \"systemid=%s\" >> /tmp/boot"; + $m .= "\n echo \"systemname=\\\"%s\\\"\" >> /tmp/boot"; + $m .= "\n echo \"sysname=%s\" >> /tmp/boot"; + $m .= "\n echo \"syssource=%s\" >> /tmp/boot"; + $m .= "\n echo \"append=%s\" >> /tmp/boot"; + $m .= "\n ;;"; + $mapping .= sprintf($m, + $c, + $d['id'], + (($d['overwrite_caption'] == 1)? $d['alternative_caption'] : $d['s_name']), + $d['s_external_id'], + $d['s_source'], + (($d['overwrite_append'] == 1)? $d['alternative_append'] : $d['s_append']) + ); + $c++; + } + $mapping .= "\n esac"; + + $entryCount = count($r); + $entries = implode(" ", $r); + + $v = $this->view; + $v->bootmenu = "$entryCount $entries"; + $v->bootmenu_mapping = $mapping; + echo $v->render('env/bootmenu.dialog'); + } + + public function getinitAction() { + + $mid = $this->getRequest()->getParam('formedia'); + + $v = $this->view; + #$v->dialog = "/bin/sh"; + echo $v->render('env/prebootInit.sh'); + } + + public function getkernelAction() { + $sid = $this->getRequest()->getParam('forsystem'); + $s = new Model_Systems(); + + $d = $s->find($sid)->toArray(); + $d = $d[0]; + + + $cmd = "atftp %s -g -r %s -l /tmp/vmlinuz"; + $cmd = sprintf($cmd, $d['source'], $d['kernel']); + + $output = array(); + $returnval = null; + exec($cmd, $output, $returnval); + + $file = "/tmp/vmlinuz"; + + header("Content-Type: application/octet-stream"); + header("Content-Transfer-Encoding: binary"); + header("Content-Length: " . (string)filesize($file)); + header('Content-Disposition: attachment; filename="vmlinuz"'); + + readfile($file); + } + + public function getinitramfsAction() { + $sid = $this->getRequest()->getParam('forsystem'); + $s = new Model_Systems(); + + $d = $s->find($sid)->toArray(); + $d = $d[0]; + + $cmd = "atftp %s -g -r %s -l /tmp/initramfs"; + $cmd = sprintf($cmd, $d['source'], $d['initrd']); + + $output = array(); + $returnval = null; + exec($cmd, $output, $returnval); + + $file = "/tmp/initramfs"; + + header("Content-Type: application/octet-stream"); + header("Content-Transfer-Encoding: binary"); + header("Content-Length: " . (string)filesize($file)); + header('Content-Disposition: attachment; filename="initramfs"'); + + readfile($file); + } + + public function getccAction() { + $sid = $this->getRequest()->getParam('forsystem'); + $s = new Model_Systems(); + + $d = $s->find($sid)->toArray(); + $d = $d[0]; + + $file = "/tmp/initramfs.".mktime(); + + $cmd = "atftp %s -g -r %s -l $file"; + $cmd = sprintf($cmd, $d['source'], $d['external_id']); + + $output = array(); + $returnval = null; + exec($cmd, $output, $returnval); + + + header("Content-Type: application/octet-stream"); + header("Content-Transfer-Encoding: binary"); + header("Content-Length: " . (string)filesize($file)); + header('Content-Disposition: attachment; filename="initramfs"'); + + readfile($file); + } + + public function __call($a, $b) + { + var_dump($a,$b); + } + + + +} + + + |