From 09389b149c05033f14708d7535dee851f3fce0d8 Mon Sep 17 00:00:00 2001 From: Björn Geiger Date: Mon, 14 Nov 2011 17:51:28 +0100 Subject: EventController Cleaning: API in eigene Klasse ausgelagert --- library/Poolctrl/Pbs2Api.php | 289 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 289 insertions(+) create mode 100644 library/Poolctrl/Pbs2Api.php (limited to 'library/Poolctrl') diff --git a/library/Poolctrl/Pbs2Api.php b/library/Poolctrl/Pbs2Api.php new file mode 100644 index 0000000..be868a3 --- /dev/null +++ b/library/Poolctrl/Pbs2Api.php @@ -0,0 +1,289 @@ +config = $config; + $this->pbs2host = $this->config['pbs2']['host']; + $this->userIDsNamespace = Zend_Session::namespaceGet('userIDs'); + if(isset($this->userIDsNamespace['apikey'])) { + $this->acl = new Poolctrl_Acl($this->pbs2host, $this->config['pbs2']['checkright'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); + } + if(!$this->userIDsNamespace['membershipID'] !='') { + $this->_helper->redirector('selectmembership', 'person'); + return; + } + } + + private function runApi($host, $path, $data = null) { + if($data) { + $apiResult = PostToHost($host, $path . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $data); + } else { + $apiResult = PostToHost($host, $path . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', ''); + } + $xmlString = $bootOsApiResult['http-body']; + if(strlen($xmlString) > 0) { + $xml = new SimpleXMLElement($xmlString); + return $xml; + } else { + return new SimpleXMLElement(); + } + } + + public function getPool(&$poolist, $poolID = null) { + if(isset($poolID)) { + $poolRequest = "poolid=" . $poolID; + $poolXML = $this->runApi($this->pbs2host, $this->config['pbs2']['getpools'], $poolRequest); + } else { + $poolXML = $this->runApi($this->pbs2host, $this->config['pbs2']['getpools']); + } + if(isset($poolXML)) { + foreach($poolXML->poollist->pool as $pool) { + $poolobj = new Application_Model_Pool(); + $poolobj->setID(sprintf("%s", $pool->id)); + $poolobj->setDescription(sprintf("%s", $pool->description)); + $poolobj->setGroupID(sprintf("%s", $pool->groupid)); + $poolobj->setLocation(sprintf("%s", $pool->location)); + $poolobj->setTitle(sprintf("%s", $pool->title)); + $poollist[$poolobj->getID()] = $poolobj; + } + } + } + + public function getPoolClients(&$clientlist, $poolID) { + $poolRequest = "poolid=" . $poolID; + $poolXML = $this->runApi($this->pbs2host, $this->config['pbs2']['getpools'], $poolRequest); + if(isset($poolXML)) { + foreach($poolXML->poollist->pool as $pool) { + $clientsXML = $pool->clients; + foreach($clientsXML->client as $clientNew) { + $client = new Application_Model_Client(); + $client->setID(sprintf("%s", $clientNew->clientID)); + $client->setCreated(sprintf("%s", $clientNew->created)); + $client->setGroupID(sprintf("%s", $clientNew->groupid)); + $client->setHardwarehash(sprintf("%s", $clientNew->location)); + $client->setIp(sprintf("%s", $clientNew->ip)); + $client->setIp6(sprintf("%s", $clientNew->ip6)); + $client->setMacadress(sprintf("%s", $clientNew->macadress)); + $clientArray = array( + 'id' => $client->getID(), + 'ip' => $client->getIp(), + 'mac' => $client->getMacadress()); + $clientlist[] = $clientArray; + } + } + } + } + + public function getBootos(&$bootoslist, &$configlist, $bootosID = null) { + if(isset($bootosID)) { + $bootOsRequest = "bootosid=" . $bootosID; + $bootOsXML = $this->runApi($this->pbs2host, $this->config['pbs2']['getbootoss'], $bootOsRequest); + } else { + $bootOsXML = $this->runApi($this->pbs2host, $this->config['pbs2']['getbootoss']); + } + if(isset($bootOsXML)) { + foreach($bootOsXML->bootoslist->bootos as $bootos) { + $bootosobj = new Application_Model_BootOs(); + $bootosobj->setID(sprintf("%s", $bootos->id)); + $bootosobj->setCreated(sprintf("%s", $bootos->created)); + $bootosobj->setDefaultkcl(sprintf("%s", $bootos->defaultkcl)); + $bootosobj->setDescription(sprintf("%s", $bootos->description)); + $bootosobj->setDistro(sprintf("%s", $bootos->distro)); + $bootosobj->setDistroversion(sprintf("%s", $bootos->distroversion)); + $bootosobj->setExpires(sprintf("%s", $bootos->expires)); + $bootosobj->setGroupID(sprintf("%s", $bootos->groupid)); + $bootosobj->setMembershipID(sprintf("%s", $bootos->membershipid)); + $bootosobj->setPublic(sprintf("%s", $bootos->public)); + $bootosobj->setShare(sprintf("%s", $bootos->share)); + $bootosobj->setShortname(sprintf("%s", $bootos->shortname)); + $bootosobj->setSource(sprintf("%s", $bootos->source)); + $bootosobj->setTitle(sprintf("%s", $bootos->title)); + $bootoslist[$bootosobj->getID()] = $bootosobj; + foreach($bootos->configs->config as $config) { + $configobj = new Application_Model_Config(); + $configobj->setID(sprintf("%s", $config->configid)); + $configobj->setBootosID(sprintf("%s", $bootosobj->getID())); + $configobj->setCreated(sprintf("%s", $config->created)); + $configobj->setMembershipID(sprintf("%s", $config->membershipid)); + $configobj->setDescription(sprintf("%s", $config->description)); + $configobj->setGroupID(sprintf("%s", $config->groupid)); + $configobj->setTitle(sprintf("%s", $config->title)); + $configobj->setVisible(sprintf("%s", $config->visible)); + if($configobj->getVisible()) { + if($configobj->getTitle() == 'Default') { + $configlist[$bootosobj->getID()][0] = $configobj; + } else { + $configlist[$bootosobj->getID()][$configobj->getID()] = $configobj; + } + } + } + } + } + } + + public function getGroup(&$groupSession, $groupID) { + $grouprequest = "groupid=" . $groupID; + $groupApiResult = PostToHost($this->pbs2host, $this->config['pbs2']['getgroup'] . $membership->getApikey(), 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $grouprequest); + $groupXMLString = $groupApiResult['http-body']; + if(strlen($groupXMLString) > 0) { + $groupXML = new SimpleXMLElement($groupXMLString); + $group = new Application_Model_Group(); + $group->setID(sprintf("%s", $groupXML->group->id)); + $group->setTitle(sprintf("%s", $groupXML->group->title)); + $group->setDescription(sprintf("%s", $groupXML->group->description)); + $groupSession->$groupID = $group; + } + } + + public function getRole(&$roleSession, $roleID) { + $roleApiResult = PostToHost($this->pbs2host, $this->config['pbs2']['getrole'] . $membership->getApikey(), 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', ''); + $roleXMLString = $roleApiResult['http-body']; + if(strlen($roleXMLString) > 0) { + $roleXML = new SimpleXMLElement($roleXMLString); + $role = new Application_Model_Role(); + $role->setID(sprintf("%s", $roleXML->role->id)); + $role->setGroupID(sprintf("%s", $roleXML->role->groupid)); + $role->setTitle(sprintf("%s", $roleXML->role->title)); + $role->setDescription(sprintf("%s", $roleXML->role->description)); + $role->setInheritance(sprintf("%s", $roleXML->role->inheritance)); + $roleSession->$roleID = $role; + } + } + + public function getPerson(&$personSession) { + $personApiResult = PostToHost($this->pbs2host, $this->config['pbs2']['getperson'] . $apikey, 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', ''); + $personXMLString = $personApiResult['http-body']; + if(strlen($personXMLString) > 0) { + $personXML = new SimpleXMLElement($personXMLString); + $person = new Application_Model_Person(); + $person->setID(sprintf("%s", $personXML->person->id)); + $person->setCity(sprintf("%s", $personXML->person->city)); + $person->setEmail(sprintf("%s", $personXML->person->email)); + $person->setFirstname(sprintf("%s", $personXML->person->firstname)); + $person->setHousenumber(sprintf("%s", $personXML->person->housenumber)); + $person->setLogin(sprintf("%s", $personXML->person->login)); + $person->setLogindate(sprintf("%s", $personXML->person->logindate)); + $person->setName(sprintf("%s", $personXML->person->name)); + $person->setPostalcode(sprintf("%s", $personXML->person->postalcode)); + $person->setRegisterdate(sprintf("%s", $personXML->person->registerdate)); + $person->setStreet(sprintf("%s", $personXML->person->street)); + $person->setSuspend(sprintf("%s", $personXML->person->suspend)); + $person->setTitle(sprintf("%s", $personXML->person->title)); + $personName = sprintf("%s", $login->personid); + $personSession->$personName = $person; + } + + } + + public function login($email, $password, &$membershipSession) { + $loginquery = "email=" . $email . "&password=" . $password; + $loginApiResult = PostToHost($this->pbs2host, $this->config['pbs2']['login'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $loginquery); + $loginXMLString = $loginApiResult['http-body']; + if(strlen($loginXMLString) > 0) { + $loginXML = new SimpleXMLElement($loginXMLString); + $login = $loginXML->login; + $success = sprintf("%s", $login->success); + if ($success === "true") { + $count = 0; + foreach($login->membershiplist->membership as $membershipXML) + { + $membership = new Application_Model_Membership(); + $membership->setID(sprintf("%s", $membershipXML->id)); + $membership->setPersonID(sprintf("%s", $membershipXML->personid)); + $membership->setGroupID(sprintf("%s", $membershipXML->groupid)); + $membership->setRoleID(sprintf("%s", $membershipXML->roleid)); + $membership->setApikey(sprintf("%s", $membershipXML->apikey)); + $membership->setSuspend(sprintf("%s", $membershipXML->suspend)); + $membershipID = $membership->getID(); + $membershipSession->$membershipID = $membership; + if($count == 0) { + $apikey = sprintf("%s", $membershipXML->apikey); + } + $count++; + } + return true; + } else { + return false; + } + } else { + return false; + } + } + + public function addBootmenu($eventTitle, $bootosID, $configID = null) { + $bootmenuquery = "bootosID=" . $bootosID . "&startcounter=0&title=Poolctrl-Bootmenu for " . $eventTitle . "&defaultbootmenu=0&order=0&kcl=0"; + if(isset($configID)) { + $bootmenuquery .= "&configID=" . $configID; + } + $bootmenuApiResult = PostToHost($this->pbs2host, $this->config['pbs2']['addbootmenu'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $bootmenuquery); + $bootmenuXMLString = $bootmenuApiResult['http-body']; + $bootmenuXML = new SimpleXMLElement($bootmenuXMLString); + $bootmenuID = sprintf("%s", $bootmenuXML->bootmenu->id); + return $bootmenuID; + } + + public function changeBootmenu($bootmenuID, $eventTitle, $bootosID, $configID = null) { + $bootmenuquery = "bootmenuid=" . $bootmenuID() . "&bootosID=" . $bootosID() . "&startcounter=0&title=Poolctrl-Bootmenu for " . $eventTitle . "&defaultbootmenu=0&order=0&kcl=0&changeentry=1"; + if(isset($configID)) { + $bootmenuquery .= "&configID=" . $configID; + } + $bootmenuApiResult = PostToHost($this->pbs2host, $this->config['pbs2']['changebootmenu'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $bootmenuquery); + return $bootmenuApiResult; + } + + public function deleteBootmenu($bootmenuID) { + $bootmenuApiResult = PostToHost($this->pbs2host, $this->config['pbs2']['deletebootmenu'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', "bootmenuid=" . $bootmenuID); + return $bootmenuApiResult; + } + + public function addFilter($eventTitle, $bootmenuID) { + $filterquery = "bootmenuID=" . $bootmenuID . "&title=Poolctrl-Filter for " . $event->getTitle() . "&description=This Filter was automatically created by the Poolctrl for Event " . $eventTitle . "&created= " . time() . "&priority=100"; + $filterApiResult = PostToHost($this->pbs2host, $this->config['pbs2']['addfilter'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $filterquery); + $filterXMLString = $filterApiResult['http-body']; + $filterXML = new SimpleXMLElement($filterXMLString); + $filterID = sprintf("%s", $filterXML->filter->id); + return $filterID; + } + + public function changeFilter($filterID, $eventTitle, $bootmenuID = null) { + $filterQuerie = "filterid=" . $filterID . "&title=Poolctrl-Filter for " . $eventTitle() . "&description=This Filter was automatically created by the Poolctrl for Event " . $eventTitle; + if(isset($bootmenuID)) { + "&bootmenuID=" . $bootmenuID; + } + $filterApiResult = PostToHost($this->pbs2host, $this->config['pbs2']['changefilter'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $filterQuerie); + return $filterApiResult; + } + + public function deleteFilter($filterID) { + $filterApiResult = PostToHost($this->pbs2host, $this->config['pbs2']['deletefilter'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', "bootmenuid=" . $filterID); + return $filterApiResult; + } + + public function addFilterentry($filterID, $filterType, $filterValue1, $filterValue2) { + $filterentriesApiResult = PostToHost($this->pbs2host, $this->config['pbs2']['addfilterentry'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $filterentriesquery); + $filterentriesXMLString = $filterentriesApiResult['http-body']; + $filterentriesXML = new SimpleXMLElement($filterentriesXMLString); + $filterentriesID = sprintf("%s", $filterentriesXML->filterentry->id); + return $filterentriesID; + } + + public function changeFilterentry($oldValue1, $oldValue2, $newValue1, $newValue2) { + $filterentriesQuerie = "filterid=" . $event->getPbs_filterID() . "&oldvalue1=" . $oldValue1 . "&oldvalue2=" . $oldValue2 . "&value1=" . $newValue1 . "&value2=" . $newValue2; + $filterApiResult = PostToHost($this->pbs2host, $this->config['pbs2']['changefilterentry'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'poolctrl', $filterentriesQuerie); + return $filterApiResult; + } +} \ No newline at end of file -- cgit v1.2.3-55-g7522