summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormichael pereira2011-03-30 10:54:29 +0200
committermichael pereira2011-03-30 10:54:29 +0200
commit912f7ffb34fb824d238ef89b91c5bd8203cfe3ad (patch)
treeec186f68b023f27fc93bb7bfa918581ccf9394e6
parentPreboot Metadaten Recht gesetzt (diff)
downloadpbs2-912f7ffb34fb824d238ef89b91c5bd8203cfe3ad.tar.gz
pbs2-912f7ffb34fb824d238ef89b91c5bd8203cfe3ad.tar.xz
pbs2-912f7ffb34fb824d238ef89b91c5bd8203cfe3ad.zip
Notifier 404 zu BootIso Download hinzugefügt
-rw-r--r--application/modules/user/controllers/BootisoController.php5
-rw-r--r--application/modules/user/controllers/BootosController.php207
-rw-r--r--application/modules/user/forms/Bootos.php144
-rw-r--r--application/modules/user/views/scripts/bootos/createbootos.phtml4
-rw-r--r--application/modules/user/views/scripts/bootos/editbootos.phtml4
-rw-r--r--application/modules/user/views/scripts/bootos/index.phtml86
-rw-r--r--library/Pbs/Notifier.php3
7 files changed, 444 insertions, 9 deletions
diff --git a/application/modules/user/controllers/BootisoController.php b/application/modules/user/controllers/BootisoController.php
index 2642a8d..73462eb 100644
--- a/application/modules/user/controllers/BootisoController.php
+++ b/application/modules/user/controllers/BootisoController.php
@@ -100,7 +100,10 @@ class user_BootisoController extends Zend_Controller_Action
$prebootID = $this->_request->getParam('prebootID');
$bootisoID = $this->_request->getParam('bootisoID');
- if(!is_dir("../resources/bootmedium/$prebootID/") || !is_numeric($prebootID) || !is_numeric($bootisoID))
+ if(!is_dir("../resources/bootmedium/$prebootID/"))
+ $this->_redirect('/user/bootiso/index/downloadresult/404');
+
+ if(!is_numeric($prebootID) || !is_numeric($bootisoID))
$this->_redirect('/user/bootiso/index/downloadresult/forbidden');
chdir("../resources/bootmedium/$prebootID/");
diff --git a/application/modules/user/controllers/BootosController.php b/application/modules/user/controllers/BootosController.php
index 56a6ae3..81ddda3 100644
--- a/application/modules/user/controllers/BootosController.php
+++ b/application/modules/user/controllers/BootosController.php
@@ -1,22 +1,215 @@
<?php
-class User_BootosController extends Zend_Controller_Action
+class user_BootosController extends Zend_Controller_Action
{
public function init()
{
- if (Zend_Auth::getInstance()->hasIdentity()) {
-
- } else {
- $this->_helper->redirector('login', 'auth');
- }
+ $db = Zend_Db_Table::getDefaultAdapter();
}
public function indexAction()
{
- // action body
+
+ $bootosmapper = new Application_Model_BootOsMapper();
+
+ $groupmapper = new Application_Model_GroupMapper();
+ $membershipmapper = new Application_Model_MembershipMapper();
+ $personmapper = new Application_Model_PersonMapper();
+ $configmapper = new Application_Model_ConfigMapper();
+
+ $this->view->bootoslist = $bootosmapper->fetchAll();
+ $this->view->update = array();
+
+ if(count($this->view->bootoslist)>0){
+ foreach ($this->view->bootoslist as $bootos){
+ $this->view->update[$bootos->getID()] = $this->checkupdateAction($bootos);
+ $bootos->setGroupID("[".$bootos->getGroupID()."] ".$groupmapper->find($bootos->getGroupID())->getTitle());
+ $bootos->setMembershipID("[".$bootos->getMembershipID()."] ".$personmapper->find($membershipmapper->find($bootos->getMembershipID())->getPersonID())->getFirstname());
+ $bootos->setConfigID("[".$bootos->getConfigID()."] ".$configmapper->find($bootos->getConfigID())->getTitle());
+
+ }
+ }
+
+ }
+
+ public function createbootosAction()
+ {
+ $groupmapper = new Application_Model_GroupMapper();
+ $configmapper = new Application_Model_ConfigMapper();
+
+ if (!isset($_POST["createbootos"])){
+ try{
+ $createbootosForm = new user_Form_BootosCreate(array('grouplist' => $groupmapper->fetchAll() ,'configlist'=>$configmapper->fetchAll()));
+ }catch(Zend_Exception $e){
+ print_a($e);
+ }
+ } else {
+
+ $createbootosForm = new user_Form_BootosCreate(array('grouplist' => $groupmapper->fetchAll() ,'configlist'=>$configmapper->fetchAll()),$_POST);
+
+ if ($createbootosForm->isValid($_POST)) {
+
+ $bootos = new Application_Model_BootOs($_POST);
+
+ $bootos->setMembershipID('1');
+ if($bootos->getConfigID() == '')
+ $bootos->setConfigID(NULL);
+ $bootosmapper = new Application_Model_BootOsMapper();
+ $bootos->setCreated(time());
+
+ try {
+ exec("wget --spider ".$bootos->getPath_kernel()." 2>&1 | grep 'Remote file exists.'", $exists_kernel);
+ exec("wget --spider ".$bootos->getPath_init()." 2>&1 | grep 'Remote file exists.'" , $exists_init);
+
+ if(!array_pop($exists_init) || !array_pop($exists_kernel)){
+ $this->view->createbootosForm = $createbootosForm;
+ return;
+ }
+
+ $bootosID = $bootosmapper->save($bootos);
+
+ $initpath = "../resources/bootos/".$bootosID."/initramfs/";
+ $kernelpath = "../resources/bootos/".$bootosID."/kernel/";
+
+ mkdir($initpath ,0777, true);
+ mkdir($kernelpath ,0777, true);
+
+ exec("wget -O '".$kernelpath."kernel' ".$bootos->getPath_kernel());
+ exec("wget -O '".$initpath."initramfs' ".$bootos->getPath_init());
+
+
+
+ }catch(Zend_Exception $e)
+ {
+ echo "Caught exception: " . get_class($e) . "<br/>";
+ echo "Message: " . $e->getMessage() . "<br/>";
+
+ }
+
+ $this->_redirect('/user/bootos');
+ }
+ }
+
+ $this->view->createbootosForm = $createbootosForm;
+ }
+
+ public function checkupdateAction($bootos)
+ {
+ exec("wget --server-response --spider '".escapeshellcmd($bootos->getPath_kernel())."' 2>&1 | grep 'Last-Modified:'", $kerneldate);
+ exec("wget --server-response --spider '".escapeshellcmd($bootos->getPath_init())."' 2>&1 | grep 'Last-Modified:'", $initdate);
+
+ $kerneldate = strtotime(trim(str_replace('Last-Modified:', '', array_pop($kerneldate))));
+ $kernelname = array_pop(scandir("../resources/bootos/".$bootos->getID()."/kernel/"));
+
+ if($kernelname != "." && $kernelname != "..")
+ $kernelolddate = filemtime("../resources/bootos/".$bootos->getID()."/kernel/".$kernelname);
+ else
+ $kernelolddate = false;
+
+ $initdate = strtotime(trim(str_replace('Last-Modified:', '', array_pop($initdate))));
+ $initname = array_pop(scandir("../resources/bootos/".$bootos->getID()."/initramfs/"));
+
+ if($initname != "." && $initname != "..")
+ $initolddate = filemtime("../resources/bootos/".$bootos->getID()."/initramfs/".$initname);
+ else
+ $initolddate = false;
+
+ //print_a($kernelname,$kerneldate,$kernelolddate,$initname,$initdate,$initolddate);
+
+
+ if($kerneldate > $kernelolddate || $initdate > $initolddate)
+ return true;
+ else
+ return false;
+
+ }
+
+ public function updatebootosAction()
+ {
+ $bootosID = $this->_request->getParam('bootosID');
+ $bootosmapper = new Application_Model_BootOsMapper();
+ $bootos = $bootosmapper->find($bootosID);
+
+ $initpath = "../resources/bootos/".$bootosID."/initramfs/";
+ $kernelpath = "../resources/bootos/".$bootosID."/kernel/";
+
+ exec("wget -P ".$kernelpath." -N ".$bootos->getPath_kernel());
+ exec("wget -P ".$initpath." -N ".$bootos->getPath_init());
+
+ $this->_redirect('/user/bootos');
+ }
+
+ public function editbootosAction()
+ {
+ $bootosID = $this->_request->getParam('bootosID');
+ $groupmapper = new Application_Model_GroupMapper();
+ $configmapper = new Application_Model_ConfigMapper();
+
+ if (!isset($_POST["editbootos"])){
+ $bootosID = $this->_request->getParam('bootosID');
+ if (!isset($bootosID) || !is_numeric($bootosID)){
+ $this->_redirect('/user/bootos');
+ } else {
+ $bootos = new Application_Model_BootOs();
+ $bootosmapper = new Application_Model_BootOsMapper();
+ $bootos = $bootosmapper->find($bootosID);
+
+ $editbootosForm = new user_Form_BootosEdit(array('grouplist' => $groupmapper->fetchAll() ,'configlist'=>$configmapper->fetchAll()));
+ $editbootosForm->populate($bootos->toArray());
+ }
+ }else{
+ $editbootosForm = new user_Form_BootosEdit(array('grouplist' => $groupmapper->fetchAll() ,'configlist'=>$configmapper->fetchAll()),$_POST);
+
+ if ($editbootosForm->isValid($_POST)) {
+
+ //TODO: Check for new URL and download new files.
+ $bootos = new Application_Model_BootOs($_POST);
+ $bootos->setMembershipID('1');
+ if($bootos->getConfigID() == '')
+ $bootos->setConfigID(NULL);
+ $bootosmapper = new Application_Model_BootOsMapper();
+ $bootos->setCreated(time());
+ $bootos->setID($bootosID);
+
+ try {
+ $bootosmapper->save($bootos);
+ }catch(Zend_Exception $e)
+ {
+ echo "Caught exception: " . get_class($e) . "<br/>";
+ echo "Message: " . $e->getMessage() . "<br/>";
+ }
+
+ $this->_redirect('/user/bootos');
+ }
+
+ }
+
+ $this->view->editbootosForm = $editbootosForm;
+
+ }
+
+ public function deletebootosAction()
+ {
+ $bootosID = $this->_request->getParam('bootosID');
+ if (!isset($bootosID)){
+ $this->_redirect('/user/bootos');
+ } else {
+ $bootos = new Application_Model_BootOs();
+ $bootos->setID($bootosID);
+ $bootosmapper = new Application_Model_BootOsMapper();
+ $bootosmapper->delete($bootos);
+ }
+ $this->_redirect('/user/bootos');
+
}
}
+
+
+
+
+
+
diff --git a/application/modules/user/forms/Bootos.php b/application/modules/user/forms/Bootos.php
new file mode 100644
index 0000000..5597f49
--- /dev/null
+++ b/application/modules/user/forms/Bootos.php
@@ -0,0 +1,144 @@
+<?php
+
+class user_Form_Bootos extends Zend_Form
+{
+
+ private $configlist;
+ private $action;
+ private $rights;
+ private $groupdepth;
+
+ public function setRights($rights){
+ $this->rights = $rights;
+ }
+ public function setAction($action){
+ $this->action = $action;
+
+ }
+ public function setConfiglist($configlist){
+ $this->configlist = $configlist;
+
+ }
+ public function setGroupdepth($groupdepth){
+ $this->groupdepth = $groupdepth;
+ }
+
+ public function init()
+ {
+ $this->setName("BootOsCreate");
+ $this->setMethod('post');
+
+ if ($this->rights == 'meta')
+ $meta = true;
+
+ $this->addElement('text', 'title', array(
+ 'filters' => array('StringTrim'),
+ 'validators' => array(
+ array('StringLength', false, array(0, 50)),
+ ),
+ 'required' => true,
+ 'label' => 'Title:',
+ ));
+
+ $configfield = $this->createElement('select','configID');
+ $configfield ->setLabel('Config:');
+ $configfield->setAttrib('readOnly', $meta);
+
+ if(count($this->configlist)>0){
+ foreach($this->configlist as $config => $c){
+ $configfield->addMultiOption($c->getID(), $c->getTitle());
+ }
+ }
+ $configfield->setRegisterInArrayValidator(false);
+ $this->addElement($configfield);
+
+ $this->addElement('text', 'path_init', array(
+ 'filters' => array('StringTrim'),
+ 'validators' => array(
+ array('StringLength', false, array(0, 250)),
+ ),
+ 'required' => true,
+ 'size' => 50,
+ 'readOnly' => $meta,
+ 'label' => 'Init-Path:',
+ ));
+
+ $this->addElement('text', 'path_kernel', array(
+ 'filters' => array('StringTrim'),
+ 'validators' => array(
+ array('StringLength', false, array(0, 250)),
+ ),
+ 'required' => true,
+ 'size' => 50,
+ 'readOnly' => $meta,
+ 'label' => 'Kernel-Path:',
+ ));
+
+ $this->addElement('textarea', 'defaultkcl', array(
+ 'filters' => array('StringTrim'),
+ 'validators' => array(
+ array('StringLength', false, array(0, 175)),
+ ),
+ 'required' => false,
+ 'rows' => 5,
+ 'cols' => 50,
+ 'readOnly' => $meta,
+ 'label' => 'Default-KCL:',
+ ));
+
+ $this->addElement('textarea', 'description', array(
+ 'filters' => array('StringTrim'),
+ 'validators' => array(
+ array('StringLength', false, array(0, 50)),
+ ),
+ 'required' => false,
+ 'rows' => 5,
+ 'cols' => 50,
+ 'label' => 'Description:',
+ ));
+
+ $date = new DateTime();
+ $date->add(new DateInterval('P1Y'));
+ $this->addElement('text', 'expires', array(
+ 'filters' => array('StringTrim'),
+ 'validators' => array(
+ array('StringLength', false, array(0, 50)),
+ ),
+ 'required' => false,
+ 'label' => 'Expires:',
+ 'readOnly' => $meta,
+ 'value' => $date->format('Y-m-d'),
+ ));
+
+ $publicfield = $this->createElement('select','public');
+ $publicfield->setLabel('Public:');
+ $publicfield->addMultiOption(0, '0. Eigene Gruppe');
+ $publicfield->setAttrib('readOnly', $meta);
+
+ for($i=1; $i<$this->groupdepth; $i++){
+ $publicfield->addMultiOption($i, "$i. Untergruppe");
+ }
+
+ $publicfield->setRegisterInArrayValidator(false);
+ $this->addElement($publicfield);
+
+ if($this->action == "createbootos")
+ $label = "Create Bootos";
+ else
+ $label = "Edit Bootos";
+
+ $this->addElement('submit', $this->action, array(
+ 'required' => false,
+ 'ignore' => true,
+ 'label' => $label,
+ ));
+
+ $this->addElement('button', 'Cancel', array(
+ 'onclick' => 'self.location="/user/bootos"'
+ ));
+
+ }
+
+
+}
+
diff --git a/application/modules/user/views/scripts/bootos/createbootos.phtml b/application/modules/user/views/scripts/bootos/createbootos.phtml
new file mode 100644
index 0000000..51c49a2
--- /dev/null
+++ b/application/modules/user/views/scripts/bootos/createbootos.phtml
@@ -0,0 +1,4 @@
+<?php
+$this->bootosForm;
+echo $this->bootosForm;
+?>
diff --git a/application/modules/user/views/scripts/bootos/editbootos.phtml b/application/modules/user/views/scripts/bootos/editbootos.phtml
new file mode 100644
index 0000000..51c49a2
--- /dev/null
+++ b/application/modules/user/views/scripts/bootos/editbootos.phtml
@@ -0,0 +1,4 @@
+<?php
+$this->bootosForm;
+echo $this->bootosForm;
+?>
diff --git a/application/modules/user/views/scripts/bootos/index.phtml b/application/modules/user/views/scripts/bootos/index.phtml
index c9bbeb9..53d219f 100644
--- a/application/modules/user/views/scripts/bootos/index.phtml
+++ b/application/modules/user/views/scripts/bootos/index.phtml
@@ -1 +1,85 @@
-<br /><br /><center>View script for controller <b>Bootos</b> and script/action name <b>index</b></center> \ No newline at end of file
+<h1>BootOS</h1>
+<?php if($this->notification != ''){echo $this->notification;} ?>
+<?php echo $this->formButton('checkupdate', 'Check for Updates', array(
+ 'onclick' => 'self.location="/user/bootos/index/checkupdate/true"',
+ 'class' => 'updatebutton',
+ ))?>
+<?php echo $this->formButton('createbootos', 'Create BootOS', array(
+ 'onclick' => 'self.location="/user/bootos/createbootos"',
+ 'class' => 'addbutton'))?>
+
+<table>
+ <tr>
+ <th>ID</th>
+ <th>Title</th>
+ <th>GroupID</th>
+ <th>MembershipID</th>
+ <th>ConfigID</th>
+ <th>Init</th>
+ <th>Kernel</th>
+ <th>Kcl</th>
+ <th>Description</th>
+ <th>Changed</th>
+ <th>Expires</th>
+ <th>Public</th>
+ <th colspan=3>Actions</th>
+ </tr>
+ <?php if(count($this->bootoslist)==0)
+ echo "</table> There are no BootOs's to display." ?>
+ <?php foreach ($this->bootoslist as $bootos): ?>
+ <tr class=entry>
+ <td><?php echo $this->escape($bootos->getID()); ?></td>
+ <td><?php echo $this->escape($bootos->getTitle()); ?></td>
+ <td><?php echo $this->escape($bootos->getGroupID()); ?></td>
+ <td><?php echo $this->escape($bootos->getMembershipID()); ?></td>
+ <td><?php echo $this->escape($bootos->getConfigID()); ?></td>
+ <td><?php echo $this->escape($bootos->getPath_init()); ?></td>
+ <td><?php echo $this->escape($bootos->getPath_kernel()); ?></td>
+ <td><?php echo $this->escape($bootos->getDefaultkcl()); ?></td>
+ <td><?php echo $this->escape($bootos->getDescription()); ?></td>
+ <td><?php echo $this->escape(date('Y-m-d H:i:s', $bootos->getCreated())); ?></td>
+ <td><?php echo $this->escape($bootos->getExpires()); ?></td>
+ <td><?php echo $this->escape($bootos->getPublic()); ?></td>
+ <?php if($this->update[$bootos->getID()]==true): ?>
+ <td class='action'><a
+ href="<?php echo $this->url(
+ array(
+ 'module' => 'user',
+ 'controller' => 'bootos',
+ 'action' => 'updatebootos',
+ 'bootosID' => $bootos->getID()
+ ),
+ 'default',
+ true, false) ?>"><img src='/media/img/update.png' alt='Updates available' /></a></td>
+ <?php else: ?>
+ <td class='action'><img src='/media/img/update_grey.png' alt='No updates available' /></td>
+ <?php endif; ?>
+ <td class='action'><a
+ href="<?php echo $this->url(
+ array(
+ 'module' => 'user',
+ 'controller' => 'bootos',
+ 'action' => 'editbootos',
+ 'bootosID' => $bootos->getID()
+ ),
+ 'default',
+ true, false) ?>"><img src='/media/img/edit.png' alt='Edit BootOS' /></a></td>
+ <td class='action'><a
+ href="<?php echo $this->url(
+ array(
+ 'module' => 'user',
+ 'controller' => 'bootos',
+ 'action' => 'deletebootos',
+ 'bootosID' => $bootos->getID()
+ ),
+ 'default',
+ true) ?>"><img src='/media/img/delete.png' alt='Delete BootOS' /></a></td>
+ </tr>
+ <?php endforeach; ?>
+</table>
+
+
+
+
+
+
diff --git a/library/Pbs/Notifier.php b/library/Pbs/Notifier.php
index 5186cdc..0edccec 100644
--- a/library/Pbs/Notifier.php
+++ b/library/Pbs/Notifier.php
@@ -45,6 +45,9 @@ class Pbs_Notifier{
case "forbidden":
$result = "<div class='errorbox'>Not allowed to download this</div>";
break;
+ case "404":
+ $result = "<div class='errorbox'>The Resource was not found on the Server</div>";
+ break;
}
break;
case "modify":