summaryrefslogtreecommitdiffstats
path: root/application/modules/ipxe/controllers/AuthController.php
diff options
context:
space:
mode:
Diffstat (limited to 'application/modules/ipxe/controllers/AuthController.php')
-rw-r--r--application/modules/ipxe/controllers/AuthController.php219
1 files changed, 157 insertions, 62 deletions
diff --git a/application/modules/ipxe/controllers/AuthController.php b/application/modules/ipxe/controllers/AuthController.php
index 1e2a179..1fdaead 100644
--- a/application/modules/ipxe/controllers/AuthController.php
+++ b/application/modules/ipxe/controllers/AuthController.php
@@ -12,22 +12,30 @@
class Ipxe_AuthController extends Zend_Controller_Action
{
- protected $membership;
-
+ protected $session;
+ protected $sessionMapper;
+ protected $error;
+
public function init()
{
$this->_helper->layout->disableLayout();
$this->_helper->viewRenderer->setNoRender();
$this->db = Zend_Db_Table::getDefaultAdapter();
- }
+ $this->session = new Application_Model_Session();
+ $this->sessionMapper = new Application_Model_SessionMapper();
- public function errorAction()
- {
- $result = $this->_request->getParam('serialresult');
- if($result != ""){
- $pbsNotifier = new Pbs_Notifier();
- echo $pbsNotifier->notify('serial',$result);
+ $alphaID = $this->_request->getParam('alpha');
+
+ if(isset($alphaID)){
+ $alphasessionID = $alphaID;
+ $result = $this->sessionMapper->findBy(array('alphasessionID' => $alphasessionID),true);
+ if(isset($result)){
+ $this->session = $this->session->setOptions($result[0]);
+ $this->session->setID($result[0]['sessionID']);
+ }else{
+ $this->error = "session";
+ }
}
}
@@ -35,62 +43,55 @@ class Ipxe_AuthController extends Zend_Controller_Action
{
$serialnumber = $this->_request->getParam('serialnumber');
$mac = $this->_request->getParam('mac');
- $login = $this->_request->getParam('login') == 'true';
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();
-
- $session = new Application_Model_Session();
- $session->setBootisoID($bootiso->getID());
- $session->setClientID($clientID);
- $session->setTime(time());
- $session->setIp($_SERVER['REMOTE_ADDR']);
- $session = $n->createSession($session);
- header('Content-Type: text/plain');
-
- $result = "#!ipxe\n";
- $result .= "imgfree\n";
- if(!$login){
- $result .= "login\n";
- $result .= "chain http://".$_SERVER['HTTP_HOST']."/ipxe/vesamenu.c32 http://\${username:uristring}:\${password:uristring}@".$_SERVER['HTTP_HOST']."/ipxe/auth/login/alpha/".$session->getAlphasessionID()."/login/true\n";
+ if(isset($results)){
+ $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();
+
+ $this->session->setBootisoID($bootiso->getID());
+ $this->session->setClientID($clientID);
+ $this->session->setTime(time());
+ $this->session->setIp($_SERVER['REMOTE_ADDR']);
+ $this->session = $n->createSession($this->session);
}else{
- $result .= "chain http://".$_SERVER['HTTP_HOST']."/ipxe/vesamenu.c32 http://".$_SERVER['HTTP_HOST']."/ipxe/resource/getvesamenuconfig/alpha/".$session->getAlphasessionID()."/login/false\n";
+ $this->error = "serial";
}
-
-
- header("Content-Length: ".(strlen($result)));
-
- echo $result;
-
}
else{
-
- $this->_redirect('/ipxe/auth/error/serialresult/noserial');
+ $this->error = "serial";
}
+
+ header('Content-Type: text/plain');
+
+ $result = "#!ipxe\n";
+ $result .= "imgfree\n";
+ if(isset($this->session)){
+ $result .= "chain http://".$_SERVER['HTTP_HOST']."/ipxe/vesamenu.c32 http://".$_SERVER['HTTP_HOST']."/ipxe/resource/getvesamenuconfig/alpha/".$this->session->getAlphasessionID()."/error/$this->error\n";
+ }else{
+ $result .= "chain http://".$_SERVER['HTTP_HOST']."/ipxe/vesamenu.c32 http://".$_SERVER['HTTP_HOST']."/ipxe/resource/getvesamenuconfig/serialnumer/$serialnumber/mac/$mac/error/$this->error\n";
+ }
+ header("Content-Length: ".(strlen($result)));
+ echo $result;
}
-
+
public function loginAction()
{
$alpha = $this->_request->getParam('alpha');
@@ -98,6 +99,12 @@ class Ipxe_AuthController extends Zend_Controller_Action
if(!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW'])){
header('WWW-Authenticate: Basic realm=""');
header('HTTP/1.0 401 Unauthorized');
+ header('Content-Type: text/plain');
+ $result = "#!ipxe\n";
+ $result .= "imgfree\n";
+ $result .= "login\n";
+ $result .= "chain http://".$_SERVER['HTTP_HOST']."/ipxe/vesamenu.c32 http://\${username:uristring}:\${password:uristring}@".$_SERVER['HTTP_HOST']."/ipxe/auth/login/alpha/".$alpha."\n";
+ header("Content-Length: ".(strlen($result)));
exit;
}
@@ -111,21 +118,109 @@ class Ipxe_AuthController extends Zend_Controller_Action
$result = $auth->authenticate($adapter);
- if ($result->isValid()) {
- $personmapper = new Application_Model_PersonMapper();
- $result = $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());
- $personmapper->save($person);
-
- $this->_redirect("/ipxe/resource/getvesamenuconfig/alpha/".$alpha."/person/".$person->getID()."/login/true");
- return;
- } else {
- echo "Wrong Email or Password.";
- }
+ if (isset($this->session)){
+ if ($result->isValid()) {
+
+ $personmapper = new Application_Model_PersonMapper();
+ $result = $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());
+ $personmapper->save($person);
+
+ $this->session->setPersonID($person->getID());
+ $this->sessionMapper->save($this->session);
+
+ } else {
+ $this->error = "login";
+ }
+ }else{
+ $this->error = "session";
+ }
+
+ header('Content-Type: text/plain');
+
+ $result = "#!ipxe\n";
+ $result .= "imgfree\n";
+ $result .= "chain http://".$_SERVER['HTTP_HOST']."/ipxe/vesamenu.c32 http://".$_SERVER['HTTP_HOST']."/ipxe/resource/getvesamenuconfig/alpha/".$alpha."/error/$this->error\n";
+
+ header("Content-Length: ".(strlen($result)));
+
+ echo $result;
}
+
+ public function logoutAction(){
+
+ $alpha = $this->_request->getParam('alpha');
+
+ if (isset($this->session)){
+ $this->session->setPersonID(null);
+ $this->session->setMembershipID(null);
+ $this->sessionMapper->save($this->session);
+ }else{
+ $this->error = "session";
+ }
+
+ header('Content-Type: text/plain');
+
+ $result = "#!ipxe\n";
+ $result .= "imgfree\n";
+ $result .= "chain http://".$_SERVER['HTTP_HOST']."/ipxe/vesamenu.c32 http://".$_SERVER['HTTP_HOST']."/ipxe/resource/getvesamenuconfig/alpha/".$alpha."/error/$this->error\n";
+ header("Content-Length: ".(strlen($result)));
+
+ echo $result;
+ }
+
+ public function switchgroupAction(){
+
+ $alpha = $this->_request->getParam('alpha');
+
+ if (isset($this->session)){
+ $this->session->setMembershipID(null);
+ $this->sessionMapper->save($this->session);
+ }else{
+ $this->error = "session";
+ }
+
+ header('Content-Type: text/plain');
+
+ $result = "#!ipxe\n";
+ $result .= "imgfree\n";
+ $result .= "chain http://".$_SERVER['HTTP_HOST']."/ipxe/vesamenu.c32 http://".$_SERVER['HTTP_HOST']."/ipxe/resource/getvesamenuconfig/alpha/".$alpha."/error/$this->error\n";
+
+ header("Content-Length: ".(strlen($result)));
+
+ echo $result;
+ }
+
+ public function setgroupAction(){
+
+ $alpha = $this->_request->getParam('alpha');
+ $membershipID = $this->_request->getParam('membershipid');
+
+ //TODO test if member of group
+ if (isset($this->session)){
+ $this->session->setMembershipID($membershipID);
+ $this->sessionMapper->save($this->session);
+ }else{
+ $this->error = "session";
+ }
+
+ header('Content-Type: text/plain');
+
+ $result = "#!ipxe\n";
+ $result .= "imgfree\n";
+ $result .= "chain http://".$_SERVER['HTTP_HOST']."/ipxe/vesamenu.c32 http://".$_SERVER['HTTP_HOST']."/ipxe/resource/getvesamenuconfig/alpha/".$alpha."/error/$this->error\n";
+
+ header("Content-Length: ".(strlen($result)));
+
+ echo $result;
+ }
+
+
+
+
}