summaryrefslogtreecommitdiffstats
path: root/application/controllers/FilterController.php
diff options
context:
space:
mode:
Diffstat (limited to 'application/controllers/FilterController.php')
-rw-r--r--application/controllers/FilterController.php680
1 files changed, 0 insertions, 680 deletions
diff --git a/application/controllers/FilterController.php b/application/controllers/FilterController.php
deleted file mode 100644
index da52c34..0000000
--- a/application/controllers/FilterController.php
+++ /dev/null
@@ -1,680 +0,0 @@
-<?php
-
-class FilterController extends Zend_Controller_Action
-{
-
- private $_filtermapper = null;
-
- private $db = null;
-
- public function init()
- {
- try{
-
- $this->_filtermapper = new Application_Model_FilterMapper();
- }catch (Zend_Exception $e) {
- echo "Error message 1: " . $e->getMessage() . "\n";
- }
- $this->db = Zend_Db_Table::getDefaultAdapter();
- }
-
- public function indexAction()
- {
- try{
- $this->_filtermapper = new Application_Model_FilterMapper();
- $this->view->filters = $this->_filtermapper->fetchAll();
- }catch (Zend_Exception $e) {
- echo "Error message 2: " . $e->getMessage() . "\n";
- }
- }
-
- public function addfilterAction()
- {
- $bmmapper = new Application_Model_BootMenuMapper();
- //TODO get bootmenu by group
- $bootmenus = $bmmapper->fetchAll();
- if (!isset($_POST["add"])){
- $addfilterform = new Application_Form_FilterAdd(array('buttontext' => 'Create Filter','bootmenus'=>$bootmenus));
- $this->view->addfilterform = $addfilterform;
- }else {
- $addfilterform = new Application_Form_FilterAdd(array('buttontext' => 'Create Filter','bootmenus'=>$bootmenus),$_POST);
- if ($addfilterform->isValid($_POST)) {
- try{
- $newfilter = new Application_Model_Filter($_POST);
- $newfilter->setCreated(time());
-
- // TODO: Ändere mit ACL
- $newfilter->setGroupID('1');
- $newfilter->setMembershipID('1');
-
- $newfilter2 = new Application_Model_FilterMapper();
- $newfilter2->save($newfilter);
-
- $this->_redirect('/filter');
- return;
- }catch (Zend_Exception $e) {
- echo "Error message 2: " . $e->getMessage() . "\n";
- }
- }
- $this->view->addfilterform = $addfilterform;
- }
- }
-
- public function removefilterAction()
- {
- $filterID = $this->_request->getParam('filterID');
- // TODO: ACL implementieren ob er den filter löschen darf
- if(is_numeric($filterID)){
- $deletefilter = new Application_Model_Filter();
- $deletefilter->setID($filterID);
- $filtermapper = new Application_Model_FilterMapper();
- $filtermapper->delete($deletefilter);
- }
- $this->_redirect('/filter');
- }
-
- public function editfilterAction()
- {
- $bmmapper = new Application_Model_BootMenuMapper();
- //TODO get bootmenu by group
- $bootmenus = $bmmapper->fetchAll();
- if (!isset($_POST["add"])){
- // TODO: ACL implementieren ob er editieren darf
- $filterID = $this->_request->getParam('filterID');
- $filter = new Application_Model_Filter();
-
-
- $filtermapper = new Application_Model_FilterMapper();
- $filtermapper->find($filterID,$filter);
- $filter2 = $filter->toArray();
-
- $editfilterform = new Application_Form_FilterAdd(array('buttontext' => 'Edit Filter','bootmenus'=>$bootmenus));
- $editfilterform->populate($filter2);
- $this->view->editfilterform = $editfilterform;
-
- } else{
- try{
- $filterID = $this->_request->getParam('filterID');
-
- $editfilterform = new Application_Form_FilterAdd(array('buttontext' => 'Edit Filter','bootmenus'=>$bootmenus),$_POST);
- //TODO: ACL integrieren
- $_POST['groupID'] = 1;
- $_POST['membershipID'] = 1;
- $_POST['created'] = time();
-
- if ($editfilterform->isValid($_POST)) {
- $newfilterenty = new Application_Model_Filter($_POST);
- $newfilterenty->setID($this->_request->getParam('filterID'));
- $newfilter2 = new Application_Model_FilterMapper();
- $newfilter2->save($newfilterenty);
- echo 'valid';
- $this->_redirect('/filter');
- }
- $this->view->editfilterform = $editfilterform;
- }catch (Zend_Exception $e) {
- echo "Error message 2: " . $e->getMessage() . "\n";
- }
- }
- }
-
- public function addfilterentryAction()
- {
- // TODO: ACL implementieren ob er editieren darf
- if (!isset($_POST["add"])){
- try{
- $editfilterform = new Application_Form_FilterEntriesAdd(
- array( 'buttontext' => 'Add Filterentry',
- 'filterID' => $this->_request->getParam('filterID'),
- 'data' => $_POST
- ));
- $editfilterform->populate($_POST);
- $this->view->editfilterform = $editfilterform;
- }catch (Zend_Exception $e) {
- echo "Error message 2: " . $e->getMessage() . "\n";
- }
- } else{
- $editfilterform = new Application_Form_FilterEntriesAdd(array('buttontext' => 'Add Filterentry'),$_POST);
- if ($editfilterform->isValid($_POST)) {
- $newfilterenty = new Application_Model_FilterEntries();
- $newfilterenty->setFilterID($_POST['filterID']);
- $newfilterenty->setFiltertypeID($_POST['filtertypeID']);
-
- if($_POST['filtertypeID'] == 1){
- $newfilterenty->setFiltervalue($this->fillIP($_POST['filtervalue']));
- $newfilterenty->setFiltervalue2($this->fillIP($_POST['filtervalue2']));
- }
- else{
- $newfilterenty->setFiltervalue($_POST['filtervalue']);
- $newfilterenty->setFiltervalue2($_POST['filtervalue2']);
- }
-
- $newfilter2 = new Application_Model_FilterEntriesMapper();
- $newfilter2->save($newfilterenty);
- #print_a($newfilterenty);
- $this->_redirect('/filter');
- }
- $this->view->editfilterform = $editfilterform;
- }
- }
-
- public function editfilterentryAction()
- {
- if (!isset($_POST["add"])){
- try{
- $filterentriesID = $this->_request->getParam('filterentriesID');
-
- $filterentry = new Application_Model_FilterEntries();
-
- $filterentriesmapper = new Application_Model_FilterEntriesMapper();
- $filterentriesmapper->find($filterentriesID,$filterentry);
-
-
-
- #$editfilterform->setFilterID($filterID);
- if(isset($_POST['filtertypeID']) && $_POST['filtertypeID'] != $filterentry->getFiltertypeID()){
- $filterentry->setFiltertypeID($_POST['filtertypeID']) ;
- }
- $data = $filterentry->toArray();
- print_a($data);
- $editfilterform = new Application_Form_FilterEntriesAdd(
- array('buttontext' => 'Edit Filterentry',
- 'data' => $data));
-
- $editfilterform->populate($filterentry->toArray());
- $this->view->editfilterform = $editfilterform;
-
- }catch (Zend_Exception $e) {
- echo "Error message 2: " . $e->getMessage() . "\n";
- }
- } else{
- try{
- $filterentriesID = $this->_request->getParam('filterentriesID');
- $editfilterform = new Application_Form_FilterEntriesAdd(array('buttontext' => 'Edit Filterentry'),$_POST);
- if ($editfilterform->isValid($_POST)) {
- if($_POST['filterID'] == '')
- unset($_POST['filterID']);
- $newfilterenty = new Application_Model_FilterEntries($_POST);
- $newfilterenty->setID($filterentriesID);
- if($_POST['filtertypeID'] == 1){
- $newfilterenty->setFiltervalue($this->fillIP($_POST['filtervalue']));
- $newfilterenty->setFiltervalue2($this->fillIP($_POST['filtervalue2']));
- }
- else{
- $newfilterenty->setFiltervalue($_POST['filtervalue']);
- $newfilterenty->setFiltervalue2($_POST['filtervalue2']);
- }
- $newfilter2 = new Application_Model_FilterEntriesMapper();
- $newfilter2->save($newfilterenty);
- #print_a($newfilterenty);
- $this->_redirect('/filter');
-
- }
- $this->view->editfilterform = $editfilterform;
- }catch (Zend_Exception $e) {
- echo "Error message 2: " . $e->getMessage() . "\n";
- }
- }
- }
-
- public function removefilterentryAction()
- {
- try{
- $filterentriesID = $this->_request->getParam('filterentriesID');
-
- // TODO: ACL implementieren ob er den filter löschen darf
- if(is_numeric($filterentriesID)){
- $deletefilterentry = new Application_Model_FilterEntries();
- $deletefilterentry->setID($filterentriesID);
- echo "<pre style='border:1px solid black;background-color:#F5B800'>";
- print_r($deletefilterentry);
- echo "</pre>";
-
- $filterentriesmapper = new Application_Model_FilterEntriesMapper();
- $filterentriesmapper->delete($deletefilterentry);
- echo "ok";
- }
- $this->_redirect('/filter');
- }catch (Zend_Exception $e) {
- echo "Error message 2: " . $e->getMessage() . "\n";
- }
- }
-
- private function fillIP($ip)
- {
- $ar = explode(".",$ip);
- $representation = array();
- foreach($ar as $part){
- $representation[] = sprintf("%03s",$part);
- }
- return implode(".",$representation);
- }
-
- private function fillMac($ip)
- {
- $ar = explode(":",$ip);
- $representation = array();
- foreach($ar as $part){
- $representation[] = sprintf("%02s",$part);
- }
- return implode(":",$representation);
- }
-
- public function evaluateAction()
- {
- $db = $this->db;
- $showPartResults = false;
- // For Testing Filters
-
-
- $testFilter = (isset($_POST['submit']))?true:false;
-
- if($testFilter){
- $ipAdress = $_POST['ip'];
- $macAdress = $_POST['mac'];
- $poolID = $_POST['poolID'];
- $bootisoID = $_POST['bootisoID'];
- $membershipID = $_POST['membershipID'];
- $groupID = $_POST['groupID'];
- $time = ($_POST['time']);
- $clientID = $_POST['clientID'];
- $weekday = $_POST['weekday'];
- $date = $_POST['date'];
- print_a('Input',
- array('ipAdress'=>$ipAdress,
- 'macAdress'=>$macAdress,
- 'poolID' => $poolID,
- 'bootisoID' => $bootisoID,
- 'membershipID'=>$membershipID,
- 'groupID'=>$groupID,
- 'time'=> $time." - ".date('d.m.Y H:i:s',$time),
- 'clientID' => $clientID,
- 'hardwarehash' => $hardwarehash,
- 'weekday' => $weekday,
- 'date' => $date));
- }
-
-
- try{
- $mysession = '1';
- $set = array();
-
-
- $session = new Application_Model_Session();
- $sessionmapper = new Application_Model_SessionMapper();
- $sessionmapper->find($mysession,$session);
- #########################################################
- // IP Adress
- $filtertypID = 1;
- // get it from session_table with session_id from the session
- if(!$testFilter){
- $ipAdress = $session->getIp();
- }
- $ipAdress = str_replace(".","",$this->fillIP($ipAdress));
-
- $select = $db->select()
- ->from(array('pbs_filterentries')
- )
- ->where('filtertypeID = ?',$filtertypID)
- ->where('REPLACE(filtervalue,".","") <= ?',$ipAdress)
- ->where('? <= REPLACE(filtervalue2,".","")',$ipAdress);
-
- $stmt = $select->query();
- $result = $stmt->fetchAll();
- foreach($result as $r){
- $set[$filtertypID][] = $r['filterID'];
- }
-
- if($showPartResults)
- print_a('ipAdress',$result,$set[$filtertypID]);
-
- #########################################################
- // Mac range
- $filtertypID = 2;
- // get it from session_table with session_id from the session
- if(!$testFilter){
- $client = new Application_Model_Client();
- $clientmapper = new Application_Model_ClientMapper();
- $clientmapper->find($session->getClientID(),$client);
- $macAdress = $client->getMacadress();
- }
- try{
- $macAdress = $this->fillMac($macAdress);
- $stmt = $db->query("SELECT * FROM pbs_filterentries WHERE
- filtertypeID = ".$filtertypID." AND
- filtervalue <= '".$macAdress."' AND
- '".$macAdress."' <= filtervalue2");
- $result = $stmt->fetchAll();
- foreach($result as $r){
- $set[$filtertypID][] = $r['filterID'];
- }
- }
- catch(Exception $e){}
- if($showPartResults)
- print_a('macAdress',$result,$set[$filtertypID]);
-
- #########################################################
- // PoolID
- $filtertypID = 3;
- // get PoolID from client_ID from session_id from the session
- if(!$testFilter){
- $poolentry = new Application_Model_PoolEntries();
- $poolentrymapper = new Application_Model_PoolEntriesMapper();
- $poolentry = $poolentrymapper->findby('clientID',$client->getID());
- $poolentry = $poolentry[0];
-
- $poolID = $poolentry['poolID'];
- }
-
- try{
- $stmt = $db->query("SELECT * FROM pbs_filterentries WHERE
- filtertypeID = ".$filtertypID." AND
- filtervalue = ".$poolID." ");
- $result = $stmt->fetchAll();
- if(count($result)>0){
- foreach($result as $r){
- $set[$filtertypID][] = $r['filterID'];
- }
- }
- }
- catch(Exception $e){}
-
- if($showPartResults)
- print_a('poolID',$result,$set[$filtertypID]);
- #########################################################
- // ClientID
- $filtertypID = 8;
- // get client_ID from session_id from the session
-
- if(!$testFilter){
- $clientID = $session->getClientID();
- }
- try{
- $stmt = $db->query("SELECT * FROM pbs_filterentries WHERE
- filtertypeID = ".$filtertypID." AND
- filtervalue = ".$clientID." ");
- $result = $stmt->fetchAll();
- foreach($result as $r){
- $set[$filtertypID][] = $r['filterID'];
- }
- }
- catch(Exception $e){}
-
- if($showPartResults)
- print_a('clientID',$result,$set[$filtertypID]);
- #########################################################
- // BootIsoID
- $filtertypID = 4;
- // get BootIsoID from client_ID from session_id from the session
- if(!$testFilter){
- $bootisoID = $session->getBootisoID();
- }
- try{
- $stmt = $db->query("SELECT * FROM pbs_filterentries WHERE
- filtertypeID = ".$filtertypID." AND
- filtervalue = ".$bootisoID." ");
- $result = $stmt->fetchAll();
- foreach($result as $r){
- $set[$filtertypID][] = $r['filterID'];
- }
- }
- catch(Exception $e){}
-
- if($showPartResults)
- print_a('bootisoID',$result,$set[$filtertypID]);
- #########################################################
- // MembershipID
- $filtertypID = 5;
-
- if(!$testFilter){
- // get membership from the session
- //TODO: GET MEMBERSHIP from SESSION
- $membershipID = 1;
- }
- try{
- $stmt = $db->query("SELECT * FROM pbs_filterentries WHERE
- filtertypeID = ".$filtertypID." AND
- filtervalue = ".$membershipID." ");
- $result = $stmt->fetchAll();
- foreach($result as $r){
- $set[$filtertypID][] = $r['filterID'];
- }
- }
- catch(Exception $e){}
-
- if($showPartResults)
- print_a('membership',$result,$set[$filtertypID]);
- #########################################################
- // GroupID
- $filtertypID = 6;
-
- if(!$testFilter){
- // get membership from the session
- //TODO: GET GROUP from SESSION
- $groupID = 1;
- }
- try{
- $stmt = $db->query("SELECT * FROM pbs_filterentries WHERE
- filtertypeID = ".$filtertypID." AND
- filtervalue = ".$groupID." ");
- $result = $stmt->fetchAll();
- foreach($result as $r){
- $set[$filtertypID][] = $r['filterID'];
- }
- }
- catch(Exception $e){}
-
- if($showPartResults)
- print_a('membership',$result,$set[$filtertypID]);
- #########################################################
- // Time
- $filtertypID = 7;
- if(!$testFilter){
- $time = time("H:i");
- }
-
- $nowShort = $time;
-
- $nowShort = str_replace(":","",$nowShort);
- try{
- $select = $db->select()
- ->from(array('pbs_filterentries')
- )
- ->where('filtertypeID = ?',$filtertypID)
- ->where('REPLACE(filtervalue,":","") <= ? AND ? <= REPLACE(filtervalue2,":","")',$nowShort);
-
- $stmt = $select->query();
- $result = $stmt->fetchAll();
- foreach($result as $r){
- $set[$filtertypID][] = $r['filterID'];
- }
- }
- catch(Exception $e){}
-
- if($showPartResults)
- print_a('time',$result,$set[$filtertypID]);
- #########################################################
- // Hardwarehash
- $filtertypID = 9;
- if(!$testFilter){
- // get hardwarehash from session
- $hardwarehash = 'aaaa';
- }
-
- try{
- $select = $db->select()
- ->from(array('pbs_filterentries')
- )
- ->where('filtertypeID = ?',$filtertypID)
- ->where('`filtervalue` = ?',$hardwarehash);
- $stmt = $select->query();
- $result = $stmt->fetchAll();
- foreach($result as $r){
- $set[$filtertypID][] = $r['filterID'];
- }
- }
- catch(Exception $e){}
-
- if($showPartResults)
- print_a('hardwarehash',$result,$set[$filtertypID]);
- #########################################################
- // weekday
- $filtertypID = 10;
- if(!$testFilter){
- $weekday = date('N');
- }
-
- try{
- $select = $db->select()
- ->from(array('pbs_filterentries')
- )
- ->where('filtertypeID = ?',$filtertypID)
- ->where('filtervalue = ? ',$weekday);
-
- $stmt = $select->query();
- $result = $stmt->fetchAll();
- foreach($result as $r){
- $set[$filtertypID][] = $r['filterID'];
- }
- }
- catch(Exception $e){}
-
- if($showPartResults)
- print_a('weekday',$result,$set[$filtertypID]);
- #########################################################
- // weekday
- $filtertypID = 11;
- if(!$testFilter){
- $date = date('d.m.Y');
- }
-
- try{
- $select = $db->select()
- ->from(array('pbs_filterentries')
- )
- ->where('filtertypeID = ?',$filtertypID)
- ->where('REPLACE(filtervalue,".","") <= ? AND ? <= REPLACE(filtervalue2,".","")',$date);
-
- $stmt = $select->query();
- $result = $stmt->fetchAll();
- foreach($result as $r){
- $set[$filtertypID][] = $r['filterID'];
- }
- }
- catch(Exception $e){}
-
- if($showPartResults)
- print_a('weekday',$result,$set[$filtertypID]);
- ########################################
- // ErgebnisSet auswerten
- print_a('the result sets of the filtertypes',$set);
-
- // Merging of the resultsets of the filter
- $kk = array();
- foreach($set as $myset){
- $kk = array_merge($kk,$myset);
- }
- $set = $kk;
- // counting how often a filter is evaluated at database
- $a = array();
- foreach($set as $k=> $s){
- $a[$s] += 1;
- }
- print_a('Übereinstimmungen pro Filter',$a);
- // Get the number of filtertypes every filter has
- $stmt = $db->query('SELECT filterID, COUNT(filtertypeID) as num FROM pbs_filterentries GROUP BY filterID');
- $resultset = $stmt->fetchAll();
- foreach($resultset as $d){
- $database[$d['filterID']] = $d['num'];
- }
- print_a('Anzahl Filterentries in Datenbank',$database);
-
- // remove all filters from resultset, which to few filtertypes satisfied
- $result = array();
- foreach($a as $i=>$b){
- if($a[$i] < $database[$i]){
- unset($a[$i]);
- }
- else{
- $result[] = $i;
- }
- }
-
- print_a('True Filters',$result);
- // now selecting the filter with the highest priority
- $query = 'SELECT filterID, bootmenuID, priority
- FROM pbs_filter WHERE ';
- foreach($result as $e){
- $queryTmp[] = "filterID = '$e'";
- }
- $query .= implode(" OR ", $queryTmp);
- $query .= 'ORDER BY priority DESC LIMIT 0,1';
- $bootmenuID = 'null';
- try{
- $stmt = $db->query($query);
- $resultset = $stmt->fetchAll();
- $bootmenuID = $resultset[0]['bootmenuID'];
- }
- catch(Exception $e){
- }
- if($bootmenuID != 'null'){
- $bm = new Application_Model_BootMenu();
- $bmmapper = new Application_Model_BootMenuMapper();
- $bmmapper->find($bootmenuID,$bm);
- echo "<h1><a href='/bootmenu/index/bootmenuid/".$bootmenuID."'>Goto BootmenuID: ".$bootmenuID."</a></h1>";
- }
- else{
- echo "<h1>No Result :-(</h1>";
- }
-
- }catch (Zend_Exception $e) {
- echo "class: ".get_class($e)."<br>\n";
- echo "Error message 2: " . $e->getMessage() . "\n";
- }
- }
-
- public function testevaluateAction()
- {
- $pm = new Application_Model_PoolMapper();
- $pools = $pm->fetchAll();
-
- $bim = new Application_Model_BootIsoMapper();
- $bootisos = $bim->fetchAll();
-
- $mm = new Application_Model_MembershipMapper();
- $memberships = $mm->fetchAll();
-
- $gm = new Application_Model_GroupMapper();
- $groups = $gm->fetchAll();
-
- $cm = new Application_Model_ClientMapper();
- $clients = $cm->fetchAll();
-
- $filterevaluate = new Application_Form_FilterEvaluate(
- array( 'pools' => $pools,
- 'bootisos' => $bootisos,
- 'memberships' => $memberships,
- 'groups' => $groups,
- 'clients' => $clients,
-
- ));
- $filterevaluate->populate(array(
- 'ip' => '132.230.5.6',
- 'mac' => '08:00:20:ae:fd:7e',
- 'time'=>date('d.m.Y H:i'))
- );
- $this->view->filterevaluate = $filterevaluate;
- }
-
-
-}
-
-
-
-
-
-
-
-
-
-
-