diff options
| author | michael pereira | 2011-03-06 20:12:43 +0100 |
|---|---|---|
| committer | michael pereira | 2011-03-06 20:12:43 +0100 |
| commit | c2e050df18557a3fe1093f0fef1685c2e631b95b (patch) | |
| tree | 532672f37cf928d0c2c81b6e3d55fd8cda7e393d /application/controllers/FilterController.php | |
| parent | datenbank erweitert, BootMenu, Config fertig (diff) | |
| parent | Pool add, edit und remove hinzugefügt (diff) | |
| download | pbs2-c2e050df18557a3fe1093f0fef1685c2e631b95b.tar.gz pbs2-c2e050df18557a3fe1093f0fef1685c2e631b95b.tar.xz pbs2-c2e050df18557a3fe1093f0fef1685c2e631b95b.zip | |
Merge branch 'master' of openslx.org:lsfks/master-teamprojekt/pbs2
Diffstat (limited to 'application/controllers/FilterController.php')
| -rw-r--r-- | application/controllers/FilterController.php | 185 |
1 files changed, 144 insertions, 41 deletions
diff --git a/application/controllers/FilterController.php b/application/controllers/FilterController.php index 55188cf..1305689 100644 --- a/application/controllers/FilterController.php +++ b/application/controllers/FilterController.php @@ -4,7 +4,7 @@ class FilterController extends Zend_Controller_Action { private $_filtermapper = null; - + private $db; public function init() { try{ @@ -12,6 +12,7 @@ class FilterController extends Zend_Controller_Action }catch (Zend_Exception $e) { echo "Error message 1: " . $e->getMessage() . "\n"; } + $this->db = Zend_Db_Table::getDefaultAdapter(); } public function indexAction() @@ -24,9 +25,9 @@ class FilterController extends Zend_Controller_Action $this->view->filterentries = $filterentries->fetchAll(); - }catch (Zend_Exception $e) { + }catch (Zend_Exception $e) { echo "Error message 2: " . $e->getMessage() . "\n"; - } + } } public function addfilterAction() @@ -254,48 +255,150 @@ class FilterController extends Zend_Controller_Action } return implode(".",$representation); } - public function evaluate(){ + 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; + try{ + ######################################################### + // IP Adress + $filtertypID = 1; + $ipAdress = "111.10.10.10"; + $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]); - // IP bereich - /* - $ipAdress = $this->fillIP('192.168.2.1'); - if( ( replace(".","",filtervalue) <= replace(".","",$ipAdress) - && replace(".","",$ipAdress) <= replace(".","",filtervalue2) - // resultset - */ - ######################################################### - // Mac bereich - /* - - */ - ######################################################### - // PoolID - /* - If client comes from a specific pool - */ - ######################################################### - // BootIso - /* - WHERE bootiso = bootiso - */ - ######################################################### - // Membership - /* + ######################################################### + // Mac range + $filtertypID = 2; + $macAdress = "00:1e:0b:27:f4:99"; + $macAdress = str_replace(":","",$this->fillMac($ipAdress)); + $stmt = $db->query("SELECT * FROM pbs_filterentries WHERE + filtertypeID = ".$filtertypID." AND + CONV(HEX('filtervalue'),16,10) <= CONV(HEX('".$macAdress."'),16,10) AND + CONV(HEX('".$macAdress."'),16,10) <= CONV(HEX('filtervalue2'),16,10)"); + $result = $stmt->fetchAll(); + foreach($result as $r){ + $set[$filtertypID][] = $r['filterID']; + } + if($showPartResults) + print_a('macAdress',$result,$set[$filtertypID]); + ######################################################### + // PoolID + $filtertypID = 3; + /* + If client comes from a specific pool + */ + ######################################################### + // BootIso + $filtertypID = 4; + /* + WHERE bootiso = bootiso + */ + ######################################################### + // Membership + $filtertypID = 5; + /* - */ - ######################################################### - // Group - ######################################################### - // Time - /* + */ + ######################################################### + // Group + $filtertypID = 6; + /* + + */ + ######################################################### + // Time + $filtertypID = 7; $nowShort = date('H-i',time()); $nowLong = date('Y-m-d-H-i',time()); - if( ( replace("-","",filtervalue) <= replace("-","",$nowShort) - && replace("-","",$nowShort) <= replace("-","",filtervalue2) - ||( replace("-","",filtervalue) <= replace("-","",$nowLong) - && replace("-","",$nowLong) <= replace("-","",filtervalue2)) - // resultset - */ + + $nowShort = str_replace("-","",$nowShort); + $nowLong = str_replace("-","",$nowLong); + + $select = $db->select() + ->from(array('pbs_filterentries') + ) + ->where('filtertypeID = ?',$filtertypID) + ->where('REPLACE(filtervalue,"-","") <= ? AND ? <= REPLACE(filtervalue2,"-","")',$nowShort) + ->orWhere('REPLACE(filtervalue,"-","") <= ? AND ? <= REPLACE(filtervalue2,"-","")',$nowLong); + + $stmt = $select->query(); + $result = $stmt->fetchAll(); + foreach($result as $r){ + $set[$filtertypID][] = $r['filterID']; + } + if($showPartResults) + print_a('time',$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 + foreach($set as $k=> $s){ + $a[$s] += 1; + } + + // 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']; + } + + // remove all filters from resultset, which to few filtertypes satisfied + foreach($a as $i=>$b){ + if($a[$i] < $database[$i]){ + unset($a[$i]); + } + else{ + $result[] = $i; + } + } + + print_a('result set of filterIDs',$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'; + $stmt = $db->query($query); + $resultset = $stmt->fetchAll(); + print_a($resultset); + echo "<h1>".$resultset[0]['bootmenuID']."</h1>"; + + }catch (Zend_Exception $e) { + echo "class: ".get_class($e)."<br>\n"; + echo "Error message 2: " . $e->getMessage() . "\n"; + } } } |
