From 1c5c739cfb65ef3183a060335aae891e2923e17b Mon Sep 17 00:00:00 2001 From: Björn Geiger Date: Mon, 30 May 2011 16:32:04 +0200 Subject: GetBootOS API Test --- application/controllers/ResourceController.php | 201 ++++++++++++++++--------- 1 file changed, 130 insertions(+), 71 deletions(-) (limited to 'application/controllers/ResourceController.php') diff --git a/application/controllers/ResourceController.php b/application/controllers/ResourceController.php index e67e008..6111bf2 100644 --- a/application/controllers/ResourceController.php +++ b/application/controllers/ResourceController.php @@ -34,13 +34,13 @@ class ResourceController extends Zend_Controller_Action $membershipMapper = new Application_Model_MembershipMapper(); $this->membership = new Application_Model_Membership(); $this->rightrolesMapper = new Application_Model_RightRolesMapper(); - + list($this->membership) = $membershipMapper->findBy(array('apikey' => $apikey)); if($this->membership == null){ header('HTTP/1.0 401 Member not found'); die(); } - + } elseif($alpha == "0"){ $bootmenuentryID = $this->_request->getParam('bootmenuentryID'); @@ -81,10 +81,10 @@ class ResourceController extends Zend_Controller_Action } -//TODO Try/Catch + Metadata check + //TODO Try/Catch + Metadata check public function addbootosAction() { - + list($rightroles) = $this->rightrolesMapper->findBy(array('rightID' => '55', 'roleID' => $this->membership->getRoleID())); if($rightroles == null){ header('HTTP/1.0 403 No Right to Create Bootos'); @@ -99,27 +99,27 @@ class ResourceController extends Zend_Controller_Action $params = $this->_request->getParams(); $source = $_SERVER['REMOTE_ADDR']; - + if($params['title'] == '' || $params['distro'] == '' || $params['distroversion'] == '' || $params['share'] == '' || $source == ''){ header('HTTP/1.0 400 Title, Distro, Distroversion and Share must be set'); die(); } - + if($_FILES['config']['size'] == 0 && $_FILES['config']['name'] != '' || $_FILES['kernel']['size'] == 0 && $_FILES['kernel']['name'] != ''|| $_FILES['init']['size'] == 0 && $_FILES['init']['name'] != ''){ header('HTTP/1.0 400 File must be larger than 0 bytes'); die(); - } + } $bootosMapper = new Application_Model_BootOsMapper(); $groupID = $this->membership->getGroupID(); - + list($bootos) = $bootosMapper->findBy(array('groupid' => $groupID, 'title' => $params['title'], 'distro' => $params['distro'], 'distroversion' => $params['distroversion'], 'source' => $source, 'share' => $params['share'])); if($bootos != null){ header('HTTP/1.0 400 Bootos already exists'); die(); - } + } $bootos = new Application_Model_BootOs(); - + $bootos->setOptions($params); $bootos->setGroupID($groupID); $bootos->setSource($source); @@ -127,7 +127,7 @@ class ResourceController extends Zend_Controller_Action $bootos->setPublic('-1'); $bootosID = $bootosMapper->save($bootos); $bootos->setID($bootosID); - + $initpath = "../resources/bootos/".$bootosID."/initramfs/"; $kernelpath = "../resources/bootos/".$bootosID."/kernel/"; $configpath = "../resources/bootos/".$bootosID."/config/"; @@ -138,7 +138,7 @@ class ResourceController extends Zend_Controller_Action if($_FILES['config']['name'] != ''){ move_uploaded_file($_FILES['config']['tmp_name'], $configpath."default.tgz"); - + } if($_FILES['kernel']['name'] != ''){ move_uploaded_file($_FILES['kernel']['tmp_name'], $kernelpath."kernel"); @@ -152,16 +152,16 @@ class ResourceController extends Zend_Controller_Action header('HTTP/1.0 201 Bootos created'); } - + public function editbootosAction() { - + list($rightroles) = $this->rightrolesMapper->findBy(array('rightID' => '58', 'roleID' => $this->membership->getRoleID())); if($rightroles == null){ header('HTTP/1.0 403 No Right to Edit Bootos'); die(); } - + $apikey = $this->_request->getParam('apikey'); if($apikey == ""){ header('HTTP/1.0 400 No API-Key'); @@ -170,23 +170,23 @@ class ResourceController extends Zend_Controller_Action $params = $this->_request->getParams(); $source = $_SERVER['REMOTE_ADDR']; - + if($params['title'] == '' || $params['distro'] == '' || $params['distroversion'] == '' || $params['share'] == '' || $source == ''){ header('HTTP/1.0 400 Title, Distro, Distroversion and Share must be set'); die(); } - + $bootos = new Application_Model_BootOs(); $bootosMapper = new Application_Model_BootOsMapper(); $groupID = $this->membership->getGroupID(); list($bootos) = $bootosMapper->findBy(array('groupid' => $groupID, 'title' => $params['title'], 'distro' => $params['distro'], 'distroversion' => $params['distroversion'], 'source' => $source, 'share' => $params['share'])); - + if($bootos == null){ header('HTTP/1.0 400 Bootos not found'); die(); - } - + } + $bootosID = $bootos->getID(); $bootossrc = $bootos->getSource(); @@ -196,7 +196,7 @@ class ResourceController extends Zend_Controller_Action $bootos->setSource($bootossrc); $bootos->setCreated(time()); $bootos->setPublic('-1'); - + $initpath = "../resources/bootos/".$bootosID."/initramfs/"; $kernelpath = "../resources/bootos/".$bootosID."/kernel/"; $configpath = "../resources/bootos/".$bootosID."/config/"; @@ -219,19 +219,19 @@ class ResourceController extends Zend_Controller_Action } $bootosMapper->save($bootos); - + header('HTTP/1.0 201 Bootos edited'); } - + public function addprebootAction() { - + list($rightroles) = $this->rightrolesMapper->findBy(array('rightID' => '40', 'roleID' => $this->membership->getRoleID())); if($rightroles == null){ header('HTTP/1.0 403 No Right to Create Preboots'); die(); } - + $apikey = $this->_request->getParam('apikey'); if($apikey == ""){ header('HTTP/1.0 400 No API-Key'); @@ -240,33 +240,33 @@ class ResourceController extends Zend_Controller_Action $params = $this->_request->getParams(); $source = $_SERVER['REMOTE_ADDR']; - + if($params['title'] == '' || $_FILES['preboot']['name'] == ''){ header('HTTP/1.0 400 Title and Preboot must be set'); die(); } - + if($_FILES['preboot']['size'] == 0 && $_FILES['preboot']['name'] != ''){ header('HTTP/1.0 400 File must be larger than 0 bytes'); die(); - } + } $prebootMapper = new Application_Model_PreBootMapper(); $groupID = $this->membership->getGroupID(); - + list($preboot) = $prebootMapper->findBy(array('groupid' => $groupID, 'title' => $params['title'])); if($preboot != null){ header('HTTP/1.0 400 Preboot already exists'); die(); } - + $preboot = new Application_Model_PreBoot(); - + $preboot->setOptions($params); $preboot->setGroupID($groupID); $preboot->setSource($source); $preboot->setCreated(time()); - + $prebootID = $prebootMapper->save($preboot); $prebootpath = "../resources/bootmedium/".$prebootID."/"; @@ -277,19 +277,19 @@ class ResourceController extends Zend_Controller_Action } header('HTTP/1.0 201 Preboot created'); - - + + } - + public function editprebootAction() { - + list($rightroles) = $this->rightrolesMapper->findBy(array('rightID' => '41', 'roleID' => $this->membership->getRoleID())); if($rightroles == null){ header('HTTP/1.0 403 No Right to Edit Preboot'); die(); } - + $apikey = $this->_request->getParam('apikey'); if($apikey == ""){ header('HTTP/1.0 400 No API-Key'); @@ -298,28 +298,28 @@ class ResourceController extends Zend_Controller_Action $params = $this->_request->getParams(); $source = $_SERVER['REMOTE_ADDR']; - + if($params['title'] == ''){ header('HTTP/1.0 400 Title must be set'); die(); } - + if($_FILES['preboot']['size'] == 0 && $_FILES['preboot']['name'] != ''){ header('HTTP/1.0 400 File must be larger than 0 bytes'); die(); - } - + } + $prebootMapper = new Application_Model_PreBootMapper(); $groupID = $this->membership->getGroupID(); $preboot = new Application_Model_PreBoot(); list($preboot) = $prebootMapper->findBy(array('groupid' => $groupID, 'title' => $params['title'])); - + if($preboot == null){ header('HTTP/1.0 400 Preboot not found'); die(); - } - + } + $prebootsrc = $preboot->getSource(); $prebootID = $preboot->getID(); @@ -327,19 +327,19 @@ class ResourceController extends Zend_Controller_Action $preboot->setGroupID($groupID); $preboot->setSource($prebootsrc); $preboot->setCreated(time()); - + $prebootpath = "../resources/bootmedium/".$prebootID."/"; mkdir($prebootpath ,0777, true); if($_FILES['preboot']['name'] != ''){ - $preboot->setSource($source); + $preboot->setSource($source); move_uploaded_file($_FILES['preboot']['tmp_name'], $prebootpath."preboot.zip"); } - + $prebootMapper->save($preboot); header('HTTP/1.0 201 Preboot edited'); - + } public function getinitramfsAction() @@ -368,7 +368,7 @@ class ResourceController extends Zend_Controller_Action } public function getconfigAction() - { + { $bootmenuentryID = $this->thisSession->getBootmenuentryID(); $bootmenuentry = new Application_Model_BootMenuEntries(); $bmm = new Application_Model_BootMenuEntriesMapper(); @@ -391,7 +391,7 @@ class ResourceController extends Zend_Controller_Action }else{ $bootosuserMapper = new Application_Model_BootOsUserMapper(); $bootosuser = $bootosuserMapper->findBy(array('configID' => $configID)); - + $hash = md5(microtime(1)); $tmp_conf = "../resources/config/$hash"; mkdir($tmp_conf ,0777, true); @@ -400,7 +400,7 @@ class ResourceController extends Zend_Controller_Action $username = ''; $userpassword = ''; - + if($this->thisSession->getMembershipID() != null){ $person = new Application_Model_Person(); $personMapper = new Application_Model_PersonMapper(); @@ -415,26 +415,26 @@ class ResourceController extends Zend_Controller_Action $test = array(); if($anzUsers <= 2){ foreach($bootosuser as $user) - $test[] = $user->getLogin(); + $test[] = $user->getLogin(); } - + $configView = new Zend_View(); $f = fopen("$tmp_conf/initramfs/postinit.local", "a"); - - foreach($bootosuser as $user){ - + + foreach($bootosuser as $user){ + if($user->getLogin() == '%username%'){ $configView->loginname = $username; }else{ $configView->loginname = $user->getLogin(); } - + if($user->getPassword() == '%password%'){ - $configView->password = $userpassword; + $configView->password = $userpassword; }else{ $configView->password = $user->getPassword(); } - + if($user->getHometypeID() == 2){ $configView->homepath = $user->getHomepath(); }elseif($user->getHometypeID() == 1){ @@ -442,29 +442,29 @@ class ResourceController extends Zend_Controller_Action }else{ $configView->homepath = "/home/".$configView->loginname; } - + if($configView->loginname != '' && $configView->password != ''){ - + if($user->getHometypeID() == 1){ $configView->usb = true; } else{ $configView->usb = false; if($anzUsers <= 2 && $user->getLogin() == 'kiosk' && in_array('%username%',$test) && $this->thisSession->getMembershipID() == null) - $configView->autologin = true; + $configView->autologin = true; elseif($anzUsers <= 2 && $user->getLogin() == '%username%' && $this->thisSession->getMembershipID() != null) - $configView->autologin = true; - else - $configView->autologin = false; - + $configView->autologin = true; + else + $configView->autologin = false; + } - - + + $configView->addScriptPath(APPLICATION_PATH.'/views/scripts/resource/'); $config = $configView->render('getconfig.phtml'); - + fputs($f, $config); - + } } fclose($f); @@ -473,7 +473,7 @@ class ResourceController extends Zend_Controller_Action chdir($tmp_conf); passthru( "tar cz *"); exec("rm -rf ../$hash"); - + } }else{ header('HTTP/1.0 404 Not Found'); @@ -569,6 +569,65 @@ class ResourceController extends Zend_Controller_Action echo $result2; } + public function getbootosAction() { + list($rightroles1) = $this->rightrolesMapper->findBy(array('rightID' => '56', 'roleID' => $this->membership->getRoleID())); + list($rightroles2) = $this->rightrolesMapper->findBy(array('rightID' => '57', 'roleID' => $this->membership->getRoleID())); + if($rightroles1 == null && $rightroles2 == null){ + header('HTTP/1.0 403 No Right to Show Bootos'); + die(); + } + + $apikey = $this->_request->getParam('apikey'); + if($apikey == ""){ + header('HTTP/1.0 400 No API-Key'); + die(); + } + + $params = $this->_request->getParams(); + $source = $_SERVER['REMOTE_ADDR']; + + $bootos = new Application_Model_BootOs(); + $bootosMapper = new Application_Model_BootOsMapper(); + $groupID = $this->membership->getGroupID(); + + list($bootos) = $bootosMapper->findBy(array('groupid' => $groupID)); + + if($bootos == null){ + header('HTTP/1.0 400 No Bootos was found'); + die(); + } + + $xml = "\n" + $xml .= "\t\n"; + foreach($bootos as $bootosobj) { + $xml .= "\t\t\n"; + $xml .= "\t\t\t" . $bootosobj->getID() . "\n"; + $xml .= "\t\t\t" . $bootosobj->getGroupID() . "\n"; + $xml .= "\t\t\t" . $bootosobj->getMembershipID() . "\n"; + $xml .= "\t\t\t" . $bootosobj->getTitle() . "\n"; + $xml .= "\t\t\t" . $bootosobj->getDefaultkcl() . "\n"; + $xml .= "\t\t\t" . $bootosobj->getCreated() . "\n"; + $xml .= "\t\t\t" . $bootosobj->getDescription() . "\n"; + $xml .= "\t\t\t" . $bootosobj->getDescription() . "\n"; + $xml .= "\t\t\t" . $bootosobj->getPublic() . "\n"; + $xml .= "\t\t\t" . $bootosobj->getSource() . "\n"; + $xml .= "\t\t\t" . $bootosobj->getDistro() . "\n"; + $xml .= "\t\t\t" . $bootosobj->getDistroversion() . "\n"; + $xml .= "\t\t\t" . $bootosobj->getShortname() . "\n"; + $xml .= "\t\t\t" . $bootosobj->getShare() . "\n"; + $xml .= "\t\t\n"; + } + $xml .= "\t\n"; + $xml .= ""; + + header('Content-Type: text/xml'); + $content_disp = ( ereg('MSIE ([0-9].[0-9]{1,2})', $_SERVER['HTTP_USER_AGENT']) == 'IE') ? 'inline' : 'attachment'; + header('Content-Disposition: ' . $content_disp . '; filename="bootos.xml"'); + header('Pragma: no-cache'); + header('Expires: 0'); + echo $xml; + } + private function generateURL($action, $varname, $varvalue, $filename){ $path = '/resource/'. $action .'/' . $varname .'/' . $varvalue .'/bootmenuentryID/'.$this->thisSession->getBootmenuentryID().'/file/' . $filename ; $path = "http://" . $_SERVER['SERVER_NAME'] . $path; -- cgit v1.2.3-55-g7522