From 1e3fc3def6918568f4e36026c46feadbe3c24e7c Mon Sep 17 00:00:00 2001 From: Simon Date: Sun, 6 Mar 2011 18:24:42 +0100 Subject: print_a funktion zum debugging hinzugefügt damit sie von überall benutzbar ist && evaluate in Filter zu großen Teilen fertig, ebenso die Auswertung, welche BootMenuID zurückgegeben werden soll --- application/controllers/FilterController.php | 181 +++++++++++++++++++++------ 1 file changed, 142 insertions(+), 39 deletions(-) (limited to 'application/controllers/FilterController.php') diff --git a/application/controllers/FilterController.php b/application/controllers/FilterController.php index 55188cf..ab24ce2 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() @@ -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 + $filtertypID = 6; + /* - */ - ######################################################### - // Group - ######################################################### - // Time - /* + */ + ######################################################### + // 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 "

".$resultset[0]['bootmenuID']."

"; + + }catch (Zend_Exception $e) { + echo "class: ".get_class($e)."
\n"; + echo "Error message 2: " . $e->getMessage() . "\n"; + } } } -- cgit v1.2.3-55-g7522 From dee12ef18da0dc4db4f1a87c62aa98d321b76bac Mon Sep 17 00:00:00 2001 From: Simon Date: Sun, 6 Mar 2011 19:56:24 +0100 Subject: clients hinzufügen und entfernen && sql-data erweitert --- .zfproject.xml | 4 +++ application/controllers/ClientController.php | 33 ++++++++++++++++++-- application/controllers/FilterController.php | 4 +-- application/forms/FilterAdd.php | 2 ++ application/views/scripts/client/index.phtml | 35 +++++++++++++++++++++- .../views/scripts/client/removeclient.phtml | 1 + pbs-data.sql | 34 +++++++++++++++++---- 7 files changed, 103 insertions(+), 10 deletions(-) create mode 100644 application/views/scripts/client/removeclient.phtml (limited to 'application/controllers/FilterController.php') diff --git a/.zfproject.xml b/.zfproject.xml index 372f431..adfe5d7 100644 --- a/.zfproject.xml +++ b/.zfproject.xml @@ -57,6 +57,7 @@ + @@ -238,6 +239,9 @@ + + + diff --git a/application/controllers/ClientController.php b/application/controllers/ClientController.php index 6c72fc3..336bf9e 100644 --- a/application/controllers/ClientController.php +++ b/application/controllers/ClientController.php @@ -10,12 +10,39 @@ class ClientController extends Zend_Controller_Action public function indexAction() { - // action body + $clientMapper = new Application_Model_ClientMapper(); + $this->view->clients = $clientMapper->fetchAll(); } public function addclientAction() { - // action body + $mac = $this->_request->getParam('mac'); + $hh = $this->_request->getParam('hh'); + + if($mac != '' && $hh != ''){ + $client = new Application_Model_Client(); + $client->setMacadress($mac); + $client->setHardwarehash($hh); + $clientmapper = new Application_Model_ClientMapper(); + $clientmapper->save($client); + print_a('inserted'); + } + else{ + print_a('no insert'); + } + } + + public function removeclientAction() + { + $clientID = $this->_request->getParam('clientID'); + // TODO: ACL implementieren ob er den filter löschen darf + if(is_numeric($clientID)){ + $removeClient = new Application_Model_Client(); + $removeClient->setID($clientID); + $clientMapper = new Application_Model_ClientMapper(); + $clientMapper->delete($removeClient); + } + $this->_redirect('/client'); } @@ -23,3 +50,5 @@ class ClientController extends Zend_Controller_Action + + diff --git a/application/controllers/FilterController.php b/application/controllers/FilterController.php index ab24ce2..1305689 100644 --- a/application/controllers/FilterController.php +++ b/application/controllers/FilterController.php @@ -25,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() diff --git a/application/forms/FilterAdd.php b/application/forms/FilterAdd.php index 43efb71..931bfee 100644 --- a/application/forms/FilterAdd.php +++ b/application/forms/FilterAdd.php @@ -21,6 +21,8 @@ class Application_Form_FilterAdd extends Zend_Form 'required' => false, 'label' => 'Description:', )); + // TODO: Add target of Filter + $this->addElement('text', 'priority', array( 'filters' => array('StringTrim'), 'validators' => array( diff --git a/application/views/scripts/client/index.phtml b/application/views/scripts/client/index.phtml index 4f0e6ec..4095a5f 100644 --- a/application/views/scripts/client/index.phtml +++ b/application/views/scripts/client/index.phtml @@ -1 +1,34 @@ -

View script for controller Client and script/action name index
\ No newline at end of file +

Clients

+ +clients): ?> + + + + + + + + + clients as $client): ?> + + + + + + + +
clientIDMACHardwarehash
escape($client->getID()) ?>escape($client->getMacadress()) ?>escape($client->getHardwarehash()) ?>remove client
+ + + + +

There are no clients to display.

+ + diff --git a/application/views/scripts/client/removeclient.phtml b/application/views/scripts/client/removeclient.phtml new file mode 100644 index 0000000..7b5f64f --- /dev/null +++ b/application/views/scripts/client/removeclient.phtml @@ -0,0 +1 @@ +

