public function store() { //if address is ipv6 link local, then it is possible to store more than one of these adresses //on different interfaces in different networks. So we need to check if the address already exists //on the given interface and if not, add if ($this->getInterfaceId() != 0 and $this->getIp() != "" and $this->ipIsInNetwork()) { if (strpos($this->getIp(), "fe80") !== false) { $ip = new Ip(false, $this->getInterfaceId(), $this->getNetworkId(), $this->getIp()); if (!$ip->fetch()) { return $this->insert(); } } else { $ip = new Ip(false, false, $this->getNetworkId(), $this->getIp()); $result = $ip->fetch(); if ($this->getIpId() != 0 and ($result and $ip->getIpId() == $this->getIpId() or !$result)) { return $this->update(); } elseif ($this->getInterfaceId() != 0 and $this->getIp() != "" and $this->getNetworkId() != 0 and $ip->getIpId() == 0) { return $this->insert(); } } } return false; }
public function setIplist($itemlist = false) { if ($itemlist instanceof Iplist) { $this->iplist = $itemlist; return true; } elseif (is_array($itemlist)) { $iplist = new Iplist(false, false, 0, 0); foreach ($itemlist as $ip_id) { $ip = new Ip((int) $ip_id); if ($ip->fetch()) { $iplist->add($ip); } } $this->setIplist($iplist); return true; } elseif ($itemlist == false and $this->getServiceId() != 0) { $result = array(); try { $stmt = DB::getInstance()->prepare("SELECT ip_id\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tFROM service_ips\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE service_id = ?"); $stmt->execute(array($this->getServiceId())); $result = $stmt->fetchAll(PDO::FETCH_ASSOC); } catch (PDOException $e) { echo $e->getMessage(); echo $e->getTraceAsString(); } $iplist = new Iplist(false, false, 0, 0); foreach ($result as $ip_id) { $ip = new Ip((int) $ip_id['ip_id']); if ($ip->fetch()) { $iplist->add($ip); } } $this->setIplist($iplist); return true; } return false; }
private function ip() { if ($this->get_request_method() == "GET" && isset($this->_request['id'])) { $ip = new Ip((int) $this->_request['id']); if ($ip->fetch()) { $domxmldata = $ip->getDomXMLElement($this->domxml); $this->response($this->finishxml($domxmldata), 200); } else { $this->error_code = 1; $this->error_message = "IP not found"; $this->response($this->finishxml(), 404); } } }
<?php require_once 'runtime.php'; require_once ROOT_DIR . '/lib/core/Ip.class.php'; require_once ROOT_DIR . '/lib/core/ConfigLine.class.php'; $ip = new Ip((int) $_GET['ip_id']); if ($ip->fetch()) { if ($ip->getNetwork()->getIpv() == 6) { $command = "ping6 -c 4 -I " . ConfigLine::configByName("network_connection_ipv6_interface") . " " . $ip->getIp(); } elseif ($ip->getNetwork()->getIpv() == 4) { $command = "ping -c 4 " . $ip->getIp(); } } else { echo "Could not fetch Info."; } $return = array(); echo "Command: " . $command . "<br><br>"; exec($command, $return); echo "Result:<pre>"; print_r($return); echo "</pre>";
public function getDestination() { if ($this->getType() == 'A' or $this->getType() == 'AAAA') { $ip = new Ip($this->getDestinationId()); if ($ip->fetch()) { return $ip; } } return false; }
} else { Permission::denyAccess(PERM_ROOT, $networkinterface->getRouter()->getUserId()); } } elseif ($_GET['section'] == 'insert_add') { $networkinterface = new Networkinterface((int) $_GET['interface_id']); $networkinterface->fetch(); if (permission::checkIfUserIsOwnerOrPermitted(PERM_ROOT, $networkinterface->getRouter()->getUserId())) { $ip = new Ip(false, (int) $_GET['interface_id'], (int) $_POST['network_id'], $_POST['ip']); if ($ip->store()) { $message[] = array('Die IP ' . $_POST['ip'] . ' wurde angelegt.', 1); Message::setMessage($message); } else { $message[] = array('Die IP ' . $_POST['ip'] . ' konnte nicht angelegt werden.', 2); Message::setMessage($message); } header('Location: ./router.php?router_id=' . $_GET['router_id']); } else { Permission::denyAccess(PERM_ROOT, $networkinterface->getRouter()->getUserId()); } } elseif ($_GET['section'] == 'delete') { $ip = new Ip((int) $_GET['ip_id']); $ip->fetch(); if (permission::checkIfUserIsOwnerOrPermitted(PERM_ROOT, $ip->getNetworkinterface()->getRouter()->getUserId())) { $ip->delete(); $message[] = array('Die IP ' . $ip->getIp() . '/' . $ip->getNetwork()->getNetmask() . ' wurde gelöscht.', 1); Message::setMessage($message); header('Location: ./router.php?router_id=' . $_GET['router_id']); } else { Permission::denyAccess(PERM_ROOT, $ip->getNetworkinterface()->getRouter()->getUserId()); } }