diff options
author | michael pereira | 2011-07-11 00:51:43 +0200 |
---|---|---|
committer | michael pereira | 2011-07-11 00:51:43 +0200 |
commit | e01348134e7d44de9471c4d76659cab41a6c9952 (patch) | |
tree | bba0e9343e6b7ed80fd57b7623fef01ae481357f | |
parent | Session fuer ipxe (diff) | |
download | pbs2-e01348134e7d44de9471c4d76659cab41a6c9952.tar.gz pbs2-e01348134e7d44de9471c4d76659cab41a6c9952.tar.xz pbs2-e01348134e7d44de9471c4d76659cab41a6c9952.zip |
Session und Filter fuer ipxe Bootmenu
-rw-r--r-- | application/controllers/ResourceController.php | 51 | ||||
-rw-r--r-- | application/modules/ipxe/controllers/AuthController.php | 124 | ||||
-rw-r--r-- | application/modules/ipxe/controllers/ResourceController.php | 124 | ||||
-rw-r--r-- | application/modules/ipxe/views/scripts/resource/getvesamenu.phtml | 157 | ||||
-rw-r--r-- | library/Pbs/Filter.php | 2 | ||||
-rw-r--r-- | library/Pbs/Session.php | 6 |
6 files changed, 345 insertions, 119 deletions
diff --git a/application/controllers/ResourceController.php b/application/controllers/ResourceController.php index b81403f..c1eaa65 100644 --- a/application/controllers/ResourceController.php +++ b/application/controllers/ResourceController.php @@ -574,59 +574,8 @@ class ResourceController extends Zend_Controller_Action $path = "http://" . $_SERVER['SERVER_NAME'] . $path; return $path; } - - public function getvesamenuAction(){ - if(is_dir("../resources/ipxe/")){ - header('Content-Type: application/octet-stream'); - $content_disp = ( ereg('MSIE ([0-9].[0-9]{1,2})', $_SERVER['HTTP_USER_AGENT']) == 'IE') ? 'inline' : 'attachment'; - header('Content-Disposition: ' . $content_disp . '; filename="vesamenu.c32"'); - header('Pragma: no-cache'); - header('Expires: 0'); - chdir("../resources/ipxe/"); - - header("Content-Length: ".filesize(getcwd()."/vesamenu.c32")); - - passthru( "cat vesamenu.c32"); - }else{ - header('HTTP/1.0 404 Not Found'); - } - - } - - public function getvesamenuconfigAction(){ - - 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="vesamenu.conf"'); - header('Pragma: no-cache'); - header('Expires: 0'); - - $vesamenuView = new Zend_View(); - $vesamenuView->addScriptPath(APPLICATION_PATH.'/views/scripts/resource/'); - $vesamenuView->host = $_SERVER['HTTP_HOST']; - $vesamenu = $vesamenuView->render('getvesamenu.phtml'); - - header("Content-Length: ".(strlen($vesamenu))); - - echo $vesamenu; - } - - public function ipxeAction(){ - - header('Content-Type: text/plain'); - - $result = "#!ipxe\n"; - $result .= "imgfree\n"; - - $result .= "chain http://".$_SERVER['HTTP_HOST']."/resource/getvesamenu http://".$_SERVER['HTTP_HOST']."/resource/getvesamenuconfig"; - - header("Content-Length: ".(strlen($result))); - - echo $result; - - } } diff --git a/application/modules/ipxe/controllers/AuthController.php b/application/modules/ipxe/controllers/AuthController.php index c553566..d3c5ca0 100644 --- a/application/modules/ipxe/controllers/AuthController.php +++ b/application/modules/ipxe/controllers/AuthController.php @@ -12,80 +12,76 @@ class Ipxe_AuthController extends Zend_Controller_Action { + protected $membership; public function init() { - $this->db = Zend_Db_Table::getDefaultAdapter(); - $this->personmapper = new Application_Model_PersonMapper(); - } + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); - public function indexAction() - { - $this->_helper-> viewRenderer-> setNoRender(); - $this->_helper->redirector('login', 'auth'); } - public function loginAction() + public function errorAction() { - if (Zend_Auth::getInstance()->hasIdentity()) { - $this->_redirect('/fbgui/'); - } else { - if (!isset($_POST["login"])){ - $loginForm = new fbgui_Form_Login(); - } else { - $loginForm = new fbgui_Form_Login($_POST); - - if ($loginForm->isValid($_POST)) { - - $auth = Zend_Auth::getInstance(); - - $adapter = new Zend_Auth_Adapter_DbTable($this->db, 'pbs_person', 'email', 'password', 'MD5(CONCAT(?, password_salt))'); - - - $adapter->setIdentity($loginForm->getValue('email')); - $adapter->setCredential($loginForm->getValue('password')); - - $result = $auth->authenticate($adapter); - - // TODO: erweiterte fehlerbeschreibung des Users - - if ($result->isValid()) { - $this->personmapper = new Application_Model_PersonMapper(); - $result = $this->personmapper->findBy(array('email' => Zend_Auth::getInstance()->getIdentity()),true); - $person = new Application_Model_Person($result[0]); - $person->setID($result[0]['personID']); - $date = new DateTime(); - $person->setLogindate($date->getTimestamp()); - $this->personmapper->save($person); - $this->_helper->redirector('selectmembership', 'person'); - return; - } else { - echo "Wrong Email or Password."; - } - } - } - $this->view->loginForm = $loginForm; + $result = $this->_request->getParam('serialresult'); + if($result != ""){ + $pbsNotifier = new Pbs_Notifier(); + echo $pbsNotifier->notify('serial',$result); } } - public function logoutAction() + public function serialAction() { - $this->_helper-> viewRenderer-> setNoRender(); - $auth = Zend_Auth::getInstance(); - $auth->clearIdentity(); - Zend_Session::namespaceUnset('userIDs'); - Zend_Session::forgetMe(); - $this->_redirect('/fbgui/index'); -# $this->_helper->redirector('fbgui', 'index'); - return; + $serialnumber = $this->_request->getParam('serialnumber'); + $mac = $this->_request->getParam('mac'); + + if(isset($serialnumber)){ + // Create a session + + $n = new Pbs_Session(); + + $bootisomapper = new Application_Model_BootIsoMapper(); + $bootiso = new Application_Model_BootIso(); + + $results = $bootisomapper->findBy(array('serialnumber' => $serialnumber),true); + if(count($results) == 0){ + $this->_redirect('/ipxe/auth/error/serialresult/noserial'); + } + $bootiso->setOptions($results[0]); + $bootiso->setID($results[0]['bootisoID']); + $groupID = $bootiso->getGroupID(); + + $client = new Application_Model_Client(); + $client->setGroupID($groupID); + $client->setMacadress($mac); + $client->setCreated(time()); + $client = $n->createClient($client); + $clientID = $client->getID(); + + if(!isset($_SESSION['alphasessionID'])){ + $session = new Application_Model_Session(); + $session->setBootisoID($bootiso->getID()); + $session->setClientID($clientID); + $session->setTime(time()); + $session->setIp($_SERVER['REMOTE_ADDR']); + $session = $n->createSession($session); + $_SESSION['alphasessionID'] = $session->getAlphasessionID(); + } + else{ + $session = new Application_Model_Session(); + $sessionMapper = new Application_Model_SessionMapper(); + $sessions = $sessionMapper->findBy(array('alphasessionID'=>$_SESSION['alphasessionID'])); + $session = $sessions[0]; + } + + $this->_redirect('/ipxe/resource/ipxe/alpha/'.$session->getAlphasessionID()); + + } + else{ + + $this->_redirect('/ipxe/auth/error/serialresult/noserial'); + } + } + } - - - - - - - - - diff --git a/application/modules/ipxe/controllers/ResourceController.php b/application/modules/ipxe/controllers/ResourceController.php new file mode 100644 index 0000000..0d1428a --- /dev/null +++ b/application/modules/ipxe/controllers/ResourceController.php @@ -0,0 +1,124 @@ +<?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 Ipxe_ResourceController extends Zend_Controller_Action +{ + + private $thisSession; + + public function init() + { + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + + $session = new Application_Model_Session(); + $sm = new Application_Model_SessionMapper(); + + //TODO Error Messages if something failed + $alphaID = $this->_request->getParam('alpha'); + + if($alphaID != ""){ + $alphasessionID = $alphaID; + $result = $sm->findBy(array('alphasessionID' => $alphasessionID),true); + # print_a($result); + $this->thisSession = $session->setOptions($result[0]); + $this->thisSession->setID($result[0]['sessionID']); + } + + } + + public function getvesamenuAction(){ + if(is_dir("../resources/ipxe/")){ + + header('Content-Type: application/octet-stream'); + $content_disp = ( ereg('MSIE ([0-9].[0-9]{1,2})', $_SERVER['HTTP_USER_AGENT']) == 'IE') ? 'inline' : 'attachment'; + header('Content-Disposition: ' . $content_disp . '; filename="vesamenu.c32"'); + header('Pragma: no-cache'); + header('Expires: 0'); + + chdir("../resources/ipxe/"); + + header("Content-Length: ".filesize(getcwd()."/vesamenu.c32")); + + passthru( "cat vesamenu.c32"); + }else{ + header('HTTP/1.0 404 Not Found'); + } + + } + + public function getvesamenuconfigAction(){ + + 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="vesamenu.conf"'); + header('Pragma: no-cache'); + header('Expires: 0'); + + $vesamenuView = new Zend_View(); + $vesamenuView->addScriptPath(APPLICATION_PATH.'/modules/ipxe/views/scripts/resource/'); + $vesamenuView->host = $_SERVER['HTTP_HOST']; + + // Request Bootmenu + $pbsFilter = new Pbs_Filter(); + $bootmenuID = $pbsFilter->evaluate(); + + if($bootmenuID != null){ + $vesamenuView->alphaID = $this->thisSession->getAlphasessionID(); + + $bootmenuMapper = new Application_Model_BootMenuMapper(); + $bm = $bootmenuMapper->find($bootmenuID); + $vesamenuView->title = $bm->getTitle(); +// $this->view->startcounter = $bm->getStartcounter(); + + $bootmenuentriesMapper = new Application_Model_BootMenuEntriesMapper(); + $res = $bootmenuentriesMapper->findBy(array('bootmenuID' => $bootmenuID),false); + $vesamenuView->bmelist = $res; + + } + else{ + + $vesamenuView->error = "You have no BootMenu."; + } + + $vesamenu = $vesamenuView->render('getvesamenu.phtml'); + + header("Content-Length: ".(strlen($vesamenu))); + + echo $vesamenu; + } + + public function ipxeAction(){ + + header('Content-Type: text/plain'); + + $result = "#!ipxe\n"; + $result .= "imgfree\n"; + + $result .= "chain http://".$_SERVER['HTTP_HOST']."/ipxe/resource/getvesamenu/alpha/".$this->thisSession->getAlphasessionID()." http://".$_SERVER['HTTP_HOST']."/ipxe/resource/getvesamenuconfig/alpha/".$this->thisSession->getAlphasessionID(); + + header("Content-Length: ".(strlen($result))); + + echo $result; + + } + + + +} + + + + + + + diff --git a/application/modules/ipxe/views/scripts/resource/getvesamenu.phtml b/application/modules/ipxe/views/scripts/resource/getvesamenu.phtml new file mode 100644 index 0000000..cb440cb --- /dev/null +++ b/application/modules/ipxe/views/scripts/resource/getvesamenu.phtml @@ -0,0 +1,157 @@ +<?php + +// $username = $_SERVER["PHP_AUTH_USER"]; +// $password = $_SERVER["PHP_AUTH_PW"]; + + $index = 0; + + function title ( $title ) { + global $username; + echo "menu title ".$title; + echo ( $username ? " for ".$username : "" )."\n"; + } + + function label ( $label ) { + global $index; + $index++; + echo "label item".$index."\n"; + echo " menu label "; + echo "^".( ( $index < 10 ) ? $index : + sprintf ( "%c", $index + ord ( 'A' ) - 10 ) )." "; + echo $label."\n"; + } + + function uriboot ( $label, $uri, $args ) { + label ( $label ); + echo " kernel ".$uri."\n"; + if ( $args ) + echo " append ".$args."\n"; + } + + function localboot () { + label ( "LOCALBOOT"); + echo "LOCALBOOT -1\n"; + texthelp("Gets you out of here by booting from next device in BIOS boot + order."); + } + + function texthelp ( $texthelp ){ + echo "TEXT HELP\n"; + echo $texthelp."\n"; + echo "ENDTEXT\n"; + } + + function retry () { + echo "label failed\n"; + echo " menu label Authentication Failed\n"; + echo " menu disable\n"; + uriboot ( "Try again", "ipxe.php", "" ); + } + + function authenticated () { + global $username; + global $password; + + switch ( "$username:$password" ) { + case "test:test": + case "guest:guest": + return 1; + default: + return 0; + } + } + + ?> +TIMEOUT 100 +PROMPT 0 +DEFAULT vesamenu.c32 + +MENU BACKGROUND http://pbs2.mp.openslx.org/media/img/pbs2.png +MENU WIDTH 78 +MENU MARGIN 9 +MENU PASSWORDMARGIN 9 +MENU ROWS 10 +MENU TABMSGROW 16 +MENU CMDLINEROW 16 +MENU ENDROW -1 +MENU PASSWORDROW 16 +MENU TIMEOUTROW 20 +MENU HELPMSGROW 16 +MENU HELPMSGENDROW -1 +MENU HSHIFT 0 +MENU VSHIFT 7 + +#menu color screen 37;40 #80ffffff #00000000 std +menu color border 37;40 #00000000 #00000000 std +menu color title 1 #ee004a99 #00000000 all +menu color unsel 37;40 #ff4f75aa #00000000 all +menu color hotkey 1;37;40 #ffff8b00 #ff8093a1 std +menu color sel 7;37;40 #ff1c2a33 #667799bb all +#menu color hotsel 1;7;37;40 #ffff8b00 #667799bb all +#menu color disabled 1;37;40 #ffff8b00 #ff8093a1 std +#menu color scrollbar 37;40 #40000000 #ee000000 std +#menu color tabmsg 37;40 #ffff8b00 #ff8093a1 std +#menu color cmdmark 1;37;40 #ffff8b00 #ff8093a1 std +#menu color cmdline 37;40 #fff0f0f0 #ff8093a1 std +#menu color pwdborder 37;40 #40000000 #ff8093a1 std +#menu color pwdheader 37;40 #ffff8b00 #ff8093a1 std +#menu color pwdentry 37;40 #ffff8b00 #ff8093a1 std +#menu color timeout_msg 37;40 #fff0f0f0 #ff8093a1 std +#menu color timeout 1;37;40 #ffff8b00 #ff8093a1 std +#menu color help 37;40 #ff1c2a33 #00000000 none +MENU MSGCOLOR #ff1c2a33 #00000000 none + +<? + if(!isset($this->error)) + title ( $this->title ); + else + title($this->error); +// +// if ( ! authenticated() ) { +// retry(); +// } else { +// +// if ( $username == "test" ) { +// +// localboot(); +// } + +$bootosmapper = new Application_Model_BootOsMapper(); + +if(isset($this->bmelist)){ + foreach($this->bmelist as $bme){ + + $kcl = $bootosmapper->find($bme->getBootosID())->getDefaultkcl(); + + if($bme->getKcl() && $kcl != null){ + uriboot ( $bme->getTitle(), + "http://$this->host/resource/getkernel/alpha/$this->alphaID/file/kernel", "initrd=http://$this->host/resource/getinitramfs/alpha/$this->alphaID/file/initramfs $kcl alpha=$this->alphaID file=http://$this->host/c/$this->alphaID/default.tgz ".$bme->getKclappend()); + }else{ + uriboot ( $bme->getTitle(), + "http://$this->host/resource/getkernel/alpha/$this->alphaID/file/kernel", "initrd=http://$this->host/resource/getinitramfs/alpha/$this->alphaID/file/initramfs alpha=$this->alphaID file=http://$this->host/c/$this->alphaID/default.tgz ".$bme->getKclappend()); + } + } +} + +localboot(); +// } + +// LABEL SLXSTDBOOT +// MENU LABEL +// KERNEL kernel +// APPEND initrd=init vga=0x317 +// TEXT HELP +// Use this (default) entry if you have configured your client. +// You have chance to edit the kernel commandline by hitting the +// TAB key (e.g. for adding debug=3 to it for bug hunting) ... +// ENDTEXT +//LABEL DEBUGBOOT +// MENU LABEL OpenSLX PreBoot - Debug Mode +// KERNEL kernel +// APPEND initrd=init vga=0x317 debug=3 +// TEXT HELP +// Use this to start the preboot environment with debug shells. +// ENDTEXT + + + ?>
\ No newline at end of file diff --git a/library/Pbs/Filter.php b/library/Pbs/Filter.php index 9cbd0ba..5b8e53b 100644 --- a/library/Pbs/Filter.php +++ b/library/Pbs/Filter.php @@ -60,7 +60,7 @@ class Pbs_Filter{ $session->setOptions($sessionarray[0]); @$session->setID($sessionarray['sessionID']); - $bootisoMapper = new Application_Model_BootisoMapper(); + $bootisoMapper = new Application_Model_BootIsoMapper(); $bootiso = new Application_Model_BootIso(); $bootisoMapper->find($session->getBootisoID(),$bootiso); $groupID = $bootiso->getGroupID(); diff --git a/library/Pbs/Session.php b/library/Pbs/Session.php index 7686077..12e6738 100644 --- a/library/Pbs/Session.php +++ b/library/Pbs/Session.php @@ -12,16 +12,16 @@ class Pbs_Session{ - public function CreateSession(Application_Model_Session $session){ + public function createSession(Application_Model_Session $session){ $sessionmapper = new Application_Model_SessionMapper(); - $uniqid = $this->getUniqueCode(10); $sm = new Application_Model_SessionMapper(); while(count($sm->findBy(array('alphasessionID' => $uniqid),true))>0){ $uniqid = $this->getUniqueCode(16); } - $session->setAlphasessionID($uniqid); + $session->setAlphasessionID($uniqid); + $id = $sessionmapper->save($session); $sessionmapper->find($id, $session); return $session; |