summaryrefslogtreecommitdiffstats
path: root/application/modules/bootloader
diff options
context:
space:
mode:
authorOpenSLX2010-01-20 16:47:35 +0100
committerOpenSLX2010-01-20 16:47:35 +0100
commit04173263974af0e7a354e066b9d7ec9c13c4289d (patch)
tree82dc2e2662d24e0aaba8a16c4c90b3819c06a662 /application/modules/bootloader
downloadpbs-04173263974af0e7a354e066b9d7ec9c13c4289d.tar.gz
pbs-04173263974af0e7a354e066b9d7ec9c13c4289d.tar.xz
pbs-04173263974af0e7a354e066b9d7ec9c13c4289d.zip
initial import
Diffstat (limited to 'application/modules/bootloader')
-rw-r--r--application/modules/bootloader/controllers/EnvController.php218
-rw-r--r--application/modules/bootloader/controllers/IndexController.php29
-rw-r--r--application/modules/bootloader/views/scripts/env/bootmenu.dialog7
-rw-r--r--application/modules/bootloader/views/scripts/env/prebootInit.sh71
-rw-r--r--application/modules/bootloader/views/scripts/index/index.phtml0
5 files changed, 325 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);
+ }
+
+
+
+}
+
+
+
diff --git a/application/modules/bootloader/controllers/IndexController.php b/application/modules/bootloader/controllers/IndexController.php
new file mode 100644
index 0000000..7a2fcea
--- /dev/null
+++ b/application/modules/bootloader/controllers/IndexController.php
@@ -0,0 +1,29 @@
+<?php
+
+class Bootloader_IndexController extends Zend_Controller_Action
+{
+
+ public function init()
+ {
+ }
+
+ public function indexAction()
+ {
+ }
+
+ public function getinitAction() {
+ echo "#!/bin/sh";
+
+ }
+
+ public function __call()
+ {
+
+ }
+
+
+
+}
+
+
+
diff --git a/application/modules/bootloader/views/scripts/env/bootmenu.dialog b/application/modules/bootloader/views/scripts/env/bootmenu.dialog
new file mode 100644
index 0000000..7cbf43e
--- /dev/null
+++ b/application/modules/bootloader/views/scripts/env/bootmenu.dialog
@@ -0,0 +1,7 @@
+#!/bin/sh
+
+while [ "x$(cat result)" = "x" ] ; do
+ dialog --no-cancel --menu "OpenSLX Boot Menu" 20 65 <?= $this->bootmenu ?> 2>result
+done
+
+<?= $this->bootmenu_mapping ?> \ No newline at end of file
diff --git a/application/modules/bootloader/views/scripts/env/prebootInit.sh b/application/modules/bootloader/views/scripts/env/prebootInit.sh
new file mode 100644
index 0000000..acf8f33
--- /dev/null
+++ b/application/modules/bootloader/views/scripts/env/prebootInit.sh
@@ -0,0 +1,71 @@
+#!/bin/ash
+# Copyright (c) 2009 - OpenSLX GmbH
+#
+# This program is free software distributed under the GPL version 2.
+# See http://openslx.org/COPYING
+#
+# If you have any feedback please consult http://openslx.org/feedback and
+# send your feedback to feedback@openslx.org
+#
+# General information about OpenSLX can be found at http://openslx.org
+#
+# preboot script for user interaction with OpenSLX preloading environment for
+# Linux stateless clients (fetched by Preboot init over the net)
+
+# get configuration
+. /etc/initramfs-setup
+. /etc/pbs.conf
+. ./preboot-scripts/dialog.functions
+
+# bring the mac address into the standard format 01-<MAC>
+client=$(echo 01-$macaddr|sed "s/:/-/g")
+
+# check if already a configuration is available to decide if user interaction
+# is required (path is to be fixed)
+#wget -q -O /tmp/have-user-config "$boot_uri/users.pl?user=${client}"
+#have_user_config=$(cat /tmp/have-user-config);
+
+#if [ "x1" == "x$have_user_config" ]; then
+# wget -q -O /tmp/oldconfig "$boot_uri/users.pl?user=${client}&action=read"
+# . /tmp/oldconfig
+# menu_oldconfig $oldconfig
+#else
+# menu_firststart
+#fi
+#rm result;
+
+# Switch here for several boot TYPE=fastboot/directkiosk/cfgkiosk/slxconfig
+# fastboot - no interaction use system from client config
+# directkiosk - start the default slx system into kiosk (using vmchooser)
+# cfgkiosk - offer the user changes to his kiosk system (GUI environment)
+# slxconfig - offer the user set of configuration options, like setting a non-
+# priviledged user, root password, standard gui, plugins to activate ...
+
+wget -q -O /preboot/bootmenu.dialog ${boot_uri}bootloader/env/getmenu/formedia/$pbs_id
+
+# we expect to have a system selection dialog file in /preboot/bootmenu.dialog
+chmod u+x /preboot/bootmenu.dialog
+/preboot/bootmenu.dialog
+
+. /tmp/boot
+
+
+# fetch kernel and initramfs of selected system
+dialog --infobox "Loading kernel of ${systemname} ..." 3 65
+#ddownload ${boot_uri}bootloader/env/getkernel/forsystem/$systemid "Kernel" /tmp/kernel
+wget -q -O /tmp/kernel ${boot_uri}bootloader/env/getkernel/forsystem/$systemid
+dialog --infobox "Loading initial ramfs of ${systemname} ..." 3 65
+#ddownload ${boot_uri}bootloader/env/getinitramfs/forsystem/$systemid "Initramfs" /tmp/initramfs
+wget -q -O /tmp/initramfs ${boot_uri}bootloader/env/getinitramfs/forsystem/$systemid
+
+# read primary IP configuration to pass it on (behaviour like IPAPPEND=1 of
+# PXElinux)
+. /tmp/ipstuff
+
+[ "x$DEBUGLEVEL" != x0 ] && { clear; ash; }
+
+# start the new kernel with initialramfs and composed cmdline
+dialog --infobox "Booting OpenSLX client $label ... (be patient this could take some time)" 3 69
+kexec -l /tmp/kernel --initrd=/tmp/initramfs \
+ --append="$append file=http://${syssource}/pbs/client-config/${sysname}/pbs.tgz $quiet ip=$ip:$siaddr:$router:$subnet:$dnssrv $debug" 2>/dev/null
+kexec -e >/dev/null 2>&1
diff --git a/application/modules/bootloader/views/scripts/index/index.phtml b/application/modules/bootloader/views/scripts/index/index.phtml
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/application/modules/bootloader/views/scripts/index/index.phtml