summaryrefslogtreecommitdiffstats
path: root/application
diff options
context:
space:
mode:
authormichael pereira2011-04-18 16:33:13 +0200
committermichael pereira2011-04-18 16:33:13 +0200
commitbe3bf392777efb6c953064e095b5fe510bff1ca8 (patch)
treed05ed80b1d25ce33b4bdf8d2c21a105e99b133b7 /application
parentPublic Level -1 (nicht freigeschaltet) bei Bootiso und Bootos (diff)
downloadpbs2-be3bf392777efb6c953064e095b5fe510bff1ca8.tar.gz
pbs2-be3bf392777efb6c953064e095b5fe510bff1ca8.tar.xz
pbs2-be3bf392777efb6c953064e095b5fe510bff1ca8.zip
API-Key bei Membership & BootOS über API fertig
Diffstat (limited to 'application')
-rw-r--r--application/controllers/ResourceController.php85
-rw-r--r--application/models/Membership.php10
-rw-r--r--application/models/MembershipMapper.php6
-rw-r--r--application/modules/user/controllers/GroupController.php6
-rw-r--r--application/modules/user/controllers/PersonController.php16
-rw-r--r--application/modules/user/controllers/RoleController.php1
-rw-r--r--application/modules/user/forms/Bootos.php6
-rw-r--r--application/modules/user/views/scripts/bootos/index.phtml2
-rw-r--r--application/modules/user/views/scripts/person/owndetails.phtml10
9 files changed, 125 insertions, 17 deletions
diff --git a/application/controllers/ResourceController.php b/application/controllers/ResourceController.php
index f6b63e2..86d3f5b 100644
--- a/application/controllers/ResourceController.php
+++ b/application/controllers/ResourceController.php
@@ -5,6 +5,7 @@ class ResourceController extends Zend_Controller_Action
private $thisSession;
private $page;
+ private $membership;
public function init()
{
@@ -16,14 +17,25 @@ class ResourceController extends Zend_Controller_Action
//TODO Error Messages if something failed
$alpha = $this->_request->getParam('alpha');
- if($alpha != "0"){
- $alphasessionID = $alpha;
- $result = $sm->findBy(array('alphasessionID' => $alphasessionID),true);
- # print_a($result);
- $this->thisSession = $session->setOptions($result[0]);
- $this->thisSession->setID($result[0]['sessionID']);
+ $apikey = $this->_request->getParam('apikey');
+
+ if($apikey != ""){
+ $membershipMapper = new Application_Model_MembershipMapper();
+ $this->membership = new Application_Model_Membership();
+ $rightrolesMapper = new Application_Model_RightRolesMapper();
+ $rightroles = new Application_Model_RightRoles();
+ @list($this->membership) = $membershipMapper->findBy(array('apikey' => $apikey));
+ if($this->membership == null){
+ header('HTTP/1.0 401 Member not found');
+ die();
+ }
+ @list($rightroles) = $rightrolesMapper->findBy(array('rightID' => '55', 'roleID' => $this->membership->getRoleID()));
+ if($rightroles == null){
+ header('HTTP/1.0 403 No Right to Create Bootos');
+ die();
+ }
}
- else{
+ elseif($alpha == "0"){
$bootmenuentryID = $this->_request->getParam('bootmenuentryID');
$this->page = $this->_request->getParam('page');
@@ -45,13 +57,70 @@ class ResourceController extends Zend_Controller_Action
$this->thisSession = $session;
}
+ elseif($alpha != ""){
+ $alphasessionID = $alpha;
+ $result = $sm->findBy(array('alphasessionID' => $alphasessionID),true);
+ # print_a($result);
+ $this->thisSession = $session->setOptions($result[0]);
+ $this->thisSession->setID($result[0]['sessionID']);
+ }
}
public function indexAction()
{
+
-
+ }
+
+ public function addbootosAction()
+ {
+ $apikey = $this->_request->getParam('apikey');
+ if($apikey == ""){
+ header('HTTP/1.0 400 No API-Key');
+ die();
+ }
+
+ $params = $this->_request->getParams();
+ if(!isset($params['title'])){
+ header('HTTP/1.0 400 Title must be set');
+ die();
+ }
+
+ $bootos = new Application_Model_BootOs();
+ $bootosMapper = new Application_Model_BootOsMapper();
+
+ $bootos->setOptions($params);
+ $bootos->setGroupID($this->membership->getGroupID());
+ $bootos->setSource($_SERVER['REMOTE_ADDR']);
+ $bootos->setPath_config($_FILES['config']['name']);
+ $bootos->setPath_init($_FILES['init']['name']);
+ $bootos->setPath_kernel($_FILES['kernel']['name']);
+ $bootos->setCreated(time());
+ $bootos->setPublic('-1');
+ $bootosID = $bootosMapper->save($bootos);
+
+ print_a($bootos);
+ $initpath = "../resources/bootos/".$bootosID."/initramfs/";
+ $kernelpath = "../resources/bootos/".$bootosID."/kernel/";
+ $configpath = "../resources/bootos/".$bootosID."/config/";
+
+ mkdir($initpath ,0777, true);
+ mkdir($kernelpath ,0777, true);
+ mkdir($configpath ,0777, true);
+
+ if(isset($_FILES['config'])){
+ move_uploaded_file($_FILES['config']['tmp_name'], $configpath."config.tgz");
+ }
+ if(isset($_FILES['kernel'])){
+ move_uploaded_file($_FILES['kernel']['tmp_name'], $kernelpath."kernel");
+ }
+ if(isset($_FILES['init'])){
+ move_uploaded_file($_FILES['init']['tmp_name'], $initpath."initramfs");
+ }
+
+ header('HTTP/1.0 201 Bootos created');
+
}
public function getinitramfsAction()
diff --git a/application/models/Membership.php b/application/models/Membership.php
index 8a18d11..0fe57a6 100644
--- a/application/models/Membership.php
+++ b/application/models/Membership.php
@@ -7,6 +7,7 @@ class Application_Model_Membership
protected $_roleID;
protected $_personID;
protected $_suspended;
+ protected $_apikey;
public function __construct(array $options = null)
{
@@ -91,6 +92,15 @@ class Application_Model_Membership
$this->_suspended = $_suspended;
return $this;
}
+ public function getApikey()
+ {
+ return $this->_apikey;
+ }
+ public function setApikey($_apikey)
+ {
+ $this->_apikey = $_apikey;
+ return $this;
+ }
/**
* Returns current data as associative array using ReflectionClass
*
diff --git a/application/models/MembershipMapper.php b/application/models/MembershipMapper.php
index 68d6db8..5368648 100644
--- a/application/models/MembershipMapper.php
+++ b/application/models/MembershipMapper.php
@@ -74,7 +74,7 @@ class Application_Model_MembershipMapper
public function save(Application_Model_Membership $membership)
{
- $data = array('membershipID'=> $membership->getID() ,'groupID'=> $membership->getGroupID() ,'roleID'=> $membership->getRoleID() ,'personID'=> $membership->getPersonID() ,'suspended'=> $membership->getSuspended() );
+ $data = array('membershipID'=> $membership->getID() ,'groupID'=> $membership->getGroupID() ,'roleID'=> $membership->getRoleID() ,'personID'=> $membership->getPersonID() ,'suspended'=> $membership->getSuspended(), 'apikey'=> $membership->getApikey() );
if (null === ($id = $membership->getID()) ) {
unset($data['membershipID']);
@@ -109,7 +109,7 @@ class Application_Model_MembershipMapper
$row = $result->current();
- $membership->setID($row->membershipID)->setGroupID($row->groupID)->setRoleID($row->roleID)->setPersonID($row->personID)->setSuspended($row->suspended);
+ $membership->setID($row->membershipID)->setGroupID($row->groupID)->setRoleID($row->roleID)->setPersonID($row->personID)->setSuspended($row->suspended)->setApikey($row->apikey);
if($return){
return $membership;
}
@@ -122,7 +122,7 @@ class Application_Model_MembershipMapper
foreach ($resultSet as $row) {
$entry = new Application_Model_Membership();
- $entry->setID($row->membershipID)->setGroupID($row->groupID)->setRoleID($row->roleID)->setPersonID($row->personID)->setSuspended($row->suspended);
+ $entry->setID($row->membershipID)->setGroupID($row->groupID)->setRoleID($row->roleID)->setPersonID($row->personID)->setSuspended($row->suspended)->setApikey($row->apikey);
$entries[] = $entry;
}
diff --git a/application/modules/user/controllers/GroupController.php b/application/modules/user/controllers/GroupController.php
index 9eca3e3..9db2ccf 100644
--- a/application/modules/user/controllers/GroupController.php
+++ b/application/modules/user/controllers/GroupController.php
@@ -411,7 +411,11 @@ class User_GroupController extends Zend_Controller_Action
$membership->setGroupID($groupRequest->getGroupID());
$membership->setPersonID($groupRequest->getPersonID());
$membership->setRoleID($_POST['roleID']);
- $membership->setSuspended(0);
+ $membership->setSuspended(0);
+ $apikey = randomString(32);
+ $membership->setApikey($apikey);
+
+
try {
$id = $this->membershipMapper->save($membership);
diff --git a/application/modules/user/controllers/PersonController.php b/application/modules/user/controllers/PersonController.php
index 4f6b975..4ec8297 100644
--- a/application/modules/user/controllers/PersonController.php
+++ b/application/modules/user/controllers/PersonController.php
@@ -35,14 +35,28 @@ class user_PersonController extends Zend_Controller_Action
$this->groupRequestMapper = new Application_Model_GroupRequestMapper();
$this->membershipMapper = new Application_Model_MembershipMapper();
$this->memberships = $this->membershipMapper->findBy(array("personID" => $this->person->getID()),true);
+
+ $rightrolesMapper = new Application_Model_RightRolesMapper();
+ $rightroles = new Application_Model_RightRoles();
+ $role = new Application_Model_Role();
+ $roleMapper = new Application_Model_RoleMapper();
+
+ $this->view->apikeys = array();
+
if(isset($this->memberships)) {
foreach($this->memberships as $membership) {
$group = $this->groupMapper->find($membership['groupID']);
+ @list($rightroles) = $rightrolesMapper->findBy(array('rightID' => '55', 'roleID' => $membership['roleID']));
+ $role = $roleMapper->find($membership['roleID']);
+ if($rightroles != null)
+ $this->view->apikeys[$group->getID()] = $membership['apikey'];
+
$this->groups[] = array (
'groupID' => $group->getID(),
'title' => $group->getTitle(),
'description' => $group->getDescription(),
- 'membershipID' => $membership['membershipID']
+ 'membershipID' => $membership['membershipID'],
+ 'role' => $role->getTitle()
);
}
}
diff --git a/application/modules/user/controllers/RoleController.php b/application/modules/user/controllers/RoleController.php
index 2c22031..bee6ecf 100644
--- a/application/modules/user/controllers/RoleController.php
+++ b/application/modules/user/controllers/RoleController.php
@@ -339,6 +339,7 @@ class User_RoleController extends Zend_Controller_Action
$rightroles = new Application_Model_RightRoles();
$rightroles->setRightID($rightID);
$rightroles->setRoleID($roleID);
+
try {
$this->rightRolesMapper->save($rightroles);
} catch(Zend_Exception $e)
diff --git a/application/modules/user/forms/Bootos.php b/application/modules/user/forms/Bootos.php
index 964fbf3..2453f1b 100644
--- a/application/modules/user/forms/Bootos.php
+++ b/application/modules/user/forms/Bootos.php
@@ -58,7 +58,7 @@ class user_Form_Bootos extends Zend_Form
'validators' => array(
array('StringLength', false, array(0, 250)),
),
- 'required' => true,
+ 'required' => flase,
'size' => 50,
'readOnly' => $meta,
'label' => 'Init-Path:',
@@ -69,7 +69,7 @@ class user_Form_Bootos extends Zend_Form
'validators' => array(
array('StringLength', false, array(0, 250)),
),
- 'required' => true,
+ 'required' => false,
'size' => 50,
'readOnly' => $meta,
'label' => 'Kernel-Path:',
@@ -80,7 +80,7 @@ class user_Form_Bootos extends Zend_Form
'validators' => array(
array('StringLength', false, array(0, 250)),
),
- 'required' => true,
+ 'required' => false,
'size' => 50,
'readOnly' => $meta,
'label' => 'Config-Path:',
diff --git a/application/modules/user/views/scripts/bootos/index.phtml b/application/modules/user/views/scripts/bootos/index.phtml
index f76338b..94e35c0 100644
--- a/application/modules/user/views/scripts/bootos/index.phtml
+++ b/application/modules/user/views/scripts/bootos/index.phtml
@@ -19,7 +19,7 @@
<div class='code'>bootosID</div>
<div class='code'>public</div>
<div class='code'>path_kernel</div>
- <div class='code'>kcl</div>
+ <div class='code'>defaultkcl</div>
<div class='code'>path_init</div>
<div class='code'>path_config</div>
<div class='code'>distro</div>
diff --git a/application/modules/user/views/scripts/person/owndetails.phtml b/application/modules/user/views/scripts/person/owndetails.phtml
index 2aaef54..3f1cfb4 100644
--- a/application/modules/user/views/scripts/person/owndetails.phtml
+++ b/application/modules/user/views/scripts/person/owndetails.phtml
@@ -70,6 +70,16 @@ if(count($this->groups)==0)
</div>
<div class='title'><?php echo $group['title']; ?></div>
<div class='subtitle'><?php echo $group['description']; ?>&nbsp;</div>
+ <div class='details'>
+ <label>Role</label>
+ <div class='item'><?php echo $group['role']; ?>&nbsp;</div>
+ </div>
+ <?php if($this->apikeys[$group['groupID']] != null):?>
+ <div class='details'>
+ <label>API-Key</label>
+ <div class='item'><?php echo $this->apikeys[$group['groupID']]; ?>&nbsp;</div>
+ </div>
+ <?php endif;?>
</div>
<div class='clear'></div>
</div>