View script for controller Client and script/action name deleteclient
\ No newline at end of file diff --git a/pbs-data.sql b/pbs-data.sql index b93c679..e3cef5f 100644 --- a/pbs-data.sql +++ b/pbs-data.sql @@ -11,12 +11,36 @@ INSERT INTO `pbs`.`pbs_filtertype` (`filtertypeID`, `filtertypename`) VALUES (NU INSERT INTO `pbs`.`pbs_filtertype` (`filtertypeID`, `filtertypename`) VALUES (NULL, 'Time'); -- Insert example data for filters - INSERT INTO `pbs`.`pbs_group` (`groupID` ,`title` ,`description`)VALUES (NULL , 'testgruppe1', NULL); INSERT INTO `pbs`.`pbs_person` (`personID`, `title`, `name`, `firstname`, `street`, `housenumber`, `city`, `postalcode`, `logindate`, `registerdate`, `email`, `login`, `password`, `password_salt`) VALUES (NULL, 'Mr.Test', 'te', 'st', NULL, NULL, NULL, NULL, NULL, '', '', 'test', '', ''); INSERT INTO `pbs`.`pbs_role` (`roleID`, `groupID`, `title`, `description`) VALUES (NULL, '1', 'Testrolle', NULL); INSERT INTO `pbs`.`pbs_membership` (`membershipID`, `groupID`, `roleID`, `personID`) VALUES (NULL, '1', '1', '1'); -INSERT INTO `pbs`.`pbs_bootmenu` (`bootmenuID`, `membershipID`, `title`, `time`) VALUES (NULL, '1', 'Bootmenu1', UNIX_TIMESTAMP()); -INSERT INTO `pbs`.`pbs_bootmenu` (`bootmenuID`, `membershipID`, `title`, `time`) VALUES (NULL, '1', 'Bootmenu2', UNIX_TIMESTAMP()); -INSERT INTO `pbs`.`pbs_filter` (`filterID`, `membershipID`, `groupID`, `bootmenuID`, `title`, `description`, `created`, `priority`) VALUES (NULL, '1', '1', '1', 'Regel 1', NULL, UNIX_TIMESTAMP(), '1'); -INSERT INTO `pbs`.`pbs_filter` (`filterID`, `membershipID`, `groupID`, `bootmenuID`, `title`, `description`, `created`, `priority`) VALUES (NULL, '1', '1', '2', 'Regel 2', NULL, UNIX_TIMESTAMP(), '5'); + +INSERT INTO `pbs`.`pbs_bootmenu` (`bootmenuID`, `membershipID`, `groupID`, `title`, `created`) VALUES (NULL, '1', '1', 'Bootmenu 1', UNIX_TIMESTAMP()); +INSERT INTO `pbs`.`pbs_bootmenu` (`bootmenuID`, `membershipID`, `groupID`, `title`, `created`) VALUES (NULL, '1', '1', 'Bootmenu 2', UNIX_TIMESTAMP()); +INSERT INTO `pbs`.`pbs_bootmenu` (`bootmenuID`, `membershipID`, `groupID`, `title`, `created`) VALUES (NULL, '1', '1', 'Bootmenu 3', UNIX_TIMESTAMP()); + +INSERT INTO `pbs`.`pbs_filter` (`filterID`, `membershipID`, `groupID`, `bootmenuID`, `title`, `description`, `created`, `priority`) VALUES (NULL, '1', '1', '1', 'Filter 1', NULL, UNIX_TIMESTAMP(), '1'); +INSERT INTO `pbs`.`pbs_filter` (`filterID`, `membershipID`, `groupID`, `bootmenuID`, `title`, `description`, `created`, `priority`) VALUES (NULL, '1', '1', '2', 'Filter 2', NULL, UNIX_TIMESTAMP(), '5'); +INSERT INTO `pbs`.`pbs_filter` (`filterID`, `membershipID`, `groupID`, `bootmenuID`, `title`, `description`, `created`, `priority`) VALUES (NULL, '1', '1', '2', 'Filter 3', NULL, UNIX_TIMESTAMP(), '9'); + +INSERT INTO `pbs_filterentries` (`filterentriesID`, `filterID`, `filtertypeID`, `filtervalue`, `filtervalue2`) VALUES +(1, 1, 1, '100.100.100.100', '200.200.200.200'), +(3, 1, 7, '08-00', '22-00'), +(4, 2, 7, '08-00', '19-00'), +(5, 3, 7, '12-00', '18-00'), +(6, 3, 2, '00:1e:0b:27:f4:00', '00:1e:0b:27:f4:f0'); + +-- Inser example data for clients and pools +INSERT INTO `pbs_client` (`clientID`, `macadress`, `hardwarehash`) VALUES +(1, '00:1e:0b:27:f4:99', 'ea9b82d9de911bc2d3cd23f53a6cab48'), +(2, '00:10:0a:25:44:69', '1e2b1599710fbbef0dc789e8cfe12455'), +(3, '01:50:2a:24:42:60', '8f6209ca3d6b35e223a11c249d1b69fc'), +(4, '04:34:26:9a:92:90', 'e17ab09f3586464f19629e2e8b1e9a9d'), +(5, '44:74:26:9a:92:90', '9bf70279d283b85440c2031c19bb6812'), +(6, '64:24:26:9a:92:90', 'ad3bce4464a6267441ec144744439c7e'), +(7, '84:94:26:9a:92:90', 'e8d7e80d79f224771b7a3a0af4e02748'), +(8, 'b4:84:26:9a:92:90', 'ded66ce272f384e9e386c1b57ded3e4d'), +(9, '24:64:26:9a:92:90', '695610ee509c060b1fca9c8011529af4'), +(10, '84:34:26:9a:92:90', 'a3562c8cad2a4fa4fc11656025dc911b'); + -- cgit v1.2.3-55-g7522