summaryrefslogtreecommitdiffstats
path: root/application/controllers/ResourceController.php
diff options
context:
space:
mode:
authorroot2011-05-30 16:58:26 +0200
committerroot2011-05-30 16:58:26 +0200
commit8d4bde45739a78561801b189efc18092ce7f21c9 (patch)
tree6205732708237d5f0d453c1f1ec73b880e348114 /application/controllers/ResourceController.php
parentfilterAPI test (diff)
parentGetBootOS API Test (diff)
downloadpbs2-8d4bde45739a78561801b189efc18092ce7f21c9.tar.gz
pbs2-8d4bde45739a78561801b189efc18092ce7f21c9.tar.xz
pbs2-8d4bde45739a78561801b189efc18092ce7f21c9.zip
Merge branch 'master' of openslx.org:lsfks/projekte/pbs2
Conflicts: application/controllers/ResourceController.php
Diffstat (limited to 'application/controllers/ResourceController.php')
-rw-r--r--application/controllers/ResourceController.php220
1 files changed, 140 insertions, 80 deletions
diff --git a/application/controllers/ResourceController.php b/application/controllers/ResourceController.php
index f70fc02..10c8fed 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,9 +152,10 @@ class ResourceController extends Zend_Controller_Action
header('HTTP/1.0 201 Bootos created');
}
+
public function addfilterAction()
{
-
+
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');
@@ -166,33 +167,33 @@ class ResourceController extends Zend_Controller_Action
header('HTTP/1.0 400 No API-Key');
die();
}
-
+
$params = $this->_request->getParams();
-
+
$filterMapper = new Application_Model_FilterMapper();
- $groupID = $this->membership->getGroupID();
-
-
+ $groupID = $this->membership->getGroupID();
+
+
$filter = new Application_Model_Filter();
-
+
$filter->setOptions($params);
$filter->setGroupID($groupID);
$filter->setCreated(time());
-
+
$filterID = $filterMapper->save($filter);
$filter->setID($filter);
-
+
}
-
+
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');
@@ -201,23 +202,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();
@@ -227,7 +228,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/";
@@ -250,19 +251,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');
@@ -271,33 +272,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."/";
@@ -308,19 +309,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');
@@ -329,28 +330,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();
@@ -358,19 +359,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()
@@ -399,7 +400,7 @@ class ResourceController extends Zend_Controller_Action
}
public function getconfigAction()
- {
+ {
$bootmenuentryID = $this->thisSession->getBootmenuentryID();
$bootmenuentry = new Application_Model_BootMenuEntries();
$bmm = new Application_Model_BootMenuEntriesMapper();
@@ -422,7 +423,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);
@@ -431,7 +432,7 @@ class ResourceController extends Zend_Controller_Action
$username = '';
$userpassword = '';
-
+
if($this->thisSession->getMembershipID() != null){
$person = new Application_Model_Person();
$personMapper = new Application_Model_PersonMapper();
@@ -446,26 +447,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){
@@ -473,29 +474,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);
@@ -504,7 +505,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');
@@ -600,6 +601,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();
+
+ $bootos = $bootosMapper->findBy(array('groupid' => $groupID));
+
+ if($bootos == null){
+ header('HTTP/1.0 400 No Bootos was found');
+ die();
+ }
+
+ $xml = "<xml>\n";
+ $xml .= "\t<bootoslist>\n";
+ foreach($bootos as $bootosobj) {
+ $xml .= "\t\t<bootos>\n";
+ $xml .= "\t\t\t<id>" . $bootosobj->getID() . "</id>\n";
+ $xml .= "\t\t\t<groupid>" . $bootosobj->getGroupID() . "</groupid>\n";
+ $xml .= "\t\t\t<membershipid>" . $bootosobj->getMembershipID() . "</membershipid>\n";
+ $xml .= "\t\t\t<title>" . $bootosobj->getTitle() . "</title>\n";
+ $xml .= "\t\t\t<defaultkcl>" . $bootosobj->getDefaultkcl() . "</defaultkcl>\n";
+ $xml .= "\t\t\t<created>" . $bootosobj->getCreated() . "</created>\n";
+ $xml .= "\t\t\t<description>" . $bootosobj->getDescription() . "</description>\n";
+ $xml .= "\t\t\t<expires>" . $bootosobj->getDescription() . "</expires>\n";
+ $xml .= "\t\t\t<public>" . $bootosobj->getPublic() . "</public>\n";
+ $xml .= "\t\t\t<source>" . $bootosobj->getSource() . "</source>\n";
+ $xml .= "\t\t\t<distro>" . $bootosobj->getDistro() . "</distro>\n";
+ $xml .= "\t\t\t<distroversion>" . $bootosobj->getDistroversion() . "</distroversion>\n";
+ $xml .= "\t\t\t<shortname>" . $bootosobj->getShortname() . "</shortname>\n";
+ $xml .= "\t\t\t<share>" . $bootosobj->getShare() . "</share>\n";
+ $xml .= "\t\t</bootos>\n";
+ }
+ $xml .= "\t</bootoslist>\n";
+ $xml .= "</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;