Updated TheTool Frontend Framework & Table

This commit is contained in:
Luca Haid
2024-05-08 12:54:26 +00:00
parent 1e57d983b7
commit 58e124a461
46 changed files with 1364 additions and 2535 deletions
+36
View File
@@ -250,7 +250,43 @@ class DeviceController extends mfBaseController
$ont = $this->request->ont;
$data = [];
switch ($do) {
case "getDevices":
$devices = DeviceModel::getAll();
foreach ($devices as $device) {
$locationText = "";
$locationUrl = "";
if (trim($device->pop->name)) {
$locationText = $device->pop->name;
$locationUrl = self::getUrl("Pop", "Detail", ["id" => $device->pop->id]);
} else if (trim($device->addr_street)) {
$locationText = $device->addr_street . " " . $device->addr_number . ", " . $device->addr_zip . " " . $device->addr_city;
$locationUrl = "http://maps.google.com/?q=" . $locationText;
} else if (trim($device->gps_lat)) {
$locationText = $device->gps_lat . " , " . $device->gps_long;
$locationUrl = "http://maps.google.com/?q=" . $locationText;
}
$data[] = [
"name" => $device->name,
"devicetype" => $device->devicetype->name,
"devicemanufactor" => $device->devicetype->devicemanufactor->name,
"locationText" => $locationText,
"locationUrl" => $locationUrl,
"ip" => $device->ip,
"mac" => $device->mac,
"serial" => $device->serial,
"price" => $device->price != "0.0" ? $device->price : $device->devicetype->price,
"power" => $device->power != "0.0" ? $device->power : $device->devicetype->power,
"backup" => $device->last_config_backup ? (time() - $device->last_config_backup <= 172800 ? 'ok' : 'aged') : 'na',
];
}
die(json_encode($data));
break;
case "getconfig":
$return = $this->getConfig($id, $format, $filename);
break;
@@ -0,0 +1,9 @@
<?php
/**
* @property mixed|null $name
*/
class DocumentationCheck extends mfBaseModel
{
}
@@ -0,0 +1,113 @@
<?php
class DocumentationCheckController extends mfBaseController {
private User $me;
private string $ZABBIX_API_URL = ZABBIX_API_URL;
private string $ZABBIX_API_KEY = ZABBIX_API_KEY;
private Zabbix $zabbix;
protected function init(): void {
$me = new User();
$me->loadMe();
$this->layout()->set("me", $me);
$this->me = $me;
if (!$this->me->isAdmin()) {
$this->redirect("dashboard");
}
$this->zabbix = new Zabbix($this->ZABBIX_API_URL, $this->ZABBIX_API_KEY);
}
protected function indexAction(): void {
$this->layout()->setTemplate("DocumentationCheck/DeviceTest");
}
protected function apiAction() {
$do = $this->request->do;
if (!$this->me->isAdmin()) {
$this->redirect("dashboard");
}
switch ($do) {
case "getDocumentationFails":
$return = $this->getDocumentationFails();
break;
default:
$return = false;
break;
}
if (!$return) {
$return = [
"status" => "error",
"message" => "Invalid request."
];
}
die(json_encode($return));
}
private function getDocumentationFails(): array {
$icmpItems = $this->zabbix->getICMPItems([]);
$zabbixICMPItems = [];
foreach ($icmpItems as $item) {
if (!isset($zabbixICMPItems[$item['hostid']])) {
$zabbixICMPItems[$item['hostid']] = [];
}
$zabbixICMPItems[$item['hostid']][] = $item;
}
$zabbixHostIPToId = [];
$zabbixHostNameToId = [];
$zabbixHosts = [];
foreach ($this->zabbix->getHosts("") as $host) {
$zabbixHostIPToId[$host['host']] = $host['hostid'];
$zabbixHostNameToId[$host['name']] = $host['hostid'];
$zabbixHosts[$host['hostid']] = $host;
}
$devices = DeviceModel::getAll();
//loop through all devices and join them by either IP or hostname and then return {device, zabbixHost}
$hosts = [];
foreach ($devices as $device) {
$deviceIP = $device->ip;
$deviceHostname = $device->name;
$zabbixHost = null;
if (isset($zabbixHostIPToId[$deviceIP])) {
$zabbixHost = $zabbixHosts[$zabbixHostIPToId[$deviceIP]];
} else if (isset($zabbixHostNameToId[$deviceHostname])) {
$zabbixHost = $zabbixHosts[$zabbixHostNameToId[$deviceHostname]];
}
$hosts[] = [
"zabbixHostId" => $zabbixHost['hostid'],
"zabbixHostName" => $zabbixHost['name'],
"zabbixHostIP" => $zabbixHost['host'],
"deviceName" => $device->name,
"deviceIP" => $device->ip,
"checkDeviceInZabbix" => $zabbixHost !== null,
"checkDeviceHasICMPPing" => isset($zabbixICMPItems[$zabbixHost['hostid']]),
"checkDeviceHasSameName" => $zabbixHost['name'] === $device->name,
"checkDeviceHasSameIP" => $zabbixHost['host'] === $device->ip
// "raw" => [
// "zabbixHost" => $zabbixHost,
// "device" => $device->toArray()
// ]
];
}
return [
"status" => "success",
"rows" => $hosts
];
}
}
+5 -10
View File
@@ -66,12 +66,6 @@ class DomainController extends mfBaseController {
die(json_encode($return));
}
protected function importDomain(): void {
// use plesk api to get all domains
}
protected function importAllDomains(): array {
try {
@@ -119,15 +113,16 @@ class DomainController extends mfBaseController {
}
private function getAllDomains(): array {
$json = json_decode(file_get_contents('php://input'), true);
$filters = $json['filters'] ?? [];
$order = $json['order'] ?? [];
$page = $json['pagination']['page'] ?? 1;
$perPage = $json['pagination']['per_page'] ?? 10;
$domains = DomainModel::getAllDomains($filters, $perPage, $perPage * $page - $perPage);
$totalRows = DomainModel::countDomains($filters);
$domains = DomainModel::getAllDomains($filters, $perPage, $perPage * $page - $perPage, $order);
$filtered_available = DomainModel::countDomains($filters);
$totalRows = DomainModel::countDomains([]);
return [
"rows" => $domains,
@@ -135,6 +130,7 @@ class DomainController extends mfBaseController {
"page" => $page,
"total_pages" => ceil($totalRows / $perPage),
"per_page" => $perPage,
"filtered_available" => intval($filtered_available),
"total_rows" => intval($totalRows)
]
];
@@ -156,7 +152,6 @@ class DomainController extends mfBaseController {
dns_get_record($domain, DNS_SOA),
dns_get_record($domain, DNS_SRV),
dns_get_record($domain, DNS_AAAA),
);
}
+14 -10
View File
@@ -93,31 +93,35 @@ class DomainModel {
}
public static function getSqlFilter($filters): string {
$sql = isset($filters['domain']) ? self::generateFilterCondition($filters['domain'], "domain") : "";
$sql .= isset($filters['crDate']) ? " AND `crDate` = " . $filters['crDate'] : "";
$sql .= isset($filters['exDate']) ? " AND `exDate` = " . $filters['exDate'] : "";
$sql .= isset($filters['reDate']) ? " AND `reDate` = " . $filters['reDate'] : "";
$sql .= isset($filters['upDate']) ? " AND `upDate` = " . $filters['upDate'] : "";
$sql .= isset($filters['status']) ? " AND `status` = '" . $filters['status'] . "'" : "";
$sql .= isset($filters['transferLock']) && $filters['transferLock'] == 1 ? " AND `transferLock` = true" : "";
$sql .= isset($filters['authCode']) ? self::generateFilterCondition($filters['authCode'], "authCode") : "";
$sql = isset($filters['domain']) ? Helper::generateFilterCondition($filters['domain'], "domain") : "";
$sql .= isset($filters['crDate']) ? Helper::generateFilterCondition($filters['crDate'], "crDate") : "";
$sql .= isset($filters['exDate']) ? Helper::generateFilterCondition($filters['exDate'], "exDate") : "";
$sql .= isset($filters['reDate']) ? Helper::generateFilterCondition($filters['reDate'], "reDate") : "";
$sql .= isset($filters['upDate']) ? Helper::generateFilterCondition($filters['upDate'], "upDate") : "";
$sql .= isset($filters['status']) ? Helper::generateFilterCondition($filters['status'], "status") : "";
$sql .= isset($filters['transferLock']) ? Helper::generateFilterCondition($filters['transferLock'], "transferLock") : "";
$sql .= isset($filters['authCode']) ? Helper::generateFilterCondition($filters['authCode'], "authCode") : "";
$sql .= isset($filters['registrant']) && $filters['registrant'] !== 'all' ? " AND `registrant` = " . $filters['registrant'] : "";
$sql .= isset($filters['admin']) && $filters['admin'] !== 'all' ? " AND `admin` = " . $filters['admin'] : "";
$sql .= isset($filters['tech']) && $filters['tech'] !== 'all' ? " AND `tech` = " . $filters['tech'] : "";
$sql .= isset($filters['billing']) && $filters['billing'] !== 'all' ? " AND `billing` = " . $filters['billing'] : "";
$sql .= isset($filters['ns']) ? self::generateFilterCondition($filters['ns'], "ns") : "";
$sql .= isset($filters['ns']) ? Helper::generateFilterCondition($filters['ns'], "ns") : "";
$sql .= isset($filters['pleskId']) ? " AND `pleskId` " . ($filters['pleskId'] === "0" ? "IS NULL" : "IS NOT NULL") : "";
return $sql;
}
public static function getAllDomains($filters, $limit = null, $offset = 0): array {
public static function getAllDomains($filters, $limit = null, $offset = 0, $order = null): array {
$db = FronkDB::singleton();
$sql = "SELECT * FROM `Domain` WHERE 1 " . self::getSqlFilter($filters);
$sql .= $order === null || $order['key'] === null ? "" : " ORDER BY `" . $order['key'] . "` " . $order['order'];
$sql .= $limit === null ? "" : " LIMIT " . $limit . " OFFSET " . $offset;
$result = $db->query($sql);
$rows = [];
while ($row = $result->fetch_assoc()) {
$row['pleskId'] = $row['pleskId'] === null ? 0 : 1;
$rows[] = new DomainModel($row);
}
@@ -54,19 +54,22 @@ class HistoricTicketController extends mfBaseController {
$json = json_decode(file_get_contents('php://input'), true);
$filters = $json['filters'] ?? [];
$order = $json['order'] ?? [];
$page = $json['pagination']['page'] ?? 1;
$perPage = $json['pagination']['per_page'] ?? 10;
$historicTickets = HistoricTicketModel::getAllHistoricTickets($filters, $perPage, ($page - 1) * $perPage);
$total = HistoricTicketModel::countHistoricTickets($filters);
$historicTickets = HistoricTicketModel::getAllHistoricTickets($filters, $perPage, ($page - 1) * $perPage, $order);
$filtered_available = HistoricTicketModel::countHistoricTickets($filters);
$totalRows = HistoricTicketModel::countHistoricTickets([]);
return [
"rows" => $historicTickets,
"pagination" => [
"page" => $page,
"total_pages" => ceil($total / $perPage),
"total_pages" => ceil($totalRows / $perPage),
"per_page" => $perPage,
"total_rows" => intval($total)
"filtered_available" => intval($filtered_available),
"total_rows" => intval($totalRows)
]
];
}
@@ -88,16 +91,6 @@ class HistoricTicketController extends mfBaseController {
];
}
$rows = HistoricTicketModel::findTicket($query);
return [
"rows" => $rows,
"pagination" => [
"page" => 1,
"total_pages" => 1,
"per_page" => count($rows),
"total_rows" => count($rows)
]
];
return HistoricTicketModel::findTicket($query);
}
}
@@ -88,11 +88,13 @@ class HistoricTicketModel {
return $sql;
}
public static function getAllHistoricTickets($filters, $limit = null, $offset = 0): array {
public static function getAllHistoricTickets($filters, $limit = null, $offset = 0, $order = null): array {
$db = FronkDB::singleton();
$sql = "SELECT * FROM `HistoricTicket` WHERE 1 " . self::getSqlFilter($filters) . " ORDER BY `ticket_number` DESC";
$sql = "SELECT * FROM `HistoricTicket` WHERE 1 " . self::getSqlFilter($filters);
$sql .= $order === null || $order['key'] === null ? " ORDER BY `ticket_number` DESC " : " ORDER BY `" . $order['key'] . "` " . $order['order'];
$sql .= $limit === null ? "" : " LIMIT " . $limit . " OFFSET " . $offset;
// die($sql);
$result = $db->query($sql);
$rows = [];
while ($row = $result->fetch_assoc()) {
@@ -162,7 +164,7 @@ class HistoricTicketModel {
"table_entry" => "ticket",
"ticket_id" => $ticket["id"],
"ticket_number" => $ticket["ticket_number"],
"ctime" => $ticket["ctime"],
"ctime" => intval($ticket["ctime"]),
"ticket_subject" => $ticket["subject"],
];
}
@@ -173,7 +175,7 @@ class HistoricTicketModel {
"ticket_id" => $message["ticket_id"],
"ticket_number" => $message["ticket_number"],
"ticket_subject" => $message["subject"],
"ctime" => $message["ctime"],
"ctime" => intval($message["ctime"]),
"ticket_message" => $message["content"],
];
}
@@ -69,11 +69,13 @@ class VoiceCallHistoryController extends mfBaseController {
$json = json_decode(file_get_contents('php://input'), true);
$filters = $json['filters'] ?? [];
$order = $json['order'] ?? [];
$page = $json['pagination']['page'] ?? 1;
$perPage = $json['pagination']['per_page'] ?? 10;
$calls = VoiceCallHistoryModel::getVoiceCallHistory($filters, $perPage, $perPage * $page - $perPage);
$totalRows = VoiceCallHistoryModel::countVoiceCallHistory($filters);
$calls = VoiceCallHistoryModel::getVoiceCallHistory($filters, $perPage, $perPage * $page - $perPage, $order);
$filtered_available = VoiceCallHistoryModel::countVoiceCallHistory($filters);
$totalRows = VoiceCallHistoryModel::countVoiceCallHistory([]);
return [
"rows" => $calls,
@@ -81,11 +83,9 @@ class VoiceCallHistoryController extends mfBaseController {
"page" => $page,
"total_pages" => ceil($totalRows / $perPage),
"per_page" => $perPage,
"filtered_available" => intval($filtered_available),
"total_rows" => intval($totalRows)
]
];
}
}
@@ -1,5 +1,4 @@
<?php
class VoiceCallHistoryModel {
public $uid;
public $voice_account;
@@ -18,28 +17,6 @@ class VoiceCallHistoryModel {
}
}
/**
* Generate SQL Filter condition (space separated) for a given column.
*
* @param string|null $filterValue The filter value to match against.
* @param string $columnName The name of the column in the database table.
* @return string The SQL condition generated based on the filter value and column name.
*/
public static function generateFilterCondition(?string $filterValue, string $columnName): string {
$sql = "";
if ($filterValue === "0" || $filterValue === "1") {
$sql .= " AND `$columnName` = " . $filterValue;
} else if (!empty($filterValue)) {
$filterItems = explode(" ", $filterValue);
foreach ($filterItems as $item) {
$sql .= " AND `$columnName` LIKE '%" . $item . "%'";
}
}
return $sql;
}
//TODO: combine these two functions into one
public static function importCallsFromKolmisoft($callHistory): array {
{
@@ -114,22 +91,24 @@ class VoiceCallHistoryModel {
if (isset($filters['start']['from']) && isset($filters['start']['to'])) {
$sql = " AND `start` >= FROM_UNIXTIME(" . $filters['start']['from'] . ") AND `start` <= FROM_UNIXTIME(" . $filters['start']['to'] . ")";
}
$sql .= isset($filters['uid']) ? self::generateFilterCondition($filters['uid'], "uid") : "";
$sql .= isset($filters['voice_account']) ? self::generateFilterCondition($filters['voice_account'], "voice_account") : "";
$sql .= isset($filters['uid']) ? Helper::generateFilterCondition($filters['uid'], "uid") : "";
$sql .= isset($filters['voice_account']) ? Helper::generateFilterCondition($filters['voice_account'], "voice_account") : "";
$sql .= isset($filters['end']) ? " AND `start` <= '" . $filters['end'] . "'" : "";
$sql .= isset($filters['source']) ? self::generateFilterCondition($filters['source'], "source") : "";
$sql .= isset($filters['destination']) ? self::generateFilterCondition($filters['destination'], "destination") : "";
$sql .= isset($filters['billable']) ? self::generateFilterCondition($filters['billable'], "billable") : "";
$sql .= isset($filters['duration']) ? self::generateFilterCondition($filters['duration'], "duration") : "";
$sql .= isset($filters['source']) ? Helper::generateFilterCondition($filters['source'], "source") : "";
$sql .= isset($filters['destination']) ? Helper::generateFilterCondition($filters['destination'], "destination") : "";
$sql .= isset($filters['billable']) ? Helper::generateFilterCondition($filters['billable'], "billable") : "";
$sql .= isset($filters['duration']) ? Helper::generateFilterCondition($filters['duration'], "duration") : "";
return $sql . " ORDER BY `start` DESC";
return $sql;
}
public static function getVoiceCallHistory($filters, $limit = null, $offset = 0): array {
public static function getVoiceCallHistory($filters, $limit = null, $offset = 0, $order = null) {
$db = FronkDB::singleton();
$sql = "SELECT * FROM `VoiceCallHistory` WHERE 1 " . self::getSqlFilter($filters);
$sql .= $order === null || $order['key'] === null ? " ORDER BY `start` DESC" : " ORDER BY `" . $order['key'] . "` " . $order['order'];
$sql .= $limit === null ? "" : " LIMIT " . $limit . " OFFSET " . $offset;
// die($sql);
$result = $db->query($sql);
$rows = [];
while ($row = $result->fetch_assoc()) {