A lot of code cleanup and code sanitation done.
This commit is contained in:
@@ -3,19 +3,19 @@
|
||||
namespace bin\php\Classes;
|
||||
class formBuilder
|
||||
{
|
||||
public $title;
|
||||
public $icon;
|
||||
public $submitButton;
|
||||
public $closeButton;
|
||||
public $closeButtonLocation;
|
||||
public string $title;
|
||||
public string $icon;
|
||||
public mixed $submitButton;
|
||||
public mixed $closeButton;
|
||||
public string $closeButtonLocation;
|
||||
|
||||
public $submitButtonColor;
|
||||
public string $submitButtonColor;
|
||||
|
||||
public $submitButtonText;
|
||||
public mixed $submitButtonText;
|
||||
|
||||
public $submitButtonIcon;
|
||||
public string $submitButtonIcon;
|
||||
|
||||
private $extraButtonsArray = array();
|
||||
private array $extraButtonsArray = array();
|
||||
|
||||
public function __construct($title, $icon, $closeButtonLocation, $submitButton = true, $closeButton = true)
|
||||
{
|
||||
@@ -29,7 +29,7 @@ class formBuilder
|
||||
$this->submitButtonIcon = $icon;
|
||||
}
|
||||
|
||||
public function startForm()
|
||||
public function startForm(): void
|
||||
{ ?>
|
||||
<div class="row"><div class="col-md-8 ms-auto me-auto"><div class="card">
|
||||
<div class="card-header">
|
||||
@@ -52,12 +52,12 @@ class formBuilder
|
||||
# 'buttonColor' => 'success'
|
||||
# ) > next array
|
||||
|
||||
public function addExtraButtons($extraButtonsArray)
|
||||
public function addExtraButtons($extraButtonsArray): bool
|
||||
{
|
||||
foreach ($extraButtonsArray as $numb => $extraButtonArray) {
|
||||
foreach ($extraButtonsArray as $extraButtonArray) {
|
||||
if (is_array($extraButtonArray)) {
|
||||
if (array_key_exists('buttonIcon', $extraButtonArray) && array_key_exists('buttonText', $extraButtonArray) && array_key_exists('buttonHref', $extraButtonArray) && array_key_exists('buttonColor', $extraButtonArray)) {
|
||||
array_push($this->extraButtonsArray, $extraButtonArray);
|
||||
$this->extraButtonsArray[] = $extraButtonArray;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -65,7 +65,7 @@ class formBuilder
|
||||
return false;
|
||||
}
|
||||
|
||||
public function formFooter()
|
||||
public function formFooter(): void
|
||||
{ ?>
|
||||
<div class="card-footer pt-3">
|
||||
<div class="row">
|
||||
@@ -74,7 +74,7 @@ class formBuilder
|
||||
<button type="submit" class="btn btn-<?php echo $this->submitButtonColor ?>"><?php echo $this->submitButtonIcon ?> <?php echo $this->submitButtonText ?></button>
|
||||
<?php }
|
||||
|
||||
foreach ($this->extraButtonsArray as $numb => $extraButtonArray) { ?>
|
||||
foreach ($this->extraButtonsArray as $extraButtonArray) { ?>
|
||||
<a href="<?php echo $extraButtonArray['buttonHref'] ?>" class="btn btn-<?php echo $extraButtonArray['buttonColor'] ?>"><?php echo $extraButtonArray['buttonIcon'] ?> <?php echo $extraButtonArray['buttonText'] ?></a>
|
||||
<?php }
|
||||
|
||||
|
||||
@@ -1,68 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace bin\php\Classes;
|
||||
if (!defined('APP_INIT')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
class healthCheck
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
include_once $_SERVER['DOCUMENT_ROOT'] . '/bin/php/db_connect.php';
|
||||
include_once $_SERVER['DOCUMENT_ROOT'] . '/bin/php/globalFunctions.php';
|
||||
}
|
||||
|
||||
public function healthCheck()
|
||||
{
|
||||
echo 'Checking and creating device data folders...';
|
||||
if ($this->checkDeviceDataFolders()) {
|
||||
echo 'Success creating device data folders';
|
||||
} else {
|
||||
echo 'something went wrong creating device data folders!';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private function checkDeviceDataFolders()
|
||||
{
|
||||
try {
|
||||
$sql = "SELECT device_slugify FROM autop_devices";
|
||||
|
||||
$stmt = $GLOBALS['conn']->prepare($sql);
|
||||
|
||||
if ($stmt === false) {
|
||||
throw new Exception("Failed to prepare the SQL statement: " . $GLOBALS['conn']->error);
|
||||
}
|
||||
|
||||
if (!$stmt->execute()) {
|
||||
throw new Exception("Failed to execute the SQL statement: " . $stmt->error);
|
||||
}
|
||||
|
||||
$result = $stmt->get_result();
|
||||
|
||||
while ($row = $result->fetch_assoc()) {
|
||||
$device_slugify = $row['device_slugify'];
|
||||
$dirsToCreate = array(
|
||||
$_SERVER['DOCUMENT_ROOT'] . "/data/devices/" . $device_slugify,
|
||||
$_SERVER['DOCUMENT_ROOT'] . "/data/devices/" . $device_slugify . "/firmware",
|
||||
$_SERVER['DOCUMENT_ROOT'] . "/data/devices/" . $device_slugify . "/documents"
|
||||
);
|
||||
|
||||
foreach ($dirsToCreate as $dir) {
|
||||
if (!file_exists($dir)) {
|
||||
if (!mkdir($dir)) {
|
||||
throw new Exception("Failed to create the directory: " . $dir);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$stmt->close();
|
||||
} catch (Exception $e) {
|
||||
return $e->getMessage();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -5,15 +5,13 @@ namespace bin\php\Classes;
|
||||
use PHPMailer\PHPMailer\Exception;
|
||||
use PHPMailer\PHPMailer\PHPMailer;
|
||||
|
||||
require $_SERVER['DOCUMENT_ROOT'] . '/../vendor/autoload.php';
|
||||
require_once "{$_SERVER['DOCUMENT_ROOT']}/../vendor/autoload.php";
|
||||
|
||||
class mailBuilder
|
||||
{
|
||||
public $mail;
|
||||
public $subject;
|
||||
public $mailText;
|
||||
|
||||
private $portal_uuid;
|
||||
public PHPMailer $mail;
|
||||
public string $subject;
|
||||
public string $mailText;
|
||||
|
||||
function __construct()
|
||||
{
|
||||
@@ -44,38 +42,44 @@ class mailBuilder
|
||||
$this->mail->CharSet = 'UTF-8';
|
||||
$this->mail->Encoding = 'base64';
|
||||
|
||||
$this->mail->setFrom($mail_settings['mail_from_address'], $mail_settings['mail_from_name']);
|
||||
try {
|
||||
$this->mail->setFrom($mail_settings['mail_from_address'], $mail_settings['mail_from_name']
|
||||
);
|
||||
} catch (Exception $e) {
|
||||
error_log($e->getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function addAddress($address, $name)
|
||||
{
|
||||
$this->mail->addAddress($address, $name);
|
||||
}
|
||||
|
||||
function sendMail()
|
||||
function addAddress($address, $name): void
|
||||
{
|
||||
try {
|
||||
$this->mail->isHTML(true);
|
||||
$this->mail->addAddress($address, $name);
|
||||
} catch (Exception $e) {
|
||||
error_log($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
function sendMail(): bool
|
||||
{
|
||||
try {
|
||||
$this->mail->isHTML();
|
||||
$this->mail->Subject = $this->subject;
|
||||
$this->mail->Body = $this->mailHtmlBody();
|
||||
|
||||
$this->mail->send();
|
||||
return true;
|
||||
} catch (Exception $e) {
|
||||
} catch (Exception) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function mailHtmlBody()
|
||||
function mailHtmlBody(): array|false|string
|
||||
{
|
||||
$body = file_get_contents($_SERVER['DOCUMENT_ROOT'] . '/src/html/mailBody.html');
|
||||
|
||||
$bodyText = $this->mailText;
|
||||
|
||||
$body = str_replace('{{bodyText}}', $bodyText, $body);
|
||||
|
||||
|
||||
return $body;
|
||||
return str_replace('{{bodyText}}', $bodyText, $body);
|
||||
}
|
||||
}
|
||||
@@ -8,12 +8,12 @@ if (!defined('APP_INIT')) {
|
||||
|
||||
use api\classes\API;
|
||||
|
||||
require_once($_SERVER['DOCUMENT_ROOT'] . '/api/classes/API.php');
|
||||
require_once "{$_SERVER['DOCUMENT_ROOT']}/api/classes/API.php";
|
||||
|
||||
class pageBuilder extends API
|
||||
class pageBuilder
|
||||
{
|
||||
|
||||
private $jsScriptLoadData;
|
||||
private array $jsScriptLoadData;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
@@ -38,12 +38,12 @@ class pageBuilder extends API
|
||||
$this->figureOutContent();
|
||||
}
|
||||
|
||||
private function figureOutContent()
|
||||
private function figureOutContent(): void
|
||||
{
|
||||
$requestUri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
|
||||
|
||||
// Remove trailing slash, but only if it’s not the root "/"
|
||||
if ($requestUri !== '/' && substr($requestUri, -1) === '/') {
|
||||
if ($requestUri !== '/' && str_ends_with($requestUri, '/')) {
|
||||
$requestUri = rtrim($requestUri, '/');
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ class pageBuilder extends API
|
||||
}
|
||||
}
|
||||
|
||||
public function buildPage()
|
||||
public function buildPage(): void
|
||||
{ ?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
@@ -94,8 +94,7 @@ class pageBuilder extends API
|
||||
</html>
|
||||
<?php }
|
||||
|
||||
private
|
||||
function pageHeadContent()
|
||||
private function pageHeadContent(): void
|
||||
{ ?>
|
||||
<head>
|
||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||||
@@ -127,12 +126,11 @@ class pageBuilder extends API
|
||||
</head>
|
||||
<?php }
|
||||
|
||||
private function pageSidebarContent()
|
||||
private function pageSidebarContent(): void
|
||||
{
|
||||
|
||||
|
||||
$API = new API();
|
||||
function showSpan($module_name)
|
||||
function showSpan($module_name): void
|
||||
{
|
||||
?>
|
||||
<li class="nav-section">
|
||||
@@ -145,7 +143,7 @@ class pageBuilder extends API
|
||||
</li>
|
||||
<?php }
|
||||
|
||||
function showPage($module_name, $page_name)
|
||||
function showPage($module_name, $page_name): void
|
||||
{
|
||||
$page = $GLOBALS['pages'][$module_name][$page_name];
|
||||
?>
|
||||
@@ -161,7 +159,7 @@ class pageBuilder extends API
|
||||
<div class="sidebar-logo">
|
||||
<div class="logo-header">
|
||||
<a href="/" class="logo">
|
||||
<img src="/src/images/logo-sidebar-dark.webp" alt="navbar brand" class="navbar-brand" height="50"/>
|
||||
<img src="/src/images/logo-sidebar-dark.webp" alt="navbar brand" class="navbar-brand" height="60"/>
|
||||
</a>
|
||||
<div class="nav-toggle">
|
||||
<button class="btn btn-toggle toggle-sidebar">
|
||||
@@ -219,8 +217,7 @@ class pageBuilder extends API
|
||||
<?php
|
||||
}
|
||||
|
||||
private
|
||||
function pageNavbarContent()
|
||||
private function pageNavbarContent(): void
|
||||
{
|
||||
?>
|
||||
<div class="main-header">
|
||||
@@ -228,7 +225,7 @@ class pageBuilder extends API
|
||||
<!-- Logo Header -->
|
||||
<div class="logo-header">
|
||||
<a href="/" class="logo">
|
||||
<img src="/src/images/logo-sidebar-dark.webp" alt="navbar brand" class="navbar-brand" height="50"/>
|
||||
<img src="/src/images/logo-sidebar-dark.webp" alt="navbar brand" class="navbar-brand" height="60"/>
|
||||
</a>
|
||||
<div class="nav-toggle">
|
||||
<button class="btn btn-toggle toggle-sidebar">
|
||||
@@ -258,37 +255,34 @@ class pageBuilder extends API
|
||||
<span class="op-7"> <?php echo __('hi') ?>, </span>
|
||||
<span class="fw-bold"><?php echo $_SESSION['user']['user_first_name'] ?></span>
|
||||
</a>
|
||||
|
||||
<ul class="dropdown-menu dropdown-user animated fadeIn">
|
||||
<div class="dropdown-user-scroll scrollbar-outer">
|
||||
<li>
|
||||
<div class="user-box">
|
||||
<div class="avatar-lg">
|
||||
<img src="<?php echo(($_SESSION['user']['user_profile_picture_thumbnail'] != null) ? 'data:image/png;base64, ' . $_SESSION['user']['user_profile_picture_thumbnail'] : '/src/images/user-avatar-default-small.png') ?>" alt="image profile" class="avatar-img rounded">
|
||||
</div>
|
||||
<div class="u-text">
|
||||
<h4><?php echo $_SESSION['user']['user_email'] ?></h4>
|
||||
<p class="text-muted"><?php echo $_SESSION['user']['user_email'] ?></p>
|
||||
</div>
|
||||
<li>
|
||||
<div class="user-box">
|
||||
<div class="avatar-lg">
|
||||
<img src="<?php echo(($_SESSION['user']['user_profile_picture_thumbnail'] != null) ? 'data:image/png;base64, ' . $_SESSION['user']['user_profile_picture_thumbnail'] : '/src/images/user-avatar-default-small.png') ?>" alt="image profile" class="avatar-img rounded">
|
||||
</div>
|
||||
</li>
|
||||
<li>
|
||||
<?php
|
||||
if ($_SESSION['user']['user_group_type'] == 'user' || $_SESSION['user']['user_group_type'] == 'admin') { ?>
|
||||
<a class="dropdown-item" href="/userprofile/"><i class="fa-solid fa-address-card"></i> <?php echo __('user_profile') ?>
|
||||
</a>
|
||||
<div class="dropdown-divider"></div>
|
||||
<?php } else { ?>
|
||||
<div class="dropdown-divider"></div>
|
||||
<?php } ?>
|
||||
<form id="logoutform" class="form-inline logoutform" action="/login/logout.php" method="POST">
|
||||
<input type="hidden" name="logout">
|
||||
<a class="dropdown-item" href="#" onclick="document.getElementById('logoutform').submit()">
|
||||
<i class="fas fa-sign-out-alt"></i> <?php echo __('logout') ?>
|
||||
</a>
|
||||
</form>
|
||||
</li>
|
||||
</div>
|
||||
<div class="u-text">
|
||||
<h4><?php echo $_SESSION['user']['user_email'] ?></h4>
|
||||
<p class="text-muted"><?php echo $_SESSION['user']['user_email'] ?></p>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
<li>
|
||||
<?php
|
||||
if ($_SESSION['user']['user_group_type'] == 'user' || $_SESSION['user']['user_group_type'] == 'admin') { ?>
|
||||
<a class="dropdown-item" href="/userprofile/"><i class="fa-solid fa-address-card"></i> <?php echo __('user_profile') ?>
|
||||
</a>
|
||||
<div class="dropdown-divider"></div>
|
||||
<?php } else { ?>
|
||||
<div class="dropdown-divider"></div>
|
||||
<?php } ?>
|
||||
<form id="logoutform" class="form-inline logoutform" action="/login/logout.php" method="POST">
|
||||
<input type="hidden" name="logout">
|
||||
<button type="submit" form="logoutform" class="dropdown-item">
|
||||
<i class="fas fa-sign-out-alt"></i> Logout
|
||||
</button>
|
||||
</form>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
@@ -298,8 +292,7 @@ class pageBuilder extends API
|
||||
</div>
|
||||
<?php }
|
||||
|
||||
private
|
||||
function pageFooterContent()
|
||||
private function pageFooterContent(): void
|
||||
{ ?>
|
||||
<footer class="footer py-2">
|
||||
<div class="container-fluid d-flex justify-content-between">
|
||||
@@ -321,8 +314,7 @@ class pageBuilder extends API
|
||||
</footer>
|
||||
<?php }
|
||||
|
||||
private
|
||||
function pageScriptContents()
|
||||
private function pageScriptContents(): void
|
||||
{ ?>
|
||||
<!-- always load these -->
|
||||
<script src="/src/js/core/jquery-3.7.1.min.js"></script>
|
||||
|
||||
@@ -7,8 +7,9 @@ if (!defined('APP_INIT')) {
|
||||
|
||||
class pageNavbar
|
||||
{
|
||||
public $breadCrumb;
|
||||
private $buttons = array();
|
||||
public bool $breadCrumb;
|
||||
private array $buttons = array();
|
||||
private string $title;
|
||||
|
||||
public function __construct($showBreadCrumb, $title = false)
|
||||
{
|
||||
@@ -16,12 +17,12 @@ class pageNavbar
|
||||
$this->title = $title;
|
||||
}
|
||||
|
||||
public function AddHTMLButton($html)
|
||||
public function AddHTMLButton($html): void
|
||||
{
|
||||
array_push($this->buttons, $html);
|
||||
$this->buttons[] = $html;
|
||||
}
|
||||
|
||||
public function outPutNavbar()
|
||||
public function outPutNavbar(): void
|
||||
{
|
||||
?>
|
||||
<div class="row">
|
||||
|
||||
@@ -36,7 +36,7 @@ class serverOverviewBuilder
|
||||
|
||||
public bool $showCompanies = true;
|
||||
|
||||
public function processServerData()
|
||||
public function processServerData(): void
|
||||
{
|
||||
foreach ($this->servers as $server) {
|
||||
if (!empty($server['server_backup'])) {
|
||||
@@ -86,7 +86,7 @@ class serverOverviewBuilder
|
||||
}
|
||||
}
|
||||
|
||||
private function cleanNumber($num)
|
||||
private function cleanNumber($num): string
|
||||
{
|
||||
// If integer value, return without formatting
|
||||
if (floor($num) == $num) {
|
||||
@@ -97,7 +97,7 @@ class serverOverviewBuilder
|
||||
return rtrim(rtrim(number_format($num, 10, '.', ''), '0'), '.');
|
||||
}
|
||||
|
||||
public function serverOverviewOutPut()
|
||||
public function serverOverviewOutPut(): void
|
||||
{ ?>
|
||||
<div class="form-group form-show-validation row mb-3">
|
||||
<?php if ($this->showServerOverviewTitle) { ?>
|
||||
|
||||
Reference in New Issue
Block a user