Feature/rework vue schema

This commit is contained in:
Luca Haid
2024-05-10 21:03:01 +00:00
parent 1f30671cf9
commit 78c9d3ef37
34 changed files with 2290 additions and 1146 deletions
@@ -5,7 +5,7 @@ class DocumentationCheckController extends mfBaseController {
private string $ZABBIX_API_URL = ZABBIX_API_URL;
private string $ZABBIX_API_KEY = ZABBIX_API_KEY;
private Zabbix $zabbix;
// private Zabbix $zabbix;
protected function init(): void {
@@ -18,7 +18,7 @@ class DocumentationCheckController extends mfBaseController {
$this->redirect("dashboard");
}
$this->zabbix = new Zabbix($this->ZABBIX_API_URL, $this->ZABBIX_API_KEY);
// $this->zabbix = new Zabbix($this->ZABBIX_API_URL, $this->ZABBIX_API_KEY);
}
protected function indexAction(): void {
+16 -2
View File
@@ -26,7 +26,21 @@ class DomainController extends mfBaseController {
}
protected function indexAction(): void {
$this->layout()->setTemplate("Domain/Index");
$JSGlobals = ["BASE_URL" => self::getUrl("Domain"),
"DASHBOARD_URL" => self::getUrl("Dashboard"),
"MFAPPNAME" => MFAPPNAME_SLUG,
"PAGE_TITLE" => "Domains",
"PATH" => [
["text" => MFAPPNAME_SLUG, "href" => self::getUrl("Dashboard")],
["text" => "Domain Management", "href" => self::getUrl("Domain")],
["text" => "Domains"]
],
"DOMAIN_API_URL" => self::getUrl("Domain/api"),
];
$this->layout()->set("vueViewName", "Domain");
$this->layout()->set("JSGlobals", $JSGlobals);
$this->layout()->setTemplate("VueViews/Vue");
}
protected function apiAction() {
@@ -128,7 +142,7 @@ class DomainController extends mfBaseController {
"rows" => $domains,
"pagination" => [
"page" => $page,
"total_pages" => ceil($totalRows / $perPage),
"total_pages" => ceil($filtered_available / $perPage),
"per_page" => $perPage,
"filtered_available" => intval($filtered_available),
"total_rows" => intval($totalRows)
+4 -23
View File
@@ -73,25 +73,6 @@ class DomainModel {
];
}
/**
* 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 (!empty($filterValue)) {
$filterItems = explode(" ", $filterValue);
foreach ($filterItems as $item) {
$sql .= " AND `$columnName` LIKE '%" . $item . "%'";
}
}
return $sql;
}
public static function getSqlFilter($filters): string {
$sql = isset($filters['domain']) ? Helper::generateFilterCondition($filters['domain'], "domain") : "";
$sql .= isset($filters['crDate']) ? Helper::generateFilterCondition($filters['crDate'], "crDate") : "";
@@ -101,10 +82,10 @@ class DomainModel {
$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['registrant']) ? Helper::generateFilterCondition($filters['registrant'], "registrant", true) : "";
$sql .= isset($filters['admin']) ? Helper::generateFilterCondition($filters['admin'], "admin", true) : "";
$sql .= isset($filters['tech']) ? Helper::generateFilterCondition($filters['tech'], "tech", true) : "";
$sql .= isset($filters['billing']) ? Helper::generateFilterCondition($filters['billing'], "billing", true) : "";
$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;
@@ -15,7 +15,21 @@ class HistoricTicketController extends mfBaseController {
if (!$this->me->is("employee")) {
$this->redirect("dashboard");
}
$this->layout()->setTemplate("HistoricTicket/Index");
$JSGlobals = ["BASE_URL" => self::getUrl("Domain"),
"DASHBOARD_URL" => self::getUrl("Dashboard"),
"MFAPPNAME" => MFAPPNAME_SLUG,
"PAGE_TITLE" => "Historische Tickets",
"PATH" => [
["text" => MFAPPNAME_SLUG, "href" => self::getUrl("Dashboard")],
["text" => "Historische Tickets", "href" => self::getUrl("HistoricTicket")]
],
"HISTORIC_TICKET_API_URL" => self::getUrl("HistoricTicket/api"),
];
$this->layout()->set("vueViewName", "HistoricTicket");
$this->layout()->set("JSGlobals", $JSGlobals);
$this->layout()->setTemplate("VueViews/Vue");
}
protected function apiAction() {
@@ -66,7 +80,7 @@ class HistoricTicketController extends mfBaseController {
"rows" => $historicTickets,
"pagination" => [
"page" => $page,
"total_pages" => ceil($totalRows / $perPage),
"total_pages" => ceil($filtered_available / $perPage),
"per_page" => $perPage,
"filtered_available" => intval($filtered_available),
"total_rows" => intval($totalRows)
@@ -2,82 +2,18 @@
use phpseclib3\Net\SSH2;
class RaspberryDisplayController extends mfBaseController
{
class RaspberryDisplayController extends mfBaseController {
private int $port = 22;
private string $username = XINON_RASPBERRY_DISPLAY_SSH_USER;
private string $password = XINON_RASPBERRY_DISPLAY_SSH_PASS;
protected function init(): void
{
protected function init(): void {
$me = new User();
$me->loadMe();
$this->me = $me;
$this->layout()->set("me", $me);
}
protected function restartRaspberryPi($id) {
$display = RaspberryDisplayModel::get($id);
$ssh = new SSH2($display->ip_address, $this->port);
$ssh->login($this->username, $this->password);
$ssh->exec('sudo reboot now');
return true;
}
protected function getDisplaysApi(): array
{
$displays = RaspberryDisplayModel::getAll();
$result = [];
foreach ($displays as $display) {
$result[] = [
"display_label" => $display->display_label,
"hostname" => $display->hostname,
"ip" => $display->ip_address,
"display_url" => $display->display_url,
"auto_refresh_enabled" => $display->auto_refresh_enabled === "1",
"margin_hot_fix_enabled" => $display->margin_hot_fix_enabled === "1",
"custom_style" => $display->custom_style,
"id" => $display->id,
];
}
return $result;
}
protected function change()
{
$displayID = $this->request->displayID;
$field = $this->request->field;
$value = $this->request->value;
$value = $value === "true" ? 1 : ($value === "false" ? 0 : $value);
$display = RaspberryDisplayModel::get($displayID);
if ($display === null) {
return false;
}
$display->$field = $value;
$display->save();
return true;
}
protected function getConfig() {
$hostname = $this->request->hostname;
$displays = RaspberryDisplayModel::getByHostname($hostname);
if ($displays === null) {
die("No display found for this hostname and ip:" . $hostname . " X ");
}
return array_map(function ($display) {
return [
"display_url" => $display->data->display_url,
"auto_refresh_enabled" => $display->data->auto_refresh_enabled === "1",
"margin_hot_fix_enabled" => $display->data->margin_hot_fix_enabled === "1",
"id" => $display->id,
];
}
, $displays);
}
protected function apiAction() {
$do = $this->request->do;
@@ -111,7 +47,7 @@ class RaspberryDisplayController extends mfBaseController
$this->returnJson($data);
}
if(!is_array($return) || !count($return)) {
if (!is_array($return) || !count($return)) {
$data = ["status" => "error"];
$this->returnJson($data);
}
@@ -120,9 +56,77 @@ class RaspberryDisplayController extends mfBaseController
$this->returnJson($data);
}
protected function indexAction(): void
{
$this->layout()->setTemplate("RaspberryDisplay/Index");
protected function getDisplaysApi(): array {
$displays = RaspberryDisplayModel::getAll();
$result = [];
foreach ($displays as $display) {
$result[] = ["display_label" => $display->display_label,
"hostname" => $display->hostname,
"ip" => $display->ip_address,
"display_url" => $display->display_url,
"auto_refresh_enabled" => $display->auto_refresh_enabled === "1",
"margin_hot_fix_enabled" => $display->margin_hot_fix_enabled === "1",
"custom_style" => $display->custom_style,
"id" => $display->id,];
}
return $result;
}
protected function change() {
$displayID = $this->request->displayID;
$field = $this->request->field;
$value = $this->request->value;
$value = $value === "true" ? 1 : ($value === "false" ? 0 : $value);
$display = RaspberryDisplayModel::get($displayID);
if ($display === null) {
return false;
}
$display->$field = $value;
$display->save();
return true;
}
protected function restartRaspberryPi($id) {
$display = RaspberryDisplayModel::get($id);
$ssh = new SSH2($display->ip_address, $this->port);
$ssh->login($this->username, $this->password);
$ssh->exec('sudo reboot now');
return true;
}
protected function getConfig() {
$hostname = $this->request->hostname;
$displays = RaspberryDisplayModel::getByHostname($hostname);
if ($displays === null) {
die("No display found for this hostname and ip:" . $hostname . " X ");
}
return array_map(function ($display) {
return ["display_url" => $display->data->display_url,
"auto_refresh_enabled" => $display->data->auto_refresh_enabled === "1",
"margin_hot_fix_enabled" => $display->data->margin_hot_fix_enabled === "1",
"id" => $display->id,];
}, $displays);
}
protected function indexAction(): void {
$JSGlobals = ["BASE_URL" => self::getUrl("RaspberryDisplay"),
"DASHBOARD_URL" => self::getUrl("Dashboard"),
"MFAPPNAME" => MFAPPNAME_SLUG,
"PAGE_TITLE" => "Raspberry Displays",
"PATH" => [
["text" => MFAPPNAME_SLUG, "href" => self::getUrl("Dashboard")],
["text" => "Raspberry Displays", "href" => self::getUrl("RaspberryDisplay")]
]
];
$this->layout()->set("vueViewName", "RaspberryDisplay");
$this->layout()->set("JSGlobals", $JSGlobals);
$this->layout()->set("additionalCSS", ["css/views/RaspberryDisplay.css"]);
$this->layout()->setTemplate("VueViews/Vue");
}
@@ -24,7 +24,21 @@ class VoiceCallActiveController extends mfBaseController {
}
protected function indexAction(): void {
$this->layout()->setTemplate("VoiceCallActive/Index");
$JSGlobals = ["BASE_URL" => self::getUrl("VoiceCallActive"),
"DASHBOARD_URL" => self::getUrl("Dashboard"),
"MFAPPNAME" => MFAPPNAME_SLUG,
"PAGE_TITLE" => "Active Voice Calls",
"PATH" => [
["text" => MFAPPNAME_SLUG, "href" => self::getUrl("Dashboard")],
["text" => "Active Voice Calls", "href" => self::getUrl("VoiceCallActive")]
],
"VOICE_CALL_ACTIVE_API_URL" => self::getUrl("VoiceCallActive/api"),
];
$this->layout()->set("additionalCSS", ["css/views/VoiceCallActive.css"]);
$this->layout()->set("vueViewName", "VoiceCallActive");
$this->layout()->set("JSGlobals", $JSGlobals);
$this->layout()->setTemplate("VueViews/Vue");
}
protected function apiAction() {
@@ -54,8 +68,10 @@ class VoiceCallActiveController extends mfBaseController {
}
private function getActiveCalls(): array {
$activeCalls = $this->kolmisoftMore->getActiveCalls();
return [
"rows" => array_reverse($this->kolmisoftMore->getActiveCalls())
"rows" => is_null($activeCalls) ? [] : (is_object($activeCalls) ? [$activeCalls] : $activeCalls),
];
}
}
@@ -24,7 +24,20 @@ class VoiceCallHistoryController extends mfBaseController {
}
protected function indexAction(): void {
$this->layout()->setTemplate("VoiceCallHistory/Index");
$JSGlobals = ["BASE_URL" => self::getUrl("Domain"),
"DASHBOARD_URL" => self::getUrl("Dashboard"),
"MFAPPNAME" => MFAPPNAME_SLUG,
"PAGE_TITLE" => "Voice Call History",
"PATH" => [
["text" => MFAPPNAME_SLUG, "href" => self::getUrl("Dashboard")],
["text" => "Voice Call History", "href" => self::getUrl("VoiceCallHistory")]
],
"VOICE_CALL_HISTORY_API_URL" => self::getUrl("VoiceCallHistory/api"),
];
$this->layout()->set("vueViewName", "VoiceCallHistory");
$this->layout()->set("JSGlobals", $JSGlobals);
$this->layout()->setTemplate("VueViews/Vue");
}
protected function apiAction() {
@@ -73,6 +86,11 @@ class VoiceCallHistoryController extends mfBaseController {
$page = $json['pagination']['page'] ?? 1;
$perPage = $json['pagination']['per_page'] ?? 10;
if (isset($filters['start']['from']) && isset($filters['start']['to']) && is_numeric($filters['start']['to'])) {
$filters['start']['from'] += 7200;
$filters['start']['to'] += 7200;
}
$calls = VoiceCallHistoryModel::getVoiceCallHistory($filters, $perPage, $perPage * $page - $perPage, $order);
$filtered_available = VoiceCallHistoryModel::countVoiceCallHistory($filters);
$totalRows = VoiceCallHistoryModel::countVoiceCallHistory([]);
@@ -81,7 +99,7 @@ class VoiceCallHistoryController extends mfBaseController {
"rows" => $calls,
"pagination" => [
"page" => $page,
"total_pages" => ceil($totalRows / $perPage),
"total_pages" => ceil($filtered_available / $perPage),
"per_page" => $perPage,
"filtered_available" => intval($filtered_available),
"total_rows" => intval($totalRows)