<?php
include("config.php");
include("function.php");
$data = array();
$abgelaufen = time() - $abgelaufen_zeit;
if ($_GET['query'] == "statistics") {
$query = $dbh->query("select (select count(assign) from ip where assign = 1) as assign, (select count(assign) from ip where assign != '1') as notassign, (select count(*) from ip) as allnetworks");
$result = $query->fetchAll(PDO::FETCH_OBJ);
foreach ($result as $row) {
$datas = array();
$datas['assign'] = $row->assign;
$datas['notassign'] = $row->notassign;
$datas['allnetworks'] = $row->allnetworks;
array_push($data, $datas);
}
}
else {
if ($_GET['query'] == "all") {
$query = $dbh->query("SELECT * FROM ip");
}
if ($_GET['query'] == "assigned") {
$query = $dbh->query("SELECT * FROM ip WHERE assign = '1'");
}
if ($_GET['query'] == "allowed") {
$query = $dbh->query("SELECT * FROM ip WHERE assign = '1' AND last_announce > '$abgelaufen'");
}
if ($_GET['query'] == "active") {
$query = $dbh->query("SELECT * FROM ip WHERE assign = '1' AND act_announce = '1'");
}
if ($_GET['query'] == "inactive") {
$query = $dbh->query("SELECT * FROM ip WHERE assign = '1' AND act_announce = '0'");
}
if ($_GET['query'] == "wrong_active") {
$query = $dbh->query("SELECT * FROM ip WHERE assign = '0' AND act_announce = '1'");
}
if ($_GET['query'] == "expired") {
$query = $dbh->query("SELECT * FROM ip WHERE assign = '1' AND last_announce <= '$abgelaufen'");
}
if ($_GET['query'] == "neverused") {
$query = $dbh->query("SELECT * FROM ip WHERE assign = '1' AND was_announce = '0'");
}
$result = $query->fetchAll(PDO::FETCH_OBJ);
foreach ($result as $row) {
$datas = array();
$datas['ip'] = $row->ip;
$datas['act_announce'] = $row->act_announce;
$datas['last_announce'] = $row->last_announce;
array_push($data, $datas);
}
}
header("Content-Type: application/json");
echo json_encode($data, JSON_PRETTY_PRINT);
//print_r($data);