summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--application/controllers/ResourceController.php2
-rw-r--r--application/models/Client.php70
-rw-r--r--application/models/ClientMapper.php100
-rw-r--r--setup/pbs-newdata.sql31
-rw-r--r--setup/pbs.sql2
5 files changed, 125 insertions, 80 deletions
diff --git a/application/controllers/ResourceController.php b/application/controllers/ResourceController.php
index 6dd3923..a6d4cc7 100644
--- a/application/controllers/ResourceController.php
+++ b/application/controllers/ResourceController.php
@@ -944,6 +944,8 @@ class ResourceController extends Zend_Controller_Action
$xml .= "\t\t\t\t\t<clientID>" . $client->getID() . "</clientID>\n";
$xml .= "\t\t\t\t\t<groupID>" . $client->getGroupID() . "</groupID>\n";
$xml .= "\t\t\t\t\t<macadress>" . $client->getMacadress() . "</macadress>\n";
+ $xml .= "\t\t\t\t\t<ip>" . $client->getIp() . "</ip>\n";
+ $xml .= "\t\t\t\t\t<ip6>" . $client->getIp6() . "</ip6>\n";
$xml .= "\t\t\t\t\t<hardwarehash>" . $client->getHardwarehash() . "</hardwarehash>\n";
$xml .= "\t\t\t\t\t<created>" . $client->getCreated() . "</created>\n";
$xml .= "\t\t\t\t</client>\n";
diff --git a/application/models/Client.php b/application/models/Client.php
index e8108ef..a32e6ce 100644
--- a/application/models/Client.php
+++ b/application/models/Client.php
@@ -16,6 +16,8 @@ class Application_Model_Client
protected $_groupID;
protected $_macadress;
protected $_hardwarehash;
+ protected $_ip;
+ protected $_ip6;
protected $_created;
public function __construct(array $options = null)
@@ -83,6 +85,24 @@ class Application_Model_Client
$this->_macadress = $_macadress;
return $this;
}
+ public function getIp()
+ {
+ return $this->_ip;
+ }
+ public function setIp($_ip)
+ {
+ $this->_ip = $_ip;
+ return $this;
+ }
+ public function getIp6()
+ {
+ return $this->_ip6;
+ }
+ public function setIp6($_ip6)
+ {
+ $this->_ip6 = $_ip6;
+ return $this;
+ }
public function getHardwarehash()
{
return $this->_hardwarehash;
@@ -101,39 +121,39 @@ class Application_Model_Client
$this->_created = $_created;
return $this;
}
- /**
- * Returns current data as associative array using ReflectionClass
- *
- * @return array Returns associative array containing model data
+ /**
+ * Returns current data as associative array using ReflectionClass
+ *
+ * @return array Returns associative array containing model data
* If "get"-method not available (our primary keys) the function getID() is called
- */
- public function toArray()
- {
- $reflectionClass = new ReflectionClass($this);
- $properties = $reflectionClass->getProperties();
- $result = array();
- foreach ($properties as $property) {
- $key = $property->name;
- if (substr($key, 0, 1) != '_' && $this->$key !== null) {
- $method = 'get' . ucfirst($key);
- if ($reflectionClass->hasMethod($method)) {
- $result[$key] = $this->$method();
- } else {
- $result[$key] = $this->$key;
- }
- }
+ */
+ public function toArray()
+ {
+ $reflectionClass = new ReflectionClass($this);
+ $properties = $reflectionClass->getProperties();
+ $result = array();
+ foreach ($properties as $property) {
+ $key = $property->name;
+ if (substr($key, 0, 1) != '_' && $this->$key !== null) {
+ $method = 'get' . ucfirst($key);
+ if ($reflectionClass->hasMethod($method)) {
+ $result[$key] = $this->$method();
+ } else {
+ $result[$key] = $this->$key;
+ }
+ }
elseif(substr($key, 0, 1) == '_' && $this->$key !== null) {
$key = substr($key, 1);
- $method = 'get' . ucfirst($key);
+ $method = 'get' . ucfirst($key);
if ($reflectionClass->hasMethod($method)) {
$result[$key] = $this->$method();
}else{
$result[$key] = $this->getID();
}
-
+
}
- }
- return $result;
- }
+ }
+ return $result;
+ }
}
diff --git a/application/models/ClientMapper.php b/application/models/ClientMapper.php
index bcb3286..4a36a70 100644
--- a/application/models/ClientMapper.php
+++ b/application/models/ClientMapper.php
@@ -12,34 +12,34 @@
class Application_Model_ClientMapper
{
-
+
protected $_dbTable;
- public function findBy($where, $array=false, $order=false)
- {
+ public function findBy($where, $array=false, $order=false)
+ {
foreach($where as $k => $v){
if($v != null)
- $where2[] = "$k = '$v'";
- else
- $where2[] = "$k IS NULL";
+ $where2[] = "$k = '$v'";
+ else
+ $where2[] = "$k IS NULL";
}
$where = implode(" AND " ,$where2);
-
- try{
+
+ try{
$db = Zend_Db_Table::getDefaultAdapter();
- $select = $this->getDbTable()->select()
- ->from($this->_dbTable)
- ->where($where);
-
+ $select = $this->getDbTable()->select()
+ ->from($this->_dbTable)
+ ->where($where);
+
if(is_array($order)){
foreach ($order as $k => $v)
- $a[] = "$k $v";
+ $a[] = "$k $v";
$select->order($a);
}
-
+
$stmt = $select->query();
$result = $stmt->fetchAll();
-
+
if(!$array){
$entries = array();
foreach ($result as $row) {
@@ -51,11 +51,11 @@ class Application_Model_ClientMapper
}else{
return $result;
}
-
- }catch (Zend_Exception $e) {
- echo "Error message 2: " . $e->getMessage() . "\n";
+
+ }catch (Zend_Exception $e) {
+ echo "Error message 2: " . $e->getMessage() . "\n";
}
- }
+ }
public function setDbTable($dbTable)
{
@@ -68,7 +68,7 @@ class Application_Model_ClientMapper
}
$this->_dbTable = $dbTable;
-
+
return $this;
}
@@ -77,19 +77,21 @@ class Application_Model_ClientMapper
if (null === $this->_dbTable) {
$this->setDbTable('Application_Model_DbTable_Client');
}
-
+
return $this->_dbTable;
}
public function save(Application_Model_Client $client)
{
-
+
$data = array('clientID'=> $client->getID() ,
'groupID' => $client->getGroupID(),
'macadress'=> $client->getMacadress() ,
'hardwarehash'=> $client->getHardwarehash(),
+ 'ip' => $client->getIp(),
+ 'ip6' => $client->getIp6(),
'created'=> $client->getCreated()
- );
+ );
if (null === ($id = $client->getID()) ) {
unset($data['clientID']);
@@ -98,7 +100,7 @@ class Application_Model_ClientMapper
return $this->getDbTable()->update($data, array('clientID = ?' => $id));
}
}
-
+
public function delete(Application_Model_Client $client)
{
if (null === ($id = $client->getID()) ) {
@@ -108,20 +110,38 @@ class Application_Model_ClientMapper
}
}
- public function find($id, Application_Model_Client $client)
+ public function find($id, Application_Model_Client $client = null)
{
$result = $this->getDbTable()->find($id);
if (0 == count($result)) {
return;
}
+ if($client != null) {
+ $return = true;
+ }
+
$row = $result->current();
-
- $client->setID($row->clientID)
- ->setGroupID($row->groupID)
- ->setMacadress($row->macadress)
- ->setHardwarehash($row->hardwarehash)
- ->setCreated($row->created);
+
+ if($return) {
+ $client = new Application_Model_Client;
+ $client->setID($row->clientID)
+ ->setGroupID($row->groupID)
+ ->setMacadress($row->macadress)
+ ->setIp($row->ip)
+ ->setIp6($row->ip6)
+ ->setHardwarehash($row->hardwarehash)
+ ->setCreated($row->created);
+ return $client;
+ } else {
+ $client->setID($row->clientID)
+ ->setGroupID($row->groupID)
+ ->setMacadress($row->macadress)
+ ->setIp($row->ip)
+ ->setIp6($row->ip6)
+ ->setHardwarehash($row->hardwarehash)
+ ->setCreated($row->created);
+ }
}
public function fetchAll()
@@ -130,24 +150,26 @@ class Application_Model_ClientMapper
$entries = array();
foreach ($resultSet as $row) {
$entry = new Application_Model_Client();
-
+
$entry->setID($row->clientID)
- ->setGroupID($row->groupID)
- ->setMacadress($row->macadress)
- ->setHardwarehash($row->hardwarehash)
- ->setCreated($row->created);
+ ->setGroupID($row->groupID)
+ ->setMacadress($row->macadress)
+ ->setIp($row->ip)
+ ->setIp6($row->ip6)
+ ->setHardwarehash($row->hardwarehash)
+ ->setCreated($row->created);
$entries[] = $entry;
}
return $entries;
- }
-
+ }
+
public function compare(Application_Model_Client $v1,Application_Model_Client $v2){
$vv1 = $v1->toArray();
$vv2 = $v2->toArray();
return array_diff($vv1,$vv2);
}
-
+
}
diff --git a/setup/pbs-newdata.sql b/setup/pbs-newdata.sql
index ecc6117..17de9bd 100644
--- a/setup/pbs-newdata.sql
+++ b/setup/pbs-newdata.sql
@@ -37,22 +37,21 @@ INSERT INTO `pbs_membership` (`membershipID`, `groupID`, `roleID`, `personID`, `
INSERT INTO `pbs_membership` (`membershipID`, `groupID`, `roleID`, `personID`, `apikey`) VALUES (NULL, '8', '1', '1', 'apikey8');
-- Adding clients
-INSERT INTO `pbs_client` (`clientID`, `groupID`,`macadress`, `hardwarehash`) VALUES
-(1, 1, 'a5:9a:0f:94:2a:b0', 'ea9b82d9de911bc2d3cd23f53a6cab48'),
-(2, 1, '91:91:f1:e2:99:aa', '1e2b1599710fbbef0dc789e8cfe12455'),
-(3, 1, '6e:5c:82:78:f2:39', '8f6209ca3d6b35e223a11c249d1b69fc'),
-(4, 1, '67:75:e9:f2:5f:8e', 'e17ab09f3586464f19629e2e8b1e9a9d'),
-(5, 1, '63:51:7e:22:aa:72', '9bf70279d283b85440c2031c19bb6812'),
-(6, 1, '68:9e:fe:47:95:c5', 'ad3bce4464a6267441ec144744439c7e'),
-(7, 1, '6e:1c:2e:01:77:33', 'e8d7e80d79f224771b7a3a0af4e02748'),
-(8, 1, 'd1:91:20:43:2f:dd', 'ded66ce272f384e9e386c1b57ded3e4d'),
-(9, 1, '1b:0f:a5:82:47:16', '695610ee509c060b1fca9c8011529af4'),
-(10, 1, '56:8e:7b:03:5f:98', 'a3562c8cad2a4fa4fc11656025dc911b'),
-(11, 2, 'af:54:07:87:63:44', '98413218152196816519841365419816'),
-(12, 2, '87:21:74:52:96:20', '98741298132516132169813516981616'),
-(13, 2, '14:47:58:47:36:48', '32168132068132068513216053516513'),
-(14, 1, '64:46:85:A1:89:23', '9684216842068420616841asd6516984');
-
+INSERT INTO `pbs_client` (`clientID`, `groupID`,`macadress`, `hardwarehash`, `ip`, `ip6`) VALUES
+(1, 1, 'a5:9a:0f:94:2a:b0', 'ea9b82d9de911bc2d3cd23f53a6cab48', '132.230.5.6', ''),
+(2, 1, '91:91:f1:e2:99:aa', '1e2b1599710fbbef0dc789e8cfe12455', '', ''),
+(3, 1, '6e:5c:82:78:f2:39', '8f6209ca3d6b35e223a11c249d1b69fc', '', ''),
+(4, 1, '67:75:e9:f2:5f:8e', 'e17ab09f3586464f19629e2e8b1e9a9d', '84.23.56.86', ''),
+(5, 1, '63:51:7e:22:aa:72', '9bf70279d283b85440c2031c19bb6812', '70.81.94.222', ''),
+(6, 1, '68:9e:fe:47:95:c5', 'ad3bce4464a6267441ec144744439c7e', '210.84.65.2', ''),
+(7, 1, '6e:1c:2e:01:77:33', 'e8d7e80d79f224771b7a3a0af4e02748', '', ''),
+(8, 1, 'd1:91:20:43:2f:dd', 'ded66ce272f384e9e386c1b57ded3e4d', '', ''),
+(9, 1, '1b:0f:a5:82:47:16', '695610ee509c060b1fca9c8011529af4', '132.230.10.2', ''),
+(10, 1, '56:8e:7b:03:5f:98', 'a3562c8cad2a4fa4fc11656025dc911b', '132.20.20.2', ''),
+(11, 2, 'af:54:07:87:63:44', '98413218152196816519841365419816', '', ''),
+(12, 2, '87:21:74:52:96:20', '98741298132516132169813516981616', '', ''),
+(13, 2, '14:47:58:47:36:48', '32168132068132068513216053516513', '', ''),
+(14, 1, '64:46:85:A1:89:23', '9684216842068420616841asd6516984', '', '');
-- Adding bootos
INSERT INTO `pbs_bootos` (`bootosID`, `groupID`, `membershipID`, `title`, `description`, `defaultkcl`, `created`, `expires`, `public`, `source`, `distro`, `distroversion`, `shortname`, `share`) VALUES
diff --git a/setup/pbs.sql b/setup/pbs.sql
index 0ddf900..33682bc 100644
--- a/setup/pbs.sql
+++ b/setup/pbs.sql
@@ -264,6 +264,8 @@ ALTER TABLE `pbs_bootiso`
CREATE TABLE IF NOT EXISTS `pbs_client` (
`clientID` int(11) NOT NULL AUTO_INCREMENT,
`macadress` varchar(17) NOT NULL,
+ `ip` varchar(15) NOT NULL,
+ `ip6` varchar(45),
`hardwarehash` varchar(32),
`created` int(15),
PRIMARY KEY (`clientID`)