public function __construct($user_id = false, $offset = false, $limit = false, $sort_by = false, $order = false) { $result = array(); if ($offset !== false) { $this->setOffset((int) $offset); } if ($limit !== false) { $this->setLimit((int) $limit); } if ($sort_by !== false) { $this->setSortBy($sort_by); } if ($order !== false) { $this->SetOrder($order); } // initialize $total_count with the total number of objects in the list (over all pages) try { $stmt = DB::getInstance()->prepare("SELECT COUNT(*) as total_count\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tFROM dns_zones\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t(user_id = :user_id OR :user_id=0)"); $stmt->bindParam(':user_id', $user_id, PDO::PARAM_INT); $stmt->execute(); $total_count = $stmt->fetch(PDO::FETCH_ASSOC); } catch (PDOException $e) { echo $e->getMessage(); echo $e->getTraceAsString(); } $this->setTotalCount((int) $total_count['total_count']); //if limit -1 then get all ressource records if ($this->getLimit() == -1) { $this->setLimit($this->getTotalCount()); } try { $stmt = DB::getInstance()->prepare("SELECT id as dns_zone_id\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tFROM dns_zones\n\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t(user_id = :user_id OR :user_id=0)\n\t\t\t\t\t\t\t\t\t\t\t\t\tORDER BY\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tcase :sort_by\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\twhen 'dns_zone_id' then dns_zones.id\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\twhen 'user_id' then dns_zones.user_id\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\telse NULL\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tend\n\t\t\t\t\t\t\t\t\t\t\t\t\t" . $this->getOrder() . "\n\t\t\t\t\t\t\t\t\t\t\t\t\tLIMIT :offset, :limit"); $stmt->bindParam(':user_id', $user_id, PDO::PARAM_INT); $stmt->bindParam(':offset', $this->getOffset(), PDO::PARAM_INT); $stmt->bindParam(':limit', $this->getLimit(), PDO::PARAM_INT); $stmt->bindParam(':sort_by', $this->getSortBy(), PDO::PARAM_STR); $stmt->execute(); $resultset = $stmt->fetchAll(PDO::FETCH_ASSOC); } catch (PDOException $e) { echo $e->getMessage(); echo $e->getTraceAsString(); } foreach ($resultset as $item) { $new_item = new DnsZone((int) $item['dns_zone_id']); $new_item->fetch(); $this->dns_zone_list[] = $new_item; } }
public function store() { if ($this->getDnsZoneId() != 0) { //update //check if we need to update the serial number $tmp_dns_zone = new DnsZone($this->getDnsZoneId()); $tmp_dns_zone->fetch(); if ($tmp_dns_zone->getSerial() == $this->getSerial()) { $tmd_serial_date = substr($tmp_dns_zone->getSerial(), 0, 8); $today_serial_date = date("Ymd", time()); if ($tmd_serial_date == $today_serial_date) { $serial_inc = str_pad(substr($this->getSerial, -2) + 1, 2, "0", STR_PAD_LEFT); } else { $serial_inc = "00"; } $this->setSerial(intval($today_serial_date . $serial_inc)); } try { $stmt = DB::getInstance()->prepare("UPDATE dns_zones SET\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tuser_id = ?,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tname = ?,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tpri_dns = ?,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tsec_dns = ?,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tserial = ?,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\trefresh = ?,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tretry = ?,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\texpire = ?,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tttl = ?,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tupdate_date = NOW()\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE id=?"); $stmt->execute(array($this->getUserId(), $this->getName(), $this->getPriDns(), $this->getSecDns(), $this->getSerial(), $this->getRefresh(), $this->getRetry(), $this->getExpire(), $this->getTtl(), $this->getDnsZoneId())); return $stmt->rowCount(); } catch (PDOException $e) { echo $e->getMessage(); echo $e->getTraceAsString(); } } elseif ($this->getUserId() != 0 and $this->getName() != "") { if ($this->getSerial() == 0) { $this->setSerial(intval($today_serial_date = date("Ymd", time()) . "00")); } try { $stmt = DB::getInstance()->prepare("INSERT INTO dns_zones (user_id, name, pri_dns, sec_dns, serial, refresh, retry, expire, ttl, create_date, update_date)\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tVALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, NOW(), NOW())"); $stmt->execute(array($this->getUserId(), $this->getName(), $this->getPriDns(), $this->getSecDns(), $this->getSerial(), $this->getRefresh(), $this->getRetry(), $this->getExpire(), $this->getTtl())); return DB::getInstance()->lastInsertId(); } catch (PDOException $e) { echo $e->getMessage(); echo $e->getTraceAsString(); } } return false; }
function objectMenu() { $menu = array(); $submenu = array(); $subsubmenu = array(); if (Permission::checkPermission(PERM_USER)) { if (strpos($_SERVER['PHP_SELF'], "router.php") !== false and !isset($_GET['section'])) { $submenu[] = array('name' => 'Routeroptionen', 'href' => '#'); $subsubmenu[] = array('name' => 'Bearbeiten', 'href' => 'routereditor.php?section=edit&router_id=' . $_GET['router_id']); $subsubmenu[] = array('name' => 'API-Keys', 'href' => 'api_key_list.php?object_type=router&object_id=' . $_GET['router_id']); $subsubmenu[] = array('name' => 'Interf. hinzufügen', 'href' => 'interface.php?section=add&router_id=' . $_GET['router_id']); $submenu[] = $subsubmenu; $menu[] = $submenu; } elseif (strpos($_SERVER['PHP_SELF'], "user.php") !== false) { $submenu[] = array('name' => 'Benutzeroptionen', 'href' => '#'); if (Permission::checkIfUserIsOwnerOrPermitted(PERM_ROOT, $_GET['user_id'])) { $subsubmenu[] = array('name' => 'Bearbeiten', 'href' => 'user_edit.php?section=edit&user_id=' . $_GET['user_id']); $subsubmenu[] = array('name' => 'API-Keys', 'href' => 'api_key_list.php?object_type=user&object_id=' . $_GET['user_id']); $subsubmenu[] = array('name' => 'Benachrichtigungen', 'href' => 'event_notifications.php?section=edit&user_id=' . $_GET['user_id']); $subsubmenu[] = array('name' => 'Dienst hinzufügen', 'href' => 'service.php?section=add&user_id=' . $_GET['user_id']); } $submenu[] = $subsubmenu; $menu[] = $submenu; } elseif (strpos($_SERVER['PHP_SELF'], "dns_zone.php") !== false and isset($_GET['dns_zone_id'])) { $submenu[] = array('name' => 'Zonenoptionen', 'href' => '#'); $dns_zone = new DnsZone((int) $_GET['dns_zone_id']); $dns_zone->fetch(); if (Permission::checkIfUserIsOwnerOrPermitted(PERM_ROOT, $dns_zone->getUserId())) { $subsubmenu[] = array('name' => 'Bearbeiten', 'href' => 'dns_zone.php?section=edit&dns_zone_id=' . $_GET['dns_zone_id']); } if (Permission::checkPermission(PERM_USER)) { $subsubmenu[] = array('name' => 'RR hinzufügen', 'href' => 'dns_ressource_record.php?section=add&dns_zone_id=' . $_GET['dns_zone_id']); } $submenu[] = $subsubmenu; $menu[] = $submenu; } } return $menu; }
private function dns_zone() { if ($this->get_request_method() == "GET" && isset($this->_request['id'])) { $dns_zone = new DnsZone((int) $this->_request['id']); if ($dns_zone->fetch()) { $domxmldata = $dns_zone->getDomXMLElement($this->domxml); $this->response($this->finishxml($domxmldata), 200); } else { $this->error_code = 1; $this->error_message = "DNS Zone not found"; $this->response($this->finishxml(), 404); } } }
public function setDnsZone($dns_zone) { if ($dns_zone instanceof DnsZone) { $this->dns_zone = $dns_zone; return true; } elseif (is_int($dns_zone)) { $dns_zone = new DnsZone($dns_zone); if ($dns_zone->fetch()) { $this->dns_zone = $dns_zone; return true; } } return false; }
Permission::denyAccess(PERM_ROOT, $dns_zone->getUserId()); } } elseif ($_GET['section'] == 'edit') { $dns_zone = new DnsZone((int) $_GET['dns_zone_id']); $dns_zone->fetch(); if (permission::checkIfUserIsOwnerOrPermitted(PERM_ROOT, $dns_zone->getUserId())) { $smarty->assign('dns_zone', $dns_zone); $smarty->assign('message', Message::getMessage()); $smarty->display("header.tpl.html"); $smarty->display("dns_zone_edit.tpl.html"); $smarty->display("footer.tpl.html"); } else { Permission::denyAccess(PERM_ROOT, $dns_zone->getUserId()); } } elseif ($_GET['section'] == 'insert_edit') { $dns_zone = new DnsZone((int) $_GET['dns_zone_id']); $dns_zone->fetch(); if (permission::checkIfUserIsOwnerOrPermitted(PERM_ROOT, $dns_zone->getUserId())) { $dns_zone->setName($_POST['name']); $dns_zone->setPriDns($_POST['pri_dns']); $dns_zone->setSecDns($_POST['sec_dns']); $dns_zone->setRefresh((int) $_POST['refresh']); $dns_zone->setRetry((int) $_POST['retry']); $dns_zone->setExpire((int) $_POST['expire']); $dns_zone->setTtl((int) $_POST['ttl']); if ($dns_zone->store()) { $message[] = array('Die Änderungen wurden gespeichert.', 1); } else { $message[] = array('Die Änderungen konnten nicht gespeichert werden.', 2); } Message::setMessage($message);